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
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
31 #ifdef HAVE_CORESERVICES_CORESERVICES_H
32 #define GetCurrentThread MacGetCurrentThread
33 #define LoadResource MacLoadResource
34 #include <CoreServices/CoreServices.h>
35 #undef GetCurrentThread
56 #include "wine/debug.h"
58 #define NO_SHLWAPI_STREAM
61 #include "wine/exception.h"
66 #include "wine/unicode.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
73 CHAR response
[MAX_REPLY_LEN
];
74 } WITHREADERROR
, *LPWITHREADERROR
;
76 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
77 HMODULE WININET_hModule
;
79 static CRITICAL_SECTION WININET_cs
;
80 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
83 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
84 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
86 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
88 static object_header_t
**handle_table
;
89 static UINT_PTR next_handle
;
90 static UINT_PTR handle_table_size
;
101 static ULONG max_conns
= 2, max_1_0_conns
= 4;
102 static ULONG connect_timeout
= 60000;
104 static const WCHAR szInternetSettings
[] =
105 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
106 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
107 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
108 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
109 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
110 static const WCHAR szProxyOverride
[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
112 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
114 UINT_PTR handle
= 0, num
;
115 object_header_t
*ret
;
119 ret
= heap_alloc_zero(size
);
123 list_init(&ret
->children
);
125 EnterCriticalSection( &WININET_cs
);
127 if(!handle_table_size
) {
129 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
132 handle_table_size
= num
;
137 }else if(next_handle
== handle_table_size
) {
138 num
= handle_table_size
* 2;
139 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
142 handle_table_size
= num
;
149 handle
= next_handle
;
150 if(handle_table
[handle
])
151 ERR("handle isn't free but should be\n");
152 handle_table
[handle
] = ret
;
153 ret
->valid_handle
= TRUE
;
155 while(next_handle
< handle_table_size
&& handle_table
[next_handle
])
159 LeaveCriticalSection( &WININET_cs
);
168 ret
->hInternet
= (HINTERNET
)handle
;
171 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
172 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
178 object_header_t
*WININET_AddRef( object_header_t
*info
)
180 ULONG refs
= InterlockedIncrement(&info
->refs
);
181 TRACE("%p -> refcount = %d\n", info
, refs
);
185 object_header_t
*get_handle_object( HINTERNET hinternet
)
187 object_header_t
*info
= NULL
;
188 UINT_PTR handle
= (UINT_PTR
) hinternet
;
190 EnterCriticalSection( &WININET_cs
);
192 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
193 info
= WININET_AddRef(handle_table
[handle
]);
195 LeaveCriticalSection( &WININET_cs
);
197 TRACE("handle %ld -> %p\n", handle
, info
);
202 static void invalidate_handle(object_header_t
*info
)
204 object_header_t
*child
, *next
;
206 if(!info
->valid_handle
)
208 info
->valid_handle
= FALSE
;
210 /* Free all children as native does */
211 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
213 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
214 invalidate_handle( child
);
217 WININET_Release(info
);
220 BOOL
WININET_Release( object_header_t
*info
)
222 ULONG refs
= InterlockedDecrement(&info
->refs
);
223 TRACE( "object %p refcount = %d\n", info
, refs
);
226 invalidate_handle(info
);
227 if ( info
->vtbl
->CloseConnection
)
229 TRACE( "closing connection %p\n", info
);
230 info
->vtbl
->CloseConnection( info
);
232 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
233 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
234 || !(info
->dwInternalFlags
& INET_OPENURL
))
236 INTERNET_SendCallback(info
, info
->dwContext
,
237 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
240 TRACE( "destroying object %p\n", info
);
241 if ( info
->htype
!= WH_HINIT
)
242 list_remove( &info
->entry
);
243 info
->vtbl
->Destroy( info
);
245 if(info
->hInternet
) {
246 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
248 EnterCriticalSection( &WININET_cs
);
250 handle_table
[handle
] = NULL
;
251 if(next_handle
> handle
)
252 next_handle
= handle
;
254 LeaveCriticalSection( &WININET_cs
);
262 /***********************************************************************
263 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
266 * hinstDLL [I] handle to the DLL's instance
268 * lpvReserved [I] reserved, must be NULL
275 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
277 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
280 case DLL_PROCESS_ATTACH
:
282 g_dwTlsErrIndex
= TlsAlloc();
284 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
289 TlsFree(g_dwTlsErrIndex
);
293 WININET_hModule
= hinstDLL
;
296 case DLL_THREAD_ATTACH
:
299 case DLL_THREAD_DETACH
:
300 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
302 heap_free(TlsGetValue(g_dwTlsErrIndex
));
306 case DLL_PROCESS_DETACH
:
307 if (lpvReserved
) break;
308 collect_connections(COLLECT_CLEANUP
);
313 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
315 heap_free(TlsGetValue(g_dwTlsErrIndex
));
316 TlsFree(g_dwTlsErrIndex
);
323 /***********************************************************************
324 * DllInstall (WININET.@)
326 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
328 FIXME("(%x %s): stub\n", bInstall
, debugstr_w(cmdline
));
332 /***********************************************************************
333 * INTERNET_SaveProxySettings
335 * Stores the proxy settings given by lpwai into the registry
338 * ERROR_SUCCESS if no error, or error code on fail
340 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
345 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
348 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
356 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
364 if ((ret
= RegDeleteValueW( key
, szProxyServer
)) && ret
!= ERROR_FILE_NOT_FOUND
)
372 return ERROR_SUCCESS
;
375 /***********************************************************************
376 * INTERNET_FindProxyForProtocol
378 * Searches the proxy string for a proxy of the given protocol.
379 * Returns the found proxy, or the default proxy if none of the given
383 * szProxy [In] proxy string to search
384 * proto [In] protocol to search for, e.g. "http"
385 * foundProxy [Out] found proxy
386 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
389 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
390 * *foundProxyLen is set to the required size in WCHARs, including the
391 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
393 WCHAR
*INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
)
398 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
400 /* First, look for the specified protocol (proto=scheme://host:port) */
401 for (ptr
= szProxy
; ptr
&& *ptr
; )
405 if (!(end
= strchrW(ptr
, ' ')))
406 end
= ptr
+ strlenW(ptr
);
407 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
408 equal
- ptr
== strlenW(proto
) &&
409 !strncmpiW(proto
, ptr
, strlenW(proto
)))
411 ret
= heap_strndupW(equal
+ 1, end
- equal
- 1);
412 TRACE("found proxy for %s: %s\n", debugstr_w(proto
), debugstr_w(ret
));
421 /* It wasn't found: look for no protocol */
422 for (ptr
= szProxy
; ptr
&& *ptr
; )
426 if (!(end
= strchrW(ptr
, ' ')))
427 end
= ptr
+ strlenW(ptr
);
428 if (!strchrW(ptr
, '='))
430 ret
= heap_strndupW(ptr
, end
- ptr
);
431 TRACE("found proxy for %s: %s\n", debugstr_w(proto
), debugstr_w(ret
));
443 /***********************************************************************
444 * InternetInitializeAutoProxyDll (WININET.@)
446 * Setup the internal proxy
455 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
458 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
462 /***********************************************************************
463 * DetectAutoProxyUrl (WININET.@)
465 * Auto detect the proxy url
471 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
472 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
475 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
479 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
481 heap_free(lpwpi
->proxy
);
482 heap_free(lpwpi
->proxyBypass
);
483 heap_free(lpwpi
->proxyUsername
);
484 heap_free(lpwpi
->proxyPassword
);
487 static proxyinfo_t
*global_proxy
;
489 static void free_global_proxy( void )
491 EnterCriticalSection( &WININET_cs
);
494 FreeProxyInfo( global_proxy
);
495 heap_free( global_proxy
);
497 LeaveCriticalSection( &WININET_cs
);
500 static BOOL
parse_proxy_url( proxyinfo_t
*info
, const WCHAR
*url
)
502 static const WCHAR fmt
[] = {'%','.','*','s',':','%','u',0};
503 URL_COMPONENTSW uc
= {sizeof(uc
)};
505 uc
.dwHostNameLength
= 1;
506 uc
.dwUserNameLength
= 1;
507 uc
.dwPasswordLength
= 1;
509 if (!InternetCrackUrlW( url
, 0, 0, &uc
)) return FALSE
;
510 if (!uc
.dwHostNameLength
)
512 if (!(info
->proxy
= heap_strdupW( url
))) return FALSE
;
513 info
->proxyUsername
= NULL
;
514 info
->proxyPassword
= NULL
;
517 if (!(info
->proxy
= heap_alloc( (uc
.dwHostNameLength
+ 12) * sizeof(WCHAR
) ))) return FALSE
;
518 sprintfW( info
->proxy
, fmt
, uc
.dwHostNameLength
, uc
.lpszHostName
, uc
.nPort
);
520 if (!uc
.dwUserNameLength
) info
->proxyUsername
= NULL
;
521 else if (!(info
->proxyUsername
= heap_strndupW( uc
.lpszUserName
, uc
.dwUserNameLength
)))
523 heap_free( info
->proxy
);
526 if (!uc
.dwPasswordLength
) info
->proxyPassword
= NULL
;
527 else if (!(info
->proxyPassword
= heap_strndupW( uc
.lpszPassword
, uc
.dwPasswordLength
)))
529 heap_free( info
->proxyUsername
);
530 heap_free( info
->proxy
);
536 /***********************************************************************
537 * INTERNET_LoadProxySettings
539 * Loads proxy information from process-wide global settings, the registry,
540 * or the environment into lpwpi.
542 * The caller should call FreeProxyInfo when done with lpwpi.
545 * The proxy may be specified in the form 'http=proxy.my.org'
546 * Presumably that means there can be ftp=ftpproxy.my.org too.
548 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
555 memset( lpwpi
, 0, sizeof(*lpwpi
) );
557 EnterCriticalSection( &WININET_cs
);
560 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
561 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
562 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
564 LeaveCriticalSection( &WININET_cs
);
566 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
568 FreeProxyInfo( lpwpi
);
573 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
575 lpwpi
->proxyEnabled
= 0;
576 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
578 FreeProxyInfo( lpwpi
);
584 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
586 /* figure out how much memory the proxy setting takes */
587 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
590 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
592 if (!(szProxy
= heap_alloc(len
)))
595 FreeProxyInfo( lpwpi
);
596 return ERROR_OUTOFMEMORY
;
598 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
600 /* find the http proxy, and strip away everything else */
601 p
= strstrW( szProxy
, szHttp
);
604 p
+= lstrlenW( szHttp
);
605 lstrcpyW( szProxy
, p
);
607 p
= strchrW( szProxy
, ';' );
610 FreeProxyInfo( lpwpi
);
611 lpwpi
->proxy
= szProxy
;
612 lpwpi
->proxyBypass
= NULL
;
614 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi
->proxy
));
618 TRACE("No proxy server settings in registry.\n");
619 FreeProxyInfo( lpwpi
);
621 lpwpi
->proxyBypass
= NULL
;
628 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
629 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
632 return ERROR_OUTOFMEMORY
;
634 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
636 FreeProxyInfo( lpwpi
);
637 if (parse_proxy_url( lpwpi
, envproxyW
))
639 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
640 lpwpi
->proxyEnabled
= 1;
641 lpwpi
->proxyBypass
= NULL
;
645 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW
));
646 lpwpi
->proxyEnabled
= 0;
648 lpwpi
->proxyBypass
= NULL
;
650 heap_free( envproxyW
);
653 if (lpwpi
->proxyEnabled
)
655 TRACE("Proxy is enabled.\n");
657 if (!(envproxy
= getenv( "no_proxy" )))
659 /* figure out how much memory the proxy setting takes */
660 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
664 if (!(szProxy
= heap_alloc(len
)))
667 return ERROR_OUTOFMEMORY
;
669 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
671 heap_free( lpwpi
->proxyBypass
);
672 lpwpi
->proxyBypass
= szProxy
;
674 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
678 heap_free( lpwpi
->proxyBypass
);
679 lpwpi
->proxyBypass
= NULL
;
681 TRACE("No proxy bypass server settings in registry.\n");
688 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
689 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
692 return ERROR_OUTOFMEMORY
;
694 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
696 heap_free( lpwpi
->proxyBypass
);
697 lpwpi
->proxyBypass
= envproxyW
;
699 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
702 else TRACE("Proxy is disabled.\n");
705 return ERROR_SUCCESS
;
708 /***********************************************************************
709 * INTERNET_ConfigureProxy
711 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
715 if (INTERNET_LoadProxySettings( &wpi
))
718 if (wpi
.proxyEnabled
)
720 TRACE("http proxy = %s bypass = %s\n", debugstr_w(wpi
.proxy
), debugstr_w(wpi
.proxyBypass
));
722 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
723 lpwai
->proxy
= wpi
.proxy
;
724 lpwai
->proxyBypass
= wpi
.proxyBypass
;
725 lpwai
->proxyUsername
= wpi
.proxyUsername
;
726 lpwai
->proxyPassword
= wpi
.proxyPassword
;
730 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
735 /***********************************************************************
736 * dump_INTERNET_FLAGS
738 * Helper function to TRACE the internet flags.
744 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
746 #define FE(x) { x, #x }
747 static const wininet_flag_info flag
[] = {
748 FE(INTERNET_FLAG_RELOAD
),
749 FE(INTERNET_FLAG_RAW_DATA
),
750 FE(INTERNET_FLAG_EXISTING_CONNECT
),
751 FE(INTERNET_FLAG_ASYNC
),
752 FE(INTERNET_FLAG_PASSIVE
),
753 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
754 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
755 FE(INTERNET_FLAG_FROM_CACHE
),
756 FE(INTERNET_FLAG_SECURE
),
757 FE(INTERNET_FLAG_KEEP_CONNECTION
),
758 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
759 FE(INTERNET_FLAG_READ_PREFETCH
),
760 FE(INTERNET_FLAG_NO_COOKIES
),
761 FE(INTERNET_FLAG_NO_AUTH
),
762 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
763 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
764 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
765 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
766 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
767 FE(INTERNET_FLAG_RESYNCHRONIZE
),
768 FE(INTERNET_FLAG_HYPERLINK
),
769 FE(INTERNET_FLAG_NO_UI
),
770 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
771 FE(INTERNET_FLAG_CACHE_ASYNC
),
772 FE(INTERNET_FLAG_FORMS_SUBMIT
),
773 FE(INTERNET_FLAG_NEED_FILE
),
774 FE(INTERNET_FLAG_TRANSFER_ASCII
),
775 FE(INTERNET_FLAG_TRANSFER_BINARY
)
780 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
781 if (flag
[i
].val
& dwFlags
) {
782 TRACE(" %s", flag
[i
].name
);
783 dwFlags
&= ~flag
[i
].val
;
787 TRACE(" Unknown flags (%08x)\n", dwFlags
);
792 /***********************************************************************
793 * INTERNET_CloseHandle (internal)
795 * Close internet handle
798 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
800 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
804 heap_free(lpwai
->agent
);
805 heap_free(lpwai
->proxy
);
806 heap_free(lpwai
->proxyBypass
);
807 heap_free(lpwai
->proxyUsername
);
808 heap_free(lpwai
->proxyPassword
);
811 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
813 appinfo_t
*ai
= (appinfo_t
*)hdr
;
816 case INTERNET_OPTION_HANDLE_TYPE
:
817 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
819 if (*size
< sizeof(ULONG
))
820 return ERROR_INSUFFICIENT_BUFFER
;
822 *size
= sizeof(DWORD
);
823 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
824 return ERROR_SUCCESS
;
826 case INTERNET_OPTION_USER_AGENT
: {
829 TRACE("INTERNET_OPTION_USER_AGENT\n");
834 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
836 *size
= (len
+ 1) * sizeof(WCHAR
);
837 if(!buffer
|| bufsize
< *size
)
838 return ERROR_INSUFFICIENT_BUFFER
;
841 strcpyW(buffer
, ai
->agent
);
843 *(WCHAR
*)buffer
= 0;
844 /* If the buffer is copied, the returned length doesn't include
845 * the NULL terminator.
850 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
853 if(!buffer
|| bufsize
< *size
)
854 return ERROR_INSUFFICIENT_BUFFER
;
857 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
860 /* If the buffer is copied, the returned length doesn't include
861 * the NULL terminator.
866 return ERROR_SUCCESS
;
869 case INTERNET_OPTION_PROXY
:
870 if(!size
) return ERROR_INVALID_PARAMETER
;
872 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
873 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
874 LPWSTR proxy
, proxy_bypass
;
877 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
879 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
880 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
882 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
883 return ERROR_INSUFFICIENT_BUFFER
;
885 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
886 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
888 pi
->dwAccessType
= ai
->accessType
;
889 pi
->lpszProxy
= NULL
;
890 pi
->lpszProxyBypass
= NULL
;
892 lstrcpyW(proxy
, ai
->proxy
);
893 pi
->lpszProxy
= proxy
;
896 if (ai
->proxyBypass
) {
897 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
898 pi
->lpszProxyBypass
= proxy_bypass
;
901 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
902 return ERROR_SUCCESS
;
904 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
905 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
906 LPSTR proxy
, proxy_bypass
;
909 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
911 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
912 NULL
, 0, NULL
, NULL
);
913 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
915 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
916 return ERROR_INSUFFICIENT_BUFFER
;
918 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
919 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
921 pi
->dwAccessType
= ai
->accessType
;
922 pi
->lpszProxy
= NULL
;
923 pi
->lpszProxyBypass
= NULL
;
925 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
926 pi
->lpszProxy
= proxy
;
929 if (ai
->proxyBypass
) {
930 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
931 proxyBypassBytesRequired
, NULL
, NULL
);
932 pi
->lpszProxyBypass
= proxy_bypass
;
935 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
936 return ERROR_SUCCESS
;
939 case INTERNET_OPTION_CONNECT_TIMEOUT
:
940 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
942 if (*size
< sizeof(ULONG
))
943 return ERROR_INSUFFICIENT_BUFFER
;
945 *(ULONG
*)buffer
= ai
->connect_timeout
;
946 *size
= sizeof(ULONG
);
948 return ERROR_SUCCESS
;
951 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
954 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
956 appinfo_t
*ai
= (appinfo_t
*)hdr
;
959 case INTERNET_OPTION_CONNECT_TIMEOUT
:
960 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
962 if(size
!= sizeof(connect_timeout
))
963 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
965 return ERROR_BAD_ARGUMENTS
;
967 ai
->connect_timeout
= *(ULONG
*)buf
;
968 return ERROR_SUCCESS
;
969 case INTERNET_OPTION_USER_AGENT
:
970 heap_free(ai
->agent
);
971 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
972 return ERROR_SUCCESS
;
975 return INET_SetOption(hdr
, option
, buf
, size
);
978 static const object_vtbl_t APPINFOVtbl
= {
989 /***********************************************************************
990 * InternetOpenW (WININET.@)
992 * Per-application initialization of wininet
995 * HINTERNET on success
999 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
1000 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
1002 appinfo_t
*lpwai
= NULL
;
1004 if (TRACE_ON(wininet
)) {
1005 #define FE(x) { x, #x }
1006 static const wininet_flag_info access_type
[] = {
1007 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
1008 FE(INTERNET_OPEN_TYPE_DIRECT
),
1009 FE(INTERNET_OPEN_TYPE_PROXY
),
1010 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
1014 const char *access_type_str
= "Unknown";
1016 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1017 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1018 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
1019 if (access_type
[i
].val
== dwAccessType
) {
1020 access_type_str
= access_type
[i
].name
;
1024 TRACE(" access type : %s\n", access_type_str
);
1026 dump_INTERNET_FLAGS(dwFlags
);
1029 /* Clear any error information */
1030 INTERNET_SetLastError(0);
1032 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1033 SetLastError(ERROR_INVALID_PARAMETER
);
1037 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1039 SetLastError(ERROR_OUTOFMEMORY
);
1043 lpwai
->hdr
.htype
= WH_HINIT
;
1044 lpwai
->hdr
.dwFlags
= dwFlags
;
1045 lpwai
->accessType
= dwAccessType
;
1046 lpwai
->proxyUsername
= NULL
;
1047 lpwai
->proxyPassword
= NULL
;
1048 lpwai
->connect_timeout
= connect_timeout
;
1050 lpwai
->agent
= heap_strdupW(lpszAgent
);
1051 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1052 INTERNET_ConfigureProxy( lpwai
);
1053 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1054 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1055 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1058 TRACE("returning %p\n", lpwai
);
1060 return lpwai
->hdr
.hInternet
;
1064 /***********************************************************************
1065 * InternetOpenA (WININET.@)
1067 * Per-application initialization of wininet
1070 * HINTERNET on success
1074 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1075 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1077 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1080 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1081 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1083 szAgent
= heap_strdupAtoW(lpszAgent
);
1084 szProxy
= heap_strdupAtoW(lpszProxy
);
1085 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1087 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1091 heap_free(szBypass
);
1095 /***********************************************************************
1096 * InternetGetLastResponseInfoA (WININET.@)
1098 * Return last wininet error description on the calling thread
1101 * TRUE on success of writing to buffer
1105 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1106 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1108 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1114 *lpdwError
= lpwite
->dwError
;
1115 if (lpwite
->dwError
)
1117 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1118 *lpdwBufferLength
= strlen(lpszBuffer
);
1121 *lpdwBufferLength
= 0;
1126 *lpdwBufferLength
= 0;
1132 /***********************************************************************
1133 * InternetGetLastResponseInfoW (WININET.@)
1135 * Return last wininet error description on the calling thread
1138 * TRUE on success of writing to buffer
1142 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1143 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1145 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1151 *lpdwError
= lpwite
->dwError
;
1152 if (lpwite
->dwError
)
1154 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1155 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1158 *lpdwBufferLength
= 0;
1163 *lpdwBufferLength
= 0;
1169 /***********************************************************************
1170 * InternetGetConnectedState (WININET.@)
1172 * Return connected state
1176 * if lpdwStatus is not null, return the status (off line,
1177 * modem, lan...) in it.
1178 * FALSE if not connected
1180 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1182 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1184 return InternetGetConnectedStateExW(lpdwStatus
, NULL
, 0, dwReserved
);
1188 /***********************************************************************
1189 * InternetGetConnectedStateExW (WININET.@)
1191 * Return connected state
1195 * lpdwStatus [O] Flags specifying the status of the internet connection.
1196 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1197 * dwNameLen [I] Size of the buffer, in characters.
1198 * dwReserved [I] Reserved. Must be set to 0.
1202 * if lpdwStatus is not null, return the status (off line,
1203 * modem, lan...) in it.
1204 * FALSE if not connected
1207 * If the system has no available network connections, an empty string is
1208 * stored in lpszConnectionName. If there is a LAN connection, a localized
1209 * "LAN Connection" string is stored. Presumably, if only a dial-up
1210 * connection is available then the name of the dial-up connection is
1211 * returned. Why any application, other than the "Internet Settings" CPL,
1212 * would want to use this function instead of the simpler InternetGetConnectedStateW
1213 * function is beyond me.
1215 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1216 DWORD dwNameLen
, DWORD dwReserved
)
1218 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1225 WARN("always returning LAN connection.\n");
1226 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1229 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1230 * the resource, avoid it as we must not change the buffer in this case */
1231 if(lpszConnectionName
&& dwNameLen
) {
1232 *lpszConnectionName
= '\0';
1233 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1240 /***********************************************************************
1241 * InternetGetConnectedStateExA (WININET.@)
1243 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1244 DWORD dwNameLen
, DWORD dwReserved
)
1246 LPWSTR lpwszConnectionName
= NULL
;
1249 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1251 if (lpszConnectionName
&& dwNameLen
> 0)
1252 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1254 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1256 if (rc
&& lpwszConnectionName
)
1257 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1258 dwNameLen
, NULL
, NULL
);
1260 heap_free(lpwszConnectionName
);
1265 /***********************************************************************
1266 * InternetConnectW (WININET.@)
1268 * Open a ftp, gopher or http session
1271 * HINTERNET a session handle on success
1275 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1276 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1277 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1278 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1281 HINTERNET rc
= NULL
;
1282 DWORD res
= ERROR_SUCCESS
;
1284 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1285 nServerPort
, debugstr_w(lpszUserName
), lpszPassword
, dwService
, dwFlags
, dwContext
);
1287 if (!lpszServerName
)
1289 SetLastError(ERROR_INVALID_PARAMETER
);
1293 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1294 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1296 res
= ERROR_INVALID_HANDLE
;
1302 case INTERNET_SERVICE_FTP
:
1303 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1304 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1306 res
= INTERNET_GetLastError();
1309 case INTERNET_SERVICE_HTTP
:
1310 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1311 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1314 case INTERNET_SERVICE_GOPHER
:
1320 WININET_Release( &hIC
->hdr
);
1322 TRACE("returning %p\n", rc
);
1328 /***********************************************************************
1329 * InternetConnectA (WININET.@)
1331 * Open a ftp, gopher or http session
1334 * HINTERNET a session handle on success
1338 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1339 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1340 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1341 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1343 HINTERNET rc
= NULL
;
1344 LPWSTR szServerName
;
1348 szServerName
= heap_strdupAtoW(lpszServerName
);
1349 szUserName
= heap_strdupAtoW(lpszUserName
);
1350 szPassword
= heap_strdupAtoW(lpszPassword
);
1352 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1353 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1355 heap_free(szServerName
);
1356 heap_free(szUserName
);
1357 heap_free(szPassword
);
1362 /***********************************************************************
1363 * InternetFindNextFileA (WININET.@)
1365 * Continues a file search from a previous call to FindFirstFile
1372 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1375 WIN32_FIND_DATAW fd
;
1377 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1379 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1383 /***********************************************************************
1384 * InternetFindNextFileW (WININET.@)
1386 * Continues a file search from a previous call to FindFirstFile
1393 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1395 object_header_t
*hdr
;
1400 hdr
= get_handle_object(hFind
);
1402 WARN("Invalid handle\n");
1403 SetLastError(ERROR_INVALID_HANDLE
);
1407 if(hdr
->vtbl
->FindNextFileW
) {
1408 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1410 WARN("Handle doesn't support NextFile\n");
1411 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1414 WININET_Release(hdr
);
1416 if(res
!= ERROR_SUCCESS
)
1418 return res
== ERROR_SUCCESS
;
1421 /***********************************************************************
1422 * InternetCloseHandle (WININET.@)
1424 * Generic close handle function
1431 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1433 object_header_t
*obj
;
1435 TRACE("%p\n", hInternet
);
1437 obj
= get_handle_object( hInternet
);
1439 SetLastError(ERROR_INVALID_HANDLE
);
1443 invalidate_handle(obj
);
1444 WININET_Release(obj
);
1449 static BOOL
set_url_component(WCHAR
**component
, DWORD
*component_length
, const WCHAR
*value
, DWORD len
)
1451 TRACE("%s (%d)\n", debugstr_wn(value
, len
), len
);
1453 if (!*component_length
)
1457 *(const WCHAR
**)component
= value
;
1458 *component_length
= len
;
1462 if (*component_length
< len
+1) {
1463 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1467 *component_length
= len
;
1469 memcpy(*component
, value
, len
*sizeof(WCHAR
));
1470 (*component
)[len
] = 0;
1474 static BOOL
set_url_component_WtoA(const WCHAR
*comp_w
, DWORD length
, const WCHAR
*url_w
, char **comp
, DWORD
*ret_length
,
1477 size_t size
, ret_size
= *ret_length
;
1481 size
= WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, NULL
, 0, NULL
, NULL
);
1484 *comp
= comp_w
? (char*)url_a
+ WideCharToMultiByte(CP_ACP
, 0, url_w
, comp_w
-url_w
, NULL
, 0, NULL
, NULL
) : NULL
;
1489 if (size
+1 > ret_size
) {
1490 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1491 *ret_length
= size
+1;
1496 WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, *comp
, ret_size
-1, NULL
, NULL
);
1501 static BOOL
set_url_component_AtoW(const char *comp_a
, DWORD len_a
, WCHAR
**comp_w
, DWORD
*len_w
, WCHAR
**buf
)
1510 if(!(*comp_w
= *buf
= heap_alloc(len_a
*sizeof(WCHAR
)))) {
1511 SetLastError(ERROR_OUTOFMEMORY
);
1518 /***********************************************************************
1519 * InternetCrackUrlA (WININET.@)
1521 * See InternetCrackUrlW.
1523 BOOL WINAPI
InternetCrackUrlA(const char *url
, DWORD url_length
, DWORD flags
, URL_COMPONENTSA
*ret_comp
)
1525 WCHAR
*host
= NULL
, *user
= NULL
, *pass
= NULL
, *path
= NULL
, *scheme
= NULL
, *extra
= NULL
;
1526 URL_COMPONENTSW comp
;
1527 WCHAR
*url_w
= NULL
;
1530 TRACE("(%s %u %x %p)\n", url_length
? debugstr_an(url
, url_length
) : debugstr_a(url
), url_length
, flags
, ret_comp
);
1532 if (!url
|| !*url
|| !ret_comp
|| ret_comp
->dwStructSize
!= sizeof(URL_COMPONENTSA
)) {
1533 SetLastError(ERROR_INVALID_PARAMETER
);
1537 comp
.dwStructSize
= sizeof(comp
);
1539 ret
= set_url_component_AtoW(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
,
1540 &comp
.lpszHostName
, &comp
.dwHostNameLength
, &host
)
1541 && set_url_component_AtoW(ret_comp
->lpszUserName
, ret_comp
->dwUserNameLength
,
1542 &comp
.lpszUserName
, &comp
.dwUserNameLength
, &user
)
1543 && set_url_component_AtoW(ret_comp
->lpszPassword
, ret_comp
->dwPasswordLength
,
1544 &comp
.lpszPassword
, &comp
.dwPasswordLength
, &pass
)
1545 && set_url_component_AtoW(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
,
1546 &comp
.lpszUrlPath
, &comp
.dwUrlPathLength
, &path
)
1547 && set_url_component_AtoW(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
,
1548 &comp
.lpszScheme
, &comp
.dwSchemeLength
, &scheme
)
1549 && set_url_component_AtoW(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
,
1550 &comp
.lpszExtraInfo
, &comp
.dwExtraInfoLength
, &extra
);
1552 if(ret
&& !(url_w
= heap_strndupAtoW(url
, url_length
? url_length
: -1, &url_length
))) {
1553 SetLastError(ERROR_OUTOFMEMORY
);
1557 if (ret
&& (ret
= InternetCrackUrlW(url_w
, url_length
, flags
, &comp
))) {
1558 ret_comp
->nScheme
= comp
.nScheme
;
1559 ret_comp
->nPort
= comp
.nPort
;
1561 ret
= set_url_component_WtoA(comp
.lpszHostName
, comp
.dwHostNameLength
, url_w
,
1562 &ret_comp
->lpszHostName
, &ret_comp
->dwHostNameLength
, url
)
1563 && set_url_component_WtoA(comp
.lpszUserName
, comp
.dwUserNameLength
, url_w
,
1564 &ret_comp
->lpszUserName
, &ret_comp
->dwUserNameLength
, url
)
1565 && set_url_component_WtoA(comp
.lpszPassword
, comp
.dwPasswordLength
, url_w
,
1566 &ret_comp
->lpszPassword
, &ret_comp
->dwPasswordLength
, url
)
1567 && set_url_component_WtoA(comp
.lpszUrlPath
, comp
.dwUrlPathLength
, url_w
,
1568 &ret_comp
->lpszUrlPath
, &ret_comp
->dwUrlPathLength
, url
)
1569 && set_url_component_WtoA(comp
.lpszScheme
, comp
.dwSchemeLength
, url_w
,
1570 &ret_comp
->lpszScheme
, &ret_comp
->dwSchemeLength
, url
)
1571 && set_url_component_WtoA(comp
.lpszExtraInfo
, comp
.dwExtraInfoLength
, url_w
,
1572 &ret_comp
->lpszExtraInfo
, &ret_comp
->dwExtraInfoLength
, url
);
1575 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url
),
1576 debugstr_an(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
),
1577 debugstr_an(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
),
1578 debugstr_an(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
),
1579 debugstr_an(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
));
1592 static const WCHAR url_schemes
[][7] =
1595 {'g','o','p','h','e','r',0},
1596 {'h','t','t','p',0},
1597 {'h','t','t','p','s',0},
1598 {'f','i','l','e',0},
1599 {'n','e','w','s',0},
1600 {'m','a','i','l','t','o',0},
1604 /***********************************************************************
1605 * GetInternetSchemeW (internal)
1611 * INTERNET_SCHEME_UNKNOWN on failure
1614 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1618 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1620 if(lpszScheme
==NULL
)
1621 return INTERNET_SCHEME_UNKNOWN
;
1623 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1624 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1625 return INTERNET_SCHEME_FIRST
+ i
;
1627 return INTERNET_SCHEME_UNKNOWN
;
1630 /***********************************************************************
1631 * InternetCrackUrlW (WININET.@)
1633 * Break up URL into its components
1639 BOOL WINAPI
InternetCrackUrlW(const WCHAR
*lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
, URL_COMPONENTSW
*lpUC
)
1643 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1646 LPCWSTR lpszParam
= NULL
;
1647 BOOL found_colon
= FALSE
;
1649 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1651 TRACE("(%s %u %x %p)\n",
1652 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1653 dwUrlLength
, dwFlags
, lpUC
);
1655 if (!lpszUrl
|| !*lpszUrl
|| !lpUC
)
1657 SetLastError(ERROR_INVALID_PARAMETER
);
1660 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1662 if (dwFlags
& ICU_DECODE
)
1665 DWORD len
= dwUrlLength
+ 1;
1668 if (!(url_tmp
= heap_strndupW(lpszUrl
, dwUrlLength
)))
1670 SetLastError(ERROR_OUTOFMEMORY
);
1673 ret
= InternetCanonicalizeUrlW(url_tmp
, url_tmp
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1675 ret
= InternetCrackUrlW(url_tmp
, len
, dwFlags
& ~ICU_DECODE
, lpUC
);
1681 /* Determine if the URI is absolute. */
1682 while (lpszap
- lpszUrl
< dwUrlLength
)
1684 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1696 lpszcp
= lpszUrl
; /* Relative url */
1703 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1707 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1708 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1710 /* Parse <params> */
1711 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1713 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1715 if(!set_url_component(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1716 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0))
1720 /* Get scheme first. */
1721 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1722 if(!set_url_component(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, lpszUrl
, lpszcp
- lpszUrl
))
1725 /* Eat ':' in protocol. */
1728 /* double slash indicates the net_loc portion is present */
1729 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1733 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1737 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1739 lpszNetLoc
= lpszParam
;
1741 else if (!lpszNetLoc
)
1742 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1750 /* [<user>[<:password>]@]<host>[:<port>] */
1751 /* First find the user and password if they exist */
1753 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1754 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1756 /* username and password not specified. */
1757 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1758 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1760 else /* Parse out username and password */
1762 LPCWSTR lpszUser
= lpszcp
;
1763 LPCWSTR lpszPasswd
= lpszHost
;
1765 while (lpszcp
< lpszHost
)
1768 lpszPasswd
= lpszcp
;
1773 if(!set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, lpszUser
, lpszPasswd
- lpszUser
))
1776 if (lpszPasswd
!= lpszHost
)
1778 if(!set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1779 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
, lpszHost
- lpszPasswd
))
1782 lpszcp
++; /* Advance to beginning of host */
1785 /* Parse <host><:port> */
1788 lpszPort
= lpszNetLoc
;
1790 /* special case for res:// URLs: there is no port here, so the host is the
1791 entire string up to the first '/' */
1792 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1794 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1800 while (lpszcp
< lpszNetLoc
)
1808 /* If the scheme is "file" and the host is just one letter, it's not a host */
1809 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1812 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1816 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1818 if (lpszPort
!= lpszNetLoc
)
1819 lpUC
->nPort
= atoiW(++lpszPort
);
1820 else switch (lpUC
->nScheme
)
1822 case INTERNET_SCHEME_HTTP
:
1823 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1825 case INTERNET_SCHEME_HTTPS
:
1826 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1828 case INTERNET_SCHEME_FTP
:
1829 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1831 case INTERNET_SCHEME_GOPHER
:
1832 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1843 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1844 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1845 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1848 /* Here lpszcp points to:
1850 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1851 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1853 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1857 /* Only truncate the parameter list if it's already been saved
1858 * in lpUC->lpszExtraInfo.
1860 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1861 len
= lpszParam
- lpszcp
;
1864 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1865 * newlines if necessary.
1867 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1868 if (lpsznewline
!= NULL
)
1869 len
= lpsznewline
- lpszcp
;
1871 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1873 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1874 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1876 WCHAR tmppath
[MAX_PATH
];
1880 PathCreateFromUrlW(lpszUrl
, tmppath
, &len
, 0);
1885 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1886 tmppath
[len
] = '\0';
1895 /* if ends in \. or \.. append a backslash */
1896 if (tmppath
[len
- 1] == '.' &&
1897 (tmppath
[len
- 2] == '\\' ||
1898 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1900 if (len
< MAX_PATH
- 1)
1902 tmppath
[len
] = '\\';
1903 tmppath
[len
+1] = '\0';
1907 if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, tmppath
, len
))
1910 else if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, len
))
1915 set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, 0);
1918 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1919 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1920 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1921 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1922 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1927 /***********************************************************************
1928 * InternetAttemptConnect (WININET.@)
1930 * Attempt to make a connection to the internet
1933 * ERROR_SUCCESS on success
1934 * Error value on failure
1937 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1940 return ERROR_SUCCESS
;
1944 /***********************************************************************
1945 * convert_url_canonicalization_flags
1947 * Helper for InternetCanonicalizeUrl
1950 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1953 * Flags suitable for UrlCanonicalize
1955 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1957 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1959 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1960 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1961 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1962 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1963 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1964 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1965 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1970 /***********************************************************************
1971 * InternetCanonicalizeUrlA (WININET.@)
1973 * Escape unsafe characters and spaces
1980 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1981 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1985 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1986 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1988 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
1989 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1990 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1991 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1996 /***********************************************************************
1997 * InternetCanonicalizeUrlW (WININET.@)
1999 * Escape unsafe characters and spaces
2006 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2007 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2011 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2012 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2014 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2015 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2016 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2017 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2022 /* #################################################### */
2024 static INTERNET_STATUS_CALLBACK
set_status_callback(
2025 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2027 INTERNET_STATUS_CALLBACK ret
;
2029 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2030 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2032 ret
= lpwh
->lpfnStatusCB
;
2033 lpwh
->lpfnStatusCB
= callback
;
2038 /***********************************************************************
2039 * InternetSetStatusCallbackA (WININET.@)
2041 * Sets up a callback function which is called as progress is made
2042 * during an operation.
2045 * Previous callback or NULL on success
2046 * INTERNET_INVALID_STATUS_CALLBACK on failure
2049 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2050 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2052 INTERNET_STATUS_CALLBACK retVal
;
2053 object_header_t
*lpwh
;
2055 TRACE("%p\n", hInternet
);
2057 if (!(lpwh
= get_handle_object(hInternet
)))
2058 return INTERNET_INVALID_STATUS_CALLBACK
;
2060 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2062 WININET_Release( lpwh
);
2066 /***********************************************************************
2067 * InternetSetStatusCallbackW (WININET.@)
2069 * Sets up a callback function which is called as progress is made
2070 * during an operation.
2073 * Previous callback or NULL on success
2074 * INTERNET_INVALID_STATUS_CALLBACK on failure
2077 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2078 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2080 INTERNET_STATUS_CALLBACK retVal
;
2081 object_header_t
*lpwh
;
2083 TRACE("%p\n", hInternet
);
2085 if (!(lpwh
= get_handle_object(hInternet
)))
2086 return INTERNET_INVALID_STATUS_CALLBACK
;
2088 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2090 WININET_Release( lpwh
);
2094 /***********************************************************************
2095 * InternetSetFilePointer (WININET.@)
2097 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2098 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2100 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2104 /***********************************************************************
2105 * InternetWriteFile (WININET.@)
2107 * Write data to an open internet file
2114 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2115 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2117 object_header_t
*lpwh
;
2120 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2122 lpwh
= get_handle_object( hFile
);
2124 WARN("Invalid handle\n");
2125 SetLastError(ERROR_INVALID_HANDLE
);
2129 if(lpwh
->vtbl
->WriteFile
) {
2130 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2132 WARN("No Writefile method.\n");
2133 res
= ERROR_INVALID_HANDLE
;
2136 WININET_Release( lpwh
);
2138 if(res
!= ERROR_SUCCESS
)
2140 return res
== ERROR_SUCCESS
;
2144 /***********************************************************************
2145 * InternetReadFile (WININET.@)
2147 * Read data from an open internet file
2154 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2155 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2157 object_header_t
*hdr
;
2158 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2160 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2162 hdr
= get_handle_object(hFile
);
2164 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2168 if(hdr
->vtbl
->ReadFile
) {
2169 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, 0, 0);
2170 if(res
== ERROR_IO_PENDING
)
2171 *pdwNumOfBytesRead
= 0;
2174 WININET_Release(hdr
);
2176 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2177 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2179 if(res
!= ERROR_SUCCESS
)
2181 return res
== ERROR_SUCCESS
;
2184 /***********************************************************************
2185 * InternetReadFileExA (WININET.@)
2187 * Read data from an open internet file
2190 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2191 * lpBuffersOut [I/O] Buffer.
2192 * dwFlags [I] Flags. See notes.
2193 * dwContext [I] Context for callbacks.
2200 * The parameter dwFlags include zero or more of the following flags:
2201 *|IRF_ASYNC - Makes the call asynchronous.
2202 *|IRF_SYNC - Makes the call synchronous.
2203 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2204 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2206 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2209 * InternetOpenUrlA(), HttpOpenRequestA()
2211 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2212 DWORD dwFlags
, DWORD_PTR dwContext
)
2214 object_header_t
*hdr
;
2215 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2217 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2219 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2220 SetLastError(ERROR_INVALID_PARAMETER
);
2224 hdr
= get_handle_object(hFile
);
2226 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2230 if(hdr
->vtbl
->ReadFile
)
2231 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2232 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2234 WININET_Release(hdr
);
2236 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2237 res
, lpBuffersOut
->dwBufferLength
);
2239 if(res
!= ERROR_SUCCESS
)
2241 return res
== ERROR_SUCCESS
;
2244 /***********************************************************************
2245 * InternetReadFileExW (WININET.@)
2247 * InternetReadFileExA()
2249 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2250 DWORD dwFlags
, DWORD_PTR dwContext
)
2252 object_header_t
*hdr
;
2253 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2255 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2257 if (!lpBuffer
|| lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2258 SetLastError(ERROR_INVALID_PARAMETER
);
2262 hdr
= get_handle_object(hFile
);
2264 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2268 if(hdr
->vtbl
->ReadFile
)
2269 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2270 dwFlags
, dwContext
);
2272 WININET_Release(hdr
);
2274 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2275 res
, lpBuffer
->dwBufferLength
);
2277 if(res
!= ERROR_SUCCESS
)
2279 return res
== ERROR_SUCCESS
;
2282 static WCHAR
*get_proxy_autoconfig_url(void)
2284 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2286 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2291 if (!settings
) return NULL
;
2293 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2295 CFRelease( settings
);
2298 len
= CFStringGetLength( ref
);
2300 ret
= heap_alloc( (len
+1) * sizeof(WCHAR
) );
2303 CFStringGetCharacters( ref
, CFRangeMake(0, len
), ret
);
2306 TRACE( "returning %s\n", debugstr_w(ret
) );
2307 CFRelease( settings
);
2310 FIXME( "no support on this platform\n" );
2315 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2317 /* FIXME: This function currently handles more options than it should. Options requiring
2318 * proper handles should be moved to proper functions */
2320 case INTERNET_OPTION_HTTP_VERSION
:
2321 if (*size
< sizeof(HTTP_VERSION_INFO
))
2322 return ERROR_INSUFFICIENT_BUFFER
;
2325 * Presently hardcoded to 1.1
2327 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2328 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2329 *size
= sizeof(HTTP_VERSION_INFO
);
2331 return ERROR_SUCCESS
;
2333 case INTERNET_OPTION_CONNECTED_STATE
:
2334 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2336 if (*size
< sizeof(ULONG
))
2337 return ERROR_INSUFFICIENT_BUFFER
;
2339 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2340 *size
= sizeof(ULONG
);
2342 return ERROR_SUCCESS
;
2344 case INTERNET_OPTION_PROXY
: {
2348 TRACE("Getting global proxy info\n");
2349 memset(&ai
, 0, sizeof(appinfo_t
));
2350 INTERNET_ConfigureProxy(&ai
);
2352 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2353 APPINFO_Destroy(&ai
.hdr
);
2357 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2358 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2360 if (*size
< sizeof(ULONG
))
2361 return ERROR_INSUFFICIENT_BUFFER
;
2363 *(ULONG
*)buffer
= max_conns
;
2364 *size
= sizeof(ULONG
);
2366 return ERROR_SUCCESS
;
2368 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2369 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2371 if (*size
< sizeof(ULONG
))
2372 return ERROR_INSUFFICIENT_BUFFER
;
2374 *(ULONG
*)buffer
= max_1_0_conns
;
2375 *size
= sizeof(ULONG
);
2377 return ERROR_SUCCESS
;
2379 case INTERNET_OPTION_SECURITY_FLAGS
:
2380 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2381 return ERROR_SUCCESS
;
2383 case INTERNET_OPTION_VERSION
: {
2384 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2386 TRACE("INTERNET_OPTION_VERSION\n");
2388 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2389 return ERROR_INSUFFICIENT_BUFFER
;
2391 memcpy(buffer
, &info
, sizeof(info
));
2392 *size
= sizeof(info
);
2394 return ERROR_SUCCESS
;
2397 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2399 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2400 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2401 DWORD res
= ERROR_SUCCESS
, i
;
2405 TRACE("Getting global proxy info\n");
2406 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2409 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2411 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2413 return ERROR_INSUFFICIENT_BUFFER
;
2416 url
= get_proxy_autoconfig_url();
2418 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2419 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2420 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2422 switch (optionW
->dwOption
) {
2423 case INTERNET_PER_CONN_FLAGS
:
2425 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2427 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2429 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2430 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2433 case INTERNET_PER_CONN_PROXY_SERVER
:
2435 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2437 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2440 case INTERNET_PER_CONN_PROXY_BYPASS
:
2442 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2444 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2447 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2449 optionW
->Value
.pszValue
= NULL
;
2451 optionW
->Value
.pszValue
= heap_strdupW(url
);
2453 optionA
->Value
.pszValue
= heap_strdupWtoA(url
);
2456 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2457 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2460 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2461 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2462 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2463 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2464 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2465 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2469 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2470 res
= ERROR_INVALID_PARAMETER
;
2479 case INTERNET_OPTION_REQUEST_FLAGS
:
2480 case INTERNET_OPTION_USER_AGENT
:
2482 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2483 case INTERNET_OPTION_POLICY
:
2484 return ERROR_INVALID_PARAMETER
;
2485 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2486 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2488 if (*size
< sizeof(ULONG
))
2489 return ERROR_INSUFFICIENT_BUFFER
;
2491 *(ULONG
*)buffer
= connect_timeout
;
2492 *size
= sizeof(ULONG
);
2494 return ERROR_SUCCESS
;
2497 FIXME("Stub for %d\n", option
);
2498 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2501 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2504 case INTERNET_OPTION_CONTEXT_VALUE
:
2506 return ERROR_INVALID_PARAMETER
;
2508 if (*size
< sizeof(DWORD_PTR
)) {
2509 *size
= sizeof(DWORD_PTR
);
2510 return ERROR_INSUFFICIENT_BUFFER
;
2513 return ERROR_INVALID_PARAMETER
;
2515 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2516 *size
= sizeof(DWORD_PTR
);
2517 return ERROR_SUCCESS
;
2519 case INTERNET_OPTION_REQUEST_FLAGS
:
2520 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2521 *size
= sizeof(DWORD
);
2522 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2524 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2525 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2526 WARN("Called on global option %u\n", option
);
2527 return ERROR_INTERNET_INVALID_OPERATION
;
2530 /* FIXME: we shouldn't call it here */
2531 return query_global_option(option
, buffer
, size
, unicode
);
2534 /***********************************************************************
2535 * InternetQueryOptionW (WININET.@)
2537 * Queries an options on the specified handle
2544 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2545 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2547 object_header_t
*hdr
;
2548 DWORD res
= ERROR_INVALID_HANDLE
;
2550 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2553 hdr
= get_handle_object(hInternet
);
2555 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2556 WININET_Release(hdr
);
2559 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2562 if(res
!= ERROR_SUCCESS
)
2564 return res
== ERROR_SUCCESS
;
2567 /***********************************************************************
2568 * InternetQueryOptionA (WININET.@)
2570 * Queries an options on the specified handle
2577 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2578 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2580 object_header_t
*hdr
;
2581 DWORD res
= ERROR_INVALID_HANDLE
;
2583 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2586 hdr
= get_handle_object(hInternet
);
2588 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2589 WININET_Release(hdr
);
2592 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2595 if(res
!= ERROR_SUCCESS
)
2597 return res
== ERROR_SUCCESS
;
2600 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2603 case INTERNET_OPTION_CALLBACK
:
2604 WARN("Not settable option %u\n", option
);
2605 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2606 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2607 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2608 WARN("Called on global option %u\n", option
);
2609 return ERROR_INTERNET_INVALID_OPERATION
;
2612 return ERROR_INTERNET_INVALID_OPTION
;
2615 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2618 case INTERNET_OPTION_CALLBACK
:
2619 WARN("Not global option %u\n", option
);
2620 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2622 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2623 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2625 if(size
!= sizeof(max_conns
))
2626 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2628 return ERROR_BAD_ARGUMENTS
;
2630 max_conns
= *(ULONG
*)buf
;
2631 return ERROR_SUCCESS
;
2633 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2634 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2636 if(size
!= sizeof(max_1_0_conns
))
2637 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2639 return ERROR_BAD_ARGUMENTS
;
2641 max_1_0_conns
= *(ULONG
*)buf
;
2642 return ERROR_SUCCESS
;
2644 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2645 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2647 if(size
!= sizeof(connect_timeout
))
2648 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2650 return ERROR_BAD_ARGUMENTS
;
2652 connect_timeout
= *(ULONG
*)buf
;
2653 return ERROR_SUCCESS
;
2655 case INTERNET_OPTION_SETTINGS_CHANGED
:
2656 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2657 collect_connections(COLLECT_CONNECTIONS
);
2658 return ERROR_SUCCESS
;
2660 case INTERNET_OPTION_SUPPRESS_BEHAVIOR
:
2661 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2663 if(size
!= sizeof(ULONG
))
2664 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2666 FIXME("%08x\n", *(ULONG
*)buf
);
2667 return ERROR_SUCCESS
;
2670 return ERROR_INTERNET_INVALID_OPTION
;
2673 /***********************************************************************
2674 * InternetSetOptionW (WININET.@)
2676 * Sets an options on the specified handle
2683 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2684 LPVOID lpBuffer
, DWORD dwBufferLength
)
2686 object_header_t
*lpwhh
;
2690 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2692 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2694 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2696 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2698 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2700 WININET_Release(lpwhh
);
2702 if(res
!= ERROR_SUCCESS
)
2705 return res
== ERROR_SUCCESS
;
2710 case INTERNET_OPTION_HTTP_VERSION
:
2712 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2713 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2716 case INTERNET_OPTION_ERROR_MASK
:
2719 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2721 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2722 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2723 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2724 SetLastError(ERROR_INVALID_PARAMETER
);
2726 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2727 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2730 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2731 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2734 case INTERNET_OPTION_PROXY
:
2736 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2738 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2740 SetLastError(ERROR_INVALID_PARAMETER
);
2745 EnterCriticalSection( &WININET_cs
);
2746 free_global_proxy();
2747 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2750 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2752 global_proxy
->proxyEnabled
= 1;
2753 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2754 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2758 global_proxy
->proxyEnabled
= 0;
2759 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2762 LeaveCriticalSection( &WININET_cs
);
2766 /* In general, each type of object should handle
2767 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2768 * get silently dropped.
2770 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2771 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2776 case INTERNET_OPTION_CODEPAGE
:
2778 ULONG codepage
= *(ULONG
*)lpBuffer
;
2779 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2782 case INTERNET_OPTION_REQUEST_PRIORITY
:
2784 ULONG priority
= *(ULONG
*)lpBuffer
;
2785 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2788 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2790 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2791 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2794 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2796 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2797 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2800 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2801 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2803 case INTERNET_OPTION_END_BROWSER_SESSION
:
2804 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2807 case INTERNET_OPTION_CONNECTED_STATE
:
2808 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2810 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2811 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2813 case INTERNET_OPTION_SEND_TIMEOUT
:
2814 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2815 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2817 ULONG timeout
= *(ULONG
*)lpBuffer
;
2818 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2821 case INTERNET_OPTION_CONNECT_RETRIES
:
2823 ULONG retries
= *(ULONG
*)lpBuffer
;
2824 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2827 case INTERNET_OPTION_CONTEXT_VALUE
:
2831 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2834 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2836 SetLastError(ERROR_INVALID_PARAMETER
);
2840 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2843 case INTERNET_OPTION_SECURITY_FLAGS
:
2844 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2846 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2847 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2849 case INTERNET_OPTION_HTTP_DECODING
:
2850 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2851 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2854 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2855 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2856 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2859 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2860 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2861 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2864 case INTERNET_OPTION_CODEPAGE_PATH
:
2865 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2866 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2869 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2870 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2871 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2874 case INTERNET_OPTION_IDN
:
2875 FIXME("INTERNET_OPTION_IDN; STUB\n");
2876 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2879 case INTERNET_OPTION_POLICY
:
2880 SetLastError(ERROR_INVALID_PARAMETER
);
2883 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2884 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2889 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2891 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2892 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2894 switch (option
->dwOption
) {
2895 case INTERNET_PER_CONN_PROXY_SERVER
:
2896 heap_free(pi
.proxy
);
2897 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2900 case INTERNET_PER_CONN_FLAGS
:
2901 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2902 pi
.proxyEnabled
= 1;
2905 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2906 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2907 pi
.proxyEnabled
= 0;
2911 case INTERNET_PER_CONN_PROXY_BYPASS
:
2912 heap_free(pi
.proxyBypass
);
2913 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
2916 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2917 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2918 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2919 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2920 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2921 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2922 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2926 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2927 SetLastError(ERROR_INVALID_PARAMETER
);
2932 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2937 ret
= (res
== ERROR_SUCCESS
);
2941 FIXME("Option %d STUB\n",dwOption
);
2942 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2948 WININET_Release( lpwhh
);
2954 /***********************************************************************
2955 * InternetSetOptionA (WININET.@)
2957 * Sets an options on the specified handle.
2964 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2965 LPVOID lpBuffer
, DWORD dwBufferLength
)
2973 case INTERNET_OPTION_PROXY
:
2975 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2976 LPINTERNET_PROXY_INFOW piw
;
2977 DWORD proxlen
, prbylen
;
2980 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2981 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2982 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2983 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2984 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2985 piw
->dwAccessType
= pi
->dwAccessType
;
2986 prox
= (LPWSTR
) &piw
[1];
2987 prby
= &prox
[proxlen
+1];
2988 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2989 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2990 piw
->lpszProxy
= prox
;
2991 piw
->lpszProxyBypass
= prby
;
2994 case INTERNET_OPTION_USER_AGENT
:
2995 case INTERNET_OPTION_USERNAME
:
2996 case INTERNET_OPTION_PASSWORD
:
2997 case INTERNET_OPTION_PROXY_USERNAME
:
2998 case INTERNET_OPTION_PROXY_PASSWORD
:
2999 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3000 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3001 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3003 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3005 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3006 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3007 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3008 wbuffer
= heap_alloc(wlen
);
3011 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3012 if (listA
->pszConnection
)
3014 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3015 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3016 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3019 listW
->pszConnection
= NULL
;
3020 listW
->dwOptionCount
= listA
->dwOptionCount
;
3021 listW
->dwOptionError
= listA
->dwOptionError
;
3022 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3024 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3025 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3026 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3028 optW
->dwOption
= optA
->dwOption
;
3030 switch (optA
->dwOption
) {
3031 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3032 case INTERNET_PER_CONN_PROXY_BYPASS
:
3033 case INTERNET_PER_CONN_PROXY_SERVER
:
3034 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3035 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3036 if (optA
->Value
.pszValue
)
3038 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3039 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3040 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3043 optW
->Value
.pszValue
= NULL
;
3045 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3046 case INTERNET_PER_CONN_FLAGS
:
3047 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3048 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3050 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3051 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3054 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3055 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3063 wlen
= dwBufferLength
;
3066 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3068 if( lpBuffer
!= wbuffer
)
3070 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3072 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3074 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3075 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3076 switch (opt
->dwOption
) {
3077 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3078 case INTERNET_PER_CONN_PROXY_BYPASS
:
3079 case INTERNET_PER_CONN_PROXY_SERVER
:
3080 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3081 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3082 heap_free( opt
->Value
.pszValue
);
3088 heap_free( list
->pOptions
);
3090 heap_free( wbuffer
);
3097 /***********************************************************************
3098 * InternetSetOptionExA (WININET.@)
3100 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3101 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3103 FIXME("Flags %08x ignored\n", dwFlags
);
3104 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3107 /***********************************************************************
3108 * InternetSetOptionExW (WININET.@)
3110 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3111 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3113 FIXME("Flags %08x ignored\n", dwFlags
);
3114 if( dwFlags
& ~ISO_VALID_FLAGS
)
3116 SetLastError( ERROR_INVALID_PARAMETER
);
3119 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3122 static const WCHAR WININET_wkday
[7][4] =
3123 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3124 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3125 static const WCHAR WININET_month
[12][4] =
3126 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3127 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3128 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3130 /***********************************************************************
3131 * InternetTimeFromSystemTimeA (WININET.@)
3133 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3136 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3138 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3140 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3142 SetLastError(ERROR_INVALID_PARAMETER
);
3146 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3148 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3152 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3153 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3158 /***********************************************************************
3159 * InternetTimeFromSystemTimeW (WININET.@)
3161 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3163 static const WCHAR date
[] =
3164 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3165 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3167 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3169 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3171 SetLastError(ERROR_INVALID_PARAMETER
);
3175 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3177 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3181 sprintfW( string
, date
,
3182 WININET_wkday
[time
->wDayOfWeek
],
3184 WININET_month
[time
->wMonth
- 1],
3193 /***********************************************************************
3194 * InternetTimeToSystemTimeA (WININET.@)
3196 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3201 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3203 stringW
= heap_strdupAtoW(string
);
3206 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3207 heap_free( stringW
);
3212 /***********************************************************************
3213 * InternetTimeToSystemTimeW (WININET.@)
3215 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3218 const WCHAR
*s
= string
;
3221 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3223 if (!string
|| !time
) return FALSE
;
3225 /* Windows does this too */
3226 GetSystemTime( time
);
3228 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3229 * a SYSTEMTIME structure.
3232 while (*s
&& !isalphaW( *s
)) s
++;
3233 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3234 time
->wDayOfWeek
= 7;
3236 for (i
= 0; i
< 7; i
++)
3238 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3239 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3240 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3242 time
->wDayOfWeek
= i
;
3247 if (time
->wDayOfWeek
> 6) return TRUE
;
3248 while (*s
&& !isdigitW( *s
)) s
++;
3249 time
->wDay
= strtolW( s
, &end
, 10 );
3252 while (*s
&& !isalphaW( *s
)) s
++;
3253 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3256 for (i
= 0; i
< 12; i
++)
3258 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3259 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3260 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3262 time
->wMonth
= i
+ 1;
3266 if (time
->wMonth
== 0) return TRUE
;
3268 while (*s
&& !isdigitW( *s
)) s
++;
3269 if (*s
== '\0') return TRUE
;
3270 time
->wYear
= strtolW( s
, &end
, 10 );
3273 while (*s
&& !isdigitW( *s
)) s
++;
3274 if (*s
== '\0') return TRUE
;
3275 time
->wHour
= strtolW( s
, &end
, 10 );
3278 while (*s
&& !isdigitW( *s
)) s
++;
3279 if (*s
== '\0') return TRUE
;
3280 time
->wMinute
= strtolW( s
, &end
, 10 );
3283 while (*s
&& !isdigitW( *s
)) s
++;
3284 if (*s
== '\0') return TRUE
;
3285 time
->wSecond
= strtolW( s
, &end
, 10 );
3288 time
->wMilliseconds
= 0;
3292 /***********************************************************************
3293 * InternetCheckConnectionW (WININET.@)
3295 * Pings a requested host to check internet connection
3298 * TRUE on success and FALSE on failure. If a failure then
3299 * ERROR_NOT_CONNECTED is placed into GetLastError
3302 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3305 * this is a kludge which runs the resident ping program and reads the output.
3307 * Anyone have a better idea?
3311 static const CHAR ping
[] = "ping -c 1 ";
3312 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3314 DWORD len
, host_len
;
3318 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl
), dwFlags
, dwReserved
);
3321 * Crack or set the Address
3323 if (lpszUrl
== NULL
)
3326 * According to the doc we are supposed to use the ip for the next
3327 * server in the WnInet internal server database. I have
3328 * no idea what that is or how to get it.
3330 * So someone needs to implement this.
3332 FIXME("Unimplemented with URL of NULL\n");
3337 URL_COMPONENTSW components
= {sizeof(components
)};
3339 components
.dwHostNameLength
= 1;
3341 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3344 host
= components
.lpszHostName
;
3345 host_len
= components
.dwHostNameLength
;
3346 port
= components
.nPort
;
3347 TRACE("host name: %s port: %d\n",debugstr_wn(host
, host_len
), port
);
3350 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3352 struct sockaddr_storage saddr
;
3353 int sa_len
= sizeof(saddr
);
3358 host_z
= heap_strndupW(host
, host_len
);
3362 b
= GetAddress(host_z
, port
, (struct sockaddr
*)&saddr
, &sa_len
, NULL
);
3367 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3370 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3378 * Build our ping command
3382 len
= WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, NULL
, 0, NULL
, NULL
);
3383 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
)+1);
3384 strcpy(command
, ping
);
3385 WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, command
+sizeof(ping
)-1, len
, NULL
, NULL
);
3386 strcpy(command
+sizeof(ping
)-1+len
, redirect
);
3388 TRACE("Ping command is : %s\n",command
);
3390 status
= system(command
);
3391 heap_free( command
);
3393 TRACE("Ping returned a code of %i\n",status
);
3395 /* Ping return code of 0 indicates success */
3402 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3408 /***********************************************************************
3409 * InternetCheckConnectionA (WININET.@)
3411 * Pings a requested host to check internet connection
3414 * TRUE on success and FALSE on failure. If a failure then
3415 * ERROR_NOT_CONNECTED is placed into GetLastError
3418 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3424 url
= heap_strdupAtoW(lpszUrl
);
3429 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3436 /**********************************************************
3437 * INTERNET_InternetOpenUrlW (internal)
3442 * handle of connection or NULL on failure
3444 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3445 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3447 URL_COMPONENTSW urlComponents
= { sizeof(urlComponents
) };
3448 WCHAR
*host
, *user
= NULL
, *pass
= NULL
, *path
;
3449 HINTERNET client
= NULL
, client1
= NULL
;
3452 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3453 dwHeadersLength
, dwFlags
, dwContext
);
3455 urlComponents
.dwHostNameLength
= 1;
3456 urlComponents
.dwUserNameLength
= 1;
3457 urlComponents
.dwPasswordLength
= 1;
3458 urlComponents
.dwUrlPathLength
= 1;
3459 urlComponents
.dwExtraInfoLength
= 1;
3460 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3463 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
3464 urlComponents
.dwExtraInfoLength
)
3466 assert(urlComponents
.lpszUrlPath
+ urlComponents
.dwUrlPathLength
== urlComponents
.lpszExtraInfo
);
3467 urlComponents
.dwUrlPathLength
+= urlComponents
.dwExtraInfoLength
;
3470 host
= heap_strndupW(urlComponents
.lpszHostName
, urlComponents
.dwHostNameLength
);
3471 path
= heap_strndupW(urlComponents
.lpszUrlPath
, urlComponents
.dwUrlPathLength
);
3472 if(urlComponents
.dwUserNameLength
)
3473 user
= heap_strndupW(urlComponents
.lpszUserName
, urlComponents
.dwUserNameLength
);
3474 if(urlComponents
.dwPasswordLength
)
3475 pass
= heap_strndupW(urlComponents
.lpszPassword
, urlComponents
.dwPasswordLength
);
3477 switch(urlComponents
.nScheme
) {
3478 case INTERNET_SCHEME_FTP
:
3479 client
= FTP_Connect(hIC
, host
, urlComponents
.nPort
,
3480 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
);
3483 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3484 if(client1
== NULL
) {
3485 InternetCloseHandle(client
);
3490 case INTERNET_SCHEME_HTTP
:
3491 case INTERNET_SCHEME_HTTPS
: {
3492 static const WCHAR szStars
[] = { '*','/','*', 0 };
3493 LPCWSTR accept
[2] = { szStars
, NULL
};
3495 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3497 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3498 res
= HTTP_Connect(hIC
, host
, urlComponents
.nPort
,
3499 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3500 if(res
!= ERROR_SUCCESS
) {
3501 INTERNET_SetLastError(res
);
3505 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3506 if(client1
== NULL
) {
3507 InternetCloseHandle(client
);
3510 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3511 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3512 GetLastError() != ERROR_IO_PENDING
) {
3513 InternetCloseHandle(client1
);
3518 case INTERNET_SCHEME_GOPHER
:
3519 /* gopher doesn't seem to be implemented in wine, but it's supposed
3520 * to be supported by InternetOpenUrlA. */
3522 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3526 TRACE(" %p <--\n", client1
);
3535 /**********************************************************
3536 * InternetOpenUrlW (WININET.@)
3541 * handle of connection or NULL on failure
3552 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3554 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3556 TRACE("%p\n", task
->hdr
.hdr
);
3558 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3559 task
->headers_len
, task
->flags
, task
->context
);
3560 heap_free(task
->url
);
3561 heap_free(task
->headers
);
3564 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3565 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3567 HINTERNET ret
= NULL
;
3568 appinfo_t
*hIC
= NULL
;
3570 if (TRACE_ON(wininet
)) {
3571 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3572 dwHeadersLength
, dwFlags
, dwContext
);
3574 dump_INTERNET_FLAGS(dwFlags
);
3579 SetLastError(ERROR_INVALID_PARAMETER
);
3583 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3584 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3585 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3589 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3590 open_url_task_t
*task
;
3592 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3593 task
->url
= heap_strdupW(lpszUrl
);
3594 task
->headers
= heap_strdupW(lpszHeaders
);
3595 task
->headers_len
= dwHeadersLength
;
3596 task
->flags
= dwFlags
;
3597 task
->context
= dwContext
;
3599 INTERNET_AsyncCall(&task
->hdr
);
3600 SetLastError(ERROR_IO_PENDING
);
3602 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3607 WININET_Release( &hIC
->hdr
);
3608 TRACE(" %p <--\n", ret
);
3613 /**********************************************************
3614 * InternetOpenUrlA (WININET.@)
3619 * handle of connection or NULL on failure
3621 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3622 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3624 HINTERNET rc
= NULL
;
3625 LPWSTR szUrl
= NULL
;
3626 WCHAR
*headers
= NULL
;
3631 szUrl
= heap_strdupAtoW(lpszUrl
);
3637 headers
= heap_strndupAtoW(lpszHeaders
, dwHeadersLength
, &dwHeadersLength
);
3644 rc
= InternetOpenUrlW(hInternet
, szUrl
, headers
, dwHeadersLength
, dwFlags
, dwContext
);
3652 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3654 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3658 lpwite
->dwError
= 0;
3659 lpwite
->response
[0] = '\0';
3662 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3671 /***********************************************************************
3672 * INTERNET_SetLastError (internal)
3674 * Set last thread specific error
3679 void INTERNET_SetLastError(DWORD dwError
)
3681 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3684 lpwite
= INTERNET_AllocThreadError();
3686 SetLastError(dwError
);
3688 lpwite
->dwError
= dwError
;
3692 /***********************************************************************
3693 * INTERNET_GetLastError (internal)
3695 * Get last thread specific error
3700 DWORD
INTERNET_GetLastError(void)
3702 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3703 if (!lpwite
) return 0;
3704 /* TlsGetValue clears last error, so set it again here */
3705 SetLastError(lpwite
->dwError
);
3706 return lpwite
->dwError
;
3710 /***********************************************************************
3711 * INTERNET_WorkerThreadFunc (internal)
3713 * Worker thread execution function
3718 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3720 task_header_t
*task
= lpvParam
;
3725 WININET_Release(task
->hdr
);
3728 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3730 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3731 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3736 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3738 task_header_t
*task
;
3740 task
= heap_alloc(size
);
3744 task
->hdr
= WININET_AddRef(hdr
);
3749 /***********************************************************************
3750 * INTERNET_AsyncCall (internal)
3752 * Retrieves work request from queue
3757 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3763 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3767 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3769 return ERROR_SUCCESS
;
3773 /***********************************************************************
3774 * INTERNET_GetResponseBuffer (internal)
3779 LPSTR
INTERNET_GetResponseBuffer(void)
3781 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3783 lpwite
= INTERNET_AllocThreadError();
3785 return lpwite
->response
;
3788 /**********************************************************
3789 * InternetQueryDataAvailable (WININET.@)
3791 * Determines how much data is available to be read.
3794 * TRUE on success, FALSE if an error occurred. If
3795 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3796 * no data is presently available, FALSE is returned with
3797 * the last error ERROR_IO_PENDING; a callback with status
3798 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3799 * data is available.
3801 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3802 LPDWORD lpdwNumberOfBytesAvailable
,
3803 DWORD dwFlags
, DWORD_PTR dwContext
)
3805 object_header_t
*hdr
;
3808 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3810 hdr
= get_handle_object( hFile
);
3812 SetLastError(ERROR_INVALID_HANDLE
);
3816 if(hdr
->vtbl
->QueryDataAvailable
) {
3817 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3819 WARN("wrong handle\n");
3820 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3823 WININET_Release(hdr
);
3825 if(res
!= ERROR_SUCCESS
)
3827 return res
== ERROR_SUCCESS
;
3830 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3832 req_file_t
*req_file
;
3834 req_file
= heap_alloc_zero(sizeof(*req_file
));
3836 return ERROR_NOT_ENOUGH_MEMORY
;
3840 req_file
->file_name
= heap_strdupW(file_name
);
3841 if(!req_file
->file_name
) {
3842 heap_free(req_file
);
3843 return ERROR_NOT_ENOUGH_MEMORY
;
3846 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3847 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3848 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
3849 req_file_release(req_file
);
3850 return GetLastError();
3854 return ERROR_SUCCESS
;
3857 void req_file_release(req_file_t
*req_file
)
3859 if(InterlockedDecrement(&req_file
->ref
))
3862 if(!req_file
->is_committed
)
3863 DeleteFileW(req_file
->file_name
);
3864 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
3865 CloseHandle(req_file
->file_handle
);
3866 heap_free(req_file
->file_name
);
3867 heap_free(req_file
->url
);
3868 heap_free(req_file
);
3871 /***********************************************************************
3872 * InternetLockRequestFile (WININET.@)
3874 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
3876 req_file_t
*req_file
= NULL
;
3877 object_header_t
*hdr
;
3880 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
3882 hdr
= get_handle_object(hInternet
);
3884 SetLastError(ERROR_INVALID_HANDLE
);
3888 if(hdr
->vtbl
->LockRequestFile
) {
3889 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
3891 WARN("wrong handle\n");
3892 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3895 WININET_Release(hdr
);
3897 *lphLockReqHandle
= req_file
;
3898 if(res
!= ERROR_SUCCESS
)
3900 return res
== ERROR_SUCCESS
;
3903 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
3905 TRACE("(%p)\n", hLockHandle
);
3907 req_file_release(hLockHandle
);
3912 /***********************************************************************
3913 * InternetAutodial (WININET.@)
3915 * On windows this function is supposed to dial the default internet
3916 * connection. We don't want to have Wine dial out to the internet so
3917 * we return TRUE by default. It might be nice to check if we are connected.
3924 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3928 /* Tell that we are connected to the internet. */
3932 /***********************************************************************
3933 * InternetAutodialHangup (WININET.@)
3935 * Hangs up a connection made with InternetAutodial
3944 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3948 /* we didn't dial, we don't disconnect */
3952 /***********************************************************************
3953 * InternetCombineUrlA (WININET.@)
3955 * Combine a base URL with a relative URL
3963 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3964 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3969 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3971 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3972 dwFlags
^= ICU_NO_ENCODE
;
3973 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3978 /***********************************************************************
3979 * InternetCombineUrlW (WININET.@)
3981 * Combine a base URL with a relative URL
3989 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3990 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3995 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3997 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3998 dwFlags
^= ICU_NO_ENCODE
;
3999 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4004 /* max port num is 65535 => 5 digits */
4005 #define MAX_WORD_DIGITS 5
4007 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4008 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4009 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4010 (url)->dw##component##Length : strlen((url)->lpsz##component))
4012 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4014 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4015 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4017 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4018 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4020 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4021 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4023 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4024 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4027 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4033 /* opaque urls do not fit into the standard url hierarchy and don't have
4034 * two following slashes */
4035 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4037 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4038 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4039 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4040 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4041 (nScheme
!= INTERNET_SCHEME_FILE
);
4044 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4047 if (scheme
< INTERNET_SCHEME_FIRST
)
4049 index
= scheme
- INTERNET_SCHEME_FIRST
;
4050 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4052 return (LPCWSTR
)url_schemes
[index
];
4055 /* we can calculate using ansi strings because we're just
4056 * calculating string length, not size
4058 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4059 LPDWORD lpdwUrlLength
)
4061 INTERNET_SCHEME nScheme
;
4065 if (lpUrlComponents
->lpszScheme
)
4067 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4068 *lpdwUrlLength
+= dwLen
;
4069 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4075 nScheme
= lpUrlComponents
->nScheme
;
4077 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4078 nScheme
= INTERNET_SCHEME_HTTP
;
4079 scheme
= INTERNET_GetSchemeString(nScheme
);
4080 *lpdwUrlLength
+= strlenW(scheme
);
4083 (*lpdwUrlLength
)++; /* ':' */
4084 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4085 *lpdwUrlLength
+= strlen("//");
4087 if (lpUrlComponents
->lpszUserName
)
4089 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4090 *lpdwUrlLength
+= strlen("@");
4094 if (lpUrlComponents
->lpszPassword
)
4096 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4101 if (lpUrlComponents
->lpszPassword
)
4103 *lpdwUrlLength
+= strlen(":");
4104 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4107 if (lpUrlComponents
->lpszHostName
)
4109 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4111 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4113 char szPort
[MAX_WORD_DIGITS
+1];
4115 *lpdwUrlLength
+= sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4116 *lpdwUrlLength
+= strlen(":");
4119 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4120 (*lpdwUrlLength
)++; /* '/' */
4123 if (lpUrlComponents
->lpszUrlPath
)
4124 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4126 if (lpUrlComponents
->lpszExtraInfo
)
4127 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4132 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4136 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4138 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4139 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4140 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4141 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4142 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4143 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4144 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4145 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4146 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4148 if (lpUrlComponents
->lpszScheme
)
4150 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4151 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4152 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4153 -1, urlCompW
->lpszScheme
, len
);
4156 if (lpUrlComponents
->lpszHostName
)
4158 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4159 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4160 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4161 -1, urlCompW
->lpszHostName
, len
);
4164 if (lpUrlComponents
->lpszUserName
)
4166 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4167 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4168 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4169 -1, urlCompW
->lpszUserName
, len
);
4172 if (lpUrlComponents
->lpszPassword
)
4174 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4175 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4176 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4177 -1, urlCompW
->lpszPassword
, len
);
4180 if (lpUrlComponents
->lpszUrlPath
)
4182 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4183 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4184 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4185 -1, urlCompW
->lpszUrlPath
, len
);
4188 if (lpUrlComponents
->lpszExtraInfo
)
4190 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4191 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4192 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4193 -1, urlCompW
->lpszExtraInfo
, len
);
4197 /***********************************************************************
4198 * InternetCreateUrlA (WININET.@)
4200 * See InternetCreateUrlW.
4202 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4203 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4207 URL_COMPONENTSW urlCompW
;
4209 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4211 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4213 SetLastError(ERROR_INVALID_PARAMETER
);
4217 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4220 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4222 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4224 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4225 *lpdwUrlLength
/= sizeof(WCHAR
);
4227 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4228 * minus one, so add one to leave room for NULL terminator
4231 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4233 heap_free(urlCompW
.lpszScheme
);
4234 heap_free(urlCompW
.lpszHostName
);
4235 heap_free(urlCompW
.lpszUserName
);
4236 heap_free(urlCompW
.lpszPassword
);
4237 heap_free(urlCompW
.lpszUrlPath
);
4238 heap_free(urlCompW
.lpszExtraInfo
);
4243 /***********************************************************************
4244 * InternetCreateUrlW (WININET.@)
4246 * Creates a URL from its component parts.
4249 * lpUrlComponents [I] URL Components.
4250 * dwFlags [I] Flags. See notes.
4251 * lpszUrl [I] Buffer in which to store the created URL.
4252 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4253 * lpszUrl in characters. On output, the number of bytes
4254 * required to store the URL including terminator.
4258 * The dwFlags parameter can be zero or more of the following:
4259 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4266 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4267 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4270 INTERNET_SCHEME nScheme
;
4272 static const WCHAR slashSlashW
[] = {'/','/'};
4273 static const WCHAR fmtW
[] = {'%','u',0};
4275 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4277 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4279 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4283 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4286 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4288 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4289 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4293 *lpdwUrlLength
= dwLen
;
4298 if (lpUrlComponents
->lpszScheme
)
4300 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4301 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4304 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4309 nScheme
= lpUrlComponents
->nScheme
;
4311 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4312 nScheme
= INTERNET_SCHEME_HTTP
;
4314 scheme
= INTERNET_GetSchemeString(nScheme
);
4315 dwLen
= strlenW(scheme
);
4316 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4320 /* all schemes are followed by at least a colon */
4324 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4326 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4327 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4330 if (lpUrlComponents
->lpszUserName
)
4332 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4333 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4336 if (lpUrlComponents
->lpszPassword
)
4341 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4342 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4350 if (lpUrlComponents
->lpszHostName
)
4352 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4353 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4356 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4360 lpszUrl
+= sprintfW(lpszUrl
, fmtW
, lpUrlComponents
->nPort
);
4363 /* add slash between hostname and path if necessary */
4364 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4371 if (lpUrlComponents
->lpszUrlPath
)
4373 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4374 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4378 if (lpUrlComponents
->lpszExtraInfo
)
4380 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4381 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4390 /***********************************************************************
4391 * InternetConfirmZoneCrossingA (WININET.@)
4394 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4396 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4397 return ERROR_SUCCESS
;
4400 /***********************************************************************
4401 * InternetConfirmZoneCrossingW (WININET.@)
4404 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4406 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4407 return ERROR_SUCCESS
;
4410 static DWORD zone_preference
= 3;
4412 /***********************************************************************
4413 * PrivacySetZonePreferenceW (WININET.@)
4415 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4417 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4419 zone_preference
= template;
4423 /***********************************************************************
4424 * PrivacyGetZonePreferenceW (WININET.@)
4426 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4427 LPWSTR preference
, LPDWORD length
)
4429 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4431 if (template) *template = zone_preference
;
4435 /***********************************************************************
4436 * InternetGetSecurityInfoByURLA (WININET.@)
4438 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4443 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4445 url
= heap_strdupAtoW(lpszURL
);
4449 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4454 /***********************************************************************
4455 * InternetGetSecurityInfoByURLW (WININET.@)
4457 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4459 URL_COMPONENTSW url
= {sizeof(url
)};
4463 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4465 url
.dwHostNameLength
= 1;
4466 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4467 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4468 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4472 server
= get_server(substr(url
.lpszHostName
, url
.dwHostNameLength
), url
.nPort
, TRUE
, FALSE
);
4474 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4478 if(server
->cert_chain
) {
4479 const CERT_CHAIN_CONTEXT
*chain_dup
;
4481 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4483 *ppCertChain
= chain_dup
;
4484 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4489 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4493 server_release(server
);
4497 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4498 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4500 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4501 lpdwConnection
, dwReserved
);
4502 return ERROR_SUCCESS
;
4505 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4506 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4508 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4509 lpdwConnection
, dwReserved
);
4510 return ERROR_SUCCESS
;
4513 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4515 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4519 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4521 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4525 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4527 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4528 return ERROR_SUCCESS
;
4531 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4534 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4535 debugstr_w(pwszTarget
), pbHexHash
);
4539 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4541 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4545 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4547 FIXME("(%p, %08lx) stub\n", a
, b
);
4551 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4553 FIXME("%p: stub\n", parent
);