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
);
1086 TRACE("(%p, %p, %p)\n", lpdwError
, lpszBuffer
, lpdwBufferLength
);
1088 if (!lpdwError
|| !lpdwBufferLength
)
1090 SetLastError(ERROR_INVALID_PARAMETER
);
1095 if (lpszBuffer
== NULL
|| *lpdwBufferLength
< strlen(lpwite
->response
))
1097 *lpdwBufferLength
= strlen(lpwite
->response
);
1098 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1101 *lpdwError
= lpwite
->dwError
;
1102 if (*lpdwBufferLength
)
1104 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1105 lpszBuffer
[*lpdwBufferLength
- 1] = 0;
1106 *lpdwBufferLength
= strlen(lpszBuffer
);
1112 *lpdwBufferLength
= 0;
1118 /***********************************************************************
1119 * InternetGetLastResponseInfoW (WININET.@)
1121 * Return last wininet error description on the calling thread
1124 * TRUE on success of writing to buffer
1128 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1129 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1131 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1133 TRACE("(%p, %p, %p)\n", lpdwError
, lpszBuffer
, lpdwBufferLength
);
1135 if (!lpdwError
|| !lpdwBufferLength
)
1137 SetLastError(ERROR_INVALID_PARAMETER
);
1142 int required_size
= MultiByteToWideChar(CP_ACP
, 0, lpwite
->response
, -1, NULL
, 0) - 1;
1143 if (lpszBuffer
== NULL
|| *lpdwBufferLength
< required_size
)
1145 *lpdwBufferLength
= required_size
;
1146 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1149 *lpdwError
= lpwite
->dwError
;
1150 if (*lpdwBufferLength
)
1151 *lpdwBufferLength
= MultiByteToWideChar(CP_ACP
, 0, lpwite
->response
, -1, lpszBuffer
, *lpdwBufferLength
);
1156 *lpdwBufferLength
= 0;
1162 /***********************************************************************
1163 * InternetGetConnectedState (WININET.@)
1165 * Return connected state
1169 * if lpdwStatus is not null, return the status (off line,
1170 * modem, lan...) in it.
1171 * FALSE if not connected
1173 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1175 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1177 return InternetGetConnectedStateExW(lpdwStatus
, NULL
, 0, dwReserved
);
1181 /***********************************************************************
1182 * InternetGetConnectedStateExW (WININET.@)
1184 * Return connected state
1188 * lpdwStatus [O] Flags specifying the status of the internet connection.
1189 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1190 * dwNameLen [I] Size of the buffer, in characters.
1191 * dwReserved [I] Reserved. Must be set to 0.
1195 * if lpdwStatus is not null, return the status (off line,
1196 * modem, lan...) in it.
1197 * FALSE if not connected
1200 * If the system has no available network connections, an empty string is
1201 * stored in lpszConnectionName. If there is a LAN connection, a localized
1202 * "LAN Connection" string is stored. Presumably, if only a dial-up
1203 * connection is available then the name of the dial-up connection is
1204 * returned. Why any application, other than the "Internet Settings" CPL,
1205 * would want to use this function instead of the simpler InternetGetConnectedStateW
1206 * function is beyond me.
1208 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1209 DWORD dwNameLen
, DWORD dwReserved
)
1211 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1218 WARN("always returning LAN connection.\n");
1219 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1222 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1223 * the resource, avoid it as we must not change the buffer in this case */
1224 if(lpszConnectionName
&& dwNameLen
) {
1225 *lpszConnectionName
= '\0';
1226 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1233 /***********************************************************************
1234 * InternetGetConnectedStateExA (WININET.@)
1236 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1237 DWORD dwNameLen
, DWORD dwReserved
)
1239 LPWSTR lpwszConnectionName
= NULL
;
1242 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1244 if (lpszConnectionName
&& dwNameLen
> 0)
1245 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1247 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1249 if (rc
&& lpwszConnectionName
)
1250 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1251 dwNameLen
, NULL
, NULL
);
1253 heap_free(lpwszConnectionName
);
1258 /***********************************************************************
1259 * InternetConnectW (WININET.@)
1261 * Open a ftp, gopher or http session
1264 * HINTERNET a session handle on success
1268 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1269 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1270 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1271 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1274 HINTERNET rc
= NULL
;
1275 DWORD res
= ERROR_SUCCESS
;
1277 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1278 nServerPort
, debugstr_w(lpszUserName
), lpszPassword
, dwService
, dwFlags
, dwContext
);
1280 if (!lpszServerName
)
1282 SetLastError(ERROR_INVALID_PARAMETER
);
1286 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1287 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1289 res
= ERROR_INVALID_HANDLE
;
1295 case INTERNET_SERVICE_FTP
:
1296 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1297 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1299 res
= INTERNET_GetLastError();
1302 case INTERNET_SERVICE_HTTP
:
1303 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1304 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1307 case INTERNET_SERVICE_GOPHER
:
1313 WININET_Release( &hIC
->hdr
);
1315 TRACE("returning %p\n", rc
);
1321 /***********************************************************************
1322 * InternetConnectA (WININET.@)
1324 * Open a ftp, gopher or http session
1327 * HINTERNET a session handle on success
1331 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1332 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1333 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1334 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1336 HINTERNET rc
= NULL
;
1337 LPWSTR szServerName
;
1341 szServerName
= heap_strdupAtoW(lpszServerName
);
1342 szUserName
= heap_strdupAtoW(lpszUserName
);
1343 szPassword
= heap_strdupAtoW(lpszPassword
);
1345 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1346 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1348 heap_free(szServerName
);
1349 heap_free(szUserName
);
1350 heap_free(szPassword
);
1355 /***********************************************************************
1356 * InternetFindNextFileA (WININET.@)
1358 * Continues a file search from a previous call to FindFirstFile
1365 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1368 WIN32_FIND_DATAW fd
;
1370 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1372 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1376 /***********************************************************************
1377 * InternetFindNextFileW (WININET.@)
1379 * Continues a file search from a previous call to FindFirstFile
1386 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1388 object_header_t
*hdr
;
1393 hdr
= get_handle_object(hFind
);
1395 WARN("Invalid handle\n");
1396 SetLastError(ERROR_INVALID_HANDLE
);
1400 if(hdr
->vtbl
->FindNextFileW
) {
1401 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1403 WARN("Handle doesn't support NextFile\n");
1404 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1407 WININET_Release(hdr
);
1409 if(res
!= ERROR_SUCCESS
)
1411 return res
== ERROR_SUCCESS
;
1414 /***********************************************************************
1415 * InternetCloseHandle (WININET.@)
1417 * Generic close handle function
1424 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1426 object_header_t
*obj
;
1428 TRACE("%p\n", hInternet
);
1430 obj
= get_handle_object( hInternet
);
1432 SetLastError(ERROR_INVALID_HANDLE
);
1436 invalidate_handle(obj
);
1437 WININET_Release(obj
);
1442 static BOOL
set_url_component(WCHAR
**component
, DWORD
*component_length
, const WCHAR
*value
, DWORD len
)
1444 TRACE("%s (%d)\n", debugstr_wn(value
, len
), len
);
1446 if (!*component_length
)
1450 *(const WCHAR
**)component
= value
;
1451 *component_length
= len
;
1455 if (*component_length
< len
+1) {
1456 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1460 *component_length
= len
;
1462 memcpy(*component
, value
, len
*sizeof(WCHAR
));
1463 (*component
)[len
] = 0;
1467 static BOOL
set_url_component_WtoA(const WCHAR
*comp_w
, DWORD length
, const WCHAR
*url_w
, char **comp
, DWORD
*ret_length
,
1470 size_t size
, ret_size
= *ret_length
;
1474 size
= WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, NULL
, 0, NULL
, NULL
);
1477 *comp
= comp_w
? (char*)url_a
+ WideCharToMultiByte(CP_ACP
, 0, url_w
, comp_w
-url_w
, NULL
, 0, NULL
, NULL
) : NULL
;
1482 if (size
+1 > ret_size
) {
1483 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1484 *ret_length
= size
+1;
1489 WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, *comp
, ret_size
-1, NULL
, NULL
);
1494 static BOOL
set_url_component_AtoW(const char *comp_a
, DWORD len_a
, WCHAR
**comp_w
, DWORD
*len_w
, WCHAR
**buf
)
1503 if(!(*comp_w
= *buf
= heap_alloc(len_a
*sizeof(WCHAR
)))) {
1504 SetLastError(ERROR_OUTOFMEMORY
);
1511 /***********************************************************************
1512 * InternetCrackUrlA (WININET.@)
1514 * See InternetCrackUrlW.
1516 BOOL WINAPI
InternetCrackUrlA(const char *url
, DWORD url_length
, DWORD flags
, URL_COMPONENTSA
*ret_comp
)
1518 WCHAR
*host
= NULL
, *user
= NULL
, *pass
= NULL
, *path
= NULL
, *scheme
= NULL
, *extra
= NULL
;
1519 URL_COMPONENTSW comp
;
1520 WCHAR
*url_w
= NULL
;
1523 TRACE("(%s %u %x %p)\n", url_length
? debugstr_an(url
, url_length
) : debugstr_a(url
), url_length
, flags
, ret_comp
);
1525 if (!url
|| !*url
|| !ret_comp
|| ret_comp
->dwStructSize
!= sizeof(URL_COMPONENTSA
)) {
1526 SetLastError(ERROR_INVALID_PARAMETER
);
1530 comp
.dwStructSize
= sizeof(comp
);
1532 ret
= set_url_component_AtoW(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
,
1533 &comp
.lpszHostName
, &comp
.dwHostNameLength
, &host
)
1534 && set_url_component_AtoW(ret_comp
->lpszUserName
, ret_comp
->dwUserNameLength
,
1535 &comp
.lpszUserName
, &comp
.dwUserNameLength
, &user
)
1536 && set_url_component_AtoW(ret_comp
->lpszPassword
, ret_comp
->dwPasswordLength
,
1537 &comp
.lpszPassword
, &comp
.dwPasswordLength
, &pass
)
1538 && set_url_component_AtoW(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
,
1539 &comp
.lpszUrlPath
, &comp
.dwUrlPathLength
, &path
)
1540 && set_url_component_AtoW(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
,
1541 &comp
.lpszScheme
, &comp
.dwSchemeLength
, &scheme
)
1542 && set_url_component_AtoW(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
,
1543 &comp
.lpszExtraInfo
, &comp
.dwExtraInfoLength
, &extra
);
1545 if(ret
&& !(url_w
= heap_strndupAtoW(url
, url_length
? url_length
: -1, &url_length
))) {
1546 SetLastError(ERROR_OUTOFMEMORY
);
1550 if (ret
&& (ret
= InternetCrackUrlW(url_w
, url_length
, flags
, &comp
))) {
1551 ret_comp
->nScheme
= comp
.nScheme
;
1552 ret_comp
->nPort
= comp
.nPort
;
1554 ret
= set_url_component_WtoA(comp
.lpszHostName
, comp
.dwHostNameLength
, url_w
,
1555 &ret_comp
->lpszHostName
, &ret_comp
->dwHostNameLength
, url
)
1556 && set_url_component_WtoA(comp
.lpszUserName
, comp
.dwUserNameLength
, url_w
,
1557 &ret_comp
->lpszUserName
, &ret_comp
->dwUserNameLength
, url
)
1558 && set_url_component_WtoA(comp
.lpszPassword
, comp
.dwPasswordLength
, url_w
,
1559 &ret_comp
->lpszPassword
, &ret_comp
->dwPasswordLength
, url
)
1560 && set_url_component_WtoA(comp
.lpszUrlPath
, comp
.dwUrlPathLength
, url_w
,
1561 &ret_comp
->lpszUrlPath
, &ret_comp
->dwUrlPathLength
, url
)
1562 && set_url_component_WtoA(comp
.lpszScheme
, comp
.dwSchemeLength
, url_w
,
1563 &ret_comp
->lpszScheme
, &ret_comp
->dwSchemeLength
, url
)
1564 && set_url_component_WtoA(comp
.lpszExtraInfo
, comp
.dwExtraInfoLength
, url_w
,
1565 &ret_comp
->lpszExtraInfo
, &ret_comp
->dwExtraInfoLength
, url
);
1568 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url
),
1569 debugstr_an(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
),
1570 debugstr_an(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
),
1571 debugstr_an(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
),
1572 debugstr_an(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
));
1585 static const WCHAR
*url_schemes
[] =
1600 /***********************************************************************
1601 * GetInternetSchemeW (internal)
1607 * INTERNET_SCHEME_UNKNOWN on failure
1610 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1614 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1616 if(lpszScheme
==NULL
)
1617 return INTERNET_SCHEME_UNKNOWN
;
1619 for (i
= 0; i
< ARRAY_SIZE(url_schemes
); i
++)
1620 if (!wcsnicmp(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1621 return INTERNET_SCHEME_FIRST
+ i
;
1623 return INTERNET_SCHEME_UNKNOWN
;
1626 /***********************************************************************
1627 * InternetCrackUrlW (WININET.@)
1629 * Break up URL into its components
1635 BOOL WINAPI
InternetCrackUrlW(const WCHAR
*lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
, URL_COMPONENTSW
*lpUC
)
1639 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1642 LPCWSTR lpszParam
= NULL
;
1643 BOOL found_colon
= FALSE
;
1645 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1647 TRACE("(%s %u %x %p)\n",
1648 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: lstrlenW(lpszUrl
)) : "(null)",
1649 dwUrlLength
, dwFlags
, lpUC
);
1651 if (!lpszUrl
|| !*lpszUrl
|| !lpUC
)
1653 SetLastError(ERROR_INVALID_PARAMETER
);
1658 dwUrlLength
= lstrlenW(lpszUrl
);
1660 /* Windows stops at a null, regardless of what dwUrlLength says. */
1661 dwUrlLength
= wcsnlen(lpszUrl
, dwUrlLength
);
1664 if (dwFlags
& ICU_DECODE
)
1666 WCHAR
*url_tmp
, *buffer
;
1667 DWORD len
= dwUrlLength
+ 1;
1670 if (!(url_tmp
= heap_strndupW(lpszUrl
, dwUrlLength
)))
1672 SetLastError(ERROR_OUTOFMEMORY
);
1677 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1678 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1680 buffer
= heap_alloc(len
* sizeof(WCHAR
));
1683 SetLastError(ERROR_OUTOFMEMORY
);
1687 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1690 ret
= InternetCrackUrlW(buffer
, len
, dwFlags
& ~ICU_DECODE
, lpUC
);
1692 if (buffer
!= url_tmp
) heap_free(buffer
);
1698 /* Determine if the URI is absolute. */
1699 while (lpszap
- lpszUrl
< dwUrlLength
)
1701 if (iswalnum(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1713 lpszcp
= lpszUrl
; /* Relative url */
1720 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1724 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1725 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1727 /* Parse <params> */
1728 lpszParam
= wmemchr(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1730 lpszParam
= wmemchr(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1732 if(!set_url_component(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1733 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0))
1737 /* Get scheme first. */
1738 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1739 if(!set_url_component(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, lpszUrl
, lpszcp
- lpszUrl
))
1742 /* Eat ':' in protocol. */
1745 /* double slash indicates the net_loc portion is present */
1746 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1750 lpszNetLoc
= wmemchr(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1754 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1756 lpszNetLoc
= lpszParam
;
1758 else if (!lpszNetLoc
)
1759 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1767 /* [<user>[<:password>]@]<host>[:<port>] */
1768 /* First find the user and password if they exist */
1770 lpszHost
= wmemchr(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1771 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1773 /* username and password not specified. */
1774 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1775 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1777 else /* Parse out username and password */
1779 LPCWSTR lpszUser
= lpszcp
;
1780 LPCWSTR lpszPasswd
= lpszHost
;
1782 while (lpszcp
< lpszHost
)
1785 lpszPasswd
= lpszcp
;
1790 if(!set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, lpszUser
, lpszPasswd
- lpszUser
))
1793 if (lpszPasswd
!= lpszHost
)
1795 if(!set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1796 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
, lpszHost
- lpszPasswd
))
1799 lpszcp
++; /* Advance to beginning of host */
1802 /* Parse <host><:port> */
1805 lpszPort
= lpszNetLoc
;
1807 /* special case for res:// URLs: there is no port here, so the host is the
1808 entire string up to the first '/' */
1809 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1811 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1817 while (lpszcp
< lpszNetLoc
)
1825 /* If the scheme is "file" and the host is just one letter, it's not a host */
1826 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1829 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1833 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1835 if (lpszPort
!= lpszNetLoc
)
1836 lpUC
->nPort
= wcstol(++lpszPort
, NULL
, 10);
1837 else switch (lpUC
->nScheme
)
1839 case INTERNET_SCHEME_HTTP
:
1840 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1842 case INTERNET_SCHEME_HTTPS
:
1843 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1845 case INTERNET_SCHEME_FTP
:
1846 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1857 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1858 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1859 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1862 /* Here lpszcp points to:
1864 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1865 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1867 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1871 /* Only truncate the parameter list if it's already been saved
1872 * in lpUC->lpszExtraInfo.
1874 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1875 len
= lpszParam
- lpszcp
;
1878 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1879 * newlines if necessary.
1881 LPWSTR lpsznewline
= wmemchr(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1882 if (lpsznewline
!= NULL
)
1883 len
= lpsznewline
- lpszcp
;
1885 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1887 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1888 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1890 WCHAR tmppath
[MAX_PATH
];
1894 PathCreateFromUrlW(lpszUrl
, tmppath
, &len
, 0);
1899 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1900 tmppath
[len
] = '\0';
1909 /* if ends in \. or \.. append a backslash */
1910 if (tmppath
[len
- 1] == '.' &&
1911 (tmppath
[len
- 2] == '\\' ||
1912 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1914 if (len
< MAX_PATH
- 1)
1916 tmppath
[len
] = '\\';
1917 tmppath
[len
+1] = '\0';
1921 if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, tmppath
, len
))
1924 else if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, len
))
1929 set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, 0);
1932 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1933 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1934 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1935 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1936 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1941 /***********************************************************************
1942 * InternetAttemptConnect (WININET.@)
1944 * Attempt to make a connection to the internet
1947 * ERROR_SUCCESS on success
1948 * Error value on failure
1951 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1954 return ERROR_SUCCESS
;
1958 /***********************************************************************
1959 * convert_url_canonicalization_flags
1961 * Helper for InternetCanonicalizeUrl
1964 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1967 * Flags suitable for UrlCanonicalize
1969 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1971 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1973 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1974 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1975 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1976 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1977 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1978 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1979 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1984 /***********************************************************************
1985 * InternetCanonicalizeUrlA (WININET.@)
1987 * Escape unsafe characters and spaces
1994 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1995 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1999 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2000 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2002 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2003 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2004 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2005 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2010 /***********************************************************************
2011 * InternetCanonicalizeUrlW (WININET.@)
2013 * Escape unsafe characters and spaces
2020 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2021 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2025 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2026 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2028 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2029 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2030 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2031 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2036 /* #################################################### */
2038 static INTERNET_STATUS_CALLBACK
set_status_callback(
2039 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2041 INTERNET_STATUS_CALLBACK ret
;
2043 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2044 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2046 ret
= lpwh
->lpfnStatusCB
;
2047 lpwh
->lpfnStatusCB
= callback
;
2052 /***********************************************************************
2053 * InternetSetStatusCallbackA (WININET.@)
2055 * Sets up a callback function which is called as progress is made
2056 * during an operation.
2059 * Previous callback or NULL on success
2060 * INTERNET_INVALID_STATUS_CALLBACK on failure
2063 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2064 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2066 INTERNET_STATUS_CALLBACK retVal
;
2067 object_header_t
*lpwh
;
2069 TRACE("%p\n", hInternet
);
2071 if (!(lpwh
= get_handle_object(hInternet
)))
2072 return INTERNET_INVALID_STATUS_CALLBACK
;
2074 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2076 WININET_Release( lpwh
);
2080 /***********************************************************************
2081 * InternetSetStatusCallbackW (WININET.@)
2083 * Sets up a callback function which is called as progress is made
2084 * during an operation.
2087 * Previous callback or NULL on success
2088 * INTERNET_INVALID_STATUS_CALLBACK on failure
2091 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2092 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2094 INTERNET_STATUS_CALLBACK retVal
;
2095 object_header_t
*lpwh
;
2097 TRACE("%p\n", hInternet
);
2099 if (!(lpwh
= get_handle_object(hInternet
)))
2100 return INTERNET_INVALID_STATUS_CALLBACK
;
2102 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2104 WININET_Release( lpwh
);
2108 /***********************************************************************
2109 * InternetSetFilePointer (WININET.@)
2111 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2112 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2114 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2116 SetLastError(ERROR_INTERNET_INVALID_OPERATION
);
2117 return INVALID_SET_FILE_POINTER
;
2120 /***********************************************************************
2121 * InternetWriteFile (WININET.@)
2123 * Write data to an open internet file
2130 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2131 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2133 object_header_t
*lpwh
;
2136 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2138 lpwh
= get_handle_object( hFile
);
2140 WARN("Invalid handle\n");
2141 SetLastError(ERROR_INVALID_HANDLE
);
2145 if(lpwh
->vtbl
->WriteFile
) {
2146 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2148 WARN("No Writefile method.\n");
2149 res
= ERROR_INVALID_HANDLE
;
2152 WININET_Release( lpwh
);
2154 if(res
!= ERROR_SUCCESS
)
2156 return res
== ERROR_SUCCESS
;
2160 /***********************************************************************
2161 * InternetReadFile (WININET.@)
2163 * Read data from an open internet file
2170 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2171 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2173 object_header_t
*hdr
;
2174 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2176 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2178 hdr
= get_handle_object(hFile
);
2180 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2184 if(hdr
->vtbl
->ReadFile
) {
2185 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, 0, 0);
2186 if(res
== ERROR_IO_PENDING
)
2187 *pdwNumOfBytesRead
= 0;
2190 WININET_Release(hdr
);
2192 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2193 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2196 return res
== ERROR_SUCCESS
;
2199 /***********************************************************************
2200 * InternetReadFileExA (WININET.@)
2202 * Read data from an open internet file
2205 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2206 * lpBuffersOut [I/O] Buffer.
2207 * dwFlags [I] Flags. See notes.
2208 * dwContext [I] Context for callbacks.
2215 * The parameter dwFlags include zero or more of the following flags:
2216 *|IRF_ASYNC - Makes the call asynchronous.
2217 *|IRF_SYNC - Makes the call synchronous.
2218 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2219 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2221 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2224 * InternetOpenUrlA(), HttpOpenRequestA()
2226 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2227 DWORD dwFlags
, DWORD_PTR dwContext
)
2229 object_header_t
*hdr
;
2230 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2232 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2234 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2235 SetLastError(ERROR_INVALID_PARAMETER
);
2239 hdr
= get_handle_object(hFile
);
2241 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2245 if(hdr
->vtbl
->ReadFile
)
2246 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2247 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2249 WININET_Release(hdr
);
2251 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2252 res
, lpBuffersOut
->dwBufferLength
);
2254 if(res
!= ERROR_SUCCESS
)
2256 return res
== ERROR_SUCCESS
;
2259 /***********************************************************************
2260 * InternetReadFileExW (WININET.@)
2262 * InternetReadFileExA()
2264 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2265 DWORD dwFlags
, DWORD_PTR dwContext
)
2267 object_header_t
*hdr
;
2268 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2270 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2272 if (!lpBuffer
|| lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2273 SetLastError(ERROR_INVALID_PARAMETER
);
2277 hdr
= get_handle_object(hFile
);
2279 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2283 if(hdr
->vtbl
->ReadFile
)
2284 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2285 dwFlags
, dwContext
);
2287 WININET_Release(hdr
);
2289 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2290 res
, lpBuffer
->dwBufferLength
);
2292 if(res
!= ERROR_SUCCESS
)
2294 return res
== ERROR_SUCCESS
;
2297 static IP_ADAPTER_ADDRESSES
*get_adapters(void)
2299 ULONG err
, size
= 1024, flags
= GAA_FLAG_SKIP_ANYCAST
| GAA_FLAG_SKIP_MULTICAST
|
2300 GAA_FLAG_SKIP_DNS_SERVER
| GAA_FLAG_SKIP_FRIENDLY_NAME
;
2301 IP_ADAPTER_ADDRESSES
*tmp
, *ret
;
2303 if (!(ret
= heap_alloc( size
))) return NULL
;
2304 err
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, ret
, &size
);
2305 while (err
== ERROR_BUFFER_OVERFLOW
)
2307 if (!(tmp
= heap_realloc( ret
, size
))) break;
2309 err
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, ret
, &size
);
2311 if (err
== ERROR_SUCCESS
) return ret
;
2316 static WCHAR
*detect_proxy_autoconfig_url_dhcp(void)
2318 IP_ADAPTER_ADDRESSES
*adapters
, *ptr
;
2319 DHCPCAPI_PARAMS_ARRAY send_params
, recv_params
;
2320 DHCPCAPI_PARAMS param
;
2321 WCHAR name
[MAX_ADAPTER_NAME_LENGTH
+ 1], *ret
= NULL
;
2323 BYTE
*tmp
, *buf
= NULL
;
2325 if (!(adapters
= get_adapters())) return NULL
;
2327 memset( &send_params
, 0, sizeof(send_params
) );
2328 memset( ¶m
, 0, sizeof(param
) );
2329 param
.OptionId
= OPTION_MSFT_IE_PROXY
;
2330 recv_params
.nParams
= 1;
2331 recv_params
.Params
= ¶m
;
2333 for (ptr
= adapters
; ptr
; ptr
= ptr
->Next
)
2335 MultiByteToWideChar( CP_ACP
, 0, ptr
->AdapterName
, -1, name
, ARRAY_SIZE(name
) );
2336 TRACE( "adapter '%s' type %u dhcpv4 enabled %d\n", wine_dbgstr_w(name
), ptr
->IfType
, ptr
->Dhcpv4Enabled
);
2338 if (ptr
->IfType
== IF_TYPE_SOFTWARE_LOOPBACK
) continue;
2339 /* FIXME: also skip adapters where DHCP is disabled */
2342 if (!(buf
= heap_alloc( size
))) goto done
;
2343 err
= DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS
, NULL
, name
, NULL
, send_params
, recv_params
,
2345 while (err
== ERROR_MORE_DATA
)
2347 if (!(tmp
= heap_realloc( buf
, size
))) goto done
;
2349 err
= DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS
, NULL
, name
, NULL
, send_params
, recv_params
,
2352 if (err
== ERROR_SUCCESS
&& param
.nBytesData
)
2354 int len
= MultiByteToWideChar( CP_ACP
, 0, (const char *)param
.Data
, param
.nBytesData
, NULL
, 0 );
2355 if ((ret
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
2357 MultiByteToWideChar( CP_ACP
, 0, (const char *)param
.Data
, param
.nBytesData
, ret
, len
);
2360 TRACE("returning %s\n", debugstr_w(ret
));
2367 heap_free( adapters
);
2371 static char *get_computer_name( COMPUTER_NAME_FORMAT format
)
2376 GetComputerNameExA( format
, NULL
, &size
);
2377 if (GetLastError() != ERROR_MORE_DATA
) return NULL
;
2378 if (!(ret
= heap_alloc( size
))) return NULL
;
2379 if (!GetComputerNameExA( format
, ret
, &size
))
2387 static BOOL
is_domain_suffix( const char *domain
, const char *suffix
)
2389 int len_domain
= strlen( domain
), len_suffix
= strlen( suffix
);
2391 if (len_suffix
> len_domain
) return FALSE
;
2392 if (!stricmp( domain
+ len_domain
- len_suffix
, suffix
)) return TRUE
;
2396 static int reverse_lookup( const struct addrinfo
*ai
, char *hostname
, size_t len
)
2398 return getnameinfo( ai
->ai_addr
, ai
->ai_addrlen
, hostname
, len
, NULL
, 0, 0 );
2401 static WCHAR
*build_wpad_url( const char *hostname
, const struct addrinfo
*ai
)
2403 char name
[NI_MAXHOST
];
2407 while (ai
&& ai
->ai_family
!= AF_INET
&& ai
->ai_family
!= AF_INET6
) ai
= ai
->ai_next
;
2408 if (!ai
) return NULL
;
2410 if (!reverse_lookup( ai
, name
, sizeof(name
) )) hostname
= name
;
2412 len
= lstrlenW( L
"http://" ) + strlen( hostname
) + lstrlenW( L
"/wpad.dat" );
2413 if (!(ret
= p
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) return NULL
;
2414 lstrcpyW( p
, L
"http://" );
2415 p
+= lstrlenW( L
"http://" );
2416 while (*hostname
) { *p
++ = *hostname
++; }
2417 lstrcpyW( p
, L
"/wpad.dat" );
2421 static WCHAR
*detect_proxy_autoconfig_url_dns(void)
2423 char *fqdn
, *domain
, *p
;
2426 if (!(fqdn
= get_computer_name( ComputerNamePhysicalDnsFullyQualified
))) return NULL
;
2427 if (!(domain
= get_computer_name( ComputerNamePhysicalDnsDomain
)))
2433 while ((p
= strchr( p
, '.' )) && is_domain_suffix( p
+ 1, domain
))
2436 struct addrinfo
*ai
;
2439 if (!(name
= heap_alloc( sizeof("wpad") + strlen(p
) )))
2442 heap_free( domain
);
2445 strcpy( name
, "wpad" );
2447 res
= getaddrinfo( name
, NULL
, NULL
, &ai
);
2450 ret
= build_wpad_url( name
, ai
);
2454 TRACE("returning %s\n", debugstr_w(ret
));
2462 heap_free( domain
);
2467 static WCHAR
*get_proxy_autoconfig_url(void)
2469 WCHAR
*ret
= detect_proxy_autoconfig_url_dhcp();
2470 if (!ret
) ret
= detect_proxy_autoconfig_url_dns();
2474 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2476 /* FIXME: This function currently handles more options than it should. Options requiring
2477 * proper handles should be moved to proper functions */
2479 case INTERNET_OPTION_HTTP_VERSION
:
2480 if (*size
< sizeof(HTTP_VERSION_INFO
))
2481 return ERROR_INSUFFICIENT_BUFFER
;
2484 * Presently hardcoded to 1.1
2486 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2487 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2488 *size
= sizeof(HTTP_VERSION_INFO
);
2490 return ERROR_SUCCESS
;
2492 case INTERNET_OPTION_CONNECTED_STATE
:
2493 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2495 if (*size
< sizeof(ULONG
))
2496 return ERROR_INSUFFICIENT_BUFFER
;
2498 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2499 *size
= sizeof(ULONG
);
2501 return ERROR_SUCCESS
;
2503 case INTERNET_OPTION_PROXY
: {
2507 TRACE("Getting global proxy info\n");
2508 memset(&ai
, 0, sizeof(appinfo_t
));
2509 INTERNET_ConfigureProxy(&ai
);
2511 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2512 APPINFO_Destroy(&ai
.hdr
);
2516 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2517 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2519 if (*size
< sizeof(ULONG
))
2520 return ERROR_INSUFFICIENT_BUFFER
;
2522 *(ULONG
*)buffer
= max_conns
;
2523 *size
= sizeof(ULONG
);
2525 return ERROR_SUCCESS
;
2527 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2528 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2530 if (*size
< sizeof(ULONG
))
2531 return ERROR_INSUFFICIENT_BUFFER
;
2533 *(ULONG
*)buffer
= max_1_0_conns
;
2534 *size
= sizeof(ULONG
);
2536 return ERROR_SUCCESS
;
2538 case INTERNET_OPTION_SECURITY_FLAGS
:
2539 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2540 return ERROR_SUCCESS
;
2542 case INTERNET_OPTION_VERSION
: {
2543 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2545 TRACE("INTERNET_OPTION_VERSION\n");
2547 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2548 return ERROR_INSUFFICIENT_BUFFER
;
2550 memcpy(buffer
, &info
, sizeof(info
));
2551 *size
= sizeof(info
);
2553 return ERROR_SUCCESS
;
2556 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2558 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2559 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2560 DWORD res
= ERROR_SUCCESS
, i
;
2564 TRACE("Getting global proxy info\n");
2565 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2568 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2570 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2572 return ERROR_INSUFFICIENT_BUFFER
;
2575 url
= get_proxy_autoconfig_url();
2577 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2578 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2579 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2581 switch (optionW
->dwOption
) {
2582 case INTERNET_PER_CONN_FLAGS
:
2584 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2586 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2588 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2589 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2592 case INTERNET_PER_CONN_PROXY_SERVER
:
2594 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2596 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2599 case INTERNET_PER_CONN_PROXY_BYPASS
:
2601 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2603 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2606 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2608 optionW
->Value
.pszValue
= NULL
;
2610 optionW
->Value
.pszValue
= heap_strdupW(url
);
2612 optionA
->Value
.pszValue
= heap_strdupWtoA(url
);
2615 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2616 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2619 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2620 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2621 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2622 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2623 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2624 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2628 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2629 res
= ERROR_INVALID_PARAMETER
;
2638 case INTERNET_OPTION_REQUEST_FLAGS
:
2639 case INTERNET_OPTION_USER_AGENT
:
2641 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2642 case INTERNET_OPTION_POLICY
:
2643 return ERROR_INVALID_PARAMETER
;
2644 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2645 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2647 if (*size
< sizeof(ULONG
))
2648 return ERROR_INSUFFICIENT_BUFFER
;
2650 *(ULONG
*)buffer
= connect_timeout
;
2651 *size
= sizeof(ULONG
);
2653 return ERROR_SUCCESS
;
2656 FIXME("Stub for %d\n", option
);
2657 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2660 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2663 case INTERNET_OPTION_CONTEXT_VALUE
:
2665 return ERROR_INVALID_PARAMETER
;
2667 if (*size
< sizeof(DWORD_PTR
)) {
2668 *size
= sizeof(DWORD_PTR
);
2669 return ERROR_INSUFFICIENT_BUFFER
;
2672 return ERROR_INVALID_PARAMETER
;
2674 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2675 *size
= sizeof(DWORD_PTR
);
2676 return ERROR_SUCCESS
;
2678 case INTERNET_OPTION_REQUEST_FLAGS
:
2679 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2680 *size
= sizeof(DWORD
);
2681 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2683 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2684 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2685 WARN("Called on global option %u\n", option
);
2686 return ERROR_INTERNET_INVALID_OPERATION
;
2689 /* FIXME: we shouldn't call it here */
2690 return query_global_option(option
, buffer
, size
, unicode
);
2693 /***********************************************************************
2694 * InternetQueryOptionW (WININET.@)
2696 * Queries an options on the specified handle
2703 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2704 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2706 object_header_t
*hdr
;
2707 DWORD res
= ERROR_INVALID_HANDLE
;
2709 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2712 hdr
= get_handle_object(hInternet
);
2714 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2715 WININET_Release(hdr
);
2718 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2721 if(res
!= ERROR_SUCCESS
)
2723 return res
== ERROR_SUCCESS
;
2726 /***********************************************************************
2727 * InternetQueryOptionA (WININET.@)
2729 * Queries an options on the specified handle
2736 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2737 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2739 object_header_t
*hdr
;
2740 DWORD res
= ERROR_INVALID_HANDLE
;
2742 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2745 hdr
= get_handle_object(hInternet
);
2747 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2748 WININET_Release(hdr
);
2751 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2754 if(res
!= ERROR_SUCCESS
)
2756 return res
== ERROR_SUCCESS
;
2759 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2762 case INTERNET_OPTION_SETTINGS_CHANGED
:
2763 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2764 collect_connections(COLLECT_CONNECTIONS
);
2765 return ERROR_SUCCESS
;
2766 case INTERNET_OPTION_CALLBACK
:
2767 WARN("Not settable option %u\n", option
);
2768 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2769 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2770 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2771 WARN("Called on global option %u\n", option
);
2772 return ERROR_INTERNET_INVALID_OPERATION
;
2773 case INTERNET_OPTION_REFRESH
:
2774 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2777 return ERROR_INTERNET_INVALID_OPTION
;
2780 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2783 case INTERNET_OPTION_CALLBACK
:
2784 WARN("Not global option %u\n", option
);
2785 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2787 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2788 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2790 if(size
!= sizeof(max_conns
))
2791 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2793 return ERROR_BAD_ARGUMENTS
;
2795 max_conns
= *(ULONG
*)buf
;
2796 return ERROR_SUCCESS
;
2798 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2799 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2801 if(size
!= sizeof(max_1_0_conns
))
2802 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2804 return ERROR_BAD_ARGUMENTS
;
2806 max_1_0_conns
= *(ULONG
*)buf
;
2807 return ERROR_SUCCESS
;
2809 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2810 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2812 if(size
!= sizeof(connect_timeout
))
2813 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2815 return ERROR_BAD_ARGUMENTS
;
2817 connect_timeout
= *(ULONG
*)buf
;
2818 return ERROR_SUCCESS
;
2820 case INTERNET_OPTION_SUPPRESS_BEHAVIOR
:
2821 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2823 if(size
!= sizeof(ULONG
))
2824 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2826 FIXME("%08x\n", *(ULONG
*)buf
);
2827 return ERROR_SUCCESS
;
2830 return INET_SetOption(NULL
, option
, buf
, size
);
2833 /***********************************************************************
2834 * InternetSetOptionW (WININET.@)
2836 * Sets an options on the specified handle
2843 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2844 LPVOID lpBuffer
, DWORD dwBufferLength
)
2846 object_header_t
*lpwhh
;
2850 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2852 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2854 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2856 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2858 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2860 WININET_Release(lpwhh
);
2862 if(res
!= ERROR_SUCCESS
)
2865 return res
== ERROR_SUCCESS
;
2870 case INTERNET_OPTION_HTTP_VERSION
:
2872 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2873 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2876 case INTERNET_OPTION_ERROR_MASK
:
2879 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2881 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2882 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2883 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2884 SetLastError(ERROR_INVALID_PARAMETER
);
2886 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2887 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2890 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2891 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2894 case INTERNET_OPTION_PROXY
:
2896 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2898 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2900 SetLastError(ERROR_INVALID_PARAMETER
);
2905 EnterCriticalSection( &WININET_cs
);
2906 free_global_proxy();
2907 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2910 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2912 global_proxy
->proxyEnabled
= 1;
2913 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2914 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2918 global_proxy
->proxyEnabled
= 0;
2919 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2922 LeaveCriticalSection( &WININET_cs
);
2926 /* In general, each type of object should handle
2927 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2928 * get silently dropped.
2930 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2931 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2936 case INTERNET_OPTION_CODEPAGE
:
2938 ULONG codepage
= *(ULONG
*)lpBuffer
;
2939 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2942 case INTERNET_OPTION_REQUEST_PRIORITY
:
2944 ULONG priority
= *(ULONG
*)lpBuffer
;
2945 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2948 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2950 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2951 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2954 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2956 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2957 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2960 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2961 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2963 case INTERNET_OPTION_END_BROWSER_SESSION
:
2964 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2966 free_authorization_cache();
2968 case INTERNET_OPTION_CONNECTED_STATE
:
2969 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2971 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2972 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2974 case INTERNET_OPTION_IGNORE_OFFLINE
:
2975 FIXME("Option INTERNET_OPTION_IGNORE_OFFLINE: STUB\n");
2977 case INTERNET_OPTION_SEND_TIMEOUT
:
2978 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2979 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2981 ULONG timeout
= *(ULONG
*)lpBuffer
;
2982 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2985 case INTERNET_OPTION_CONNECT_RETRIES
:
2987 ULONG retries
= *(ULONG
*)lpBuffer
;
2988 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2991 case INTERNET_OPTION_CONTEXT_VALUE
:
2995 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2998 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
3000 SetLastError(ERROR_INVALID_PARAMETER
);
3004 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
3007 case INTERNET_OPTION_SECURITY_FLAGS
:
3008 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
3010 case INTERNET_OPTION_DISABLE_AUTODIAL
:
3011 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
3013 case INTERNET_OPTION_HTTP_DECODING
:
3016 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3019 if (!lpBuffer
|| dwBufferLength
!= sizeof(BOOL
))
3021 SetLastError(ERROR_INVALID_PARAMETER
);
3025 lpwhh
->decoding
= *(BOOL
*)lpBuffer
;
3027 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
3028 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
3029 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3032 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
3033 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
3034 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3037 case INTERNET_OPTION_CODEPAGE_PATH
:
3038 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
3039 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3042 case INTERNET_OPTION_CODEPAGE_EXTRA
:
3043 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
3044 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3047 case INTERNET_OPTION_IDN
:
3048 FIXME("INTERNET_OPTION_IDN; STUB\n");
3049 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3052 case INTERNET_OPTION_POLICY
:
3053 SetLastError(ERROR_INVALID_PARAMETER
);
3056 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3057 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
3062 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
3064 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
3065 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
3067 switch (option
->dwOption
) {
3068 case INTERNET_PER_CONN_PROXY_SERVER
:
3069 heap_free(pi
.proxy
);
3070 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
3073 case INTERNET_PER_CONN_FLAGS
:
3074 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
3075 pi
.proxyEnabled
= 1;
3078 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
3079 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
3080 pi
.proxyEnabled
= 0;
3084 case INTERNET_PER_CONN_PROXY_BYPASS
:
3085 heap_free(pi
.proxyBypass
);
3086 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
3089 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3090 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3091 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3092 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3093 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3094 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3095 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
3099 FIXME("Unknown dwOption %d\n", option
->dwOption
);
3100 SetLastError(ERROR_INVALID_PARAMETER
);
3105 if ((res
= INTERNET_SaveProxySettings(&pi
)))
3110 ret
= (res
== ERROR_SUCCESS
);
3114 FIXME("Option %d STUB\n",dwOption
);
3115 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3121 WININET_Release( lpwhh
);
3127 /***********************************************************************
3128 * InternetSetOptionA (WININET.@)
3130 * Sets an options on the specified handle.
3137 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3138 LPVOID lpBuffer
, DWORD dwBufferLength
)
3146 case INTERNET_OPTION_PROXY
:
3148 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3149 LPINTERNET_PROXY_INFOW piw
;
3150 DWORD proxlen
, prbylen
;
3153 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3154 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3155 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3156 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3157 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3158 piw
->dwAccessType
= pi
->dwAccessType
;
3159 prox
= (LPWSTR
) &piw
[1];
3160 prby
= &prox
[proxlen
+1];
3161 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3162 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3163 piw
->lpszProxy
= prox
;
3164 piw
->lpszProxyBypass
= prby
;
3167 case INTERNET_OPTION_USER_AGENT
:
3168 case INTERNET_OPTION_USERNAME
:
3169 case INTERNET_OPTION_PASSWORD
:
3170 case INTERNET_OPTION_PROXY_USERNAME
:
3171 case INTERNET_OPTION_PROXY_PASSWORD
:
3172 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3173 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3174 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3176 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3178 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3179 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3180 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3181 wbuffer
= heap_alloc(wlen
);
3184 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3185 if (listA
->pszConnection
)
3187 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3188 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3189 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3192 listW
->pszConnection
= NULL
;
3193 listW
->dwOptionCount
= listA
->dwOptionCount
;
3194 listW
->dwOptionError
= listA
->dwOptionError
;
3195 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3197 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3198 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3199 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3201 optW
->dwOption
= optA
->dwOption
;
3203 switch (optA
->dwOption
) {
3204 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3205 case INTERNET_PER_CONN_PROXY_BYPASS
:
3206 case INTERNET_PER_CONN_PROXY_SERVER
:
3207 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3208 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3209 if (optA
->Value
.pszValue
)
3211 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3212 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3213 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3216 optW
->Value
.pszValue
= NULL
;
3218 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3219 case INTERNET_PER_CONN_FLAGS
:
3220 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3221 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3223 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3224 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3227 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3228 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3236 wlen
= dwBufferLength
;
3239 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3241 if( lpBuffer
!= wbuffer
)
3243 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3245 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3247 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3248 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3249 switch (opt
->dwOption
) {
3250 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3251 case INTERNET_PER_CONN_PROXY_BYPASS
:
3252 case INTERNET_PER_CONN_PROXY_SERVER
:
3253 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3254 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3255 heap_free( opt
->Value
.pszValue
);
3261 heap_free( list
->pOptions
);
3263 heap_free( wbuffer
);
3270 /***********************************************************************
3271 * InternetSetOptionExA (WININET.@)
3273 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3274 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3276 FIXME("Flags %08x ignored\n", dwFlags
);
3277 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3280 /***********************************************************************
3281 * InternetSetOptionExW (WININET.@)
3283 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3284 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3286 FIXME("Flags %08x ignored\n", dwFlags
);
3287 if( dwFlags
& ~ISO_VALID_FLAGS
)
3289 SetLastError( ERROR_INVALID_PARAMETER
);
3292 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3295 static const WCHAR WININET_wkday
[7][4] =
3296 { L
"Sun", L
"Mon", L
"Tue", L
"Wed",
3297 L
"Thu", L
"Fri", L
"Sat"};
3298 static const WCHAR WININET_month
[12][4] =
3299 { L
"Jan", L
"Feb", L
"Mar", L
"Apr",
3300 L
"May", L
"Jun", L
"Jul", L
"Aug",
3301 L
"Sep", L
"Oct", L
"Nov", L
"Dec"};
3303 /***********************************************************************
3304 * InternetTimeFromSystemTimeA (WININET.@)
3306 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3309 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3311 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3313 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3315 SetLastError(ERROR_INVALID_PARAMETER
);
3319 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3321 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3325 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3326 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3331 /***********************************************************************
3332 * InternetTimeFromSystemTimeW (WININET.@)
3334 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3336 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3338 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3340 SetLastError(ERROR_INVALID_PARAMETER
);
3344 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3346 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3350 swprintf( string
, size
, L
"%s, %02d %s %4d %02d:%02d:%02d GMT",
3351 WININET_wkday
[time
->wDayOfWeek
],
3353 WININET_month
[time
->wMonth
- 1],
3362 /***********************************************************************
3363 * InternetTimeToSystemTimeA (WININET.@)
3365 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3370 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3372 stringW
= heap_strdupAtoW(string
);
3375 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3376 heap_free( stringW
);
3381 /***********************************************************************
3382 * InternetTimeToSystemTimeW (WININET.@)
3384 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3387 const WCHAR
*s
= string
;
3390 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3392 if (!string
|| !time
) return FALSE
;
3394 /* Windows does this too */
3395 GetSystemTime( time
);
3397 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3398 * a SYSTEMTIME structure.
3401 while (*s
&& !iswalpha( *s
)) s
++;
3402 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3403 time
->wDayOfWeek
= 7;
3405 for (i
= 0; i
< 7; i
++)
3407 if (!wcsnicmp( WININET_wkday
[i
], s
, 3 ))
3409 time
->wDayOfWeek
= i
;
3414 if (time
->wDayOfWeek
> 6) return TRUE
;
3415 while (*s
&& !iswdigit( *s
)) s
++;
3416 time
->wDay
= wcstol( s
, &end
, 10 );
3419 while (*s
&& !iswalpha( *s
)) s
++;
3420 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3423 for (i
= 0; i
< 12; i
++)
3425 if (!wcsnicmp( WININET_month
[i
], s
, 3 ))
3427 time
->wMonth
= i
+ 1;
3431 if (time
->wMonth
== 0) return TRUE
;
3433 while (*s
&& !iswdigit( *s
)) s
++;
3434 if (*s
== '\0') return TRUE
;
3435 time
->wYear
= wcstol( s
, &end
, 10 );
3438 while (*s
&& !iswdigit( *s
)) s
++;
3439 if (*s
== '\0') return TRUE
;
3440 time
->wHour
= wcstol( s
, &end
, 10 );
3443 while (*s
&& !iswdigit( *s
)) s
++;
3444 if (*s
== '\0') return TRUE
;
3445 time
->wMinute
= wcstol( s
, &end
, 10 );
3448 while (*s
&& !iswdigit( *s
)) s
++;
3449 if (*s
== '\0') return TRUE
;
3450 time
->wSecond
= wcstol( s
, &end
, 10 );
3453 time
->wMilliseconds
= 0;
3457 /***********************************************************************
3458 * InternetCheckConnectionW (WININET.@)
3460 * Pings a requested host to check internet connection
3463 * TRUE on success and FALSE on failure. If a failure then
3464 * ERROR_NOT_CONNECTED is placed into GetLastError
3467 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3470 * this is a kludge which runs the resident ping program and reads the output.
3472 * Anyone have a better idea?
3476 static const CHAR ping
[] = "ping -c 1 ";
3477 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3479 DWORD len
, host_len
;
3483 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl
), dwFlags
, dwReserved
);
3486 * Crack or set the Address
3488 if (lpszUrl
== NULL
)
3491 * According to the doc we are supposed to use the ip for the next
3492 * server in the WnInet internal server database. I have
3493 * no idea what that is or how to get it.
3495 * So someone needs to implement this.
3497 FIXME("Unimplemented with URL of NULL\n");
3502 URL_COMPONENTSW components
= {sizeof(components
)};
3504 components
.dwHostNameLength
= 1;
3506 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3509 host
= components
.lpszHostName
;
3510 host_len
= components
.dwHostNameLength
;
3511 port
= components
.nPort
;
3512 TRACE("host name: %s port: %d\n",debugstr_wn(host
, host_len
), port
);
3515 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3517 struct sockaddr_storage saddr
;
3518 int sa_len
= sizeof(saddr
);
3523 host_z
= heap_strndupW(host
, host_len
);
3527 b
= GetAddress(host_z
, port
, (struct sockaddr
*)&saddr
, &sa_len
, NULL
);
3532 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3535 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3543 * Build our ping command
3547 len
= WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, NULL
, 0, NULL
, NULL
);
3548 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
)+1);
3549 strcpy(command
, ping
);
3550 WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, command
+sizeof(ping
)-1, len
, NULL
, NULL
);
3551 strcpy(command
+sizeof(ping
)-1+len
, redirect
);
3553 TRACE("Ping command is : %s\n",command
);
3555 status
= system(command
);
3556 heap_free( command
);
3558 TRACE("Ping returned a code of %i\n",status
);
3560 /* Ping return code of 0 indicates success */
3567 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3573 /***********************************************************************
3574 * InternetCheckConnectionA (WININET.@)
3576 * Pings a requested host to check internet connection
3579 * TRUE on success and FALSE on failure. If a failure then
3580 * ERROR_NOT_CONNECTED is placed into GetLastError
3583 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3589 url
= heap_strdupAtoW(lpszUrl
);
3594 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3601 /**********************************************************
3602 * INTERNET_InternetOpenUrlW (internal)
3607 * handle of connection or NULL on failure
3609 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3610 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3612 URL_COMPONENTSW urlComponents
= { sizeof(urlComponents
) };
3613 WCHAR
*host
, *user
= NULL
, *pass
= NULL
, *path
;
3614 HINTERNET client
= NULL
, client1
= NULL
;
3617 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3618 dwHeadersLength
, dwFlags
, dwContext
);
3620 urlComponents
.dwHostNameLength
= 1;
3621 urlComponents
.dwUserNameLength
= 1;
3622 urlComponents
.dwPasswordLength
= 1;
3623 urlComponents
.dwUrlPathLength
= 1;
3624 urlComponents
.dwExtraInfoLength
= 1;
3625 if(!InternetCrackUrlW(lpszUrl
, lstrlenW(lpszUrl
), 0, &urlComponents
))
3628 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
3629 urlComponents
.dwExtraInfoLength
)
3631 assert(urlComponents
.lpszUrlPath
+ urlComponents
.dwUrlPathLength
== urlComponents
.lpszExtraInfo
);
3632 urlComponents
.dwUrlPathLength
+= urlComponents
.dwExtraInfoLength
;
3635 host
= heap_strndupW(urlComponents
.lpszHostName
, urlComponents
.dwHostNameLength
);
3636 path
= heap_strndupW(urlComponents
.lpszUrlPath
, urlComponents
.dwUrlPathLength
);
3637 if(urlComponents
.dwUserNameLength
)
3638 user
= heap_strndupW(urlComponents
.lpszUserName
, urlComponents
.dwUserNameLength
);
3639 if(urlComponents
.dwPasswordLength
)
3640 pass
= heap_strndupW(urlComponents
.lpszPassword
, urlComponents
.dwPasswordLength
);
3642 switch(urlComponents
.nScheme
) {
3643 case INTERNET_SCHEME_FTP
:
3644 client
= FTP_Connect(hIC
, host
, urlComponents
.nPort
,
3645 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
);
3648 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3649 if(client1
== NULL
) {
3650 InternetCloseHandle(client
);
3655 case INTERNET_SCHEME_HTTP
:
3656 case INTERNET_SCHEME_HTTPS
: {
3657 LPCWSTR accept
[2] = { L
"*/*", NULL
};
3659 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3661 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3662 res
= HTTP_Connect(hIC
, host
, urlComponents
.nPort
,
3663 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3664 if(res
!= ERROR_SUCCESS
) {
3665 INTERNET_SetLastError(res
);
3669 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3670 if(client1
== NULL
) {
3671 InternetCloseHandle(client
);
3674 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3675 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3676 GetLastError() != ERROR_IO_PENDING
) {
3677 InternetCloseHandle(client1
);
3682 case INTERNET_SCHEME_GOPHER
:
3683 /* gopher doesn't seem to be implemented in wine, but it's supposed
3684 * to be supported by InternetOpenUrlA. */
3686 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3690 TRACE(" %p <--\n", client1
);
3699 /**********************************************************
3700 * InternetOpenUrlW (WININET.@)
3705 * handle of connection or NULL on failure
3716 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3718 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3720 TRACE("%p\n", task
->hdr
.hdr
);
3722 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3723 task
->headers_len
, task
->flags
, task
->context
);
3724 heap_free(task
->url
);
3725 heap_free(task
->headers
);
3728 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3729 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3731 HINTERNET ret
= NULL
;
3732 appinfo_t
*hIC
= NULL
;
3734 if (TRACE_ON(wininet
)) {
3735 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3736 dwHeadersLength
, dwFlags
, dwContext
);
3738 dump_INTERNET_FLAGS(dwFlags
);
3743 SetLastError(ERROR_INVALID_PARAMETER
);
3747 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3748 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3749 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3753 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3754 open_url_task_t
*task
;
3756 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3757 task
->url
= heap_strdupW(lpszUrl
);
3758 task
->headers
= heap_strdupW(lpszHeaders
);
3759 task
->headers_len
= dwHeadersLength
;
3760 task
->flags
= dwFlags
;
3761 task
->context
= dwContext
;
3763 INTERNET_AsyncCall(&task
->hdr
);
3764 SetLastError(ERROR_IO_PENDING
);
3766 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3771 WININET_Release( &hIC
->hdr
);
3772 TRACE(" %p <--\n", ret
);
3777 /**********************************************************
3778 * InternetOpenUrlA (WININET.@)
3783 * handle of connection or NULL on failure
3785 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3786 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3788 HINTERNET rc
= NULL
;
3789 LPWSTR szUrl
= NULL
;
3790 WCHAR
*headers
= NULL
;
3795 szUrl
= heap_strdupAtoW(lpszUrl
);
3801 headers
= heap_strndupAtoW(lpszHeaders
, dwHeadersLength
, &dwHeadersLength
);
3808 rc
= InternetOpenUrlW(hInternet
, szUrl
, headers
, dwHeadersLength
, dwFlags
, dwContext
);
3816 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3818 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3822 lpwite
->dwError
= 0;
3823 lpwite
->response
[0] = '\0';
3826 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3835 /***********************************************************************
3836 * INTERNET_SetLastError (internal)
3838 * Set last thread specific error
3843 void INTERNET_SetLastError(DWORD dwError
)
3845 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3848 lpwite
= INTERNET_AllocThreadError();
3850 SetLastError(dwError
);
3852 lpwite
->dwError
= dwError
;
3856 /***********************************************************************
3857 * INTERNET_GetLastError (internal)
3859 * Get last thread specific error
3864 DWORD
INTERNET_GetLastError(void)
3866 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3867 if (!lpwite
) return 0;
3868 /* TlsGetValue clears last error, so set it again here */
3869 SetLastError(lpwite
->dwError
);
3870 return lpwite
->dwError
;
3874 /***********************************************************************
3875 * INTERNET_WorkerThreadFunc (internal)
3877 * Worker thread execution function
3882 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3884 task_header_t
*task
= lpvParam
;
3889 WININET_Release(task
->hdr
);
3892 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3894 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3895 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3900 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3902 task_header_t
*task
;
3904 task
= heap_alloc(size
);
3908 task
->hdr
= WININET_AddRef(hdr
);
3913 /***********************************************************************
3914 * INTERNET_AsyncCall (internal)
3916 * Retrieves work request from queue
3921 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3927 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3931 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3933 return ERROR_SUCCESS
;
3937 /***********************************************************************
3938 * INTERNET_GetResponseBuffer (internal)
3943 LPSTR
INTERNET_GetResponseBuffer(void)
3945 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3947 lpwite
= INTERNET_AllocThreadError();
3949 return lpwite
->response
;
3952 /**********************************************************
3953 * InternetQueryDataAvailable (WININET.@)
3955 * Determines how much data is available to be read.
3958 * TRUE on success, FALSE if an error occurred. If
3959 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3960 * no data is presently available, FALSE is returned with
3961 * the last error ERROR_IO_PENDING; a callback with status
3962 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3963 * data is available.
3965 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3966 LPDWORD lpdwNumberOfBytesAvailable
,
3967 DWORD dwFlags
, DWORD_PTR dwContext
)
3969 object_header_t
*hdr
;
3972 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3974 hdr
= get_handle_object( hFile
);
3976 SetLastError(ERROR_INVALID_HANDLE
);
3980 if(hdr
->vtbl
->QueryDataAvailable
) {
3981 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3983 WARN("wrong handle\n");
3984 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3987 WININET_Release(hdr
);
3989 if(res
!= ERROR_SUCCESS
)
3991 return res
== ERROR_SUCCESS
;
3994 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3996 req_file_t
*req_file
;
3998 req_file
= heap_alloc_zero(sizeof(*req_file
));
4000 return ERROR_NOT_ENOUGH_MEMORY
;
4004 req_file
->file_name
= heap_strdupW(file_name
);
4005 if(!req_file
->file_name
) {
4006 heap_free(req_file
);
4007 return ERROR_NOT_ENOUGH_MEMORY
;
4010 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
4011 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
4012 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
4013 req_file_release(req_file
);
4014 return GetLastError();
4018 return ERROR_SUCCESS
;
4021 void req_file_release(req_file_t
*req_file
)
4023 if(InterlockedDecrement(&req_file
->ref
))
4026 if(!req_file
->is_committed
)
4027 DeleteFileW(req_file
->file_name
);
4028 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
4029 CloseHandle(req_file
->file_handle
);
4030 heap_free(req_file
->file_name
);
4031 heap_free(req_file
->url
);
4032 heap_free(req_file
);
4035 /***********************************************************************
4036 * InternetLockRequestFile (WININET.@)
4038 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
4040 req_file_t
*req_file
= NULL
;
4041 object_header_t
*hdr
;
4044 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
4046 hdr
= get_handle_object(hInternet
);
4048 SetLastError(ERROR_INVALID_HANDLE
);
4052 if(hdr
->vtbl
->LockRequestFile
) {
4053 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
4055 WARN("wrong handle\n");
4056 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4059 WININET_Release(hdr
);
4061 *lphLockReqHandle
= req_file
;
4062 if(res
!= ERROR_SUCCESS
)
4064 return res
== ERROR_SUCCESS
;
4067 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
4069 TRACE("(%p)\n", hLockHandle
);
4071 req_file_release(hLockHandle
);
4076 /***********************************************************************
4077 * InternetAutodial (WININET.@)
4079 * On windows this function is supposed to dial the default internet
4080 * connection. We don't want to have Wine dial out to the internet so
4081 * we return TRUE by default. It might be nice to check if we are connected.
4088 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
4092 /* Tell that we are connected to the internet. */
4096 /***********************************************************************
4097 * InternetAutodialHangup (WININET.@)
4099 * Hangs up a connection made with InternetAutodial
4108 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
4112 /* we didn't dial, we don't disconnect */
4116 /***********************************************************************
4117 * InternetCombineUrlA (WININET.@)
4119 * Combine a base URL with a relative URL
4127 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
4128 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4133 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4135 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4136 dwFlags
^= ICU_NO_ENCODE
;
4137 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4142 /***********************************************************************
4143 * InternetCombineUrlW (WININET.@)
4145 * Combine a base URL with a relative URL
4153 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4154 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4159 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4161 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4162 dwFlags
^= ICU_NO_ENCODE
;
4163 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4168 /* max port num is 65535 => 5 digits */
4169 #define MAX_WORD_DIGITS 5
4171 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4172 (url)->dw##component##Length : lstrlenW((url)->lpsz##component))
4173 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4174 (url)->dw##component##Length : strlen((url)->lpsz##component))
4176 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4178 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4179 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4181 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4182 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4184 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4185 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4187 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4188 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4191 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4197 /* opaque urls do not fit into the standard url hierarchy and don't have
4198 * two following slashes */
4199 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4201 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4202 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4203 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4204 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4205 (nScheme
!= INTERNET_SCHEME_FILE
);
4208 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4211 if (scheme
< INTERNET_SCHEME_FIRST
)
4213 index
= scheme
- INTERNET_SCHEME_FIRST
;
4214 if (index
>= ARRAY_SIZE(url_schemes
))
4216 return url_schemes
[index
];
4219 /* we can calculate using ansi strings because we're just
4220 * calculating string length, not size
4222 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4223 LPDWORD lpdwUrlLength
)
4225 INTERNET_SCHEME nScheme
;
4229 if (lpUrlComponents
->lpszScheme
)
4231 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4232 *lpdwUrlLength
+= dwLen
;
4233 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4239 nScheme
= lpUrlComponents
->nScheme
;
4241 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4242 nScheme
= INTERNET_SCHEME_HTTP
;
4243 scheme
= INTERNET_GetSchemeString(nScheme
);
4244 *lpdwUrlLength
+= lstrlenW(scheme
);
4247 (*lpdwUrlLength
)++; /* ':' */
4248 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4249 *lpdwUrlLength
+= strlen("//");
4251 if (lpUrlComponents
->lpszUserName
)
4253 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4254 *lpdwUrlLength
+= strlen("@");
4258 if (lpUrlComponents
->lpszPassword
)
4260 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4265 if (lpUrlComponents
->lpszPassword
)
4267 *lpdwUrlLength
+= strlen(":");
4268 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4271 if (lpUrlComponents
->lpszHostName
)
4273 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4275 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4277 WCHAR port
[MAX_WORD_DIGITS
+ 1];
4279 _ltow(lpUrlComponents
->nPort
, port
, 10);
4280 *lpdwUrlLength
+= lstrlenW(port
);
4281 *lpdwUrlLength
+= strlen(":");
4284 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4285 (*lpdwUrlLength
)++; /* '/' */
4288 if (lpUrlComponents
->lpszUrlPath
)
4289 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4291 if (lpUrlComponents
->lpszExtraInfo
)
4292 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4297 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4301 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4303 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4304 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4305 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4306 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4307 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4308 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4309 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4310 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4311 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4313 if (lpUrlComponents
->lpszScheme
)
4315 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4316 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4317 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4318 -1, urlCompW
->lpszScheme
, len
);
4321 if (lpUrlComponents
->lpszHostName
)
4323 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4324 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4325 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4326 -1, urlCompW
->lpszHostName
, len
);
4329 if (lpUrlComponents
->lpszUserName
)
4331 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4332 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4333 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4334 -1, urlCompW
->lpszUserName
, len
);
4337 if (lpUrlComponents
->lpszPassword
)
4339 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4340 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4341 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4342 -1, urlCompW
->lpszPassword
, len
);
4345 if (lpUrlComponents
->lpszUrlPath
)
4347 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4348 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4349 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4350 -1, urlCompW
->lpszUrlPath
, len
);
4353 if (lpUrlComponents
->lpszExtraInfo
)
4355 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4356 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4357 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4358 -1, urlCompW
->lpszExtraInfo
, len
);
4362 /***********************************************************************
4363 * InternetCreateUrlA (WININET.@)
4365 * See InternetCreateUrlW.
4367 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4368 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4372 URL_COMPONENTSW urlCompW
;
4374 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4376 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4378 SetLastError(ERROR_INVALID_PARAMETER
);
4382 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4385 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4387 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4389 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4390 *lpdwUrlLength
/= sizeof(WCHAR
);
4392 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4393 * minus one, so add one to leave room for NULL terminator
4396 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4398 heap_free(urlCompW
.lpszScheme
);
4399 heap_free(urlCompW
.lpszHostName
);
4400 heap_free(urlCompW
.lpszUserName
);
4401 heap_free(urlCompW
.lpszPassword
);
4402 heap_free(urlCompW
.lpszUrlPath
);
4403 heap_free(urlCompW
.lpszExtraInfo
);
4408 /***********************************************************************
4409 * InternetCreateUrlW (WININET.@)
4411 * Creates a URL from its component parts.
4414 * lpUrlComponents [I] URL Components.
4415 * dwFlags [I] Flags. See notes.
4416 * lpszUrl [I] Buffer in which to store the created URL.
4417 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4418 * lpszUrl in characters. On output, the number of bytes
4419 * required to store the URL including terminator.
4423 * The dwFlags parameter can be zero or more of the following:
4424 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4431 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4432 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4435 INTERNET_SCHEME nScheme
;
4437 static const WCHAR slashSlashW
[] = {'/','/'};
4439 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4441 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4443 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4447 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4450 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4452 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4453 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4457 *lpdwUrlLength
= dwLen
;
4462 if (lpUrlComponents
->lpszScheme
)
4464 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4465 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4468 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4473 nScheme
= lpUrlComponents
->nScheme
;
4475 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4476 nScheme
= INTERNET_SCHEME_HTTP
;
4478 scheme
= INTERNET_GetSchemeString(nScheme
);
4479 dwLen
= lstrlenW(scheme
);
4480 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4484 /* all schemes are followed by at least a colon */
4488 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4490 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4491 lpszUrl
+= ARRAY_SIZE(slashSlashW
);
4494 if (lpUrlComponents
->lpszUserName
)
4496 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4497 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4500 if (lpUrlComponents
->lpszPassword
)
4505 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4506 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4514 if (lpUrlComponents
->lpszHostName
)
4516 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4517 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4520 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4523 _ltow(lpUrlComponents
->nPort
, lpszUrl
, 10);
4524 lpszUrl
+= lstrlenW(lpszUrl
);
4527 /* add slash between hostname and path if necessary */
4528 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4535 if (lpUrlComponents
->lpszUrlPath
)
4537 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4538 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4542 if (lpUrlComponents
->lpszExtraInfo
)
4544 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4545 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4554 /***********************************************************************
4555 * InternetConfirmZoneCrossingA (WININET.@)
4558 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4560 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4561 return ERROR_SUCCESS
;
4564 /***********************************************************************
4565 * InternetConfirmZoneCrossingW (WININET.@)
4568 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4570 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4571 return ERROR_SUCCESS
;
4574 static DWORD zone_preference
= 3;
4576 /***********************************************************************
4577 * PrivacySetZonePreferenceW (WININET.@)
4579 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4581 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4583 zone_preference
= template;
4587 /***********************************************************************
4588 * PrivacyGetZonePreferenceW (WININET.@)
4590 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4591 LPWSTR preference
, LPDWORD length
)
4593 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4595 if (template) *template = zone_preference
;
4599 /***********************************************************************
4600 * InternetGetSecurityInfoByURLA (WININET.@)
4602 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4607 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4609 url
= heap_strdupAtoW(lpszURL
);
4613 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4618 /***********************************************************************
4619 * InternetGetSecurityInfoByURLW (WININET.@)
4621 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4623 URL_COMPONENTSW url
= {sizeof(url
)};
4627 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4629 if (!ppCertChain
&& !pdwSecureFlags
) {
4630 SetLastError(ERROR_INVALID_PARAMETER
);
4634 url
.dwHostNameLength
= 1;
4635 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4636 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4637 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4641 server
= get_server(substr(url
.lpszHostName
, url
.dwHostNameLength
), url
.nPort
, TRUE
, FALSE
);
4643 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4647 if(server
->cert_chain
) {
4649 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4651 if(ppCertChain
&& !(*ppCertChain
= CertDuplicateCertificateChain(server
->cert_chain
)))
4654 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4658 server_release(server
);
4662 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4663 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4665 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4666 lpdwConnection
, dwReserved
);
4667 return ERROR_SUCCESS
;
4670 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4671 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4673 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4674 lpdwConnection
, dwReserved
);
4675 return ERROR_SUCCESS
;
4678 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4680 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4684 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4686 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4690 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4692 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4693 return ERROR_SUCCESS
;
4696 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4699 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4700 debugstr_w(pwszTarget
), pbHexHash
);
4704 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4706 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4710 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4712 FIXME("(%p, %08lx) stub\n", a
, b
);
4716 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4718 FIXME("%p: stub\n", parent
);