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
;
973 case INTERNET_OPTION_REFRESH
:
974 FIXME("INTERNET_OPTION_REFRESH\n");
975 return ERROR_SUCCESS
;
978 return INET_SetOption(hdr
, option
, buf
, size
);
981 static const object_vtbl_t APPINFOVtbl
= {
992 /***********************************************************************
993 * InternetOpenW (WININET.@)
995 * Per-application initialization of wininet
998 * HINTERNET on success
1002 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
1003 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
1005 appinfo_t
*lpwai
= NULL
;
1007 if (TRACE_ON(wininet
)) {
1008 #define FE(x) { x, #x }
1009 static const wininet_flag_info access_type
[] = {
1010 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
1011 FE(INTERNET_OPEN_TYPE_DIRECT
),
1012 FE(INTERNET_OPEN_TYPE_PROXY
),
1013 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
1017 const char *access_type_str
= "Unknown";
1019 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1020 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1021 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
1022 if (access_type
[i
].val
== dwAccessType
) {
1023 access_type_str
= access_type
[i
].name
;
1027 TRACE(" access type : %s\n", access_type_str
);
1029 dump_INTERNET_FLAGS(dwFlags
);
1032 /* Clear any error information */
1033 INTERNET_SetLastError(0);
1035 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1036 SetLastError(ERROR_INVALID_PARAMETER
);
1040 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1042 SetLastError(ERROR_OUTOFMEMORY
);
1046 lpwai
->hdr
.htype
= WH_HINIT
;
1047 lpwai
->hdr
.dwFlags
= dwFlags
;
1048 lpwai
->accessType
= dwAccessType
;
1049 lpwai
->proxyUsername
= NULL
;
1050 lpwai
->proxyPassword
= NULL
;
1051 lpwai
->connect_timeout
= connect_timeout
;
1053 lpwai
->agent
= heap_strdupW(lpszAgent
);
1054 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1055 INTERNET_ConfigureProxy( lpwai
);
1056 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1057 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1058 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1061 TRACE("returning %p\n", lpwai
);
1063 return lpwai
->hdr
.hInternet
;
1067 /***********************************************************************
1068 * InternetOpenA (WININET.@)
1070 * Per-application initialization of wininet
1073 * HINTERNET on success
1077 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1078 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1080 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1083 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1084 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1086 szAgent
= heap_strdupAtoW(lpszAgent
);
1087 szProxy
= heap_strdupAtoW(lpszProxy
);
1088 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1090 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1094 heap_free(szBypass
);
1098 /***********************************************************************
1099 * InternetGetLastResponseInfoA (WININET.@)
1101 * Return last wininet error description on the calling thread
1104 * TRUE on success of writing to buffer
1108 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1109 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1111 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1117 *lpdwError
= lpwite
->dwError
;
1118 if (lpwite
->dwError
)
1120 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1121 *lpdwBufferLength
= strlen(lpszBuffer
);
1124 *lpdwBufferLength
= 0;
1129 *lpdwBufferLength
= 0;
1135 /***********************************************************************
1136 * InternetGetLastResponseInfoW (WININET.@)
1138 * Return last wininet error description on the calling thread
1141 * TRUE on success of writing to buffer
1145 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1146 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1148 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1154 *lpdwError
= lpwite
->dwError
;
1155 if (lpwite
->dwError
)
1157 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1158 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1161 *lpdwBufferLength
= 0;
1166 *lpdwBufferLength
= 0;
1172 /***********************************************************************
1173 * InternetGetConnectedState (WININET.@)
1175 * Return connected state
1179 * if lpdwStatus is not null, return the status (off line,
1180 * modem, lan...) in it.
1181 * FALSE if not connected
1183 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1185 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1187 return InternetGetConnectedStateExW(lpdwStatus
, NULL
, 0, dwReserved
);
1191 /***********************************************************************
1192 * InternetGetConnectedStateExW (WININET.@)
1194 * Return connected state
1198 * lpdwStatus [O] Flags specifying the status of the internet connection.
1199 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1200 * dwNameLen [I] Size of the buffer, in characters.
1201 * dwReserved [I] Reserved. Must be set to 0.
1205 * if lpdwStatus is not null, return the status (off line,
1206 * modem, lan...) in it.
1207 * FALSE if not connected
1210 * If the system has no available network connections, an empty string is
1211 * stored in lpszConnectionName. If there is a LAN connection, a localized
1212 * "LAN Connection" string is stored. Presumably, if only a dial-up
1213 * connection is available then the name of the dial-up connection is
1214 * returned. Why any application, other than the "Internet Settings" CPL,
1215 * would want to use this function instead of the simpler InternetGetConnectedStateW
1216 * function is beyond me.
1218 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1219 DWORD dwNameLen
, DWORD dwReserved
)
1221 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1228 WARN("always returning LAN connection.\n");
1229 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1232 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1233 * the resource, avoid it as we must not change the buffer in this case */
1234 if(lpszConnectionName
&& dwNameLen
) {
1235 *lpszConnectionName
= '\0';
1236 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1243 /***********************************************************************
1244 * InternetGetConnectedStateExA (WININET.@)
1246 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1247 DWORD dwNameLen
, DWORD dwReserved
)
1249 LPWSTR lpwszConnectionName
= NULL
;
1252 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1254 if (lpszConnectionName
&& dwNameLen
> 0)
1255 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1257 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1259 if (rc
&& lpwszConnectionName
)
1260 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1261 dwNameLen
, NULL
, NULL
);
1263 heap_free(lpwszConnectionName
);
1268 /***********************************************************************
1269 * InternetConnectW (WININET.@)
1271 * Open a ftp, gopher or http session
1274 * HINTERNET a session handle on success
1278 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1279 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1280 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1281 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1284 HINTERNET rc
= NULL
;
1285 DWORD res
= ERROR_SUCCESS
;
1287 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1288 nServerPort
, debugstr_w(lpszUserName
), lpszPassword
, dwService
, dwFlags
, dwContext
);
1290 if (!lpszServerName
)
1292 SetLastError(ERROR_INVALID_PARAMETER
);
1296 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1297 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1299 res
= ERROR_INVALID_HANDLE
;
1305 case INTERNET_SERVICE_FTP
:
1306 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1307 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1309 res
= INTERNET_GetLastError();
1312 case INTERNET_SERVICE_HTTP
:
1313 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1314 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1317 case INTERNET_SERVICE_GOPHER
:
1323 WININET_Release( &hIC
->hdr
);
1325 TRACE("returning %p\n", rc
);
1331 /***********************************************************************
1332 * InternetConnectA (WININET.@)
1334 * Open a ftp, gopher or http session
1337 * HINTERNET a session handle on success
1341 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1342 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1343 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1344 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1346 HINTERNET rc
= NULL
;
1347 LPWSTR szServerName
;
1351 szServerName
= heap_strdupAtoW(lpszServerName
);
1352 szUserName
= heap_strdupAtoW(lpszUserName
);
1353 szPassword
= heap_strdupAtoW(lpszPassword
);
1355 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1356 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1358 heap_free(szServerName
);
1359 heap_free(szUserName
);
1360 heap_free(szPassword
);
1365 /***********************************************************************
1366 * InternetFindNextFileA (WININET.@)
1368 * Continues a file search from a previous call to FindFirstFile
1375 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1378 WIN32_FIND_DATAW fd
;
1380 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1382 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1386 /***********************************************************************
1387 * InternetFindNextFileW (WININET.@)
1389 * Continues a file search from a previous call to FindFirstFile
1396 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1398 object_header_t
*hdr
;
1403 hdr
= get_handle_object(hFind
);
1405 WARN("Invalid handle\n");
1406 SetLastError(ERROR_INVALID_HANDLE
);
1410 if(hdr
->vtbl
->FindNextFileW
) {
1411 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1413 WARN("Handle doesn't support NextFile\n");
1414 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1417 WININET_Release(hdr
);
1419 if(res
!= ERROR_SUCCESS
)
1421 return res
== ERROR_SUCCESS
;
1424 /***********************************************************************
1425 * InternetCloseHandle (WININET.@)
1427 * Generic close handle function
1434 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1436 object_header_t
*obj
;
1438 TRACE("%p\n", hInternet
);
1440 obj
= get_handle_object( hInternet
);
1442 SetLastError(ERROR_INVALID_HANDLE
);
1446 invalidate_handle(obj
);
1447 WININET_Release(obj
);
1452 static BOOL
set_url_component(WCHAR
**component
, DWORD
*component_length
, const WCHAR
*value
, DWORD len
)
1454 TRACE("%s (%d)\n", debugstr_wn(value
, len
), len
);
1456 if (!*component_length
)
1460 *(const WCHAR
**)component
= value
;
1461 *component_length
= len
;
1465 if (*component_length
< len
+1) {
1466 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1470 *component_length
= len
;
1472 memcpy(*component
, value
, len
*sizeof(WCHAR
));
1473 (*component
)[len
] = 0;
1477 static BOOL
set_url_component_WtoA(const WCHAR
*comp_w
, DWORD length
, const WCHAR
*url_w
, char **comp
, DWORD
*ret_length
,
1480 size_t size
, ret_size
= *ret_length
;
1484 size
= WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, NULL
, 0, NULL
, NULL
);
1487 *comp
= comp_w
? (char*)url_a
+ WideCharToMultiByte(CP_ACP
, 0, url_w
, comp_w
-url_w
, NULL
, 0, NULL
, NULL
) : NULL
;
1492 if (size
+1 > ret_size
) {
1493 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1494 *ret_length
= size
+1;
1499 WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, *comp
, ret_size
-1, NULL
, NULL
);
1504 static BOOL
set_url_component_AtoW(const char *comp_a
, DWORD len_a
, WCHAR
**comp_w
, DWORD
*len_w
, WCHAR
**buf
)
1513 if(!(*comp_w
= *buf
= heap_alloc(len_a
*sizeof(WCHAR
)))) {
1514 SetLastError(ERROR_OUTOFMEMORY
);
1521 /***********************************************************************
1522 * InternetCrackUrlA (WININET.@)
1524 * See InternetCrackUrlW.
1526 BOOL WINAPI
InternetCrackUrlA(const char *url
, DWORD url_length
, DWORD flags
, URL_COMPONENTSA
*ret_comp
)
1528 WCHAR
*host
= NULL
, *user
= NULL
, *pass
= NULL
, *path
= NULL
, *scheme
= NULL
, *extra
= NULL
;
1529 URL_COMPONENTSW comp
;
1530 WCHAR
*url_w
= NULL
;
1533 TRACE("(%s %u %x %p)\n", url_length
? debugstr_an(url
, url_length
) : debugstr_a(url
), url_length
, flags
, ret_comp
);
1535 if (!url
|| !*url
|| !ret_comp
|| ret_comp
->dwStructSize
!= sizeof(URL_COMPONENTSA
)) {
1536 SetLastError(ERROR_INVALID_PARAMETER
);
1540 comp
.dwStructSize
= sizeof(comp
);
1542 ret
= set_url_component_AtoW(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
,
1543 &comp
.lpszHostName
, &comp
.dwHostNameLength
, &host
)
1544 && set_url_component_AtoW(ret_comp
->lpszUserName
, ret_comp
->dwUserNameLength
,
1545 &comp
.lpszUserName
, &comp
.dwUserNameLength
, &user
)
1546 && set_url_component_AtoW(ret_comp
->lpszPassword
, ret_comp
->dwPasswordLength
,
1547 &comp
.lpszPassword
, &comp
.dwPasswordLength
, &pass
)
1548 && set_url_component_AtoW(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
,
1549 &comp
.lpszUrlPath
, &comp
.dwUrlPathLength
, &path
)
1550 && set_url_component_AtoW(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
,
1551 &comp
.lpszScheme
, &comp
.dwSchemeLength
, &scheme
)
1552 && set_url_component_AtoW(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
,
1553 &comp
.lpszExtraInfo
, &comp
.dwExtraInfoLength
, &extra
);
1555 if(ret
&& !(url_w
= heap_strndupAtoW(url
, url_length
? url_length
: -1, &url_length
))) {
1556 SetLastError(ERROR_OUTOFMEMORY
);
1560 if (ret
&& (ret
= InternetCrackUrlW(url_w
, url_length
, flags
, &comp
))) {
1561 ret_comp
->nScheme
= comp
.nScheme
;
1562 ret_comp
->nPort
= comp
.nPort
;
1564 ret
= set_url_component_WtoA(comp
.lpszHostName
, comp
.dwHostNameLength
, url_w
,
1565 &ret_comp
->lpszHostName
, &ret_comp
->dwHostNameLength
, url
)
1566 && set_url_component_WtoA(comp
.lpszUserName
, comp
.dwUserNameLength
, url_w
,
1567 &ret_comp
->lpszUserName
, &ret_comp
->dwUserNameLength
, url
)
1568 && set_url_component_WtoA(comp
.lpszPassword
, comp
.dwPasswordLength
, url_w
,
1569 &ret_comp
->lpszPassword
, &ret_comp
->dwPasswordLength
, url
)
1570 && set_url_component_WtoA(comp
.lpszUrlPath
, comp
.dwUrlPathLength
, url_w
,
1571 &ret_comp
->lpszUrlPath
, &ret_comp
->dwUrlPathLength
, url
)
1572 && set_url_component_WtoA(comp
.lpszScheme
, comp
.dwSchemeLength
, url_w
,
1573 &ret_comp
->lpszScheme
, &ret_comp
->dwSchemeLength
, url
)
1574 && set_url_component_WtoA(comp
.lpszExtraInfo
, comp
.dwExtraInfoLength
, url_w
,
1575 &ret_comp
->lpszExtraInfo
, &ret_comp
->dwExtraInfoLength
, url
);
1578 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url
),
1579 debugstr_an(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
),
1580 debugstr_an(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
),
1581 debugstr_an(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
),
1582 debugstr_an(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
));
1595 static const WCHAR url_schemes
[][7] =
1598 {'g','o','p','h','e','r',0},
1599 {'h','t','t','p',0},
1600 {'h','t','t','p','s',0},
1601 {'f','i','l','e',0},
1602 {'n','e','w','s',0},
1603 {'m','a','i','l','t','o',0},
1607 /***********************************************************************
1608 * GetInternetSchemeW (internal)
1614 * INTERNET_SCHEME_UNKNOWN on failure
1617 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1621 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1623 if(lpszScheme
==NULL
)
1624 return INTERNET_SCHEME_UNKNOWN
;
1626 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1627 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1628 return INTERNET_SCHEME_FIRST
+ i
;
1630 return INTERNET_SCHEME_UNKNOWN
;
1633 /***********************************************************************
1634 * InternetCrackUrlW (WININET.@)
1636 * Break up URL into its components
1642 BOOL WINAPI
InternetCrackUrlW(const WCHAR
*lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
, URL_COMPONENTSW
*lpUC
)
1646 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1649 LPCWSTR lpszParam
= NULL
;
1650 BOOL found_colon
= FALSE
;
1652 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1654 TRACE("(%s %u %x %p)\n",
1655 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1656 dwUrlLength
, dwFlags
, lpUC
);
1658 if (!lpszUrl
|| !*lpszUrl
|| !lpUC
)
1660 SetLastError(ERROR_INVALID_PARAMETER
);
1663 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1665 if (dwFlags
& ICU_DECODE
)
1668 DWORD len
= dwUrlLength
+ 1;
1671 if (!(url_tmp
= heap_strndupW(lpszUrl
, dwUrlLength
)))
1673 SetLastError(ERROR_OUTOFMEMORY
);
1676 ret
= InternetCanonicalizeUrlW(url_tmp
, url_tmp
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1678 ret
= InternetCrackUrlW(url_tmp
, len
, dwFlags
& ~ICU_DECODE
, lpUC
);
1684 /* Determine if the URI is absolute. */
1685 while (lpszap
- lpszUrl
< dwUrlLength
)
1687 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1699 lpszcp
= lpszUrl
; /* Relative url */
1706 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1710 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1711 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1713 /* Parse <params> */
1714 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1716 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1718 if(!set_url_component(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1719 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0))
1723 /* Get scheme first. */
1724 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1725 if(!set_url_component(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, lpszUrl
, lpszcp
- lpszUrl
))
1728 /* Eat ':' in protocol. */
1731 /* double slash indicates the net_loc portion is present */
1732 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1736 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1740 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1742 lpszNetLoc
= lpszParam
;
1744 else if (!lpszNetLoc
)
1745 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1753 /* [<user>[<:password>]@]<host>[:<port>] */
1754 /* First find the user and password if they exist */
1756 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1757 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1759 /* username and password not specified. */
1760 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1761 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1763 else /* Parse out username and password */
1765 LPCWSTR lpszUser
= lpszcp
;
1766 LPCWSTR lpszPasswd
= lpszHost
;
1768 while (lpszcp
< lpszHost
)
1771 lpszPasswd
= lpszcp
;
1776 if(!set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, lpszUser
, lpszPasswd
- lpszUser
))
1779 if (lpszPasswd
!= lpszHost
)
1781 if(!set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1782 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
, lpszHost
- lpszPasswd
))
1785 lpszcp
++; /* Advance to beginning of host */
1788 /* Parse <host><:port> */
1791 lpszPort
= lpszNetLoc
;
1793 /* special case for res:// URLs: there is no port here, so the host is the
1794 entire string up to the first '/' */
1795 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1797 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1803 while (lpszcp
< lpszNetLoc
)
1811 /* If the scheme is "file" and the host is just one letter, it's not a host */
1812 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1815 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1819 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1821 if (lpszPort
!= lpszNetLoc
)
1822 lpUC
->nPort
= atoiW(++lpszPort
);
1823 else switch (lpUC
->nScheme
)
1825 case INTERNET_SCHEME_HTTP
:
1826 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1828 case INTERNET_SCHEME_HTTPS
:
1829 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1831 case INTERNET_SCHEME_FTP
:
1832 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1834 case INTERNET_SCHEME_GOPHER
:
1835 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1846 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1847 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1848 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1851 /* Here lpszcp points to:
1853 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1854 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1856 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1860 /* Only truncate the parameter list if it's already been saved
1861 * in lpUC->lpszExtraInfo.
1863 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1864 len
= lpszParam
- lpszcp
;
1867 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1868 * newlines if necessary.
1870 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1871 if (lpsznewline
!= NULL
)
1872 len
= lpsznewline
- lpszcp
;
1874 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1876 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1877 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1879 WCHAR tmppath
[MAX_PATH
];
1883 PathCreateFromUrlW(lpszUrl
, tmppath
, &len
, 0);
1888 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1889 tmppath
[len
] = '\0';
1898 /* if ends in \. or \.. append a backslash */
1899 if (tmppath
[len
- 1] == '.' &&
1900 (tmppath
[len
- 2] == '\\' ||
1901 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1903 if (len
< MAX_PATH
- 1)
1905 tmppath
[len
] = '\\';
1906 tmppath
[len
+1] = '\0';
1910 if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, tmppath
, len
))
1913 else if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, len
))
1918 set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, 0);
1921 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1922 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1923 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1924 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1925 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1930 /***********************************************************************
1931 * InternetAttemptConnect (WININET.@)
1933 * Attempt to make a connection to the internet
1936 * ERROR_SUCCESS on success
1937 * Error value on failure
1940 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1943 return ERROR_SUCCESS
;
1947 /***********************************************************************
1948 * convert_url_canonicalization_flags
1950 * Helper for InternetCanonicalizeUrl
1953 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1956 * Flags suitable for UrlCanonicalize
1958 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1960 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1962 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1963 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1964 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1965 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1966 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1967 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1968 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1973 /***********************************************************************
1974 * InternetCanonicalizeUrlA (WININET.@)
1976 * Escape unsafe characters and spaces
1983 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1984 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1988 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1989 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1991 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
1992 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1993 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1994 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1999 /***********************************************************************
2000 * InternetCanonicalizeUrlW (WININET.@)
2002 * Escape unsafe characters and spaces
2009 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2010 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2014 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2015 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2017 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2018 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2019 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2020 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2025 /* #################################################### */
2027 static INTERNET_STATUS_CALLBACK
set_status_callback(
2028 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2030 INTERNET_STATUS_CALLBACK ret
;
2032 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2033 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2035 ret
= lpwh
->lpfnStatusCB
;
2036 lpwh
->lpfnStatusCB
= callback
;
2041 /***********************************************************************
2042 * InternetSetStatusCallbackA (WININET.@)
2044 * Sets up a callback function which is called as progress is made
2045 * during an operation.
2048 * Previous callback or NULL on success
2049 * INTERNET_INVALID_STATUS_CALLBACK on failure
2052 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2053 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2055 INTERNET_STATUS_CALLBACK retVal
;
2056 object_header_t
*lpwh
;
2058 TRACE("%p\n", hInternet
);
2060 if (!(lpwh
= get_handle_object(hInternet
)))
2061 return INTERNET_INVALID_STATUS_CALLBACK
;
2063 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2065 WININET_Release( lpwh
);
2069 /***********************************************************************
2070 * InternetSetStatusCallbackW (WININET.@)
2072 * Sets up a callback function which is called as progress is made
2073 * during an operation.
2076 * Previous callback or NULL on success
2077 * INTERNET_INVALID_STATUS_CALLBACK on failure
2080 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2081 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2083 INTERNET_STATUS_CALLBACK retVal
;
2084 object_header_t
*lpwh
;
2086 TRACE("%p\n", hInternet
);
2088 if (!(lpwh
= get_handle_object(hInternet
)))
2089 return INTERNET_INVALID_STATUS_CALLBACK
;
2091 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2093 WININET_Release( lpwh
);
2097 /***********************************************************************
2098 * InternetSetFilePointer (WININET.@)
2100 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2101 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2103 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2107 /***********************************************************************
2108 * InternetWriteFile (WININET.@)
2110 * Write data to an open internet file
2117 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2118 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2120 object_header_t
*lpwh
;
2123 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2125 lpwh
= get_handle_object( hFile
);
2127 WARN("Invalid handle\n");
2128 SetLastError(ERROR_INVALID_HANDLE
);
2132 if(lpwh
->vtbl
->WriteFile
) {
2133 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2135 WARN("No Writefile method.\n");
2136 res
= ERROR_INVALID_HANDLE
;
2139 WININET_Release( lpwh
);
2141 if(res
!= ERROR_SUCCESS
)
2143 return res
== ERROR_SUCCESS
;
2147 /***********************************************************************
2148 * InternetReadFile (WININET.@)
2150 * Read data from an open internet file
2157 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2158 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2160 object_header_t
*hdr
;
2161 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2163 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2165 hdr
= get_handle_object(hFile
);
2167 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2171 if(hdr
->vtbl
->ReadFile
) {
2172 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, 0, 0);
2173 if(res
== ERROR_IO_PENDING
)
2174 *pdwNumOfBytesRead
= 0;
2177 WININET_Release(hdr
);
2179 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2180 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2182 if(res
!= ERROR_SUCCESS
)
2184 return res
== ERROR_SUCCESS
;
2187 /***********************************************************************
2188 * InternetReadFileExA (WININET.@)
2190 * Read data from an open internet file
2193 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2194 * lpBuffersOut [I/O] Buffer.
2195 * dwFlags [I] Flags. See notes.
2196 * dwContext [I] Context for callbacks.
2203 * The parameter dwFlags include zero or more of the following flags:
2204 *|IRF_ASYNC - Makes the call asynchronous.
2205 *|IRF_SYNC - Makes the call synchronous.
2206 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2207 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2209 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2212 * InternetOpenUrlA(), HttpOpenRequestA()
2214 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2215 DWORD dwFlags
, DWORD_PTR dwContext
)
2217 object_header_t
*hdr
;
2218 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2220 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2222 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2223 SetLastError(ERROR_INVALID_PARAMETER
);
2227 hdr
= get_handle_object(hFile
);
2229 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2233 if(hdr
->vtbl
->ReadFile
)
2234 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2235 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2237 WININET_Release(hdr
);
2239 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2240 res
, lpBuffersOut
->dwBufferLength
);
2242 if(res
!= ERROR_SUCCESS
)
2244 return res
== ERROR_SUCCESS
;
2247 /***********************************************************************
2248 * InternetReadFileExW (WININET.@)
2250 * InternetReadFileExA()
2252 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2253 DWORD dwFlags
, DWORD_PTR dwContext
)
2255 object_header_t
*hdr
;
2256 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2258 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2260 if (!lpBuffer
|| lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2261 SetLastError(ERROR_INVALID_PARAMETER
);
2265 hdr
= get_handle_object(hFile
);
2267 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2271 if(hdr
->vtbl
->ReadFile
)
2272 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2273 dwFlags
, dwContext
);
2275 WININET_Release(hdr
);
2277 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2278 res
, lpBuffer
->dwBufferLength
);
2280 if(res
!= ERROR_SUCCESS
)
2282 return res
== ERROR_SUCCESS
;
2285 static WCHAR
*get_proxy_autoconfig_url(void)
2287 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2289 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2294 if (!settings
) return NULL
;
2296 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2298 CFRelease( settings
);
2301 len
= CFStringGetLength( ref
);
2303 ret
= heap_alloc( (len
+1) * sizeof(WCHAR
) );
2306 CFStringGetCharacters( ref
, CFRangeMake(0, len
), ret
);
2309 TRACE( "returning %s\n", debugstr_w(ret
) );
2310 CFRelease( settings
);
2313 FIXME( "no support on this platform\n" );
2318 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2320 /* FIXME: This function currently handles more options than it should. Options requiring
2321 * proper handles should be moved to proper functions */
2323 case INTERNET_OPTION_HTTP_VERSION
:
2324 if (*size
< sizeof(HTTP_VERSION_INFO
))
2325 return ERROR_INSUFFICIENT_BUFFER
;
2328 * Presently hardcoded to 1.1
2330 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2331 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2332 *size
= sizeof(HTTP_VERSION_INFO
);
2334 return ERROR_SUCCESS
;
2336 case INTERNET_OPTION_CONNECTED_STATE
:
2337 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2339 if (*size
< sizeof(ULONG
))
2340 return ERROR_INSUFFICIENT_BUFFER
;
2342 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2343 *size
= sizeof(ULONG
);
2345 return ERROR_SUCCESS
;
2347 case INTERNET_OPTION_PROXY
: {
2351 TRACE("Getting global proxy info\n");
2352 memset(&ai
, 0, sizeof(appinfo_t
));
2353 INTERNET_ConfigureProxy(&ai
);
2355 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2356 APPINFO_Destroy(&ai
.hdr
);
2360 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2361 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2363 if (*size
< sizeof(ULONG
))
2364 return ERROR_INSUFFICIENT_BUFFER
;
2366 *(ULONG
*)buffer
= max_conns
;
2367 *size
= sizeof(ULONG
);
2369 return ERROR_SUCCESS
;
2371 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2372 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2374 if (*size
< sizeof(ULONG
))
2375 return ERROR_INSUFFICIENT_BUFFER
;
2377 *(ULONG
*)buffer
= max_1_0_conns
;
2378 *size
= sizeof(ULONG
);
2380 return ERROR_SUCCESS
;
2382 case INTERNET_OPTION_SECURITY_FLAGS
:
2383 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2384 return ERROR_SUCCESS
;
2386 case INTERNET_OPTION_VERSION
: {
2387 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2389 TRACE("INTERNET_OPTION_VERSION\n");
2391 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2392 return ERROR_INSUFFICIENT_BUFFER
;
2394 memcpy(buffer
, &info
, sizeof(info
));
2395 *size
= sizeof(info
);
2397 return ERROR_SUCCESS
;
2400 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2402 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2403 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2404 DWORD res
= ERROR_SUCCESS
, i
;
2408 TRACE("Getting global proxy info\n");
2409 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2412 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2414 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2416 return ERROR_INSUFFICIENT_BUFFER
;
2419 url
= get_proxy_autoconfig_url();
2421 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2422 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2423 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2425 switch (optionW
->dwOption
) {
2426 case INTERNET_PER_CONN_FLAGS
:
2428 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2430 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2432 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2433 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2436 case INTERNET_PER_CONN_PROXY_SERVER
:
2438 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2440 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2443 case INTERNET_PER_CONN_PROXY_BYPASS
:
2445 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2447 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2450 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2452 optionW
->Value
.pszValue
= NULL
;
2454 optionW
->Value
.pszValue
= heap_strdupW(url
);
2456 optionA
->Value
.pszValue
= heap_strdupWtoA(url
);
2459 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2460 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2463 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2464 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2465 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2466 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2467 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2468 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2472 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2473 res
= ERROR_INVALID_PARAMETER
;
2482 case INTERNET_OPTION_REQUEST_FLAGS
:
2483 case INTERNET_OPTION_USER_AGENT
:
2485 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2486 case INTERNET_OPTION_POLICY
:
2487 return ERROR_INVALID_PARAMETER
;
2488 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2489 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2491 if (*size
< sizeof(ULONG
))
2492 return ERROR_INSUFFICIENT_BUFFER
;
2494 *(ULONG
*)buffer
= connect_timeout
;
2495 *size
= sizeof(ULONG
);
2497 return ERROR_SUCCESS
;
2500 FIXME("Stub for %d\n", option
);
2501 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2504 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2507 case INTERNET_OPTION_CONTEXT_VALUE
:
2509 return ERROR_INVALID_PARAMETER
;
2511 if (*size
< sizeof(DWORD_PTR
)) {
2512 *size
= sizeof(DWORD_PTR
);
2513 return ERROR_INSUFFICIENT_BUFFER
;
2516 return ERROR_INVALID_PARAMETER
;
2518 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2519 *size
= sizeof(DWORD_PTR
);
2520 return ERROR_SUCCESS
;
2522 case INTERNET_OPTION_REQUEST_FLAGS
:
2523 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2524 *size
= sizeof(DWORD
);
2525 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2527 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2528 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2529 WARN("Called on global option %u\n", option
);
2530 return ERROR_INTERNET_INVALID_OPERATION
;
2533 /* FIXME: we shouldn't call it here */
2534 return query_global_option(option
, buffer
, size
, unicode
);
2537 /***********************************************************************
2538 * InternetQueryOptionW (WININET.@)
2540 * Queries an options on the specified handle
2547 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2548 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2550 object_header_t
*hdr
;
2551 DWORD res
= ERROR_INVALID_HANDLE
;
2553 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2556 hdr
= get_handle_object(hInternet
);
2558 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2559 WININET_Release(hdr
);
2562 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2565 if(res
!= ERROR_SUCCESS
)
2567 return res
== ERROR_SUCCESS
;
2570 /***********************************************************************
2571 * InternetQueryOptionA (WININET.@)
2573 * Queries an options on the specified handle
2580 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2581 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2583 object_header_t
*hdr
;
2584 DWORD res
= ERROR_INVALID_HANDLE
;
2586 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2589 hdr
= get_handle_object(hInternet
);
2591 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2592 WININET_Release(hdr
);
2595 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2598 if(res
!= ERROR_SUCCESS
)
2600 return res
== ERROR_SUCCESS
;
2603 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2606 case INTERNET_OPTION_SETTINGS_CHANGED
:
2607 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2608 collect_connections(COLLECT_CONNECTIONS
);
2609 return ERROR_SUCCESS
;
2610 case INTERNET_OPTION_CALLBACK
:
2611 WARN("Not settable option %u\n", option
);
2612 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2613 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2614 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2615 WARN("Called on global option %u\n", option
);
2616 return ERROR_INTERNET_INVALID_OPERATION
;
2617 case INTERNET_OPTION_REFRESH
:
2618 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2621 return ERROR_INTERNET_INVALID_OPTION
;
2624 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2627 case INTERNET_OPTION_CALLBACK
:
2628 WARN("Not global option %u\n", option
);
2629 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2631 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2632 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2634 if(size
!= sizeof(max_conns
))
2635 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2637 return ERROR_BAD_ARGUMENTS
;
2639 max_conns
= *(ULONG
*)buf
;
2640 return ERROR_SUCCESS
;
2642 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2643 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2645 if(size
!= sizeof(max_1_0_conns
))
2646 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2648 return ERROR_BAD_ARGUMENTS
;
2650 max_1_0_conns
= *(ULONG
*)buf
;
2651 return ERROR_SUCCESS
;
2653 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2654 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2656 if(size
!= sizeof(connect_timeout
))
2657 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2659 return ERROR_BAD_ARGUMENTS
;
2661 connect_timeout
= *(ULONG
*)buf
;
2662 return ERROR_SUCCESS
;
2664 case INTERNET_OPTION_SUPPRESS_BEHAVIOR
:
2665 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2667 if(size
!= sizeof(ULONG
))
2668 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2670 FIXME("%08x\n", *(ULONG
*)buf
);
2671 return ERROR_SUCCESS
;
2674 return INET_SetOption(NULL
, option
, buf
, size
);
2677 /***********************************************************************
2678 * InternetSetOptionW (WININET.@)
2680 * Sets an options on the specified handle
2687 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2688 LPVOID lpBuffer
, DWORD dwBufferLength
)
2690 object_header_t
*lpwhh
;
2694 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2696 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2698 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2700 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2702 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2704 WININET_Release(lpwhh
);
2706 if(res
!= ERROR_SUCCESS
)
2709 return res
== ERROR_SUCCESS
;
2714 case INTERNET_OPTION_HTTP_VERSION
:
2716 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2717 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2720 case INTERNET_OPTION_ERROR_MASK
:
2723 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2725 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2726 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2727 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2728 SetLastError(ERROR_INVALID_PARAMETER
);
2730 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2731 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2734 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2735 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2738 case INTERNET_OPTION_PROXY
:
2740 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2742 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2744 SetLastError(ERROR_INVALID_PARAMETER
);
2749 EnterCriticalSection( &WININET_cs
);
2750 free_global_proxy();
2751 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2754 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2756 global_proxy
->proxyEnabled
= 1;
2757 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2758 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2762 global_proxy
->proxyEnabled
= 0;
2763 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2766 LeaveCriticalSection( &WININET_cs
);
2770 /* In general, each type of object should handle
2771 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2772 * get silently dropped.
2774 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2775 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2780 case INTERNET_OPTION_CODEPAGE
:
2782 ULONG codepage
= *(ULONG
*)lpBuffer
;
2783 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2786 case INTERNET_OPTION_REQUEST_PRIORITY
:
2788 ULONG priority
= *(ULONG
*)lpBuffer
;
2789 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2792 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2794 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2795 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2798 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2800 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2801 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2804 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2805 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2807 case INTERNET_OPTION_END_BROWSER_SESSION
:
2808 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2811 case INTERNET_OPTION_CONNECTED_STATE
:
2812 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2814 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2815 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2817 case INTERNET_OPTION_SEND_TIMEOUT
:
2818 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2819 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2821 ULONG timeout
= *(ULONG
*)lpBuffer
;
2822 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2825 case INTERNET_OPTION_CONNECT_RETRIES
:
2827 ULONG retries
= *(ULONG
*)lpBuffer
;
2828 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2831 case INTERNET_OPTION_CONTEXT_VALUE
:
2835 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2838 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2840 SetLastError(ERROR_INVALID_PARAMETER
);
2844 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2847 case INTERNET_OPTION_SECURITY_FLAGS
:
2848 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2850 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2851 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2853 case INTERNET_OPTION_HTTP_DECODING
:
2854 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2855 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2858 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2859 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2860 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2863 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2864 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2865 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2868 case INTERNET_OPTION_CODEPAGE_PATH
:
2869 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2870 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2873 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2874 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2875 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2878 case INTERNET_OPTION_IDN
:
2879 FIXME("INTERNET_OPTION_IDN; STUB\n");
2880 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2883 case INTERNET_OPTION_POLICY
:
2884 SetLastError(ERROR_INVALID_PARAMETER
);
2887 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2888 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2893 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2895 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2896 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2898 switch (option
->dwOption
) {
2899 case INTERNET_PER_CONN_PROXY_SERVER
:
2900 heap_free(pi
.proxy
);
2901 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2904 case INTERNET_PER_CONN_FLAGS
:
2905 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2906 pi
.proxyEnabled
= 1;
2909 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2910 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2911 pi
.proxyEnabled
= 0;
2915 case INTERNET_PER_CONN_PROXY_BYPASS
:
2916 heap_free(pi
.proxyBypass
);
2917 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
2920 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2921 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2922 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2923 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2924 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2925 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2926 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2930 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2931 SetLastError(ERROR_INVALID_PARAMETER
);
2936 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2941 ret
= (res
== ERROR_SUCCESS
);
2945 FIXME("Option %d STUB\n",dwOption
);
2946 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2952 WININET_Release( lpwhh
);
2958 /***********************************************************************
2959 * InternetSetOptionA (WININET.@)
2961 * Sets an options on the specified handle.
2968 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2969 LPVOID lpBuffer
, DWORD dwBufferLength
)
2977 case INTERNET_OPTION_PROXY
:
2979 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2980 LPINTERNET_PROXY_INFOW piw
;
2981 DWORD proxlen
, prbylen
;
2984 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2985 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2986 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2987 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2988 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2989 piw
->dwAccessType
= pi
->dwAccessType
;
2990 prox
= (LPWSTR
) &piw
[1];
2991 prby
= &prox
[proxlen
+1];
2992 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2993 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2994 piw
->lpszProxy
= prox
;
2995 piw
->lpszProxyBypass
= prby
;
2998 case INTERNET_OPTION_USER_AGENT
:
2999 case INTERNET_OPTION_USERNAME
:
3000 case INTERNET_OPTION_PASSWORD
:
3001 case INTERNET_OPTION_PROXY_USERNAME
:
3002 case INTERNET_OPTION_PROXY_PASSWORD
:
3003 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3004 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3005 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3007 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3009 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3010 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3011 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3012 wbuffer
= heap_alloc(wlen
);
3015 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3016 if (listA
->pszConnection
)
3018 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3019 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3020 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3023 listW
->pszConnection
= NULL
;
3024 listW
->dwOptionCount
= listA
->dwOptionCount
;
3025 listW
->dwOptionError
= listA
->dwOptionError
;
3026 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3028 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3029 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3030 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3032 optW
->dwOption
= optA
->dwOption
;
3034 switch (optA
->dwOption
) {
3035 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3036 case INTERNET_PER_CONN_PROXY_BYPASS
:
3037 case INTERNET_PER_CONN_PROXY_SERVER
:
3038 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3039 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3040 if (optA
->Value
.pszValue
)
3042 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3043 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3044 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3047 optW
->Value
.pszValue
= NULL
;
3049 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3050 case INTERNET_PER_CONN_FLAGS
:
3051 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3052 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3054 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3055 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3058 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3059 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3067 wlen
= dwBufferLength
;
3070 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3072 if( lpBuffer
!= wbuffer
)
3074 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3076 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3078 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3079 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3080 switch (opt
->dwOption
) {
3081 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3082 case INTERNET_PER_CONN_PROXY_BYPASS
:
3083 case INTERNET_PER_CONN_PROXY_SERVER
:
3084 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3085 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3086 heap_free( opt
->Value
.pszValue
);
3092 heap_free( list
->pOptions
);
3094 heap_free( wbuffer
);
3101 /***********************************************************************
3102 * InternetSetOptionExA (WININET.@)
3104 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3105 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3107 FIXME("Flags %08x ignored\n", dwFlags
);
3108 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3111 /***********************************************************************
3112 * InternetSetOptionExW (WININET.@)
3114 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3115 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3117 FIXME("Flags %08x ignored\n", dwFlags
);
3118 if( dwFlags
& ~ISO_VALID_FLAGS
)
3120 SetLastError( ERROR_INVALID_PARAMETER
);
3123 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3126 static const WCHAR WININET_wkday
[7][4] =
3127 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3128 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3129 static const WCHAR WININET_month
[12][4] =
3130 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3131 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3132 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3134 /***********************************************************************
3135 * InternetTimeFromSystemTimeA (WININET.@)
3137 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3140 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3142 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3144 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3146 SetLastError(ERROR_INVALID_PARAMETER
);
3150 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3152 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3156 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3157 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3162 /***********************************************************************
3163 * InternetTimeFromSystemTimeW (WININET.@)
3165 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3167 static const WCHAR date
[] =
3168 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3169 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3171 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3173 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3175 SetLastError(ERROR_INVALID_PARAMETER
);
3179 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3181 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3185 sprintfW( string
, date
,
3186 WININET_wkday
[time
->wDayOfWeek
],
3188 WININET_month
[time
->wMonth
- 1],
3197 /***********************************************************************
3198 * InternetTimeToSystemTimeA (WININET.@)
3200 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3205 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3207 stringW
= heap_strdupAtoW(string
);
3210 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3211 heap_free( stringW
);
3216 /***********************************************************************
3217 * InternetTimeToSystemTimeW (WININET.@)
3219 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3222 const WCHAR
*s
= string
;
3225 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3227 if (!string
|| !time
) return FALSE
;
3229 /* Windows does this too */
3230 GetSystemTime( time
);
3232 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3233 * a SYSTEMTIME structure.
3236 while (*s
&& !isalphaW( *s
)) s
++;
3237 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3238 time
->wDayOfWeek
= 7;
3240 for (i
= 0; i
< 7; i
++)
3242 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3243 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3244 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3246 time
->wDayOfWeek
= i
;
3251 if (time
->wDayOfWeek
> 6) return TRUE
;
3252 while (*s
&& !isdigitW( *s
)) s
++;
3253 time
->wDay
= strtolW( s
, &end
, 10 );
3256 while (*s
&& !isalphaW( *s
)) s
++;
3257 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3260 for (i
= 0; i
< 12; i
++)
3262 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3263 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3264 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3266 time
->wMonth
= i
+ 1;
3270 if (time
->wMonth
== 0) return TRUE
;
3272 while (*s
&& !isdigitW( *s
)) s
++;
3273 if (*s
== '\0') return TRUE
;
3274 time
->wYear
= strtolW( s
, &end
, 10 );
3277 while (*s
&& !isdigitW( *s
)) s
++;
3278 if (*s
== '\0') return TRUE
;
3279 time
->wHour
= strtolW( s
, &end
, 10 );
3282 while (*s
&& !isdigitW( *s
)) s
++;
3283 if (*s
== '\0') return TRUE
;
3284 time
->wMinute
= strtolW( s
, &end
, 10 );
3287 while (*s
&& !isdigitW( *s
)) s
++;
3288 if (*s
== '\0') return TRUE
;
3289 time
->wSecond
= strtolW( s
, &end
, 10 );
3292 time
->wMilliseconds
= 0;
3296 /***********************************************************************
3297 * InternetCheckConnectionW (WININET.@)
3299 * Pings a requested host to check internet connection
3302 * TRUE on success and FALSE on failure. If a failure then
3303 * ERROR_NOT_CONNECTED is placed into GetLastError
3306 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3309 * this is a kludge which runs the resident ping program and reads the output.
3311 * Anyone have a better idea?
3315 static const CHAR ping
[] = "ping -c 1 ";
3316 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3318 DWORD len
, host_len
;
3322 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl
), dwFlags
, dwReserved
);
3325 * Crack or set the Address
3327 if (lpszUrl
== NULL
)
3330 * According to the doc we are supposed to use the ip for the next
3331 * server in the WnInet internal server database. I have
3332 * no idea what that is or how to get it.
3334 * So someone needs to implement this.
3336 FIXME("Unimplemented with URL of NULL\n");
3341 URL_COMPONENTSW components
= {sizeof(components
)};
3343 components
.dwHostNameLength
= 1;
3345 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3348 host
= components
.lpszHostName
;
3349 host_len
= components
.dwHostNameLength
;
3350 port
= components
.nPort
;
3351 TRACE("host name: %s port: %d\n",debugstr_wn(host
, host_len
), port
);
3354 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3356 struct sockaddr_storage saddr
;
3357 int sa_len
= sizeof(saddr
);
3362 host_z
= heap_strndupW(host
, host_len
);
3366 b
= GetAddress(host_z
, port
, (struct sockaddr
*)&saddr
, &sa_len
, NULL
);
3371 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3374 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3382 * Build our ping command
3386 len
= WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, NULL
, 0, NULL
, NULL
);
3387 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
)+1);
3388 strcpy(command
, ping
);
3389 WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, command
+sizeof(ping
)-1, len
, NULL
, NULL
);
3390 strcpy(command
+sizeof(ping
)-1+len
, redirect
);
3392 TRACE("Ping command is : %s\n",command
);
3394 status
= system(command
);
3395 heap_free( command
);
3397 TRACE("Ping returned a code of %i\n",status
);
3399 /* Ping return code of 0 indicates success */
3406 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3412 /***********************************************************************
3413 * InternetCheckConnectionA (WININET.@)
3415 * Pings a requested host to check internet connection
3418 * TRUE on success and FALSE on failure. If a failure then
3419 * ERROR_NOT_CONNECTED is placed into GetLastError
3422 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3428 url
= heap_strdupAtoW(lpszUrl
);
3433 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3440 /**********************************************************
3441 * INTERNET_InternetOpenUrlW (internal)
3446 * handle of connection or NULL on failure
3448 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3449 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3451 URL_COMPONENTSW urlComponents
= { sizeof(urlComponents
) };
3452 WCHAR
*host
, *user
= NULL
, *pass
= NULL
, *path
;
3453 HINTERNET client
= NULL
, client1
= NULL
;
3456 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3457 dwHeadersLength
, dwFlags
, dwContext
);
3459 urlComponents
.dwHostNameLength
= 1;
3460 urlComponents
.dwUserNameLength
= 1;
3461 urlComponents
.dwPasswordLength
= 1;
3462 urlComponents
.dwUrlPathLength
= 1;
3463 urlComponents
.dwExtraInfoLength
= 1;
3464 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3467 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
3468 urlComponents
.dwExtraInfoLength
)
3470 assert(urlComponents
.lpszUrlPath
+ urlComponents
.dwUrlPathLength
== urlComponents
.lpszExtraInfo
);
3471 urlComponents
.dwUrlPathLength
+= urlComponents
.dwExtraInfoLength
;
3474 host
= heap_strndupW(urlComponents
.lpszHostName
, urlComponents
.dwHostNameLength
);
3475 path
= heap_strndupW(urlComponents
.lpszUrlPath
, urlComponents
.dwUrlPathLength
);
3476 if(urlComponents
.dwUserNameLength
)
3477 user
= heap_strndupW(urlComponents
.lpszUserName
, urlComponents
.dwUserNameLength
);
3478 if(urlComponents
.dwPasswordLength
)
3479 pass
= heap_strndupW(urlComponents
.lpszPassword
, urlComponents
.dwPasswordLength
);
3481 switch(urlComponents
.nScheme
) {
3482 case INTERNET_SCHEME_FTP
:
3483 client
= FTP_Connect(hIC
, host
, urlComponents
.nPort
,
3484 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
);
3487 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3488 if(client1
== NULL
) {
3489 InternetCloseHandle(client
);
3494 case INTERNET_SCHEME_HTTP
:
3495 case INTERNET_SCHEME_HTTPS
: {
3496 static const WCHAR szStars
[] = { '*','/','*', 0 };
3497 LPCWSTR accept
[2] = { szStars
, NULL
};
3499 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3501 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3502 res
= HTTP_Connect(hIC
, host
, urlComponents
.nPort
,
3503 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3504 if(res
!= ERROR_SUCCESS
) {
3505 INTERNET_SetLastError(res
);
3509 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3510 if(client1
== NULL
) {
3511 InternetCloseHandle(client
);
3514 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3515 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3516 GetLastError() != ERROR_IO_PENDING
) {
3517 InternetCloseHandle(client1
);
3522 case INTERNET_SCHEME_GOPHER
:
3523 /* gopher doesn't seem to be implemented in wine, but it's supposed
3524 * to be supported by InternetOpenUrlA. */
3526 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3530 TRACE(" %p <--\n", client1
);
3539 /**********************************************************
3540 * InternetOpenUrlW (WININET.@)
3545 * handle of connection or NULL on failure
3556 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3558 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3560 TRACE("%p\n", task
->hdr
.hdr
);
3562 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3563 task
->headers_len
, task
->flags
, task
->context
);
3564 heap_free(task
->url
);
3565 heap_free(task
->headers
);
3568 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3569 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3571 HINTERNET ret
= NULL
;
3572 appinfo_t
*hIC
= NULL
;
3574 if (TRACE_ON(wininet
)) {
3575 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3576 dwHeadersLength
, dwFlags
, dwContext
);
3578 dump_INTERNET_FLAGS(dwFlags
);
3583 SetLastError(ERROR_INVALID_PARAMETER
);
3587 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3588 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3589 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3593 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3594 open_url_task_t
*task
;
3596 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3597 task
->url
= heap_strdupW(lpszUrl
);
3598 task
->headers
= heap_strdupW(lpszHeaders
);
3599 task
->headers_len
= dwHeadersLength
;
3600 task
->flags
= dwFlags
;
3601 task
->context
= dwContext
;
3603 INTERNET_AsyncCall(&task
->hdr
);
3604 SetLastError(ERROR_IO_PENDING
);
3606 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3611 WININET_Release( &hIC
->hdr
);
3612 TRACE(" %p <--\n", ret
);
3617 /**********************************************************
3618 * InternetOpenUrlA (WININET.@)
3623 * handle of connection or NULL on failure
3625 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3626 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3628 HINTERNET rc
= NULL
;
3629 LPWSTR szUrl
= NULL
;
3630 WCHAR
*headers
= NULL
;
3635 szUrl
= heap_strdupAtoW(lpszUrl
);
3641 headers
= heap_strndupAtoW(lpszHeaders
, dwHeadersLength
, &dwHeadersLength
);
3648 rc
= InternetOpenUrlW(hInternet
, szUrl
, headers
, dwHeadersLength
, dwFlags
, dwContext
);
3656 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3658 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3662 lpwite
->dwError
= 0;
3663 lpwite
->response
[0] = '\0';
3666 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3675 /***********************************************************************
3676 * INTERNET_SetLastError (internal)
3678 * Set last thread specific error
3683 void INTERNET_SetLastError(DWORD dwError
)
3685 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3688 lpwite
= INTERNET_AllocThreadError();
3690 SetLastError(dwError
);
3692 lpwite
->dwError
= dwError
;
3696 /***********************************************************************
3697 * INTERNET_GetLastError (internal)
3699 * Get last thread specific error
3704 DWORD
INTERNET_GetLastError(void)
3706 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3707 if (!lpwite
) return 0;
3708 /* TlsGetValue clears last error, so set it again here */
3709 SetLastError(lpwite
->dwError
);
3710 return lpwite
->dwError
;
3714 /***********************************************************************
3715 * INTERNET_WorkerThreadFunc (internal)
3717 * Worker thread execution function
3722 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3724 task_header_t
*task
= lpvParam
;
3729 WININET_Release(task
->hdr
);
3732 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3734 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3735 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3740 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3742 task_header_t
*task
;
3744 task
= heap_alloc(size
);
3748 task
->hdr
= WININET_AddRef(hdr
);
3753 /***********************************************************************
3754 * INTERNET_AsyncCall (internal)
3756 * Retrieves work request from queue
3761 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3767 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3771 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3773 return ERROR_SUCCESS
;
3777 /***********************************************************************
3778 * INTERNET_GetResponseBuffer (internal)
3783 LPSTR
INTERNET_GetResponseBuffer(void)
3785 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3787 lpwite
= INTERNET_AllocThreadError();
3789 return lpwite
->response
;
3792 /**********************************************************
3793 * InternetQueryDataAvailable (WININET.@)
3795 * Determines how much data is available to be read.
3798 * TRUE on success, FALSE if an error occurred. If
3799 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3800 * no data is presently available, FALSE is returned with
3801 * the last error ERROR_IO_PENDING; a callback with status
3802 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3803 * data is available.
3805 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3806 LPDWORD lpdwNumberOfBytesAvailable
,
3807 DWORD dwFlags
, DWORD_PTR dwContext
)
3809 object_header_t
*hdr
;
3812 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3814 hdr
= get_handle_object( hFile
);
3816 SetLastError(ERROR_INVALID_HANDLE
);
3820 if(hdr
->vtbl
->QueryDataAvailable
) {
3821 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3823 WARN("wrong handle\n");
3824 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3827 WININET_Release(hdr
);
3829 if(res
!= ERROR_SUCCESS
)
3831 return res
== ERROR_SUCCESS
;
3834 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3836 req_file_t
*req_file
;
3838 req_file
= heap_alloc_zero(sizeof(*req_file
));
3840 return ERROR_NOT_ENOUGH_MEMORY
;
3844 req_file
->file_name
= heap_strdupW(file_name
);
3845 if(!req_file
->file_name
) {
3846 heap_free(req_file
);
3847 return ERROR_NOT_ENOUGH_MEMORY
;
3850 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3851 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3852 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
3853 req_file_release(req_file
);
3854 return GetLastError();
3858 return ERROR_SUCCESS
;
3861 void req_file_release(req_file_t
*req_file
)
3863 if(InterlockedDecrement(&req_file
->ref
))
3866 if(!req_file
->is_committed
)
3867 DeleteFileW(req_file
->file_name
);
3868 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
3869 CloseHandle(req_file
->file_handle
);
3870 heap_free(req_file
->file_name
);
3871 heap_free(req_file
->url
);
3872 heap_free(req_file
);
3875 /***********************************************************************
3876 * InternetLockRequestFile (WININET.@)
3878 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
3880 req_file_t
*req_file
= NULL
;
3881 object_header_t
*hdr
;
3884 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
3886 hdr
= get_handle_object(hInternet
);
3888 SetLastError(ERROR_INVALID_HANDLE
);
3892 if(hdr
->vtbl
->LockRequestFile
) {
3893 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
3895 WARN("wrong handle\n");
3896 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3899 WININET_Release(hdr
);
3901 *lphLockReqHandle
= req_file
;
3902 if(res
!= ERROR_SUCCESS
)
3904 return res
== ERROR_SUCCESS
;
3907 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
3909 TRACE("(%p)\n", hLockHandle
);
3911 req_file_release(hLockHandle
);
3916 /***********************************************************************
3917 * InternetAutodial (WININET.@)
3919 * On windows this function is supposed to dial the default internet
3920 * connection. We don't want to have Wine dial out to the internet so
3921 * we return TRUE by default. It might be nice to check if we are connected.
3928 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3932 /* Tell that we are connected to the internet. */
3936 /***********************************************************************
3937 * InternetAutodialHangup (WININET.@)
3939 * Hangs up a connection made with InternetAutodial
3948 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3952 /* we didn't dial, we don't disconnect */
3956 /***********************************************************************
3957 * InternetCombineUrlA (WININET.@)
3959 * Combine a base URL with a relative URL
3967 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3968 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3973 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3975 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3976 dwFlags
^= ICU_NO_ENCODE
;
3977 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3982 /***********************************************************************
3983 * InternetCombineUrlW (WININET.@)
3985 * Combine a base URL with a relative URL
3993 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3994 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3999 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4001 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4002 dwFlags
^= ICU_NO_ENCODE
;
4003 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4008 /* max port num is 65535 => 5 digits */
4009 #define MAX_WORD_DIGITS 5
4011 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4012 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4013 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4014 (url)->dw##component##Length : strlen((url)->lpsz##component))
4016 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4018 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4019 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4021 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4022 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4024 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4025 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4027 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4028 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4031 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4037 /* opaque urls do not fit into the standard url hierarchy and don't have
4038 * two following slashes */
4039 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4041 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4042 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4043 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4044 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4045 (nScheme
!= INTERNET_SCHEME_FILE
);
4048 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4051 if (scheme
< INTERNET_SCHEME_FIRST
)
4053 index
= scheme
- INTERNET_SCHEME_FIRST
;
4054 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4056 return (LPCWSTR
)url_schemes
[index
];
4059 /* we can calculate using ansi strings because we're just
4060 * calculating string length, not size
4062 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4063 LPDWORD lpdwUrlLength
)
4065 INTERNET_SCHEME nScheme
;
4069 if (lpUrlComponents
->lpszScheme
)
4071 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4072 *lpdwUrlLength
+= dwLen
;
4073 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4079 nScheme
= lpUrlComponents
->nScheme
;
4081 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4082 nScheme
= INTERNET_SCHEME_HTTP
;
4083 scheme
= INTERNET_GetSchemeString(nScheme
);
4084 *lpdwUrlLength
+= strlenW(scheme
);
4087 (*lpdwUrlLength
)++; /* ':' */
4088 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4089 *lpdwUrlLength
+= strlen("//");
4091 if (lpUrlComponents
->lpszUserName
)
4093 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4094 *lpdwUrlLength
+= strlen("@");
4098 if (lpUrlComponents
->lpszPassword
)
4100 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4105 if (lpUrlComponents
->lpszPassword
)
4107 *lpdwUrlLength
+= strlen(":");
4108 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4111 if (lpUrlComponents
->lpszHostName
)
4113 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4115 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4117 char szPort
[MAX_WORD_DIGITS
+1];
4119 *lpdwUrlLength
+= sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4120 *lpdwUrlLength
+= strlen(":");
4123 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4124 (*lpdwUrlLength
)++; /* '/' */
4127 if (lpUrlComponents
->lpszUrlPath
)
4128 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4130 if (lpUrlComponents
->lpszExtraInfo
)
4131 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4136 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4140 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4142 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4143 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4144 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4145 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4146 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4147 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4148 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4149 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4150 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4152 if (lpUrlComponents
->lpszScheme
)
4154 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4155 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4156 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4157 -1, urlCompW
->lpszScheme
, len
);
4160 if (lpUrlComponents
->lpszHostName
)
4162 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4163 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4164 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4165 -1, urlCompW
->lpszHostName
, len
);
4168 if (lpUrlComponents
->lpszUserName
)
4170 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4171 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4172 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4173 -1, urlCompW
->lpszUserName
, len
);
4176 if (lpUrlComponents
->lpszPassword
)
4178 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4179 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4180 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4181 -1, urlCompW
->lpszPassword
, len
);
4184 if (lpUrlComponents
->lpszUrlPath
)
4186 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4187 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4188 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4189 -1, urlCompW
->lpszUrlPath
, len
);
4192 if (lpUrlComponents
->lpszExtraInfo
)
4194 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4195 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4196 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4197 -1, urlCompW
->lpszExtraInfo
, len
);
4201 /***********************************************************************
4202 * InternetCreateUrlA (WININET.@)
4204 * See InternetCreateUrlW.
4206 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4207 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4211 URL_COMPONENTSW urlCompW
;
4213 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4215 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4217 SetLastError(ERROR_INVALID_PARAMETER
);
4221 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4224 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4226 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4228 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4229 *lpdwUrlLength
/= sizeof(WCHAR
);
4231 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4232 * minus one, so add one to leave room for NULL terminator
4235 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4237 heap_free(urlCompW
.lpszScheme
);
4238 heap_free(urlCompW
.lpszHostName
);
4239 heap_free(urlCompW
.lpszUserName
);
4240 heap_free(urlCompW
.lpszPassword
);
4241 heap_free(urlCompW
.lpszUrlPath
);
4242 heap_free(urlCompW
.lpszExtraInfo
);
4247 /***********************************************************************
4248 * InternetCreateUrlW (WININET.@)
4250 * Creates a URL from its component parts.
4253 * lpUrlComponents [I] URL Components.
4254 * dwFlags [I] Flags. See notes.
4255 * lpszUrl [I] Buffer in which to store the created URL.
4256 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4257 * lpszUrl in characters. On output, the number of bytes
4258 * required to store the URL including terminator.
4262 * The dwFlags parameter can be zero or more of the following:
4263 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4270 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4271 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4274 INTERNET_SCHEME nScheme
;
4276 static const WCHAR slashSlashW
[] = {'/','/'};
4277 static const WCHAR fmtW
[] = {'%','u',0};
4279 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4281 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4283 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4287 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4290 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4292 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4293 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4297 *lpdwUrlLength
= dwLen
;
4302 if (lpUrlComponents
->lpszScheme
)
4304 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4305 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4308 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4313 nScheme
= lpUrlComponents
->nScheme
;
4315 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4316 nScheme
= INTERNET_SCHEME_HTTP
;
4318 scheme
= INTERNET_GetSchemeString(nScheme
);
4319 dwLen
= strlenW(scheme
);
4320 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4324 /* all schemes are followed by at least a colon */
4328 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4330 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4331 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4334 if (lpUrlComponents
->lpszUserName
)
4336 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4337 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4340 if (lpUrlComponents
->lpszPassword
)
4345 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4346 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4354 if (lpUrlComponents
->lpszHostName
)
4356 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4357 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4360 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4364 lpszUrl
+= sprintfW(lpszUrl
, fmtW
, lpUrlComponents
->nPort
);
4367 /* add slash between hostname and path if necessary */
4368 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4375 if (lpUrlComponents
->lpszUrlPath
)
4377 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4378 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4382 if (lpUrlComponents
->lpszExtraInfo
)
4384 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4385 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4394 /***********************************************************************
4395 * InternetConfirmZoneCrossingA (WININET.@)
4398 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4400 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4401 return ERROR_SUCCESS
;
4404 /***********************************************************************
4405 * InternetConfirmZoneCrossingW (WININET.@)
4408 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4410 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4411 return ERROR_SUCCESS
;
4414 static DWORD zone_preference
= 3;
4416 /***********************************************************************
4417 * PrivacySetZonePreferenceW (WININET.@)
4419 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4421 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4423 zone_preference
= template;
4427 /***********************************************************************
4428 * PrivacyGetZonePreferenceW (WININET.@)
4430 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4431 LPWSTR preference
, LPDWORD length
)
4433 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4435 if (template) *template = zone_preference
;
4439 /***********************************************************************
4440 * InternetGetSecurityInfoByURLA (WININET.@)
4442 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4447 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4449 url
= heap_strdupAtoW(lpszURL
);
4453 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4458 /***********************************************************************
4459 * InternetGetSecurityInfoByURLW (WININET.@)
4461 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4463 URL_COMPONENTSW url
= {sizeof(url
)};
4467 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4469 if (!ppCertChain
&& !pdwSecureFlags
) {
4470 SetLastError(ERROR_INVALID_PARAMETER
);
4474 url
.dwHostNameLength
= 1;
4475 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4476 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4477 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4481 server
= get_server(substr(url
.lpszHostName
, url
.dwHostNameLength
), url
.nPort
, TRUE
, FALSE
);
4483 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4487 if(server
->cert_chain
) {
4489 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4491 if(ppCertChain
&& !(*ppCertChain
= CertDuplicateCertificateChain(server
->cert_chain
)))
4494 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4498 server_release(server
);
4502 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4503 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4505 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4506 lpdwConnection
, dwReserved
);
4507 return ERROR_SUCCESS
;
4510 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4511 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4513 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4514 lpdwConnection
, dwReserved
);
4515 return ERROR_SUCCESS
;
4518 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4520 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4524 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4526 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4530 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4532 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4533 return ERROR_SUCCESS
;
4536 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4539 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4540 debugstr_w(pwszTarget
), pbHexHash
);
4544 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4546 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4550 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4552 FIXME("(%p, %08lx) stub\n", a
, b
);
4556 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4558 FIXME("%p: stub\n", parent
);