include: Use force_align_arg_pointer on MacOS to fix the stack on entry to Wine.
[wine/multimedia.git] / dlls / wininet / internet.c
blob11651e5566b7102ed7cc58b3d5168fff8cfcddfa
1 /*
2 * Wininet
4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
10 * Ulrich Czekalla
11 * Aric Stewart
12 * David Hammerton
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "config.h"
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
34 #include <string.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
40 #endif
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
43 #endif
44 #include <stdlib.h>
45 #include <ctype.h>
46 #ifdef HAVE_UNISTD_H
47 # include <unistd.h>
48 #endif
49 #include <assert.h>
51 #include "windef.h"
52 #include "winbase.h"
53 #include "winreg.h"
54 #include "winuser.h"
55 #include "wininet.h"
56 #include "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:
286 break;
288 case DLL_THREAD_DETACH:
289 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
291 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
292 HeapFree(GetProcessHeap(), 0, lpwite);
294 break;
296 case DLL_PROCESS_DETACH:
298 URLCacheContainers_DeleteAll();
300 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
302 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
303 TlsFree(g_dwTlsErrIndex);
306 SetEvent(hQuitEvent);
308 CloseHandle(hQuitEvent);
309 CloseHandle(hWorkEvent);
310 DeleteCriticalSection(&csQueue);
311 break;
314 return TRUE;
318 /***********************************************************************
319 * InternetInitializeAutoProxyDll (WININET.@)
321 * Setup the internal proxy
323 * PARAMETERS
324 * dwReserved
326 * RETURNS
327 * FALSE on failure
330 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
332 FIXME("STUB\n");
333 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
334 return FALSE;
337 /***********************************************************************
338 * DetectAutoProxyUrl (WININET.@)
340 * Auto detect the proxy url
342 * RETURNS
343 * FALSE on failure
346 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
347 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
349 FIXME("STUB\n");
350 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
351 return FALSE;
355 /***********************************************************************
356 * INTERNET_ConfigureProxyFromReg
358 * FIXME:
359 * The proxy may be specified in the form 'http=proxy.my.org'
360 * Presumably that means there can be ftp=ftpproxy.my.org too.
362 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
364 HKEY key;
365 DWORD r, keytype, len, enabled;
366 LPCSTR lpszInternetSettings =
367 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
368 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
370 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
371 if ( r != ERROR_SUCCESS )
372 return FALSE;
374 len = sizeof enabled;
375 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
376 (BYTE*)&enabled, &len);
377 if( (r == ERROR_SUCCESS) && enabled )
379 TRACE("Proxy is enabled.\n");
381 /* figure out how much memory the proxy setting takes */
382 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
383 NULL, &len);
384 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
386 LPWSTR szProxy, p;
387 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
389 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
390 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
391 (BYTE*)szProxy, &len);
393 /* find the http proxy, and strip away everything else */
394 p = strstrW( szProxy, szHttp );
395 if( p )
397 p += lstrlenW(szHttp);
398 lstrcpyW( szProxy, p );
400 p = strchrW( szProxy, ' ' );
401 if( p )
402 *p = 0;
404 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
405 lpwai->lpszProxy = szProxy;
407 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
409 else
410 ERR("Couldn't read proxy server settings.\n");
412 else
413 TRACE("Proxy is not enabled.\n");
414 RegCloseKey(key);
416 return enabled;
419 /***********************************************************************
420 * dump_INTERNET_FLAGS
422 * Helper function to TRACE the internet flags.
424 * RETURNS
425 * None
428 static void dump_INTERNET_FLAGS(DWORD dwFlags)
430 #define FE(x) { x, #x }
431 static const wininet_flag_info flag[] = {
432 FE(INTERNET_FLAG_RELOAD),
433 FE(INTERNET_FLAG_RAW_DATA),
434 FE(INTERNET_FLAG_EXISTING_CONNECT),
435 FE(INTERNET_FLAG_ASYNC),
436 FE(INTERNET_FLAG_PASSIVE),
437 FE(INTERNET_FLAG_NO_CACHE_WRITE),
438 FE(INTERNET_FLAG_MAKE_PERSISTENT),
439 FE(INTERNET_FLAG_FROM_CACHE),
440 FE(INTERNET_FLAG_SECURE),
441 FE(INTERNET_FLAG_KEEP_CONNECTION),
442 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
443 FE(INTERNET_FLAG_READ_PREFETCH),
444 FE(INTERNET_FLAG_NO_COOKIES),
445 FE(INTERNET_FLAG_NO_AUTH),
446 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
447 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
448 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
449 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
450 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
451 FE(INTERNET_FLAG_RESYNCHRONIZE),
452 FE(INTERNET_FLAG_HYPERLINK),
453 FE(INTERNET_FLAG_NO_UI),
454 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
455 FE(INTERNET_FLAG_CACHE_ASYNC),
456 FE(INTERNET_FLAG_FORMS_SUBMIT),
457 FE(INTERNET_FLAG_NEED_FILE),
458 FE(INTERNET_FLAG_TRANSFER_ASCII),
459 FE(INTERNET_FLAG_TRANSFER_BINARY)
461 #undef FE
462 int i;
464 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
465 if (flag[i].val & dwFlags) {
466 TRACE(" %s", flag[i].name);
467 dwFlags &= ~flag[i].val;
470 if (dwFlags)
471 TRACE(" Unknown flags (%08lx)\n", dwFlags);
472 else
473 TRACE("\n");
476 /***********************************************************************
477 * InternetOpenW (WININET.@)
479 * Per-application initialization of wininet
481 * RETURNS
482 * HINTERNET on success
483 * NULL on failure
486 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
487 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
489 LPWININETAPPINFOW lpwai = NULL;
490 HINTERNET handle = NULL;
492 if (TRACE_ON(wininet)) {
493 #define FE(x) { x, #x }
494 static const wininet_flag_info access_type[] = {
495 FE(INTERNET_OPEN_TYPE_PRECONFIG),
496 FE(INTERNET_OPEN_TYPE_DIRECT),
497 FE(INTERNET_OPEN_TYPE_PROXY),
498 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
500 #undef FE
501 DWORD i;
502 const char *access_type_str = "Unknown";
504 TRACE("(%s, %li, %s, %s, %li)\n", debugstr_w(lpszAgent), dwAccessType,
505 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
506 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
507 if (access_type[i].val == dwAccessType) {
508 access_type_str = access_type[i].name;
509 break;
512 TRACE(" access type : %s\n", access_type_str);
513 TRACE(" flags :");
514 dump_INTERNET_FLAGS(dwFlags);
517 /* Clear any error information */
518 INTERNET_SetLastError(0);
520 lpwai = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW));
521 if (NULL == lpwai)
523 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
524 goto lend;
527 memset(lpwai, 0, sizeof(WININETAPPINFOW));
528 lpwai->hdr.htype = WH_HINIT;
529 lpwai->hdr.lpwhparent = NULL;
530 lpwai->hdr.dwFlags = dwFlags;
531 lpwai->hdr.dwRefCount = 1;
532 lpwai->hdr.destroy = INTERNET_CloseHandle;
533 lpwai->dwAccessType = dwAccessType;
534 lpwai->lpszProxyUsername = NULL;
535 lpwai->lpszProxyPassword = NULL;
537 handle = WININET_AllocHandle( &lpwai->hdr );
538 if( !handle )
540 HeapFree( GetProcessHeap(), 0, lpwai );
541 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
542 goto lend;
545 if (NULL != lpszAgent)
547 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
548 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
549 if (lpwai->lpszAgent)
550 lstrcpyW( lpwai->lpszAgent, lpszAgent );
552 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
553 INTERNET_ConfigureProxyFromReg( lpwai );
554 else if (NULL != lpszProxy)
556 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
557 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
558 if (lpwai->lpszProxy)
559 lstrcpyW( lpwai->lpszProxy, lpszProxy );
562 if (NULL != lpszProxyBypass)
564 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
565 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
566 if (lpwai->lpszProxyBypass)
567 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
570 lend:
571 if( lpwai )
572 WININET_Release( &lpwai->hdr );
574 TRACE("returning %p\n", lpwai);
576 return handle;
580 /***********************************************************************
581 * InternetOpenA (WININET.@)
583 * Per-application initialization of wininet
585 * RETURNS
586 * HINTERNET on success
587 * NULL on failure
590 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
591 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
593 HINTERNET rc = (HINTERNET)NULL;
594 INT len;
595 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
597 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent),
598 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
600 if( lpszAgent )
602 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
603 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
604 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
607 if( lpszProxy )
609 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
610 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
611 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
614 if( lpszProxyBypass )
616 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
617 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
618 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
621 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
623 HeapFree(GetProcessHeap(), 0, szAgent);
624 HeapFree(GetProcessHeap(), 0, szProxy);
625 HeapFree(GetProcessHeap(), 0, szBypass);
627 return rc;
630 /***********************************************************************
631 * InternetGetLastResponseInfoA (WININET.@)
633 * Return last wininet error description on the calling thread
635 * RETURNS
636 * TRUE on success of writing to buffer
637 * FALSE on failure
640 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
641 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
643 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
645 TRACE("\n");
647 if (lpwite)
649 *lpdwError = lpwite->dwError;
650 if (lpwite->dwError)
652 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
653 *lpdwBufferLength = strlen(lpszBuffer);
655 else
656 *lpdwBufferLength = 0;
658 else
660 *lpdwError = 0;
661 *lpdwBufferLength = 0;
664 return TRUE;
667 /***********************************************************************
668 * InternetGetLastResponseInfoW (WININET.@)
670 * Return last wininet error description on the calling thread
672 * RETURNS
673 * TRUE on success of writing to buffer
674 * FALSE on failure
677 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
678 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
680 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
682 TRACE("\n");
684 if (lpwite)
686 *lpdwError = lpwite->dwError;
687 if (lpwite->dwError)
689 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
690 *lpdwBufferLength = lstrlenW(lpszBuffer);
692 else
693 *lpdwBufferLength = 0;
695 else
697 *lpdwError = 0;
698 *lpdwBufferLength = 0;
701 return TRUE;
704 /***********************************************************************
705 * InternetGetConnectedState (WININET.@)
707 * Return connected state
709 * RETURNS
710 * TRUE if connected
711 * if lpdwStatus is not null, return the status (off line,
712 * modem, lan...) in it.
713 * FALSE if not connected
715 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
717 TRACE("(%p, 0x%08lx)\n", lpdwStatus, dwReserved);
719 if (lpdwStatus) {
720 FIXME("always returning LAN connection.\n");
721 *lpdwStatus = INTERNET_CONNECTION_LAN;
723 return TRUE;
727 /***********************************************************************
728 * InternetGetConnectedStateExW (WININET.@)
730 * Return connected state
732 * PARAMS
734 * lpdwStatus [O] Flags specifying the status of the internet connection.
735 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
736 * dwNameLen [I] Size of the buffer, in characters.
737 * dwReserved [I] Reserved. Must be set to 0.
739 * RETURNS
740 * TRUE if connected
741 * if lpdwStatus is not null, return the status (off line,
742 * modem, lan...) in it.
743 * FALSE if not connected
745 * NOTES
746 * If the system has no available network connections, an empty string is
747 * stored in lpszConnectionName. If there is a LAN connection, a localized
748 * "LAN Connection" string is stored. Presumably, if only a dial-up
749 * connection is available then the name of the dial-up connection is
750 * returned. Why any application, other than the "Internet Settings" CPL,
751 * would want to use this function instead of the simpler InternetGetConnectedStateW
752 * function is beyond me.
754 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
755 DWORD dwNameLen, DWORD dwReserved)
757 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
759 /* Must be zero */
760 if(dwReserved)
761 return FALSE;
763 if (lpdwStatus) {
764 FIXME("always returning LAN connection.\n");
765 *lpdwStatus = INTERNET_CONNECTION_LAN;
767 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
771 /***********************************************************************
772 * InternetGetConnectedStateExA (WININET.@)
774 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
775 DWORD dwNameLen, DWORD dwReserved)
777 LPWSTR lpwszConnectionName = NULL;
778 BOOL rc;
780 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
782 if (lpszConnectionName && dwNameLen > 0)
783 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
785 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
786 dwReserved);
787 if (rc && lpwszConnectionName)
789 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
790 dwNameLen, NULL, NULL);
792 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
795 return rc;
799 /***********************************************************************
800 * InternetConnectW (WININET.@)
802 * Open a ftp, gopher or http session
804 * RETURNS
805 * HINTERNET a session handle on success
806 * NULL on failure
809 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
810 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
811 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
812 DWORD dwService, DWORD dwFlags, DWORD dwContext)
814 LPWININETAPPINFOW hIC;
815 HINTERNET rc = NULL;
817 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet, debugstr_w(lpszServerName),
818 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
819 dwService, dwFlags, dwContext);
821 if (!lpszServerName)
823 SetLastError(ERROR_INVALID_PARAMETER);
824 return NULL;
827 /* Clear any error information */
828 INTERNET_SetLastError(0);
829 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
830 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
832 SetLastError(ERROR_INVALID_HANDLE);
833 goto lend;
836 switch (dwService)
838 case INTERNET_SERVICE_FTP:
839 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
840 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
841 break;
843 case INTERNET_SERVICE_HTTP:
844 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
845 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
846 break;
848 case INTERNET_SERVICE_GOPHER:
849 default:
850 break;
852 lend:
853 if( hIC )
854 WININET_Release( &hIC->hdr );
856 TRACE("returning %p\n", rc);
857 return rc;
861 /***********************************************************************
862 * InternetConnectA (WININET.@)
864 * Open a ftp, gopher or http session
866 * RETURNS
867 * HINTERNET a session handle on success
868 * NULL on failure
871 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
872 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
873 LPCSTR lpszUserName, LPCSTR lpszPassword,
874 DWORD dwService, DWORD dwFlags, DWORD dwContext)
876 HINTERNET rc = (HINTERNET)NULL;
877 INT len = 0;
878 LPWSTR szServerName = NULL;
879 LPWSTR szUserName = NULL;
880 LPWSTR szPassword = NULL;
882 if (lpszServerName)
884 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
885 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
886 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
888 if (lpszUserName)
890 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
891 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
892 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
894 if (lpszPassword)
896 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
897 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
898 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
902 rc = InternetConnectW(hInternet, szServerName, nServerPort,
903 szUserName, szPassword, dwService, dwFlags, dwContext);
905 HeapFree(GetProcessHeap(), 0, szServerName);
906 HeapFree(GetProcessHeap(), 0, szUserName);
907 HeapFree(GetProcessHeap(), 0, szPassword);
908 return rc;
912 /***********************************************************************
913 * InternetFindNextFileA (WININET.@)
915 * Continues a file search from a previous call to FindFirstFile
917 * RETURNS
918 * TRUE on success
919 * FALSE on failure
922 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
924 BOOL ret;
925 WIN32_FIND_DATAW fd;
927 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
928 if(lpvFindData)
929 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
930 return ret;
933 /***********************************************************************
934 * InternetFindNextFileW (WININET.@)
936 * Continues a file search from a previous call to FindFirstFile
938 * RETURNS
939 * TRUE on success
940 * FALSE on failure
943 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
945 LPWININETAPPINFOW hIC = NULL;
946 LPWININETFINDNEXTW lpwh;
947 BOOL bSuccess = FALSE;
949 TRACE("\n");
951 lpwh = (LPWININETFINDNEXTW) WININET_GetObject( hFind );
952 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
954 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
955 goto lend;
958 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
959 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
961 WORKREQUEST workRequest;
962 struct WORKREQ_INTERNETFINDNEXTW *req;
964 workRequest.asyncall = INTERNETFINDNEXTW;
965 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
966 req = &workRequest.u.InternetFindNextW;
967 req->lpFindFileData = lpvFindData;
969 bSuccess = INTERNET_AsyncCall(&workRequest);
971 else
973 bSuccess = INTERNET_FindNextFileW(lpwh, lpvFindData);
975 lend:
976 if( lpwh )
977 WININET_Release( &lpwh->hdr );
978 return bSuccess;
981 /***********************************************************************
982 * INTERNET_FindNextFileW (Internal)
984 * Continues a file search from a previous call to FindFirstFile
986 * RETURNS
987 * TRUE on success
988 * FALSE on failure
991 BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData)
993 BOOL bSuccess = TRUE;
994 LPWIN32_FIND_DATAW lpFindFileData;
996 TRACE("\n");
998 assert (lpwh->hdr.htype == WH_HFINDNEXT);
1000 /* Clear any error information */
1001 INTERNET_SetLastError(0);
1003 if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
1005 FIXME("Only FTP find next supported\n");
1006 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1007 return FALSE;
1010 TRACE("index(%ld) size(%ld)\n", lpwh->index, lpwh->size);
1012 lpFindFileData = (LPWIN32_FIND_DATAW) lpvFindData;
1013 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
1015 if (lpwh->index >= lpwh->size)
1017 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
1018 bSuccess = FALSE;
1019 goto lend;
1022 FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
1023 lpwh->index++;
1025 TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData->cFileName), lpFindFileData->nFileSizeLow);
1027 lend:
1029 if (lpwh->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1031 INTERNET_ASYNC_RESULT iar;
1033 iar.dwResult = (DWORD)bSuccess;
1034 iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
1035 INTERNET_GetLastError();
1037 INTERNET_SendCallback(&lpwh->hdr, lpwh->hdr.dwContext,
1038 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1039 sizeof(INTERNET_ASYNC_RESULT));
1042 return bSuccess;
1046 /***********************************************************************
1047 * INTERNET_CloseHandle (internal)
1049 * Close internet handle
1051 * RETURNS
1052 * Void
1055 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
1057 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
1059 TRACE("%p\n",lpwai);
1061 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
1062 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
1063 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
1064 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
1065 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
1066 HeapFree(GetProcessHeap(), 0, lpwai);
1070 /***********************************************************************
1071 * InternetCloseHandle (WININET.@)
1073 * Generic close handle function
1075 * RETURNS
1076 * TRUE on success
1077 * FALSE on failure
1080 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1082 LPWININETHANDLEHEADER lpwh;
1084 TRACE("%p\n",hInternet);
1086 lpwh = WININET_GetObject( hInternet );
1087 if (NULL == lpwh)
1089 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1090 return FALSE;
1093 /* FIXME: native appears to send this from the equivalent of
1094 * WININET_Release */
1095 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1096 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
1097 sizeof(HINTERNET));
1099 if( lpwh->lpwhparent )
1100 WININET_Release( lpwh->lpwhparent );
1101 WININET_FreeHandle( hInternet );
1102 WININET_Release( lpwh );
1104 return TRUE;
1108 /***********************************************************************
1109 * ConvertUrlComponentValue (Internal)
1111 * Helper function for InternetCrackUrlW
1114 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1115 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1116 LPCSTR lpszStart, LPCWSTR lpwszStart)
1118 TRACE("%p %ld %p %ld %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1119 if (*dwComponentLen != 0)
1121 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1122 if (*lppszComponent == NULL)
1124 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1125 if (lpwszComponent)
1126 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1127 else
1128 *lppszComponent = NULL;
1129 *dwComponentLen = nASCIILength;
1131 else
1133 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1134 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1135 (*lppszComponent)[ncpylen]=0;
1136 *dwComponentLen = ncpylen;
1142 /***********************************************************************
1143 * InternetCrackUrlA (WININET.@)
1145 * See InternetCrackUrlW.
1147 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1148 LPURL_COMPONENTSA lpUrlComponents)
1150 DWORD nLength;
1151 URL_COMPONENTSW UCW;
1152 WCHAR* lpwszUrl;
1154 TRACE("(%s %lu %lx %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1155 if(dwUrlLength<=0)
1156 dwUrlLength=-1;
1157 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1159 /* if dwUrlLength=-1 then nLength includes null but length to
1160 InternetCrackUrlW should not include it */
1161 if (dwUrlLength == -1) nLength--;
1163 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1164 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1166 memset(&UCW,0,sizeof(UCW));
1167 if(lpUrlComponents->dwHostNameLength!=0)
1168 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1169 if(lpUrlComponents->dwUserNameLength!=0)
1170 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1171 if(lpUrlComponents->dwPasswordLength!=0)
1172 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1173 if(lpUrlComponents->dwUrlPathLength!=0)
1174 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1175 if(lpUrlComponents->dwSchemeLength!=0)
1176 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1177 if(lpUrlComponents->dwExtraInfoLength!=0)
1178 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1179 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1181 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1182 return FALSE;
1185 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1186 UCW.lpszHostName, UCW.dwHostNameLength,
1187 lpszUrl, lpwszUrl);
1188 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1189 UCW.lpszUserName, UCW.dwUserNameLength,
1190 lpszUrl, lpwszUrl);
1191 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1192 UCW.lpszPassword, UCW.dwPasswordLength,
1193 lpszUrl, lpwszUrl);
1194 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1195 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1196 lpszUrl, lpwszUrl);
1197 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1198 UCW.lpszScheme, UCW.dwSchemeLength,
1199 lpszUrl, lpwszUrl);
1200 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1201 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1202 lpszUrl, lpwszUrl);
1203 lpUrlComponents->nScheme=UCW.nScheme;
1204 lpUrlComponents->nPort=UCW.nPort;
1205 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1207 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1208 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1209 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1210 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1211 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1213 return TRUE;
1216 static const WCHAR url_schemes[][7] =
1218 {'f','t','p',0},
1219 {'g','o','p','h','e','r',0},
1220 {'h','t','t','p',0},
1221 {'h','t','t','p','s',0},
1222 {'f','i','l','e',0},
1223 {'n','e','w','s',0},
1224 {'m','a','i','l','t','o',0},
1225 {'r','e','s',0},
1228 /***********************************************************************
1229 * GetInternetSchemeW (internal)
1231 * Get scheme of url
1233 * RETURNS
1234 * scheme on success
1235 * INTERNET_SCHEME_UNKNOWN on failure
1238 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1240 int i;
1242 TRACE("%s %ld\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1244 if(lpszScheme==NULL)
1245 return INTERNET_SCHEME_UNKNOWN;
1247 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1248 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1249 return INTERNET_SCHEME_FIRST + i;
1251 return INTERNET_SCHEME_UNKNOWN;
1254 /***********************************************************************
1255 * SetUrlComponentValueW (Internal)
1257 * Helper function for InternetCrackUrlW
1259 * PARAMS
1260 * lppszComponent [O] Holds the returned string
1261 * dwComponentLen [I] Holds the size of lppszComponent
1262 * [O] Holds the length of the string in lppszComponent without '\0'
1263 * lpszStart [I] Holds the string to copy from
1264 * len [I] Holds the length of lpszStart without '\0'
1266 * RETURNS
1267 * TRUE on success
1268 * FALSE on failure
1271 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1273 TRACE("%s (%ld)\n", debugstr_wn(lpszStart,len), len);
1275 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1276 return FALSE;
1278 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1280 if (*lppszComponent == NULL)
1282 *lppszComponent = (LPWSTR)lpszStart;
1283 *dwComponentLen = len;
1285 else
1287 DWORD ncpylen = min((*dwComponentLen)-1, len);
1288 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1289 (*lppszComponent)[ncpylen] = '\0';
1290 *dwComponentLen = ncpylen;
1294 return TRUE;
1297 /***********************************************************************
1298 * InternetCrackUrlW (WININET.@)
1300 * Break up URL into its components
1302 * RETURNS
1303 * TRUE on success
1304 * FALSE on failure
1306 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1307 LPURL_COMPONENTSW lpUC)
1310 * RFC 1808
1311 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1314 LPCWSTR lpszParam = NULL;
1315 BOOL bIsAbsolute = FALSE;
1316 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1317 LPCWSTR lpszcp = NULL;
1318 LPWSTR lpszUrl_decode = NULL;
1319 DWORD dwUrlLength = dwUrlLength_orig;
1320 const WCHAR lpszSeparators[3]={';','?',0};
1321 const WCHAR lpszSlash[2]={'/',0};
1322 if(dwUrlLength==0)
1323 dwUrlLength=strlenW(lpszUrl);
1325 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1326 if (dwFlags & ICU_DECODE)
1328 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1329 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1331 lpszUrl = lpszUrl_decode;
1334 lpszap = lpszUrl;
1336 /* Determine if the URI is absolute. */
1337 while (*lpszap != '\0')
1339 if (isalnumW(*lpszap))
1341 lpszap++;
1342 continue;
1344 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1346 bIsAbsolute = TRUE;
1347 lpszcp = lpszap;
1349 else
1351 lpszcp = lpszUrl; /* Relative url */
1354 break;
1357 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1358 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1360 /* Parse <params> */
1361 lpszParam = strpbrkW(lpszap, lpszSeparators);
1362 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1363 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1365 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1367 LPCWSTR lpszNetLoc;
1369 /* Get scheme first. */
1370 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1371 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1372 lpszUrl, lpszcp - lpszUrl);
1374 /* Eat ':' in protocol. */
1375 lpszcp++;
1377 /* double slash indicates the net_loc portion is present */
1378 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1380 lpszcp += 2;
1382 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1383 if (lpszParam)
1385 if (lpszNetLoc)
1386 lpszNetLoc = min(lpszNetLoc, lpszParam);
1387 else
1388 lpszNetLoc = lpszParam;
1390 else if (!lpszNetLoc)
1391 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1393 /* Parse net-loc */
1394 if (lpszNetLoc)
1396 LPCWSTR lpszHost;
1397 LPCWSTR lpszPort;
1399 /* [<user>[<:password>]@]<host>[:<port>] */
1400 /* First find the user and password if they exist */
1402 lpszHost = strchrW(lpszcp, '@');
1403 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1405 /* username and password not specified. */
1406 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1407 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1409 else /* Parse out username and password */
1411 LPCWSTR lpszUser = lpszcp;
1412 LPCWSTR lpszPasswd = lpszHost;
1414 while (lpszcp < lpszHost)
1416 if (*lpszcp == ':')
1417 lpszPasswd = lpszcp;
1419 lpszcp++;
1422 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1423 lpszUser, lpszPasswd - lpszUser);
1425 if (lpszPasswd != lpszHost)
1426 lpszPasswd++;
1427 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1428 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1429 lpszHost - lpszPasswd);
1431 lpszcp++; /* Advance to beginning of host */
1434 /* Parse <host><:port> */
1436 lpszHost = lpszcp;
1437 lpszPort = lpszNetLoc;
1439 /* special case for res:// URLs: there is no port here, so the host is the
1440 entire string up to the first '/' */
1441 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1443 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1444 lpszHost, lpszPort - lpszHost);
1445 lpszcp=lpszNetLoc;
1447 else
1449 while (lpszcp < lpszNetLoc)
1451 if (*lpszcp == ':')
1452 lpszPort = lpszcp;
1454 lpszcp++;
1457 /* If the scheme is "file" and the host is just one letter, it's not a host */
1458 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1460 lpszcp=lpszHost;
1461 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1462 NULL, 0);
1464 else
1466 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1467 lpszHost, lpszPort - lpszHost);
1468 if (lpszPort != lpszNetLoc)
1469 lpUC->nPort = atoiW(++lpszPort);
1470 else switch (lpUC->nScheme)
1472 case INTERNET_SCHEME_HTTP:
1473 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1474 break;
1475 case INTERNET_SCHEME_HTTPS:
1476 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1477 break;
1478 case INTERNET_SCHEME_FTP:
1479 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1480 break;
1481 case INTERNET_SCHEME_GOPHER:
1482 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1483 break;
1484 default:
1485 break;
1491 else
1493 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1494 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1495 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1498 else
1500 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1501 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1502 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1503 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1506 /* Here lpszcp points to:
1508 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1509 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1511 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1513 INT len;
1515 /* Only truncate the parameter list if it's already been saved
1516 * in lpUC->lpszExtraInfo.
1518 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1519 len = lpszParam - lpszcp;
1520 else
1522 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1523 * newlines if necessary.
1525 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1526 if (lpsznewline != NULL)
1527 len = lpsznewline - lpszcp;
1528 else
1529 len = dwUrlLength-(lpszcp-lpszUrl);
1531 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1532 lpszcp, len);
1534 else
1536 lpUC->dwUrlPathLength = 0;
1539 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1540 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1541 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1542 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1543 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1545 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1546 return TRUE;
1549 /***********************************************************************
1550 * InternetAttemptConnect (WININET.@)
1552 * Attempt to make a connection to the internet
1554 * RETURNS
1555 * ERROR_SUCCESS on success
1556 * Error value on failure
1559 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1561 FIXME("Stub\n");
1562 return ERROR_SUCCESS;
1566 /***********************************************************************
1567 * InternetCanonicalizeUrlA (WININET.@)
1569 * Escape unsafe characters and spaces
1571 * RETURNS
1572 * TRUE on success
1573 * FALSE on failure
1576 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1577 LPDWORD lpdwBufferLength, DWORD dwFlags)
1579 HRESULT hr;
1580 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1581 if(dwFlags & ICU_DECODE)
1583 dwURLFlags |= URL_UNESCAPE;
1584 dwFlags &= ~ICU_DECODE;
1587 if(dwFlags & ICU_ESCAPE)
1589 dwURLFlags |= URL_UNESCAPE;
1590 dwFlags &= ~ICU_ESCAPE;
1592 if(dwFlags & ICU_BROWSER_MODE)
1594 dwURLFlags |= URL_BROWSER_MODE;
1595 dwFlags &= ~ICU_BROWSER_MODE;
1597 if(dwFlags)
1598 FIXME("Unhandled flags 0x%08lx\n", dwFlags);
1599 TRACE("%s %p %p %08lx\n", debugstr_a(lpszUrl), lpszBuffer,
1600 lpdwBufferLength, dwURLFlags);
1602 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1603 dwFlags ^= ICU_NO_ENCODE;
1605 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1607 return (hr == S_OK) ? TRUE : FALSE;
1610 /***********************************************************************
1611 * InternetCanonicalizeUrlW (WININET.@)
1613 * Escape unsafe characters and spaces
1615 * RETURNS
1616 * TRUE on success
1617 * FALSE on failure
1620 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1621 LPDWORD lpdwBufferLength, DWORD dwFlags)
1623 HRESULT hr;
1624 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1625 if(dwFlags & ICU_DECODE)
1627 dwURLFlags |= URL_UNESCAPE;
1628 dwFlags &= ~ICU_DECODE;
1631 if(dwFlags & ICU_ESCAPE)
1633 dwURLFlags |= URL_UNESCAPE;
1634 dwFlags &= ~ICU_ESCAPE;
1636 if(dwFlags & ICU_BROWSER_MODE)
1638 dwURLFlags |= URL_BROWSER_MODE;
1639 dwFlags &= ~ICU_BROWSER_MODE;
1641 if(dwFlags)
1642 FIXME("Unhandled flags 0x%08lx\n", dwFlags);
1643 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
1644 lpdwBufferLength, dwURLFlags);
1646 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1647 dwFlags ^= ICU_NO_ENCODE;
1649 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1651 return (hr == S_OK) ? TRUE : FALSE;
1655 /***********************************************************************
1656 * InternetSetStatusCallbackA (WININET.@)
1658 * Sets up a callback function which is called as progress is made
1659 * during an operation.
1661 * RETURNS
1662 * Previous callback or NULL on success
1663 * INTERNET_INVALID_STATUS_CALLBACK on failure
1666 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1667 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1669 INTERNET_STATUS_CALLBACK retVal;
1670 LPWININETHANDLEHEADER lpwh;
1672 TRACE("0x%08lx\n", (ULONG)hInternet);
1674 lpwh = WININET_GetObject(hInternet);
1675 if (!lpwh)
1676 return INTERNET_INVALID_STATUS_CALLBACK;
1678 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1679 retVal = lpwh->lpfnStatusCB;
1680 lpwh->lpfnStatusCB = lpfnIntCB;
1682 WININET_Release( lpwh );
1684 return retVal;
1687 /***********************************************************************
1688 * InternetSetStatusCallbackW (WININET.@)
1690 * Sets up a callback function which is called as progress is made
1691 * during an operation.
1693 * RETURNS
1694 * Previous callback or NULL on success
1695 * INTERNET_INVALID_STATUS_CALLBACK on failure
1698 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1699 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1701 INTERNET_STATUS_CALLBACK retVal;
1702 LPWININETHANDLEHEADER lpwh;
1704 TRACE("0x%08lx\n", (ULONG)hInternet);
1706 lpwh = WININET_GetObject(hInternet);
1707 if (!lpwh)
1708 return INTERNET_INVALID_STATUS_CALLBACK;
1710 lpwh->dwInternalFlags |= INET_CALLBACKW;
1711 retVal = lpwh->lpfnStatusCB;
1712 lpwh->lpfnStatusCB = lpfnIntCB;
1714 WININET_Release( lpwh );
1716 return retVal;
1719 /***********************************************************************
1720 * InternetSetFilePointer (WININET.@)
1722 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1723 PVOID pReserved, DWORD dwMoveContext, DWORD dwContext)
1725 FIXME("stub\n");
1726 return FALSE;
1729 /***********************************************************************
1730 * InternetWriteFile (WININET.@)
1732 * Write data to an open internet file
1734 * RETURNS
1735 * TRUE on success
1736 * FALSE on failure
1739 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1740 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1742 BOOL retval = FALSE;
1743 int nSocket = -1;
1744 LPWININETHANDLEHEADER lpwh;
1746 TRACE("\n");
1747 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1748 if (NULL == lpwh)
1749 return FALSE;
1751 switch (lpwh->htype)
1753 case WH_HHTTPREQ:
1755 LPWININETHTTPREQW lpwhr;
1756 lpwhr = (LPWININETHTTPREQW)lpwh;
1758 TRACE("HTTPREQ %li\n",dwNumOfBytesToWrite);
1759 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1760 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1762 WININET_Release( lpwh );
1763 return retval;
1765 break;
1767 case WH_HFILE:
1768 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1769 break;
1771 default:
1772 break;
1775 if (nSocket != -1)
1777 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1778 retval = (res >= 0);
1779 *lpdwNumOfBytesWritten = retval ? res : 0;
1781 WININET_Release( lpwh );
1783 return retval;
1787 static BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1788 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1789 BOOL bWait, BOOL bSendCompletionStatus)
1791 BOOL retval = FALSE;
1792 int nSocket = -1;
1794 /* FIXME: this should use NETCON functions! */
1795 switch (lpwh->htype)
1797 case WH_HHTTPREQ:
1798 if (!NETCON_recv(&((LPWININETHTTPREQW)lpwh)->netConnection, lpBuffer,
1799 dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0, (int *)pdwNumOfBytesRead))
1801 *pdwNumOfBytesRead = 0;
1802 retval = TRUE; /* Under windows, it seems to return 0 even if nothing was read... */
1804 else
1805 retval = TRUE;
1806 break;
1808 case WH_HFILE:
1809 /* FIXME: FTP should use NETCON_ stuff */
1810 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1811 if (nSocket != -1)
1813 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1814 retval = (res >= 0);
1815 *pdwNumOfBytesRead = retval ? res : 0;
1817 break;
1819 default:
1820 break;
1823 if (bSendCompletionStatus)
1825 INTERNET_ASYNC_RESULT iar;
1827 iar.dwResult = retval;
1828 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1829 INTERNET_GetLastError();
1831 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1832 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1833 sizeof(INTERNET_ASYNC_RESULT));
1835 return retval;
1838 /***********************************************************************
1839 * InternetReadFile (WININET.@)
1841 * Read data from an open internet file
1843 * RETURNS
1844 * TRUE on success
1845 * FALSE on failure
1848 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1849 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1851 LPWININETHANDLEHEADER lpwh;
1852 BOOL retval;
1854 TRACE("%p %p %ld %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1856 lpwh = WININET_GetObject( hFile );
1857 if (!lpwh)
1859 SetLastError(ERROR_INVALID_HANDLE);
1860 return FALSE;
1863 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1864 WININET_Release( lpwh );
1866 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1867 return retval;
1870 /***********************************************************************
1871 * InternetReadFileExA (WININET.@)
1873 * Read data from an open internet file
1875 * PARAMS
1876 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1877 * lpBuffersOut [I/O] Buffer.
1878 * dwFlags [I] Flags. See notes.
1879 * dwContext [I] Context for callbacks.
1881 * RETURNS
1882 * TRUE on success
1883 * FALSE on failure
1885 * NOTES
1886 * The parameter dwFlags include zero or more of the following flags:
1887 *|IRF_ASYNC - Makes the call asynchronous.
1888 *|IRF_SYNC - Makes the call synchronous.
1889 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1890 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1892 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1894 * SEE
1895 * InternetOpenUrlA(), HttpOpenRequestA()
1897 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1898 DWORD dwFlags, DWORD dwContext)
1900 BOOL retval = FALSE;
1901 LPWININETHANDLEHEADER lpwh;
1903 TRACE("(%p %p 0x%lx 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1905 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1906 FIXME("these dwFlags aren't implemented: 0x%lx\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1908 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1910 SetLastError(ERROR_INVALID_PARAMETER);
1911 return FALSE;
1914 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1915 if (!lpwh)
1917 SetLastError(ERROR_INVALID_HANDLE);
1918 return FALSE;
1921 /* FIXME: native only does it asynchronously if the amount of data
1922 * requested isn't available. See NtReadFile. */
1923 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1924 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better, but
1925 * we should implement the above first */
1926 if (dwFlags & IRF_ASYNC)
1928 WORKREQUEST workRequest;
1929 struct WORKREQ_INTERNETREADFILEEXA *req;
1931 workRequest.asyncall = INTERNETREADFILEEXA;
1932 workRequest.hdr = WININET_AddRef( lpwh );
1933 req = &workRequest.u.InternetReadFileExA;
1934 req->lpBuffersOut = lpBuffersOut;
1936 retval = INTERNET_AsyncCall(&workRequest);
1937 if (!retval) return FALSE;
1939 SetLastError(ERROR_IO_PENDING);
1940 return FALSE;
1943 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1944 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1945 !(dwFlags & IRF_NO_WAIT), FALSE);
1947 WININET_Release( lpwh );
1949 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1950 return retval;
1953 /***********************************************************************
1954 * InternetReadFileExW (WININET.@)
1956 * Read data from an open internet file.
1958 * PARAMS
1959 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1960 * lpBuffersOut [I/O] Buffer.
1961 * dwFlags [I] Flags.
1962 * dwContext [I] Context for callbacks.
1964 * RETURNS
1965 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1967 * NOTES
1968 * Not implemented in Wine or native either (as of IE6 SP2).
1971 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1972 DWORD dwFlags, DWORD dwContext)
1974 ERR("(%p, %p, 0x%lx, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1976 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1977 return FALSE;
1980 /***********************************************************************
1981 * INET_QueryOptionHelper (internal)
1983 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1984 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1986 LPWININETHANDLEHEADER lpwhh;
1987 BOOL bSuccess = FALSE;
1989 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1991 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1993 switch (dwOption)
1995 case INTERNET_OPTION_HANDLE_TYPE:
1997 ULONG type;
1999 if (!lpwhh)
2001 WARN("Invalid hInternet handle\n");
2002 SetLastError(ERROR_INVALID_HANDLE);
2003 return FALSE;
2006 type = lpwhh->htype;
2008 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
2010 if (*lpdwBufferLength < sizeof(ULONG))
2011 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2012 else
2014 memcpy(lpBuffer, &type, sizeof(ULONG));
2015 bSuccess = TRUE;
2017 *lpdwBufferLength = sizeof(ULONG);
2018 break;
2021 case INTERNET_OPTION_REQUEST_FLAGS:
2023 ULONG flags = 4;
2024 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
2025 if (*lpdwBufferLength < sizeof(ULONG))
2026 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2027 else
2029 memcpy(lpBuffer, &flags, sizeof(ULONG));
2030 bSuccess = TRUE;
2032 *lpdwBufferLength = sizeof(ULONG);
2033 break;
2036 case INTERNET_OPTION_URL:
2037 case INTERNET_OPTION_DATAFILE_NAME:
2039 if (!lpwhh)
2041 WARN("Invalid hInternet handle\n");
2042 SetLastError(ERROR_INVALID_HANDLE);
2043 return FALSE;
2045 if (lpwhh->htype == WH_HHTTPREQ)
2047 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2048 WCHAR url[1023];
2049 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2050 static const WCHAR szHost[] = {'H','o','s','t',0};
2051 DWORD sizeRequired;
2052 LPHTTPHEADERW Host;
2054 Host = HTTP_GetHeader(lpreq,szHost);
2055 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2056 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2057 if(!bIsUnicode)
2059 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2060 lpBuffer,*lpdwBufferLength,NULL,NULL);
2061 if (sizeRequired > *lpdwBufferLength)
2062 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2063 else
2064 bSuccess = TRUE;
2065 *lpdwBufferLength = sizeRequired;
2067 else
2069 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2070 if (*lpdwBufferLength < sizeRequired)
2071 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2072 else
2074 strcpyW(lpBuffer, url);
2075 bSuccess = TRUE;
2077 *lpdwBufferLength = sizeRequired;
2080 break;
2082 case INTERNET_OPTION_HTTP_VERSION:
2084 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2085 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2086 else
2089 * Presently hardcoded to 1.1
2091 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2092 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2093 bSuccess = TRUE;
2095 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2096 break;
2098 case INTERNET_OPTION_CONNECTED_STATE:
2100 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2101 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2103 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2104 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2105 else
2107 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2108 bSuccess = TRUE;
2110 *lpdwBufferLength = sizeof(*pdwConnectedState);
2111 break;
2113 case INTERNET_OPTION_PROXY:
2115 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2116 WININETAPPINFOW wai;
2118 if (lpwai == NULL)
2120 TRACE("Getting global proxy info\n");
2121 memset(&wai, 0, sizeof(WININETAPPINFOW));
2122 INTERNET_ConfigureProxyFromReg( &wai );
2123 lpwai = &wai;
2126 if (bIsUnicode)
2128 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2129 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2131 if (lpwai->lpszProxy)
2132 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2133 sizeof(WCHAR);
2134 if (lpwai->lpszProxyBypass)
2135 proxyBypassBytesRequired =
2136 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2137 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2138 proxyBytesRequired + proxyBypassBytesRequired)
2139 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2140 else
2142 pPI->dwAccessType = lpwai->dwAccessType;
2143 if (lpwai->lpszProxy)
2145 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2146 sizeof(INTERNET_PROXY_INFOW));
2147 lstrcpyW((LPWSTR)pPI->lpszProxy, lpwai->lpszProxy);
2149 else
2151 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2152 sizeof(INTERNET_PROXY_INFOW));
2153 *((LPWSTR)(pPI->lpszProxy)) = 0;
2156 if (lpwai->lpszProxyBypass)
2158 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2159 sizeof(INTERNET_PROXY_INFOW) +
2160 proxyBytesRequired);
2161 lstrcpyW((LPWSTR)pPI->lpszProxyBypass,
2162 lpwai->lpszProxyBypass);
2164 else
2166 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2167 sizeof(INTERNET_PROXY_INFOW) +
2168 proxyBytesRequired);
2169 *((LPWSTR)(pPI->lpszProxyBypass)) = 0;
2171 bSuccess = TRUE;
2173 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2174 proxyBytesRequired + proxyBypassBytesRequired;
2176 else
2178 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2179 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2181 if (lpwai->lpszProxy)
2182 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2183 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2184 if (lpwai->lpszProxyBypass)
2185 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2186 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2187 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2188 proxyBytesRequired + proxyBypassBytesRequired)
2189 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2190 else
2192 pPI->dwAccessType = lpwai->dwAccessType;
2193 if (lpwai->lpszProxy)
2195 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2196 sizeof(INTERNET_PROXY_INFOA));
2197 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2198 (LPSTR)pPI->lpszProxy, proxyBytesRequired, NULL, NULL);
2200 else
2202 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2203 sizeof(INTERNET_PROXY_INFOA));
2204 *((LPSTR)(pPI->lpszProxy)) = '\0';
2207 if (lpwai->lpszProxyBypass)
2209 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2210 sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
2211 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2212 -1, (LPSTR)pPI->lpszProxyBypass,
2213 proxyBypassBytesRequired,
2214 NULL, NULL);
2216 else
2218 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2219 sizeof(INTERNET_PROXY_INFOA) +
2220 proxyBytesRequired);
2221 *((LPSTR)(pPI->lpszProxyBypass)) = '\0';
2223 bSuccess = TRUE;
2225 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2226 proxyBytesRequired + proxyBypassBytesRequired;
2228 break;
2230 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2232 ULONG conn = 2;
2233 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %ld\n", conn);
2234 if (*lpdwBufferLength < sizeof(ULONG))
2235 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2236 else
2238 memcpy(lpBuffer, &conn, sizeof(ULONG));
2239 bSuccess = TRUE;
2241 *lpdwBufferLength = sizeof(ULONG);
2242 break;
2244 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2246 ULONG conn = 4;
2247 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %ld\n", conn);
2248 if (*lpdwBufferLength < sizeof(ULONG))
2249 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2250 else
2252 memcpy(lpBuffer, &conn, sizeof(ULONG));
2253 bSuccess = TRUE;
2255 *lpdwBufferLength = sizeof(ULONG);
2256 break;
2258 case INTERNET_OPTION_SECURITY_FLAGS:
2259 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2260 break;
2262 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2263 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2265 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2266 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2268 else if (lpwhh->htype == WH_HHTTPREQ)
2270 LPWININETHTTPREQW lpwhr;
2271 PCCERT_CONTEXT context;
2273 lpwhr = (LPWININETHTTPREQW)lpwhh;
2274 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2275 if (context)
2277 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2278 DWORD strLen;
2280 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2281 info->ftExpiry = context->pCertInfo->NotAfter;
2282 info->ftStart = context->pCertInfo->NotBefore;
2283 if (bIsUnicode)
2285 strLen = CertNameToStrW(context->dwCertEncodingType,
2286 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2287 NULL, 0);
2288 info->lpszSubjectInfo = LocalAlloc(0,
2289 strLen * sizeof(WCHAR));
2290 if (info->lpszSubjectInfo)
2291 CertNameToStrW(context->dwCertEncodingType,
2292 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2293 info->lpszSubjectInfo, strLen);
2294 strLen = CertNameToStrW(context->dwCertEncodingType,
2295 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2296 NULL, 0);
2297 info->lpszIssuerInfo = LocalAlloc(0,
2298 strLen * sizeof(WCHAR));
2299 if (info->lpszIssuerInfo)
2300 CertNameToStrW(context->dwCertEncodingType,
2301 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2302 info->lpszIssuerInfo, strLen);
2304 else
2306 LPINTERNET_CERTIFICATE_INFOA infoA =
2307 (LPINTERNET_CERTIFICATE_INFOA)info;
2309 strLen = CertNameToStrA(context->dwCertEncodingType,
2310 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2311 NULL, 0);
2312 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2313 if (infoA->lpszSubjectInfo)
2314 CertNameToStrA(context->dwCertEncodingType,
2315 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2316 infoA->lpszSubjectInfo, strLen);
2317 strLen = CertNameToStrA(context->dwCertEncodingType,
2318 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2319 NULL, 0);
2320 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2321 if (infoA->lpszIssuerInfo)
2322 CertNameToStrA(context->dwCertEncodingType,
2323 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2324 infoA->lpszIssuerInfo, strLen);
2327 * Contrary to MSDN, these do not appear to be set.
2328 * lpszProtocolName
2329 * lpszSignatureAlgName
2330 * lpszEncryptionAlgName
2331 * dwKeySize
2333 CertFreeCertificateContext(context);
2334 bSuccess = TRUE;
2337 break;
2338 default:
2339 FIXME("Stub! %ld\n", dwOption);
2340 break;
2342 if (lpwhh)
2343 WININET_Release( lpwhh );
2345 return bSuccess;
2348 /***********************************************************************
2349 * InternetQueryOptionW (WININET.@)
2351 * Queries an options on the specified handle
2353 * RETURNS
2354 * TRUE on success
2355 * FALSE on failure
2358 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2359 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2361 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2364 /***********************************************************************
2365 * InternetQueryOptionA (WININET.@)
2367 * Queries an options on the specified handle
2369 * RETURNS
2370 * TRUE on success
2371 * FALSE on failure
2374 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2375 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2377 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2381 /***********************************************************************
2382 * InternetSetOptionW (WININET.@)
2384 * Sets an options on the specified handle
2386 * RETURNS
2387 * TRUE on success
2388 * FALSE on failure
2391 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2392 LPVOID lpBuffer, DWORD dwBufferLength)
2394 LPWININETHANDLEHEADER lpwhh;
2395 BOOL ret = TRUE;
2397 TRACE("0x%08lx\n", dwOption);
2399 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2400 if( !lpwhh )
2401 return FALSE;
2403 switch (dwOption)
2405 case INTERNET_OPTION_HTTP_VERSION:
2407 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2408 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2410 break;
2411 case INTERNET_OPTION_ERROR_MASK:
2413 unsigned long flags=*(unsigned long*)lpBuffer;
2414 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2416 break;
2417 case INTERNET_OPTION_CODEPAGE:
2419 unsigned long codepage=*(unsigned long*)lpBuffer;
2420 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2422 break;
2423 case INTERNET_OPTION_REQUEST_PRIORITY:
2425 unsigned long priority=*(unsigned long*)lpBuffer;
2426 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2428 break;
2429 case INTERNET_OPTION_CONNECT_TIMEOUT:
2431 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2432 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2434 break;
2435 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2437 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2438 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2440 break;
2441 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2443 unsigned long conns=*(unsigned long*)lpBuffer;
2444 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2446 break;
2447 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2449 unsigned long conns=*(unsigned long*)lpBuffer;
2450 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2452 break;
2453 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2454 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2455 break;
2456 case INTERNET_OPTION_END_BROWSER_SESSION:
2457 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2458 break;
2459 case INTERNET_OPTION_CONNECTED_STATE:
2460 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2461 break;
2462 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2463 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2464 break;
2465 case INTERNET_OPTION_SEND_TIMEOUT:
2466 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2467 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2468 if (dwBufferLength == sizeof(DWORD))
2470 if (lpwhh->htype == WH_HHTTPREQ)
2471 ret = NETCON_set_timeout(
2472 &((LPWININETHTTPREQW)lpwhh)->netConnection,
2473 dwOption == INTERNET_OPTION_SEND_TIMEOUT,
2474 *(DWORD *)lpBuffer);
2475 else
2477 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2478 lpwhh->htype);
2479 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2480 ret = FALSE;
2483 else
2485 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2486 ret = FALSE;
2488 break;
2489 case INTERNET_OPTION_CONNECT_RETRIES:
2490 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2491 break;
2492 case INTERNET_OPTION_CONTEXT_VALUE:
2493 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2494 break;
2495 default:
2496 FIXME("Option %ld STUB\n",dwOption);
2497 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2498 ret = FALSE;
2499 break;
2501 WININET_Release( lpwhh );
2503 return ret;
2507 /***********************************************************************
2508 * InternetSetOptionA (WININET.@)
2510 * Sets an options on the specified handle.
2512 * RETURNS
2513 * TRUE on success
2514 * FALSE on failure
2517 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2518 LPVOID lpBuffer, DWORD dwBufferLength)
2520 LPVOID wbuffer;
2521 DWORD wlen;
2522 BOOL r;
2524 switch( dwOption )
2526 case INTERNET_OPTION_PROXY:
2528 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2529 LPINTERNET_PROXY_INFOW piw;
2530 DWORD proxlen, prbylen;
2531 LPWSTR prox, prby;
2533 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2534 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2535 wlen = sizeof(*piw) + proxlen + prbylen;
2536 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2537 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2538 piw->dwAccessType = pi->dwAccessType;
2539 prox = (LPWSTR) &piw[1];
2540 prby = &prox[proxlen+1];
2541 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2542 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2543 piw->lpszProxy = prox;
2544 piw->lpszProxyBypass = prby;
2546 break;
2547 case INTERNET_OPTION_USER_AGENT:
2548 case INTERNET_OPTION_USERNAME:
2549 case INTERNET_OPTION_PASSWORD:
2550 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2551 NULL, 0 );
2552 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2553 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2554 wbuffer, wlen );
2555 break;
2556 default:
2557 wbuffer = lpBuffer;
2558 wlen = dwBufferLength;
2561 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2563 if( lpBuffer != wbuffer )
2564 HeapFree( GetProcessHeap(), 0, wbuffer );
2566 return r;
2570 /***********************************************************************
2571 * InternetSetOptionExA (WININET.@)
2573 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2574 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2576 FIXME("Flags %08lx ignored\n", dwFlags);
2577 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2580 /***********************************************************************
2581 * InternetSetOptionExW (WININET.@)
2583 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2584 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2586 FIXME("Flags %08lx ignored\n", dwFlags);
2587 if( dwFlags & ~ISO_VALID_FLAGS )
2589 SetLastError( ERROR_INVALID_PARAMETER );
2590 return FALSE;
2592 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2595 static const WCHAR WININET_wkday[7][4] =
2596 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2597 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2598 static const WCHAR WININET_month[12][4] =
2599 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2600 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2601 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2603 /***********************************************************************
2604 * InternetTimeFromSystemTimeA (WININET.@)
2606 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2608 BOOL ret;
2609 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2611 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2613 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2614 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2616 return ret;
2619 /***********************************************************************
2620 * InternetTimeFromSystemTimeW (WININET.@)
2622 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2624 static const WCHAR date[] =
2625 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2626 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2628 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2630 if (!time || !string) return FALSE;
2632 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2633 return FALSE;
2635 sprintfW( string, date,
2636 WININET_wkday[time->wDayOfWeek],
2637 time->wDay,
2638 WININET_month[time->wMonth - 1],
2639 time->wYear,
2640 time->wHour,
2641 time->wMinute,
2642 time->wSecond );
2644 return TRUE;
2647 /***********************************************************************
2648 * InternetTimeToSystemTimeA (WININET.@)
2650 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2652 BOOL ret = FALSE;
2653 WCHAR *stringW;
2654 int len;
2656 TRACE( "%s %p 0x%08lx\n", debugstr_a(string), time, reserved );
2658 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2659 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2661 if (stringW)
2663 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2664 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2665 HeapFree( GetProcessHeap(), 0, stringW );
2667 return ret;
2670 /***********************************************************************
2671 * InternetTimeToSystemTimeW (WININET.@)
2673 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2675 unsigned int i;
2676 WCHAR *s = (LPWSTR)string;
2678 TRACE( "%s %p 0x%08lx\n", debugstr_w(string), time, reserved );
2680 if (!string || !time) return FALSE;
2682 /* Windows does this too */
2683 GetSystemTime( time );
2685 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2686 * a SYSTEMTIME structure.
2689 while (*s && !isalphaW( *s )) s++;
2690 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2691 time->wDayOfWeek = 7;
2693 for (i = 0; i < 7; i++)
2695 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2696 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2697 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2699 time->wDayOfWeek = i;
2700 break;
2704 if (time->wDayOfWeek > 6) return TRUE;
2705 while (*s && !isdigitW( *s )) s++;
2706 time->wDay = strtolW( s, &s, 10 );
2708 while (*s && !isalphaW( *s )) s++;
2709 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2710 time->wMonth = 0;
2712 for (i = 0; i < 12; i++)
2714 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2715 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2716 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2718 time->wMonth = i + 1;
2719 break;
2722 if (time->wMonth == 0) return TRUE;
2724 while (*s && !isdigitW( *s )) s++;
2725 if (*s == '\0') return TRUE;
2726 time->wYear = strtolW( s, &s, 10 );
2728 while (*s && !isdigitW( *s )) s++;
2729 if (*s == '\0') return TRUE;
2730 time->wHour = strtolW( s, &s, 10 );
2732 while (*s && !isdigitW( *s )) s++;
2733 if (*s == '\0') return TRUE;
2734 time->wMinute = strtolW( s, &s, 10 );
2736 while (*s && !isdigitW( *s )) s++;
2737 if (*s == '\0') return TRUE;
2738 time->wSecond = strtolW( s, &s, 10 );
2740 time->wMilliseconds = 0;
2741 return TRUE;
2744 /***********************************************************************
2745 * InternetCheckConnectionW (WININET.@)
2747 * Pings a requested host to check internet connection
2749 * RETURNS
2750 * TRUE on success and FALSE on failure. If a failure then
2751 * ERROR_NOT_CONNECTED is placed into GetLastError
2754 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2757 * this is a kludge which runs the resident ping program and reads the output.
2759 * Anyone have a better idea?
2762 BOOL rc = FALSE;
2763 static const CHAR ping[] = "ping -w 1 ";
2764 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2765 CHAR *command = NULL;
2766 WCHAR hostW[1024];
2767 DWORD len;
2768 int status = -1;
2770 FIXME("\n");
2773 * Crack or set the Address
2775 if (lpszUrl == NULL)
2778 * According to the doc we are supost to use the ip for the next
2779 * server in the WnInet internal server database. I have
2780 * no idea what that is or how to get it.
2782 * So someone needs to implement this.
2784 FIXME("Unimplemented with URL of NULL\n");
2785 return TRUE;
2787 else
2789 URL_COMPONENTSW components;
2791 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2792 components.lpszHostName = (LPWSTR)&hostW;
2793 components.dwHostNameLength = 1024;
2795 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2796 goto End;
2798 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2802 * Build our ping command
2804 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2805 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2806 strcpy(command,ping);
2807 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2808 strcat(command,redirect);
2810 TRACE("Ping command is : %s\n",command);
2812 status = system(command);
2814 TRACE("Ping returned a code of %i\n",status);
2816 /* Ping return code of 0 indicates success */
2817 if (status == 0)
2818 rc = TRUE;
2820 End:
2822 HeapFree( GetProcessHeap(), 0, command );
2823 if (rc == FALSE)
2824 SetLastError(ERROR_NOT_CONNECTED);
2826 return rc;
2830 /***********************************************************************
2831 * InternetCheckConnectionA (WININET.@)
2833 * Pings a requested host to check internet connection
2835 * RETURNS
2836 * TRUE on success and FALSE on failure. If a failure then
2837 * ERROR_NOT_CONNECTED is placed into GetLastError
2840 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2842 WCHAR *szUrl;
2843 INT len;
2844 BOOL rc;
2846 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2847 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2848 return FALSE;
2849 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2850 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2851 HeapFree(GetProcessHeap(), 0, szUrl);
2853 return rc;
2857 /**********************************************************
2858 * INTERNET_InternetOpenUrlW (internal)
2860 * Opens an URL
2862 * RETURNS
2863 * handle of connection or NULL on failure
2865 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2866 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2868 URL_COMPONENTSW urlComponents;
2869 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2870 WCHAR password[1024], path[2048], extra[1024];
2871 HINTERNET client = NULL, client1 = NULL;
2873 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2874 dwHeadersLength, dwFlags, dwContext);
2876 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2877 urlComponents.lpszScheme = protocol;
2878 urlComponents.dwSchemeLength = 32;
2879 urlComponents.lpszHostName = hostName;
2880 urlComponents.dwHostNameLength = MAXHOSTNAME;
2881 urlComponents.lpszUserName = userName;
2882 urlComponents.dwUserNameLength = 1024;
2883 urlComponents.lpszPassword = password;
2884 urlComponents.dwPasswordLength = 1024;
2885 urlComponents.lpszUrlPath = path;
2886 urlComponents.dwUrlPathLength = 2048;
2887 urlComponents.lpszExtraInfo = extra;
2888 urlComponents.dwExtraInfoLength = 1024;
2889 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2890 return NULL;
2891 switch(urlComponents.nScheme) {
2892 case INTERNET_SCHEME_FTP:
2893 if(urlComponents.nPort == 0)
2894 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2895 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2896 userName, password, dwFlags, dwContext, INET_OPENURL);
2897 if(client == NULL)
2898 break;
2899 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2900 if(client1 == NULL) {
2901 InternetCloseHandle(client);
2902 break;
2904 break;
2906 case INTERNET_SCHEME_HTTP:
2907 case INTERNET_SCHEME_HTTPS: {
2908 static const WCHAR szStars[] = { '*','/','*', 0 };
2909 LPCWSTR accept[2] = { szStars, NULL };
2910 if(urlComponents.nPort == 0) {
2911 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2912 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2913 else
2914 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2916 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2917 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2918 userName, password, dwFlags, dwContext, INET_OPENURL);
2919 if(client == NULL)
2920 break;
2921 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2922 if(client1 == NULL) {
2923 InternetCloseHandle(client);
2924 break;
2926 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2927 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0)) {
2928 InternetCloseHandle(client1);
2929 client1 = NULL;
2930 break;
2933 case INTERNET_SCHEME_GOPHER:
2934 /* gopher doesn't seem to be implemented in wine, but it's supposed
2935 * to be supported by InternetOpenUrlA. */
2936 default:
2937 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2938 break;
2941 TRACE(" %p <--\n", client1);
2943 return client1;
2946 /**********************************************************
2947 * InternetOpenUrlW (WININET.@)
2949 * Opens an URL
2951 * RETURNS
2952 * handle of connection or NULL on failure
2954 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2955 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2957 HINTERNET ret = NULL;
2958 LPWININETAPPINFOW hIC = NULL;
2960 if (TRACE_ON(wininet)) {
2961 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2962 dwHeadersLength, dwFlags, dwContext);
2963 TRACE(" flags :");
2964 dump_INTERNET_FLAGS(dwFlags);
2967 if (!lpszUrl)
2969 SetLastError(ERROR_INVALID_PARAMETER);
2970 goto lend;
2973 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2974 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2975 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2976 goto lend;
2979 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2980 WORKREQUEST workRequest;
2981 struct WORKREQ_INTERNETOPENURLW *req;
2983 workRequest.asyncall = INTERNETOPENURLW;
2984 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2985 req = &workRequest.u.InternetOpenUrlW;
2986 req->lpszUrl = WININET_strdupW(lpszUrl);
2987 if (lpszHeaders)
2988 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2989 else
2990 req->lpszHeaders = 0;
2991 req->dwHeadersLength = dwHeadersLength;
2992 req->dwFlags = dwFlags;
2993 req->dwContext = dwContext;
2995 INTERNET_AsyncCall(&workRequest);
2997 * This is from windows.
2999 SetLastError(ERROR_IO_PENDING);
3000 } else {
3001 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3004 lend:
3005 if( hIC )
3006 WININET_Release( &hIC->hdr );
3007 TRACE(" %p <--\n", ret);
3009 return ret;
3012 /**********************************************************
3013 * InternetOpenUrlA (WININET.@)
3015 * Opens an URL
3017 * RETURNS
3018 * handle of connection or NULL on failure
3020 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3021 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
3023 HINTERNET rc = (HINTERNET)NULL;
3025 INT lenUrl;
3026 INT lenHeaders = 0;
3027 LPWSTR szUrl = NULL;
3028 LPWSTR szHeaders = NULL;
3030 TRACE("\n");
3032 if(lpszUrl) {
3033 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3034 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3035 if(!szUrl)
3036 return (HINTERNET)NULL;
3037 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3040 if(lpszHeaders) {
3041 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3042 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3043 if(!szHeaders) {
3044 HeapFree(GetProcessHeap(), 0, szUrl);
3045 return (HINTERNET)NULL;
3047 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3050 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3051 lenHeaders, dwFlags, dwContext);
3053 HeapFree(GetProcessHeap(), 0, szUrl);
3054 HeapFree(GetProcessHeap(), 0, szHeaders);
3056 return rc;
3060 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3062 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3064 if (lpwite)
3066 lpwite->dwError = 0;
3067 lpwite->response[0] = '\0';
3070 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3072 HeapFree(GetProcessHeap(), 0, lpwite);
3073 return NULL;
3076 return lpwite;
3080 /***********************************************************************
3081 * INTERNET_SetLastError (internal)
3083 * Set last thread specific error
3085 * RETURNS
3088 void INTERNET_SetLastError(DWORD dwError)
3090 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3092 if (!lpwite)
3093 lpwite = INTERNET_AllocThreadError();
3095 SetLastError(dwError);
3096 if(lpwite)
3097 lpwite->dwError = dwError;
3101 /***********************************************************************
3102 * INTERNET_GetLastError (internal)
3104 * Get last thread specific error
3106 * RETURNS
3109 DWORD INTERNET_GetLastError(void)
3111 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3112 if (!lpwite) return 0;
3113 /* TlsGetValue clears last error, so set it again here */
3114 SetLastError(lpwite->dwError);
3115 return lpwite->dwError;
3119 /***********************************************************************
3120 * INTERNET_WorkerThreadFunc (internal)
3122 * Worker thread execution function
3124 * RETURNS
3127 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3129 DWORD dwWaitRes;
3131 while (1)
3133 if(dwNumJobs > 0) {
3134 INTERNET_ExecuteWork();
3135 continue;
3137 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
3139 if (dwWaitRes == WAIT_OBJECT_0 + 1)
3140 INTERNET_ExecuteWork();
3141 else
3142 break;
3144 InterlockedIncrement(&dwNumIdleThreads);
3147 InterlockedDecrement(&dwNumIdleThreads);
3148 InterlockedDecrement(&dwNumThreads);
3149 TRACE("Worker thread exiting\n");
3150 return TRUE;
3154 /***********************************************************************
3155 * INTERNET_InsertWorkRequest (internal)
3157 * Insert work request into queue
3159 * RETURNS
3162 static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
3164 BOOL bSuccess = FALSE;
3165 LPWORKREQUEST lpNewRequest;
3167 TRACE("\n");
3169 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3170 if (lpNewRequest)
3172 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3173 lpNewRequest->prev = NULL;
3175 EnterCriticalSection(&csQueue);
3177 lpNewRequest->next = lpWorkQueueTail;
3178 if (lpWorkQueueTail)
3179 lpWorkQueueTail->prev = lpNewRequest;
3180 lpWorkQueueTail = lpNewRequest;
3181 if (!lpHeadWorkQueue)
3182 lpHeadWorkQueue = lpWorkQueueTail;
3184 LeaveCriticalSection(&csQueue);
3186 bSuccess = TRUE;
3187 InterlockedIncrement(&dwNumJobs);
3190 return bSuccess;
3194 /***********************************************************************
3195 * INTERNET_GetWorkRequest (internal)
3197 * Retrieves work request from queue
3199 * RETURNS
3202 static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
3204 BOOL bSuccess = FALSE;
3205 LPWORKREQUEST lpRequest = NULL;
3207 TRACE("\n");
3209 EnterCriticalSection(&csQueue);
3211 if (lpHeadWorkQueue)
3213 lpRequest = lpHeadWorkQueue;
3214 lpHeadWorkQueue = lpHeadWorkQueue->prev;
3215 if (lpRequest == lpWorkQueueTail)
3216 lpWorkQueueTail = lpHeadWorkQueue;
3219 LeaveCriticalSection(&csQueue);
3221 if (lpRequest)
3223 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
3224 HeapFree(GetProcessHeap(), 0, lpRequest);
3225 bSuccess = TRUE;
3226 InterlockedDecrement(&dwNumJobs);
3229 return bSuccess;
3233 /***********************************************************************
3234 * INTERNET_AsyncCall (internal)
3236 * Retrieves work request from queue
3238 * RETURNS
3241 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3243 HANDLE hThread;
3244 DWORD dwTID;
3245 BOOL bSuccess = FALSE;
3247 TRACE("\n");
3249 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
3251 InterlockedIncrement(&dwNumIdleThreads);
3253 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
3254 !(hThread = CreateThread(NULL, 0,
3255 INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
3257 InterlockedDecrement(&dwNumThreads);
3258 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3259 goto lerror;
3262 TRACE("Created new thread\n");
3265 bSuccess = TRUE;
3266 INTERNET_InsertWorkRequest(lpWorkRequest);
3267 SetEvent(hWorkEvent);
3269 lerror:
3271 return bSuccess;
3275 /***********************************************************************
3276 * INTERNET_ExecuteWork (internal)
3278 * RETURNS
3281 static VOID INTERNET_ExecuteWork(void)
3283 WORKREQUEST workRequest;
3285 TRACE("\n");
3287 if (!INTERNET_GetWorkRequest(&workRequest))
3288 return;
3290 switch (workRequest.asyncall)
3292 case FTPPUTFILEW:
3294 struct WORKREQ_FTPPUTFILEW *req = &workRequest.u.FtpPutFileW;
3295 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3297 TRACE("FTPPUTFILEW %p\n", lpwfs);
3299 FTP_FtpPutFileW(lpwfs, req->lpszLocalFile,
3300 req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
3302 HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
3303 HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
3305 break;
3307 case FTPSETCURRENTDIRECTORYW:
3309 struct WORKREQ_FTPSETCURRENTDIRECTORYW *req;
3310 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3312 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs);
3314 req = &workRequest.u.FtpSetCurrentDirectoryW;
3315 FTP_FtpSetCurrentDirectoryW(lpwfs, req->lpszDirectory);
3316 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3318 break;
3320 case FTPCREATEDIRECTORYW:
3322 struct WORKREQ_FTPCREATEDIRECTORYW *req;
3323 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3325 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs);
3327 req = &workRequest.u.FtpCreateDirectoryW;
3328 FTP_FtpCreateDirectoryW(lpwfs, req->lpszDirectory);
3329 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3331 break;
3333 case FTPFINDFIRSTFILEW:
3335 struct WORKREQ_FTPFINDFIRSTFILEW *req;
3336 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3338 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs);
3340 req = &workRequest.u.FtpFindFirstFileW;
3341 FTP_FtpFindFirstFileW(lpwfs, req->lpszSearchFile,
3342 req->lpFindFileData, req->dwFlags, req->dwContext);
3343 HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
3345 break;
3347 case FTPGETCURRENTDIRECTORYW:
3349 struct WORKREQ_FTPGETCURRENTDIRECTORYW *req;
3350 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3352 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs);
3354 req = &workRequest.u.FtpGetCurrentDirectoryW;
3355 FTP_FtpGetCurrentDirectoryW(lpwfs,
3356 req->lpszDirectory, req->lpdwDirectory);
3358 break;
3360 case FTPOPENFILEW:
3362 struct WORKREQ_FTPOPENFILEW *req = &workRequest.u.FtpOpenFileW;
3363 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3365 TRACE("FTPOPENFILEW %p\n", lpwfs);
3367 FTP_FtpOpenFileW(lpwfs, req->lpszFilename,
3368 req->dwAccess, req->dwFlags, req->dwContext);
3369 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3371 break;
3373 case FTPGETFILEW:
3375 struct WORKREQ_FTPGETFILEW *req = &workRequest.u.FtpGetFileW;
3376 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3378 TRACE("FTPGETFILEW %p\n", lpwfs);
3380 FTP_FtpGetFileW(lpwfs, req->lpszRemoteFile,
3381 req->lpszNewFile, req->fFailIfExists,
3382 req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
3383 HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
3384 HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
3386 break;
3388 case FTPDELETEFILEW:
3390 struct WORKREQ_FTPDELETEFILEW *req = &workRequest.u.FtpDeleteFileW;
3391 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3393 TRACE("FTPDELETEFILEW %p\n", lpwfs);
3395 FTP_FtpDeleteFileW(lpwfs, req->lpszFilename);
3396 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3398 break;
3400 case FTPREMOVEDIRECTORYW:
3402 struct WORKREQ_FTPREMOVEDIRECTORYW *req;
3403 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3405 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs);
3407 req = &workRequest.u.FtpRemoveDirectoryW;
3408 FTP_FtpRemoveDirectoryW(lpwfs, req->lpszDirectory);
3409 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3411 break;
3413 case FTPRENAMEFILEW:
3415 struct WORKREQ_FTPRENAMEFILEW *req = &workRequest.u.FtpRenameFileW;
3416 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3418 TRACE("FTPRENAMEFILEW %p\n", lpwfs);
3420 FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
3421 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
3422 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
3424 break;
3426 case INTERNETFINDNEXTW:
3428 struct WORKREQ_INTERNETFINDNEXTW *req;
3429 LPWININETFINDNEXTW lpwh = (LPWININETFINDNEXTW) workRequest.hdr;
3431 TRACE("INTERNETFINDNEXTW %p\n", lpwh);
3433 req = &workRequest.u.InternetFindNextW;
3434 INTERNET_FindNextFileW(lpwh, req->lpFindFileData);
3436 break;
3438 case HTTPSENDREQUESTW:
3440 struct WORKREQ_HTTPSENDREQUESTW *req = &workRequest.u.HttpSendRequestW;
3441 LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) workRequest.hdr;
3443 TRACE("HTTPSENDREQUESTW %p\n", lpwhr);
3445 HTTP_HttpSendRequestW(lpwhr, req->lpszHeader,
3446 req->dwHeaderLength, req->lpOptional, req->dwOptionalLength,
3447 req->dwContentLength, req->bEndRequest);
3449 HeapFree(GetProcessHeap(), 0, req->lpszHeader);
3451 break;
3453 case HTTPOPENREQUESTW:
3455 struct WORKREQ_HTTPOPENREQUESTW *req = &workRequest.u.HttpOpenRequestW;
3456 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) workRequest.hdr;
3458 TRACE("HTTPOPENREQUESTW %p\n", lpwhs);
3460 HTTP_HttpOpenRequestW(lpwhs, req->lpszVerb,
3461 req->lpszObjectName, req->lpszVersion, req->lpszReferrer,
3462 req->lpszAcceptTypes, req->dwFlags, req->dwContext);
3464 HeapFree(GetProcessHeap(), 0, req->lpszVerb);
3465 HeapFree(GetProcessHeap(), 0, req->lpszObjectName);
3466 HeapFree(GetProcessHeap(), 0, req->lpszVersion);
3467 HeapFree(GetProcessHeap(), 0, req->lpszReferrer);
3469 break;
3471 case SENDCALLBACK:
3473 struct WORKREQ_SENDCALLBACK *req = &workRequest.u.SendCallback;
3475 TRACE("SENDCALLBACK %p\n", workRequest.hdr);
3477 INTERNET_SendCallback(workRequest.hdr,
3478 req->dwContext, req->dwInternetStatus, req->lpvStatusInfo,
3479 req->dwStatusInfoLength);
3481 /* And frees the copy of the status info */
3482 HeapFree(GetProcessHeap(), 0, req->lpvStatusInfo);
3484 break;
3486 case INTERNETOPENURLW:
3488 struct WORKREQ_INTERNETOPENURLW *req = &workRequest.u.InternetOpenUrlW;
3489 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest.hdr;
3491 TRACE("INTERNETOPENURLW %p\n", hIC);
3493 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3494 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3495 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3496 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3498 break;
3499 case INTERNETREADFILEEXA:
3501 struct WORKREQ_INTERNETREADFILEEXA *req = &workRequest.u.InternetReadFileExA;
3503 TRACE("INTERNETREADFILEEXA %p\n", workRequest.hdr);
3505 INTERNET_ReadFile(workRequest.hdr, req->lpBuffersOut->lpvBuffer,
3506 req->lpBuffersOut->dwBufferLength,
3507 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
3509 break;
3511 WININET_Release( workRequest.hdr );
3515 /***********************************************************************
3516 * INTERNET_GetResponseBuffer (internal)
3518 * RETURNS
3521 LPSTR INTERNET_GetResponseBuffer(void)
3523 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3524 if (!lpwite)
3525 lpwite = INTERNET_AllocThreadError();
3526 TRACE("\n");
3527 return lpwite->response;
3530 /***********************************************************************
3531 * INTERNET_GetNextLine (internal)
3533 * Parse next line in directory string listing
3535 * RETURNS
3536 * Pointer to beginning of next line
3537 * NULL on failure
3541 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3543 struct timeval tv;
3544 fd_set infd;
3545 BOOL bSuccess = FALSE;
3546 INT nRecv = 0;
3547 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3549 TRACE("\n");
3551 FD_ZERO(&infd);
3552 FD_SET(nSocket, &infd);
3553 tv.tv_sec=RESPONSE_TIMEOUT;
3554 tv.tv_usec=0;
3556 while (nRecv < MAX_REPLY_LEN)
3558 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3560 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3562 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3563 goto lend;
3566 if (lpszBuffer[nRecv] == '\n')
3568 bSuccess = TRUE;
3569 break;
3571 if (lpszBuffer[nRecv] != '\r')
3572 nRecv++;
3574 else
3576 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3577 goto lend;
3581 lend:
3582 if (bSuccess)
3584 lpszBuffer[nRecv] = '\0';
3585 *dwLen = nRecv - 1;
3586 TRACE(":%d %s\n", nRecv, lpszBuffer);
3587 return lpszBuffer;
3589 else
3591 return NULL;
3595 /**********************************************************
3596 * InternetQueryDataAvailable (WININET.@)
3598 * Determines how much data is available to be read.
3600 * RETURNS
3601 * If there is data available then TRUE, otherwise if there
3602 * is not or an error occurred then FALSE. Use GetLastError() to
3603 * check for ERROR_NO_MORE_FILES to see if it was the former.
3605 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3606 LPDWORD lpdwNumberOfBytesAvailble,
3607 DWORD dwFlags, DWORD dwConext)
3609 LPWININETHTTPREQW lpwhr;
3610 BOOL retval = FALSE;
3611 char buffer[4048];
3613 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3614 if (NULL == lpwhr)
3616 SetLastError(ERROR_NO_MORE_FILES);
3617 return FALSE;
3620 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3622 switch (lpwhr->hdr.htype)
3624 case WH_HHTTPREQ:
3625 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3626 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3628 SetLastError(ERROR_NO_MORE_FILES);
3629 retval = FALSE;
3631 else
3632 retval = TRUE;
3633 break;
3635 default:
3636 FIXME("unsupported file type\n");
3637 break;
3639 WININET_Release( &lpwhr->hdr );
3641 TRACE("<-- %i\n",retval);
3642 return retval;
3646 /***********************************************************************
3647 * InternetLockRequestFile (WININET.@)
3649 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3650 *lphLockReqHandle)
3652 FIXME("STUB\n");
3653 return FALSE;
3656 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3658 FIXME("STUB\n");
3659 return FALSE;
3663 /***********************************************************************
3664 * InternetAutodial (WININET.@)
3666 * On windows this function is supposed to dial the default internet
3667 * connection. We don't want to have Wine dial out to the internet so
3668 * we return TRUE by default. It might be nice to check if we are connected.
3670 * RETURNS
3671 * TRUE on success
3672 * FALSE on failure
3675 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3677 FIXME("STUB\n");
3679 /* Tell that we are connected to the internet. */
3680 return TRUE;
3683 /***********************************************************************
3684 * InternetAutodialHangup (WININET.@)
3686 * Hangs up a connection made with InternetAutodial
3688 * PARAM
3689 * dwReserved
3690 * RETURNS
3691 * TRUE on success
3692 * FALSE on failure
3695 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3697 FIXME("STUB\n");
3699 /* we didn't dial, we don't disconnect */
3700 return TRUE;
3703 /***********************************************************************
3704 * InternetCombineUrlA (WININET.@)
3706 * Combine a base URL with a relative URL
3708 * RETURNS
3709 * TRUE on success
3710 * FALSE on failure
3714 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3715 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3716 DWORD dwFlags)
3718 HRESULT hr=S_OK;
3720 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3722 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3723 dwFlags ^= ICU_NO_ENCODE;
3724 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3726 return (hr==S_OK);
3729 /***********************************************************************
3730 * InternetCombineUrlW (WININET.@)
3732 * Combine a base URL with a relative URL
3734 * RETURNS
3735 * TRUE on success
3736 * FALSE on failure
3740 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3741 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3742 DWORD dwFlags)
3744 HRESULT hr=S_OK;
3746 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3748 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3749 dwFlags ^= ICU_NO_ENCODE;
3750 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3752 return (hr==S_OK);
3755 /* max port num is 65535 => 5 digits */
3756 #define MAX_WORD_DIGITS 5
3758 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3759 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3760 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3761 (url)->dw##component##Length : strlen((url)->lpsz##component))
3763 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3765 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3766 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3767 return TRUE;
3768 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3769 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3770 return TRUE;
3771 if ((nScheme == INTERNET_SCHEME_FTP) &&
3772 (nPort == INTERNET_DEFAULT_FTP_PORT))
3773 return TRUE;
3774 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3775 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3776 return TRUE;
3778 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3779 return TRUE;
3781 return FALSE;
3784 /* opaque urls do not fit into the standard url hierarchy and don't have
3785 * two following slashes */
3786 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3788 return (nScheme != INTERNET_SCHEME_FTP) &&
3789 (nScheme != INTERNET_SCHEME_GOPHER) &&
3790 (nScheme != INTERNET_SCHEME_HTTP) &&
3791 (nScheme != INTERNET_SCHEME_HTTPS) &&
3792 (nScheme != INTERNET_SCHEME_FILE);
3795 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3797 int index;
3798 if (scheme < INTERNET_SCHEME_FIRST)
3799 return NULL;
3800 index = scheme - INTERNET_SCHEME_FIRST;
3801 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3802 return NULL;
3803 return (LPCWSTR)&url_schemes[index];
3806 /* we can calculate using ansi strings because we're just
3807 * calculating string length, not size
3809 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3810 LPDWORD lpdwUrlLength)
3812 INTERNET_SCHEME nScheme;
3814 *lpdwUrlLength = 0;
3816 if (lpUrlComponents->lpszScheme)
3818 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3819 *lpdwUrlLength += dwLen;
3820 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3822 else
3824 LPCWSTR scheme;
3826 nScheme = lpUrlComponents->nScheme;
3828 if (nScheme == INTERNET_SCHEME_DEFAULT)
3829 nScheme = INTERNET_SCHEME_HTTP;
3830 scheme = INTERNET_GetSchemeString(nScheme);
3831 *lpdwUrlLength += strlenW(scheme);
3834 (*lpdwUrlLength)++; /* ':' */
3835 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3836 *lpdwUrlLength += strlen("//");
3838 if (lpUrlComponents->lpszUserName)
3840 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3841 *lpdwUrlLength += strlen("@");
3843 else
3845 if (lpUrlComponents->lpszPassword)
3847 SetLastError(ERROR_INVALID_PARAMETER);
3848 return FALSE;
3852 if (lpUrlComponents->lpszPassword)
3854 *lpdwUrlLength += strlen(":");
3855 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3858 if (lpUrlComponents->lpszHostName)
3860 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3862 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3864 char szPort[MAX_WORD_DIGITS+1];
3866 sprintf(szPort, "%d", lpUrlComponents->nPort);
3867 *lpdwUrlLength += strlen(szPort);
3868 *lpdwUrlLength += strlen(":");
3871 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3872 (*lpdwUrlLength)++; /* '/' */
3875 if (lpUrlComponents->lpszUrlPath)
3876 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3878 return TRUE;
3881 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3883 INT len;
3885 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3887 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3888 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3889 urlCompW->nScheme = lpUrlComponents->nScheme;
3890 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3891 urlCompW->nPort = lpUrlComponents->nPort;
3892 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3893 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3894 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3895 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3897 if (lpUrlComponents->lpszScheme)
3899 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3900 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3901 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3902 -1, urlCompW->lpszScheme, len);
3905 if (lpUrlComponents->lpszHostName)
3907 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3908 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3909 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3910 -1, urlCompW->lpszHostName, len);
3913 if (lpUrlComponents->lpszUserName)
3915 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3916 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3917 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3918 -1, urlCompW->lpszUserName, len);
3921 if (lpUrlComponents->lpszPassword)
3923 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3924 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3925 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3926 -1, urlCompW->lpszPassword, len);
3929 if (lpUrlComponents->lpszUrlPath)
3931 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3932 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3933 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3934 -1, urlCompW->lpszUrlPath, len);
3937 if (lpUrlComponents->lpszExtraInfo)
3939 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3940 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3941 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3942 -1, urlCompW->lpszExtraInfo, len);
3946 /***********************************************************************
3947 * InternetCreateUrlA (WININET.@)
3949 * See InternetCreateUrlW.
3951 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3952 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3954 BOOL ret;
3955 LPWSTR urlW = NULL;
3956 URL_COMPONENTSW urlCompW;
3958 TRACE("(%p,%ld,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3960 if (!lpUrlComponents)
3961 return FALSE;
3963 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3965 SetLastError(ERROR_INVALID_PARAMETER);
3966 return FALSE;
3969 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3971 if (lpszUrl)
3972 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3974 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3976 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3977 *lpdwUrlLength /= sizeof(WCHAR);
3979 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3980 * minus one, so add one to leave room for NULL terminator
3982 if (ret)
3983 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3985 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3986 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3987 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3988 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3989 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3990 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3991 HeapFree(GetProcessHeap(), 0, urlW);
3993 return ret;
3996 /***********************************************************************
3997 * InternetCreateUrlW (WININET.@)
3999 * Creates a URL from its component parts.
4001 * PARAMS
4002 * lpUrlComponents [I] URL Components.
4003 * dwFlags [I] Flags. See notes.
4004 * lpszUrl [I] Buffer in which to store the created URL.
4005 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4006 * lpszUrl in characters. On output, the number of bytes
4007 * required to store the URL including terminator.
4009 * NOTES
4011 * The dwFlags parameter can be zero or more of the following:
4012 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4014 * RETURNS
4015 * TRUE on success
4016 * FALSE on failure
4019 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4020 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4022 DWORD dwLen;
4023 INTERNET_SCHEME nScheme;
4025 static const WCHAR slashSlashW[] = {'/','/'};
4026 static const WCHAR percentD[] = {'%','d',0};
4028 TRACE("(%p,%ld,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4030 if (!lpUrlComponents)
4031 return FALSE;
4033 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4035 SetLastError(ERROR_INVALID_PARAMETER);
4036 return FALSE;
4039 if (!calc_url_length(lpUrlComponents, &dwLen))
4040 return FALSE;
4042 if (!lpszUrl || *lpdwUrlLength < dwLen)
4044 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4045 SetLastError(ERROR_INSUFFICIENT_BUFFER);
4046 return FALSE;
4049 *lpdwUrlLength = dwLen;
4050 lpszUrl[0] = 0x00;
4052 dwLen = 0;
4054 if (lpUrlComponents->lpszScheme)
4056 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4057 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4058 lpszUrl += dwLen;
4060 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4062 else
4064 LPCWSTR scheme;
4065 nScheme = lpUrlComponents->nScheme;
4067 if (nScheme == INTERNET_SCHEME_DEFAULT)
4068 nScheme = INTERNET_SCHEME_HTTP;
4070 scheme = INTERNET_GetSchemeString(nScheme);
4071 dwLen = strlenW(scheme);
4072 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4073 lpszUrl += dwLen;
4076 /* all schemes are followed by at least a colon */
4077 *lpszUrl = ':';
4078 lpszUrl++;
4080 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4082 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4083 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4086 if (lpUrlComponents->lpszUserName)
4088 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4089 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4090 lpszUrl += dwLen;
4092 if (lpUrlComponents->lpszPassword)
4094 *lpszUrl = ':';
4095 lpszUrl++;
4097 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4098 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4099 lpszUrl += dwLen;
4102 *lpszUrl = '@';
4103 lpszUrl++;
4106 if (lpUrlComponents->lpszHostName)
4108 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4109 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4110 lpszUrl += dwLen;
4112 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4114 WCHAR szPort[MAX_WORD_DIGITS+1];
4116 sprintfW(szPort, percentD, lpUrlComponents->nPort);
4117 *lpszUrl = ':';
4118 lpszUrl++;
4119 dwLen = strlenW(szPort);
4120 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4121 lpszUrl += dwLen;
4124 /* add slash between hostname and path if necessary */
4125 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4127 *lpszUrl = '/';
4128 lpszUrl++;
4133 if (lpUrlComponents->lpszUrlPath)
4135 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4136 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4137 lpszUrl += dwLen;
4140 *lpszUrl = '\0';
4142 return TRUE;
4145 /***********************************************************************
4146 * InternetConfirmZoneCrossingA (WININET.@)
4149 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4151 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4152 return ERROR_SUCCESS;
4155 /***********************************************************************
4156 * InternetConfirmZoneCrossingW (WININET.@)
4159 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4161 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4162 return ERROR_SUCCESS;
4165 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4166 LPDWORD lpdwConnection, DWORD dwReserved )
4168 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
4169 lpdwConnection, dwReserved);
4170 return ERROR_SUCCESS;
4173 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4174 LPDWORD lpdwConnection, DWORD dwReserved )
4176 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
4177 lpdwConnection, dwReserved);
4178 return ERROR_SUCCESS;
4181 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4183 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4184 return TRUE;
4187 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4189 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4190 return TRUE;
4193 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
4195 FIXME("(0x%08lx, 0x%08lx) stub\n", dwConnection, dwReserved);
4196 return ERROR_SUCCESS;
4199 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4200 PBYTE pbHexHash )
4202 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4203 debugstr_w(pwszTarget), pbHexHash);
4204 return FALSE;
4207 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4209 FIXME("(%p, 0x%08lx) stub\n", hInternet, dwError);
4210 return FALSE;