4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
46 #include "wine/debug.h"
48 #define NO_SHLWAPI_STREAM
55 #include "wine/exception.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
65 CHAR response
[MAX_REPLY_LEN
];
66 } WITHREADERROR
, *LPWITHREADERROR
;
68 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
69 HMODULE WININET_hModule
;
71 static CRITICAL_SECTION WININET_cs
;
72 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
75 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
76 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
78 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
80 static object_header_t
**handle_table
;
81 static UINT_PTR next_handle
;
82 static UINT_PTR handle_table_size
;
93 static ULONG max_conns
= 2, max_1_0_conns
= 4;
94 static ULONG connect_timeout
= 60000;
96 static const WCHAR szInternetSettings
[] =
97 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
98 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
99 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
100 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
101 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
102 static const WCHAR szProxyOverride
[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
104 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
106 UINT_PTR handle
= 0, num
;
107 object_header_t
*ret
;
111 ret
= heap_alloc_zero(size
);
115 list_init(&ret
->children
);
117 EnterCriticalSection( &WININET_cs
);
119 if(!handle_table_size
) {
121 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
124 handle_table_size
= num
;
129 }else if(next_handle
== handle_table_size
) {
130 num
= handle_table_size
* 2;
131 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
134 handle_table_size
= num
;
141 handle
= next_handle
;
142 if(handle_table
[handle
])
143 ERR("handle isn't free but should be\n");
144 handle_table
[handle
] = ret
;
145 ret
->valid_handle
= TRUE
;
147 while(next_handle
< handle_table_size
&& handle_table
[next_handle
])
151 LeaveCriticalSection( &WININET_cs
);
160 ret
->hInternet
= (HINTERNET
)handle
;
163 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
164 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
170 object_header_t
*WININET_AddRef( object_header_t
*info
)
172 ULONG refs
= InterlockedIncrement(&info
->refs
);
173 TRACE("%p -> refcount = %d\n", info
, refs
);
177 object_header_t
*get_handle_object( HINTERNET hinternet
)
179 object_header_t
*info
= NULL
;
180 UINT_PTR handle
= (UINT_PTR
) hinternet
;
182 EnterCriticalSection( &WININET_cs
);
184 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
185 info
= WININET_AddRef(handle_table
[handle
]);
187 LeaveCriticalSection( &WININET_cs
);
189 TRACE("handle %ld -> %p\n", handle
, info
);
194 static void invalidate_handle(object_header_t
*info
)
196 object_header_t
*child
, *next
;
198 if(!info
->valid_handle
)
200 info
->valid_handle
= FALSE
;
202 /* Free all children as native does */
203 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
205 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
206 invalidate_handle( child
);
209 WININET_Release(info
);
212 BOOL
WININET_Release( object_header_t
*info
)
214 ULONG refs
= InterlockedDecrement(&info
->refs
);
215 TRACE( "object %p refcount = %d\n", info
, refs
);
218 invalidate_handle(info
);
219 if ( info
->vtbl
->CloseConnection
)
221 TRACE( "closing connection %p\n", info
);
222 info
->vtbl
->CloseConnection( info
);
224 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
225 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
226 || !(info
->dwInternalFlags
& INET_OPENURL
))
228 INTERNET_SendCallback(info
, info
->dwContext
,
229 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
232 TRACE( "destroying object %p\n", info
);
233 if ( info
->htype
!= WH_HINIT
)
234 list_remove( &info
->entry
);
235 info
->vtbl
->Destroy( info
);
237 if(info
->hInternet
) {
238 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
240 EnterCriticalSection( &WININET_cs
);
242 handle_table
[handle
] = NULL
;
243 if(next_handle
> handle
)
244 next_handle
= handle
;
246 LeaveCriticalSection( &WININET_cs
);
254 /***********************************************************************
255 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
258 * hinstDLL [I] handle to the DLL's instance
260 * lpvReserved [I] reserved, must be NULL
267 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
269 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
272 case DLL_PROCESS_ATTACH
:
274 g_dwTlsErrIndex
= TlsAlloc();
276 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
281 TlsFree(g_dwTlsErrIndex
);
285 WININET_hModule
= hinstDLL
;
288 case DLL_THREAD_ATTACH
:
291 case DLL_THREAD_DETACH
:
292 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
294 heap_free(TlsGetValue(g_dwTlsErrIndex
));
298 case DLL_PROCESS_DETACH
:
299 if (lpvReserved
) break;
300 collect_connections(COLLECT_CLEANUP
);
305 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
307 heap_free(TlsGetValue(g_dwTlsErrIndex
));
308 TlsFree(g_dwTlsErrIndex
);
315 /***********************************************************************
316 * DllInstall (WININET.@)
318 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
320 FIXME("(%x %s): stub\n", bInstall
, debugstr_w(cmdline
));
324 /***********************************************************************
325 * INTERNET_SaveProxySettings
327 * Stores the proxy settings given by lpwai into the registry
330 * ERROR_SUCCESS if no error, or error code on fail
332 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
337 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
340 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
348 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
356 if ((ret
= RegDeleteValueW( key
, szProxyServer
)) && ret
!= ERROR_FILE_NOT_FOUND
)
364 return ERROR_SUCCESS
;
367 /***********************************************************************
368 * INTERNET_FindProxyForProtocol
370 * Searches the proxy string for a proxy of the given protocol.
371 * Returns the found proxy, or the default proxy if none of the given
375 * szProxy [In] proxy string to search
376 * proto [In] protocol to search for, e.g. "http"
377 * foundProxy [Out] found proxy
378 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
381 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
382 * *foundProxyLen is set to the required size in WCHARs, including the
383 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
385 WCHAR
*INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
)
390 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
392 /* First, look for the specified protocol (proto=scheme://host:port) */
393 for (ptr
= szProxy
; ptr
&& *ptr
; )
397 if (!(end
= wcschr(ptr
, ' ')))
398 end
= ptr
+ lstrlenW(ptr
);
399 if ((equal
= wcschr(ptr
, '=')) && equal
< end
&&
400 equal
- ptr
== lstrlenW(proto
) &&
401 !wcsnicmp(proto
, ptr
, lstrlenW(proto
)))
403 ret
= heap_strndupW(equal
+ 1, end
- equal
- 1);
404 TRACE("found proxy for %s: %s\n", debugstr_w(proto
), debugstr_w(ret
));
413 /* It wasn't found: look for no protocol */
414 for (ptr
= szProxy
; ptr
&& *ptr
; )
418 if (!(end
= wcschr(ptr
, ' ')))
419 end
= ptr
+ lstrlenW(ptr
);
420 if (!wcschr(ptr
, '='))
422 ret
= heap_strndupW(ptr
, end
- ptr
);
423 TRACE("found proxy for %s: %s\n", debugstr_w(proto
), debugstr_w(ret
));
435 /***********************************************************************
436 * InternetInitializeAutoProxyDll (WININET.@)
438 * Setup the internal proxy
447 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
450 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
454 /***********************************************************************
455 * DetectAutoProxyUrl (WININET.@)
457 * Auto detect the proxy url
463 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
464 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
467 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
471 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
473 heap_free(lpwpi
->proxy
);
474 heap_free(lpwpi
->proxyBypass
);
475 heap_free(lpwpi
->proxyUsername
);
476 heap_free(lpwpi
->proxyPassword
);
479 static proxyinfo_t
*global_proxy
;
481 static void free_global_proxy( void )
483 EnterCriticalSection( &WININET_cs
);
486 FreeProxyInfo( global_proxy
);
487 heap_free( global_proxy
);
489 LeaveCriticalSection( &WININET_cs
);
492 static BOOL
parse_proxy_url( proxyinfo_t
*info
, const WCHAR
*url
)
494 static const WCHAR fmt
[] = {'%','.','*','s',':','%','u',0};
495 URL_COMPONENTSW uc
= {sizeof(uc
)};
497 uc
.dwHostNameLength
= 1;
498 uc
.dwUserNameLength
= 1;
499 uc
.dwPasswordLength
= 1;
501 if (!InternetCrackUrlW( url
, 0, 0, &uc
)) return FALSE
;
502 if (!uc
.dwHostNameLength
)
504 if (!(info
->proxy
= heap_strdupW( url
))) return FALSE
;
505 info
->proxyUsername
= NULL
;
506 info
->proxyPassword
= NULL
;
509 if (!(info
->proxy
= heap_alloc( (uc
.dwHostNameLength
+ 12) * sizeof(WCHAR
) ))) return FALSE
;
510 swprintf( info
->proxy
, uc
.dwHostNameLength
+ 12, fmt
, uc
.dwHostNameLength
, uc
.lpszHostName
, uc
.nPort
);
512 if (!uc
.dwUserNameLength
) info
->proxyUsername
= NULL
;
513 else if (!(info
->proxyUsername
= heap_strndupW( uc
.lpszUserName
, uc
.dwUserNameLength
)))
515 heap_free( info
->proxy
);
518 if (!uc
.dwPasswordLength
) info
->proxyPassword
= NULL
;
519 else if (!(info
->proxyPassword
= heap_strndupW( uc
.lpszPassword
, uc
.dwPasswordLength
)))
521 heap_free( info
->proxyUsername
);
522 heap_free( info
->proxy
);
528 /***********************************************************************
529 * INTERNET_LoadProxySettings
531 * Loads proxy information from process-wide global settings, the registry,
532 * or the environment into lpwpi.
534 * The caller should call FreeProxyInfo when done with lpwpi.
537 * The proxy may be specified in the form 'http=proxy.my.org'
538 * Presumably that means there can be ftp=ftpproxy.my.org too.
540 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
544 const WCHAR
*envproxy
;
547 memset( lpwpi
, 0, sizeof(*lpwpi
) );
549 EnterCriticalSection( &WININET_cs
);
552 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
553 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
554 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
556 LeaveCriticalSection( &WININET_cs
);
558 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
560 FreeProxyInfo( lpwpi
);
565 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
567 lpwpi
->proxyEnabled
= 0;
568 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
570 FreeProxyInfo( lpwpi
);
576 if (!(envproxy
= _wgetenv( L
"http_proxy" )) || lpwpi
->proxyEnabled
)
578 /* figure out how much memory the proxy setting takes */
579 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
582 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
584 if (!(szProxy
= heap_alloc(len
)))
587 FreeProxyInfo( lpwpi
);
588 return ERROR_OUTOFMEMORY
;
590 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
592 /* find the http proxy, and strip away everything else */
593 p
= wcsstr( szProxy
, szHttp
);
596 p
+= lstrlenW( szHttp
);
597 lstrcpyW( szProxy
, p
);
599 p
= wcschr( szProxy
, ';' );
602 FreeProxyInfo( lpwpi
);
603 lpwpi
->proxy
= szProxy
;
604 lpwpi
->proxyBypass
= NULL
;
606 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi
->proxy
));
610 TRACE("No proxy server settings in registry.\n");
611 FreeProxyInfo( lpwpi
);
613 lpwpi
->proxyBypass
= NULL
;
618 FreeProxyInfo( lpwpi
);
619 if (parse_proxy_url( lpwpi
, envproxy
))
621 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
622 lpwpi
->proxyEnabled
= 1;
623 lpwpi
->proxyBypass
= NULL
;
627 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxy
));
628 lpwpi
->proxyEnabled
= 0;
630 lpwpi
->proxyBypass
= NULL
;
634 if (lpwpi
->proxyEnabled
)
636 TRACE("Proxy is enabled.\n");
638 if (!(envproxy
= _wgetenv( L
"no_proxy" )))
640 /* figure out how much memory the proxy setting takes */
641 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
645 if (!(szProxy
= heap_alloc(len
)))
648 return ERROR_OUTOFMEMORY
;
650 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
652 heap_free( lpwpi
->proxyBypass
);
653 lpwpi
->proxyBypass
= szProxy
;
655 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
659 heap_free( lpwpi
->proxyBypass
);
660 lpwpi
->proxyBypass
= NULL
;
662 TRACE("No proxy bypass server settings in registry.\n");
669 if (!(envproxyW
= heap_alloc(lstrlenW(envproxy
) * sizeof(WCHAR
))))
672 return ERROR_OUTOFMEMORY
;
674 lstrcpyW( envproxyW
, envproxy
);
676 heap_free( lpwpi
->proxyBypass
);
677 lpwpi
->proxyBypass
= envproxyW
;
679 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
682 else TRACE("Proxy is disabled.\n");
685 return ERROR_SUCCESS
;
688 /***********************************************************************
689 * INTERNET_ConfigureProxy
691 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
695 if (INTERNET_LoadProxySettings( &wpi
))
698 if (wpi
.proxyEnabled
)
700 TRACE("http proxy = %s bypass = %s\n", debugstr_w(wpi
.proxy
), debugstr_w(wpi
.proxyBypass
));
702 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
703 lpwai
->proxy
= wpi
.proxy
;
704 lpwai
->proxyBypass
= wpi
.proxyBypass
;
705 lpwai
->proxyUsername
= wpi
.proxyUsername
;
706 lpwai
->proxyPassword
= wpi
.proxyPassword
;
710 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
715 /***********************************************************************
716 * dump_INTERNET_FLAGS
718 * Helper function to TRACE the internet flags.
724 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
726 #define FE(x) { x, #x }
727 static const wininet_flag_info flag
[] = {
728 FE(INTERNET_FLAG_RELOAD
),
729 FE(INTERNET_FLAG_RAW_DATA
),
730 FE(INTERNET_FLAG_EXISTING_CONNECT
),
731 FE(INTERNET_FLAG_ASYNC
),
732 FE(INTERNET_FLAG_PASSIVE
),
733 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
734 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
735 FE(INTERNET_FLAG_FROM_CACHE
),
736 FE(INTERNET_FLAG_SECURE
),
737 FE(INTERNET_FLAG_KEEP_CONNECTION
),
738 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
739 FE(INTERNET_FLAG_READ_PREFETCH
),
740 FE(INTERNET_FLAG_NO_COOKIES
),
741 FE(INTERNET_FLAG_NO_AUTH
),
742 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
743 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
744 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
745 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
746 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
747 FE(INTERNET_FLAG_RESYNCHRONIZE
),
748 FE(INTERNET_FLAG_HYPERLINK
),
749 FE(INTERNET_FLAG_NO_UI
),
750 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
751 FE(INTERNET_FLAG_CACHE_ASYNC
),
752 FE(INTERNET_FLAG_FORMS_SUBMIT
),
753 FE(INTERNET_FLAG_NEED_FILE
),
754 FE(INTERNET_FLAG_TRANSFER_ASCII
),
755 FE(INTERNET_FLAG_TRANSFER_BINARY
)
760 for (i
= 0; i
< ARRAY_SIZE(flag
); i
++) {
761 if (flag
[i
].val
& dwFlags
) {
762 TRACE(" %s", flag
[i
].name
);
763 dwFlags
&= ~flag
[i
].val
;
767 TRACE(" Unknown flags (%08x)\n", dwFlags
);
772 /***********************************************************************
773 * INTERNET_CloseHandle (internal)
775 * Close internet handle
778 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
780 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
784 heap_free(lpwai
->agent
);
785 heap_free(lpwai
->proxy
);
786 heap_free(lpwai
->proxyBypass
);
787 heap_free(lpwai
->proxyUsername
);
788 heap_free(lpwai
->proxyPassword
);
791 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
793 appinfo_t
*ai
= (appinfo_t
*)hdr
;
796 case INTERNET_OPTION_HANDLE_TYPE
:
797 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
799 if (*size
< sizeof(ULONG
))
800 return ERROR_INSUFFICIENT_BUFFER
;
802 *size
= sizeof(DWORD
);
803 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
804 return ERROR_SUCCESS
;
806 case INTERNET_OPTION_USER_AGENT
: {
809 TRACE("INTERNET_OPTION_USER_AGENT\n");
814 DWORD len
= ai
->agent
? lstrlenW(ai
->agent
) : 0;
816 *size
= (len
+ 1) * sizeof(WCHAR
);
817 if(!buffer
|| bufsize
< *size
)
818 return ERROR_INSUFFICIENT_BUFFER
;
821 lstrcpyW(buffer
, ai
->agent
);
823 *(WCHAR
*)buffer
= 0;
824 /* If the buffer is copied, the returned length doesn't include
825 * the NULL terminator.
830 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
833 if(!buffer
|| bufsize
< *size
)
834 return ERROR_INSUFFICIENT_BUFFER
;
837 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
840 /* If the buffer is copied, the returned length doesn't include
841 * the NULL terminator.
846 return ERROR_SUCCESS
;
849 case INTERNET_OPTION_PROXY
:
850 if(!size
) return ERROR_INVALID_PARAMETER
;
852 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
853 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
854 LPWSTR proxy
, proxy_bypass
;
857 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
859 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
860 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
862 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
863 return ERROR_INSUFFICIENT_BUFFER
;
865 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
866 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
868 pi
->dwAccessType
= ai
->accessType
;
869 pi
->lpszProxy
= NULL
;
870 pi
->lpszProxyBypass
= NULL
;
872 lstrcpyW(proxy
, ai
->proxy
);
873 pi
->lpszProxy
= proxy
;
876 if (ai
->proxyBypass
) {
877 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
878 pi
->lpszProxyBypass
= proxy_bypass
;
881 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
882 return ERROR_SUCCESS
;
884 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
885 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
886 LPSTR proxy
, proxy_bypass
;
889 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
891 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
892 NULL
, 0, NULL
, NULL
);
893 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
895 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
896 return ERROR_INSUFFICIENT_BUFFER
;
898 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
899 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
901 pi
->dwAccessType
= ai
->accessType
;
902 pi
->lpszProxy
= NULL
;
903 pi
->lpszProxyBypass
= NULL
;
905 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
906 pi
->lpszProxy
= proxy
;
909 if (ai
->proxyBypass
) {
910 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
911 proxyBypassBytesRequired
, NULL
, NULL
);
912 pi
->lpszProxyBypass
= proxy_bypass
;
915 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
916 return ERROR_SUCCESS
;
919 case INTERNET_OPTION_CONNECT_TIMEOUT
:
920 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
922 if (*size
< sizeof(ULONG
))
923 return ERROR_INSUFFICIENT_BUFFER
;
925 *(ULONG
*)buffer
= ai
->connect_timeout
;
926 *size
= sizeof(ULONG
);
928 return ERROR_SUCCESS
;
931 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
934 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
936 appinfo_t
*ai
= (appinfo_t
*)hdr
;
939 case INTERNET_OPTION_CONNECT_TIMEOUT
:
940 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
942 if(size
!= sizeof(connect_timeout
))
943 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
945 return ERROR_BAD_ARGUMENTS
;
947 ai
->connect_timeout
= *(ULONG
*)buf
;
948 return ERROR_SUCCESS
;
949 case INTERNET_OPTION_USER_AGENT
:
950 heap_free(ai
->agent
);
951 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
952 return ERROR_SUCCESS
;
953 case INTERNET_OPTION_REFRESH
:
954 FIXME("INTERNET_OPTION_REFRESH\n");
955 return ERROR_SUCCESS
;
958 return INET_SetOption(hdr
, option
, buf
, size
);
961 static const object_vtbl_t APPINFOVtbl
= {
972 /***********************************************************************
973 * InternetOpenW (WININET.@)
975 * Per-application initialization of wininet
978 * HINTERNET on success
982 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
983 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
985 appinfo_t
*lpwai
= NULL
;
987 if (TRACE_ON(wininet
)) {
988 #define FE(x) { x, #x }
989 static const wininet_flag_info access_type
[] = {
990 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
991 FE(INTERNET_OPEN_TYPE_DIRECT
),
992 FE(INTERNET_OPEN_TYPE_PROXY
),
993 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
997 const char *access_type_str
= "Unknown";
999 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1000 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1001 for (i
= 0; i
< ARRAY_SIZE(access_type
); i
++) {
1002 if (access_type
[i
].val
== dwAccessType
) {
1003 access_type_str
= access_type
[i
].name
;
1007 TRACE(" access type : %s\n", access_type_str
);
1009 dump_INTERNET_FLAGS(dwFlags
);
1012 /* Clear any error information */
1013 INTERNET_SetLastError(0);
1015 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1016 SetLastError(ERROR_INVALID_PARAMETER
);
1020 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1022 SetLastError(ERROR_OUTOFMEMORY
);
1026 lpwai
->hdr
.htype
= WH_HINIT
;
1027 lpwai
->hdr
.dwFlags
= dwFlags
;
1028 lpwai
->accessType
= dwAccessType
;
1029 lpwai
->proxyUsername
= NULL
;
1030 lpwai
->proxyPassword
= NULL
;
1031 lpwai
->connect_timeout
= connect_timeout
;
1033 lpwai
->agent
= heap_strdupW(lpszAgent
);
1034 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1035 INTERNET_ConfigureProxy( lpwai
);
1036 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1037 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1038 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1041 TRACE("returning %p\n", lpwai
);
1043 return lpwai
->hdr
.hInternet
;
1047 /***********************************************************************
1048 * InternetOpenA (WININET.@)
1050 * Per-application initialization of wininet
1053 * HINTERNET on success
1057 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1058 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1060 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1063 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1064 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1066 szAgent
= heap_strdupAtoW(lpszAgent
);
1067 szProxy
= heap_strdupAtoW(lpszProxy
);
1068 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1070 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1074 heap_free(szBypass
);
1078 /***********************************************************************
1079 * InternetGetLastResponseInfoA (WININET.@)
1081 * Return last wininet error description on the calling thread
1084 * TRUE on success of writing to buffer
1088 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1089 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1091 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1097 *lpdwError
= lpwite
->dwError
;
1098 if (lpwite
->dwError
)
1100 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1101 *lpdwBufferLength
= strlen(lpszBuffer
);
1104 *lpdwBufferLength
= 0;
1109 *lpdwBufferLength
= 0;
1115 /***********************************************************************
1116 * InternetGetLastResponseInfoW (WININET.@)
1118 * Return last wininet error description on the calling thread
1121 * TRUE on success of writing to buffer
1125 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1126 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1128 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1134 *lpdwError
= lpwite
->dwError
;
1135 if (lpwite
->dwError
)
1137 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1138 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1141 *lpdwBufferLength
= 0;
1146 *lpdwBufferLength
= 0;
1152 /***********************************************************************
1153 * InternetGetConnectedState (WININET.@)
1155 * Return connected state
1159 * if lpdwStatus is not null, return the status (off line,
1160 * modem, lan...) in it.
1161 * FALSE if not connected
1163 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1165 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1167 return InternetGetConnectedStateExW(lpdwStatus
, NULL
, 0, dwReserved
);
1171 /***********************************************************************
1172 * InternetGetConnectedStateExW (WININET.@)
1174 * Return connected state
1178 * lpdwStatus [O] Flags specifying the status of the internet connection.
1179 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1180 * dwNameLen [I] Size of the buffer, in characters.
1181 * dwReserved [I] Reserved. Must be set to 0.
1185 * if lpdwStatus is not null, return the status (off line,
1186 * modem, lan...) in it.
1187 * FALSE if not connected
1190 * If the system has no available network connections, an empty string is
1191 * stored in lpszConnectionName. If there is a LAN connection, a localized
1192 * "LAN Connection" string is stored. Presumably, if only a dial-up
1193 * connection is available then the name of the dial-up connection is
1194 * returned. Why any application, other than the "Internet Settings" CPL,
1195 * would want to use this function instead of the simpler InternetGetConnectedStateW
1196 * function is beyond me.
1198 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1199 DWORD dwNameLen
, DWORD dwReserved
)
1201 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1208 WARN("always returning LAN connection.\n");
1209 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1212 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1213 * the resource, avoid it as we must not change the buffer in this case */
1214 if(lpszConnectionName
&& dwNameLen
) {
1215 *lpszConnectionName
= '\0';
1216 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1223 /***********************************************************************
1224 * InternetGetConnectedStateExA (WININET.@)
1226 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1227 DWORD dwNameLen
, DWORD dwReserved
)
1229 LPWSTR lpwszConnectionName
= NULL
;
1232 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1234 if (lpszConnectionName
&& dwNameLen
> 0)
1235 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1237 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1239 if (rc
&& lpwszConnectionName
)
1240 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1241 dwNameLen
, NULL
, NULL
);
1243 heap_free(lpwszConnectionName
);
1248 /***********************************************************************
1249 * InternetConnectW (WININET.@)
1251 * Open a ftp, gopher or http session
1254 * HINTERNET a session handle on success
1258 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1259 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1260 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1261 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1264 HINTERNET rc
= NULL
;
1265 DWORD res
= ERROR_SUCCESS
;
1267 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1268 nServerPort
, debugstr_w(lpszUserName
), lpszPassword
, dwService
, dwFlags
, dwContext
);
1270 if (!lpszServerName
)
1272 SetLastError(ERROR_INVALID_PARAMETER
);
1276 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1277 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1279 res
= ERROR_INVALID_HANDLE
;
1285 case INTERNET_SERVICE_FTP
:
1286 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1287 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1289 res
= INTERNET_GetLastError();
1292 case INTERNET_SERVICE_HTTP
:
1293 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1294 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1297 case INTERNET_SERVICE_GOPHER
:
1303 WININET_Release( &hIC
->hdr
);
1305 TRACE("returning %p\n", rc
);
1311 /***********************************************************************
1312 * InternetConnectA (WININET.@)
1314 * Open a ftp, gopher or http session
1317 * HINTERNET a session handle on success
1321 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1322 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1323 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1324 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1326 HINTERNET rc
= NULL
;
1327 LPWSTR szServerName
;
1331 szServerName
= heap_strdupAtoW(lpszServerName
);
1332 szUserName
= heap_strdupAtoW(lpszUserName
);
1333 szPassword
= heap_strdupAtoW(lpszPassword
);
1335 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1336 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1338 heap_free(szServerName
);
1339 heap_free(szUserName
);
1340 heap_free(szPassword
);
1345 /***********************************************************************
1346 * InternetFindNextFileA (WININET.@)
1348 * Continues a file search from a previous call to FindFirstFile
1355 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1358 WIN32_FIND_DATAW fd
;
1360 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1362 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1366 /***********************************************************************
1367 * InternetFindNextFileW (WININET.@)
1369 * Continues a file search from a previous call to FindFirstFile
1376 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1378 object_header_t
*hdr
;
1383 hdr
= get_handle_object(hFind
);
1385 WARN("Invalid handle\n");
1386 SetLastError(ERROR_INVALID_HANDLE
);
1390 if(hdr
->vtbl
->FindNextFileW
) {
1391 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1393 WARN("Handle doesn't support NextFile\n");
1394 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1397 WININET_Release(hdr
);
1399 if(res
!= ERROR_SUCCESS
)
1401 return res
== ERROR_SUCCESS
;
1404 /***********************************************************************
1405 * InternetCloseHandle (WININET.@)
1407 * Generic close handle function
1414 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1416 object_header_t
*obj
;
1418 TRACE("%p\n", hInternet
);
1420 obj
= get_handle_object( hInternet
);
1422 SetLastError(ERROR_INVALID_HANDLE
);
1426 invalidate_handle(obj
);
1427 WININET_Release(obj
);
1432 static BOOL
set_url_component(WCHAR
**component
, DWORD
*component_length
, const WCHAR
*value
, DWORD len
)
1434 TRACE("%s (%d)\n", debugstr_wn(value
, len
), len
);
1436 if (!*component_length
)
1440 *(const WCHAR
**)component
= value
;
1441 *component_length
= len
;
1445 if (*component_length
< len
+1) {
1446 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1450 *component_length
= len
;
1452 memcpy(*component
, value
, len
*sizeof(WCHAR
));
1453 (*component
)[len
] = 0;
1457 static BOOL
set_url_component_WtoA(const WCHAR
*comp_w
, DWORD length
, const WCHAR
*url_w
, char **comp
, DWORD
*ret_length
,
1460 size_t size
, ret_size
= *ret_length
;
1464 size
= WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, NULL
, 0, NULL
, NULL
);
1467 *comp
= comp_w
? (char*)url_a
+ WideCharToMultiByte(CP_ACP
, 0, url_w
, comp_w
-url_w
, NULL
, 0, NULL
, NULL
) : NULL
;
1472 if (size
+1 > ret_size
) {
1473 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1474 *ret_length
= size
+1;
1479 WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, *comp
, ret_size
-1, NULL
, NULL
);
1484 static BOOL
set_url_component_AtoW(const char *comp_a
, DWORD len_a
, WCHAR
**comp_w
, DWORD
*len_w
, WCHAR
**buf
)
1493 if(!(*comp_w
= *buf
= heap_alloc(len_a
*sizeof(WCHAR
)))) {
1494 SetLastError(ERROR_OUTOFMEMORY
);
1501 /***********************************************************************
1502 * InternetCrackUrlA (WININET.@)
1504 * See InternetCrackUrlW.
1506 BOOL WINAPI
InternetCrackUrlA(const char *url
, DWORD url_length
, DWORD flags
, URL_COMPONENTSA
*ret_comp
)
1508 WCHAR
*host
= NULL
, *user
= NULL
, *pass
= NULL
, *path
= NULL
, *scheme
= NULL
, *extra
= NULL
;
1509 URL_COMPONENTSW comp
;
1510 WCHAR
*url_w
= NULL
;
1513 TRACE("(%s %u %x %p)\n", url_length
? debugstr_an(url
, url_length
) : debugstr_a(url
), url_length
, flags
, ret_comp
);
1515 if (!url
|| !*url
|| !ret_comp
|| ret_comp
->dwStructSize
!= sizeof(URL_COMPONENTSA
)) {
1516 SetLastError(ERROR_INVALID_PARAMETER
);
1520 comp
.dwStructSize
= sizeof(comp
);
1522 ret
= set_url_component_AtoW(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
,
1523 &comp
.lpszHostName
, &comp
.dwHostNameLength
, &host
)
1524 && set_url_component_AtoW(ret_comp
->lpszUserName
, ret_comp
->dwUserNameLength
,
1525 &comp
.lpszUserName
, &comp
.dwUserNameLength
, &user
)
1526 && set_url_component_AtoW(ret_comp
->lpszPassword
, ret_comp
->dwPasswordLength
,
1527 &comp
.lpszPassword
, &comp
.dwPasswordLength
, &pass
)
1528 && set_url_component_AtoW(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
,
1529 &comp
.lpszUrlPath
, &comp
.dwUrlPathLength
, &path
)
1530 && set_url_component_AtoW(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
,
1531 &comp
.lpszScheme
, &comp
.dwSchemeLength
, &scheme
)
1532 && set_url_component_AtoW(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
,
1533 &comp
.lpszExtraInfo
, &comp
.dwExtraInfoLength
, &extra
);
1535 if(ret
&& !(url_w
= heap_strndupAtoW(url
, url_length
? url_length
: -1, &url_length
))) {
1536 SetLastError(ERROR_OUTOFMEMORY
);
1540 if (ret
&& (ret
= InternetCrackUrlW(url_w
, url_length
, flags
, &comp
))) {
1541 ret_comp
->nScheme
= comp
.nScheme
;
1542 ret_comp
->nPort
= comp
.nPort
;
1544 ret
= set_url_component_WtoA(comp
.lpszHostName
, comp
.dwHostNameLength
, url_w
,
1545 &ret_comp
->lpszHostName
, &ret_comp
->dwHostNameLength
, url
)
1546 && set_url_component_WtoA(comp
.lpszUserName
, comp
.dwUserNameLength
, url_w
,
1547 &ret_comp
->lpszUserName
, &ret_comp
->dwUserNameLength
, url
)
1548 && set_url_component_WtoA(comp
.lpszPassword
, comp
.dwPasswordLength
, url_w
,
1549 &ret_comp
->lpszPassword
, &ret_comp
->dwPasswordLength
, url
)
1550 && set_url_component_WtoA(comp
.lpszUrlPath
, comp
.dwUrlPathLength
, url_w
,
1551 &ret_comp
->lpszUrlPath
, &ret_comp
->dwUrlPathLength
, url
)
1552 && set_url_component_WtoA(comp
.lpszScheme
, comp
.dwSchemeLength
, url_w
,
1553 &ret_comp
->lpszScheme
, &ret_comp
->dwSchemeLength
, url
)
1554 && set_url_component_WtoA(comp
.lpszExtraInfo
, comp
.dwExtraInfoLength
, url_w
,
1555 &ret_comp
->lpszExtraInfo
, &ret_comp
->dwExtraInfoLength
, url
);
1558 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url
),
1559 debugstr_an(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
),
1560 debugstr_an(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
),
1561 debugstr_an(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
),
1562 debugstr_an(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
));
1575 static const WCHAR url_schemes
[][7] =
1578 {'g','o','p','h','e','r',0},
1579 {'h','t','t','p',0},
1580 {'h','t','t','p','s',0},
1581 {'f','i','l','e',0},
1582 {'n','e','w','s',0},
1583 {'m','a','i','l','t','o',0},
1587 /***********************************************************************
1588 * GetInternetSchemeW (internal)
1594 * INTERNET_SCHEME_UNKNOWN on failure
1597 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1601 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1603 if(lpszScheme
==NULL
)
1604 return INTERNET_SCHEME_UNKNOWN
;
1606 for (i
= 0; i
< ARRAY_SIZE(url_schemes
); i
++)
1607 if (!wcsnicmp(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1608 return INTERNET_SCHEME_FIRST
+ i
;
1610 return INTERNET_SCHEME_UNKNOWN
;
1613 /***********************************************************************
1614 * InternetCrackUrlW (WININET.@)
1616 * Break up URL into its components
1622 BOOL WINAPI
InternetCrackUrlW(const WCHAR
*lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
, URL_COMPONENTSW
*lpUC
)
1626 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1629 LPCWSTR lpszParam
= NULL
;
1630 BOOL found_colon
= FALSE
;
1632 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1634 TRACE("(%s %u %x %p)\n",
1635 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: lstrlenW(lpszUrl
)) : "(null)",
1636 dwUrlLength
, dwFlags
, lpUC
);
1638 if (!lpszUrl
|| !*lpszUrl
|| !lpUC
)
1640 SetLastError(ERROR_INVALID_PARAMETER
);
1643 if (!dwUrlLength
) dwUrlLength
= lstrlenW(lpszUrl
);
1645 if (dwFlags
& ICU_DECODE
)
1647 WCHAR
*url_tmp
, *buffer
;
1648 DWORD len
= dwUrlLength
+ 1;
1651 if (!(url_tmp
= heap_strndupW(lpszUrl
, dwUrlLength
)))
1653 SetLastError(ERROR_OUTOFMEMORY
);
1658 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1659 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1661 buffer
= heap_alloc(len
* sizeof(WCHAR
));
1664 SetLastError(ERROR_OUTOFMEMORY
);
1668 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1671 ret
= InternetCrackUrlW(buffer
, len
, dwFlags
& ~ICU_DECODE
, lpUC
);
1673 if (buffer
!= url_tmp
) heap_free(buffer
);
1679 /* Determine if the URI is absolute. */
1680 while (lpszap
- lpszUrl
< dwUrlLength
)
1682 if (iswalnum(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1694 lpszcp
= lpszUrl
; /* Relative url */
1701 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1705 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1706 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1708 /* Parse <params> */
1709 lpszParam
= wmemchr(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1711 lpszParam
= wmemchr(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1713 if(!set_url_component(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1714 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0))
1718 /* Get scheme first. */
1719 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1720 if(!set_url_component(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, lpszUrl
, lpszcp
- lpszUrl
))
1723 /* Eat ':' in protocol. */
1726 /* double slash indicates the net_loc portion is present */
1727 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1731 lpszNetLoc
= wmemchr(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1735 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1737 lpszNetLoc
= lpszParam
;
1739 else if (!lpszNetLoc
)
1740 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1748 /* [<user>[<:password>]@]<host>[:<port>] */
1749 /* First find the user and password if they exist */
1751 lpszHost
= wmemchr(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1752 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1754 /* username and password not specified. */
1755 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1756 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1758 else /* Parse out username and password */
1760 LPCWSTR lpszUser
= lpszcp
;
1761 LPCWSTR lpszPasswd
= lpszHost
;
1763 while (lpszcp
< lpszHost
)
1766 lpszPasswd
= lpszcp
;
1771 if(!set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, lpszUser
, lpszPasswd
- lpszUser
))
1774 if (lpszPasswd
!= lpszHost
)
1776 if(!set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1777 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
, lpszHost
- lpszPasswd
))
1780 lpszcp
++; /* Advance to beginning of host */
1783 /* Parse <host><:port> */
1786 lpszPort
= lpszNetLoc
;
1788 /* special case for res:// URLs: there is no port here, so the host is the
1789 entire string up to the first '/' */
1790 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1792 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1798 while (lpszcp
< lpszNetLoc
)
1806 /* If the scheme is "file" and the host is just one letter, it's not a host */
1807 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1810 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1814 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1816 if (lpszPort
!= lpszNetLoc
)
1817 lpUC
->nPort
= wcstol(++lpszPort
, NULL
, 10);
1818 else switch (lpUC
->nScheme
)
1820 case INTERNET_SCHEME_HTTP
:
1821 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1823 case INTERNET_SCHEME_HTTPS
:
1824 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1826 case INTERNET_SCHEME_FTP
:
1827 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1829 case INTERNET_SCHEME_GOPHER
:
1830 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1841 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1842 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1843 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1846 /* Here lpszcp points to:
1848 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1849 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1851 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1855 /* Only truncate the parameter list if it's already been saved
1856 * in lpUC->lpszExtraInfo.
1858 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1859 len
= lpszParam
- lpszcp
;
1862 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1863 * newlines if necessary.
1865 LPWSTR lpsznewline
= wmemchr(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1866 if (lpsznewline
!= NULL
)
1867 len
= lpsznewline
- lpszcp
;
1869 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1871 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1872 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1874 WCHAR tmppath
[MAX_PATH
];
1878 PathCreateFromUrlW(lpszUrl
, tmppath
, &len
, 0);
1883 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1884 tmppath
[len
] = '\0';
1893 /* if ends in \. or \.. append a backslash */
1894 if (tmppath
[len
- 1] == '.' &&
1895 (tmppath
[len
- 2] == '\\' ||
1896 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1898 if (len
< MAX_PATH
- 1)
1900 tmppath
[len
] = '\\';
1901 tmppath
[len
+1] = '\0';
1905 if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, tmppath
, len
))
1908 else if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, len
))
1913 set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, 0);
1916 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1917 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1918 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1919 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1920 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1925 /***********************************************************************
1926 * InternetAttemptConnect (WININET.@)
1928 * Attempt to make a connection to the internet
1931 * ERROR_SUCCESS on success
1932 * Error value on failure
1935 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1938 return ERROR_SUCCESS
;
1942 /***********************************************************************
1943 * convert_url_canonicalization_flags
1945 * Helper for InternetCanonicalizeUrl
1948 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1951 * Flags suitable for UrlCanonicalize
1953 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1955 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1957 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1958 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1959 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1960 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1961 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1962 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1963 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1968 /***********************************************************************
1969 * InternetCanonicalizeUrlA (WININET.@)
1971 * Escape unsafe characters and spaces
1978 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1979 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1983 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1984 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1986 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
1987 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1988 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1989 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1994 /***********************************************************************
1995 * InternetCanonicalizeUrlW (WININET.@)
1997 * Escape unsafe characters and spaces
2004 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2005 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2009 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2010 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2012 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2013 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2014 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2015 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2020 /* #################################################### */
2022 static INTERNET_STATUS_CALLBACK
set_status_callback(
2023 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2025 INTERNET_STATUS_CALLBACK ret
;
2027 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2028 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2030 ret
= lpwh
->lpfnStatusCB
;
2031 lpwh
->lpfnStatusCB
= callback
;
2036 /***********************************************************************
2037 * InternetSetStatusCallbackA (WININET.@)
2039 * Sets up a callback function which is called as progress is made
2040 * during an operation.
2043 * Previous callback or NULL on success
2044 * INTERNET_INVALID_STATUS_CALLBACK on failure
2047 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2048 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2050 INTERNET_STATUS_CALLBACK retVal
;
2051 object_header_t
*lpwh
;
2053 TRACE("%p\n", hInternet
);
2055 if (!(lpwh
= get_handle_object(hInternet
)))
2056 return INTERNET_INVALID_STATUS_CALLBACK
;
2058 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2060 WININET_Release( lpwh
);
2064 /***********************************************************************
2065 * InternetSetStatusCallbackW (WININET.@)
2067 * Sets up a callback function which is called as progress is made
2068 * during an operation.
2071 * Previous callback or NULL on success
2072 * INTERNET_INVALID_STATUS_CALLBACK on failure
2075 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2076 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2078 INTERNET_STATUS_CALLBACK retVal
;
2079 object_header_t
*lpwh
;
2081 TRACE("%p\n", hInternet
);
2083 if (!(lpwh
= get_handle_object(hInternet
)))
2084 return INTERNET_INVALID_STATUS_CALLBACK
;
2086 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2088 WININET_Release( lpwh
);
2092 /***********************************************************************
2093 * InternetSetFilePointer (WININET.@)
2095 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2096 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2098 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2102 /***********************************************************************
2103 * InternetWriteFile (WININET.@)
2105 * Write data to an open internet file
2112 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2113 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2115 object_header_t
*lpwh
;
2118 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2120 lpwh
= get_handle_object( hFile
);
2122 WARN("Invalid handle\n");
2123 SetLastError(ERROR_INVALID_HANDLE
);
2127 if(lpwh
->vtbl
->WriteFile
) {
2128 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2130 WARN("No Writefile method.\n");
2131 res
= ERROR_INVALID_HANDLE
;
2134 WININET_Release( lpwh
);
2136 if(res
!= ERROR_SUCCESS
)
2138 return res
== ERROR_SUCCESS
;
2142 /***********************************************************************
2143 * InternetReadFile (WININET.@)
2145 * Read data from an open internet file
2152 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2153 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2155 object_header_t
*hdr
;
2156 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2158 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2160 hdr
= get_handle_object(hFile
);
2162 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2166 if(hdr
->vtbl
->ReadFile
) {
2167 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, 0, 0);
2168 if(res
== ERROR_IO_PENDING
)
2169 *pdwNumOfBytesRead
= 0;
2172 WININET_Release(hdr
);
2174 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2175 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2178 return res
== ERROR_SUCCESS
;
2181 /***********************************************************************
2182 * InternetReadFileExA (WININET.@)
2184 * Read data from an open internet file
2187 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2188 * lpBuffersOut [I/O] Buffer.
2189 * dwFlags [I] Flags. See notes.
2190 * dwContext [I] Context for callbacks.
2197 * The parameter dwFlags include zero or more of the following flags:
2198 *|IRF_ASYNC - Makes the call asynchronous.
2199 *|IRF_SYNC - Makes the call synchronous.
2200 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2201 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2203 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2206 * InternetOpenUrlA(), HttpOpenRequestA()
2208 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2209 DWORD dwFlags
, DWORD_PTR dwContext
)
2211 object_header_t
*hdr
;
2212 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2214 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2216 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2217 SetLastError(ERROR_INVALID_PARAMETER
);
2221 hdr
= get_handle_object(hFile
);
2223 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2227 if(hdr
->vtbl
->ReadFile
)
2228 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2229 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2231 WININET_Release(hdr
);
2233 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2234 res
, lpBuffersOut
->dwBufferLength
);
2236 if(res
!= ERROR_SUCCESS
)
2238 return res
== ERROR_SUCCESS
;
2241 /***********************************************************************
2242 * InternetReadFileExW (WININET.@)
2244 * InternetReadFileExA()
2246 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2247 DWORD dwFlags
, DWORD_PTR dwContext
)
2249 object_header_t
*hdr
;
2250 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2252 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2254 if (!lpBuffer
|| lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2255 SetLastError(ERROR_INVALID_PARAMETER
);
2259 hdr
= get_handle_object(hFile
);
2261 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2265 if(hdr
->vtbl
->ReadFile
)
2266 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2267 dwFlags
, dwContext
);
2269 WININET_Release(hdr
);
2271 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2272 res
, lpBuffer
->dwBufferLength
);
2274 if(res
!= ERROR_SUCCESS
)
2276 return res
== ERROR_SUCCESS
;
2279 static IP_ADAPTER_ADDRESSES
*get_adapters(void)
2281 ULONG err
, size
= 1024, flags
= GAA_FLAG_SKIP_ANYCAST
| GAA_FLAG_SKIP_MULTICAST
|
2282 GAA_FLAG_SKIP_DNS_SERVER
| GAA_FLAG_SKIP_FRIENDLY_NAME
;
2283 IP_ADAPTER_ADDRESSES
*tmp
, *ret
;
2285 if (!(ret
= heap_alloc( size
))) return NULL
;
2286 err
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, ret
, &size
);
2287 while (err
== ERROR_BUFFER_OVERFLOW
)
2289 if (!(tmp
= heap_realloc( ret
, size
))) break;
2291 err
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, ret
, &size
);
2293 if (err
== ERROR_SUCCESS
) return ret
;
2298 static WCHAR
*detect_proxy_autoconfig_url_dhcp(void)
2300 IP_ADAPTER_ADDRESSES
*adapters
, *ptr
;
2301 DHCPCAPI_PARAMS_ARRAY send_params
, recv_params
;
2302 DHCPCAPI_PARAMS param
;
2303 WCHAR name
[MAX_ADAPTER_NAME_LENGTH
+ 1], *ret
= NULL
;
2305 BYTE
*tmp
, *buf
= NULL
;
2307 if (!(adapters
= get_adapters())) return NULL
;
2309 memset( &send_params
, 0, sizeof(send_params
) );
2310 memset( ¶m
, 0, sizeof(param
) );
2311 param
.OptionId
= OPTION_MSFT_IE_PROXY
;
2312 recv_params
.nParams
= 1;
2313 recv_params
.Params
= ¶m
;
2315 for (ptr
= adapters
; ptr
; ptr
= ptr
->Next
)
2317 MultiByteToWideChar( CP_ACP
, 0, ptr
->AdapterName
, -1, name
, ARRAY_SIZE(name
) );
2318 TRACE( "adapter '%s' type %u dhcpv4 enabled %d\n", wine_dbgstr_w(name
), ptr
->IfType
, ptr
->Dhcpv4Enabled
);
2320 if (ptr
->IfType
== IF_TYPE_SOFTWARE_LOOPBACK
) continue;
2321 /* FIXME: also skip adapters where DHCP is disabled */
2324 if (!(buf
= heap_alloc( size
))) goto done
;
2325 err
= DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS
, NULL
, name
, NULL
, send_params
, recv_params
,
2327 while (err
== ERROR_MORE_DATA
)
2329 if (!(tmp
= heap_realloc( buf
, size
))) goto done
;
2331 err
= DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS
, NULL
, name
, NULL
, send_params
, recv_params
,
2334 if (err
== ERROR_SUCCESS
&& param
.nBytesData
)
2336 int len
= MultiByteToWideChar( CP_ACP
, 0, (const char *)param
.Data
, param
.nBytesData
, NULL
, 0 );
2337 if ((ret
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
2339 MultiByteToWideChar( CP_ACP
, 0, (const char *)param
.Data
, param
.nBytesData
, ret
, len
);
2342 TRACE("returning %s\n", debugstr_w(ret
));
2349 heap_free( adapters
);
2353 static char *get_computer_name( COMPUTER_NAME_FORMAT format
)
2358 GetComputerNameExA( format
, NULL
, &size
);
2359 if (GetLastError() != ERROR_MORE_DATA
) return NULL
;
2360 if (!(ret
= heap_alloc( size
))) return NULL
;
2361 if (!GetComputerNameExA( format
, ret
, &size
))
2369 static BOOL
is_domain_suffix( const char *domain
, const char *suffix
)
2371 int len_domain
= strlen( domain
), len_suffix
= strlen( suffix
);
2373 if (len_suffix
> len_domain
) return FALSE
;
2374 if (!_strnicmp( domain
+ len_domain
- len_suffix
, suffix
, -1 )) return TRUE
;
2378 static int reverse_lookup( const struct addrinfo
*ai
, char *hostname
, size_t len
)
2380 return getnameinfo( ai
->ai_addr
, ai
->ai_addrlen
, hostname
, len
, NULL
, 0, 0 );
2383 static WCHAR
*build_wpad_url( const char *hostname
, const struct addrinfo
*ai
)
2385 static const WCHAR httpW
[] = {'h','t','t','p',':','/','/',0};
2386 static const WCHAR wpadW
[] = {'/','w','p','a','d','.','d','a','t',0};
2387 char name
[NI_MAXHOST
];
2391 while (ai
&& ai
->ai_family
!= AF_INET
&& ai
->ai_family
!= AF_INET6
) ai
= ai
->ai_next
;
2392 if (!ai
) return NULL
;
2394 if (!reverse_lookup( ai
, name
, sizeof(name
) )) hostname
= name
;
2396 len
= lstrlenW( httpW
) + strlen( hostname
) + lstrlenW( wpadW
);
2397 if (!(ret
= p
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) return NULL
;
2398 lstrcpyW( p
, httpW
);
2399 p
+= lstrlenW( httpW
);
2400 while (*hostname
) { *p
++ = *hostname
++; }
2401 lstrcpyW( p
, wpadW
);
2405 static WCHAR
*detect_proxy_autoconfig_url_dns(void)
2407 char *fqdn
, *domain
, *p
;
2410 if (!(fqdn
= get_computer_name( ComputerNamePhysicalDnsFullyQualified
))) return NULL
;
2411 if (!(domain
= get_computer_name( ComputerNamePhysicalDnsDomain
)))
2417 while ((p
= strchr( p
, '.' )) && is_domain_suffix( p
+ 1, domain
))
2420 struct addrinfo
*ai
;
2423 if (!(name
= heap_alloc( sizeof("wpad") + strlen(p
) )))
2426 heap_free( domain
);
2429 strcpy( name
, "wpad" );
2431 res
= getaddrinfo( name
, NULL
, NULL
, &ai
);
2434 ret
= build_wpad_url( name
, ai
);
2438 TRACE("returning %s\n", debugstr_w(ret
));
2446 heap_free( domain
);
2451 static WCHAR
*get_proxy_autoconfig_url(void)
2453 WCHAR
*ret
= detect_proxy_autoconfig_url_dhcp();
2454 if (!ret
) ret
= detect_proxy_autoconfig_url_dns();
2458 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2460 /* FIXME: This function currently handles more options than it should. Options requiring
2461 * proper handles should be moved to proper functions */
2463 case INTERNET_OPTION_HTTP_VERSION
:
2464 if (*size
< sizeof(HTTP_VERSION_INFO
))
2465 return ERROR_INSUFFICIENT_BUFFER
;
2468 * Presently hardcoded to 1.1
2470 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2471 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2472 *size
= sizeof(HTTP_VERSION_INFO
);
2474 return ERROR_SUCCESS
;
2476 case INTERNET_OPTION_CONNECTED_STATE
:
2477 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2479 if (*size
< sizeof(ULONG
))
2480 return ERROR_INSUFFICIENT_BUFFER
;
2482 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2483 *size
= sizeof(ULONG
);
2485 return ERROR_SUCCESS
;
2487 case INTERNET_OPTION_PROXY
: {
2491 TRACE("Getting global proxy info\n");
2492 memset(&ai
, 0, sizeof(appinfo_t
));
2493 INTERNET_ConfigureProxy(&ai
);
2495 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2496 APPINFO_Destroy(&ai
.hdr
);
2500 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2501 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2503 if (*size
< sizeof(ULONG
))
2504 return ERROR_INSUFFICIENT_BUFFER
;
2506 *(ULONG
*)buffer
= max_conns
;
2507 *size
= sizeof(ULONG
);
2509 return ERROR_SUCCESS
;
2511 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2512 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2514 if (*size
< sizeof(ULONG
))
2515 return ERROR_INSUFFICIENT_BUFFER
;
2517 *(ULONG
*)buffer
= max_1_0_conns
;
2518 *size
= sizeof(ULONG
);
2520 return ERROR_SUCCESS
;
2522 case INTERNET_OPTION_SECURITY_FLAGS
:
2523 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2524 return ERROR_SUCCESS
;
2526 case INTERNET_OPTION_VERSION
: {
2527 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2529 TRACE("INTERNET_OPTION_VERSION\n");
2531 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2532 return ERROR_INSUFFICIENT_BUFFER
;
2534 memcpy(buffer
, &info
, sizeof(info
));
2535 *size
= sizeof(info
);
2537 return ERROR_SUCCESS
;
2540 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2542 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2543 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2544 DWORD res
= ERROR_SUCCESS
, i
;
2548 TRACE("Getting global proxy info\n");
2549 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2552 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2554 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2556 return ERROR_INSUFFICIENT_BUFFER
;
2559 url
= get_proxy_autoconfig_url();
2561 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2562 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2563 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2565 switch (optionW
->dwOption
) {
2566 case INTERNET_PER_CONN_FLAGS
:
2568 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2570 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2572 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2573 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2576 case INTERNET_PER_CONN_PROXY_SERVER
:
2578 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2580 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2583 case INTERNET_PER_CONN_PROXY_BYPASS
:
2585 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2587 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2590 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2592 optionW
->Value
.pszValue
= NULL
;
2594 optionW
->Value
.pszValue
= heap_strdupW(url
);
2596 optionA
->Value
.pszValue
= heap_strdupWtoA(url
);
2599 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2600 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2603 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2604 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2605 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2606 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2607 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2608 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2612 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2613 res
= ERROR_INVALID_PARAMETER
;
2622 case INTERNET_OPTION_REQUEST_FLAGS
:
2623 case INTERNET_OPTION_USER_AGENT
:
2625 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2626 case INTERNET_OPTION_POLICY
:
2627 return ERROR_INVALID_PARAMETER
;
2628 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2629 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2631 if (*size
< sizeof(ULONG
))
2632 return ERROR_INSUFFICIENT_BUFFER
;
2634 *(ULONG
*)buffer
= connect_timeout
;
2635 *size
= sizeof(ULONG
);
2637 return ERROR_SUCCESS
;
2640 FIXME("Stub for %d\n", option
);
2641 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2644 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2647 case INTERNET_OPTION_CONTEXT_VALUE
:
2649 return ERROR_INVALID_PARAMETER
;
2651 if (*size
< sizeof(DWORD_PTR
)) {
2652 *size
= sizeof(DWORD_PTR
);
2653 return ERROR_INSUFFICIENT_BUFFER
;
2656 return ERROR_INVALID_PARAMETER
;
2658 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2659 *size
= sizeof(DWORD_PTR
);
2660 return ERROR_SUCCESS
;
2662 case INTERNET_OPTION_REQUEST_FLAGS
:
2663 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2664 *size
= sizeof(DWORD
);
2665 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2667 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2668 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2669 WARN("Called on global option %u\n", option
);
2670 return ERROR_INTERNET_INVALID_OPERATION
;
2673 /* FIXME: we shouldn't call it here */
2674 return query_global_option(option
, buffer
, size
, unicode
);
2677 /***********************************************************************
2678 * InternetQueryOptionW (WININET.@)
2680 * Queries an options on the specified handle
2687 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2688 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2690 object_header_t
*hdr
;
2691 DWORD res
= ERROR_INVALID_HANDLE
;
2693 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2696 hdr
= get_handle_object(hInternet
);
2698 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2699 WININET_Release(hdr
);
2702 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2705 if(res
!= ERROR_SUCCESS
)
2707 return res
== ERROR_SUCCESS
;
2710 /***********************************************************************
2711 * InternetQueryOptionA (WININET.@)
2713 * Queries an options on the specified handle
2720 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2721 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2723 object_header_t
*hdr
;
2724 DWORD res
= ERROR_INVALID_HANDLE
;
2726 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2729 hdr
= get_handle_object(hInternet
);
2731 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2732 WININET_Release(hdr
);
2735 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2738 if(res
!= ERROR_SUCCESS
)
2740 return res
== ERROR_SUCCESS
;
2743 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2746 case INTERNET_OPTION_SETTINGS_CHANGED
:
2747 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2748 collect_connections(COLLECT_CONNECTIONS
);
2749 return ERROR_SUCCESS
;
2750 case INTERNET_OPTION_CALLBACK
:
2751 WARN("Not settable option %u\n", option
);
2752 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2753 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2754 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2755 WARN("Called on global option %u\n", option
);
2756 return ERROR_INTERNET_INVALID_OPERATION
;
2757 case INTERNET_OPTION_REFRESH
:
2758 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2761 return ERROR_INTERNET_INVALID_OPTION
;
2764 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2767 case INTERNET_OPTION_CALLBACK
:
2768 WARN("Not global option %u\n", option
);
2769 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2771 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2772 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2774 if(size
!= sizeof(max_conns
))
2775 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2777 return ERROR_BAD_ARGUMENTS
;
2779 max_conns
= *(ULONG
*)buf
;
2780 return ERROR_SUCCESS
;
2782 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2783 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2785 if(size
!= sizeof(max_1_0_conns
))
2786 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2788 return ERROR_BAD_ARGUMENTS
;
2790 max_1_0_conns
= *(ULONG
*)buf
;
2791 return ERROR_SUCCESS
;
2793 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2794 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2796 if(size
!= sizeof(connect_timeout
))
2797 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2799 return ERROR_BAD_ARGUMENTS
;
2801 connect_timeout
= *(ULONG
*)buf
;
2802 return ERROR_SUCCESS
;
2804 case INTERNET_OPTION_SUPPRESS_BEHAVIOR
:
2805 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2807 if(size
!= sizeof(ULONG
))
2808 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2810 FIXME("%08x\n", *(ULONG
*)buf
);
2811 return ERROR_SUCCESS
;
2814 return INET_SetOption(NULL
, option
, buf
, size
);
2817 /***********************************************************************
2818 * InternetSetOptionW (WININET.@)
2820 * Sets an options on the specified handle
2827 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2828 LPVOID lpBuffer
, DWORD dwBufferLength
)
2830 object_header_t
*lpwhh
;
2834 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2836 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2838 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2840 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2842 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2844 WININET_Release(lpwhh
);
2846 if(res
!= ERROR_SUCCESS
)
2849 return res
== ERROR_SUCCESS
;
2854 case INTERNET_OPTION_HTTP_VERSION
:
2856 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2857 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2860 case INTERNET_OPTION_ERROR_MASK
:
2863 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2865 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2866 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2867 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2868 SetLastError(ERROR_INVALID_PARAMETER
);
2870 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2871 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2874 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2875 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2878 case INTERNET_OPTION_PROXY
:
2880 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2882 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2884 SetLastError(ERROR_INVALID_PARAMETER
);
2889 EnterCriticalSection( &WININET_cs
);
2890 free_global_proxy();
2891 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2894 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2896 global_proxy
->proxyEnabled
= 1;
2897 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2898 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2902 global_proxy
->proxyEnabled
= 0;
2903 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2906 LeaveCriticalSection( &WININET_cs
);
2910 /* In general, each type of object should handle
2911 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2912 * get silently dropped.
2914 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2915 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2920 case INTERNET_OPTION_CODEPAGE
:
2922 ULONG codepage
= *(ULONG
*)lpBuffer
;
2923 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2926 case INTERNET_OPTION_REQUEST_PRIORITY
:
2928 ULONG priority
= *(ULONG
*)lpBuffer
;
2929 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2932 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2934 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2935 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2938 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2940 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2941 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2944 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2945 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2947 case INTERNET_OPTION_END_BROWSER_SESSION
:
2948 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2950 free_authorization_cache();
2952 case INTERNET_OPTION_CONNECTED_STATE
:
2953 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2955 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2956 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2958 case INTERNET_OPTION_SEND_TIMEOUT
:
2959 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2960 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2962 ULONG timeout
= *(ULONG
*)lpBuffer
;
2963 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2966 case INTERNET_OPTION_CONNECT_RETRIES
:
2968 ULONG retries
= *(ULONG
*)lpBuffer
;
2969 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2972 case INTERNET_OPTION_CONTEXT_VALUE
:
2976 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2979 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2981 SetLastError(ERROR_INVALID_PARAMETER
);
2985 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2988 case INTERNET_OPTION_SECURITY_FLAGS
:
2989 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2991 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2992 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2994 case INTERNET_OPTION_HTTP_DECODING
:
2997 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3000 if (!lpBuffer
|| dwBufferLength
!= sizeof(BOOL
))
3002 SetLastError(ERROR_INVALID_PARAMETER
);
3006 lpwhh
->decoding
= *(BOOL
*)lpBuffer
;
3008 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
3009 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
3010 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3013 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
3014 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
3015 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3018 case INTERNET_OPTION_CODEPAGE_PATH
:
3019 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
3020 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3023 case INTERNET_OPTION_CODEPAGE_EXTRA
:
3024 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
3025 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3028 case INTERNET_OPTION_IDN
:
3029 FIXME("INTERNET_OPTION_IDN; STUB\n");
3030 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3033 case INTERNET_OPTION_POLICY
:
3034 SetLastError(ERROR_INVALID_PARAMETER
);
3037 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3038 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
3043 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
3045 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
3046 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
3048 switch (option
->dwOption
) {
3049 case INTERNET_PER_CONN_PROXY_SERVER
:
3050 heap_free(pi
.proxy
);
3051 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
3054 case INTERNET_PER_CONN_FLAGS
:
3055 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
3056 pi
.proxyEnabled
= 1;
3059 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
3060 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
3061 pi
.proxyEnabled
= 0;
3065 case INTERNET_PER_CONN_PROXY_BYPASS
:
3066 heap_free(pi
.proxyBypass
);
3067 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
3070 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3071 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3072 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3073 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3074 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3075 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3076 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
3080 FIXME("Unknown dwOption %d\n", option
->dwOption
);
3081 SetLastError(ERROR_INVALID_PARAMETER
);
3086 if ((res
= INTERNET_SaveProxySettings(&pi
)))
3091 ret
= (res
== ERROR_SUCCESS
);
3095 FIXME("Option %d STUB\n",dwOption
);
3096 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3102 WININET_Release( lpwhh
);
3108 /***********************************************************************
3109 * InternetSetOptionA (WININET.@)
3111 * Sets an options on the specified handle.
3118 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3119 LPVOID lpBuffer
, DWORD dwBufferLength
)
3127 case INTERNET_OPTION_PROXY
:
3129 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3130 LPINTERNET_PROXY_INFOW piw
;
3131 DWORD proxlen
, prbylen
;
3134 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3135 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3136 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3137 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3138 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3139 piw
->dwAccessType
= pi
->dwAccessType
;
3140 prox
= (LPWSTR
) &piw
[1];
3141 prby
= &prox
[proxlen
+1];
3142 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3143 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3144 piw
->lpszProxy
= prox
;
3145 piw
->lpszProxyBypass
= prby
;
3148 case INTERNET_OPTION_USER_AGENT
:
3149 case INTERNET_OPTION_USERNAME
:
3150 case INTERNET_OPTION_PASSWORD
:
3151 case INTERNET_OPTION_PROXY_USERNAME
:
3152 case INTERNET_OPTION_PROXY_PASSWORD
:
3153 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3154 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3155 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3157 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3159 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3160 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3161 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3162 wbuffer
= heap_alloc(wlen
);
3165 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3166 if (listA
->pszConnection
)
3168 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3169 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3170 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3173 listW
->pszConnection
= NULL
;
3174 listW
->dwOptionCount
= listA
->dwOptionCount
;
3175 listW
->dwOptionError
= listA
->dwOptionError
;
3176 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3178 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3179 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3180 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3182 optW
->dwOption
= optA
->dwOption
;
3184 switch (optA
->dwOption
) {
3185 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3186 case INTERNET_PER_CONN_PROXY_BYPASS
:
3187 case INTERNET_PER_CONN_PROXY_SERVER
:
3188 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3189 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3190 if (optA
->Value
.pszValue
)
3192 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3193 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3194 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3197 optW
->Value
.pszValue
= NULL
;
3199 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3200 case INTERNET_PER_CONN_FLAGS
:
3201 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3202 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3204 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3205 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3208 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3209 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3217 wlen
= dwBufferLength
;
3220 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3222 if( lpBuffer
!= wbuffer
)
3224 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3226 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3228 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3229 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3230 switch (opt
->dwOption
) {
3231 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3232 case INTERNET_PER_CONN_PROXY_BYPASS
:
3233 case INTERNET_PER_CONN_PROXY_SERVER
:
3234 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3235 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3236 heap_free( opt
->Value
.pszValue
);
3242 heap_free( list
->pOptions
);
3244 heap_free( wbuffer
);
3251 /***********************************************************************
3252 * InternetSetOptionExA (WININET.@)
3254 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3255 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3257 FIXME("Flags %08x ignored\n", dwFlags
);
3258 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3261 /***********************************************************************
3262 * InternetSetOptionExW (WININET.@)
3264 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3265 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3267 FIXME("Flags %08x ignored\n", dwFlags
);
3268 if( dwFlags
& ~ISO_VALID_FLAGS
)
3270 SetLastError( ERROR_INVALID_PARAMETER
);
3273 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3276 static const WCHAR WININET_wkday
[7][4] =
3277 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3278 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3279 static const WCHAR WININET_month
[12][4] =
3280 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3281 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3282 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3284 /***********************************************************************
3285 * InternetTimeFromSystemTimeA (WININET.@)
3287 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3290 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3292 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3294 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3296 SetLastError(ERROR_INVALID_PARAMETER
);
3300 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3302 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3306 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3307 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3312 /***********************************************************************
3313 * InternetTimeFromSystemTimeW (WININET.@)
3315 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3317 static const WCHAR date
[] =
3318 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3319 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3321 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3323 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3325 SetLastError(ERROR_INVALID_PARAMETER
);
3329 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3331 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3335 swprintf( string
, size
, date
,
3336 WININET_wkday
[time
->wDayOfWeek
],
3338 WININET_month
[time
->wMonth
- 1],
3347 /***********************************************************************
3348 * InternetTimeToSystemTimeA (WININET.@)
3350 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3355 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3357 stringW
= heap_strdupAtoW(string
);
3360 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3361 heap_free( stringW
);
3366 /***********************************************************************
3367 * InternetTimeToSystemTimeW (WININET.@)
3369 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3372 const WCHAR
*s
= string
;
3375 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3377 if (!string
|| !time
) return FALSE
;
3379 /* Windows does this too */
3380 GetSystemTime( time
);
3382 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3383 * a SYSTEMTIME structure.
3386 while (*s
&& !iswalpha( *s
)) s
++;
3387 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3388 time
->wDayOfWeek
= 7;
3390 for (i
= 0; i
< 7; i
++)
3392 if (!wcsnicmp( WININET_wkday
[i
], s
, 3 ))
3394 time
->wDayOfWeek
= i
;
3399 if (time
->wDayOfWeek
> 6) return TRUE
;
3400 while (*s
&& !iswdigit( *s
)) s
++;
3401 time
->wDay
= wcstol( s
, &end
, 10 );
3404 while (*s
&& !iswalpha( *s
)) s
++;
3405 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3408 for (i
= 0; i
< 12; i
++)
3410 if (!wcsnicmp( WININET_month
[i
], s
, 3 ))
3412 time
->wMonth
= i
+ 1;
3416 if (time
->wMonth
== 0) return TRUE
;
3418 while (*s
&& !iswdigit( *s
)) s
++;
3419 if (*s
== '\0') return TRUE
;
3420 time
->wYear
= wcstol( s
, &end
, 10 );
3423 while (*s
&& !iswdigit( *s
)) s
++;
3424 if (*s
== '\0') return TRUE
;
3425 time
->wHour
= wcstol( s
, &end
, 10 );
3428 while (*s
&& !iswdigit( *s
)) s
++;
3429 if (*s
== '\0') return TRUE
;
3430 time
->wMinute
= wcstol( s
, &end
, 10 );
3433 while (*s
&& !iswdigit( *s
)) s
++;
3434 if (*s
== '\0') return TRUE
;
3435 time
->wSecond
= wcstol( s
, &end
, 10 );
3438 time
->wMilliseconds
= 0;
3442 /***********************************************************************
3443 * InternetCheckConnectionW (WININET.@)
3445 * Pings a requested host to check internet connection
3448 * TRUE on success and FALSE on failure. If a failure then
3449 * ERROR_NOT_CONNECTED is placed into GetLastError
3452 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3455 * this is a kludge which runs the resident ping program and reads the output.
3457 * Anyone have a better idea?
3461 static const CHAR ping
[] = "ping -c 1 ";
3462 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3464 DWORD len
, host_len
;
3468 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl
), dwFlags
, dwReserved
);
3471 * Crack or set the Address
3473 if (lpszUrl
== NULL
)
3476 * According to the doc we are supposed to use the ip for the next
3477 * server in the WnInet internal server database. I have
3478 * no idea what that is or how to get it.
3480 * So someone needs to implement this.
3482 FIXME("Unimplemented with URL of NULL\n");
3487 URL_COMPONENTSW components
= {sizeof(components
)};
3489 components
.dwHostNameLength
= 1;
3491 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3494 host
= components
.lpszHostName
;
3495 host_len
= components
.dwHostNameLength
;
3496 port
= components
.nPort
;
3497 TRACE("host name: %s port: %d\n",debugstr_wn(host
, host_len
), port
);
3500 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3502 struct sockaddr_storage saddr
;
3503 int sa_len
= sizeof(saddr
);
3508 host_z
= heap_strndupW(host
, host_len
);
3512 b
= GetAddress(host_z
, port
, (struct sockaddr
*)&saddr
, &sa_len
, NULL
);
3517 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3520 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3528 * Build our ping command
3532 len
= WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, NULL
, 0, NULL
, NULL
);
3533 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
)+1);
3534 strcpy(command
, ping
);
3535 WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, command
+sizeof(ping
)-1, len
, NULL
, NULL
);
3536 strcpy(command
+sizeof(ping
)-1+len
, redirect
);
3538 TRACE("Ping command is : %s\n",command
);
3540 status
= system(command
);
3541 heap_free( command
);
3543 TRACE("Ping returned a code of %i\n",status
);
3545 /* Ping return code of 0 indicates success */
3552 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3558 /***********************************************************************
3559 * InternetCheckConnectionA (WININET.@)
3561 * Pings a requested host to check internet connection
3564 * TRUE on success and FALSE on failure. If a failure then
3565 * ERROR_NOT_CONNECTED is placed into GetLastError
3568 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3574 url
= heap_strdupAtoW(lpszUrl
);
3579 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3586 /**********************************************************
3587 * INTERNET_InternetOpenUrlW (internal)
3592 * handle of connection or NULL on failure
3594 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3595 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3597 URL_COMPONENTSW urlComponents
= { sizeof(urlComponents
) };
3598 WCHAR
*host
, *user
= NULL
, *pass
= NULL
, *path
;
3599 HINTERNET client
= NULL
, client1
= NULL
;
3602 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3603 dwHeadersLength
, dwFlags
, dwContext
);
3605 urlComponents
.dwHostNameLength
= 1;
3606 urlComponents
.dwUserNameLength
= 1;
3607 urlComponents
.dwPasswordLength
= 1;
3608 urlComponents
.dwUrlPathLength
= 1;
3609 urlComponents
.dwExtraInfoLength
= 1;
3610 if(!InternetCrackUrlW(lpszUrl
, lstrlenW(lpszUrl
), 0, &urlComponents
))
3613 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
3614 urlComponents
.dwExtraInfoLength
)
3616 assert(urlComponents
.lpszUrlPath
+ urlComponents
.dwUrlPathLength
== urlComponents
.lpszExtraInfo
);
3617 urlComponents
.dwUrlPathLength
+= urlComponents
.dwExtraInfoLength
;
3620 host
= heap_strndupW(urlComponents
.lpszHostName
, urlComponents
.dwHostNameLength
);
3621 path
= heap_strndupW(urlComponents
.lpszUrlPath
, urlComponents
.dwUrlPathLength
);
3622 if(urlComponents
.dwUserNameLength
)
3623 user
= heap_strndupW(urlComponents
.lpszUserName
, urlComponents
.dwUserNameLength
);
3624 if(urlComponents
.dwPasswordLength
)
3625 pass
= heap_strndupW(urlComponents
.lpszPassword
, urlComponents
.dwPasswordLength
);
3627 switch(urlComponents
.nScheme
) {
3628 case INTERNET_SCHEME_FTP
:
3629 client
= FTP_Connect(hIC
, host
, urlComponents
.nPort
,
3630 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
);
3633 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3634 if(client1
== NULL
) {
3635 InternetCloseHandle(client
);
3640 case INTERNET_SCHEME_HTTP
:
3641 case INTERNET_SCHEME_HTTPS
: {
3642 static const WCHAR szStars
[] = { '*','/','*', 0 };
3643 LPCWSTR accept
[2] = { szStars
, NULL
};
3645 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3647 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3648 res
= HTTP_Connect(hIC
, host
, urlComponents
.nPort
,
3649 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3650 if(res
!= ERROR_SUCCESS
) {
3651 INTERNET_SetLastError(res
);
3655 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3656 if(client1
== NULL
) {
3657 InternetCloseHandle(client
);
3660 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3661 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3662 GetLastError() != ERROR_IO_PENDING
) {
3663 InternetCloseHandle(client1
);
3668 case INTERNET_SCHEME_GOPHER
:
3669 /* gopher doesn't seem to be implemented in wine, but it's supposed
3670 * to be supported by InternetOpenUrlA. */
3672 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3676 TRACE(" %p <--\n", client1
);
3685 /**********************************************************
3686 * InternetOpenUrlW (WININET.@)
3691 * handle of connection or NULL on failure
3702 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3704 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3706 TRACE("%p\n", task
->hdr
.hdr
);
3708 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3709 task
->headers_len
, task
->flags
, task
->context
);
3710 heap_free(task
->url
);
3711 heap_free(task
->headers
);
3714 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3715 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3717 HINTERNET ret
= NULL
;
3718 appinfo_t
*hIC
= NULL
;
3720 if (TRACE_ON(wininet
)) {
3721 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3722 dwHeadersLength
, dwFlags
, dwContext
);
3724 dump_INTERNET_FLAGS(dwFlags
);
3729 SetLastError(ERROR_INVALID_PARAMETER
);
3733 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3734 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3735 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3739 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3740 open_url_task_t
*task
;
3742 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3743 task
->url
= heap_strdupW(lpszUrl
);
3744 task
->headers
= heap_strdupW(lpszHeaders
);
3745 task
->headers_len
= dwHeadersLength
;
3746 task
->flags
= dwFlags
;
3747 task
->context
= dwContext
;
3749 INTERNET_AsyncCall(&task
->hdr
);
3750 SetLastError(ERROR_IO_PENDING
);
3752 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3757 WININET_Release( &hIC
->hdr
);
3758 TRACE(" %p <--\n", ret
);
3763 /**********************************************************
3764 * InternetOpenUrlA (WININET.@)
3769 * handle of connection or NULL on failure
3771 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3772 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3774 HINTERNET rc
= NULL
;
3775 LPWSTR szUrl
= NULL
;
3776 WCHAR
*headers
= NULL
;
3781 szUrl
= heap_strdupAtoW(lpszUrl
);
3787 headers
= heap_strndupAtoW(lpszHeaders
, dwHeadersLength
, &dwHeadersLength
);
3794 rc
= InternetOpenUrlW(hInternet
, szUrl
, headers
, dwHeadersLength
, dwFlags
, dwContext
);
3802 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3804 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3808 lpwite
->dwError
= 0;
3809 lpwite
->response
[0] = '\0';
3812 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3821 /***********************************************************************
3822 * INTERNET_SetLastError (internal)
3824 * Set last thread specific error
3829 void INTERNET_SetLastError(DWORD dwError
)
3831 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3834 lpwite
= INTERNET_AllocThreadError();
3836 SetLastError(dwError
);
3838 lpwite
->dwError
= dwError
;
3842 /***********************************************************************
3843 * INTERNET_GetLastError (internal)
3845 * Get last thread specific error
3850 DWORD
INTERNET_GetLastError(void)
3852 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3853 if (!lpwite
) return 0;
3854 /* TlsGetValue clears last error, so set it again here */
3855 SetLastError(lpwite
->dwError
);
3856 return lpwite
->dwError
;
3860 /***********************************************************************
3861 * INTERNET_WorkerThreadFunc (internal)
3863 * Worker thread execution function
3868 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3870 task_header_t
*task
= lpvParam
;
3875 WININET_Release(task
->hdr
);
3878 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3880 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3881 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3886 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3888 task_header_t
*task
;
3890 task
= heap_alloc(size
);
3894 task
->hdr
= WININET_AddRef(hdr
);
3899 /***********************************************************************
3900 * INTERNET_AsyncCall (internal)
3902 * Retrieves work request from queue
3907 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3913 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3917 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3919 return ERROR_SUCCESS
;
3923 /***********************************************************************
3924 * INTERNET_GetResponseBuffer (internal)
3929 LPSTR
INTERNET_GetResponseBuffer(void)
3931 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3933 lpwite
= INTERNET_AllocThreadError();
3935 return lpwite
->response
;
3938 /**********************************************************
3939 * InternetQueryDataAvailable (WININET.@)
3941 * Determines how much data is available to be read.
3944 * TRUE on success, FALSE if an error occurred. If
3945 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3946 * no data is presently available, FALSE is returned with
3947 * the last error ERROR_IO_PENDING; a callback with status
3948 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3949 * data is available.
3951 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3952 LPDWORD lpdwNumberOfBytesAvailable
,
3953 DWORD dwFlags
, DWORD_PTR dwContext
)
3955 object_header_t
*hdr
;
3958 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3960 hdr
= get_handle_object( hFile
);
3962 SetLastError(ERROR_INVALID_HANDLE
);
3966 if(hdr
->vtbl
->QueryDataAvailable
) {
3967 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3969 WARN("wrong handle\n");
3970 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3973 WININET_Release(hdr
);
3975 if(res
!= ERROR_SUCCESS
)
3977 return res
== ERROR_SUCCESS
;
3980 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3982 req_file_t
*req_file
;
3984 req_file
= heap_alloc_zero(sizeof(*req_file
));
3986 return ERROR_NOT_ENOUGH_MEMORY
;
3990 req_file
->file_name
= heap_strdupW(file_name
);
3991 if(!req_file
->file_name
) {
3992 heap_free(req_file
);
3993 return ERROR_NOT_ENOUGH_MEMORY
;
3996 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3997 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3998 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
3999 req_file_release(req_file
);
4000 return GetLastError();
4004 return ERROR_SUCCESS
;
4007 void req_file_release(req_file_t
*req_file
)
4009 if(InterlockedDecrement(&req_file
->ref
))
4012 if(!req_file
->is_committed
)
4013 DeleteFileW(req_file
->file_name
);
4014 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
4015 CloseHandle(req_file
->file_handle
);
4016 heap_free(req_file
->file_name
);
4017 heap_free(req_file
->url
);
4018 heap_free(req_file
);
4021 /***********************************************************************
4022 * InternetLockRequestFile (WININET.@)
4024 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
4026 req_file_t
*req_file
= NULL
;
4027 object_header_t
*hdr
;
4030 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
4032 hdr
= get_handle_object(hInternet
);
4034 SetLastError(ERROR_INVALID_HANDLE
);
4038 if(hdr
->vtbl
->LockRequestFile
) {
4039 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
4041 WARN("wrong handle\n");
4042 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4045 WININET_Release(hdr
);
4047 *lphLockReqHandle
= req_file
;
4048 if(res
!= ERROR_SUCCESS
)
4050 return res
== ERROR_SUCCESS
;
4053 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
4055 TRACE("(%p)\n", hLockHandle
);
4057 req_file_release(hLockHandle
);
4062 /***********************************************************************
4063 * InternetAutodial (WININET.@)
4065 * On windows this function is supposed to dial the default internet
4066 * connection. We don't want to have Wine dial out to the internet so
4067 * we return TRUE by default. It might be nice to check if we are connected.
4074 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
4078 /* Tell that we are connected to the internet. */
4082 /***********************************************************************
4083 * InternetAutodialHangup (WININET.@)
4085 * Hangs up a connection made with InternetAutodial
4094 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
4098 /* we didn't dial, we don't disconnect */
4102 /***********************************************************************
4103 * InternetCombineUrlA (WININET.@)
4105 * Combine a base URL with a relative URL
4113 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
4114 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4119 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4121 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4122 dwFlags
^= ICU_NO_ENCODE
;
4123 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4128 /***********************************************************************
4129 * InternetCombineUrlW (WININET.@)
4131 * Combine a base URL with a relative URL
4139 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4140 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4145 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4147 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4148 dwFlags
^= ICU_NO_ENCODE
;
4149 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4154 /* max port num is 65535 => 5 digits */
4155 #define MAX_WORD_DIGITS 5
4157 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4158 (url)->dw##component##Length : lstrlenW((url)->lpsz##component))
4159 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4160 (url)->dw##component##Length : strlen((url)->lpsz##component))
4162 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4164 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4165 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4167 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4168 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4170 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4171 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4173 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4174 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4177 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4183 /* opaque urls do not fit into the standard url hierarchy and don't have
4184 * two following slashes */
4185 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4187 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4188 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4189 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4190 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4191 (nScheme
!= INTERNET_SCHEME_FILE
);
4194 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4197 if (scheme
< INTERNET_SCHEME_FIRST
)
4199 index
= scheme
- INTERNET_SCHEME_FIRST
;
4200 if (index
>= ARRAY_SIZE(url_schemes
))
4202 return (LPCWSTR
)url_schemes
[index
];
4205 /* we can calculate using ansi strings because we're just
4206 * calculating string length, not size
4208 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4209 LPDWORD lpdwUrlLength
)
4211 INTERNET_SCHEME nScheme
;
4215 if (lpUrlComponents
->lpszScheme
)
4217 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4218 *lpdwUrlLength
+= dwLen
;
4219 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4225 nScheme
= lpUrlComponents
->nScheme
;
4227 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4228 nScheme
= INTERNET_SCHEME_HTTP
;
4229 scheme
= INTERNET_GetSchemeString(nScheme
);
4230 *lpdwUrlLength
+= lstrlenW(scheme
);
4233 (*lpdwUrlLength
)++; /* ':' */
4234 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4235 *lpdwUrlLength
+= strlen("//");
4237 if (lpUrlComponents
->lpszUserName
)
4239 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4240 *lpdwUrlLength
+= strlen("@");
4244 if (lpUrlComponents
->lpszPassword
)
4246 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4251 if (lpUrlComponents
->lpszPassword
)
4253 *lpdwUrlLength
+= strlen(":");
4254 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4257 if (lpUrlComponents
->lpszHostName
)
4259 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4261 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4263 char szPort
[MAX_WORD_DIGITS
+1];
4265 *lpdwUrlLength
+= sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4266 *lpdwUrlLength
+= strlen(":");
4269 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4270 (*lpdwUrlLength
)++; /* '/' */
4273 if (lpUrlComponents
->lpszUrlPath
)
4274 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4276 if (lpUrlComponents
->lpszExtraInfo
)
4277 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4282 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4286 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4288 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4289 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4290 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4291 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4292 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4293 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4294 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4295 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4296 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4298 if (lpUrlComponents
->lpszScheme
)
4300 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4301 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4302 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4303 -1, urlCompW
->lpszScheme
, len
);
4306 if (lpUrlComponents
->lpszHostName
)
4308 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4309 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4310 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4311 -1, urlCompW
->lpszHostName
, len
);
4314 if (lpUrlComponents
->lpszUserName
)
4316 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4317 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4318 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4319 -1, urlCompW
->lpszUserName
, len
);
4322 if (lpUrlComponents
->lpszPassword
)
4324 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4325 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4326 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4327 -1, urlCompW
->lpszPassword
, len
);
4330 if (lpUrlComponents
->lpszUrlPath
)
4332 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4333 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4334 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4335 -1, urlCompW
->lpszUrlPath
, len
);
4338 if (lpUrlComponents
->lpszExtraInfo
)
4340 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4341 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4342 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4343 -1, urlCompW
->lpszExtraInfo
, len
);
4347 /***********************************************************************
4348 * InternetCreateUrlA (WININET.@)
4350 * See InternetCreateUrlW.
4352 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4353 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4357 URL_COMPONENTSW urlCompW
;
4359 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4361 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4363 SetLastError(ERROR_INVALID_PARAMETER
);
4367 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4370 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4372 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4374 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4375 *lpdwUrlLength
/= sizeof(WCHAR
);
4377 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4378 * minus one, so add one to leave room for NULL terminator
4381 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4383 heap_free(urlCompW
.lpszScheme
);
4384 heap_free(urlCompW
.lpszHostName
);
4385 heap_free(urlCompW
.lpszUserName
);
4386 heap_free(urlCompW
.lpszPassword
);
4387 heap_free(urlCompW
.lpszUrlPath
);
4388 heap_free(urlCompW
.lpszExtraInfo
);
4393 /***********************************************************************
4394 * InternetCreateUrlW (WININET.@)
4396 * Creates a URL from its component parts.
4399 * lpUrlComponents [I] URL Components.
4400 * dwFlags [I] Flags. See notes.
4401 * lpszUrl [I] Buffer in which to store the created URL.
4402 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4403 * lpszUrl in characters. On output, the number of bytes
4404 * required to store the URL including terminator.
4408 * The dwFlags parameter can be zero or more of the following:
4409 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4416 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4417 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4420 INTERNET_SCHEME nScheme
;
4421 WCHAR
*start
= lpszUrl
;
4423 static const WCHAR slashSlashW
[] = {'/','/'};
4424 static const WCHAR fmtW
[] = {'%','u',0};
4426 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4428 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4430 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4434 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4437 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4439 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4440 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4444 *lpdwUrlLength
= dwLen
;
4449 if (lpUrlComponents
->lpszScheme
)
4451 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4452 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4455 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4460 nScheme
= lpUrlComponents
->nScheme
;
4462 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4463 nScheme
= INTERNET_SCHEME_HTTP
;
4465 scheme
= INTERNET_GetSchemeString(nScheme
);
4466 dwLen
= lstrlenW(scheme
);
4467 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4471 /* all schemes are followed by at least a colon */
4475 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4477 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4478 lpszUrl
+= ARRAY_SIZE(slashSlashW
);
4481 if (lpUrlComponents
->lpszUserName
)
4483 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4484 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4487 if (lpUrlComponents
->lpszPassword
)
4492 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4493 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4501 if (lpUrlComponents
->lpszHostName
)
4503 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4504 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4507 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4511 lpszUrl
+= swprintf(lpszUrl
, *lpdwUrlLength
- (lpszUrl
- start
), fmtW
, lpUrlComponents
->nPort
);
4514 /* add slash between hostname and path if necessary */
4515 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4522 if (lpUrlComponents
->lpszUrlPath
)
4524 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4525 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4529 if (lpUrlComponents
->lpszExtraInfo
)
4531 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4532 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4541 /***********************************************************************
4542 * InternetConfirmZoneCrossingA (WININET.@)
4545 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4547 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4548 return ERROR_SUCCESS
;
4551 /***********************************************************************
4552 * InternetConfirmZoneCrossingW (WININET.@)
4555 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4557 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4558 return ERROR_SUCCESS
;
4561 static DWORD zone_preference
= 3;
4563 /***********************************************************************
4564 * PrivacySetZonePreferenceW (WININET.@)
4566 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4568 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4570 zone_preference
= template;
4574 /***********************************************************************
4575 * PrivacyGetZonePreferenceW (WININET.@)
4577 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4578 LPWSTR preference
, LPDWORD length
)
4580 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4582 if (template) *template = zone_preference
;
4586 /***********************************************************************
4587 * InternetGetSecurityInfoByURLA (WININET.@)
4589 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4594 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4596 url
= heap_strdupAtoW(lpszURL
);
4600 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4605 /***********************************************************************
4606 * InternetGetSecurityInfoByURLW (WININET.@)
4608 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4610 URL_COMPONENTSW url
= {sizeof(url
)};
4614 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4616 if (!ppCertChain
&& !pdwSecureFlags
) {
4617 SetLastError(ERROR_INVALID_PARAMETER
);
4621 url
.dwHostNameLength
= 1;
4622 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4623 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4624 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4628 server
= get_server(substr(url
.lpszHostName
, url
.dwHostNameLength
), url
.nPort
, TRUE
, FALSE
);
4630 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4634 if(server
->cert_chain
) {
4636 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4638 if(ppCertChain
&& !(*ppCertChain
= CertDuplicateCertificateChain(server
->cert_chain
)))
4641 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4645 server_release(server
);
4649 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4650 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4652 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4653 lpdwConnection
, dwReserved
);
4654 return ERROR_SUCCESS
;
4657 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4658 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4660 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4661 lpdwConnection
, dwReserved
);
4662 return ERROR_SUCCESS
;
4665 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4667 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4671 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4673 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4677 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4679 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4680 return ERROR_SUCCESS
;
4683 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4686 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4687 debugstr_w(pwszTarget
), pbHexHash
);
4691 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4693 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4697 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4699 FIXME("(%p, %08lx) stub\n", a
, b
);
4703 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4705 FIXME("%p: stub\n", parent
);