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
58 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
63 CHAR response
[MAX_REPLY_LEN
];
64 } WITHREADERROR
, *LPWITHREADERROR
;
66 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
67 HMODULE WININET_hModule
;
69 static CRITICAL_SECTION WININET_cs
;
70 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
73 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
74 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
76 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
78 static object_header_t
**handle_table
;
79 static UINT_PTR next_handle
;
80 static UINT_PTR handle_table_size
;
91 static ULONG max_conns
= 2, max_1_0_conns
= 4;
92 static ULONG connect_timeout
= 60000;
94 static const WCHAR szInternetSettings
[] =
95 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
97 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
99 UINT_PTR handle
= 0, num
;
100 object_header_t
*ret
;
104 ret
= heap_alloc_zero(size
);
108 list_init(&ret
->children
);
110 EnterCriticalSection( &WININET_cs
);
112 if(!handle_table_size
) {
114 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
117 handle_table_size
= num
;
122 }else if(next_handle
== handle_table_size
) {
123 num
= handle_table_size
* 2;
124 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
127 handle_table_size
= num
;
134 handle
= next_handle
;
135 if(handle_table
[handle
])
136 ERR("handle isn't free but should be\n");
137 handle_table
[handle
] = ret
;
138 ret
->valid_handle
= TRUE
;
140 while(next_handle
< handle_table_size
&& handle_table
[next_handle
])
144 LeaveCriticalSection( &WININET_cs
);
153 ret
->hInternet
= (HINTERNET
)handle
;
156 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
157 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
163 object_header_t
*WININET_AddRef( object_header_t
*info
)
165 ULONG refs
= InterlockedIncrement(&info
->refs
);
166 TRACE("%p -> refcount = %ld\n", info
, refs
);
170 object_header_t
*get_handle_object( HINTERNET hinternet
)
172 object_header_t
*info
= NULL
;
173 UINT_PTR handle
= (UINT_PTR
) hinternet
;
175 EnterCriticalSection( &WININET_cs
);
177 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
178 info
= WININET_AddRef(handle_table
[handle
]);
180 LeaveCriticalSection( &WININET_cs
);
182 TRACE("handle %Id -> %p\n", handle
, info
);
187 static void invalidate_handle(object_header_t
*info
)
189 object_header_t
*child
, *next
;
191 if(!info
->valid_handle
)
193 info
->valid_handle
= FALSE
;
195 /* Free all children as native does */
196 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
198 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
199 invalidate_handle( child
);
202 WININET_Release(info
);
205 BOOL
WININET_Release( object_header_t
*info
)
207 ULONG refs
= InterlockedDecrement(&info
->refs
);
208 TRACE( "object %p refcount = %ld\n", info
, refs
);
211 invalidate_handle(info
);
212 if ( info
->vtbl
->CloseConnection
)
214 TRACE( "closing connection %p\n", info
);
215 info
->vtbl
->CloseConnection( info
);
217 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
218 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
219 || !(info
->dwInternalFlags
& INET_OPENURL
))
221 INTERNET_SendCallback(info
, info
->dwContext
,
222 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
225 TRACE( "destroying object %p\n", info
);
226 if ( info
->htype
!= WH_HINIT
)
227 list_remove( &info
->entry
);
228 info
->vtbl
->Destroy( info
);
230 if(info
->hInternet
) {
231 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
233 EnterCriticalSection( &WININET_cs
);
235 handle_table
[handle
] = NULL
;
236 if(next_handle
> handle
)
237 next_handle
= handle
;
239 LeaveCriticalSection( &WININET_cs
);
247 /***********************************************************************
248 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
251 * hinstDLL [I] handle to the DLL's instance
253 * lpvReserved [I] reserved, must be NULL
260 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
262 TRACE("%p,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
265 case DLL_PROCESS_ATTACH
:
267 g_dwTlsErrIndex
= TlsAlloc();
269 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
274 TlsFree(g_dwTlsErrIndex
);
278 WININET_hModule
= hinstDLL
;
281 case DLL_THREAD_ATTACH
:
284 case DLL_THREAD_DETACH
:
285 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
287 heap_free(TlsGetValue(g_dwTlsErrIndex
));
291 case DLL_PROCESS_DETACH
:
292 if (lpvReserved
) break;
293 collect_connections(COLLECT_CLEANUP
);
298 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
300 heap_free(TlsGetValue(g_dwTlsErrIndex
));
301 TlsFree(g_dwTlsErrIndex
);
308 /***********************************************************************
309 * DllInstall (WININET.@)
311 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
313 FIXME("(%x %s): stub\n", bInstall
, debugstr_w(cmdline
));
317 /***********************************************************************
318 * INTERNET_SaveProxySettings
320 * Stores the proxy settings given by lpwai into the registry
323 * ERROR_SUCCESS if no error, or error code on fail
325 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
330 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
333 if ((ret
= RegSetValueExW( key
, L
"ProxyEnable", 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
341 if ((ret
= RegSetValueExW( key
, L
"ProxyServer", 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
349 if ((ret
= RegDeleteValueW( key
, L
"ProxyServer" )) && ret
!= ERROR_FILE_NOT_FOUND
)
357 return ERROR_SUCCESS
;
360 /***********************************************************************
361 * INTERNET_FindProxyForProtocol
363 * Searches the proxy string for a proxy of the given protocol.
364 * Returns the found proxy, or the default proxy if none of the given
368 * szProxy [In] proxy string to search
369 * proto [In] protocol to search for, e.g. "http"
370 * foundProxy [Out] found proxy
371 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
374 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
375 * *foundProxyLen is set to the required size in WCHARs, including the
376 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
378 WCHAR
*INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
)
383 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
385 /* First, look for the specified protocol (proto=scheme://host:port) */
386 for (ptr
= szProxy
; ptr
&& *ptr
; )
390 if (!(end
= wcschr(ptr
, ' ')))
391 end
= ptr
+ lstrlenW(ptr
);
392 if ((equal
= wcschr(ptr
, '=')) && equal
< end
&&
393 equal
- ptr
== lstrlenW(proto
) &&
394 !wcsnicmp(proto
, ptr
, lstrlenW(proto
)))
396 ret
= heap_strndupW(equal
+ 1, end
- equal
- 1);
397 TRACE("found proxy for %s: %s\n", debugstr_w(proto
), debugstr_w(ret
));
406 /* It wasn't found: look for no protocol */
407 for (ptr
= szProxy
; ptr
&& *ptr
; )
411 if (!(end
= wcschr(ptr
, ' ')))
412 end
= ptr
+ lstrlenW(ptr
);
413 if (!wcschr(ptr
, '='))
415 ret
= heap_strndupW(ptr
, end
- ptr
);
416 TRACE("found proxy for %s: %s\n", debugstr_w(proto
), debugstr_w(ret
));
428 /***********************************************************************
429 * InternetInitializeAutoProxyDll (WININET.@)
431 * Setup the internal proxy
440 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
443 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
447 /***********************************************************************
448 * DetectAutoProxyUrl (WININET.@)
450 * Auto detect the proxy url
456 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
457 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
460 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
464 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
466 heap_free(lpwpi
->proxy
);
467 heap_free(lpwpi
->proxyBypass
);
468 heap_free(lpwpi
->proxyUsername
);
469 heap_free(lpwpi
->proxyPassword
);
472 static proxyinfo_t
*global_proxy
;
474 static void free_global_proxy( void )
476 EnterCriticalSection( &WININET_cs
);
479 FreeProxyInfo( global_proxy
);
480 heap_free( global_proxy
);
482 LeaveCriticalSection( &WININET_cs
);
485 static BOOL
parse_proxy_url( proxyinfo_t
*info
, const WCHAR
*url
)
487 URL_COMPONENTSW uc
= {sizeof(uc
)};
489 uc
.dwHostNameLength
= 1;
490 uc
.dwUserNameLength
= 1;
491 uc
.dwPasswordLength
= 1;
493 if (!InternetCrackUrlW( url
, 0, 0, &uc
)) return FALSE
;
494 if (!uc
.dwHostNameLength
)
496 if (!(info
->proxy
= heap_strdupW( url
))) return FALSE
;
497 info
->proxyUsername
= NULL
;
498 info
->proxyPassword
= NULL
;
501 if (!(info
->proxy
= heap_alloc( (uc
.dwHostNameLength
+ 12) * sizeof(WCHAR
) ))) return FALSE
;
502 swprintf( info
->proxy
, uc
.dwHostNameLength
+ 12, L
"%.*s:%u", uc
.dwHostNameLength
, uc
.lpszHostName
, uc
.nPort
);
504 if (!uc
.dwUserNameLength
) info
->proxyUsername
= NULL
;
505 else if (!(info
->proxyUsername
= heap_strndupW( uc
.lpszUserName
, uc
.dwUserNameLength
)))
507 heap_free( info
->proxy
);
510 if (!uc
.dwPasswordLength
) info
->proxyPassword
= NULL
;
511 else if (!(info
->proxyPassword
= heap_strndupW( uc
.lpszPassword
, uc
.dwPasswordLength
)))
513 heap_free( info
->proxyUsername
);
514 heap_free( info
->proxy
);
520 /***********************************************************************
521 * INTERNET_LoadProxySettings
523 * Loads proxy information from process-wide global settings, the registry,
524 * or the environment into lpwpi.
526 * The caller should call FreeProxyInfo when done with lpwpi.
529 * The proxy may be specified in the form 'http=proxy.my.org'
530 * Presumably that means there can be ftp=ftpproxy.my.org too.
532 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
536 const WCHAR
*envproxy
;
539 memset( lpwpi
, 0, sizeof(*lpwpi
) );
541 EnterCriticalSection( &WININET_cs
);
544 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
545 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
546 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
548 LeaveCriticalSection( &WININET_cs
);
550 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
552 FreeProxyInfo( lpwpi
);
557 if (RegQueryValueExW( key
, L
"ProxyEnable", NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
559 lpwpi
->proxyEnabled
= 0;
560 if((ret
= RegSetValueExW( key
, L
"ProxyEnable", 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
562 FreeProxyInfo( lpwpi
);
568 if (!(envproxy
= _wgetenv( L
"http_proxy" )) || lpwpi
->proxyEnabled
)
570 /* figure out how much memory the proxy setting takes */
571 if (!RegQueryValueExW( key
, L
"ProxyServer", NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
575 if (!(szProxy
= heap_alloc(len
)))
578 FreeProxyInfo( lpwpi
);
579 return ERROR_OUTOFMEMORY
;
581 RegQueryValueExW( key
, L
"ProxyServer", NULL
, &type
, (BYTE
*)szProxy
, &len
);
583 /* find the http proxy, and strip away everything else */
584 p
= wcsstr( szProxy
, L
"http=" );
587 p
+= lstrlenW( L
"http=" );
588 lstrcpyW( szProxy
, p
);
590 p
= wcschr( szProxy
, ';' );
593 FreeProxyInfo( lpwpi
);
594 lpwpi
->proxy
= szProxy
;
595 lpwpi
->proxyBypass
= NULL
;
597 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi
->proxy
));
601 TRACE("No proxy server settings in registry.\n");
602 FreeProxyInfo( lpwpi
);
604 lpwpi
->proxyBypass
= NULL
;
609 FreeProxyInfo( lpwpi
);
610 if (parse_proxy_url( lpwpi
, envproxy
))
612 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
613 lpwpi
->proxyEnabled
= 1;
614 lpwpi
->proxyBypass
= NULL
;
618 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxy
));
619 lpwpi
->proxyEnabled
= 0;
621 lpwpi
->proxyBypass
= NULL
;
625 if (lpwpi
->proxyEnabled
)
627 TRACE("Proxy is enabled.\n");
629 if (!(envproxy
= _wgetenv( L
"no_proxy" )))
631 /* figure out how much memory the proxy setting takes */
632 if (!RegQueryValueExW( key
, L
"ProxyOverride", NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
636 if (!(szProxy
= heap_alloc(len
)))
639 return ERROR_OUTOFMEMORY
;
641 RegQueryValueExW( key
, L
"ProxyOverride", NULL
, &type
, (BYTE
*)szProxy
, &len
);
643 heap_free( lpwpi
->proxyBypass
);
644 lpwpi
->proxyBypass
= szProxy
;
646 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
650 heap_free( lpwpi
->proxyBypass
);
651 lpwpi
->proxyBypass
= NULL
;
653 TRACE("No proxy bypass server settings in registry.\n");
660 if (!(envproxyW
= heap_alloc(lstrlenW(envproxy
) * sizeof(WCHAR
))))
663 return ERROR_OUTOFMEMORY
;
665 lstrcpyW( envproxyW
, envproxy
);
667 heap_free( lpwpi
->proxyBypass
);
668 lpwpi
->proxyBypass
= envproxyW
;
670 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
673 else TRACE("Proxy is disabled.\n");
676 return ERROR_SUCCESS
;
679 /***********************************************************************
680 * INTERNET_ConfigureProxy
682 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
686 if (INTERNET_LoadProxySettings( &wpi
))
689 if (wpi
.proxyEnabled
)
691 TRACE("http proxy = %s bypass = %s\n", debugstr_w(wpi
.proxy
), debugstr_w(wpi
.proxyBypass
));
693 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
694 lpwai
->proxy
= wpi
.proxy
;
695 lpwai
->proxyBypass
= wpi
.proxyBypass
;
696 lpwai
->proxyUsername
= wpi
.proxyUsername
;
697 lpwai
->proxyPassword
= wpi
.proxyPassword
;
701 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
706 /***********************************************************************
707 * dump_INTERNET_FLAGS
709 * Helper function to TRACE the internet flags.
715 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
717 #define FE(x) { x, #x }
718 static const wininet_flag_info flag
[] = {
719 FE(INTERNET_FLAG_RELOAD
),
720 FE(INTERNET_FLAG_RAW_DATA
),
721 FE(INTERNET_FLAG_EXISTING_CONNECT
),
722 FE(INTERNET_FLAG_ASYNC
),
723 FE(INTERNET_FLAG_PASSIVE
),
724 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
725 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
726 FE(INTERNET_FLAG_FROM_CACHE
),
727 FE(INTERNET_FLAG_SECURE
),
728 FE(INTERNET_FLAG_KEEP_CONNECTION
),
729 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
730 FE(INTERNET_FLAG_READ_PREFETCH
),
731 FE(INTERNET_FLAG_NO_COOKIES
),
732 FE(INTERNET_FLAG_NO_AUTH
),
733 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
734 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
735 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
736 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
737 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
738 FE(INTERNET_FLAG_RESYNCHRONIZE
),
739 FE(INTERNET_FLAG_HYPERLINK
),
740 FE(INTERNET_FLAG_NO_UI
),
741 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
742 FE(INTERNET_FLAG_CACHE_ASYNC
),
743 FE(INTERNET_FLAG_FORMS_SUBMIT
),
744 FE(INTERNET_FLAG_NEED_FILE
),
745 FE(INTERNET_FLAG_TRANSFER_ASCII
),
746 FE(INTERNET_FLAG_TRANSFER_BINARY
)
751 for (i
= 0; i
< ARRAY_SIZE(flag
); i
++) {
752 if (flag
[i
].val
& dwFlags
) {
753 TRACE(" %s", flag
[i
].name
);
754 dwFlags
&= ~flag
[i
].val
;
758 TRACE(" Unknown flags (%08lx)\n", dwFlags
);
763 /***********************************************************************
764 * INTERNET_CloseHandle (internal)
766 * Close internet handle
769 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
771 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
775 heap_free(lpwai
->agent
);
776 heap_free(lpwai
->proxy
);
777 heap_free(lpwai
->proxyBypass
);
778 heap_free(lpwai
->proxyUsername
);
779 heap_free(lpwai
->proxyPassword
);
782 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
784 appinfo_t
*ai
= (appinfo_t
*)hdr
;
787 case INTERNET_OPTION_HANDLE_TYPE
:
788 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
790 if (*size
< sizeof(ULONG
))
791 return ERROR_INSUFFICIENT_BUFFER
;
793 *size
= sizeof(DWORD
);
794 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
795 return ERROR_SUCCESS
;
797 case INTERNET_OPTION_USER_AGENT
: {
800 TRACE("INTERNET_OPTION_USER_AGENT\n");
805 DWORD len
= ai
->agent
? lstrlenW(ai
->agent
) : 0;
807 *size
= (len
+ 1) * sizeof(WCHAR
);
808 if(!buffer
|| bufsize
< *size
)
809 return ERROR_INSUFFICIENT_BUFFER
;
812 lstrcpyW(buffer
, ai
->agent
);
814 *(WCHAR
*)buffer
= 0;
815 /* If the buffer is copied, the returned length doesn't include
816 * the NULL terminator.
821 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
824 if(!buffer
|| bufsize
< *size
)
825 return ERROR_INSUFFICIENT_BUFFER
;
828 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
831 /* If the buffer is copied, the returned length doesn't include
832 * the NULL terminator.
837 return ERROR_SUCCESS
;
840 case INTERNET_OPTION_PROXY
:
841 if(!size
) return ERROR_INVALID_PARAMETER
;
843 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
844 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
845 LPWSTR proxy
, proxy_bypass
;
848 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
850 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
851 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
853 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
854 return ERROR_INSUFFICIENT_BUFFER
;
856 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
857 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
859 pi
->dwAccessType
= ai
->accessType
;
860 pi
->lpszProxy
= NULL
;
861 pi
->lpszProxyBypass
= NULL
;
863 lstrcpyW(proxy
, ai
->proxy
);
864 pi
->lpszProxy
= proxy
;
867 if (ai
->proxyBypass
) {
868 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
869 pi
->lpszProxyBypass
= proxy_bypass
;
872 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
873 return ERROR_SUCCESS
;
875 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
876 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
877 LPSTR proxy
, proxy_bypass
;
880 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
882 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
883 NULL
, 0, NULL
, NULL
);
884 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
886 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
887 return ERROR_INSUFFICIENT_BUFFER
;
889 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
890 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
892 pi
->dwAccessType
= ai
->accessType
;
893 pi
->lpszProxy
= NULL
;
894 pi
->lpszProxyBypass
= NULL
;
896 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
897 pi
->lpszProxy
= proxy
;
900 if (ai
->proxyBypass
) {
901 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
902 proxyBypassBytesRequired
, NULL
, NULL
);
903 pi
->lpszProxyBypass
= proxy_bypass
;
906 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
907 return ERROR_SUCCESS
;
910 case INTERNET_OPTION_CONNECT_TIMEOUT
:
911 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
913 if (*size
< sizeof(ULONG
))
914 return ERROR_INSUFFICIENT_BUFFER
;
916 *(ULONG
*)buffer
= ai
->connect_timeout
;
917 *size
= sizeof(ULONG
);
919 return ERROR_SUCCESS
;
922 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
925 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
927 appinfo_t
*ai
= (appinfo_t
*)hdr
;
930 case INTERNET_OPTION_CONNECT_TIMEOUT
:
931 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
933 if(size
!= sizeof(connect_timeout
))
934 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
936 return ERROR_BAD_ARGUMENTS
;
938 ai
->connect_timeout
= *(ULONG
*)buf
;
939 return ERROR_SUCCESS
;
940 case INTERNET_OPTION_USER_AGENT
:
941 heap_free(ai
->agent
);
942 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
943 return ERROR_SUCCESS
;
944 case INTERNET_OPTION_REFRESH
:
945 FIXME("INTERNET_OPTION_REFRESH\n");
946 return ERROR_SUCCESS
;
949 return INET_SetOption(hdr
, option
, buf
, size
);
952 static const object_vtbl_t APPINFOVtbl
= {
963 /***********************************************************************
964 * InternetOpenW (WININET.@)
966 * Per-application initialization of wininet
969 * HINTERNET on success
973 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
974 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
976 appinfo_t
*lpwai
= NULL
;
978 if (TRACE_ON(wininet
)) {
979 #define FE(x) { x, #x }
980 static const wininet_flag_info access_type
[] = {
981 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
982 FE(INTERNET_OPEN_TYPE_DIRECT
),
983 FE(INTERNET_OPEN_TYPE_PROXY
),
984 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
988 const char *access_type_str
= "Unknown";
990 TRACE("(%s, %li, %s, %s, %li)\n", debugstr_w(lpszAgent
), dwAccessType
,
991 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
992 for (i
= 0; i
< ARRAY_SIZE(access_type
); i
++) {
993 if (access_type
[i
].val
== dwAccessType
) {
994 access_type_str
= access_type
[i
].name
;
998 TRACE(" access type : %s\n", access_type_str
);
1000 dump_INTERNET_FLAGS(dwFlags
);
1003 /* Clear any error information */
1004 INTERNET_SetLastError(0);
1006 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1007 SetLastError(ERROR_INVALID_PARAMETER
);
1011 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1013 SetLastError(ERROR_OUTOFMEMORY
);
1017 lpwai
->hdr
.htype
= WH_HINIT
;
1018 lpwai
->hdr
.dwFlags
= dwFlags
;
1019 lpwai
->accessType
= dwAccessType
;
1020 lpwai
->proxyUsername
= NULL
;
1021 lpwai
->proxyPassword
= NULL
;
1022 lpwai
->connect_timeout
= connect_timeout
;
1024 lpwai
->agent
= heap_strdupW(lpszAgent
);
1025 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1026 INTERNET_ConfigureProxy( lpwai
);
1027 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1028 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1029 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1032 TRACE("returning %p\n", lpwai
);
1034 return lpwai
->hdr
.hInternet
;
1038 /***********************************************************************
1039 * InternetOpenA (WININET.@)
1041 * Per-application initialization of wininet
1044 * HINTERNET on success
1048 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1049 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1051 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1054 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent
),
1055 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1057 szAgent
= heap_strdupAtoW(lpszAgent
);
1058 szProxy
= heap_strdupAtoW(lpszProxy
);
1059 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1061 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1065 heap_free(szBypass
);
1069 /***********************************************************************
1070 * InternetGetLastResponseInfoA (WININET.@)
1072 * Return last wininet error description on the calling thread
1075 * TRUE on success of writing to buffer
1079 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1080 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1082 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1084 TRACE("(%p, %p, %p)\n", lpdwError
, lpszBuffer
, lpdwBufferLength
);
1086 if (!lpdwError
|| !lpdwBufferLength
)
1088 SetLastError(ERROR_INVALID_PARAMETER
);
1093 if (lpszBuffer
== NULL
|| *lpdwBufferLength
< strlen(lpwite
->response
))
1095 *lpdwBufferLength
= strlen(lpwite
->response
);
1096 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1099 *lpdwError
= lpwite
->dwError
;
1100 if (*lpdwBufferLength
)
1102 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1103 lpszBuffer
[*lpdwBufferLength
- 1] = 0;
1104 *lpdwBufferLength
= strlen(lpszBuffer
);
1110 *lpdwBufferLength
= 0;
1116 /***********************************************************************
1117 * InternetGetLastResponseInfoW (WININET.@)
1119 * Return last wininet error description on the calling thread
1122 * TRUE on success of writing to buffer
1126 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1127 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1129 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1131 TRACE("(%p, %p, %p)\n", lpdwError
, lpszBuffer
, lpdwBufferLength
);
1133 if (!lpdwError
|| !lpdwBufferLength
)
1135 SetLastError(ERROR_INVALID_PARAMETER
);
1140 int required_size
= MultiByteToWideChar(CP_ACP
, 0, lpwite
->response
, -1, NULL
, 0) - 1;
1141 if (lpszBuffer
== NULL
|| *lpdwBufferLength
< required_size
)
1143 *lpdwBufferLength
= required_size
;
1144 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1147 *lpdwError
= lpwite
->dwError
;
1148 if (*lpdwBufferLength
)
1149 *lpdwBufferLength
= MultiByteToWideChar(CP_ACP
, 0, lpwite
->response
, -1, lpszBuffer
, *lpdwBufferLength
);
1154 *lpdwBufferLength
= 0;
1160 /***********************************************************************
1161 * InternetGetConnectedState (WININET.@)
1163 * Return connected state
1167 * if lpdwStatus is not null, return the status (off line,
1168 * modem, lan...) in it.
1169 * FALSE if not connected
1171 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1173 TRACE("(%p, 0x%08lx)\n", lpdwStatus
, dwReserved
);
1175 return InternetGetConnectedStateExW(lpdwStatus
, NULL
, 0, dwReserved
);
1179 /***********************************************************************
1180 * InternetGetConnectedStateExW (WININET.@)
1182 * Return connected state
1186 * lpdwStatus [O] Flags specifying the status of the internet connection.
1187 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1188 * dwNameLen [I] Size of the buffer, in characters.
1189 * dwReserved [I] Reserved. Must be set to 0.
1193 * if lpdwStatus is not null, return the status (off line,
1194 * modem, lan...) in it.
1195 * FALSE if not connected
1198 * If the system has no available network connections, an empty string is
1199 * stored in lpszConnectionName. If there is a LAN connection, a localized
1200 * "LAN Connection" string is stored. Presumably, if only a dial-up
1201 * connection is available then the name of the dial-up connection is
1202 * returned. Why any application, other than the "Internet Settings" CPL,
1203 * would want to use this function instead of the simpler InternetGetConnectedStateW
1204 * function is beyond me.
1206 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1207 DWORD dwNameLen
, DWORD dwReserved
)
1209 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1216 WARN("always returning LAN connection.\n");
1217 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1220 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1221 * the resource, avoid it as we must not change the buffer in this case */
1222 if(lpszConnectionName
&& dwNameLen
) {
1223 *lpszConnectionName
= '\0';
1224 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1231 /***********************************************************************
1232 * InternetGetConnectedStateExA (WININET.@)
1234 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1235 DWORD dwNameLen
, DWORD dwReserved
)
1237 LPWSTR lpwszConnectionName
= NULL
;
1240 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1242 if (lpszConnectionName
&& dwNameLen
> 0)
1243 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1245 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1247 if (rc
&& lpwszConnectionName
)
1248 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1249 dwNameLen
, NULL
, NULL
);
1251 heap_free(lpwszConnectionName
);
1256 /***********************************************************************
1257 * InternetConnectW (WININET.@)
1259 * Open a ftp, gopher or http session
1262 * HINTERNET a session handle on success
1266 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1267 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1268 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1269 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1272 HINTERNET rc
= NULL
;
1273 DWORD res
= ERROR_SUCCESS
;
1275 TRACE("(%p, %s, %u, %s, %p, %lu, %lx, %Ix)\n", hInternet
, debugstr_w(lpszServerName
),
1276 nServerPort
, debugstr_w(lpszUserName
), lpszPassword
, dwService
, dwFlags
, dwContext
);
1278 if (!lpszServerName
)
1280 SetLastError(ERROR_INVALID_PARAMETER
);
1284 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1285 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1287 res
= ERROR_INVALID_HANDLE
;
1293 case INTERNET_SERVICE_FTP
:
1294 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1295 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1297 res
= INTERNET_GetLastError();
1300 case INTERNET_SERVICE_HTTP
:
1301 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1302 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1305 case INTERNET_SERVICE_GOPHER
:
1311 WININET_Release( &hIC
->hdr
);
1313 TRACE("returning %p\n", rc
);
1319 /***********************************************************************
1320 * InternetConnectA (WININET.@)
1322 * Open a ftp, gopher or http session
1325 * HINTERNET a session handle on success
1329 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1330 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1331 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1332 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1334 HINTERNET rc
= NULL
;
1335 LPWSTR szServerName
;
1339 szServerName
= heap_strdupAtoW(lpszServerName
);
1340 szUserName
= heap_strdupAtoW(lpszUserName
);
1341 szPassword
= heap_strdupAtoW(lpszPassword
);
1343 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1344 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1346 heap_free(szServerName
);
1347 heap_free(szUserName
);
1348 heap_free(szPassword
);
1353 /***********************************************************************
1354 * InternetFindNextFileA (WININET.@)
1356 * Continues a file search from a previous call to FindFirstFile
1363 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1366 WIN32_FIND_DATAW fd
;
1368 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1370 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1374 /***********************************************************************
1375 * InternetFindNextFileW (WININET.@)
1377 * Continues a file search from a previous call to FindFirstFile
1384 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1386 object_header_t
*hdr
;
1391 hdr
= get_handle_object(hFind
);
1393 WARN("Invalid handle\n");
1394 SetLastError(ERROR_INVALID_HANDLE
);
1398 if(hdr
->vtbl
->FindNextFileW
) {
1399 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1401 WARN("Handle doesn't support NextFile\n");
1402 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1405 WININET_Release(hdr
);
1407 if(res
!= ERROR_SUCCESS
)
1409 return res
== ERROR_SUCCESS
;
1412 /***********************************************************************
1413 * InternetCloseHandle (WININET.@)
1415 * Generic close handle function
1422 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1424 object_header_t
*obj
;
1426 TRACE("%p\n", hInternet
);
1428 obj
= get_handle_object( hInternet
);
1430 SetLastError(ERROR_INVALID_HANDLE
);
1434 invalidate_handle(obj
);
1435 WININET_Release(obj
);
1440 static BOOL
set_url_component(WCHAR
**component
, DWORD
*component_length
, const WCHAR
*value
, DWORD len
)
1442 TRACE("%s (%ld)\n", debugstr_wn(value
, len
), len
);
1444 if (!*component_length
)
1448 *(const WCHAR
**)component
= value
;
1449 *component_length
= len
;
1453 if (*component_length
< len
+1) {
1454 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1458 *component_length
= len
;
1460 memcpy(*component
, value
, len
*sizeof(WCHAR
));
1461 (*component
)[len
] = 0;
1465 static BOOL
set_url_component_WtoA(const WCHAR
*comp_w
, DWORD length
, const WCHAR
*url_w
, char **comp
, DWORD
*ret_length
,
1468 size_t size
, ret_size
= *ret_length
;
1472 size
= WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, NULL
, 0, NULL
, NULL
);
1475 *comp
= comp_w
? (char*)url_a
+ WideCharToMultiByte(CP_ACP
, 0, url_w
, comp_w
-url_w
, NULL
, 0, NULL
, NULL
) : NULL
;
1480 if (size
+1 > ret_size
) {
1481 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1482 *ret_length
= size
+1;
1487 WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, *comp
, ret_size
-1, NULL
, NULL
);
1492 static BOOL
set_url_component_AtoW(const char *comp_a
, DWORD len_a
, WCHAR
**comp_w
, DWORD
*len_w
, WCHAR
**buf
)
1501 if(!(*comp_w
= *buf
= heap_alloc(len_a
*sizeof(WCHAR
)))) {
1502 SetLastError(ERROR_OUTOFMEMORY
);
1509 /***********************************************************************
1510 * InternetCrackUrlA (WININET.@)
1512 * See InternetCrackUrlW.
1514 BOOL WINAPI
InternetCrackUrlA(const char *url
, DWORD url_length
, DWORD flags
, URL_COMPONENTSA
*ret_comp
)
1516 WCHAR
*host
= NULL
, *user
= NULL
, *pass
= NULL
, *path
= NULL
, *scheme
= NULL
, *extra
= NULL
;
1517 URL_COMPONENTSW comp
;
1518 WCHAR
*url_w
= NULL
;
1521 TRACE("(%s %lu %lx %p)\n", url_length
? debugstr_an(url
, url_length
) : debugstr_a(url
), url_length
, flags
, ret_comp
);
1523 if (!url
|| !*url
|| !ret_comp
|| ret_comp
->dwStructSize
!= sizeof(URL_COMPONENTSA
)) {
1524 SetLastError(ERROR_INVALID_PARAMETER
);
1528 comp
.dwStructSize
= sizeof(comp
);
1530 ret
= set_url_component_AtoW(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
,
1531 &comp
.lpszHostName
, &comp
.dwHostNameLength
, &host
)
1532 && set_url_component_AtoW(ret_comp
->lpszUserName
, ret_comp
->dwUserNameLength
,
1533 &comp
.lpszUserName
, &comp
.dwUserNameLength
, &user
)
1534 && set_url_component_AtoW(ret_comp
->lpszPassword
, ret_comp
->dwPasswordLength
,
1535 &comp
.lpszPassword
, &comp
.dwPasswordLength
, &pass
)
1536 && set_url_component_AtoW(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
,
1537 &comp
.lpszUrlPath
, &comp
.dwUrlPathLength
, &path
)
1538 && set_url_component_AtoW(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
,
1539 &comp
.lpszScheme
, &comp
.dwSchemeLength
, &scheme
)
1540 && set_url_component_AtoW(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
,
1541 &comp
.lpszExtraInfo
, &comp
.dwExtraInfoLength
, &extra
);
1543 if(ret
&& !(url_w
= heap_strndupAtoW(url
, url_length
? url_length
: -1, &url_length
))) {
1544 SetLastError(ERROR_OUTOFMEMORY
);
1548 if (ret
&& (ret
= InternetCrackUrlW(url_w
, url_length
, flags
, &comp
))) {
1549 ret_comp
->nScheme
= comp
.nScheme
;
1550 ret_comp
->nPort
= comp
.nPort
;
1552 ret
= set_url_component_WtoA(comp
.lpszHostName
, comp
.dwHostNameLength
, url_w
,
1553 &ret_comp
->lpszHostName
, &ret_comp
->dwHostNameLength
, url
)
1554 && set_url_component_WtoA(comp
.lpszUserName
, comp
.dwUserNameLength
, url_w
,
1555 &ret_comp
->lpszUserName
, &ret_comp
->dwUserNameLength
, url
)
1556 && set_url_component_WtoA(comp
.lpszPassword
, comp
.dwPasswordLength
, url_w
,
1557 &ret_comp
->lpszPassword
, &ret_comp
->dwPasswordLength
, url
)
1558 && set_url_component_WtoA(comp
.lpszUrlPath
, comp
.dwUrlPathLength
, url_w
,
1559 &ret_comp
->lpszUrlPath
, &ret_comp
->dwUrlPathLength
, url
)
1560 && set_url_component_WtoA(comp
.lpszScheme
, comp
.dwSchemeLength
, url_w
,
1561 &ret_comp
->lpszScheme
, &ret_comp
->dwSchemeLength
, url
)
1562 && set_url_component_WtoA(comp
.lpszExtraInfo
, comp
.dwExtraInfoLength
, url_w
,
1563 &ret_comp
->lpszExtraInfo
, &ret_comp
->dwExtraInfoLength
, url
);
1566 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url
),
1567 debugstr_an(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
),
1568 debugstr_an(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
),
1569 debugstr_an(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
),
1570 debugstr_an(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
));
1583 static const WCHAR
*url_schemes
[] =
1598 /***********************************************************************
1599 * GetInternetSchemeW (internal)
1605 * INTERNET_SCHEME_UNKNOWN on failure
1608 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1612 TRACE("%s %ld\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1614 if(lpszScheme
==NULL
)
1615 return INTERNET_SCHEME_UNKNOWN
;
1617 for (i
= 0; i
< ARRAY_SIZE(url_schemes
); i
++)
1618 if (!wcsnicmp(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1619 return INTERNET_SCHEME_FIRST
+ i
;
1621 return INTERNET_SCHEME_UNKNOWN
;
1624 /***********************************************************************
1625 * InternetCrackUrlW (WININET.@)
1627 * Break up URL into its components
1633 BOOL WINAPI
InternetCrackUrlW(const WCHAR
*lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
, URL_COMPONENTSW
*lpUC
)
1637 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1640 LPCWSTR lpszParam
= NULL
;
1641 BOOL found_colon
= FALSE
;
1643 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1645 TRACE("(%s %lu %lx %p)\n",
1646 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: lstrlenW(lpszUrl
)) : "(null)",
1647 dwUrlLength
, dwFlags
, lpUC
);
1649 if (!lpszUrl
|| !*lpszUrl
|| !lpUC
)
1651 SetLastError(ERROR_INVALID_PARAMETER
);
1656 dwUrlLength
= lstrlenW(lpszUrl
);
1658 /* Windows stops at a null, regardless of what dwUrlLength says. */
1659 dwUrlLength
= wcsnlen(lpszUrl
, dwUrlLength
);
1662 if (dwFlags
& ICU_DECODE
)
1664 WCHAR
*url_tmp
, *buffer
;
1665 DWORD len
= dwUrlLength
+ 1;
1668 if (!(url_tmp
= heap_strndupW(lpszUrl
, dwUrlLength
)))
1670 SetLastError(ERROR_OUTOFMEMORY
);
1675 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1676 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1678 buffer
= heap_alloc(len
* sizeof(WCHAR
));
1681 SetLastError(ERROR_OUTOFMEMORY
);
1685 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1688 ret
= InternetCrackUrlW(buffer
, len
, dwFlags
& ~ICU_DECODE
, lpUC
);
1690 if (buffer
!= url_tmp
) heap_free(buffer
);
1696 /* Determine if the URI is absolute. */
1697 while (lpszap
- lpszUrl
< dwUrlLength
)
1699 if (iswalnum(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1711 lpszcp
= lpszUrl
; /* Relative url */
1718 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1722 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1723 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1725 /* Parse <params> */
1726 lpszParam
= wmemchr(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1728 lpszParam
= wmemchr(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1730 if(!set_url_component(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1731 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0))
1735 /* Get scheme first. */
1736 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1737 if(!set_url_component(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, lpszUrl
, lpszcp
- lpszUrl
))
1740 /* Eat ':' in protocol. */
1743 /* double slash indicates the net_loc portion is present */
1744 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1748 lpszNetLoc
= wmemchr(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1752 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1754 lpszNetLoc
= lpszParam
;
1756 else if (!lpszNetLoc
)
1757 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1765 /* [<user>[<:password>]@]<host>[:<port>] */
1766 /* First find the user and password if they exist */
1768 lpszHost
= wmemchr(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1769 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1771 /* username and password not specified. */
1772 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1773 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1775 else /* Parse out username and password */
1777 LPCWSTR lpszUser
= lpszcp
;
1778 LPCWSTR lpszPasswd
= lpszHost
;
1780 while (lpszcp
< lpszHost
)
1783 lpszPasswd
= lpszcp
;
1788 if(!set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, lpszUser
, lpszPasswd
- lpszUser
))
1791 if (lpszPasswd
!= lpszHost
)
1793 if(!set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1794 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
, lpszHost
- lpszPasswd
))
1797 lpszcp
++; /* Advance to beginning of host */
1800 /* Parse <host><:port> */
1803 lpszPort
= lpszNetLoc
;
1805 /* special case for res:// URLs: there is no port here, so the host is the
1806 entire string up to the first '/' */
1807 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1809 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1815 while (lpszcp
< lpszNetLoc
)
1823 /* If the scheme is "file" and the host is just one letter, it's not a host */
1824 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1827 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1831 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1833 if (lpszPort
!= lpszNetLoc
)
1834 lpUC
->nPort
= wcstol(++lpszPort
, NULL
, 10);
1835 else switch (lpUC
->nScheme
)
1837 case INTERNET_SCHEME_HTTP
:
1838 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1840 case INTERNET_SCHEME_HTTPS
:
1841 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1843 case INTERNET_SCHEME_FTP
:
1844 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1855 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1856 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1857 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1860 /* Here lpszcp points to:
1862 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1863 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1865 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1869 /* Only truncate the parameter list if it's already been saved
1870 * in lpUC->lpszExtraInfo.
1872 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1873 len
= lpszParam
- lpszcp
;
1876 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1877 * newlines if necessary.
1879 LPWSTR lpsznewline
= wmemchr(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1880 if (lpsznewline
!= NULL
)
1881 len
= lpsznewline
- lpszcp
;
1883 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1885 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1886 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1888 WCHAR tmppath
[MAX_PATH
];
1892 PathCreateFromUrlW(lpszUrl
, tmppath
, &len
, 0);
1897 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1898 tmppath
[len
] = '\0';
1907 /* if ends in \. or \.. append a backslash */
1908 if (tmppath
[len
- 1] == '.' &&
1909 (tmppath
[len
- 2] == '\\' ||
1910 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1912 if (len
< MAX_PATH
- 1)
1914 tmppath
[len
] = '\\';
1915 tmppath
[len
+1] = '\0';
1919 if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, tmppath
, len
))
1922 else if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, len
))
1927 set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, 0);
1930 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1931 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1932 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1933 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1934 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1939 /***********************************************************************
1940 * InternetAttemptConnect (WININET.@)
1942 * Attempt to make a connection to the internet
1945 * ERROR_SUCCESS on success
1946 * Error value on failure
1949 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1952 return ERROR_SUCCESS
;
1956 /***********************************************************************
1957 * convert_url_canonicalization_flags
1959 * Helper for InternetCanonicalizeUrl
1962 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1965 * Flags suitable for UrlCanonicalize
1967 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1969 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1971 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1972 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1973 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1974 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1975 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1976 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1977 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1982 /***********************************************************************
1983 * InternetCanonicalizeUrlA (WININET.@)
1985 * Escape unsafe characters and spaces
1992 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1993 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1997 TRACE("(%s, %p, %p, 0x%08lx) buffer length: %ld\n", debugstr_a(lpszUrl
), lpszBuffer
,
1998 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2000 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2001 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2002 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2003 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2008 /***********************************************************************
2009 * InternetCanonicalizeUrlW (WININET.@)
2011 * Escape unsafe characters and spaces
2018 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2019 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2023 TRACE("(%s, %p, %p, 0x%08lx) buffer length: %ld\n", debugstr_w(lpszUrl
), lpszBuffer
,
2024 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2026 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2027 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2028 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2029 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2034 /* #################################################### */
2036 static INTERNET_STATUS_CALLBACK
set_status_callback(
2037 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2039 INTERNET_STATUS_CALLBACK ret
;
2041 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2042 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2044 ret
= lpwh
->lpfnStatusCB
;
2045 lpwh
->lpfnStatusCB
= callback
;
2050 /***********************************************************************
2051 * InternetSetStatusCallbackA (WININET.@)
2053 * Sets up a callback function which is called as progress is made
2054 * during an operation.
2057 * Previous callback or NULL on success
2058 * INTERNET_INVALID_STATUS_CALLBACK on failure
2061 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2062 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2064 INTERNET_STATUS_CALLBACK retVal
;
2065 object_header_t
*lpwh
;
2067 TRACE("%p\n", hInternet
);
2069 if (!(lpwh
= get_handle_object(hInternet
)))
2070 return INTERNET_INVALID_STATUS_CALLBACK
;
2072 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2074 WININET_Release( lpwh
);
2078 /***********************************************************************
2079 * InternetSetStatusCallbackW (WININET.@)
2081 * Sets up a callback function which is called as progress is made
2082 * during an operation.
2085 * Previous callback or NULL on success
2086 * INTERNET_INVALID_STATUS_CALLBACK on failure
2089 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2090 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2092 INTERNET_STATUS_CALLBACK retVal
;
2093 object_header_t
*lpwh
;
2095 TRACE("%p\n", hInternet
);
2097 if (!(lpwh
= get_handle_object(hInternet
)))
2098 return INTERNET_INVALID_STATUS_CALLBACK
;
2100 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2102 WININET_Release( lpwh
);
2106 /***********************************************************************
2107 * InternetSetFilePointer (WININET.@)
2109 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2110 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2112 FIXME("(%p %ld %p %ld %Ix): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2114 SetLastError(ERROR_INTERNET_INVALID_OPERATION
);
2115 return INVALID_SET_FILE_POINTER
;
2118 /***********************************************************************
2119 * InternetWriteFile (WININET.@)
2121 * Write data to an open internet file
2128 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2129 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2131 object_header_t
*lpwh
;
2134 TRACE("(%p %p %ld %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2136 lpwh
= get_handle_object( hFile
);
2138 WARN("Invalid handle\n");
2139 SetLastError(ERROR_INVALID_HANDLE
);
2143 if(lpwh
->vtbl
->WriteFile
) {
2144 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2146 WARN("No Writefile method.\n");
2147 res
= ERROR_INVALID_HANDLE
;
2150 WININET_Release( lpwh
);
2152 if(res
!= ERROR_SUCCESS
)
2154 return res
== ERROR_SUCCESS
;
2158 /***********************************************************************
2159 * InternetReadFile (WININET.@)
2161 * Read data from an open internet file
2168 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2169 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2171 object_header_t
*hdr
;
2172 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2174 TRACE("%p %p %ld %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2176 hdr
= get_handle_object(hFile
);
2178 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2182 if(hdr
->vtbl
->ReadFile
) {
2183 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, 0, 0);
2184 if(res
== ERROR_IO_PENDING
)
2185 *pdwNumOfBytesRead
= 0;
2188 WININET_Release(hdr
);
2190 TRACE("-- %s (%lu) (bytes read: %ld)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2191 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2194 return res
== ERROR_SUCCESS
;
2197 /***********************************************************************
2198 * InternetReadFileExA (WININET.@)
2200 * Read data from an open internet file
2203 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2204 * lpBuffersOut [I/O] Buffer.
2205 * dwFlags [I] Flags. See notes.
2206 * dwContext [I] Context for callbacks.
2213 * The parameter dwFlags include zero or more of the following flags:
2214 *|IRF_ASYNC - Makes the call asynchronous.
2215 *|IRF_SYNC - Makes the call synchronous.
2216 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2217 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2219 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2222 * InternetOpenUrlA(), HttpOpenRequestA()
2224 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2225 DWORD dwFlags
, DWORD_PTR dwContext
)
2227 object_header_t
*hdr
;
2228 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2230 TRACE("(%p %p 0x%lx 0x%Ix)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2232 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2233 SetLastError(ERROR_INVALID_PARAMETER
);
2237 hdr
= get_handle_object(hFile
);
2239 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2243 if(hdr
->vtbl
->ReadFile
)
2244 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2245 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2247 WININET_Release(hdr
);
2249 TRACE("-- %s (%lu, bytes read: %ld)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2250 res
, lpBuffersOut
->dwBufferLength
);
2252 if(res
!= ERROR_SUCCESS
)
2254 return res
== ERROR_SUCCESS
;
2257 /***********************************************************************
2258 * InternetReadFileExW (WININET.@)
2260 * InternetReadFileExA()
2262 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2263 DWORD dwFlags
, DWORD_PTR dwContext
)
2265 object_header_t
*hdr
;
2266 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2268 TRACE("(%p %p 0x%lx 0x%Ix)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2270 if (!lpBuffer
|| lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2271 SetLastError(ERROR_INVALID_PARAMETER
);
2275 hdr
= get_handle_object(hFile
);
2277 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2281 if(hdr
->vtbl
->ReadFile
)
2282 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2283 dwFlags
, dwContext
);
2285 WININET_Release(hdr
);
2287 TRACE("-- %s (%lu, bytes read: %ld)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2288 res
, lpBuffer
->dwBufferLength
);
2290 if(res
!= ERROR_SUCCESS
)
2292 return res
== ERROR_SUCCESS
;
2295 static IP_ADAPTER_ADDRESSES
*get_adapters(void)
2297 ULONG err
, size
= 1024, flags
= GAA_FLAG_SKIP_ANYCAST
| GAA_FLAG_SKIP_MULTICAST
|
2298 GAA_FLAG_SKIP_DNS_SERVER
| GAA_FLAG_SKIP_FRIENDLY_NAME
;
2299 IP_ADAPTER_ADDRESSES
*tmp
, *ret
;
2301 if (!(ret
= heap_alloc( size
))) return NULL
;
2302 err
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, ret
, &size
);
2303 while (err
== ERROR_BUFFER_OVERFLOW
)
2305 if (!(tmp
= heap_realloc( ret
, size
))) break;
2307 err
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, ret
, &size
);
2309 if (err
== ERROR_SUCCESS
) return ret
;
2314 static WCHAR
*detect_proxy_autoconfig_url_dhcp(void)
2316 IP_ADAPTER_ADDRESSES
*adapters
, *ptr
;
2317 DHCPCAPI_PARAMS_ARRAY send_params
, recv_params
;
2318 DHCPCAPI_PARAMS param
;
2319 WCHAR name
[MAX_ADAPTER_NAME_LENGTH
+ 1], *ret
= NULL
;
2321 BYTE
*tmp
, *buf
= NULL
;
2323 if (!(adapters
= get_adapters())) return NULL
;
2325 memset( &send_params
, 0, sizeof(send_params
) );
2326 memset( ¶m
, 0, sizeof(param
) );
2327 param
.OptionId
= OPTION_MSFT_IE_PROXY
;
2328 recv_params
.nParams
= 1;
2329 recv_params
.Params
= ¶m
;
2331 for (ptr
= adapters
; ptr
; ptr
= ptr
->Next
)
2333 MultiByteToWideChar( CP_ACP
, 0, ptr
->AdapterName
, -1, name
, ARRAY_SIZE(name
) );
2334 TRACE( "adapter '%s' type %lu dhcpv4 enabled %d\n", wine_dbgstr_w(name
), ptr
->IfType
, ptr
->Dhcpv4Enabled
);
2336 if (ptr
->IfType
== IF_TYPE_SOFTWARE_LOOPBACK
) continue;
2337 /* FIXME: also skip adapters where DHCP is disabled */
2340 if (!(buf
= heap_alloc( size
))) goto done
;
2341 err
= DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS
, NULL
, name
, NULL
, send_params
, recv_params
,
2343 while (err
== ERROR_MORE_DATA
)
2345 if (!(tmp
= heap_realloc( buf
, size
))) goto done
;
2347 err
= DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS
, NULL
, name
, NULL
, send_params
, recv_params
,
2350 if (err
== ERROR_SUCCESS
&& param
.nBytesData
)
2352 int len
= MultiByteToWideChar( CP_ACP
, 0, (const char *)param
.Data
, param
.nBytesData
, NULL
, 0 );
2353 if ((ret
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
2355 MultiByteToWideChar( CP_ACP
, 0, (const char *)param
.Data
, param
.nBytesData
, ret
, len
);
2358 TRACE("returning %s\n", debugstr_w(ret
));
2365 heap_free( adapters
);
2369 static char *get_computer_name( COMPUTER_NAME_FORMAT format
)
2374 GetComputerNameExA( format
, NULL
, &size
);
2375 if (GetLastError() != ERROR_MORE_DATA
) return NULL
;
2376 if (!(ret
= heap_alloc( size
))) return NULL
;
2377 if (!GetComputerNameExA( format
, ret
, &size
))
2385 static BOOL
is_domain_suffix( const char *domain
, const char *suffix
)
2387 int len_domain
= strlen( domain
), len_suffix
= strlen( suffix
);
2389 if (len_suffix
> len_domain
) return FALSE
;
2390 if (!stricmp( domain
+ len_domain
- len_suffix
, suffix
)) return TRUE
;
2394 static int reverse_lookup( const struct addrinfo
*ai
, char *hostname
, size_t len
)
2396 return getnameinfo( ai
->ai_addr
, ai
->ai_addrlen
, hostname
, len
, NULL
, 0, 0 );
2399 static WCHAR
*build_wpad_url( const char *hostname
, const struct addrinfo
*ai
)
2401 char name
[NI_MAXHOST
];
2405 while (ai
&& ai
->ai_family
!= AF_INET
&& ai
->ai_family
!= AF_INET6
) ai
= ai
->ai_next
;
2406 if (!ai
) return NULL
;
2408 if (!reverse_lookup( ai
, name
, sizeof(name
) )) hostname
= name
;
2410 len
= lstrlenW( L
"http://" ) + strlen( hostname
) + lstrlenW( L
"/wpad.dat" );
2411 if (!(ret
= p
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) return NULL
;
2412 lstrcpyW( p
, L
"http://" );
2413 p
+= lstrlenW( L
"http://" );
2414 while (*hostname
) { *p
++ = *hostname
++; }
2415 lstrcpyW( p
, L
"/wpad.dat" );
2419 static WCHAR
*detect_proxy_autoconfig_url_dns(void)
2421 char *fqdn
, *domain
, *p
;
2424 if (!(fqdn
= get_computer_name( ComputerNamePhysicalDnsFullyQualified
))) return NULL
;
2425 if (!(domain
= get_computer_name( ComputerNamePhysicalDnsDomain
)))
2431 while ((p
= strchr( p
, '.' )) && is_domain_suffix( p
+ 1, domain
))
2434 struct addrinfo
*ai
, hints
;
2437 if (!(name
= heap_alloc( sizeof("wpad") + strlen(p
) )))
2440 heap_free( domain
);
2443 strcpy( name
, "wpad" );
2445 memset( &hints
, 0, sizeof(hints
) );
2446 hints
.ai_flags
= AI_ALL
| AI_DNS_ONLY
;
2447 hints
.ai_family
= AF_UNSPEC
;
2448 res
= getaddrinfo( name
, NULL
, &hints
, &ai
);
2451 ret
= build_wpad_url( name
, ai
);
2455 TRACE("returning %s\n", debugstr_w(ret
));
2463 heap_free( domain
);
2468 static WCHAR
*get_proxy_autoconfig_url(void)
2470 WCHAR
*ret
= detect_proxy_autoconfig_url_dhcp();
2471 if (!ret
) ret
= detect_proxy_autoconfig_url_dns();
2475 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2477 /* FIXME: This function currently handles more options than it should. Options requiring
2478 * proper handles should be moved to proper functions */
2480 case INTERNET_OPTION_HTTP_VERSION
:
2481 if (*size
< sizeof(HTTP_VERSION_INFO
))
2482 return ERROR_INSUFFICIENT_BUFFER
;
2485 * Presently hardcoded to 1.1
2487 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2488 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2489 *size
= sizeof(HTTP_VERSION_INFO
);
2491 return ERROR_SUCCESS
;
2493 case INTERNET_OPTION_CONNECTED_STATE
:
2494 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2496 if (*size
< sizeof(ULONG
))
2497 return ERROR_INSUFFICIENT_BUFFER
;
2499 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2500 *size
= sizeof(ULONG
);
2502 return ERROR_SUCCESS
;
2504 case INTERNET_OPTION_PROXY
: {
2508 TRACE("Getting global proxy info\n");
2509 memset(&ai
, 0, sizeof(appinfo_t
));
2510 INTERNET_ConfigureProxy(&ai
);
2512 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2513 APPINFO_Destroy(&ai
.hdr
);
2517 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2518 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2520 if (*size
< sizeof(ULONG
))
2521 return ERROR_INSUFFICIENT_BUFFER
;
2523 *(ULONG
*)buffer
= max_conns
;
2524 *size
= sizeof(ULONG
);
2526 return ERROR_SUCCESS
;
2528 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2529 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2531 if (*size
< sizeof(ULONG
))
2532 return ERROR_INSUFFICIENT_BUFFER
;
2534 *(ULONG
*)buffer
= max_1_0_conns
;
2535 *size
= sizeof(ULONG
);
2537 return ERROR_SUCCESS
;
2539 case INTERNET_OPTION_SECURITY_FLAGS
:
2540 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2541 return ERROR_SUCCESS
;
2543 case INTERNET_OPTION_VERSION
: {
2544 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2546 TRACE("INTERNET_OPTION_VERSION\n");
2548 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2549 return ERROR_INSUFFICIENT_BUFFER
;
2551 memcpy(buffer
, &info
, sizeof(info
));
2552 *size
= sizeof(info
);
2554 return ERROR_SUCCESS
;
2557 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2559 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2560 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2561 DWORD res
= ERROR_SUCCESS
, i
;
2565 TRACE("Getting global proxy info\n");
2566 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2569 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2571 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2573 return ERROR_INSUFFICIENT_BUFFER
;
2576 url
= get_proxy_autoconfig_url();
2578 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2579 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2580 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2582 switch (optionW
->dwOption
) {
2583 case INTERNET_PER_CONN_FLAGS
:
2585 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2587 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2589 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2590 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2593 case INTERNET_PER_CONN_PROXY_SERVER
:
2595 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2597 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2600 case INTERNET_PER_CONN_PROXY_BYPASS
:
2602 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2604 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2607 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2609 optionW
->Value
.pszValue
= NULL
;
2611 optionW
->Value
.pszValue
= heap_strdupW(url
);
2613 optionA
->Value
.pszValue
= heap_strdupWtoA(url
);
2616 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2617 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2620 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2621 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2622 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2623 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2624 FIXME("Unhandled dwOption %ld\n", optionW
->dwOption
);
2625 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2629 FIXME("Unknown dwOption %ld\n", optionW
->dwOption
);
2630 res
= ERROR_INVALID_PARAMETER
;
2639 case INTERNET_OPTION_REQUEST_FLAGS
:
2640 case INTERNET_OPTION_USER_AGENT
:
2642 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2643 case INTERNET_OPTION_POLICY
:
2644 return ERROR_INVALID_PARAMETER
;
2645 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2646 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2648 if (*size
< sizeof(ULONG
))
2649 return ERROR_INSUFFICIENT_BUFFER
;
2651 *(ULONG
*)buffer
= connect_timeout
;
2652 *size
= sizeof(ULONG
);
2654 return ERROR_SUCCESS
;
2657 FIXME("Stub for %ld\n", option
);
2658 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2661 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2664 case INTERNET_OPTION_CONTEXT_VALUE
:
2666 return ERROR_INVALID_PARAMETER
;
2668 if (*size
< sizeof(DWORD_PTR
)) {
2669 *size
= sizeof(DWORD_PTR
);
2670 return ERROR_INSUFFICIENT_BUFFER
;
2673 return ERROR_INVALID_PARAMETER
;
2675 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2676 *size
= sizeof(DWORD_PTR
);
2677 return ERROR_SUCCESS
;
2679 case INTERNET_OPTION_REQUEST_FLAGS
:
2680 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2681 *size
= sizeof(DWORD
);
2682 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2684 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2685 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2686 WARN("Called on global option %lu\n", option
);
2687 return ERROR_INTERNET_INVALID_OPERATION
;
2690 /* FIXME: we shouldn't call it here */
2691 return query_global_option(option
, buffer
, size
, unicode
);
2694 /***********************************************************************
2695 * InternetQueryOptionW (WININET.@)
2697 * Queries an options on the specified handle
2704 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2705 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2707 object_header_t
*hdr
;
2708 DWORD res
= ERROR_INVALID_HANDLE
;
2710 TRACE("%p %ld %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2713 hdr
= get_handle_object(hInternet
);
2715 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2716 WININET_Release(hdr
);
2719 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2722 if(res
!= ERROR_SUCCESS
)
2724 return res
== ERROR_SUCCESS
;
2727 /***********************************************************************
2728 * InternetQueryOptionA (WININET.@)
2730 * Queries an options on the specified handle
2737 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2738 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2740 object_header_t
*hdr
;
2741 DWORD res
= ERROR_INVALID_HANDLE
;
2743 TRACE("%p %ld %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2746 hdr
= get_handle_object(hInternet
);
2748 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2749 WININET_Release(hdr
);
2752 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2755 if(res
!= ERROR_SUCCESS
)
2757 return res
== ERROR_SUCCESS
;
2760 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2763 case INTERNET_OPTION_SETTINGS_CHANGED
:
2764 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2765 collect_connections(COLLECT_CONNECTIONS
);
2766 return ERROR_SUCCESS
;
2767 case INTERNET_OPTION_CALLBACK
:
2768 WARN("Not settable option %lu\n", option
);
2769 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2770 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2771 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2772 WARN("Called on global option %lu\n", option
);
2773 return ERROR_INTERNET_INVALID_OPERATION
;
2774 case INTERNET_OPTION_REFRESH
:
2775 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2778 return ERROR_INTERNET_INVALID_OPTION
;
2781 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2784 case INTERNET_OPTION_CALLBACK
:
2785 WARN("Not global option %lu\n", option
);
2786 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2788 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2789 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2791 if(size
!= sizeof(max_conns
))
2792 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2794 return ERROR_BAD_ARGUMENTS
;
2796 max_conns
= *(ULONG
*)buf
;
2797 return ERROR_SUCCESS
;
2799 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2800 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2802 if(size
!= sizeof(max_1_0_conns
))
2803 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2805 return ERROR_BAD_ARGUMENTS
;
2807 max_1_0_conns
= *(ULONG
*)buf
;
2808 return ERROR_SUCCESS
;
2810 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2811 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2813 if(size
!= sizeof(connect_timeout
))
2814 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2816 return ERROR_BAD_ARGUMENTS
;
2818 connect_timeout
= *(ULONG
*)buf
;
2819 return ERROR_SUCCESS
;
2821 case INTERNET_OPTION_SUPPRESS_BEHAVIOR
:
2822 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2824 if(size
!= sizeof(ULONG
))
2825 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2827 FIXME("%08lx\n", *(ULONG
*)buf
);
2828 return ERROR_SUCCESS
;
2831 return INET_SetOption(NULL
, option
, buf
, size
);
2834 /***********************************************************************
2835 * InternetSetOptionW (WININET.@)
2837 * Sets an options on the specified handle
2844 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2845 LPVOID lpBuffer
, DWORD dwBufferLength
)
2847 object_header_t
*lpwhh
;
2851 TRACE("(%p %ld %p %ld)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2853 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2855 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2857 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2859 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2861 WININET_Release(lpwhh
);
2863 if(res
!= ERROR_SUCCESS
)
2866 return res
== ERROR_SUCCESS
;
2871 case INTERNET_OPTION_HTTP_VERSION
:
2873 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2874 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2877 case INTERNET_OPTION_ERROR_MASK
:
2880 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2882 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2883 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2884 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2885 SetLastError(ERROR_INVALID_PARAMETER
);
2887 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2888 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2891 TRACE("INTERNET_OPTION_ERROR_MASK: %lx\n", *(ULONG
*)lpBuffer
);
2892 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2896 case INTERNET_OPTION_PROXY
:
2898 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2900 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2902 SetLastError(ERROR_INVALID_PARAMETER
);
2907 EnterCriticalSection( &WININET_cs
);
2908 free_global_proxy();
2909 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2912 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2914 global_proxy
->proxyEnabled
= 1;
2915 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2916 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2920 global_proxy
->proxyEnabled
= 0;
2921 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2924 LeaveCriticalSection( &WININET_cs
);
2928 /* In general, each type of object should handle
2929 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2930 * get silently dropped.
2932 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2933 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2938 case INTERNET_OPTION_CODEPAGE
:
2940 ULONG codepage
= *(ULONG
*)lpBuffer
;
2941 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n", codepage
);
2944 case INTERNET_OPTION_REQUEST_PRIORITY
:
2946 ULONG priority
= *(ULONG
*)lpBuffer
;
2947 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n", priority
);
2950 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2952 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2953 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n", connecttimeout
);
2956 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2958 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2959 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n", receivetimeout
);
2962 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2963 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2965 case INTERNET_OPTION_END_BROWSER_SESSION
:
2966 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2968 free_authorization_cache();
2970 case INTERNET_OPTION_CONNECTED_STATE
:
2971 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2973 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2974 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2976 case INTERNET_OPTION_IGNORE_OFFLINE
:
2977 FIXME("Option INTERNET_OPTION_IGNORE_OFFLINE: STUB\n");
2979 case INTERNET_OPTION_SEND_TIMEOUT
:
2980 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2981 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2983 ULONG timeout
= *(ULONG
*)lpBuffer
;
2984 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %ld\n", timeout
);
2987 case INTERNET_OPTION_CONNECT_RETRIES
:
2989 ULONG retries
= *(ULONG
*)lpBuffer
;
2990 FIXME("INTERNET_OPTION_CONNECT_RETRIES %ld\n", retries
);
2993 case INTERNET_OPTION_CONTEXT_VALUE
:
2997 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3000 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
3002 SetLastError(ERROR_INVALID_PARAMETER
);
3006 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
3009 case INTERNET_OPTION_SECURITY_FLAGS
:
3010 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
3012 case INTERNET_OPTION_DISABLE_AUTODIAL
:
3013 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
3015 case INTERNET_OPTION_HTTP_DECODING
:
3018 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3021 if (!lpBuffer
|| dwBufferLength
!= sizeof(BOOL
))
3023 SetLastError(ERROR_INVALID_PARAMETER
);
3027 lpwhh
->decoding
= *(BOOL
*)lpBuffer
;
3029 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
3030 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
3031 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3034 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
3035 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
3036 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3039 case INTERNET_OPTION_CODEPAGE_PATH
:
3040 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
3041 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3044 case INTERNET_OPTION_CODEPAGE_EXTRA
:
3045 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
3046 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3049 case INTERNET_OPTION_IDN
:
3050 FIXME("INTERNET_OPTION_IDN; STUB\n");
3051 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3054 case INTERNET_OPTION_POLICY
:
3055 SetLastError(ERROR_INVALID_PARAMETER
);
3058 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3059 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
3064 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
3066 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
3067 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
3069 switch (option
->dwOption
) {
3070 case INTERNET_PER_CONN_PROXY_SERVER
:
3071 heap_free(pi
.proxy
);
3072 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
3075 case INTERNET_PER_CONN_FLAGS
:
3076 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
3077 pi
.proxyEnabled
= 1;
3080 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
3081 FIXME("Unhandled flags: 0x%lx\n", option
->Value
.dwValue
);
3082 pi
.proxyEnabled
= 0;
3086 case INTERNET_PER_CONN_PROXY_BYPASS
:
3087 heap_free(pi
.proxyBypass
);
3088 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
3091 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3092 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3093 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3094 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3095 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3096 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3097 FIXME("Unhandled dwOption %ld\n", option
->dwOption
);
3101 FIXME("Unknown dwOption %ld\n", option
->dwOption
);
3102 SetLastError(ERROR_INVALID_PARAMETER
);
3107 if ((res
= INTERNET_SaveProxySettings(&pi
)))
3112 ret
= (res
== ERROR_SUCCESS
);
3116 FIXME("Option %ld STUB\n",dwOption
);
3117 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3123 WININET_Release( lpwhh
);
3129 /***********************************************************************
3130 * InternetSetOptionA (WININET.@)
3132 * Sets an options on the specified handle.
3139 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3140 LPVOID lpBuffer
, DWORD dwBufferLength
)
3148 case INTERNET_OPTION_PROXY
:
3150 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3151 LPINTERNET_PROXY_INFOW piw
;
3152 DWORD proxlen
, prbylen
;
3155 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3156 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3157 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3158 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3159 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3160 piw
->dwAccessType
= pi
->dwAccessType
;
3161 prox
= (LPWSTR
) &piw
[1];
3162 prby
= &prox
[proxlen
+1];
3163 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3164 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3165 piw
->lpszProxy
= prox
;
3166 piw
->lpszProxyBypass
= prby
;
3169 case INTERNET_OPTION_USER_AGENT
:
3170 case INTERNET_OPTION_USERNAME
:
3171 case INTERNET_OPTION_PASSWORD
:
3172 case INTERNET_OPTION_PROXY_USERNAME
:
3173 case INTERNET_OPTION_PROXY_PASSWORD
:
3174 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3175 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3176 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3178 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3180 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3181 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3182 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3183 wbuffer
= heap_alloc(wlen
);
3186 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3187 if (listA
->pszConnection
)
3189 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3190 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3191 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3194 listW
->pszConnection
= NULL
;
3195 listW
->dwOptionCount
= listA
->dwOptionCount
;
3196 listW
->dwOptionError
= listA
->dwOptionError
;
3197 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3199 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3200 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3201 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3203 optW
->dwOption
= optA
->dwOption
;
3205 switch (optA
->dwOption
) {
3206 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3207 case INTERNET_PER_CONN_PROXY_BYPASS
:
3208 case INTERNET_PER_CONN_PROXY_SERVER
:
3209 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3210 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3211 if (optA
->Value
.pszValue
)
3213 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3214 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3215 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3218 optW
->Value
.pszValue
= NULL
;
3220 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3221 case INTERNET_PER_CONN_FLAGS
:
3222 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3223 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3225 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3226 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3229 WARN("Unknown PER_CONN dwOption: %ld, guessing at conversion to Wide\n", optA
->dwOption
);
3230 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3238 wlen
= dwBufferLength
;
3241 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3243 if( lpBuffer
!= wbuffer
)
3245 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3247 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3249 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3250 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3251 switch (opt
->dwOption
) {
3252 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3253 case INTERNET_PER_CONN_PROXY_BYPASS
:
3254 case INTERNET_PER_CONN_PROXY_SERVER
:
3255 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3256 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3257 heap_free( opt
->Value
.pszValue
);
3263 heap_free( list
->pOptions
);
3265 heap_free( wbuffer
);
3272 /***********************************************************************
3273 * InternetSetOptionExA (WININET.@)
3275 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3276 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3278 FIXME("Flags %08lx ignored\n", dwFlags
);
3279 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3282 /***********************************************************************
3283 * InternetSetOptionExW (WININET.@)
3285 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3286 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3288 FIXME("Flags %08lx ignored\n", dwFlags
);
3289 if( dwFlags
& ~ISO_VALID_FLAGS
)
3291 SetLastError( ERROR_INVALID_PARAMETER
);
3294 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3297 static const WCHAR WININET_wkday
[7][4] =
3298 { L
"Sun", L
"Mon", L
"Tue", L
"Wed",
3299 L
"Thu", L
"Fri", L
"Sat"};
3300 static const WCHAR WININET_month
[12][4] =
3301 { L
"Jan", L
"Feb", L
"Mar", L
"Apr",
3302 L
"May", L
"Jun", L
"Jul", L
"Aug",
3303 L
"Sep", L
"Oct", L
"Nov", L
"Dec"};
3305 static inline BOOL
is_time_digit(const WCHAR c
)
3307 return c
>= '0' && c
<= '9';
3310 /***********************************************************************
3311 * InternetTimeFromSystemTimeA (WININET.@)
3313 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3316 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3318 TRACE( "%p 0x%08lx %p 0x%08lx\n", time
, format
, string
, size
);
3320 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3322 SetLastError(ERROR_INVALID_PARAMETER
);
3326 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3328 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3332 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3333 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3338 /***********************************************************************
3339 * InternetTimeFromSystemTimeW (WININET.@)
3341 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3343 TRACE( "%p 0x%08lx %p 0x%08lx\n", time
, format
, string
, size
);
3345 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3347 SetLastError(ERROR_INVALID_PARAMETER
);
3351 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3353 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3357 swprintf( string
, size
, L
"%s, %02d %s %4d %02d:%02d:%02d GMT",
3358 WININET_wkday
[time
->wDayOfWeek
],
3360 WININET_month
[time
->wMonth
- 1],
3369 /***********************************************************************
3370 * InternetTimeToSystemTimeA (WININET.@)
3372 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3377 TRACE( "%s %p 0x%08lx\n", debugstr_a(string
), time
, reserved
);
3379 stringW
= heap_strdupAtoW(string
);
3382 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3383 heap_free( stringW
);
3388 /***********************************************************************
3389 * InternetTimeToSystemTimeW (WININET.@)
3391 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3394 const WCHAR
*s
= string
;
3397 TRACE( "%s %p 0x%08lx\n", debugstr_w(string
), time
, reserved
);
3399 if (!string
|| !time
) return FALSE
;
3401 /* Windows does this too */
3402 GetSystemTime( time
);
3404 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3405 * a SYSTEMTIME structure.
3408 while (*s
&& !iswalpha(*s
) && !is_time_digit(*s
)) s
++;
3409 if (*s
== '\0') return TRUE
;
3410 time
->wDayOfWeek
= 7;
3414 if (s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3415 for (i
= 0; i
< 7; i
++)
3417 if (!wcsnicmp(WININET_wkday
[i
], s
, 3))
3419 time
->wDayOfWeek
= i
;
3424 else if (is_time_digit(*s
))
3426 time
->wDayOfWeek
= wcstol(s
, &end
, 10);
3429 if (time
->wDayOfWeek
> 6) return TRUE
;
3431 while (*s
&& !is_time_digit(*s
)) s
++;
3432 time
->wDay
= wcstol( s
, &end
, 10 );
3435 while (*s
&& !iswalpha(*s
) && !is_time_digit(*s
)) s
++;
3436 if (*s
== '\0') return TRUE
;
3441 if (s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3442 for (i
= 0; i
< 12; i
++)
3444 if (!wcsnicmp(WININET_month
[i
], s
, 3))
3446 time
->wMonth
= i
+ 1;
3451 else if (is_time_digit(*s
))
3453 time
->wMonth
= wcstol(s
, &end
, 10);
3456 if (time
->wMonth
== 0) return TRUE
;
3458 while (*s
&& !is_time_digit(*s
)) s
++;
3459 if (*s
== '\0') return TRUE
;
3460 time
->wYear
= wcstol( s
, &end
, 10 );
3463 while (*s
&& !is_time_digit(*s
)) s
++;
3464 if (*s
== '\0') return TRUE
;
3465 time
->wHour
= wcstol( s
, &end
, 10 );
3468 while (*s
&& !is_time_digit(*s
)) s
++;
3469 if (*s
== '\0') return TRUE
;
3470 time
->wMinute
= wcstol( s
, &end
, 10 );
3473 while (*s
&& !is_time_digit(*s
)) s
++;
3474 if (*s
== '\0') return TRUE
;
3475 time
->wSecond
= wcstol( s
, &end
, 10 );
3478 time
->wMilliseconds
= 0;
3482 /***********************************************************************
3483 * InternetCheckConnectionW (WININET.@)
3485 * Pings a requested host to check internet connection
3488 * TRUE on success and FALSE on failure. If a failure then
3489 * ERROR_NOT_CONNECTED is placed into GetLastError
3492 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3495 * this is a kludge which runs the resident ping program and reads the output.
3497 * Anyone have a better idea?
3501 static const CHAR ping
[] = "ping -c 1 ";
3502 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3504 DWORD len
, host_len
;
3508 FIXME("(%s %lx %lx)\n", debugstr_w(lpszUrl
), dwFlags
, dwReserved
);
3511 * Crack or set the Address
3513 if (lpszUrl
== NULL
)
3516 * According to the doc we are supposed to use the ip for the next
3517 * server in the WnInet internal server database. I have
3518 * no idea what that is or how to get it.
3520 * So someone needs to implement this.
3522 FIXME("Unimplemented with URL of NULL\n");
3527 URL_COMPONENTSW components
= {sizeof(components
)};
3529 components
.dwHostNameLength
= 1;
3531 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3534 host
= components
.lpszHostName
;
3535 host_len
= components
.dwHostNameLength
;
3536 port
= components
.nPort
;
3537 TRACE("host name: %s port: %d\n",debugstr_wn(host
, host_len
), port
);
3540 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3542 struct sockaddr_storage saddr
;
3543 int sa_len
= sizeof(saddr
);
3548 host_z
= heap_strndupW(host
, host_len
);
3552 b
= GetAddress(host_z
, port
, (struct sockaddr
*)&saddr
, &sa_len
, NULL
);
3557 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3560 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3568 * Build our ping command
3572 len
= WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, NULL
, 0, NULL
, NULL
);
3573 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
)+1);
3574 strcpy(command
, ping
);
3575 WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, command
+sizeof(ping
)-1, len
, NULL
, NULL
);
3576 strcpy(command
+sizeof(ping
)-1+len
, redirect
);
3578 TRACE("Ping command is : %s\n",command
);
3580 status
= system(command
);
3581 heap_free( command
);
3583 TRACE("Ping returned a code of %i\n",status
);
3585 /* Ping return code of 0 indicates success */
3592 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3598 /***********************************************************************
3599 * InternetCheckConnectionA (WININET.@)
3601 * Pings a requested host to check internet connection
3604 * TRUE on success and FALSE on failure. If a failure then
3605 * ERROR_NOT_CONNECTED is placed into GetLastError
3608 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3614 url
= heap_strdupAtoW(lpszUrl
);
3619 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3626 /**********************************************************
3627 * INTERNET_InternetOpenUrlW (internal)
3632 * handle of connection or NULL on failure
3634 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3635 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3637 URL_COMPONENTSW urlComponents
= { sizeof(urlComponents
) };
3638 WCHAR
*host
, *user
= NULL
, *pass
= NULL
, *path
;
3639 HINTERNET client
= NULL
, client1
= NULL
;
3642 TRACE("(%p, %s, %s, %08lx, %08lx, %08Ix)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3643 dwHeadersLength
, dwFlags
, dwContext
);
3645 urlComponents
.dwHostNameLength
= 1;
3646 urlComponents
.dwUserNameLength
= 1;
3647 urlComponents
.dwPasswordLength
= 1;
3648 urlComponents
.dwUrlPathLength
= 1;
3649 urlComponents
.dwExtraInfoLength
= 1;
3650 if(!InternetCrackUrlW(lpszUrl
, lstrlenW(lpszUrl
), 0, &urlComponents
))
3653 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
3654 urlComponents
.dwExtraInfoLength
)
3656 assert(urlComponents
.lpszUrlPath
+ urlComponents
.dwUrlPathLength
== urlComponents
.lpszExtraInfo
);
3657 urlComponents
.dwUrlPathLength
+= urlComponents
.dwExtraInfoLength
;
3660 host
= heap_strndupW(urlComponents
.lpszHostName
, urlComponents
.dwHostNameLength
);
3661 path
= heap_strndupW(urlComponents
.lpszUrlPath
, urlComponents
.dwUrlPathLength
);
3662 if(urlComponents
.dwUserNameLength
)
3663 user
= heap_strndupW(urlComponents
.lpszUserName
, urlComponents
.dwUserNameLength
);
3664 if(urlComponents
.dwPasswordLength
)
3665 pass
= heap_strndupW(urlComponents
.lpszPassword
, urlComponents
.dwPasswordLength
);
3667 switch(urlComponents
.nScheme
) {
3668 case INTERNET_SCHEME_FTP
:
3669 client
= FTP_Connect(hIC
, host
, urlComponents
.nPort
,
3670 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
);
3673 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3674 if(client1
== NULL
) {
3675 InternetCloseHandle(client
);
3680 case INTERNET_SCHEME_HTTP
:
3681 case INTERNET_SCHEME_HTTPS
: {
3682 LPCWSTR accept
[2] = { L
"*/*", NULL
};
3684 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3686 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3687 res
= HTTP_Connect(hIC
, host
, urlComponents
.nPort
,
3688 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3689 if(res
!= ERROR_SUCCESS
) {
3690 INTERNET_SetLastError(res
);
3694 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3695 if(client1
== NULL
) {
3696 InternetCloseHandle(client
);
3699 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3700 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3701 GetLastError() != ERROR_IO_PENDING
) {
3702 InternetCloseHandle(client1
);
3707 case INTERNET_SCHEME_GOPHER
:
3708 /* gopher doesn't seem to be implemented in wine, but it's supposed
3709 * to be supported by InternetOpenUrlA. */
3711 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3715 TRACE(" %p <--\n", client1
);
3724 /**********************************************************
3725 * InternetOpenUrlW (WININET.@)
3730 * handle of connection or NULL on failure
3741 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3743 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3745 TRACE("%p\n", task
->hdr
.hdr
);
3747 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3748 task
->headers_len
, task
->flags
, task
->context
);
3749 heap_free(task
->url
);
3750 heap_free(task
->headers
);
3753 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3754 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3756 HINTERNET ret
= NULL
;
3757 appinfo_t
*hIC
= NULL
;
3759 if (TRACE_ON(wininet
)) {
3760 TRACE("(%p, %s, %s, %08lx, %08lx, %08Ix)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3761 dwHeadersLength
, dwFlags
, dwContext
);
3763 dump_INTERNET_FLAGS(dwFlags
);
3768 SetLastError(ERROR_INVALID_PARAMETER
);
3772 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3773 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3774 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3778 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3779 open_url_task_t
*task
;
3781 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3782 task
->url
= heap_strdupW(lpszUrl
);
3783 task
->headers
= heap_strdupW(lpszHeaders
);
3784 task
->headers_len
= dwHeadersLength
;
3785 task
->flags
= dwFlags
;
3786 task
->context
= dwContext
;
3788 INTERNET_AsyncCall(&task
->hdr
);
3789 SetLastError(ERROR_IO_PENDING
);
3791 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3796 WININET_Release( &hIC
->hdr
);
3797 TRACE(" %p <--\n", ret
);
3802 /**********************************************************
3803 * InternetOpenUrlA (WININET.@)
3808 * handle of connection or NULL on failure
3810 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3811 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3813 HINTERNET rc
= NULL
;
3814 LPWSTR szUrl
= NULL
;
3815 WCHAR
*headers
= NULL
;
3820 szUrl
= heap_strdupAtoW(lpszUrl
);
3826 headers
= heap_strndupAtoW(lpszHeaders
, dwHeadersLength
, &dwHeadersLength
);
3833 rc
= InternetOpenUrlW(hInternet
, szUrl
, headers
, dwHeadersLength
, dwFlags
, dwContext
);
3841 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3843 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3847 lpwite
->dwError
= 0;
3848 lpwite
->response
[0] = '\0';
3851 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3860 /***********************************************************************
3861 * INTERNET_SetLastError (internal)
3863 * Set last thread specific error
3868 void INTERNET_SetLastError(DWORD dwError
)
3870 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3873 lpwite
= INTERNET_AllocThreadError();
3875 SetLastError(dwError
);
3877 lpwite
->dwError
= dwError
;
3881 /***********************************************************************
3882 * INTERNET_GetLastError (internal)
3884 * Get last thread specific error
3889 DWORD
INTERNET_GetLastError(void)
3891 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3892 if (!lpwite
) return 0;
3893 /* TlsGetValue clears last error, so set it again here */
3894 SetLastError(lpwite
->dwError
);
3895 return lpwite
->dwError
;
3899 /***********************************************************************
3900 * INTERNET_WorkerThreadFunc (internal)
3902 * Worker thread execution function
3907 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3909 task_header_t
*task
= lpvParam
;
3914 WININET_Release(task
->hdr
);
3917 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3919 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3920 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3925 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3927 task_header_t
*task
;
3929 task
= heap_alloc(size
);
3933 task
->hdr
= WININET_AddRef(hdr
);
3938 /***********************************************************************
3939 * INTERNET_AsyncCall (internal)
3941 * Retrieves work request from queue
3946 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3952 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3956 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3958 return ERROR_SUCCESS
;
3962 /***********************************************************************
3963 * INTERNET_GetResponseBuffer (internal)
3968 LPSTR
INTERNET_GetResponseBuffer(void)
3970 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3972 lpwite
= INTERNET_AllocThreadError();
3974 return lpwite
->response
;
3977 /**********************************************************
3978 * InternetQueryDataAvailable (WININET.@)
3980 * Determines how much data is available to be read.
3983 * TRUE on success, FALSE if an error occurred. If
3984 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3985 * no data is presently available, FALSE is returned with
3986 * the last error ERROR_IO_PENDING; a callback with status
3987 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3988 * data is available.
3990 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3991 LPDWORD lpdwNumberOfBytesAvailable
,
3992 DWORD dwFlags
, DWORD_PTR dwContext
)
3994 object_header_t
*hdr
;
3997 TRACE("(%p %p %lx %Ix)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3999 hdr
= get_handle_object( hFile
);
4001 SetLastError(ERROR_INVALID_HANDLE
);
4005 if(hdr
->vtbl
->QueryDataAvailable
) {
4006 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
4008 WARN("wrong handle\n");
4009 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4012 WININET_Release(hdr
);
4014 if(res
!= ERROR_SUCCESS
)
4016 return res
== ERROR_SUCCESS
;
4019 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
4021 req_file_t
*req_file
;
4023 req_file
= heap_alloc_zero(sizeof(*req_file
));
4025 return ERROR_NOT_ENOUGH_MEMORY
;
4029 req_file
->file_name
= heap_strdupW(file_name
);
4030 if(!req_file
->file_name
) {
4031 heap_free(req_file
);
4032 return ERROR_NOT_ENOUGH_MEMORY
;
4035 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
4036 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
4037 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
4038 req_file_release(req_file
);
4039 return GetLastError();
4043 return ERROR_SUCCESS
;
4046 void req_file_release(req_file_t
*req_file
)
4048 if(InterlockedDecrement(&req_file
->ref
))
4051 if(!req_file
->is_committed
)
4052 DeleteFileW(req_file
->file_name
);
4053 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
4054 CloseHandle(req_file
->file_handle
);
4055 heap_free(req_file
->file_name
);
4056 heap_free(req_file
->url
);
4057 heap_free(req_file
);
4060 /***********************************************************************
4061 * InternetLockRequestFile (WININET.@)
4063 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
4065 req_file_t
*req_file
= NULL
;
4066 object_header_t
*hdr
;
4069 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
4071 hdr
= get_handle_object(hInternet
);
4073 SetLastError(ERROR_INVALID_HANDLE
);
4077 if(hdr
->vtbl
->LockRequestFile
) {
4078 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
4080 WARN("wrong handle\n");
4081 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4084 WININET_Release(hdr
);
4086 *lphLockReqHandle
= req_file
;
4087 if(res
!= ERROR_SUCCESS
)
4089 return res
== ERROR_SUCCESS
;
4092 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
4094 TRACE("(%p)\n", hLockHandle
);
4096 req_file_release(hLockHandle
);
4101 /***********************************************************************
4102 * InternetAutodial (WININET.@)
4104 * On windows this function is supposed to dial the default internet
4105 * connection. We don't want to have Wine dial out to the internet so
4106 * we return TRUE by default. It might be nice to check if we are connected.
4113 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
4117 /* Tell that we are connected to the internet. */
4121 /***********************************************************************
4122 * InternetAutodialHangup (WININET.@)
4124 * Hangs up a connection made with InternetAutodial
4133 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
4137 /* we didn't dial, we don't disconnect */
4141 /***********************************************************************
4142 * InternetCombineUrlA (WININET.@)
4144 * Combine a base URL with a relative URL
4152 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
4153 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4158 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4160 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4161 dwFlags
^= ICU_NO_ENCODE
;
4162 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4167 /***********************************************************************
4168 * InternetCombineUrlW (WININET.@)
4170 * Combine a base URL with a relative URL
4178 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4179 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4184 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4186 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4187 dwFlags
^= ICU_NO_ENCODE
;
4188 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4193 /* max port num is 65535 => 5 digits */
4194 #define MAX_WORD_DIGITS 5
4196 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4197 (url)->dw##component##Length : lstrlenW((url)->lpsz##component))
4198 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4199 (url)->dw##component##Length : strlen((url)->lpsz##component))
4201 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4203 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4204 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4206 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4207 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4209 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4210 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4212 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4213 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4216 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4222 /* opaque urls do not fit into the standard url hierarchy and don't have
4223 * two following slashes */
4224 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4226 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4227 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4228 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4229 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4230 (nScheme
!= INTERNET_SCHEME_FILE
);
4233 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4236 if (scheme
< INTERNET_SCHEME_FIRST
)
4238 index
= scheme
- INTERNET_SCHEME_FIRST
;
4239 if (index
>= ARRAY_SIZE(url_schemes
))
4241 return url_schemes
[index
];
4244 /* we can calculate using ansi strings because we're just
4245 * calculating string length, not size
4247 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4248 LPDWORD lpdwUrlLength
)
4250 INTERNET_SCHEME nScheme
;
4254 if (lpUrlComponents
->lpszScheme
)
4256 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4257 *lpdwUrlLength
+= dwLen
;
4258 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4264 nScheme
= lpUrlComponents
->nScheme
;
4266 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4267 nScheme
= INTERNET_SCHEME_HTTP
;
4268 scheme
= INTERNET_GetSchemeString(nScheme
);
4269 *lpdwUrlLength
+= lstrlenW(scheme
);
4272 (*lpdwUrlLength
)++; /* ':' */
4273 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4274 *lpdwUrlLength
+= strlen("//");
4276 if (lpUrlComponents
->lpszUserName
)
4278 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4279 *lpdwUrlLength
+= strlen("@");
4283 if (lpUrlComponents
->lpszPassword
)
4285 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4290 if (lpUrlComponents
->lpszPassword
)
4292 *lpdwUrlLength
+= strlen(":");
4293 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4296 if (lpUrlComponents
->lpszHostName
)
4298 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4300 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4302 WCHAR port
[MAX_WORD_DIGITS
+ 1];
4304 _ltow(lpUrlComponents
->nPort
, port
, 10);
4305 *lpdwUrlLength
+= lstrlenW(port
);
4306 *lpdwUrlLength
+= strlen(":");
4309 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4310 (*lpdwUrlLength
)++; /* '/' */
4313 if (lpUrlComponents
->lpszUrlPath
)
4314 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4316 if (lpUrlComponents
->lpszExtraInfo
)
4317 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4322 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4326 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4328 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4329 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4330 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4331 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4332 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4333 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4334 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4335 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4336 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4338 if (lpUrlComponents
->lpszScheme
)
4340 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4341 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4342 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4343 -1, urlCompW
->lpszScheme
, len
);
4346 if (lpUrlComponents
->lpszHostName
)
4348 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4349 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4350 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4351 -1, urlCompW
->lpszHostName
, len
);
4354 if (lpUrlComponents
->lpszUserName
)
4356 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4357 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4358 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4359 -1, urlCompW
->lpszUserName
, len
);
4362 if (lpUrlComponents
->lpszPassword
)
4364 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4365 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4366 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4367 -1, urlCompW
->lpszPassword
, len
);
4370 if (lpUrlComponents
->lpszUrlPath
)
4372 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4373 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4374 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4375 -1, urlCompW
->lpszUrlPath
, len
);
4378 if (lpUrlComponents
->lpszExtraInfo
)
4380 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4381 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4382 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4383 -1, urlCompW
->lpszExtraInfo
, len
);
4387 /***********************************************************************
4388 * InternetCreateUrlA (WININET.@)
4390 * See InternetCreateUrlW.
4392 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4393 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4397 URL_COMPONENTSW urlCompW
;
4399 TRACE("(%p,%ld,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4401 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4403 SetLastError(ERROR_INVALID_PARAMETER
);
4407 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4410 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4412 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4414 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4415 *lpdwUrlLength
/= sizeof(WCHAR
);
4417 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4418 * minus one, so add one to leave room for NULL terminator
4421 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4423 heap_free(urlCompW
.lpszScheme
);
4424 heap_free(urlCompW
.lpszHostName
);
4425 heap_free(urlCompW
.lpszUserName
);
4426 heap_free(urlCompW
.lpszPassword
);
4427 heap_free(urlCompW
.lpszUrlPath
);
4428 heap_free(urlCompW
.lpszExtraInfo
);
4433 /***********************************************************************
4434 * InternetCreateUrlW (WININET.@)
4436 * Creates a URL from its component parts.
4439 * lpUrlComponents [I] URL Components.
4440 * dwFlags [I] Flags. See notes.
4441 * lpszUrl [I] Buffer in which to store the created URL.
4442 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4443 * lpszUrl in characters. On output, the number of bytes
4444 * required to store the URL including terminator.
4448 * The dwFlags parameter can be zero or more of the following:
4449 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4456 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4457 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4460 INTERNET_SCHEME nScheme
;
4462 static const WCHAR slashSlashW
[] = {'/','/'};
4464 TRACE("(%p,%ld,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4466 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4468 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4472 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4475 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4477 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4478 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4482 *lpdwUrlLength
= dwLen
;
4487 if (lpUrlComponents
->lpszScheme
)
4489 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4490 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4493 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4498 nScheme
= lpUrlComponents
->nScheme
;
4500 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4501 nScheme
= INTERNET_SCHEME_HTTP
;
4503 scheme
= INTERNET_GetSchemeString(nScheme
);
4504 dwLen
= lstrlenW(scheme
);
4505 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4509 /* all schemes are followed by at least a colon */
4513 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4515 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4516 lpszUrl
+= ARRAY_SIZE(slashSlashW
);
4519 if (lpUrlComponents
->lpszUserName
)
4521 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4522 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4525 if (lpUrlComponents
->lpszPassword
)
4530 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4531 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4539 if (lpUrlComponents
->lpszHostName
)
4541 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4542 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4545 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4548 _ltow(lpUrlComponents
->nPort
, lpszUrl
, 10);
4549 lpszUrl
+= lstrlenW(lpszUrl
);
4552 /* add slash between hostname and path if necessary */
4553 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4560 if (lpUrlComponents
->lpszUrlPath
)
4562 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4563 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4567 if (lpUrlComponents
->lpszExtraInfo
)
4569 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4570 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4579 /***********************************************************************
4580 * InternetConfirmZoneCrossingA (WININET.@)
4583 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4585 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4586 return ERROR_SUCCESS
;
4589 /***********************************************************************
4590 * InternetConfirmZoneCrossingW (WININET.@)
4593 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4595 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4596 return ERROR_SUCCESS
;
4599 static DWORD zone_preference
= 3;
4601 /***********************************************************************
4602 * PrivacySetZonePreferenceW (WININET.@)
4604 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4606 FIXME( "%lx %lx %lx %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4608 zone_preference
= template;
4612 /***********************************************************************
4613 * PrivacyGetZonePreferenceW (WININET.@)
4615 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4616 LPWSTR preference
, LPDWORD length
)
4618 FIXME( "%lx %lx %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4620 if (template) *template = zone_preference
;
4624 /***********************************************************************
4625 * InternetGetSecurityInfoByURLA (WININET.@)
4627 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4632 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4634 url
= heap_strdupAtoW(lpszURL
);
4638 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4643 /***********************************************************************
4644 * InternetGetSecurityInfoByURLW (WININET.@)
4646 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4648 URL_COMPONENTSW url
= {sizeof(url
)};
4652 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4654 if (!ppCertChain
&& !pdwSecureFlags
) {
4655 SetLastError(ERROR_INVALID_PARAMETER
);
4659 url
.dwHostNameLength
= 1;
4660 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4661 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4662 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4666 server
= get_server(substr(url
.lpszHostName
, url
.dwHostNameLength
), url
.nPort
, TRUE
, FALSE
);
4668 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4672 if(server
->cert_chain
) {
4674 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4676 if(ppCertChain
&& !(*ppCertChain
= CertDuplicateCertificateChain(server
->cert_chain
)))
4679 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4683 server_release(server
);
4687 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4688 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4690 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4691 lpdwConnection
, dwReserved
);
4692 return ERROR_SUCCESS
;
4695 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4696 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4698 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4699 lpdwConnection
, dwReserved
);
4700 return ERROR_SUCCESS
;
4703 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4705 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4709 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4711 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4715 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4717 FIXME("(0x%08Ix, 0x%08lx) stub\n", dwConnection
, dwReserved
);
4718 return ERROR_SUCCESS
;
4721 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4724 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4725 debugstr_w(pwszTarget
), pbHexHash
);
4729 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4731 FIXME("(%p, 0x%08lx) stub\n", hInternet
, dwError
);
4735 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4737 FIXME("(%p, %08Ix) stub\n", a
, b
);
4741 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4743 FIXME("%p: stub\n", parent
);