- set size required correctly for all supported options
[wine.git] / dlls / wininet / internet.c
blob63ffeac9159408cebf37b7e24bc98f1b2ed334eb
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 DWORD dwNumThreads;
95 static DWORD dwNumIdleThreads;
96 static DWORD 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 extern void URLCacheContainers_CreateDefaults(void);
106 extern void URLCacheContainers_DeleteAll(void);
108 #define HANDLE_CHUNK_SIZE 0x10
110 static CRITICAL_SECTION WININET_cs;
111 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
113 0, 0, &WININET_cs,
114 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
115 0, 0, { 0, (DWORD)(__FILE__ ": WININET_cs") }
117 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
119 static LPWININETHANDLEHEADER *WININET_Handles;
120 static UINT WININET_dwNextHandle;
121 static UINT WININET_dwMaxHandles;
123 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
125 LPWININETHANDLEHEADER *p;
126 UINT handle = 0, num;
128 EnterCriticalSection( &WININET_cs );
129 if( !WININET_dwMaxHandles )
131 num = HANDLE_CHUNK_SIZE;
132 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
133 sizeof (UINT)* num);
134 if( !p )
135 goto end;
136 WININET_Handles = p;
137 WININET_dwMaxHandles = num;
139 if( WININET_dwMaxHandles == WININET_dwNextHandle )
141 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
142 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
143 WININET_Handles, sizeof (UINT)* num);
144 if( !p )
145 goto end;
146 WININET_Handles = p;
147 WININET_dwMaxHandles = num;
150 handle = WININET_dwNextHandle;
151 if( WININET_Handles[handle] )
152 ERR("handle isn't free but should be\n");
153 WININET_Handles[handle] = WININET_AddRef( info );
155 while( WININET_Handles[WININET_dwNextHandle] &&
156 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
157 WININET_dwNextHandle++;
159 end:
160 LeaveCriticalSection( &WININET_cs );
162 return (HINTERNET) (handle+1);
165 HINTERNET WININET_FindHandle( LPWININETHANDLEHEADER info )
167 UINT i, handle = 0;
169 EnterCriticalSection( &WININET_cs );
170 for( i=0; i<WININET_dwMaxHandles; i++ )
172 if( info == WININET_Handles[i] )
174 WININET_AddRef( info );
175 handle = i+1;
176 break;
179 LeaveCriticalSection( &WININET_cs );
181 return (HINTERNET) handle;
184 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
186 info->dwRefCount++;
187 TRACE("%p -> refcount = %ld\n", info, info->dwRefCount );
188 return info;
191 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
193 LPWININETHANDLEHEADER info = NULL;
194 UINT handle = (UINT) hinternet;
196 EnterCriticalSection( &WININET_cs );
198 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
199 WININET_Handles[handle-1] )
200 info = WININET_AddRef( WININET_Handles[handle-1] );
202 LeaveCriticalSection( &WININET_cs );
204 TRACE("handle %d -> %p\n", handle, info);
206 return info;
209 BOOL WININET_Release( LPWININETHANDLEHEADER info )
211 info->dwRefCount--;
212 TRACE( "object %p refcount = %ld\n", info, info->dwRefCount );
213 if( !info->dwRefCount )
215 TRACE( "destroying object %p\n", info);
216 info->destroy( info );
218 return TRUE;
221 BOOL WININET_FreeHandle( HINTERNET hinternet )
223 BOOL ret = FALSE;
224 UINT handle = (UINT) hinternet;
225 LPWININETHANDLEHEADER info = NULL;
227 EnterCriticalSection( &WININET_cs );
229 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
231 handle--;
232 if( WININET_Handles[handle] )
234 info = WININET_Handles[handle];
235 TRACE( "destroying handle %d for object %p\n", handle+1, info);
236 WININET_Handles[handle] = NULL;
237 ret = TRUE;
238 if( WININET_dwNextHandle > handle )
239 WININET_dwNextHandle = handle;
243 LeaveCriticalSection( &WININET_cs );
245 if( info )
246 WININET_Release( info );
248 return ret;
251 /***********************************************************************
252 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
254 * PARAMS
255 * hinstDLL [I] handle to the DLL's instance
256 * fdwReason [I]
257 * lpvReserved [I] reserved, must be NULL
259 * RETURNS
260 * Success: TRUE
261 * Failure: FALSE
264 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
266 TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
268 switch (fdwReason) {
269 case DLL_PROCESS_ATTACH:
271 g_dwTlsErrIndex = TlsAlloc();
273 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
274 return FALSE;
276 hQuitEvent = CreateEventW(0, TRUE, FALSE, NULL);
277 hWorkEvent = CreateEventW(0, FALSE, FALSE, NULL);
278 InitializeCriticalSection(&csQueue);
280 URLCacheContainers_CreateDefaults();
282 dwNumThreads = 0;
283 dwNumIdleThreads = 0;
284 dwNumJobs = 0;
286 WININET_hModule = (HMODULE)hinstDLL;
288 case DLL_THREAD_ATTACH:
290 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR));
291 if (NULL == lpwite)
292 return FALSE;
294 TlsSetValue(g_dwTlsErrIndex, (LPVOID)lpwite);
296 break;
298 case DLL_THREAD_DETACH:
299 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
301 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
302 HeapFree(GetProcessHeap(), 0, lpwite);
304 break;
306 case DLL_PROCESS_DETACH:
308 URLCacheContainers_DeleteAll();
310 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
312 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
313 TlsFree(g_dwTlsErrIndex);
316 SetEvent(hQuitEvent);
318 CloseHandle(hQuitEvent);
319 CloseHandle(hWorkEvent);
320 DeleteCriticalSection(&csQueue);
321 break;
324 return TRUE;
328 /***********************************************************************
329 * InternetInitializeAutoProxyDll (WININET.@)
331 * Setup the internal proxy
333 * PARAMETERS
334 * dwReserved
336 * RETURNS
337 * FALSE on failure
340 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
342 FIXME("STUB\n");
343 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
344 return FALSE;
347 /***********************************************************************
348 * DetectAutoProxyUrl (WININET.@)
350 * Auto detect the proxy url
352 * RETURNS
353 * FALSE on failure
356 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
357 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
359 FIXME("STUB\n");
360 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
361 return FALSE;
365 /***********************************************************************
366 * INTERNET_ConfigureProxyFromReg
368 * FIXME:
369 * The proxy may be specified in the form 'http=proxy.my.org'
370 * Presumably that means there can be ftp=ftpproxy.my.org too.
372 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
374 HKEY key;
375 DWORD r, keytype, len, enabled;
376 LPSTR lpszInternetSettings =
377 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
378 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
380 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
381 if ( r != ERROR_SUCCESS )
382 return FALSE;
384 len = sizeof enabled;
385 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
386 (BYTE*)&enabled, &len);
387 if( (r == ERROR_SUCCESS) && enabled )
389 TRACE("Proxy is enabled.\n");
391 /* figure out how much memory the proxy setting takes */
392 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
393 NULL, &len);
394 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
396 LPWSTR szProxy, p;
397 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
399 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
400 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
401 (BYTE*)szProxy, &len);
403 /* find the http proxy, and strip away everything else */
404 p = strstrW( szProxy, szHttp );
405 if( p )
407 p += lstrlenW(szHttp);
408 lstrcpyW( szProxy, p );
410 p = strchrW( szProxy, ' ' );
411 if( p )
412 *p = 0;
414 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
415 lpwai->lpszProxy = szProxy;
417 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
419 else
420 ERR("Couldn't read proxy server settings.\n");
422 else
423 TRACE("Proxy is not enabled.\n");
424 RegCloseKey(key);
426 return enabled;
429 /***********************************************************************
430 * InternetOpenW (WININET.@)
432 * Per-application initialization of wininet
434 * RETURNS
435 * HINTERNET on success
436 * NULL on failure
439 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
440 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
442 LPWININETAPPINFOW lpwai = NULL;
443 HINTERNET handle = NULL;
445 if (TRACE_ON(wininet)) {
446 #define FE(x) { x, #x }
447 static const wininet_flag_info access_type[] = {
448 FE(INTERNET_OPEN_TYPE_PRECONFIG),
449 FE(INTERNET_OPEN_TYPE_DIRECT),
450 FE(INTERNET_OPEN_TYPE_PROXY),
451 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
453 #undef FE
454 DWORD i;
455 const char *access_type_str = "Unknown";
457 TRACE("(%s, %li, %s, %s, %li)\n", debugstr_w(lpszAgent), dwAccessType,
458 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
459 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
460 if (access_type[i].val == dwAccessType) {
461 access_type_str = access_type[i].name;
462 break;
465 TRACE(" access type : %s\n", access_type_str);
466 TRACE(" flags :");
467 dump_INTERNET_FLAGS(dwFlags);
470 /* Clear any error information */
471 INTERNET_SetLastError(0);
473 lpwai = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW));
474 if (NULL == lpwai)
476 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
477 goto lend;
480 memset(lpwai, 0, sizeof(WININETAPPINFOW));
481 lpwai->hdr.htype = WH_HINIT;
482 lpwai->hdr.lpwhparent = NULL;
483 lpwai->hdr.dwFlags = dwFlags;
484 lpwai->hdr.dwRefCount = 1;
485 lpwai->hdr.destroy = INTERNET_CloseHandle;
486 lpwai->dwAccessType = dwAccessType;
487 lpwai->lpszProxyUsername = NULL;
488 lpwai->lpszProxyPassword = NULL;
490 handle = WININET_AllocHandle( &lpwai->hdr );
491 if( !handle )
493 HeapFree( GetProcessHeap(), 0, lpwai );
494 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
495 goto lend;
498 if (NULL != lpszAgent)
500 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
501 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
502 if (lpwai->lpszAgent)
503 lstrcpyW( lpwai->lpszAgent, lpszAgent );
505 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
506 INTERNET_ConfigureProxyFromReg( lpwai );
507 else if (NULL != lpszProxy)
509 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
510 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
511 if (lpwai->lpszProxy)
512 lstrcpyW( lpwai->lpszProxy, lpszProxy );
515 if (NULL != lpszProxyBypass)
517 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
518 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
519 if (lpwai->lpszProxyBypass)
520 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
523 lend:
524 if( lpwai )
525 WININET_Release( &lpwai->hdr );
527 TRACE("returning %p\n", lpwai);
529 return handle;
533 /***********************************************************************
534 * InternetOpenA (WININET.@)
536 * Per-application initialization of wininet
538 * RETURNS
539 * HINTERNET on success
540 * NULL on failure
543 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
544 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
546 HINTERNET rc = (HINTERNET)NULL;
547 INT len;
548 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
550 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent),
551 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
553 if( lpszAgent )
555 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
556 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
557 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
560 if( lpszProxy )
562 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
563 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
564 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
567 if( lpszProxyBypass )
569 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
570 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
571 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
574 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
576 HeapFree(GetProcessHeap(), 0, szAgent);
577 HeapFree(GetProcessHeap(), 0, szProxy);
578 HeapFree(GetProcessHeap(), 0, szBypass);
580 return rc;
583 /***********************************************************************
584 * InternetGetLastResponseInfoA (WININET.@)
586 * Return last wininet error description on the calling thread
588 * RETURNS
589 * TRUE on success of writing to buffer
590 * FALSE on failure
593 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
594 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
596 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
598 TRACE("\n");
600 *lpdwError = lpwite->dwError;
601 if (lpwite->dwError)
603 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
604 *lpdwBufferLength = strlen(lpszBuffer);
606 else
607 *lpdwBufferLength = 0;
609 return TRUE;
612 /***********************************************************************
613 * InternetGetLastResponseInfoW (WININET.@)
615 * Return last wininet error description on the calling thread
617 * RETURNS
618 * TRUE on success of writing to buffer
619 * FALSE on failure
622 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
623 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
625 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
627 TRACE("\n");
629 *lpdwError = lpwite->dwError;
630 if (lpwite->dwError)
632 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
633 *lpdwBufferLength = lstrlenW(lpszBuffer);
635 else
636 *lpdwBufferLength = 0;
638 return TRUE;
641 /***********************************************************************
642 * InternetGetConnectedState (WININET.@)
644 * Return connected state
646 * RETURNS
647 * TRUE if connected
648 * if lpdwStatus is not null, return the status (off line,
649 * modem, lan...) in it.
650 * FALSE if not connected
652 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
654 TRACE("(%p, 0x%08lx)\n", lpdwStatus, dwReserved);
656 if (lpdwStatus) {
657 FIXME("always returning LAN connection.\n");
658 *lpdwStatus = INTERNET_CONNECTION_LAN;
660 return TRUE;
664 /***********************************************************************
665 * InternetGetConnectedStateExW (WININET.@)
667 * Return connected state
669 * PARAMS
671 * lpdwStatus [O] Flags specifying the status of the internet connection.
672 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
673 * dwNameLen [I] Size of the buffer, in characters.
674 * dwReserved [I] Reserved. Must be set to 0.
676 * RETURNS
677 * TRUE if connected
678 * if lpdwStatus is not null, return the status (off line,
679 * modem, lan...) in it.
680 * FALSE if not connected
682 * NOTES
683 * If the system has no available network connections, an empty string is
684 * stored in lpszConnectionName. If there is a LAN connection, a localized
685 * "LAN Connection" string is stored. Presumably, if only a dial-up
686 * connection is available then the name of the dial-up connection is
687 * returned. Why any application, other than the "Internet Settings" CPL,
688 * would want to use this function instead of the simpler InternetGetConnectedStateW
689 * function is beyond me.
691 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
692 DWORD dwNameLen, DWORD dwReserved)
694 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
696 /* Must be zero */
697 if(dwReserved)
698 return FALSE;
700 if (lpdwStatus) {
701 FIXME("always returning LAN connection.\n");
702 *lpdwStatus = INTERNET_CONNECTION_LAN;
704 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
708 /***********************************************************************
709 * InternetGetConnectedStateExA (WININET.@)
711 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
712 DWORD dwNameLen, DWORD dwReserved)
714 LPWSTR lpwszConnectionName = NULL;
715 BOOL rc;
717 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
719 if (lpszConnectionName && dwNameLen > 0)
720 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
722 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
723 dwReserved);
724 if (rc && lpwszConnectionName)
726 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
727 dwNameLen, NULL, NULL);
729 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
732 return rc;
736 /***********************************************************************
737 * InternetConnectW (WININET.@)
739 * Open a ftp, gopher or http session
741 * RETURNS
742 * HINTERNET a session handle on success
743 * NULL on failure
746 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
747 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
748 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
749 DWORD dwService, DWORD dwFlags, DWORD dwContext)
751 LPWININETAPPINFOW hIC;
752 HINTERNET rc = (HINTERNET) NULL;
754 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet, debugstr_w(lpszServerName),
755 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
756 dwService, dwFlags, dwContext);
758 /* Clear any error information */
759 INTERNET_SetLastError(0);
760 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
761 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
762 goto lend;
764 switch (dwService)
766 case INTERNET_SERVICE_FTP:
767 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
768 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
769 break;
771 case INTERNET_SERVICE_HTTP:
772 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
773 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
774 break;
776 case INTERNET_SERVICE_GOPHER:
777 default:
778 break;
780 lend:
781 if( hIC )
782 WININET_Release( &hIC->hdr );
784 TRACE("returning %p\n", rc);
785 return rc;
789 /***********************************************************************
790 * InternetConnectA (WININET.@)
792 * Open a ftp, gopher or http session
794 * RETURNS
795 * HINTERNET a session handle on success
796 * NULL on failure
799 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
800 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
801 LPCSTR lpszUserName, LPCSTR lpszPassword,
802 DWORD dwService, DWORD dwFlags, DWORD dwContext)
804 HINTERNET rc = (HINTERNET)NULL;
805 INT len = 0;
806 LPWSTR szServerName = NULL;
807 LPWSTR szUserName = NULL;
808 LPWSTR szPassword = NULL;
810 if (lpszServerName)
812 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
813 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
814 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
816 if (lpszUserName)
818 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
819 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
820 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
822 if (lpszPassword)
824 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
825 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
826 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
830 rc = InternetConnectW(hInternet, szServerName, nServerPort,
831 szUserName, szPassword, dwService, dwFlags, dwContext);
833 HeapFree(GetProcessHeap(), 0, szServerName);
834 HeapFree(GetProcessHeap(), 0, szUserName);
835 HeapFree(GetProcessHeap(), 0, szPassword);
836 return rc;
840 /***********************************************************************
841 * InternetFindNextFileA (WININET.@)
843 * Continues a file search from a previous call to FindFirstFile
845 * RETURNS
846 * TRUE on success
847 * FALSE on failure
850 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
852 BOOL ret;
853 WIN32_FIND_DATAW fd;
855 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
856 if(lpvFindData)
857 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
858 return ret;
861 /***********************************************************************
862 * InternetFindNextFileW (WININET.@)
864 * Continues a file search from a previous call to FindFirstFile
866 * RETURNS
867 * TRUE on success
868 * FALSE on failure
871 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
873 LPWININETAPPINFOW hIC = NULL;
874 LPWININETFINDNEXTW lpwh;
875 BOOL bSuccess = FALSE;
877 TRACE("\n");
879 lpwh = (LPWININETFINDNEXTW) WININET_GetObject( hFind );
880 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
882 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
883 goto lend;
886 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
887 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
889 WORKREQUEST workRequest;
890 struct WORKREQ_INTERNETFINDNEXTW *req;
892 workRequest.asyncall = INTERNETFINDNEXTW;
893 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
894 req = &workRequest.u.InternetFindNextW;
895 req->lpFindFileData = lpvFindData;
897 bSuccess = INTERNET_AsyncCall(&workRequest);
899 else
901 bSuccess = INTERNET_FindNextFileW(lpwh, lpvFindData);
903 lend:
904 if( lpwh )
905 WININET_Release( &lpwh->hdr );
906 return bSuccess;
909 /***********************************************************************
910 * INTERNET_FindNextFileW (Internal)
912 * Continues a file search from a previous call to FindFirstFile
914 * RETURNS
915 * TRUE on success
916 * FALSE on failure
919 BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData)
921 BOOL bSuccess = TRUE;
922 LPWIN32_FIND_DATAW lpFindFileData;
924 TRACE("\n");
926 assert (lpwh->hdr.htype == WH_HFINDNEXT);
928 /* Clear any error information */
929 INTERNET_SetLastError(0);
931 if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
933 FIXME("Only FTP find next supported\n");
934 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
935 return FALSE;
938 TRACE("index(%ld) size(%ld)\n", lpwh->index, lpwh->size);
940 lpFindFileData = (LPWIN32_FIND_DATAW) lpvFindData;
941 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
943 if (lpwh->index >= lpwh->size)
945 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
946 bSuccess = FALSE;
947 goto lend;
950 FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
951 lpwh->index++;
953 TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData->cFileName), lpFindFileData->nFileSizeLow);
955 lend:
957 if (lpwh->hdr.dwFlags & INTERNET_FLAG_ASYNC && lpwh->hdr.lpfnStatusCB)
959 INTERNET_ASYNC_RESULT iar;
961 iar.dwResult = (DWORD)bSuccess;
962 iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
963 INTERNET_GetLastError();
965 SendAsyncCallback(&lpwh->hdr, lpwh->hdr.dwContext,
966 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
967 sizeof(INTERNET_ASYNC_RESULT));
970 return bSuccess;
974 /***********************************************************************
975 * INTERNET_CloseHandle (internal)
977 * Close internet handle
979 * RETURNS
980 * Void
983 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
985 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
987 TRACE("%p\n",lpwai);
989 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
990 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
991 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
992 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
993 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
994 HeapFree(GetProcessHeap(), 0, lpwai);
998 /***********************************************************************
999 * InternetCloseHandle (WININET.@)
1001 * Generic close handle function
1003 * RETURNS
1004 * TRUE on success
1005 * FALSE on failure
1008 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1010 LPWININETHANDLEHEADER lpwh;
1012 TRACE("%p\n",hInternet);
1014 lpwh = WININET_GetObject( hInternet );
1015 if (NULL == lpwh)
1017 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1018 return FALSE;
1021 SendAsyncCallback(lpwh, lpwh->dwContext,
1022 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
1023 sizeof(HINTERNET*));
1025 if( lpwh->lpwhparent )
1026 WININET_Release( lpwh->lpwhparent );
1027 WININET_FreeHandle( hInternet );
1028 WININET_Release( lpwh );
1030 return TRUE;
1034 /***********************************************************************
1035 * ConvertUrlComponentValue (Internal)
1037 * Helper function for InternetCrackUrlW
1040 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1041 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1042 LPCSTR lpszStart, LPCWSTR lpwszStart)
1044 if (*dwComponentLen != 0)
1046 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1047 if (*lppszComponent == NULL)
1049 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1050 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1051 *dwComponentLen = nASCIILength;
1053 else
1055 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1056 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1057 (*lppszComponent)[ncpylen]=0;
1058 *dwComponentLen = ncpylen;
1064 /***********************************************************************
1065 * InternetCrackUrlA (WININET.@)
1067 * Break up URL into its components
1069 * TODO: Handle dwFlags
1071 * RETURNS
1072 * TRUE on success
1073 * FALSE on failure
1076 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1077 LPURL_COMPONENTSA lpUrlComponents)
1079 DWORD nLength;
1080 URL_COMPONENTSW UCW;
1081 WCHAR* lpwszUrl;
1083 if(dwUrlLength<=0)
1084 dwUrlLength=-1;
1085 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1086 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1087 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1089 memset(&UCW,0,sizeof(UCW));
1090 if(lpUrlComponents->dwHostNameLength!=0)
1091 UCW.dwHostNameLength=1;
1092 if(lpUrlComponents->dwUserNameLength!=0)
1093 UCW.dwUserNameLength=1;
1094 if(lpUrlComponents->dwPasswordLength!=0)
1095 UCW.dwPasswordLength=1;
1096 if(lpUrlComponents->dwUrlPathLength!=0)
1097 UCW.dwUrlPathLength=1;
1098 if(lpUrlComponents->dwSchemeLength!=0)
1099 UCW.dwSchemeLength=1;
1100 if(lpUrlComponents->dwExtraInfoLength!=0)
1101 UCW.dwExtraInfoLength=1;
1102 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1104 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1105 return FALSE;
1108 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1109 UCW.lpszHostName, UCW.dwHostNameLength,
1110 lpszUrl, lpwszUrl);
1111 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1112 UCW.lpszUserName, UCW.dwUserNameLength,
1113 lpszUrl, lpwszUrl);
1114 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1115 UCW.lpszPassword, UCW.dwPasswordLength,
1116 lpszUrl, lpwszUrl);
1117 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1118 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1119 lpszUrl, lpwszUrl);
1120 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1121 UCW.lpszScheme, UCW.dwSchemeLength,
1122 lpszUrl, lpwszUrl);
1123 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1124 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1125 lpszUrl, lpwszUrl);
1126 lpUrlComponents->nScheme=UCW.nScheme;
1127 lpUrlComponents->nPort=UCW.nPort;
1128 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1130 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1131 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1132 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1133 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1134 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1136 return TRUE;
1139 /***********************************************************************
1140 * GetInternetSchemeW (internal)
1142 * Get scheme of url
1144 * RETURNS
1145 * scheme on success
1146 * INTERNET_SCHEME_UNKNOWN on failure
1149 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1151 INTERNET_SCHEME iScheme=INTERNET_SCHEME_UNKNOWN;
1152 static const WCHAR lpszFtp[]={'f','t','p',0};
1153 static const WCHAR lpszGopher[]={'g','o','p','h','e','r',0};
1154 static const WCHAR lpszHttp[]={'h','t','t','p',0};
1155 static const WCHAR lpszHttps[]={'h','t','t','p','s',0};
1156 static const WCHAR lpszFile[]={'f','i','l','e',0};
1157 static const WCHAR lpszNews[]={'n','e','w','s',0};
1158 static const WCHAR lpszMailto[]={'m','a','i','l','t','o',0};
1159 static const WCHAR lpszRes[]={'r','e','s',0};
1160 WCHAR* tempBuffer=NULL;
1161 TRACE("\n");
1162 if(lpszScheme==NULL)
1163 return INTERNET_SCHEME_UNKNOWN;
1165 tempBuffer=HeapAlloc(GetProcessHeap(),0,(nMaxCmp+1)*sizeof(WCHAR));
1166 lstrcpynW(tempBuffer,lpszScheme,nMaxCmp+1);
1167 strlwrW(tempBuffer);
1168 if (nMaxCmp==strlenW(lpszFtp) && !strncmpW(lpszFtp, tempBuffer, nMaxCmp))
1169 iScheme=INTERNET_SCHEME_FTP;
1170 else if (nMaxCmp==strlenW(lpszGopher) && !strncmpW(lpszGopher, tempBuffer, nMaxCmp))
1171 iScheme=INTERNET_SCHEME_GOPHER;
1172 else if (nMaxCmp==strlenW(lpszHttp) && !strncmpW(lpszHttp, tempBuffer, nMaxCmp))
1173 iScheme=INTERNET_SCHEME_HTTP;
1174 else if (nMaxCmp==strlenW(lpszHttps) && !strncmpW(lpszHttps, tempBuffer, nMaxCmp))
1175 iScheme=INTERNET_SCHEME_HTTPS;
1176 else if (nMaxCmp==strlenW(lpszFile) && !strncmpW(lpszFile, tempBuffer, nMaxCmp))
1177 iScheme=INTERNET_SCHEME_FILE;
1178 else if (nMaxCmp==strlenW(lpszNews) && !strncmpW(lpszNews, tempBuffer, nMaxCmp))
1179 iScheme=INTERNET_SCHEME_NEWS;
1180 else if (nMaxCmp==strlenW(lpszMailto) && !strncmpW(lpszMailto, tempBuffer, nMaxCmp))
1181 iScheme=INTERNET_SCHEME_MAILTO;
1182 else if (nMaxCmp==strlenW(lpszRes) && !strncmpW(lpszRes, tempBuffer, nMaxCmp))
1183 iScheme=INTERNET_SCHEME_RES;
1184 HeapFree(GetProcessHeap(),0,tempBuffer);
1185 return iScheme;
1188 /***********************************************************************
1189 * SetUrlComponentValueW (Internal)
1191 * Helper function for InternetCrackUrlW
1193 * RETURNS
1194 * TRUE on success
1195 * FALSE on failure
1198 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1200 TRACE("%s (%ld)\n", debugstr_wn(lpszStart,len), len);
1202 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1203 return FALSE;
1205 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1207 if (*lppszComponent == NULL)
1209 *lppszComponent = (LPWSTR)lpszStart;
1210 *dwComponentLen = len;
1212 else
1214 DWORD ncpylen = min((*dwComponentLen)-1, len);
1215 strncpyW(*lppszComponent, lpszStart, ncpylen);
1216 (*lppszComponent)[ncpylen] = '\0';
1217 *dwComponentLen = ncpylen;
1221 return TRUE;
1224 /***********************************************************************
1225 * InternetCrackUrlW (WININET.@)
1227 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1228 LPURL_COMPONENTSW lpUC)
1231 * RFC 1808
1232 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1235 LPCWSTR lpszParam = NULL;
1236 BOOL bIsAbsolute = FALSE;
1237 LPCWSTR lpszap = lpszUrl;
1238 LPCWSTR lpszcp = NULL;
1239 const WCHAR lpszSeparators[3]={';','?',0};
1240 const WCHAR lpszSlash[2]={'/',0};
1241 if(dwUrlLength==0)
1242 dwUrlLength=strlenW(lpszUrl);
1244 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1246 /* Determine if the URI is absolute. */
1247 while (*lpszap != '\0')
1249 if (isalnumW(*lpszap))
1251 lpszap++;
1252 continue;
1254 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1256 bIsAbsolute = TRUE;
1257 lpszcp = lpszap;
1259 else
1261 lpszcp = lpszUrl; /* Relative url */
1264 break;
1267 /* Parse <params> */
1268 lpszParam = strpbrkW(lpszap, lpszSeparators);
1269 if (lpszParam != NULL)
1271 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1272 lpszParam, dwUrlLength-(lpszParam-lpszUrl));
1275 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1277 LPCWSTR lpszNetLoc;
1278 static const WCHAR wszAbout[]={'a','b','o','u','t',':',0};
1280 /* Get scheme first. */
1281 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1282 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1283 lpszUrl, lpszcp - lpszUrl);
1285 /* Eat ':' in protocol. */
1286 lpszcp++;
1288 /* if the scheme is "about", there is no host */
1289 if(strncmpW(wszAbout,lpszUrl, lpszcp - lpszUrl)==0)
1291 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1292 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1293 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1294 lpUC->nPort = 0;
1296 else
1298 /* Skip over slashes. */
1299 if (*lpszcp == '/')
1301 lpszcp++;
1302 if (*lpszcp == '/')
1304 lpszcp++;
1305 if (*lpszcp == '/')
1306 lpszcp++;
1310 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1311 if (lpszParam)
1313 if (lpszNetLoc)
1314 lpszNetLoc = min(lpszNetLoc, lpszParam);
1315 else
1316 lpszNetLoc = lpszParam;
1318 else if (!lpszNetLoc)
1319 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1321 /* Parse net-loc */
1322 if (lpszNetLoc)
1324 LPCWSTR lpszHost;
1325 LPCWSTR lpszPort;
1327 /* [<user>[<:password>]@]<host>[:<port>] */
1328 /* First find the user and password if they exist */
1330 lpszHost = strchrW(lpszcp, '@');
1331 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1333 /* username and password not specified. */
1334 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1335 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1337 else /* Parse out username and password */
1339 LPCWSTR lpszUser = lpszcp;
1340 LPCWSTR lpszPasswd = lpszHost;
1342 while (lpszcp < lpszHost)
1344 if (*lpszcp == ':')
1345 lpszPasswd = lpszcp;
1347 lpszcp++;
1350 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1351 lpszUser, lpszPasswd - lpszUser);
1353 if (lpszPasswd != lpszHost)
1354 lpszPasswd++;
1355 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1356 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1357 lpszHost - lpszPasswd);
1359 lpszcp++; /* Advance to beginning of host */
1362 /* Parse <host><:port> */
1364 lpszHost = lpszcp;
1365 lpszPort = lpszNetLoc;
1367 /* special case for res:// URLs: there is no port here, so the host is the
1368 entire string up to the first '/' */
1369 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1371 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1372 lpszHost, lpszPort - lpszHost);
1373 lpUC->nPort = 0;
1374 lpszcp=lpszNetLoc;
1376 else
1378 while (lpszcp < lpszNetLoc)
1380 if (*lpszcp == ':')
1381 lpszPort = lpszcp;
1383 lpszcp++;
1386 /* If the scheme is "file" and the host is just one letter, it's not a host */
1387 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1389 lpszcp=lpszHost;
1390 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1391 NULL, 0);
1392 lpUC->nPort = 0;
1394 else
1396 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1397 lpszHost, lpszPort - lpszHost);
1398 if (lpszPort != lpszNetLoc)
1399 lpUC->nPort = atoiW(++lpszPort);
1400 else
1401 lpUC->nPort = 0;
1408 /* Here lpszcp points to:
1410 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1411 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1413 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1415 INT len;
1417 /* Only truncate the parameter list if it's already been saved
1418 * in lpUC->lpszExtraInfo.
1420 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1421 len = lpszParam - lpszcp;
1422 else
1424 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1425 * newlines if necessary.
1427 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1428 if (lpsznewline != NULL)
1429 len = lpsznewline - lpszcp;
1430 else
1431 len = dwUrlLength-(lpszcp-lpszUrl);
1434 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1435 lpszcp, len);
1437 else
1439 lpUC->dwUrlPathLength = 0;
1442 TRACE("%s: host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1443 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1444 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1445 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1447 return TRUE;
1450 /***********************************************************************
1451 * InternetAttemptConnect (WININET.@)
1453 * Attempt to make a connection to the internet
1455 * RETURNS
1456 * ERROR_SUCCESS on success
1457 * Error value on failure
1460 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1462 FIXME("Stub\n");
1463 return ERROR_SUCCESS;
1467 /***********************************************************************
1468 * InternetCanonicalizeUrlA (WININET.@)
1470 * Escape unsafe characters and spaces
1472 * RETURNS
1473 * TRUE on success
1474 * FALSE on failure
1477 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1478 LPDWORD lpdwBufferLength, DWORD dwFlags)
1480 HRESULT hr;
1481 TRACE("%s %p %p %08lx\n",debugstr_a(lpszUrl), lpszBuffer,
1482 lpdwBufferLength, dwFlags);
1484 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1485 dwFlags ^= ICU_NO_ENCODE;
1487 dwFlags |= 0x80000000; /* Don't know what this means */
1489 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
1491 return (hr == S_OK) ? TRUE : FALSE;
1494 /***********************************************************************
1495 * InternetCanonicalizeUrlW (WININET.@)
1497 * Escape unsafe characters and spaces
1499 * RETURNS
1500 * TRUE on success
1501 * FALSE on failure
1504 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1505 LPDWORD lpdwBufferLength, DWORD dwFlags)
1507 HRESULT hr;
1508 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
1509 lpdwBufferLength, dwFlags);
1511 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1512 dwFlags ^= ICU_NO_ENCODE;
1514 dwFlags |= 0x80000000; /* Don't know what this means */
1516 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
1518 return (hr == S_OK) ? TRUE : FALSE;
1522 /***********************************************************************
1523 * InternetSetStatusCallbackA (WININET.@)
1525 * Sets up a callback function which is called as progress is made
1526 * during an operation.
1528 * RETURNS
1529 * Previous callback or NULL on success
1530 * INTERNET_INVALID_STATUS_CALLBACK on failure
1533 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1534 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1536 INTERNET_STATUS_CALLBACK retVal;
1537 LPWININETHANDLEHEADER lpwh;
1539 TRACE("0x%08lx\n", (ULONG)hInternet);
1541 lpwh = WININET_GetObject(hInternet);
1542 if (!lpwh)
1543 return INTERNET_INVALID_STATUS_CALLBACK;
1545 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1546 retVal = lpwh->lpfnStatusCB;
1547 lpwh->lpfnStatusCB = lpfnIntCB;
1549 WININET_Release( lpwh );
1551 return retVal;
1554 /***********************************************************************
1555 * InternetSetStatusCallbackW (WININET.@)
1557 * Sets up a callback function which is called as progress is made
1558 * during an operation.
1560 * RETURNS
1561 * Previous callback or NULL on success
1562 * INTERNET_INVALID_STATUS_CALLBACK on failure
1565 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1566 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1568 INTERNET_STATUS_CALLBACK retVal;
1569 LPWININETHANDLEHEADER lpwh;
1571 TRACE("0x%08lx\n", (ULONG)hInternet);
1573 lpwh = WININET_GetObject(hInternet);
1574 if (!lpwh)
1575 return INTERNET_INVALID_STATUS_CALLBACK;
1577 lpwh->dwInternalFlags |= INET_CALLBACKW;
1578 retVal = lpwh->lpfnStatusCB;
1579 lpwh->lpfnStatusCB = lpfnIntCB;
1581 WININET_Release( lpwh );
1583 return retVal;
1586 /***********************************************************************
1587 * InternetSetFilePointer (WININET.@)
1589 DWORD WINAPI InternetSetFilePointer(HINTERNET f1, LONG f2, PVOID f3, DWORD f4, DWORD f5)
1591 FIXME("stub\n");
1592 return FALSE;
1595 /***********************************************************************
1596 * InternetWriteFile (WININET.@)
1598 * Write data to an open internet file
1600 * RETURNS
1601 * TRUE on success
1602 * FALSE on failure
1605 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1606 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1608 BOOL retval = FALSE;
1609 int nSocket = -1;
1610 LPWININETHANDLEHEADER lpwh;
1612 TRACE("\n");
1613 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1614 if (NULL == lpwh)
1615 return FALSE;
1617 switch (lpwh->htype)
1619 case WH_HHTTPREQ:
1620 FIXME("This shouldn't be here! We don't support this kind"
1621 " of connection anymore. Must use NETCON functions,"
1622 " especially if using SSL\n");
1623 nSocket = ((LPWININETHTTPREQW)lpwh)->netConnection.socketFD;
1624 break;
1626 case WH_HFILE:
1627 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1628 break;
1630 default:
1631 break;
1634 if (nSocket != -1)
1636 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1637 retval = (res >= 0);
1638 *lpdwNumOfBytesWritten = retval ? res : 0;
1640 WININET_Release( lpwh );
1642 return retval;
1646 /***********************************************************************
1647 * InternetReadFile (WININET.@)
1649 * Read data from an open internet file
1651 * RETURNS
1652 * TRUE on success
1653 * FALSE on failure
1656 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1657 DWORD dwNumOfBytesToRead, LPDWORD dwNumOfBytesRead)
1659 BOOL retval = FALSE;
1660 int nSocket = -1;
1661 LPWININETHANDLEHEADER lpwh;
1663 TRACE("%p %p %ld %p\n", hFile, lpBuffer, dwNumOfBytesToRead, dwNumOfBytesRead);
1665 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1666 if (NULL == lpwh)
1667 return FALSE;
1669 /* FIXME: this should use NETCON functions! */
1670 switch (lpwh->htype)
1672 case WH_HHTTPREQ:
1673 if (!NETCON_recv(&((LPWININETHTTPREQW)lpwh)->netConnection, lpBuffer,
1674 dwNumOfBytesToRead, MSG_WAITALL, (int *)dwNumOfBytesRead))
1676 *dwNumOfBytesRead = 0;
1677 retval = TRUE; /* Under windows, it seems to return 0 even if nothing was read... */
1679 else
1680 retval = TRUE;
1681 break;
1683 case WH_HFILE:
1684 /* FIXME: FTP should use NETCON_ stuff */
1685 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1686 if (nSocket != -1)
1688 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, MSG_WAITALL);
1689 retval = (res >= 0);
1690 *dwNumOfBytesRead = retval ? res : 0;
1692 break;
1694 default:
1695 break;
1697 WININET_Release( lpwh );
1699 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", dwNumOfBytesRead ? *dwNumOfBytesRead : -1);
1700 return retval;
1703 /***********************************************************************
1704 * InternetReadFileExA (WININET.@)
1706 * Read data from an open internet file
1708 * RETURNS
1709 * TRUE on success
1710 * FALSE on failure
1713 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffer,
1714 DWORD dwFlags, DWORD dwContext)
1716 FIXME("stub\n");
1717 return FALSE;
1720 /***********************************************************************
1721 * InternetReadFileExW (WININET.@)
1723 * Read data from an open internet file
1725 * RETURNS
1726 * TRUE on success
1727 * FALSE on failure
1730 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1731 DWORD dwFlags, DWORD dwContext)
1733 FIXME("stub\n");
1735 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1736 return FALSE;
1739 /***********************************************************************
1740 * INET_QueryOptionHelper (internal)
1742 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1743 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1745 LPWININETHANDLEHEADER lpwhh;
1746 BOOL bSuccess = FALSE;
1748 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1750 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1752 switch (dwOption)
1754 case INTERNET_OPTION_HANDLE_TYPE:
1756 ULONG type;
1758 if (!lpwhh)
1760 WARN("Invalid hInternet handle\n");
1761 SetLastError(ERROR_INVALID_HANDLE);
1762 return FALSE;
1765 type = lpwhh->htype;
1767 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
1769 if (*lpdwBufferLength < sizeof(ULONG))
1770 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1771 else
1773 memcpy(lpBuffer, &type, sizeof(ULONG));
1774 bSuccess = TRUE;
1776 *lpdwBufferLength = sizeof(ULONG);
1777 break;
1780 case INTERNET_OPTION_REQUEST_FLAGS:
1782 ULONG flags = 4;
1783 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
1784 if (*lpdwBufferLength < sizeof(ULONG))
1785 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1786 else
1788 memcpy(lpBuffer, &flags, sizeof(ULONG));
1789 bSuccess = TRUE;
1791 *lpdwBufferLength = sizeof(ULONG);
1792 break;
1795 case INTERNET_OPTION_URL:
1796 case INTERNET_OPTION_DATAFILE_NAME:
1798 if (!lpwhh)
1800 WARN("Invalid hInternet handle\n");
1801 SetLastError(ERROR_INVALID_HANDLE);
1802 return FALSE;
1804 if (lpwhh->htype == WH_HHTTPREQ)
1806 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
1807 WCHAR url[1023];
1808 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
1809 DWORD sizeRequired;
1811 sprintfW(url,szFmt,lpreq->StdHeaders[HTTP_QUERY_HOST].lpszValue,lpreq->lpszPath);
1812 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
1813 if(!bIsUnicode)
1815 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
1816 lpBuffer,*lpdwBufferLength,NULL,NULL);
1817 if (sizeRequired > *lpdwBufferLength)
1818 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1819 else
1820 bSuccess = TRUE;
1821 *lpdwBufferLength = sizeRequired;
1823 else
1825 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
1826 if (*lpdwBufferLength < sizeRequired)
1827 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1828 else
1830 strcpyW(lpBuffer, url);
1831 bSuccess = TRUE;
1833 *lpdwBufferLength = sizeRequired;
1836 break;
1838 case INTERNET_OPTION_HTTP_VERSION:
1840 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
1841 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1842 else
1845 * Presently hardcoded to 1.1
1847 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
1848 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
1849 bSuccess = TRUE;
1851 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
1852 break;
1854 case INTERNET_OPTION_CONNECTED_STATE:
1856 INTERNET_CONNECTED_INFO * pCi = (INTERNET_CONNECTED_INFO *)lpBuffer;
1857 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
1859 if (*lpdwBufferLength < sizeof(INTERNET_CONNECTED_INFO))
1860 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1861 else
1863 pCi->dwConnectedState = INTERNET_STATE_CONNECTED;
1864 pCi->dwFlags = 0;
1865 bSuccess = TRUE;
1867 *lpdwBufferLength = sizeof(INTERNET_CONNECTED_INFO);
1868 break;
1870 case INTERNET_OPTION_PROXY:
1872 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
1874 if (bIsUnicode)
1876 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
1877 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
1879 if (lpwai->lpszProxy)
1880 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
1881 sizeof(WCHAR);
1882 if (lpwai->lpszProxyBypass)
1883 proxyBypassBytesRequired =
1884 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
1885 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
1886 proxyBytesRequired + proxyBypassBytesRequired)
1887 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1888 else
1890 pPI->dwAccessType = lpwai->dwAccessType;
1891 if (lpwai->lpszProxy)
1893 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
1894 sizeof(INTERNET_PROXY_INFOW));
1895 lstrcpyW((LPWSTR)pPI->lpszProxy, lpwai->lpszProxy);
1897 else
1898 pPI->lpszProxy = NULL;
1899 if (lpwai->lpszProxyBypass)
1901 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
1902 sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
1903 lstrcpyW((LPWSTR)pPI->lpszProxyBypass,
1904 lpwai->lpszProxyBypass);
1906 else
1907 pPI->lpszProxyBypass = NULL;
1908 bSuccess = TRUE;
1910 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
1911 proxyBytesRequired + proxyBypassBytesRequired;
1913 else
1915 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
1916 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
1918 if (lpwai->lpszProxy)
1919 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
1920 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
1921 if (lpwai->lpszProxyBypass)
1922 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
1923 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
1924 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
1925 proxyBytesRequired + proxyBypassBytesRequired)
1926 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1927 else
1929 pPI->dwAccessType = lpwai->dwAccessType;
1930 FIXME("INTERNET_OPTION_PROXY: Stub\n");
1931 if (lpwai->lpszProxy)
1933 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
1934 sizeof(INTERNET_PROXY_INFOA));
1935 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
1936 (LPSTR)pPI->lpszProxy, proxyBytesRequired, NULL, NULL);
1938 else
1939 pPI->lpszProxy = NULL;
1940 if (lpwai->lpszProxyBypass)
1942 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
1943 sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
1944 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
1945 -1, (LPSTR)pPI->lpszProxyBypass,
1946 proxyBypassBytesRequired,
1947 NULL, NULL);
1949 else
1950 pPI->lpszProxyBypass = NULL;
1951 bSuccess = TRUE;
1953 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
1954 proxyBytesRequired + proxyBypassBytesRequired;
1956 break;
1958 case INTERNET_OPTION_SECURITY_FLAGS:
1959 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
1960 break;
1962 default:
1963 FIXME("Stub! %ld \n",dwOption);
1964 break;
1966 if (lpwhh)
1967 WININET_Release( lpwhh );
1969 return bSuccess;
1972 /***********************************************************************
1973 * InternetQueryOptionW (WININET.@)
1975 * Queries an options on the specified handle
1977 * RETURNS
1978 * TRUE on success
1979 * FALSE on failure
1982 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
1983 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1985 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
1988 /***********************************************************************
1989 * InternetQueryOptionA (WININET.@)
1991 * Queries an options on the specified handle
1993 * RETURNS
1994 * TRUE on success
1995 * FALSE on failure
1998 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
1999 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2001 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2005 /***********************************************************************
2006 * InternetSetOptionW (WININET.@)
2008 * Sets an options on the specified handle
2010 * RETURNS
2011 * TRUE on success
2012 * FALSE on failure
2015 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2016 LPVOID lpBuffer, DWORD dwBufferLength)
2018 LPWININETHANDLEHEADER lpwhh;
2019 BOOL ret = TRUE;
2021 TRACE("0x%08lx\n", dwOption);
2023 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2024 if( !lpwhh )
2025 return FALSE;
2027 switch (dwOption)
2029 case INTERNET_OPTION_HTTP_VERSION:
2031 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2032 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2034 break;
2035 case INTERNET_OPTION_ERROR_MASK:
2037 unsigned long flags=*(unsigned long*)lpBuffer;
2038 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2040 break;
2041 case INTERNET_OPTION_CODEPAGE:
2043 unsigned long codepage=*(unsigned long*)lpBuffer;
2044 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2046 break;
2047 case INTERNET_OPTION_REQUEST_PRIORITY:
2049 unsigned long priority=*(unsigned long*)lpBuffer;
2050 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2052 break;
2053 case INTERNET_OPTION_CONNECT_TIMEOUT:
2055 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2056 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2058 break;
2059 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2061 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2062 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2064 break;
2065 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2066 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2067 break;
2068 case INTERNET_OPTION_END_BROWSER_SESSION:
2069 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2070 break;
2071 case INTERNET_OPTION_CONNECTED_STATE:
2072 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2073 break;
2074 default:
2075 FIXME("Option %ld STUB\n",dwOption);
2076 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2077 ret = FALSE;
2078 break;
2080 WININET_Release( lpwhh );
2082 return TRUE;
2086 /***********************************************************************
2087 * InternetSetOptionA (WININET.@)
2089 * Sets an options on the specified handle.
2091 * RETURNS
2092 * TRUE on success
2093 * FALSE on failure
2096 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2097 LPVOID lpBuffer, DWORD dwBufferLength)
2099 LPVOID wbuffer;
2100 DWORD wlen;
2101 BOOL r;
2103 switch( dwOption )
2105 case INTERNET_OPTION_PROXY:
2107 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2108 LPINTERNET_PROXY_INFOW piw;
2109 DWORD proxlen, prbylen;
2110 LPWSTR prox, prby;
2112 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2113 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2114 wlen = sizeof(*piw) + proxlen + prbylen;
2115 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2116 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2117 piw->dwAccessType = pi->dwAccessType;
2118 prox = (LPWSTR) &piw[1];
2119 prby = &prox[proxlen+1];
2120 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2121 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2122 piw->lpszProxy = prox;
2123 piw->lpszProxyBypass = prby;
2125 break;
2126 case INTERNET_OPTION_USER_AGENT:
2127 case INTERNET_OPTION_USERNAME:
2128 case INTERNET_OPTION_PASSWORD:
2129 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2130 NULL, 0 );
2131 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2132 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2133 wbuffer, wlen );
2134 break;
2135 default:
2136 wbuffer = lpBuffer;
2137 wlen = dwBufferLength;
2140 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2142 if( lpBuffer != wbuffer )
2143 HeapFree( GetProcessHeap(), 0, wbuffer );
2145 return r;
2149 /***********************************************************************
2150 * InternetSetOptionExA (WININET.@)
2152 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2153 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2155 FIXME("Flags %08lx ignored\n", dwFlags);
2156 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2159 /***********************************************************************
2160 * InternetSetOptionExW (WININET.@)
2162 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2163 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2165 FIXME("Flags %08lx ignored\n", dwFlags);
2166 if( dwFlags & ~ISO_VALID_FLAGS )
2168 SetLastError( ERROR_INVALID_PARAMETER );
2169 return FALSE;
2171 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2174 static const WCHAR WININET_wkday[7][4] =
2175 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2176 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2177 static const WCHAR WININET_month[12][4] =
2178 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2179 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2180 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2182 /***********************************************************************
2183 * InternetTimeFromSystemTimeA (WININET.@)
2185 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2187 BOOL ret;
2188 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2190 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2192 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2193 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2195 return ret;
2198 /***********************************************************************
2199 * InternetTimeFromSystemTimeW (WININET.@)
2201 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2203 static const WCHAR date[] =
2204 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2205 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2207 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2209 if (!time || !string) return FALSE;
2211 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2212 return FALSE;
2214 sprintfW( string, date,
2215 WININET_wkday[time->wDayOfWeek],
2216 time->wDay,
2217 WININET_month[time->wMonth - 1],
2218 time->wYear,
2219 time->wHour,
2220 time->wMinute,
2221 time->wSecond );
2223 return TRUE;
2226 /***********************************************************************
2227 * InternetTimeToSystemTimeA (WININET.@)
2229 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2231 BOOL ret = FALSE;
2232 WCHAR *stringW;
2233 int len;
2235 TRACE( "%s %p 0x%08lx\n", debugstr_a(string), time, reserved );
2237 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2238 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2240 if (stringW)
2242 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2243 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2244 HeapFree( GetProcessHeap(), 0, stringW );
2246 return ret;
2249 /***********************************************************************
2250 * InternetTimeToSystemTimeW (WININET.@)
2252 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2254 unsigned int i;
2255 WCHAR *s = (LPWSTR)string;
2257 TRACE( "%s %p 0x%08lx\n", debugstr_w(string), time, reserved );
2259 if (!string || !time) return FALSE;
2261 /* Windows does this too */
2262 GetSystemTime( time );
2264 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2265 * a SYSTEMTIME structure.
2268 while (*s && !isalphaW( *s )) s++;
2269 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2270 time->wDayOfWeek = 7;
2272 for (i = 0; i < 7; i++)
2274 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2275 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2276 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2278 time->wDayOfWeek = i;
2279 break;
2283 if (time->wDayOfWeek > 6) return TRUE;
2284 while (*s && !isdigitW( *s )) s++;
2285 time->wDay = strtolW( s, &s, 10 );
2287 while (*s && !isalphaW( *s )) s++;
2288 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2289 time->wMonth = 0;
2291 for (i = 0; i < 12; i++)
2293 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2294 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2295 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2297 time->wMonth = i + 1;
2298 break;
2301 if (time->wMonth == 0) return TRUE;
2303 while (*s && !isdigitW( *s )) s++;
2304 if (*s == '\0') return TRUE;
2305 time->wYear = strtolW( s, &s, 10 );
2307 while (*s && !isdigitW( *s )) s++;
2308 if (*s == '\0') return TRUE;
2309 time->wHour = strtolW( s, &s, 10 );
2311 while (*s && !isdigitW( *s )) s++;
2312 if (*s == '\0') return TRUE;
2313 time->wMinute = strtolW( s, &s, 10 );
2315 while (*s && !isdigitW( *s )) s++;
2316 if (*s == '\0') return TRUE;
2317 time->wSecond = strtolW( s, &s, 10 );
2319 time->wMilliseconds = 0;
2320 return TRUE;
2323 /***********************************************************************
2324 * InternetCheckConnectionA (WININET.@)
2326 * Pings a requested host to check internet connection
2328 * RETURNS
2329 * TRUE on success and FALSE on failure. If a failure then
2330 * ERROR_NOT_CONNECTED is placesd into GetLastError
2333 BOOL WINAPI InternetCheckConnectionA( LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2336 * this is a kludge which runs the resident ping program and reads the output.
2338 * Anyone have a better idea?
2341 BOOL rc = FALSE;
2342 char command[1024];
2343 char host[1024];
2344 int status = -1;
2346 FIXME("\n");
2349 * Crack or set the Address
2351 if (lpszUrl == NULL)
2354 * According to the doc we are supost to use the ip for the next
2355 * server in the WnInet internal server database. I have
2356 * no idea what that is or how to get it.
2358 * So someone needs to implement this.
2360 FIXME("Unimplemented with URL of NULL\n");
2361 return TRUE;
2363 else
2365 URL_COMPONENTSA components;
2367 ZeroMemory(&components,sizeof(URL_COMPONENTSA));
2368 components.lpszHostName = (LPSTR)&host;
2369 components.dwHostNameLength = 1024;
2371 if (!InternetCrackUrlA(lpszUrl,0,0,&components))
2372 goto End;
2374 TRACE("host name : %s\n",components.lpszHostName);
2378 * Build our ping command
2380 strcpy(command,"ping -w 1 ");
2381 strcat(command,host);
2382 strcat(command," >/dev/null 2>/dev/null");
2384 TRACE("Ping command is : %s\n",command);
2386 status = system(command);
2388 TRACE("Ping returned a code of %i \n",status);
2390 /* Ping return code of 0 indicates success */
2391 if (status == 0)
2392 rc = TRUE;
2394 End:
2396 if (rc == FALSE)
2397 SetLastError(ERROR_NOT_CONNECTED);
2399 return rc;
2403 /***********************************************************************
2404 * InternetCheckConnectionW (WININET.@)
2406 * Pings a requested host to check internet connection
2408 * RETURNS
2409 * TRUE on success and FALSE on failure. If a failure then
2410 * ERROR_NOT_CONNECTED is placed into GetLastError
2413 BOOL WINAPI InternetCheckConnectionW(LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2415 CHAR *szUrl;
2416 INT len;
2417 BOOL rc;
2419 len = WideCharToMultiByte(CP_ACP, 0, lpszUrl, -1, NULL, 0, NULL, NULL);
2420 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(CHAR))))
2421 return FALSE;
2422 WideCharToMultiByte(CP_ACP, 0, lpszUrl, -1, szUrl, len, NULL, NULL);
2423 rc = InternetCheckConnectionA((LPCSTR)szUrl, dwFlags, dwReserved);
2424 HeapFree(GetProcessHeap(), 0, szUrl);
2426 return rc;
2430 /**********************************************************
2431 * INTERNET_InternetOpenUrlW (internal)
2433 * Opens an URL
2435 * RETURNS
2436 * handle of connection or NULL on failure
2438 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2439 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2441 URL_COMPONENTSW urlComponents;
2442 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2443 WCHAR password[1024], path[2048], extra[1024];
2444 HINTERNET client = NULL, client1 = NULL;
2446 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2447 dwHeadersLength, dwFlags, dwContext);
2449 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2450 urlComponents.lpszScheme = protocol;
2451 urlComponents.dwSchemeLength = 32;
2452 urlComponents.lpszHostName = hostName;
2453 urlComponents.dwHostNameLength = MAXHOSTNAME;
2454 urlComponents.lpszUserName = userName;
2455 urlComponents.dwUserNameLength = 1024;
2456 urlComponents.lpszPassword = password;
2457 urlComponents.dwPasswordLength = 1024;
2458 urlComponents.lpszUrlPath = path;
2459 urlComponents.dwUrlPathLength = 2048;
2460 urlComponents.lpszExtraInfo = extra;
2461 urlComponents.dwExtraInfoLength = 1024;
2462 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2463 return NULL;
2464 switch(urlComponents.nScheme) {
2465 case INTERNET_SCHEME_FTP:
2466 if(urlComponents.nPort == 0)
2467 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2468 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2469 userName, password, dwFlags, dwContext, INET_OPENURL);
2470 if(client == NULL)
2471 break;
2472 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2473 if(client1 == NULL) {
2474 InternetCloseHandle(client);
2475 break;
2477 break;
2479 case INTERNET_SCHEME_HTTP:
2480 case INTERNET_SCHEME_HTTPS: {
2481 static const WCHAR szStars[] = { '*','/','*', 0 };
2482 LPCWSTR accept[2] = { szStars, NULL };
2483 if(urlComponents.nPort == 0) {
2484 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2485 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2486 else
2487 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2489 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2490 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2491 userName, password, dwFlags, dwContext, INET_OPENURL);
2492 if(client == NULL)
2493 break;
2494 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2495 if(client1 == NULL) {
2496 InternetCloseHandle(client);
2497 break;
2499 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2500 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0)) {
2501 InternetCloseHandle(client1);
2502 client1 = NULL;
2503 break;
2506 case INTERNET_SCHEME_GOPHER:
2507 /* gopher doesn't seem to be implemented in wine, but it's supposed
2508 * to be supported by InternetOpenUrlA. */
2509 default:
2510 break;
2513 TRACE(" %p <--\n", client1);
2515 return client1;
2518 /**********************************************************
2519 * InternetOpenUrlW (WININET.@)
2521 * Opens an URL
2523 * RETURNS
2524 * handle of connection or NULL on failure
2526 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2527 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2529 HINTERNET ret = NULL;
2530 LPWININETAPPINFOW hIC = NULL;
2532 if (TRACE_ON(wininet)) {
2533 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2534 dwHeadersLength, dwFlags, dwContext);
2535 TRACE(" flags :");
2536 dump_INTERNET_FLAGS(dwFlags);
2539 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2540 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2541 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2542 goto lend;
2545 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2546 WORKREQUEST workRequest;
2547 struct WORKREQ_INTERNETOPENURLW *req;
2549 workRequest.asyncall = INTERNETOPENURLW;
2550 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2551 req = &workRequest.u.InternetOpenUrlW;
2552 if (lpszUrl)
2553 req->lpszUrl = WININET_strdupW(lpszUrl);
2554 else
2555 req->lpszUrl = 0;
2556 if (lpszHeaders)
2557 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2558 else
2559 req->lpszHeaders = 0;
2560 req->dwHeadersLength = dwHeadersLength;
2561 req->dwFlags = dwFlags;
2562 req->dwContext = dwContext;
2564 INTERNET_AsyncCall(&workRequest);
2566 * This is from windows.
2568 SetLastError(ERROR_IO_PENDING);
2569 } else {
2570 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2573 lend:
2574 if( hIC )
2575 WININET_Release( &hIC->hdr );
2576 TRACE(" %p <--\n", ret);
2578 return ret;
2581 /**********************************************************
2582 * InternetOpenUrlA (WININET.@)
2584 * Opens an URL
2586 * RETURNS
2587 * handle of connection or NULL on failure
2589 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2590 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2592 HINTERNET rc = (HINTERNET)NULL;
2594 INT lenUrl;
2595 INT lenHeaders = 0;
2596 LPWSTR szUrl = NULL;
2597 LPWSTR szHeaders = NULL;
2599 TRACE("\n");
2601 if(lpszUrl) {
2602 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
2603 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
2604 if(!szUrl)
2605 return (HINTERNET)NULL;
2606 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
2609 if(lpszHeaders) {
2610 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
2611 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
2612 if(!szHeaders) {
2613 HeapFree(GetProcessHeap(), 0, szUrl);
2614 return (HINTERNET)NULL;
2616 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
2619 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
2620 lenHeaders, dwFlags, dwContext);
2622 HeapFree(GetProcessHeap(), 0, szUrl);
2623 HeapFree(GetProcessHeap(), 0, szHeaders);
2625 return rc;
2629 /***********************************************************************
2630 * INTERNET_SetLastError (internal)
2632 * Set last thread specific error
2634 * RETURNS
2637 void INTERNET_SetLastError(DWORD dwError)
2639 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2641 SetLastError(dwError);
2642 if(lpwite)
2643 lpwite->dwError = dwError;
2647 /***********************************************************************
2648 * INTERNET_GetLastError (internal)
2650 * Get last thread specific error
2652 * RETURNS
2655 DWORD INTERNET_GetLastError(void)
2657 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2658 return lpwite->dwError;
2662 /***********************************************************************
2663 * INTERNET_WorkerThreadFunc (internal)
2665 * Worker thread execution function
2667 * RETURNS
2670 static DWORD INTERNET_WorkerThreadFunc(LPVOID *lpvParam)
2672 DWORD dwWaitRes;
2674 while (1)
2676 if(dwNumJobs > 0) {
2677 INTERNET_ExecuteWork();
2678 continue;
2680 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
2682 if (dwWaitRes == WAIT_OBJECT_0 + 1)
2683 INTERNET_ExecuteWork();
2684 else
2685 break;
2687 InterlockedIncrement(&dwNumIdleThreads);
2690 InterlockedDecrement(&dwNumIdleThreads);
2691 InterlockedDecrement(&dwNumThreads);
2692 TRACE("Worker thread exiting\n");
2693 return TRUE;
2697 /***********************************************************************
2698 * INTERNET_InsertWorkRequest (internal)
2700 * Insert work request into queue
2702 * RETURNS
2705 static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
2707 BOOL bSuccess = FALSE;
2708 LPWORKREQUEST lpNewRequest;
2710 TRACE("\n");
2712 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
2713 if (lpNewRequest)
2715 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
2716 lpNewRequest->prev = NULL;
2718 EnterCriticalSection(&csQueue);
2720 lpNewRequest->next = lpWorkQueueTail;
2721 if (lpWorkQueueTail)
2722 lpWorkQueueTail->prev = lpNewRequest;
2723 lpWorkQueueTail = lpNewRequest;
2724 if (!lpHeadWorkQueue)
2725 lpHeadWorkQueue = lpWorkQueueTail;
2727 LeaveCriticalSection(&csQueue);
2729 bSuccess = TRUE;
2730 InterlockedIncrement(&dwNumJobs);
2733 return bSuccess;
2737 /***********************************************************************
2738 * INTERNET_GetWorkRequest (internal)
2740 * Retrieves work request from queue
2742 * RETURNS
2745 static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
2747 BOOL bSuccess = FALSE;
2748 LPWORKREQUEST lpRequest = NULL;
2750 TRACE("\n");
2752 EnterCriticalSection(&csQueue);
2754 if (lpHeadWorkQueue)
2756 lpRequest = lpHeadWorkQueue;
2757 lpHeadWorkQueue = lpHeadWorkQueue->prev;
2758 if (lpRequest == lpWorkQueueTail)
2759 lpWorkQueueTail = lpHeadWorkQueue;
2762 LeaveCriticalSection(&csQueue);
2764 if (lpRequest)
2766 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
2767 HeapFree(GetProcessHeap(), 0, lpRequest);
2768 bSuccess = TRUE;
2769 InterlockedDecrement(&dwNumJobs);
2772 return bSuccess;
2776 /***********************************************************************
2777 * INTERNET_AsyncCall (internal)
2779 * Retrieves work request from queue
2781 * RETURNS
2784 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
2786 HANDLE hThread;
2787 DWORD dwTID;
2788 BOOL bSuccess = FALSE;
2790 TRACE("\n");
2792 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
2794 InterlockedIncrement(&dwNumIdleThreads);
2796 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
2797 !(hThread = CreateThread(NULL, 0,
2798 (LPTHREAD_START_ROUTINE)INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
2800 InterlockedDecrement(&dwNumThreads);
2801 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
2802 goto lerror;
2805 TRACE("Created new thread\n");
2808 bSuccess = TRUE;
2809 INTERNET_InsertWorkRequest(lpWorkRequest);
2810 SetEvent(hWorkEvent);
2812 lerror:
2814 return bSuccess;
2818 /***********************************************************************
2819 * INTERNET_ExecuteWork (internal)
2821 * RETURNS
2824 static VOID INTERNET_ExecuteWork(void)
2826 WORKREQUEST workRequest;
2828 TRACE("\n");
2830 if (!INTERNET_GetWorkRequest(&workRequest))
2831 return;
2833 switch (workRequest.asyncall)
2835 case FTPPUTFILEW:
2837 struct WORKREQ_FTPPUTFILEW *req = &workRequest.u.FtpPutFileW;
2838 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2840 TRACE("FTPPUTFILEW %p\n", lpwfs);
2842 FTP_FtpPutFileW(lpwfs, req->lpszLocalFile,
2843 req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
2845 HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
2846 HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
2848 break;
2850 case FTPSETCURRENTDIRECTORYW:
2852 struct WORKREQ_FTPSETCURRENTDIRECTORYW *req;
2853 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2855 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs);
2857 req = &workRequest.u.FtpSetCurrentDirectoryW;
2858 FTP_FtpSetCurrentDirectoryW(lpwfs, req->lpszDirectory);
2859 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
2861 break;
2863 case FTPCREATEDIRECTORYW:
2865 struct WORKREQ_FTPCREATEDIRECTORYW *req;
2866 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2868 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs);
2870 req = &workRequest.u.FtpCreateDirectoryW;
2871 FTP_FtpCreateDirectoryW(lpwfs, req->lpszDirectory);
2872 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
2874 break;
2876 case FTPFINDFIRSTFILEW:
2878 struct WORKREQ_FTPFINDFIRSTFILEW *req;
2879 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2881 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs);
2883 req = &workRequest.u.FtpFindFirstFileW;
2884 FTP_FtpFindFirstFileW(lpwfs, req->lpszSearchFile,
2885 req->lpFindFileData, req->dwFlags, req->dwContext);
2886 HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
2888 break;
2890 case FTPGETCURRENTDIRECTORYW:
2892 struct WORKREQ_FTPGETCURRENTDIRECTORYW *req;
2893 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2895 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs);
2897 req = &workRequest.u.FtpGetCurrentDirectoryW;
2898 FTP_FtpGetCurrentDirectoryW(lpwfs,
2899 req->lpszDirectory, req->lpdwDirectory);
2901 break;
2903 case FTPOPENFILEW:
2905 struct WORKREQ_FTPOPENFILEW *req = &workRequest.u.FtpOpenFileW;
2906 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2908 TRACE("FTPOPENFILEW %p\n", lpwfs);
2910 FTP_FtpOpenFileW(lpwfs, req->lpszFilename,
2911 req->dwAccess, req->dwFlags, req->dwContext);
2912 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
2914 break;
2916 case FTPGETFILEW:
2918 struct WORKREQ_FTPGETFILEW *req = &workRequest.u.FtpGetFileW;
2919 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2921 TRACE("FTPGETFILEW %p\n", lpwfs);
2923 FTP_FtpGetFileW(lpwfs, req->lpszRemoteFile,
2924 req->lpszNewFile, req->fFailIfExists,
2925 req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
2926 HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
2927 HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
2929 break;
2931 case FTPDELETEFILEW:
2933 struct WORKREQ_FTPDELETEFILEW *req = &workRequest.u.FtpDeleteFileW;
2934 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2936 TRACE("FTPDELETEFILEW %p\n", lpwfs);
2938 FTP_FtpDeleteFileW(lpwfs, req->lpszFilename);
2939 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
2941 break;
2943 case FTPREMOVEDIRECTORYW:
2945 struct WORKREQ_FTPREMOVEDIRECTORYW *req;
2946 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2948 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs);
2950 req = &workRequest.u.FtpRemoveDirectoryW;
2951 FTP_FtpRemoveDirectoryW(lpwfs, req->lpszDirectory);
2952 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
2954 break;
2956 case FTPRENAMEFILEW:
2958 struct WORKREQ_FTPRENAMEFILEW *req = &workRequest.u.FtpRenameFileW;
2959 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2961 TRACE("FTPRENAMEFILEW %p\n", lpwfs);
2963 FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
2964 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
2965 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
2967 break;
2969 case INTERNETFINDNEXTW:
2971 struct WORKREQ_INTERNETFINDNEXTW *req;
2972 LPWININETFINDNEXTW lpwh = (LPWININETFINDNEXTW) workRequest.hdr;
2974 TRACE("INTERNETFINDNEXTW %p\n", lpwh);
2976 req = &workRequest.u.InternetFindNextW;
2977 INTERNET_FindNextFileW(lpwh, req->lpFindFileData);
2979 break;
2981 case HTTPSENDREQUESTW:
2983 struct WORKREQ_HTTPSENDREQUESTW *req = &workRequest.u.HttpSendRequestW;
2984 LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) workRequest.hdr;
2986 TRACE("HTTPSENDREQUESTW %p\n", lpwhr);
2988 HTTP_HttpSendRequestW(lpwhr, req->lpszHeader,
2989 req->dwHeaderLength, req->lpOptional, req->dwOptionalLength);
2991 HeapFree(GetProcessHeap(), 0, req->lpszHeader);
2993 break;
2995 case HTTPOPENREQUESTW:
2997 struct WORKREQ_HTTPOPENREQUESTW *req = &workRequest.u.HttpOpenRequestW;
2998 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) workRequest.hdr;
3000 TRACE("HTTPOPENREQUESTW %p\n", lpwhs);
3002 HTTP_HttpOpenRequestW(lpwhs, req->lpszVerb,
3003 req->lpszObjectName, req->lpszVersion, req->lpszReferrer,
3004 req->lpszAcceptTypes, req->dwFlags, req->dwContext);
3006 HeapFree(GetProcessHeap(), 0, req->lpszVerb);
3007 HeapFree(GetProcessHeap(), 0, req->lpszObjectName);
3008 HeapFree(GetProcessHeap(), 0, req->lpszVersion);
3009 HeapFree(GetProcessHeap(), 0, req->lpszReferrer);
3011 break;
3013 case SENDCALLBACK:
3015 struct WORKREQ_SENDCALLBACK *req = &workRequest.u.SendCallback;
3017 TRACE("SENDCALLBACK %p\n", workRequest.hdr);
3019 SendSyncCallback(workRequest.hdr,
3020 req->dwContext, req->dwInternetStatus, req->lpvStatusInfo,
3021 req->dwStatusInfoLength);
3023 /* And frees the copy of the status info */
3024 HeapFree(GetProcessHeap(), 0, req->lpvStatusInfo);
3026 break;
3028 case INTERNETOPENURLW:
3030 struct WORKREQ_INTERNETOPENURLW *req = &workRequest.u.InternetOpenUrlW;
3031 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest.hdr;
3033 TRACE("INTERNETOPENURLW %p\n", hIC);
3035 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3036 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3037 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3038 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3040 break;
3042 WININET_Release( workRequest.hdr );
3046 /***********************************************************************
3047 * INTERNET_GetResponseBuffer
3049 * RETURNS
3052 LPSTR INTERNET_GetResponseBuffer(void)
3054 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3055 TRACE("\n");
3056 return lpwite->response;
3059 /***********************************************************************
3060 * INTERNET_GetNextLine (internal)
3062 * Parse next line in directory string listing
3064 * RETURNS
3065 * Pointer to beginning of next line
3066 * NULL on failure
3070 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3072 struct timeval tv;
3073 fd_set infd;
3074 BOOL bSuccess = FALSE;
3075 INT nRecv = 0;
3076 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3078 TRACE("\n");
3080 FD_ZERO(&infd);
3081 FD_SET(nSocket, &infd);
3082 tv.tv_sec=RESPONSE_TIMEOUT;
3083 tv.tv_usec=0;
3085 while (nRecv < MAX_REPLY_LEN)
3087 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3089 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3091 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3092 goto lend;
3095 if (lpszBuffer[nRecv] == '\n')
3097 bSuccess = TRUE;
3098 break;
3100 if (lpszBuffer[nRecv] != '\r')
3101 nRecv++;
3103 else
3105 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3106 goto lend;
3110 lend:
3111 if (bSuccess)
3113 lpszBuffer[nRecv] = '\0';
3114 *dwLen = nRecv - 1;
3115 TRACE(":%d %s\n", nRecv, lpszBuffer);
3116 return lpszBuffer;
3118 else
3120 return NULL;
3124 /***********************************************************************
3127 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3128 LPDWORD lpdwNumberOfBytesAvailble,
3129 DWORD dwFlags, DWORD dwConext)
3131 LPWININETHTTPREQW lpwhr;
3132 INT retval = -1;
3133 char buffer[4048];
3135 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3136 if (NULL == lpwhr)
3138 SetLastError(ERROR_NO_MORE_FILES);
3139 return FALSE;
3142 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3144 switch (lpwhr->hdr.htype)
3146 case WH_HHTTPREQ:
3147 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3148 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3150 SetLastError(ERROR_NO_MORE_FILES);
3151 retval = FALSE;
3153 else
3154 retval = TRUE;
3155 break;
3157 default:
3158 FIXME("unsupported file type\n");
3159 break;
3161 WININET_Release( &lpwhr->hdr );
3163 TRACE("<-- %i\n",retval);
3164 return (retval+1);
3168 /***********************************************************************
3171 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3172 *lphLockReqHandle)
3174 FIXME("STUB\n");
3175 return FALSE;
3178 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3180 FIXME("STUB\n");
3181 return FALSE;
3185 /***********************************************************************
3186 * InternetAutodial
3188 * On windows this function is supposed to dial the default internet
3189 * connection. We don't want to have Wine dial out to the internet so
3190 * we return TRUE by default. It might be nice to check if we are connected.
3192 * RETURNS
3193 * TRUE on success
3194 * FALSE on failure
3197 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3199 FIXME("STUB\n");
3201 /* Tell that we are connected to the internet. */
3202 return TRUE;
3205 /***********************************************************************
3206 * InternetAutodialHangup
3208 * Hangs up a connection made with InternetAutodial
3210 * PARAM
3211 * dwReserved
3212 * RETURNS
3213 * TRUE on success
3214 * FALSE on failure
3217 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3219 FIXME("STUB\n");
3221 /* we didn't dial, we don't disconnect */
3222 return TRUE;
3225 /***********************************************************************
3227 * InternetCombineUrlA
3229 * Combine a base URL with a relative URL
3231 * RETURNS
3232 * TRUE on success
3233 * FALSE on failure
3237 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3238 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3239 DWORD dwFlags)
3241 HRESULT hr=S_OK;
3243 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3245 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3246 dwFlags ^= ICU_NO_ENCODE;
3247 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3249 return (hr==S_OK);
3252 /***********************************************************************
3254 * InternetCombineUrlW
3256 * Combine a base URL with a relative URL
3258 * RETURNS
3259 * TRUE on success
3260 * FALSE on failure
3264 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3265 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3266 DWORD dwFlags)
3268 HRESULT hr=S_OK;
3270 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3272 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3273 dwFlags ^= ICU_NO_ENCODE;
3274 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3276 return (hr==S_OK);
3279 /***********************************************************************
3281 * InternetCreateUrlA
3283 * RETURNS
3284 * TRUE on success
3285 * FALSE on failure
3288 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3289 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3291 FIXME("\n");
3292 return FALSE;
3295 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3297 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3298 return ERROR_SUCCESS;
3301 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3303 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3304 return ERROR_SUCCESS;
3307 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3308 LPDWORD lpdwConnection, DWORD dwReserved )
3310 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
3311 lpdwConnection, dwReserved);
3312 return ERROR_SUCCESS;
3315 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3316 LPDWORD lpdwConnection, DWORD dwReserved )
3318 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
3319 lpdwConnection, dwReserved);
3320 return ERROR_SUCCESS;
3323 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3325 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3326 return TRUE;
3329 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3331 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3332 return TRUE;
3335 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
3337 FIXME("(0x%08lx, 0x%08lx) stub\n", dwConnection, dwReserved);
3338 return ERROR_SUCCESS;
3341 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3342 PBYTE pbHexHash )
3344 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3345 debugstr_w(pwszTarget), pbHexHash);
3346 return FALSE;
3349 BOOL WINAPI InternetClearAllPerSiteCookieDecisions( VOID )
3351 FIXME("stub\n");
3352 return TRUE;
3355 BOOL WINAPI InternetEnumPerSiteCookieDecisionA( LPSTR pszSiteName, unsigned long *pcSiteNameSize,
3356 unsigned long *pdwDecision, unsigned long dwIndex )
3358 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
3359 debugstr_a(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
3360 return FALSE;
3363 BOOL WINAPI InternetEnumPerSiteCookieDecisionW( LPWSTR pszSiteName, unsigned long *pcSiteNameSize,
3364 unsigned long *pdwDecision, unsigned long dwIndex )
3366 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
3367 debugstr_w(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
3368 return FALSE;
3371 BOOL WINAPI InternetGetCookieExA( LPCSTR pchURL, LPCSTR pchCookieName, LPSTR pchCookieData,
3372 LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
3374 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
3375 debugstr_a(pchURL), debugstr_a(pchCookieName), debugstr_a(pchCookieData),
3376 pcchCookieData, dwFlags, lpReserved);
3377 return FALSE;
3380 BOOL WINAPI InternetGetCookieExW( LPCWSTR pchURL, LPCWSTR pchCookieName, LPWSTR pchCookieData,
3381 LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
3383 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
3384 debugstr_w(pchURL), debugstr_w(pchCookieName), debugstr_w(pchCookieData),
3385 pcchCookieData, dwFlags, lpReserved);
3386 return FALSE;
3389 BOOL WINAPI InternetGetPerSiteCookieDecisionA( LPCSTR pwchHostName, unsigned long *pResult )
3391 FIXME("(%s, %p) stub\n", debugstr_a(pwchHostName), pResult);
3392 return FALSE;
3395 BOOL WINAPI InternetGetPerSiteCookieDecisionW( LPCWSTR pwchHostName, unsigned long *pResult )
3397 FIXME("(%s, %p) stub\n", debugstr_w(pwchHostName), pResult);
3398 return FALSE;
3401 BOOL WINAPI InternetSetPerSiteCookieDecisionA( LPCSTR pchHostName, DWORD dwDecision )
3403 FIXME("(%s, 0x%08lx) stub\n", debugstr_a(pchHostName), dwDecision);
3404 return FALSE;
3407 BOOL WINAPI InternetSetPerSiteCookieDecisionW( LPCWSTR pchHostName, DWORD dwDecision )
3409 FIXME("(%s, 0x%08lx) stub\n", debugstr_w(pchHostName), dwDecision);
3410 return FALSE;
3413 DWORD WINAPI InternetSetCookieExA( LPCSTR lpszURL, LPCSTR lpszCookieName, LPCSTR lpszCookieData,
3414 DWORD dwFlags, DWORD_PTR dwReserved)
3416 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
3417 debugstr_a(lpszURL), debugstr_a(lpszCookieName), debugstr_a(lpszCookieData),
3418 dwFlags, dwReserved);
3419 return TRUE;
3422 DWORD WINAPI InternetSetCookieExW( LPCWSTR lpszURL, LPCWSTR lpszCookieName, LPCWSTR lpszCookieData,
3423 DWORD dwFlags, DWORD_PTR dwReserved)
3425 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
3426 debugstr_w(lpszURL), debugstr_w(lpszCookieName), debugstr_w(lpszCookieData),
3427 dwFlags, dwReserved);
3428 return TRUE;
3431 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3433 FIXME("(%p, 0x%08lx) stub\n", hInternet, dwError);
3434 return FALSE;
3437 /***********************************************************************
3439 * InternetCreateUrlW
3441 * RETURNS
3442 * TRUE on success
3443 * FALSE on failure
3446 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3447 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3449 FIXME("\n");
3450 return FALSE;
3453 /***********************************************************************
3454 * dump_INTERNET_FLAGS
3456 * Helper function to TRACE the internet flags.
3458 * RETURNS
3459 * None
3462 void dump_INTERNET_FLAGS(DWORD dwFlags)
3464 #define FE(x) { x, #x }
3465 static const wininet_flag_info flag[] = {
3466 FE(INTERNET_FLAG_RELOAD),
3467 FE(INTERNET_FLAG_RAW_DATA),
3468 FE(INTERNET_FLAG_EXISTING_CONNECT),
3469 FE(INTERNET_FLAG_ASYNC),
3470 FE(INTERNET_FLAG_PASSIVE),
3471 FE(INTERNET_FLAG_NO_CACHE_WRITE),
3472 FE(INTERNET_FLAG_MAKE_PERSISTENT),
3473 FE(INTERNET_FLAG_FROM_CACHE),
3474 FE(INTERNET_FLAG_SECURE),
3475 FE(INTERNET_FLAG_KEEP_CONNECTION),
3476 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
3477 FE(INTERNET_FLAG_READ_PREFETCH),
3478 FE(INTERNET_FLAG_NO_COOKIES),
3479 FE(INTERNET_FLAG_NO_AUTH),
3480 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
3481 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
3482 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
3483 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
3484 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
3485 FE(INTERNET_FLAG_RESYNCHRONIZE),
3486 FE(INTERNET_FLAG_HYPERLINK),
3487 FE(INTERNET_FLAG_NO_UI),
3488 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
3489 FE(INTERNET_FLAG_CACHE_ASYNC),
3490 FE(INTERNET_FLAG_FORMS_SUBMIT),
3491 FE(INTERNET_FLAG_NEED_FILE),
3492 FE(INTERNET_FLAG_TRANSFER_ASCII),
3493 FE(INTERNET_FLAG_TRANSFER_BINARY)
3495 #undef FE
3496 int i;
3498 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
3499 if (flag[i].val & dwFlags) {
3500 TRACE(" %s", flag[i].name);
3501 dwFlags &= ~flag[i].val;
3504 if (dwFlags)
3505 TRACE(" Unknown flags (%08lx)\n", dwFlags);
3506 else
3507 TRACE("\n");