dmusic: Assign to structs instead of using memcpy.
[wine.git] / dlls / wininet / internet.c
blobc5b6a9f501432d5bb001c1dda942770ad178c23b
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 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr);
82 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
83 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext);
85 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
86 static HMODULE WININET_hModule;
88 #define HANDLE_CHUNK_SIZE 0x10
90 static CRITICAL_SECTION WININET_cs;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
93 0, 0, &WININET_cs,
94 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
95 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
99 static LPWININETHANDLEHEADER *WININET_Handles;
100 static UINT WININET_dwNextHandle;
101 static UINT WININET_dwMaxHandles;
103 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
105 LPWININETHANDLEHEADER *p;
106 UINT handle = 0, num;
108 list_init( &info->children );
110 EnterCriticalSection( &WININET_cs );
111 if( !WININET_dwMaxHandles )
113 num = HANDLE_CHUNK_SIZE;
114 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
115 sizeof (UINT)* num);
116 if( !p )
117 goto end;
118 WININET_Handles = p;
119 WININET_dwMaxHandles = num;
121 if( WININET_dwMaxHandles == WININET_dwNextHandle )
123 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
124 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
125 WININET_Handles, sizeof (UINT)* num);
126 if( !p )
127 goto end;
128 WININET_Handles = p;
129 WININET_dwMaxHandles = num;
132 handle = WININET_dwNextHandle;
133 if( WININET_Handles[handle] )
134 ERR("handle isn't free but should be\n");
135 WININET_Handles[handle] = WININET_AddRef( info );
137 while( WININET_Handles[WININET_dwNextHandle] &&
138 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
139 WININET_dwNextHandle++;
141 end:
142 LeaveCriticalSection( &WININET_cs );
144 return info->hInternet = (HINTERNET) (handle+1);
147 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
149 info->dwRefCount++;
150 TRACE("%p -> refcount = %d\n", info, info->dwRefCount );
151 return info;
154 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
156 LPWININETHANDLEHEADER info = NULL;
157 UINT handle = (UINT) hinternet;
159 EnterCriticalSection( &WININET_cs );
161 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
162 WININET_Handles[handle-1] )
163 info = WININET_AddRef( WININET_Handles[handle-1] );
165 LeaveCriticalSection( &WININET_cs );
167 TRACE("handle %d -> %p\n", handle, info);
169 return info;
172 BOOL WININET_Release( LPWININETHANDLEHEADER info )
174 info->dwRefCount--;
175 TRACE( "object %p refcount = %d\n", info, info->dwRefCount );
176 if( !info->dwRefCount )
178 if ( info->close_connection )
180 TRACE( "closing connection %p\n", info);
181 info->close_connection( info );
183 INTERNET_SendCallback(info, info->dwContext,
184 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
185 sizeof(HINTERNET));
186 TRACE( "destroying object %p\n", info);
187 if ( info->htype != WH_HINIT )
188 list_remove( &info->entry );
189 info->destroy( info );
191 return TRUE;
194 BOOL WININET_FreeHandle( HINTERNET hinternet )
196 BOOL ret = FALSE;
197 UINT handle = (UINT) hinternet;
198 LPWININETHANDLEHEADER info = NULL, child, next;
200 EnterCriticalSection( &WININET_cs );
202 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
204 handle--;
205 if( WININET_Handles[handle] )
207 info = WININET_Handles[handle];
208 TRACE( "destroying handle %d for object %p\n", handle+1, info);
209 WININET_Handles[handle] = NULL;
210 ret = TRUE;
214 LeaveCriticalSection( &WININET_cs );
216 /* As on native when the equivalent of WININET_Release is called, the handle
217 * is already invalid, but if a new handle is created at this time it does
218 * not yet get assigned the freed handle number */
219 if( info )
221 /* Free all children as native does */
222 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, WININETHANDLEHEADER, entry )
224 TRACE( "freeing child handle %d for parent handle %d\n",
225 (UINT)child->hInternet, handle+1);
226 WININET_FreeHandle( child->hInternet );
228 WININET_Release( info );
231 EnterCriticalSection( &WININET_cs );
233 if( WININET_dwNextHandle > handle && !WININET_Handles[handle] )
234 WININET_dwNextHandle = handle;
236 LeaveCriticalSection( &WININET_cs );
238 return ret;
241 /***********************************************************************
242 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
244 * PARAMS
245 * hinstDLL [I] handle to the DLL's instance
246 * fdwReason [I]
247 * lpvReserved [I] reserved, must be NULL
249 * RETURNS
250 * Success: TRUE
251 * Failure: FALSE
254 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
256 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
258 switch (fdwReason) {
259 case DLL_PROCESS_ATTACH:
261 g_dwTlsErrIndex = TlsAlloc();
263 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
264 return FALSE;
266 URLCacheContainers_CreateDefaults();
268 WININET_hModule = hinstDLL;
270 case DLL_THREAD_ATTACH:
271 break;
273 case DLL_THREAD_DETACH:
274 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
276 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
277 HeapFree(GetProcessHeap(), 0, lpwite);
279 break;
281 case DLL_PROCESS_DETACH:
283 URLCacheContainers_DeleteAll();
285 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
287 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
288 TlsFree(g_dwTlsErrIndex);
290 break;
293 return TRUE;
297 /***********************************************************************
298 * InternetInitializeAutoProxyDll (WININET.@)
300 * Setup the internal proxy
302 * PARAMETERS
303 * dwReserved
305 * RETURNS
306 * FALSE on failure
309 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
311 FIXME("STUB\n");
312 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
313 return FALSE;
316 /***********************************************************************
317 * DetectAutoProxyUrl (WININET.@)
319 * Auto detect the proxy url
321 * RETURNS
322 * FALSE on failure
325 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
326 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
328 FIXME("STUB\n");
329 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
330 return FALSE;
334 /***********************************************************************
335 * INTERNET_ConfigureProxyFromReg
337 * FIXME:
338 * The proxy may be specified in the form 'http=proxy.my.org'
339 * Presumably that means there can be ftp=ftpproxy.my.org too.
341 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
343 HKEY key;
344 DWORD r, keytype, len, enabled;
345 LPCSTR lpszInternetSettings =
346 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
347 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
349 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
350 if ( r != ERROR_SUCCESS )
351 return FALSE;
353 len = sizeof enabled;
354 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
355 (BYTE*)&enabled, &len);
356 if( (r == ERROR_SUCCESS) && enabled )
358 TRACE("Proxy is enabled.\n");
360 /* figure out how much memory the proxy setting takes */
361 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
362 NULL, &len);
363 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
365 LPWSTR szProxy, p;
366 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
368 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
369 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
370 (BYTE*)szProxy, &len);
372 /* find the http proxy, and strip away everything else */
373 p = strstrW( szProxy, szHttp );
374 if( p )
376 p += lstrlenW(szHttp);
377 lstrcpyW( szProxy, p );
379 p = strchrW( szProxy, ' ' );
380 if( p )
381 *p = 0;
383 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
384 lpwai->lpszProxy = szProxy;
386 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
388 else
389 ERR("Couldn't read proxy server settings.\n");
391 else
392 TRACE("Proxy is not enabled.\n");
393 RegCloseKey(key);
395 return enabled;
398 /***********************************************************************
399 * dump_INTERNET_FLAGS
401 * Helper function to TRACE the internet flags.
403 * RETURNS
404 * None
407 static void dump_INTERNET_FLAGS(DWORD dwFlags)
409 #define FE(x) { x, #x }
410 static const wininet_flag_info flag[] = {
411 FE(INTERNET_FLAG_RELOAD),
412 FE(INTERNET_FLAG_RAW_DATA),
413 FE(INTERNET_FLAG_EXISTING_CONNECT),
414 FE(INTERNET_FLAG_ASYNC),
415 FE(INTERNET_FLAG_PASSIVE),
416 FE(INTERNET_FLAG_NO_CACHE_WRITE),
417 FE(INTERNET_FLAG_MAKE_PERSISTENT),
418 FE(INTERNET_FLAG_FROM_CACHE),
419 FE(INTERNET_FLAG_SECURE),
420 FE(INTERNET_FLAG_KEEP_CONNECTION),
421 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
422 FE(INTERNET_FLAG_READ_PREFETCH),
423 FE(INTERNET_FLAG_NO_COOKIES),
424 FE(INTERNET_FLAG_NO_AUTH),
425 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
426 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
427 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
428 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
429 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
430 FE(INTERNET_FLAG_RESYNCHRONIZE),
431 FE(INTERNET_FLAG_HYPERLINK),
432 FE(INTERNET_FLAG_NO_UI),
433 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
434 FE(INTERNET_FLAG_CACHE_ASYNC),
435 FE(INTERNET_FLAG_FORMS_SUBMIT),
436 FE(INTERNET_FLAG_NEED_FILE),
437 FE(INTERNET_FLAG_TRANSFER_ASCII),
438 FE(INTERNET_FLAG_TRANSFER_BINARY)
440 #undef FE
441 int i;
443 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
444 if (flag[i].val & dwFlags) {
445 TRACE(" %s", flag[i].name);
446 dwFlags &= ~flag[i].val;
449 if (dwFlags)
450 TRACE(" Unknown flags (%08x)\n", dwFlags);
451 else
452 TRACE("\n");
455 /***********************************************************************
456 * InternetOpenW (WININET.@)
458 * Per-application initialization of wininet
460 * RETURNS
461 * HINTERNET on success
462 * NULL on failure
465 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
466 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
468 LPWININETAPPINFOW lpwai = NULL;
469 HINTERNET handle = NULL;
471 if (TRACE_ON(wininet)) {
472 #define FE(x) { x, #x }
473 static const wininet_flag_info access_type[] = {
474 FE(INTERNET_OPEN_TYPE_PRECONFIG),
475 FE(INTERNET_OPEN_TYPE_DIRECT),
476 FE(INTERNET_OPEN_TYPE_PROXY),
477 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
479 #undef FE
480 DWORD i;
481 const char *access_type_str = "Unknown";
483 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
484 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
485 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
486 if (access_type[i].val == dwAccessType) {
487 access_type_str = access_type[i].name;
488 break;
491 TRACE(" access type : %s\n", access_type_str);
492 TRACE(" flags :");
493 dump_INTERNET_FLAGS(dwFlags);
496 /* Clear any error information */
497 INTERNET_SetLastError(0);
499 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETAPPINFOW));
500 if (NULL == lpwai)
502 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
503 goto lend;
506 lpwai->hdr.htype = WH_HINIT;
507 lpwai->hdr.dwFlags = dwFlags;
508 lpwai->hdr.dwRefCount = 1;
509 lpwai->hdr.close_connection = NULL;
510 lpwai->hdr.destroy = INTERNET_CloseHandle;
511 lpwai->dwAccessType = dwAccessType;
512 lpwai->lpszProxyUsername = NULL;
513 lpwai->lpszProxyPassword = NULL;
515 handle = WININET_AllocHandle( &lpwai->hdr );
516 if( !handle )
518 HeapFree( GetProcessHeap(), 0, lpwai );
519 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
520 goto lend;
523 if (NULL != lpszAgent)
525 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
526 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
527 if (lpwai->lpszAgent)
528 lstrcpyW( lpwai->lpszAgent, lpszAgent );
530 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
531 INTERNET_ConfigureProxyFromReg( lpwai );
532 else if (NULL != lpszProxy)
534 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
535 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
536 if (lpwai->lpszProxy)
537 lstrcpyW( lpwai->lpszProxy, lpszProxy );
540 if (NULL != lpszProxyBypass)
542 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
543 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
544 if (lpwai->lpszProxyBypass)
545 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
548 lend:
549 if( lpwai )
550 WININET_Release( &lpwai->hdr );
552 TRACE("returning %p\n", lpwai);
554 return handle;
558 /***********************************************************************
559 * InternetOpenA (WININET.@)
561 * Per-application initialization of wininet
563 * RETURNS
564 * HINTERNET on success
565 * NULL on failure
568 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
569 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
571 HINTERNET rc = NULL;
572 INT len;
573 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
575 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
576 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
578 if( lpszAgent )
580 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
581 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
582 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
585 if( lpszProxy )
587 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
588 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
589 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
592 if( lpszProxyBypass )
594 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
595 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
596 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
599 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
601 HeapFree(GetProcessHeap(), 0, szAgent);
602 HeapFree(GetProcessHeap(), 0, szProxy);
603 HeapFree(GetProcessHeap(), 0, szBypass);
605 return rc;
608 /***********************************************************************
609 * InternetGetLastResponseInfoA (WININET.@)
611 * Return last wininet error description on the calling thread
613 * RETURNS
614 * TRUE on success of writing to buffer
615 * FALSE on failure
618 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
619 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
621 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
623 TRACE("\n");
625 if (lpwite)
627 *lpdwError = lpwite->dwError;
628 if (lpwite->dwError)
630 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
631 *lpdwBufferLength = strlen(lpszBuffer);
633 else
634 *lpdwBufferLength = 0;
636 else
638 *lpdwError = 0;
639 *lpdwBufferLength = 0;
642 return TRUE;
645 /***********************************************************************
646 * InternetGetLastResponseInfoW (WININET.@)
648 * Return last wininet error description on the calling thread
650 * RETURNS
651 * TRUE on success of writing to buffer
652 * FALSE on failure
655 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
656 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
658 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
660 TRACE("\n");
662 if (lpwite)
664 *lpdwError = lpwite->dwError;
665 if (lpwite->dwError)
667 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
668 *lpdwBufferLength = lstrlenW(lpszBuffer);
670 else
671 *lpdwBufferLength = 0;
673 else
675 *lpdwError = 0;
676 *lpdwBufferLength = 0;
679 return TRUE;
682 /***********************************************************************
683 * InternetGetConnectedState (WININET.@)
685 * Return connected state
687 * RETURNS
688 * TRUE if connected
689 * if lpdwStatus is not null, return the status (off line,
690 * modem, lan...) in it.
691 * FALSE if not connected
693 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
695 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
697 if (lpdwStatus) {
698 FIXME("always returning LAN connection.\n");
699 *lpdwStatus = INTERNET_CONNECTION_LAN;
701 return TRUE;
705 /***********************************************************************
706 * InternetGetConnectedStateExW (WININET.@)
708 * Return connected state
710 * PARAMS
712 * lpdwStatus [O] Flags specifying the status of the internet connection.
713 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
714 * dwNameLen [I] Size of the buffer, in characters.
715 * dwReserved [I] Reserved. Must be set to 0.
717 * RETURNS
718 * TRUE if connected
719 * if lpdwStatus is not null, return the status (off line,
720 * modem, lan...) in it.
721 * FALSE if not connected
723 * NOTES
724 * If the system has no available network connections, an empty string is
725 * stored in lpszConnectionName. If there is a LAN connection, a localized
726 * "LAN Connection" string is stored. Presumably, if only a dial-up
727 * connection is available then the name of the dial-up connection is
728 * returned. Why any application, other than the "Internet Settings" CPL,
729 * would want to use this function instead of the simpler InternetGetConnectedStateW
730 * function is beyond me.
732 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
733 DWORD dwNameLen, DWORD dwReserved)
735 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
737 /* Must be zero */
738 if(dwReserved)
739 return FALSE;
741 if (lpdwStatus) {
742 FIXME("always returning LAN connection.\n");
743 *lpdwStatus = INTERNET_CONNECTION_LAN;
745 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
749 /***********************************************************************
750 * InternetGetConnectedStateExA (WININET.@)
752 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
753 DWORD dwNameLen, DWORD dwReserved)
755 LPWSTR lpwszConnectionName = NULL;
756 BOOL rc;
758 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
760 if (lpszConnectionName && dwNameLen > 0)
761 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
763 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
764 dwReserved);
765 if (rc && lpwszConnectionName)
767 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
768 dwNameLen, NULL, NULL);
770 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
773 return rc;
777 /***********************************************************************
778 * InternetConnectW (WININET.@)
780 * Open a ftp, gopher or http session
782 * RETURNS
783 * HINTERNET a session handle on success
784 * NULL on failure
787 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
788 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
789 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
790 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
792 LPWININETAPPINFOW hIC;
793 HINTERNET rc = NULL;
795 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
796 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
797 dwService, dwFlags, dwContext);
799 if (!lpszServerName)
801 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
802 return NULL;
805 /* Clear any error information */
806 INTERNET_SetLastError(0);
807 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
808 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
810 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
811 goto lend;
814 switch (dwService)
816 case INTERNET_SERVICE_FTP:
817 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
818 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
819 break;
821 case INTERNET_SERVICE_HTTP:
822 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
823 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
824 break;
826 case INTERNET_SERVICE_GOPHER:
827 default:
828 break;
830 lend:
831 if( hIC )
832 WININET_Release( &hIC->hdr );
834 TRACE("returning %p\n", rc);
835 return rc;
839 /***********************************************************************
840 * InternetConnectA (WININET.@)
842 * Open a ftp, gopher or http session
844 * RETURNS
845 * HINTERNET a session handle on success
846 * NULL on failure
849 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
850 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
851 LPCSTR lpszUserName, LPCSTR lpszPassword,
852 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
854 HINTERNET rc = NULL;
855 INT len = 0;
856 LPWSTR szServerName = NULL;
857 LPWSTR szUserName = NULL;
858 LPWSTR szPassword = NULL;
860 if (lpszServerName)
862 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
863 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
864 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
866 if (lpszUserName)
868 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
869 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
870 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
872 if (lpszPassword)
874 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
875 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
876 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
880 rc = InternetConnectW(hInternet, szServerName, nServerPort,
881 szUserName, szPassword, dwService, dwFlags, dwContext);
883 HeapFree(GetProcessHeap(), 0, szServerName);
884 HeapFree(GetProcessHeap(), 0, szUserName);
885 HeapFree(GetProcessHeap(), 0, szPassword);
886 return rc;
890 /***********************************************************************
891 * InternetFindNextFileA (WININET.@)
893 * Continues a file search from a previous call to FindFirstFile
895 * RETURNS
896 * TRUE on success
897 * FALSE on failure
900 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
902 BOOL ret;
903 WIN32_FIND_DATAW fd;
905 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
906 if(lpvFindData)
907 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
908 return ret;
911 /***********************************************************************
912 * InternetFindNextFileW (WININET.@)
914 * Continues a file search from a previous call to FindFirstFile
916 * RETURNS
917 * TRUE on success
918 * FALSE on failure
921 static void AsyncFtpFindNextFileProc(WORKREQUEST *workRequest)
923 struct WORKREQ_FTPFINDNEXTW *req = &workRequest->u.FtpFindNextW;
924 LPWININETFTPFINDNEXTW lpwh = (LPWININETFTPFINDNEXTW) workRequest->hdr;
926 TRACE("%p\n", lpwh);
928 FTP_FindNextFileW(lpwh, req->lpFindFileData);
931 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
933 LPWININETAPPINFOW hIC = NULL;
934 LPWININETFTPFINDNEXTW lpwh;
935 BOOL bSuccess = FALSE;
937 TRACE("\n");
939 lpwh = (LPWININETFTPFINDNEXTW) WININET_GetObject( hFind );
940 if (NULL == lpwh || lpwh->hdr.htype != WH_HFTPFINDNEXT)
942 FIXME("Only FTP supported\n");
943 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
944 goto lend;
947 hIC = lpwh->lpFtpSession->lpAppInfo;
948 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
950 WORKREQUEST workRequest;
951 struct WORKREQ_FTPFINDNEXTW *req;
953 workRequest.asyncproc = AsyncFtpFindNextFileProc;
954 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
955 req = &workRequest.u.FtpFindNextW;
956 req->lpFindFileData = lpvFindData;
958 bSuccess = INTERNET_AsyncCall(&workRequest);
960 else
962 bSuccess = FTP_FindNextFileW(lpwh, lpvFindData);
964 lend:
965 if( lpwh )
966 WININET_Release( &lpwh->hdr );
967 return bSuccess;
970 /***********************************************************************
971 * INTERNET_CloseHandle (internal)
973 * Close internet handle
975 * RETURNS
976 * Void
979 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
981 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
983 TRACE("%p\n",lpwai);
985 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
986 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
987 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
988 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
989 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
990 HeapFree(GetProcessHeap(), 0, lpwai);
994 /***********************************************************************
995 * InternetCloseHandle (WININET.@)
997 * Generic close handle function
999 * RETURNS
1000 * TRUE on success
1001 * FALSE on failure
1004 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1006 LPWININETHANDLEHEADER lpwh;
1008 TRACE("%p\n",hInternet);
1010 lpwh = WININET_GetObject( hInternet );
1011 if (NULL == lpwh)
1013 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1014 return FALSE;
1017 WININET_Release( lpwh );
1018 WININET_FreeHandle( hInternet );
1020 return TRUE;
1024 /***********************************************************************
1025 * ConvertUrlComponentValue (Internal)
1027 * Helper function for InternetCrackUrlW
1030 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1031 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1032 LPCSTR lpszStart, LPCWSTR lpwszStart)
1034 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1035 if (*dwComponentLen != 0)
1037 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1038 if (*lppszComponent == NULL)
1040 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1041 if (lpwszComponent)
1042 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1043 else
1044 *lppszComponent = NULL;
1045 *dwComponentLen = nASCIILength;
1047 else
1049 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1050 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1051 (*lppszComponent)[ncpylen]=0;
1052 *dwComponentLen = ncpylen;
1058 /***********************************************************************
1059 * InternetCrackUrlA (WININET.@)
1061 * See InternetCrackUrlW.
1063 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1064 LPURL_COMPONENTSA lpUrlComponents)
1066 DWORD nLength;
1067 URL_COMPONENTSW UCW;
1068 WCHAR* lpwszUrl;
1070 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1072 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1073 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1075 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1076 return FALSE;
1079 if(dwUrlLength<=0)
1080 dwUrlLength=-1;
1081 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1083 /* if dwUrlLength=-1 then nLength includes null but length to
1084 InternetCrackUrlW should not include it */
1085 if (dwUrlLength == -1) nLength--;
1087 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1088 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1090 memset(&UCW,0,sizeof(UCW));
1091 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1092 if(lpUrlComponents->dwHostNameLength!=0)
1093 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1094 if(lpUrlComponents->dwUserNameLength!=0)
1095 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1096 if(lpUrlComponents->dwPasswordLength!=0)
1097 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1098 if(lpUrlComponents->dwUrlPathLength!=0)
1099 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1100 if(lpUrlComponents->dwSchemeLength!=0)
1101 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1102 if(lpUrlComponents->dwExtraInfoLength!=0)
1103 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1104 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1106 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1107 return FALSE;
1110 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1111 UCW.lpszHostName, UCW.dwHostNameLength,
1112 lpszUrl, lpwszUrl);
1113 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1114 UCW.lpszUserName, UCW.dwUserNameLength,
1115 lpszUrl, lpwszUrl);
1116 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1117 UCW.lpszPassword, UCW.dwPasswordLength,
1118 lpszUrl, lpwszUrl);
1119 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1120 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1121 lpszUrl, lpwszUrl);
1122 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1123 UCW.lpszScheme, UCW.dwSchemeLength,
1124 lpszUrl, lpwszUrl);
1125 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1126 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1127 lpszUrl, lpwszUrl);
1128 lpUrlComponents->nScheme=UCW.nScheme;
1129 lpUrlComponents->nPort=UCW.nPort;
1130 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1132 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1133 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1134 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1135 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1136 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1138 return TRUE;
1141 static const WCHAR url_schemes[][7] =
1143 {'f','t','p',0},
1144 {'g','o','p','h','e','r',0},
1145 {'h','t','t','p',0},
1146 {'h','t','t','p','s',0},
1147 {'f','i','l','e',0},
1148 {'n','e','w','s',0},
1149 {'m','a','i','l','t','o',0},
1150 {'r','e','s',0},
1153 /***********************************************************************
1154 * GetInternetSchemeW (internal)
1156 * Get scheme of url
1158 * RETURNS
1159 * scheme on success
1160 * INTERNET_SCHEME_UNKNOWN on failure
1163 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1165 int i;
1167 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1169 if(lpszScheme==NULL)
1170 return INTERNET_SCHEME_UNKNOWN;
1172 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1173 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1174 return INTERNET_SCHEME_FIRST + i;
1176 return INTERNET_SCHEME_UNKNOWN;
1179 /***********************************************************************
1180 * SetUrlComponentValueW (Internal)
1182 * Helper function for InternetCrackUrlW
1184 * PARAMS
1185 * lppszComponent [O] Holds the returned string
1186 * dwComponentLen [I] Holds the size of lppszComponent
1187 * [O] Holds the length of the string in lppszComponent without '\0'
1188 * lpszStart [I] Holds the string to copy from
1189 * len [I] Holds the length of lpszStart without '\0'
1191 * RETURNS
1192 * TRUE on success
1193 * FALSE on failure
1196 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1198 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1200 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1201 return FALSE;
1203 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1205 if (*lppszComponent == NULL)
1207 *lppszComponent = (LPWSTR)lpszStart;
1208 *dwComponentLen = len;
1210 else
1212 DWORD ncpylen = min((*dwComponentLen)-1, len);
1213 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1214 (*lppszComponent)[ncpylen] = '\0';
1215 *dwComponentLen = ncpylen;
1219 return TRUE;
1222 /***********************************************************************
1223 * InternetCrackUrlW (WININET.@)
1225 * Break up URL into its components
1227 * RETURNS
1228 * TRUE on success
1229 * FALSE on failure
1231 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1232 LPURL_COMPONENTSW lpUC)
1235 * RFC 1808
1236 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1239 LPCWSTR lpszParam = NULL;
1240 BOOL bIsAbsolute = FALSE;
1241 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1242 LPCWSTR lpszcp = NULL;
1243 LPWSTR lpszUrl_decode = NULL;
1244 DWORD dwUrlLength = dwUrlLength_orig;
1245 const WCHAR lpszSeparators[3]={';','?',0};
1246 const WCHAR lpszSlash[2]={'/',0};
1248 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1250 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1252 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1253 return FALSE;
1255 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1257 if (dwFlags & ICU_DECODE)
1259 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1260 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1262 lpszUrl = lpszUrl_decode;
1265 lpszap = lpszUrl;
1267 /* Determine if the URI is absolute. */
1268 while (*lpszap != '\0')
1270 if (isalnumW(*lpszap))
1272 lpszap++;
1273 continue;
1275 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1277 bIsAbsolute = TRUE;
1278 lpszcp = lpszap;
1280 else
1282 lpszcp = lpszUrl; /* Relative url */
1285 break;
1288 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1289 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1291 /* Parse <params> */
1292 lpszParam = strpbrkW(lpszap, lpszSeparators);
1293 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1294 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1296 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1298 LPCWSTR lpszNetLoc;
1300 /* Get scheme first. */
1301 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1302 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1303 lpszUrl, lpszcp - lpszUrl);
1305 /* Eat ':' in protocol. */
1306 lpszcp++;
1308 /* double slash indicates the net_loc portion is present */
1309 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1311 lpszcp += 2;
1313 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1314 if (lpszParam)
1316 if (lpszNetLoc)
1317 lpszNetLoc = min(lpszNetLoc, lpszParam);
1318 else
1319 lpszNetLoc = lpszParam;
1321 else if (!lpszNetLoc)
1322 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1324 /* Parse net-loc */
1325 if (lpszNetLoc)
1327 LPCWSTR lpszHost;
1328 LPCWSTR lpszPort;
1330 /* [<user>[<:password>]@]<host>[:<port>] */
1331 /* First find the user and password if they exist */
1333 lpszHost = strchrW(lpszcp, '@');
1334 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1336 /* username and password not specified. */
1337 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1338 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1340 else /* Parse out username and password */
1342 LPCWSTR lpszUser = lpszcp;
1343 LPCWSTR lpszPasswd = lpszHost;
1345 while (lpszcp < lpszHost)
1347 if (*lpszcp == ':')
1348 lpszPasswd = lpszcp;
1350 lpszcp++;
1353 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1354 lpszUser, lpszPasswd - lpszUser);
1356 if (lpszPasswd != lpszHost)
1357 lpszPasswd++;
1358 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1359 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1360 lpszHost - lpszPasswd);
1362 lpszcp++; /* Advance to beginning of host */
1365 /* Parse <host><:port> */
1367 lpszHost = lpszcp;
1368 lpszPort = lpszNetLoc;
1370 /* special case for res:// URLs: there is no port here, so the host is the
1371 entire string up to the first '/' */
1372 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1374 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1375 lpszHost, lpszPort - lpszHost);
1376 lpszcp=lpszNetLoc;
1378 else
1380 while (lpszcp < lpszNetLoc)
1382 if (*lpszcp == ':')
1383 lpszPort = lpszcp;
1385 lpszcp++;
1388 /* If the scheme is "file" and the host is just one letter, it's not a host */
1389 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1391 lpszcp=lpszHost;
1392 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1393 NULL, 0);
1395 else
1397 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1398 lpszHost, lpszPort - lpszHost);
1399 if (lpszPort != lpszNetLoc)
1400 lpUC->nPort = atoiW(++lpszPort);
1401 else switch (lpUC->nScheme)
1403 case INTERNET_SCHEME_HTTP:
1404 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1405 break;
1406 case INTERNET_SCHEME_HTTPS:
1407 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1408 break;
1409 case INTERNET_SCHEME_FTP:
1410 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1411 break;
1412 case INTERNET_SCHEME_GOPHER:
1413 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1414 break;
1415 default:
1416 break;
1422 else
1424 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1425 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1426 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1429 else
1431 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1432 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1433 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1434 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1437 /* Here lpszcp points to:
1439 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1440 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1442 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1444 INT len;
1446 /* Only truncate the parameter list if it's already been saved
1447 * in lpUC->lpszExtraInfo.
1449 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1450 len = lpszParam - lpszcp;
1451 else
1453 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1454 * newlines if necessary.
1456 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1457 if (lpsznewline != NULL)
1458 len = lpsznewline - lpszcp;
1459 else
1460 len = dwUrlLength-(lpszcp-lpszUrl);
1462 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1463 lpszcp, len);
1465 else
1467 lpUC->dwUrlPathLength = 0;
1470 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1471 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1472 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1473 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1474 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1476 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1477 return TRUE;
1480 /***********************************************************************
1481 * InternetAttemptConnect (WININET.@)
1483 * Attempt to make a connection to the internet
1485 * RETURNS
1486 * ERROR_SUCCESS on success
1487 * Error value on failure
1490 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1492 FIXME("Stub\n");
1493 return ERROR_SUCCESS;
1497 /***********************************************************************
1498 * InternetCanonicalizeUrlA (WININET.@)
1500 * Escape unsafe characters and spaces
1502 * RETURNS
1503 * TRUE on success
1504 * FALSE on failure
1507 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1508 LPDWORD lpdwBufferLength, DWORD dwFlags)
1510 HRESULT hr;
1511 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1513 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1514 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1516 if(dwFlags & ICU_DECODE)
1518 dwURLFlags |= URL_UNESCAPE;
1519 dwFlags &= ~ICU_DECODE;
1522 if(dwFlags & ICU_ESCAPE)
1524 dwURLFlags |= URL_UNESCAPE;
1525 dwFlags &= ~ICU_ESCAPE;
1528 if(dwFlags & ICU_BROWSER_MODE)
1530 dwURLFlags |= URL_BROWSER_MODE;
1531 dwFlags &= ~ICU_BROWSER_MODE;
1534 if(dwFlags & ICU_NO_ENCODE)
1536 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1537 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1538 dwFlags &= ~ICU_NO_ENCODE;
1541 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1543 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1544 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1545 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1547 return (hr == S_OK) ? TRUE : FALSE;
1550 /***********************************************************************
1551 * InternetCanonicalizeUrlW (WININET.@)
1553 * Escape unsafe characters and spaces
1555 * RETURNS
1556 * TRUE on success
1557 * FALSE on failure
1560 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1561 LPDWORD lpdwBufferLength, DWORD dwFlags)
1563 HRESULT hr;
1564 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1566 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1567 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1569 if(dwFlags & ICU_DECODE)
1571 dwURLFlags |= URL_UNESCAPE;
1572 dwFlags &= ~ICU_DECODE;
1575 if(dwFlags & ICU_ESCAPE)
1577 dwURLFlags |= URL_UNESCAPE;
1578 dwFlags &= ~ICU_ESCAPE;
1581 if(dwFlags & ICU_BROWSER_MODE)
1583 dwURLFlags |= URL_BROWSER_MODE;
1584 dwFlags &= ~ICU_BROWSER_MODE;
1587 if(dwFlags & ICU_NO_ENCODE)
1589 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1590 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1591 dwFlags &= ~ICU_NO_ENCODE;
1594 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1596 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1597 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1598 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1600 return (hr == S_OK) ? TRUE : FALSE;
1603 /* #################################################### */
1605 static INTERNET_STATUS_CALLBACK set_status_callback(
1606 LPWININETHANDLEHEADER lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1608 INTERNET_STATUS_CALLBACK ret;
1610 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1611 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1613 ret = lpwh->lpfnStatusCB;
1614 lpwh->lpfnStatusCB = callback;
1616 return ret;
1619 /***********************************************************************
1620 * InternetSetStatusCallbackA (WININET.@)
1622 * Sets up a callback function which is called as progress is made
1623 * during an operation.
1625 * RETURNS
1626 * Previous callback or NULL on success
1627 * INTERNET_INVALID_STATUS_CALLBACK on failure
1630 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1631 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1633 INTERNET_STATUS_CALLBACK retVal;
1634 LPWININETHANDLEHEADER lpwh;
1636 TRACE("0x%08x\n", (ULONG)hInternet);
1638 if (!(lpwh = WININET_GetObject(hInternet)))
1639 return INTERNET_INVALID_STATUS_CALLBACK;
1641 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1643 WININET_Release( lpwh );
1644 return retVal;
1647 /***********************************************************************
1648 * InternetSetStatusCallbackW (WININET.@)
1650 * Sets up a callback function which is called as progress is made
1651 * during an operation.
1653 * RETURNS
1654 * Previous callback or NULL on success
1655 * INTERNET_INVALID_STATUS_CALLBACK on failure
1658 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1659 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1661 INTERNET_STATUS_CALLBACK retVal;
1662 LPWININETHANDLEHEADER lpwh;
1664 TRACE("0x%08x\n", (ULONG)hInternet);
1666 if (!(lpwh = WININET_GetObject(hInternet)))
1667 return INTERNET_INVALID_STATUS_CALLBACK;
1669 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
1671 WININET_Release( lpwh );
1672 return retVal;
1675 /***********************************************************************
1676 * InternetSetFilePointer (WININET.@)
1678 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1679 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
1681 FIXME("stub\n");
1682 return FALSE;
1685 /***********************************************************************
1686 * InternetWriteFile (WININET.@)
1688 * Write data to an open internet file
1690 * RETURNS
1691 * TRUE on success
1692 * FALSE on failure
1695 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1696 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1698 BOOL retval = FALSE;
1699 int nSocket = -1;
1700 LPWININETHANDLEHEADER lpwh;
1702 TRACE("\n");
1703 lpwh = WININET_GetObject( hFile );
1704 if (NULL == lpwh)
1705 return FALSE;
1707 switch (lpwh->htype)
1709 case WH_HHTTPREQ:
1711 LPWININETHTTPREQW lpwhr;
1712 lpwhr = (LPWININETHTTPREQW)lpwh;
1714 TRACE("HTTPREQ %i\n",dwNumOfBytesToWrite);
1715 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1716 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1718 WININET_Release( lpwh );
1719 return retval;
1721 break;
1723 case WH_HFILE:
1724 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1725 break;
1727 default:
1728 break;
1731 if (nSocket != -1)
1733 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1734 retval = (res >= 0);
1735 *lpdwNumOfBytesWritten = retval ? res : 0;
1737 WININET_Release( lpwh );
1739 return retval;
1743 BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1744 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1745 BOOL bWait, BOOL bSendCompletionStatus)
1747 BOOL retval = FALSE;
1748 int nSocket = -1;
1749 int bytes_read;
1750 LPWININETHTTPREQW lpwhr;
1752 /* FIXME: this should use NETCON functions! */
1753 switch (lpwh->htype)
1755 case WH_HHTTPREQ:
1756 lpwhr = (LPWININETHTTPREQW)lpwh;
1758 if (!NETCON_recv(&lpwhr->netConnection, lpBuffer,
1759 min(dwNumOfBytesToRead, lpwhr->dwContentLength - lpwhr->dwContentRead),
1760 bWait ? MSG_WAITALL : 0, &bytes_read))
1763 if (((lpwhr->dwContentLength != -1) &&
1764 (lpwhr->dwContentRead != lpwhr->dwContentLength)))
1765 ERR("not all data received %d/%d\n", lpwhr->dwContentRead,
1766 lpwhr->dwContentLength);
1768 /* always returns TRUE, even if the network layer returns an
1769 * error */
1770 *pdwNumOfBytesRead = 0;
1771 HTTP_FinishedReading(lpwhr);
1772 retval = TRUE;
1774 else
1776 lpwhr->dwContentRead += bytes_read;
1777 *pdwNumOfBytesRead = bytes_read;
1779 if(lpwhr->lpszCacheFile) {
1780 BOOL res;
1782 res = WriteFile(lpwhr->hCacheFile, lpBuffer, bytes_read, NULL, NULL);
1783 if(!res)
1784 WARN("WriteFile failed: %u\n", GetLastError());
1787 if (!bytes_read && (lpwhr->dwContentRead == lpwhr->dwContentLength))
1788 retval = HTTP_FinishedReading(lpwhr);
1789 else
1790 retval = TRUE;
1792 break;
1794 case WH_HFILE:
1795 /* FIXME: FTP should use NETCON_ stuff */
1796 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1797 if (nSocket != -1)
1799 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1800 retval = (res >= 0);
1801 *pdwNumOfBytesRead = retval ? res : 0;
1803 break;
1805 default:
1806 break;
1809 if (bSendCompletionStatus)
1811 INTERNET_ASYNC_RESULT iar;
1813 iar.dwResult = retval;
1814 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1815 INTERNET_GetLastError();
1817 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1818 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1819 sizeof(INTERNET_ASYNC_RESULT));
1821 return retval;
1824 /***********************************************************************
1825 * InternetReadFile (WININET.@)
1827 * Read data from an open internet file
1829 * RETURNS
1830 * TRUE on success
1831 * FALSE on failure
1834 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1835 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1837 LPWININETHANDLEHEADER lpwh;
1838 BOOL retval;
1840 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1842 lpwh = WININET_GetObject( hFile );
1843 if (!lpwh)
1845 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1846 return FALSE;
1849 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1850 WININET_Release( lpwh );
1852 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1853 return retval;
1856 /***********************************************************************
1857 * InternetReadFileExA (WININET.@)
1859 * Read data from an open internet file
1861 * PARAMS
1862 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1863 * lpBuffersOut [I/O] Buffer.
1864 * dwFlags [I] Flags. See notes.
1865 * dwContext [I] Context for callbacks.
1867 * RETURNS
1868 * TRUE on success
1869 * FALSE on failure
1871 * NOTES
1872 * The parameter dwFlags include zero or more of the following flags:
1873 *|IRF_ASYNC - Makes the call asynchronous.
1874 *|IRF_SYNC - Makes the call synchronous.
1875 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1876 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1878 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1880 * SEE
1881 * InternetOpenUrlA(), HttpOpenRequestA()
1883 void AsyncInternetReadFileExProc(WORKREQUEST *workRequest)
1885 struct WORKREQ_INTERNETREADFILEEXA const *req = &workRequest->u.InternetReadFileExA;
1887 TRACE("INTERNETREADFILEEXA %p\n", workRequest->hdr);
1889 INTERNET_ReadFile(workRequest->hdr, req->lpBuffersOut->lpvBuffer,
1890 req->lpBuffersOut->dwBufferLength,
1891 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
1894 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1895 DWORD dwFlags, DWORD_PTR dwContext)
1897 BOOL retval = FALSE;
1898 LPWININETHANDLEHEADER lpwh;
1900 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1902 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1903 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1905 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1907 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1908 return FALSE;
1911 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1912 if (!lpwh)
1914 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1915 return FALSE;
1918 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1919 INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
1921 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1922 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1923 if (dwFlags & IRF_ASYNC)
1925 DWORD dwDataAvailable = 0;
1927 if (lpwh->htype == WH_HHTTPREQ)
1928 NETCON_query_data_available(&((LPWININETHTTPREQW)lpwh)->netConnection,
1929 &dwDataAvailable);
1931 if (!dwDataAvailable)
1933 WORKREQUEST workRequest;
1934 struct WORKREQ_INTERNETREADFILEEXA *req;
1936 workRequest.asyncproc = AsyncInternetReadFileExProc;
1937 workRequest.hdr = WININET_AddRef( lpwh );
1938 req = &workRequest.u.InternetReadFileExA;
1939 req->lpBuffersOut = lpBuffersOut;
1941 if (!INTERNET_AsyncCall(&workRequest))
1942 WININET_Release( lpwh );
1943 else
1944 INTERNET_SetLastError(ERROR_IO_PENDING);
1945 goto end;
1949 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1950 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1951 !(dwFlags & IRF_NO_WAIT), FALSE);
1953 if (retval)
1955 DWORD dwBytesReceived = lpBuffersOut->dwBufferLength;
1956 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1957 INTERNET_STATUS_RESPONSE_RECEIVED, &dwBytesReceived,
1958 sizeof(dwBytesReceived));
1961 end:
1962 WININET_Release( lpwh );
1964 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1965 return retval;
1968 /***********************************************************************
1969 * InternetReadFileExW (WININET.@)
1971 * Read data from an open internet file.
1973 * PARAMS
1974 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1975 * lpBuffersOut [I/O] Buffer.
1976 * dwFlags [I] Flags.
1977 * dwContext [I] Context for callbacks.
1979 * RETURNS
1980 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1982 * NOTES
1983 * Not implemented in Wine or native either (as of IE6 SP2).
1986 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1987 DWORD dwFlags, DWORD_PTR dwContext)
1989 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1991 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1992 return FALSE;
1995 /***********************************************************************
1996 * INET_QueryOptionHelper (internal)
1998 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1999 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2001 LPWININETHANDLEHEADER lpwhh;
2002 BOOL bSuccess = FALSE;
2004 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2006 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2008 switch (dwOption)
2010 case INTERNET_OPTION_HANDLE_TYPE:
2012 ULONG type;
2014 if (!lpwhh)
2016 WARN("Invalid hInternet handle\n");
2017 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2018 return FALSE;
2021 type = lpwhh->htype;
2023 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type);
2025 if (*lpdwBufferLength < sizeof(ULONG))
2026 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2027 else
2029 memcpy(lpBuffer, &type, sizeof(ULONG));
2030 bSuccess = TRUE;
2032 *lpdwBufferLength = sizeof(ULONG);
2033 break;
2036 case INTERNET_OPTION_REQUEST_FLAGS:
2038 ULONG flags = 4;
2039 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
2040 if (*lpdwBufferLength < sizeof(ULONG))
2041 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2042 else
2044 memcpy(lpBuffer, &flags, sizeof(ULONG));
2045 bSuccess = TRUE;
2047 *lpdwBufferLength = sizeof(ULONG);
2048 break;
2051 case INTERNET_OPTION_URL:
2053 TRACE("INTERNET_OPTION_URL\n");
2055 if (!lpwhh)
2057 WARN("Invalid hInternet handle\n");
2058 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2059 return FALSE;
2061 if (lpwhh->htype == WH_HHTTPREQ)
2063 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2064 WCHAR url[1023];
2065 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2066 static const WCHAR szHost[] = {'H','o','s','t',0};
2067 DWORD sizeRequired;
2068 LPHTTPHEADERW Host;
2070 Host = HTTP_GetHeader(lpreq,szHost);
2071 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2072 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2073 if(!bIsUnicode)
2075 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2076 lpBuffer,*lpdwBufferLength,NULL,NULL);
2077 if (sizeRequired > *lpdwBufferLength)
2078 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2079 else
2080 bSuccess = TRUE;
2081 *lpdwBufferLength = sizeRequired;
2083 else
2085 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2086 if (*lpdwBufferLength < sizeRequired)
2087 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2088 else
2090 strcpyW(lpBuffer, url);
2091 bSuccess = TRUE;
2093 *lpdwBufferLength = sizeRequired;
2096 break;
2099 case INTERNET_OPTION_DATAFILE_NAME:
2101 TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
2102 if (!lpwhh)
2104 WARN("Invalid hInternet handle\n");
2105 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2106 return FALSE;
2108 if (lpwhh->htype == WH_HHTTPREQ)
2110 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2111 DWORD size;
2113 if(!lpreq->lpszCacheFile) {
2114 *lpdwBufferLength = 0;
2115 INTERNET_SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
2117 else if(bIsUnicode)
2119 size = (lstrlenW(lpreq->lpszCacheFile)+1) * sizeof(WCHAR);
2120 if (*lpdwBufferLength < size)
2121 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2122 else
2124 memcpy(lpBuffer, lpreq->lpszCacheFile, size);
2125 bSuccess = TRUE;
2127 *lpdwBufferLength = size;
2129 else
2131 size = WideCharToMultiByte(CP_ACP, 0, lpreq->lpszCacheFile, -1, NULL, 0, NULL, NULL);
2132 if (size > *lpdwBufferLength) {
2133 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2134 }else {
2135 *lpdwBufferLength = WideCharToMultiByte(CP_ACP, 0, lpreq->lpszCacheFile,
2136 -1, lpBuffer, *lpdwBufferLength, NULL, NULL);
2137 bSuccess = TRUE;
2141 break;
2144 case INTERNET_OPTION_HTTP_VERSION:
2146 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2147 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2148 else
2151 * Presently hardcoded to 1.1
2153 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2154 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2155 bSuccess = TRUE;
2157 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2158 break;
2160 case INTERNET_OPTION_CONNECTED_STATE:
2162 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2163 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2165 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2166 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2167 else
2169 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2170 bSuccess = TRUE;
2172 *lpdwBufferLength = sizeof(*pdwConnectedState);
2173 break;
2175 case INTERNET_OPTION_PROXY:
2177 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2178 WININETAPPINFOW wai;
2180 if (lpwai == NULL)
2182 TRACE("Getting global proxy info\n");
2183 memset(&wai, 0, sizeof(WININETAPPINFOW));
2184 INTERNET_ConfigureProxyFromReg( &wai );
2185 lpwai = &wai;
2188 if (bIsUnicode)
2190 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2191 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2193 if (lpwai->lpszProxy)
2194 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2195 sizeof(WCHAR);
2196 if (lpwai->lpszProxyBypass)
2197 proxyBypassBytesRequired =
2198 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2199 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2200 proxyBytesRequired + proxyBypassBytesRequired)
2201 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2202 else
2204 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
2205 sizeof(INTERNET_PROXY_INFOW));
2206 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
2207 sizeof(INTERNET_PROXY_INFOW) +
2208 proxyBytesRequired);
2210 pPI->dwAccessType = lpwai->dwAccessType;
2211 pPI->lpszProxy = NULL;
2212 pPI->lpszProxyBypass = NULL;
2213 if (lpwai->lpszProxy)
2215 lstrcpyW(proxy, lpwai->lpszProxy);
2216 pPI->lpszProxy = proxy;
2219 if (lpwai->lpszProxyBypass)
2221 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
2222 pPI->lpszProxyBypass = proxy_bypass;
2224 bSuccess = TRUE;
2226 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2227 proxyBytesRequired + proxyBypassBytesRequired;
2229 else
2231 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2232 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2234 if (lpwai->lpszProxy)
2235 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2236 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2237 if (lpwai->lpszProxyBypass)
2238 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2239 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2240 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2241 proxyBytesRequired + proxyBypassBytesRequired)
2242 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2243 else
2245 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2246 sizeof(INTERNET_PROXY_INFOA));
2247 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2248 sizeof(INTERNET_PROXY_INFOA) +
2249 proxyBytesRequired);
2251 pPI->dwAccessType = lpwai->dwAccessType;
2252 pPI->lpszProxy = NULL;
2253 pPI->lpszProxyBypass = NULL;
2254 if (lpwai->lpszProxy)
2256 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2257 proxy, proxyBytesRequired, NULL, NULL);
2258 pPI->lpszProxy = proxy;
2261 if (lpwai->lpszProxyBypass)
2263 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2264 -1, proxy_bypass, proxyBypassBytesRequired,
2265 NULL, NULL);
2266 pPI->lpszProxyBypass = proxy_bypass;
2268 bSuccess = TRUE;
2270 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2271 proxyBytesRequired + proxyBypassBytesRequired;
2273 break;
2275 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2277 ULONG conn = 2;
2278 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2279 if (*lpdwBufferLength < sizeof(ULONG))
2280 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2281 else
2283 memcpy(lpBuffer, &conn, sizeof(ULONG));
2284 bSuccess = TRUE;
2286 *lpdwBufferLength = sizeof(ULONG);
2287 break;
2289 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2291 ULONG conn = 4;
2292 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2293 if (*lpdwBufferLength < sizeof(ULONG))
2294 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2295 else
2297 memcpy(lpBuffer, &conn, sizeof(ULONG));
2298 bSuccess = TRUE;
2300 *lpdwBufferLength = sizeof(ULONG);
2301 break;
2303 case INTERNET_OPTION_SECURITY_FLAGS:
2304 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2305 bSuccess = TRUE;
2306 break;
2308 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2309 if (!lpwhh)
2311 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2312 return FALSE;
2314 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2316 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2317 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2319 else if (lpwhh->htype == WH_HHTTPREQ)
2321 LPWININETHTTPREQW lpwhr;
2322 PCCERT_CONTEXT context;
2324 lpwhr = (LPWININETHTTPREQW)lpwhh;
2325 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2326 if (context)
2328 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2329 DWORD strLen;
2331 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2332 info->ftExpiry = context->pCertInfo->NotAfter;
2333 info->ftStart = context->pCertInfo->NotBefore;
2334 if (bIsUnicode)
2336 strLen = CertNameToStrW(context->dwCertEncodingType,
2337 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2338 NULL, 0);
2339 info->lpszSubjectInfo = LocalAlloc(0,
2340 strLen * sizeof(WCHAR));
2341 if (info->lpszSubjectInfo)
2342 CertNameToStrW(context->dwCertEncodingType,
2343 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2344 info->lpszSubjectInfo, strLen);
2345 strLen = CertNameToStrW(context->dwCertEncodingType,
2346 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2347 NULL, 0);
2348 info->lpszIssuerInfo = LocalAlloc(0,
2349 strLen * sizeof(WCHAR));
2350 if (info->lpszIssuerInfo)
2351 CertNameToStrW(context->dwCertEncodingType,
2352 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2353 info->lpszIssuerInfo, strLen);
2355 else
2357 LPINTERNET_CERTIFICATE_INFOA infoA =
2358 (LPINTERNET_CERTIFICATE_INFOA)info;
2360 strLen = CertNameToStrA(context->dwCertEncodingType,
2361 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2362 NULL, 0);
2363 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2364 if (infoA->lpszSubjectInfo)
2365 CertNameToStrA(context->dwCertEncodingType,
2366 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2367 infoA->lpszSubjectInfo, strLen);
2368 strLen = CertNameToStrA(context->dwCertEncodingType,
2369 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2370 NULL, 0);
2371 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2372 if (infoA->lpszIssuerInfo)
2373 CertNameToStrA(context->dwCertEncodingType,
2374 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2375 infoA->lpszIssuerInfo, strLen);
2378 * Contrary to MSDN, these do not appear to be set.
2379 * lpszProtocolName
2380 * lpszSignatureAlgName
2381 * lpszEncryptionAlgName
2382 * dwKeySize
2384 CertFreeCertificateContext(context);
2385 bSuccess = TRUE;
2388 break;
2389 case INTERNET_OPTION_VERSION:
2391 TRACE("INTERNET_OPTION_VERSION\n");
2392 if (*lpdwBufferLength < sizeof(INTERNET_VERSION_INFO))
2393 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2394 else
2396 static const INTERNET_VERSION_INFO info = { 6, 0 };
2397 memcpy(lpBuffer, &info, sizeof(info));
2398 *lpdwBufferLength = sizeof(info);
2399 bSuccess = TRUE;
2401 break;
2403 default:
2404 FIXME("Stub! %d\n", dwOption);
2405 break;
2407 if (lpwhh)
2408 WININET_Release( lpwhh );
2410 return bSuccess;
2413 /***********************************************************************
2414 * InternetQueryOptionW (WININET.@)
2416 * Queries an options on the specified handle
2418 * RETURNS
2419 * TRUE on success
2420 * FALSE on failure
2423 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2424 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2426 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2429 /***********************************************************************
2430 * InternetQueryOptionA (WININET.@)
2432 * Queries an options on the specified handle
2434 * RETURNS
2435 * TRUE on success
2436 * FALSE on failure
2439 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2440 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2442 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2446 /***********************************************************************
2447 * InternetSetOptionW (WININET.@)
2449 * Sets an options on the specified handle
2451 * RETURNS
2452 * TRUE on success
2453 * FALSE on failure
2456 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2457 LPVOID lpBuffer, DWORD dwBufferLength)
2459 LPWININETHANDLEHEADER lpwhh;
2460 BOOL ret = TRUE;
2462 TRACE("0x%08x\n", dwOption);
2464 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2465 if( !lpwhh )
2466 return FALSE;
2468 switch (dwOption)
2470 case INTERNET_OPTION_CALLBACK:
2472 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2473 ret = (set_status_callback(lpwhh, callback, TRUE) != INTERNET_INVALID_STATUS_CALLBACK);
2474 break;
2476 case INTERNET_OPTION_HTTP_VERSION:
2478 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2479 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2481 break;
2482 case INTERNET_OPTION_ERROR_MASK:
2484 unsigned long flags=*(unsigned long*)lpBuffer;
2485 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2487 break;
2488 case INTERNET_OPTION_CODEPAGE:
2490 unsigned long codepage=*(unsigned long*)lpBuffer;
2491 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2493 break;
2494 case INTERNET_OPTION_REQUEST_PRIORITY:
2496 unsigned long priority=*(unsigned long*)lpBuffer;
2497 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2499 break;
2500 case INTERNET_OPTION_CONNECT_TIMEOUT:
2502 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2503 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2505 break;
2506 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2508 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2509 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2511 break;
2512 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2514 unsigned long conns=*(unsigned long*)lpBuffer;
2515 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2517 break;
2518 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2520 unsigned long conns=*(unsigned long*)lpBuffer;
2521 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2523 break;
2524 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2525 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2526 break;
2527 case INTERNET_OPTION_END_BROWSER_SESSION:
2528 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2529 break;
2530 case INTERNET_OPTION_CONNECTED_STATE:
2531 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2532 break;
2533 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2534 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2535 break;
2536 case INTERNET_OPTION_SEND_TIMEOUT:
2537 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2538 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2539 if (dwBufferLength == sizeof(DWORD))
2541 if (lpwhh->htype == WH_HHTTPREQ)
2542 ret = NETCON_set_timeout(
2543 &((LPWININETHTTPREQW)lpwhh)->netConnection,
2544 dwOption == INTERNET_OPTION_SEND_TIMEOUT,
2545 *(DWORD *)lpBuffer);
2546 else
2548 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2549 lpwhh->htype);
2552 else
2554 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2555 ret = FALSE;
2557 break;
2558 case INTERNET_OPTION_CONNECT_RETRIES:
2559 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2560 break;
2561 case INTERNET_OPTION_CONTEXT_VALUE:
2562 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2563 break;
2564 case INTERNET_OPTION_SECURITY_FLAGS:
2565 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2566 break;
2567 default:
2568 FIXME("Option %d STUB\n",dwOption);
2569 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2570 ret = FALSE;
2571 break;
2573 WININET_Release( lpwhh );
2575 return ret;
2579 /***********************************************************************
2580 * InternetSetOptionA (WININET.@)
2582 * Sets an options on the specified handle.
2584 * RETURNS
2585 * TRUE on success
2586 * FALSE on failure
2589 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2590 LPVOID lpBuffer, DWORD dwBufferLength)
2592 LPVOID wbuffer;
2593 DWORD wlen;
2594 BOOL r;
2596 switch( dwOption )
2598 case INTERNET_OPTION_CALLBACK:
2600 LPWININETHANDLEHEADER lpwh;
2601 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2603 if (!(lpwh = WININET_GetObject(hInternet))) return FALSE;
2604 r = (set_status_callback(lpwh, callback, FALSE) != INTERNET_INVALID_STATUS_CALLBACK);
2605 WININET_Release(lpwh);
2606 return r;
2608 case INTERNET_OPTION_PROXY:
2610 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2611 LPINTERNET_PROXY_INFOW piw;
2612 DWORD proxlen, prbylen;
2613 LPWSTR prox, prby;
2615 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2616 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2617 wlen = sizeof(*piw) + proxlen + prbylen;
2618 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2619 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2620 piw->dwAccessType = pi->dwAccessType;
2621 prox = (LPWSTR) &piw[1];
2622 prby = &prox[proxlen+1];
2623 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2624 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2625 piw->lpszProxy = prox;
2626 piw->lpszProxyBypass = prby;
2628 break;
2629 case INTERNET_OPTION_USER_AGENT:
2630 case INTERNET_OPTION_USERNAME:
2631 case INTERNET_OPTION_PASSWORD:
2632 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2633 NULL, 0 );
2634 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2635 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2636 wbuffer, wlen );
2637 break;
2638 default:
2639 wbuffer = lpBuffer;
2640 wlen = dwBufferLength;
2643 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2645 if( lpBuffer != wbuffer )
2646 HeapFree( GetProcessHeap(), 0, wbuffer );
2648 return r;
2652 /***********************************************************************
2653 * InternetSetOptionExA (WININET.@)
2655 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2656 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2658 FIXME("Flags %08x ignored\n", dwFlags);
2659 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2662 /***********************************************************************
2663 * InternetSetOptionExW (WININET.@)
2665 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2666 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2668 FIXME("Flags %08x ignored\n", dwFlags);
2669 if( dwFlags & ~ISO_VALID_FLAGS )
2671 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2672 return FALSE;
2674 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2677 static const WCHAR WININET_wkday[7][4] =
2678 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2679 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2680 static const WCHAR WININET_month[12][4] =
2681 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2682 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2683 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2685 /***********************************************************************
2686 * InternetTimeFromSystemTimeA (WININET.@)
2688 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2690 BOOL ret;
2691 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2693 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2695 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2696 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2698 return ret;
2701 /***********************************************************************
2702 * InternetTimeFromSystemTimeW (WININET.@)
2704 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2706 static const WCHAR date[] =
2707 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2708 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2710 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2712 if (!time || !string) return FALSE;
2714 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2715 return FALSE;
2717 sprintfW( string, date,
2718 WININET_wkday[time->wDayOfWeek],
2719 time->wDay,
2720 WININET_month[time->wMonth - 1],
2721 time->wYear,
2722 time->wHour,
2723 time->wMinute,
2724 time->wSecond );
2726 return TRUE;
2729 /***********************************************************************
2730 * InternetTimeToSystemTimeA (WININET.@)
2732 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2734 BOOL ret = FALSE;
2735 WCHAR *stringW;
2736 int len;
2738 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2740 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2741 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2743 if (stringW)
2745 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2746 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2747 HeapFree( GetProcessHeap(), 0, stringW );
2749 return ret;
2752 /***********************************************************************
2753 * InternetTimeToSystemTimeW (WININET.@)
2755 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2757 unsigned int i;
2758 const WCHAR *s = string;
2759 WCHAR *end;
2761 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2763 if (!string || !time) return FALSE;
2765 /* Windows does this too */
2766 GetSystemTime( time );
2768 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2769 * a SYSTEMTIME structure.
2772 while (*s && !isalphaW( *s )) s++;
2773 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2774 time->wDayOfWeek = 7;
2776 for (i = 0; i < 7; i++)
2778 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2779 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2780 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2782 time->wDayOfWeek = i;
2783 break;
2787 if (time->wDayOfWeek > 6) return TRUE;
2788 while (*s && !isdigitW( *s )) s++;
2789 time->wDay = strtolW( s, &end, 10 );
2790 s = end;
2792 while (*s && !isalphaW( *s )) s++;
2793 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2794 time->wMonth = 0;
2796 for (i = 0; i < 12; i++)
2798 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2799 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2800 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2802 time->wMonth = i + 1;
2803 break;
2806 if (time->wMonth == 0) return TRUE;
2808 while (*s && !isdigitW( *s )) s++;
2809 if (*s == '\0') return TRUE;
2810 time->wYear = strtolW( s, &end, 10 );
2811 s = end;
2813 while (*s && !isdigitW( *s )) s++;
2814 if (*s == '\0') return TRUE;
2815 time->wHour = strtolW( s, &end, 10 );
2816 s = end;
2818 while (*s && !isdigitW( *s )) s++;
2819 if (*s == '\0') return TRUE;
2820 time->wMinute = strtolW( s, &end, 10 );
2821 s = end;
2823 while (*s && !isdigitW( *s )) s++;
2824 if (*s == '\0') return TRUE;
2825 time->wSecond = strtolW( s, &end, 10 );
2826 s = end;
2828 time->wMilliseconds = 0;
2829 return TRUE;
2832 /***********************************************************************
2833 * InternetCheckConnectionW (WININET.@)
2835 * Pings a requested host to check internet connection
2837 * RETURNS
2838 * TRUE on success and FALSE on failure. If a failure then
2839 * ERROR_NOT_CONNECTED is placed into GetLastError
2842 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2845 * this is a kludge which runs the resident ping program and reads the output.
2847 * Anyone have a better idea?
2850 BOOL rc = FALSE;
2851 static const CHAR ping[] = "ping -c 1 ";
2852 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2853 CHAR *command = NULL;
2854 WCHAR hostW[1024];
2855 DWORD len;
2856 INTERNET_PORT port;
2857 int status = -1;
2859 FIXME("\n");
2862 * Crack or set the Address
2864 if (lpszUrl == NULL)
2867 * According to the doc we are supposed to use the ip for the next
2868 * server in the WnInet internal server database. I have
2869 * no idea what that is or how to get it.
2871 * So someone needs to implement this.
2873 FIXME("Unimplemented with URL of NULL\n");
2874 return TRUE;
2876 else
2878 URL_COMPONENTSW components;
2880 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2881 components.lpszHostName = (LPWSTR)&hostW;
2882 components.dwHostNameLength = 1024;
2884 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2885 goto End;
2887 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2888 port = components.nPort;
2889 TRACE("port: %d\n", port);
2892 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
2894 struct sockaddr_in sin;
2895 int fd;
2897 if (!GetAddress(hostW, port, &sin))
2898 goto End;
2899 fd = socket(sin.sin_family, SOCK_STREAM, 0);
2900 if (fd != -1)
2902 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == 0)
2903 rc = TRUE;
2904 close(fd);
2907 else
2910 * Build our ping command
2912 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2913 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2914 strcpy(command,ping);
2915 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2916 strcat(command,redirect);
2918 TRACE("Ping command is : %s\n",command);
2920 status = system(command);
2922 TRACE("Ping returned a code of %i\n",status);
2924 /* Ping return code of 0 indicates success */
2925 if (status == 0)
2926 rc = TRUE;
2929 End:
2931 HeapFree( GetProcessHeap(), 0, command );
2932 if (rc == FALSE)
2933 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2935 return rc;
2939 /***********************************************************************
2940 * InternetCheckConnectionA (WININET.@)
2942 * Pings a requested host to check internet connection
2944 * RETURNS
2945 * TRUE on success and FALSE on failure. If a failure then
2946 * ERROR_NOT_CONNECTED is placed into GetLastError
2949 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2951 WCHAR *szUrl;
2952 INT len;
2953 BOOL rc;
2955 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2956 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2957 return FALSE;
2958 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2959 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2960 HeapFree(GetProcessHeap(), 0, szUrl);
2962 return rc;
2966 /**********************************************************
2967 * INTERNET_InternetOpenUrlW (internal)
2969 * Opens an URL
2971 * RETURNS
2972 * handle of connection or NULL on failure
2974 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2975 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2977 URL_COMPONENTSW urlComponents;
2978 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2979 WCHAR password[1024], path[2048], extra[1024];
2980 HINTERNET client = NULL, client1 = NULL;
2982 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2983 dwHeadersLength, dwFlags, dwContext);
2985 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2986 urlComponents.lpszScheme = protocol;
2987 urlComponents.dwSchemeLength = 32;
2988 urlComponents.lpszHostName = hostName;
2989 urlComponents.dwHostNameLength = MAXHOSTNAME;
2990 urlComponents.lpszUserName = userName;
2991 urlComponents.dwUserNameLength = 1024;
2992 urlComponents.lpszPassword = password;
2993 urlComponents.dwPasswordLength = 1024;
2994 urlComponents.lpszUrlPath = path;
2995 urlComponents.dwUrlPathLength = 2048;
2996 urlComponents.lpszExtraInfo = extra;
2997 urlComponents.dwExtraInfoLength = 1024;
2998 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2999 return NULL;
3000 switch(urlComponents.nScheme) {
3001 case INTERNET_SCHEME_FTP:
3002 if(urlComponents.nPort == 0)
3003 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3004 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3005 userName, password, dwFlags, dwContext, INET_OPENURL);
3006 if(client == NULL)
3007 break;
3008 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3009 if(client1 == NULL) {
3010 InternetCloseHandle(client);
3011 break;
3013 break;
3015 case INTERNET_SCHEME_HTTP:
3016 case INTERNET_SCHEME_HTTPS: {
3017 static const WCHAR szStars[] = { '*','/','*', 0 };
3018 LPCWSTR accept[2] = { szStars, NULL };
3019 if(urlComponents.nPort == 0) {
3020 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3021 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3022 else
3023 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3025 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3026 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3027 userName, password, dwFlags, dwContext, INET_OPENURL);
3028 if(client == NULL)
3029 break;
3031 if (urlComponents.dwExtraInfoLength) {
3032 WCHAR *path_extra;
3033 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3035 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
3037 InternetCloseHandle(client);
3038 break;
3040 strcpyW(path_extra, urlComponents.lpszUrlPath);
3041 strcatW(path_extra, urlComponents.lpszExtraInfo);
3042 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3043 HeapFree(GetProcessHeap(), 0, path_extra);
3045 else
3046 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3048 if(client1 == NULL) {
3049 InternetCloseHandle(client);
3050 break;
3052 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3053 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3054 GetLastError() != ERROR_IO_PENDING) {
3055 InternetCloseHandle(client1);
3056 client1 = NULL;
3057 break;
3060 case INTERNET_SCHEME_GOPHER:
3061 /* gopher doesn't seem to be implemented in wine, but it's supposed
3062 * to be supported by InternetOpenUrlA. */
3063 default:
3064 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3065 break;
3068 TRACE(" %p <--\n", client1);
3070 return client1;
3073 /**********************************************************
3074 * InternetOpenUrlW (WININET.@)
3076 * Opens an URL
3078 * RETURNS
3079 * handle of connection or NULL on failure
3081 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3083 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3084 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
3086 TRACE("%p\n", hIC);
3088 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3089 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3090 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3091 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3094 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3095 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3097 HINTERNET ret = NULL;
3098 LPWININETAPPINFOW hIC = NULL;
3100 if (TRACE_ON(wininet)) {
3101 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3102 dwHeadersLength, dwFlags, dwContext);
3103 TRACE(" flags :");
3104 dump_INTERNET_FLAGS(dwFlags);
3107 if (!lpszUrl)
3109 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3110 goto lend;
3113 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
3114 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3115 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3116 goto lend;
3119 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3120 WORKREQUEST workRequest;
3121 struct WORKREQ_INTERNETOPENURLW *req;
3123 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3124 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3125 req = &workRequest.u.InternetOpenUrlW;
3126 req->lpszUrl = WININET_strdupW(lpszUrl);
3127 if (lpszHeaders)
3128 req->lpszHeaders = WININET_strdupW(lpszHeaders);
3129 else
3130 req->lpszHeaders = 0;
3131 req->dwHeadersLength = dwHeadersLength;
3132 req->dwFlags = dwFlags;
3133 req->dwContext = dwContext;
3135 INTERNET_AsyncCall(&workRequest);
3137 * This is from windows.
3139 INTERNET_SetLastError(ERROR_IO_PENDING);
3140 } else {
3141 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3144 lend:
3145 if( hIC )
3146 WININET_Release( &hIC->hdr );
3147 TRACE(" %p <--\n", ret);
3149 return ret;
3152 /**********************************************************
3153 * InternetOpenUrlA (WININET.@)
3155 * Opens an URL
3157 * RETURNS
3158 * handle of connection or NULL on failure
3160 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3161 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3163 HINTERNET rc = NULL;
3165 INT lenUrl;
3166 INT lenHeaders = 0;
3167 LPWSTR szUrl = NULL;
3168 LPWSTR szHeaders = NULL;
3170 TRACE("\n");
3172 if(lpszUrl) {
3173 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3174 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3175 if(!szUrl)
3176 return NULL;
3177 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3180 if(lpszHeaders) {
3181 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3182 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3183 if(!szHeaders) {
3184 HeapFree(GetProcessHeap(), 0, szUrl);
3185 return NULL;
3187 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3190 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3191 lenHeaders, dwFlags, dwContext);
3193 HeapFree(GetProcessHeap(), 0, szUrl);
3194 HeapFree(GetProcessHeap(), 0, szHeaders);
3196 return rc;
3200 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3202 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3204 if (lpwite)
3206 lpwite->dwError = 0;
3207 lpwite->response[0] = '\0';
3210 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3212 HeapFree(GetProcessHeap(), 0, lpwite);
3213 return NULL;
3216 return lpwite;
3220 /***********************************************************************
3221 * INTERNET_SetLastError (internal)
3223 * Set last thread specific error
3225 * RETURNS
3228 void INTERNET_SetLastError(DWORD dwError)
3230 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3232 if (!lpwite)
3233 lpwite = INTERNET_AllocThreadError();
3235 SetLastError(dwError);
3236 if(lpwite)
3237 lpwite->dwError = dwError;
3241 /***********************************************************************
3242 * INTERNET_GetLastError (internal)
3244 * Get last thread specific error
3246 * RETURNS
3249 DWORD INTERNET_GetLastError(void)
3251 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3252 if (!lpwite) return 0;
3253 /* TlsGetValue clears last error, so set it again here */
3254 SetLastError(lpwite->dwError);
3255 return lpwite->dwError;
3259 /***********************************************************************
3260 * INTERNET_WorkerThreadFunc (internal)
3262 * Worker thread execution function
3264 * RETURNS
3267 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3269 LPWORKREQUEST lpRequest = lpvParam;
3270 WORKREQUEST workRequest;
3272 TRACE("\n");
3274 memcpy(&workRequest, lpRequest, sizeof(WORKREQUEST));
3275 HeapFree(GetProcessHeap(), 0, lpRequest);
3277 workRequest.asyncproc(&workRequest);
3279 WININET_Release( workRequest.hdr );
3280 return TRUE;
3284 /***********************************************************************
3285 * INTERNET_AsyncCall (internal)
3287 * Retrieves work request from queue
3289 * RETURNS
3292 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3294 BOOL bSuccess;
3295 LPWORKREQUEST lpNewRequest;
3297 TRACE("\n");
3299 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3300 if (!lpNewRequest)
3301 return FALSE;
3303 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3305 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3306 if (!bSuccess)
3308 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3309 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3312 return bSuccess;
3316 /***********************************************************************
3317 * INTERNET_GetResponseBuffer (internal)
3319 * RETURNS
3322 LPSTR INTERNET_GetResponseBuffer(void)
3324 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3325 if (!lpwite)
3326 lpwite = INTERNET_AllocThreadError();
3327 TRACE("\n");
3328 return lpwite->response;
3331 /***********************************************************************
3332 * INTERNET_GetNextLine (internal)
3334 * Parse next line in directory string listing
3336 * RETURNS
3337 * Pointer to beginning of next line
3338 * NULL on failure
3342 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3344 struct timeval tv;
3345 fd_set infd;
3346 BOOL bSuccess = FALSE;
3347 INT nRecv = 0;
3348 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3350 TRACE("\n");
3352 FD_ZERO(&infd);
3353 FD_SET(nSocket, &infd);
3354 tv.tv_sec=RESPONSE_TIMEOUT;
3355 tv.tv_usec=0;
3357 while (nRecv < MAX_REPLY_LEN)
3359 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3361 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3363 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3364 goto lend;
3367 if (lpszBuffer[nRecv] == '\n')
3369 bSuccess = TRUE;
3370 break;
3372 if (lpszBuffer[nRecv] != '\r')
3373 nRecv++;
3375 else
3377 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3378 goto lend;
3382 lend:
3383 if (bSuccess)
3385 lpszBuffer[nRecv] = '\0';
3386 *dwLen = nRecv - 1;
3387 TRACE(":%d %s\n", nRecv, lpszBuffer);
3388 return lpszBuffer;
3390 else
3392 return NULL;
3396 /**********************************************************
3397 * InternetQueryDataAvailable (WININET.@)
3399 * Determines how much data is available to be read.
3401 * RETURNS
3402 * TRUE on success, FALSE if an error occurred. If
3403 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3404 * no data is presently available, FALSE is returned with
3405 * the last error ERROR_IO_PENDING; a callback with status
3406 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3407 * data is available.
3409 void AsyncInternetQueryDataAvailableProc(WORKREQUEST *workRequest)
3411 LPWININETHTTPREQW lpwhr;
3412 INTERNET_ASYNC_RESULT iar;
3413 char buffer[4048];
3415 TRACE("INTERNETQUERYDATAAVAILABLE %p\n", workRequest->hdr);
3417 switch (workRequest->hdr->htype)
3419 case WH_HHTTPREQ:
3420 lpwhr = (LPWININETHTTPREQW)workRequest->hdr;
3421 iar.dwResult = NETCON_recv(&lpwhr->netConnection, buffer,
3422 min(sizeof(buffer),
3423 lpwhr->dwContentLength - lpwhr->dwContentRead),
3424 MSG_PEEK, (int *)&iar.dwError);
3425 INTERNET_SendCallback(workRequest->hdr, workRequest->hdr->dwContext,
3426 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
3427 sizeof(INTERNET_ASYNC_RESULT));
3428 break;
3430 default:
3431 FIXME("unsupported file type\n");
3432 break;
3436 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3437 LPDWORD lpdwNumberOfBytesAvailble,
3438 DWORD dwFlags, DWORD_PTR dwContext)
3440 LPWININETHTTPREQW lpwhr;
3441 BOOL retval = FALSE;
3442 char buffer[4048];
3444 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3445 if (NULL == lpwhr)
3447 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
3448 return FALSE;
3451 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3453 switch (lpwhr->hdr.htype)
3455 case WH_HHTTPREQ:
3456 retval = TRUE;
3457 if (NETCON_query_data_available(&lpwhr->netConnection,
3458 lpdwNumberOfBytesAvailble) &&
3459 !*lpdwNumberOfBytesAvailble)
3461 /* Even if we are in async mode, we need to determine whether
3462 * there is actually more data available. We do this by trying
3463 * to peek only a single byte in async mode. */
3464 BOOL async = (lpwhr->lpHttpSession->lpAppInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC);
3465 if (NETCON_recv(&lpwhr->netConnection, buffer,
3466 min(async ? 1 : sizeof(buffer),
3467 lpwhr->dwContentLength - lpwhr->dwContentRead),
3468 MSG_PEEK, (int *)lpdwNumberOfBytesAvailble) &&
3469 async && *lpdwNumberOfBytesAvailble)
3471 WORKREQUEST workRequest;
3473 *lpdwNumberOfBytesAvailble = 0;
3474 workRequest.asyncproc = AsyncInternetQueryDataAvailableProc;
3475 workRequest.hdr = WININET_AddRef( &lpwhr->hdr );
3477 retval = INTERNET_AsyncCall(&workRequest);
3478 if (!retval)
3480 WININET_Release( &lpwhr->hdr );
3482 else
3484 INTERNET_SetLastError(ERROR_IO_PENDING);
3485 retval = FALSE;
3489 break;
3491 default:
3492 FIXME("unsupported file type\n");
3493 break;
3495 WININET_Release( &lpwhr->hdr );
3497 TRACE("<-- %i\n",retval);
3498 return retval;
3502 /***********************************************************************
3503 * InternetLockRequestFile (WININET.@)
3505 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3506 *lphLockReqHandle)
3508 FIXME("STUB\n");
3509 return FALSE;
3512 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3514 FIXME("STUB\n");
3515 return FALSE;
3519 /***********************************************************************
3520 * InternetAutodial (WININET.@)
3522 * On windows this function is supposed to dial the default internet
3523 * connection. We don't want to have Wine dial out to the internet so
3524 * we return TRUE by default. It might be nice to check if we are connected.
3526 * RETURNS
3527 * TRUE on success
3528 * FALSE on failure
3531 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3533 FIXME("STUB\n");
3535 /* Tell that we are connected to the internet. */
3536 return TRUE;
3539 /***********************************************************************
3540 * InternetAutodialHangup (WININET.@)
3542 * Hangs up a connection made with InternetAutodial
3544 * PARAM
3545 * dwReserved
3546 * RETURNS
3547 * TRUE on success
3548 * FALSE on failure
3551 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3553 FIXME("STUB\n");
3555 /* we didn't dial, we don't disconnect */
3556 return TRUE;
3559 /***********************************************************************
3560 * InternetCombineUrlA (WININET.@)
3562 * Combine a base URL with a relative URL
3564 * RETURNS
3565 * TRUE on success
3566 * FALSE on failure
3570 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3571 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3572 DWORD dwFlags)
3574 HRESULT hr=S_OK;
3576 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3578 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3579 dwFlags ^= ICU_NO_ENCODE;
3580 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3582 return (hr==S_OK);
3585 /***********************************************************************
3586 * InternetCombineUrlW (WININET.@)
3588 * Combine a base URL with a relative URL
3590 * RETURNS
3591 * TRUE on success
3592 * FALSE on failure
3596 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3597 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3598 DWORD dwFlags)
3600 HRESULT hr=S_OK;
3602 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3604 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3605 dwFlags ^= ICU_NO_ENCODE;
3606 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3608 return (hr==S_OK);
3611 /* max port num is 65535 => 5 digits */
3612 #define MAX_WORD_DIGITS 5
3614 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3615 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3616 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3617 (url)->dw##component##Length : strlen((url)->lpsz##component))
3619 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3621 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3622 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3623 return TRUE;
3624 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3625 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3626 return TRUE;
3627 if ((nScheme == INTERNET_SCHEME_FTP) &&
3628 (nPort == INTERNET_DEFAULT_FTP_PORT))
3629 return TRUE;
3630 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3631 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3632 return TRUE;
3634 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3635 return TRUE;
3637 return FALSE;
3640 /* opaque urls do not fit into the standard url hierarchy and don't have
3641 * two following slashes */
3642 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3644 return (nScheme != INTERNET_SCHEME_FTP) &&
3645 (nScheme != INTERNET_SCHEME_GOPHER) &&
3646 (nScheme != INTERNET_SCHEME_HTTP) &&
3647 (nScheme != INTERNET_SCHEME_HTTPS) &&
3648 (nScheme != INTERNET_SCHEME_FILE);
3651 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3653 int index;
3654 if (scheme < INTERNET_SCHEME_FIRST)
3655 return NULL;
3656 index = scheme - INTERNET_SCHEME_FIRST;
3657 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3658 return NULL;
3659 return (LPCWSTR)&url_schemes[index];
3662 /* we can calculate using ansi strings because we're just
3663 * calculating string length, not size
3665 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3666 LPDWORD lpdwUrlLength)
3668 INTERNET_SCHEME nScheme;
3670 *lpdwUrlLength = 0;
3672 if (lpUrlComponents->lpszScheme)
3674 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3675 *lpdwUrlLength += dwLen;
3676 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3678 else
3680 LPCWSTR scheme;
3682 nScheme = lpUrlComponents->nScheme;
3684 if (nScheme == INTERNET_SCHEME_DEFAULT)
3685 nScheme = INTERNET_SCHEME_HTTP;
3686 scheme = INTERNET_GetSchemeString(nScheme);
3687 *lpdwUrlLength += strlenW(scheme);
3690 (*lpdwUrlLength)++; /* ':' */
3691 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3692 *lpdwUrlLength += strlen("//");
3694 if (lpUrlComponents->lpszUserName)
3696 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3697 *lpdwUrlLength += strlen("@");
3699 else
3701 if (lpUrlComponents->lpszPassword)
3703 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3704 return FALSE;
3708 if (lpUrlComponents->lpszPassword)
3710 *lpdwUrlLength += strlen(":");
3711 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3714 if (lpUrlComponents->lpszHostName)
3716 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3718 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3720 char szPort[MAX_WORD_DIGITS+1];
3722 sprintf(szPort, "%d", lpUrlComponents->nPort);
3723 *lpdwUrlLength += strlen(szPort);
3724 *lpdwUrlLength += strlen(":");
3727 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3728 (*lpdwUrlLength)++; /* '/' */
3731 if (lpUrlComponents->lpszUrlPath)
3732 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3734 return TRUE;
3737 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3739 INT len;
3741 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3743 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3744 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3745 urlCompW->nScheme = lpUrlComponents->nScheme;
3746 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3747 urlCompW->nPort = lpUrlComponents->nPort;
3748 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3749 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3750 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3751 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3753 if (lpUrlComponents->lpszScheme)
3755 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3756 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3757 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3758 -1, urlCompW->lpszScheme, len);
3761 if (lpUrlComponents->lpszHostName)
3763 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3764 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3765 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3766 -1, urlCompW->lpszHostName, len);
3769 if (lpUrlComponents->lpszUserName)
3771 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3772 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3773 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3774 -1, urlCompW->lpszUserName, len);
3777 if (lpUrlComponents->lpszPassword)
3779 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3780 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3781 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3782 -1, urlCompW->lpszPassword, len);
3785 if (lpUrlComponents->lpszUrlPath)
3787 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3788 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3789 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3790 -1, urlCompW->lpszUrlPath, len);
3793 if (lpUrlComponents->lpszExtraInfo)
3795 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3796 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3797 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3798 -1, urlCompW->lpszExtraInfo, len);
3802 /***********************************************************************
3803 * InternetCreateUrlA (WININET.@)
3805 * See InternetCreateUrlW.
3807 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3808 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3810 BOOL ret;
3811 LPWSTR urlW = NULL;
3812 URL_COMPONENTSW urlCompW;
3814 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3816 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3818 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3819 return FALSE;
3822 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3824 if (lpszUrl)
3825 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3827 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3829 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3830 *lpdwUrlLength /= sizeof(WCHAR);
3832 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3833 * minus one, so add one to leave room for NULL terminator
3835 if (ret)
3836 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3838 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3839 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3840 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3841 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3842 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3843 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3844 HeapFree(GetProcessHeap(), 0, urlW);
3846 return ret;
3849 /***********************************************************************
3850 * InternetCreateUrlW (WININET.@)
3852 * Creates a URL from its component parts.
3854 * PARAMS
3855 * lpUrlComponents [I] URL Components.
3856 * dwFlags [I] Flags. See notes.
3857 * lpszUrl [I] Buffer in which to store the created URL.
3858 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3859 * lpszUrl in characters. On output, the number of bytes
3860 * required to store the URL including terminator.
3862 * NOTES
3864 * The dwFlags parameter can be zero or more of the following:
3865 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3867 * RETURNS
3868 * TRUE on success
3869 * FALSE on failure
3872 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3873 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3875 DWORD dwLen;
3876 INTERNET_SCHEME nScheme;
3878 static const WCHAR slashSlashW[] = {'/','/'};
3879 static const WCHAR percentD[] = {'%','d',0};
3881 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3883 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3885 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3886 return FALSE;
3889 if (!calc_url_length(lpUrlComponents, &dwLen))
3890 return FALSE;
3892 if (!lpszUrl || *lpdwUrlLength < dwLen)
3894 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3895 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3896 return FALSE;
3899 *lpdwUrlLength = dwLen;
3900 lpszUrl[0] = 0x00;
3902 dwLen = 0;
3904 if (lpUrlComponents->lpszScheme)
3906 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3907 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3908 lpszUrl += dwLen;
3910 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3912 else
3914 LPCWSTR scheme;
3915 nScheme = lpUrlComponents->nScheme;
3917 if (nScheme == INTERNET_SCHEME_DEFAULT)
3918 nScheme = INTERNET_SCHEME_HTTP;
3920 scheme = INTERNET_GetSchemeString(nScheme);
3921 dwLen = strlenW(scheme);
3922 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3923 lpszUrl += dwLen;
3926 /* all schemes are followed by at least a colon */
3927 *lpszUrl = ':';
3928 lpszUrl++;
3930 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3932 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3933 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3936 if (lpUrlComponents->lpszUserName)
3938 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3939 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3940 lpszUrl += dwLen;
3942 if (lpUrlComponents->lpszPassword)
3944 *lpszUrl = ':';
3945 lpszUrl++;
3947 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3948 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3949 lpszUrl += dwLen;
3952 *lpszUrl = '@';
3953 lpszUrl++;
3956 if (lpUrlComponents->lpszHostName)
3958 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3959 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3960 lpszUrl += dwLen;
3962 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3964 WCHAR szPort[MAX_WORD_DIGITS+1];
3966 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3967 *lpszUrl = ':';
3968 lpszUrl++;
3969 dwLen = strlenW(szPort);
3970 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3971 lpszUrl += dwLen;
3974 /* add slash between hostname and path if necessary */
3975 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3977 *lpszUrl = '/';
3978 lpszUrl++;
3983 if (lpUrlComponents->lpszUrlPath)
3985 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3986 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3987 lpszUrl += dwLen;
3990 *lpszUrl = '\0';
3992 return TRUE;
3995 /***********************************************************************
3996 * InternetConfirmZoneCrossingA (WININET.@)
3999 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4001 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4002 return ERROR_SUCCESS;
4005 /***********************************************************************
4006 * InternetConfirmZoneCrossingW (WININET.@)
4009 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4011 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4012 return ERROR_SUCCESS;
4015 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4016 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4018 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4019 lpdwConnection, dwReserved);
4020 return ERROR_SUCCESS;
4023 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4024 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4026 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4027 lpdwConnection, dwReserved);
4028 return ERROR_SUCCESS;
4031 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4033 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4034 return TRUE;
4037 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4039 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4040 return TRUE;
4043 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4045 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4046 return ERROR_SUCCESS;
4049 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4050 PBYTE pbHexHash )
4052 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4053 debugstr_w(pwszTarget), pbHexHash);
4054 return FALSE;
4057 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4059 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4060 return FALSE;
4063 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4065 FIXME("(%p, %08lx) stub\n", a, b);
4066 return 0;