msvcrt: Add a stub for _wsetlocale.
[wine/multimedia.git] / dlls / wininet / internet.c
blobf52103d494d361f634b646ebbe0f0012ea854062
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 "windef.h"
52 #include "winbase.h"
53 #include "winreg.h"
54 #include "winuser.h"
55 #include "wininet.h"
56 #include "winnls.h"
57 #include "wine/debug.h"
58 #include "winerror.h"
59 #define NO_SHLWAPI_STREAM
60 #include "shlwapi.h"
62 #include "wine/exception.h"
63 #include "excpt.h"
65 #include "internet.h"
66 #include "resource.h"
68 #include "wine/unicode.h"
69 #include "wincrypt.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define MAX_IDLE_WORKER 1000*60*1
74 #define MAX_WORKER_THREADS 10
75 #define RESPONSE_TIMEOUT 30
77 #define GET_HWININET_FROM_LPWININETFINDNEXT(lpwh) \
78 (LPWININETAPPINFOW)(((LPWININETFTPSESSIONW)(lpwh->hdr.lpwhparent))->hdr.lpwhparent)
81 typedef struct
83 DWORD dwError;
84 CHAR response[MAX_REPLY_LEN];
85 } WITHREADERROR, *LPWITHREADERROR;
87 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr);
88 BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData);
89 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
90 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext);
91 static VOID INTERNET_ExecuteWork(void);
93 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
94 static LONG dwNumThreads;
95 static LONG dwNumIdleThreads;
96 static LONG dwNumJobs;
97 static HANDLE hEventArray[2];
98 #define hQuitEvent hEventArray[0]
99 #define hWorkEvent hEventArray[1]
100 static CRITICAL_SECTION csQueue;
101 static LPWORKREQUEST lpHeadWorkQueue;
102 static LPWORKREQUEST lpWorkQueueTail;
103 static HMODULE WININET_hModule;
105 #define HANDLE_CHUNK_SIZE 0x10
107 static CRITICAL_SECTION WININET_cs;
108 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
110 0, 0, &WININET_cs,
111 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
112 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
114 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
116 static LPWININETHANDLEHEADER *WININET_Handles;
117 static UINT WININET_dwNextHandle;
118 static UINT WININET_dwMaxHandles;
120 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
122 LPWININETHANDLEHEADER *p;
123 UINT handle = 0, num;
125 EnterCriticalSection( &WININET_cs );
126 if( !WININET_dwMaxHandles )
128 num = HANDLE_CHUNK_SIZE;
129 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
130 sizeof (UINT)* num);
131 if( !p )
132 goto end;
133 WININET_Handles = p;
134 WININET_dwMaxHandles = num;
136 if( WININET_dwMaxHandles == WININET_dwNextHandle )
138 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
139 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
140 WININET_Handles, sizeof (UINT)* num);
141 if( !p )
142 goto end;
143 WININET_Handles = p;
144 WININET_dwMaxHandles = num;
147 handle = WININET_dwNextHandle;
148 if( WININET_Handles[handle] )
149 ERR("handle isn't free but should be\n");
150 WININET_Handles[handle] = WININET_AddRef( info );
152 while( WININET_Handles[WININET_dwNextHandle] &&
153 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
154 WININET_dwNextHandle++;
156 end:
157 LeaveCriticalSection( &WININET_cs );
159 return (HINTERNET) (handle+1);
162 HINTERNET WININET_FindHandle( LPWININETHANDLEHEADER info )
164 UINT i, handle = 0;
166 EnterCriticalSection( &WININET_cs );
167 for( i=0; i<WININET_dwMaxHandles; i++ )
169 if( info == WININET_Handles[i] )
171 WININET_AddRef( info );
172 handle = i+1;
173 break;
176 LeaveCriticalSection( &WININET_cs );
178 return (HINTERNET) handle;
181 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
183 info->dwRefCount++;
184 TRACE("%p -> refcount = %ld\n", info, info->dwRefCount );
185 return info;
188 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
190 LPWININETHANDLEHEADER info = NULL;
191 UINT handle = (UINT) hinternet;
193 EnterCriticalSection( &WININET_cs );
195 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
196 WININET_Handles[handle-1] )
197 info = WININET_AddRef( WININET_Handles[handle-1] );
199 LeaveCriticalSection( &WININET_cs );
201 TRACE("handle %d -> %p\n", handle, info);
203 return info;
206 BOOL WININET_Release( LPWININETHANDLEHEADER info )
208 info->dwRefCount--;
209 TRACE( "object %p refcount = %ld\n", info, info->dwRefCount );
210 if( !info->dwRefCount )
212 TRACE( "destroying object %p\n", info);
213 info->destroy( info );
215 return TRUE;
218 BOOL WININET_FreeHandle( HINTERNET hinternet )
220 BOOL ret = FALSE;
221 UINT handle = (UINT) hinternet;
222 LPWININETHANDLEHEADER info = NULL;
224 EnterCriticalSection( &WININET_cs );
226 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
228 handle--;
229 if( WININET_Handles[handle] )
231 info = WININET_Handles[handle];
232 TRACE( "destroying handle %d for object %p\n", handle+1, info);
233 WININET_Handles[handle] = NULL;
234 ret = TRUE;
235 if( WININET_dwNextHandle > handle )
236 WININET_dwNextHandle = handle;
240 LeaveCriticalSection( &WININET_cs );
242 if( info )
243 WININET_Release( info );
245 return ret;
248 /***********************************************************************
249 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
251 * PARAMS
252 * hinstDLL [I] handle to the DLL's instance
253 * fdwReason [I]
254 * lpvReserved [I] reserved, must be NULL
256 * RETURNS
257 * Success: TRUE
258 * Failure: FALSE
261 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
263 TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
265 switch (fdwReason) {
266 case DLL_PROCESS_ATTACH:
268 g_dwTlsErrIndex = TlsAlloc();
270 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
271 return FALSE;
273 hQuitEvent = CreateEventW(0, TRUE, FALSE, NULL);
274 hWorkEvent = CreateEventW(0, FALSE, FALSE, NULL);
275 InitializeCriticalSection(&csQueue);
277 URLCacheContainers_CreateDefaults();
279 dwNumThreads = 0;
280 dwNumIdleThreads = 0;
281 dwNumJobs = 0;
283 WININET_hModule = (HMODULE)hinstDLL;
285 case DLL_THREAD_ATTACH:
287 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR));
288 if (NULL == lpwite)
289 return FALSE;
291 TlsSetValue(g_dwTlsErrIndex, (LPVOID)lpwite);
293 break;
295 case DLL_THREAD_DETACH:
296 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
298 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
299 HeapFree(GetProcessHeap(), 0, lpwite);
301 break;
303 case DLL_PROCESS_DETACH:
305 URLCacheContainers_DeleteAll();
307 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
309 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
310 TlsFree(g_dwTlsErrIndex);
313 SetEvent(hQuitEvent);
315 CloseHandle(hQuitEvent);
316 CloseHandle(hWorkEvent);
317 DeleteCriticalSection(&csQueue);
318 break;
321 return TRUE;
325 /***********************************************************************
326 * InternetInitializeAutoProxyDll (WININET.@)
328 * Setup the internal proxy
330 * PARAMETERS
331 * dwReserved
333 * RETURNS
334 * FALSE on failure
337 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
339 FIXME("STUB\n");
340 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
341 return FALSE;
344 /***********************************************************************
345 * DetectAutoProxyUrl (WININET.@)
347 * Auto detect the proxy url
349 * RETURNS
350 * FALSE on failure
353 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
354 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
356 FIXME("STUB\n");
357 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
358 return FALSE;
362 /***********************************************************************
363 * INTERNET_ConfigureProxyFromReg
365 * FIXME:
366 * The proxy may be specified in the form 'http=proxy.my.org'
367 * Presumably that means there can be ftp=ftpproxy.my.org too.
369 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
371 HKEY key;
372 DWORD r, keytype, len, enabled;
373 LPCSTR lpszInternetSettings =
374 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
375 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
377 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
378 if ( r != ERROR_SUCCESS )
379 return FALSE;
381 len = sizeof enabled;
382 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
383 (BYTE*)&enabled, &len);
384 if( (r == ERROR_SUCCESS) && enabled )
386 TRACE("Proxy is enabled.\n");
388 /* figure out how much memory the proxy setting takes */
389 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
390 NULL, &len);
391 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
393 LPWSTR szProxy, p;
394 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
396 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
397 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
398 (BYTE*)szProxy, &len);
400 /* find the http proxy, and strip away everything else */
401 p = strstrW( szProxy, szHttp );
402 if( p )
404 p += lstrlenW(szHttp);
405 lstrcpyW( szProxy, p );
407 p = strchrW( szProxy, ' ' );
408 if( p )
409 *p = 0;
411 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
412 lpwai->lpszProxy = szProxy;
414 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
416 else
417 ERR("Couldn't read proxy server settings.\n");
419 else
420 TRACE("Proxy is not enabled.\n");
421 RegCloseKey(key);
423 return enabled;
426 /***********************************************************************
427 * dump_INTERNET_FLAGS
429 * Helper function to TRACE the internet flags.
431 * RETURNS
432 * None
435 static void dump_INTERNET_FLAGS(DWORD dwFlags)
437 #define FE(x) { x, #x }
438 static const wininet_flag_info flag[] = {
439 FE(INTERNET_FLAG_RELOAD),
440 FE(INTERNET_FLAG_RAW_DATA),
441 FE(INTERNET_FLAG_EXISTING_CONNECT),
442 FE(INTERNET_FLAG_ASYNC),
443 FE(INTERNET_FLAG_PASSIVE),
444 FE(INTERNET_FLAG_NO_CACHE_WRITE),
445 FE(INTERNET_FLAG_MAKE_PERSISTENT),
446 FE(INTERNET_FLAG_FROM_CACHE),
447 FE(INTERNET_FLAG_SECURE),
448 FE(INTERNET_FLAG_KEEP_CONNECTION),
449 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
450 FE(INTERNET_FLAG_READ_PREFETCH),
451 FE(INTERNET_FLAG_NO_COOKIES),
452 FE(INTERNET_FLAG_NO_AUTH),
453 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
454 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
455 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
456 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
457 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
458 FE(INTERNET_FLAG_RESYNCHRONIZE),
459 FE(INTERNET_FLAG_HYPERLINK),
460 FE(INTERNET_FLAG_NO_UI),
461 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
462 FE(INTERNET_FLAG_CACHE_ASYNC),
463 FE(INTERNET_FLAG_FORMS_SUBMIT),
464 FE(INTERNET_FLAG_NEED_FILE),
465 FE(INTERNET_FLAG_TRANSFER_ASCII),
466 FE(INTERNET_FLAG_TRANSFER_BINARY)
468 #undef FE
469 int i;
471 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
472 if (flag[i].val & dwFlags) {
473 TRACE(" %s", flag[i].name);
474 dwFlags &= ~flag[i].val;
477 if (dwFlags)
478 TRACE(" Unknown flags (%08lx)\n", dwFlags);
479 else
480 TRACE("\n");
483 /***********************************************************************
484 * InternetOpenW (WININET.@)
486 * Per-application initialization of wininet
488 * RETURNS
489 * HINTERNET on success
490 * NULL on failure
493 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
494 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
496 LPWININETAPPINFOW lpwai = NULL;
497 HINTERNET handle = NULL;
499 if (TRACE_ON(wininet)) {
500 #define FE(x) { x, #x }
501 static const wininet_flag_info access_type[] = {
502 FE(INTERNET_OPEN_TYPE_PRECONFIG),
503 FE(INTERNET_OPEN_TYPE_DIRECT),
504 FE(INTERNET_OPEN_TYPE_PROXY),
505 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
507 #undef FE
508 DWORD i;
509 const char *access_type_str = "Unknown";
511 TRACE("(%s, %li, %s, %s, %li)\n", debugstr_w(lpszAgent), dwAccessType,
512 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
513 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
514 if (access_type[i].val == dwAccessType) {
515 access_type_str = access_type[i].name;
516 break;
519 TRACE(" access type : %s\n", access_type_str);
520 TRACE(" flags :");
521 dump_INTERNET_FLAGS(dwFlags);
524 /* Clear any error information */
525 INTERNET_SetLastError(0);
527 lpwai = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW));
528 if (NULL == lpwai)
530 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
531 goto lend;
534 memset(lpwai, 0, sizeof(WININETAPPINFOW));
535 lpwai->hdr.htype = WH_HINIT;
536 lpwai->hdr.lpwhparent = NULL;
537 lpwai->hdr.dwFlags = dwFlags;
538 lpwai->hdr.dwRefCount = 1;
539 lpwai->hdr.destroy = INTERNET_CloseHandle;
540 lpwai->dwAccessType = dwAccessType;
541 lpwai->lpszProxyUsername = NULL;
542 lpwai->lpszProxyPassword = NULL;
544 handle = WININET_AllocHandle( &lpwai->hdr );
545 if( !handle )
547 HeapFree( GetProcessHeap(), 0, lpwai );
548 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
549 goto lend;
552 if (NULL != lpszAgent)
554 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
555 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
556 if (lpwai->lpszAgent)
557 lstrcpyW( lpwai->lpszAgent, lpszAgent );
559 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
560 INTERNET_ConfigureProxyFromReg( lpwai );
561 else if (NULL != lpszProxy)
563 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
564 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
565 if (lpwai->lpszProxy)
566 lstrcpyW( lpwai->lpszProxy, lpszProxy );
569 if (NULL != lpszProxyBypass)
571 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
572 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
573 if (lpwai->lpszProxyBypass)
574 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
577 lend:
578 if( lpwai )
579 WININET_Release( &lpwai->hdr );
581 TRACE("returning %p\n", lpwai);
583 return handle;
587 /***********************************************************************
588 * InternetOpenA (WININET.@)
590 * Per-application initialization of wininet
592 * RETURNS
593 * HINTERNET on success
594 * NULL on failure
597 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
598 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
600 HINTERNET rc = (HINTERNET)NULL;
601 INT len;
602 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
604 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent),
605 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
607 if( lpszAgent )
609 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
610 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
611 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
614 if( lpszProxy )
616 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
617 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
618 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
621 if( lpszProxyBypass )
623 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
624 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
625 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
628 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
630 HeapFree(GetProcessHeap(), 0, szAgent);
631 HeapFree(GetProcessHeap(), 0, szProxy);
632 HeapFree(GetProcessHeap(), 0, szBypass);
634 return rc;
637 /***********************************************************************
638 * InternetGetLastResponseInfoA (WININET.@)
640 * Return last wininet error description on the calling thread
642 * RETURNS
643 * TRUE on success of writing to buffer
644 * FALSE on failure
647 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
648 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
650 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
652 TRACE("\n");
654 *lpdwError = lpwite->dwError;
655 if (lpwite->dwError)
657 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
658 *lpdwBufferLength = strlen(lpszBuffer);
660 else
661 *lpdwBufferLength = 0;
663 return TRUE;
666 /***********************************************************************
667 * InternetGetLastResponseInfoW (WININET.@)
669 * Return last wininet error description on the calling thread
671 * RETURNS
672 * TRUE on success of writing to buffer
673 * FALSE on failure
676 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
677 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
679 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
681 TRACE("\n");
683 *lpdwError = lpwite->dwError;
684 if (lpwite->dwError)
686 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
687 *lpdwBufferLength = lstrlenW(lpszBuffer);
689 else
690 *lpdwBufferLength = 0;
692 return TRUE;
695 /***********************************************************************
696 * InternetGetConnectedState (WININET.@)
698 * Return connected state
700 * RETURNS
701 * TRUE if connected
702 * if lpdwStatus is not null, return the status (off line,
703 * modem, lan...) in it.
704 * FALSE if not connected
706 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
708 TRACE("(%p, 0x%08lx)\n", lpdwStatus, dwReserved);
710 if (lpdwStatus) {
711 FIXME("always returning LAN connection.\n");
712 *lpdwStatus = INTERNET_CONNECTION_LAN;
714 return TRUE;
718 /***********************************************************************
719 * InternetGetConnectedStateExW (WININET.@)
721 * Return connected state
723 * PARAMS
725 * lpdwStatus [O] Flags specifying the status of the internet connection.
726 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
727 * dwNameLen [I] Size of the buffer, in characters.
728 * dwReserved [I] Reserved. Must be set to 0.
730 * RETURNS
731 * TRUE if connected
732 * if lpdwStatus is not null, return the status (off line,
733 * modem, lan...) in it.
734 * FALSE if not connected
736 * NOTES
737 * If the system has no available network connections, an empty string is
738 * stored in lpszConnectionName. If there is a LAN connection, a localized
739 * "LAN Connection" string is stored. Presumably, if only a dial-up
740 * connection is available then the name of the dial-up connection is
741 * returned. Why any application, other than the "Internet Settings" CPL,
742 * would want to use this function instead of the simpler InternetGetConnectedStateW
743 * function is beyond me.
745 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
746 DWORD dwNameLen, DWORD dwReserved)
748 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
750 /* Must be zero */
751 if(dwReserved)
752 return FALSE;
754 if (lpdwStatus) {
755 FIXME("always returning LAN connection.\n");
756 *lpdwStatus = INTERNET_CONNECTION_LAN;
758 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
762 /***********************************************************************
763 * InternetGetConnectedStateExA (WININET.@)
765 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
766 DWORD dwNameLen, DWORD dwReserved)
768 LPWSTR lpwszConnectionName = NULL;
769 BOOL rc;
771 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
773 if (lpszConnectionName && dwNameLen > 0)
774 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
776 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
777 dwReserved);
778 if (rc && lpwszConnectionName)
780 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
781 dwNameLen, NULL, NULL);
783 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
786 return rc;
790 /***********************************************************************
791 * InternetConnectW (WININET.@)
793 * Open a ftp, gopher or http session
795 * RETURNS
796 * HINTERNET a session handle on success
797 * NULL on failure
800 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
801 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
802 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
803 DWORD dwService, DWORD dwFlags, DWORD dwContext)
805 LPWININETAPPINFOW hIC;
806 HINTERNET rc = (HINTERNET) NULL;
808 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet, debugstr_w(lpszServerName),
809 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
810 dwService, dwFlags, dwContext);
812 /* Clear any error information */
813 INTERNET_SetLastError(0);
814 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
815 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
816 goto lend;
818 switch (dwService)
820 case INTERNET_SERVICE_FTP:
821 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
822 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
823 break;
825 case INTERNET_SERVICE_HTTP:
826 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
827 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
828 break;
830 case INTERNET_SERVICE_GOPHER:
831 default:
832 break;
834 lend:
835 if( hIC )
836 WININET_Release( &hIC->hdr );
838 TRACE("returning %p\n", rc);
839 return rc;
843 /***********************************************************************
844 * InternetConnectA (WININET.@)
846 * Open a ftp, gopher or http session
848 * RETURNS
849 * HINTERNET a session handle on success
850 * NULL on failure
853 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
854 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
855 LPCSTR lpszUserName, LPCSTR lpszPassword,
856 DWORD dwService, DWORD dwFlags, DWORD dwContext)
858 HINTERNET rc = (HINTERNET)NULL;
859 INT len = 0;
860 LPWSTR szServerName = NULL;
861 LPWSTR szUserName = NULL;
862 LPWSTR szPassword = NULL;
864 if (lpszServerName)
866 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
867 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
868 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
870 if (lpszUserName)
872 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
873 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
874 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
876 if (lpszPassword)
878 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
879 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
880 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
884 rc = InternetConnectW(hInternet, szServerName, nServerPort,
885 szUserName, szPassword, dwService, dwFlags, dwContext);
887 HeapFree(GetProcessHeap(), 0, szServerName);
888 HeapFree(GetProcessHeap(), 0, szUserName);
889 HeapFree(GetProcessHeap(), 0, szPassword);
890 return rc;
894 /***********************************************************************
895 * InternetFindNextFileA (WININET.@)
897 * Continues a file search from a previous call to FindFirstFile
899 * RETURNS
900 * TRUE on success
901 * FALSE on failure
904 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
906 BOOL ret;
907 WIN32_FIND_DATAW fd;
909 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
910 if(lpvFindData)
911 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
912 return ret;
915 /***********************************************************************
916 * InternetFindNextFileW (WININET.@)
918 * Continues a file search from a previous call to FindFirstFile
920 * RETURNS
921 * TRUE on success
922 * FALSE on failure
925 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
927 LPWININETAPPINFOW hIC = NULL;
928 LPWININETFINDNEXTW lpwh;
929 BOOL bSuccess = FALSE;
931 TRACE("\n");
933 lpwh = (LPWININETFINDNEXTW) WININET_GetObject( hFind );
934 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
936 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
937 goto lend;
940 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
941 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
943 WORKREQUEST workRequest;
944 struct WORKREQ_INTERNETFINDNEXTW *req;
946 workRequest.asyncall = INTERNETFINDNEXTW;
947 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
948 req = &workRequest.u.InternetFindNextW;
949 req->lpFindFileData = lpvFindData;
951 bSuccess = INTERNET_AsyncCall(&workRequest);
953 else
955 bSuccess = INTERNET_FindNextFileW(lpwh, lpvFindData);
957 lend:
958 if( lpwh )
959 WININET_Release( &lpwh->hdr );
960 return bSuccess;
963 /***********************************************************************
964 * INTERNET_FindNextFileW (Internal)
966 * Continues a file search from a previous call to FindFirstFile
968 * RETURNS
969 * TRUE on success
970 * FALSE on failure
973 BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData)
975 BOOL bSuccess = TRUE;
976 LPWIN32_FIND_DATAW lpFindFileData;
978 TRACE("\n");
980 assert (lpwh->hdr.htype == WH_HFINDNEXT);
982 /* Clear any error information */
983 INTERNET_SetLastError(0);
985 if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
987 FIXME("Only FTP find next supported\n");
988 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
989 return FALSE;
992 TRACE("index(%ld) size(%ld)\n", lpwh->index, lpwh->size);
994 lpFindFileData = (LPWIN32_FIND_DATAW) lpvFindData;
995 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
997 if (lpwh->index >= lpwh->size)
999 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
1000 bSuccess = FALSE;
1001 goto lend;
1004 FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
1005 lpwh->index++;
1007 TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData->cFileName), lpFindFileData->nFileSizeLow);
1009 lend:
1011 if (lpwh->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1013 INTERNET_ASYNC_RESULT iar;
1015 iar.dwResult = (DWORD)bSuccess;
1016 iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
1017 INTERNET_GetLastError();
1019 INTERNET_SendCallback(&lpwh->hdr, lpwh->hdr.dwContext,
1020 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1021 sizeof(INTERNET_ASYNC_RESULT));
1024 return bSuccess;
1028 /***********************************************************************
1029 * INTERNET_CloseHandle (internal)
1031 * Close internet handle
1033 * RETURNS
1034 * Void
1037 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
1039 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
1041 TRACE("%p\n",lpwai);
1043 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
1044 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
1045 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
1046 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
1047 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
1048 HeapFree(GetProcessHeap(), 0, lpwai);
1052 /***********************************************************************
1053 * InternetCloseHandle (WININET.@)
1055 * Generic close handle function
1057 * RETURNS
1058 * TRUE on success
1059 * FALSE on failure
1062 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1064 LPWININETHANDLEHEADER lpwh;
1066 TRACE("%p\n",hInternet);
1068 lpwh = WININET_GetObject( hInternet );
1069 if (NULL == lpwh)
1071 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1072 return FALSE;
1075 /* FIXME: native appears to send this from the equivalent of
1076 * WININET_Release */
1077 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1078 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
1079 sizeof(HINTERNET));
1081 if( lpwh->lpwhparent )
1082 WININET_Release( lpwh->lpwhparent );
1083 WININET_FreeHandle( hInternet );
1084 WININET_Release( lpwh );
1086 return TRUE;
1090 /***********************************************************************
1091 * ConvertUrlComponentValue (Internal)
1093 * Helper function for InternetCrackUrlW
1096 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1097 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1098 LPCSTR lpszStart, LPCWSTR lpwszStart)
1100 TRACE("%p %p %p %ld %p %p\n", lppszComponent, dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1101 if (*dwComponentLen != 0)
1103 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1104 if (*lppszComponent == NULL)
1106 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1107 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1108 *dwComponentLen = nASCIILength;
1110 else
1112 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1113 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1114 (*lppszComponent)[ncpylen]=0;
1115 *dwComponentLen = ncpylen;
1121 /***********************************************************************
1122 * InternetCrackUrlA (WININET.@)
1124 * Break up URL into its components
1126 * TODO: Handle dwFlags
1128 * RETURNS
1129 * TRUE on success
1130 * FALSE on failure
1133 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1134 LPURL_COMPONENTSA lpUrlComponents)
1136 DWORD nLength;
1137 URL_COMPONENTSW UCW;
1138 WCHAR* lpwszUrl;
1140 TRACE("(%s %lu %lx %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1141 if(dwUrlLength<=0)
1142 dwUrlLength=-1;
1143 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1145 /* if dwUrlLength=-1 then nLength includes null but length to
1146 InternetCrackUrlW should not include it */
1147 if (dwUrlLength == -1) nLength--;
1149 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1150 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1152 memset(&UCW,0,sizeof(UCW));
1153 if(lpUrlComponents->dwHostNameLength!=0)
1154 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1155 if(lpUrlComponents->dwUserNameLength!=0)
1156 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1157 if(lpUrlComponents->dwPasswordLength!=0)
1158 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1159 if(lpUrlComponents->dwUrlPathLength!=0)
1160 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1161 if(lpUrlComponents->dwSchemeLength!=0)
1162 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1163 if(lpUrlComponents->dwExtraInfoLength!=0)
1164 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1165 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1167 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1168 return FALSE;
1171 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1172 UCW.lpszHostName, UCW.dwHostNameLength,
1173 lpszUrl, lpwszUrl);
1174 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1175 UCW.lpszUserName, UCW.dwUserNameLength,
1176 lpszUrl, lpwszUrl);
1177 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1178 UCW.lpszPassword, UCW.dwPasswordLength,
1179 lpszUrl, lpwszUrl);
1180 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1181 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1182 lpszUrl, lpwszUrl);
1183 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1184 UCW.lpszScheme, UCW.dwSchemeLength,
1185 lpszUrl, lpwszUrl);
1186 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1187 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1188 lpszUrl, lpwszUrl);
1189 lpUrlComponents->nScheme=UCW.nScheme;
1190 lpUrlComponents->nPort=UCW.nPort;
1191 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1193 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1194 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1195 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1196 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1197 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1199 return TRUE;
1202 /***********************************************************************
1203 * GetInternetSchemeW (internal)
1205 * Get scheme of url
1207 * RETURNS
1208 * scheme on success
1209 * INTERNET_SCHEME_UNKNOWN on failure
1212 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1214 INTERNET_SCHEME iScheme=INTERNET_SCHEME_UNKNOWN;
1215 static const WCHAR lpszFtp[]={'f','t','p',0};
1216 static const WCHAR lpszGopher[]={'g','o','p','h','e','r',0};
1217 static const WCHAR lpszHttp[]={'h','t','t','p',0};
1218 static const WCHAR lpszHttps[]={'h','t','t','p','s',0};
1219 static const WCHAR lpszFile[]={'f','i','l','e',0};
1220 static const WCHAR lpszNews[]={'n','e','w','s',0};
1221 static const WCHAR lpszMailto[]={'m','a','i','l','t','o',0};
1222 static const WCHAR lpszRes[]={'r','e','s',0};
1223 WCHAR* tempBuffer=NULL;
1224 TRACE("%s %ld\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1225 if(lpszScheme==NULL)
1226 return INTERNET_SCHEME_UNKNOWN;
1228 tempBuffer=HeapAlloc(GetProcessHeap(),0,(nMaxCmp+1)*sizeof(WCHAR));
1229 lstrcpynW(tempBuffer,lpszScheme,nMaxCmp+1);
1230 strlwrW(tempBuffer);
1231 if (nMaxCmp==strlenW(lpszFtp) && !strncmpW(lpszFtp, tempBuffer, nMaxCmp))
1232 iScheme=INTERNET_SCHEME_FTP;
1233 else if (nMaxCmp==strlenW(lpszGopher) && !strncmpW(lpszGopher, tempBuffer, nMaxCmp))
1234 iScheme=INTERNET_SCHEME_GOPHER;
1235 else if (nMaxCmp==strlenW(lpszHttp) && !strncmpW(lpszHttp, tempBuffer, nMaxCmp))
1236 iScheme=INTERNET_SCHEME_HTTP;
1237 else if (nMaxCmp==strlenW(lpszHttps) && !strncmpW(lpszHttps, tempBuffer, nMaxCmp))
1238 iScheme=INTERNET_SCHEME_HTTPS;
1239 else if (nMaxCmp==strlenW(lpszFile) && !strncmpW(lpszFile, tempBuffer, nMaxCmp))
1240 iScheme=INTERNET_SCHEME_FILE;
1241 else if (nMaxCmp==strlenW(lpszNews) && !strncmpW(lpszNews, tempBuffer, nMaxCmp))
1242 iScheme=INTERNET_SCHEME_NEWS;
1243 else if (nMaxCmp==strlenW(lpszMailto) && !strncmpW(lpszMailto, tempBuffer, nMaxCmp))
1244 iScheme=INTERNET_SCHEME_MAILTO;
1245 else if (nMaxCmp==strlenW(lpszRes) && !strncmpW(lpszRes, tempBuffer, nMaxCmp))
1246 iScheme=INTERNET_SCHEME_RES;
1247 HeapFree(GetProcessHeap(),0,tempBuffer);
1248 return iScheme;
1251 /***********************************************************************
1252 * SetUrlComponentValueW (Internal)
1254 * Helper function for InternetCrackUrlW
1256 * PARAMS
1257 * lppszComponent [O] Holds the returned string
1258 * dwComponentLen [I] Holds the size of lppszComponent
1259 * [O] Holds the length of the string in lppszComponent without '\0'
1260 * lpszStart [I] Holds the string to copy from
1261 * len [I] Holds the length of lpszStart without '\0'
1263 * RETURNS
1264 * TRUE on success
1265 * FALSE on failure
1268 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1270 TRACE("%s (%ld)\n", debugstr_wn(lpszStart,len), len);
1272 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1273 return FALSE;
1275 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1277 if (*lppszComponent == NULL)
1279 *lppszComponent = (LPWSTR)lpszStart;
1280 *dwComponentLen = len;
1282 else
1284 DWORD ncpylen = min((*dwComponentLen)-1, len);
1285 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1286 (*lppszComponent)[ncpylen] = '\0';
1287 *dwComponentLen = ncpylen;
1291 return TRUE;
1294 /***********************************************************************
1295 * InternetCrackUrlW (WININET.@)
1297 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1298 LPURL_COMPONENTSW lpUC)
1301 * RFC 1808
1302 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1305 LPCWSTR lpszParam = NULL;
1306 BOOL bIsAbsolute = FALSE;
1307 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1308 LPCWSTR lpszcp = NULL;
1309 LPWSTR lpszUrl_decode = NULL;
1310 DWORD dwUrlLength = dwUrlLength_orig;
1311 const WCHAR lpszSeparators[3]={';','?',0};
1312 const WCHAR lpszSlash[2]={'/',0};
1313 if(dwUrlLength==0)
1314 dwUrlLength=strlenW(lpszUrl);
1316 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1317 if (dwFlags & ICU_DECODE)
1319 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1320 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1322 lpszUrl = lpszUrl_decode;
1325 lpszap = lpszUrl;
1327 /* Determine if the URI is absolute. */
1328 while (*lpszap != '\0')
1330 if (isalnumW(*lpszap))
1332 lpszap++;
1333 continue;
1335 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1337 bIsAbsolute = TRUE;
1338 lpszcp = lpszap;
1340 else
1342 lpszcp = lpszUrl; /* Relative url */
1345 break;
1348 /* Parse <params> */
1349 lpszParam = strpbrkW(lpszap, lpszSeparators);
1350 if (lpszParam != NULL)
1352 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1353 lpszParam, dwUrlLength-(lpszParam-lpszUrl));
1356 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1358 LPCWSTR lpszNetLoc;
1359 static const WCHAR wszAbout[]={'a','b','o','u','t',':',0};
1361 /* Get scheme first. */
1362 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1363 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1364 lpszUrl, lpszcp - lpszUrl);
1366 /* Eat ':' in protocol. */
1367 lpszcp++;
1369 /* if the scheme is "about", there is no host */
1370 if(strncmpW(wszAbout,lpszUrl, lpszcp - lpszUrl)==0)
1372 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1373 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1374 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1375 lpUC->nPort = 0;
1377 else
1379 /* Skip over slashes. */
1380 if (*lpszcp == '/')
1382 lpszcp++;
1383 if (*lpszcp == '/')
1385 lpszcp++;
1386 if (*lpszcp == '/')
1387 lpszcp++;
1391 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1392 if (lpszParam)
1394 if (lpszNetLoc)
1395 lpszNetLoc = min(lpszNetLoc, lpszParam);
1396 else
1397 lpszNetLoc = lpszParam;
1399 else if (!lpszNetLoc)
1400 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1402 /* Parse net-loc */
1403 if (lpszNetLoc)
1405 LPCWSTR lpszHost;
1406 LPCWSTR lpszPort;
1408 /* [<user>[<:password>]@]<host>[:<port>] */
1409 /* First find the user and password if they exist */
1411 lpszHost = strchrW(lpszcp, '@');
1412 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1414 /* username and password not specified. */
1415 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1416 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1418 else /* Parse out username and password */
1420 LPCWSTR lpszUser = lpszcp;
1421 LPCWSTR lpszPasswd = lpszHost;
1423 while (lpszcp < lpszHost)
1425 if (*lpszcp == ':')
1426 lpszPasswd = lpszcp;
1428 lpszcp++;
1431 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1432 lpszUser, lpszPasswd - lpszUser);
1434 if (lpszPasswd != lpszHost)
1435 lpszPasswd++;
1436 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1437 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1438 lpszHost - lpszPasswd);
1440 lpszcp++; /* Advance to beginning of host */
1443 /* Parse <host><:port> */
1445 lpszHost = lpszcp;
1446 lpszPort = lpszNetLoc;
1448 /* special case for res:// URLs: there is no port here, so the host is the
1449 entire string up to the first '/' */
1450 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1452 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1453 lpszHost, lpszPort - lpszHost);
1454 lpUC->nPort = 0;
1455 lpszcp=lpszNetLoc;
1457 else
1459 while (lpszcp < lpszNetLoc)
1461 if (*lpszcp == ':')
1462 lpszPort = lpszcp;
1464 lpszcp++;
1467 /* If the scheme is "file" and the host is just one letter, it's not a host */
1468 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1470 lpszcp=lpszHost;
1471 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1472 NULL, 0);
1473 lpUC->nPort = 0;
1475 else
1477 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1478 lpszHost, lpszPort - lpszHost);
1479 if (lpszPort != lpszNetLoc)
1480 lpUC->nPort = atoiW(++lpszPort);
1481 else
1482 lpUC->nPort = 0;
1489 /* Here lpszcp points to:
1491 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1492 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1494 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1496 INT len;
1498 /* Only truncate the parameter list if it's already been saved
1499 * in lpUC->lpszExtraInfo.
1501 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1502 len = lpszParam - lpszcp;
1503 else
1505 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1506 * newlines if necessary.
1508 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1509 if (lpsznewline != NULL)
1510 len = lpsznewline - lpszcp;
1511 else
1512 len = dwUrlLength-(lpszcp-lpszUrl);
1514 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1515 lpszcp, len);
1517 else
1519 lpUC->dwUrlPathLength = 0;
1522 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1523 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1524 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1525 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1526 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1528 if (lpszUrl_decode)
1529 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1530 return TRUE;
1533 /***********************************************************************
1534 * InternetAttemptConnect (WININET.@)
1536 * Attempt to make a connection to the internet
1538 * RETURNS
1539 * ERROR_SUCCESS on success
1540 * Error value on failure
1543 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1545 FIXME("Stub\n");
1546 return ERROR_SUCCESS;
1550 /***********************************************************************
1551 * InternetCanonicalizeUrlA (WININET.@)
1553 * Escape unsafe characters and spaces
1555 * RETURNS
1556 * TRUE on success
1557 * FALSE on failure
1560 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1561 LPDWORD lpdwBufferLength, DWORD dwFlags)
1563 HRESULT hr;
1564 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1565 if(dwFlags & ICU_DECODE)
1567 dwURLFlags |= URL_UNESCAPE;
1568 dwFlags &= ~ICU_DECODE;
1571 if(dwFlags & ICU_ESCAPE)
1573 dwURLFlags |= URL_UNESCAPE;
1574 dwFlags &= ~ICU_ESCAPE;
1576 if(dwFlags & ICU_BROWSER_MODE)
1578 dwURLFlags |= URL_BROWSER_MODE;
1579 dwFlags &= ~ICU_BROWSER_MODE;
1581 if(dwFlags)
1582 FIXME("Unhandled flags 0x%08lx\n", dwFlags);
1583 TRACE("%s %p %p %08lx\n", debugstr_a(lpszUrl), lpszBuffer,
1584 lpdwBufferLength, dwURLFlags);
1586 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1587 dwFlags ^= ICU_NO_ENCODE;
1589 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1591 return (hr == S_OK) ? TRUE : FALSE;
1594 /***********************************************************************
1595 * InternetCanonicalizeUrlW (WININET.@)
1597 * Escape unsafe characters and spaces
1599 * RETURNS
1600 * TRUE on success
1601 * FALSE on failure
1604 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1605 LPDWORD lpdwBufferLength, DWORD dwFlags)
1607 HRESULT hr;
1608 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1609 if(dwFlags & ICU_DECODE)
1611 dwURLFlags |= URL_UNESCAPE;
1612 dwFlags &= ~ICU_DECODE;
1615 if(dwFlags & ICU_ESCAPE)
1617 dwURLFlags |= URL_UNESCAPE;
1618 dwFlags &= ~ICU_ESCAPE;
1620 if(dwFlags & ICU_BROWSER_MODE)
1622 dwURLFlags |= URL_BROWSER_MODE;
1623 dwFlags &= ~ICU_BROWSER_MODE;
1625 if(dwFlags)
1626 FIXME("Unhandled flags 0x%08lx\n", dwFlags);
1627 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
1628 lpdwBufferLength, dwURLFlags);
1630 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1631 dwFlags ^= ICU_NO_ENCODE;
1633 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1635 return (hr == S_OK) ? TRUE : FALSE;
1639 /***********************************************************************
1640 * InternetSetStatusCallbackA (WININET.@)
1642 * Sets up a callback function which is called as progress is made
1643 * during an operation.
1645 * RETURNS
1646 * Previous callback or NULL on success
1647 * INTERNET_INVALID_STATUS_CALLBACK on failure
1650 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1651 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1653 INTERNET_STATUS_CALLBACK retVal;
1654 LPWININETHANDLEHEADER lpwh;
1656 TRACE("0x%08lx\n", (ULONG)hInternet);
1658 lpwh = WININET_GetObject(hInternet);
1659 if (!lpwh)
1660 return INTERNET_INVALID_STATUS_CALLBACK;
1662 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1663 retVal = lpwh->lpfnStatusCB;
1664 lpwh->lpfnStatusCB = lpfnIntCB;
1666 WININET_Release( lpwh );
1668 return retVal;
1671 /***********************************************************************
1672 * InternetSetStatusCallbackW (WININET.@)
1674 * Sets up a callback function which is called as progress is made
1675 * during an operation.
1677 * RETURNS
1678 * Previous callback or NULL on success
1679 * INTERNET_INVALID_STATUS_CALLBACK on failure
1682 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1683 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1685 INTERNET_STATUS_CALLBACK retVal;
1686 LPWININETHANDLEHEADER lpwh;
1688 TRACE("0x%08lx\n", (ULONG)hInternet);
1690 lpwh = WININET_GetObject(hInternet);
1691 if (!lpwh)
1692 return INTERNET_INVALID_STATUS_CALLBACK;
1694 lpwh->dwInternalFlags |= INET_CALLBACKW;
1695 retVal = lpwh->lpfnStatusCB;
1696 lpwh->lpfnStatusCB = lpfnIntCB;
1698 WININET_Release( lpwh );
1700 return retVal;
1703 /***********************************************************************
1704 * InternetSetFilePointer (WININET.@)
1706 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1707 PVOID pReserved, DWORD dwMoveContext, DWORD dwContext)
1709 FIXME("stub\n");
1710 return FALSE;
1713 /***********************************************************************
1714 * InternetWriteFile (WININET.@)
1716 * Write data to an open internet file
1718 * RETURNS
1719 * TRUE on success
1720 * FALSE on failure
1723 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1724 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1726 BOOL retval = FALSE;
1727 int nSocket = -1;
1728 LPWININETHANDLEHEADER lpwh;
1730 TRACE("\n");
1731 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1732 if (NULL == lpwh)
1733 return FALSE;
1735 switch (lpwh->htype)
1737 case WH_HHTTPREQ:
1739 LPWININETHTTPREQW lpwhr;
1740 lpwhr = (LPWININETHTTPREQW)lpwh;
1742 TRACE("HTTPREQ %li\n",dwNumOfBytesToWrite);
1743 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1744 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1746 WININET_Release( lpwh );
1747 return retval;
1749 break;
1751 case WH_HFILE:
1752 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1753 break;
1755 default:
1756 break;
1759 if (nSocket != -1)
1761 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1762 retval = (res >= 0);
1763 *lpdwNumOfBytesWritten = retval ? res : 0;
1765 WININET_Release( lpwh );
1767 return retval;
1771 static BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1772 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1773 BOOL bWait, BOOL bSendCompletionStatus)
1775 BOOL retval = FALSE;
1776 int nSocket = -1;
1778 /* FIXME: this should use NETCON functions! */
1779 switch (lpwh->htype)
1781 case WH_HHTTPREQ:
1782 if (!NETCON_recv(&((LPWININETHTTPREQW)lpwh)->netConnection, lpBuffer,
1783 dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0, (int *)pdwNumOfBytesRead))
1785 *pdwNumOfBytesRead = 0;
1786 retval = TRUE; /* Under windows, it seems to return 0 even if nothing was read... */
1788 else
1789 retval = TRUE;
1790 break;
1792 case WH_HFILE:
1793 /* FIXME: FTP should use NETCON_ stuff */
1794 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1795 if (nSocket != -1)
1797 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1798 retval = (res >= 0);
1799 *pdwNumOfBytesRead = retval ? res : 0;
1801 break;
1803 default:
1804 break;
1807 if (bSendCompletionStatus)
1809 INTERNET_ASYNC_RESULT iar;
1811 iar.dwResult = retval;
1812 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1813 INTERNET_GetLastError();
1815 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1816 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1817 sizeof(INTERNET_ASYNC_RESULT));
1819 return retval;
1822 /***********************************************************************
1823 * InternetReadFile (WININET.@)
1825 * Read data from an open internet file
1827 * RETURNS
1828 * TRUE on success
1829 * FALSE on failure
1832 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1833 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1835 LPWININETHANDLEHEADER lpwh;
1836 BOOL retval;
1838 TRACE("%p %p %ld %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1840 lpwh = WININET_GetObject( hFile );
1841 if (!lpwh)
1843 SetLastError(ERROR_INVALID_HANDLE);
1844 return FALSE;
1847 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1848 WININET_Release( lpwh );
1850 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1851 return retval;
1854 /***********************************************************************
1855 * InternetReadFileExA (WININET.@)
1857 * Read data from an open internet file
1859 * PARAMS
1860 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1861 * lpBuffersOut [I/O] Buffer.
1862 * dwFlags [I] Flags. See notes.
1863 * dwContext [I] Context for callbacks.
1865 * RETURNS
1866 * TRUE on success
1867 * FALSE on failure
1869 * NOTES
1870 * The parameter dwFlags include zero or more of the following flags:
1871 *|IRF_ASYNC - Makes the call asynchronous.
1872 *|IRF_SYNC - Makes the call synchronous.
1873 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1874 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1876 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1878 * SEE
1879 * InternetOpenUrlA(), HttpOpenRequestA()
1881 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1882 DWORD dwFlags, DWORD dwContext)
1884 BOOL retval = FALSE;
1885 LPWININETHANDLEHEADER lpwh;
1887 TRACE("(%p %p 0x%lx 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1889 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1890 FIXME("these dwFlags aren't implemented: 0x%lx\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1892 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1894 SetLastError(ERROR_INVALID_PARAMETER);
1895 return FALSE;
1898 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1899 if (!lpwh)
1901 SetLastError(ERROR_INVALID_HANDLE);
1902 return FALSE;
1905 /* FIXME: native only does it asynchronously if the amount of data
1906 * requested isn't available. See NtReadFile. */
1907 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1908 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better, but
1909 * we should implement the above first */
1910 if (dwFlags & IRF_ASYNC)
1912 WORKREQUEST workRequest;
1913 struct WORKREQ_INTERNETREADFILEEXA *req;
1915 workRequest.asyncall = INTERNETREADFILEEXA;
1916 workRequest.hdr = WININET_AddRef( lpwh );
1917 req = &workRequest.u.InternetReadFileExA;
1918 req->lpBuffersOut = lpBuffersOut;
1920 retval = INTERNET_AsyncCall(&workRequest);
1921 if (!retval) return FALSE;
1923 SetLastError(ERROR_IO_PENDING);
1924 return FALSE;
1927 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1928 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1929 !(dwFlags & IRF_NO_WAIT), FALSE);
1931 WININET_Release( lpwh );
1933 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1934 return retval;
1937 /***********************************************************************
1938 * InternetReadFileExW (WININET.@)
1940 * Read data from an open internet file.
1942 * PARAMS
1943 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1944 * lpBuffersOut [I/O] Buffer.
1945 * dwFlags [I] Flags.
1946 * dwContext [I] Context for callbacks.
1948 * RETURNS
1949 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1951 * NOTES
1952 * Not implemented in Wine or native either (as of IE6 SP2).
1955 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1956 DWORD dwFlags, DWORD dwContext)
1958 ERR("(%p, %p, 0x%lx, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1960 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1961 return FALSE;
1964 /***********************************************************************
1965 * INET_QueryOptionHelper (internal)
1967 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1968 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1970 LPWININETHANDLEHEADER lpwhh;
1971 BOOL bSuccess = FALSE;
1973 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1975 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1977 switch (dwOption)
1979 case INTERNET_OPTION_HANDLE_TYPE:
1981 ULONG type;
1983 if (!lpwhh)
1985 WARN("Invalid hInternet handle\n");
1986 SetLastError(ERROR_INVALID_HANDLE);
1987 return FALSE;
1990 type = lpwhh->htype;
1992 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
1994 if (*lpdwBufferLength < sizeof(ULONG))
1995 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1996 else
1998 memcpy(lpBuffer, &type, sizeof(ULONG));
1999 bSuccess = TRUE;
2001 *lpdwBufferLength = sizeof(ULONG);
2002 break;
2005 case INTERNET_OPTION_REQUEST_FLAGS:
2007 ULONG flags = 4;
2008 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
2009 if (*lpdwBufferLength < sizeof(ULONG))
2010 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2011 else
2013 memcpy(lpBuffer, &flags, sizeof(ULONG));
2014 bSuccess = TRUE;
2016 *lpdwBufferLength = sizeof(ULONG);
2017 break;
2020 case INTERNET_OPTION_URL:
2021 case INTERNET_OPTION_DATAFILE_NAME:
2023 if (!lpwhh)
2025 WARN("Invalid hInternet handle\n");
2026 SetLastError(ERROR_INVALID_HANDLE);
2027 return FALSE;
2029 if (lpwhh->htype == WH_HHTTPREQ)
2031 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2032 WCHAR url[1023];
2033 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2034 static const WCHAR szHost[] = {'H','o','s','t',0};
2035 DWORD sizeRequired;
2036 LPHTTPHEADERW Host;
2038 Host = HTTP_GetHeader(lpreq,szHost);
2039 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2040 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2041 if(!bIsUnicode)
2043 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2044 lpBuffer,*lpdwBufferLength,NULL,NULL);
2045 if (sizeRequired > *lpdwBufferLength)
2046 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2047 else
2048 bSuccess = TRUE;
2049 *lpdwBufferLength = sizeRequired;
2051 else
2053 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2054 if (*lpdwBufferLength < sizeRequired)
2055 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2056 else
2058 strcpyW(lpBuffer, url);
2059 bSuccess = TRUE;
2061 *lpdwBufferLength = sizeRequired;
2064 break;
2066 case INTERNET_OPTION_HTTP_VERSION:
2068 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2069 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2070 else
2073 * Presently hardcoded to 1.1
2075 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2076 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2077 bSuccess = TRUE;
2079 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2080 break;
2082 case INTERNET_OPTION_CONNECTED_STATE:
2084 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2085 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2087 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2088 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2089 else
2091 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2092 bSuccess = TRUE;
2094 *lpdwBufferLength = sizeof(*pdwConnectedState);
2095 break;
2097 case INTERNET_OPTION_PROXY:
2099 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2100 WININETAPPINFOW wai;
2102 if (lpwai == NULL)
2104 TRACE("Getting global proxy info\n");
2105 memset(&wai, 0, sizeof(WININETAPPINFOW));
2106 INTERNET_ConfigureProxyFromReg( &wai );
2107 lpwai = &wai;
2110 if (bIsUnicode)
2112 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2113 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2115 if (lpwai->lpszProxy)
2116 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2117 sizeof(WCHAR);
2118 if (lpwai->lpszProxyBypass)
2119 proxyBypassBytesRequired =
2120 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2121 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2122 proxyBytesRequired + proxyBypassBytesRequired)
2123 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2124 else
2126 pPI->dwAccessType = lpwai->dwAccessType;
2127 if (lpwai->lpszProxy)
2129 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2130 sizeof(INTERNET_PROXY_INFOW));
2131 lstrcpyW((LPWSTR)pPI->lpszProxy, lpwai->lpszProxy);
2133 else
2135 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2136 sizeof(INTERNET_PROXY_INFOW));
2137 *((LPWSTR)(pPI->lpszProxy)) = 0;
2140 if (lpwai->lpszProxyBypass)
2142 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2143 sizeof(INTERNET_PROXY_INFOW) +
2144 proxyBytesRequired);
2145 lstrcpyW((LPWSTR)pPI->lpszProxyBypass,
2146 lpwai->lpszProxyBypass);
2148 else
2150 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2151 sizeof(INTERNET_PROXY_INFOW) +
2152 proxyBytesRequired);
2153 *((LPWSTR)(pPI->lpszProxyBypass)) = 0;
2155 bSuccess = TRUE;
2157 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2158 proxyBytesRequired + proxyBypassBytesRequired;
2160 else
2162 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2163 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2165 if (lpwai->lpszProxy)
2166 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2167 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2168 if (lpwai->lpszProxyBypass)
2169 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2170 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2171 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2172 proxyBytesRequired + proxyBypassBytesRequired)
2173 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2174 else
2176 pPI->dwAccessType = lpwai->dwAccessType;
2177 if (lpwai->lpszProxy)
2179 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2180 sizeof(INTERNET_PROXY_INFOA));
2181 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2182 (LPSTR)pPI->lpszProxy, proxyBytesRequired, NULL, NULL);
2184 else
2186 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2187 sizeof(INTERNET_PROXY_INFOA));
2188 *((LPSTR)(pPI->lpszProxy)) = '\0';
2191 if (lpwai->lpszProxyBypass)
2193 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2194 sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
2195 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2196 -1, (LPSTR)pPI->lpszProxyBypass,
2197 proxyBypassBytesRequired,
2198 NULL, NULL);
2200 else
2202 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2203 sizeof(INTERNET_PROXY_INFOA) +
2204 proxyBytesRequired);
2205 *((LPSTR)(pPI->lpszProxyBypass)) = '\0';
2207 bSuccess = TRUE;
2209 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2210 proxyBytesRequired + proxyBypassBytesRequired;
2212 break;
2214 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2216 ULONG conn = 2;
2217 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %ld\n", conn);
2218 if (*lpdwBufferLength < sizeof(ULONG))
2219 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2220 else
2222 memcpy(lpBuffer, &conn, sizeof(ULONG));
2223 bSuccess = TRUE;
2225 *lpdwBufferLength = sizeof(ULONG);
2226 break;
2228 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2230 ULONG conn = 4;
2231 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %ld\n", conn);
2232 if (*lpdwBufferLength < sizeof(ULONG))
2233 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2234 else
2236 memcpy(lpBuffer, &conn, sizeof(ULONG));
2237 bSuccess = TRUE;
2239 *lpdwBufferLength = sizeof(ULONG);
2240 break;
2242 case INTERNET_OPTION_SECURITY_FLAGS:
2243 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2244 break;
2246 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2247 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2249 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2250 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2252 else if (lpwhh->htype == WH_HHTTPREQ)
2254 LPWININETHTTPREQW lpwhr;
2255 PCCERT_CONTEXT context;
2257 lpwhr = (LPWININETHTTPREQW)lpwhh;
2258 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2259 if (context)
2261 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2262 DWORD strLen;
2264 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2265 info->ftExpiry = context->pCertInfo->NotAfter;
2266 info->ftStart = context->pCertInfo->NotBefore;
2267 if (bIsUnicode)
2269 strLen = CertNameToStrW(context->dwCertEncodingType,
2270 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2271 NULL, 0);
2272 info->lpszSubjectInfo = LocalAlloc(0,
2273 strLen * sizeof(WCHAR));
2274 if (info->lpszSubjectInfo)
2275 CertNameToStrW(context->dwCertEncodingType,
2276 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2277 info->lpszSubjectInfo, strLen);
2278 strLen = CertNameToStrW(context->dwCertEncodingType,
2279 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2280 NULL, 0);
2281 info->lpszIssuerInfo = LocalAlloc(0,
2282 strLen * sizeof(WCHAR));
2283 if (info->lpszIssuerInfo)
2284 CertNameToStrW(context->dwCertEncodingType,
2285 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2286 info->lpszIssuerInfo, strLen);
2288 else
2290 LPINTERNET_CERTIFICATE_INFOA infoA =
2291 (LPINTERNET_CERTIFICATE_INFOA)info;
2293 strLen = CertNameToStrA(context->dwCertEncodingType,
2294 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2295 NULL, 0);
2296 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2297 if (infoA->lpszSubjectInfo)
2298 CertNameToStrA(context->dwCertEncodingType,
2299 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2300 infoA->lpszSubjectInfo, strLen);
2301 strLen = CertNameToStrA(context->dwCertEncodingType,
2302 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2303 NULL, 0);
2304 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2305 if (infoA->lpszIssuerInfo)
2306 CertNameToStrA(context->dwCertEncodingType,
2307 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2308 infoA->lpszIssuerInfo, strLen);
2311 * Contrary to MSDN, these do not appear to be set.
2312 * lpszProtocolName
2313 * lpszSignatureAlgName
2314 * lpszEncryptionAlgName
2315 * dwKeySize
2317 CertFreeCertificateContext(context);
2318 bSuccess = TRUE;
2321 break;
2322 default:
2323 FIXME("Stub! %ld\n", dwOption);
2324 break;
2326 if (lpwhh)
2327 WININET_Release( lpwhh );
2329 return bSuccess;
2332 /***********************************************************************
2333 * InternetQueryOptionW (WININET.@)
2335 * Queries an options on the specified handle
2337 * RETURNS
2338 * TRUE on success
2339 * FALSE on failure
2342 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2343 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2345 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2348 /***********************************************************************
2349 * InternetQueryOptionA (WININET.@)
2351 * Queries an options on the specified handle
2353 * RETURNS
2354 * TRUE on success
2355 * FALSE on failure
2358 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2359 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2361 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2365 /***********************************************************************
2366 * InternetSetOptionW (WININET.@)
2368 * Sets an options on the specified handle
2370 * RETURNS
2371 * TRUE on success
2372 * FALSE on failure
2375 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2376 LPVOID lpBuffer, DWORD dwBufferLength)
2378 LPWININETHANDLEHEADER lpwhh;
2379 BOOL ret = TRUE;
2381 TRACE("0x%08lx\n", dwOption);
2383 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2384 if( !lpwhh )
2385 return FALSE;
2387 switch (dwOption)
2389 case INTERNET_OPTION_HTTP_VERSION:
2391 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2392 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2394 break;
2395 case INTERNET_OPTION_ERROR_MASK:
2397 unsigned long flags=*(unsigned long*)lpBuffer;
2398 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2400 break;
2401 case INTERNET_OPTION_CODEPAGE:
2403 unsigned long codepage=*(unsigned long*)lpBuffer;
2404 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2406 break;
2407 case INTERNET_OPTION_REQUEST_PRIORITY:
2409 unsigned long priority=*(unsigned long*)lpBuffer;
2410 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2412 break;
2413 case INTERNET_OPTION_CONNECT_TIMEOUT:
2415 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2416 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2418 break;
2419 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2421 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2422 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2424 break;
2425 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2427 unsigned long conns=*(unsigned long*)lpBuffer;
2428 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2430 break;
2431 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2433 unsigned long conns=*(unsigned long*)lpBuffer;
2434 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2436 break;
2437 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2438 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2439 break;
2440 case INTERNET_OPTION_END_BROWSER_SESSION:
2441 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2442 break;
2443 case INTERNET_OPTION_CONNECTED_STATE:
2444 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2445 break;
2446 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2447 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2448 break;
2449 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2450 FIXME("Option INTERNET_OPTION_RECEIVE_TIMEOUT: STUB\n");
2451 break;
2452 case INTERNET_OPTION_SEND_TIMEOUT:
2453 FIXME("Option INTERNET_OPTION_SEND_TIMEOUT: STUB\n");
2454 break;
2455 case INTERNET_OPTION_CONNECT_RETRIES:
2456 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2457 break;
2458 default:
2459 FIXME("Option %ld STUB\n",dwOption);
2460 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2461 ret = FALSE;
2462 break;
2464 WININET_Release( lpwhh );
2466 return ret;
2470 /***********************************************************************
2471 * InternetSetOptionA (WININET.@)
2473 * Sets an options on the specified handle.
2475 * RETURNS
2476 * TRUE on success
2477 * FALSE on failure
2480 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2481 LPVOID lpBuffer, DWORD dwBufferLength)
2483 LPVOID wbuffer;
2484 DWORD wlen;
2485 BOOL r;
2487 switch( dwOption )
2489 case INTERNET_OPTION_PROXY:
2491 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2492 LPINTERNET_PROXY_INFOW piw;
2493 DWORD proxlen, prbylen;
2494 LPWSTR prox, prby;
2496 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2497 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2498 wlen = sizeof(*piw) + proxlen + prbylen;
2499 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2500 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2501 piw->dwAccessType = pi->dwAccessType;
2502 prox = (LPWSTR) &piw[1];
2503 prby = &prox[proxlen+1];
2504 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2505 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2506 piw->lpszProxy = prox;
2507 piw->lpszProxyBypass = prby;
2509 break;
2510 case INTERNET_OPTION_USER_AGENT:
2511 case INTERNET_OPTION_USERNAME:
2512 case INTERNET_OPTION_PASSWORD:
2513 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2514 NULL, 0 );
2515 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2516 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2517 wbuffer, wlen );
2518 break;
2519 default:
2520 wbuffer = lpBuffer;
2521 wlen = dwBufferLength;
2524 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2526 if( lpBuffer != wbuffer )
2527 HeapFree( GetProcessHeap(), 0, wbuffer );
2529 return r;
2533 /***********************************************************************
2534 * InternetSetOptionExA (WININET.@)
2536 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2537 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2539 FIXME("Flags %08lx ignored\n", dwFlags);
2540 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2543 /***********************************************************************
2544 * InternetSetOptionExW (WININET.@)
2546 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2547 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2549 FIXME("Flags %08lx ignored\n", dwFlags);
2550 if( dwFlags & ~ISO_VALID_FLAGS )
2552 SetLastError( ERROR_INVALID_PARAMETER );
2553 return FALSE;
2555 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2558 static const WCHAR WININET_wkday[7][4] =
2559 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2560 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2561 static const WCHAR WININET_month[12][4] =
2562 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2563 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2564 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2566 /***********************************************************************
2567 * InternetTimeFromSystemTimeA (WININET.@)
2569 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2571 BOOL ret;
2572 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2574 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2576 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2577 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2579 return ret;
2582 /***********************************************************************
2583 * InternetTimeFromSystemTimeW (WININET.@)
2585 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2587 static const WCHAR date[] =
2588 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2589 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2591 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2593 if (!time || !string) return FALSE;
2595 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2596 return FALSE;
2598 sprintfW( string, date,
2599 WININET_wkday[time->wDayOfWeek],
2600 time->wDay,
2601 WININET_month[time->wMonth - 1],
2602 time->wYear,
2603 time->wHour,
2604 time->wMinute,
2605 time->wSecond );
2607 return TRUE;
2610 /***********************************************************************
2611 * InternetTimeToSystemTimeA (WININET.@)
2613 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2615 BOOL ret = FALSE;
2616 WCHAR *stringW;
2617 int len;
2619 TRACE( "%s %p 0x%08lx\n", debugstr_a(string), time, reserved );
2621 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2622 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2624 if (stringW)
2626 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2627 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2628 HeapFree( GetProcessHeap(), 0, stringW );
2630 return ret;
2633 /***********************************************************************
2634 * InternetTimeToSystemTimeW (WININET.@)
2636 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2638 unsigned int i;
2639 WCHAR *s = (LPWSTR)string;
2641 TRACE( "%s %p 0x%08lx\n", debugstr_w(string), time, reserved );
2643 if (!string || !time) return FALSE;
2645 /* Windows does this too */
2646 GetSystemTime( time );
2648 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2649 * a SYSTEMTIME structure.
2652 while (*s && !isalphaW( *s )) s++;
2653 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2654 time->wDayOfWeek = 7;
2656 for (i = 0; i < 7; i++)
2658 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2659 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2660 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2662 time->wDayOfWeek = i;
2663 break;
2667 if (time->wDayOfWeek > 6) return TRUE;
2668 while (*s && !isdigitW( *s )) s++;
2669 time->wDay = strtolW( s, &s, 10 );
2671 while (*s && !isalphaW( *s )) s++;
2672 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2673 time->wMonth = 0;
2675 for (i = 0; i < 12; i++)
2677 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2678 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2679 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2681 time->wMonth = i + 1;
2682 break;
2685 if (time->wMonth == 0) return TRUE;
2687 while (*s && !isdigitW( *s )) s++;
2688 if (*s == '\0') return TRUE;
2689 time->wYear = strtolW( s, &s, 10 );
2691 while (*s && !isdigitW( *s )) s++;
2692 if (*s == '\0') return TRUE;
2693 time->wHour = strtolW( s, &s, 10 );
2695 while (*s && !isdigitW( *s )) s++;
2696 if (*s == '\0') return TRUE;
2697 time->wMinute = strtolW( s, &s, 10 );
2699 while (*s && !isdigitW( *s )) s++;
2700 if (*s == '\0') return TRUE;
2701 time->wSecond = strtolW( s, &s, 10 );
2703 time->wMilliseconds = 0;
2704 return TRUE;
2707 /***********************************************************************
2708 * InternetCheckConnectionW (WININET.@)
2710 * Pings a requested host to check internet connection
2712 * RETURNS
2713 * TRUE on success and FALSE on failure. If a failure then
2714 * ERROR_NOT_CONNECTED is placed into GetLastError
2717 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2720 * this is a kludge which runs the resident ping program and reads the output.
2722 * Anyone have a better idea?
2725 BOOL rc = FALSE;
2726 static const CHAR ping[] = "ping -w 1 ";
2727 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2728 CHAR *command = NULL;
2729 WCHAR hostW[1024];
2730 DWORD len;
2731 int status = -1;
2733 FIXME("\n");
2736 * Crack or set the Address
2738 if (lpszUrl == NULL)
2741 * According to the doc we are supost to use the ip for the next
2742 * server in the WnInet internal server database. I have
2743 * no idea what that is or how to get it.
2745 * So someone needs to implement this.
2747 FIXME("Unimplemented with URL of NULL\n");
2748 return TRUE;
2750 else
2752 URL_COMPONENTSW components;
2754 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2755 components.lpszHostName = (LPWSTR)&hostW;
2756 components.dwHostNameLength = 1024;
2758 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2759 goto End;
2761 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2765 * Build our ping command
2767 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2768 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2769 strcpy(command,ping);
2770 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2771 strcat(command,redirect);
2773 TRACE("Ping command is : %s\n",command);
2775 status = system(command);
2777 TRACE("Ping returned a code of %i\n",status);
2779 /* Ping return code of 0 indicates success */
2780 if (status == 0)
2781 rc = TRUE;
2783 End:
2785 HeapFree( GetProcessHeap(), 0, command );
2786 if (rc == FALSE)
2787 SetLastError(ERROR_NOT_CONNECTED);
2789 return rc;
2793 /***********************************************************************
2794 * InternetCheckConnectionA (WININET.@)
2796 * Pings a requested host to check internet connection
2798 * RETURNS
2799 * TRUE on success and FALSE on failure. If a failure then
2800 * ERROR_NOT_CONNECTED is placed into GetLastError
2803 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2805 WCHAR *szUrl;
2806 INT len;
2807 BOOL rc;
2809 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2810 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2811 return FALSE;
2812 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2813 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2814 HeapFree(GetProcessHeap(), 0, szUrl);
2816 return rc;
2820 /**********************************************************
2821 * INTERNET_InternetOpenUrlW (internal)
2823 * Opens an URL
2825 * RETURNS
2826 * handle of connection or NULL on failure
2828 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2829 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2831 URL_COMPONENTSW urlComponents;
2832 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2833 WCHAR password[1024], path[2048], extra[1024];
2834 HINTERNET client = NULL, client1 = NULL;
2836 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2837 dwHeadersLength, dwFlags, dwContext);
2839 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2840 urlComponents.lpszScheme = protocol;
2841 urlComponents.dwSchemeLength = 32;
2842 urlComponents.lpszHostName = hostName;
2843 urlComponents.dwHostNameLength = MAXHOSTNAME;
2844 urlComponents.lpszUserName = userName;
2845 urlComponents.dwUserNameLength = 1024;
2846 urlComponents.lpszPassword = password;
2847 urlComponents.dwPasswordLength = 1024;
2848 urlComponents.lpszUrlPath = path;
2849 urlComponents.dwUrlPathLength = 2048;
2850 urlComponents.lpszExtraInfo = extra;
2851 urlComponents.dwExtraInfoLength = 1024;
2852 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2853 return NULL;
2854 switch(urlComponents.nScheme) {
2855 case INTERNET_SCHEME_FTP:
2856 if(urlComponents.nPort == 0)
2857 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2858 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2859 userName, password, dwFlags, dwContext, INET_OPENURL);
2860 if(client == NULL)
2861 break;
2862 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2863 if(client1 == NULL) {
2864 InternetCloseHandle(client);
2865 break;
2867 break;
2869 case INTERNET_SCHEME_HTTP:
2870 case INTERNET_SCHEME_HTTPS: {
2871 static const WCHAR szStars[] = { '*','/','*', 0 };
2872 LPCWSTR accept[2] = { szStars, NULL };
2873 if(urlComponents.nPort == 0) {
2874 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2875 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2876 else
2877 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2879 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2880 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2881 userName, password, dwFlags, dwContext, INET_OPENURL);
2882 if(client == NULL)
2883 break;
2884 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2885 if(client1 == NULL) {
2886 InternetCloseHandle(client);
2887 break;
2889 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2890 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0)) {
2891 InternetCloseHandle(client1);
2892 client1 = NULL;
2893 break;
2896 case INTERNET_SCHEME_GOPHER:
2897 /* gopher doesn't seem to be implemented in wine, but it's supposed
2898 * to be supported by InternetOpenUrlA. */
2899 default:
2900 break;
2903 TRACE(" %p <--\n", client1);
2905 return client1;
2908 /**********************************************************
2909 * InternetOpenUrlW (WININET.@)
2911 * Opens an URL
2913 * RETURNS
2914 * handle of connection or NULL on failure
2916 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2917 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2919 HINTERNET ret = NULL;
2920 LPWININETAPPINFOW hIC = NULL;
2922 if (TRACE_ON(wininet)) {
2923 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2924 dwHeadersLength, dwFlags, dwContext);
2925 TRACE(" flags :");
2926 dump_INTERNET_FLAGS(dwFlags);
2929 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2930 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2931 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2932 goto lend;
2935 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2936 WORKREQUEST workRequest;
2937 struct WORKREQ_INTERNETOPENURLW *req;
2939 workRequest.asyncall = INTERNETOPENURLW;
2940 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2941 req = &workRequest.u.InternetOpenUrlW;
2942 if (lpszUrl)
2943 req->lpszUrl = WININET_strdupW(lpszUrl);
2944 else
2945 req->lpszUrl = 0;
2946 if (lpszHeaders)
2947 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2948 else
2949 req->lpszHeaders = 0;
2950 req->dwHeadersLength = dwHeadersLength;
2951 req->dwFlags = dwFlags;
2952 req->dwContext = dwContext;
2954 INTERNET_AsyncCall(&workRequest);
2956 * This is from windows.
2958 SetLastError(ERROR_IO_PENDING);
2959 } else {
2960 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2963 lend:
2964 if( hIC )
2965 WININET_Release( &hIC->hdr );
2966 TRACE(" %p <--\n", ret);
2968 return ret;
2971 /**********************************************************
2972 * InternetOpenUrlA (WININET.@)
2974 * Opens an URL
2976 * RETURNS
2977 * handle of connection or NULL on failure
2979 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2980 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2982 HINTERNET rc = (HINTERNET)NULL;
2984 INT lenUrl;
2985 INT lenHeaders = 0;
2986 LPWSTR szUrl = NULL;
2987 LPWSTR szHeaders = NULL;
2989 TRACE("\n");
2991 if(lpszUrl) {
2992 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
2993 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
2994 if(!szUrl)
2995 return (HINTERNET)NULL;
2996 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
2999 if(lpszHeaders) {
3000 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3001 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3002 if(!szHeaders) {
3003 HeapFree(GetProcessHeap(), 0, szUrl);
3004 return (HINTERNET)NULL;
3006 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3009 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3010 lenHeaders, dwFlags, dwContext);
3012 HeapFree(GetProcessHeap(), 0, szUrl);
3013 HeapFree(GetProcessHeap(), 0, szHeaders);
3015 return rc;
3019 /***********************************************************************
3020 * INTERNET_SetLastError (internal)
3022 * Set last thread specific error
3024 * RETURNS
3027 void INTERNET_SetLastError(DWORD dwError)
3029 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3031 SetLastError(dwError);
3032 if(lpwite)
3033 lpwite->dwError = dwError;
3037 /***********************************************************************
3038 * INTERNET_GetLastError (internal)
3040 * Get last thread specific error
3042 * RETURNS
3045 DWORD INTERNET_GetLastError(void)
3047 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3048 /* TlsGetValue clears last error, so set it again here */
3049 SetLastError(lpwite->dwError);
3050 return lpwite->dwError;
3054 /***********************************************************************
3055 * INTERNET_WorkerThreadFunc (internal)
3057 * Worker thread execution function
3059 * RETURNS
3062 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3064 DWORD dwWaitRes;
3066 while (1)
3068 if(dwNumJobs > 0) {
3069 INTERNET_ExecuteWork();
3070 continue;
3072 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
3074 if (dwWaitRes == WAIT_OBJECT_0 + 1)
3075 INTERNET_ExecuteWork();
3076 else
3077 break;
3079 InterlockedIncrement(&dwNumIdleThreads);
3082 InterlockedDecrement(&dwNumIdleThreads);
3083 InterlockedDecrement(&dwNumThreads);
3084 TRACE("Worker thread exiting\n");
3085 return TRUE;
3089 /***********************************************************************
3090 * INTERNET_InsertWorkRequest (internal)
3092 * Insert work request into queue
3094 * RETURNS
3097 static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
3099 BOOL bSuccess = FALSE;
3100 LPWORKREQUEST lpNewRequest;
3102 TRACE("\n");
3104 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3105 if (lpNewRequest)
3107 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3108 lpNewRequest->prev = NULL;
3110 EnterCriticalSection(&csQueue);
3112 lpNewRequest->next = lpWorkQueueTail;
3113 if (lpWorkQueueTail)
3114 lpWorkQueueTail->prev = lpNewRequest;
3115 lpWorkQueueTail = lpNewRequest;
3116 if (!lpHeadWorkQueue)
3117 lpHeadWorkQueue = lpWorkQueueTail;
3119 LeaveCriticalSection(&csQueue);
3121 bSuccess = TRUE;
3122 InterlockedIncrement(&dwNumJobs);
3125 return bSuccess;
3129 /***********************************************************************
3130 * INTERNET_GetWorkRequest (internal)
3132 * Retrieves work request from queue
3134 * RETURNS
3137 static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
3139 BOOL bSuccess = FALSE;
3140 LPWORKREQUEST lpRequest = NULL;
3142 TRACE("\n");
3144 EnterCriticalSection(&csQueue);
3146 if (lpHeadWorkQueue)
3148 lpRequest = lpHeadWorkQueue;
3149 lpHeadWorkQueue = lpHeadWorkQueue->prev;
3150 if (lpRequest == lpWorkQueueTail)
3151 lpWorkQueueTail = lpHeadWorkQueue;
3154 LeaveCriticalSection(&csQueue);
3156 if (lpRequest)
3158 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
3159 HeapFree(GetProcessHeap(), 0, lpRequest);
3160 bSuccess = TRUE;
3161 InterlockedDecrement(&dwNumJobs);
3164 return bSuccess;
3168 /***********************************************************************
3169 * INTERNET_AsyncCall (internal)
3171 * Retrieves work request from queue
3173 * RETURNS
3176 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3178 HANDLE hThread;
3179 DWORD dwTID;
3180 BOOL bSuccess = FALSE;
3182 TRACE("\n");
3184 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
3186 InterlockedIncrement(&dwNumIdleThreads);
3188 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
3189 !(hThread = CreateThread(NULL, 0,
3190 INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
3192 InterlockedDecrement(&dwNumThreads);
3193 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3194 goto lerror;
3197 TRACE("Created new thread\n");
3200 bSuccess = TRUE;
3201 INTERNET_InsertWorkRequest(lpWorkRequest);
3202 SetEvent(hWorkEvent);
3204 lerror:
3206 return bSuccess;
3210 /***********************************************************************
3211 * INTERNET_ExecuteWork (internal)
3213 * RETURNS
3216 static VOID INTERNET_ExecuteWork(void)
3218 WORKREQUEST workRequest;
3220 TRACE("\n");
3222 if (!INTERNET_GetWorkRequest(&workRequest))
3223 return;
3225 switch (workRequest.asyncall)
3227 case FTPPUTFILEW:
3229 struct WORKREQ_FTPPUTFILEW *req = &workRequest.u.FtpPutFileW;
3230 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3232 TRACE("FTPPUTFILEW %p\n", lpwfs);
3234 FTP_FtpPutFileW(lpwfs, req->lpszLocalFile,
3235 req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
3237 HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
3238 HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
3240 break;
3242 case FTPSETCURRENTDIRECTORYW:
3244 struct WORKREQ_FTPSETCURRENTDIRECTORYW *req;
3245 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3247 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs);
3249 req = &workRequest.u.FtpSetCurrentDirectoryW;
3250 FTP_FtpSetCurrentDirectoryW(lpwfs, req->lpszDirectory);
3251 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3253 break;
3255 case FTPCREATEDIRECTORYW:
3257 struct WORKREQ_FTPCREATEDIRECTORYW *req;
3258 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3260 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs);
3262 req = &workRequest.u.FtpCreateDirectoryW;
3263 FTP_FtpCreateDirectoryW(lpwfs, req->lpszDirectory);
3264 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3266 break;
3268 case FTPFINDFIRSTFILEW:
3270 struct WORKREQ_FTPFINDFIRSTFILEW *req;
3271 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3273 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs);
3275 req = &workRequest.u.FtpFindFirstFileW;
3276 FTP_FtpFindFirstFileW(lpwfs, req->lpszSearchFile,
3277 req->lpFindFileData, req->dwFlags, req->dwContext);
3278 HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
3280 break;
3282 case FTPGETCURRENTDIRECTORYW:
3284 struct WORKREQ_FTPGETCURRENTDIRECTORYW *req;
3285 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3287 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs);
3289 req = &workRequest.u.FtpGetCurrentDirectoryW;
3290 FTP_FtpGetCurrentDirectoryW(lpwfs,
3291 req->lpszDirectory, req->lpdwDirectory);
3293 break;
3295 case FTPOPENFILEW:
3297 struct WORKREQ_FTPOPENFILEW *req = &workRequest.u.FtpOpenFileW;
3298 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3300 TRACE("FTPOPENFILEW %p\n", lpwfs);
3302 FTP_FtpOpenFileW(lpwfs, req->lpszFilename,
3303 req->dwAccess, req->dwFlags, req->dwContext);
3304 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3306 break;
3308 case FTPGETFILEW:
3310 struct WORKREQ_FTPGETFILEW *req = &workRequest.u.FtpGetFileW;
3311 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3313 TRACE("FTPGETFILEW %p\n", lpwfs);
3315 FTP_FtpGetFileW(lpwfs, req->lpszRemoteFile,
3316 req->lpszNewFile, req->fFailIfExists,
3317 req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
3318 HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
3319 HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
3321 break;
3323 case FTPDELETEFILEW:
3325 struct WORKREQ_FTPDELETEFILEW *req = &workRequest.u.FtpDeleteFileW;
3326 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3328 TRACE("FTPDELETEFILEW %p\n", lpwfs);
3330 FTP_FtpDeleteFileW(lpwfs, req->lpszFilename);
3331 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3333 break;
3335 case FTPREMOVEDIRECTORYW:
3337 struct WORKREQ_FTPREMOVEDIRECTORYW *req;
3338 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3340 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs);
3342 req = &workRequest.u.FtpRemoveDirectoryW;
3343 FTP_FtpRemoveDirectoryW(lpwfs, req->lpszDirectory);
3344 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3346 break;
3348 case FTPRENAMEFILEW:
3350 struct WORKREQ_FTPRENAMEFILEW *req = &workRequest.u.FtpRenameFileW;
3351 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3353 TRACE("FTPRENAMEFILEW %p\n", lpwfs);
3355 FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
3356 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
3357 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
3359 break;
3361 case INTERNETFINDNEXTW:
3363 struct WORKREQ_INTERNETFINDNEXTW *req;
3364 LPWININETFINDNEXTW lpwh = (LPWININETFINDNEXTW) workRequest.hdr;
3366 TRACE("INTERNETFINDNEXTW %p\n", lpwh);
3368 req = &workRequest.u.InternetFindNextW;
3369 INTERNET_FindNextFileW(lpwh, req->lpFindFileData);
3371 break;
3373 case HTTPSENDREQUESTW:
3375 struct WORKREQ_HTTPSENDREQUESTW *req = &workRequest.u.HttpSendRequestW;
3376 LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) workRequest.hdr;
3378 TRACE("HTTPSENDREQUESTW %p\n", lpwhr);
3380 HTTP_HttpSendRequestW(lpwhr, req->lpszHeader,
3381 req->dwHeaderLength, req->lpOptional, req->dwOptionalLength,
3382 req->dwContentLength, req->bEndRequest);
3384 HeapFree(GetProcessHeap(), 0, req->lpszHeader);
3386 break;
3388 case HTTPOPENREQUESTW:
3390 struct WORKREQ_HTTPOPENREQUESTW *req = &workRequest.u.HttpOpenRequestW;
3391 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) workRequest.hdr;
3393 TRACE("HTTPOPENREQUESTW %p\n", lpwhs);
3395 HTTP_HttpOpenRequestW(lpwhs, req->lpszVerb,
3396 req->lpszObjectName, req->lpszVersion, req->lpszReferrer,
3397 req->lpszAcceptTypes, req->dwFlags, req->dwContext);
3399 HeapFree(GetProcessHeap(), 0, req->lpszVerb);
3400 HeapFree(GetProcessHeap(), 0, req->lpszObjectName);
3401 HeapFree(GetProcessHeap(), 0, req->lpszVersion);
3402 HeapFree(GetProcessHeap(), 0, req->lpszReferrer);
3404 break;
3406 case SENDCALLBACK:
3408 struct WORKREQ_SENDCALLBACK *req = &workRequest.u.SendCallback;
3410 TRACE("SENDCALLBACK %p\n", workRequest.hdr);
3412 INTERNET_SendCallback(workRequest.hdr,
3413 req->dwContext, req->dwInternetStatus, req->lpvStatusInfo,
3414 req->dwStatusInfoLength);
3416 /* And frees the copy of the status info */
3417 HeapFree(GetProcessHeap(), 0, req->lpvStatusInfo);
3419 break;
3421 case INTERNETOPENURLW:
3423 struct WORKREQ_INTERNETOPENURLW *req = &workRequest.u.InternetOpenUrlW;
3424 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest.hdr;
3426 TRACE("INTERNETOPENURLW %p\n", hIC);
3428 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3429 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3430 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3431 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3433 break;
3434 case INTERNETREADFILEEXA:
3436 struct WORKREQ_INTERNETREADFILEEXA *req = &workRequest.u.InternetReadFileExA;
3438 TRACE("INTERNETREADFILEEXA %p\n", workRequest.hdr);
3440 INTERNET_ReadFile(workRequest.hdr, req->lpBuffersOut->lpvBuffer,
3441 req->lpBuffersOut->dwBufferLength,
3442 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
3444 break;
3446 WININET_Release( workRequest.hdr );
3450 /***********************************************************************
3451 * INTERNET_GetResponseBuffer (internal)
3453 * RETURNS
3456 LPSTR INTERNET_GetResponseBuffer(void)
3458 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3459 TRACE("\n");
3460 return lpwite->response;
3463 /***********************************************************************
3464 * INTERNET_GetNextLine (internal)
3466 * Parse next line in directory string listing
3468 * RETURNS
3469 * Pointer to beginning of next line
3470 * NULL on failure
3474 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3476 struct timeval tv;
3477 fd_set infd;
3478 BOOL bSuccess = FALSE;
3479 INT nRecv = 0;
3480 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3482 TRACE("\n");
3484 FD_ZERO(&infd);
3485 FD_SET(nSocket, &infd);
3486 tv.tv_sec=RESPONSE_TIMEOUT;
3487 tv.tv_usec=0;
3489 while (nRecv < MAX_REPLY_LEN)
3491 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3493 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3495 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3496 goto lend;
3499 if (lpszBuffer[nRecv] == '\n')
3501 bSuccess = TRUE;
3502 break;
3504 if (lpszBuffer[nRecv] != '\r')
3505 nRecv++;
3507 else
3509 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3510 goto lend;
3514 lend:
3515 if (bSuccess)
3517 lpszBuffer[nRecv] = '\0';
3518 *dwLen = nRecv - 1;
3519 TRACE(":%d %s\n", nRecv, lpszBuffer);
3520 return lpszBuffer;
3522 else
3524 return NULL;
3528 /**********************************************************
3529 * InternetQueryDataAvailable (WININET.@)
3531 * Determines how much data is available to be read.
3533 * RETURNS
3534 * If there is data available then TRUE, otherwise if there
3535 * is not or an error occurred then FALSE. Use GetLastError() to
3536 * check for ERROR_NO_MORE_FILES to see if it was the former.
3538 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3539 LPDWORD lpdwNumberOfBytesAvailble,
3540 DWORD dwFlags, DWORD dwConext)
3542 LPWININETHTTPREQW lpwhr;
3543 BOOL retval = FALSE;
3544 char buffer[4048];
3546 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3547 if (NULL == lpwhr)
3549 SetLastError(ERROR_NO_MORE_FILES);
3550 return FALSE;
3553 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3555 switch (lpwhr->hdr.htype)
3557 case WH_HHTTPREQ:
3558 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3559 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3561 SetLastError(ERROR_NO_MORE_FILES);
3562 retval = FALSE;
3564 else
3565 retval = TRUE;
3566 break;
3568 default:
3569 FIXME("unsupported file type\n");
3570 break;
3572 WININET_Release( &lpwhr->hdr );
3574 TRACE("<-- %i\n",retval);
3575 return retval;
3579 /***********************************************************************
3580 * InternetLockRequestFile (WININET.@)
3582 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3583 *lphLockReqHandle)
3585 FIXME("STUB\n");
3586 return FALSE;
3589 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3591 FIXME("STUB\n");
3592 return FALSE;
3596 /***********************************************************************
3597 * InternetAutodial (WININET.@)
3599 * On windows this function is supposed to dial the default internet
3600 * connection. We don't want to have Wine dial out to the internet so
3601 * we return TRUE by default. It might be nice to check if we are connected.
3603 * RETURNS
3604 * TRUE on success
3605 * FALSE on failure
3608 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3610 FIXME("STUB\n");
3612 /* Tell that we are connected to the internet. */
3613 return TRUE;
3616 /***********************************************************************
3617 * InternetAutodialHangup (WININET.@)
3619 * Hangs up a connection made with InternetAutodial
3621 * PARAM
3622 * dwReserved
3623 * RETURNS
3624 * TRUE on success
3625 * FALSE on failure
3628 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3630 FIXME("STUB\n");
3632 /* we didn't dial, we don't disconnect */
3633 return TRUE;
3636 /***********************************************************************
3637 * InternetCombineUrlA (WININET.@)
3639 * Combine a base URL with a relative URL
3641 * RETURNS
3642 * TRUE on success
3643 * FALSE on failure
3647 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3648 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3649 DWORD dwFlags)
3651 HRESULT hr=S_OK;
3653 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3655 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3656 dwFlags ^= ICU_NO_ENCODE;
3657 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3659 return (hr==S_OK);
3662 /***********************************************************************
3663 * InternetCombineUrlW (WININET.@)
3665 * Combine a base URL with a relative URL
3667 * RETURNS
3668 * TRUE on success
3669 * FALSE on failure
3673 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3674 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3675 DWORD dwFlags)
3677 HRESULT hr=S_OK;
3679 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3681 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3682 dwFlags ^= ICU_NO_ENCODE;
3683 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3685 return (hr==S_OK);
3688 /* max port num is 65535 => 5 digits */
3689 #define MAX_WORD_DIGITS 5
3691 /* we can calculate using ansi strings because we're just
3692 * calculating string length, not size
3694 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3695 LPDWORD lpdwUrlLength, LPDWORD lpdwSchemeLength)
3697 static const WCHAR httpW[] = {'h','t','t','p',0};
3699 *lpdwUrlLength = 0;
3701 switch (lpUrlComponents->nScheme)
3703 case INTERNET_SCHEME_FTP:
3704 case INTERNET_SCHEME_RES:
3705 *lpdwSchemeLength = 3;
3706 break;
3707 case INTERNET_SCHEME_HTTP:
3708 case INTERNET_SCHEME_FILE:
3709 case INTERNET_SCHEME_NEWS:
3710 *lpdwSchemeLength = 4;
3711 break;
3713 default:
3714 *lpdwSchemeLength = 4;
3715 break;
3718 *lpdwUrlLength += *lpdwSchemeLength;
3719 *lpdwUrlLength += strlen("://");
3721 if (lpUrlComponents->lpszUserName)
3723 *lpdwUrlLength += lpUrlComponents->dwUserNameLength;
3724 *lpdwUrlLength += strlen("@");
3726 else
3728 if (lpUrlComponents->lpszPassword)
3730 SetLastError(ERROR_INVALID_PARAMETER);
3731 return FALSE;
3735 if (lpUrlComponents->lpszPassword)
3737 *lpdwUrlLength += strlen(":");
3738 *lpdwUrlLength += lpUrlComponents->dwPasswordLength;
3741 *lpdwUrlLength += lpUrlComponents->dwHostNameLength;
3743 if (lpUrlComponents->nPort != 80 ||
3744 (lpUrlComponents->lpszScheme && strncmpW(lpUrlComponents->lpszScheme, httpW, lpUrlComponents->dwSchemeLength)))
3746 char szPort[MAX_WORD_DIGITS];
3748 sprintf(szPort, "%d", lpUrlComponents->nPort);
3749 *lpdwUrlLength += strlen(szPort);
3750 *lpdwUrlLength += strlen(":");
3753 *lpdwUrlLength += lpUrlComponents->dwUrlPathLength;
3754 return TRUE;
3757 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3759 INT len;
3761 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3763 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3764 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3765 urlCompW->nScheme = lpUrlComponents->nScheme;
3766 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3767 urlCompW->nPort = lpUrlComponents->nPort;
3768 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3769 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3770 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3771 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3773 if (lpUrlComponents->lpszScheme)
3775 len = lpUrlComponents->dwSchemeLength + 1;
3776 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3777 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3778 -1, urlCompW->lpszScheme, len);
3781 if (lpUrlComponents->lpszHostName)
3783 len = lpUrlComponents->dwHostNameLength + 1;
3784 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3785 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3786 -1, urlCompW->lpszHostName, len);
3789 if (lpUrlComponents->lpszUserName)
3791 len = lpUrlComponents->dwUserNameLength + 1;
3792 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3793 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3794 -1, urlCompW->lpszUserName, len);
3797 if (lpUrlComponents->lpszPassword)
3799 len = lpUrlComponents->dwPasswordLength + 1;
3800 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3801 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3802 -1, urlCompW->lpszPassword, len);
3805 if (lpUrlComponents->lpszUrlPath)
3807 len = lpUrlComponents->dwUrlPathLength + 1;
3808 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3809 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3810 -1, urlCompW->lpszUrlPath, len);
3813 if (lpUrlComponents->lpszExtraInfo)
3815 len = lpUrlComponents->dwExtraInfoLength + 1;
3816 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3817 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3818 -1, urlCompW->lpszExtraInfo, len);
3822 /***********************************************************************
3823 * InternetCreateUrlA (WININET.@)
3825 * RETURNS
3826 * TRUE on success
3827 * FALSE on failure
3830 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3831 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3833 BOOL ret;
3834 LPWSTR urlW = NULL;
3835 URL_COMPONENTSW urlCompW;
3837 TRACE("(%p,%ld,%s,%p)\n", lpUrlComponents, dwFlags, debugstr_a(lpszUrl), lpdwUrlLength);
3839 if (!lpUrlComponents)
3840 return FALSE;
3842 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3844 SetLastError(ERROR_INVALID_PARAMETER);
3845 return FALSE;
3848 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3850 if (lpszUrl)
3851 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3853 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3855 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3856 * minus one, so add one to leave room for NULL terminator
3858 if (ret)
3859 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3861 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3862 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3863 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3864 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3865 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3866 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3867 HeapFree(GetProcessHeap(), 0, urlW);
3869 return ret;
3872 /***********************************************************************
3873 * InternetCreateUrlW (WININET.@)
3875 * RETURNS
3876 * TRUE on success
3877 * FALSE on failure
3880 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3881 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3883 DWORD dwLen, dwSchemeLen;
3885 static const WCHAR colonSlashW[] = {':','/','/',0};
3886 static const WCHAR httpW[] = {'h','t','t','p',0};
3887 static const WCHAR colonW[] = {':',0};
3888 static const WCHAR atW[] = {'@',0};
3889 static const WCHAR percentD[] = {'%','d',0};
3891 TRACE("(%p,%ld,%s,%p)\n", lpUrlComponents, dwFlags, debugstr_w(lpszUrl), lpdwUrlLength);
3893 if (!lpUrlComponents)
3894 return FALSE;
3896 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3898 SetLastError(ERROR_INVALID_PARAMETER);
3899 return FALSE;
3902 if (!calc_url_length(lpUrlComponents, &dwLen, &dwSchemeLen))
3903 return FALSE;
3905 if (!lpszUrl || *lpdwUrlLength < dwLen)
3907 *lpdwUrlLength = dwLen + 1; /* terminating null */
3908 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3909 return FALSE;
3912 *lpdwUrlLength = dwLen;
3913 lpszUrl[0] = 0x00;
3915 if (lpUrlComponents->lpszScheme)
3916 lstrcpynW(lpszUrl, lpUrlComponents->lpszScheme,
3917 min(lpUrlComponents->dwSchemeLength, dwSchemeLen) + 1);
3919 lstrcatW(lpszUrl, colonSlashW);
3921 if (lpUrlComponents->lpszUserName)
3923 if (!*lpUrlComponents->lpszUserName)
3924 return TRUE;
3926 lstrcatW(lpszUrl, lpUrlComponents->lpszUserName);
3928 if (lpUrlComponents->lpszPassword)
3930 lstrcatW(lpszUrl, colonW);
3932 if (!*lpUrlComponents->lpszPassword)
3933 return TRUE;
3934 else
3935 lstrcatW(lpszUrl, lpUrlComponents->lpszPassword);
3938 lstrcatW(lpszUrl, atW);
3941 lstrcatW(lpszUrl, lpUrlComponents->lpszHostName);
3943 if (lpUrlComponents->nPort != 80 || (lpUrlComponents->lpszScheme &&
3944 strncmpW(lpUrlComponents->lpszScheme, httpW, lpUrlComponents->dwSchemeLength)))
3946 WCHAR szPort[MAX_WORD_DIGITS];
3948 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3949 lstrcatW(lpszUrl, colonW);
3950 lstrcatW(lpszUrl, szPort);
3953 lstrcatW(lpszUrl, lpUrlComponents->lpszUrlPath);
3955 return TRUE;
3958 /***********************************************************************
3959 * InternetConfirmZoneCrossingA (WININET.@)
3962 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3964 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3965 return ERROR_SUCCESS;
3968 /***********************************************************************
3969 * InternetConfirmZoneCrossingW (WININET.@)
3972 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3974 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3975 return ERROR_SUCCESS;
3978 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3979 LPDWORD lpdwConnection, DWORD dwReserved )
3981 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
3982 lpdwConnection, dwReserved);
3983 return ERROR_SUCCESS;
3986 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3987 LPDWORD lpdwConnection, DWORD dwReserved )
3989 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
3990 lpdwConnection, dwReserved);
3991 return ERROR_SUCCESS;
3994 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3996 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3997 return TRUE;
4000 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4002 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4003 return TRUE;
4006 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
4008 FIXME("(0x%08lx, 0x%08lx) stub\n", dwConnection, dwReserved);
4009 return ERROR_SUCCESS;
4012 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4013 PBYTE pbHexHash )
4015 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4016 debugstr_w(pwszTarget), pbHexHash);
4017 return FALSE;
4020 BOOL WINAPI InternetClearAllPerSiteCookieDecisions( VOID )
4022 FIXME("stub\n");
4023 return TRUE;
4026 BOOL WINAPI InternetEnumPerSiteCookieDecisionA( LPSTR pszSiteName, unsigned long *pcSiteNameSize,
4027 unsigned long *pdwDecision, unsigned long dwIndex )
4029 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
4030 debugstr_a(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
4031 return FALSE;
4034 BOOL WINAPI InternetEnumPerSiteCookieDecisionW( LPWSTR pszSiteName, unsigned long *pcSiteNameSize,
4035 unsigned long *pdwDecision, unsigned long dwIndex )
4037 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
4038 debugstr_w(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
4039 return FALSE;
4042 BOOL WINAPI InternetGetCookieExA( LPCSTR pchURL, LPCSTR pchCookieName, LPSTR pchCookieData,
4043 LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
4045 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
4046 debugstr_a(pchURL), debugstr_a(pchCookieName), debugstr_a(pchCookieData),
4047 pcchCookieData, dwFlags, lpReserved);
4048 return FALSE;
4051 BOOL WINAPI InternetGetCookieExW( LPCWSTR pchURL, LPCWSTR pchCookieName, LPWSTR pchCookieData,
4052 LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
4054 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
4055 debugstr_w(pchURL), debugstr_w(pchCookieName), debugstr_w(pchCookieData),
4056 pcchCookieData, dwFlags, lpReserved);
4057 return FALSE;
4060 BOOL WINAPI InternetGetPerSiteCookieDecisionA( LPCSTR pwchHostName, unsigned long *pResult )
4062 FIXME("(%s, %p) stub\n", debugstr_a(pwchHostName), pResult);
4063 return FALSE;
4066 BOOL WINAPI InternetGetPerSiteCookieDecisionW( LPCWSTR pwchHostName, unsigned long *pResult )
4068 FIXME("(%s, %p) stub\n", debugstr_w(pwchHostName), pResult);
4069 return FALSE;
4072 BOOL WINAPI InternetSetPerSiteCookieDecisionA( LPCSTR pchHostName, DWORD dwDecision )
4074 FIXME("(%s, 0x%08lx) stub\n", debugstr_a(pchHostName), dwDecision);
4075 return FALSE;
4078 BOOL WINAPI InternetSetPerSiteCookieDecisionW( LPCWSTR pchHostName, DWORD dwDecision )
4080 FIXME("(%s, 0x%08lx) stub\n", debugstr_w(pchHostName), dwDecision);
4081 return FALSE;
4084 DWORD WINAPI InternetSetCookieExA( LPCSTR lpszURL, LPCSTR lpszCookieName, LPCSTR lpszCookieData,
4085 DWORD dwFlags, DWORD_PTR dwReserved)
4087 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
4088 debugstr_a(lpszURL), debugstr_a(lpszCookieName), debugstr_a(lpszCookieData),
4089 dwFlags, dwReserved);
4090 return TRUE;
4093 DWORD WINAPI InternetSetCookieExW( LPCWSTR lpszURL, LPCWSTR lpszCookieName, LPCWSTR lpszCookieData,
4094 DWORD dwFlags, DWORD_PTR dwReserved)
4096 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
4097 debugstr_w(lpszURL), debugstr_w(lpszCookieName), debugstr_w(lpszCookieData),
4098 dwFlags, dwReserved);
4099 return TRUE;
4102 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4104 FIXME("(%p, 0x%08lx) stub\n", hInternet, dwError);
4105 return FALSE;