push 014043c4937c940c54cd1214c96e33a3b3c8cf7d
[wine/hacks.git] / dlls / wininet / internet.c
blobdcddfd291d214114482632c8f14b5259f6030e17
1 /*
2 * Wininet
4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
10 * Ulrich Czekalla
11 * Aric Stewart
12 * David Hammerton
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "config.h"
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
34 #include <string.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
40 #endif
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
43 #endif
44 #include <stdlib.h>
45 #include <ctype.h>
46 #ifdef HAVE_UNISTD_H
47 # include <unistd.h>
48 #endif
49 #include <assert.h>
51 #include "windef.h"
52 #include "winbase.h"
53 #include "winreg.h"
54 #include "winuser.h"
55 #include "wininet.h"
56 #include "winineti.h"
57 #include "winnls.h"
58 #include "wine/debug.h"
59 #include "winerror.h"
60 #define NO_SHLWAPI_STREAM
61 #include "shlwapi.h"
62 #include "wincrypt.h"
64 #include "wine/exception.h"
66 #include "internet.h"
67 #include "resource.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define RESPONSE_TIMEOUT 30
75 typedef struct
77 DWORD dwError;
78 CHAR response[MAX_REPLY_LEN];
79 } WITHREADERROR, *LPWITHREADERROR;
81 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
82 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext);
84 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
85 static HMODULE WININET_hModule;
87 #define HANDLE_CHUNK_SIZE 0x10
89 static CRITICAL_SECTION WININET_cs;
90 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
92 0, 0, &WININET_cs,
93 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
94 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
96 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
98 static LPWININETHANDLEHEADER *WININET_Handles;
99 static UINT WININET_dwNextHandle;
100 static UINT WININET_dwMaxHandles;
102 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
104 LPWININETHANDLEHEADER *p;
105 UINT handle = 0, num;
107 list_init( &info->children );
109 EnterCriticalSection( &WININET_cs );
110 if( !WININET_dwMaxHandles )
112 num = HANDLE_CHUNK_SIZE;
113 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
114 sizeof (UINT)* num);
115 if( !p )
116 goto end;
117 WININET_Handles = p;
118 WININET_dwMaxHandles = num;
120 if( WININET_dwMaxHandles == WININET_dwNextHandle )
122 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
123 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
124 WININET_Handles, sizeof (UINT)* num);
125 if( !p )
126 goto end;
127 WININET_Handles = p;
128 WININET_dwMaxHandles = num;
131 handle = WININET_dwNextHandle;
132 if( WININET_Handles[handle] )
133 ERR("handle isn't free but should be\n");
134 WININET_Handles[handle] = WININET_AddRef( info );
136 while( WININET_Handles[WININET_dwNextHandle] &&
137 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
138 WININET_dwNextHandle++;
140 end:
141 LeaveCriticalSection( &WININET_cs );
143 return info->hInternet = (HINTERNET) (handle+1);
146 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
148 info->dwRefCount++;
149 TRACE("%p -> refcount = %d\n", info, info->dwRefCount );
150 return info;
153 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
155 LPWININETHANDLEHEADER info = NULL;
156 UINT handle = (UINT) hinternet;
158 EnterCriticalSection( &WININET_cs );
160 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
161 WININET_Handles[handle-1] )
162 info = WININET_AddRef( WININET_Handles[handle-1] );
164 LeaveCriticalSection( &WININET_cs );
166 TRACE("handle %d -> %p\n", handle, info);
168 return info;
171 BOOL WININET_Release( LPWININETHANDLEHEADER info )
173 info->dwRefCount--;
174 TRACE( "object %p refcount = %d\n", info, info->dwRefCount );
175 if( !info->dwRefCount )
177 if ( info->vtbl->CloseConnection )
179 TRACE( "closing connection %p\n", info);
180 info->vtbl->CloseConnection( info );
182 INTERNET_SendCallback(info, info->dwContext,
183 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
184 sizeof(HINTERNET));
185 TRACE( "destroying object %p\n", info);
186 if ( info->htype != WH_HINIT )
187 list_remove( &info->entry );
188 info->vtbl->Destroy( info );
190 return TRUE;
193 BOOL WININET_FreeHandle( HINTERNET hinternet )
195 BOOL ret = FALSE;
196 UINT handle = (UINT) hinternet;
197 LPWININETHANDLEHEADER info = NULL, child, next;
199 EnterCriticalSection( &WININET_cs );
201 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
203 handle--;
204 if( WININET_Handles[handle] )
206 info = WININET_Handles[handle];
207 TRACE( "destroying handle %d for object %p\n", handle+1, info);
208 WININET_Handles[handle] = NULL;
209 ret = TRUE;
213 LeaveCriticalSection( &WININET_cs );
215 /* As on native when the equivalent of WININET_Release is called, the handle
216 * is already invalid, but if a new handle is created at this time it does
217 * not yet get assigned the freed handle number */
218 if( info )
220 /* Free all children as native does */
221 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, WININETHANDLEHEADER, entry )
223 TRACE( "freeing child handle %d for parent handle %d\n",
224 (UINT)child->hInternet, handle+1);
225 WININET_FreeHandle( child->hInternet );
227 WININET_Release( info );
230 EnterCriticalSection( &WININET_cs );
232 if( WININET_dwNextHandle > handle && !WININET_Handles[handle] )
233 WININET_dwNextHandle = handle;
235 LeaveCriticalSection( &WININET_cs );
237 return ret;
240 /***********************************************************************
241 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
243 * PARAMS
244 * hinstDLL [I] handle to the DLL's instance
245 * fdwReason [I]
246 * lpvReserved [I] reserved, must be NULL
248 * RETURNS
249 * Success: TRUE
250 * Failure: FALSE
253 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
255 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
257 switch (fdwReason) {
258 case DLL_PROCESS_ATTACH:
260 g_dwTlsErrIndex = TlsAlloc();
262 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
263 return FALSE;
265 URLCacheContainers_CreateDefaults();
267 WININET_hModule = hinstDLL;
269 case DLL_THREAD_ATTACH:
270 break;
272 case DLL_THREAD_DETACH:
273 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
275 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
276 HeapFree(GetProcessHeap(), 0, lpwite);
278 break;
280 case DLL_PROCESS_DETACH:
282 URLCacheContainers_DeleteAll();
284 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
286 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
287 TlsFree(g_dwTlsErrIndex);
289 break;
292 return TRUE;
296 /***********************************************************************
297 * InternetInitializeAutoProxyDll (WININET.@)
299 * Setup the internal proxy
301 * PARAMETERS
302 * dwReserved
304 * RETURNS
305 * FALSE on failure
308 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
310 FIXME("STUB\n");
311 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
312 return FALSE;
315 /***********************************************************************
316 * DetectAutoProxyUrl (WININET.@)
318 * Auto detect the proxy url
320 * RETURNS
321 * FALSE on failure
324 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
325 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
327 FIXME("STUB\n");
328 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
329 return FALSE;
333 /***********************************************************************
334 * INTERNET_ConfigureProxyFromReg
336 * FIXME:
337 * The proxy may be specified in the form 'http=proxy.my.org'
338 * Presumably that means there can be ftp=ftpproxy.my.org too.
340 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
342 HKEY key;
343 DWORD r, keytype, len, enabled;
344 LPCSTR lpszInternetSettings =
345 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
346 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
348 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
349 if ( r != ERROR_SUCCESS )
350 return FALSE;
352 len = sizeof enabled;
353 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
354 (BYTE*)&enabled, &len);
355 if( (r == ERROR_SUCCESS) && enabled )
357 TRACE("Proxy is enabled.\n");
359 /* figure out how much memory the proxy setting takes */
360 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
361 NULL, &len);
362 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
364 LPWSTR szProxy, p;
365 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
367 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
368 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
369 (BYTE*)szProxy, &len);
371 /* find the http proxy, and strip away everything else */
372 p = strstrW( szProxy, szHttp );
373 if( p )
375 p += lstrlenW(szHttp);
376 lstrcpyW( szProxy, p );
378 p = strchrW( szProxy, ' ' );
379 if( p )
380 *p = 0;
382 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
383 lpwai->lpszProxy = szProxy;
385 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
387 else
388 ERR("Couldn't read proxy server settings.\n");
390 else
391 TRACE("Proxy is not enabled.\n");
392 RegCloseKey(key);
394 return enabled;
397 /***********************************************************************
398 * dump_INTERNET_FLAGS
400 * Helper function to TRACE the internet flags.
402 * RETURNS
403 * None
406 static void dump_INTERNET_FLAGS(DWORD dwFlags)
408 #define FE(x) { x, #x }
409 static const wininet_flag_info flag[] = {
410 FE(INTERNET_FLAG_RELOAD),
411 FE(INTERNET_FLAG_RAW_DATA),
412 FE(INTERNET_FLAG_EXISTING_CONNECT),
413 FE(INTERNET_FLAG_ASYNC),
414 FE(INTERNET_FLAG_PASSIVE),
415 FE(INTERNET_FLAG_NO_CACHE_WRITE),
416 FE(INTERNET_FLAG_MAKE_PERSISTENT),
417 FE(INTERNET_FLAG_FROM_CACHE),
418 FE(INTERNET_FLAG_SECURE),
419 FE(INTERNET_FLAG_KEEP_CONNECTION),
420 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
421 FE(INTERNET_FLAG_READ_PREFETCH),
422 FE(INTERNET_FLAG_NO_COOKIES),
423 FE(INTERNET_FLAG_NO_AUTH),
424 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
425 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
426 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
427 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
428 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
429 FE(INTERNET_FLAG_RESYNCHRONIZE),
430 FE(INTERNET_FLAG_HYPERLINK),
431 FE(INTERNET_FLAG_NO_UI),
432 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
433 FE(INTERNET_FLAG_CACHE_ASYNC),
434 FE(INTERNET_FLAG_FORMS_SUBMIT),
435 FE(INTERNET_FLAG_NEED_FILE),
436 FE(INTERNET_FLAG_TRANSFER_ASCII),
437 FE(INTERNET_FLAG_TRANSFER_BINARY)
439 #undef FE
440 int i;
442 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
443 if (flag[i].val & dwFlags) {
444 TRACE(" %s", flag[i].name);
445 dwFlags &= ~flag[i].val;
448 if (dwFlags)
449 TRACE(" Unknown flags (%08x)\n", dwFlags);
450 else
451 TRACE("\n");
454 /***********************************************************************
455 * INTERNET_CloseHandle (internal)
457 * Close internet handle
460 static VOID APPINFO_Destroy(WININETHANDLEHEADER *hdr)
462 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
464 TRACE("%p\n",lpwai);
466 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
467 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
468 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
469 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
470 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
471 HeapFree(GetProcessHeap(), 0, lpwai);
474 static const HANDLEHEADERVtbl APPINFOVtbl = {
475 APPINFO_Destroy,
476 NULL,
477 NULL,
478 NULL,
479 NULL,
480 NULL
484 /***********************************************************************
485 * InternetOpenW (WININET.@)
487 * Per-application initialization of wininet
489 * RETURNS
490 * HINTERNET on success
491 * NULL on failure
494 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
495 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
497 LPWININETAPPINFOW lpwai = NULL;
498 HINTERNET handle = NULL;
500 if (TRACE_ON(wininet)) {
501 #define FE(x) { x, #x }
502 static const wininet_flag_info access_type[] = {
503 FE(INTERNET_OPEN_TYPE_PRECONFIG),
504 FE(INTERNET_OPEN_TYPE_DIRECT),
505 FE(INTERNET_OPEN_TYPE_PROXY),
506 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
508 #undef FE
509 DWORD i;
510 const char *access_type_str = "Unknown";
512 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
513 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
514 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
515 if (access_type[i].val == dwAccessType) {
516 access_type_str = access_type[i].name;
517 break;
520 TRACE(" access type : %s\n", access_type_str);
521 TRACE(" flags :");
522 dump_INTERNET_FLAGS(dwFlags);
525 /* Clear any error information */
526 INTERNET_SetLastError(0);
528 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETAPPINFOW));
529 if (NULL == lpwai)
531 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
532 goto lend;
535 lpwai->hdr.htype = WH_HINIT;
536 lpwai->hdr.vtbl = &APPINFOVtbl;
537 lpwai->hdr.dwFlags = dwFlags;
538 lpwai->hdr.dwRefCount = 1;
539 lpwai->dwAccessType = dwAccessType;
540 lpwai->lpszProxyUsername = NULL;
541 lpwai->lpszProxyPassword = NULL;
543 handle = WININET_AllocHandle( &lpwai->hdr );
544 if( !handle )
546 HeapFree( GetProcessHeap(), 0, lpwai );
547 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
548 goto lend;
551 if (NULL != lpszAgent)
553 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
554 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
555 if (lpwai->lpszAgent)
556 lstrcpyW( lpwai->lpszAgent, lpszAgent );
558 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
559 INTERNET_ConfigureProxyFromReg( lpwai );
560 else if (NULL != lpszProxy)
562 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
563 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
564 if (lpwai->lpszProxy)
565 lstrcpyW( lpwai->lpszProxy, lpszProxy );
568 if (NULL != lpszProxyBypass)
570 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
571 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
572 if (lpwai->lpszProxyBypass)
573 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
576 lend:
577 if( lpwai )
578 WININET_Release( &lpwai->hdr );
580 TRACE("returning %p\n", lpwai);
582 return handle;
586 /***********************************************************************
587 * InternetOpenA (WININET.@)
589 * Per-application initialization of wininet
591 * RETURNS
592 * HINTERNET on success
593 * NULL on failure
596 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
597 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
599 HINTERNET rc = NULL;
600 INT len;
601 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
603 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
604 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
606 if( lpszAgent )
608 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
609 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
610 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
613 if( lpszProxy )
615 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
616 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
617 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
620 if( lpszProxyBypass )
622 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
623 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
624 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
627 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
629 HeapFree(GetProcessHeap(), 0, szAgent);
630 HeapFree(GetProcessHeap(), 0, szProxy);
631 HeapFree(GetProcessHeap(), 0, szBypass);
633 return rc;
636 /***********************************************************************
637 * InternetGetLastResponseInfoA (WININET.@)
639 * Return last wininet error description on the calling thread
641 * RETURNS
642 * TRUE on success of writing to buffer
643 * FALSE on failure
646 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
647 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
649 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
651 TRACE("\n");
653 if (lpwite)
655 *lpdwError = lpwite->dwError;
656 if (lpwite->dwError)
658 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
659 *lpdwBufferLength = strlen(lpszBuffer);
661 else
662 *lpdwBufferLength = 0;
664 else
666 *lpdwError = 0;
667 *lpdwBufferLength = 0;
670 return TRUE;
673 /***********************************************************************
674 * InternetGetLastResponseInfoW (WININET.@)
676 * Return last wininet error description on the calling thread
678 * RETURNS
679 * TRUE on success of writing to buffer
680 * FALSE on failure
683 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
684 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
686 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
688 TRACE("\n");
690 if (lpwite)
692 *lpdwError = lpwite->dwError;
693 if (lpwite->dwError)
695 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
696 *lpdwBufferLength = lstrlenW(lpszBuffer);
698 else
699 *lpdwBufferLength = 0;
701 else
703 *lpdwError = 0;
704 *lpdwBufferLength = 0;
707 return TRUE;
710 /***********************************************************************
711 * InternetGetConnectedState (WININET.@)
713 * Return connected state
715 * RETURNS
716 * TRUE if connected
717 * if lpdwStatus is not null, return the status (off line,
718 * modem, lan...) in it.
719 * FALSE if not connected
721 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
723 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
725 if (lpdwStatus) {
726 FIXME("always returning LAN connection.\n");
727 *lpdwStatus = INTERNET_CONNECTION_LAN;
729 return TRUE;
733 /***********************************************************************
734 * InternetGetConnectedStateExW (WININET.@)
736 * Return connected state
738 * PARAMS
740 * lpdwStatus [O] Flags specifying the status of the internet connection.
741 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
742 * dwNameLen [I] Size of the buffer, in characters.
743 * dwReserved [I] Reserved. Must be set to 0.
745 * RETURNS
746 * TRUE if connected
747 * if lpdwStatus is not null, return the status (off line,
748 * modem, lan...) in it.
749 * FALSE if not connected
751 * NOTES
752 * If the system has no available network connections, an empty string is
753 * stored in lpszConnectionName. If there is a LAN connection, a localized
754 * "LAN Connection" string is stored. Presumably, if only a dial-up
755 * connection is available then the name of the dial-up connection is
756 * returned. Why any application, other than the "Internet Settings" CPL,
757 * would want to use this function instead of the simpler InternetGetConnectedStateW
758 * function is beyond me.
760 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
761 DWORD dwNameLen, DWORD dwReserved)
763 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
765 /* Must be zero */
766 if(dwReserved)
767 return FALSE;
769 if (lpdwStatus) {
770 FIXME("always returning LAN connection.\n");
771 *lpdwStatus = INTERNET_CONNECTION_LAN;
773 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
777 /***********************************************************************
778 * InternetGetConnectedStateExA (WININET.@)
780 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
781 DWORD dwNameLen, DWORD dwReserved)
783 LPWSTR lpwszConnectionName = NULL;
784 BOOL rc;
786 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
788 if (lpszConnectionName && dwNameLen > 0)
789 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
791 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
792 dwReserved);
793 if (rc && lpwszConnectionName)
795 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
796 dwNameLen, NULL, NULL);
798 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
801 return rc;
805 /***********************************************************************
806 * InternetConnectW (WININET.@)
808 * Open a ftp, gopher or http session
810 * RETURNS
811 * HINTERNET a session handle on success
812 * NULL on failure
815 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
816 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
817 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
818 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
820 LPWININETAPPINFOW hIC;
821 HINTERNET rc = NULL;
823 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
824 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
825 dwService, dwFlags, dwContext);
827 if (!lpszServerName)
829 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
830 return NULL;
833 /* Clear any error information */
834 INTERNET_SetLastError(0);
835 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
836 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
838 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
839 goto lend;
842 switch (dwService)
844 case INTERNET_SERVICE_FTP:
845 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
846 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
847 break;
849 case INTERNET_SERVICE_HTTP:
850 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
851 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
852 break;
854 case INTERNET_SERVICE_GOPHER:
855 default:
856 break;
858 lend:
859 if( hIC )
860 WININET_Release( &hIC->hdr );
862 TRACE("returning %p\n", rc);
863 return rc;
867 /***********************************************************************
868 * InternetConnectA (WININET.@)
870 * Open a ftp, gopher or http session
872 * RETURNS
873 * HINTERNET a session handle on success
874 * NULL on failure
877 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
878 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
879 LPCSTR lpszUserName, LPCSTR lpszPassword,
880 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
882 HINTERNET rc = NULL;
883 INT len = 0;
884 LPWSTR szServerName = NULL;
885 LPWSTR szUserName = NULL;
886 LPWSTR szPassword = NULL;
888 if (lpszServerName)
890 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
891 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
892 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
894 if (lpszUserName)
896 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
897 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
898 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
900 if (lpszPassword)
902 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
903 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
904 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
908 rc = InternetConnectW(hInternet, szServerName, nServerPort,
909 szUserName, szPassword, dwService, dwFlags, dwContext);
911 HeapFree(GetProcessHeap(), 0, szServerName);
912 HeapFree(GetProcessHeap(), 0, szUserName);
913 HeapFree(GetProcessHeap(), 0, szPassword);
914 return rc;
918 /***********************************************************************
919 * InternetFindNextFileA (WININET.@)
921 * Continues a file search from a previous call to FindFirstFile
923 * RETURNS
924 * TRUE on success
925 * FALSE on failure
928 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
930 BOOL ret;
931 WIN32_FIND_DATAW fd;
933 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
934 if(lpvFindData)
935 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
936 return ret;
939 /***********************************************************************
940 * InternetFindNextFileW (WININET.@)
942 * Continues a file search from a previous call to FindFirstFile
944 * RETURNS
945 * TRUE on success
946 * FALSE on failure
949 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
951 WININETHANDLEHEADER *hdr;
952 DWORD res;
954 TRACE("\n");
956 hdr = WININET_GetObject(hFind);
957 if(!hdr) {
958 WARN("Invalid handle\n");
959 SetLastError(ERROR_INVALID_HANDLE);
960 return FALSE;
963 if(hdr->vtbl->FindNextFileW) {
964 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
965 }else {
966 WARN("Handle doesn't support NextFile\n");
967 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
970 WININET_Release(hdr);
972 if(res != ERROR_SUCCESS)
973 SetLastError(res);
974 return res == ERROR_SUCCESS;
977 /***********************************************************************
978 * InternetCloseHandle (WININET.@)
980 * Generic close handle function
982 * RETURNS
983 * TRUE on success
984 * FALSE on failure
987 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
989 LPWININETHANDLEHEADER lpwh;
991 TRACE("%p\n",hInternet);
993 lpwh = WININET_GetObject( hInternet );
994 if (NULL == lpwh)
996 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
997 return FALSE;
1000 WININET_Release( lpwh );
1001 WININET_FreeHandle( hInternet );
1003 return TRUE;
1007 /***********************************************************************
1008 * ConvertUrlComponentValue (Internal)
1010 * Helper function for InternetCrackUrlW
1013 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1014 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1015 LPCSTR lpszStart, LPCWSTR lpwszStart)
1017 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1018 if (*dwComponentLen != 0)
1020 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1021 if (*lppszComponent == NULL)
1023 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1024 if (lpwszComponent)
1025 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1026 else
1027 *lppszComponent = NULL;
1028 *dwComponentLen = nASCIILength;
1030 else
1032 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1033 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1034 (*lppszComponent)[ncpylen]=0;
1035 *dwComponentLen = ncpylen;
1041 /***********************************************************************
1042 * InternetCrackUrlA (WININET.@)
1044 * See InternetCrackUrlW.
1046 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1047 LPURL_COMPONENTSA lpUrlComponents)
1049 DWORD nLength;
1050 URL_COMPONENTSW UCW;
1051 WCHAR* lpwszUrl;
1053 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1055 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1056 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1058 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1059 return FALSE;
1062 if(dwUrlLength<=0)
1063 dwUrlLength=-1;
1064 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1066 /* if dwUrlLength=-1 then nLength includes null but length to
1067 InternetCrackUrlW should not include it */
1068 if (dwUrlLength == -1) nLength--;
1070 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1071 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1073 memset(&UCW,0,sizeof(UCW));
1074 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1075 if(lpUrlComponents->dwHostNameLength!=0)
1076 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1077 if(lpUrlComponents->dwUserNameLength!=0)
1078 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1079 if(lpUrlComponents->dwPasswordLength!=0)
1080 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1081 if(lpUrlComponents->dwUrlPathLength!=0)
1082 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1083 if(lpUrlComponents->dwSchemeLength!=0)
1084 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1085 if(lpUrlComponents->dwExtraInfoLength!=0)
1086 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1087 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1089 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1090 return FALSE;
1093 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1094 UCW.lpszHostName, UCW.dwHostNameLength,
1095 lpszUrl, lpwszUrl);
1096 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1097 UCW.lpszUserName, UCW.dwUserNameLength,
1098 lpszUrl, lpwszUrl);
1099 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1100 UCW.lpszPassword, UCW.dwPasswordLength,
1101 lpszUrl, lpwszUrl);
1102 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1103 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1104 lpszUrl, lpwszUrl);
1105 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1106 UCW.lpszScheme, UCW.dwSchemeLength,
1107 lpszUrl, lpwszUrl);
1108 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1109 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1110 lpszUrl, lpwszUrl);
1111 lpUrlComponents->nScheme=UCW.nScheme;
1112 lpUrlComponents->nPort=UCW.nPort;
1113 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1115 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1116 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1117 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1118 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1119 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1121 return TRUE;
1124 static const WCHAR url_schemes[][7] =
1126 {'f','t','p',0},
1127 {'g','o','p','h','e','r',0},
1128 {'h','t','t','p',0},
1129 {'h','t','t','p','s',0},
1130 {'f','i','l','e',0},
1131 {'n','e','w','s',0},
1132 {'m','a','i','l','t','o',0},
1133 {'r','e','s',0},
1136 /***********************************************************************
1137 * GetInternetSchemeW (internal)
1139 * Get scheme of url
1141 * RETURNS
1142 * scheme on success
1143 * INTERNET_SCHEME_UNKNOWN on failure
1146 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1148 int i;
1150 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1152 if(lpszScheme==NULL)
1153 return INTERNET_SCHEME_UNKNOWN;
1155 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1156 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1157 return INTERNET_SCHEME_FIRST + i;
1159 return INTERNET_SCHEME_UNKNOWN;
1162 /***********************************************************************
1163 * SetUrlComponentValueW (Internal)
1165 * Helper function for InternetCrackUrlW
1167 * PARAMS
1168 * lppszComponent [O] Holds the returned string
1169 * dwComponentLen [I] Holds the size of lppszComponent
1170 * [O] Holds the length of the string in lppszComponent without '\0'
1171 * lpszStart [I] Holds the string to copy from
1172 * len [I] Holds the length of lpszStart without '\0'
1174 * RETURNS
1175 * TRUE on success
1176 * FALSE on failure
1179 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1181 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1183 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1184 return FALSE;
1186 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1188 if (*lppszComponent == NULL)
1190 *lppszComponent = (LPWSTR)lpszStart;
1191 *dwComponentLen = len;
1193 else
1195 DWORD ncpylen = min((*dwComponentLen)-1, len);
1196 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1197 (*lppszComponent)[ncpylen] = '\0';
1198 *dwComponentLen = ncpylen;
1202 return TRUE;
1205 /***********************************************************************
1206 * InternetCrackUrlW (WININET.@)
1208 * Break up URL into its components
1210 * RETURNS
1211 * TRUE on success
1212 * FALSE on failure
1214 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1215 LPURL_COMPONENTSW lpUC)
1218 * RFC 1808
1219 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1222 LPCWSTR lpszParam = NULL;
1223 BOOL bIsAbsolute = FALSE;
1224 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1225 LPCWSTR lpszcp = NULL;
1226 LPWSTR lpszUrl_decode = NULL;
1227 DWORD dwUrlLength = dwUrlLength_orig;
1228 const WCHAR lpszSeparators[3]={';','?',0};
1229 const WCHAR lpszSlash[2]={'/',0};
1231 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1233 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1235 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1236 return FALSE;
1238 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1240 if (dwFlags & ICU_DECODE)
1242 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1243 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1245 lpszUrl = lpszUrl_decode;
1248 lpszap = lpszUrl;
1250 /* Determine if the URI is absolute. */
1251 while (*lpszap != '\0')
1253 if (isalnumW(*lpszap))
1255 lpszap++;
1256 continue;
1258 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1260 bIsAbsolute = TRUE;
1261 lpszcp = lpszap;
1263 else
1265 lpszcp = lpszUrl; /* Relative url */
1268 break;
1271 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1272 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1274 /* Parse <params> */
1275 lpszParam = strpbrkW(lpszap, lpszSeparators);
1276 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1277 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1279 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1281 LPCWSTR lpszNetLoc;
1283 /* Get scheme first. */
1284 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1285 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1286 lpszUrl, lpszcp - lpszUrl);
1288 /* Eat ':' in protocol. */
1289 lpszcp++;
1291 /* double slash indicates the net_loc portion is present */
1292 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1294 lpszcp += 2;
1296 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1297 if (lpszParam)
1299 if (lpszNetLoc)
1300 lpszNetLoc = min(lpszNetLoc, lpszParam);
1301 else
1302 lpszNetLoc = lpszParam;
1304 else if (!lpszNetLoc)
1305 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1307 /* Parse net-loc */
1308 if (lpszNetLoc)
1310 LPCWSTR lpszHost;
1311 LPCWSTR lpszPort;
1313 /* [<user>[<:password>]@]<host>[:<port>] */
1314 /* First find the user and password if they exist */
1316 lpszHost = strchrW(lpszcp, '@');
1317 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1319 /* username and password not specified. */
1320 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1321 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1323 else /* Parse out username and password */
1325 LPCWSTR lpszUser = lpszcp;
1326 LPCWSTR lpszPasswd = lpszHost;
1328 while (lpszcp < lpszHost)
1330 if (*lpszcp == ':')
1331 lpszPasswd = lpszcp;
1333 lpszcp++;
1336 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1337 lpszUser, lpszPasswd - lpszUser);
1339 if (lpszPasswd != lpszHost)
1340 lpszPasswd++;
1341 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1342 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1343 lpszHost - lpszPasswd);
1345 lpszcp++; /* Advance to beginning of host */
1348 /* Parse <host><:port> */
1350 lpszHost = lpszcp;
1351 lpszPort = lpszNetLoc;
1353 /* special case for res:// URLs: there is no port here, so the host is the
1354 entire string up to the first '/' */
1355 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1357 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1358 lpszHost, lpszPort - lpszHost);
1359 lpszcp=lpszNetLoc;
1361 else
1363 while (lpszcp < lpszNetLoc)
1365 if (*lpszcp == ':')
1366 lpszPort = lpszcp;
1368 lpszcp++;
1371 /* If the scheme is "file" and the host is just one letter, it's not a host */
1372 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1374 lpszcp=lpszHost;
1375 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1376 NULL, 0);
1378 else
1380 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1381 lpszHost, lpszPort - lpszHost);
1382 if (lpszPort != lpszNetLoc)
1383 lpUC->nPort = atoiW(++lpszPort);
1384 else switch (lpUC->nScheme)
1386 case INTERNET_SCHEME_HTTP:
1387 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1388 break;
1389 case INTERNET_SCHEME_HTTPS:
1390 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1391 break;
1392 case INTERNET_SCHEME_FTP:
1393 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1394 break;
1395 case INTERNET_SCHEME_GOPHER:
1396 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1397 break;
1398 default:
1399 break;
1405 else
1407 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1408 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1409 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1412 else
1414 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1415 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1416 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1417 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1420 /* Here lpszcp points to:
1422 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1423 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1425 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1427 INT len;
1429 /* Only truncate the parameter list if it's already been saved
1430 * in lpUC->lpszExtraInfo.
1432 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1433 len = lpszParam - lpszcp;
1434 else
1436 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1437 * newlines if necessary.
1439 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1440 if (lpsznewline != NULL)
1441 len = lpsznewline - lpszcp;
1442 else
1443 len = dwUrlLength-(lpszcp-lpszUrl);
1445 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1446 lpszcp, len);
1448 else
1450 lpUC->dwUrlPathLength = 0;
1453 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1454 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1455 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1456 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1457 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1459 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1460 return TRUE;
1463 /***********************************************************************
1464 * InternetAttemptConnect (WININET.@)
1466 * Attempt to make a connection to the internet
1468 * RETURNS
1469 * ERROR_SUCCESS on success
1470 * Error value on failure
1473 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1475 FIXME("Stub\n");
1476 return ERROR_SUCCESS;
1480 /***********************************************************************
1481 * InternetCanonicalizeUrlA (WININET.@)
1483 * Escape unsafe characters and spaces
1485 * RETURNS
1486 * TRUE on success
1487 * FALSE on failure
1490 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1491 LPDWORD lpdwBufferLength, DWORD dwFlags)
1493 HRESULT hr;
1494 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1496 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1497 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1499 if(dwFlags & ICU_DECODE)
1501 dwURLFlags |= URL_UNESCAPE;
1502 dwFlags &= ~ICU_DECODE;
1505 if(dwFlags & ICU_ESCAPE)
1507 dwURLFlags |= URL_UNESCAPE;
1508 dwFlags &= ~ICU_ESCAPE;
1511 if(dwFlags & ICU_BROWSER_MODE)
1513 dwURLFlags |= URL_BROWSER_MODE;
1514 dwFlags &= ~ICU_BROWSER_MODE;
1517 if(dwFlags & ICU_NO_ENCODE)
1519 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1520 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1521 dwFlags &= ~ICU_NO_ENCODE;
1524 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1526 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1527 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1528 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1530 return (hr == S_OK) ? TRUE : FALSE;
1533 /***********************************************************************
1534 * InternetCanonicalizeUrlW (WININET.@)
1536 * Escape unsafe characters and spaces
1538 * RETURNS
1539 * TRUE on success
1540 * FALSE on failure
1543 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1544 LPDWORD lpdwBufferLength, DWORD dwFlags)
1546 HRESULT hr;
1547 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1549 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1550 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1552 if(dwFlags & ICU_DECODE)
1554 dwURLFlags |= URL_UNESCAPE;
1555 dwFlags &= ~ICU_DECODE;
1558 if(dwFlags & ICU_ESCAPE)
1560 dwURLFlags |= URL_UNESCAPE;
1561 dwFlags &= ~ICU_ESCAPE;
1564 if(dwFlags & ICU_BROWSER_MODE)
1566 dwURLFlags |= URL_BROWSER_MODE;
1567 dwFlags &= ~ICU_BROWSER_MODE;
1570 if(dwFlags & ICU_NO_ENCODE)
1572 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1573 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1574 dwFlags &= ~ICU_NO_ENCODE;
1577 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1579 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1580 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1581 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1583 return (hr == S_OK) ? TRUE : FALSE;
1586 /* #################################################### */
1588 static INTERNET_STATUS_CALLBACK set_status_callback(
1589 LPWININETHANDLEHEADER lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1591 INTERNET_STATUS_CALLBACK ret;
1593 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1594 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1596 ret = lpwh->lpfnStatusCB;
1597 lpwh->lpfnStatusCB = callback;
1599 return ret;
1602 /***********************************************************************
1603 * InternetSetStatusCallbackA (WININET.@)
1605 * Sets up a callback function which is called as progress is made
1606 * during an operation.
1608 * RETURNS
1609 * Previous callback or NULL on success
1610 * INTERNET_INVALID_STATUS_CALLBACK on failure
1613 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1614 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1616 INTERNET_STATUS_CALLBACK retVal;
1617 LPWININETHANDLEHEADER lpwh;
1619 TRACE("0x%08x\n", (ULONG)hInternet);
1621 if (!(lpwh = WININET_GetObject(hInternet)))
1622 return INTERNET_INVALID_STATUS_CALLBACK;
1624 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1626 WININET_Release( lpwh );
1627 return retVal;
1630 /***********************************************************************
1631 * InternetSetStatusCallbackW (WININET.@)
1633 * Sets up a callback function which is called as progress is made
1634 * during an operation.
1636 * RETURNS
1637 * Previous callback or NULL on success
1638 * INTERNET_INVALID_STATUS_CALLBACK on failure
1641 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1642 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1644 INTERNET_STATUS_CALLBACK retVal;
1645 LPWININETHANDLEHEADER lpwh;
1647 TRACE("0x%08x\n", (ULONG)hInternet);
1649 if (!(lpwh = WININET_GetObject(hInternet)))
1650 return INTERNET_INVALID_STATUS_CALLBACK;
1652 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
1654 WININET_Release( lpwh );
1655 return retVal;
1658 /***********************************************************************
1659 * InternetSetFilePointer (WININET.@)
1661 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1662 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
1664 FIXME("stub\n");
1665 return FALSE;
1668 /***********************************************************************
1669 * InternetWriteFile (WININET.@)
1671 * Write data to an open internet file
1673 * RETURNS
1674 * TRUE on success
1675 * FALSE on failure
1678 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
1679 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1681 LPWININETHANDLEHEADER lpwh;
1682 BOOL retval = FALSE;
1684 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1686 lpwh = WININET_GetObject( hFile );
1688 if(lpwh && lpwh->vtbl->WriteFile) {
1689 retval = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1690 }else {
1691 WARN("Invalid handle\n");
1692 SetLastError(ERROR_INVALID_HANDLE);
1693 retval = FALSE;
1696 WININET_Release( lpwh );
1698 return retval;
1702 BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1703 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1704 BOOL bWait, BOOL bSendCompletionStatus)
1706 BOOL retval = FALSE;
1707 int nSocket = -1;
1708 int bytes_read;
1709 LPWININETHTTPREQW lpwhr;
1711 /* FIXME: this should use NETCON functions! */
1712 switch (lpwh->htype)
1714 case WH_HHTTPREQ:
1715 lpwhr = (LPWININETHTTPREQW)lpwh;
1717 if (!NETCON_recv(&lpwhr->netConnection, lpBuffer,
1718 min(dwNumOfBytesToRead, lpwhr->dwContentLength - lpwhr->dwContentRead),
1719 bWait ? MSG_WAITALL : 0, &bytes_read))
1722 if (((lpwhr->dwContentLength != -1) &&
1723 (lpwhr->dwContentRead != lpwhr->dwContentLength)))
1724 ERR("not all data received %d/%d\n", lpwhr->dwContentRead,
1725 lpwhr->dwContentLength);
1727 /* always returns TRUE, even if the network layer returns an
1728 * error */
1729 *pdwNumOfBytesRead = 0;
1730 HTTP_FinishedReading(lpwhr);
1731 retval = TRUE;
1733 else
1735 lpwhr->dwContentRead += bytes_read;
1736 *pdwNumOfBytesRead = bytes_read;
1738 if(lpwhr->lpszCacheFile) {
1739 BOOL res;
1741 res = WriteFile(lpwhr->hCacheFile, lpBuffer, bytes_read, NULL, NULL);
1742 if(!res)
1743 WARN("WriteFile failed: %u\n", GetLastError());
1746 if (!bytes_read && (lpwhr->dwContentRead == lpwhr->dwContentLength))
1747 retval = HTTP_FinishedReading(lpwhr);
1748 else
1749 retval = TRUE;
1751 break;
1753 case WH_HFILE:
1754 /* FIXME: FTP should use NETCON_ stuff */
1755 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1756 if (nSocket != -1)
1758 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1759 retval = (res >= 0);
1760 *pdwNumOfBytesRead = retval ? res : 0;
1762 break;
1764 default:
1765 break;
1768 if (bSendCompletionStatus)
1770 INTERNET_ASYNC_RESULT iar;
1772 iar.dwResult = retval;
1773 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1774 INTERNET_GetLastError();
1776 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1777 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1778 sizeof(INTERNET_ASYNC_RESULT));
1780 return retval;
1783 /***********************************************************************
1784 * InternetReadFile (WININET.@)
1786 * Read data from an open internet file
1788 * RETURNS
1789 * TRUE on success
1790 * FALSE on failure
1793 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1794 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1796 LPWININETHANDLEHEADER lpwh;
1797 BOOL retval;
1799 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1801 lpwh = WININET_GetObject( hFile );
1802 if (!lpwh)
1804 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1805 return FALSE;
1808 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1809 WININET_Release( lpwh );
1811 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1812 return retval;
1815 /***********************************************************************
1816 * InternetReadFileExA (WININET.@)
1818 * Read data from an open internet file
1820 * PARAMS
1821 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1822 * lpBuffersOut [I/O] Buffer.
1823 * dwFlags [I] Flags. See notes.
1824 * dwContext [I] Context for callbacks.
1826 * RETURNS
1827 * TRUE on success
1828 * FALSE on failure
1830 * NOTES
1831 * The parameter dwFlags include zero or more of the following flags:
1832 *|IRF_ASYNC - Makes the call asynchronous.
1833 *|IRF_SYNC - Makes the call synchronous.
1834 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1835 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1837 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1839 * SEE
1840 * InternetOpenUrlA(), HttpOpenRequestA()
1842 void AsyncInternetReadFileExProc(WORKREQUEST *workRequest)
1844 struct WORKREQ_INTERNETREADFILEEXA const *req = &workRequest->u.InternetReadFileExA;
1846 TRACE("INTERNETREADFILEEXA %p\n", workRequest->hdr);
1848 INTERNET_ReadFile(workRequest->hdr, req->lpBuffersOut->lpvBuffer,
1849 req->lpBuffersOut->dwBufferLength,
1850 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
1853 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1854 DWORD dwFlags, DWORD_PTR dwContext)
1856 BOOL retval = FALSE;
1857 LPWININETHANDLEHEADER lpwh;
1859 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1861 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1862 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1864 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1866 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1867 return FALSE;
1870 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1871 if (!lpwh)
1873 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1874 return FALSE;
1877 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1878 INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
1880 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1881 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1882 if (dwFlags & IRF_ASYNC)
1884 DWORD dwDataAvailable = 0;
1886 if (lpwh->htype == WH_HHTTPREQ)
1887 NETCON_query_data_available(&((LPWININETHTTPREQW)lpwh)->netConnection,
1888 &dwDataAvailable);
1890 if (!dwDataAvailable)
1892 WORKREQUEST workRequest;
1893 struct WORKREQ_INTERNETREADFILEEXA *req;
1895 workRequest.asyncproc = AsyncInternetReadFileExProc;
1896 workRequest.hdr = WININET_AddRef( lpwh );
1897 req = &workRequest.u.InternetReadFileExA;
1898 req->lpBuffersOut = lpBuffersOut;
1900 if (!INTERNET_AsyncCall(&workRequest))
1901 WININET_Release( lpwh );
1902 else
1903 INTERNET_SetLastError(ERROR_IO_PENDING);
1904 goto end;
1908 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1909 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1910 !(dwFlags & IRF_NO_WAIT), FALSE);
1912 if (retval)
1914 DWORD dwBytesReceived = lpBuffersOut->dwBufferLength;
1915 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1916 INTERNET_STATUS_RESPONSE_RECEIVED, &dwBytesReceived,
1917 sizeof(dwBytesReceived));
1920 end:
1921 WININET_Release( lpwh );
1923 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1924 return retval;
1927 /***********************************************************************
1928 * InternetReadFileExW (WININET.@)
1930 * Read data from an open internet file.
1932 * PARAMS
1933 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1934 * lpBuffersOut [I/O] Buffer.
1935 * dwFlags [I] Flags.
1936 * dwContext [I] Context for callbacks.
1938 * RETURNS
1939 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1941 * NOTES
1942 * Not implemented in Wine or native either (as of IE6 SP2).
1945 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1946 DWORD dwFlags, DWORD_PTR dwContext)
1948 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1950 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1951 return FALSE;
1954 /***********************************************************************
1955 * INET_QueryOptionHelper (internal)
1957 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1958 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1960 LPWININETHANDLEHEADER lpwhh;
1961 BOOL bSuccess = FALSE;
1963 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1965 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1967 switch (dwOption)
1969 case INTERNET_OPTION_HANDLE_TYPE:
1971 ULONG type;
1973 if (!lpwhh)
1975 WARN("Invalid hInternet handle\n");
1976 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1977 return FALSE;
1980 type = lpwhh->htype;
1982 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type);
1984 if (*lpdwBufferLength < sizeof(ULONG))
1985 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1986 else
1988 memcpy(lpBuffer, &type, sizeof(ULONG));
1989 bSuccess = TRUE;
1991 *lpdwBufferLength = sizeof(ULONG);
1992 break;
1995 case INTERNET_OPTION_REQUEST_FLAGS:
1997 ULONG flags = 4;
1998 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
1999 if (*lpdwBufferLength < sizeof(ULONG))
2000 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2001 else
2003 memcpy(lpBuffer, &flags, sizeof(ULONG));
2004 bSuccess = TRUE;
2006 *lpdwBufferLength = sizeof(ULONG);
2007 break;
2010 case INTERNET_OPTION_URL:
2012 TRACE("INTERNET_OPTION_URL\n");
2014 if (!lpwhh)
2016 WARN("Invalid hInternet handle\n");
2017 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2018 return FALSE;
2020 if (lpwhh->htype == WH_HHTTPREQ)
2022 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2023 WCHAR url[1023];
2024 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2025 static const WCHAR szHost[] = {'H','o','s','t',0};
2026 DWORD sizeRequired;
2027 LPHTTPHEADERW Host;
2029 Host = HTTP_GetHeader(lpreq,szHost);
2030 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2031 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2032 if(!bIsUnicode)
2034 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2035 lpBuffer,*lpdwBufferLength,NULL,NULL);
2036 if (sizeRequired > *lpdwBufferLength)
2037 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2038 else
2039 bSuccess = TRUE;
2040 *lpdwBufferLength = sizeRequired;
2042 else
2044 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2045 if (*lpdwBufferLength < sizeRequired)
2046 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2047 else
2049 strcpyW(lpBuffer, url);
2050 bSuccess = TRUE;
2052 *lpdwBufferLength = sizeRequired;
2055 break;
2058 case INTERNET_OPTION_DATAFILE_NAME:
2060 TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
2061 if (!lpwhh)
2063 WARN("Invalid hInternet handle\n");
2064 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2065 return FALSE;
2067 if (lpwhh->htype == WH_HHTTPREQ)
2069 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2070 DWORD size;
2072 if(!lpreq->lpszCacheFile) {
2073 *lpdwBufferLength = 0;
2074 INTERNET_SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
2076 else if(bIsUnicode)
2078 size = (lstrlenW(lpreq->lpszCacheFile)+1) * sizeof(WCHAR);
2079 if (*lpdwBufferLength < size)
2080 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2081 else
2083 memcpy(lpBuffer, lpreq->lpszCacheFile, size);
2084 bSuccess = TRUE;
2086 *lpdwBufferLength = size;
2088 else
2090 size = WideCharToMultiByte(CP_ACP, 0, lpreq->lpszCacheFile, -1, NULL, 0, NULL, NULL);
2091 if (size > *lpdwBufferLength) {
2092 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2093 }else {
2094 *lpdwBufferLength = WideCharToMultiByte(CP_ACP, 0, lpreq->lpszCacheFile,
2095 -1, lpBuffer, *lpdwBufferLength, NULL, NULL);
2096 bSuccess = TRUE;
2100 break;
2103 case INTERNET_OPTION_HTTP_VERSION:
2105 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2106 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2107 else
2110 * Presently hardcoded to 1.1
2112 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2113 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2114 bSuccess = TRUE;
2116 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2117 break;
2119 case INTERNET_OPTION_CONNECTED_STATE:
2121 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2122 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2124 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2125 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2126 else
2128 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2129 bSuccess = TRUE;
2131 *lpdwBufferLength = sizeof(*pdwConnectedState);
2132 break;
2134 case INTERNET_OPTION_PROXY:
2136 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2137 WININETAPPINFOW wai;
2139 if (lpwai == NULL)
2141 TRACE("Getting global proxy info\n");
2142 memset(&wai, 0, sizeof(WININETAPPINFOW));
2143 INTERNET_ConfigureProxyFromReg( &wai );
2144 lpwai = &wai;
2147 if (bIsUnicode)
2149 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2150 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2152 if (lpwai->lpszProxy)
2153 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2154 sizeof(WCHAR);
2155 if (lpwai->lpszProxyBypass)
2156 proxyBypassBytesRequired =
2157 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2158 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2159 proxyBytesRequired + proxyBypassBytesRequired)
2160 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2161 else
2163 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
2164 sizeof(INTERNET_PROXY_INFOW));
2165 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
2166 sizeof(INTERNET_PROXY_INFOW) +
2167 proxyBytesRequired);
2169 pPI->dwAccessType = lpwai->dwAccessType;
2170 pPI->lpszProxy = NULL;
2171 pPI->lpszProxyBypass = NULL;
2172 if (lpwai->lpszProxy)
2174 lstrcpyW(proxy, lpwai->lpszProxy);
2175 pPI->lpszProxy = proxy;
2178 if (lpwai->lpszProxyBypass)
2180 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
2181 pPI->lpszProxyBypass = proxy_bypass;
2183 bSuccess = TRUE;
2185 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2186 proxyBytesRequired + proxyBypassBytesRequired;
2188 else
2190 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2191 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2193 if (lpwai->lpszProxy)
2194 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2195 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2196 if (lpwai->lpszProxyBypass)
2197 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2198 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2199 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2200 proxyBytesRequired + proxyBypassBytesRequired)
2201 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2202 else
2204 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2205 sizeof(INTERNET_PROXY_INFOA));
2206 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2207 sizeof(INTERNET_PROXY_INFOA) +
2208 proxyBytesRequired);
2210 pPI->dwAccessType = lpwai->dwAccessType;
2211 pPI->lpszProxy = NULL;
2212 pPI->lpszProxyBypass = NULL;
2213 if (lpwai->lpszProxy)
2215 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2216 proxy, proxyBytesRequired, NULL, NULL);
2217 pPI->lpszProxy = proxy;
2220 if (lpwai->lpszProxyBypass)
2222 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2223 -1, proxy_bypass, proxyBypassBytesRequired,
2224 NULL, NULL);
2225 pPI->lpszProxyBypass = proxy_bypass;
2227 bSuccess = TRUE;
2229 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2230 proxyBytesRequired + proxyBypassBytesRequired;
2232 break;
2234 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2236 ULONG conn = 2;
2237 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2238 if (*lpdwBufferLength < sizeof(ULONG))
2239 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2240 else
2242 memcpy(lpBuffer, &conn, sizeof(ULONG));
2243 bSuccess = TRUE;
2245 *lpdwBufferLength = sizeof(ULONG);
2246 break;
2248 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2250 ULONG conn = 4;
2251 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2252 if (*lpdwBufferLength < sizeof(ULONG))
2253 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2254 else
2256 memcpy(lpBuffer, &conn, sizeof(ULONG));
2257 bSuccess = TRUE;
2259 *lpdwBufferLength = sizeof(ULONG);
2260 break;
2262 case INTERNET_OPTION_SECURITY_FLAGS:
2263 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2264 bSuccess = TRUE;
2265 break;
2267 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2268 if (!lpwhh)
2270 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2271 return FALSE;
2273 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2275 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2276 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2278 else if (lpwhh->htype == WH_HHTTPREQ)
2280 LPWININETHTTPREQW lpwhr;
2281 PCCERT_CONTEXT context;
2283 lpwhr = (LPWININETHTTPREQW)lpwhh;
2284 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2285 if (context)
2287 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2288 DWORD strLen;
2290 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2291 info->ftExpiry = context->pCertInfo->NotAfter;
2292 info->ftStart = context->pCertInfo->NotBefore;
2293 if (bIsUnicode)
2295 strLen = CertNameToStrW(context->dwCertEncodingType,
2296 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2297 NULL, 0);
2298 info->lpszSubjectInfo = LocalAlloc(0,
2299 strLen * sizeof(WCHAR));
2300 if (info->lpszSubjectInfo)
2301 CertNameToStrW(context->dwCertEncodingType,
2302 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2303 info->lpszSubjectInfo, strLen);
2304 strLen = CertNameToStrW(context->dwCertEncodingType,
2305 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2306 NULL, 0);
2307 info->lpszIssuerInfo = LocalAlloc(0,
2308 strLen * sizeof(WCHAR));
2309 if (info->lpszIssuerInfo)
2310 CertNameToStrW(context->dwCertEncodingType,
2311 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2312 info->lpszIssuerInfo, strLen);
2314 else
2316 LPINTERNET_CERTIFICATE_INFOA infoA =
2317 (LPINTERNET_CERTIFICATE_INFOA)info;
2319 strLen = CertNameToStrA(context->dwCertEncodingType,
2320 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2321 NULL, 0);
2322 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2323 if (infoA->lpszSubjectInfo)
2324 CertNameToStrA(context->dwCertEncodingType,
2325 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2326 infoA->lpszSubjectInfo, strLen);
2327 strLen = CertNameToStrA(context->dwCertEncodingType,
2328 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2329 NULL, 0);
2330 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2331 if (infoA->lpszIssuerInfo)
2332 CertNameToStrA(context->dwCertEncodingType,
2333 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2334 infoA->lpszIssuerInfo, strLen);
2337 * Contrary to MSDN, these do not appear to be set.
2338 * lpszProtocolName
2339 * lpszSignatureAlgName
2340 * lpszEncryptionAlgName
2341 * dwKeySize
2343 CertFreeCertificateContext(context);
2344 bSuccess = TRUE;
2347 break;
2348 case INTERNET_OPTION_VERSION:
2350 TRACE("INTERNET_OPTION_VERSION\n");
2351 if (*lpdwBufferLength < sizeof(INTERNET_VERSION_INFO))
2352 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2353 else
2355 static const INTERNET_VERSION_INFO info = { 1, 2 };
2356 memcpy(lpBuffer, &info, sizeof(info));
2357 *lpdwBufferLength = sizeof(info);
2358 bSuccess = TRUE;
2360 break;
2362 case INTERNET_OPTION_PER_CONNECTION_OPTION:
2363 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2364 if (*lpdwBufferLength < sizeof(INTERNET_PER_CONN_OPTION_LISTW))
2365 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2366 else
2368 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2369 int x;
2370 bSuccess = TRUE;
2371 for (x = 0; x < con->dwOptionCount; ++x)
2373 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + x;
2374 switch (option->dwOption)
2376 case INTERNET_PER_CONN_FLAGS:
2377 option->Value.dwValue = PROXY_TYPE_DIRECT;
2378 break;
2380 case INTERNET_PER_CONN_PROXY_SERVER:
2381 case INTERNET_PER_CONN_PROXY_BYPASS:
2382 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2383 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2384 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2385 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2386 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2387 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2388 FIXME("Unhandled dwOption %d\n", option->dwOption);
2389 option->Value.dwValue = 0;
2390 bSuccess = FALSE;
2391 break;
2393 default:
2394 FIXME("Unknown dwOption %d\n", option->dwOption);
2395 bSuccess = FALSE;
2396 break;
2399 if (!bSuccess)
2400 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2402 break;
2403 case 66:
2404 FIXME("66\n");
2405 bSuccess = TRUE;
2406 break;
2407 default:
2408 FIXME("Stub! %d\n", dwOption);
2409 break;
2411 if (lpwhh)
2412 WININET_Release( lpwhh );
2414 return bSuccess;
2417 /***********************************************************************
2418 * InternetQueryOptionW (WININET.@)
2420 * Queries an options on the specified handle
2422 * RETURNS
2423 * TRUE on success
2424 * FALSE on failure
2427 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2428 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2430 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2433 /***********************************************************************
2434 * InternetQueryOptionA (WININET.@)
2436 * Queries an options on the specified handle
2438 * RETURNS
2439 * TRUE on success
2440 * FALSE on failure
2443 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2444 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2446 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2450 /***********************************************************************
2451 * InternetSetOptionW (WININET.@)
2453 * Sets an options on the specified handle
2455 * RETURNS
2456 * TRUE on success
2457 * FALSE on failure
2460 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2461 LPVOID lpBuffer, DWORD dwBufferLength)
2463 LPWININETHANDLEHEADER lpwhh;
2464 BOOL ret = TRUE;
2466 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2468 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2469 if(lpwhh && lpwhh->vtbl->SetOption) {
2470 DWORD res;
2472 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2473 if(res != ERROR_INTERNET_INVALID_OPTION) {
2474 WININET_Release( lpwhh );
2476 if(res != ERROR_SUCCESS)
2477 SetLastError(res);
2479 return res == ERROR_SUCCESS;
2483 switch (dwOption)
2485 case INTERNET_OPTION_CALLBACK:
2487 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2488 ret = (set_status_callback(lpwhh, callback, TRUE) != INTERNET_INVALID_STATUS_CALLBACK);
2489 break;
2491 case INTERNET_OPTION_HTTP_VERSION:
2493 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2494 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2496 break;
2497 case INTERNET_OPTION_ERROR_MASK:
2499 unsigned long flags=*(unsigned long*)lpBuffer;
2500 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2502 break;
2503 case INTERNET_OPTION_CODEPAGE:
2505 unsigned long codepage=*(unsigned long*)lpBuffer;
2506 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2508 break;
2509 case INTERNET_OPTION_REQUEST_PRIORITY:
2511 unsigned long priority=*(unsigned long*)lpBuffer;
2512 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2514 break;
2515 case INTERNET_OPTION_CONNECT_TIMEOUT:
2517 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2518 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2520 break;
2521 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2523 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2524 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2526 break;
2527 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2529 unsigned long conns=*(unsigned long*)lpBuffer;
2530 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2532 break;
2533 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2535 unsigned long conns=*(unsigned long*)lpBuffer;
2536 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2538 break;
2539 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2540 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2541 break;
2542 case INTERNET_OPTION_END_BROWSER_SESSION:
2543 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2544 break;
2545 case INTERNET_OPTION_CONNECTED_STATE:
2546 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2547 break;
2548 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2549 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2550 break;
2551 case INTERNET_OPTION_SEND_TIMEOUT:
2552 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2553 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2554 break;
2555 case INTERNET_OPTION_CONNECT_RETRIES:
2556 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2557 break;
2558 case INTERNET_OPTION_CONTEXT_VALUE:
2559 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2560 break;
2561 case INTERNET_OPTION_SECURITY_FLAGS:
2562 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2563 break;
2564 case 86:
2565 FIXME("86\n");
2566 break;
2567 default:
2568 FIXME("Option %d STUB\n",dwOption);
2569 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2570 ret = FALSE;
2571 break;
2574 if(lpwhh)
2575 WININET_Release( lpwhh );
2577 return ret;
2581 /***********************************************************************
2582 * InternetSetOptionA (WININET.@)
2584 * Sets an options on the specified handle.
2586 * RETURNS
2587 * TRUE on success
2588 * FALSE on failure
2591 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2592 LPVOID lpBuffer, DWORD dwBufferLength)
2594 LPVOID wbuffer;
2595 DWORD wlen;
2596 BOOL r;
2598 switch( dwOption )
2600 case INTERNET_OPTION_CALLBACK:
2602 LPWININETHANDLEHEADER lpwh;
2603 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2605 if (!(lpwh = WININET_GetObject(hInternet))) return FALSE;
2606 r = (set_status_callback(lpwh, callback, FALSE) != INTERNET_INVALID_STATUS_CALLBACK);
2607 WININET_Release(lpwh);
2608 return r;
2610 case INTERNET_OPTION_PROXY:
2612 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2613 LPINTERNET_PROXY_INFOW piw;
2614 DWORD proxlen, prbylen;
2615 LPWSTR prox, prby;
2617 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2618 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2619 wlen = sizeof(*piw) + proxlen + prbylen;
2620 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2621 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2622 piw->dwAccessType = pi->dwAccessType;
2623 prox = (LPWSTR) &piw[1];
2624 prby = &prox[proxlen+1];
2625 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2626 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2627 piw->lpszProxy = prox;
2628 piw->lpszProxyBypass = prby;
2630 break;
2631 case INTERNET_OPTION_USER_AGENT:
2632 case INTERNET_OPTION_USERNAME:
2633 case INTERNET_OPTION_PASSWORD:
2634 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2635 NULL, 0 );
2636 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2637 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2638 wbuffer, wlen );
2639 break;
2640 default:
2641 wbuffer = lpBuffer;
2642 wlen = dwBufferLength;
2645 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2647 if( lpBuffer != wbuffer )
2648 HeapFree( GetProcessHeap(), 0, wbuffer );
2650 return r;
2654 /***********************************************************************
2655 * InternetSetOptionExA (WININET.@)
2657 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2658 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2660 FIXME("Flags %08x ignored\n", dwFlags);
2661 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2664 /***********************************************************************
2665 * InternetSetOptionExW (WININET.@)
2667 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2668 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2670 FIXME("Flags %08x ignored\n", dwFlags);
2671 if( dwFlags & ~ISO_VALID_FLAGS )
2673 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2674 return FALSE;
2676 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2679 static const WCHAR WININET_wkday[7][4] =
2680 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2681 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2682 static const WCHAR WININET_month[12][4] =
2683 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2684 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2685 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2687 /***********************************************************************
2688 * InternetTimeFromSystemTimeA (WININET.@)
2690 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2692 BOOL ret;
2693 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2695 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2697 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2698 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2700 return ret;
2703 /***********************************************************************
2704 * InternetTimeFromSystemTimeW (WININET.@)
2706 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2708 static const WCHAR date[] =
2709 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2710 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2712 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2714 if (!time || !string) return FALSE;
2716 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2717 return FALSE;
2719 sprintfW( string, date,
2720 WININET_wkday[time->wDayOfWeek],
2721 time->wDay,
2722 WININET_month[time->wMonth - 1],
2723 time->wYear,
2724 time->wHour,
2725 time->wMinute,
2726 time->wSecond );
2728 return TRUE;
2731 /***********************************************************************
2732 * InternetTimeToSystemTimeA (WININET.@)
2734 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2736 BOOL ret = FALSE;
2737 WCHAR *stringW;
2738 int len;
2740 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2742 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2743 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2745 if (stringW)
2747 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2748 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2749 HeapFree( GetProcessHeap(), 0, stringW );
2751 return ret;
2754 /***********************************************************************
2755 * InternetTimeToSystemTimeW (WININET.@)
2757 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2759 unsigned int i;
2760 const WCHAR *s = string;
2761 WCHAR *end;
2763 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2765 if (!string || !time) return FALSE;
2767 /* Windows does this too */
2768 GetSystemTime( time );
2770 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2771 * a SYSTEMTIME structure.
2774 while (*s && !isalphaW( *s )) s++;
2775 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2776 time->wDayOfWeek = 7;
2778 for (i = 0; i < 7; i++)
2780 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2781 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2782 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2784 time->wDayOfWeek = i;
2785 break;
2789 if (time->wDayOfWeek > 6) return TRUE;
2790 while (*s && !isdigitW( *s )) s++;
2791 time->wDay = strtolW( s, &end, 10 );
2792 s = end;
2794 while (*s && !isalphaW( *s )) s++;
2795 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2796 time->wMonth = 0;
2798 for (i = 0; i < 12; i++)
2800 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2801 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2802 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2804 time->wMonth = i + 1;
2805 break;
2808 if (time->wMonth == 0) return TRUE;
2810 while (*s && !isdigitW( *s )) s++;
2811 if (*s == '\0') return TRUE;
2812 time->wYear = strtolW( s, &end, 10 );
2813 s = end;
2815 while (*s && !isdigitW( *s )) s++;
2816 if (*s == '\0') return TRUE;
2817 time->wHour = strtolW( s, &end, 10 );
2818 s = end;
2820 while (*s && !isdigitW( *s )) s++;
2821 if (*s == '\0') return TRUE;
2822 time->wMinute = strtolW( s, &end, 10 );
2823 s = end;
2825 while (*s && !isdigitW( *s )) s++;
2826 if (*s == '\0') return TRUE;
2827 time->wSecond = strtolW( s, &end, 10 );
2828 s = end;
2830 time->wMilliseconds = 0;
2831 return TRUE;
2834 /***********************************************************************
2835 * InternetCheckConnectionW (WININET.@)
2837 * Pings a requested host to check internet connection
2839 * RETURNS
2840 * TRUE on success and FALSE on failure. If a failure then
2841 * ERROR_NOT_CONNECTED is placed into GetLastError
2844 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2847 * this is a kludge which runs the resident ping program and reads the output.
2849 * Anyone have a better idea?
2852 BOOL rc = FALSE;
2853 static const CHAR ping[] = "ping -c 1 ";
2854 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2855 CHAR *command = NULL;
2856 WCHAR hostW[1024];
2857 DWORD len;
2858 INTERNET_PORT port;
2859 int status = -1;
2861 FIXME("\n");
2864 * Crack or set the Address
2866 if (lpszUrl == NULL)
2869 * According to the doc we are supposed to use the ip for the next
2870 * server in the WnInet internal server database. I have
2871 * no idea what that is or how to get it.
2873 * So someone needs to implement this.
2875 FIXME("Unimplemented with URL of NULL\n");
2876 return TRUE;
2878 else
2880 URL_COMPONENTSW components;
2882 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2883 components.lpszHostName = (LPWSTR)&hostW;
2884 components.dwHostNameLength = 1024;
2886 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2887 goto End;
2889 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2890 port = components.nPort;
2891 TRACE("port: %d\n", port);
2894 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
2896 struct sockaddr_in sin;
2897 int fd;
2899 if (!GetAddress(hostW, port, &sin))
2900 goto End;
2901 fd = socket(sin.sin_family, SOCK_STREAM, 0);
2902 if (fd != -1)
2904 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == 0)
2905 rc = TRUE;
2906 close(fd);
2909 else
2912 * Build our ping command
2914 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2915 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2916 strcpy(command,ping);
2917 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2918 strcat(command,redirect);
2920 TRACE("Ping command is : %s\n",command);
2922 status = system(command);
2924 TRACE("Ping returned a code of %i\n",status);
2926 /* Ping return code of 0 indicates success */
2927 if (status == 0)
2928 rc = TRUE;
2931 End:
2933 HeapFree( GetProcessHeap(), 0, command );
2934 if (rc == FALSE)
2935 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2937 return rc;
2941 /***********************************************************************
2942 * InternetCheckConnectionA (WININET.@)
2944 * Pings a requested host to check internet connection
2946 * RETURNS
2947 * TRUE on success and FALSE on failure. If a failure then
2948 * ERROR_NOT_CONNECTED is placed into GetLastError
2951 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2953 WCHAR *szUrl;
2954 INT len;
2955 BOOL rc;
2957 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2958 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2959 return FALSE;
2960 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2961 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2962 HeapFree(GetProcessHeap(), 0, szUrl);
2964 return rc;
2968 /**********************************************************
2969 * INTERNET_InternetOpenUrlW (internal)
2971 * Opens an URL
2973 * RETURNS
2974 * handle of connection or NULL on failure
2976 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2977 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2979 URL_COMPONENTSW urlComponents;
2980 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2981 WCHAR password[1024], path[2048], extra[1024];
2982 HINTERNET client = NULL, client1 = NULL;
2984 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2985 dwHeadersLength, dwFlags, dwContext);
2987 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2988 urlComponents.lpszScheme = protocol;
2989 urlComponents.dwSchemeLength = 32;
2990 urlComponents.lpszHostName = hostName;
2991 urlComponents.dwHostNameLength = MAXHOSTNAME;
2992 urlComponents.lpszUserName = userName;
2993 urlComponents.dwUserNameLength = 1024;
2994 urlComponents.lpszPassword = password;
2995 urlComponents.dwPasswordLength = 1024;
2996 urlComponents.lpszUrlPath = path;
2997 urlComponents.dwUrlPathLength = 2048;
2998 urlComponents.lpszExtraInfo = extra;
2999 urlComponents.dwExtraInfoLength = 1024;
3000 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3001 return NULL;
3002 switch(urlComponents.nScheme) {
3003 case INTERNET_SCHEME_FTP:
3004 if(urlComponents.nPort == 0)
3005 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3006 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3007 userName, password, dwFlags, dwContext, INET_OPENURL);
3008 if(client == NULL)
3009 break;
3010 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3011 if(client1 == NULL) {
3012 InternetCloseHandle(client);
3013 break;
3015 break;
3017 case INTERNET_SCHEME_HTTP:
3018 case INTERNET_SCHEME_HTTPS: {
3019 static const WCHAR szStars[] = { '*','/','*', 0 };
3020 LPCWSTR accept[2] = { szStars, NULL };
3021 if(urlComponents.nPort == 0) {
3022 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3023 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3024 else
3025 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3027 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3028 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3029 userName, password, dwFlags, dwContext, INET_OPENURL);
3030 if(client == NULL)
3031 break;
3033 if (urlComponents.dwExtraInfoLength) {
3034 WCHAR *path_extra;
3035 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3037 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
3039 InternetCloseHandle(client);
3040 break;
3042 strcpyW(path_extra, urlComponents.lpszUrlPath);
3043 strcatW(path_extra, urlComponents.lpszExtraInfo);
3044 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3045 HeapFree(GetProcessHeap(), 0, path_extra);
3047 else
3048 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3050 if(client1 == NULL) {
3051 InternetCloseHandle(client);
3052 break;
3054 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3055 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3056 GetLastError() != ERROR_IO_PENDING) {
3057 InternetCloseHandle(client1);
3058 client1 = NULL;
3059 break;
3062 case INTERNET_SCHEME_GOPHER:
3063 /* gopher doesn't seem to be implemented in wine, but it's supposed
3064 * to be supported by InternetOpenUrlA. */
3065 default:
3066 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3067 break;
3070 TRACE(" %p <--\n", client1);
3072 return client1;
3075 /**********************************************************
3076 * InternetOpenUrlW (WININET.@)
3078 * Opens an URL
3080 * RETURNS
3081 * handle of connection or NULL on failure
3083 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3085 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3086 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
3088 TRACE("%p\n", hIC);
3090 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3091 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3092 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3093 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3096 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3097 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3099 HINTERNET ret = NULL;
3100 LPWININETAPPINFOW hIC = NULL;
3102 if (TRACE_ON(wininet)) {
3103 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3104 dwHeadersLength, dwFlags, dwContext);
3105 TRACE(" flags :");
3106 dump_INTERNET_FLAGS(dwFlags);
3109 if (!lpszUrl)
3111 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3112 goto lend;
3115 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
3116 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3117 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3118 goto lend;
3121 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3122 WORKREQUEST workRequest;
3123 struct WORKREQ_INTERNETOPENURLW *req;
3125 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3126 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3127 req = &workRequest.u.InternetOpenUrlW;
3128 req->lpszUrl = WININET_strdupW(lpszUrl);
3129 if (lpszHeaders)
3130 req->lpszHeaders = WININET_strdupW(lpszHeaders);
3131 else
3132 req->lpszHeaders = 0;
3133 req->dwHeadersLength = dwHeadersLength;
3134 req->dwFlags = dwFlags;
3135 req->dwContext = dwContext;
3137 INTERNET_AsyncCall(&workRequest);
3139 * This is from windows.
3141 INTERNET_SetLastError(ERROR_IO_PENDING);
3142 } else {
3143 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3146 lend:
3147 if( hIC )
3148 WININET_Release( &hIC->hdr );
3149 TRACE(" %p <--\n", ret);
3151 return ret;
3154 /**********************************************************
3155 * InternetOpenUrlA (WININET.@)
3157 * Opens an URL
3159 * RETURNS
3160 * handle of connection or NULL on failure
3162 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3163 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3165 HINTERNET rc = NULL;
3167 INT lenUrl;
3168 INT lenHeaders = 0;
3169 LPWSTR szUrl = NULL;
3170 LPWSTR szHeaders = NULL;
3172 TRACE("\n");
3174 if(lpszUrl) {
3175 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3176 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3177 if(!szUrl)
3178 return NULL;
3179 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3182 if(lpszHeaders) {
3183 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3184 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3185 if(!szHeaders) {
3186 HeapFree(GetProcessHeap(), 0, szUrl);
3187 return NULL;
3189 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3192 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3193 lenHeaders, dwFlags, dwContext);
3195 HeapFree(GetProcessHeap(), 0, szUrl);
3196 HeapFree(GetProcessHeap(), 0, szHeaders);
3198 return rc;
3202 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3204 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3206 if (lpwite)
3208 lpwite->dwError = 0;
3209 lpwite->response[0] = '\0';
3212 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3214 HeapFree(GetProcessHeap(), 0, lpwite);
3215 return NULL;
3218 return lpwite;
3222 /***********************************************************************
3223 * INTERNET_SetLastError (internal)
3225 * Set last thread specific error
3227 * RETURNS
3230 void INTERNET_SetLastError(DWORD dwError)
3232 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3234 if (!lpwite)
3235 lpwite = INTERNET_AllocThreadError();
3237 SetLastError(dwError);
3238 if(lpwite)
3239 lpwite->dwError = dwError;
3243 /***********************************************************************
3244 * INTERNET_GetLastError (internal)
3246 * Get last thread specific error
3248 * RETURNS
3251 DWORD INTERNET_GetLastError(void)
3253 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3254 if (!lpwite) return 0;
3255 /* TlsGetValue clears last error, so set it again here */
3256 SetLastError(lpwite->dwError);
3257 return lpwite->dwError;
3261 /***********************************************************************
3262 * INTERNET_WorkerThreadFunc (internal)
3264 * Worker thread execution function
3266 * RETURNS
3269 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3271 LPWORKREQUEST lpRequest = lpvParam;
3272 WORKREQUEST workRequest;
3274 TRACE("\n");
3276 memcpy(&workRequest, lpRequest, sizeof(WORKREQUEST));
3277 HeapFree(GetProcessHeap(), 0, lpRequest);
3279 workRequest.asyncproc(&workRequest);
3281 WININET_Release( workRequest.hdr );
3282 return TRUE;
3286 /***********************************************************************
3287 * INTERNET_AsyncCall (internal)
3289 * Retrieves work request from queue
3291 * RETURNS
3294 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3296 BOOL bSuccess;
3297 LPWORKREQUEST lpNewRequest;
3299 TRACE("\n");
3301 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3302 if (!lpNewRequest)
3303 return FALSE;
3305 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3307 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3308 if (!bSuccess)
3310 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3311 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3314 return bSuccess;
3318 /***********************************************************************
3319 * INTERNET_GetResponseBuffer (internal)
3321 * RETURNS
3324 LPSTR INTERNET_GetResponseBuffer(void)
3326 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3327 if (!lpwite)
3328 lpwite = INTERNET_AllocThreadError();
3329 TRACE("\n");
3330 return lpwite->response;
3333 /***********************************************************************
3334 * INTERNET_GetNextLine (internal)
3336 * Parse next line in directory string listing
3338 * RETURNS
3339 * Pointer to beginning of next line
3340 * NULL on failure
3344 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3346 struct timeval tv;
3347 fd_set infd;
3348 BOOL bSuccess = FALSE;
3349 INT nRecv = 0;
3350 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3352 TRACE("\n");
3354 FD_ZERO(&infd);
3355 FD_SET(nSocket, &infd);
3356 tv.tv_sec=RESPONSE_TIMEOUT;
3357 tv.tv_usec=0;
3359 while (nRecv < MAX_REPLY_LEN)
3361 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3363 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3365 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3366 goto lend;
3369 if (lpszBuffer[nRecv] == '\n')
3371 bSuccess = TRUE;
3372 break;
3374 if (lpszBuffer[nRecv] != '\r')
3375 nRecv++;
3377 else
3379 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3380 goto lend;
3384 lend:
3385 if (bSuccess)
3387 lpszBuffer[nRecv] = '\0';
3388 *dwLen = nRecv - 1;
3389 TRACE(":%d %s\n", nRecv, lpszBuffer);
3390 return lpszBuffer;
3392 else
3394 return NULL;
3398 /**********************************************************
3399 * InternetQueryDataAvailable (WININET.@)
3401 * Determines how much data is available to be read.
3403 * RETURNS
3404 * TRUE on success, FALSE if an error occurred. If
3405 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3406 * no data is presently available, FALSE is returned with
3407 * the last error ERROR_IO_PENDING; a callback with status
3408 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3409 * data is available.
3411 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3412 LPDWORD lpdwNumberOfBytesAvailble,
3413 DWORD dwFlags, DWORD_PTR dwContext)
3415 WININETHANDLEHEADER *hdr;
3416 DWORD res;
3418 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3420 hdr = WININET_GetObject( hFile );
3421 if (!hdr) {
3422 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
3423 return FALSE;
3426 if(hdr->vtbl->QueryDataAvailable) {
3427 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3428 }else {
3429 WARN("wrong handle\n");
3430 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3433 WININET_Release(hdr);
3435 if(res != ERROR_SUCCESS)
3436 SetLastError(res);
3437 return res == ERROR_SUCCESS;
3441 /***********************************************************************
3442 * InternetLockRequestFile (WININET.@)
3444 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3445 *lphLockReqHandle)
3447 FIXME("STUB\n");
3448 return FALSE;
3451 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3453 FIXME("STUB\n");
3454 return FALSE;
3458 /***********************************************************************
3459 * InternetAutodial (WININET.@)
3461 * On windows this function is supposed to dial the default internet
3462 * connection. We don't want to have Wine dial out to the internet so
3463 * we return TRUE by default. It might be nice to check if we are connected.
3465 * RETURNS
3466 * TRUE on success
3467 * FALSE on failure
3470 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3472 FIXME("STUB\n");
3474 /* Tell that we are connected to the internet. */
3475 return TRUE;
3478 /***********************************************************************
3479 * InternetAutodialHangup (WININET.@)
3481 * Hangs up a connection made with InternetAutodial
3483 * PARAM
3484 * dwReserved
3485 * RETURNS
3486 * TRUE on success
3487 * FALSE on failure
3490 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3492 FIXME("STUB\n");
3494 /* we didn't dial, we don't disconnect */
3495 return TRUE;
3498 /***********************************************************************
3499 * InternetCombineUrlA (WININET.@)
3501 * Combine a base URL with a relative URL
3503 * RETURNS
3504 * TRUE on success
3505 * FALSE on failure
3509 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3510 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3511 DWORD dwFlags)
3513 HRESULT hr=S_OK;
3515 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3517 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3518 dwFlags ^= ICU_NO_ENCODE;
3519 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3521 return (hr==S_OK);
3524 /***********************************************************************
3525 * InternetCombineUrlW (WININET.@)
3527 * Combine a base URL with a relative URL
3529 * RETURNS
3530 * TRUE on success
3531 * FALSE on failure
3535 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3536 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3537 DWORD dwFlags)
3539 HRESULT hr=S_OK;
3541 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3543 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3544 dwFlags ^= ICU_NO_ENCODE;
3545 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3547 return (hr==S_OK);
3550 /* max port num is 65535 => 5 digits */
3551 #define MAX_WORD_DIGITS 5
3553 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3554 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3555 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3556 (url)->dw##component##Length : strlen((url)->lpsz##component))
3558 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3560 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3561 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3562 return TRUE;
3563 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3564 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3565 return TRUE;
3566 if ((nScheme == INTERNET_SCHEME_FTP) &&
3567 (nPort == INTERNET_DEFAULT_FTP_PORT))
3568 return TRUE;
3569 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3570 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3571 return TRUE;
3573 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3574 return TRUE;
3576 return FALSE;
3579 /* opaque urls do not fit into the standard url hierarchy and don't have
3580 * two following slashes */
3581 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3583 return (nScheme != INTERNET_SCHEME_FTP) &&
3584 (nScheme != INTERNET_SCHEME_GOPHER) &&
3585 (nScheme != INTERNET_SCHEME_HTTP) &&
3586 (nScheme != INTERNET_SCHEME_HTTPS) &&
3587 (nScheme != INTERNET_SCHEME_FILE);
3590 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3592 int index;
3593 if (scheme < INTERNET_SCHEME_FIRST)
3594 return NULL;
3595 index = scheme - INTERNET_SCHEME_FIRST;
3596 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3597 return NULL;
3598 return (LPCWSTR)&url_schemes[index];
3601 /* we can calculate using ansi strings because we're just
3602 * calculating string length, not size
3604 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3605 LPDWORD lpdwUrlLength)
3607 INTERNET_SCHEME nScheme;
3609 *lpdwUrlLength = 0;
3611 if (lpUrlComponents->lpszScheme)
3613 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3614 *lpdwUrlLength += dwLen;
3615 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3617 else
3619 LPCWSTR scheme;
3621 nScheme = lpUrlComponents->nScheme;
3623 if (nScheme == INTERNET_SCHEME_DEFAULT)
3624 nScheme = INTERNET_SCHEME_HTTP;
3625 scheme = INTERNET_GetSchemeString(nScheme);
3626 *lpdwUrlLength += strlenW(scheme);
3629 (*lpdwUrlLength)++; /* ':' */
3630 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3631 *lpdwUrlLength += strlen("//");
3633 if (lpUrlComponents->lpszUserName)
3635 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3636 *lpdwUrlLength += strlen("@");
3638 else
3640 if (lpUrlComponents->lpszPassword)
3642 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3643 return FALSE;
3647 if (lpUrlComponents->lpszPassword)
3649 *lpdwUrlLength += strlen(":");
3650 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3653 if (lpUrlComponents->lpszHostName)
3655 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3657 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3659 char szPort[MAX_WORD_DIGITS+1];
3661 sprintf(szPort, "%d", lpUrlComponents->nPort);
3662 *lpdwUrlLength += strlen(szPort);
3663 *lpdwUrlLength += strlen(":");
3666 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3667 (*lpdwUrlLength)++; /* '/' */
3670 if (lpUrlComponents->lpszUrlPath)
3671 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3673 return TRUE;
3676 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3678 INT len;
3680 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3682 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3683 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3684 urlCompW->nScheme = lpUrlComponents->nScheme;
3685 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3686 urlCompW->nPort = lpUrlComponents->nPort;
3687 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3688 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3689 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3690 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3692 if (lpUrlComponents->lpszScheme)
3694 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3695 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3696 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3697 -1, urlCompW->lpszScheme, len);
3700 if (lpUrlComponents->lpszHostName)
3702 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3703 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3704 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3705 -1, urlCompW->lpszHostName, len);
3708 if (lpUrlComponents->lpszUserName)
3710 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3711 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3712 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3713 -1, urlCompW->lpszUserName, len);
3716 if (lpUrlComponents->lpszPassword)
3718 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3719 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3720 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3721 -1, urlCompW->lpszPassword, len);
3724 if (lpUrlComponents->lpszUrlPath)
3726 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3727 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3728 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3729 -1, urlCompW->lpszUrlPath, len);
3732 if (lpUrlComponents->lpszExtraInfo)
3734 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3735 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3736 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3737 -1, urlCompW->lpszExtraInfo, len);
3741 /***********************************************************************
3742 * InternetCreateUrlA (WININET.@)
3744 * See InternetCreateUrlW.
3746 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3747 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3749 BOOL ret;
3750 LPWSTR urlW = NULL;
3751 URL_COMPONENTSW urlCompW;
3753 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3755 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3757 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3758 return FALSE;
3761 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3763 if (lpszUrl)
3764 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3766 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3768 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3769 *lpdwUrlLength /= sizeof(WCHAR);
3771 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3772 * minus one, so add one to leave room for NULL terminator
3774 if (ret)
3775 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3777 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3778 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3779 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3780 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3781 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3782 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3783 HeapFree(GetProcessHeap(), 0, urlW);
3785 return ret;
3788 /***********************************************************************
3789 * InternetCreateUrlW (WININET.@)
3791 * Creates a URL from its component parts.
3793 * PARAMS
3794 * lpUrlComponents [I] URL Components.
3795 * dwFlags [I] Flags. See notes.
3796 * lpszUrl [I] Buffer in which to store the created URL.
3797 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3798 * lpszUrl in characters. On output, the number of bytes
3799 * required to store the URL including terminator.
3801 * NOTES
3803 * The dwFlags parameter can be zero or more of the following:
3804 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3806 * RETURNS
3807 * TRUE on success
3808 * FALSE on failure
3811 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3812 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3814 DWORD dwLen;
3815 INTERNET_SCHEME nScheme;
3817 static const WCHAR slashSlashW[] = {'/','/'};
3818 static const WCHAR percentD[] = {'%','d',0};
3820 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3822 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3824 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3825 return FALSE;
3828 if (!calc_url_length(lpUrlComponents, &dwLen))
3829 return FALSE;
3831 if (!lpszUrl || *lpdwUrlLength < dwLen)
3833 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3834 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3835 return FALSE;
3838 *lpdwUrlLength = dwLen;
3839 lpszUrl[0] = 0x00;
3841 dwLen = 0;
3843 if (lpUrlComponents->lpszScheme)
3845 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3846 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3847 lpszUrl += dwLen;
3849 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3851 else
3853 LPCWSTR scheme;
3854 nScheme = lpUrlComponents->nScheme;
3856 if (nScheme == INTERNET_SCHEME_DEFAULT)
3857 nScheme = INTERNET_SCHEME_HTTP;
3859 scheme = INTERNET_GetSchemeString(nScheme);
3860 dwLen = strlenW(scheme);
3861 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3862 lpszUrl += dwLen;
3865 /* all schemes are followed by at least a colon */
3866 *lpszUrl = ':';
3867 lpszUrl++;
3869 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3871 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3872 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3875 if (lpUrlComponents->lpszUserName)
3877 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3878 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3879 lpszUrl += dwLen;
3881 if (lpUrlComponents->lpszPassword)
3883 *lpszUrl = ':';
3884 lpszUrl++;
3886 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3887 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3888 lpszUrl += dwLen;
3891 *lpszUrl = '@';
3892 lpszUrl++;
3895 if (lpUrlComponents->lpszHostName)
3897 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3898 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3899 lpszUrl += dwLen;
3901 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3903 WCHAR szPort[MAX_WORD_DIGITS+1];
3905 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3906 *lpszUrl = ':';
3907 lpszUrl++;
3908 dwLen = strlenW(szPort);
3909 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3910 lpszUrl += dwLen;
3913 /* add slash between hostname and path if necessary */
3914 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3916 *lpszUrl = '/';
3917 lpszUrl++;
3922 if (lpUrlComponents->lpszUrlPath)
3924 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3925 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3926 lpszUrl += dwLen;
3929 *lpszUrl = '\0';
3931 return TRUE;
3934 /***********************************************************************
3935 * InternetConfirmZoneCrossingA (WININET.@)
3938 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3940 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3941 return ERROR_SUCCESS;
3944 /***********************************************************************
3945 * InternetConfirmZoneCrossingW (WININET.@)
3948 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3950 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3951 return ERROR_SUCCESS;
3954 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3955 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3957 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3958 lpdwConnection, dwReserved);
3959 return ERROR_SUCCESS;
3962 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3963 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3965 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3966 lpdwConnection, dwReserved);
3967 return ERROR_SUCCESS;
3970 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3972 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3973 return TRUE;
3976 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3978 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3979 return TRUE;
3982 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
3984 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
3985 return ERROR_SUCCESS;
3988 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3989 PBYTE pbHexHash )
3991 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3992 debugstr_w(pwszTarget), pbHexHash);
3993 return FALSE;
3996 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3998 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
3999 return FALSE;
4002 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4004 FIXME("(%p, %08lx) stub\n", a, b);
4005 return 0;