wininet: Add a skeleton winineti.h header with fixed prototypes for [GS]etUrlCacheCon...
[wine.git] / dlls / wininet / internet.c
blob36546b2944977531314c5114557e6d821bc9c89f
1 /*
2 * Wininet
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
10 * Ulrich Czekalla
11 * Aric Stewart
12 * David Hammerton
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "config.h"
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
34 #include <string.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
40 #endif
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
43 #endif
44 #include <stdlib.h>
45 #include <ctype.h>
46 #ifdef HAVE_UNISTD_H
47 # include <unistd.h>
48 #endif
49 #include <assert.h>
51 #include "windef.h"
52 #include "winbase.h"
53 #include "winreg.h"
54 #include "winuser.h"
55 #include "wininet.h"
56 #include "winineti.h"
57 #include "winnls.h"
58 #include "wine/debug.h"
59 #include "winerror.h"
60 #define NO_SHLWAPI_STREAM
61 #include "shlwapi.h"
62 #include "wincrypt.h"
64 #include "wine/exception.h"
66 #include "internet.h"
67 #include "resource.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define RESPONSE_TIMEOUT 30
75 typedef struct
77 DWORD dwError;
78 CHAR response[MAX_REPLY_LEN];
79 } WITHREADERROR, *LPWITHREADERROR;
81 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr);
82 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
83 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext);
85 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
86 static HMODULE WININET_hModule;
88 #define HANDLE_CHUNK_SIZE 0x10
90 static CRITICAL_SECTION WININET_cs;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
93 0, 0, &WININET_cs,
94 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
95 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
99 static LPWININETHANDLEHEADER *WININET_Handles;
100 static UINT WININET_dwNextHandle;
101 static UINT WININET_dwMaxHandles;
103 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
105 LPWININETHANDLEHEADER *p;
106 UINT handle = 0, num;
108 EnterCriticalSection( &WININET_cs );
109 if( !WININET_dwMaxHandles )
111 num = HANDLE_CHUNK_SIZE;
112 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
113 sizeof (UINT)* num);
114 if( !p )
115 goto end;
116 WININET_Handles = p;
117 WININET_dwMaxHandles = num;
119 if( WININET_dwMaxHandles == WININET_dwNextHandle )
121 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
122 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
123 WININET_Handles, sizeof (UINT)* num);
124 if( !p )
125 goto end;
126 WININET_Handles = p;
127 WININET_dwMaxHandles = num;
130 handle = WININET_dwNextHandle;
131 if( WININET_Handles[handle] )
132 ERR("handle isn't free but should be\n");
133 WININET_Handles[handle] = WININET_AddRef( info );
135 while( WININET_Handles[WININET_dwNextHandle] &&
136 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
137 WININET_dwNextHandle++;
139 end:
140 LeaveCriticalSection( &WININET_cs );
142 return info->hInternet = (HINTERNET) (handle+1);
145 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
147 info->dwRefCount++;
148 TRACE("%p -> refcount = %d\n", info, info->dwRefCount );
149 return info;
152 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
154 LPWININETHANDLEHEADER info = NULL;
155 UINT handle = (UINT) hinternet;
157 EnterCriticalSection( &WININET_cs );
159 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
160 WININET_Handles[handle-1] )
161 info = WININET_AddRef( WININET_Handles[handle-1] );
163 LeaveCriticalSection( &WININET_cs );
165 TRACE("handle %d -> %p\n", handle, info);
167 return info;
170 BOOL WININET_Release( LPWININETHANDLEHEADER info )
172 info->dwRefCount--;
173 TRACE( "object %p refcount = %d\n", info, info->dwRefCount );
174 if( !info->dwRefCount )
176 TRACE( "destroying object %p\n", info);
177 info->destroy( info );
179 return TRUE;
182 BOOL WININET_FreeHandle( HINTERNET hinternet )
184 BOOL ret = FALSE;
185 UINT handle = (UINT) hinternet;
186 LPWININETHANDLEHEADER info = NULL;
188 EnterCriticalSection( &WININET_cs );
190 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
192 handle--;
193 if( WININET_Handles[handle] )
195 info = WININET_Handles[handle];
196 TRACE( "destroying handle %d for object %p\n", handle+1, info);
197 WININET_Handles[handle] = NULL;
198 ret = TRUE;
199 if( WININET_dwNextHandle > handle )
200 WININET_dwNextHandle = handle;
204 LeaveCriticalSection( &WININET_cs );
206 if( info )
207 WININET_Release( info );
209 return ret;
212 /***********************************************************************
213 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
215 * PARAMS
216 * hinstDLL [I] handle to the DLL's instance
217 * fdwReason [I]
218 * lpvReserved [I] reserved, must be NULL
220 * RETURNS
221 * Success: TRUE
222 * Failure: FALSE
225 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
227 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
229 switch (fdwReason) {
230 case DLL_PROCESS_ATTACH:
232 g_dwTlsErrIndex = TlsAlloc();
234 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
235 return FALSE;
237 URLCacheContainers_CreateDefaults();
239 WININET_hModule = (HMODULE)hinstDLL;
241 case DLL_THREAD_ATTACH:
242 break;
244 case DLL_THREAD_DETACH:
245 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
247 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
248 HeapFree(GetProcessHeap(), 0, lpwite);
250 break;
252 case DLL_PROCESS_DETACH:
254 URLCacheContainers_DeleteAll();
256 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
258 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
259 TlsFree(g_dwTlsErrIndex);
261 break;
264 return TRUE;
268 /***********************************************************************
269 * InternetInitializeAutoProxyDll (WININET.@)
271 * Setup the internal proxy
273 * PARAMETERS
274 * dwReserved
276 * RETURNS
277 * FALSE on failure
280 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
282 FIXME("STUB\n");
283 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
284 return FALSE;
287 /***********************************************************************
288 * DetectAutoProxyUrl (WININET.@)
290 * Auto detect the proxy url
292 * RETURNS
293 * FALSE on failure
296 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
297 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
299 FIXME("STUB\n");
300 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
301 return FALSE;
305 /***********************************************************************
306 * INTERNET_ConfigureProxyFromReg
308 * FIXME:
309 * The proxy may be specified in the form 'http=proxy.my.org'
310 * Presumably that means there can be ftp=ftpproxy.my.org too.
312 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
314 HKEY key;
315 DWORD r, keytype, len, enabled;
316 LPCSTR lpszInternetSettings =
317 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
318 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
320 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
321 if ( r != ERROR_SUCCESS )
322 return FALSE;
324 len = sizeof enabled;
325 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
326 (BYTE*)&enabled, &len);
327 if( (r == ERROR_SUCCESS) && enabled )
329 TRACE("Proxy is enabled.\n");
331 /* figure out how much memory the proxy setting takes */
332 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
333 NULL, &len);
334 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
336 LPWSTR szProxy, p;
337 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
339 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
340 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
341 (BYTE*)szProxy, &len);
343 /* find the http proxy, and strip away everything else */
344 p = strstrW( szProxy, szHttp );
345 if( p )
347 p += lstrlenW(szHttp);
348 lstrcpyW( szProxy, p );
350 p = strchrW( szProxy, ' ' );
351 if( p )
352 *p = 0;
354 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
355 lpwai->lpszProxy = szProxy;
357 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
359 else
360 ERR("Couldn't read proxy server settings.\n");
362 else
363 TRACE("Proxy is not enabled.\n");
364 RegCloseKey(key);
366 return enabled;
369 /***********************************************************************
370 * dump_INTERNET_FLAGS
372 * Helper function to TRACE the internet flags.
374 * RETURNS
375 * None
378 static void dump_INTERNET_FLAGS(DWORD dwFlags)
380 #define FE(x) { x, #x }
381 static const wininet_flag_info flag[] = {
382 FE(INTERNET_FLAG_RELOAD),
383 FE(INTERNET_FLAG_RAW_DATA),
384 FE(INTERNET_FLAG_EXISTING_CONNECT),
385 FE(INTERNET_FLAG_ASYNC),
386 FE(INTERNET_FLAG_PASSIVE),
387 FE(INTERNET_FLAG_NO_CACHE_WRITE),
388 FE(INTERNET_FLAG_MAKE_PERSISTENT),
389 FE(INTERNET_FLAG_FROM_CACHE),
390 FE(INTERNET_FLAG_SECURE),
391 FE(INTERNET_FLAG_KEEP_CONNECTION),
392 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
393 FE(INTERNET_FLAG_READ_PREFETCH),
394 FE(INTERNET_FLAG_NO_COOKIES),
395 FE(INTERNET_FLAG_NO_AUTH),
396 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
397 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
398 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
399 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
400 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
401 FE(INTERNET_FLAG_RESYNCHRONIZE),
402 FE(INTERNET_FLAG_HYPERLINK),
403 FE(INTERNET_FLAG_NO_UI),
404 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
405 FE(INTERNET_FLAG_CACHE_ASYNC),
406 FE(INTERNET_FLAG_FORMS_SUBMIT),
407 FE(INTERNET_FLAG_NEED_FILE),
408 FE(INTERNET_FLAG_TRANSFER_ASCII),
409 FE(INTERNET_FLAG_TRANSFER_BINARY)
411 #undef FE
412 int i;
414 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
415 if (flag[i].val & dwFlags) {
416 TRACE(" %s", flag[i].name);
417 dwFlags &= ~flag[i].val;
420 if (dwFlags)
421 TRACE(" Unknown flags (%08x)\n", dwFlags);
422 else
423 TRACE("\n");
426 /***********************************************************************
427 * InternetOpenW (WININET.@)
429 * Per-application initialization of wininet
431 * RETURNS
432 * HINTERNET on success
433 * NULL on failure
436 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
437 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
439 LPWININETAPPINFOW lpwai = NULL;
440 HINTERNET handle = NULL;
442 if (TRACE_ON(wininet)) {
443 #define FE(x) { x, #x }
444 static const wininet_flag_info access_type[] = {
445 FE(INTERNET_OPEN_TYPE_PRECONFIG),
446 FE(INTERNET_OPEN_TYPE_DIRECT),
447 FE(INTERNET_OPEN_TYPE_PROXY),
448 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
450 #undef FE
451 DWORD i;
452 const char *access_type_str = "Unknown";
454 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
455 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
456 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
457 if (access_type[i].val == dwAccessType) {
458 access_type_str = access_type[i].name;
459 break;
462 TRACE(" access type : %s\n", access_type_str);
463 TRACE(" flags :");
464 dump_INTERNET_FLAGS(dwFlags);
467 /* Clear any error information */
468 INTERNET_SetLastError(0);
470 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETAPPINFOW));
471 if (NULL == lpwai)
473 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
474 goto lend;
477 lpwai->hdr.htype = WH_HINIT;
478 lpwai->hdr.dwFlags = dwFlags;
479 lpwai->hdr.dwRefCount = 1;
480 lpwai->hdr.destroy = INTERNET_CloseHandle;
481 lpwai->dwAccessType = dwAccessType;
482 lpwai->lpszProxyUsername = NULL;
483 lpwai->lpszProxyPassword = NULL;
485 handle = WININET_AllocHandle( &lpwai->hdr );
486 if( !handle )
488 HeapFree( GetProcessHeap(), 0, lpwai );
489 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
490 goto lend;
493 if (NULL != lpszAgent)
495 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
496 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
497 if (lpwai->lpszAgent)
498 lstrcpyW( lpwai->lpszAgent, lpszAgent );
500 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
501 INTERNET_ConfigureProxyFromReg( lpwai );
502 else if (NULL != lpszProxy)
504 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
505 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
506 if (lpwai->lpszProxy)
507 lstrcpyW( lpwai->lpszProxy, lpszProxy );
510 if (NULL != lpszProxyBypass)
512 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
513 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
514 if (lpwai->lpszProxyBypass)
515 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
518 lend:
519 if( lpwai )
520 WININET_Release( &lpwai->hdr );
522 TRACE("returning %p\n", lpwai);
524 return handle;
528 /***********************************************************************
529 * InternetOpenA (WININET.@)
531 * Per-application initialization of wininet
533 * RETURNS
534 * HINTERNET on success
535 * NULL on failure
538 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
539 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
541 HINTERNET rc = (HINTERNET)NULL;
542 INT len;
543 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
545 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
546 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
548 if( lpszAgent )
550 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
551 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
552 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
555 if( lpszProxy )
557 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
558 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
559 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
562 if( lpszProxyBypass )
564 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
565 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
566 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
569 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
571 HeapFree(GetProcessHeap(), 0, szAgent);
572 HeapFree(GetProcessHeap(), 0, szProxy);
573 HeapFree(GetProcessHeap(), 0, szBypass);
575 return rc;
578 /***********************************************************************
579 * InternetGetLastResponseInfoA (WININET.@)
581 * Return last wininet error description on the calling thread
583 * RETURNS
584 * TRUE on success of writing to buffer
585 * FALSE on failure
588 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
589 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
591 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
593 TRACE("\n");
595 if (lpwite)
597 *lpdwError = lpwite->dwError;
598 if (lpwite->dwError)
600 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
601 *lpdwBufferLength = strlen(lpszBuffer);
603 else
604 *lpdwBufferLength = 0;
606 else
608 *lpdwError = 0;
609 *lpdwBufferLength = 0;
612 return TRUE;
615 /***********************************************************************
616 * InternetGetLastResponseInfoW (WININET.@)
618 * Return last wininet error description on the calling thread
620 * RETURNS
621 * TRUE on success of writing to buffer
622 * FALSE on failure
625 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
626 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
628 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
630 TRACE("\n");
632 if (lpwite)
634 *lpdwError = lpwite->dwError;
635 if (lpwite->dwError)
637 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
638 *lpdwBufferLength = lstrlenW(lpszBuffer);
640 else
641 *lpdwBufferLength = 0;
643 else
645 *lpdwError = 0;
646 *lpdwBufferLength = 0;
649 return TRUE;
652 /***********************************************************************
653 * InternetGetConnectedState (WININET.@)
655 * Return connected state
657 * RETURNS
658 * TRUE if connected
659 * if lpdwStatus is not null, return the status (off line,
660 * modem, lan...) in it.
661 * FALSE if not connected
663 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
665 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
667 if (lpdwStatus) {
668 FIXME("always returning LAN connection.\n");
669 *lpdwStatus = INTERNET_CONNECTION_LAN;
671 return TRUE;
675 /***********************************************************************
676 * InternetGetConnectedStateExW (WININET.@)
678 * Return connected state
680 * PARAMS
682 * lpdwStatus [O] Flags specifying the status of the internet connection.
683 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
684 * dwNameLen [I] Size of the buffer, in characters.
685 * dwReserved [I] Reserved. Must be set to 0.
687 * RETURNS
688 * TRUE if connected
689 * if lpdwStatus is not null, return the status (off line,
690 * modem, lan...) in it.
691 * FALSE if not connected
693 * NOTES
694 * If the system has no available network connections, an empty string is
695 * stored in lpszConnectionName. If there is a LAN connection, a localized
696 * "LAN Connection" string is stored. Presumably, if only a dial-up
697 * connection is available then the name of the dial-up connection is
698 * returned. Why any application, other than the "Internet Settings" CPL,
699 * would want to use this function instead of the simpler InternetGetConnectedStateW
700 * function is beyond me.
702 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
703 DWORD dwNameLen, DWORD dwReserved)
705 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
707 /* Must be zero */
708 if(dwReserved)
709 return FALSE;
711 if (lpdwStatus) {
712 FIXME("always returning LAN connection.\n");
713 *lpdwStatus = INTERNET_CONNECTION_LAN;
715 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
719 /***********************************************************************
720 * InternetGetConnectedStateExA (WININET.@)
722 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
723 DWORD dwNameLen, DWORD dwReserved)
725 LPWSTR lpwszConnectionName = NULL;
726 BOOL rc;
728 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
730 if (lpszConnectionName && dwNameLen > 0)
731 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
733 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
734 dwReserved);
735 if (rc && lpwszConnectionName)
737 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
738 dwNameLen, NULL, NULL);
740 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
743 return rc;
747 /***********************************************************************
748 * InternetConnectW (WININET.@)
750 * Open a ftp, gopher or http session
752 * RETURNS
753 * HINTERNET a session handle on success
754 * NULL on failure
757 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
758 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
759 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
760 DWORD dwService, DWORD dwFlags, DWORD dwContext)
762 LPWININETAPPINFOW hIC;
763 HINTERNET rc = NULL;
765 TRACE("(%p, %s, %i, %s, %s, %i, %i, %i)\n", hInternet, debugstr_w(lpszServerName),
766 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
767 dwService, dwFlags, dwContext);
769 if (!lpszServerName)
771 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
772 return NULL;
775 /* Clear any error information */
776 INTERNET_SetLastError(0);
777 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
778 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
780 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
781 goto lend;
784 switch (dwService)
786 case INTERNET_SERVICE_FTP:
787 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
788 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
789 break;
791 case INTERNET_SERVICE_HTTP:
792 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
793 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
794 break;
796 case INTERNET_SERVICE_GOPHER:
797 default:
798 break;
800 lend:
801 if( hIC )
802 WININET_Release( &hIC->hdr );
804 TRACE("returning %p\n", rc);
805 return rc;
809 /***********************************************************************
810 * InternetConnectA (WININET.@)
812 * Open a ftp, gopher or http session
814 * RETURNS
815 * HINTERNET a session handle on success
816 * NULL on failure
819 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
820 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
821 LPCSTR lpszUserName, LPCSTR lpszPassword,
822 DWORD dwService, DWORD dwFlags, DWORD dwContext)
824 HINTERNET rc = (HINTERNET)NULL;
825 INT len = 0;
826 LPWSTR szServerName = NULL;
827 LPWSTR szUserName = NULL;
828 LPWSTR szPassword = NULL;
830 if (lpszServerName)
832 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
833 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
834 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
836 if (lpszUserName)
838 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
839 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
840 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
842 if (lpszPassword)
844 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
845 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
846 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
850 rc = InternetConnectW(hInternet, szServerName, nServerPort,
851 szUserName, szPassword, dwService, dwFlags, dwContext);
853 HeapFree(GetProcessHeap(), 0, szServerName);
854 HeapFree(GetProcessHeap(), 0, szUserName);
855 HeapFree(GetProcessHeap(), 0, szPassword);
856 return rc;
860 /***********************************************************************
861 * InternetFindNextFileA (WININET.@)
863 * Continues a file search from a previous call to FindFirstFile
865 * RETURNS
866 * TRUE on success
867 * FALSE on failure
870 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
872 BOOL ret;
873 WIN32_FIND_DATAW fd;
875 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
876 if(lpvFindData)
877 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
878 return ret;
881 /***********************************************************************
882 * InternetFindNextFileW (WININET.@)
884 * Continues a file search from a previous call to FindFirstFile
886 * RETURNS
887 * TRUE on success
888 * FALSE on failure
891 static void AsyncFtpFindNextFileProc(WORKREQUEST *workRequest)
893 struct WORKREQ_FTPFINDNEXTW *req = &workRequest->u.FtpFindNextW;
894 LPWININETFTPFINDNEXTW lpwh = (LPWININETFTPFINDNEXTW) workRequest->hdr;
896 TRACE("%p\n", lpwh);
898 FTP_FindNextFileW(lpwh, req->lpFindFileData);
901 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
903 LPWININETAPPINFOW hIC = NULL;
904 LPWININETFTPFINDNEXTW lpwh;
905 BOOL bSuccess = FALSE;
907 TRACE("\n");
909 lpwh = (LPWININETFTPFINDNEXTW) WININET_GetObject( hFind );
910 if (NULL == lpwh || lpwh->hdr.htype != WH_HFTPFINDNEXT)
912 FIXME("Only FTP supported\n");
913 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
914 goto lend;
917 hIC = lpwh->lpFtpSession->lpAppInfo;
918 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
920 WORKREQUEST workRequest;
921 struct WORKREQ_FTPFINDNEXTW *req;
923 workRequest.asyncproc = AsyncFtpFindNextFileProc;
924 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
925 req = &workRequest.u.FtpFindNextW;
926 req->lpFindFileData = lpvFindData;
928 bSuccess = INTERNET_AsyncCall(&workRequest);
930 else
932 bSuccess = FTP_FindNextFileW(lpwh, lpvFindData);
934 lend:
935 if( lpwh )
936 WININET_Release( &lpwh->hdr );
937 return bSuccess;
940 /***********************************************************************
941 * INTERNET_CloseHandle (internal)
943 * Close internet handle
945 * RETURNS
946 * Void
949 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
951 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
953 TRACE("%p\n",lpwai);
955 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
956 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
957 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
958 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
959 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
960 HeapFree(GetProcessHeap(), 0, lpwai);
964 /***********************************************************************
965 * InternetCloseHandle (WININET.@)
967 * Generic close handle function
969 * RETURNS
970 * TRUE on success
971 * FALSE on failure
974 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
976 LPWININETHANDLEHEADER lpwh;
978 TRACE("%p\n",hInternet);
980 lpwh = WININET_GetObject( hInternet );
981 if (NULL == lpwh)
983 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
984 return FALSE;
987 /* FIXME: native appears to send this from the equivalent of
988 * WININET_Release */
989 INTERNET_SendCallback(lpwh, lpwh->dwContext,
990 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
991 sizeof(HINTERNET));
993 WININET_FreeHandle( hInternet );
994 WININET_Release( lpwh );
996 return TRUE;
1000 /***********************************************************************
1001 * ConvertUrlComponentValue (Internal)
1003 * Helper function for InternetCrackUrlW
1006 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1007 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1008 LPCSTR lpszStart, LPCWSTR lpwszStart)
1010 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1011 if (*dwComponentLen != 0)
1013 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1014 if (*lppszComponent == NULL)
1016 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1017 if (lpwszComponent)
1018 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1019 else
1020 *lppszComponent = NULL;
1021 *dwComponentLen = nASCIILength;
1023 else
1025 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1026 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1027 (*lppszComponent)[ncpylen]=0;
1028 *dwComponentLen = ncpylen;
1034 /***********************************************************************
1035 * InternetCrackUrlA (WININET.@)
1037 * See InternetCrackUrlW.
1039 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1040 LPURL_COMPONENTSA lpUrlComponents)
1042 DWORD nLength;
1043 URL_COMPONENTSW UCW;
1044 WCHAR* lpwszUrl;
1046 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1048 if (!lpszUrl || !*lpszUrl)
1050 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1051 return FALSE;
1054 if(dwUrlLength<=0)
1055 dwUrlLength=-1;
1056 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1058 /* if dwUrlLength=-1 then nLength includes null but length to
1059 InternetCrackUrlW should not include it */
1060 if (dwUrlLength == -1) nLength--;
1062 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1063 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1065 memset(&UCW,0,sizeof(UCW));
1066 if(lpUrlComponents->dwHostNameLength!=0)
1067 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1068 if(lpUrlComponents->dwUserNameLength!=0)
1069 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1070 if(lpUrlComponents->dwPasswordLength!=0)
1071 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1072 if(lpUrlComponents->dwUrlPathLength!=0)
1073 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1074 if(lpUrlComponents->dwSchemeLength!=0)
1075 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1076 if(lpUrlComponents->dwExtraInfoLength!=0)
1077 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1078 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1080 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1081 return FALSE;
1084 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1085 UCW.lpszHostName, UCW.dwHostNameLength,
1086 lpszUrl, lpwszUrl);
1087 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1088 UCW.lpszUserName, UCW.dwUserNameLength,
1089 lpszUrl, lpwszUrl);
1090 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1091 UCW.lpszPassword, UCW.dwPasswordLength,
1092 lpszUrl, lpwszUrl);
1093 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1094 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1095 lpszUrl, lpwszUrl);
1096 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1097 UCW.lpszScheme, UCW.dwSchemeLength,
1098 lpszUrl, lpwszUrl);
1099 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1100 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1101 lpszUrl, lpwszUrl);
1102 lpUrlComponents->nScheme=UCW.nScheme;
1103 lpUrlComponents->nPort=UCW.nPort;
1104 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1106 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1107 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1108 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1109 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1110 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1112 return TRUE;
1115 static const WCHAR url_schemes[][7] =
1117 {'f','t','p',0},
1118 {'g','o','p','h','e','r',0},
1119 {'h','t','t','p',0},
1120 {'h','t','t','p','s',0},
1121 {'f','i','l','e',0},
1122 {'n','e','w','s',0},
1123 {'m','a','i','l','t','o',0},
1124 {'r','e','s',0},
1127 /***********************************************************************
1128 * GetInternetSchemeW (internal)
1130 * Get scheme of url
1132 * RETURNS
1133 * scheme on success
1134 * INTERNET_SCHEME_UNKNOWN on failure
1137 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1139 int i;
1141 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1143 if(lpszScheme==NULL)
1144 return INTERNET_SCHEME_UNKNOWN;
1146 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1147 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1148 return INTERNET_SCHEME_FIRST + i;
1150 return INTERNET_SCHEME_UNKNOWN;
1153 /***********************************************************************
1154 * SetUrlComponentValueW (Internal)
1156 * Helper function for InternetCrackUrlW
1158 * PARAMS
1159 * lppszComponent [O] Holds the returned string
1160 * dwComponentLen [I] Holds the size of lppszComponent
1161 * [O] Holds the length of the string in lppszComponent without '\0'
1162 * lpszStart [I] Holds the string to copy from
1163 * len [I] Holds the length of lpszStart without '\0'
1165 * RETURNS
1166 * TRUE on success
1167 * FALSE on failure
1170 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1172 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1174 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1175 return FALSE;
1177 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1179 if (*lppszComponent == NULL)
1181 *lppszComponent = (LPWSTR)lpszStart;
1182 *dwComponentLen = len;
1184 else
1186 DWORD ncpylen = min((*dwComponentLen)-1, len);
1187 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1188 (*lppszComponent)[ncpylen] = '\0';
1189 *dwComponentLen = ncpylen;
1193 return TRUE;
1196 /***********************************************************************
1197 * InternetCrackUrlW (WININET.@)
1199 * Break up URL into its components
1201 * RETURNS
1202 * TRUE on success
1203 * FALSE on failure
1205 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1206 LPURL_COMPONENTSW lpUC)
1209 * RFC 1808
1210 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1213 LPCWSTR lpszParam = NULL;
1214 BOOL bIsAbsolute = FALSE;
1215 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1216 LPCWSTR lpszcp = NULL;
1217 LPWSTR lpszUrl_decode = NULL;
1218 DWORD dwUrlLength = dwUrlLength_orig;
1219 const WCHAR lpszSeparators[3]={';','?',0};
1220 const WCHAR lpszSlash[2]={'/',0};
1221 if(dwUrlLength==0)
1222 dwUrlLength=strlenW(lpszUrl);
1224 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1226 if (!lpszUrl_orig || !*lpszUrl_orig)
1228 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1229 return FALSE;
1232 if (dwFlags & ICU_DECODE)
1234 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1235 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1237 lpszUrl = lpszUrl_decode;
1240 lpszap = lpszUrl;
1242 /* Determine if the URI is absolute. */
1243 while (*lpszap != '\0')
1245 if (isalnumW(*lpszap))
1247 lpszap++;
1248 continue;
1250 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1252 bIsAbsolute = TRUE;
1253 lpszcp = lpszap;
1255 else
1257 lpszcp = lpszUrl; /* Relative url */
1260 break;
1263 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1264 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1266 /* Parse <params> */
1267 lpszParam = strpbrkW(lpszap, lpszSeparators);
1268 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1269 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1271 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1273 LPCWSTR lpszNetLoc;
1275 /* Get scheme first. */
1276 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1277 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1278 lpszUrl, lpszcp - lpszUrl);
1280 /* Eat ':' in protocol. */
1281 lpszcp++;
1283 /* double slash indicates the net_loc portion is present */
1284 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1286 lpszcp += 2;
1288 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1289 if (lpszParam)
1291 if (lpszNetLoc)
1292 lpszNetLoc = min(lpszNetLoc, lpszParam);
1293 else
1294 lpszNetLoc = lpszParam;
1296 else if (!lpszNetLoc)
1297 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1299 /* Parse net-loc */
1300 if (lpszNetLoc)
1302 LPCWSTR lpszHost;
1303 LPCWSTR lpszPort;
1305 /* [<user>[<:password>]@]<host>[:<port>] */
1306 /* First find the user and password if they exist */
1308 lpszHost = strchrW(lpszcp, '@');
1309 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1311 /* username and password not specified. */
1312 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1313 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1315 else /* Parse out username and password */
1317 LPCWSTR lpszUser = lpszcp;
1318 LPCWSTR lpszPasswd = lpszHost;
1320 while (lpszcp < lpszHost)
1322 if (*lpszcp == ':')
1323 lpszPasswd = lpszcp;
1325 lpszcp++;
1328 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1329 lpszUser, lpszPasswd - lpszUser);
1331 if (lpszPasswd != lpszHost)
1332 lpszPasswd++;
1333 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1334 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1335 lpszHost - lpszPasswd);
1337 lpszcp++; /* Advance to beginning of host */
1340 /* Parse <host><:port> */
1342 lpszHost = lpszcp;
1343 lpszPort = lpszNetLoc;
1345 /* special case for res:// URLs: there is no port here, so the host is the
1346 entire string up to the first '/' */
1347 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1349 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1350 lpszHost, lpszPort - lpszHost);
1351 lpszcp=lpszNetLoc;
1353 else
1355 while (lpszcp < lpszNetLoc)
1357 if (*lpszcp == ':')
1358 lpszPort = lpszcp;
1360 lpszcp++;
1363 /* If the scheme is "file" and the host is just one letter, it's not a host */
1364 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1366 lpszcp=lpszHost;
1367 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1368 NULL, 0);
1370 else
1372 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1373 lpszHost, lpszPort - lpszHost);
1374 if (lpszPort != lpszNetLoc)
1375 lpUC->nPort = atoiW(++lpszPort);
1376 else switch (lpUC->nScheme)
1378 case INTERNET_SCHEME_HTTP:
1379 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1380 break;
1381 case INTERNET_SCHEME_HTTPS:
1382 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1383 break;
1384 case INTERNET_SCHEME_FTP:
1385 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1386 break;
1387 case INTERNET_SCHEME_GOPHER:
1388 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1389 break;
1390 default:
1391 break;
1397 else
1399 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1400 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1401 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1404 else
1406 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1407 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1408 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1409 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1412 /* Here lpszcp points to:
1414 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1415 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1417 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1419 INT len;
1421 /* Only truncate the parameter list if it's already been saved
1422 * in lpUC->lpszExtraInfo.
1424 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1425 len = lpszParam - lpszcp;
1426 else
1428 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1429 * newlines if necessary.
1431 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1432 if (lpsznewline != NULL)
1433 len = lpsznewline - lpszcp;
1434 else
1435 len = dwUrlLength-(lpszcp-lpszUrl);
1437 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1438 lpszcp, len);
1440 else
1442 lpUC->dwUrlPathLength = 0;
1445 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1446 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1447 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1448 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1449 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1451 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1452 return TRUE;
1455 /***********************************************************************
1456 * InternetAttemptConnect (WININET.@)
1458 * Attempt to make a connection to the internet
1460 * RETURNS
1461 * ERROR_SUCCESS on success
1462 * Error value on failure
1465 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1467 FIXME("Stub\n");
1468 return ERROR_SUCCESS;
1472 /***********************************************************************
1473 * InternetCanonicalizeUrlA (WININET.@)
1475 * Escape unsafe characters and spaces
1477 * RETURNS
1478 * TRUE on success
1479 * FALSE on failure
1482 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1483 LPDWORD lpdwBufferLength, DWORD dwFlags)
1485 HRESULT hr;
1486 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1487 if(dwFlags & ICU_DECODE)
1489 dwURLFlags |= URL_UNESCAPE;
1490 dwFlags &= ~ICU_DECODE;
1493 if(dwFlags & ICU_ESCAPE)
1495 dwURLFlags |= URL_UNESCAPE;
1496 dwFlags &= ~ICU_ESCAPE;
1498 if(dwFlags & ICU_BROWSER_MODE)
1500 dwURLFlags |= URL_BROWSER_MODE;
1501 dwFlags &= ~ICU_BROWSER_MODE;
1503 if(dwFlags)
1504 FIXME("Unhandled flags 0x%08x\n", dwFlags);
1505 TRACE("%s %p %p %08x\n", debugstr_a(lpszUrl), lpszBuffer,
1506 lpdwBufferLength, dwURLFlags);
1508 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1509 dwFlags ^= ICU_NO_ENCODE;
1511 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1513 return (hr == S_OK) ? TRUE : FALSE;
1516 /***********************************************************************
1517 * InternetCanonicalizeUrlW (WININET.@)
1519 * Escape unsafe characters and spaces
1521 * RETURNS
1522 * TRUE on success
1523 * FALSE on failure
1526 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1527 LPDWORD lpdwBufferLength, DWORD dwFlags)
1529 HRESULT hr;
1530 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1531 if(dwFlags & ICU_DECODE)
1533 dwURLFlags |= URL_UNESCAPE;
1534 dwFlags &= ~ICU_DECODE;
1537 if(dwFlags & ICU_ESCAPE)
1539 dwURLFlags |= URL_UNESCAPE;
1540 dwFlags &= ~ICU_ESCAPE;
1542 if(dwFlags & ICU_BROWSER_MODE)
1544 dwURLFlags |= URL_BROWSER_MODE;
1545 dwFlags &= ~ICU_BROWSER_MODE;
1547 if(dwFlags)
1548 FIXME("Unhandled flags 0x%08x\n", dwFlags);
1549 TRACE("%s %p %p %08x\n", debugstr_w(lpszUrl), lpszBuffer,
1550 lpdwBufferLength, dwURLFlags);
1552 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1553 dwFlags ^= ICU_NO_ENCODE;
1555 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1557 return (hr == S_OK) ? TRUE : FALSE;
1561 /***********************************************************************
1562 * InternetSetStatusCallbackA (WININET.@)
1564 * Sets up a callback function which is called as progress is made
1565 * during an operation.
1567 * RETURNS
1568 * Previous callback or NULL on success
1569 * INTERNET_INVALID_STATUS_CALLBACK on failure
1572 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1573 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1575 INTERNET_STATUS_CALLBACK retVal;
1576 LPWININETHANDLEHEADER lpwh;
1578 TRACE("0x%08x\n", (ULONG)hInternet);
1580 lpwh = WININET_GetObject(hInternet);
1581 if (!lpwh)
1582 return INTERNET_INVALID_STATUS_CALLBACK;
1584 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1585 retVal = lpwh->lpfnStatusCB;
1586 lpwh->lpfnStatusCB = lpfnIntCB;
1588 WININET_Release( lpwh );
1590 return retVal;
1593 /***********************************************************************
1594 * InternetSetStatusCallbackW (WININET.@)
1596 * Sets up a callback function which is called as progress is made
1597 * during an operation.
1599 * RETURNS
1600 * Previous callback or NULL on success
1601 * INTERNET_INVALID_STATUS_CALLBACK on failure
1604 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1605 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1607 INTERNET_STATUS_CALLBACK retVal;
1608 LPWININETHANDLEHEADER lpwh;
1610 TRACE("0x%08x\n", (ULONG)hInternet);
1612 lpwh = WININET_GetObject(hInternet);
1613 if (!lpwh)
1614 return INTERNET_INVALID_STATUS_CALLBACK;
1616 lpwh->dwInternalFlags |= INET_CALLBACKW;
1617 retVal = lpwh->lpfnStatusCB;
1618 lpwh->lpfnStatusCB = lpfnIntCB;
1620 WININET_Release( lpwh );
1622 return retVal;
1625 /***********************************************************************
1626 * InternetSetFilePointer (WININET.@)
1628 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1629 PVOID pReserved, DWORD dwMoveContext, DWORD dwContext)
1631 FIXME("stub\n");
1632 return FALSE;
1635 /***********************************************************************
1636 * InternetWriteFile (WININET.@)
1638 * Write data to an open internet file
1640 * RETURNS
1641 * TRUE on success
1642 * FALSE on failure
1645 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1646 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1648 BOOL retval = FALSE;
1649 int nSocket = -1;
1650 LPWININETHANDLEHEADER lpwh;
1652 TRACE("\n");
1653 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1654 if (NULL == lpwh)
1655 return FALSE;
1657 switch (lpwh->htype)
1659 case WH_HHTTPREQ:
1661 LPWININETHTTPREQW lpwhr;
1662 lpwhr = (LPWININETHTTPREQW)lpwh;
1664 TRACE("HTTPREQ %i\n",dwNumOfBytesToWrite);
1665 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1666 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1668 WININET_Release( lpwh );
1669 return retval;
1671 break;
1673 case WH_HFILE:
1674 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1675 break;
1677 default:
1678 break;
1681 if (nSocket != -1)
1683 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1684 retval = (res >= 0);
1685 *lpdwNumOfBytesWritten = retval ? res : 0;
1687 WININET_Release( lpwh );
1689 return retval;
1693 BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1694 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1695 BOOL bWait, BOOL bSendCompletionStatus)
1697 BOOL retval = FALSE;
1698 int nSocket = -1;
1699 int bytes_read;
1700 LPWININETHTTPREQW lpwhr;
1702 /* FIXME: this should use NETCON functions! */
1703 switch (lpwh->htype)
1705 case WH_HHTTPREQ:
1706 lpwhr = (LPWININETHTTPREQW)lpwh;
1708 if (!NETCON_recv(&lpwhr->netConnection, lpBuffer,
1709 min(dwNumOfBytesToRead, lpwhr->dwContentLength - lpwhr->dwContentRead),
1710 bWait ? MSG_WAITALL : 0, &bytes_read))
1713 if (((lpwhr->dwContentLength != -1) &&
1714 (lpwhr->dwContentRead != lpwhr->dwContentLength)))
1715 ERR("not all data received %d/%d\n", lpwhr->dwContentRead,
1716 lpwhr->dwContentLength);
1718 /* always returns TRUE, even if the network layer returns an
1719 * error */
1720 *pdwNumOfBytesRead = 0;
1721 HTTP_FinishedReading(lpwhr);
1722 retval = TRUE;
1724 else
1726 lpwhr->dwContentRead += bytes_read;
1727 *pdwNumOfBytesRead = bytes_read;
1728 if (!bytes_read && (lpwhr->dwContentRead == lpwhr->dwContentLength))
1729 retval = HTTP_FinishedReading(lpwhr);
1730 else
1731 retval = TRUE;
1733 break;
1735 case WH_HFILE:
1736 /* FIXME: FTP should use NETCON_ stuff */
1737 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1738 if (nSocket != -1)
1740 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1741 retval = (res >= 0);
1742 *pdwNumOfBytesRead = retval ? res : 0;
1744 break;
1746 default:
1747 break;
1750 if (bSendCompletionStatus)
1752 INTERNET_ASYNC_RESULT iar;
1754 iar.dwResult = retval;
1755 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1756 INTERNET_GetLastError();
1758 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1759 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1760 sizeof(INTERNET_ASYNC_RESULT));
1762 return retval;
1765 /***********************************************************************
1766 * InternetReadFile (WININET.@)
1768 * Read data from an open internet file
1770 * RETURNS
1771 * TRUE on success
1772 * FALSE on failure
1775 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1776 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1778 LPWININETHANDLEHEADER lpwh;
1779 BOOL retval;
1781 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1783 lpwh = WININET_GetObject( hFile );
1784 if (!lpwh)
1786 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1787 return FALSE;
1790 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1791 WININET_Release( lpwh );
1793 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1794 return retval;
1797 /***********************************************************************
1798 * InternetReadFileExA (WININET.@)
1800 * Read data from an open internet file
1802 * PARAMS
1803 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1804 * lpBuffersOut [I/O] Buffer.
1805 * dwFlags [I] Flags. See notes.
1806 * dwContext [I] Context for callbacks.
1808 * RETURNS
1809 * TRUE on success
1810 * FALSE on failure
1812 * NOTES
1813 * The parameter dwFlags include zero or more of the following flags:
1814 *|IRF_ASYNC - Makes the call asynchronous.
1815 *|IRF_SYNC - Makes the call synchronous.
1816 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1817 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1819 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1821 * SEE
1822 * InternetOpenUrlA(), HttpOpenRequestA()
1824 void AsyncInternetReadFileExProc(WORKREQUEST *workRequest)
1826 struct WORKREQ_INTERNETREADFILEEXA const *req = &workRequest->u.InternetReadFileExA;
1828 TRACE("INTERNETREADFILEEXA %p\n", workRequest->hdr);
1830 INTERNET_ReadFile(workRequest->hdr, req->lpBuffersOut->lpvBuffer,
1831 req->lpBuffersOut->dwBufferLength,
1832 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
1835 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1836 DWORD dwFlags, DWORD dwContext)
1838 BOOL retval = FALSE;
1839 LPWININETHANDLEHEADER lpwh;
1841 TRACE("(%p %p 0x%x 0x%x)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1843 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1844 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1846 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1848 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1849 return FALSE;
1852 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1853 if (!lpwh)
1855 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1856 return FALSE;
1859 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1860 INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
1862 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1863 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1864 if (dwFlags & IRF_ASYNC)
1866 DWORD dwDataAvailable = 0;
1868 if (lpwh->htype == WH_HHTTPREQ)
1869 NETCON_query_data_available(&((LPWININETHTTPREQW)lpwh)->netConnection,
1870 &dwDataAvailable);
1872 if (!dwDataAvailable)
1874 WORKREQUEST workRequest;
1875 struct WORKREQ_INTERNETREADFILEEXA *req;
1877 workRequest.asyncproc = AsyncInternetReadFileExProc;
1878 workRequest.hdr = WININET_AddRef( lpwh );
1879 req = &workRequest.u.InternetReadFileExA;
1880 req->lpBuffersOut = lpBuffersOut;
1882 retval = INTERNET_AsyncCall(&workRequest);
1883 if (!retval) return FALSE;
1885 INTERNET_SetLastError(ERROR_IO_PENDING);
1886 return FALSE;
1890 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1891 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1892 !(dwFlags & IRF_NO_WAIT), FALSE);
1894 if (retval)
1896 DWORD dwBytesReceived = lpBuffersOut->dwBufferLength;
1897 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1898 INTERNET_STATUS_RESPONSE_RECEIVED, &dwBytesReceived,
1899 sizeof(dwBytesReceived));
1902 WININET_Release( lpwh );
1904 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1905 return retval;
1908 /***********************************************************************
1909 * InternetReadFileExW (WININET.@)
1911 * Read data from an open internet file.
1913 * PARAMS
1914 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1915 * lpBuffersOut [I/O] Buffer.
1916 * dwFlags [I] Flags.
1917 * dwContext [I] Context for callbacks.
1919 * RETURNS
1920 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1922 * NOTES
1923 * Not implemented in Wine or native either (as of IE6 SP2).
1926 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1927 DWORD dwFlags, DWORD dwContext)
1929 ERR("(%p, %p, 0x%x, 0x%x): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1931 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1932 return FALSE;
1935 /***********************************************************************
1936 * INET_QueryOptionHelper (internal)
1938 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1939 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1941 LPWININETHANDLEHEADER lpwhh;
1942 BOOL bSuccess = FALSE;
1944 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1946 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1948 switch (dwOption)
1950 case INTERNET_OPTION_HANDLE_TYPE:
1952 ULONG type;
1954 if (!lpwhh)
1956 WARN("Invalid hInternet handle\n");
1957 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1958 return FALSE;
1961 type = lpwhh->htype;
1963 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type);
1965 if (*lpdwBufferLength < sizeof(ULONG))
1966 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1967 else
1969 memcpy(lpBuffer, &type, sizeof(ULONG));
1970 bSuccess = TRUE;
1972 *lpdwBufferLength = sizeof(ULONG);
1973 break;
1976 case INTERNET_OPTION_REQUEST_FLAGS:
1978 ULONG flags = 4;
1979 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
1980 if (*lpdwBufferLength < sizeof(ULONG))
1981 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1982 else
1984 memcpy(lpBuffer, &flags, sizeof(ULONG));
1985 bSuccess = TRUE;
1987 *lpdwBufferLength = sizeof(ULONG);
1988 break;
1991 case INTERNET_OPTION_URL:
1992 case INTERNET_OPTION_DATAFILE_NAME:
1994 if (!lpwhh)
1996 WARN("Invalid hInternet handle\n");
1997 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1998 return FALSE;
2000 if (lpwhh->htype == WH_HHTTPREQ)
2002 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2003 WCHAR url[1023];
2004 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2005 static const WCHAR szHost[] = {'H','o','s','t',0};
2006 DWORD sizeRequired;
2007 LPHTTPHEADERW Host;
2009 Host = HTTP_GetHeader(lpreq,szHost);
2010 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2011 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2012 if(!bIsUnicode)
2014 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2015 lpBuffer,*lpdwBufferLength,NULL,NULL);
2016 if (sizeRequired > *lpdwBufferLength)
2017 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2018 else
2019 bSuccess = TRUE;
2020 *lpdwBufferLength = sizeRequired;
2022 else
2024 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2025 if (*lpdwBufferLength < sizeRequired)
2026 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2027 else
2029 strcpyW(lpBuffer, url);
2030 bSuccess = TRUE;
2032 *lpdwBufferLength = sizeRequired;
2035 break;
2037 case INTERNET_OPTION_HTTP_VERSION:
2039 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2040 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2041 else
2044 * Presently hardcoded to 1.1
2046 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2047 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2048 bSuccess = TRUE;
2050 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2051 break;
2053 case INTERNET_OPTION_CONNECTED_STATE:
2055 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2056 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2058 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2059 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2060 else
2062 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2063 bSuccess = TRUE;
2065 *lpdwBufferLength = sizeof(*pdwConnectedState);
2066 break;
2068 case INTERNET_OPTION_PROXY:
2070 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2071 WININETAPPINFOW wai;
2073 if (lpwai == NULL)
2075 TRACE("Getting global proxy info\n");
2076 memset(&wai, 0, sizeof(WININETAPPINFOW));
2077 INTERNET_ConfigureProxyFromReg( &wai );
2078 lpwai = &wai;
2081 if (bIsUnicode)
2083 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2084 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2086 if (lpwai->lpszProxy)
2087 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2088 sizeof(WCHAR);
2089 if (lpwai->lpszProxyBypass)
2090 proxyBypassBytesRequired =
2091 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2092 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2093 proxyBytesRequired + proxyBypassBytesRequired)
2094 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2095 else
2097 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
2098 sizeof(INTERNET_PROXY_INFOW));
2099 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
2100 sizeof(INTERNET_PROXY_INFOW) +
2101 proxyBytesRequired);
2103 pPI->dwAccessType = lpwai->dwAccessType;
2104 pPI->lpszProxy = NULL;
2105 pPI->lpszProxyBypass = NULL;
2106 if (lpwai->lpszProxy)
2108 lstrcpyW(proxy, lpwai->lpszProxy);
2109 pPI->lpszProxy = proxy;
2112 if (lpwai->lpszProxyBypass)
2114 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
2115 pPI->lpszProxyBypass = proxy_bypass;
2117 bSuccess = TRUE;
2119 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2120 proxyBytesRequired + proxyBypassBytesRequired;
2122 else
2124 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2125 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2127 if (lpwai->lpszProxy)
2128 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2129 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2130 if (lpwai->lpszProxyBypass)
2131 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2132 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2133 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2134 proxyBytesRequired + proxyBypassBytesRequired)
2135 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2136 else
2138 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2139 sizeof(INTERNET_PROXY_INFOA));
2140 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2141 sizeof(INTERNET_PROXY_INFOA) +
2142 proxyBytesRequired);
2144 pPI->dwAccessType = lpwai->dwAccessType;
2145 pPI->lpszProxy = NULL;
2146 pPI->lpszProxyBypass = NULL;
2147 if (lpwai->lpszProxy)
2149 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2150 proxy, proxyBytesRequired, NULL, NULL);
2151 pPI->lpszProxy = proxy;
2154 if (lpwai->lpszProxyBypass)
2156 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2157 -1, proxy_bypass, proxyBypassBytesRequired,
2158 NULL, NULL);
2159 pPI->lpszProxyBypass = proxy_bypass;
2161 bSuccess = TRUE;
2163 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2164 proxyBytesRequired + proxyBypassBytesRequired;
2166 break;
2168 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2170 ULONG conn = 2;
2171 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2172 if (*lpdwBufferLength < sizeof(ULONG))
2173 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2174 else
2176 memcpy(lpBuffer, &conn, sizeof(ULONG));
2177 bSuccess = TRUE;
2179 *lpdwBufferLength = sizeof(ULONG);
2180 break;
2182 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2184 ULONG conn = 4;
2185 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2186 if (*lpdwBufferLength < sizeof(ULONG))
2187 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2188 else
2190 memcpy(lpBuffer, &conn, sizeof(ULONG));
2191 bSuccess = TRUE;
2193 *lpdwBufferLength = sizeof(ULONG);
2194 break;
2196 case INTERNET_OPTION_SECURITY_FLAGS:
2197 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2198 break;
2200 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2201 if (!lpwhh)
2203 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2204 return FALSE;
2206 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2208 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2209 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2211 else if (lpwhh->htype == WH_HHTTPREQ)
2213 LPWININETHTTPREQW lpwhr;
2214 PCCERT_CONTEXT context;
2216 lpwhr = (LPWININETHTTPREQW)lpwhh;
2217 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2218 if (context)
2220 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2221 DWORD strLen;
2223 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2224 info->ftExpiry = context->pCertInfo->NotAfter;
2225 info->ftStart = context->pCertInfo->NotBefore;
2226 if (bIsUnicode)
2228 strLen = CertNameToStrW(context->dwCertEncodingType,
2229 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2230 NULL, 0);
2231 info->lpszSubjectInfo = LocalAlloc(0,
2232 strLen * sizeof(WCHAR));
2233 if (info->lpszSubjectInfo)
2234 CertNameToStrW(context->dwCertEncodingType,
2235 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2236 info->lpszSubjectInfo, strLen);
2237 strLen = CertNameToStrW(context->dwCertEncodingType,
2238 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2239 NULL, 0);
2240 info->lpszIssuerInfo = LocalAlloc(0,
2241 strLen * sizeof(WCHAR));
2242 if (info->lpszIssuerInfo)
2243 CertNameToStrW(context->dwCertEncodingType,
2244 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2245 info->lpszIssuerInfo, strLen);
2247 else
2249 LPINTERNET_CERTIFICATE_INFOA infoA =
2250 (LPINTERNET_CERTIFICATE_INFOA)info;
2252 strLen = CertNameToStrA(context->dwCertEncodingType,
2253 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2254 NULL, 0);
2255 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2256 if (infoA->lpszSubjectInfo)
2257 CertNameToStrA(context->dwCertEncodingType,
2258 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2259 infoA->lpszSubjectInfo, strLen);
2260 strLen = CertNameToStrA(context->dwCertEncodingType,
2261 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2262 NULL, 0);
2263 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2264 if (infoA->lpszIssuerInfo)
2265 CertNameToStrA(context->dwCertEncodingType,
2266 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2267 infoA->lpszIssuerInfo, strLen);
2270 * Contrary to MSDN, these do not appear to be set.
2271 * lpszProtocolName
2272 * lpszSignatureAlgName
2273 * lpszEncryptionAlgName
2274 * dwKeySize
2276 CertFreeCertificateContext(context);
2277 bSuccess = TRUE;
2280 break;
2281 default:
2282 FIXME("Stub! %d\n", dwOption);
2283 break;
2285 if (lpwhh)
2286 WININET_Release( lpwhh );
2288 return bSuccess;
2291 /***********************************************************************
2292 * InternetQueryOptionW (WININET.@)
2294 * Queries an options on the specified handle
2296 * RETURNS
2297 * TRUE on success
2298 * FALSE on failure
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
2312 * RETURNS
2313 * TRUE on success
2314 * FALSE on failure
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
2329 * RETURNS
2330 * TRUE on success
2331 * FALSE on failure
2334 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2335 LPVOID lpBuffer, DWORD dwBufferLength)
2337 LPWININETHANDLEHEADER lpwhh;
2338 BOOL ret = TRUE;
2340 TRACE("0x%08x\n", dwOption);
2342 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2343 if( !lpwhh )
2344 return FALSE;
2346 switch (dwOption)
2348 case INTERNET_OPTION_HTTP_VERSION:
2350 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2351 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2353 break;
2354 case INTERNET_OPTION_ERROR_MASK:
2356 unsigned long flags=*(unsigned long*)lpBuffer;
2357 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2359 break;
2360 case INTERNET_OPTION_CODEPAGE:
2362 unsigned long codepage=*(unsigned long*)lpBuffer;
2363 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2365 break;
2366 case INTERNET_OPTION_REQUEST_PRIORITY:
2368 unsigned long priority=*(unsigned long*)lpBuffer;
2369 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2371 break;
2372 case INTERNET_OPTION_CONNECT_TIMEOUT:
2374 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2375 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2377 break;
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);
2383 break;
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);
2389 break;
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);
2395 break;
2396 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2397 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2398 break;
2399 case INTERNET_OPTION_END_BROWSER_SESSION:
2400 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2401 break;
2402 case INTERNET_OPTION_CONNECTED_STATE:
2403 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2404 break;
2405 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2406 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2407 break;
2408 case INTERNET_OPTION_SEND_TIMEOUT:
2409 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2410 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2411 if (dwBufferLength == sizeof(DWORD))
2413 if (lpwhh->htype == WH_HHTTPREQ)
2414 ret = NETCON_set_timeout(
2415 &((LPWININETHTTPREQW)lpwhh)->netConnection,
2416 dwOption == INTERNET_OPTION_SEND_TIMEOUT,
2417 *(DWORD *)lpBuffer);
2418 else
2420 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2421 lpwhh->htype);
2424 else
2426 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2427 ret = FALSE;
2429 break;
2430 case INTERNET_OPTION_CONNECT_RETRIES:
2431 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2432 break;
2433 case INTERNET_OPTION_CONTEXT_VALUE:
2434 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2435 break;
2436 case INTERNET_OPTION_SECURITY_FLAGS:
2437 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2438 break;
2439 default:
2440 FIXME("Option %d STUB\n",dwOption);
2441 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2442 ret = FALSE;
2443 break;
2445 WININET_Release( lpwhh );
2447 return ret;
2451 /***********************************************************************
2452 * InternetSetOptionA (WININET.@)
2454 * Sets an options on the specified handle.
2456 * RETURNS
2457 * TRUE on success
2458 * FALSE on failure
2461 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2462 LPVOID lpBuffer, DWORD dwBufferLength)
2464 LPVOID wbuffer;
2465 DWORD wlen;
2466 BOOL r;
2468 switch( dwOption )
2470 case INTERNET_OPTION_PROXY:
2472 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2473 LPINTERNET_PROXY_INFOW piw;
2474 DWORD proxlen, prbylen;
2475 LPWSTR prox, prby;
2477 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2478 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2479 wlen = sizeof(*piw) + proxlen + prbylen;
2480 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2481 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2482 piw->dwAccessType = pi->dwAccessType;
2483 prox = (LPWSTR) &piw[1];
2484 prby = &prox[proxlen+1];
2485 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2486 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2487 piw->lpszProxy = prox;
2488 piw->lpszProxyBypass = prby;
2490 break;
2491 case INTERNET_OPTION_USER_AGENT:
2492 case INTERNET_OPTION_USERNAME:
2493 case INTERNET_OPTION_PASSWORD:
2494 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2495 NULL, 0 );
2496 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2497 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2498 wbuffer, wlen );
2499 break;
2500 default:
2501 wbuffer = lpBuffer;
2502 wlen = dwBufferLength;
2505 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2507 if( lpBuffer != wbuffer )
2508 HeapFree( GetProcessHeap(), 0, wbuffer );
2510 return r;
2514 /***********************************************************************
2515 * InternetSetOptionExA (WININET.@)
2517 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2518 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2520 FIXME("Flags %08x ignored\n", dwFlags);
2521 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2524 /***********************************************************************
2525 * InternetSetOptionExW (WININET.@)
2527 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2528 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2530 FIXME("Flags %08x ignored\n", dwFlags);
2531 if( dwFlags & ~ISO_VALID_FLAGS )
2533 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2534 return FALSE;
2536 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2539 static const WCHAR WININET_wkday[7][4] =
2540 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2541 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2542 static const WCHAR WININET_month[12][4] =
2543 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2544 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2545 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2547 /***********************************************************************
2548 * InternetTimeFromSystemTimeA (WININET.@)
2550 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2552 BOOL ret;
2553 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2555 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2557 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2558 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2560 return ret;
2563 /***********************************************************************
2564 * InternetTimeFromSystemTimeW (WININET.@)
2566 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2568 static const WCHAR date[] =
2569 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2570 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2572 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2574 if (!time || !string) return FALSE;
2576 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2577 return FALSE;
2579 sprintfW( string, date,
2580 WININET_wkday[time->wDayOfWeek],
2581 time->wDay,
2582 WININET_month[time->wMonth - 1],
2583 time->wYear,
2584 time->wHour,
2585 time->wMinute,
2586 time->wSecond );
2588 return TRUE;
2591 /***********************************************************************
2592 * InternetTimeToSystemTimeA (WININET.@)
2594 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2596 BOOL ret = FALSE;
2597 WCHAR *stringW;
2598 int len;
2600 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2602 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2603 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2605 if (stringW)
2607 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2608 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2609 HeapFree( GetProcessHeap(), 0, stringW );
2611 return ret;
2614 /***********************************************************************
2615 * InternetTimeToSystemTimeW (WININET.@)
2617 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2619 unsigned int i;
2620 const WCHAR *s = string;
2621 WCHAR *end;
2623 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2625 if (!string || !time) return FALSE;
2627 /* Windows does this too */
2628 GetSystemTime( time );
2630 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2631 * a SYSTEMTIME structure.
2634 while (*s && !isalphaW( *s )) s++;
2635 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2636 time->wDayOfWeek = 7;
2638 for (i = 0; i < 7; i++)
2640 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2641 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2642 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2644 time->wDayOfWeek = i;
2645 break;
2649 if (time->wDayOfWeek > 6) return TRUE;
2650 while (*s && !isdigitW( *s )) s++;
2651 time->wDay = strtolW( s, &end, 10 );
2652 s = end;
2654 while (*s && !isalphaW( *s )) s++;
2655 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2656 time->wMonth = 0;
2658 for (i = 0; i < 12; i++)
2660 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2661 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2662 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2664 time->wMonth = i + 1;
2665 break;
2668 if (time->wMonth == 0) return TRUE;
2670 while (*s && !isdigitW( *s )) s++;
2671 if (*s == '\0') return TRUE;
2672 time->wYear = strtolW( s, &end, 10 );
2673 s = end;
2675 while (*s && !isdigitW( *s )) s++;
2676 if (*s == '\0') return TRUE;
2677 time->wHour = strtolW( s, &end, 10 );
2678 s = end;
2680 while (*s && !isdigitW( *s )) s++;
2681 if (*s == '\0') return TRUE;
2682 time->wMinute = strtolW( s, &end, 10 );
2683 s = end;
2685 while (*s && !isdigitW( *s )) s++;
2686 if (*s == '\0') return TRUE;
2687 time->wSecond = strtolW( s, &end, 10 );
2688 s = end;
2690 time->wMilliseconds = 0;
2691 return TRUE;
2694 /***********************************************************************
2695 * InternetCheckConnectionW (WININET.@)
2697 * Pings a requested host to check internet connection
2699 * RETURNS
2700 * TRUE on success and FALSE on failure. If a failure then
2701 * ERROR_NOT_CONNECTED is placed into GetLastError
2704 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2707 * this is a kludge which runs the resident ping program and reads the output.
2709 * Anyone have a better idea?
2712 BOOL rc = FALSE;
2713 static const CHAR ping[] = "ping -c 1 ";
2714 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2715 CHAR *command = NULL;
2716 WCHAR hostW[1024];
2717 DWORD len;
2718 int status = -1;
2720 FIXME("\n");
2723 * Crack or set the Address
2725 if (lpszUrl == NULL)
2728 * According to the doc we are supost to use the ip for the next
2729 * server in the WnInet internal server database. I have
2730 * no idea what that is or how to get it.
2732 * So someone needs to implement this.
2734 FIXME("Unimplemented with URL of NULL\n");
2735 return TRUE;
2737 else
2739 URL_COMPONENTSW components;
2741 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2742 components.lpszHostName = (LPWSTR)&hostW;
2743 components.dwHostNameLength = 1024;
2745 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2746 goto End;
2748 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2752 * Build our ping command
2754 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2755 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2756 strcpy(command,ping);
2757 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2758 strcat(command,redirect);
2760 TRACE("Ping command is : %s\n",command);
2762 status = system(command);
2764 TRACE("Ping returned a code of %i\n",status);
2766 /* Ping return code of 0 indicates success */
2767 if (status == 0)
2768 rc = TRUE;
2770 End:
2772 HeapFree( GetProcessHeap(), 0, command );
2773 if (rc == FALSE)
2774 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2776 return rc;
2780 /***********************************************************************
2781 * InternetCheckConnectionA (WININET.@)
2783 * Pings a requested host to check internet connection
2785 * RETURNS
2786 * TRUE on success and FALSE on failure. If a failure then
2787 * ERROR_NOT_CONNECTED is placed into GetLastError
2790 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2792 WCHAR *szUrl;
2793 INT len;
2794 BOOL rc;
2796 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2797 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2798 return FALSE;
2799 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2800 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2801 HeapFree(GetProcessHeap(), 0, szUrl);
2803 return rc;
2807 /**********************************************************
2808 * INTERNET_InternetOpenUrlW (internal)
2810 * Opens an URL
2812 * RETURNS
2813 * handle of connection or NULL on failure
2815 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2816 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2818 URL_COMPONENTSW urlComponents;
2819 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2820 WCHAR password[1024], path[2048], extra[1024];
2821 HINTERNET client = NULL, client1 = NULL;
2823 TRACE("(%p, %s, %s, %08x, %08x, %08x)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2824 dwHeadersLength, dwFlags, dwContext);
2826 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2827 urlComponents.lpszScheme = protocol;
2828 urlComponents.dwSchemeLength = 32;
2829 urlComponents.lpszHostName = hostName;
2830 urlComponents.dwHostNameLength = MAXHOSTNAME;
2831 urlComponents.lpszUserName = userName;
2832 urlComponents.dwUserNameLength = 1024;
2833 urlComponents.lpszPassword = password;
2834 urlComponents.dwPasswordLength = 1024;
2835 urlComponents.lpszUrlPath = path;
2836 urlComponents.dwUrlPathLength = 2048;
2837 urlComponents.lpszExtraInfo = extra;
2838 urlComponents.dwExtraInfoLength = 1024;
2839 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2840 return NULL;
2841 switch(urlComponents.nScheme) {
2842 case INTERNET_SCHEME_FTP:
2843 if(urlComponents.nPort == 0)
2844 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2845 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2846 userName, password, dwFlags, dwContext, INET_OPENURL);
2847 if(client == NULL)
2848 break;
2849 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2850 if(client1 == NULL) {
2851 InternetCloseHandle(client);
2852 break;
2854 break;
2856 case INTERNET_SCHEME_HTTP:
2857 case INTERNET_SCHEME_HTTPS: {
2858 static const WCHAR szStars[] = { '*','/','*', 0 };
2859 LPCWSTR accept[2] = { szStars, NULL };
2860 if(urlComponents.nPort == 0) {
2861 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2862 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2863 else
2864 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2866 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2867 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2868 userName, password, dwFlags, dwContext, INET_OPENURL);
2869 if(client == NULL)
2870 break;
2872 if (urlComponents.dwExtraInfoLength) {
2873 WCHAR *path_extra;
2874 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
2876 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
2878 InternetCloseHandle(client);
2879 break;
2881 strcpyW(path_extra, urlComponents.lpszUrlPath);
2882 strcatW(path_extra, urlComponents.lpszExtraInfo);
2883 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
2884 HeapFree(GetProcessHeap(), 0, path_extra);
2886 else
2887 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2889 if(client1 == NULL) {
2890 InternetCloseHandle(client);
2891 break;
2893 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2894 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2895 GetLastError() != ERROR_IO_PENDING) {
2896 InternetCloseHandle(client1);
2897 client1 = NULL;
2898 break;
2901 case INTERNET_SCHEME_GOPHER:
2902 /* gopher doesn't seem to be implemented in wine, but it's supposed
2903 * to be supported by InternetOpenUrlA. */
2904 default:
2905 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2906 break;
2909 TRACE(" %p <--\n", client1);
2911 return client1;
2914 /**********************************************************
2915 * InternetOpenUrlW (WININET.@)
2917 * Opens an URL
2919 * RETURNS
2920 * handle of connection or NULL on failure
2922 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
2924 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
2925 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
2927 TRACE("%p\n", hIC);
2929 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
2930 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2931 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2932 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2935 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2936 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2938 HINTERNET ret = NULL;
2939 LPWININETAPPINFOW hIC = NULL;
2941 if (TRACE_ON(wininet)) {
2942 TRACE("(%p, %s, %s, %08x, %08x, %08x)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2943 dwHeadersLength, dwFlags, dwContext);
2944 TRACE(" flags :");
2945 dump_INTERNET_FLAGS(dwFlags);
2948 if (!lpszUrl)
2950 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2951 goto lend;
2954 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2955 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2956 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2957 goto lend;
2960 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2961 WORKREQUEST workRequest;
2962 struct WORKREQ_INTERNETOPENURLW *req;
2964 workRequest.asyncproc = AsyncInternetOpenUrlProc;
2965 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2966 req = &workRequest.u.InternetOpenUrlW;
2967 req->lpszUrl = WININET_strdupW(lpszUrl);
2968 if (lpszHeaders)
2969 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2970 else
2971 req->lpszHeaders = 0;
2972 req->dwHeadersLength = dwHeadersLength;
2973 req->dwFlags = dwFlags;
2974 req->dwContext = dwContext;
2976 INTERNET_AsyncCall(&workRequest);
2978 * This is from windows.
2980 INTERNET_SetLastError(ERROR_IO_PENDING);
2981 } else {
2982 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2985 lend:
2986 if( hIC )
2987 WININET_Release( &hIC->hdr );
2988 TRACE(" %p <--\n", ret);
2990 return ret;
2993 /**********************************************************
2994 * InternetOpenUrlA (WININET.@)
2996 * Opens an URL
2998 * RETURNS
2999 * handle of connection or NULL on failure
3001 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3002 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
3004 HINTERNET rc = (HINTERNET)NULL;
3006 INT lenUrl;
3007 INT lenHeaders = 0;
3008 LPWSTR szUrl = NULL;
3009 LPWSTR szHeaders = NULL;
3011 TRACE("\n");
3013 if(lpszUrl) {
3014 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3015 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3016 if(!szUrl)
3017 return (HINTERNET)NULL;
3018 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3021 if(lpszHeaders) {
3022 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3023 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3024 if(!szHeaders) {
3025 HeapFree(GetProcessHeap(), 0, szUrl);
3026 return (HINTERNET)NULL;
3028 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3031 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3032 lenHeaders, dwFlags, dwContext);
3034 HeapFree(GetProcessHeap(), 0, szUrl);
3035 HeapFree(GetProcessHeap(), 0, szHeaders);
3037 return rc;
3041 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3043 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3045 if (lpwite)
3047 lpwite->dwError = 0;
3048 lpwite->response[0] = '\0';
3051 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3053 HeapFree(GetProcessHeap(), 0, lpwite);
3054 return NULL;
3057 return lpwite;
3061 /***********************************************************************
3062 * INTERNET_SetLastError (internal)
3064 * Set last thread specific error
3066 * RETURNS
3069 void INTERNET_SetLastError(DWORD dwError)
3071 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3073 if (!lpwite)
3074 lpwite = INTERNET_AllocThreadError();
3076 SetLastError(dwError);
3077 if(lpwite)
3078 lpwite->dwError = dwError;
3082 /***********************************************************************
3083 * INTERNET_GetLastError (internal)
3085 * Get last thread specific error
3087 * RETURNS
3090 DWORD INTERNET_GetLastError(void)
3092 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3093 if (!lpwite) return 0;
3094 /* TlsGetValue clears last error, so set it again here */
3095 SetLastError(lpwite->dwError);
3096 return lpwite->dwError;
3100 /***********************************************************************
3101 * INTERNET_WorkerThreadFunc (internal)
3103 * Worker thread execution function
3105 * RETURNS
3108 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3110 LPWORKREQUEST lpRequest = lpvParam;
3111 WORKREQUEST workRequest;
3113 TRACE("\n");
3115 memcpy(&workRequest, lpRequest, sizeof(WORKREQUEST));
3116 HeapFree(GetProcessHeap(), 0, lpRequest);
3118 workRequest.asyncproc(&workRequest);
3120 WININET_Release( workRequest.hdr );
3121 return TRUE;
3125 /***********************************************************************
3126 * INTERNET_AsyncCall (internal)
3128 * Retrieves work request from queue
3130 * RETURNS
3133 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3135 BOOL bSuccess;
3136 LPWORKREQUEST lpNewRequest;
3138 TRACE("\n");
3140 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3141 if (!lpNewRequest)
3142 return FALSE;
3144 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3146 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3147 if (!bSuccess)
3149 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3150 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3153 return bSuccess;
3157 /***********************************************************************
3158 * INTERNET_GetResponseBuffer (internal)
3160 * RETURNS
3163 LPSTR INTERNET_GetResponseBuffer(void)
3165 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3166 if (!lpwite)
3167 lpwite = INTERNET_AllocThreadError();
3168 TRACE("\n");
3169 return lpwite->response;
3172 /***********************************************************************
3173 * INTERNET_GetNextLine (internal)
3175 * Parse next line in directory string listing
3177 * RETURNS
3178 * Pointer to beginning of next line
3179 * NULL on failure
3183 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3185 struct timeval tv;
3186 fd_set infd;
3187 BOOL bSuccess = FALSE;
3188 INT nRecv = 0;
3189 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3191 TRACE("\n");
3193 FD_ZERO(&infd);
3194 FD_SET(nSocket, &infd);
3195 tv.tv_sec=RESPONSE_TIMEOUT;
3196 tv.tv_usec=0;
3198 while (nRecv < MAX_REPLY_LEN)
3200 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3202 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3204 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3205 goto lend;
3208 if (lpszBuffer[nRecv] == '\n')
3210 bSuccess = TRUE;
3211 break;
3213 if (lpszBuffer[nRecv] != '\r')
3214 nRecv++;
3216 else
3218 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3219 goto lend;
3223 lend:
3224 if (bSuccess)
3226 lpszBuffer[nRecv] = '\0';
3227 *dwLen = nRecv - 1;
3228 TRACE(":%d %s\n", nRecv, lpszBuffer);
3229 return lpszBuffer;
3231 else
3233 return NULL;
3237 /**********************************************************
3238 * InternetQueryDataAvailable (WININET.@)
3240 * Determines how much data is available to be read.
3242 * RETURNS
3243 * TRUE on success, FALSE if an error occurred. If
3244 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3245 * no data is presently available, FALSE is returned with
3246 * the last error ERROR_IO_PENDING; a callback with status
3247 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3248 * data is available.
3250 void AsyncInternetQueryDataAvailableProc(WORKREQUEST *workRequest)
3252 LPWININETHTTPREQW lpwhr;
3253 INTERNET_ASYNC_RESULT iar;
3254 char buffer[4048];
3256 TRACE("INTERNETQUERYDATAAVAILABLE %p\n", workRequest->hdr);
3258 switch (workRequest->hdr->htype)
3260 case WH_HHTTPREQ:
3261 lpwhr = (LPWININETHTTPREQW)workRequest->hdr;
3262 iar.dwResult = NETCON_recv(&lpwhr->netConnection, buffer,
3263 min(sizeof(buffer),
3264 lpwhr->dwContentLength - lpwhr->dwContentRead),
3265 MSG_PEEK, (int *)&iar.dwError);
3266 INTERNET_SendCallback(workRequest->hdr, workRequest->hdr->dwContext,
3267 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
3268 sizeof(INTERNET_ASYNC_RESULT));
3269 break;
3271 default:
3272 FIXME("unsupported file type\n");
3273 break;
3277 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3278 LPDWORD lpdwNumberOfBytesAvailble,
3279 DWORD dwFlags, DWORD dwConext)
3281 LPWININETHTTPREQW lpwhr;
3282 BOOL retval = FALSE;
3283 char buffer[4048];
3285 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3286 if (NULL == lpwhr)
3288 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
3289 return FALSE;
3292 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3294 switch (lpwhr->hdr.htype)
3296 case WH_HHTTPREQ:
3297 if (NETCON_query_data_available(&lpwhr->netConnection,
3298 lpdwNumberOfBytesAvailble))
3300 retval = TRUE;
3301 if (!*lpdwNumberOfBytesAvailble)
3303 /* Even if we are in async mode, we need to determine whether
3304 * there is actually more data available. We do this by trying
3305 * to peek only a single byte in async mode. */
3306 BOOL async = (lpwhr->lpHttpSession->lpAppInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC);
3307 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3308 async ? 1 : min(sizeof(buffer),
3309 lpwhr->dwContentLength - lpwhr->dwContentRead),
3310 MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3312 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
3313 retval = FALSE;
3315 else if (async && *lpdwNumberOfBytesAvailble)
3317 WORKREQUEST workRequest;
3319 *lpdwNumberOfBytesAvailble = 0;
3320 workRequest.asyncproc = AsyncInternetQueryDataAvailableProc;
3321 workRequest.hdr = WININET_AddRef( &lpwhr->hdr );
3323 retval = INTERNET_AsyncCall(&workRequest);
3324 if (!retval)
3326 WININET_Release( &lpwhr->hdr );
3328 else
3330 INTERNET_SetLastError(ERROR_IO_PENDING);
3331 retval = FALSE;
3336 else
3338 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
3340 break;
3342 default:
3343 FIXME("unsupported file type\n");
3344 break;
3346 WININET_Release( &lpwhr->hdr );
3348 TRACE("<-- %i\n",retval);
3349 return retval;
3353 /***********************************************************************
3354 * InternetLockRequestFile (WININET.@)
3356 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3357 *lphLockReqHandle)
3359 FIXME("STUB\n");
3360 return FALSE;
3363 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3365 FIXME("STUB\n");
3366 return FALSE;
3370 /***********************************************************************
3371 * InternetAutodial (WININET.@)
3373 * On windows this function is supposed to dial the default internet
3374 * connection. We don't want to have Wine dial out to the internet so
3375 * we return TRUE by default. It might be nice to check if we are connected.
3377 * RETURNS
3378 * TRUE on success
3379 * FALSE on failure
3382 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3384 FIXME("STUB\n");
3386 /* Tell that we are connected to the internet. */
3387 return TRUE;
3390 /***********************************************************************
3391 * InternetAutodialHangup (WININET.@)
3393 * Hangs up a connection made with InternetAutodial
3395 * PARAM
3396 * dwReserved
3397 * RETURNS
3398 * TRUE on success
3399 * FALSE on failure
3402 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3404 FIXME("STUB\n");
3406 /* we didn't dial, we don't disconnect */
3407 return TRUE;
3410 /***********************************************************************
3411 * InternetCombineUrlA (WININET.@)
3413 * Combine a base URL with a relative URL
3415 * RETURNS
3416 * TRUE on success
3417 * FALSE on failure
3421 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3422 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3423 DWORD dwFlags)
3425 HRESULT hr=S_OK;
3427 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3429 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3430 dwFlags ^= ICU_NO_ENCODE;
3431 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3433 return (hr==S_OK);
3436 /***********************************************************************
3437 * InternetCombineUrlW (WININET.@)
3439 * Combine a base URL with a relative URL
3441 * RETURNS
3442 * TRUE on success
3443 * FALSE on failure
3447 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3448 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3449 DWORD dwFlags)
3451 HRESULT hr=S_OK;
3453 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3455 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3456 dwFlags ^= ICU_NO_ENCODE;
3457 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3459 return (hr==S_OK);
3462 /* max port num is 65535 => 5 digits */
3463 #define MAX_WORD_DIGITS 5
3465 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3466 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3467 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3468 (url)->dw##component##Length : strlen((url)->lpsz##component))
3470 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3472 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3473 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3474 return TRUE;
3475 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3476 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3477 return TRUE;
3478 if ((nScheme == INTERNET_SCHEME_FTP) &&
3479 (nPort == INTERNET_DEFAULT_FTP_PORT))
3480 return TRUE;
3481 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3482 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3483 return TRUE;
3485 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3486 return TRUE;
3488 return FALSE;
3491 /* opaque urls do not fit into the standard url hierarchy and don't have
3492 * two following slashes */
3493 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3495 return (nScheme != INTERNET_SCHEME_FTP) &&
3496 (nScheme != INTERNET_SCHEME_GOPHER) &&
3497 (nScheme != INTERNET_SCHEME_HTTP) &&
3498 (nScheme != INTERNET_SCHEME_HTTPS) &&
3499 (nScheme != INTERNET_SCHEME_FILE);
3502 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3504 int index;
3505 if (scheme < INTERNET_SCHEME_FIRST)
3506 return NULL;
3507 index = scheme - INTERNET_SCHEME_FIRST;
3508 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3509 return NULL;
3510 return (LPCWSTR)&url_schemes[index];
3513 /* we can calculate using ansi strings because we're just
3514 * calculating string length, not size
3516 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3517 LPDWORD lpdwUrlLength)
3519 INTERNET_SCHEME nScheme;
3521 *lpdwUrlLength = 0;
3523 if (lpUrlComponents->lpszScheme)
3525 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3526 *lpdwUrlLength += dwLen;
3527 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3529 else
3531 LPCWSTR scheme;
3533 nScheme = lpUrlComponents->nScheme;
3535 if (nScheme == INTERNET_SCHEME_DEFAULT)
3536 nScheme = INTERNET_SCHEME_HTTP;
3537 scheme = INTERNET_GetSchemeString(nScheme);
3538 *lpdwUrlLength += strlenW(scheme);
3541 (*lpdwUrlLength)++; /* ':' */
3542 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3543 *lpdwUrlLength += strlen("//");
3545 if (lpUrlComponents->lpszUserName)
3547 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3548 *lpdwUrlLength += strlen("@");
3550 else
3552 if (lpUrlComponents->lpszPassword)
3554 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3555 return FALSE;
3559 if (lpUrlComponents->lpszPassword)
3561 *lpdwUrlLength += strlen(":");
3562 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3565 if (lpUrlComponents->lpszHostName)
3567 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3569 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3571 char szPort[MAX_WORD_DIGITS+1];
3573 sprintf(szPort, "%d", lpUrlComponents->nPort);
3574 *lpdwUrlLength += strlen(szPort);
3575 *lpdwUrlLength += strlen(":");
3578 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3579 (*lpdwUrlLength)++; /* '/' */
3582 if (lpUrlComponents->lpszUrlPath)
3583 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3585 return TRUE;
3588 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3590 INT len;
3592 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3594 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3595 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3596 urlCompW->nScheme = lpUrlComponents->nScheme;
3597 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3598 urlCompW->nPort = lpUrlComponents->nPort;
3599 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3600 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3601 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3602 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3604 if (lpUrlComponents->lpszScheme)
3606 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3607 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3608 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3609 -1, urlCompW->lpszScheme, len);
3612 if (lpUrlComponents->lpszHostName)
3614 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3615 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3616 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3617 -1, urlCompW->lpszHostName, len);
3620 if (lpUrlComponents->lpszUserName)
3622 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3623 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3624 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3625 -1, urlCompW->lpszUserName, len);
3628 if (lpUrlComponents->lpszPassword)
3630 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3631 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3632 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3633 -1, urlCompW->lpszPassword, len);
3636 if (lpUrlComponents->lpszUrlPath)
3638 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3639 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3640 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3641 -1, urlCompW->lpszUrlPath, len);
3644 if (lpUrlComponents->lpszExtraInfo)
3646 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3647 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3648 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3649 -1, urlCompW->lpszExtraInfo, len);
3653 /***********************************************************************
3654 * InternetCreateUrlA (WININET.@)
3656 * See InternetCreateUrlW.
3658 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3659 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3661 BOOL ret;
3662 LPWSTR urlW = NULL;
3663 URL_COMPONENTSW urlCompW;
3665 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3667 if (!lpUrlComponents)
3668 return FALSE;
3670 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3672 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3673 return FALSE;
3676 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3678 if (lpszUrl)
3679 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3681 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3683 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3684 *lpdwUrlLength /= sizeof(WCHAR);
3686 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3687 * minus one, so add one to leave room for NULL terminator
3689 if (ret)
3690 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3692 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3693 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3694 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3695 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3696 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3697 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3698 HeapFree(GetProcessHeap(), 0, urlW);
3700 return ret;
3703 /***********************************************************************
3704 * InternetCreateUrlW (WININET.@)
3706 * Creates a URL from its component parts.
3708 * PARAMS
3709 * lpUrlComponents [I] URL Components.
3710 * dwFlags [I] Flags. See notes.
3711 * lpszUrl [I] Buffer in which to store the created URL.
3712 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3713 * lpszUrl in characters. On output, the number of bytes
3714 * required to store the URL including terminator.
3716 * NOTES
3718 * The dwFlags parameter can be zero or more of the following:
3719 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3721 * RETURNS
3722 * TRUE on success
3723 * FALSE on failure
3726 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3727 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3729 DWORD dwLen;
3730 INTERNET_SCHEME nScheme;
3732 static const WCHAR slashSlashW[] = {'/','/'};
3733 static const WCHAR percentD[] = {'%','d',0};
3735 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3737 if (!lpUrlComponents)
3738 return FALSE;
3740 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3742 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3743 return FALSE;
3746 if (!calc_url_length(lpUrlComponents, &dwLen))
3747 return FALSE;
3749 if (!lpszUrl || *lpdwUrlLength < dwLen)
3751 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3752 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3753 return FALSE;
3756 *lpdwUrlLength = dwLen;
3757 lpszUrl[0] = 0x00;
3759 dwLen = 0;
3761 if (lpUrlComponents->lpszScheme)
3763 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3764 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3765 lpszUrl += dwLen;
3767 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3769 else
3771 LPCWSTR scheme;
3772 nScheme = lpUrlComponents->nScheme;
3774 if (nScheme == INTERNET_SCHEME_DEFAULT)
3775 nScheme = INTERNET_SCHEME_HTTP;
3777 scheme = INTERNET_GetSchemeString(nScheme);
3778 dwLen = strlenW(scheme);
3779 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3780 lpszUrl += dwLen;
3783 /* all schemes are followed by at least a colon */
3784 *lpszUrl = ':';
3785 lpszUrl++;
3787 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3789 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3790 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3793 if (lpUrlComponents->lpszUserName)
3795 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3796 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3797 lpszUrl += dwLen;
3799 if (lpUrlComponents->lpszPassword)
3801 *lpszUrl = ':';
3802 lpszUrl++;
3804 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3805 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3806 lpszUrl += dwLen;
3809 *lpszUrl = '@';
3810 lpszUrl++;
3813 if (lpUrlComponents->lpszHostName)
3815 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3816 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3817 lpszUrl += dwLen;
3819 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3821 WCHAR szPort[MAX_WORD_DIGITS+1];
3823 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3824 *lpszUrl = ':';
3825 lpszUrl++;
3826 dwLen = strlenW(szPort);
3827 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3828 lpszUrl += dwLen;
3831 /* add slash between hostname and path if necessary */
3832 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3834 *lpszUrl = '/';
3835 lpszUrl++;
3840 if (lpUrlComponents->lpszUrlPath)
3842 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3843 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3844 lpszUrl += dwLen;
3847 *lpszUrl = '\0';
3849 return TRUE;
3852 /***********************************************************************
3853 * InternetConfirmZoneCrossingA (WININET.@)
3856 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3858 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3859 return ERROR_SUCCESS;
3862 /***********************************************************************
3863 * InternetConfirmZoneCrossingW (WININET.@)
3866 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3868 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3869 return ERROR_SUCCESS;
3872 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3873 LPDWORD lpdwConnection, DWORD dwReserved )
3875 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3876 lpdwConnection, dwReserved);
3877 return ERROR_SUCCESS;
3880 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3881 LPDWORD lpdwConnection, DWORD dwReserved )
3883 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3884 lpdwConnection, dwReserved);
3885 return ERROR_SUCCESS;
3888 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3890 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3891 return TRUE;
3894 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3896 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3897 return TRUE;
3900 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
3902 FIXME("(0x%08x, 0x%08x) stub\n", dwConnection, dwReserved);
3903 return ERROR_SUCCESS;
3906 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3907 PBYTE pbHexHash )
3909 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3910 debugstr_w(pwszTarget), pbHexHash);
3911 return FALSE;
3914 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3916 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
3917 return FALSE;
3920 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
3922 FIXME("(%p, %08lx) stub\n", a, b);
3923 return 0;