wininet: Move INTERNET_STATUS_REQUEST_COMPLETE call from INTERNET_ReadFile.
[wine/hacks.git] / dlls / wininet / internet.c
blob0019bb966152bad8b17a4567ff21cfc97b057ec3
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, BOOL bWait)
1705 BOOL retval = FALSE;
1706 int nSocket = -1;
1707 int bytes_read;
1708 LPWININETHTTPREQW lpwhr;
1710 /* FIXME: this should use NETCON functions! */
1711 switch (lpwh->htype)
1713 case WH_HHTTPREQ:
1714 lpwhr = (LPWININETHTTPREQW)lpwh;
1716 if (!NETCON_recv(&lpwhr->netConnection, lpBuffer,
1717 min(dwNumOfBytesToRead, lpwhr->dwContentLength - lpwhr->dwContentRead),
1718 bWait ? MSG_WAITALL : 0, &bytes_read))
1721 if (((lpwhr->dwContentLength != -1) &&
1722 (lpwhr->dwContentRead != lpwhr->dwContentLength)))
1723 ERR("not all data received %d/%d\n", lpwhr->dwContentRead,
1724 lpwhr->dwContentLength);
1726 /* always returns TRUE, even if the network layer returns an
1727 * error */
1728 *pdwNumOfBytesRead = 0;
1729 HTTP_FinishedReading(lpwhr);
1730 retval = TRUE;
1732 else
1734 lpwhr->dwContentRead += bytes_read;
1735 *pdwNumOfBytesRead = bytes_read;
1737 if(lpwhr->lpszCacheFile) {
1738 BOOL res;
1740 res = WriteFile(lpwhr->hCacheFile, lpBuffer, bytes_read, NULL, NULL);
1741 if(!res)
1742 WARN("WriteFile failed: %u\n", GetLastError());
1745 if (!bytes_read && (lpwhr->dwContentRead == lpwhr->dwContentLength))
1746 retval = HTTP_FinishedReading(lpwhr);
1747 else
1748 retval = TRUE;
1750 break;
1752 case WH_HFILE:
1753 /* FIXME: FTP should use NETCON_ stuff */
1754 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1755 if (nSocket != -1)
1757 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1758 retval = (res >= 0);
1759 *pdwNumOfBytesRead = retval ? res : 0;
1761 break;
1763 default:
1764 break;
1767 return retval;
1770 /***********************************************************************
1771 * InternetReadFile (WININET.@)
1773 * Read data from an open internet file
1775 * RETURNS
1776 * TRUE on success
1777 * FALSE on failure
1780 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1781 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1783 LPWININETHANDLEHEADER lpwh;
1784 BOOL retval;
1786 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1788 lpwh = WININET_GetObject( hFile );
1789 if (!lpwh)
1791 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1792 return FALSE;
1795 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE);
1796 WININET_Release( lpwh );
1798 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1799 return retval;
1802 /***********************************************************************
1803 * InternetReadFileExA (WININET.@)
1805 * Read data from an open internet file
1807 * PARAMS
1808 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1809 * lpBuffersOut [I/O] Buffer.
1810 * dwFlags [I] Flags. See notes.
1811 * dwContext [I] Context for callbacks.
1813 * RETURNS
1814 * TRUE on success
1815 * FALSE on failure
1817 * NOTES
1818 * The parameter dwFlags include zero or more of the following flags:
1819 *|IRF_ASYNC - Makes the call asynchronous.
1820 *|IRF_SYNC - Makes the call synchronous.
1821 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1822 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1824 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1826 * SEE
1827 * InternetOpenUrlA(), HttpOpenRequestA()
1829 void AsyncInternetReadFileExProc(WORKREQUEST *workRequest)
1831 struct WORKREQ_INTERNETREADFILEEXA const *req = &workRequest->u.InternetReadFileExA;
1832 INTERNET_ASYNC_RESULT iar;
1833 BOOL res;
1835 TRACE("INTERNETREADFILEEXA %p\n", workRequest->hdr);
1837 res = INTERNET_ReadFile(workRequest->hdr, req->lpBuffersOut->lpvBuffer,
1838 req->lpBuffersOut->dwBufferLength,
1839 &req->lpBuffersOut->dwBufferLength, TRUE);
1841 iar.dwResult = res;
1842 iar.dwError = res ? ERROR_SUCCESS : INTERNET_GetLastError();
1844 INTERNET_SendCallback(workRequest->hdr, workRequest->hdr->dwContext,
1845 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1846 sizeof(INTERNET_ASYNC_RESULT));
1849 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1850 DWORD dwFlags, DWORD_PTR dwContext)
1852 BOOL retval = FALSE;
1853 LPWININETHANDLEHEADER lpwh;
1855 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1857 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1858 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1860 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1862 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1863 return FALSE;
1866 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1867 if (!lpwh)
1869 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1870 return FALSE;
1873 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1874 INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
1876 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1877 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1878 if (dwFlags & IRF_ASYNC)
1880 DWORD dwDataAvailable = 0;
1882 if (lpwh->htype == WH_HHTTPREQ)
1883 NETCON_query_data_available(&((LPWININETHTTPREQW)lpwh)->netConnection,
1884 &dwDataAvailable);
1886 if (!dwDataAvailable)
1888 WORKREQUEST workRequest;
1889 struct WORKREQ_INTERNETREADFILEEXA *req;
1891 workRequest.asyncproc = AsyncInternetReadFileExProc;
1892 workRequest.hdr = WININET_AddRef( lpwh );
1893 req = &workRequest.u.InternetReadFileExA;
1894 req->lpBuffersOut = lpBuffersOut;
1896 if (!INTERNET_AsyncCall(&workRequest))
1897 WININET_Release( lpwh );
1898 else
1899 INTERNET_SetLastError(ERROR_IO_PENDING);
1900 goto end;
1904 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1905 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1906 !(dwFlags & IRF_NO_WAIT));
1908 if (retval)
1910 DWORD dwBytesReceived = lpBuffersOut->dwBufferLength;
1911 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1912 INTERNET_STATUS_RESPONSE_RECEIVED, &dwBytesReceived,
1913 sizeof(dwBytesReceived));
1916 end:
1917 WININET_Release( lpwh );
1919 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1920 return retval;
1923 /***********************************************************************
1924 * InternetReadFileExW (WININET.@)
1926 * Read data from an open internet file.
1928 * PARAMS
1929 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1930 * lpBuffersOut [I/O] Buffer.
1931 * dwFlags [I] Flags.
1932 * dwContext [I] Context for callbacks.
1934 * RETURNS
1935 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1937 * NOTES
1938 * Not implemented in Wine or native either (as of IE6 SP2).
1941 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1942 DWORD dwFlags, DWORD_PTR dwContext)
1944 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1946 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1947 return FALSE;
1950 /***********************************************************************
1951 * INET_QueryOptionHelper (internal)
1953 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1954 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1956 LPWININETHANDLEHEADER lpwhh;
1957 BOOL bSuccess = FALSE;
1959 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1961 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1963 switch (dwOption)
1965 case INTERNET_OPTION_HANDLE_TYPE:
1967 ULONG type;
1969 if (!lpwhh)
1971 WARN("Invalid hInternet handle\n");
1972 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1973 return FALSE;
1976 type = lpwhh->htype;
1978 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type);
1980 if (*lpdwBufferLength < sizeof(ULONG))
1981 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1982 else
1984 memcpy(lpBuffer, &type, sizeof(ULONG));
1985 bSuccess = TRUE;
1987 *lpdwBufferLength = sizeof(ULONG);
1988 break;
1991 case INTERNET_OPTION_REQUEST_FLAGS:
1993 ULONG flags = 4;
1994 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
1995 if (*lpdwBufferLength < sizeof(ULONG))
1996 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1997 else
1999 memcpy(lpBuffer, &flags, sizeof(ULONG));
2000 bSuccess = TRUE;
2002 *lpdwBufferLength = sizeof(ULONG);
2003 break;
2006 case INTERNET_OPTION_URL:
2008 TRACE("INTERNET_OPTION_URL\n");
2010 if (!lpwhh)
2012 WARN("Invalid hInternet handle\n");
2013 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2014 return FALSE;
2016 if (lpwhh->htype == WH_HHTTPREQ)
2018 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2019 WCHAR url[1023];
2020 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2021 static const WCHAR szHost[] = {'H','o','s','t',0};
2022 DWORD sizeRequired;
2023 LPHTTPHEADERW Host;
2025 Host = HTTP_GetHeader(lpreq,szHost);
2026 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2027 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2028 if(!bIsUnicode)
2030 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2031 lpBuffer,*lpdwBufferLength,NULL,NULL);
2032 if (sizeRequired > *lpdwBufferLength)
2033 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2034 else
2035 bSuccess = TRUE;
2036 *lpdwBufferLength = sizeRequired;
2038 else
2040 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2041 if (*lpdwBufferLength < sizeRequired)
2042 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2043 else
2045 strcpyW(lpBuffer, url);
2046 bSuccess = TRUE;
2048 *lpdwBufferLength = sizeRequired;
2051 break;
2054 case INTERNET_OPTION_DATAFILE_NAME:
2056 TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
2057 if (!lpwhh)
2059 WARN("Invalid hInternet handle\n");
2060 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2061 return FALSE;
2063 if (lpwhh->htype == WH_HHTTPREQ)
2065 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2066 DWORD size;
2068 if(!lpreq->lpszCacheFile) {
2069 *lpdwBufferLength = 0;
2070 INTERNET_SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
2072 else if(bIsUnicode)
2074 size = (lstrlenW(lpreq->lpszCacheFile)+1) * sizeof(WCHAR);
2075 if (*lpdwBufferLength < size)
2076 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2077 else
2079 memcpy(lpBuffer, lpreq->lpszCacheFile, size);
2080 bSuccess = TRUE;
2082 *lpdwBufferLength = size;
2084 else
2086 size = WideCharToMultiByte(CP_ACP, 0, lpreq->lpszCacheFile, -1, NULL, 0, NULL, NULL);
2087 if (size > *lpdwBufferLength) {
2088 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2089 }else {
2090 *lpdwBufferLength = WideCharToMultiByte(CP_ACP, 0, lpreq->lpszCacheFile,
2091 -1, lpBuffer, *lpdwBufferLength, NULL, NULL);
2092 bSuccess = TRUE;
2096 break;
2099 case INTERNET_OPTION_HTTP_VERSION:
2101 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2102 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2103 else
2106 * Presently hardcoded to 1.1
2108 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2109 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2110 bSuccess = TRUE;
2112 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2113 break;
2115 case INTERNET_OPTION_CONNECTED_STATE:
2117 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2118 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2120 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2121 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2122 else
2124 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2125 bSuccess = TRUE;
2127 *lpdwBufferLength = sizeof(*pdwConnectedState);
2128 break;
2130 case INTERNET_OPTION_PROXY:
2132 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2133 WININETAPPINFOW wai;
2135 if (lpwai == NULL)
2137 TRACE("Getting global proxy info\n");
2138 memset(&wai, 0, sizeof(WININETAPPINFOW));
2139 INTERNET_ConfigureProxyFromReg( &wai );
2140 lpwai = &wai;
2143 if (bIsUnicode)
2145 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2146 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2148 if (lpwai->lpszProxy)
2149 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2150 sizeof(WCHAR);
2151 if (lpwai->lpszProxyBypass)
2152 proxyBypassBytesRequired =
2153 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2154 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2155 proxyBytesRequired + proxyBypassBytesRequired)
2156 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2157 else
2159 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
2160 sizeof(INTERNET_PROXY_INFOW));
2161 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
2162 sizeof(INTERNET_PROXY_INFOW) +
2163 proxyBytesRequired);
2165 pPI->dwAccessType = lpwai->dwAccessType;
2166 pPI->lpszProxy = NULL;
2167 pPI->lpszProxyBypass = NULL;
2168 if (lpwai->lpszProxy)
2170 lstrcpyW(proxy, lpwai->lpszProxy);
2171 pPI->lpszProxy = proxy;
2174 if (lpwai->lpszProxyBypass)
2176 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
2177 pPI->lpszProxyBypass = proxy_bypass;
2179 bSuccess = TRUE;
2181 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2182 proxyBytesRequired + proxyBypassBytesRequired;
2184 else
2186 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2187 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2189 if (lpwai->lpszProxy)
2190 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2191 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2192 if (lpwai->lpszProxyBypass)
2193 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2194 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2195 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2196 proxyBytesRequired + proxyBypassBytesRequired)
2197 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2198 else
2200 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2201 sizeof(INTERNET_PROXY_INFOA));
2202 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2203 sizeof(INTERNET_PROXY_INFOA) +
2204 proxyBytesRequired);
2206 pPI->dwAccessType = lpwai->dwAccessType;
2207 pPI->lpszProxy = NULL;
2208 pPI->lpszProxyBypass = NULL;
2209 if (lpwai->lpszProxy)
2211 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2212 proxy, proxyBytesRequired, NULL, NULL);
2213 pPI->lpszProxy = proxy;
2216 if (lpwai->lpszProxyBypass)
2218 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2219 -1, proxy_bypass, proxyBypassBytesRequired,
2220 NULL, NULL);
2221 pPI->lpszProxyBypass = proxy_bypass;
2223 bSuccess = TRUE;
2225 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2226 proxyBytesRequired + proxyBypassBytesRequired;
2228 break;
2230 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2232 ULONG conn = 2;
2233 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2234 if (*lpdwBufferLength < sizeof(ULONG))
2235 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2236 else
2238 memcpy(lpBuffer, &conn, sizeof(ULONG));
2239 bSuccess = TRUE;
2241 *lpdwBufferLength = sizeof(ULONG);
2242 break;
2244 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2246 ULONG conn = 4;
2247 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2248 if (*lpdwBufferLength < sizeof(ULONG))
2249 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2250 else
2252 memcpy(lpBuffer, &conn, sizeof(ULONG));
2253 bSuccess = TRUE;
2255 *lpdwBufferLength = sizeof(ULONG);
2256 break;
2258 case INTERNET_OPTION_SECURITY_FLAGS:
2259 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2260 bSuccess = TRUE;
2261 break;
2263 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2264 if (!lpwhh)
2266 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2267 return FALSE;
2269 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2271 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2272 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2274 else if (lpwhh->htype == WH_HHTTPREQ)
2276 LPWININETHTTPREQW lpwhr;
2277 PCCERT_CONTEXT context;
2279 lpwhr = (LPWININETHTTPREQW)lpwhh;
2280 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2281 if (context)
2283 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2284 DWORD strLen;
2286 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2287 info->ftExpiry = context->pCertInfo->NotAfter;
2288 info->ftStart = context->pCertInfo->NotBefore;
2289 if (bIsUnicode)
2291 strLen = CertNameToStrW(context->dwCertEncodingType,
2292 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2293 NULL, 0);
2294 info->lpszSubjectInfo = LocalAlloc(0,
2295 strLen * sizeof(WCHAR));
2296 if (info->lpszSubjectInfo)
2297 CertNameToStrW(context->dwCertEncodingType,
2298 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2299 info->lpszSubjectInfo, strLen);
2300 strLen = CertNameToStrW(context->dwCertEncodingType,
2301 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2302 NULL, 0);
2303 info->lpszIssuerInfo = LocalAlloc(0,
2304 strLen * sizeof(WCHAR));
2305 if (info->lpszIssuerInfo)
2306 CertNameToStrW(context->dwCertEncodingType,
2307 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2308 info->lpszIssuerInfo, strLen);
2310 else
2312 LPINTERNET_CERTIFICATE_INFOA infoA =
2313 (LPINTERNET_CERTIFICATE_INFOA)info;
2315 strLen = CertNameToStrA(context->dwCertEncodingType,
2316 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2317 NULL, 0);
2318 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2319 if (infoA->lpszSubjectInfo)
2320 CertNameToStrA(context->dwCertEncodingType,
2321 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2322 infoA->lpszSubjectInfo, strLen);
2323 strLen = CertNameToStrA(context->dwCertEncodingType,
2324 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2325 NULL, 0);
2326 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2327 if (infoA->lpszIssuerInfo)
2328 CertNameToStrA(context->dwCertEncodingType,
2329 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2330 infoA->lpszIssuerInfo, strLen);
2333 * Contrary to MSDN, these do not appear to be set.
2334 * lpszProtocolName
2335 * lpszSignatureAlgName
2336 * lpszEncryptionAlgName
2337 * dwKeySize
2339 CertFreeCertificateContext(context);
2340 bSuccess = TRUE;
2343 break;
2344 case INTERNET_OPTION_VERSION:
2346 TRACE("INTERNET_OPTION_VERSION\n");
2347 if (*lpdwBufferLength < sizeof(INTERNET_VERSION_INFO))
2348 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2349 else
2351 static const INTERNET_VERSION_INFO info = { 1, 2 };
2352 memcpy(lpBuffer, &info, sizeof(info));
2353 *lpdwBufferLength = sizeof(info);
2354 bSuccess = TRUE;
2356 break;
2358 case INTERNET_OPTION_PER_CONNECTION_OPTION:
2359 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2360 if (*lpdwBufferLength < sizeof(INTERNET_PER_CONN_OPTION_LISTW))
2361 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2362 else
2364 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2365 int x;
2366 bSuccess = TRUE;
2367 for (x = 0; x < con->dwOptionCount; ++x)
2369 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + x;
2370 switch (option->dwOption)
2372 case INTERNET_PER_CONN_FLAGS:
2373 option->Value.dwValue = PROXY_TYPE_DIRECT;
2374 break;
2376 case INTERNET_PER_CONN_PROXY_SERVER:
2377 case INTERNET_PER_CONN_PROXY_BYPASS:
2378 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2379 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2380 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2381 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2382 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2383 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2384 FIXME("Unhandled dwOption %d\n", option->dwOption);
2385 option->Value.dwValue = 0;
2386 bSuccess = FALSE;
2387 break;
2389 default:
2390 FIXME("Unknown dwOption %d\n", option->dwOption);
2391 bSuccess = FALSE;
2392 break;
2395 if (!bSuccess)
2396 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2398 break;
2399 case 66:
2400 FIXME("66\n");
2401 bSuccess = TRUE;
2402 break;
2403 default:
2404 FIXME("Stub! %d\n", dwOption);
2405 break;
2407 if (lpwhh)
2408 WININET_Release( lpwhh );
2410 return bSuccess;
2413 /***********************************************************************
2414 * InternetQueryOptionW (WININET.@)
2416 * Queries an options on the specified handle
2418 * RETURNS
2419 * TRUE on success
2420 * FALSE on failure
2423 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2424 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2426 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2429 /***********************************************************************
2430 * InternetQueryOptionA (WININET.@)
2432 * Queries an options on the specified handle
2434 * RETURNS
2435 * TRUE on success
2436 * FALSE on failure
2439 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2440 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2442 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2446 /***********************************************************************
2447 * InternetSetOptionW (WININET.@)
2449 * Sets an options on the specified handle
2451 * RETURNS
2452 * TRUE on success
2453 * FALSE on failure
2456 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2457 LPVOID lpBuffer, DWORD dwBufferLength)
2459 LPWININETHANDLEHEADER lpwhh;
2460 BOOL ret = TRUE;
2462 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2464 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2465 if(lpwhh && lpwhh->vtbl->SetOption) {
2466 DWORD res;
2468 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2469 if(res != ERROR_INTERNET_INVALID_OPTION) {
2470 WININET_Release( lpwhh );
2472 if(res != ERROR_SUCCESS)
2473 SetLastError(res);
2475 return res == ERROR_SUCCESS;
2479 switch (dwOption)
2481 case INTERNET_OPTION_CALLBACK:
2483 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2484 ret = (set_status_callback(lpwhh, callback, TRUE) != INTERNET_INVALID_STATUS_CALLBACK);
2485 break;
2487 case INTERNET_OPTION_HTTP_VERSION:
2489 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2490 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2492 break;
2493 case INTERNET_OPTION_ERROR_MASK:
2495 unsigned long flags=*(unsigned long*)lpBuffer;
2496 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2498 break;
2499 case INTERNET_OPTION_CODEPAGE:
2501 unsigned long codepage=*(unsigned long*)lpBuffer;
2502 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2504 break;
2505 case INTERNET_OPTION_REQUEST_PRIORITY:
2507 unsigned long priority=*(unsigned long*)lpBuffer;
2508 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2510 break;
2511 case INTERNET_OPTION_CONNECT_TIMEOUT:
2513 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2514 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2516 break;
2517 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2519 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2520 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2522 break;
2523 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2525 unsigned long conns=*(unsigned long*)lpBuffer;
2526 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2528 break;
2529 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2531 unsigned long conns=*(unsigned long*)lpBuffer;
2532 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2534 break;
2535 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2536 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2537 break;
2538 case INTERNET_OPTION_END_BROWSER_SESSION:
2539 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2540 break;
2541 case INTERNET_OPTION_CONNECTED_STATE:
2542 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2543 break;
2544 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2545 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2546 break;
2547 case INTERNET_OPTION_SEND_TIMEOUT:
2548 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2549 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2550 break;
2551 case INTERNET_OPTION_CONNECT_RETRIES:
2552 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2553 break;
2554 case INTERNET_OPTION_CONTEXT_VALUE:
2555 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2556 break;
2557 case INTERNET_OPTION_SECURITY_FLAGS:
2558 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2559 break;
2560 case 86:
2561 FIXME("86\n");
2562 break;
2563 default:
2564 FIXME("Option %d STUB\n",dwOption);
2565 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2566 ret = FALSE;
2567 break;
2570 if(lpwhh)
2571 WININET_Release( lpwhh );
2573 return ret;
2577 /***********************************************************************
2578 * InternetSetOptionA (WININET.@)
2580 * Sets an options on the specified handle.
2582 * RETURNS
2583 * TRUE on success
2584 * FALSE on failure
2587 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2588 LPVOID lpBuffer, DWORD dwBufferLength)
2590 LPVOID wbuffer;
2591 DWORD wlen;
2592 BOOL r;
2594 switch( dwOption )
2596 case INTERNET_OPTION_CALLBACK:
2598 LPWININETHANDLEHEADER lpwh;
2599 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2601 if (!(lpwh = WININET_GetObject(hInternet))) return FALSE;
2602 r = (set_status_callback(lpwh, callback, FALSE) != INTERNET_INVALID_STATUS_CALLBACK);
2603 WININET_Release(lpwh);
2604 return r;
2606 case INTERNET_OPTION_PROXY:
2608 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2609 LPINTERNET_PROXY_INFOW piw;
2610 DWORD proxlen, prbylen;
2611 LPWSTR prox, prby;
2613 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2614 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2615 wlen = sizeof(*piw) + proxlen + prbylen;
2616 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2617 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2618 piw->dwAccessType = pi->dwAccessType;
2619 prox = (LPWSTR) &piw[1];
2620 prby = &prox[proxlen+1];
2621 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2622 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2623 piw->lpszProxy = prox;
2624 piw->lpszProxyBypass = prby;
2626 break;
2627 case INTERNET_OPTION_USER_AGENT:
2628 case INTERNET_OPTION_USERNAME:
2629 case INTERNET_OPTION_PASSWORD:
2630 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2631 NULL, 0 );
2632 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2633 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2634 wbuffer, wlen );
2635 break;
2636 default:
2637 wbuffer = lpBuffer;
2638 wlen = dwBufferLength;
2641 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2643 if( lpBuffer != wbuffer )
2644 HeapFree( GetProcessHeap(), 0, wbuffer );
2646 return r;
2650 /***********************************************************************
2651 * InternetSetOptionExA (WININET.@)
2653 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2654 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2656 FIXME("Flags %08x ignored\n", dwFlags);
2657 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2660 /***********************************************************************
2661 * InternetSetOptionExW (WININET.@)
2663 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2664 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2666 FIXME("Flags %08x ignored\n", dwFlags);
2667 if( dwFlags & ~ISO_VALID_FLAGS )
2669 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2670 return FALSE;
2672 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2675 static const WCHAR WININET_wkday[7][4] =
2676 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2677 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2678 static const WCHAR WININET_month[12][4] =
2679 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2680 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2681 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2683 /***********************************************************************
2684 * InternetTimeFromSystemTimeA (WININET.@)
2686 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2688 BOOL ret;
2689 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2691 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2693 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2694 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2696 return ret;
2699 /***********************************************************************
2700 * InternetTimeFromSystemTimeW (WININET.@)
2702 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2704 static const WCHAR date[] =
2705 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2706 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2708 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2710 if (!time || !string) return FALSE;
2712 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2713 return FALSE;
2715 sprintfW( string, date,
2716 WININET_wkday[time->wDayOfWeek],
2717 time->wDay,
2718 WININET_month[time->wMonth - 1],
2719 time->wYear,
2720 time->wHour,
2721 time->wMinute,
2722 time->wSecond );
2724 return TRUE;
2727 /***********************************************************************
2728 * InternetTimeToSystemTimeA (WININET.@)
2730 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2732 BOOL ret = FALSE;
2733 WCHAR *stringW;
2734 int len;
2736 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2738 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2739 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2741 if (stringW)
2743 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2744 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2745 HeapFree( GetProcessHeap(), 0, stringW );
2747 return ret;
2750 /***********************************************************************
2751 * InternetTimeToSystemTimeW (WININET.@)
2753 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2755 unsigned int i;
2756 const WCHAR *s = string;
2757 WCHAR *end;
2759 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2761 if (!string || !time) return FALSE;
2763 /* Windows does this too */
2764 GetSystemTime( time );
2766 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2767 * a SYSTEMTIME structure.
2770 while (*s && !isalphaW( *s )) s++;
2771 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2772 time->wDayOfWeek = 7;
2774 for (i = 0; i < 7; i++)
2776 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2777 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2778 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2780 time->wDayOfWeek = i;
2781 break;
2785 if (time->wDayOfWeek > 6) return TRUE;
2786 while (*s && !isdigitW( *s )) s++;
2787 time->wDay = strtolW( s, &end, 10 );
2788 s = end;
2790 while (*s && !isalphaW( *s )) s++;
2791 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2792 time->wMonth = 0;
2794 for (i = 0; i < 12; i++)
2796 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2797 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2798 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2800 time->wMonth = i + 1;
2801 break;
2804 if (time->wMonth == 0) return TRUE;
2806 while (*s && !isdigitW( *s )) s++;
2807 if (*s == '\0') return TRUE;
2808 time->wYear = strtolW( s, &end, 10 );
2809 s = end;
2811 while (*s && !isdigitW( *s )) s++;
2812 if (*s == '\0') return TRUE;
2813 time->wHour = strtolW( s, &end, 10 );
2814 s = end;
2816 while (*s && !isdigitW( *s )) s++;
2817 if (*s == '\0') return TRUE;
2818 time->wMinute = strtolW( s, &end, 10 );
2819 s = end;
2821 while (*s && !isdigitW( *s )) s++;
2822 if (*s == '\0') return TRUE;
2823 time->wSecond = strtolW( s, &end, 10 );
2824 s = end;
2826 time->wMilliseconds = 0;
2827 return TRUE;
2830 /***********************************************************************
2831 * InternetCheckConnectionW (WININET.@)
2833 * Pings a requested host to check internet connection
2835 * RETURNS
2836 * TRUE on success and FALSE on failure. If a failure then
2837 * ERROR_NOT_CONNECTED is placed into GetLastError
2840 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2843 * this is a kludge which runs the resident ping program and reads the output.
2845 * Anyone have a better idea?
2848 BOOL rc = FALSE;
2849 static const CHAR ping[] = "ping -c 1 ";
2850 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2851 CHAR *command = NULL;
2852 WCHAR hostW[1024];
2853 DWORD len;
2854 INTERNET_PORT port;
2855 int status = -1;
2857 FIXME("\n");
2860 * Crack or set the Address
2862 if (lpszUrl == NULL)
2865 * According to the doc we are supposed to use the ip for the next
2866 * server in the WnInet internal server database. I have
2867 * no idea what that is or how to get it.
2869 * So someone needs to implement this.
2871 FIXME("Unimplemented with URL of NULL\n");
2872 return TRUE;
2874 else
2876 URL_COMPONENTSW components;
2878 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2879 components.lpszHostName = (LPWSTR)&hostW;
2880 components.dwHostNameLength = 1024;
2882 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2883 goto End;
2885 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2886 port = components.nPort;
2887 TRACE("port: %d\n", port);
2890 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
2892 struct sockaddr_in sin;
2893 int fd;
2895 if (!GetAddress(hostW, port, &sin))
2896 goto End;
2897 fd = socket(sin.sin_family, SOCK_STREAM, 0);
2898 if (fd != -1)
2900 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == 0)
2901 rc = TRUE;
2902 close(fd);
2905 else
2908 * Build our ping command
2910 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2911 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2912 strcpy(command,ping);
2913 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2914 strcat(command,redirect);
2916 TRACE("Ping command is : %s\n",command);
2918 status = system(command);
2920 TRACE("Ping returned a code of %i\n",status);
2922 /* Ping return code of 0 indicates success */
2923 if (status == 0)
2924 rc = TRUE;
2927 End:
2929 HeapFree( GetProcessHeap(), 0, command );
2930 if (rc == FALSE)
2931 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2933 return rc;
2937 /***********************************************************************
2938 * InternetCheckConnectionA (WININET.@)
2940 * Pings a requested host to check internet connection
2942 * RETURNS
2943 * TRUE on success and FALSE on failure. If a failure then
2944 * ERROR_NOT_CONNECTED is placed into GetLastError
2947 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2949 WCHAR *szUrl;
2950 INT len;
2951 BOOL rc;
2953 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2954 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2955 return FALSE;
2956 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2957 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2958 HeapFree(GetProcessHeap(), 0, szUrl);
2960 return rc;
2964 /**********************************************************
2965 * INTERNET_InternetOpenUrlW (internal)
2967 * Opens an URL
2969 * RETURNS
2970 * handle of connection or NULL on failure
2972 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2973 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2975 URL_COMPONENTSW urlComponents;
2976 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2977 WCHAR password[1024], path[2048], extra[1024];
2978 HINTERNET client = NULL, client1 = NULL;
2980 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2981 dwHeadersLength, dwFlags, dwContext);
2983 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2984 urlComponents.lpszScheme = protocol;
2985 urlComponents.dwSchemeLength = 32;
2986 urlComponents.lpszHostName = hostName;
2987 urlComponents.dwHostNameLength = MAXHOSTNAME;
2988 urlComponents.lpszUserName = userName;
2989 urlComponents.dwUserNameLength = 1024;
2990 urlComponents.lpszPassword = password;
2991 urlComponents.dwPasswordLength = 1024;
2992 urlComponents.lpszUrlPath = path;
2993 urlComponents.dwUrlPathLength = 2048;
2994 urlComponents.lpszExtraInfo = extra;
2995 urlComponents.dwExtraInfoLength = 1024;
2996 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2997 return NULL;
2998 switch(urlComponents.nScheme) {
2999 case INTERNET_SCHEME_FTP:
3000 if(urlComponents.nPort == 0)
3001 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3002 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3003 userName, password, dwFlags, dwContext, INET_OPENURL);
3004 if(client == NULL)
3005 break;
3006 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3007 if(client1 == NULL) {
3008 InternetCloseHandle(client);
3009 break;
3011 break;
3013 case INTERNET_SCHEME_HTTP:
3014 case INTERNET_SCHEME_HTTPS: {
3015 static const WCHAR szStars[] = { '*','/','*', 0 };
3016 LPCWSTR accept[2] = { szStars, NULL };
3017 if(urlComponents.nPort == 0) {
3018 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3019 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3020 else
3021 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3023 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3024 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3025 userName, password, dwFlags, dwContext, INET_OPENURL);
3026 if(client == NULL)
3027 break;
3029 if (urlComponents.dwExtraInfoLength) {
3030 WCHAR *path_extra;
3031 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3033 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
3035 InternetCloseHandle(client);
3036 break;
3038 strcpyW(path_extra, urlComponents.lpszUrlPath);
3039 strcatW(path_extra, urlComponents.lpszExtraInfo);
3040 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3041 HeapFree(GetProcessHeap(), 0, path_extra);
3043 else
3044 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3046 if(client1 == NULL) {
3047 InternetCloseHandle(client);
3048 break;
3050 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3051 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3052 GetLastError() != ERROR_IO_PENDING) {
3053 InternetCloseHandle(client1);
3054 client1 = NULL;
3055 break;
3058 case INTERNET_SCHEME_GOPHER:
3059 /* gopher doesn't seem to be implemented in wine, but it's supposed
3060 * to be supported by InternetOpenUrlA. */
3061 default:
3062 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3063 break;
3066 TRACE(" %p <--\n", client1);
3068 return client1;
3071 /**********************************************************
3072 * InternetOpenUrlW (WININET.@)
3074 * Opens an URL
3076 * RETURNS
3077 * handle of connection or NULL on failure
3079 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3081 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3082 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
3084 TRACE("%p\n", hIC);
3086 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3087 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3088 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3089 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3092 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3093 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3095 HINTERNET ret = NULL;
3096 LPWININETAPPINFOW hIC = NULL;
3098 if (TRACE_ON(wininet)) {
3099 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3100 dwHeadersLength, dwFlags, dwContext);
3101 TRACE(" flags :");
3102 dump_INTERNET_FLAGS(dwFlags);
3105 if (!lpszUrl)
3107 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3108 goto lend;
3111 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
3112 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3113 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3114 goto lend;
3117 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3118 WORKREQUEST workRequest;
3119 struct WORKREQ_INTERNETOPENURLW *req;
3121 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3122 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3123 req = &workRequest.u.InternetOpenUrlW;
3124 req->lpszUrl = WININET_strdupW(lpszUrl);
3125 if (lpszHeaders)
3126 req->lpszHeaders = WININET_strdupW(lpszHeaders);
3127 else
3128 req->lpszHeaders = 0;
3129 req->dwHeadersLength = dwHeadersLength;
3130 req->dwFlags = dwFlags;
3131 req->dwContext = dwContext;
3133 INTERNET_AsyncCall(&workRequest);
3135 * This is from windows.
3137 INTERNET_SetLastError(ERROR_IO_PENDING);
3138 } else {
3139 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3142 lend:
3143 if( hIC )
3144 WININET_Release( &hIC->hdr );
3145 TRACE(" %p <--\n", ret);
3147 return ret;
3150 /**********************************************************
3151 * InternetOpenUrlA (WININET.@)
3153 * Opens an URL
3155 * RETURNS
3156 * handle of connection or NULL on failure
3158 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3159 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3161 HINTERNET rc = NULL;
3163 INT lenUrl;
3164 INT lenHeaders = 0;
3165 LPWSTR szUrl = NULL;
3166 LPWSTR szHeaders = NULL;
3168 TRACE("\n");
3170 if(lpszUrl) {
3171 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3172 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3173 if(!szUrl)
3174 return NULL;
3175 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3178 if(lpszHeaders) {
3179 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3180 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3181 if(!szHeaders) {
3182 HeapFree(GetProcessHeap(), 0, szUrl);
3183 return NULL;
3185 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3188 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3189 lenHeaders, dwFlags, dwContext);
3191 HeapFree(GetProcessHeap(), 0, szUrl);
3192 HeapFree(GetProcessHeap(), 0, szHeaders);
3194 return rc;
3198 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3200 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3202 if (lpwite)
3204 lpwite->dwError = 0;
3205 lpwite->response[0] = '\0';
3208 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3210 HeapFree(GetProcessHeap(), 0, lpwite);
3211 return NULL;
3214 return lpwite;
3218 /***********************************************************************
3219 * INTERNET_SetLastError (internal)
3221 * Set last thread specific error
3223 * RETURNS
3226 void INTERNET_SetLastError(DWORD dwError)
3228 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3230 if (!lpwite)
3231 lpwite = INTERNET_AllocThreadError();
3233 SetLastError(dwError);
3234 if(lpwite)
3235 lpwite->dwError = dwError;
3239 /***********************************************************************
3240 * INTERNET_GetLastError (internal)
3242 * Get last thread specific error
3244 * RETURNS
3247 DWORD INTERNET_GetLastError(void)
3249 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3250 if (!lpwite) return 0;
3251 /* TlsGetValue clears last error, so set it again here */
3252 SetLastError(lpwite->dwError);
3253 return lpwite->dwError;
3257 /***********************************************************************
3258 * INTERNET_WorkerThreadFunc (internal)
3260 * Worker thread execution function
3262 * RETURNS
3265 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3267 LPWORKREQUEST lpRequest = lpvParam;
3268 WORKREQUEST workRequest;
3270 TRACE("\n");
3272 memcpy(&workRequest, lpRequest, sizeof(WORKREQUEST));
3273 HeapFree(GetProcessHeap(), 0, lpRequest);
3275 workRequest.asyncproc(&workRequest);
3277 WININET_Release( workRequest.hdr );
3278 return TRUE;
3282 /***********************************************************************
3283 * INTERNET_AsyncCall (internal)
3285 * Retrieves work request from queue
3287 * RETURNS
3290 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3292 BOOL bSuccess;
3293 LPWORKREQUEST lpNewRequest;
3295 TRACE("\n");
3297 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3298 if (!lpNewRequest)
3299 return FALSE;
3301 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3303 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3304 if (!bSuccess)
3306 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3307 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3310 return bSuccess;
3314 /***********************************************************************
3315 * INTERNET_GetResponseBuffer (internal)
3317 * RETURNS
3320 LPSTR INTERNET_GetResponseBuffer(void)
3322 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3323 if (!lpwite)
3324 lpwite = INTERNET_AllocThreadError();
3325 TRACE("\n");
3326 return lpwite->response;
3329 /***********************************************************************
3330 * INTERNET_GetNextLine (internal)
3332 * Parse next line in directory string listing
3334 * RETURNS
3335 * Pointer to beginning of next line
3336 * NULL on failure
3340 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3342 struct timeval tv;
3343 fd_set infd;
3344 BOOL bSuccess = FALSE;
3345 INT nRecv = 0;
3346 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3348 TRACE("\n");
3350 FD_ZERO(&infd);
3351 FD_SET(nSocket, &infd);
3352 tv.tv_sec=RESPONSE_TIMEOUT;
3353 tv.tv_usec=0;
3355 while (nRecv < MAX_REPLY_LEN)
3357 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3359 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3361 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3362 goto lend;
3365 if (lpszBuffer[nRecv] == '\n')
3367 bSuccess = TRUE;
3368 break;
3370 if (lpszBuffer[nRecv] != '\r')
3371 nRecv++;
3373 else
3375 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3376 goto lend;
3380 lend:
3381 if (bSuccess)
3383 lpszBuffer[nRecv] = '\0';
3384 *dwLen = nRecv - 1;
3385 TRACE(":%d %s\n", nRecv, lpszBuffer);
3386 return lpszBuffer;
3388 else
3390 return NULL;
3394 /**********************************************************
3395 * InternetQueryDataAvailable (WININET.@)
3397 * Determines how much data is available to be read.
3399 * RETURNS
3400 * TRUE on success, FALSE if an error occurred. If
3401 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3402 * no data is presently available, FALSE is returned with
3403 * the last error ERROR_IO_PENDING; a callback with status
3404 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3405 * data is available.
3407 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3408 LPDWORD lpdwNumberOfBytesAvailble,
3409 DWORD dwFlags, DWORD_PTR dwContext)
3411 WININETHANDLEHEADER *hdr;
3412 DWORD res;
3414 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3416 hdr = WININET_GetObject( hFile );
3417 if (!hdr) {
3418 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
3419 return FALSE;
3422 if(hdr->vtbl->QueryDataAvailable) {
3423 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3424 }else {
3425 WARN("wrong handle\n");
3426 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3429 WININET_Release(hdr);
3431 if(res != ERROR_SUCCESS)
3432 SetLastError(res);
3433 return res == ERROR_SUCCESS;
3437 /***********************************************************************
3438 * InternetLockRequestFile (WININET.@)
3440 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3441 *lphLockReqHandle)
3443 FIXME("STUB\n");
3444 return FALSE;
3447 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3449 FIXME("STUB\n");
3450 return FALSE;
3454 /***********************************************************************
3455 * InternetAutodial (WININET.@)
3457 * On windows this function is supposed to dial the default internet
3458 * connection. We don't want to have Wine dial out to the internet so
3459 * we return TRUE by default. It might be nice to check if we are connected.
3461 * RETURNS
3462 * TRUE on success
3463 * FALSE on failure
3466 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3468 FIXME("STUB\n");
3470 /* Tell that we are connected to the internet. */
3471 return TRUE;
3474 /***********************************************************************
3475 * InternetAutodialHangup (WININET.@)
3477 * Hangs up a connection made with InternetAutodial
3479 * PARAM
3480 * dwReserved
3481 * RETURNS
3482 * TRUE on success
3483 * FALSE on failure
3486 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3488 FIXME("STUB\n");
3490 /* we didn't dial, we don't disconnect */
3491 return TRUE;
3494 /***********************************************************************
3495 * InternetCombineUrlA (WININET.@)
3497 * Combine a base URL with a relative URL
3499 * RETURNS
3500 * TRUE on success
3501 * FALSE on failure
3505 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3506 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3507 DWORD dwFlags)
3509 HRESULT hr=S_OK;
3511 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3513 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3514 dwFlags ^= ICU_NO_ENCODE;
3515 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3517 return (hr==S_OK);
3520 /***********************************************************************
3521 * InternetCombineUrlW (WININET.@)
3523 * Combine a base URL with a relative URL
3525 * RETURNS
3526 * TRUE on success
3527 * FALSE on failure
3531 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3532 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3533 DWORD dwFlags)
3535 HRESULT hr=S_OK;
3537 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3539 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3540 dwFlags ^= ICU_NO_ENCODE;
3541 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3543 return (hr==S_OK);
3546 /* max port num is 65535 => 5 digits */
3547 #define MAX_WORD_DIGITS 5
3549 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3550 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3551 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3552 (url)->dw##component##Length : strlen((url)->lpsz##component))
3554 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3556 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3557 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3558 return TRUE;
3559 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3560 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3561 return TRUE;
3562 if ((nScheme == INTERNET_SCHEME_FTP) &&
3563 (nPort == INTERNET_DEFAULT_FTP_PORT))
3564 return TRUE;
3565 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3566 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3567 return TRUE;
3569 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3570 return TRUE;
3572 return FALSE;
3575 /* opaque urls do not fit into the standard url hierarchy and don't have
3576 * two following slashes */
3577 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3579 return (nScheme != INTERNET_SCHEME_FTP) &&
3580 (nScheme != INTERNET_SCHEME_GOPHER) &&
3581 (nScheme != INTERNET_SCHEME_HTTP) &&
3582 (nScheme != INTERNET_SCHEME_HTTPS) &&
3583 (nScheme != INTERNET_SCHEME_FILE);
3586 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3588 int index;
3589 if (scheme < INTERNET_SCHEME_FIRST)
3590 return NULL;
3591 index = scheme - INTERNET_SCHEME_FIRST;
3592 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3593 return NULL;
3594 return (LPCWSTR)&url_schemes[index];
3597 /* we can calculate using ansi strings because we're just
3598 * calculating string length, not size
3600 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3601 LPDWORD lpdwUrlLength)
3603 INTERNET_SCHEME nScheme;
3605 *lpdwUrlLength = 0;
3607 if (lpUrlComponents->lpszScheme)
3609 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3610 *lpdwUrlLength += dwLen;
3611 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3613 else
3615 LPCWSTR scheme;
3617 nScheme = lpUrlComponents->nScheme;
3619 if (nScheme == INTERNET_SCHEME_DEFAULT)
3620 nScheme = INTERNET_SCHEME_HTTP;
3621 scheme = INTERNET_GetSchemeString(nScheme);
3622 *lpdwUrlLength += strlenW(scheme);
3625 (*lpdwUrlLength)++; /* ':' */
3626 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3627 *lpdwUrlLength += strlen("//");
3629 if (lpUrlComponents->lpszUserName)
3631 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3632 *lpdwUrlLength += strlen("@");
3634 else
3636 if (lpUrlComponents->lpszPassword)
3638 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3639 return FALSE;
3643 if (lpUrlComponents->lpszPassword)
3645 *lpdwUrlLength += strlen(":");
3646 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3649 if (lpUrlComponents->lpszHostName)
3651 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3653 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3655 char szPort[MAX_WORD_DIGITS+1];
3657 sprintf(szPort, "%d", lpUrlComponents->nPort);
3658 *lpdwUrlLength += strlen(szPort);
3659 *lpdwUrlLength += strlen(":");
3662 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3663 (*lpdwUrlLength)++; /* '/' */
3666 if (lpUrlComponents->lpszUrlPath)
3667 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3669 return TRUE;
3672 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3674 INT len;
3676 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3678 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3679 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3680 urlCompW->nScheme = lpUrlComponents->nScheme;
3681 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3682 urlCompW->nPort = lpUrlComponents->nPort;
3683 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3684 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3685 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3686 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3688 if (lpUrlComponents->lpszScheme)
3690 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3691 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3692 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3693 -1, urlCompW->lpszScheme, len);
3696 if (lpUrlComponents->lpszHostName)
3698 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3699 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3700 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3701 -1, urlCompW->lpszHostName, len);
3704 if (lpUrlComponents->lpszUserName)
3706 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3707 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3708 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3709 -1, urlCompW->lpszUserName, len);
3712 if (lpUrlComponents->lpszPassword)
3714 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3715 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3716 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3717 -1, urlCompW->lpszPassword, len);
3720 if (lpUrlComponents->lpszUrlPath)
3722 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3723 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3724 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3725 -1, urlCompW->lpszUrlPath, len);
3728 if (lpUrlComponents->lpszExtraInfo)
3730 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3731 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3732 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3733 -1, urlCompW->lpszExtraInfo, len);
3737 /***********************************************************************
3738 * InternetCreateUrlA (WININET.@)
3740 * See InternetCreateUrlW.
3742 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3743 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3745 BOOL ret;
3746 LPWSTR urlW = NULL;
3747 URL_COMPONENTSW urlCompW;
3749 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3751 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3753 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3754 return FALSE;
3757 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3759 if (lpszUrl)
3760 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3762 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3764 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3765 *lpdwUrlLength /= sizeof(WCHAR);
3767 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3768 * minus one, so add one to leave room for NULL terminator
3770 if (ret)
3771 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3773 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3774 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3775 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3776 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3777 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3778 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3779 HeapFree(GetProcessHeap(), 0, urlW);
3781 return ret;
3784 /***********************************************************************
3785 * InternetCreateUrlW (WININET.@)
3787 * Creates a URL from its component parts.
3789 * PARAMS
3790 * lpUrlComponents [I] URL Components.
3791 * dwFlags [I] Flags. See notes.
3792 * lpszUrl [I] Buffer in which to store the created URL.
3793 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3794 * lpszUrl in characters. On output, the number of bytes
3795 * required to store the URL including terminator.
3797 * NOTES
3799 * The dwFlags parameter can be zero or more of the following:
3800 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3802 * RETURNS
3803 * TRUE on success
3804 * FALSE on failure
3807 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3808 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3810 DWORD dwLen;
3811 INTERNET_SCHEME nScheme;
3813 static const WCHAR slashSlashW[] = {'/','/'};
3814 static const WCHAR percentD[] = {'%','d',0};
3816 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3818 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3820 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3821 return FALSE;
3824 if (!calc_url_length(lpUrlComponents, &dwLen))
3825 return FALSE;
3827 if (!lpszUrl || *lpdwUrlLength < dwLen)
3829 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3830 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3831 return FALSE;
3834 *lpdwUrlLength = dwLen;
3835 lpszUrl[0] = 0x00;
3837 dwLen = 0;
3839 if (lpUrlComponents->lpszScheme)
3841 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3842 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3843 lpszUrl += dwLen;
3845 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3847 else
3849 LPCWSTR scheme;
3850 nScheme = lpUrlComponents->nScheme;
3852 if (nScheme == INTERNET_SCHEME_DEFAULT)
3853 nScheme = INTERNET_SCHEME_HTTP;
3855 scheme = INTERNET_GetSchemeString(nScheme);
3856 dwLen = strlenW(scheme);
3857 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3858 lpszUrl += dwLen;
3861 /* all schemes are followed by at least a colon */
3862 *lpszUrl = ':';
3863 lpszUrl++;
3865 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3867 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3868 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3871 if (lpUrlComponents->lpszUserName)
3873 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3874 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3875 lpszUrl += dwLen;
3877 if (lpUrlComponents->lpszPassword)
3879 *lpszUrl = ':';
3880 lpszUrl++;
3882 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3883 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3884 lpszUrl += dwLen;
3887 *lpszUrl = '@';
3888 lpszUrl++;
3891 if (lpUrlComponents->lpszHostName)
3893 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3894 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3895 lpszUrl += dwLen;
3897 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3899 WCHAR szPort[MAX_WORD_DIGITS+1];
3901 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3902 *lpszUrl = ':';
3903 lpszUrl++;
3904 dwLen = strlenW(szPort);
3905 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3906 lpszUrl += dwLen;
3909 /* add slash between hostname and path if necessary */
3910 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3912 *lpszUrl = '/';
3913 lpszUrl++;
3918 if (lpUrlComponents->lpszUrlPath)
3920 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3921 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3922 lpszUrl += dwLen;
3925 *lpszUrl = '\0';
3927 return TRUE;
3930 /***********************************************************************
3931 * InternetConfirmZoneCrossingA (WININET.@)
3934 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3936 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3937 return ERROR_SUCCESS;
3940 /***********************************************************************
3941 * InternetConfirmZoneCrossingW (WININET.@)
3944 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3946 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3947 return ERROR_SUCCESS;
3950 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3951 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3953 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3954 lpdwConnection, dwReserved);
3955 return ERROR_SUCCESS;
3958 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3959 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3961 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3962 lpdwConnection, dwReserved);
3963 return ERROR_SUCCESS;
3966 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3968 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3969 return TRUE;
3972 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3974 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3975 return TRUE;
3978 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
3980 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
3981 return ERROR_SUCCESS;
3984 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3985 PBYTE pbHexHash )
3987 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3988 debugstr_w(pwszTarget), pbHexHash);
3989 return FALSE;
3992 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3994 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
3995 return FALSE;
3998 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4000 FIXME("(%p, %08lx) stub\n", a, b);
4001 return 0;