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
46 #include "wine/debug.h"
48 #define NO_SHLWAPI_STREAM
55 #include "wine/exception.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
65 CHAR response
[MAX_REPLY_LEN
];
66 } WITHREADERROR
, *LPWITHREADERROR
;
68 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
69 HMODULE WININET_hModule
;
71 static CRITICAL_SECTION WININET_cs
;
72 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
75 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
76 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
78 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
80 static object_header_t
**handle_table
;
81 static UINT_PTR next_handle
;
82 static UINT_PTR handle_table_size
;
93 static ULONG max_conns
= 2, max_1_0_conns
= 4;
94 static ULONG connect_timeout
= 60000;
96 static const WCHAR szInternetSettings
[] =
97 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
99 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
101 UINT_PTR handle
= 0, num
;
102 object_header_t
*ret
;
106 ret
= heap_alloc_zero(size
);
110 list_init(&ret
->children
);
112 EnterCriticalSection( &WININET_cs
);
114 if(!handle_table_size
) {
116 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
119 handle_table_size
= num
;
124 }else if(next_handle
== handle_table_size
) {
125 num
= handle_table_size
* 2;
126 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
129 handle_table_size
= num
;
136 handle
= next_handle
;
137 if(handle_table
[handle
])
138 ERR("handle isn't free but should be\n");
139 handle_table
[handle
] = ret
;
140 ret
->valid_handle
= TRUE
;
142 while(next_handle
< handle_table_size
&& handle_table
[next_handle
])
146 LeaveCriticalSection( &WININET_cs
);
155 ret
->hInternet
= (HINTERNET
)handle
;
158 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
159 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
165 object_header_t
*WININET_AddRef( object_header_t
*info
)
167 ULONG refs
= InterlockedIncrement(&info
->refs
);
168 TRACE("%p -> refcount = %d\n", info
, refs
);
172 object_header_t
*get_handle_object( HINTERNET hinternet
)
174 object_header_t
*info
= NULL
;
175 UINT_PTR handle
= (UINT_PTR
) hinternet
;
177 EnterCriticalSection( &WININET_cs
);
179 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
180 info
= WININET_AddRef(handle_table
[handle
]);
182 LeaveCriticalSection( &WININET_cs
);
184 TRACE("handle %ld -> %p\n", handle
, info
);
189 static void invalidate_handle(object_header_t
*info
)
191 object_header_t
*child
, *next
;
193 if(!info
->valid_handle
)
195 info
->valid_handle
= FALSE
;
197 /* Free all children as native does */
198 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
200 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
201 invalidate_handle( child
);
204 WININET_Release(info
);
207 BOOL
WININET_Release( object_header_t
*info
)
209 ULONG refs
= InterlockedDecrement(&info
->refs
);
210 TRACE( "object %p refcount = %d\n", info
, refs
);
213 invalidate_handle(info
);
214 if ( info
->vtbl
->CloseConnection
)
216 TRACE( "closing connection %p\n", info
);
217 info
->vtbl
->CloseConnection( info
);
219 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
220 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
221 || !(info
->dwInternalFlags
& INET_OPENURL
))
223 INTERNET_SendCallback(info
, info
->dwContext
,
224 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
227 TRACE( "destroying object %p\n", info
);
228 if ( info
->htype
!= WH_HINIT
)
229 list_remove( &info
->entry
);
230 info
->vtbl
->Destroy( info
);
232 if(info
->hInternet
) {
233 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
235 EnterCriticalSection( &WININET_cs
);
237 handle_table
[handle
] = NULL
;
238 if(next_handle
> handle
)
239 next_handle
= handle
;
241 LeaveCriticalSection( &WININET_cs
);
249 /***********************************************************************
250 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
253 * hinstDLL [I] handle to the DLL's instance
255 * lpvReserved [I] reserved, must be NULL
262 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
264 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
267 case DLL_PROCESS_ATTACH
:
269 g_dwTlsErrIndex
= TlsAlloc();
271 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
276 TlsFree(g_dwTlsErrIndex
);
280 WININET_hModule
= hinstDLL
;
283 case DLL_THREAD_ATTACH
:
286 case DLL_THREAD_DETACH
:
287 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
289 heap_free(TlsGetValue(g_dwTlsErrIndex
));
293 case DLL_PROCESS_DETACH
:
294 if (lpvReserved
) break;
295 collect_connections(COLLECT_CLEANUP
);
300 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
302 heap_free(TlsGetValue(g_dwTlsErrIndex
));
303 TlsFree(g_dwTlsErrIndex
);
310 /***********************************************************************
311 * DllInstall (WININET.@)
313 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
315 FIXME("(%x %s): stub\n", bInstall
, debugstr_w(cmdline
));
319 /***********************************************************************
320 * INTERNET_SaveProxySettings
322 * Stores the proxy settings given by lpwai into the registry
325 * ERROR_SUCCESS if no error, or error code on fail
327 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
332 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
335 if ((ret
= RegSetValueExW( key
, L
"ProxyEnable", 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
343 if ((ret
= RegSetValueExW( key
, L
"ProxyServer", 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
351 if ((ret
= RegDeleteValueW( key
, L
"ProxyServer" )) && ret
!= ERROR_FILE_NOT_FOUND
)
359 return ERROR_SUCCESS
;
362 /***********************************************************************
363 * INTERNET_FindProxyForProtocol
365 * Searches the proxy string for a proxy of the given protocol.
366 * Returns the found proxy, or the default proxy if none of the given
370 * szProxy [In] proxy string to search
371 * proto [In] protocol to search for, e.g. "http"
372 * foundProxy [Out] found proxy
373 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
376 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
377 * *foundProxyLen is set to the required size in WCHARs, including the
378 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
380 WCHAR
*INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
)
385 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
387 /* First, look for the specified protocol (proto=scheme://host:port) */
388 for (ptr
= szProxy
; ptr
&& *ptr
; )
392 if (!(end
= wcschr(ptr
, ' ')))
393 end
= ptr
+ lstrlenW(ptr
);
394 if ((equal
= wcschr(ptr
, '=')) && equal
< end
&&
395 equal
- ptr
== lstrlenW(proto
) &&
396 !wcsnicmp(proto
, ptr
, lstrlenW(proto
)))
398 ret
= heap_strndupW(equal
+ 1, end
- equal
- 1);
399 TRACE("found proxy for %s: %s\n", debugstr_w(proto
), debugstr_w(ret
));
408 /* It wasn't found: look for no protocol */
409 for (ptr
= szProxy
; ptr
&& *ptr
; )
413 if (!(end
= wcschr(ptr
, ' ')))
414 end
= ptr
+ lstrlenW(ptr
);
415 if (!wcschr(ptr
, '='))
417 ret
= heap_strndupW(ptr
, end
- ptr
);
418 TRACE("found proxy for %s: %s\n", debugstr_w(proto
), debugstr_w(ret
));
430 /***********************************************************************
431 * InternetInitializeAutoProxyDll (WININET.@)
433 * Setup the internal proxy
442 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
445 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
449 /***********************************************************************
450 * DetectAutoProxyUrl (WININET.@)
452 * Auto detect the proxy url
458 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
459 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
462 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
466 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
468 heap_free(lpwpi
->proxy
);
469 heap_free(lpwpi
->proxyBypass
);
470 heap_free(lpwpi
->proxyUsername
);
471 heap_free(lpwpi
->proxyPassword
);
474 static proxyinfo_t
*global_proxy
;
476 static void free_global_proxy( void )
478 EnterCriticalSection( &WININET_cs
);
481 FreeProxyInfo( global_proxy
);
482 heap_free( global_proxy
);
484 LeaveCriticalSection( &WININET_cs
);
487 static BOOL
parse_proxy_url( proxyinfo_t
*info
, const WCHAR
*url
)
489 URL_COMPONENTSW uc
= {sizeof(uc
)};
491 uc
.dwHostNameLength
= 1;
492 uc
.dwUserNameLength
= 1;
493 uc
.dwPasswordLength
= 1;
495 if (!InternetCrackUrlW( url
, 0, 0, &uc
)) return FALSE
;
496 if (!uc
.dwHostNameLength
)
498 if (!(info
->proxy
= heap_strdupW( url
))) return FALSE
;
499 info
->proxyUsername
= NULL
;
500 info
->proxyPassword
= NULL
;
503 if (!(info
->proxy
= heap_alloc( (uc
.dwHostNameLength
+ 12) * sizeof(WCHAR
) ))) return FALSE
;
504 swprintf( info
->proxy
, uc
.dwHostNameLength
+ 12, L
"%.*s:%u", uc
.dwHostNameLength
, uc
.lpszHostName
, uc
.nPort
);
506 if (!uc
.dwUserNameLength
) info
->proxyUsername
= NULL
;
507 else if (!(info
->proxyUsername
= heap_strndupW( uc
.lpszUserName
, uc
.dwUserNameLength
)))
509 heap_free( info
->proxy
);
512 if (!uc
.dwPasswordLength
) info
->proxyPassword
= NULL
;
513 else if (!(info
->proxyPassword
= heap_strndupW( uc
.lpszPassword
, uc
.dwPasswordLength
)))
515 heap_free( info
->proxyUsername
);
516 heap_free( info
->proxy
);
522 /***********************************************************************
523 * INTERNET_LoadProxySettings
525 * Loads proxy information from process-wide global settings, the registry,
526 * or the environment into lpwpi.
528 * The caller should call FreeProxyInfo when done with lpwpi.
531 * The proxy may be specified in the form 'http=proxy.my.org'
532 * Presumably that means there can be ftp=ftpproxy.my.org too.
534 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
538 const WCHAR
*envproxy
;
541 memset( lpwpi
, 0, sizeof(*lpwpi
) );
543 EnterCriticalSection( &WININET_cs
);
546 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
547 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
548 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
550 LeaveCriticalSection( &WININET_cs
);
552 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
554 FreeProxyInfo( lpwpi
);
559 if (RegQueryValueExW( key
, L
"ProxyEnable", NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
561 lpwpi
->proxyEnabled
= 0;
562 if((ret
= RegSetValueExW( key
, L
"ProxyEnable", 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
564 FreeProxyInfo( lpwpi
);
570 if (!(envproxy
= _wgetenv( L
"http_proxy" )) || lpwpi
->proxyEnabled
)
572 /* figure out how much memory the proxy setting takes */
573 if (!RegQueryValueExW( key
, L
"ProxyServer", NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
577 if (!(szProxy
= heap_alloc(len
)))
580 FreeProxyInfo( lpwpi
);
581 return ERROR_OUTOFMEMORY
;
583 RegQueryValueExW( key
, L
"ProxyServer", NULL
, &type
, (BYTE
*)szProxy
, &len
);
585 /* find the http proxy, and strip away everything else */
586 p
= wcsstr( szProxy
, L
"http=" );
589 p
+= lstrlenW( L
"http=" );
590 lstrcpyW( szProxy
, p
);
592 p
= wcschr( szProxy
, ';' );
595 FreeProxyInfo( lpwpi
);
596 lpwpi
->proxy
= szProxy
;
597 lpwpi
->proxyBypass
= NULL
;
599 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi
->proxy
));
603 TRACE("No proxy server settings in registry.\n");
604 FreeProxyInfo( lpwpi
);
606 lpwpi
->proxyBypass
= NULL
;
611 FreeProxyInfo( lpwpi
);
612 if (parse_proxy_url( lpwpi
, envproxy
))
614 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
615 lpwpi
->proxyEnabled
= 1;
616 lpwpi
->proxyBypass
= NULL
;
620 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxy
));
621 lpwpi
->proxyEnabled
= 0;
623 lpwpi
->proxyBypass
= NULL
;
627 if (lpwpi
->proxyEnabled
)
629 TRACE("Proxy is enabled.\n");
631 if (!(envproxy
= _wgetenv( L
"no_proxy" )))
633 /* figure out how much memory the proxy setting takes */
634 if (!RegQueryValueExW( key
, L
"ProxyOverride", NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
638 if (!(szProxy
= heap_alloc(len
)))
641 return ERROR_OUTOFMEMORY
;
643 RegQueryValueExW( key
, L
"ProxyOverride", NULL
, &type
, (BYTE
*)szProxy
, &len
);
645 heap_free( lpwpi
->proxyBypass
);
646 lpwpi
->proxyBypass
= szProxy
;
648 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
652 heap_free( lpwpi
->proxyBypass
);
653 lpwpi
->proxyBypass
= NULL
;
655 TRACE("No proxy bypass server settings in registry.\n");
662 if (!(envproxyW
= heap_alloc(lstrlenW(envproxy
) * sizeof(WCHAR
))))
665 return ERROR_OUTOFMEMORY
;
667 lstrcpyW( envproxyW
, envproxy
);
669 heap_free( lpwpi
->proxyBypass
);
670 lpwpi
->proxyBypass
= envproxyW
;
672 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
675 else TRACE("Proxy is disabled.\n");
678 return ERROR_SUCCESS
;
681 /***********************************************************************
682 * INTERNET_ConfigureProxy
684 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
688 if (INTERNET_LoadProxySettings( &wpi
))
691 if (wpi
.proxyEnabled
)
693 TRACE("http proxy = %s bypass = %s\n", debugstr_w(wpi
.proxy
), debugstr_w(wpi
.proxyBypass
));
695 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
696 lpwai
->proxy
= wpi
.proxy
;
697 lpwai
->proxyBypass
= wpi
.proxyBypass
;
698 lpwai
->proxyUsername
= wpi
.proxyUsername
;
699 lpwai
->proxyPassword
= wpi
.proxyPassword
;
703 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
708 /***********************************************************************
709 * dump_INTERNET_FLAGS
711 * Helper function to TRACE the internet flags.
717 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
719 #define FE(x) { x, #x }
720 static const wininet_flag_info flag
[] = {
721 FE(INTERNET_FLAG_RELOAD
),
722 FE(INTERNET_FLAG_RAW_DATA
),
723 FE(INTERNET_FLAG_EXISTING_CONNECT
),
724 FE(INTERNET_FLAG_ASYNC
),
725 FE(INTERNET_FLAG_PASSIVE
),
726 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
727 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
728 FE(INTERNET_FLAG_FROM_CACHE
),
729 FE(INTERNET_FLAG_SECURE
),
730 FE(INTERNET_FLAG_KEEP_CONNECTION
),
731 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
732 FE(INTERNET_FLAG_READ_PREFETCH
),
733 FE(INTERNET_FLAG_NO_COOKIES
),
734 FE(INTERNET_FLAG_NO_AUTH
),
735 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
736 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
737 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
738 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
739 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
740 FE(INTERNET_FLAG_RESYNCHRONIZE
),
741 FE(INTERNET_FLAG_HYPERLINK
),
742 FE(INTERNET_FLAG_NO_UI
),
743 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
744 FE(INTERNET_FLAG_CACHE_ASYNC
),
745 FE(INTERNET_FLAG_FORMS_SUBMIT
),
746 FE(INTERNET_FLAG_NEED_FILE
),
747 FE(INTERNET_FLAG_TRANSFER_ASCII
),
748 FE(INTERNET_FLAG_TRANSFER_BINARY
)
753 for (i
= 0; i
< ARRAY_SIZE(flag
); i
++) {
754 if (flag
[i
].val
& dwFlags
) {
755 TRACE(" %s", flag
[i
].name
);
756 dwFlags
&= ~flag
[i
].val
;
760 TRACE(" Unknown flags (%08x)\n", dwFlags
);
765 /***********************************************************************
766 * INTERNET_CloseHandle (internal)
768 * Close internet handle
771 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
773 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
777 heap_free(lpwai
->agent
);
778 heap_free(lpwai
->proxy
);
779 heap_free(lpwai
->proxyBypass
);
780 heap_free(lpwai
->proxyUsername
);
781 heap_free(lpwai
->proxyPassword
);
784 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
786 appinfo_t
*ai
= (appinfo_t
*)hdr
;
789 case INTERNET_OPTION_HANDLE_TYPE
:
790 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
792 if (*size
< sizeof(ULONG
))
793 return ERROR_INSUFFICIENT_BUFFER
;
795 *size
= sizeof(DWORD
);
796 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
797 return ERROR_SUCCESS
;
799 case INTERNET_OPTION_USER_AGENT
: {
802 TRACE("INTERNET_OPTION_USER_AGENT\n");
807 DWORD len
= ai
->agent
? lstrlenW(ai
->agent
) : 0;
809 *size
= (len
+ 1) * sizeof(WCHAR
);
810 if(!buffer
|| bufsize
< *size
)
811 return ERROR_INSUFFICIENT_BUFFER
;
814 lstrcpyW(buffer
, ai
->agent
);
816 *(WCHAR
*)buffer
= 0;
817 /* If the buffer is copied, the returned length doesn't include
818 * the NULL terminator.
823 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
826 if(!buffer
|| bufsize
< *size
)
827 return ERROR_INSUFFICIENT_BUFFER
;
830 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
833 /* If the buffer is copied, the returned length doesn't include
834 * the NULL terminator.
839 return ERROR_SUCCESS
;
842 case INTERNET_OPTION_PROXY
:
843 if(!size
) return ERROR_INVALID_PARAMETER
;
845 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
846 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
847 LPWSTR proxy
, proxy_bypass
;
850 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
852 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
853 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
855 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
856 return ERROR_INSUFFICIENT_BUFFER
;
858 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
859 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
861 pi
->dwAccessType
= ai
->accessType
;
862 pi
->lpszProxy
= NULL
;
863 pi
->lpszProxyBypass
= NULL
;
865 lstrcpyW(proxy
, ai
->proxy
);
866 pi
->lpszProxy
= proxy
;
869 if (ai
->proxyBypass
) {
870 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
871 pi
->lpszProxyBypass
= proxy_bypass
;
874 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
875 return ERROR_SUCCESS
;
877 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
878 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
879 LPSTR proxy
, proxy_bypass
;
882 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
884 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
885 NULL
, 0, NULL
, NULL
);
886 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
888 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
889 return ERROR_INSUFFICIENT_BUFFER
;
891 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
892 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
894 pi
->dwAccessType
= ai
->accessType
;
895 pi
->lpszProxy
= NULL
;
896 pi
->lpszProxyBypass
= NULL
;
898 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
899 pi
->lpszProxy
= proxy
;
902 if (ai
->proxyBypass
) {
903 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
904 proxyBypassBytesRequired
, NULL
, NULL
);
905 pi
->lpszProxyBypass
= proxy_bypass
;
908 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
909 return ERROR_SUCCESS
;
912 case INTERNET_OPTION_CONNECT_TIMEOUT
:
913 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
915 if (*size
< sizeof(ULONG
))
916 return ERROR_INSUFFICIENT_BUFFER
;
918 *(ULONG
*)buffer
= ai
->connect_timeout
;
919 *size
= sizeof(ULONG
);
921 return ERROR_SUCCESS
;
924 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
927 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
929 appinfo_t
*ai
= (appinfo_t
*)hdr
;
932 case INTERNET_OPTION_CONNECT_TIMEOUT
:
933 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
935 if(size
!= sizeof(connect_timeout
))
936 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
938 return ERROR_BAD_ARGUMENTS
;
940 ai
->connect_timeout
= *(ULONG
*)buf
;
941 return ERROR_SUCCESS
;
942 case INTERNET_OPTION_USER_AGENT
:
943 heap_free(ai
->agent
);
944 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
945 return ERROR_SUCCESS
;
946 case INTERNET_OPTION_REFRESH
:
947 FIXME("INTERNET_OPTION_REFRESH\n");
948 return ERROR_SUCCESS
;
951 return INET_SetOption(hdr
, option
, buf
, size
);
954 static const object_vtbl_t APPINFOVtbl
= {
965 /***********************************************************************
966 * InternetOpenW (WININET.@)
968 * Per-application initialization of wininet
971 * HINTERNET on success
975 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
976 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
978 appinfo_t
*lpwai
= NULL
;
980 if (TRACE_ON(wininet
)) {
981 #define FE(x) { x, #x }
982 static const wininet_flag_info access_type
[] = {
983 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
984 FE(INTERNET_OPEN_TYPE_DIRECT
),
985 FE(INTERNET_OPEN_TYPE_PROXY
),
986 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
990 const char *access_type_str
= "Unknown";
992 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
993 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
994 for (i
= 0; i
< ARRAY_SIZE(access_type
); i
++) {
995 if (access_type
[i
].val
== dwAccessType
) {
996 access_type_str
= access_type
[i
].name
;
1000 TRACE(" access type : %s\n", access_type_str
);
1002 dump_INTERNET_FLAGS(dwFlags
);
1005 /* Clear any error information */
1006 INTERNET_SetLastError(0);
1008 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1009 SetLastError(ERROR_INVALID_PARAMETER
);
1013 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1015 SetLastError(ERROR_OUTOFMEMORY
);
1019 lpwai
->hdr
.htype
= WH_HINIT
;
1020 lpwai
->hdr
.dwFlags
= dwFlags
;
1021 lpwai
->accessType
= dwAccessType
;
1022 lpwai
->proxyUsername
= NULL
;
1023 lpwai
->proxyPassword
= NULL
;
1024 lpwai
->connect_timeout
= connect_timeout
;
1026 lpwai
->agent
= heap_strdupW(lpszAgent
);
1027 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1028 INTERNET_ConfigureProxy( lpwai
);
1029 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1030 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1031 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1034 TRACE("returning %p\n", lpwai
);
1036 return lpwai
->hdr
.hInternet
;
1040 /***********************************************************************
1041 * InternetOpenA (WININET.@)
1043 * Per-application initialization of wininet
1046 * HINTERNET on success
1050 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1051 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1053 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1056 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1057 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1059 szAgent
= heap_strdupAtoW(lpszAgent
);
1060 szProxy
= heap_strdupAtoW(lpszProxy
);
1061 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1063 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1067 heap_free(szBypass
);
1071 /***********************************************************************
1072 * InternetGetLastResponseInfoA (WININET.@)
1074 * Return last wininet error description on the calling thread
1077 * TRUE on success of writing to buffer
1081 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1082 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1084 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1090 *lpdwError
= lpwite
->dwError
;
1091 if (lpwite
->dwError
)
1093 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1094 *lpdwBufferLength
= strlen(lpszBuffer
);
1097 *lpdwBufferLength
= 0;
1102 *lpdwBufferLength
= 0;
1108 /***********************************************************************
1109 * InternetGetLastResponseInfoW (WININET.@)
1111 * Return last wininet error description on the calling thread
1114 * TRUE on success of writing to buffer
1118 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1119 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1121 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1127 *lpdwError
= lpwite
->dwError
;
1128 if (lpwite
->dwError
)
1130 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1131 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1134 *lpdwBufferLength
= 0;
1139 *lpdwBufferLength
= 0;
1145 /***********************************************************************
1146 * InternetGetConnectedState (WININET.@)
1148 * Return connected state
1152 * if lpdwStatus is not null, return the status (off line,
1153 * modem, lan...) in it.
1154 * FALSE if not connected
1156 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1158 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1160 return InternetGetConnectedStateExW(lpdwStatus
, NULL
, 0, dwReserved
);
1164 /***********************************************************************
1165 * InternetGetConnectedStateExW (WININET.@)
1167 * Return connected state
1171 * lpdwStatus [O] Flags specifying the status of the internet connection.
1172 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1173 * dwNameLen [I] Size of the buffer, in characters.
1174 * dwReserved [I] Reserved. Must be set to 0.
1178 * if lpdwStatus is not null, return the status (off line,
1179 * modem, lan...) in it.
1180 * FALSE if not connected
1183 * If the system has no available network connections, an empty string is
1184 * stored in lpszConnectionName. If there is a LAN connection, a localized
1185 * "LAN Connection" string is stored. Presumably, if only a dial-up
1186 * connection is available then the name of the dial-up connection is
1187 * returned. Why any application, other than the "Internet Settings" CPL,
1188 * would want to use this function instead of the simpler InternetGetConnectedStateW
1189 * function is beyond me.
1191 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1192 DWORD dwNameLen
, DWORD dwReserved
)
1194 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1201 WARN("always returning LAN connection.\n");
1202 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1205 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1206 * the resource, avoid it as we must not change the buffer in this case */
1207 if(lpszConnectionName
&& dwNameLen
) {
1208 *lpszConnectionName
= '\0';
1209 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1216 /***********************************************************************
1217 * InternetGetConnectedStateExA (WININET.@)
1219 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1220 DWORD dwNameLen
, DWORD dwReserved
)
1222 LPWSTR lpwszConnectionName
= NULL
;
1225 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1227 if (lpszConnectionName
&& dwNameLen
> 0)
1228 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1230 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1232 if (rc
&& lpwszConnectionName
)
1233 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1234 dwNameLen
, NULL
, NULL
);
1236 heap_free(lpwszConnectionName
);
1241 /***********************************************************************
1242 * InternetConnectW (WININET.@)
1244 * Open a ftp, gopher or http session
1247 * HINTERNET a session handle on success
1251 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1252 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1253 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1254 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1257 HINTERNET rc
= NULL
;
1258 DWORD res
= ERROR_SUCCESS
;
1260 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1261 nServerPort
, debugstr_w(lpszUserName
), lpszPassword
, dwService
, dwFlags
, dwContext
);
1263 if (!lpszServerName
)
1265 SetLastError(ERROR_INVALID_PARAMETER
);
1269 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1270 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1272 res
= ERROR_INVALID_HANDLE
;
1278 case INTERNET_SERVICE_FTP
:
1279 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1280 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1282 res
= INTERNET_GetLastError();
1285 case INTERNET_SERVICE_HTTP
:
1286 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1287 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1290 case INTERNET_SERVICE_GOPHER
:
1296 WININET_Release( &hIC
->hdr
);
1298 TRACE("returning %p\n", rc
);
1304 /***********************************************************************
1305 * InternetConnectA (WININET.@)
1307 * Open a ftp, gopher or http session
1310 * HINTERNET a session handle on success
1314 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1315 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1316 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1317 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1319 HINTERNET rc
= NULL
;
1320 LPWSTR szServerName
;
1324 szServerName
= heap_strdupAtoW(lpszServerName
);
1325 szUserName
= heap_strdupAtoW(lpszUserName
);
1326 szPassword
= heap_strdupAtoW(lpszPassword
);
1328 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1329 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1331 heap_free(szServerName
);
1332 heap_free(szUserName
);
1333 heap_free(szPassword
);
1338 /***********************************************************************
1339 * InternetFindNextFileA (WININET.@)
1341 * Continues a file search from a previous call to FindFirstFile
1348 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1351 WIN32_FIND_DATAW fd
;
1353 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1355 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1359 /***********************************************************************
1360 * InternetFindNextFileW (WININET.@)
1362 * Continues a file search from a previous call to FindFirstFile
1369 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1371 object_header_t
*hdr
;
1376 hdr
= get_handle_object(hFind
);
1378 WARN("Invalid handle\n");
1379 SetLastError(ERROR_INVALID_HANDLE
);
1383 if(hdr
->vtbl
->FindNextFileW
) {
1384 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1386 WARN("Handle doesn't support NextFile\n");
1387 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1390 WININET_Release(hdr
);
1392 if(res
!= ERROR_SUCCESS
)
1394 return res
== ERROR_SUCCESS
;
1397 /***********************************************************************
1398 * InternetCloseHandle (WININET.@)
1400 * Generic close handle function
1407 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1409 object_header_t
*obj
;
1411 TRACE("%p\n", hInternet
);
1413 obj
= get_handle_object( hInternet
);
1415 SetLastError(ERROR_INVALID_HANDLE
);
1419 invalidate_handle(obj
);
1420 WININET_Release(obj
);
1425 static BOOL
set_url_component(WCHAR
**component
, DWORD
*component_length
, const WCHAR
*value
, DWORD len
)
1427 TRACE("%s (%d)\n", debugstr_wn(value
, len
), len
);
1429 if (!*component_length
)
1433 *(const WCHAR
**)component
= value
;
1434 *component_length
= len
;
1438 if (*component_length
< len
+1) {
1439 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1443 *component_length
= len
;
1445 memcpy(*component
, value
, len
*sizeof(WCHAR
));
1446 (*component
)[len
] = 0;
1450 static BOOL
set_url_component_WtoA(const WCHAR
*comp_w
, DWORD length
, const WCHAR
*url_w
, char **comp
, DWORD
*ret_length
,
1453 size_t size
, ret_size
= *ret_length
;
1457 size
= WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, NULL
, 0, NULL
, NULL
);
1460 *comp
= comp_w
? (char*)url_a
+ WideCharToMultiByte(CP_ACP
, 0, url_w
, comp_w
-url_w
, NULL
, 0, NULL
, NULL
) : NULL
;
1465 if (size
+1 > ret_size
) {
1466 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1467 *ret_length
= size
+1;
1472 WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, *comp
, ret_size
-1, NULL
, NULL
);
1477 static BOOL
set_url_component_AtoW(const char *comp_a
, DWORD len_a
, WCHAR
**comp_w
, DWORD
*len_w
, WCHAR
**buf
)
1486 if(!(*comp_w
= *buf
= heap_alloc(len_a
*sizeof(WCHAR
)))) {
1487 SetLastError(ERROR_OUTOFMEMORY
);
1494 /***********************************************************************
1495 * InternetCrackUrlA (WININET.@)
1497 * See InternetCrackUrlW.
1499 BOOL WINAPI
InternetCrackUrlA(const char *url
, DWORD url_length
, DWORD flags
, URL_COMPONENTSA
*ret_comp
)
1501 WCHAR
*host
= NULL
, *user
= NULL
, *pass
= NULL
, *path
= NULL
, *scheme
= NULL
, *extra
= NULL
;
1502 URL_COMPONENTSW comp
;
1503 WCHAR
*url_w
= NULL
;
1506 TRACE("(%s %u %x %p)\n", url_length
? debugstr_an(url
, url_length
) : debugstr_a(url
), url_length
, flags
, ret_comp
);
1508 if (!url
|| !*url
|| !ret_comp
|| ret_comp
->dwStructSize
!= sizeof(URL_COMPONENTSA
)) {
1509 SetLastError(ERROR_INVALID_PARAMETER
);
1513 comp
.dwStructSize
= sizeof(comp
);
1515 ret
= set_url_component_AtoW(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
,
1516 &comp
.lpszHostName
, &comp
.dwHostNameLength
, &host
)
1517 && set_url_component_AtoW(ret_comp
->lpszUserName
, ret_comp
->dwUserNameLength
,
1518 &comp
.lpszUserName
, &comp
.dwUserNameLength
, &user
)
1519 && set_url_component_AtoW(ret_comp
->lpszPassword
, ret_comp
->dwPasswordLength
,
1520 &comp
.lpszPassword
, &comp
.dwPasswordLength
, &pass
)
1521 && set_url_component_AtoW(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
,
1522 &comp
.lpszUrlPath
, &comp
.dwUrlPathLength
, &path
)
1523 && set_url_component_AtoW(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
,
1524 &comp
.lpszScheme
, &comp
.dwSchemeLength
, &scheme
)
1525 && set_url_component_AtoW(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
,
1526 &comp
.lpszExtraInfo
, &comp
.dwExtraInfoLength
, &extra
);
1528 if(ret
&& !(url_w
= heap_strndupAtoW(url
, url_length
? url_length
: -1, &url_length
))) {
1529 SetLastError(ERROR_OUTOFMEMORY
);
1533 if (ret
&& (ret
= InternetCrackUrlW(url_w
, url_length
, flags
, &comp
))) {
1534 ret_comp
->nScheme
= comp
.nScheme
;
1535 ret_comp
->nPort
= comp
.nPort
;
1537 ret
= set_url_component_WtoA(comp
.lpszHostName
, comp
.dwHostNameLength
, url_w
,
1538 &ret_comp
->lpszHostName
, &ret_comp
->dwHostNameLength
, url
)
1539 && set_url_component_WtoA(comp
.lpszUserName
, comp
.dwUserNameLength
, url_w
,
1540 &ret_comp
->lpszUserName
, &ret_comp
->dwUserNameLength
, url
)
1541 && set_url_component_WtoA(comp
.lpszPassword
, comp
.dwPasswordLength
, url_w
,
1542 &ret_comp
->lpszPassword
, &ret_comp
->dwPasswordLength
, url
)
1543 && set_url_component_WtoA(comp
.lpszUrlPath
, comp
.dwUrlPathLength
, url_w
,
1544 &ret_comp
->lpszUrlPath
, &ret_comp
->dwUrlPathLength
, url
)
1545 && set_url_component_WtoA(comp
.lpszScheme
, comp
.dwSchemeLength
, url_w
,
1546 &ret_comp
->lpszScheme
, &ret_comp
->dwSchemeLength
, url
)
1547 && set_url_component_WtoA(comp
.lpszExtraInfo
, comp
.dwExtraInfoLength
, url_w
,
1548 &ret_comp
->lpszExtraInfo
, &ret_comp
->dwExtraInfoLength
, url
);
1551 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url
),
1552 debugstr_an(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
),
1553 debugstr_an(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
),
1554 debugstr_an(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
),
1555 debugstr_an(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
));
1568 static const WCHAR
*url_schemes
[] =
1583 /***********************************************************************
1584 * GetInternetSchemeW (internal)
1590 * INTERNET_SCHEME_UNKNOWN on failure
1593 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1597 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1599 if(lpszScheme
==NULL
)
1600 return INTERNET_SCHEME_UNKNOWN
;
1602 for (i
= 0; i
< ARRAY_SIZE(url_schemes
); i
++)
1603 if (!wcsnicmp(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1604 return INTERNET_SCHEME_FIRST
+ i
;
1606 return INTERNET_SCHEME_UNKNOWN
;
1609 /***********************************************************************
1610 * InternetCrackUrlW (WININET.@)
1612 * Break up URL into its components
1618 BOOL WINAPI
InternetCrackUrlW(const WCHAR
*lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
, URL_COMPONENTSW
*lpUC
)
1622 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1625 LPCWSTR lpszParam
= NULL
;
1626 BOOL found_colon
= FALSE
;
1628 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1630 TRACE("(%s %u %x %p)\n",
1631 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: lstrlenW(lpszUrl
)) : "(null)",
1632 dwUrlLength
, dwFlags
, lpUC
);
1634 if (!lpszUrl
|| !*lpszUrl
|| !lpUC
)
1636 SetLastError(ERROR_INVALID_PARAMETER
);
1639 if (!dwUrlLength
) dwUrlLength
= lstrlenW(lpszUrl
);
1641 if (dwFlags
& ICU_DECODE
)
1643 WCHAR
*url_tmp
, *buffer
;
1644 DWORD len
= dwUrlLength
+ 1;
1647 if (!(url_tmp
= heap_strndupW(lpszUrl
, dwUrlLength
)))
1649 SetLastError(ERROR_OUTOFMEMORY
);
1654 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1655 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1657 buffer
= heap_alloc(len
* sizeof(WCHAR
));
1660 SetLastError(ERROR_OUTOFMEMORY
);
1664 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1667 ret
= InternetCrackUrlW(buffer
, len
, dwFlags
& ~ICU_DECODE
, lpUC
);
1669 if (buffer
!= url_tmp
) heap_free(buffer
);
1675 /* Determine if the URI is absolute. */
1676 while (lpszap
- lpszUrl
< dwUrlLength
)
1678 if (iswalnum(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1690 lpszcp
= lpszUrl
; /* Relative url */
1697 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1701 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1702 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1704 /* Parse <params> */
1705 lpszParam
= wmemchr(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1707 lpszParam
= wmemchr(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1709 if(!set_url_component(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1710 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0))
1714 /* Get scheme first. */
1715 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1716 if(!set_url_component(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, lpszUrl
, lpszcp
- lpszUrl
))
1719 /* Eat ':' in protocol. */
1722 /* double slash indicates the net_loc portion is present */
1723 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1727 lpszNetLoc
= wmemchr(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1731 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1733 lpszNetLoc
= lpszParam
;
1735 else if (!lpszNetLoc
)
1736 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1744 /* [<user>[<:password>]@]<host>[:<port>] */
1745 /* First find the user and password if they exist */
1747 lpszHost
= wmemchr(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1748 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1750 /* username and password not specified. */
1751 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1752 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1754 else /* Parse out username and password */
1756 LPCWSTR lpszUser
= lpszcp
;
1757 LPCWSTR lpszPasswd
= lpszHost
;
1759 while (lpszcp
< lpszHost
)
1762 lpszPasswd
= lpszcp
;
1767 if(!set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, lpszUser
, lpszPasswd
- lpszUser
))
1770 if (lpszPasswd
!= lpszHost
)
1772 if(!set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1773 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
, lpszHost
- lpszPasswd
))
1776 lpszcp
++; /* Advance to beginning of host */
1779 /* Parse <host><:port> */
1782 lpszPort
= lpszNetLoc
;
1784 /* special case for res:// URLs: there is no port here, so the host is the
1785 entire string up to the first '/' */
1786 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1788 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1794 while (lpszcp
< lpszNetLoc
)
1802 /* If the scheme is "file" and the host is just one letter, it's not a host */
1803 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1806 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1810 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1812 if (lpszPort
!= lpszNetLoc
)
1813 lpUC
->nPort
= wcstol(++lpszPort
, NULL
, 10);
1814 else switch (lpUC
->nScheme
)
1816 case INTERNET_SCHEME_HTTP
:
1817 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1819 case INTERNET_SCHEME_HTTPS
:
1820 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1822 case INTERNET_SCHEME_FTP
:
1823 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1834 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1835 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1836 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1839 /* Here lpszcp points to:
1841 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1842 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1844 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1848 /* Only truncate the parameter list if it's already been saved
1849 * in lpUC->lpszExtraInfo.
1851 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1852 len
= lpszParam
- lpszcp
;
1855 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1856 * newlines if necessary.
1858 LPWSTR lpsznewline
= wmemchr(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1859 if (lpsznewline
!= NULL
)
1860 len
= lpsznewline
- lpszcp
;
1862 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1864 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1865 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1867 WCHAR tmppath
[MAX_PATH
];
1871 PathCreateFromUrlW(lpszUrl
, tmppath
, &len
, 0);
1876 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1877 tmppath
[len
] = '\0';
1886 /* if ends in \. or \.. append a backslash */
1887 if (tmppath
[len
- 1] == '.' &&
1888 (tmppath
[len
- 2] == '\\' ||
1889 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1891 if (len
< MAX_PATH
- 1)
1893 tmppath
[len
] = '\\';
1894 tmppath
[len
+1] = '\0';
1898 if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, tmppath
, len
))
1901 else if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, len
))
1906 set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, 0);
1909 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1910 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1911 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1912 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1913 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1918 /***********************************************************************
1919 * InternetAttemptConnect (WININET.@)
1921 * Attempt to make a connection to the internet
1924 * ERROR_SUCCESS on success
1925 * Error value on failure
1928 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1931 return ERROR_SUCCESS
;
1935 /***********************************************************************
1936 * convert_url_canonicalization_flags
1938 * Helper for InternetCanonicalizeUrl
1941 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1944 * Flags suitable for UrlCanonicalize
1946 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1948 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1950 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1951 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1952 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1953 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1954 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1955 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1956 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1961 /***********************************************************************
1962 * InternetCanonicalizeUrlA (WININET.@)
1964 * Escape unsafe characters and spaces
1971 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1972 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1976 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1977 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1979 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
1980 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1981 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1982 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1987 /***********************************************************************
1988 * InternetCanonicalizeUrlW (WININET.@)
1990 * Escape unsafe characters and spaces
1997 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1998 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2002 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2003 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2005 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2006 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2007 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2008 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2013 /* #################################################### */
2015 static INTERNET_STATUS_CALLBACK
set_status_callback(
2016 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2018 INTERNET_STATUS_CALLBACK ret
;
2020 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2021 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2023 ret
= lpwh
->lpfnStatusCB
;
2024 lpwh
->lpfnStatusCB
= callback
;
2029 /***********************************************************************
2030 * InternetSetStatusCallbackA (WININET.@)
2032 * Sets up a callback function which is called as progress is made
2033 * during an operation.
2036 * Previous callback or NULL on success
2037 * INTERNET_INVALID_STATUS_CALLBACK on failure
2040 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2041 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2043 INTERNET_STATUS_CALLBACK retVal
;
2044 object_header_t
*lpwh
;
2046 TRACE("%p\n", hInternet
);
2048 if (!(lpwh
= get_handle_object(hInternet
)))
2049 return INTERNET_INVALID_STATUS_CALLBACK
;
2051 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2053 WININET_Release( lpwh
);
2057 /***********************************************************************
2058 * InternetSetStatusCallbackW (WININET.@)
2060 * Sets up a callback function which is called as progress is made
2061 * during an operation.
2064 * Previous callback or NULL on success
2065 * INTERNET_INVALID_STATUS_CALLBACK on failure
2068 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2069 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2071 INTERNET_STATUS_CALLBACK retVal
;
2072 object_header_t
*lpwh
;
2074 TRACE("%p\n", hInternet
);
2076 if (!(lpwh
= get_handle_object(hInternet
)))
2077 return INTERNET_INVALID_STATUS_CALLBACK
;
2079 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2081 WININET_Release( lpwh
);
2085 /***********************************************************************
2086 * InternetSetFilePointer (WININET.@)
2088 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2089 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2091 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2093 SetLastError(ERROR_INTERNET_INVALID_OPERATION
);
2094 return INVALID_SET_FILE_POINTER
;
2097 /***********************************************************************
2098 * InternetWriteFile (WININET.@)
2100 * Write data to an open internet file
2107 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2108 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2110 object_header_t
*lpwh
;
2113 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2115 lpwh
= get_handle_object( hFile
);
2117 WARN("Invalid handle\n");
2118 SetLastError(ERROR_INVALID_HANDLE
);
2122 if(lpwh
->vtbl
->WriteFile
) {
2123 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2125 WARN("No Writefile method.\n");
2126 res
= ERROR_INVALID_HANDLE
;
2129 WININET_Release( lpwh
);
2131 if(res
!= ERROR_SUCCESS
)
2133 return res
== ERROR_SUCCESS
;
2137 /***********************************************************************
2138 * InternetReadFile (WININET.@)
2140 * Read data from an open internet file
2147 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2148 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2150 object_header_t
*hdr
;
2151 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2153 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2155 hdr
= get_handle_object(hFile
);
2157 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2161 if(hdr
->vtbl
->ReadFile
) {
2162 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, 0, 0);
2163 if(res
== ERROR_IO_PENDING
)
2164 *pdwNumOfBytesRead
= 0;
2167 WININET_Release(hdr
);
2169 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2170 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2173 return res
== ERROR_SUCCESS
;
2176 /***********************************************************************
2177 * InternetReadFileExA (WININET.@)
2179 * Read data from an open internet file
2182 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2183 * lpBuffersOut [I/O] Buffer.
2184 * dwFlags [I] Flags. See notes.
2185 * dwContext [I] Context for callbacks.
2192 * The parameter dwFlags include zero or more of the following flags:
2193 *|IRF_ASYNC - Makes the call asynchronous.
2194 *|IRF_SYNC - Makes the call synchronous.
2195 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2196 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2198 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2201 * InternetOpenUrlA(), HttpOpenRequestA()
2203 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2204 DWORD dwFlags
, DWORD_PTR dwContext
)
2206 object_header_t
*hdr
;
2207 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2209 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2211 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2212 SetLastError(ERROR_INVALID_PARAMETER
);
2216 hdr
= get_handle_object(hFile
);
2218 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2222 if(hdr
->vtbl
->ReadFile
)
2223 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2224 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2226 WININET_Release(hdr
);
2228 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2229 res
, lpBuffersOut
->dwBufferLength
);
2231 if(res
!= ERROR_SUCCESS
)
2233 return res
== ERROR_SUCCESS
;
2236 /***********************************************************************
2237 * InternetReadFileExW (WININET.@)
2239 * InternetReadFileExA()
2241 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2242 DWORD dwFlags
, DWORD_PTR dwContext
)
2244 object_header_t
*hdr
;
2245 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2247 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2249 if (!lpBuffer
|| lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2250 SetLastError(ERROR_INVALID_PARAMETER
);
2254 hdr
= get_handle_object(hFile
);
2256 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2260 if(hdr
->vtbl
->ReadFile
)
2261 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2262 dwFlags
, dwContext
);
2264 WININET_Release(hdr
);
2266 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2267 res
, lpBuffer
->dwBufferLength
);
2269 if(res
!= ERROR_SUCCESS
)
2271 return res
== ERROR_SUCCESS
;
2274 static IP_ADAPTER_ADDRESSES
*get_adapters(void)
2276 ULONG err
, size
= 1024, flags
= GAA_FLAG_SKIP_ANYCAST
| GAA_FLAG_SKIP_MULTICAST
|
2277 GAA_FLAG_SKIP_DNS_SERVER
| GAA_FLAG_SKIP_FRIENDLY_NAME
;
2278 IP_ADAPTER_ADDRESSES
*tmp
, *ret
;
2280 if (!(ret
= heap_alloc( size
))) return NULL
;
2281 err
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, ret
, &size
);
2282 while (err
== ERROR_BUFFER_OVERFLOW
)
2284 if (!(tmp
= heap_realloc( ret
, size
))) break;
2286 err
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, ret
, &size
);
2288 if (err
== ERROR_SUCCESS
) return ret
;
2293 static WCHAR
*detect_proxy_autoconfig_url_dhcp(void)
2295 IP_ADAPTER_ADDRESSES
*adapters
, *ptr
;
2296 DHCPCAPI_PARAMS_ARRAY send_params
, recv_params
;
2297 DHCPCAPI_PARAMS param
;
2298 WCHAR name
[MAX_ADAPTER_NAME_LENGTH
+ 1], *ret
= NULL
;
2300 BYTE
*tmp
, *buf
= NULL
;
2302 if (!(adapters
= get_adapters())) return NULL
;
2304 memset( &send_params
, 0, sizeof(send_params
) );
2305 memset( ¶m
, 0, sizeof(param
) );
2306 param
.OptionId
= OPTION_MSFT_IE_PROXY
;
2307 recv_params
.nParams
= 1;
2308 recv_params
.Params
= ¶m
;
2310 for (ptr
= adapters
; ptr
; ptr
= ptr
->Next
)
2312 MultiByteToWideChar( CP_ACP
, 0, ptr
->AdapterName
, -1, name
, ARRAY_SIZE(name
) );
2313 TRACE( "adapter '%s' type %u dhcpv4 enabled %d\n", wine_dbgstr_w(name
), ptr
->IfType
, ptr
->Dhcpv4Enabled
);
2315 if (ptr
->IfType
== IF_TYPE_SOFTWARE_LOOPBACK
) continue;
2316 /* FIXME: also skip adapters where DHCP is disabled */
2319 if (!(buf
= heap_alloc( size
))) goto done
;
2320 err
= DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS
, NULL
, name
, NULL
, send_params
, recv_params
,
2322 while (err
== ERROR_MORE_DATA
)
2324 if (!(tmp
= heap_realloc( buf
, size
))) goto done
;
2326 err
= DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS
, NULL
, name
, NULL
, send_params
, recv_params
,
2329 if (err
== ERROR_SUCCESS
&& param
.nBytesData
)
2331 int len
= MultiByteToWideChar( CP_ACP
, 0, (const char *)param
.Data
, param
.nBytesData
, NULL
, 0 );
2332 if ((ret
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
2334 MultiByteToWideChar( CP_ACP
, 0, (const char *)param
.Data
, param
.nBytesData
, ret
, len
);
2337 TRACE("returning %s\n", debugstr_w(ret
));
2344 heap_free( adapters
);
2348 static char *get_computer_name( COMPUTER_NAME_FORMAT format
)
2353 GetComputerNameExA( format
, NULL
, &size
);
2354 if (GetLastError() != ERROR_MORE_DATA
) return NULL
;
2355 if (!(ret
= heap_alloc( size
))) return NULL
;
2356 if (!GetComputerNameExA( format
, ret
, &size
))
2364 static BOOL
is_domain_suffix( const char *domain
, const char *suffix
)
2366 int len_domain
= strlen( domain
), len_suffix
= strlen( suffix
);
2368 if (len_suffix
> len_domain
) return FALSE
;
2369 if (!stricmp( domain
+ len_domain
- len_suffix
, suffix
)) return TRUE
;
2373 static int reverse_lookup( const struct addrinfo
*ai
, char *hostname
, size_t len
)
2375 return getnameinfo( ai
->ai_addr
, ai
->ai_addrlen
, hostname
, len
, NULL
, 0, 0 );
2378 static WCHAR
*build_wpad_url( const char *hostname
, const struct addrinfo
*ai
)
2380 char name
[NI_MAXHOST
];
2384 while (ai
&& ai
->ai_family
!= AF_INET
&& ai
->ai_family
!= AF_INET6
) ai
= ai
->ai_next
;
2385 if (!ai
) return NULL
;
2387 if (!reverse_lookup( ai
, name
, sizeof(name
) )) hostname
= name
;
2389 len
= lstrlenW( L
"http://" ) + strlen( hostname
) + lstrlenW( L
"/wpad.dat" );
2390 if (!(ret
= p
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) return NULL
;
2391 lstrcpyW( p
, L
"http://" );
2392 p
+= lstrlenW( L
"http://" );
2393 while (*hostname
) { *p
++ = *hostname
++; }
2394 lstrcpyW( p
, L
"/wpad.dat" );
2398 static WCHAR
*detect_proxy_autoconfig_url_dns(void)
2400 char *fqdn
, *domain
, *p
;
2403 if (!(fqdn
= get_computer_name( ComputerNamePhysicalDnsFullyQualified
))) return NULL
;
2404 if (!(domain
= get_computer_name( ComputerNamePhysicalDnsDomain
)))
2410 while ((p
= strchr( p
, '.' )) && is_domain_suffix( p
+ 1, domain
))
2413 struct addrinfo
*ai
;
2416 if (!(name
= heap_alloc( sizeof("wpad") + strlen(p
) )))
2419 heap_free( domain
);
2422 strcpy( name
, "wpad" );
2424 res
= getaddrinfo( name
, NULL
, NULL
, &ai
);
2427 ret
= build_wpad_url( name
, ai
);
2431 TRACE("returning %s\n", debugstr_w(ret
));
2439 heap_free( domain
);
2444 static WCHAR
*get_proxy_autoconfig_url(void)
2446 WCHAR
*ret
= detect_proxy_autoconfig_url_dhcp();
2447 if (!ret
) ret
= detect_proxy_autoconfig_url_dns();
2451 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2453 /* FIXME: This function currently handles more options than it should. Options requiring
2454 * proper handles should be moved to proper functions */
2456 case INTERNET_OPTION_HTTP_VERSION
:
2457 if (*size
< sizeof(HTTP_VERSION_INFO
))
2458 return ERROR_INSUFFICIENT_BUFFER
;
2461 * Presently hardcoded to 1.1
2463 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2464 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2465 *size
= sizeof(HTTP_VERSION_INFO
);
2467 return ERROR_SUCCESS
;
2469 case INTERNET_OPTION_CONNECTED_STATE
:
2470 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2472 if (*size
< sizeof(ULONG
))
2473 return ERROR_INSUFFICIENT_BUFFER
;
2475 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2476 *size
= sizeof(ULONG
);
2478 return ERROR_SUCCESS
;
2480 case INTERNET_OPTION_PROXY
: {
2484 TRACE("Getting global proxy info\n");
2485 memset(&ai
, 0, sizeof(appinfo_t
));
2486 INTERNET_ConfigureProxy(&ai
);
2488 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2489 APPINFO_Destroy(&ai
.hdr
);
2493 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2494 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2496 if (*size
< sizeof(ULONG
))
2497 return ERROR_INSUFFICIENT_BUFFER
;
2499 *(ULONG
*)buffer
= max_conns
;
2500 *size
= sizeof(ULONG
);
2502 return ERROR_SUCCESS
;
2504 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2505 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2507 if (*size
< sizeof(ULONG
))
2508 return ERROR_INSUFFICIENT_BUFFER
;
2510 *(ULONG
*)buffer
= max_1_0_conns
;
2511 *size
= sizeof(ULONG
);
2513 return ERROR_SUCCESS
;
2515 case INTERNET_OPTION_SECURITY_FLAGS
:
2516 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2517 return ERROR_SUCCESS
;
2519 case INTERNET_OPTION_VERSION
: {
2520 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2522 TRACE("INTERNET_OPTION_VERSION\n");
2524 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2525 return ERROR_INSUFFICIENT_BUFFER
;
2527 memcpy(buffer
, &info
, sizeof(info
));
2528 *size
= sizeof(info
);
2530 return ERROR_SUCCESS
;
2533 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2535 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2536 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2537 DWORD res
= ERROR_SUCCESS
, i
;
2541 TRACE("Getting global proxy info\n");
2542 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2545 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2547 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2549 return ERROR_INSUFFICIENT_BUFFER
;
2552 url
= get_proxy_autoconfig_url();
2554 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2555 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2556 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2558 switch (optionW
->dwOption
) {
2559 case INTERNET_PER_CONN_FLAGS
:
2561 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2563 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2565 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2566 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2569 case INTERNET_PER_CONN_PROXY_SERVER
:
2571 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2573 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2576 case INTERNET_PER_CONN_PROXY_BYPASS
:
2578 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2580 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2583 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2585 optionW
->Value
.pszValue
= NULL
;
2587 optionW
->Value
.pszValue
= heap_strdupW(url
);
2589 optionA
->Value
.pszValue
= heap_strdupWtoA(url
);
2592 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2593 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2596 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2597 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2598 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2599 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2600 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2601 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2605 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2606 res
= ERROR_INVALID_PARAMETER
;
2615 case INTERNET_OPTION_REQUEST_FLAGS
:
2616 case INTERNET_OPTION_USER_AGENT
:
2618 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2619 case INTERNET_OPTION_POLICY
:
2620 return ERROR_INVALID_PARAMETER
;
2621 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2622 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2624 if (*size
< sizeof(ULONG
))
2625 return ERROR_INSUFFICIENT_BUFFER
;
2627 *(ULONG
*)buffer
= connect_timeout
;
2628 *size
= sizeof(ULONG
);
2630 return ERROR_SUCCESS
;
2633 FIXME("Stub for %d\n", option
);
2634 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2637 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2640 case INTERNET_OPTION_CONTEXT_VALUE
:
2642 return ERROR_INVALID_PARAMETER
;
2644 if (*size
< sizeof(DWORD_PTR
)) {
2645 *size
= sizeof(DWORD_PTR
);
2646 return ERROR_INSUFFICIENT_BUFFER
;
2649 return ERROR_INVALID_PARAMETER
;
2651 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2652 *size
= sizeof(DWORD_PTR
);
2653 return ERROR_SUCCESS
;
2655 case INTERNET_OPTION_REQUEST_FLAGS
:
2656 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2657 *size
= sizeof(DWORD
);
2658 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2660 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2661 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2662 WARN("Called on global option %u\n", option
);
2663 return ERROR_INTERNET_INVALID_OPERATION
;
2666 /* FIXME: we shouldn't call it here */
2667 return query_global_option(option
, buffer
, size
, unicode
);
2670 /***********************************************************************
2671 * InternetQueryOptionW (WININET.@)
2673 * Queries an options on the specified handle
2680 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2681 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2683 object_header_t
*hdr
;
2684 DWORD res
= ERROR_INVALID_HANDLE
;
2686 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2689 hdr
= get_handle_object(hInternet
);
2691 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2692 WININET_Release(hdr
);
2695 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2698 if(res
!= ERROR_SUCCESS
)
2700 return res
== ERROR_SUCCESS
;
2703 /***********************************************************************
2704 * InternetQueryOptionA (WININET.@)
2706 * Queries an options on the specified handle
2713 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2714 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2716 object_header_t
*hdr
;
2717 DWORD res
= ERROR_INVALID_HANDLE
;
2719 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2722 hdr
= get_handle_object(hInternet
);
2724 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2725 WININET_Release(hdr
);
2728 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2731 if(res
!= ERROR_SUCCESS
)
2733 return res
== ERROR_SUCCESS
;
2736 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2739 case INTERNET_OPTION_SETTINGS_CHANGED
:
2740 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2741 collect_connections(COLLECT_CONNECTIONS
);
2742 return ERROR_SUCCESS
;
2743 case INTERNET_OPTION_CALLBACK
:
2744 WARN("Not settable option %u\n", option
);
2745 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2746 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2747 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2748 WARN("Called on global option %u\n", option
);
2749 return ERROR_INTERNET_INVALID_OPERATION
;
2750 case INTERNET_OPTION_REFRESH
:
2751 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2754 return ERROR_INTERNET_INVALID_OPTION
;
2757 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2760 case INTERNET_OPTION_CALLBACK
:
2761 WARN("Not global option %u\n", option
);
2762 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2764 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2765 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2767 if(size
!= sizeof(max_conns
))
2768 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2770 return ERROR_BAD_ARGUMENTS
;
2772 max_conns
= *(ULONG
*)buf
;
2773 return ERROR_SUCCESS
;
2775 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2776 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2778 if(size
!= sizeof(max_1_0_conns
))
2779 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2781 return ERROR_BAD_ARGUMENTS
;
2783 max_1_0_conns
= *(ULONG
*)buf
;
2784 return ERROR_SUCCESS
;
2786 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2787 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2789 if(size
!= sizeof(connect_timeout
))
2790 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2792 return ERROR_BAD_ARGUMENTS
;
2794 connect_timeout
= *(ULONG
*)buf
;
2795 return ERROR_SUCCESS
;
2797 case INTERNET_OPTION_SUPPRESS_BEHAVIOR
:
2798 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2800 if(size
!= sizeof(ULONG
))
2801 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2803 FIXME("%08x\n", *(ULONG
*)buf
);
2804 return ERROR_SUCCESS
;
2807 return INET_SetOption(NULL
, option
, buf
, size
);
2810 /***********************************************************************
2811 * InternetSetOptionW (WININET.@)
2813 * Sets an options on the specified handle
2820 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2821 LPVOID lpBuffer
, DWORD dwBufferLength
)
2823 object_header_t
*lpwhh
;
2827 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2829 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2831 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2833 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2835 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2837 WININET_Release(lpwhh
);
2839 if(res
!= ERROR_SUCCESS
)
2842 return res
== ERROR_SUCCESS
;
2847 case INTERNET_OPTION_HTTP_VERSION
:
2849 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2850 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2853 case INTERNET_OPTION_ERROR_MASK
:
2856 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2858 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2859 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2860 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2861 SetLastError(ERROR_INVALID_PARAMETER
);
2863 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2864 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2867 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2868 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2871 case INTERNET_OPTION_PROXY
:
2873 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2875 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2877 SetLastError(ERROR_INVALID_PARAMETER
);
2882 EnterCriticalSection( &WININET_cs
);
2883 free_global_proxy();
2884 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2887 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2889 global_proxy
->proxyEnabled
= 1;
2890 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2891 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2895 global_proxy
->proxyEnabled
= 0;
2896 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2899 LeaveCriticalSection( &WININET_cs
);
2903 /* In general, each type of object should handle
2904 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2905 * get silently dropped.
2907 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2908 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2913 case INTERNET_OPTION_CODEPAGE
:
2915 ULONG codepage
= *(ULONG
*)lpBuffer
;
2916 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2919 case INTERNET_OPTION_REQUEST_PRIORITY
:
2921 ULONG priority
= *(ULONG
*)lpBuffer
;
2922 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2925 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2927 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2928 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2931 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2933 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2934 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2937 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2938 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2940 case INTERNET_OPTION_END_BROWSER_SESSION
:
2941 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2943 free_authorization_cache();
2945 case INTERNET_OPTION_CONNECTED_STATE
:
2946 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2948 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2949 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2951 case INTERNET_OPTION_IGNORE_OFFLINE
:
2952 FIXME("Option INTERNET_OPTION_IGNORE_OFFLINE: STUB\n");
2954 case INTERNET_OPTION_SEND_TIMEOUT
:
2955 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2956 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2958 ULONG timeout
= *(ULONG
*)lpBuffer
;
2959 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2962 case INTERNET_OPTION_CONNECT_RETRIES
:
2964 ULONG retries
= *(ULONG
*)lpBuffer
;
2965 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2968 case INTERNET_OPTION_CONTEXT_VALUE
:
2972 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2975 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2977 SetLastError(ERROR_INVALID_PARAMETER
);
2981 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2984 case INTERNET_OPTION_SECURITY_FLAGS
:
2985 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2987 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2988 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2990 case INTERNET_OPTION_HTTP_DECODING
:
2993 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2996 if (!lpBuffer
|| dwBufferLength
!= sizeof(BOOL
))
2998 SetLastError(ERROR_INVALID_PARAMETER
);
3002 lpwhh
->decoding
= *(BOOL
*)lpBuffer
;
3004 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
3005 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
3006 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3009 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
3010 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
3011 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3014 case INTERNET_OPTION_CODEPAGE_PATH
:
3015 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
3016 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3019 case INTERNET_OPTION_CODEPAGE_EXTRA
:
3020 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
3021 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3024 case INTERNET_OPTION_IDN
:
3025 FIXME("INTERNET_OPTION_IDN; STUB\n");
3026 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3029 case INTERNET_OPTION_POLICY
:
3030 SetLastError(ERROR_INVALID_PARAMETER
);
3033 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3034 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
3039 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
3041 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
3042 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
3044 switch (option
->dwOption
) {
3045 case INTERNET_PER_CONN_PROXY_SERVER
:
3046 heap_free(pi
.proxy
);
3047 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
3050 case INTERNET_PER_CONN_FLAGS
:
3051 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
3052 pi
.proxyEnabled
= 1;
3055 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
3056 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
3057 pi
.proxyEnabled
= 0;
3061 case INTERNET_PER_CONN_PROXY_BYPASS
:
3062 heap_free(pi
.proxyBypass
);
3063 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
3066 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3067 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3068 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3069 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3070 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3071 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3072 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
3076 FIXME("Unknown dwOption %d\n", option
->dwOption
);
3077 SetLastError(ERROR_INVALID_PARAMETER
);
3082 if ((res
= INTERNET_SaveProxySettings(&pi
)))
3087 ret
= (res
== ERROR_SUCCESS
);
3091 FIXME("Option %d STUB\n",dwOption
);
3092 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3098 WININET_Release( lpwhh
);
3104 /***********************************************************************
3105 * InternetSetOptionA (WININET.@)
3107 * Sets an options on the specified handle.
3114 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3115 LPVOID lpBuffer
, DWORD dwBufferLength
)
3123 case INTERNET_OPTION_PROXY
:
3125 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3126 LPINTERNET_PROXY_INFOW piw
;
3127 DWORD proxlen
, prbylen
;
3130 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3131 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3132 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3133 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3134 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3135 piw
->dwAccessType
= pi
->dwAccessType
;
3136 prox
= (LPWSTR
) &piw
[1];
3137 prby
= &prox
[proxlen
+1];
3138 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3139 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3140 piw
->lpszProxy
= prox
;
3141 piw
->lpszProxyBypass
= prby
;
3144 case INTERNET_OPTION_USER_AGENT
:
3145 case INTERNET_OPTION_USERNAME
:
3146 case INTERNET_OPTION_PASSWORD
:
3147 case INTERNET_OPTION_PROXY_USERNAME
:
3148 case INTERNET_OPTION_PROXY_PASSWORD
:
3149 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3150 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3151 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3153 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3155 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3156 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3157 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3158 wbuffer
= heap_alloc(wlen
);
3161 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3162 if (listA
->pszConnection
)
3164 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3165 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3166 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3169 listW
->pszConnection
= NULL
;
3170 listW
->dwOptionCount
= listA
->dwOptionCount
;
3171 listW
->dwOptionError
= listA
->dwOptionError
;
3172 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3174 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3175 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3176 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3178 optW
->dwOption
= optA
->dwOption
;
3180 switch (optA
->dwOption
) {
3181 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3182 case INTERNET_PER_CONN_PROXY_BYPASS
:
3183 case INTERNET_PER_CONN_PROXY_SERVER
:
3184 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3185 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3186 if (optA
->Value
.pszValue
)
3188 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3189 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3190 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3193 optW
->Value
.pszValue
= NULL
;
3195 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3196 case INTERNET_PER_CONN_FLAGS
:
3197 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3198 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3200 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3201 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3204 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3205 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3213 wlen
= dwBufferLength
;
3216 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3218 if( lpBuffer
!= wbuffer
)
3220 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3222 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3224 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3225 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3226 switch (opt
->dwOption
) {
3227 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3228 case INTERNET_PER_CONN_PROXY_BYPASS
:
3229 case INTERNET_PER_CONN_PROXY_SERVER
:
3230 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3231 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3232 heap_free( opt
->Value
.pszValue
);
3238 heap_free( list
->pOptions
);
3240 heap_free( wbuffer
);
3247 /***********************************************************************
3248 * InternetSetOptionExA (WININET.@)
3250 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3251 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3253 FIXME("Flags %08x ignored\n", dwFlags
);
3254 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3257 /***********************************************************************
3258 * InternetSetOptionExW (WININET.@)
3260 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3261 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3263 FIXME("Flags %08x ignored\n", dwFlags
);
3264 if( dwFlags
& ~ISO_VALID_FLAGS
)
3266 SetLastError( ERROR_INVALID_PARAMETER
);
3269 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3272 static const WCHAR WININET_wkday
[7][4] =
3273 { L
"Sun", L
"Mon", L
"Tue", L
"Wed",
3274 L
"Thu", L
"Fri", L
"Sat"};
3275 static const WCHAR WININET_month
[12][4] =
3276 { L
"Jan", L
"Feb", L
"Mar", L
"Apr",
3277 L
"May", L
"Jun", L
"Jul", L
"Aug",
3278 L
"Sep", L
"Oct", L
"Nov", L
"Dec"};
3280 /***********************************************************************
3281 * InternetTimeFromSystemTimeA (WININET.@)
3283 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3286 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3288 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3290 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3292 SetLastError(ERROR_INVALID_PARAMETER
);
3296 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3298 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3302 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3303 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3308 /***********************************************************************
3309 * InternetTimeFromSystemTimeW (WININET.@)
3311 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3313 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3315 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3317 SetLastError(ERROR_INVALID_PARAMETER
);
3321 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3323 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3327 swprintf( string
, size
, L
"%s, %02d %s %4d %02d:%02d:%02d GMT",
3328 WININET_wkday
[time
->wDayOfWeek
],
3330 WININET_month
[time
->wMonth
- 1],
3339 /***********************************************************************
3340 * InternetTimeToSystemTimeA (WININET.@)
3342 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3347 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3349 stringW
= heap_strdupAtoW(string
);
3352 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3353 heap_free( stringW
);
3358 /***********************************************************************
3359 * InternetTimeToSystemTimeW (WININET.@)
3361 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3364 const WCHAR
*s
= string
;
3367 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3369 if (!string
|| !time
) return FALSE
;
3371 /* Windows does this too */
3372 GetSystemTime( time
);
3374 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3375 * a SYSTEMTIME structure.
3378 while (*s
&& !iswalpha( *s
)) s
++;
3379 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3380 time
->wDayOfWeek
= 7;
3382 for (i
= 0; i
< 7; i
++)
3384 if (!wcsnicmp( WININET_wkday
[i
], s
, 3 ))
3386 time
->wDayOfWeek
= i
;
3391 if (time
->wDayOfWeek
> 6) return TRUE
;
3392 while (*s
&& !iswdigit( *s
)) s
++;
3393 time
->wDay
= wcstol( s
, &end
, 10 );
3396 while (*s
&& !iswalpha( *s
)) s
++;
3397 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3400 for (i
= 0; i
< 12; i
++)
3402 if (!wcsnicmp( WININET_month
[i
], s
, 3 ))
3404 time
->wMonth
= i
+ 1;
3408 if (time
->wMonth
== 0) return TRUE
;
3410 while (*s
&& !iswdigit( *s
)) s
++;
3411 if (*s
== '\0') return TRUE
;
3412 time
->wYear
= wcstol( s
, &end
, 10 );
3415 while (*s
&& !iswdigit( *s
)) s
++;
3416 if (*s
== '\0') return TRUE
;
3417 time
->wHour
= wcstol( s
, &end
, 10 );
3420 while (*s
&& !iswdigit( *s
)) s
++;
3421 if (*s
== '\0') return TRUE
;
3422 time
->wMinute
= wcstol( s
, &end
, 10 );
3425 while (*s
&& !iswdigit( *s
)) s
++;
3426 if (*s
== '\0') return TRUE
;
3427 time
->wSecond
= wcstol( s
, &end
, 10 );
3430 time
->wMilliseconds
= 0;
3434 /***********************************************************************
3435 * InternetCheckConnectionW (WININET.@)
3437 * Pings a requested host to check internet connection
3440 * TRUE on success and FALSE on failure. If a failure then
3441 * ERROR_NOT_CONNECTED is placed into GetLastError
3444 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3447 * this is a kludge which runs the resident ping program and reads the output.
3449 * Anyone have a better idea?
3453 static const CHAR ping
[] = "ping -c 1 ";
3454 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3456 DWORD len
, host_len
;
3460 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl
), dwFlags
, dwReserved
);
3463 * Crack or set the Address
3465 if (lpszUrl
== NULL
)
3468 * According to the doc we are supposed to use the ip for the next
3469 * server in the WnInet internal server database. I have
3470 * no idea what that is or how to get it.
3472 * So someone needs to implement this.
3474 FIXME("Unimplemented with URL of NULL\n");
3479 URL_COMPONENTSW components
= {sizeof(components
)};
3481 components
.dwHostNameLength
= 1;
3483 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3486 host
= components
.lpszHostName
;
3487 host_len
= components
.dwHostNameLength
;
3488 port
= components
.nPort
;
3489 TRACE("host name: %s port: %d\n",debugstr_wn(host
, host_len
), port
);
3492 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3494 struct sockaddr_storage saddr
;
3495 int sa_len
= sizeof(saddr
);
3500 host_z
= heap_strndupW(host
, host_len
);
3504 b
= GetAddress(host_z
, port
, (struct sockaddr
*)&saddr
, &sa_len
, NULL
);
3509 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3512 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3520 * Build our ping command
3524 len
= WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, NULL
, 0, NULL
, NULL
);
3525 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
)+1);
3526 strcpy(command
, ping
);
3527 WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, command
+sizeof(ping
)-1, len
, NULL
, NULL
);
3528 strcpy(command
+sizeof(ping
)-1+len
, redirect
);
3530 TRACE("Ping command is : %s\n",command
);
3532 status
= system(command
);
3533 heap_free( command
);
3535 TRACE("Ping returned a code of %i\n",status
);
3537 /* Ping return code of 0 indicates success */
3544 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3550 /***********************************************************************
3551 * InternetCheckConnectionA (WININET.@)
3553 * Pings a requested host to check internet connection
3556 * TRUE on success and FALSE on failure. If a failure then
3557 * ERROR_NOT_CONNECTED is placed into GetLastError
3560 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3566 url
= heap_strdupAtoW(lpszUrl
);
3571 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3578 /**********************************************************
3579 * INTERNET_InternetOpenUrlW (internal)
3584 * handle of connection or NULL on failure
3586 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3587 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3589 URL_COMPONENTSW urlComponents
= { sizeof(urlComponents
) };
3590 WCHAR
*host
, *user
= NULL
, *pass
= NULL
, *path
;
3591 HINTERNET client
= NULL
, client1
= NULL
;
3594 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3595 dwHeadersLength
, dwFlags
, dwContext
);
3597 urlComponents
.dwHostNameLength
= 1;
3598 urlComponents
.dwUserNameLength
= 1;
3599 urlComponents
.dwPasswordLength
= 1;
3600 urlComponents
.dwUrlPathLength
= 1;
3601 urlComponents
.dwExtraInfoLength
= 1;
3602 if(!InternetCrackUrlW(lpszUrl
, lstrlenW(lpszUrl
), 0, &urlComponents
))
3605 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
3606 urlComponents
.dwExtraInfoLength
)
3608 assert(urlComponents
.lpszUrlPath
+ urlComponents
.dwUrlPathLength
== urlComponents
.lpszExtraInfo
);
3609 urlComponents
.dwUrlPathLength
+= urlComponents
.dwExtraInfoLength
;
3612 host
= heap_strndupW(urlComponents
.lpszHostName
, urlComponents
.dwHostNameLength
);
3613 path
= heap_strndupW(urlComponents
.lpszUrlPath
, urlComponents
.dwUrlPathLength
);
3614 if(urlComponents
.dwUserNameLength
)
3615 user
= heap_strndupW(urlComponents
.lpszUserName
, urlComponents
.dwUserNameLength
);
3616 if(urlComponents
.dwPasswordLength
)
3617 pass
= heap_strndupW(urlComponents
.lpszPassword
, urlComponents
.dwPasswordLength
);
3619 switch(urlComponents
.nScheme
) {
3620 case INTERNET_SCHEME_FTP
:
3621 client
= FTP_Connect(hIC
, host
, urlComponents
.nPort
,
3622 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
);
3625 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3626 if(client1
== NULL
) {
3627 InternetCloseHandle(client
);
3632 case INTERNET_SCHEME_HTTP
:
3633 case INTERNET_SCHEME_HTTPS
: {
3634 LPCWSTR accept
[2] = { L
"*/*", NULL
};
3636 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3638 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3639 res
= HTTP_Connect(hIC
, host
, urlComponents
.nPort
,
3640 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3641 if(res
!= ERROR_SUCCESS
) {
3642 INTERNET_SetLastError(res
);
3646 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3647 if(client1
== NULL
) {
3648 InternetCloseHandle(client
);
3651 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3652 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3653 GetLastError() != ERROR_IO_PENDING
) {
3654 InternetCloseHandle(client1
);
3659 case INTERNET_SCHEME_GOPHER
:
3660 /* gopher doesn't seem to be implemented in wine, but it's supposed
3661 * to be supported by InternetOpenUrlA. */
3663 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3667 TRACE(" %p <--\n", client1
);
3676 /**********************************************************
3677 * InternetOpenUrlW (WININET.@)
3682 * handle of connection or NULL on failure
3693 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3695 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3697 TRACE("%p\n", task
->hdr
.hdr
);
3699 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3700 task
->headers_len
, task
->flags
, task
->context
);
3701 heap_free(task
->url
);
3702 heap_free(task
->headers
);
3705 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3706 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3708 HINTERNET ret
= NULL
;
3709 appinfo_t
*hIC
= NULL
;
3711 if (TRACE_ON(wininet
)) {
3712 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3713 dwHeadersLength
, dwFlags
, dwContext
);
3715 dump_INTERNET_FLAGS(dwFlags
);
3720 SetLastError(ERROR_INVALID_PARAMETER
);
3724 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3725 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3726 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3730 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3731 open_url_task_t
*task
;
3733 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3734 task
->url
= heap_strdupW(lpszUrl
);
3735 task
->headers
= heap_strdupW(lpszHeaders
);
3736 task
->headers_len
= dwHeadersLength
;
3737 task
->flags
= dwFlags
;
3738 task
->context
= dwContext
;
3740 INTERNET_AsyncCall(&task
->hdr
);
3741 SetLastError(ERROR_IO_PENDING
);
3743 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3748 WININET_Release( &hIC
->hdr
);
3749 TRACE(" %p <--\n", ret
);
3754 /**********************************************************
3755 * InternetOpenUrlA (WININET.@)
3760 * handle of connection or NULL on failure
3762 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3763 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3765 HINTERNET rc
= NULL
;
3766 LPWSTR szUrl
= NULL
;
3767 WCHAR
*headers
= NULL
;
3772 szUrl
= heap_strdupAtoW(lpszUrl
);
3778 headers
= heap_strndupAtoW(lpszHeaders
, dwHeadersLength
, &dwHeadersLength
);
3785 rc
= InternetOpenUrlW(hInternet
, szUrl
, headers
, dwHeadersLength
, dwFlags
, dwContext
);
3793 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3795 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3799 lpwite
->dwError
= 0;
3800 lpwite
->response
[0] = '\0';
3803 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3812 /***********************************************************************
3813 * INTERNET_SetLastError (internal)
3815 * Set last thread specific error
3820 void INTERNET_SetLastError(DWORD dwError
)
3822 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3825 lpwite
= INTERNET_AllocThreadError();
3827 SetLastError(dwError
);
3829 lpwite
->dwError
= dwError
;
3833 /***********************************************************************
3834 * INTERNET_GetLastError (internal)
3836 * Get last thread specific error
3841 DWORD
INTERNET_GetLastError(void)
3843 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3844 if (!lpwite
) return 0;
3845 /* TlsGetValue clears last error, so set it again here */
3846 SetLastError(lpwite
->dwError
);
3847 return lpwite
->dwError
;
3851 /***********************************************************************
3852 * INTERNET_WorkerThreadFunc (internal)
3854 * Worker thread execution function
3859 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3861 task_header_t
*task
= lpvParam
;
3866 WININET_Release(task
->hdr
);
3869 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3871 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3872 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3877 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3879 task_header_t
*task
;
3881 task
= heap_alloc(size
);
3885 task
->hdr
= WININET_AddRef(hdr
);
3890 /***********************************************************************
3891 * INTERNET_AsyncCall (internal)
3893 * Retrieves work request from queue
3898 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3904 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3908 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3910 return ERROR_SUCCESS
;
3914 /***********************************************************************
3915 * INTERNET_GetResponseBuffer (internal)
3920 LPSTR
INTERNET_GetResponseBuffer(void)
3922 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3924 lpwite
= INTERNET_AllocThreadError();
3926 return lpwite
->response
;
3929 /**********************************************************
3930 * InternetQueryDataAvailable (WININET.@)
3932 * Determines how much data is available to be read.
3935 * TRUE on success, FALSE if an error occurred. If
3936 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3937 * no data is presently available, FALSE is returned with
3938 * the last error ERROR_IO_PENDING; a callback with status
3939 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3940 * data is available.
3942 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3943 LPDWORD lpdwNumberOfBytesAvailable
,
3944 DWORD dwFlags
, DWORD_PTR dwContext
)
3946 object_header_t
*hdr
;
3949 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3951 hdr
= get_handle_object( hFile
);
3953 SetLastError(ERROR_INVALID_HANDLE
);
3957 if(hdr
->vtbl
->QueryDataAvailable
) {
3958 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3960 WARN("wrong handle\n");
3961 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3964 WININET_Release(hdr
);
3966 if(res
!= ERROR_SUCCESS
)
3968 return res
== ERROR_SUCCESS
;
3971 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3973 req_file_t
*req_file
;
3975 req_file
= heap_alloc_zero(sizeof(*req_file
));
3977 return ERROR_NOT_ENOUGH_MEMORY
;
3981 req_file
->file_name
= heap_strdupW(file_name
);
3982 if(!req_file
->file_name
) {
3983 heap_free(req_file
);
3984 return ERROR_NOT_ENOUGH_MEMORY
;
3987 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3988 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3989 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
3990 req_file_release(req_file
);
3991 return GetLastError();
3995 return ERROR_SUCCESS
;
3998 void req_file_release(req_file_t
*req_file
)
4000 if(InterlockedDecrement(&req_file
->ref
))
4003 if(!req_file
->is_committed
)
4004 DeleteFileW(req_file
->file_name
);
4005 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
4006 CloseHandle(req_file
->file_handle
);
4007 heap_free(req_file
->file_name
);
4008 heap_free(req_file
->url
);
4009 heap_free(req_file
);
4012 /***********************************************************************
4013 * InternetLockRequestFile (WININET.@)
4015 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
4017 req_file_t
*req_file
= NULL
;
4018 object_header_t
*hdr
;
4021 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
4023 hdr
= get_handle_object(hInternet
);
4025 SetLastError(ERROR_INVALID_HANDLE
);
4029 if(hdr
->vtbl
->LockRequestFile
) {
4030 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
4032 WARN("wrong handle\n");
4033 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4036 WININET_Release(hdr
);
4038 *lphLockReqHandle
= req_file
;
4039 if(res
!= ERROR_SUCCESS
)
4041 return res
== ERROR_SUCCESS
;
4044 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
4046 TRACE("(%p)\n", hLockHandle
);
4048 req_file_release(hLockHandle
);
4053 /***********************************************************************
4054 * InternetAutodial (WININET.@)
4056 * On windows this function is supposed to dial the default internet
4057 * connection. We don't want to have Wine dial out to the internet so
4058 * we return TRUE by default. It might be nice to check if we are connected.
4065 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
4069 /* Tell that we are connected to the internet. */
4073 /***********************************************************************
4074 * InternetAutodialHangup (WININET.@)
4076 * Hangs up a connection made with InternetAutodial
4085 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
4089 /* we didn't dial, we don't disconnect */
4093 /***********************************************************************
4094 * InternetCombineUrlA (WININET.@)
4096 * Combine a base URL with a relative URL
4104 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
4105 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4110 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4112 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4113 dwFlags
^= ICU_NO_ENCODE
;
4114 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4119 /***********************************************************************
4120 * InternetCombineUrlW (WININET.@)
4122 * Combine a base URL with a relative URL
4130 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4131 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4136 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4138 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4139 dwFlags
^= ICU_NO_ENCODE
;
4140 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4145 /* max port num is 65535 => 5 digits */
4146 #define MAX_WORD_DIGITS 5
4148 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4149 (url)->dw##component##Length : lstrlenW((url)->lpsz##component))
4150 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4151 (url)->dw##component##Length : strlen((url)->lpsz##component))
4153 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4155 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4156 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4158 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4159 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4161 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4162 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4164 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4165 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4168 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4174 /* opaque urls do not fit into the standard url hierarchy and don't have
4175 * two following slashes */
4176 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4178 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4179 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4180 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4181 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4182 (nScheme
!= INTERNET_SCHEME_FILE
);
4185 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4188 if (scheme
< INTERNET_SCHEME_FIRST
)
4190 index
= scheme
- INTERNET_SCHEME_FIRST
;
4191 if (index
>= ARRAY_SIZE(url_schemes
))
4193 return url_schemes
[index
];
4196 /* we can calculate using ansi strings because we're just
4197 * calculating string length, not size
4199 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4200 LPDWORD lpdwUrlLength
)
4202 INTERNET_SCHEME nScheme
;
4206 if (lpUrlComponents
->lpszScheme
)
4208 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4209 *lpdwUrlLength
+= dwLen
;
4210 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4216 nScheme
= lpUrlComponents
->nScheme
;
4218 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4219 nScheme
= INTERNET_SCHEME_HTTP
;
4220 scheme
= INTERNET_GetSchemeString(nScheme
);
4221 *lpdwUrlLength
+= lstrlenW(scheme
);
4224 (*lpdwUrlLength
)++; /* ':' */
4225 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4226 *lpdwUrlLength
+= strlen("//");
4228 if (lpUrlComponents
->lpszUserName
)
4230 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4231 *lpdwUrlLength
+= strlen("@");
4235 if (lpUrlComponents
->lpszPassword
)
4237 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4242 if (lpUrlComponents
->lpszPassword
)
4244 *lpdwUrlLength
+= strlen(":");
4245 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4248 if (lpUrlComponents
->lpszHostName
)
4250 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4252 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4254 WCHAR port
[MAX_WORD_DIGITS
+ 1];
4256 _ltow(lpUrlComponents
->nPort
, port
, 10);
4257 *lpdwUrlLength
+= lstrlenW(port
);
4258 *lpdwUrlLength
+= strlen(":");
4261 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4262 (*lpdwUrlLength
)++; /* '/' */
4265 if (lpUrlComponents
->lpszUrlPath
)
4266 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4268 if (lpUrlComponents
->lpszExtraInfo
)
4269 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4274 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4278 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4280 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4281 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4282 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4283 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4284 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4285 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4286 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4287 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4288 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4290 if (lpUrlComponents
->lpszScheme
)
4292 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4293 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4294 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4295 -1, urlCompW
->lpszScheme
, len
);
4298 if (lpUrlComponents
->lpszHostName
)
4300 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4301 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4302 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4303 -1, urlCompW
->lpszHostName
, len
);
4306 if (lpUrlComponents
->lpszUserName
)
4308 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4309 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4310 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4311 -1, urlCompW
->lpszUserName
, len
);
4314 if (lpUrlComponents
->lpszPassword
)
4316 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4317 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4318 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4319 -1, urlCompW
->lpszPassword
, len
);
4322 if (lpUrlComponents
->lpszUrlPath
)
4324 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4325 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4326 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4327 -1, urlCompW
->lpszUrlPath
, len
);
4330 if (lpUrlComponents
->lpszExtraInfo
)
4332 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4333 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4334 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4335 -1, urlCompW
->lpszExtraInfo
, len
);
4339 /***********************************************************************
4340 * InternetCreateUrlA (WININET.@)
4342 * See InternetCreateUrlW.
4344 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4345 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4349 URL_COMPONENTSW urlCompW
;
4351 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4353 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4355 SetLastError(ERROR_INVALID_PARAMETER
);
4359 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4362 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4364 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4366 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4367 *lpdwUrlLength
/= sizeof(WCHAR
);
4369 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4370 * minus one, so add one to leave room for NULL terminator
4373 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4375 heap_free(urlCompW
.lpszScheme
);
4376 heap_free(urlCompW
.lpszHostName
);
4377 heap_free(urlCompW
.lpszUserName
);
4378 heap_free(urlCompW
.lpszPassword
);
4379 heap_free(urlCompW
.lpszUrlPath
);
4380 heap_free(urlCompW
.lpszExtraInfo
);
4385 /***********************************************************************
4386 * InternetCreateUrlW (WININET.@)
4388 * Creates a URL from its component parts.
4391 * lpUrlComponents [I] URL Components.
4392 * dwFlags [I] Flags. See notes.
4393 * lpszUrl [I] Buffer in which to store the created URL.
4394 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4395 * lpszUrl in characters. On output, the number of bytes
4396 * required to store the URL including terminator.
4400 * The dwFlags parameter can be zero or more of the following:
4401 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4408 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4409 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4412 INTERNET_SCHEME nScheme
;
4414 static const WCHAR slashSlashW
[] = {'/','/'};
4416 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4418 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4420 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4424 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4427 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4429 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4430 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4434 *lpdwUrlLength
= dwLen
;
4439 if (lpUrlComponents
->lpszScheme
)
4441 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4442 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4445 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4450 nScheme
= lpUrlComponents
->nScheme
;
4452 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4453 nScheme
= INTERNET_SCHEME_HTTP
;
4455 scheme
= INTERNET_GetSchemeString(nScheme
);
4456 dwLen
= lstrlenW(scheme
);
4457 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4461 /* all schemes are followed by at least a colon */
4465 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4467 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4468 lpszUrl
+= ARRAY_SIZE(slashSlashW
);
4471 if (lpUrlComponents
->lpszUserName
)
4473 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4474 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4477 if (lpUrlComponents
->lpszPassword
)
4482 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4483 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4491 if (lpUrlComponents
->lpszHostName
)
4493 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4494 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4497 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4500 _ltow(lpUrlComponents
->nPort
, lpszUrl
, 10);
4501 lpszUrl
+= lstrlenW(lpszUrl
);
4504 /* add slash between hostname and path if necessary */
4505 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4512 if (lpUrlComponents
->lpszUrlPath
)
4514 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4515 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4519 if (lpUrlComponents
->lpszExtraInfo
)
4521 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4522 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4531 /***********************************************************************
4532 * InternetConfirmZoneCrossingA (WININET.@)
4535 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4537 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4538 return ERROR_SUCCESS
;
4541 /***********************************************************************
4542 * InternetConfirmZoneCrossingW (WININET.@)
4545 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4547 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4548 return ERROR_SUCCESS
;
4551 static DWORD zone_preference
= 3;
4553 /***********************************************************************
4554 * PrivacySetZonePreferenceW (WININET.@)
4556 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4558 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4560 zone_preference
= template;
4564 /***********************************************************************
4565 * PrivacyGetZonePreferenceW (WININET.@)
4567 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4568 LPWSTR preference
, LPDWORD length
)
4570 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4572 if (template) *template = zone_preference
;
4576 /***********************************************************************
4577 * InternetGetSecurityInfoByURLA (WININET.@)
4579 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4584 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4586 url
= heap_strdupAtoW(lpszURL
);
4590 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4595 /***********************************************************************
4596 * InternetGetSecurityInfoByURLW (WININET.@)
4598 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4600 URL_COMPONENTSW url
= {sizeof(url
)};
4604 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4606 if (!ppCertChain
&& !pdwSecureFlags
) {
4607 SetLastError(ERROR_INVALID_PARAMETER
);
4611 url
.dwHostNameLength
= 1;
4612 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4613 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4614 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4618 server
= get_server(substr(url
.lpszHostName
, url
.dwHostNameLength
), url
.nPort
, TRUE
, FALSE
);
4620 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4624 if(server
->cert_chain
) {
4626 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4628 if(ppCertChain
&& !(*ppCertChain
= CertDuplicateCertificateChain(server
->cert_chain
)))
4631 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4635 server_release(server
);
4639 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4640 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4642 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4643 lpdwConnection
, dwReserved
);
4644 return ERROR_SUCCESS
;
4647 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4648 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4650 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4651 lpdwConnection
, dwReserved
);
4652 return ERROR_SUCCESS
;
4655 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4657 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4661 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4663 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4667 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4669 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4670 return ERROR_SUCCESS
;
4673 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4676 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4677 debugstr_w(pwszTarget
), pbHexHash
);
4681 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4683 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4687 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4689 FIXME("(%p, %08lx) stub\n", a
, b
);
4693 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4695 FIXME("%p: stub\n", parent
);