wininet: Moved InternetFindNextFileW implementation to vtbl.
[wine/hacks.git] / dlls / wininet / internet.c
blobfeda3070cbba246c65c18f6a5194fbf66cdab751
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 "winineti.h"
57 #include "winnls.h"
58 #include "wine/debug.h"
59 #include "winerror.h"
60 #define NO_SHLWAPI_STREAM
61 #include "shlwapi.h"
62 #include "wincrypt.h"
64 #include "wine/exception.h"
66 #include "internet.h"
67 #include "resource.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define RESPONSE_TIMEOUT 30
75 typedef struct
77 DWORD dwError;
78 CHAR response[MAX_REPLY_LEN];
79 } WITHREADERROR, *LPWITHREADERROR;
81 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
82 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext);
84 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
85 static HMODULE WININET_hModule;
87 #define HANDLE_CHUNK_SIZE 0x10
89 static CRITICAL_SECTION WININET_cs;
90 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
92 0, 0, &WININET_cs,
93 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
94 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
96 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
98 static LPWININETHANDLEHEADER *WININET_Handles;
99 static UINT WININET_dwNextHandle;
100 static UINT WININET_dwMaxHandles;
102 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
104 LPWININETHANDLEHEADER *p;
105 UINT handle = 0, num;
107 list_init( &info->children );
109 EnterCriticalSection( &WININET_cs );
110 if( !WININET_dwMaxHandles )
112 num = HANDLE_CHUNK_SIZE;
113 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
114 sizeof (UINT)* num);
115 if( !p )
116 goto end;
117 WININET_Handles = p;
118 WININET_dwMaxHandles = num;
120 if( WININET_dwMaxHandles == WININET_dwNextHandle )
122 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
123 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
124 WININET_Handles, sizeof (UINT)* num);
125 if( !p )
126 goto end;
127 WININET_Handles = p;
128 WININET_dwMaxHandles = num;
131 handle = WININET_dwNextHandle;
132 if( WININET_Handles[handle] )
133 ERR("handle isn't free but should be\n");
134 WININET_Handles[handle] = WININET_AddRef( info );
136 while( WININET_Handles[WININET_dwNextHandle] &&
137 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
138 WININET_dwNextHandle++;
140 end:
141 LeaveCriticalSection( &WININET_cs );
143 return info->hInternet = (HINTERNET) (handle+1);
146 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
148 info->dwRefCount++;
149 TRACE("%p -> refcount = %d\n", info, info->dwRefCount );
150 return info;
153 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
155 LPWININETHANDLEHEADER info = NULL;
156 UINT handle = (UINT) hinternet;
158 EnterCriticalSection( &WININET_cs );
160 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
161 WININET_Handles[handle-1] )
162 info = WININET_AddRef( WININET_Handles[handle-1] );
164 LeaveCriticalSection( &WININET_cs );
166 TRACE("handle %d -> %p\n", handle, info);
168 return info;
171 BOOL WININET_Release( LPWININETHANDLEHEADER info )
173 info->dwRefCount--;
174 TRACE( "object %p refcount = %d\n", info, info->dwRefCount );
175 if( !info->dwRefCount )
177 if ( info->vtbl->CloseConnection )
179 TRACE( "closing connection %p\n", info);
180 info->vtbl->CloseConnection( info );
182 INTERNET_SendCallback(info, info->dwContext,
183 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
184 sizeof(HINTERNET));
185 TRACE( "destroying object %p\n", info);
186 if ( info->htype != WH_HINIT )
187 list_remove( &info->entry );
188 info->vtbl->Destroy( info );
190 return TRUE;
193 BOOL WININET_FreeHandle( HINTERNET hinternet )
195 BOOL ret = FALSE;
196 UINT handle = (UINT) hinternet;
197 LPWININETHANDLEHEADER info = NULL, child, next;
199 EnterCriticalSection( &WININET_cs );
201 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
203 handle--;
204 if( WININET_Handles[handle] )
206 info = WININET_Handles[handle];
207 TRACE( "destroying handle %d for object %p\n", handle+1, info);
208 WININET_Handles[handle] = NULL;
209 ret = TRUE;
213 LeaveCriticalSection( &WININET_cs );
215 /* As on native when the equivalent of WININET_Release is called, the handle
216 * is already invalid, but if a new handle is created at this time it does
217 * not yet get assigned the freed handle number */
218 if( info )
220 /* Free all children as native does */
221 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, WININETHANDLEHEADER, entry )
223 TRACE( "freeing child handle %d for parent handle %d\n",
224 (UINT)child->hInternet, handle+1);
225 WININET_FreeHandle( child->hInternet );
227 WININET_Release( info );
230 EnterCriticalSection( &WININET_cs );
232 if( WININET_dwNextHandle > handle && !WININET_Handles[handle] )
233 WININET_dwNextHandle = handle;
235 LeaveCriticalSection( &WININET_cs );
237 return ret;
240 /***********************************************************************
241 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
243 * PARAMS
244 * hinstDLL [I] handle to the DLL's instance
245 * fdwReason [I]
246 * lpvReserved [I] reserved, must be NULL
248 * RETURNS
249 * Success: TRUE
250 * Failure: FALSE
253 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
255 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
257 switch (fdwReason) {
258 case DLL_PROCESS_ATTACH:
260 g_dwTlsErrIndex = TlsAlloc();
262 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
263 return FALSE;
265 URLCacheContainers_CreateDefaults();
267 WININET_hModule = hinstDLL;
269 case DLL_THREAD_ATTACH:
270 break;
272 case DLL_THREAD_DETACH:
273 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
275 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
276 HeapFree(GetProcessHeap(), 0, lpwite);
278 break;
280 case DLL_PROCESS_DETACH:
282 URLCacheContainers_DeleteAll();
284 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
286 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
287 TlsFree(g_dwTlsErrIndex);
289 break;
292 return TRUE;
296 /***********************************************************************
297 * InternetInitializeAutoProxyDll (WININET.@)
299 * Setup the internal proxy
301 * PARAMETERS
302 * dwReserved
304 * RETURNS
305 * FALSE on failure
308 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
310 FIXME("STUB\n");
311 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
312 return FALSE;
315 /***********************************************************************
316 * DetectAutoProxyUrl (WININET.@)
318 * Auto detect the proxy url
320 * RETURNS
321 * FALSE on failure
324 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
325 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
327 FIXME("STUB\n");
328 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
329 return FALSE;
333 /***********************************************************************
334 * INTERNET_ConfigureProxyFromReg
336 * FIXME:
337 * The proxy may be specified in the form 'http=proxy.my.org'
338 * Presumably that means there can be ftp=ftpproxy.my.org too.
340 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
342 HKEY key;
343 DWORD r, keytype, len, enabled;
344 LPCSTR lpszInternetSettings =
345 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
346 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
348 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
349 if ( r != ERROR_SUCCESS )
350 return FALSE;
352 len = sizeof enabled;
353 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
354 (BYTE*)&enabled, &len);
355 if( (r == ERROR_SUCCESS) && enabled )
357 TRACE("Proxy is enabled.\n");
359 /* figure out how much memory the proxy setting takes */
360 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
361 NULL, &len);
362 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
364 LPWSTR szProxy, p;
365 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
367 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
368 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
369 (BYTE*)szProxy, &len);
371 /* find the http proxy, and strip away everything else */
372 p = strstrW( szProxy, szHttp );
373 if( p )
375 p += lstrlenW(szHttp);
376 lstrcpyW( szProxy, p );
378 p = strchrW( szProxy, ' ' );
379 if( p )
380 *p = 0;
382 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
383 lpwai->lpszProxy = szProxy;
385 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
387 else
388 ERR("Couldn't read proxy server settings.\n");
390 else
391 TRACE("Proxy is not enabled.\n");
392 RegCloseKey(key);
394 return enabled;
397 /***********************************************************************
398 * dump_INTERNET_FLAGS
400 * Helper function to TRACE the internet flags.
402 * RETURNS
403 * None
406 static void dump_INTERNET_FLAGS(DWORD dwFlags)
408 #define FE(x) { x, #x }
409 static const wininet_flag_info flag[] = {
410 FE(INTERNET_FLAG_RELOAD),
411 FE(INTERNET_FLAG_RAW_DATA),
412 FE(INTERNET_FLAG_EXISTING_CONNECT),
413 FE(INTERNET_FLAG_ASYNC),
414 FE(INTERNET_FLAG_PASSIVE),
415 FE(INTERNET_FLAG_NO_CACHE_WRITE),
416 FE(INTERNET_FLAG_MAKE_PERSISTENT),
417 FE(INTERNET_FLAG_FROM_CACHE),
418 FE(INTERNET_FLAG_SECURE),
419 FE(INTERNET_FLAG_KEEP_CONNECTION),
420 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
421 FE(INTERNET_FLAG_READ_PREFETCH),
422 FE(INTERNET_FLAG_NO_COOKIES),
423 FE(INTERNET_FLAG_NO_AUTH),
424 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
425 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
426 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
427 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
428 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
429 FE(INTERNET_FLAG_RESYNCHRONIZE),
430 FE(INTERNET_FLAG_HYPERLINK),
431 FE(INTERNET_FLAG_NO_UI),
432 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
433 FE(INTERNET_FLAG_CACHE_ASYNC),
434 FE(INTERNET_FLAG_FORMS_SUBMIT),
435 FE(INTERNET_FLAG_NEED_FILE),
436 FE(INTERNET_FLAG_TRANSFER_ASCII),
437 FE(INTERNET_FLAG_TRANSFER_BINARY)
439 #undef FE
440 int i;
442 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
443 if (flag[i].val & dwFlags) {
444 TRACE(" %s", flag[i].name);
445 dwFlags &= ~flag[i].val;
448 if (dwFlags)
449 TRACE(" Unknown flags (%08x)\n", dwFlags);
450 else
451 TRACE("\n");
454 /***********************************************************************
455 * INTERNET_CloseHandle (internal)
457 * Close internet handle
460 static VOID APPINFO_Destroy(WININETHANDLEHEADER *hdr)
462 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
464 TRACE("%p\n",lpwai);
466 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
467 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
468 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
469 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
470 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
471 HeapFree(GetProcessHeap(), 0, lpwai);
474 static const HANDLEHEADERVtbl APPINFOVtbl = {
475 APPINFO_Destroy,
476 NULL,
477 NULL,
478 NULL,
479 NULL
483 /***********************************************************************
484 * InternetOpenW (WININET.@)
486 * Per-application initialization of wininet
488 * RETURNS
489 * HINTERNET on success
490 * NULL on failure
493 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
494 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
496 LPWININETAPPINFOW lpwai = NULL;
497 HINTERNET handle = NULL;
499 if (TRACE_ON(wininet)) {
500 #define FE(x) { x, #x }
501 static const wininet_flag_info access_type[] = {
502 FE(INTERNET_OPEN_TYPE_PRECONFIG),
503 FE(INTERNET_OPEN_TYPE_DIRECT),
504 FE(INTERNET_OPEN_TYPE_PROXY),
505 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
507 #undef FE
508 DWORD i;
509 const char *access_type_str = "Unknown";
511 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
512 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
513 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
514 if (access_type[i].val == dwAccessType) {
515 access_type_str = access_type[i].name;
516 break;
519 TRACE(" access type : %s\n", access_type_str);
520 TRACE(" flags :");
521 dump_INTERNET_FLAGS(dwFlags);
524 /* Clear any error information */
525 INTERNET_SetLastError(0);
527 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETAPPINFOW));
528 if (NULL == lpwai)
530 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
531 goto lend;
534 lpwai->hdr.htype = WH_HINIT;
535 lpwai->hdr.vtbl = &APPINFOVtbl;
536 lpwai->hdr.dwFlags = dwFlags;
537 lpwai->hdr.dwRefCount = 1;
538 lpwai->dwAccessType = dwAccessType;
539 lpwai->lpszProxyUsername = NULL;
540 lpwai->lpszProxyPassword = NULL;
542 handle = WININET_AllocHandle( &lpwai->hdr );
543 if( !handle )
545 HeapFree( GetProcessHeap(), 0, lpwai );
546 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
547 goto lend;
550 if (NULL != lpszAgent)
552 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
553 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
554 if (lpwai->lpszAgent)
555 lstrcpyW( lpwai->lpszAgent, lpszAgent );
557 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
558 INTERNET_ConfigureProxyFromReg( lpwai );
559 else if (NULL != lpszProxy)
561 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
562 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
563 if (lpwai->lpszProxy)
564 lstrcpyW( lpwai->lpszProxy, lpszProxy );
567 if (NULL != lpszProxyBypass)
569 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
570 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
571 if (lpwai->lpszProxyBypass)
572 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
575 lend:
576 if( lpwai )
577 WININET_Release( &lpwai->hdr );
579 TRACE("returning %p\n", lpwai);
581 return handle;
585 /***********************************************************************
586 * InternetOpenA (WININET.@)
588 * Per-application initialization of wininet
590 * RETURNS
591 * HINTERNET on success
592 * NULL on failure
595 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
596 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
598 HINTERNET rc = NULL;
599 INT len;
600 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
602 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
603 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
605 if( lpszAgent )
607 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
608 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
609 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
612 if( lpszProxy )
614 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
615 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
616 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
619 if( lpszProxyBypass )
621 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
622 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
623 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
626 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
628 HeapFree(GetProcessHeap(), 0, szAgent);
629 HeapFree(GetProcessHeap(), 0, szProxy);
630 HeapFree(GetProcessHeap(), 0, szBypass);
632 return rc;
635 /***********************************************************************
636 * InternetGetLastResponseInfoA (WININET.@)
638 * Return last wininet error description on the calling thread
640 * RETURNS
641 * TRUE on success of writing to buffer
642 * FALSE on failure
645 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
646 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
648 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
650 TRACE("\n");
652 if (lpwite)
654 *lpdwError = lpwite->dwError;
655 if (lpwite->dwError)
657 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
658 *lpdwBufferLength = strlen(lpszBuffer);
660 else
661 *lpdwBufferLength = 0;
663 else
665 *lpdwError = 0;
666 *lpdwBufferLength = 0;
669 return TRUE;
672 /***********************************************************************
673 * InternetGetLastResponseInfoW (WININET.@)
675 * Return last wininet error description on the calling thread
677 * RETURNS
678 * TRUE on success of writing to buffer
679 * FALSE on failure
682 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
683 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
685 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
687 TRACE("\n");
689 if (lpwite)
691 *lpdwError = lpwite->dwError;
692 if (lpwite->dwError)
694 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
695 *lpdwBufferLength = lstrlenW(lpszBuffer);
697 else
698 *lpdwBufferLength = 0;
700 else
702 *lpdwError = 0;
703 *lpdwBufferLength = 0;
706 return TRUE;
709 /***********************************************************************
710 * InternetGetConnectedState (WININET.@)
712 * Return connected state
714 * RETURNS
715 * TRUE if connected
716 * if lpdwStatus is not null, return the status (off line,
717 * modem, lan...) in it.
718 * FALSE if not connected
720 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
722 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
724 if (lpdwStatus) {
725 FIXME("always returning LAN connection.\n");
726 *lpdwStatus = INTERNET_CONNECTION_LAN;
728 return TRUE;
732 /***********************************************************************
733 * InternetGetConnectedStateExW (WININET.@)
735 * Return connected state
737 * PARAMS
739 * lpdwStatus [O] Flags specifying the status of the internet connection.
740 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
741 * dwNameLen [I] Size of the buffer, in characters.
742 * dwReserved [I] Reserved. Must be set to 0.
744 * RETURNS
745 * TRUE if connected
746 * if lpdwStatus is not null, return the status (off line,
747 * modem, lan...) in it.
748 * FALSE if not connected
750 * NOTES
751 * If the system has no available network connections, an empty string is
752 * stored in lpszConnectionName. If there is a LAN connection, a localized
753 * "LAN Connection" string is stored. Presumably, if only a dial-up
754 * connection is available then the name of the dial-up connection is
755 * returned. Why any application, other than the "Internet Settings" CPL,
756 * would want to use this function instead of the simpler InternetGetConnectedStateW
757 * function is beyond me.
759 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
760 DWORD dwNameLen, DWORD dwReserved)
762 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
764 /* Must be zero */
765 if(dwReserved)
766 return FALSE;
768 if (lpdwStatus) {
769 FIXME("always returning LAN connection.\n");
770 *lpdwStatus = INTERNET_CONNECTION_LAN;
772 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
776 /***********************************************************************
777 * InternetGetConnectedStateExA (WININET.@)
779 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
780 DWORD dwNameLen, DWORD dwReserved)
782 LPWSTR lpwszConnectionName = NULL;
783 BOOL rc;
785 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
787 if (lpszConnectionName && dwNameLen > 0)
788 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
790 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
791 dwReserved);
792 if (rc && lpwszConnectionName)
794 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
795 dwNameLen, NULL, NULL);
797 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
800 return rc;
804 /***********************************************************************
805 * InternetConnectW (WININET.@)
807 * Open a ftp, gopher or http session
809 * RETURNS
810 * HINTERNET a session handle on success
811 * NULL on failure
814 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
815 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
816 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
817 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
819 LPWININETAPPINFOW hIC;
820 HINTERNET rc = NULL;
822 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
823 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
824 dwService, dwFlags, dwContext);
826 if (!lpszServerName)
828 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
829 return NULL;
832 /* Clear any error information */
833 INTERNET_SetLastError(0);
834 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
835 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
837 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
838 goto lend;
841 switch (dwService)
843 case INTERNET_SERVICE_FTP:
844 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
845 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
846 break;
848 case INTERNET_SERVICE_HTTP:
849 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
850 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
851 break;
853 case INTERNET_SERVICE_GOPHER:
854 default:
855 break;
857 lend:
858 if( hIC )
859 WININET_Release( &hIC->hdr );
861 TRACE("returning %p\n", rc);
862 return rc;
866 /***********************************************************************
867 * InternetConnectA (WININET.@)
869 * Open a ftp, gopher or http session
871 * RETURNS
872 * HINTERNET a session handle on success
873 * NULL on failure
876 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
877 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
878 LPCSTR lpszUserName, LPCSTR lpszPassword,
879 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
881 HINTERNET rc = NULL;
882 INT len = 0;
883 LPWSTR szServerName = NULL;
884 LPWSTR szUserName = NULL;
885 LPWSTR szPassword = NULL;
887 if (lpszServerName)
889 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
890 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
891 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
893 if (lpszUserName)
895 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
896 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
897 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
899 if (lpszPassword)
901 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
902 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
903 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
907 rc = InternetConnectW(hInternet, szServerName, nServerPort,
908 szUserName, szPassword, dwService, dwFlags, dwContext);
910 HeapFree(GetProcessHeap(), 0, szServerName);
911 HeapFree(GetProcessHeap(), 0, szUserName);
912 HeapFree(GetProcessHeap(), 0, szPassword);
913 return rc;
917 /***********************************************************************
918 * InternetFindNextFileA (WININET.@)
920 * Continues a file search from a previous call to FindFirstFile
922 * RETURNS
923 * TRUE on success
924 * FALSE on failure
927 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
929 BOOL ret;
930 WIN32_FIND_DATAW fd;
932 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
933 if(lpvFindData)
934 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
935 return ret;
938 /***********************************************************************
939 * InternetFindNextFileW (WININET.@)
941 * Continues a file search from a previous call to FindFirstFile
943 * RETURNS
944 * TRUE on success
945 * FALSE on failure
948 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
950 WININETHANDLEHEADER *hdr;
951 DWORD res;
953 TRACE("\n");
955 hdr = WININET_GetObject(hFind);
956 if(!hdr) {
957 WARN("Invalid handle\n");
958 SetLastError(ERROR_INVALID_HANDLE);
959 return FALSE;
962 if(hdr->vtbl->FindNextFileW) {
963 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
964 }else {
965 WARN("Handle doesn't support NextFile\n");
966 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
969 WININET_Release(hdr);
971 if(res != ERROR_SUCCESS)
972 SetLastError(res);
973 return res == ERROR_SUCCESS;
976 /***********************************************************************
977 * InternetCloseHandle (WININET.@)
979 * Generic close handle function
981 * RETURNS
982 * TRUE on success
983 * FALSE on failure
986 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
988 LPWININETHANDLEHEADER lpwh;
990 TRACE("%p\n",hInternet);
992 lpwh = WININET_GetObject( hInternet );
993 if (NULL == lpwh)
995 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
996 return FALSE;
999 WININET_Release( lpwh );
1000 WININET_FreeHandle( hInternet );
1002 return TRUE;
1006 /***********************************************************************
1007 * ConvertUrlComponentValue (Internal)
1009 * Helper function for InternetCrackUrlW
1012 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1013 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1014 LPCSTR lpszStart, LPCWSTR lpwszStart)
1016 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1017 if (*dwComponentLen != 0)
1019 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1020 if (*lppszComponent == NULL)
1022 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1023 if (lpwszComponent)
1024 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1025 else
1026 *lppszComponent = NULL;
1027 *dwComponentLen = nASCIILength;
1029 else
1031 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1032 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1033 (*lppszComponent)[ncpylen]=0;
1034 *dwComponentLen = ncpylen;
1040 /***********************************************************************
1041 * InternetCrackUrlA (WININET.@)
1043 * See InternetCrackUrlW.
1045 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1046 LPURL_COMPONENTSA lpUrlComponents)
1048 DWORD nLength;
1049 URL_COMPONENTSW UCW;
1050 WCHAR* lpwszUrl;
1052 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1054 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1055 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1057 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1058 return FALSE;
1061 if(dwUrlLength<=0)
1062 dwUrlLength=-1;
1063 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1065 /* if dwUrlLength=-1 then nLength includes null but length to
1066 InternetCrackUrlW should not include it */
1067 if (dwUrlLength == -1) nLength--;
1069 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1070 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1072 memset(&UCW,0,sizeof(UCW));
1073 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1074 if(lpUrlComponents->dwHostNameLength!=0)
1075 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1076 if(lpUrlComponents->dwUserNameLength!=0)
1077 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1078 if(lpUrlComponents->dwPasswordLength!=0)
1079 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1080 if(lpUrlComponents->dwUrlPathLength!=0)
1081 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1082 if(lpUrlComponents->dwSchemeLength!=0)
1083 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1084 if(lpUrlComponents->dwExtraInfoLength!=0)
1085 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1086 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1088 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1089 return FALSE;
1092 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1093 UCW.lpszHostName, UCW.dwHostNameLength,
1094 lpszUrl, lpwszUrl);
1095 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1096 UCW.lpszUserName, UCW.dwUserNameLength,
1097 lpszUrl, lpwszUrl);
1098 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1099 UCW.lpszPassword, UCW.dwPasswordLength,
1100 lpszUrl, lpwszUrl);
1101 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1102 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1103 lpszUrl, lpwszUrl);
1104 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1105 UCW.lpszScheme, UCW.dwSchemeLength,
1106 lpszUrl, lpwszUrl);
1107 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1108 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1109 lpszUrl, lpwszUrl);
1110 lpUrlComponents->nScheme=UCW.nScheme;
1111 lpUrlComponents->nPort=UCW.nPort;
1112 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1114 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1115 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1116 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1117 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1118 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1120 return TRUE;
1123 static const WCHAR url_schemes[][7] =
1125 {'f','t','p',0},
1126 {'g','o','p','h','e','r',0},
1127 {'h','t','t','p',0},
1128 {'h','t','t','p','s',0},
1129 {'f','i','l','e',0},
1130 {'n','e','w','s',0},
1131 {'m','a','i','l','t','o',0},
1132 {'r','e','s',0},
1135 /***********************************************************************
1136 * GetInternetSchemeW (internal)
1138 * Get scheme of url
1140 * RETURNS
1141 * scheme on success
1142 * INTERNET_SCHEME_UNKNOWN on failure
1145 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1147 int i;
1149 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1151 if(lpszScheme==NULL)
1152 return INTERNET_SCHEME_UNKNOWN;
1154 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1155 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1156 return INTERNET_SCHEME_FIRST + i;
1158 return INTERNET_SCHEME_UNKNOWN;
1161 /***********************************************************************
1162 * SetUrlComponentValueW (Internal)
1164 * Helper function for InternetCrackUrlW
1166 * PARAMS
1167 * lppszComponent [O] Holds the returned string
1168 * dwComponentLen [I] Holds the size of lppszComponent
1169 * [O] Holds the length of the string in lppszComponent without '\0'
1170 * lpszStart [I] Holds the string to copy from
1171 * len [I] Holds the length of lpszStart without '\0'
1173 * RETURNS
1174 * TRUE on success
1175 * FALSE on failure
1178 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1180 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1182 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1183 return FALSE;
1185 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1187 if (*lppszComponent == NULL)
1189 *lppszComponent = (LPWSTR)lpszStart;
1190 *dwComponentLen = len;
1192 else
1194 DWORD ncpylen = min((*dwComponentLen)-1, len);
1195 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1196 (*lppszComponent)[ncpylen] = '\0';
1197 *dwComponentLen = ncpylen;
1201 return TRUE;
1204 /***********************************************************************
1205 * InternetCrackUrlW (WININET.@)
1207 * Break up URL into its components
1209 * RETURNS
1210 * TRUE on success
1211 * FALSE on failure
1213 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1214 LPURL_COMPONENTSW lpUC)
1217 * RFC 1808
1218 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1221 LPCWSTR lpszParam = NULL;
1222 BOOL bIsAbsolute = FALSE;
1223 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1224 LPCWSTR lpszcp = NULL;
1225 LPWSTR lpszUrl_decode = NULL;
1226 DWORD dwUrlLength = dwUrlLength_orig;
1227 const WCHAR lpszSeparators[3]={';','?',0};
1228 const WCHAR lpszSlash[2]={'/',0};
1230 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1232 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1234 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1235 return FALSE;
1237 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1239 if (dwFlags & ICU_DECODE)
1241 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1242 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1244 lpszUrl = lpszUrl_decode;
1247 lpszap = lpszUrl;
1249 /* Determine if the URI is absolute. */
1250 while (*lpszap != '\0')
1252 if (isalnumW(*lpszap))
1254 lpszap++;
1255 continue;
1257 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1259 bIsAbsolute = TRUE;
1260 lpszcp = lpszap;
1262 else
1264 lpszcp = lpszUrl; /* Relative url */
1267 break;
1270 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1271 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1273 /* Parse <params> */
1274 lpszParam = strpbrkW(lpszap, lpszSeparators);
1275 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1276 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1278 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1280 LPCWSTR lpszNetLoc;
1282 /* Get scheme first. */
1283 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1284 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1285 lpszUrl, lpszcp - lpszUrl);
1287 /* Eat ':' in protocol. */
1288 lpszcp++;
1290 /* double slash indicates the net_loc portion is present */
1291 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1293 lpszcp += 2;
1295 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1296 if (lpszParam)
1298 if (lpszNetLoc)
1299 lpszNetLoc = min(lpszNetLoc, lpszParam);
1300 else
1301 lpszNetLoc = lpszParam;
1303 else if (!lpszNetLoc)
1304 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1306 /* Parse net-loc */
1307 if (lpszNetLoc)
1309 LPCWSTR lpszHost;
1310 LPCWSTR lpszPort;
1312 /* [<user>[<:password>]@]<host>[:<port>] */
1313 /* First find the user and password if they exist */
1315 lpszHost = strchrW(lpszcp, '@');
1316 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1318 /* username and password not specified. */
1319 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1320 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1322 else /* Parse out username and password */
1324 LPCWSTR lpszUser = lpszcp;
1325 LPCWSTR lpszPasswd = lpszHost;
1327 while (lpszcp < lpszHost)
1329 if (*lpszcp == ':')
1330 lpszPasswd = lpszcp;
1332 lpszcp++;
1335 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1336 lpszUser, lpszPasswd - lpszUser);
1338 if (lpszPasswd != lpszHost)
1339 lpszPasswd++;
1340 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1341 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1342 lpszHost - lpszPasswd);
1344 lpszcp++; /* Advance to beginning of host */
1347 /* Parse <host><:port> */
1349 lpszHost = lpszcp;
1350 lpszPort = lpszNetLoc;
1352 /* special case for res:// URLs: there is no port here, so the host is the
1353 entire string up to the first '/' */
1354 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1356 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1357 lpszHost, lpszPort - lpszHost);
1358 lpszcp=lpszNetLoc;
1360 else
1362 while (lpszcp < lpszNetLoc)
1364 if (*lpszcp == ':')
1365 lpszPort = lpszcp;
1367 lpszcp++;
1370 /* If the scheme is "file" and the host is just one letter, it's not a host */
1371 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1373 lpszcp=lpszHost;
1374 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1375 NULL, 0);
1377 else
1379 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1380 lpszHost, lpszPort - lpszHost);
1381 if (lpszPort != lpszNetLoc)
1382 lpUC->nPort = atoiW(++lpszPort);
1383 else switch (lpUC->nScheme)
1385 case INTERNET_SCHEME_HTTP:
1386 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1387 break;
1388 case INTERNET_SCHEME_HTTPS:
1389 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1390 break;
1391 case INTERNET_SCHEME_FTP:
1392 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1393 break;
1394 case INTERNET_SCHEME_GOPHER:
1395 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1396 break;
1397 default:
1398 break;
1404 else
1406 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1407 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1408 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1411 else
1413 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1414 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1415 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1416 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1419 /* Here lpszcp points to:
1421 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1422 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1424 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1426 INT len;
1428 /* Only truncate the parameter list if it's already been saved
1429 * in lpUC->lpszExtraInfo.
1431 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1432 len = lpszParam - lpszcp;
1433 else
1435 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1436 * newlines if necessary.
1438 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1439 if (lpsznewline != NULL)
1440 len = lpsznewline - lpszcp;
1441 else
1442 len = dwUrlLength-(lpszcp-lpszUrl);
1444 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1445 lpszcp, len);
1447 else
1449 lpUC->dwUrlPathLength = 0;
1452 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1453 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1454 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1455 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1456 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1458 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1459 return TRUE;
1462 /***********************************************************************
1463 * InternetAttemptConnect (WININET.@)
1465 * Attempt to make a connection to the internet
1467 * RETURNS
1468 * ERROR_SUCCESS on success
1469 * Error value on failure
1472 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1474 FIXME("Stub\n");
1475 return ERROR_SUCCESS;
1479 /***********************************************************************
1480 * InternetCanonicalizeUrlA (WININET.@)
1482 * Escape unsafe characters and spaces
1484 * RETURNS
1485 * TRUE on success
1486 * FALSE on failure
1489 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1490 LPDWORD lpdwBufferLength, DWORD dwFlags)
1492 HRESULT hr;
1493 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1495 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1496 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1498 if(dwFlags & ICU_DECODE)
1500 dwURLFlags |= URL_UNESCAPE;
1501 dwFlags &= ~ICU_DECODE;
1504 if(dwFlags & ICU_ESCAPE)
1506 dwURLFlags |= URL_UNESCAPE;
1507 dwFlags &= ~ICU_ESCAPE;
1510 if(dwFlags & ICU_BROWSER_MODE)
1512 dwURLFlags |= URL_BROWSER_MODE;
1513 dwFlags &= ~ICU_BROWSER_MODE;
1516 if(dwFlags & ICU_NO_ENCODE)
1518 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1519 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1520 dwFlags &= ~ICU_NO_ENCODE;
1523 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1525 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1526 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1527 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1529 return (hr == S_OK) ? TRUE : FALSE;
1532 /***********************************************************************
1533 * InternetCanonicalizeUrlW (WININET.@)
1535 * Escape unsafe characters and spaces
1537 * RETURNS
1538 * TRUE on success
1539 * FALSE on failure
1542 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1543 LPDWORD lpdwBufferLength, DWORD dwFlags)
1545 HRESULT hr;
1546 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1548 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1549 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1551 if(dwFlags & ICU_DECODE)
1553 dwURLFlags |= URL_UNESCAPE;
1554 dwFlags &= ~ICU_DECODE;
1557 if(dwFlags & ICU_ESCAPE)
1559 dwURLFlags |= URL_UNESCAPE;
1560 dwFlags &= ~ICU_ESCAPE;
1563 if(dwFlags & ICU_BROWSER_MODE)
1565 dwURLFlags |= URL_BROWSER_MODE;
1566 dwFlags &= ~ICU_BROWSER_MODE;
1569 if(dwFlags & ICU_NO_ENCODE)
1571 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1572 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1573 dwFlags &= ~ICU_NO_ENCODE;
1576 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1578 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1579 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1580 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1582 return (hr == S_OK) ? TRUE : FALSE;
1585 /* #################################################### */
1587 static INTERNET_STATUS_CALLBACK set_status_callback(
1588 LPWININETHANDLEHEADER lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1590 INTERNET_STATUS_CALLBACK ret;
1592 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1593 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1595 ret = lpwh->lpfnStatusCB;
1596 lpwh->lpfnStatusCB = callback;
1598 return ret;
1601 /***********************************************************************
1602 * InternetSetStatusCallbackA (WININET.@)
1604 * Sets up a callback function which is called as progress is made
1605 * during an operation.
1607 * RETURNS
1608 * Previous callback or NULL on success
1609 * INTERNET_INVALID_STATUS_CALLBACK on failure
1612 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1613 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1615 INTERNET_STATUS_CALLBACK retVal;
1616 LPWININETHANDLEHEADER lpwh;
1618 TRACE("0x%08x\n", (ULONG)hInternet);
1620 if (!(lpwh = WININET_GetObject(hInternet)))
1621 return INTERNET_INVALID_STATUS_CALLBACK;
1623 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1625 WININET_Release( lpwh );
1626 return retVal;
1629 /***********************************************************************
1630 * InternetSetStatusCallbackW (WININET.@)
1632 * Sets up a callback function which is called as progress is made
1633 * during an operation.
1635 * RETURNS
1636 * Previous callback or NULL on success
1637 * INTERNET_INVALID_STATUS_CALLBACK on failure
1640 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1641 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1643 INTERNET_STATUS_CALLBACK retVal;
1644 LPWININETHANDLEHEADER lpwh;
1646 TRACE("0x%08x\n", (ULONG)hInternet);
1648 if (!(lpwh = WININET_GetObject(hInternet)))
1649 return INTERNET_INVALID_STATUS_CALLBACK;
1651 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
1653 WININET_Release( lpwh );
1654 return retVal;
1657 /***********************************************************************
1658 * InternetSetFilePointer (WININET.@)
1660 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1661 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
1663 FIXME("stub\n");
1664 return FALSE;
1667 /***********************************************************************
1668 * InternetWriteFile (WININET.@)
1670 * Write data to an open internet file
1672 * RETURNS
1673 * TRUE on success
1674 * FALSE on failure
1677 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
1678 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1680 LPWININETHANDLEHEADER lpwh;
1681 BOOL retval = FALSE;
1683 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1685 lpwh = WININET_GetObject( hFile );
1687 if(lpwh && lpwh->vtbl->WriteFile) {
1688 retval = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1689 }else {
1690 WARN("Invalid handle\n");
1691 SetLastError(ERROR_INVALID_HANDLE);
1692 retval = FALSE;
1695 WININET_Release( lpwh );
1697 return retval;
1701 BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1702 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1703 BOOL bWait, BOOL bSendCompletionStatus)
1705 BOOL retval = FALSE;
1706 int nSocket = -1;
1707 int bytes_read;
1708 LPWININETHTTPREQW lpwhr;
1710 /* FIXME: this should use NETCON functions! */
1711 switch (lpwh->htype)
1713 case WH_HHTTPREQ:
1714 lpwhr = (LPWININETHTTPREQW)lpwh;
1716 if (!NETCON_recv(&lpwhr->netConnection, lpBuffer,
1717 min(dwNumOfBytesToRead, lpwhr->dwContentLength - lpwhr->dwContentRead),
1718 bWait ? MSG_WAITALL : 0, &bytes_read))
1721 if (((lpwhr->dwContentLength != -1) &&
1722 (lpwhr->dwContentRead != lpwhr->dwContentLength)))
1723 ERR("not all data received %d/%d\n", lpwhr->dwContentRead,
1724 lpwhr->dwContentLength);
1726 /* always returns TRUE, even if the network layer returns an
1727 * error */
1728 *pdwNumOfBytesRead = 0;
1729 HTTP_FinishedReading(lpwhr);
1730 retval = TRUE;
1732 else
1734 lpwhr->dwContentRead += bytes_read;
1735 *pdwNumOfBytesRead = bytes_read;
1737 if(lpwhr->lpszCacheFile) {
1738 BOOL res;
1740 res = WriteFile(lpwhr->hCacheFile, lpBuffer, bytes_read, NULL, NULL);
1741 if(!res)
1742 WARN("WriteFile failed: %u\n", GetLastError());
1745 if (!bytes_read && (lpwhr->dwContentRead == lpwhr->dwContentLength))
1746 retval = HTTP_FinishedReading(lpwhr);
1747 else
1748 retval = TRUE;
1750 break;
1752 case WH_HFILE:
1753 /* FIXME: FTP should use NETCON_ stuff */
1754 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1755 if (nSocket != -1)
1757 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1758 retval = (res >= 0);
1759 *pdwNumOfBytesRead = retval ? res : 0;
1761 break;
1763 default:
1764 break;
1767 if (bSendCompletionStatus)
1769 INTERNET_ASYNC_RESULT iar;
1771 iar.dwResult = retval;
1772 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1773 INTERNET_GetLastError();
1775 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1776 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1777 sizeof(INTERNET_ASYNC_RESULT));
1779 return retval;
1782 /***********************************************************************
1783 * InternetReadFile (WININET.@)
1785 * Read data from an open internet file
1787 * RETURNS
1788 * TRUE on success
1789 * FALSE on failure
1792 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1793 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1795 LPWININETHANDLEHEADER lpwh;
1796 BOOL retval;
1798 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1800 lpwh = WININET_GetObject( hFile );
1801 if (!lpwh)
1803 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1804 return FALSE;
1807 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1808 WININET_Release( lpwh );
1810 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1811 return retval;
1814 /***********************************************************************
1815 * InternetReadFileExA (WININET.@)
1817 * Read data from an open internet file
1819 * PARAMS
1820 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1821 * lpBuffersOut [I/O] Buffer.
1822 * dwFlags [I] Flags. See notes.
1823 * dwContext [I] Context for callbacks.
1825 * RETURNS
1826 * TRUE on success
1827 * FALSE on failure
1829 * NOTES
1830 * The parameter dwFlags include zero or more of the following flags:
1831 *|IRF_ASYNC - Makes the call asynchronous.
1832 *|IRF_SYNC - Makes the call synchronous.
1833 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1834 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1836 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1838 * SEE
1839 * InternetOpenUrlA(), HttpOpenRequestA()
1841 void AsyncInternetReadFileExProc(WORKREQUEST *workRequest)
1843 struct WORKREQ_INTERNETREADFILEEXA const *req = &workRequest->u.InternetReadFileExA;
1845 TRACE("INTERNETREADFILEEXA %p\n", workRequest->hdr);
1847 INTERNET_ReadFile(workRequest->hdr, req->lpBuffersOut->lpvBuffer,
1848 req->lpBuffersOut->dwBufferLength,
1849 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
1852 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1853 DWORD dwFlags, DWORD_PTR dwContext)
1855 BOOL retval = FALSE;
1856 LPWININETHANDLEHEADER lpwh;
1858 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1860 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1861 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1863 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1865 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1866 return FALSE;
1869 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1870 if (!lpwh)
1872 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1873 return FALSE;
1876 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1877 INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
1879 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1880 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1881 if (dwFlags & IRF_ASYNC)
1883 DWORD dwDataAvailable = 0;
1885 if (lpwh->htype == WH_HHTTPREQ)
1886 NETCON_query_data_available(&((LPWININETHTTPREQW)lpwh)->netConnection,
1887 &dwDataAvailable);
1889 if (!dwDataAvailable)
1891 WORKREQUEST workRequest;
1892 struct WORKREQ_INTERNETREADFILEEXA *req;
1894 workRequest.asyncproc = AsyncInternetReadFileExProc;
1895 workRequest.hdr = WININET_AddRef( lpwh );
1896 req = &workRequest.u.InternetReadFileExA;
1897 req->lpBuffersOut = lpBuffersOut;
1899 if (!INTERNET_AsyncCall(&workRequest))
1900 WININET_Release( lpwh );
1901 else
1902 INTERNET_SetLastError(ERROR_IO_PENDING);
1903 goto end;
1907 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1908 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1909 !(dwFlags & IRF_NO_WAIT), FALSE);
1911 if (retval)
1913 DWORD dwBytesReceived = lpBuffersOut->dwBufferLength;
1914 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1915 INTERNET_STATUS_RESPONSE_RECEIVED, &dwBytesReceived,
1916 sizeof(dwBytesReceived));
1919 end:
1920 WININET_Release( lpwh );
1922 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1923 return retval;
1926 /***********************************************************************
1927 * InternetReadFileExW (WININET.@)
1929 * Read data from an open internet file.
1931 * PARAMS
1932 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1933 * lpBuffersOut [I/O] Buffer.
1934 * dwFlags [I] Flags.
1935 * dwContext [I] Context for callbacks.
1937 * RETURNS
1938 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1940 * NOTES
1941 * Not implemented in Wine or native either (as of IE6 SP2).
1944 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1945 DWORD dwFlags, DWORD_PTR dwContext)
1947 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1949 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1950 return FALSE;
1953 /***********************************************************************
1954 * INET_QueryOptionHelper (internal)
1956 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1957 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1959 LPWININETHANDLEHEADER lpwhh;
1960 BOOL bSuccess = FALSE;
1962 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1964 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1966 switch (dwOption)
1968 case INTERNET_OPTION_HANDLE_TYPE:
1970 ULONG type;
1972 if (!lpwhh)
1974 WARN("Invalid hInternet handle\n");
1975 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1976 return FALSE;
1979 type = lpwhh->htype;
1981 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type);
1983 if (*lpdwBufferLength < sizeof(ULONG))
1984 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1985 else
1987 memcpy(lpBuffer, &type, sizeof(ULONG));
1988 bSuccess = TRUE;
1990 *lpdwBufferLength = sizeof(ULONG);
1991 break;
1994 case INTERNET_OPTION_REQUEST_FLAGS:
1996 ULONG flags = 4;
1997 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
1998 if (*lpdwBufferLength < sizeof(ULONG))
1999 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2000 else
2002 memcpy(lpBuffer, &flags, sizeof(ULONG));
2003 bSuccess = TRUE;
2005 *lpdwBufferLength = sizeof(ULONG);
2006 break;
2009 case INTERNET_OPTION_URL:
2011 TRACE("INTERNET_OPTION_URL\n");
2013 if (!lpwhh)
2015 WARN("Invalid hInternet handle\n");
2016 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2017 return FALSE;
2019 if (lpwhh->htype == WH_HHTTPREQ)
2021 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2022 WCHAR url[1023];
2023 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2024 static const WCHAR szHost[] = {'H','o','s','t',0};
2025 DWORD sizeRequired;
2026 LPHTTPHEADERW Host;
2028 Host = HTTP_GetHeader(lpreq,szHost);
2029 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2030 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2031 if(!bIsUnicode)
2033 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2034 lpBuffer,*lpdwBufferLength,NULL,NULL);
2035 if (sizeRequired > *lpdwBufferLength)
2036 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2037 else
2038 bSuccess = TRUE;
2039 *lpdwBufferLength = sizeRequired;
2041 else
2043 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2044 if (*lpdwBufferLength < sizeRequired)
2045 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2046 else
2048 strcpyW(lpBuffer, url);
2049 bSuccess = TRUE;
2051 *lpdwBufferLength = sizeRequired;
2054 break;
2057 case INTERNET_OPTION_DATAFILE_NAME:
2059 TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
2060 if (!lpwhh)
2062 WARN("Invalid hInternet handle\n");
2063 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2064 return FALSE;
2066 if (lpwhh->htype == WH_HHTTPREQ)
2068 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2069 DWORD size;
2071 if(!lpreq->lpszCacheFile) {
2072 *lpdwBufferLength = 0;
2073 INTERNET_SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
2075 else if(bIsUnicode)
2077 size = (lstrlenW(lpreq->lpszCacheFile)+1) * sizeof(WCHAR);
2078 if (*lpdwBufferLength < size)
2079 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2080 else
2082 memcpy(lpBuffer, lpreq->lpszCacheFile, size);
2083 bSuccess = TRUE;
2085 *lpdwBufferLength = size;
2087 else
2089 size = WideCharToMultiByte(CP_ACP, 0, lpreq->lpszCacheFile, -1, NULL, 0, NULL, NULL);
2090 if (size > *lpdwBufferLength) {
2091 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2092 }else {
2093 *lpdwBufferLength = WideCharToMultiByte(CP_ACP, 0, lpreq->lpszCacheFile,
2094 -1, lpBuffer, *lpdwBufferLength, NULL, NULL);
2095 bSuccess = TRUE;
2099 break;
2102 case INTERNET_OPTION_HTTP_VERSION:
2104 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2105 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2106 else
2109 * Presently hardcoded to 1.1
2111 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2112 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2113 bSuccess = TRUE;
2115 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2116 break;
2118 case INTERNET_OPTION_CONNECTED_STATE:
2120 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2121 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2123 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2124 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2125 else
2127 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2128 bSuccess = TRUE;
2130 *lpdwBufferLength = sizeof(*pdwConnectedState);
2131 break;
2133 case INTERNET_OPTION_PROXY:
2135 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2136 WININETAPPINFOW wai;
2138 if (lpwai == NULL)
2140 TRACE("Getting global proxy info\n");
2141 memset(&wai, 0, sizeof(WININETAPPINFOW));
2142 INTERNET_ConfigureProxyFromReg( &wai );
2143 lpwai = &wai;
2146 if (bIsUnicode)
2148 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2149 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2151 if (lpwai->lpszProxy)
2152 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2153 sizeof(WCHAR);
2154 if (lpwai->lpszProxyBypass)
2155 proxyBypassBytesRequired =
2156 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2157 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2158 proxyBytesRequired + proxyBypassBytesRequired)
2159 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2160 else
2162 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
2163 sizeof(INTERNET_PROXY_INFOW));
2164 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
2165 sizeof(INTERNET_PROXY_INFOW) +
2166 proxyBytesRequired);
2168 pPI->dwAccessType = lpwai->dwAccessType;
2169 pPI->lpszProxy = NULL;
2170 pPI->lpszProxyBypass = NULL;
2171 if (lpwai->lpszProxy)
2173 lstrcpyW(proxy, lpwai->lpszProxy);
2174 pPI->lpszProxy = proxy;
2177 if (lpwai->lpszProxyBypass)
2179 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
2180 pPI->lpszProxyBypass = proxy_bypass;
2182 bSuccess = TRUE;
2184 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2185 proxyBytesRequired + proxyBypassBytesRequired;
2187 else
2189 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2190 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2192 if (lpwai->lpszProxy)
2193 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2194 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2195 if (lpwai->lpszProxyBypass)
2196 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2197 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2198 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2199 proxyBytesRequired + proxyBypassBytesRequired)
2200 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2201 else
2203 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2204 sizeof(INTERNET_PROXY_INFOA));
2205 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2206 sizeof(INTERNET_PROXY_INFOA) +
2207 proxyBytesRequired);
2209 pPI->dwAccessType = lpwai->dwAccessType;
2210 pPI->lpszProxy = NULL;
2211 pPI->lpszProxyBypass = NULL;
2212 if (lpwai->lpszProxy)
2214 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2215 proxy, proxyBytesRequired, NULL, NULL);
2216 pPI->lpszProxy = proxy;
2219 if (lpwai->lpszProxyBypass)
2221 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2222 -1, proxy_bypass, proxyBypassBytesRequired,
2223 NULL, NULL);
2224 pPI->lpszProxyBypass = proxy_bypass;
2226 bSuccess = TRUE;
2228 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2229 proxyBytesRequired + proxyBypassBytesRequired;
2231 break;
2233 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2235 ULONG conn = 2;
2236 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2237 if (*lpdwBufferLength < sizeof(ULONG))
2238 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2239 else
2241 memcpy(lpBuffer, &conn, sizeof(ULONG));
2242 bSuccess = TRUE;
2244 *lpdwBufferLength = sizeof(ULONG);
2245 break;
2247 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2249 ULONG conn = 4;
2250 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2251 if (*lpdwBufferLength < sizeof(ULONG))
2252 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2253 else
2255 memcpy(lpBuffer, &conn, sizeof(ULONG));
2256 bSuccess = TRUE;
2258 *lpdwBufferLength = sizeof(ULONG);
2259 break;
2261 case INTERNET_OPTION_SECURITY_FLAGS:
2262 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2263 bSuccess = TRUE;
2264 break;
2266 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2267 if (!lpwhh)
2269 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2270 return FALSE;
2272 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2274 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2275 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2277 else if (lpwhh->htype == WH_HHTTPREQ)
2279 LPWININETHTTPREQW lpwhr;
2280 PCCERT_CONTEXT context;
2282 lpwhr = (LPWININETHTTPREQW)lpwhh;
2283 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2284 if (context)
2286 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2287 DWORD strLen;
2289 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2290 info->ftExpiry = context->pCertInfo->NotAfter;
2291 info->ftStart = context->pCertInfo->NotBefore;
2292 if (bIsUnicode)
2294 strLen = CertNameToStrW(context->dwCertEncodingType,
2295 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2296 NULL, 0);
2297 info->lpszSubjectInfo = LocalAlloc(0,
2298 strLen * sizeof(WCHAR));
2299 if (info->lpszSubjectInfo)
2300 CertNameToStrW(context->dwCertEncodingType,
2301 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2302 info->lpszSubjectInfo, strLen);
2303 strLen = CertNameToStrW(context->dwCertEncodingType,
2304 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2305 NULL, 0);
2306 info->lpszIssuerInfo = LocalAlloc(0,
2307 strLen * sizeof(WCHAR));
2308 if (info->lpszIssuerInfo)
2309 CertNameToStrW(context->dwCertEncodingType,
2310 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2311 info->lpszIssuerInfo, strLen);
2313 else
2315 LPINTERNET_CERTIFICATE_INFOA infoA =
2316 (LPINTERNET_CERTIFICATE_INFOA)info;
2318 strLen = CertNameToStrA(context->dwCertEncodingType,
2319 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2320 NULL, 0);
2321 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2322 if (infoA->lpszSubjectInfo)
2323 CertNameToStrA(context->dwCertEncodingType,
2324 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2325 infoA->lpszSubjectInfo, strLen);
2326 strLen = CertNameToStrA(context->dwCertEncodingType,
2327 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2328 NULL, 0);
2329 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2330 if (infoA->lpszIssuerInfo)
2331 CertNameToStrA(context->dwCertEncodingType,
2332 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2333 infoA->lpszIssuerInfo, strLen);
2336 * Contrary to MSDN, these do not appear to be set.
2337 * lpszProtocolName
2338 * lpszSignatureAlgName
2339 * lpszEncryptionAlgName
2340 * dwKeySize
2342 CertFreeCertificateContext(context);
2343 bSuccess = TRUE;
2346 break;
2347 case INTERNET_OPTION_VERSION:
2349 TRACE("INTERNET_OPTION_VERSION\n");
2350 if (*lpdwBufferLength < sizeof(INTERNET_VERSION_INFO))
2351 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2352 else
2354 static const INTERNET_VERSION_INFO info = { 1, 2 };
2355 memcpy(lpBuffer, &info, sizeof(info));
2356 *lpdwBufferLength = sizeof(info);
2357 bSuccess = TRUE;
2359 break;
2361 case INTERNET_OPTION_PER_CONNECTION_OPTION:
2362 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2363 if (*lpdwBufferLength < sizeof(INTERNET_PER_CONN_OPTION_LISTW))
2364 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2365 else
2367 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2368 int x;
2369 bSuccess = TRUE;
2370 for (x = 0; x < con->dwOptionCount; ++x)
2372 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + x;
2373 switch (option->dwOption)
2375 case INTERNET_PER_CONN_FLAGS:
2376 option->Value.dwValue = PROXY_TYPE_DIRECT;
2377 break;
2379 case INTERNET_PER_CONN_PROXY_SERVER:
2380 case INTERNET_PER_CONN_PROXY_BYPASS:
2381 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2382 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2383 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2384 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2385 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2386 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2387 FIXME("Unhandled dwOption %d\n", option->dwOption);
2388 option->Value.dwValue = 0;
2389 bSuccess = FALSE;
2390 break;
2392 default:
2393 FIXME("Unknown dwOption %d\n", option->dwOption);
2394 bSuccess = FALSE;
2395 break;
2398 if (!bSuccess)
2399 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2401 break;
2402 default:
2403 FIXME("Stub! %d\n", dwOption);
2404 break;
2406 if (lpwhh)
2407 WININET_Release( lpwhh );
2409 return bSuccess;
2412 /***********************************************************************
2413 * InternetQueryOptionW (WININET.@)
2415 * Queries an options on the specified handle
2417 * RETURNS
2418 * TRUE on success
2419 * FALSE on failure
2422 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2423 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2425 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2428 /***********************************************************************
2429 * InternetQueryOptionA (WININET.@)
2431 * Queries an options on the specified handle
2433 * RETURNS
2434 * TRUE on success
2435 * FALSE on failure
2438 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2439 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2441 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2445 /***********************************************************************
2446 * InternetSetOptionW (WININET.@)
2448 * Sets an options on the specified handle
2450 * RETURNS
2451 * TRUE on success
2452 * FALSE on failure
2455 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2456 LPVOID lpBuffer, DWORD dwBufferLength)
2458 LPWININETHANDLEHEADER lpwhh;
2459 BOOL ret = TRUE;
2461 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2463 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2464 if(lpwhh && lpwhh->vtbl->SetOption) {
2465 DWORD res;
2467 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2468 if(res != ERROR_INTERNET_INVALID_OPTION) {
2469 WININET_Release( lpwhh );
2471 if(res != ERROR_SUCCESS)
2472 SetLastError(res);
2474 return res == ERROR_SUCCESS;
2478 switch (dwOption)
2480 case INTERNET_OPTION_CALLBACK:
2482 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2483 ret = (set_status_callback(lpwhh, callback, TRUE) != INTERNET_INVALID_STATUS_CALLBACK);
2484 break;
2486 case INTERNET_OPTION_HTTP_VERSION:
2488 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2489 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2491 break;
2492 case INTERNET_OPTION_ERROR_MASK:
2494 unsigned long flags=*(unsigned long*)lpBuffer;
2495 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2497 break;
2498 case INTERNET_OPTION_CODEPAGE:
2500 unsigned long codepage=*(unsigned long*)lpBuffer;
2501 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2503 break;
2504 case INTERNET_OPTION_REQUEST_PRIORITY:
2506 unsigned long priority=*(unsigned long*)lpBuffer;
2507 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2509 break;
2510 case INTERNET_OPTION_CONNECT_TIMEOUT:
2512 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2513 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2515 break;
2516 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2518 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2519 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2521 break;
2522 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2524 unsigned long conns=*(unsigned long*)lpBuffer;
2525 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2527 break;
2528 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2530 unsigned long conns=*(unsigned long*)lpBuffer;
2531 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2533 break;
2534 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2535 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2536 break;
2537 case INTERNET_OPTION_END_BROWSER_SESSION:
2538 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2539 break;
2540 case INTERNET_OPTION_CONNECTED_STATE:
2541 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2542 break;
2543 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2544 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2545 break;
2546 case INTERNET_OPTION_SEND_TIMEOUT:
2547 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2548 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2549 break;
2550 case INTERNET_OPTION_CONNECT_RETRIES:
2551 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2552 break;
2553 case INTERNET_OPTION_CONTEXT_VALUE:
2554 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2555 break;
2556 case INTERNET_OPTION_SECURITY_FLAGS:
2557 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2558 break;
2559 default:
2560 FIXME("Option %d STUB\n",dwOption);
2561 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2562 ret = FALSE;
2563 break;
2566 if(lpwhh)
2567 WININET_Release( lpwhh );
2569 return ret;
2573 /***********************************************************************
2574 * InternetSetOptionA (WININET.@)
2576 * Sets an options on the specified handle.
2578 * RETURNS
2579 * TRUE on success
2580 * FALSE on failure
2583 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2584 LPVOID lpBuffer, DWORD dwBufferLength)
2586 LPVOID wbuffer;
2587 DWORD wlen;
2588 BOOL r;
2590 switch( dwOption )
2592 case INTERNET_OPTION_CALLBACK:
2594 LPWININETHANDLEHEADER lpwh;
2595 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2597 if (!(lpwh = WININET_GetObject(hInternet))) return FALSE;
2598 r = (set_status_callback(lpwh, callback, FALSE) != INTERNET_INVALID_STATUS_CALLBACK);
2599 WININET_Release(lpwh);
2600 return r;
2602 case INTERNET_OPTION_PROXY:
2604 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2605 LPINTERNET_PROXY_INFOW piw;
2606 DWORD proxlen, prbylen;
2607 LPWSTR prox, prby;
2609 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2610 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2611 wlen = sizeof(*piw) + proxlen + prbylen;
2612 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2613 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2614 piw->dwAccessType = pi->dwAccessType;
2615 prox = (LPWSTR) &piw[1];
2616 prby = &prox[proxlen+1];
2617 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2618 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2619 piw->lpszProxy = prox;
2620 piw->lpszProxyBypass = prby;
2622 break;
2623 case INTERNET_OPTION_USER_AGENT:
2624 case INTERNET_OPTION_USERNAME:
2625 case INTERNET_OPTION_PASSWORD:
2626 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2627 NULL, 0 );
2628 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2629 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2630 wbuffer, wlen );
2631 break;
2632 default:
2633 wbuffer = lpBuffer;
2634 wlen = dwBufferLength;
2637 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2639 if( lpBuffer != wbuffer )
2640 HeapFree( GetProcessHeap(), 0, wbuffer );
2642 return r;
2646 /***********************************************************************
2647 * InternetSetOptionExA (WININET.@)
2649 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2650 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2652 FIXME("Flags %08x ignored\n", dwFlags);
2653 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2656 /***********************************************************************
2657 * InternetSetOptionExW (WININET.@)
2659 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2660 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2662 FIXME("Flags %08x ignored\n", dwFlags);
2663 if( dwFlags & ~ISO_VALID_FLAGS )
2665 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2666 return FALSE;
2668 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2671 static const WCHAR WININET_wkday[7][4] =
2672 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2673 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2674 static const WCHAR WININET_month[12][4] =
2675 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2676 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2677 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2679 /***********************************************************************
2680 * InternetTimeFromSystemTimeA (WININET.@)
2682 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2684 BOOL ret;
2685 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2687 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2689 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2690 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2692 return ret;
2695 /***********************************************************************
2696 * InternetTimeFromSystemTimeW (WININET.@)
2698 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2700 static const WCHAR date[] =
2701 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2702 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2704 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2706 if (!time || !string) return FALSE;
2708 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2709 return FALSE;
2711 sprintfW( string, date,
2712 WININET_wkday[time->wDayOfWeek],
2713 time->wDay,
2714 WININET_month[time->wMonth - 1],
2715 time->wYear,
2716 time->wHour,
2717 time->wMinute,
2718 time->wSecond );
2720 return TRUE;
2723 /***********************************************************************
2724 * InternetTimeToSystemTimeA (WININET.@)
2726 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2728 BOOL ret = FALSE;
2729 WCHAR *stringW;
2730 int len;
2732 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2734 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2735 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2737 if (stringW)
2739 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2740 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2741 HeapFree( GetProcessHeap(), 0, stringW );
2743 return ret;
2746 /***********************************************************************
2747 * InternetTimeToSystemTimeW (WININET.@)
2749 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2751 unsigned int i;
2752 const WCHAR *s = string;
2753 WCHAR *end;
2755 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2757 if (!string || !time) return FALSE;
2759 /* Windows does this too */
2760 GetSystemTime( time );
2762 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2763 * a SYSTEMTIME structure.
2766 while (*s && !isalphaW( *s )) s++;
2767 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2768 time->wDayOfWeek = 7;
2770 for (i = 0; i < 7; i++)
2772 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2773 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2774 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2776 time->wDayOfWeek = i;
2777 break;
2781 if (time->wDayOfWeek > 6) return TRUE;
2782 while (*s && !isdigitW( *s )) s++;
2783 time->wDay = strtolW( s, &end, 10 );
2784 s = end;
2786 while (*s && !isalphaW( *s )) s++;
2787 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2788 time->wMonth = 0;
2790 for (i = 0; i < 12; i++)
2792 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2793 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2794 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2796 time->wMonth = i + 1;
2797 break;
2800 if (time->wMonth == 0) return TRUE;
2802 while (*s && !isdigitW( *s )) s++;
2803 if (*s == '\0') return TRUE;
2804 time->wYear = strtolW( s, &end, 10 );
2805 s = end;
2807 while (*s && !isdigitW( *s )) s++;
2808 if (*s == '\0') return TRUE;
2809 time->wHour = strtolW( s, &end, 10 );
2810 s = end;
2812 while (*s && !isdigitW( *s )) s++;
2813 if (*s == '\0') return TRUE;
2814 time->wMinute = strtolW( s, &end, 10 );
2815 s = end;
2817 while (*s && !isdigitW( *s )) s++;
2818 if (*s == '\0') return TRUE;
2819 time->wSecond = strtolW( s, &end, 10 );
2820 s = end;
2822 time->wMilliseconds = 0;
2823 return TRUE;
2826 /***********************************************************************
2827 * InternetCheckConnectionW (WININET.@)
2829 * Pings a requested host to check internet connection
2831 * RETURNS
2832 * TRUE on success and FALSE on failure. If a failure then
2833 * ERROR_NOT_CONNECTED is placed into GetLastError
2836 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2839 * this is a kludge which runs the resident ping program and reads the output.
2841 * Anyone have a better idea?
2844 BOOL rc = FALSE;
2845 static const CHAR ping[] = "ping -c 1 ";
2846 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2847 CHAR *command = NULL;
2848 WCHAR hostW[1024];
2849 DWORD len;
2850 INTERNET_PORT port;
2851 int status = -1;
2853 FIXME("\n");
2856 * Crack or set the Address
2858 if (lpszUrl == NULL)
2861 * According to the doc we are supposed to use the ip for the next
2862 * server in the WnInet internal server database. I have
2863 * no idea what that is or how to get it.
2865 * So someone needs to implement this.
2867 FIXME("Unimplemented with URL of NULL\n");
2868 return TRUE;
2870 else
2872 URL_COMPONENTSW components;
2874 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2875 components.lpszHostName = (LPWSTR)&hostW;
2876 components.dwHostNameLength = 1024;
2878 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2879 goto End;
2881 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2882 port = components.nPort;
2883 TRACE("port: %d\n", port);
2886 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
2888 struct sockaddr_in sin;
2889 int fd;
2891 if (!GetAddress(hostW, port, &sin))
2892 goto End;
2893 fd = socket(sin.sin_family, SOCK_STREAM, 0);
2894 if (fd != -1)
2896 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == 0)
2897 rc = TRUE;
2898 close(fd);
2901 else
2904 * Build our ping command
2906 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2907 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2908 strcpy(command,ping);
2909 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2910 strcat(command,redirect);
2912 TRACE("Ping command is : %s\n",command);
2914 status = system(command);
2916 TRACE("Ping returned a code of %i\n",status);
2918 /* Ping return code of 0 indicates success */
2919 if (status == 0)
2920 rc = TRUE;
2923 End:
2925 HeapFree( GetProcessHeap(), 0, command );
2926 if (rc == FALSE)
2927 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2929 return rc;
2933 /***********************************************************************
2934 * InternetCheckConnectionA (WININET.@)
2936 * Pings a requested host to check internet connection
2938 * RETURNS
2939 * TRUE on success and FALSE on failure. If a failure then
2940 * ERROR_NOT_CONNECTED is placed into GetLastError
2943 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2945 WCHAR *szUrl;
2946 INT len;
2947 BOOL rc;
2949 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2950 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2951 return FALSE;
2952 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2953 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2954 HeapFree(GetProcessHeap(), 0, szUrl);
2956 return rc;
2960 /**********************************************************
2961 * INTERNET_InternetOpenUrlW (internal)
2963 * Opens an URL
2965 * RETURNS
2966 * handle of connection or NULL on failure
2968 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2969 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2971 URL_COMPONENTSW urlComponents;
2972 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2973 WCHAR password[1024], path[2048], extra[1024];
2974 HINTERNET client = NULL, client1 = NULL;
2976 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2977 dwHeadersLength, dwFlags, dwContext);
2979 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2980 urlComponents.lpszScheme = protocol;
2981 urlComponents.dwSchemeLength = 32;
2982 urlComponents.lpszHostName = hostName;
2983 urlComponents.dwHostNameLength = MAXHOSTNAME;
2984 urlComponents.lpszUserName = userName;
2985 urlComponents.dwUserNameLength = 1024;
2986 urlComponents.lpszPassword = password;
2987 urlComponents.dwPasswordLength = 1024;
2988 urlComponents.lpszUrlPath = path;
2989 urlComponents.dwUrlPathLength = 2048;
2990 urlComponents.lpszExtraInfo = extra;
2991 urlComponents.dwExtraInfoLength = 1024;
2992 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2993 return NULL;
2994 switch(urlComponents.nScheme) {
2995 case INTERNET_SCHEME_FTP:
2996 if(urlComponents.nPort == 0)
2997 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2998 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2999 userName, password, dwFlags, dwContext, INET_OPENURL);
3000 if(client == NULL)
3001 break;
3002 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3003 if(client1 == NULL) {
3004 InternetCloseHandle(client);
3005 break;
3007 break;
3009 case INTERNET_SCHEME_HTTP:
3010 case INTERNET_SCHEME_HTTPS: {
3011 static const WCHAR szStars[] = { '*','/','*', 0 };
3012 LPCWSTR accept[2] = { szStars, NULL };
3013 if(urlComponents.nPort == 0) {
3014 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3015 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3016 else
3017 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3019 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3020 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3021 userName, password, dwFlags, dwContext, INET_OPENURL);
3022 if(client == NULL)
3023 break;
3025 if (urlComponents.dwExtraInfoLength) {
3026 WCHAR *path_extra;
3027 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3029 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
3031 InternetCloseHandle(client);
3032 break;
3034 strcpyW(path_extra, urlComponents.lpszUrlPath);
3035 strcatW(path_extra, urlComponents.lpszExtraInfo);
3036 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3037 HeapFree(GetProcessHeap(), 0, path_extra);
3039 else
3040 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3042 if(client1 == NULL) {
3043 InternetCloseHandle(client);
3044 break;
3046 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3047 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3048 GetLastError() != ERROR_IO_PENDING) {
3049 InternetCloseHandle(client1);
3050 client1 = NULL;
3051 break;
3054 case INTERNET_SCHEME_GOPHER:
3055 /* gopher doesn't seem to be implemented in wine, but it's supposed
3056 * to be supported by InternetOpenUrlA. */
3057 default:
3058 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3059 break;
3062 TRACE(" %p <--\n", client1);
3064 return client1;
3067 /**********************************************************
3068 * InternetOpenUrlW (WININET.@)
3070 * Opens an URL
3072 * RETURNS
3073 * handle of connection or NULL on failure
3075 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3077 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3078 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
3080 TRACE("%p\n", hIC);
3082 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3083 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3084 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3085 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3088 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3089 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3091 HINTERNET ret = NULL;
3092 LPWININETAPPINFOW hIC = NULL;
3094 if (TRACE_ON(wininet)) {
3095 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3096 dwHeadersLength, dwFlags, dwContext);
3097 TRACE(" flags :");
3098 dump_INTERNET_FLAGS(dwFlags);
3101 if (!lpszUrl)
3103 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3104 goto lend;
3107 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
3108 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3109 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3110 goto lend;
3113 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3114 WORKREQUEST workRequest;
3115 struct WORKREQ_INTERNETOPENURLW *req;
3117 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3118 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3119 req = &workRequest.u.InternetOpenUrlW;
3120 req->lpszUrl = WININET_strdupW(lpszUrl);
3121 if (lpszHeaders)
3122 req->lpszHeaders = WININET_strdupW(lpszHeaders);
3123 else
3124 req->lpszHeaders = 0;
3125 req->dwHeadersLength = dwHeadersLength;
3126 req->dwFlags = dwFlags;
3127 req->dwContext = dwContext;
3129 INTERNET_AsyncCall(&workRequest);
3131 * This is from windows.
3133 INTERNET_SetLastError(ERROR_IO_PENDING);
3134 } else {
3135 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3138 lend:
3139 if( hIC )
3140 WININET_Release( &hIC->hdr );
3141 TRACE(" %p <--\n", ret);
3143 return ret;
3146 /**********************************************************
3147 * InternetOpenUrlA (WININET.@)
3149 * Opens an URL
3151 * RETURNS
3152 * handle of connection or NULL on failure
3154 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3155 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3157 HINTERNET rc = NULL;
3159 INT lenUrl;
3160 INT lenHeaders = 0;
3161 LPWSTR szUrl = NULL;
3162 LPWSTR szHeaders = NULL;
3164 TRACE("\n");
3166 if(lpszUrl) {
3167 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3168 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3169 if(!szUrl)
3170 return NULL;
3171 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3174 if(lpszHeaders) {
3175 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3176 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3177 if(!szHeaders) {
3178 HeapFree(GetProcessHeap(), 0, szUrl);
3179 return NULL;
3181 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3184 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3185 lenHeaders, dwFlags, dwContext);
3187 HeapFree(GetProcessHeap(), 0, szUrl);
3188 HeapFree(GetProcessHeap(), 0, szHeaders);
3190 return rc;
3194 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3196 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3198 if (lpwite)
3200 lpwite->dwError = 0;
3201 lpwite->response[0] = '\0';
3204 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3206 HeapFree(GetProcessHeap(), 0, lpwite);
3207 return NULL;
3210 return lpwite;
3214 /***********************************************************************
3215 * INTERNET_SetLastError (internal)
3217 * Set last thread specific error
3219 * RETURNS
3222 void INTERNET_SetLastError(DWORD dwError)
3224 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3226 if (!lpwite)
3227 lpwite = INTERNET_AllocThreadError();
3229 SetLastError(dwError);
3230 if(lpwite)
3231 lpwite->dwError = dwError;
3235 /***********************************************************************
3236 * INTERNET_GetLastError (internal)
3238 * Get last thread specific error
3240 * RETURNS
3243 DWORD INTERNET_GetLastError(void)
3245 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3246 if (!lpwite) return 0;
3247 /* TlsGetValue clears last error, so set it again here */
3248 SetLastError(lpwite->dwError);
3249 return lpwite->dwError;
3253 /***********************************************************************
3254 * INTERNET_WorkerThreadFunc (internal)
3256 * Worker thread execution function
3258 * RETURNS
3261 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3263 LPWORKREQUEST lpRequest = lpvParam;
3264 WORKREQUEST workRequest;
3266 TRACE("\n");
3268 memcpy(&workRequest, lpRequest, sizeof(WORKREQUEST));
3269 HeapFree(GetProcessHeap(), 0, lpRequest);
3271 workRequest.asyncproc(&workRequest);
3273 WININET_Release( workRequest.hdr );
3274 return TRUE;
3278 /***********************************************************************
3279 * INTERNET_AsyncCall (internal)
3281 * Retrieves work request from queue
3283 * RETURNS
3286 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3288 BOOL bSuccess;
3289 LPWORKREQUEST lpNewRequest;
3291 TRACE("\n");
3293 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3294 if (!lpNewRequest)
3295 return FALSE;
3297 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3299 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3300 if (!bSuccess)
3302 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3303 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3306 return bSuccess;
3310 /***********************************************************************
3311 * INTERNET_GetResponseBuffer (internal)
3313 * RETURNS
3316 LPSTR INTERNET_GetResponseBuffer(void)
3318 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3319 if (!lpwite)
3320 lpwite = INTERNET_AllocThreadError();
3321 TRACE("\n");
3322 return lpwite->response;
3325 /***********************************************************************
3326 * INTERNET_GetNextLine (internal)
3328 * Parse next line in directory string listing
3330 * RETURNS
3331 * Pointer to beginning of next line
3332 * NULL on failure
3336 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3338 struct timeval tv;
3339 fd_set infd;
3340 BOOL bSuccess = FALSE;
3341 INT nRecv = 0;
3342 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3344 TRACE("\n");
3346 FD_ZERO(&infd);
3347 FD_SET(nSocket, &infd);
3348 tv.tv_sec=RESPONSE_TIMEOUT;
3349 tv.tv_usec=0;
3351 while (nRecv < MAX_REPLY_LEN)
3353 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3355 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3357 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3358 goto lend;
3361 if (lpszBuffer[nRecv] == '\n')
3363 bSuccess = TRUE;
3364 break;
3366 if (lpszBuffer[nRecv] != '\r')
3367 nRecv++;
3369 else
3371 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3372 goto lend;
3376 lend:
3377 if (bSuccess)
3379 lpszBuffer[nRecv] = '\0';
3380 *dwLen = nRecv - 1;
3381 TRACE(":%d %s\n", nRecv, lpszBuffer);
3382 return lpszBuffer;
3384 else
3386 return NULL;
3390 /**********************************************************
3391 * InternetQueryDataAvailable (WININET.@)
3393 * Determines how much data is available to be read.
3395 * RETURNS
3396 * TRUE on success, FALSE if an error occurred. If
3397 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3398 * no data is presently available, FALSE is returned with
3399 * the last error ERROR_IO_PENDING; a callback with status
3400 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3401 * data is available.
3403 void AsyncInternetQueryDataAvailableProc(WORKREQUEST *workRequest)
3405 LPWININETHTTPREQW lpwhr;
3406 INTERNET_ASYNC_RESULT iar;
3407 char buffer[4048];
3409 TRACE("INTERNETQUERYDATAAVAILABLE %p\n", workRequest->hdr);
3411 switch (workRequest->hdr->htype)
3413 case WH_HHTTPREQ:
3414 lpwhr = (LPWININETHTTPREQW)workRequest->hdr;
3415 iar.dwResult = NETCON_recv(&lpwhr->netConnection, buffer,
3416 min(sizeof(buffer),
3417 lpwhr->dwContentLength - lpwhr->dwContentRead),
3418 MSG_PEEK, (int *)&iar.dwError);
3419 INTERNET_SendCallback(workRequest->hdr, workRequest->hdr->dwContext,
3420 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
3421 sizeof(INTERNET_ASYNC_RESULT));
3422 break;
3424 default:
3425 FIXME("unsupported file type\n");
3426 break;
3430 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3431 LPDWORD lpdwNumberOfBytesAvailble,
3432 DWORD dwFlags, DWORD_PTR dwContext)
3434 LPWININETHTTPREQW lpwhr;
3435 BOOL retval = FALSE;
3436 char buffer[4048];
3438 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3439 if (NULL == lpwhr)
3441 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
3442 return FALSE;
3445 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3447 switch (lpwhr->hdr.htype)
3449 case WH_HHTTPREQ:
3450 retval = TRUE;
3451 if (NETCON_query_data_available(&lpwhr->netConnection,
3452 lpdwNumberOfBytesAvailble) &&
3453 !*lpdwNumberOfBytesAvailble)
3455 /* Even if we are in async mode, we need to determine whether
3456 * there is actually more data available. We do this by trying
3457 * to peek only a single byte in async mode. */
3458 BOOL async = (lpwhr->lpHttpSession->lpAppInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC);
3459 if (NETCON_recv(&lpwhr->netConnection, buffer,
3460 min(async ? 1 : sizeof(buffer),
3461 lpwhr->dwContentLength - lpwhr->dwContentRead),
3462 MSG_PEEK, (int *)lpdwNumberOfBytesAvailble) &&
3463 async && *lpdwNumberOfBytesAvailble)
3465 WORKREQUEST workRequest;
3467 *lpdwNumberOfBytesAvailble = 0;
3468 workRequest.asyncproc = AsyncInternetQueryDataAvailableProc;
3469 workRequest.hdr = WININET_AddRef( &lpwhr->hdr );
3471 retval = INTERNET_AsyncCall(&workRequest);
3472 if (!retval)
3474 WININET_Release( &lpwhr->hdr );
3476 else
3478 INTERNET_SetLastError(ERROR_IO_PENDING);
3479 retval = FALSE;
3483 break;
3485 default:
3486 FIXME("unsupported file type\n");
3487 break;
3489 WININET_Release( &lpwhr->hdr );
3491 TRACE("<-- %i\n",retval);
3492 return retval;
3496 /***********************************************************************
3497 * InternetLockRequestFile (WININET.@)
3499 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3500 *lphLockReqHandle)
3502 FIXME("STUB\n");
3503 return FALSE;
3506 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3508 FIXME("STUB\n");
3509 return FALSE;
3513 /***********************************************************************
3514 * InternetAutodial (WININET.@)
3516 * On windows this function is supposed to dial the default internet
3517 * connection. We don't want to have Wine dial out to the internet so
3518 * we return TRUE by default. It might be nice to check if we are connected.
3520 * RETURNS
3521 * TRUE on success
3522 * FALSE on failure
3525 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3527 FIXME("STUB\n");
3529 /* Tell that we are connected to the internet. */
3530 return TRUE;
3533 /***********************************************************************
3534 * InternetAutodialHangup (WININET.@)
3536 * Hangs up a connection made with InternetAutodial
3538 * PARAM
3539 * dwReserved
3540 * RETURNS
3541 * TRUE on success
3542 * FALSE on failure
3545 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3547 FIXME("STUB\n");
3549 /* we didn't dial, we don't disconnect */
3550 return TRUE;
3553 /***********************************************************************
3554 * InternetCombineUrlA (WININET.@)
3556 * Combine a base URL with a relative URL
3558 * RETURNS
3559 * TRUE on success
3560 * FALSE on failure
3564 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3565 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3566 DWORD dwFlags)
3568 HRESULT hr=S_OK;
3570 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3572 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3573 dwFlags ^= ICU_NO_ENCODE;
3574 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3576 return (hr==S_OK);
3579 /***********************************************************************
3580 * InternetCombineUrlW (WININET.@)
3582 * Combine a base URL with a relative URL
3584 * RETURNS
3585 * TRUE on success
3586 * FALSE on failure
3590 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3591 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3592 DWORD dwFlags)
3594 HRESULT hr=S_OK;
3596 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3598 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3599 dwFlags ^= ICU_NO_ENCODE;
3600 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3602 return (hr==S_OK);
3605 /* max port num is 65535 => 5 digits */
3606 #define MAX_WORD_DIGITS 5
3608 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3609 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3610 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3611 (url)->dw##component##Length : strlen((url)->lpsz##component))
3613 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3615 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3616 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3617 return TRUE;
3618 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3619 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3620 return TRUE;
3621 if ((nScheme == INTERNET_SCHEME_FTP) &&
3622 (nPort == INTERNET_DEFAULT_FTP_PORT))
3623 return TRUE;
3624 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3625 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3626 return TRUE;
3628 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3629 return TRUE;
3631 return FALSE;
3634 /* opaque urls do not fit into the standard url hierarchy and don't have
3635 * two following slashes */
3636 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3638 return (nScheme != INTERNET_SCHEME_FTP) &&
3639 (nScheme != INTERNET_SCHEME_GOPHER) &&
3640 (nScheme != INTERNET_SCHEME_HTTP) &&
3641 (nScheme != INTERNET_SCHEME_HTTPS) &&
3642 (nScheme != INTERNET_SCHEME_FILE);
3645 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3647 int index;
3648 if (scheme < INTERNET_SCHEME_FIRST)
3649 return NULL;
3650 index = scheme - INTERNET_SCHEME_FIRST;
3651 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3652 return NULL;
3653 return (LPCWSTR)&url_schemes[index];
3656 /* we can calculate using ansi strings because we're just
3657 * calculating string length, not size
3659 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3660 LPDWORD lpdwUrlLength)
3662 INTERNET_SCHEME nScheme;
3664 *lpdwUrlLength = 0;
3666 if (lpUrlComponents->lpszScheme)
3668 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3669 *lpdwUrlLength += dwLen;
3670 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3672 else
3674 LPCWSTR scheme;
3676 nScheme = lpUrlComponents->nScheme;
3678 if (nScheme == INTERNET_SCHEME_DEFAULT)
3679 nScheme = INTERNET_SCHEME_HTTP;
3680 scheme = INTERNET_GetSchemeString(nScheme);
3681 *lpdwUrlLength += strlenW(scheme);
3684 (*lpdwUrlLength)++; /* ':' */
3685 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3686 *lpdwUrlLength += strlen("//");
3688 if (lpUrlComponents->lpszUserName)
3690 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3691 *lpdwUrlLength += strlen("@");
3693 else
3695 if (lpUrlComponents->lpszPassword)
3697 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3698 return FALSE;
3702 if (lpUrlComponents->lpszPassword)
3704 *lpdwUrlLength += strlen(":");
3705 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3708 if (lpUrlComponents->lpszHostName)
3710 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3712 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3714 char szPort[MAX_WORD_DIGITS+1];
3716 sprintf(szPort, "%d", lpUrlComponents->nPort);
3717 *lpdwUrlLength += strlen(szPort);
3718 *lpdwUrlLength += strlen(":");
3721 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3722 (*lpdwUrlLength)++; /* '/' */
3725 if (lpUrlComponents->lpszUrlPath)
3726 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3728 return TRUE;
3731 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3733 INT len;
3735 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3737 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3738 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3739 urlCompW->nScheme = lpUrlComponents->nScheme;
3740 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3741 urlCompW->nPort = lpUrlComponents->nPort;
3742 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3743 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3744 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3745 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3747 if (lpUrlComponents->lpszScheme)
3749 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3750 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3751 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3752 -1, urlCompW->lpszScheme, len);
3755 if (lpUrlComponents->lpszHostName)
3757 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3758 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3759 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3760 -1, urlCompW->lpszHostName, len);
3763 if (lpUrlComponents->lpszUserName)
3765 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3766 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3767 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3768 -1, urlCompW->lpszUserName, len);
3771 if (lpUrlComponents->lpszPassword)
3773 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3774 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3775 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3776 -1, urlCompW->lpszPassword, len);
3779 if (lpUrlComponents->lpszUrlPath)
3781 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3782 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3783 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3784 -1, urlCompW->lpszUrlPath, len);
3787 if (lpUrlComponents->lpszExtraInfo)
3789 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3790 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3791 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3792 -1, urlCompW->lpszExtraInfo, len);
3796 /***********************************************************************
3797 * InternetCreateUrlA (WININET.@)
3799 * See InternetCreateUrlW.
3801 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3802 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3804 BOOL ret;
3805 LPWSTR urlW = NULL;
3806 URL_COMPONENTSW urlCompW;
3808 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3810 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3812 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3813 return FALSE;
3816 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3818 if (lpszUrl)
3819 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3821 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3823 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3824 *lpdwUrlLength /= sizeof(WCHAR);
3826 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3827 * minus one, so add one to leave room for NULL terminator
3829 if (ret)
3830 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3832 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3833 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3834 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3835 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3836 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3837 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3838 HeapFree(GetProcessHeap(), 0, urlW);
3840 return ret;
3843 /***********************************************************************
3844 * InternetCreateUrlW (WININET.@)
3846 * Creates a URL from its component parts.
3848 * PARAMS
3849 * lpUrlComponents [I] URL Components.
3850 * dwFlags [I] Flags. See notes.
3851 * lpszUrl [I] Buffer in which to store the created URL.
3852 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3853 * lpszUrl in characters. On output, the number of bytes
3854 * required to store the URL including terminator.
3856 * NOTES
3858 * The dwFlags parameter can be zero or more of the following:
3859 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3861 * RETURNS
3862 * TRUE on success
3863 * FALSE on failure
3866 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3867 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3869 DWORD dwLen;
3870 INTERNET_SCHEME nScheme;
3872 static const WCHAR slashSlashW[] = {'/','/'};
3873 static const WCHAR percentD[] = {'%','d',0};
3875 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3877 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3879 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3880 return FALSE;
3883 if (!calc_url_length(lpUrlComponents, &dwLen))
3884 return FALSE;
3886 if (!lpszUrl || *lpdwUrlLength < dwLen)
3888 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3889 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3890 return FALSE;
3893 *lpdwUrlLength = dwLen;
3894 lpszUrl[0] = 0x00;
3896 dwLen = 0;
3898 if (lpUrlComponents->lpszScheme)
3900 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3901 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3902 lpszUrl += dwLen;
3904 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3906 else
3908 LPCWSTR scheme;
3909 nScheme = lpUrlComponents->nScheme;
3911 if (nScheme == INTERNET_SCHEME_DEFAULT)
3912 nScheme = INTERNET_SCHEME_HTTP;
3914 scheme = INTERNET_GetSchemeString(nScheme);
3915 dwLen = strlenW(scheme);
3916 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3917 lpszUrl += dwLen;
3920 /* all schemes are followed by at least a colon */
3921 *lpszUrl = ':';
3922 lpszUrl++;
3924 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3926 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3927 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3930 if (lpUrlComponents->lpszUserName)
3932 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3933 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3934 lpszUrl += dwLen;
3936 if (lpUrlComponents->lpszPassword)
3938 *lpszUrl = ':';
3939 lpszUrl++;
3941 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3942 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3943 lpszUrl += dwLen;
3946 *lpszUrl = '@';
3947 lpszUrl++;
3950 if (lpUrlComponents->lpszHostName)
3952 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3953 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3954 lpszUrl += dwLen;
3956 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3958 WCHAR szPort[MAX_WORD_DIGITS+1];
3960 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3961 *lpszUrl = ':';
3962 lpszUrl++;
3963 dwLen = strlenW(szPort);
3964 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3965 lpszUrl += dwLen;
3968 /* add slash between hostname and path if necessary */
3969 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3971 *lpszUrl = '/';
3972 lpszUrl++;
3977 if (lpUrlComponents->lpszUrlPath)
3979 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3980 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3981 lpszUrl += dwLen;
3984 *lpszUrl = '\0';
3986 return TRUE;
3989 /***********************************************************************
3990 * InternetConfirmZoneCrossingA (WININET.@)
3993 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3995 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3996 return ERROR_SUCCESS;
3999 /***********************************************************************
4000 * InternetConfirmZoneCrossingW (WININET.@)
4003 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4005 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4006 return ERROR_SUCCESS;
4009 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4010 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4012 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4013 lpdwConnection, dwReserved);
4014 return ERROR_SUCCESS;
4017 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4018 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4020 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4021 lpdwConnection, dwReserved);
4022 return ERROR_SUCCESS;
4025 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4027 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4028 return TRUE;
4031 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4033 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4034 return TRUE;
4037 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4039 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4040 return ERROR_SUCCESS;
4043 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4044 PBYTE pbHexHash )
4046 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4047 debugstr_w(pwszTarget), pbHexHash);
4048 return FALSE;
4051 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4053 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4054 return FALSE;
4057 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4059 FIXME("(%p, %08lx) stub\n", a, b);
4060 return 0;