Handle CBR_BLOCK in EXECUTE and ADVISE DDE transactions.
[wine/hacks.git] / dlls / wininet / internet.c
blobc63182639238e3a71d480ecb5711e1e79fa7eb45
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 strncpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
604 *lpdwBufferLength = strlen(lpszBuffer);
606 else
607 *lpdwBufferLength = 0;
609 return TRUE;
613 /***********************************************************************
614 * InternetGetConnectedState (WININET.@)
616 * Return connected state
618 * RETURNS
619 * TRUE if connected
620 * if lpdwStatus is not null, return the status (off line,
621 * modem, lan...) in it.
622 * FALSE if not connected
624 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
626 TRACE("(%p, 0x%08lx)\n", lpdwStatus, dwReserved);
628 if (lpdwStatus) {
629 FIXME("always returning LAN connection.\n");
630 *lpdwStatus = INTERNET_CONNECTION_LAN;
632 return TRUE;
636 /***********************************************************************
637 * InternetGetConnectedStateExW (WININET.@)
639 * Return connected state
641 * PARAMS
643 * lpdwStatus [O] Flags specifying the status of the internet connection.
644 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
645 * dwNameLen [I] Size of the buffer, in characters.
646 * dwReserved [I] Reserved. Must be set to 0.
648 * RETURNS
649 * TRUE if connected
650 * if lpdwStatus is not null, return the status (off line,
651 * modem, lan...) in it.
652 * FALSE if not connected
654 * NOTES
655 * If the system has no available network connections, an empty string is
656 * stored in lpszConnectionName. If there is a LAN connection, a localized
657 * "LAN Connection" string is stored. Presumably, if only a dial-up
658 * connection is available then the name of the dial-up connection is
659 * returned. Why any application, other than the "Internet Settings" CPL,
660 * would want to use this function instead of the simpler InternetGetConnectedStateW
661 * function is beyond me.
663 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
664 DWORD dwNameLen, DWORD dwReserved)
666 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
668 /* Must be zero */
669 if(dwReserved)
670 return FALSE;
672 if (lpdwStatus) {
673 FIXME("always returning LAN connection.\n");
674 *lpdwStatus = INTERNET_CONNECTION_LAN;
676 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
680 /***********************************************************************
681 * InternetGetConnectedStateExA (WININET.@)
683 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
684 DWORD dwNameLen, DWORD dwReserved)
686 LPWSTR lpwszConnectionName = NULL;
687 BOOL rc;
689 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
691 if (lpszConnectionName && dwNameLen > 0)
692 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
694 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
695 dwReserved);
696 if (rc && lpwszConnectionName)
698 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
699 dwNameLen, NULL, NULL);
701 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
704 return rc;
708 /***********************************************************************
709 * InternetConnectW (WININET.@)
711 * Open a ftp, gopher or http session
713 * RETURNS
714 * HINTERNET a session handle on success
715 * NULL on failure
718 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
719 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
720 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
721 DWORD dwService, DWORD dwFlags, DWORD dwContext)
723 LPWININETAPPINFOW hIC;
724 HINTERNET rc = (HINTERNET) NULL;
726 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet, debugstr_w(lpszServerName),
727 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
728 dwService, dwFlags, dwContext);
730 /* Clear any error information */
731 INTERNET_SetLastError(0);
732 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
733 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
734 goto lend;
736 switch (dwService)
738 case INTERNET_SERVICE_FTP:
739 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
740 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
741 break;
743 case INTERNET_SERVICE_HTTP:
744 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
745 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
746 break;
748 case INTERNET_SERVICE_GOPHER:
749 default:
750 break;
752 lend:
753 if( hIC )
754 WININET_Release( &hIC->hdr );
756 TRACE("returning %p\n", rc);
757 return rc;
761 /***********************************************************************
762 * InternetConnectA (WININET.@)
764 * Open a ftp, gopher or http session
766 * RETURNS
767 * HINTERNET a session handle on success
768 * NULL on failure
771 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
772 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
773 LPCSTR lpszUserName, LPCSTR lpszPassword,
774 DWORD dwService, DWORD dwFlags, DWORD dwContext)
776 HINTERNET rc = (HINTERNET)NULL;
777 INT len = 0;
778 LPWSTR szServerName = NULL;
779 LPWSTR szUserName = NULL;
780 LPWSTR szPassword = NULL;
782 if (lpszServerName)
784 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
785 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
786 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
788 if (lpszUserName)
790 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
791 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
792 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
794 if (lpszPassword)
796 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
797 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
798 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
802 rc = InternetConnectW(hInternet, szServerName, nServerPort,
803 szUserName, szPassword, dwService, dwFlags, dwContext);
805 HeapFree(GetProcessHeap(), 0, szServerName);
806 HeapFree(GetProcessHeap(), 0, szUserName);
807 HeapFree(GetProcessHeap(), 0, szPassword);
808 return rc;
812 /***********************************************************************
813 * InternetFindNextFileA (WININET.@)
815 * Continues a file search from a previous call to FindFirstFile
817 * RETURNS
818 * TRUE on success
819 * FALSE on failure
822 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
824 BOOL ret;
825 WIN32_FIND_DATAW fd;
827 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
828 if(lpvFindData)
829 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
830 return ret;
833 /***********************************************************************
834 * InternetFindNextFileW (WININET.@)
836 * Continues a file search from a previous call to FindFirstFile
838 * RETURNS
839 * TRUE on success
840 * FALSE on failure
843 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
845 LPWININETAPPINFOW hIC = NULL;
846 LPWININETFINDNEXTW lpwh;
847 BOOL bSuccess = FALSE;
849 TRACE("\n");
851 lpwh = (LPWININETFINDNEXTW) WININET_GetObject( hFind );
852 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
854 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
855 goto lend;
858 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
859 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
861 WORKREQUEST workRequest;
862 struct WORKREQ_INTERNETFINDNEXTW *req;
864 workRequest.asyncall = INTERNETFINDNEXTW;
865 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
866 req = &workRequest.u.InternetFindNextW;
867 req->lpFindFileData = lpvFindData;
869 bSuccess = INTERNET_AsyncCall(&workRequest);
871 else
873 bSuccess = INTERNET_FindNextFileW(lpwh, lpvFindData);
875 lend:
876 if( lpwh )
877 WININET_Release( &lpwh->hdr );
878 return bSuccess;
881 /***********************************************************************
882 * INTERNET_FindNextFileW (Internal)
884 * Continues a file search from a previous call to FindFirstFile
886 * RETURNS
887 * TRUE on success
888 * FALSE on failure
891 BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData)
893 BOOL bSuccess = TRUE;
894 LPWIN32_FIND_DATAW lpFindFileData;
896 TRACE("\n");
898 assert (lpwh->hdr.htype == WH_HFINDNEXT);
900 /* Clear any error information */
901 INTERNET_SetLastError(0);
903 if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
905 FIXME("Only FTP find next supported\n");
906 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
907 return FALSE;
910 TRACE("index(%ld) size(%ld)\n", lpwh->index, lpwh->size);
912 lpFindFileData = (LPWIN32_FIND_DATAW) lpvFindData;
913 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
915 if (lpwh->index >= lpwh->size)
917 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
918 bSuccess = FALSE;
919 goto lend;
922 FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
923 lpwh->index++;
925 TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData->cFileName), lpFindFileData->nFileSizeLow);
927 lend:
929 if (lpwh->hdr.dwFlags & INTERNET_FLAG_ASYNC && lpwh->hdr.lpfnStatusCB)
931 INTERNET_ASYNC_RESULT iar;
933 iar.dwResult = (DWORD)bSuccess;
934 iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
935 INTERNET_GetLastError();
937 SendAsyncCallback(&lpwh->hdr, lpwh->hdr.dwContext,
938 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
939 sizeof(INTERNET_ASYNC_RESULT));
942 return bSuccess;
946 /***********************************************************************
947 * INTERNET_CloseHandle (internal)
949 * Close internet handle
951 * RETURNS
952 * Void
955 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
957 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
959 TRACE("%p\n",lpwai);
961 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
962 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
963 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
964 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
965 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
966 HeapFree(GetProcessHeap(), 0, lpwai);
970 /***********************************************************************
971 * InternetCloseHandle (WININET.@)
973 * Generic close handle function
975 * RETURNS
976 * TRUE on success
977 * FALSE on failure
980 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
982 LPWININETHANDLEHEADER lpwh;
984 TRACE("%p\n",hInternet);
986 lpwh = WININET_GetObject( hInternet );
987 if (NULL == lpwh)
989 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
990 return FALSE;
993 SendAsyncCallback(lpwh, lpwh->dwContext,
994 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
995 sizeof(HINTERNET*));
997 if( lpwh->lpwhparent )
998 WININET_Release( lpwh->lpwhparent );
999 WININET_FreeHandle( hInternet );
1000 WININET_Release( lpwh );
1002 return TRUE;
1006 /***********************************************************************
1007 * ConvertUrlComponentValue (Internal)
1009 * Helper function for InternetCrackUrlW
1012 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1013 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1014 LPCSTR lpszStart, LPCWSTR lpwszStart)
1016 if (*dwComponentLen != 0)
1018 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1019 if (*lppszComponent == NULL)
1021 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1022 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1023 *dwComponentLen = nASCIILength;
1025 else
1027 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1028 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1029 (*lppszComponent)[ncpylen]=0;
1030 *dwComponentLen = ncpylen;
1036 /***********************************************************************
1037 * InternetCrackUrlA (WININET.@)
1039 * Break up URL into its components
1041 * TODO: Handle dwFlags
1043 * RETURNS
1044 * TRUE on success
1045 * FALSE on failure
1048 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1049 LPURL_COMPONENTSA lpUrlComponents)
1051 DWORD nLength;
1052 URL_COMPONENTSW UCW;
1053 WCHAR* lpwszUrl;
1055 if(dwUrlLength<=0)
1056 dwUrlLength=-1;
1057 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1058 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1059 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1061 memset(&UCW,0,sizeof(UCW));
1062 if(lpUrlComponents->dwHostNameLength!=0)
1063 UCW.dwHostNameLength=1;
1064 if(lpUrlComponents->dwUserNameLength!=0)
1065 UCW.dwUserNameLength=1;
1066 if(lpUrlComponents->dwPasswordLength!=0)
1067 UCW.dwPasswordLength=1;
1068 if(lpUrlComponents->dwUrlPathLength!=0)
1069 UCW.dwUrlPathLength=1;
1070 if(lpUrlComponents->dwSchemeLength!=0)
1071 UCW.dwSchemeLength=1;
1072 if(lpUrlComponents->dwExtraInfoLength!=0)
1073 UCW.dwExtraInfoLength=1;
1074 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1076 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1077 return FALSE;
1080 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1081 UCW.lpszHostName, UCW.dwHostNameLength,
1082 lpszUrl, lpwszUrl);
1083 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1084 UCW.lpszUserName, UCW.dwUserNameLength,
1085 lpszUrl, lpwszUrl);
1086 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1087 UCW.lpszPassword, UCW.dwPasswordLength,
1088 lpszUrl, lpwszUrl);
1089 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1090 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1091 lpszUrl, lpwszUrl);
1092 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1093 UCW.lpszScheme, UCW.dwSchemeLength,
1094 lpszUrl, lpwszUrl);
1095 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1096 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1097 lpszUrl, lpwszUrl);
1098 lpUrlComponents->nScheme=UCW.nScheme;
1099 lpUrlComponents->nPort=UCW.nPort;
1100 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1102 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1103 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1104 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1105 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1106 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1108 return TRUE;
1111 /***********************************************************************
1112 * GetInternetSchemeW (internal)
1114 * Get scheme of url
1116 * RETURNS
1117 * scheme on success
1118 * INTERNET_SCHEME_UNKNOWN on failure
1121 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1123 INTERNET_SCHEME iScheme=INTERNET_SCHEME_UNKNOWN;
1124 static const WCHAR lpszFtp[]={'f','t','p',0};
1125 static const WCHAR lpszGopher[]={'g','o','p','h','e','r',0};
1126 static const WCHAR lpszHttp[]={'h','t','t','p',0};
1127 static const WCHAR lpszHttps[]={'h','t','t','p','s',0};
1128 static const WCHAR lpszFile[]={'f','i','l','e',0};
1129 static const WCHAR lpszNews[]={'n','e','w','s',0};
1130 static const WCHAR lpszMailto[]={'m','a','i','l','t','o',0};
1131 static const WCHAR lpszRes[]={'r','e','s',0};
1132 WCHAR* tempBuffer=NULL;
1133 TRACE("\n");
1134 if(lpszScheme==NULL)
1135 return INTERNET_SCHEME_UNKNOWN;
1137 tempBuffer=HeapAlloc(GetProcessHeap(),0,(nMaxCmp+1)*sizeof(WCHAR));
1138 strncpyW(tempBuffer,lpszScheme,nMaxCmp);
1139 tempBuffer[nMaxCmp]=0;
1140 strlwrW(tempBuffer);
1141 if (nMaxCmp==strlenW(lpszFtp) && !strncmpW(lpszFtp, tempBuffer, nMaxCmp))
1142 iScheme=INTERNET_SCHEME_FTP;
1143 else if (nMaxCmp==strlenW(lpszGopher) && !strncmpW(lpszGopher, tempBuffer, nMaxCmp))
1144 iScheme=INTERNET_SCHEME_GOPHER;
1145 else if (nMaxCmp==strlenW(lpszHttp) && !strncmpW(lpszHttp, tempBuffer, nMaxCmp))
1146 iScheme=INTERNET_SCHEME_HTTP;
1147 else if (nMaxCmp==strlenW(lpszHttps) && !strncmpW(lpszHttps, tempBuffer, nMaxCmp))
1148 iScheme=INTERNET_SCHEME_HTTPS;
1149 else if (nMaxCmp==strlenW(lpszFile) && !strncmpW(lpszFile, tempBuffer, nMaxCmp))
1150 iScheme=INTERNET_SCHEME_FILE;
1151 else if (nMaxCmp==strlenW(lpszNews) && !strncmpW(lpszNews, tempBuffer, nMaxCmp))
1152 iScheme=INTERNET_SCHEME_NEWS;
1153 else if (nMaxCmp==strlenW(lpszMailto) && !strncmpW(lpszMailto, tempBuffer, nMaxCmp))
1154 iScheme=INTERNET_SCHEME_MAILTO;
1155 else if (nMaxCmp==strlenW(lpszRes) && !strncmpW(lpszRes, tempBuffer, nMaxCmp))
1156 iScheme=INTERNET_SCHEME_RES;
1157 HeapFree(GetProcessHeap(),0,tempBuffer);
1158 return iScheme;
1161 /***********************************************************************
1162 * SetUrlComponentValueW (Internal)
1164 * Helper function for InternetCrackUrlW
1166 * RETURNS
1167 * TRUE on success
1168 * FALSE on failure
1171 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1173 TRACE("%s (%ld)\n", debugstr_wn(lpszStart,len), len);
1175 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1176 return FALSE;
1178 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1180 if (*lppszComponent == NULL)
1182 *lppszComponent = (LPWSTR)lpszStart;
1183 *dwComponentLen = len;
1185 else
1187 DWORD ncpylen = min((*dwComponentLen)-1, len);
1188 strncpyW(*lppszComponent, lpszStart, ncpylen);
1189 (*lppszComponent)[ncpylen] = '\0';
1190 *dwComponentLen = ncpylen;
1194 return TRUE;
1197 /***********************************************************************
1198 * InternetCrackUrlW (WININET.@)
1200 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1201 LPURL_COMPONENTSW lpUC)
1204 * RFC 1808
1205 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1208 LPCWSTR lpszParam = NULL;
1209 BOOL bIsAbsolute = FALSE;
1210 LPCWSTR lpszap = lpszUrl;
1211 LPCWSTR lpszcp = NULL;
1212 const WCHAR lpszSeparators[3]={';','?',0};
1213 const WCHAR lpszSlash[2]={'/',0};
1214 if(dwUrlLength==0)
1215 dwUrlLength=strlenW(lpszUrl);
1217 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1219 /* Determine if the URI is absolute. */
1220 while (*lpszap != '\0')
1222 if (isalnumW(*lpszap))
1224 lpszap++;
1225 continue;
1227 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1229 bIsAbsolute = TRUE;
1230 lpszcp = lpszap;
1232 else
1234 lpszcp = lpszUrl; /* Relative url */
1237 break;
1240 /* Parse <params> */
1241 lpszParam = strpbrkW(lpszap, lpszSeparators);
1242 if (lpszParam != NULL)
1244 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1245 lpszParam, dwUrlLength-(lpszParam-lpszUrl));
1248 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1250 LPCWSTR lpszNetLoc;
1251 static const WCHAR wszAbout[]={'a','b','o','u','t',':',0};
1253 /* Get scheme first. */
1254 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1255 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1256 lpszUrl, lpszcp - lpszUrl);
1258 /* Eat ':' in protocol. */
1259 lpszcp++;
1261 /* if the scheme is "about", there is no host */
1262 if(strncmpW(wszAbout,lpszUrl, lpszcp - lpszUrl)==0)
1264 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1265 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1266 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1267 lpUC->nPort = 0;
1269 else
1271 /* Skip over slashes. */
1272 if (*lpszcp == '/')
1274 lpszcp++;
1275 if (*lpszcp == '/')
1277 lpszcp++;
1278 if (*lpszcp == '/')
1279 lpszcp++;
1283 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1284 if (lpszParam)
1286 if (lpszNetLoc)
1287 lpszNetLoc = min(lpszNetLoc, lpszParam);
1288 else
1289 lpszNetLoc = lpszParam;
1291 else if (!lpszNetLoc)
1292 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1294 /* Parse net-loc */
1295 if (lpszNetLoc)
1297 LPCWSTR lpszHost;
1298 LPCWSTR lpszPort;
1300 /* [<user>[<:password>]@]<host>[:<port>] */
1301 /* First find the user and password if they exist */
1303 lpszHost = strchrW(lpszcp, '@');
1304 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1306 /* username and password not specified. */
1307 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1308 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1310 else /* Parse out username and password */
1312 LPCWSTR lpszUser = lpszcp;
1313 LPCWSTR lpszPasswd = lpszHost;
1315 while (lpszcp < lpszHost)
1317 if (*lpszcp == ':')
1318 lpszPasswd = lpszcp;
1320 lpszcp++;
1323 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1324 lpszUser, lpszPasswd - lpszUser);
1326 if (lpszPasswd != lpszHost)
1327 lpszPasswd++;
1328 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1329 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1330 lpszHost - lpszPasswd);
1332 lpszcp++; /* Advance to beginning of host */
1335 /* Parse <host><:port> */
1337 lpszHost = lpszcp;
1338 lpszPort = lpszNetLoc;
1340 /* special case for res:// URLs: there is no port here, so the host is the
1341 entire string up to the first '/' */
1342 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1344 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1345 lpszHost, lpszPort - lpszHost);
1346 lpUC->nPort = 0;
1347 lpszcp=lpszNetLoc;
1349 else
1351 while (lpszcp < lpszNetLoc)
1353 if (*lpszcp == ':')
1354 lpszPort = lpszcp;
1356 lpszcp++;
1359 /* If the scheme is "file" and the host is just one letter, it's not a host */
1360 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1362 lpszcp=lpszHost;
1363 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1364 NULL, 0);
1365 lpUC->nPort = 0;
1367 else
1369 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1370 lpszHost, lpszPort - lpszHost);
1371 if (lpszPort != lpszNetLoc)
1372 lpUC->nPort = atoiW(++lpszPort);
1373 else
1374 lpUC->nPort = 0;
1381 /* Here lpszcp points to:
1383 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1384 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1386 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1388 INT len;
1390 /* Only truncate the parameter list if it's already been saved
1391 * in lpUC->lpszExtraInfo.
1393 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1394 len = lpszParam - lpszcp;
1395 else
1397 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1398 * newlines if necessary.
1400 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1401 if (lpsznewline != NULL)
1402 len = lpsznewline - lpszcp;
1403 else
1404 len = dwUrlLength-(lpszcp-lpszUrl);
1407 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1408 lpszcp, len);
1410 else
1412 lpUC->dwUrlPathLength = 0;
1415 TRACE("%s: host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1416 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1417 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1418 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1420 return TRUE;
1423 /***********************************************************************
1424 * InternetAttemptConnect (WININET.@)
1426 * Attempt to make a connection to the internet
1428 * RETURNS
1429 * ERROR_SUCCESS on success
1430 * Error value on failure
1433 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1435 FIXME("Stub\n");
1436 return ERROR_SUCCESS;
1440 /***********************************************************************
1441 * InternetCanonicalizeUrlA (WININET.@)
1443 * Escape unsafe characters and spaces
1445 * RETURNS
1446 * TRUE on success
1447 * FALSE on failure
1450 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1451 LPDWORD lpdwBufferLength, DWORD dwFlags)
1453 HRESULT hr;
1454 TRACE("%s %p %p %08lx\n",debugstr_a(lpszUrl), lpszBuffer,
1455 lpdwBufferLength, dwFlags);
1457 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1458 dwFlags ^= ICU_NO_ENCODE;
1460 dwFlags |= 0x80000000; /* Don't know what this means */
1462 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
1464 return (hr == S_OK) ? TRUE : FALSE;
1467 /***********************************************************************
1468 * InternetCanonicalizeUrlW (WININET.@)
1470 * Escape unsafe characters and spaces
1472 * RETURNS
1473 * TRUE on success
1474 * FALSE on failure
1477 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1478 LPDWORD lpdwBufferLength, DWORD dwFlags)
1480 HRESULT hr;
1481 TRACE("%s %p %p %08lx\n", debugstr_w(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 = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
1491 return (hr == S_OK) ? TRUE : FALSE;
1495 /***********************************************************************
1496 * InternetSetStatusCallbackA (WININET.@)
1498 * Sets up a callback function which is called as progress is made
1499 * during an operation.
1501 * RETURNS
1502 * Previous callback or NULL on success
1503 * INTERNET_INVALID_STATUS_CALLBACK on failure
1506 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1507 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1509 INTERNET_STATUS_CALLBACK retVal;
1510 LPWININETHANDLEHEADER lpwh;
1512 TRACE("0x%08lx\n", (ULONG)hInternet);
1514 lpwh = WININET_GetObject(hInternet);
1515 if (!lpwh)
1516 return INTERNET_INVALID_STATUS_CALLBACK;
1518 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1519 retVal = lpwh->lpfnStatusCB;
1520 lpwh->lpfnStatusCB = lpfnIntCB;
1522 WININET_Release( lpwh );
1524 return retVal;
1527 /***********************************************************************
1528 * InternetSetStatusCallbackW (WININET.@)
1530 * Sets up a callback function which is called as progress is made
1531 * during an operation.
1533 * RETURNS
1534 * Previous callback or NULL on success
1535 * INTERNET_INVALID_STATUS_CALLBACK on failure
1538 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1539 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1541 INTERNET_STATUS_CALLBACK retVal;
1542 LPWININETHANDLEHEADER lpwh;
1544 TRACE("0x%08lx\n", (ULONG)hInternet);
1546 lpwh = WININET_GetObject(hInternet);
1547 if (!lpwh)
1548 return INTERNET_INVALID_STATUS_CALLBACK;
1550 lpwh->dwInternalFlags |= INET_CALLBACKW;
1551 retVal = lpwh->lpfnStatusCB;
1552 lpwh->lpfnStatusCB = lpfnIntCB;
1554 WININET_Release( lpwh );
1556 return retVal;
1559 /***********************************************************************
1560 * InternetSetFilePointer (WININET.@)
1562 DWORD WINAPI InternetSetFilePointer(HINTERNET f1, LONG f2, PVOID f3, DWORD f4, DWORD f5)
1564 FIXME("stub\n");
1565 return FALSE;
1568 /***********************************************************************
1569 * InternetWriteFile (WININET.@)
1571 * Write data to an open internet file
1573 * RETURNS
1574 * TRUE on success
1575 * FALSE on failure
1578 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1579 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1581 BOOL retval = FALSE;
1582 int nSocket = -1;
1583 LPWININETHANDLEHEADER lpwh;
1585 TRACE("\n");
1586 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1587 if (NULL == lpwh)
1588 return FALSE;
1590 switch (lpwh->htype)
1592 case WH_HHTTPREQ:
1593 FIXME("This shouldn't be here! We don't support this kind"
1594 " of connection anymore. Must use NETCON functions,"
1595 " especially if using SSL\n");
1596 nSocket = ((LPWININETHTTPREQW)lpwh)->netConnection.socketFD;
1597 break;
1599 case WH_HFILE:
1600 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1601 break;
1603 default:
1604 break;
1607 if (nSocket != -1)
1609 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1610 retval = (res >= 0);
1611 *lpdwNumOfBytesWritten = retval ? res : 0;
1613 WININET_Release( lpwh );
1615 return retval;
1619 /***********************************************************************
1620 * InternetReadFile (WININET.@)
1622 * Read data from an open internet file
1624 * RETURNS
1625 * TRUE on success
1626 * FALSE on failure
1629 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1630 DWORD dwNumOfBytesToRead, LPDWORD dwNumOfBytesRead)
1632 BOOL retval = FALSE;
1633 int nSocket = -1;
1634 LPWININETHANDLEHEADER lpwh;
1636 TRACE("%p %p %ld %p\n", hFile, lpBuffer, dwNumOfBytesToRead, dwNumOfBytesRead);
1638 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1639 if (NULL == lpwh)
1640 return FALSE;
1642 /* FIXME: this should use NETCON functions! */
1643 switch (lpwh->htype)
1645 case WH_HHTTPREQ:
1646 if (!NETCON_recv(&((LPWININETHTTPREQW)lpwh)->netConnection, lpBuffer,
1647 dwNumOfBytesToRead, MSG_WAITALL, (int *)dwNumOfBytesRead))
1649 *dwNumOfBytesRead = 0;
1650 retval = TRUE; /* Under windows, it seems to return 0 even if nothing was read... */
1652 else
1653 retval = TRUE;
1654 break;
1656 case WH_HFILE:
1657 /* FIXME: FTP should use NETCON_ stuff */
1658 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1659 if (nSocket != -1)
1661 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, MSG_WAITALL);
1662 retval = (res >= 0);
1663 *dwNumOfBytesRead = retval ? res : 0;
1665 break;
1667 default:
1668 break;
1670 WININET_Release( lpwh );
1672 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", dwNumOfBytesRead ? *dwNumOfBytesRead : -1);
1673 return retval;
1676 /***********************************************************************
1677 * InternetReadFileExA (WININET.@)
1679 * Read data from an open internet file
1681 * RETURNS
1682 * TRUE on success
1683 * FALSE on failure
1686 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffer,
1687 DWORD dwFlags, DWORD dwContext)
1689 FIXME("stub\n");
1690 return FALSE;
1693 /***********************************************************************
1694 * InternetReadFileExW (WININET.@)
1696 * Read data from an open internet file
1698 * RETURNS
1699 * TRUE on success
1700 * FALSE on failure
1703 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1704 DWORD dwFlags, DWORD dwContext)
1706 FIXME("stub\n");
1708 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1709 return FALSE;
1712 /***********************************************************************
1713 * INET_QueryOptionHelper (internal)
1715 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1716 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1718 LPWININETHANDLEHEADER lpwhh;
1719 BOOL bSuccess = FALSE;
1721 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1723 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1725 switch (dwOption)
1727 case INTERNET_OPTION_HANDLE_TYPE:
1729 ULONG type;
1731 if (!lpwhh)
1733 WARN("Invalid hInternet handle\n");
1734 SetLastError(ERROR_INVALID_HANDLE);
1735 return FALSE;
1738 type = lpwhh->htype;
1740 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
1742 if (*lpdwBufferLength < sizeof(ULONG))
1743 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1744 else
1746 memcpy(lpBuffer, &type, sizeof(ULONG));
1747 *lpdwBufferLength = sizeof(ULONG);
1748 bSuccess = TRUE;
1750 break;
1753 case INTERNET_OPTION_REQUEST_FLAGS:
1755 ULONG flags = 4;
1756 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
1757 if (*lpdwBufferLength < sizeof(ULONG))
1758 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1759 else
1761 memcpy(lpBuffer, &flags, sizeof(ULONG));
1762 *lpdwBufferLength = sizeof(ULONG);
1763 bSuccess = TRUE;
1765 break;
1768 case INTERNET_OPTION_URL:
1769 case INTERNET_OPTION_DATAFILE_NAME:
1771 if (!lpwhh)
1773 WARN("Invalid hInternet handle\n");
1774 SetLastError(ERROR_INVALID_HANDLE);
1775 return FALSE;
1777 if (lpwhh->htype == WH_HHTTPREQ)
1779 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
1780 WCHAR url[1023];
1781 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
1783 sprintfW(url,szFmt,lpreq->StdHeaders[HTTP_QUERY_HOST].lpszValue,lpreq->lpszPath);
1784 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
1785 if (*lpdwBufferLength < strlenW(url)+1)
1786 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1787 else
1789 if(!bIsUnicode)
1791 *lpdwBufferLength=WideCharToMultiByte(CP_ACP,0,url,-1,lpBuffer,*lpdwBufferLength,NULL,NULL);
1793 else
1795 strcpyW(lpBuffer, url);
1796 *lpdwBufferLength = strlenW(url)+1;
1798 bSuccess = TRUE;
1801 break;
1803 case INTERNET_OPTION_HTTP_VERSION:
1806 * Presently hardcoded to 1.1
1808 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
1809 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
1810 bSuccess = TRUE;
1811 break;
1813 case INTERNET_OPTION_CONNECTED_STATE:
1815 INTERNET_CONNECTED_INFO * pCi = (INTERNET_CONNECTED_INFO *)lpBuffer;
1816 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
1817 pCi->dwConnectedState = INTERNET_STATE_CONNECTED;
1818 pCi->dwFlags = 0;
1819 bSuccess = TRUE;
1820 break;
1822 case INTERNET_OPTION_SECURITY_FLAGS:
1823 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
1824 break;
1826 default:
1827 FIXME("Stub! %ld \n",dwOption);
1828 break;
1830 if (lpwhh)
1831 WININET_Release( lpwhh );
1833 return bSuccess;
1836 /***********************************************************************
1837 * InternetQueryOptionW (WININET.@)
1839 * Queries an options on the specified handle
1841 * RETURNS
1842 * TRUE on success
1843 * FALSE on failure
1846 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
1847 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1849 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
1852 /***********************************************************************
1853 * InternetQueryOptionA (WININET.@)
1855 * Queries an options on the specified handle
1857 * RETURNS
1858 * TRUE on success
1859 * FALSE on failure
1862 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
1863 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1865 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
1869 /***********************************************************************
1870 * InternetSetOptionW (WININET.@)
1872 * Sets an options on the specified handle
1874 * RETURNS
1875 * TRUE on success
1876 * FALSE on failure
1879 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
1880 LPVOID lpBuffer, DWORD dwBufferLength)
1882 LPWININETHANDLEHEADER lpwhh;
1883 BOOL ret = TRUE;
1885 TRACE("0x%08lx\n", dwOption);
1887 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1888 if( !lpwhh )
1889 return FALSE;
1891 switch (dwOption)
1893 case INTERNET_OPTION_HTTP_VERSION:
1895 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
1896 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
1898 break;
1899 case INTERNET_OPTION_ERROR_MASK:
1901 unsigned long flags=*(unsigned long*)lpBuffer;
1902 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
1904 break;
1905 case INTERNET_OPTION_CODEPAGE:
1907 unsigned long codepage=*(unsigned long*)lpBuffer;
1908 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
1910 break;
1911 case INTERNET_OPTION_REQUEST_PRIORITY:
1913 unsigned long priority=*(unsigned long*)lpBuffer;
1914 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
1916 break;
1917 case INTERNET_OPTION_CONNECT_TIMEOUT:
1919 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
1920 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
1922 break;
1923 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
1925 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
1926 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
1928 break;
1929 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
1930 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
1931 break;
1932 case INTERNET_OPTION_END_BROWSER_SESSION:
1933 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
1934 break;
1935 case INTERNET_OPTION_CONNECTED_STATE:
1936 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
1937 break;
1938 default:
1939 FIXME("Option %ld STUB\n",dwOption);
1940 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1941 ret = FALSE;
1942 break;
1944 WININET_Release( lpwhh );
1946 return TRUE;
1950 /***********************************************************************
1951 * InternetSetOptionA (WININET.@)
1953 * Sets an options on the specified handle.
1955 * RETURNS
1956 * TRUE on success
1957 * FALSE on failure
1960 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
1961 LPVOID lpBuffer, DWORD dwBufferLength)
1963 LPVOID wbuffer;
1964 DWORD wlen;
1965 BOOL r;
1967 switch( dwOption )
1969 case INTERNET_OPTION_PROXY:
1971 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
1972 LPINTERNET_PROXY_INFOW piw;
1973 DWORD proxlen, prbylen;
1974 LPWSTR prox, prby;
1976 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
1977 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
1978 wlen = sizeof(*piw) + proxlen + prbylen;
1979 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
1980 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
1981 piw->dwAccessType = pi->dwAccessType;
1982 prox = (LPWSTR) &piw[1];
1983 prby = &prox[proxlen+1];
1984 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
1985 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
1986 piw->lpszProxy = prox;
1987 piw->lpszProxyBypass = prby;
1989 break;
1990 case INTERNET_OPTION_USER_AGENT:
1991 case INTERNET_OPTION_USERNAME:
1992 case INTERNET_OPTION_PASSWORD:
1993 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
1994 NULL, 0 );
1995 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
1996 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
1997 wbuffer, wlen );
1998 break;
1999 default:
2000 wbuffer = lpBuffer;
2001 wlen = dwBufferLength;
2004 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2006 if( lpBuffer != wbuffer )
2007 HeapFree( GetProcessHeap(), 0, wbuffer );
2009 return r;
2013 /***********************************************************************
2014 * InternetSetOptionExA (WININET.@)
2016 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2017 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2019 FIXME("Flags %08lx ignored\n", dwFlags);
2020 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2023 /***********************************************************************
2024 * InternetSetOptionExW (WININET.@)
2026 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2027 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2029 FIXME("Flags %08lx ignored\n", dwFlags);
2030 if( dwFlags & ~ISO_VALID_FLAGS )
2032 SetLastError( ERROR_INVALID_PARAMETER );
2033 return FALSE;
2035 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2038 static const WCHAR WININET_wkday[7][4] =
2039 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2040 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2041 static const WCHAR WININET_month[12][4] =
2042 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2043 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2044 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2046 /***********************************************************************
2047 * InternetTimeFromSystemTimeA (WININET.@)
2049 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2051 BOOL ret;
2052 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2054 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2056 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2057 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2059 return ret;
2062 /***********************************************************************
2063 * InternetTimeFromSystemTimeW (WININET.@)
2065 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2067 static const WCHAR date[] =
2068 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2069 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2071 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2073 if (!time || !string) return FALSE;
2075 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2076 return FALSE;
2078 sprintfW( string, date,
2079 WININET_wkday[time->wDayOfWeek],
2080 time->wDay,
2081 WININET_month[time->wMonth - 1],
2082 time->wYear,
2083 time->wHour,
2084 time->wMinute,
2085 time->wSecond );
2087 return TRUE;
2090 /***********************************************************************
2091 * InternetTimeToSystemTimeA (WININET.@)
2093 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2095 BOOL ret = FALSE;
2096 WCHAR *stringW;
2097 int len;
2099 TRACE( "%s %p 0x%08lx\n", debugstr_a(string), time, reserved );
2101 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2102 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2104 if (stringW)
2106 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2107 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2108 HeapFree( GetProcessHeap(), 0, stringW );
2110 return ret;
2113 /***********************************************************************
2114 * InternetTimeToSystemTimeW (WININET.@)
2116 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2118 unsigned int i;
2119 WCHAR *s = (LPWSTR)string;
2121 TRACE( "%s %p 0x%08lx\n", debugstr_w(string), time, reserved );
2123 if (!string || !time || reserved != 0) return FALSE;
2125 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2126 * a SYSTEMTIME structure.
2129 while (*s && !isalphaW( *s )) s++;
2130 if (*s == '\0' || *(s + 1) == '\0' || *(s + 2) == '\0') return FALSE;
2131 time->wDayOfWeek = 7;
2133 for (i = 0; i < 7; i++)
2135 if (toupperW( WININET_wkday[i][0] ) == toupperW( *s ) &&
2136 toupperW( WININET_wkday[i][1] ) == toupperW( *(s + 1) ) &&
2137 toupperW( WININET_wkday[i][2] ) == toupperW( *(s + 2) ) )
2139 time->wDayOfWeek = i;
2140 break;
2144 if (time->wDayOfWeek > 6) return FALSE;
2145 while (*s && !isdigitW( *s )) s++;
2146 time->wDay = strtolW( s, &s, 10 );
2148 while (*s && !isalphaW( *s )) s++;
2149 if (*s == '\0' || *(s + 1) == '\0' || *(s + 2) == '\0') return FALSE;
2150 time->wMonth = 0;
2152 for (i = 0; i < 12; i++)
2154 if (toupperW( WININET_month[i][0]) == toupperW( *s ) &&
2155 toupperW( WININET_month[i][1]) == toupperW( *(s + 1) ) &&
2156 toupperW( WININET_month[i][2]) == toupperW( *(s + 2) ) )
2158 time->wMonth = i + 1;
2159 break;
2162 if (time->wMonth == 0) return FALSE;
2164 while (*s && !isdigitW( *s )) s++;
2165 if (*s == '\0') return FALSE;
2166 time->wYear = strtolW( s, &s, 10 );
2168 while (*s && !isdigitW( *s )) s++;
2169 if (*s == '\0') return FALSE;
2170 time->wHour = strtolW( s, &s, 10 );
2172 while (*s && !isdigitW( *s )) s++;
2173 if (*s == '\0') return FALSE;
2174 time->wMinute = strtolW( s, &s, 10 );
2176 while (*s && !isdigitW( *s )) s++;
2177 if (*s == '\0') return FALSE;
2178 time->wSecond = strtolW( s, &s, 10 );
2180 time->wMilliseconds = 0;
2181 return TRUE;
2184 /***********************************************************************
2185 * InternetCheckConnectionA (WININET.@)
2187 * Pings a requested host to check internet connection
2189 * RETURNS
2190 * TRUE on success and FALSE on failure. If a failure then
2191 * ERROR_NOT_CONNECTED is placesd into GetLastError
2194 BOOL WINAPI InternetCheckConnectionA( LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2197 * this is a kludge which runs the resident ping program and reads the output.
2199 * Anyone have a better idea?
2202 BOOL rc = FALSE;
2203 char command[1024];
2204 char host[1024];
2205 int status = -1;
2207 FIXME("\n");
2210 * Crack or set the Address
2212 if (lpszUrl == NULL)
2215 * According to the doc we are supost to use the ip for the next
2216 * server in the WnInet internal server database. I have
2217 * no idea what that is or how to get it.
2219 * So someone needs to implement this.
2221 FIXME("Unimplemented with URL of NULL\n");
2222 return TRUE;
2224 else
2226 URL_COMPONENTSA components;
2228 ZeroMemory(&components,sizeof(URL_COMPONENTSA));
2229 components.lpszHostName = (LPSTR)&host;
2230 components.dwHostNameLength = 1024;
2232 if (!InternetCrackUrlA(lpszUrl,0,0,&components))
2233 goto End;
2235 TRACE("host name : %s\n",components.lpszHostName);
2239 * Build our ping command
2241 strcpy(command,"ping -w 1 ");
2242 strcat(command,host);
2243 strcat(command," >/dev/null 2>/dev/null");
2245 TRACE("Ping command is : %s\n",command);
2247 status = system(command);
2249 TRACE("Ping returned a code of %i \n",status);
2251 /* Ping return code of 0 indicates success */
2252 if (status == 0)
2253 rc = TRUE;
2255 End:
2257 if (rc == FALSE)
2258 SetLastError(ERROR_NOT_CONNECTED);
2260 return rc;
2264 /***********************************************************************
2265 * InternetCheckConnectionW (WININET.@)
2267 * Pings a requested host to check internet connection
2269 * RETURNS
2270 * TRUE on success and FALSE on failure. If a failure then
2271 * ERROR_NOT_CONNECTED is placed into GetLastError
2274 BOOL WINAPI InternetCheckConnectionW(LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2276 CHAR *szUrl;
2277 INT len;
2278 BOOL rc;
2280 len = WideCharToMultiByte(CP_ACP, 0, lpszUrl, -1, NULL, 0, NULL, NULL);
2281 if (!(szUrl = (CHAR *)HeapAlloc(GetProcessHeap(), 0, len*sizeof(CHAR))))
2282 return FALSE;
2283 WideCharToMultiByte(CP_ACP, 0, lpszUrl, -1, szUrl, len, NULL, NULL);
2284 rc = InternetCheckConnectionA((LPCSTR)szUrl, dwFlags, dwReserved);
2285 HeapFree(GetProcessHeap(), 0, szUrl);
2287 return rc;
2291 /**********************************************************
2292 * INTERNET_InternetOpenUrlW (internal)
2294 * Opens an URL
2296 * RETURNS
2297 * handle of connection or NULL on failure
2299 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2300 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2302 URL_COMPONENTSW urlComponents;
2303 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2304 WCHAR password[1024], path[2048], extra[1024];
2305 HINTERNET client = NULL, client1 = NULL;
2307 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2308 dwHeadersLength, dwFlags, dwContext);
2310 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2311 urlComponents.lpszScheme = protocol;
2312 urlComponents.dwSchemeLength = 32;
2313 urlComponents.lpszHostName = hostName;
2314 urlComponents.dwHostNameLength = MAXHOSTNAME;
2315 urlComponents.lpszUserName = userName;
2316 urlComponents.dwUserNameLength = 1024;
2317 urlComponents.lpszPassword = password;
2318 urlComponents.dwPasswordLength = 1024;
2319 urlComponents.lpszUrlPath = path;
2320 urlComponents.dwUrlPathLength = 2048;
2321 urlComponents.lpszExtraInfo = extra;
2322 urlComponents.dwExtraInfoLength = 1024;
2323 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2324 return NULL;
2325 switch(urlComponents.nScheme) {
2326 case INTERNET_SCHEME_FTP:
2327 if(urlComponents.nPort == 0)
2328 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2329 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2330 userName, password, dwFlags, dwContext, INET_OPENURL);
2331 if(client == NULL)
2332 break;
2333 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2334 if(client1 == NULL) {
2335 InternetCloseHandle(client);
2336 break;
2338 break;
2340 case INTERNET_SCHEME_HTTP:
2341 case INTERNET_SCHEME_HTTPS: {
2342 static const WCHAR szStars[] = { '*','/','*', 0 };
2343 LPCWSTR accept[2] = { szStars, NULL };
2344 if(urlComponents.nPort == 0) {
2345 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2346 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2347 else
2348 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2350 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2351 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2352 userName, password, dwFlags, dwContext, INET_OPENURL);
2353 if(client == NULL)
2354 break;
2355 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2356 if(client1 == NULL) {
2357 InternetCloseHandle(client);
2358 break;
2360 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2361 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0)) {
2362 InternetCloseHandle(client1);
2363 client1 = NULL;
2364 break;
2367 case INTERNET_SCHEME_GOPHER:
2368 /* gopher doesn't seem to be implemented in wine, but it's supposed
2369 * to be supported by InternetOpenUrlA. */
2370 default:
2371 break;
2374 TRACE(" %p <--\n", client1);
2376 return client1;
2379 /**********************************************************
2380 * InternetOpenUrlW (WININET.@)
2382 * Opens an URL
2384 * RETURNS
2385 * handle of connection or NULL on failure
2387 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2388 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2390 HINTERNET ret = NULL;
2391 LPWININETAPPINFOW hIC = NULL;
2393 if (TRACE_ON(wininet)) {
2394 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2395 dwHeadersLength, dwFlags, dwContext);
2396 TRACE(" flags :");
2397 dump_INTERNET_FLAGS(dwFlags);
2400 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2401 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2402 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2403 goto lend;
2406 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2407 WORKREQUEST workRequest;
2408 struct WORKREQ_INTERNETOPENURLW *req;
2410 workRequest.asyncall = INTERNETOPENURLW;
2411 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2412 req = &workRequest.u.InternetOpenUrlW;
2413 if (lpszUrl)
2414 req->lpszUrl = WININET_strdupW(lpszUrl);
2415 else
2416 req->lpszUrl = 0;
2417 if (lpszHeaders)
2418 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2419 else
2420 req->lpszHeaders = 0;
2421 req->dwHeadersLength = dwHeadersLength;
2422 req->dwFlags = dwFlags;
2423 req->dwContext = dwContext;
2425 INTERNET_AsyncCall(&workRequest);
2427 * This is from windows.
2429 SetLastError(ERROR_IO_PENDING);
2430 } else {
2431 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2434 lend:
2435 if( hIC )
2436 WININET_Release( &hIC->hdr );
2437 TRACE(" %p <--\n", ret);
2439 return ret;
2442 /**********************************************************
2443 * InternetOpenUrlA (WININET.@)
2445 * Opens an URL
2447 * RETURNS
2448 * handle of connection or NULL on failure
2450 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2451 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2453 HINTERNET rc = (HINTERNET)NULL;
2455 INT lenUrl;
2456 INT lenHeaders = 0;
2457 LPWSTR szUrl = NULL;
2458 LPWSTR szHeaders = NULL;
2460 TRACE("\n");
2462 if(lpszUrl) {
2463 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
2464 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
2465 if(!szUrl)
2466 return (HINTERNET)NULL;
2467 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
2470 if(lpszHeaders) {
2471 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
2472 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
2473 if(!szHeaders) {
2474 HeapFree(GetProcessHeap(), 0, szUrl);
2475 return (HINTERNET)NULL;
2477 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
2480 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
2481 lenHeaders, dwFlags, dwContext);
2483 HeapFree(GetProcessHeap(), 0, szUrl);
2484 HeapFree(GetProcessHeap(), 0, szHeaders);
2486 return rc;
2490 /***********************************************************************
2491 * INTERNET_SetLastError (internal)
2493 * Set last thread specific error
2495 * RETURNS
2498 void INTERNET_SetLastError(DWORD dwError)
2500 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2502 SetLastError(dwError);
2503 if(lpwite)
2504 lpwite->dwError = dwError;
2508 /***********************************************************************
2509 * INTERNET_GetLastError (internal)
2511 * Get last thread specific error
2513 * RETURNS
2516 DWORD INTERNET_GetLastError(void)
2518 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2519 return lpwite->dwError;
2523 /***********************************************************************
2524 * INTERNET_WorkerThreadFunc (internal)
2526 * Worker thread execution function
2528 * RETURNS
2531 static DWORD INTERNET_WorkerThreadFunc(LPVOID *lpvParam)
2533 DWORD dwWaitRes;
2535 while (1)
2537 if(dwNumJobs > 0) {
2538 INTERNET_ExecuteWork();
2539 continue;
2541 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
2543 if (dwWaitRes == WAIT_OBJECT_0 + 1)
2544 INTERNET_ExecuteWork();
2545 else
2546 break;
2548 InterlockedIncrement(&dwNumIdleThreads);
2551 InterlockedDecrement(&dwNumIdleThreads);
2552 InterlockedDecrement(&dwNumThreads);
2553 TRACE("Worker thread exiting\n");
2554 return TRUE;
2558 /***********************************************************************
2559 * INTERNET_InsertWorkRequest (internal)
2561 * Insert work request into queue
2563 * RETURNS
2566 static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
2568 BOOL bSuccess = FALSE;
2569 LPWORKREQUEST lpNewRequest;
2571 TRACE("\n");
2573 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
2574 if (lpNewRequest)
2576 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
2577 lpNewRequest->prev = NULL;
2579 EnterCriticalSection(&csQueue);
2581 lpNewRequest->next = lpWorkQueueTail;
2582 if (lpWorkQueueTail)
2583 lpWorkQueueTail->prev = lpNewRequest;
2584 lpWorkQueueTail = lpNewRequest;
2585 if (!lpHeadWorkQueue)
2586 lpHeadWorkQueue = lpWorkQueueTail;
2588 LeaveCriticalSection(&csQueue);
2590 bSuccess = TRUE;
2591 InterlockedIncrement(&dwNumJobs);
2594 return bSuccess;
2598 /***********************************************************************
2599 * INTERNET_GetWorkRequest (internal)
2601 * Retrieves work request from queue
2603 * RETURNS
2606 static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
2608 BOOL bSuccess = FALSE;
2609 LPWORKREQUEST lpRequest = NULL;
2611 TRACE("\n");
2613 EnterCriticalSection(&csQueue);
2615 if (lpHeadWorkQueue)
2617 lpRequest = lpHeadWorkQueue;
2618 lpHeadWorkQueue = lpHeadWorkQueue->prev;
2619 if (lpRequest == lpWorkQueueTail)
2620 lpWorkQueueTail = lpHeadWorkQueue;
2623 LeaveCriticalSection(&csQueue);
2625 if (lpRequest)
2627 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
2628 HeapFree(GetProcessHeap(), 0, lpRequest);
2629 bSuccess = TRUE;
2630 InterlockedDecrement(&dwNumJobs);
2633 return bSuccess;
2637 /***********************************************************************
2638 * INTERNET_AsyncCall (internal)
2640 * Retrieves work request from queue
2642 * RETURNS
2645 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
2647 HANDLE hThread;
2648 DWORD dwTID;
2649 BOOL bSuccess = FALSE;
2651 TRACE("\n");
2653 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
2655 InterlockedIncrement(&dwNumIdleThreads);
2657 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
2658 !(hThread = CreateThread(NULL, 0,
2659 (LPTHREAD_START_ROUTINE)INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
2661 InterlockedDecrement(&dwNumThreads);
2662 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
2663 goto lerror;
2666 TRACE("Created new thread\n");
2669 bSuccess = TRUE;
2670 INTERNET_InsertWorkRequest(lpWorkRequest);
2671 SetEvent(hWorkEvent);
2673 lerror:
2675 return bSuccess;
2679 /***********************************************************************
2680 * INTERNET_ExecuteWork (internal)
2682 * RETURNS
2685 static VOID INTERNET_ExecuteWork(void)
2687 WORKREQUEST workRequest;
2689 TRACE("\n");
2691 if (!INTERNET_GetWorkRequest(&workRequest))
2692 return;
2694 switch (workRequest.asyncall)
2696 case FTPPUTFILEW:
2698 struct WORKREQ_FTPPUTFILEW *req = &workRequest.u.FtpPutFileW;
2699 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2701 TRACE("FTPPUTFILEW %p\n", lpwfs);
2703 FTP_FtpPutFileW(lpwfs, req->lpszLocalFile,
2704 req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
2706 HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
2707 HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
2709 break;
2711 case FTPSETCURRENTDIRECTORYW:
2713 struct WORKREQ_FTPSETCURRENTDIRECTORYW *req;
2714 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2716 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs);
2718 req = &workRequest.u.FtpSetCurrentDirectoryW;
2719 FTP_FtpSetCurrentDirectoryW(lpwfs, req->lpszDirectory);
2720 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
2722 break;
2724 case FTPCREATEDIRECTORYW:
2726 struct WORKREQ_FTPCREATEDIRECTORYW *req;
2727 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2729 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs);
2731 req = &workRequest.u.FtpCreateDirectoryW;
2732 FTP_FtpCreateDirectoryW(lpwfs, req->lpszDirectory);
2733 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
2735 break;
2737 case FTPFINDFIRSTFILEW:
2739 struct WORKREQ_FTPFINDFIRSTFILEW *req;
2740 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2742 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs);
2744 req = &workRequest.u.FtpFindFirstFileW;
2745 FTP_FtpFindFirstFileW(lpwfs, req->lpszSearchFile,
2746 req->lpFindFileData, req->dwFlags, req->dwContext);
2747 HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
2749 break;
2751 case FTPGETCURRENTDIRECTORYW:
2753 struct WORKREQ_FTPGETCURRENTDIRECTORYW *req;
2754 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2756 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs);
2758 req = &workRequest.u.FtpGetCurrentDirectoryW;
2759 FTP_FtpGetCurrentDirectoryW(lpwfs,
2760 req->lpszDirectory, req->lpdwDirectory);
2762 break;
2764 case FTPOPENFILEW:
2766 struct WORKREQ_FTPOPENFILEW *req = &workRequest.u.FtpOpenFileW;
2767 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2769 TRACE("FTPOPENFILEW %p\n", lpwfs);
2771 FTP_FtpOpenFileW(lpwfs, req->lpszFilename,
2772 req->dwAccess, req->dwFlags, req->dwContext);
2773 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
2775 break;
2777 case FTPGETFILEW:
2779 struct WORKREQ_FTPGETFILEW *req = &workRequest.u.FtpGetFileW;
2780 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2782 TRACE("FTPGETFILEW %p\n", lpwfs);
2784 FTP_FtpGetFileW(lpwfs, req->lpszRemoteFile,
2785 req->lpszNewFile, req->fFailIfExists,
2786 req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
2787 HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
2788 HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
2790 break;
2792 case FTPDELETEFILEW:
2794 struct WORKREQ_FTPDELETEFILEW *req = &workRequest.u.FtpDeleteFileW;
2795 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2797 TRACE("FTPDELETEFILEW %p\n", lpwfs);
2799 FTP_FtpDeleteFileW(lpwfs, req->lpszFilename);
2800 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
2802 break;
2804 case FTPREMOVEDIRECTORYW:
2806 struct WORKREQ_FTPREMOVEDIRECTORYW *req;
2807 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2809 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs);
2811 req = &workRequest.u.FtpRemoveDirectoryW;
2812 FTP_FtpRemoveDirectoryW(lpwfs, req->lpszDirectory);
2813 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
2815 break;
2817 case FTPRENAMEFILEW:
2819 struct WORKREQ_FTPRENAMEFILEW *req = &workRequest.u.FtpRenameFileW;
2820 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
2822 TRACE("FTPRENAMEFILEW %p\n", lpwfs);
2824 FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
2825 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
2826 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
2828 break;
2830 case INTERNETFINDNEXTW:
2832 struct WORKREQ_INTERNETFINDNEXTW *req;
2833 LPWININETFINDNEXTW lpwh = (LPWININETFINDNEXTW) workRequest.hdr;
2835 TRACE("INTERNETFINDNEXTW %p\n", lpwh);
2837 req = &workRequest.u.InternetFindNextW;
2838 INTERNET_FindNextFileW(lpwh, req->lpFindFileData);
2840 break;
2842 case HTTPSENDREQUESTW:
2844 struct WORKREQ_HTTPSENDREQUESTW *req = &workRequest.u.HttpSendRequestW;
2845 LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) workRequest.hdr;
2847 TRACE("HTTPSENDREQUESTW %p\n", lpwhr);
2849 HTTP_HttpSendRequestW(lpwhr, req->lpszHeader,
2850 req->dwHeaderLength, req->lpOptional, req->dwOptionalLength);
2852 HeapFree(GetProcessHeap(), 0, req->lpszHeader);
2854 break;
2856 case HTTPOPENREQUESTW:
2858 struct WORKREQ_HTTPOPENREQUESTW *req = &workRequest.u.HttpOpenRequestW;
2859 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) workRequest.hdr;
2861 TRACE("HTTPOPENREQUESTW %p\n", lpwhs);
2863 HTTP_HttpOpenRequestW(lpwhs, req->lpszVerb,
2864 req->lpszObjectName, req->lpszVersion, req->lpszReferrer,
2865 req->lpszAcceptTypes, req->dwFlags, req->dwContext);
2867 HeapFree(GetProcessHeap(), 0, req->lpszVerb);
2868 HeapFree(GetProcessHeap(), 0, req->lpszObjectName);
2869 HeapFree(GetProcessHeap(), 0, req->lpszVersion);
2870 HeapFree(GetProcessHeap(), 0, req->lpszReferrer);
2872 break;
2874 case SENDCALLBACK:
2876 struct WORKREQ_SENDCALLBACK *req = &workRequest.u.SendCallback;
2878 TRACE("SENDCALLBACK %p\n", workRequest.hdr);
2880 SendSyncCallback(workRequest.hdr,
2881 req->dwContext, req->dwInternetStatus, req->lpvStatusInfo,
2882 req->dwStatusInfoLength);
2884 /* And frees the copy of the status info */
2885 HeapFree(GetProcessHeap(), 0, req->lpvStatusInfo);
2887 break;
2889 case INTERNETOPENURLW:
2891 struct WORKREQ_INTERNETOPENURLW *req = &workRequest.u.InternetOpenUrlW;
2892 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest.hdr;
2894 TRACE("INTERNETOPENURLW %p\n", hIC);
2896 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
2897 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2898 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2899 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2901 break;
2903 WININET_Release( workRequest.hdr );
2907 /***********************************************************************
2908 * INTERNET_GetResponseBuffer
2910 * RETURNS
2913 LPSTR INTERNET_GetResponseBuffer(void)
2915 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2916 TRACE("\n");
2917 return lpwite->response;
2920 /***********************************************************************
2921 * INTERNET_GetNextLine (internal)
2923 * Parse next line in directory string listing
2925 * RETURNS
2926 * Pointer to beginning of next line
2927 * NULL on failure
2931 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
2933 struct timeval tv;
2934 fd_set infd;
2935 BOOL bSuccess = FALSE;
2936 INT nRecv = 0;
2937 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
2939 TRACE("\n");
2941 FD_ZERO(&infd);
2942 FD_SET(nSocket, &infd);
2943 tv.tv_sec=RESPONSE_TIMEOUT;
2944 tv.tv_usec=0;
2946 while (nRecv < MAX_REPLY_LEN)
2948 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
2950 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
2952 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
2953 goto lend;
2956 if (lpszBuffer[nRecv] == '\n')
2958 bSuccess = TRUE;
2959 break;
2961 if (lpszBuffer[nRecv] != '\r')
2962 nRecv++;
2964 else
2966 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
2967 goto lend;
2971 lend:
2972 if (bSuccess)
2974 lpszBuffer[nRecv] = '\0';
2975 *dwLen = nRecv - 1;
2976 TRACE(":%d %s\n", nRecv, lpszBuffer);
2977 return lpszBuffer;
2979 else
2981 return NULL;
2985 /***********************************************************************
2988 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
2989 LPDWORD lpdwNumberOfBytesAvailble,
2990 DWORD dwFlags, DWORD dwConext)
2992 LPWININETHTTPREQW lpwhr;
2993 INT retval = -1;
2994 char buffer[4048];
2996 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
2997 if (NULL == lpwhr)
2999 SetLastError(ERROR_NO_MORE_FILES);
3000 return FALSE;
3003 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3005 switch (lpwhr->hdr.htype)
3007 case WH_HHTTPREQ:
3008 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3009 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3011 SetLastError(ERROR_NO_MORE_FILES);
3012 retval = FALSE;
3014 else
3015 retval = TRUE;
3016 break;
3018 default:
3019 FIXME("unsupported file type\n");
3020 break;
3022 WININET_Release( &lpwhr->hdr );
3024 TRACE("<-- %i\n",retval);
3025 return (retval+1);
3029 /***********************************************************************
3032 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3033 *lphLockReqHandle)
3035 FIXME("STUB\n");
3036 return FALSE;
3039 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3041 FIXME("STUB\n");
3042 return FALSE;
3046 /***********************************************************************
3047 * InternetAutodial
3049 * On windows this function is supposed to dial the default internet
3050 * connection. We don't want to have Wine dial out to the internet so
3051 * we return TRUE by default. It might be nice to check if we are connected.
3053 * RETURNS
3054 * TRUE on success
3055 * FALSE on failure
3058 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3060 FIXME("STUB\n");
3062 /* Tell that we are connected to the internet. */
3063 return TRUE;
3066 /***********************************************************************
3067 * InternetAutodialHangup
3069 * Hangs up an connection made with InternetAutodial
3071 * PARAM
3072 * dwReserved
3073 * RETURNS
3074 * TRUE on success
3075 * FALSE on failure
3078 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3080 FIXME("STUB\n");
3082 /* we didn't dial, we don't disconnect */
3083 return TRUE;
3086 /***********************************************************************
3088 * InternetCombineUrlA
3090 * Combine a base URL with a relative URL
3092 * RETURNS
3093 * TRUE on success
3094 * FALSE on failure
3098 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3099 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3100 DWORD dwFlags)
3102 HRESULT hr=S_OK;
3104 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3106 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3107 dwFlags ^= ICU_NO_ENCODE;
3108 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3110 return (hr==S_OK);
3113 /***********************************************************************
3115 * InternetCombineUrlW
3117 * Combine a base URL with a relative URL
3119 * RETURNS
3120 * TRUE on success
3121 * FALSE on failure
3125 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3126 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3127 DWORD dwFlags)
3129 HRESULT hr=S_OK;
3131 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3133 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3134 dwFlags ^= ICU_NO_ENCODE;
3135 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3137 return (hr==S_OK);
3140 /***********************************************************************
3142 * InternetCreateUrlA
3144 * RETURNS
3145 * TRUE on success
3146 * FALSE on failure
3149 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3150 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3152 FIXME("\n");
3153 return FALSE;
3156 /***********************************************************************
3158 * InternetCreateUrlW
3160 * RETURNS
3161 * TRUE on success
3162 * FALSE on failure
3165 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3166 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3168 FIXME("\n");
3169 return FALSE;
3172 /***********************************************************************
3173 * dump_INTERNET_FLAGS
3175 * Helper function to TRACE the internet flags.
3177 * RETURNS
3178 * None
3181 void dump_INTERNET_FLAGS(DWORD dwFlags)
3183 #define FE(x) { x, #x }
3184 static const wininet_flag_info flag[] = {
3185 FE(INTERNET_FLAG_RELOAD),
3186 FE(INTERNET_FLAG_RAW_DATA),
3187 FE(INTERNET_FLAG_EXISTING_CONNECT),
3188 FE(INTERNET_FLAG_ASYNC),
3189 FE(INTERNET_FLAG_PASSIVE),
3190 FE(INTERNET_FLAG_NO_CACHE_WRITE),
3191 FE(INTERNET_FLAG_MAKE_PERSISTENT),
3192 FE(INTERNET_FLAG_FROM_CACHE),
3193 FE(INTERNET_FLAG_SECURE),
3194 FE(INTERNET_FLAG_KEEP_CONNECTION),
3195 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
3196 FE(INTERNET_FLAG_READ_PREFETCH),
3197 FE(INTERNET_FLAG_NO_COOKIES),
3198 FE(INTERNET_FLAG_NO_AUTH),
3199 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
3200 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
3201 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
3202 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
3203 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
3204 FE(INTERNET_FLAG_RESYNCHRONIZE),
3205 FE(INTERNET_FLAG_HYPERLINK),
3206 FE(INTERNET_FLAG_NO_UI),
3207 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
3208 FE(INTERNET_FLAG_CACHE_ASYNC),
3209 FE(INTERNET_FLAG_FORMS_SUBMIT),
3210 FE(INTERNET_FLAG_NEED_FILE),
3211 FE(INTERNET_FLAG_TRANSFER_ASCII),
3212 FE(INTERNET_FLAG_TRANSFER_BINARY)
3214 #undef FE
3215 int i;
3217 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
3218 if (flag[i].val & dwFlags) {
3219 TRACE(" %s", flag[i].name);
3220 dwFlags &= ~flag[i].val;
3223 if (dwFlags)
3224 TRACE(" Unknown flags (%08lx)\n", dwFlags);
3225 else
3226 TRACE("\n");