Implement the use of NETCON_send for HTTP connections when in
[wine/multimedia.git] / dlls / wininet / internet.c
blobecf32ae2755870e5ce0a124088242d7c3ddfed0e
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "ntstatus.h"
52 #include "windef.h"
53 #include "winbase.h"
54 #include "winreg.h"
55 #include "winuser.h"
56 #include "wininet.h"
57 #include "winnls.h"
58 #include "wine/debug.h"
59 #include "winerror.h"
60 #define NO_SHLWAPI_STREAM
61 #include "shlwapi.h"
63 #include "wine/exception.h"
64 #include "excpt.h"
66 #include "internet.h"
67 #include "resource.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define MAX_IDLE_WORKER 1000*60*1
74 #define MAX_WORKER_THREADS 10
75 #define RESPONSE_TIMEOUT 30
77 #define GET_HWININET_FROM_LPWININETFINDNEXT(lpwh) \
78 (LPWININETAPPINFOW)(((LPWININETFTPSESSIONW)(lpwh->hdr.lpwhparent))->hdr.lpwhparent)
81 typedef struct
83 DWORD dwError;
84 CHAR response[MAX_REPLY_LEN];
85 } WITHREADERROR, *LPWITHREADERROR;
87 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr);
88 BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData);
89 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
90 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext);
91 static VOID INTERNET_ExecuteWork(void);
93 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
94 static LONG dwNumThreads;
95 static LONG dwNumIdleThreads;
96 static LONG dwNumJobs;
97 static HANDLE hEventArray[2];
98 #define hQuitEvent hEventArray[0]
99 #define hWorkEvent hEventArray[1]
100 static CRITICAL_SECTION csQueue;
101 static LPWORKREQUEST lpHeadWorkQueue;
102 static LPWORKREQUEST lpWorkQueueTail;
103 static HMODULE WININET_hModule;
105 #define HANDLE_CHUNK_SIZE 0x10
107 static CRITICAL_SECTION WININET_cs;
108 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
110 0, 0, &WININET_cs,
111 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
112 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
114 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
116 static LPWININETHANDLEHEADER *WININET_Handles;
117 static UINT WININET_dwNextHandle;
118 static UINT WININET_dwMaxHandles;
120 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
122 LPWININETHANDLEHEADER *p;
123 UINT handle = 0, num;
125 EnterCriticalSection( &WININET_cs );
126 if( !WININET_dwMaxHandles )
128 num = HANDLE_CHUNK_SIZE;
129 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
130 sizeof (UINT)* num);
131 if( !p )
132 goto end;
133 WININET_Handles = p;
134 WININET_dwMaxHandles = num;
136 if( WININET_dwMaxHandles == WININET_dwNextHandle )
138 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
139 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
140 WININET_Handles, sizeof (UINT)* num);
141 if( !p )
142 goto end;
143 WININET_Handles = p;
144 WININET_dwMaxHandles = num;
147 handle = WININET_dwNextHandle;
148 if( WININET_Handles[handle] )
149 ERR("handle isn't free but should be\n");
150 WININET_Handles[handle] = WININET_AddRef( info );
152 while( WININET_Handles[WININET_dwNextHandle] &&
153 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
154 WININET_dwNextHandle++;
156 end:
157 LeaveCriticalSection( &WININET_cs );
159 return (HINTERNET) (handle+1);
162 HINTERNET WININET_FindHandle( LPWININETHANDLEHEADER info )
164 UINT i, handle = 0;
166 EnterCriticalSection( &WININET_cs );
167 for( i=0; i<WININET_dwMaxHandles; i++ )
169 if( info == WININET_Handles[i] )
171 WININET_AddRef( info );
172 handle = i+1;
173 break;
176 LeaveCriticalSection( &WININET_cs );
178 return (HINTERNET) handle;
181 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
183 info->dwRefCount++;
184 TRACE("%p -> refcount = %ld\n", info, info->dwRefCount );
185 return info;
188 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
190 LPWININETHANDLEHEADER info = NULL;
191 UINT handle = (UINT) hinternet;
193 EnterCriticalSection( &WININET_cs );
195 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
196 WININET_Handles[handle-1] )
197 info = WININET_AddRef( WININET_Handles[handle-1] );
199 LeaveCriticalSection( &WININET_cs );
201 TRACE("handle %d -> %p\n", handle, info);
203 return info;
206 BOOL WININET_Release( LPWININETHANDLEHEADER info )
208 info->dwRefCount--;
209 TRACE( "object %p refcount = %ld\n", info, info->dwRefCount );
210 if( !info->dwRefCount )
212 TRACE( "destroying object %p\n", info);
213 info->destroy( info );
215 return TRUE;
218 BOOL WININET_FreeHandle( HINTERNET hinternet )
220 BOOL ret = FALSE;
221 UINT handle = (UINT) hinternet;
222 LPWININETHANDLEHEADER info = NULL;
224 EnterCriticalSection( &WININET_cs );
226 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
228 handle--;
229 if( WININET_Handles[handle] )
231 info = WININET_Handles[handle];
232 TRACE( "destroying handle %d for object %p\n", handle+1, info);
233 WININET_Handles[handle] = NULL;
234 ret = TRUE;
235 if( WININET_dwNextHandle > handle )
236 WININET_dwNextHandle = handle;
240 LeaveCriticalSection( &WININET_cs );
242 if( info )
243 WININET_Release( info );
245 return ret;
248 /***********************************************************************
249 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
251 * PARAMS
252 * hinstDLL [I] handle to the DLL's instance
253 * fdwReason [I]
254 * lpvReserved [I] reserved, must be NULL
256 * RETURNS
257 * Success: TRUE
258 * Failure: FALSE
261 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
263 TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
265 switch (fdwReason) {
266 case DLL_PROCESS_ATTACH:
268 g_dwTlsErrIndex = TlsAlloc();
270 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
271 return FALSE;
273 hQuitEvent = CreateEventW(0, TRUE, FALSE, NULL);
274 hWorkEvent = CreateEventW(0, FALSE, FALSE, NULL);
275 InitializeCriticalSection(&csQueue);
277 URLCacheContainers_CreateDefaults();
279 dwNumThreads = 0;
280 dwNumIdleThreads = 0;
281 dwNumJobs = 0;
283 WININET_hModule = (HMODULE)hinstDLL;
285 case DLL_THREAD_ATTACH:
287 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR));
288 if (NULL == lpwite)
289 return FALSE;
291 TlsSetValue(g_dwTlsErrIndex, (LPVOID)lpwite);
293 break;
295 case DLL_THREAD_DETACH:
296 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
298 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
299 HeapFree(GetProcessHeap(), 0, lpwite);
301 break;
303 case DLL_PROCESS_DETACH:
305 URLCacheContainers_DeleteAll();
307 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
309 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
310 TlsFree(g_dwTlsErrIndex);
313 SetEvent(hQuitEvent);
315 CloseHandle(hQuitEvent);
316 CloseHandle(hWorkEvent);
317 DeleteCriticalSection(&csQueue);
318 break;
321 return TRUE;
325 /***********************************************************************
326 * InternetInitializeAutoProxyDll (WININET.@)
328 * Setup the internal proxy
330 * PARAMETERS
331 * dwReserved
333 * RETURNS
334 * FALSE on failure
337 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
339 FIXME("STUB\n");
340 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
341 return FALSE;
344 /***********************************************************************
345 * DetectAutoProxyUrl (WININET.@)
347 * Auto detect the proxy url
349 * RETURNS
350 * FALSE on failure
353 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
354 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
356 FIXME("STUB\n");
357 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
358 return FALSE;
362 /***********************************************************************
363 * INTERNET_ConfigureProxyFromReg
365 * FIXME:
366 * The proxy may be specified in the form 'http=proxy.my.org'
367 * Presumably that means there can be ftp=ftpproxy.my.org too.
369 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
371 HKEY key;
372 DWORD r, keytype, len, enabled;
373 LPCSTR lpszInternetSettings =
374 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
375 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
377 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
378 if ( r != ERROR_SUCCESS )
379 return FALSE;
381 len = sizeof enabled;
382 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
383 (BYTE*)&enabled, &len);
384 if( (r == ERROR_SUCCESS) && enabled )
386 TRACE("Proxy is enabled.\n");
388 /* figure out how much memory the proxy setting takes */
389 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
390 NULL, &len);
391 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
393 LPWSTR szProxy, p;
394 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
396 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
397 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
398 (BYTE*)szProxy, &len);
400 /* find the http proxy, and strip away everything else */
401 p = strstrW( szProxy, szHttp );
402 if( p )
404 p += lstrlenW(szHttp);
405 lstrcpyW( szProxy, p );
407 p = strchrW( szProxy, ' ' );
408 if( p )
409 *p = 0;
411 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
412 lpwai->lpszProxy = szProxy;
414 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
416 else
417 ERR("Couldn't read proxy server settings.\n");
419 else
420 TRACE("Proxy is not enabled.\n");
421 RegCloseKey(key);
423 return enabled;
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, %li, %s, %s, %li)\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(), 0, sizeof(WININETAPPINFOW));
471 if (NULL == lpwai)
473 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
474 goto lend;
477 memset(lpwai, 0, sizeof(WININETAPPINFOW));
478 lpwai->hdr.htype = WH_HINIT;
479 lpwai->hdr.lpwhparent = NULL;
480 lpwai->hdr.dwFlags = dwFlags;
481 lpwai->hdr.dwRefCount = 1;
482 lpwai->hdr.destroy = INTERNET_CloseHandle;
483 lpwai->dwAccessType = dwAccessType;
484 lpwai->lpszProxyUsername = NULL;
485 lpwai->lpszProxyPassword = NULL;
487 handle = WININET_AllocHandle( &lpwai->hdr );
488 if( !handle )
490 HeapFree( GetProcessHeap(), 0, lpwai );
491 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
492 goto lend;
495 if (NULL != lpszAgent)
497 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
498 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
499 if (lpwai->lpszAgent)
500 lstrcpyW( lpwai->lpszAgent, lpszAgent );
502 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
503 INTERNET_ConfigureProxyFromReg( lpwai );
504 else if (NULL != lpszProxy)
506 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
507 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
508 if (lpwai->lpszProxy)
509 lstrcpyW( lpwai->lpszProxy, lpszProxy );
512 if (NULL != lpszProxyBypass)
514 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
515 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
516 if (lpwai->lpszProxyBypass)
517 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
520 lend:
521 if( lpwai )
522 WININET_Release( &lpwai->hdr );
524 TRACE("returning %p\n", lpwai);
526 return handle;
530 /***********************************************************************
531 * InternetOpenA (WININET.@)
533 * Per-application initialization of wininet
535 * RETURNS
536 * HINTERNET on success
537 * NULL on failure
540 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
541 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
543 HINTERNET rc = (HINTERNET)NULL;
544 INT len;
545 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
547 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent),
548 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
550 if( lpszAgent )
552 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
553 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
554 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
557 if( lpszProxy )
559 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
560 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
561 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
564 if( lpszProxyBypass )
566 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
567 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
568 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
571 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
573 HeapFree(GetProcessHeap(), 0, szAgent);
574 HeapFree(GetProcessHeap(), 0, szProxy);
575 HeapFree(GetProcessHeap(), 0, szBypass);
577 return rc;
580 /***********************************************************************
581 * InternetGetLastResponseInfoA (WININET.@)
583 * Return last wininet error description on the calling thread
585 * RETURNS
586 * TRUE on success of writing to buffer
587 * FALSE on failure
590 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
591 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
593 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
595 TRACE("\n");
597 *lpdwError = lpwite->dwError;
598 if (lpwite->dwError)
600 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
601 *lpdwBufferLength = strlen(lpszBuffer);
603 else
604 *lpdwBufferLength = 0;
606 return TRUE;
609 /***********************************************************************
610 * InternetGetLastResponseInfoW (WININET.@)
612 * Return last wininet error description on the calling thread
614 * RETURNS
615 * TRUE on success of writing to buffer
616 * FALSE on failure
619 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
620 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
622 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
624 TRACE("\n");
626 *lpdwError = lpwite->dwError;
627 if (lpwite->dwError)
629 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
630 *lpdwBufferLength = lstrlenW(lpszBuffer);
632 else
633 *lpdwBufferLength = 0;
635 return TRUE;
638 /***********************************************************************
639 * InternetGetConnectedState (WININET.@)
641 * Return connected state
643 * RETURNS
644 * TRUE if connected
645 * if lpdwStatus is not null, return the status (off line,
646 * modem, lan...) in it.
647 * FALSE if not connected
649 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
651 TRACE("(%p, 0x%08lx)\n", lpdwStatus, dwReserved);
653 if (lpdwStatus) {
654 FIXME("always returning LAN connection.\n");
655 *lpdwStatus = INTERNET_CONNECTION_LAN;
657 return TRUE;
661 /***********************************************************************
662 * InternetGetConnectedStateExW (WININET.@)
664 * Return connected state
666 * PARAMS
668 * lpdwStatus [O] Flags specifying the status of the internet connection.
669 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
670 * dwNameLen [I] Size of the buffer, in characters.
671 * dwReserved [I] Reserved. Must be set to 0.
673 * RETURNS
674 * TRUE if connected
675 * if lpdwStatus is not null, return the status (off line,
676 * modem, lan...) in it.
677 * FALSE if not connected
679 * NOTES
680 * If the system has no available network connections, an empty string is
681 * stored in lpszConnectionName. If there is a LAN connection, a localized
682 * "LAN Connection" string is stored. Presumably, if only a dial-up
683 * connection is available then the name of the dial-up connection is
684 * returned. Why any application, other than the "Internet Settings" CPL,
685 * would want to use this function instead of the simpler InternetGetConnectedStateW
686 * function is beyond me.
688 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
689 DWORD dwNameLen, DWORD dwReserved)
691 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
693 /* Must be zero */
694 if(dwReserved)
695 return FALSE;
697 if (lpdwStatus) {
698 FIXME("always returning LAN connection.\n");
699 *lpdwStatus = INTERNET_CONNECTION_LAN;
701 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
705 /***********************************************************************
706 * InternetGetConnectedStateExA (WININET.@)
708 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
709 DWORD dwNameLen, DWORD dwReserved)
711 LPWSTR lpwszConnectionName = NULL;
712 BOOL rc;
714 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
716 if (lpszConnectionName && dwNameLen > 0)
717 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
719 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
720 dwReserved);
721 if (rc && lpwszConnectionName)
723 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
724 dwNameLen, NULL, NULL);
726 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
729 return rc;
733 /***********************************************************************
734 * InternetConnectW (WININET.@)
736 * Open a ftp, gopher or http session
738 * RETURNS
739 * HINTERNET a session handle on success
740 * NULL on failure
743 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
744 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
745 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
746 DWORD dwService, DWORD dwFlags, DWORD dwContext)
748 LPWININETAPPINFOW hIC;
749 HINTERNET rc = (HINTERNET) NULL;
751 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet, debugstr_w(lpszServerName),
752 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
753 dwService, dwFlags, dwContext);
755 /* Clear any error information */
756 INTERNET_SetLastError(0);
757 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
758 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
759 goto lend;
761 switch (dwService)
763 case INTERNET_SERVICE_FTP:
764 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
765 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
766 break;
768 case INTERNET_SERVICE_HTTP:
769 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
770 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
771 break;
773 case INTERNET_SERVICE_GOPHER:
774 default:
775 break;
777 lend:
778 if( hIC )
779 WININET_Release( &hIC->hdr );
781 TRACE("returning %p\n", rc);
782 return rc;
786 /***********************************************************************
787 * InternetConnectA (WININET.@)
789 * Open a ftp, gopher or http session
791 * RETURNS
792 * HINTERNET a session handle on success
793 * NULL on failure
796 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
797 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
798 LPCSTR lpszUserName, LPCSTR lpszPassword,
799 DWORD dwService, DWORD dwFlags, DWORD dwContext)
801 HINTERNET rc = (HINTERNET)NULL;
802 INT len = 0;
803 LPWSTR szServerName = NULL;
804 LPWSTR szUserName = NULL;
805 LPWSTR szPassword = NULL;
807 if (lpszServerName)
809 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
810 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
811 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
813 if (lpszUserName)
815 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
816 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
817 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
819 if (lpszPassword)
821 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
822 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
823 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
827 rc = InternetConnectW(hInternet, szServerName, nServerPort,
828 szUserName, szPassword, dwService, dwFlags, dwContext);
830 HeapFree(GetProcessHeap(), 0, szServerName);
831 HeapFree(GetProcessHeap(), 0, szUserName);
832 HeapFree(GetProcessHeap(), 0, szPassword);
833 return rc;
837 /***********************************************************************
838 * InternetFindNextFileA (WININET.@)
840 * Continues a file search from a previous call to FindFirstFile
842 * RETURNS
843 * TRUE on success
844 * FALSE on failure
847 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
849 BOOL ret;
850 WIN32_FIND_DATAW fd;
852 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
853 if(lpvFindData)
854 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
855 return ret;
858 /***********************************************************************
859 * InternetFindNextFileW (WININET.@)
861 * Continues a file search from a previous call to FindFirstFile
863 * RETURNS
864 * TRUE on success
865 * FALSE on failure
868 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
870 LPWININETAPPINFOW hIC = NULL;
871 LPWININETFINDNEXTW lpwh;
872 BOOL bSuccess = FALSE;
874 TRACE("\n");
876 lpwh = (LPWININETFINDNEXTW) WININET_GetObject( hFind );
877 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
879 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
880 goto lend;
883 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
884 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
886 WORKREQUEST workRequest;
887 struct WORKREQ_INTERNETFINDNEXTW *req;
889 workRequest.asyncall = INTERNETFINDNEXTW;
890 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
891 req = &workRequest.u.InternetFindNextW;
892 req->lpFindFileData = lpvFindData;
894 bSuccess = INTERNET_AsyncCall(&workRequest);
896 else
898 bSuccess = INTERNET_FindNextFileW(lpwh, lpvFindData);
900 lend:
901 if( lpwh )
902 WININET_Release( &lpwh->hdr );
903 return bSuccess;
906 /***********************************************************************
907 * INTERNET_FindNextFileW (Internal)
909 * Continues a file search from a previous call to FindFirstFile
911 * RETURNS
912 * TRUE on success
913 * FALSE on failure
916 BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData)
918 BOOL bSuccess = TRUE;
919 LPWIN32_FIND_DATAW lpFindFileData;
921 TRACE("\n");
923 assert (lpwh->hdr.htype == WH_HFINDNEXT);
925 /* Clear any error information */
926 INTERNET_SetLastError(0);
928 if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
930 FIXME("Only FTP find next supported\n");
931 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
932 return FALSE;
935 TRACE("index(%ld) size(%ld)\n", lpwh->index, lpwh->size);
937 lpFindFileData = (LPWIN32_FIND_DATAW) lpvFindData;
938 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
940 if (lpwh->index >= lpwh->size)
942 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
943 bSuccess = FALSE;
944 goto lend;
947 FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
948 lpwh->index++;
950 TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData->cFileName), lpFindFileData->nFileSizeLow);
952 lend:
954 if (lpwh->hdr.dwFlags & INTERNET_FLAG_ASYNC && lpwh->hdr.lpfnStatusCB)
956 INTERNET_ASYNC_RESULT iar;
958 iar.dwResult = (DWORD)bSuccess;
959 iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
960 INTERNET_GetLastError();
962 SendAsyncCallback(&lpwh->hdr, lpwh->hdr.dwContext,
963 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
964 sizeof(INTERNET_ASYNC_RESULT));
967 return bSuccess;
971 /***********************************************************************
972 * INTERNET_CloseHandle (internal)
974 * Close internet handle
976 * RETURNS
977 * Void
980 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
982 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
984 TRACE("%p\n",lpwai);
986 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
987 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
988 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
989 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
990 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
991 HeapFree(GetProcessHeap(), 0, lpwai);
995 /***********************************************************************
996 * InternetCloseHandle (WININET.@)
998 * Generic close handle function
1000 * RETURNS
1001 * TRUE on success
1002 * FALSE on failure
1005 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1007 LPWININETHANDLEHEADER lpwh;
1009 TRACE("%p\n",hInternet);
1011 lpwh = WININET_GetObject( hInternet );
1012 if (NULL == lpwh)
1014 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1015 return FALSE;
1018 SendAsyncCallback(lpwh, lpwh->dwContext,
1019 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
1020 sizeof(HINTERNET));
1022 if( lpwh->lpwhparent )
1023 WININET_Release( lpwh->lpwhparent );
1024 WININET_FreeHandle( hInternet );
1025 WININET_Release( lpwh );
1027 return TRUE;
1031 /***********************************************************************
1032 * ConvertUrlComponentValue (Internal)
1034 * Helper function for InternetCrackUrlW
1037 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1038 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1039 LPCSTR lpszStart, LPCWSTR lpwszStart)
1041 TRACE("%p %p %p %ld %p %p\n", lppszComponent, dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1042 if (*dwComponentLen != 0)
1044 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1045 if (*lppszComponent == NULL)
1047 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1048 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1049 *dwComponentLen = nASCIILength;
1051 else
1053 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1054 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1055 (*lppszComponent)[ncpylen]=0;
1056 *dwComponentLen = ncpylen;
1062 /***********************************************************************
1063 * InternetCrackUrlA (WININET.@)
1065 * Break up URL into its components
1067 * TODO: Handle dwFlags
1069 * RETURNS
1070 * TRUE on success
1071 * FALSE on failure
1074 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1075 LPURL_COMPONENTSA lpUrlComponents)
1077 DWORD nLength;
1078 URL_COMPONENTSW UCW;
1079 WCHAR* lpwszUrl;
1081 TRACE("(%s %lu %lx %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1082 if(dwUrlLength<=0)
1083 dwUrlLength=-1;
1084 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1086 /* if dwUrlLength=-1 then nLength includes null but length to
1087 InternetCrackUrlW should not include it */
1088 if (dwUrlLength == -1) nLength--;
1090 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1091 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1093 memset(&UCW,0,sizeof(UCW));
1094 if(lpUrlComponents->dwHostNameLength!=0)
1095 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1096 if(lpUrlComponents->dwUserNameLength!=0)
1097 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1098 if(lpUrlComponents->dwPasswordLength!=0)
1099 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1100 if(lpUrlComponents->dwUrlPathLength!=0)
1101 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1102 if(lpUrlComponents->dwSchemeLength!=0)
1103 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1104 if(lpUrlComponents->dwExtraInfoLength!=0)
1105 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1106 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1108 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1109 return FALSE;
1112 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1113 UCW.lpszHostName, UCW.dwHostNameLength,
1114 lpszUrl, lpwszUrl);
1115 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1116 UCW.lpszUserName, UCW.dwUserNameLength,
1117 lpszUrl, lpwszUrl);
1118 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1119 UCW.lpszPassword, UCW.dwPasswordLength,
1120 lpszUrl, lpwszUrl);
1121 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1122 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1123 lpszUrl, lpwszUrl);
1124 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1125 UCW.lpszScheme, UCW.dwSchemeLength,
1126 lpszUrl, lpwszUrl);
1127 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1128 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1129 lpszUrl, lpwszUrl);
1130 lpUrlComponents->nScheme=UCW.nScheme;
1131 lpUrlComponents->nPort=UCW.nPort;
1132 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1134 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1135 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1136 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1137 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1138 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1140 return TRUE;
1143 /***********************************************************************
1144 * GetInternetSchemeW (internal)
1146 * Get scheme of url
1148 * RETURNS
1149 * scheme on success
1150 * INTERNET_SCHEME_UNKNOWN on failure
1153 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1155 INTERNET_SCHEME iScheme=INTERNET_SCHEME_UNKNOWN;
1156 static const WCHAR lpszFtp[]={'f','t','p',0};
1157 static const WCHAR lpszGopher[]={'g','o','p','h','e','r',0};
1158 static const WCHAR lpszHttp[]={'h','t','t','p',0};
1159 static const WCHAR lpszHttps[]={'h','t','t','p','s',0};
1160 static const WCHAR lpszFile[]={'f','i','l','e',0};
1161 static const WCHAR lpszNews[]={'n','e','w','s',0};
1162 static const WCHAR lpszMailto[]={'m','a','i','l','t','o',0};
1163 static const WCHAR lpszRes[]={'r','e','s',0};
1164 WCHAR* tempBuffer=NULL;
1165 TRACE("%s %ld\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1166 if(lpszScheme==NULL)
1167 return INTERNET_SCHEME_UNKNOWN;
1169 tempBuffer=HeapAlloc(GetProcessHeap(),0,(nMaxCmp+1)*sizeof(WCHAR));
1170 lstrcpynW(tempBuffer,lpszScheme,nMaxCmp+1);
1171 strlwrW(tempBuffer);
1172 if (nMaxCmp==strlenW(lpszFtp) && !strncmpW(lpszFtp, tempBuffer, nMaxCmp))
1173 iScheme=INTERNET_SCHEME_FTP;
1174 else if (nMaxCmp==strlenW(lpszGopher) && !strncmpW(lpszGopher, tempBuffer, nMaxCmp))
1175 iScheme=INTERNET_SCHEME_GOPHER;
1176 else if (nMaxCmp==strlenW(lpszHttp) && !strncmpW(lpszHttp, tempBuffer, nMaxCmp))
1177 iScheme=INTERNET_SCHEME_HTTP;
1178 else if (nMaxCmp==strlenW(lpszHttps) && !strncmpW(lpszHttps, tempBuffer, nMaxCmp))
1179 iScheme=INTERNET_SCHEME_HTTPS;
1180 else if (nMaxCmp==strlenW(lpszFile) && !strncmpW(lpszFile, tempBuffer, nMaxCmp))
1181 iScheme=INTERNET_SCHEME_FILE;
1182 else if (nMaxCmp==strlenW(lpszNews) && !strncmpW(lpszNews, tempBuffer, nMaxCmp))
1183 iScheme=INTERNET_SCHEME_NEWS;
1184 else if (nMaxCmp==strlenW(lpszMailto) && !strncmpW(lpszMailto, tempBuffer, nMaxCmp))
1185 iScheme=INTERNET_SCHEME_MAILTO;
1186 else if (nMaxCmp==strlenW(lpszRes) && !strncmpW(lpszRes, tempBuffer, nMaxCmp))
1187 iScheme=INTERNET_SCHEME_RES;
1188 HeapFree(GetProcessHeap(),0,tempBuffer);
1189 return iScheme;
1192 /***********************************************************************
1193 * SetUrlComponentValueW (Internal)
1195 * Helper function for InternetCrackUrlW
1197 * PARAMS
1198 * lppszComponent [O] Holds the returned string
1199 * dwComponentLen [I] Holds the size of lppszComponent
1200 * [O] Holds the length of the string in lppszComponent without '\0'
1201 * lpszStart [I] Holds the string to copy from
1202 * len [I] Holds the length of lpszStart without '\0'
1204 * RETURNS
1205 * TRUE on success
1206 * FALSE on failure
1209 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1211 TRACE("%s (%ld)\n", debugstr_wn(lpszStart,len), len);
1213 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1214 return FALSE;
1216 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1218 if (*lppszComponent == NULL)
1220 *lppszComponent = (LPWSTR)lpszStart;
1221 *dwComponentLen = len;
1223 else
1225 DWORD ncpylen = min((*dwComponentLen)-1, len);
1226 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1227 (*lppszComponent)[ncpylen] = '\0';
1228 *dwComponentLen = ncpylen;
1232 return TRUE;
1235 /***********************************************************************
1236 * InternetCrackUrlW (WININET.@)
1238 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1239 LPURL_COMPONENTSW lpUC)
1242 * RFC 1808
1243 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1246 LPCWSTR lpszParam = NULL;
1247 BOOL bIsAbsolute = FALSE;
1248 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1249 LPCWSTR lpszcp = NULL;
1250 LPWSTR lpszUrl_decode = NULL;
1251 DWORD dwUrlLength = dwUrlLength_orig;
1252 const WCHAR lpszSeparators[3]={';','?',0};
1253 const WCHAR lpszSlash[2]={'/',0};
1254 if(dwUrlLength==0)
1255 dwUrlLength=strlenW(lpszUrl);
1257 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1258 if (dwFlags & ICU_DECODE)
1260 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1261 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1263 lpszUrl = lpszUrl_decode;
1266 lpszap = lpszUrl;
1268 /* Determine if the URI is absolute. */
1269 while (*lpszap != '\0')
1271 if (isalnumW(*lpszap))
1273 lpszap++;
1274 continue;
1276 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1278 bIsAbsolute = TRUE;
1279 lpszcp = lpszap;
1281 else
1283 lpszcp = lpszUrl; /* Relative url */
1286 break;
1289 /* Parse <params> */
1290 lpszParam = strpbrkW(lpszap, lpszSeparators);
1291 if (lpszParam != NULL)
1293 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1294 lpszParam, dwUrlLength-(lpszParam-lpszUrl));
1297 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1299 LPCWSTR lpszNetLoc;
1300 static const WCHAR wszAbout[]={'a','b','o','u','t',':',0};
1302 /* Get scheme first. */
1303 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1304 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1305 lpszUrl, lpszcp - lpszUrl);
1307 /* Eat ':' in protocol. */
1308 lpszcp++;
1310 /* if the scheme is "about", there is no host */
1311 if(strncmpW(wszAbout,lpszUrl, lpszcp - lpszUrl)==0)
1313 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1314 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1315 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1316 lpUC->nPort = 0;
1318 else
1320 /* Skip over slashes. */
1321 if (*lpszcp == '/')
1323 lpszcp++;
1324 if (*lpszcp == '/')
1326 lpszcp++;
1327 if (*lpszcp == '/')
1328 lpszcp++;
1332 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1333 if (lpszParam)
1335 if (lpszNetLoc)
1336 lpszNetLoc = min(lpszNetLoc, lpszParam);
1337 else
1338 lpszNetLoc = lpszParam;
1340 else if (!lpszNetLoc)
1341 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1343 /* Parse net-loc */
1344 if (lpszNetLoc)
1346 LPCWSTR lpszHost;
1347 LPCWSTR lpszPort;
1349 /* [<user>[<:password>]@]<host>[:<port>] */
1350 /* First find the user and password if they exist */
1352 lpszHost = strchrW(lpszcp, '@');
1353 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1355 /* username and password not specified. */
1356 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1357 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1359 else /* Parse out username and password */
1361 LPCWSTR lpszUser = lpszcp;
1362 LPCWSTR lpszPasswd = lpszHost;
1364 while (lpszcp < lpszHost)
1366 if (*lpszcp == ':')
1367 lpszPasswd = lpszcp;
1369 lpszcp++;
1372 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1373 lpszUser, lpszPasswd - lpszUser);
1375 if (lpszPasswd != lpszHost)
1376 lpszPasswd++;
1377 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1378 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1379 lpszHost - lpszPasswd);
1381 lpszcp++; /* Advance to beginning of host */
1384 /* Parse <host><:port> */
1386 lpszHost = lpszcp;
1387 lpszPort = lpszNetLoc;
1389 /* special case for res:// URLs: there is no port here, so the host is the
1390 entire string up to the first '/' */
1391 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1393 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1394 lpszHost, lpszPort - lpszHost);
1395 lpUC->nPort = 0;
1396 lpszcp=lpszNetLoc;
1398 else
1400 while (lpszcp < lpszNetLoc)
1402 if (*lpszcp == ':')
1403 lpszPort = lpszcp;
1405 lpszcp++;
1408 /* If the scheme is "file" and the host is just one letter, it's not a host */
1409 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1411 lpszcp=lpszHost;
1412 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1413 NULL, 0);
1414 lpUC->nPort = 0;
1416 else
1418 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1419 lpszHost, lpszPort - lpszHost);
1420 if (lpszPort != lpszNetLoc)
1421 lpUC->nPort = atoiW(++lpszPort);
1422 else
1423 lpUC->nPort = 0;
1430 /* Here lpszcp points to:
1432 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1433 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1435 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1437 INT len;
1439 /* Only truncate the parameter list if it's already been saved
1440 * in lpUC->lpszExtraInfo.
1442 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1443 len = lpszParam - lpszcp;
1444 else
1446 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1447 * newlines if necessary.
1449 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1450 if (lpsznewline != NULL)
1451 len = lpsznewline - lpszcp;
1452 else
1453 len = dwUrlLength-(lpszcp-lpszUrl);
1455 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1456 lpszcp, len);
1458 else
1460 lpUC->dwUrlPathLength = 0;
1463 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1464 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1465 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1466 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1467 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1469 if (lpszUrl_decode)
1470 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1471 return TRUE;
1474 /***********************************************************************
1475 * InternetAttemptConnect (WININET.@)
1477 * Attempt to make a connection to the internet
1479 * RETURNS
1480 * ERROR_SUCCESS on success
1481 * Error value on failure
1484 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1486 FIXME("Stub\n");
1487 return ERROR_SUCCESS;
1491 /***********************************************************************
1492 * InternetCanonicalizeUrlA (WININET.@)
1494 * Escape unsafe characters and spaces
1496 * RETURNS
1497 * TRUE on success
1498 * FALSE on failure
1501 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1502 LPDWORD lpdwBufferLength, DWORD dwFlags)
1504 HRESULT hr;
1505 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1506 if(dwFlags & ICU_DECODE)
1508 dwURLFlags |= URL_UNESCAPE;
1509 dwFlags &= ~ICU_DECODE;
1512 if(dwFlags & ICU_ESCAPE)
1514 dwURLFlags |= URL_UNESCAPE;
1515 dwFlags &= ~ICU_ESCAPE;
1517 if(dwFlags & ICU_BROWSER_MODE)
1519 dwURLFlags |= URL_BROWSER_MODE;
1520 dwFlags &= ~ICU_BROWSER_MODE;
1522 if(dwFlags)
1523 FIXME("Unhandled flags 0x%08lx\n", dwFlags);
1524 TRACE("%s %p %p %08lx\n", debugstr_a(lpszUrl), lpszBuffer,
1525 lpdwBufferLength, dwURLFlags);
1527 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1528 dwFlags ^= ICU_NO_ENCODE;
1530 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1532 return (hr == S_OK) ? TRUE : FALSE;
1535 /***********************************************************************
1536 * InternetCanonicalizeUrlW (WININET.@)
1538 * Escape unsafe characters and spaces
1540 * RETURNS
1541 * TRUE on success
1542 * FALSE on failure
1545 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1546 LPDWORD lpdwBufferLength, DWORD dwFlags)
1548 HRESULT hr;
1549 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1550 if(dwFlags & ICU_DECODE)
1552 dwURLFlags |= URL_UNESCAPE;
1553 dwFlags &= ~ICU_DECODE;
1556 if(dwFlags & ICU_ESCAPE)
1558 dwURLFlags |= URL_UNESCAPE;
1559 dwFlags &= ~ICU_ESCAPE;
1561 if(dwFlags & ICU_BROWSER_MODE)
1563 dwURLFlags |= URL_BROWSER_MODE;
1564 dwFlags &= ~ICU_BROWSER_MODE;
1566 if(dwFlags)
1567 FIXME("Unhandled flags 0x%08lx\n", dwFlags);
1568 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
1569 lpdwBufferLength, dwURLFlags);
1571 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1572 dwFlags ^= ICU_NO_ENCODE;
1574 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1576 return (hr == S_OK) ? TRUE : FALSE;
1580 /***********************************************************************
1581 * InternetSetStatusCallbackA (WININET.@)
1583 * Sets up a callback function which is called as progress is made
1584 * during an operation.
1586 * RETURNS
1587 * Previous callback or NULL on success
1588 * INTERNET_INVALID_STATUS_CALLBACK on failure
1591 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1592 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1594 INTERNET_STATUS_CALLBACK retVal;
1595 LPWININETHANDLEHEADER lpwh;
1597 TRACE("0x%08lx\n", (ULONG)hInternet);
1599 lpwh = WININET_GetObject(hInternet);
1600 if (!lpwh)
1601 return INTERNET_INVALID_STATUS_CALLBACK;
1603 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1604 retVal = lpwh->lpfnStatusCB;
1605 lpwh->lpfnStatusCB = lpfnIntCB;
1607 WININET_Release( lpwh );
1609 return retVal;
1612 /***********************************************************************
1613 * InternetSetStatusCallbackW (WININET.@)
1615 * Sets up a callback function which is called as progress is made
1616 * during an operation.
1618 * RETURNS
1619 * Previous callback or NULL on success
1620 * INTERNET_INVALID_STATUS_CALLBACK on failure
1623 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1624 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1626 INTERNET_STATUS_CALLBACK retVal;
1627 LPWININETHANDLEHEADER lpwh;
1629 TRACE("0x%08lx\n", (ULONG)hInternet);
1631 lpwh = WININET_GetObject(hInternet);
1632 if (!lpwh)
1633 return INTERNET_INVALID_STATUS_CALLBACK;
1635 lpwh->dwInternalFlags |= INET_CALLBACKW;
1636 retVal = lpwh->lpfnStatusCB;
1637 lpwh->lpfnStatusCB = lpfnIntCB;
1639 WININET_Release( lpwh );
1641 return retVal;
1644 /***********************************************************************
1645 * InternetSetFilePointer (WININET.@)
1647 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1648 PVOID pReserved, DWORD dwMoveContext, DWORD dwContext)
1650 FIXME("stub\n");
1651 return FALSE;
1654 /***********************************************************************
1655 * InternetWriteFile (WININET.@)
1657 * Write data to an open internet file
1659 * RETURNS
1660 * TRUE on success
1661 * FALSE on failure
1664 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1665 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1667 BOOL retval = FALSE;
1668 int nSocket = -1;
1669 LPWININETHANDLEHEADER lpwh;
1671 TRACE("\n");
1672 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1673 if (NULL == lpwh)
1674 return FALSE;
1676 switch (lpwh->htype)
1678 case WH_HHTTPREQ:
1680 LPWININETHTTPREQW lpwhr;
1681 lpwhr = (LPWININETHTTPREQW)lpwh;
1683 TRACE("HTTPREQ %li\n",dwNumOfBytesToWrite);
1684 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1685 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1687 WININET_Release( lpwh );
1688 return retval;
1690 break;
1692 case WH_HFILE:
1693 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1694 break;
1696 default:
1697 break;
1700 if (nSocket != -1)
1702 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1703 retval = (res >= 0);
1704 *lpdwNumOfBytesWritten = retval ? res : 0;
1706 WININET_Release( lpwh );
1708 return retval;
1712 static BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1713 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1714 BOOL bWait, BOOL bSendCompletionStatus)
1716 BOOL retval = FALSE;
1717 int nSocket = -1;
1719 /* FIXME: this should use NETCON functions! */
1720 switch (lpwh->htype)
1722 case WH_HHTTPREQ:
1723 if (!NETCON_recv(&((LPWININETHTTPREQW)lpwh)->netConnection, lpBuffer,
1724 dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0, (int *)pdwNumOfBytesRead))
1726 *pdwNumOfBytesRead = 0;
1727 retval = TRUE; /* Under windows, it seems to return 0 even if nothing was read... */
1729 else
1730 retval = TRUE;
1731 break;
1733 case WH_HFILE:
1734 /* FIXME: FTP should use NETCON_ stuff */
1735 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1736 if (nSocket != -1)
1738 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1739 retval = (res >= 0);
1740 *pdwNumOfBytesRead = retval ? res : 0;
1742 break;
1744 default:
1745 break;
1748 if (bSendCompletionStatus)
1750 INTERNET_ASYNC_RESULT iar;
1752 iar.dwResult = retval;
1753 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1754 INTERNET_GetLastError();
1756 SendAsyncCallback(lpwh, lpwh->dwContext,
1757 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1758 sizeof(INTERNET_ASYNC_RESULT));
1760 return retval;
1763 /***********************************************************************
1764 * InternetReadFile (WININET.@)
1766 * Read data from an open internet file
1768 * RETURNS
1769 * TRUE on success
1770 * FALSE on failure
1773 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1774 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1776 LPWININETHANDLEHEADER lpwh;
1777 BOOL retval;
1779 TRACE("%p %p %ld %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1781 lpwh = WININET_GetObject( hFile );
1782 if (!lpwh)
1784 SetLastError(ERROR_INVALID_HANDLE);
1785 return FALSE;
1788 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1789 WININET_Release( lpwh );
1791 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1792 return retval;
1795 /***********************************************************************
1796 * InternetReadFileExA (WININET.@)
1798 * Read data from an open internet file
1800 * PARAMS
1801 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1802 * lpBuffersOut [I/O] Buffer.
1803 * dwFlags [I] Flags. See notes.
1804 * dwContext [I] Context for callbacks.
1806 * RETURNS
1807 * TRUE on success
1808 * FALSE on failure
1810 * NOTES
1811 * The parameter dwFlags include zero or more of the following flags:
1812 *|IRF_ASYNC - Makes the call asynchronous.
1813 *|IRF_SYNC - Makes the call synchronous.
1814 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1815 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1817 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1819 * SEE
1820 * InternetOpenUrlA(), HttpOpenRequestA()
1822 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1823 DWORD dwFlags, DWORD dwContext)
1825 BOOL retval = FALSE;
1826 LPWININETHANDLEHEADER lpwh;
1828 TRACE("(%p %p 0x%lx 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1830 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1831 FIXME("these dwFlags aren't implemented: 0x%lx\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1833 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1835 SetLastError(ERROR_INVALID_PARAMETER);
1836 return FALSE;
1839 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1840 if (!lpwh)
1842 SetLastError(ERROR_INVALID_HANDLE);
1843 return FALSE;
1846 /* FIXME: native only does it asynchronously if the amount of data
1847 * requested isn't available. See NtReadFile. */
1848 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1849 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better, but
1850 * we should implement the above first */
1851 if (dwFlags & IRF_ASYNC)
1853 WORKREQUEST workRequest;
1854 struct WORKREQ_INTERNETREADFILEEXA *req;
1856 workRequest.asyncall = INTERNETREADFILEEXA;
1857 workRequest.hdr = WININET_AddRef( lpwh );
1858 req = &workRequest.u.InternetReadFileExA;
1859 req->lpBuffersOut = lpBuffersOut;
1861 retval = INTERNET_AsyncCall(&workRequest);
1862 if (!retval) return FALSE;
1864 SetLastError(ERROR_IO_PENDING);
1865 return FALSE;
1868 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1869 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1870 !(dwFlags & IRF_NO_WAIT), FALSE);
1872 WININET_Release( lpwh );
1874 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1875 return retval;
1878 /***********************************************************************
1879 * InternetReadFileExW (WININET.@)
1881 * Read data from an open internet file.
1883 * PARAMS
1884 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1885 * lpBuffersOut [I/O] Buffer.
1886 * dwFlags [I] Flags.
1887 * dwContext [I] Context for callbacks.
1889 * RETURNS
1890 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1892 * NOTES
1893 * Not implemented in Wine or native either (as of IE6 SP2).
1896 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1897 DWORD dwFlags, DWORD dwContext)
1899 ERR("(%p, %p, 0x%lx, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1901 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1902 return FALSE;
1905 /***********************************************************************
1906 * INET_QueryOptionHelper (internal)
1908 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1909 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1911 LPWININETHANDLEHEADER lpwhh;
1912 BOOL bSuccess = FALSE;
1914 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1916 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1918 switch (dwOption)
1920 case INTERNET_OPTION_HANDLE_TYPE:
1922 ULONG type;
1924 if (!lpwhh)
1926 WARN("Invalid hInternet handle\n");
1927 SetLastError(ERROR_INVALID_HANDLE);
1928 return FALSE;
1931 type = lpwhh->htype;
1933 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
1935 if (*lpdwBufferLength < sizeof(ULONG))
1936 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1937 else
1939 memcpy(lpBuffer, &type, sizeof(ULONG));
1940 bSuccess = TRUE;
1942 *lpdwBufferLength = sizeof(ULONG);
1943 break;
1946 case INTERNET_OPTION_REQUEST_FLAGS:
1948 ULONG flags = 4;
1949 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
1950 if (*lpdwBufferLength < sizeof(ULONG))
1951 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1952 else
1954 memcpy(lpBuffer, &flags, sizeof(ULONG));
1955 bSuccess = TRUE;
1957 *lpdwBufferLength = sizeof(ULONG);
1958 break;
1961 case INTERNET_OPTION_URL:
1962 case INTERNET_OPTION_DATAFILE_NAME:
1964 if (!lpwhh)
1966 WARN("Invalid hInternet handle\n");
1967 SetLastError(ERROR_INVALID_HANDLE);
1968 return FALSE;
1970 if (lpwhh->htype == WH_HHTTPREQ)
1972 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
1973 WCHAR url[1023];
1974 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
1975 DWORD sizeRequired;
1977 sprintfW(url,szFmt,lpreq->StdHeaders[HTTP_QUERY_HOST].lpszValue,lpreq->lpszPath);
1978 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
1979 if(!bIsUnicode)
1981 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
1982 lpBuffer,*lpdwBufferLength,NULL,NULL);
1983 if (sizeRequired > *lpdwBufferLength)
1984 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1985 else
1986 bSuccess = TRUE;
1987 *lpdwBufferLength = sizeRequired;
1989 else
1991 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
1992 if (*lpdwBufferLength < sizeRequired)
1993 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1994 else
1996 strcpyW(lpBuffer, url);
1997 bSuccess = TRUE;
1999 *lpdwBufferLength = sizeRequired;
2002 break;
2004 case INTERNET_OPTION_HTTP_VERSION:
2006 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2007 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2008 else
2011 * Presently hardcoded to 1.1
2013 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2014 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2015 bSuccess = TRUE;
2017 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2018 break;
2020 case INTERNET_OPTION_CONNECTED_STATE:
2022 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2023 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2025 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2026 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2027 else
2029 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2030 bSuccess = TRUE;
2032 *lpdwBufferLength = sizeof(*pdwConnectedState);
2033 break;
2035 case INTERNET_OPTION_PROXY:
2037 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2038 WININETAPPINFOW wai;
2040 if (lpwai == NULL)
2042 TRACE("Getting global proxy info\n");
2043 memset(&wai, 0, sizeof(WININETAPPINFOW));
2044 INTERNET_ConfigureProxyFromReg( &wai );
2045 lpwai = &wai;
2048 if (bIsUnicode)
2050 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2051 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2053 if (lpwai->lpszProxy)
2054 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2055 sizeof(WCHAR);
2056 if (lpwai->lpszProxyBypass)
2057 proxyBypassBytesRequired =
2058 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2059 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2060 proxyBytesRequired + proxyBypassBytesRequired)
2061 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2062 else
2064 pPI->dwAccessType = lpwai->dwAccessType;
2065 if (lpwai->lpszProxy)
2067 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2068 sizeof(INTERNET_PROXY_INFOW));
2069 lstrcpyW((LPWSTR)pPI->lpszProxy, lpwai->lpszProxy);
2071 else
2073 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2074 sizeof(INTERNET_PROXY_INFOW));
2075 *((LPWSTR)(pPI->lpszProxy)) = 0;
2078 if (lpwai->lpszProxyBypass)
2080 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2081 sizeof(INTERNET_PROXY_INFOW) +
2082 proxyBytesRequired);
2083 lstrcpyW((LPWSTR)pPI->lpszProxyBypass,
2084 lpwai->lpszProxyBypass);
2086 else
2088 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2089 sizeof(INTERNET_PROXY_INFOW) +
2090 proxyBytesRequired);
2091 *((LPWSTR)(pPI->lpszProxyBypass)) = 0;
2093 bSuccess = TRUE;
2095 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2096 proxyBytesRequired + proxyBypassBytesRequired;
2098 else
2100 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2101 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2103 if (lpwai->lpszProxy)
2104 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2105 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2106 if (lpwai->lpszProxyBypass)
2107 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2108 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2109 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2110 proxyBytesRequired + proxyBypassBytesRequired)
2111 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2112 else
2114 pPI->dwAccessType = lpwai->dwAccessType;
2115 if (lpwai->lpszProxy)
2117 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2118 sizeof(INTERNET_PROXY_INFOA));
2119 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2120 (LPSTR)pPI->lpszProxy, proxyBytesRequired, NULL, NULL);
2122 else
2124 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2125 sizeof(INTERNET_PROXY_INFOA));
2126 *((LPSTR)(pPI->lpszProxy)) = '\0';
2129 if (lpwai->lpszProxyBypass)
2131 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2132 sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
2133 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2134 -1, (LPSTR)pPI->lpszProxyBypass,
2135 proxyBypassBytesRequired,
2136 NULL, NULL);
2138 else
2140 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2141 sizeof(INTERNET_PROXY_INFOA) +
2142 proxyBytesRequired);
2143 *((LPSTR)(pPI->lpszProxyBypass)) = '\0';
2145 bSuccess = TRUE;
2147 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2148 proxyBytesRequired + proxyBypassBytesRequired;
2150 break;
2152 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2154 ULONG conn = 2;
2155 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %ld\n", conn);
2156 if (*lpdwBufferLength < sizeof(ULONG))
2157 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2158 else
2160 memcpy(lpBuffer, &conn, sizeof(ULONG));
2161 bSuccess = TRUE;
2163 *lpdwBufferLength = sizeof(ULONG);
2164 break;
2166 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2168 ULONG conn = 4;
2169 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %ld\n", conn);
2170 if (*lpdwBufferLength < sizeof(ULONG))
2171 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2172 else
2174 memcpy(lpBuffer, &conn, sizeof(ULONG));
2175 bSuccess = TRUE;
2177 *lpdwBufferLength = sizeof(ULONG);
2178 break;
2180 case INTERNET_OPTION_SECURITY_FLAGS:
2181 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2182 break;
2184 default:
2185 FIXME("Stub! %ld\n", dwOption);
2186 break;
2188 if (lpwhh)
2189 WININET_Release( lpwhh );
2191 return bSuccess;
2194 /***********************************************************************
2195 * InternetQueryOptionW (WININET.@)
2197 * Queries an options on the specified handle
2199 * RETURNS
2200 * TRUE on success
2201 * FALSE on failure
2204 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2205 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2207 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2210 /***********************************************************************
2211 * InternetQueryOptionA (WININET.@)
2213 * Queries an options on the specified handle
2215 * RETURNS
2216 * TRUE on success
2217 * FALSE on failure
2220 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2221 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2223 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2227 /***********************************************************************
2228 * InternetSetOptionW (WININET.@)
2230 * Sets an options on the specified handle
2232 * RETURNS
2233 * TRUE on success
2234 * FALSE on failure
2237 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2238 LPVOID lpBuffer, DWORD dwBufferLength)
2240 LPWININETHANDLEHEADER lpwhh;
2241 BOOL ret = TRUE;
2243 TRACE("0x%08lx\n", dwOption);
2245 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2246 if( !lpwhh )
2247 return FALSE;
2249 switch (dwOption)
2251 case INTERNET_OPTION_HTTP_VERSION:
2253 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2254 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2256 break;
2257 case INTERNET_OPTION_ERROR_MASK:
2259 unsigned long flags=*(unsigned long*)lpBuffer;
2260 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2262 break;
2263 case INTERNET_OPTION_CODEPAGE:
2265 unsigned long codepage=*(unsigned long*)lpBuffer;
2266 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2268 break;
2269 case INTERNET_OPTION_REQUEST_PRIORITY:
2271 unsigned long priority=*(unsigned long*)lpBuffer;
2272 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2274 break;
2275 case INTERNET_OPTION_CONNECT_TIMEOUT:
2277 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2278 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2280 break;
2281 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2283 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2284 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2286 break;
2287 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2289 unsigned long conns=*(unsigned long*)lpBuffer;
2290 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2292 break;
2293 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2295 unsigned long conns=*(unsigned long*)lpBuffer;
2296 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2298 break;
2299 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2300 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2301 break;
2302 case INTERNET_OPTION_END_BROWSER_SESSION:
2303 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2304 break;
2305 case INTERNET_OPTION_CONNECTED_STATE:
2306 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2307 break;
2308 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2309 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2310 break;
2311 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2312 FIXME("Option INTERNET_OPTION_RECEIVE_TIMEOUT: STUB\n");
2313 break;
2314 case INTERNET_OPTION_SEND_TIMEOUT:
2315 FIXME("Option INTERNET_OPTION_SEND_TIMEOUT: STUB\n");
2316 break;
2317 case INTERNET_OPTION_CONNECT_RETRIES:
2318 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2319 break;
2320 default:
2321 FIXME("Option %ld STUB\n",dwOption);
2322 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2323 ret = FALSE;
2324 break;
2326 WININET_Release( lpwhh );
2328 return ret;
2332 /***********************************************************************
2333 * InternetSetOptionA (WININET.@)
2335 * Sets an options on the specified handle.
2337 * RETURNS
2338 * TRUE on success
2339 * FALSE on failure
2342 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2343 LPVOID lpBuffer, DWORD dwBufferLength)
2345 LPVOID wbuffer;
2346 DWORD wlen;
2347 BOOL r;
2349 switch( dwOption )
2351 case INTERNET_OPTION_PROXY:
2353 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2354 LPINTERNET_PROXY_INFOW piw;
2355 DWORD proxlen, prbylen;
2356 LPWSTR prox, prby;
2358 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2359 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2360 wlen = sizeof(*piw) + proxlen + prbylen;
2361 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2362 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2363 piw->dwAccessType = pi->dwAccessType;
2364 prox = (LPWSTR) &piw[1];
2365 prby = &prox[proxlen+1];
2366 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2367 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2368 piw->lpszProxy = prox;
2369 piw->lpszProxyBypass = prby;
2371 break;
2372 case INTERNET_OPTION_USER_AGENT:
2373 case INTERNET_OPTION_USERNAME:
2374 case INTERNET_OPTION_PASSWORD:
2375 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2376 NULL, 0 );
2377 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2378 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2379 wbuffer, wlen );
2380 break;
2381 default:
2382 wbuffer = lpBuffer;
2383 wlen = dwBufferLength;
2386 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2388 if( lpBuffer != wbuffer )
2389 HeapFree( GetProcessHeap(), 0, wbuffer );
2391 return r;
2395 /***********************************************************************
2396 * InternetSetOptionExA (WININET.@)
2398 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2399 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2401 FIXME("Flags %08lx ignored\n", dwFlags);
2402 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2405 /***********************************************************************
2406 * InternetSetOptionExW (WININET.@)
2408 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2409 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2411 FIXME("Flags %08lx ignored\n", dwFlags);
2412 if( dwFlags & ~ISO_VALID_FLAGS )
2414 SetLastError( ERROR_INVALID_PARAMETER );
2415 return FALSE;
2417 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2420 static const WCHAR WININET_wkday[7][4] =
2421 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2422 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2423 static const WCHAR WININET_month[12][4] =
2424 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2425 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2426 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2428 /***********************************************************************
2429 * InternetTimeFromSystemTimeA (WININET.@)
2431 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2433 BOOL ret;
2434 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2436 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2438 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2439 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2441 return ret;
2444 /***********************************************************************
2445 * InternetTimeFromSystemTimeW (WININET.@)
2447 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2449 static const WCHAR date[] =
2450 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2451 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2453 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2455 if (!time || !string) return FALSE;
2457 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2458 return FALSE;
2460 sprintfW( string, date,
2461 WININET_wkday[time->wDayOfWeek],
2462 time->wDay,
2463 WININET_month[time->wMonth - 1],
2464 time->wYear,
2465 time->wHour,
2466 time->wMinute,
2467 time->wSecond );
2469 return TRUE;
2472 /***********************************************************************
2473 * InternetTimeToSystemTimeA (WININET.@)
2475 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2477 BOOL ret = FALSE;
2478 WCHAR *stringW;
2479 int len;
2481 TRACE( "%s %p 0x%08lx\n", debugstr_a(string), time, reserved );
2483 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2484 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2486 if (stringW)
2488 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2489 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2490 HeapFree( GetProcessHeap(), 0, stringW );
2492 return ret;
2495 /***********************************************************************
2496 * InternetTimeToSystemTimeW (WININET.@)
2498 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2500 unsigned int i;
2501 WCHAR *s = (LPWSTR)string;
2503 TRACE( "%s %p 0x%08lx\n", debugstr_w(string), time, reserved );
2505 if (!string || !time) return FALSE;
2507 /* Windows does this too */
2508 GetSystemTime( time );
2510 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2511 * a SYSTEMTIME structure.
2514 while (*s && !isalphaW( *s )) s++;
2515 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2516 time->wDayOfWeek = 7;
2518 for (i = 0; i < 7; i++)
2520 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2521 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2522 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2524 time->wDayOfWeek = i;
2525 break;
2529 if (time->wDayOfWeek > 6) return TRUE;
2530 while (*s && !isdigitW( *s )) s++;
2531 time->wDay = strtolW( s, &s, 10 );
2533 while (*s && !isalphaW( *s )) s++;
2534 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2535 time->wMonth = 0;
2537 for (i = 0; i < 12; i++)
2539 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2540 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2541 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2543 time->wMonth = i + 1;
2544 break;
2547 if (time->wMonth == 0) return TRUE;
2549 while (*s && !isdigitW( *s )) s++;
2550 if (*s == '\0') return TRUE;
2551 time->wYear = strtolW( s, &s, 10 );
2553 while (*s && !isdigitW( *s )) s++;
2554 if (*s == '\0') return TRUE;
2555 time->wHour = strtolW( s, &s, 10 );
2557 while (*s && !isdigitW( *s )) s++;
2558 if (*s == '\0') return TRUE;
2559 time->wMinute = strtolW( s, &s, 10 );
2561 while (*s && !isdigitW( *s )) s++;
2562 if (*s == '\0') return TRUE;
2563 time->wSecond = strtolW( s, &s, 10 );
2565 time->wMilliseconds = 0;
2566 return TRUE;
2569 /***********************************************************************
2570 * InternetCheckConnectionW (WININET.@)
2572 * Pings a requested host to check internet connection
2574 * RETURNS
2575 * TRUE on success and FALSE on failure. If a failure then
2576 * ERROR_NOT_CONNECTED is placed into GetLastError
2579 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2582 * this is a kludge which runs the resident ping program and reads the output.
2584 * Anyone have a better idea?
2587 BOOL rc = FALSE;
2588 static const CHAR ping[] = "ping -w 1 ";
2589 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2590 CHAR *command = NULL;
2591 WCHAR hostW[1024];
2592 DWORD len;
2593 int status = -1;
2595 FIXME("\n");
2598 * Crack or set the Address
2600 if (lpszUrl == NULL)
2603 * According to the doc we are supost to use the ip for the next
2604 * server in the WnInet internal server database. I have
2605 * no idea what that is or how to get it.
2607 * So someone needs to implement this.
2609 FIXME("Unimplemented with URL of NULL\n");
2610 return TRUE;
2612 else
2614 URL_COMPONENTSW components;
2616 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2617 components.lpszHostName = (LPWSTR)&hostW;
2618 components.dwHostNameLength = 1024;
2620 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2621 goto End;
2623 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2627 * Build our ping command
2629 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2630 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2631 strcpy(command,ping);
2632 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2633 strcat(command,redirect);
2635 TRACE("Ping command is : %s\n",command);
2637 status = system(command);
2639 TRACE("Ping returned a code of %i\n",status);
2641 /* Ping return code of 0 indicates success */
2642 if (status == 0)
2643 rc = TRUE;
2645 End:
2647 HeapFree( GetProcessHeap(), 0, command );
2648 if (rc == FALSE)
2649 SetLastError(ERROR_NOT_CONNECTED);
2651 return rc;
2655 /***********************************************************************
2656 * InternetCheckConnectionA (WININET.@)
2658 * Pings a requested host to check internet connection
2660 * RETURNS
2661 * TRUE on success and FALSE on failure. If a failure then
2662 * ERROR_NOT_CONNECTED is placed into GetLastError
2665 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2667 WCHAR *szUrl;
2668 INT len;
2669 BOOL rc;
2671 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2672 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2673 return FALSE;
2674 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2675 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2676 HeapFree(GetProcessHeap(), 0, szUrl);
2678 return rc;
2682 /**********************************************************
2683 * INTERNET_InternetOpenUrlW (internal)
2685 * Opens an URL
2687 * RETURNS
2688 * handle of connection or NULL on failure
2690 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2691 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2693 URL_COMPONENTSW urlComponents;
2694 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2695 WCHAR password[1024], path[2048], extra[1024];
2696 HINTERNET client = NULL, client1 = NULL;
2698 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2699 dwHeadersLength, dwFlags, dwContext);
2701 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2702 urlComponents.lpszScheme = protocol;
2703 urlComponents.dwSchemeLength = 32;
2704 urlComponents.lpszHostName = hostName;
2705 urlComponents.dwHostNameLength = MAXHOSTNAME;
2706 urlComponents.lpszUserName = userName;
2707 urlComponents.dwUserNameLength = 1024;
2708 urlComponents.lpszPassword = password;
2709 urlComponents.dwPasswordLength = 1024;
2710 urlComponents.lpszUrlPath = path;
2711 urlComponents.dwUrlPathLength = 2048;
2712 urlComponents.lpszExtraInfo = extra;
2713 urlComponents.dwExtraInfoLength = 1024;
2714 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2715 return NULL;
2716 switch(urlComponents.nScheme) {
2717 case INTERNET_SCHEME_FTP:
2718 if(urlComponents.nPort == 0)
2719 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2720 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2721 userName, password, dwFlags, dwContext, INET_OPENURL);
2722 if(client == NULL)
2723 break;
2724 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2725 if(client1 == NULL) {
2726 InternetCloseHandle(client);
2727 break;
2729 break;
2731 case INTERNET_SCHEME_HTTP:
2732 case INTERNET_SCHEME_HTTPS: {
2733 static const WCHAR szStars[] = { '*','/','*', 0 };
2734 LPCWSTR accept[2] = { szStars, NULL };
2735 if(urlComponents.nPort == 0) {
2736 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2737 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2738 else
2739 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2741 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2742 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2743 userName, password, dwFlags, dwContext, INET_OPENURL);
2744 if(client == NULL)
2745 break;
2746 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2747 if(client1 == NULL) {
2748 InternetCloseHandle(client);
2749 break;
2751 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2752 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0)) {
2753 InternetCloseHandle(client1);
2754 client1 = NULL;
2755 break;
2758 case INTERNET_SCHEME_GOPHER:
2759 /* gopher doesn't seem to be implemented in wine, but it's supposed
2760 * to be supported by InternetOpenUrlA. */
2761 default:
2762 break;
2765 TRACE(" %p <--\n", client1);
2767 return client1;
2770 /**********************************************************
2771 * InternetOpenUrlW (WININET.@)
2773 * Opens an URL
2775 * RETURNS
2776 * handle of connection or NULL on failure
2778 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2779 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2781 HINTERNET ret = NULL;
2782 LPWININETAPPINFOW hIC = NULL;
2784 if (TRACE_ON(wininet)) {
2785 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2786 dwHeadersLength, dwFlags, dwContext);
2787 TRACE(" flags :");
2788 dump_INTERNET_FLAGS(dwFlags);
2791 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2792 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2793 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2794 goto lend;
2797 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2798 WORKREQUEST workRequest;
2799 struct WORKREQ_INTERNETOPENURLW *req;
2801 workRequest.asyncall = INTERNETOPENURLW;
2802 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2803 req = &workRequest.u.InternetOpenUrlW;
2804 if (lpszUrl)
2805 req->lpszUrl = WININET_strdupW(lpszUrl);
2806 else
2807 req->lpszUrl = 0;
2808 if (lpszHeaders)
2809 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2810 else
2811 req->lpszHeaders = 0;
2812 req->dwHeadersLength = dwHeadersLength;
2813 req->dwFlags = dwFlags;
2814 req->dwContext = dwContext;
2816 INTERNET_AsyncCall(&workRequest);
2818 * This is from windows.
2820 SetLastError(ERROR_IO_PENDING);
2821 } else {
2822 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2825 lend:
2826 if( hIC )
2827 WININET_Release( &hIC->hdr );
2828 TRACE(" %p <--\n", ret);
2830 return ret;
2833 /**********************************************************
2834 * InternetOpenUrlA (WININET.@)
2836 * Opens an URL
2838 * RETURNS
2839 * handle of connection or NULL on failure
2841 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2842 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2844 HINTERNET rc = (HINTERNET)NULL;
2846 INT lenUrl;
2847 INT lenHeaders = 0;
2848 LPWSTR szUrl = NULL;
2849 LPWSTR szHeaders = NULL;
2851 TRACE("\n");
2853 if(lpszUrl) {
2854 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
2855 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
2856 if(!szUrl)
2857 return (HINTERNET)NULL;
2858 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
2861 if(lpszHeaders) {
2862 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
2863 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
2864 if(!szHeaders) {
2865 HeapFree(GetProcessHeap(), 0, szUrl);
2866 return (HINTERNET)NULL;
2868 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
2871 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
2872 lenHeaders, dwFlags, dwContext);
2874 HeapFree(GetProcessHeap(), 0, szUrl);
2875 HeapFree(GetProcessHeap(), 0, szHeaders);
2877 return rc;
2881 /***********************************************************************
2882 * INTERNET_SetLastError (internal)
2884 * Set last thread specific error
2886 * RETURNS
2889 void INTERNET_SetLastError(DWORD dwError)
2891 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2893 SetLastError(dwError);
2894 if(lpwite)
2895 lpwite->dwError = dwError;
2899 /***********************************************************************
2900 * INTERNET_GetLastError (internal)
2902 * Get last thread specific error
2904 * RETURNS
2907 DWORD INTERNET_GetLastError(void)
2909 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2910 return lpwite->dwError;
2914 /***********************************************************************
2915 * INTERNET_WorkerThreadFunc (internal)
2917 * Worker thread execution function
2919 * RETURNS
2922 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
2924 DWORD dwWaitRes;
2926 while (1)
2928 if(dwNumJobs > 0) {
2929 INTERNET_ExecuteWork();
2930 continue;
2932 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
2934 if (dwWaitRes == WAIT_OBJECT_0 + 1)
2935 INTERNET_ExecuteWork();
2936 else
2937 break;
2939 InterlockedIncrement(&dwNumIdleThreads);
2942 InterlockedDecrement(&dwNumIdleThreads);
2943 InterlockedDecrement(&dwNumThreads);
2944 TRACE("Worker thread exiting\n");
2945 return TRUE;
2949 /***********************************************************************
2950 * INTERNET_InsertWorkRequest (internal)
2952 * Insert work request into queue
2954 * RETURNS
2957 static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
2959 BOOL bSuccess = FALSE;
2960 LPWORKREQUEST lpNewRequest;
2962 TRACE("\n");
2964 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
2965 if (lpNewRequest)
2967 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
2968 lpNewRequest->prev = NULL;
2970 EnterCriticalSection(&csQueue);
2972 lpNewRequest->next = lpWorkQueueTail;
2973 if (lpWorkQueueTail)
2974 lpWorkQueueTail->prev = lpNewRequest;
2975 lpWorkQueueTail = lpNewRequest;
2976 if (!lpHeadWorkQueue)
2977 lpHeadWorkQueue = lpWorkQueueTail;
2979 LeaveCriticalSection(&csQueue);
2981 bSuccess = TRUE;
2982 InterlockedIncrement(&dwNumJobs);
2985 return bSuccess;
2989 /***********************************************************************
2990 * INTERNET_GetWorkRequest (internal)
2992 * Retrieves work request from queue
2994 * RETURNS
2997 static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
2999 BOOL bSuccess = FALSE;
3000 LPWORKREQUEST lpRequest = NULL;
3002 TRACE("\n");
3004 EnterCriticalSection(&csQueue);
3006 if (lpHeadWorkQueue)
3008 lpRequest = lpHeadWorkQueue;
3009 lpHeadWorkQueue = lpHeadWorkQueue->prev;
3010 if (lpRequest == lpWorkQueueTail)
3011 lpWorkQueueTail = lpHeadWorkQueue;
3014 LeaveCriticalSection(&csQueue);
3016 if (lpRequest)
3018 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
3019 HeapFree(GetProcessHeap(), 0, lpRequest);
3020 bSuccess = TRUE;
3021 InterlockedDecrement(&dwNumJobs);
3024 return bSuccess;
3028 /***********************************************************************
3029 * INTERNET_AsyncCall (internal)
3031 * Retrieves work request from queue
3033 * RETURNS
3036 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3038 HANDLE hThread;
3039 DWORD dwTID;
3040 BOOL bSuccess = FALSE;
3042 TRACE("\n");
3044 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
3046 InterlockedIncrement(&dwNumIdleThreads);
3048 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
3049 !(hThread = CreateThread(NULL, 0,
3050 INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
3052 InterlockedDecrement(&dwNumThreads);
3053 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3054 goto lerror;
3057 TRACE("Created new thread\n");
3060 bSuccess = TRUE;
3061 INTERNET_InsertWorkRequest(lpWorkRequest);
3062 SetEvent(hWorkEvent);
3064 lerror:
3066 return bSuccess;
3070 /***********************************************************************
3071 * INTERNET_ExecuteWork (internal)
3073 * RETURNS
3076 static VOID INTERNET_ExecuteWork(void)
3078 WORKREQUEST workRequest;
3080 TRACE("\n");
3082 if (!INTERNET_GetWorkRequest(&workRequest))
3083 return;
3085 switch (workRequest.asyncall)
3087 case FTPPUTFILEW:
3089 struct WORKREQ_FTPPUTFILEW *req = &workRequest.u.FtpPutFileW;
3090 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3092 TRACE("FTPPUTFILEW %p\n", lpwfs);
3094 FTP_FtpPutFileW(lpwfs, req->lpszLocalFile,
3095 req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
3097 HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
3098 HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
3100 break;
3102 case FTPSETCURRENTDIRECTORYW:
3104 struct WORKREQ_FTPSETCURRENTDIRECTORYW *req;
3105 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3107 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs);
3109 req = &workRequest.u.FtpSetCurrentDirectoryW;
3110 FTP_FtpSetCurrentDirectoryW(lpwfs, req->lpszDirectory);
3111 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3113 break;
3115 case FTPCREATEDIRECTORYW:
3117 struct WORKREQ_FTPCREATEDIRECTORYW *req;
3118 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3120 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs);
3122 req = &workRequest.u.FtpCreateDirectoryW;
3123 FTP_FtpCreateDirectoryW(lpwfs, req->lpszDirectory);
3124 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3126 break;
3128 case FTPFINDFIRSTFILEW:
3130 struct WORKREQ_FTPFINDFIRSTFILEW *req;
3131 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3133 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs);
3135 req = &workRequest.u.FtpFindFirstFileW;
3136 FTP_FtpFindFirstFileW(lpwfs, req->lpszSearchFile,
3137 req->lpFindFileData, req->dwFlags, req->dwContext);
3138 HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
3140 break;
3142 case FTPGETCURRENTDIRECTORYW:
3144 struct WORKREQ_FTPGETCURRENTDIRECTORYW *req;
3145 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3147 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs);
3149 req = &workRequest.u.FtpGetCurrentDirectoryW;
3150 FTP_FtpGetCurrentDirectoryW(lpwfs,
3151 req->lpszDirectory, req->lpdwDirectory);
3153 break;
3155 case FTPOPENFILEW:
3157 struct WORKREQ_FTPOPENFILEW *req = &workRequest.u.FtpOpenFileW;
3158 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3160 TRACE("FTPOPENFILEW %p\n", lpwfs);
3162 FTP_FtpOpenFileW(lpwfs, req->lpszFilename,
3163 req->dwAccess, req->dwFlags, req->dwContext);
3164 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3166 break;
3168 case FTPGETFILEW:
3170 struct WORKREQ_FTPGETFILEW *req = &workRequest.u.FtpGetFileW;
3171 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3173 TRACE("FTPGETFILEW %p\n", lpwfs);
3175 FTP_FtpGetFileW(lpwfs, req->lpszRemoteFile,
3176 req->lpszNewFile, req->fFailIfExists,
3177 req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
3178 HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
3179 HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
3181 break;
3183 case FTPDELETEFILEW:
3185 struct WORKREQ_FTPDELETEFILEW *req = &workRequest.u.FtpDeleteFileW;
3186 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3188 TRACE("FTPDELETEFILEW %p\n", lpwfs);
3190 FTP_FtpDeleteFileW(lpwfs, req->lpszFilename);
3191 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3193 break;
3195 case FTPREMOVEDIRECTORYW:
3197 struct WORKREQ_FTPREMOVEDIRECTORYW *req;
3198 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3200 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs);
3202 req = &workRequest.u.FtpRemoveDirectoryW;
3203 FTP_FtpRemoveDirectoryW(lpwfs, req->lpszDirectory);
3204 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3206 break;
3208 case FTPRENAMEFILEW:
3210 struct WORKREQ_FTPRENAMEFILEW *req = &workRequest.u.FtpRenameFileW;
3211 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3213 TRACE("FTPRENAMEFILEW %p\n", lpwfs);
3215 FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
3216 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
3217 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
3219 break;
3221 case INTERNETFINDNEXTW:
3223 struct WORKREQ_INTERNETFINDNEXTW *req;
3224 LPWININETFINDNEXTW lpwh = (LPWININETFINDNEXTW) workRequest.hdr;
3226 TRACE("INTERNETFINDNEXTW %p\n", lpwh);
3228 req = &workRequest.u.InternetFindNextW;
3229 INTERNET_FindNextFileW(lpwh, req->lpFindFileData);
3231 break;
3233 case HTTPSENDREQUESTW:
3235 struct WORKREQ_HTTPSENDREQUESTW *req = &workRequest.u.HttpSendRequestW;
3236 LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) workRequest.hdr;
3238 TRACE("HTTPSENDREQUESTW %p\n", lpwhr);
3240 HTTP_HttpSendRequestW(lpwhr, req->lpszHeader,
3241 req->dwHeaderLength, req->lpOptional, req->dwOptionalLength);
3243 HeapFree(GetProcessHeap(), 0, req->lpszHeader);
3245 break;
3247 case HTTPOPENREQUESTW:
3249 struct WORKREQ_HTTPOPENREQUESTW *req = &workRequest.u.HttpOpenRequestW;
3250 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) workRequest.hdr;
3252 TRACE("HTTPOPENREQUESTW %p\n", lpwhs);
3254 HTTP_HttpOpenRequestW(lpwhs, req->lpszVerb,
3255 req->lpszObjectName, req->lpszVersion, req->lpszReferrer,
3256 req->lpszAcceptTypes, req->dwFlags, req->dwContext);
3258 HeapFree(GetProcessHeap(), 0, req->lpszVerb);
3259 HeapFree(GetProcessHeap(), 0, req->lpszObjectName);
3260 HeapFree(GetProcessHeap(), 0, req->lpszVersion);
3261 HeapFree(GetProcessHeap(), 0, req->lpszReferrer);
3263 break;
3265 case SENDCALLBACK:
3267 struct WORKREQ_SENDCALLBACK *req = &workRequest.u.SendCallback;
3269 TRACE("SENDCALLBACK %p\n", workRequest.hdr);
3271 SendSyncCallback(workRequest.hdr,
3272 req->dwContext, req->dwInternetStatus, req->lpvStatusInfo,
3273 req->dwStatusInfoLength);
3275 /* And frees the copy of the status info */
3276 HeapFree(GetProcessHeap(), 0, req->lpvStatusInfo);
3278 break;
3280 case INTERNETOPENURLW:
3282 struct WORKREQ_INTERNETOPENURLW *req = &workRequest.u.InternetOpenUrlW;
3283 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest.hdr;
3285 TRACE("INTERNETOPENURLW %p\n", hIC);
3287 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3288 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3289 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3290 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3292 break;
3293 case INTERNETREADFILEEXA:
3295 struct WORKREQ_INTERNETREADFILEEXA *req = &workRequest.u.InternetReadFileExA;
3297 TRACE("INTERNETREADFILEEXA %p\n", workRequest.hdr);
3299 INTERNET_ReadFile(workRequest.hdr, req->lpBuffersOut->lpvBuffer,
3300 req->lpBuffersOut->dwBufferLength,
3301 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
3303 break;
3305 WININET_Release( workRequest.hdr );
3309 /***********************************************************************
3310 * INTERNET_GetResponseBuffer
3312 * RETURNS
3315 LPSTR INTERNET_GetResponseBuffer(void)
3317 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3318 TRACE("\n");
3319 return lpwite->response;
3322 /***********************************************************************
3323 * INTERNET_GetNextLine (internal)
3325 * Parse next line in directory string listing
3327 * RETURNS
3328 * Pointer to beginning of next line
3329 * NULL on failure
3333 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3335 struct timeval tv;
3336 fd_set infd;
3337 BOOL bSuccess = FALSE;
3338 INT nRecv = 0;
3339 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3341 TRACE("\n");
3343 FD_ZERO(&infd);
3344 FD_SET(nSocket, &infd);
3345 tv.tv_sec=RESPONSE_TIMEOUT;
3346 tv.tv_usec=0;
3348 while (nRecv < MAX_REPLY_LEN)
3350 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3352 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3354 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3355 goto lend;
3358 if (lpszBuffer[nRecv] == '\n')
3360 bSuccess = TRUE;
3361 break;
3363 if (lpszBuffer[nRecv] != '\r')
3364 nRecv++;
3366 else
3368 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3369 goto lend;
3373 lend:
3374 if (bSuccess)
3376 lpszBuffer[nRecv] = '\0';
3377 *dwLen = nRecv - 1;
3378 TRACE(":%d %s\n", nRecv, lpszBuffer);
3379 return lpszBuffer;
3381 else
3383 return NULL;
3387 /**********************************************************
3388 * InternetQueryDataAvailable (WININET.@)
3390 * Determines how much data is available to be read.
3392 * RETURNS
3393 * If there is data available then TRUE, otherwise if there
3394 * is not or an error occurred then FALSE. Use GetLastError() to
3395 * check for ERROR_NO_MORE_FILES to see if it was the former.
3397 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3398 LPDWORD lpdwNumberOfBytesAvailble,
3399 DWORD dwFlags, DWORD dwConext)
3401 LPWININETHTTPREQW lpwhr;
3402 BOOL retval = FALSE;
3403 char buffer[4048];
3405 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3406 if (NULL == lpwhr)
3408 SetLastError(ERROR_NO_MORE_FILES);
3409 return FALSE;
3412 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3414 switch (lpwhr->hdr.htype)
3416 case WH_HHTTPREQ:
3417 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3418 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3420 SetLastError(ERROR_NO_MORE_FILES);
3421 retval = FALSE;
3423 else
3424 retval = TRUE;
3425 break;
3427 default:
3428 FIXME("unsupported file type\n");
3429 break;
3431 WININET_Release( &lpwhr->hdr );
3433 TRACE("<-- %i\n",retval);
3434 return retval;
3438 /***********************************************************************
3441 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3442 *lphLockReqHandle)
3444 FIXME("STUB\n");
3445 return FALSE;
3448 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3450 FIXME("STUB\n");
3451 return FALSE;
3455 /***********************************************************************
3456 * InternetAutodial
3458 * On windows this function is supposed to dial the default internet
3459 * connection. We don't want to have Wine dial out to the internet so
3460 * we return TRUE by default. It might be nice to check if we are connected.
3462 * RETURNS
3463 * TRUE on success
3464 * FALSE on failure
3467 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3469 FIXME("STUB\n");
3471 /* Tell that we are connected to the internet. */
3472 return TRUE;
3475 /***********************************************************************
3476 * InternetAutodialHangup
3478 * Hangs up a connection made with InternetAutodial
3480 * PARAM
3481 * dwReserved
3482 * RETURNS
3483 * TRUE on success
3484 * FALSE on failure
3487 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3489 FIXME("STUB\n");
3491 /* we didn't dial, we don't disconnect */
3492 return TRUE;
3495 /***********************************************************************
3497 * InternetCombineUrlA
3499 * Combine a base URL with a relative URL
3501 * RETURNS
3502 * TRUE on success
3503 * FALSE on failure
3507 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3508 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3509 DWORD dwFlags)
3511 HRESULT hr=S_OK;
3513 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3515 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3516 dwFlags ^= ICU_NO_ENCODE;
3517 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3519 return (hr==S_OK);
3522 /***********************************************************************
3524 * InternetCombineUrlW
3526 * Combine a base URL with a relative URL
3528 * RETURNS
3529 * TRUE on success
3530 * FALSE on failure
3534 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3535 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3536 DWORD dwFlags)
3538 HRESULT hr=S_OK;
3540 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3542 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3543 dwFlags ^= ICU_NO_ENCODE;
3544 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3546 return (hr==S_OK);
3549 /* max port num is 65535 => 5 digits */
3550 #define MAX_WORD_DIGITS 5
3552 /* we can calculate using ansi strings because we're just
3553 * calculating string length, not size
3555 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3556 LPDWORD lpdwUrlLength, LPDWORD lpdwSchemeLength)
3558 static const WCHAR httpW[] = {'h','t','t','p',0};
3560 *lpdwUrlLength = 0;
3562 switch (lpUrlComponents->nScheme)
3564 case INTERNET_SCHEME_FTP:
3565 case INTERNET_SCHEME_RES:
3566 *lpdwSchemeLength = 3;
3567 break;
3568 case INTERNET_SCHEME_HTTP:
3569 case INTERNET_SCHEME_FILE:
3570 case INTERNET_SCHEME_NEWS:
3571 *lpdwSchemeLength = 4;
3572 break;
3574 default:
3575 *lpdwSchemeLength = 4;
3576 break;
3579 *lpdwUrlLength += *lpdwSchemeLength;
3580 *lpdwUrlLength += strlen("://");
3582 if (lpUrlComponents->lpszUserName)
3584 *lpdwUrlLength += lpUrlComponents->dwUserNameLength;
3585 *lpdwUrlLength += strlen("@");
3587 else
3589 if (lpUrlComponents->lpszPassword)
3591 SetLastError(ERROR_INVALID_PARAMETER);
3592 return FALSE;
3596 if (lpUrlComponents->lpszPassword)
3598 *lpdwUrlLength += strlen(":");
3599 *lpdwUrlLength += lpUrlComponents->dwPasswordLength;
3602 *lpdwUrlLength += lpUrlComponents->dwHostNameLength;
3604 if (lpUrlComponents->nPort != 80 ||
3605 (lpUrlComponents->lpszScheme && strncmpW(lpUrlComponents->lpszScheme, httpW, lpUrlComponents->dwSchemeLength)))
3607 char szPort[MAX_WORD_DIGITS];
3609 sprintf(szPort, "%d", lpUrlComponents->nPort);
3610 *lpdwUrlLength += strlen(szPort);
3611 *lpdwUrlLength += strlen(":");
3614 *lpdwUrlLength += lpUrlComponents->dwUrlPathLength;
3615 return TRUE;
3618 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3620 INT len;
3622 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3624 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3625 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3626 urlCompW->nScheme = lpUrlComponents->nScheme;
3627 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3628 urlCompW->nPort = lpUrlComponents->nPort;
3629 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3630 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3631 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3632 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3634 if (lpUrlComponents->lpszScheme)
3636 len = lpUrlComponents->dwSchemeLength + 1;
3637 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3638 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3639 -1, urlCompW->lpszScheme, len);
3642 if (lpUrlComponents->lpszHostName)
3644 len = lpUrlComponents->dwHostNameLength + 1;
3645 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3646 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3647 -1, urlCompW->lpszHostName, len);
3650 if (lpUrlComponents->lpszUserName)
3652 len = lpUrlComponents->dwUserNameLength + 1;
3653 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3654 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3655 -1, urlCompW->lpszUserName, len);
3658 if (lpUrlComponents->lpszPassword)
3660 len = lpUrlComponents->dwPasswordLength + 1;
3661 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3662 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3663 -1, urlCompW->lpszPassword, len);
3666 if (lpUrlComponents->lpszUrlPath)
3668 len = lpUrlComponents->dwUrlPathLength + 1;
3669 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3670 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3671 -1, urlCompW->lpszUrlPath, len);
3674 if (lpUrlComponents->lpszExtraInfo)
3676 len = lpUrlComponents->dwExtraInfoLength + 1;
3677 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3678 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3679 -1, urlCompW->lpszExtraInfo, len);
3683 /***********************************************************************
3685 * InternetCreateUrlA
3687 * RETURNS
3688 * TRUE on success
3689 * FALSE on failure
3692 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3693 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3695 BOOL ret;
3696 LPWSTR urlW = NULL;
3697 URL_COMPONENTSW urlCompW;
3699 TRACE("(%p,%ld,%s,%p)\n", lpUrlComponents, dwFlags, debugstr_a(lpszUrl), lpdwUrlLength);
3701 if (!lpUrlComponents)
3702 return FALSE;
3704 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3706 SetLastError(ERROR_INVALID_PARAMETER);
3707 return FALSE;
3710 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3712 if (lpszUrl)
3713 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3715 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3717 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3718 * minus one, so add one to leave room for NULL terminator
3720 if (ret)
3721 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3723 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3724 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3725 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3726 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3727 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3728 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3729 HeapFree(GetProcessHeap(), 0, urlW);
3731 return ret;
3734 /***********************************************************************
3736 * InternetCreateUrlW
3738 * RETURNS
3739 * TRUE on success
3740 * FALSE on failure
3743 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3744 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3746 DWORD dwLen, dwSchemeLen;
3748 static const WCHAR colonSlashW[] = {':','/','/',0};
3749 static const WCHAR httpW[] = {'h','t','t','p',0};
3750 static const WCHAR colonW[] = {':',0};
3751 static const WCHAR atW[] = {'@',0};
3752 static const WCHAR percentD[] = {'%','d',0};
3754 TRACE("(%p,%ld,%s,%p)\n", lpUrlComponents, dwFlags, debugstr_w(lpszUrl), lpdwUrlLength);
3756 if (!lpUrlComponents)
3757 return FALSE;
3759 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3761 SetLastError(ERROR_INVALID_PARAMETER);
3762 return FALSE;
3765 if (!calc_url_length(lpUrlComponents, &dwLen, &dwSchemeLen))
3766 return FALSE;
3768 if (!lpszUrl || *lpdwUrlLength < dwLen)
3770 *lpdwUrlLength = dwLen + 1; /* terminating null */
3771 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3772 return FALSE;
3775 *lpdwUrlLength = dwLen;
3776 lpszUrl[0] = 0x00;
3778 if (lpUrlComponents->lpszScheme)
3779 lstrcpynW(lpszUrl, lpUrlComponents->lpszScheme,
3780 min(lpUrlComponents->dwSchemeLength, dwSchemeLen) + 1);
3782 lstrcatW(lpszUrl, colonSlashW);
3784 if (lpUrlComponents->lpszUserName)
3786 if (!*lpUrlComponents->lpszUserName)
3787 return TRUE;
3789 lstrcatW(lpszUrl, lpUrlComponents->lpszUserName);
3791 if (lpUrlComponents->lpszPassword)
3793 lstrcatW(lpszUrl, colonW);
3795 if (!*lpUrlComponents->lpszPassword)
3796 return TRUE;
3797 else
3798 lstrcatW(lpszUrl, lpUrlComponents->lpszPassword);
3801 lstrcatW(lpszUrl, atW);
3804 lstrcatW(lpszUrl, lpUrlComponents->lpszHostName);
3806 if (lpUrlComponents->nPort != 80 || (lpUrlComponents->lpszScheme &&
3807 strncmpW(lpUrlComponents->lpszScheme, httpW, lpUrlComponents->dwSchemeLength)))
3809 WCHAR szPort[MAX_WORD_DIGITS];
3811 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3812 lstrcatW(lpszUrl, colonW);
3813 lstrcatW(lpszUrl, szPort);
3816 lstrcatW(lpszUrl, lpUrlComponents->lpszUrlPath);
3818 return TRUE;
3821 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3823 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3824 return ERROR_SUCCESS;
3827 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3829 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3830 return ERROR_SUCCESS;
3833 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3834 LPDWORD lpdwConnection, DWORD dwReserved )
3836 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
3837 lpdwConnection, dwReserved);
3838 return ERROR_SUCCESS;
3841 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3842 LPDWORD lpdwConnection, DWORD dwReserved )
3844 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
3845 lpdwConnection, dwReserved);
3846 return ERROR_SUCCESS;
3849 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3851 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3852 return TRUE;
3855 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3857 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3858 return TRUE;
3861 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
3863 FIXME("(0x%08lx, 0x%08lx) stub\n", dwConnection, dwReserved);
3864 return ERROR_SUCCESS;
3867 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3868 PBYTE pbHexHash )
3870 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3871 debugstr_w(pwszTarget), pbHexHash);
3872 return FALSE;
3875 BOOL WINAPI InternetClearAllPerSiteCookieDecisions( VOID )
3877 FIXME("stub\n");
3878 return TRUE;
3881 BOOL WINAPI InternetEnumPerSiteCookieDecisionA( LPSTR pszSiteName, unsigned long *pcSiteNameSize,
3882 unsigned long *pdwDecision, unsigned long dwIndex )
3884 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
3885 debugstr_a(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
3886 return FALSE;
3889 BOOL WINAPI InternetEnumPerSiteCookieDecisionW( LPWSTR pszSiteName, unsigned long *pcSiteNameSize,
3890 unsigned long *pdwDecision, unsigned long dwIndex )
3892 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
3893 debugstr_w(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
3894 return FALSE;
3897 BOOL WINAPI InternetGetCookieExA( LPCSTR pchURL, LPCSTR pchCookieName, LPSTR pchCookieData,
3898 LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
3900 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
3901 debugstr_a(pchURL), debugstr_a(pchCookieName), debugstr_a(pchCookieData),
3902 pcchCookieData, dwFlags, lpReserved);
3903 return FALSE;
3906 BOOL WINAPI InternetGetCookieExW( LPCWSTR pchURL, LPCWSTR pchCookieName, LPWSTR pchCookieData,
3907 LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
3909 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
3910 debugstr_w(pchURL), debugstr_w(pchCookieName), debugstr_w(pchCookieData),
3911 pcchCookieData, dwFlags, lpReserved);
3912 return FALSE;
3915 BOOL WINAPI InternetGetPerSiteCookieDecisionA( LPCSTR pwchHostName, unsigned long *pResult )
3917 FIXME("(%s, %p) stub\n", debugstr_a(pwchHostName), pResult);
3918 return FALSE;
3921 BOOL WINAPI InternetGetPerSiteCookieDecisionW( LPCWSTR pwchHostName, unsigned long *pResult )
3923 FIXME("(%s, %p) stub\n", debugstr_w(pwchHostName), pResult);
3924 return FALSE;
3927 BOOL WINAPI InternetSetPerSiteCookieDecisionA( LPCSTR pchHostName, DWORD dwDecision )
3929 FIXME("(%s, 0x%08lx) stub\n", debugstr_a(pchHostName), dwDecision);
3930 return FALSE;
3933 BOOL WINAPI InternetSetPerSiteCookieDecisionW( LPCWSTR pchHostName, DWORD dwDecision )
3935 FIXME("(%s, 0x%08lx) stub\n", debugstr_w(pchHostName), dwDecision);
3936 return FALSE;
3939 DWORD WINAPI InternetSetCookieExA( LPCSTR lpszURL, LPCSTR lpszCookieName, LPCSTR lpszCookieData,
3940 DWORD dwFlags, DWORD_PTR dwReserved)
3942 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
3943 debugstr_a(lpszURL), debugstr_a(lpszCookieName), debugstr_a(lpszCookieData),
3944 dwFlags, dwReserved);
3945 return TRUE;
3948 DWORD WINAPI InternetSetCookieExW( LPCWSTR lpszURL, LPCWSTR lpszCookieName, LPCWSTR lpszCookieData,
3949 DWORD dwFlags, DWORD_PTR dwReserved)
3951 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
3952 debugstr_w(lpszURL), debugstr_w(lpszCookieName), debugstr_w(lpszCookieData),
3953 dwFlags, dwReserved);
3954 return TRUE;
3957 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3959 FIXME("(%p, 0x%08lx) stub\n", hInternet, dwError);
3960 return FALSE;
3963 /***********************************************************************
3964 * dump_INTERNET_FLAGS
3966 * Helper function to TRACE the internet flags.
3968 * RETURNS
3969 * None
3972 void dump_INTERNET_FLAGS(DWORD dwFlags)
3974 #define FE(x) { x, #x }
3975 static const wininet_flag_info flag[] = {
3976 FE(INTERNET_FLAG_RELOAD),
3977 FE(INTERNET_FLAG_RAW_DATA),
3978 FE(INTERNET_FLAG_EXISTING_CONNECT),
3979 FE(INTERNET_FLAG_ASYNC),
3980 FE(INTERNET_FLAG_PASSIVE),
3981 FE(INTERNET_FLAG_NO_CACHE_WRITE),
3982 FE(INTERNET_FLAG_MAKE_PERSISTENT),
3983 FE(INTERNET_FLAG_FROM_CACHE),
3984 FE(INTERNET_FLAG_SECURE),
3985 FE(INTERNET_FLAG_KEEP_CONNECTION),
3986 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
3987 FE(INTERNET_FLAG_READ_PREFETCH),
3988 FE(INTERNET_FLAG_NO_COOKIES),
3989 FE(INTERNET_FLAG_NO_AUTH),
3990 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
3991 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
3992 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
3993 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
3994 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
3995 FE(INTERNET_FLAG_RESYNCHRONIZE),
3996 FE(INTERNET_FLAG_HYPERLINK),
3997 FE(INTERNET_FLAG_NO_UI),
3998 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
3999 FE(INTERNET_FLAG_CACHE_ASYNC),
4000 FE(INTERNET_FLAG_FORMS_SUBMIT),
4001 FE(INTERNET_FLAG_NEED_FILE),
4002 FE(INTERNET_FLAG_TRANSFER_ASCII),
4003 FE(INTERNET_FLAG_TRANSFER_BINARY)
4005 #undef FE
4006 int i;
4008 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
4009 if (flag[i].val & dwFlags) {
4010 TRACE(" %s", flag[i].name);
4011 dwFlags &= ~flag[i].val;
4014 if (dwFlags)
4015 TRACE(" Unknown flags (%08lx)\n", dwFlags);
4016 else
4017 TRACE("\n");