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
34 CHAR response
[MAX_REPLY_LEN
];
35 } WITHREADERROR
, *LPWITHREADERROR
;
37 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
38 HMODULE WININET_hModule
;
40 static CRITICAL_SECTION WININET_cs
;
41 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
44 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
45 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
47 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
49 static object_header_t
**handle_table
;
50 static UINT_PTR next_handle
;
51 static UINT_PTR handle_table_size
;
62 static ULONG max_conns
= 2, max_1_0_conns
= 4;
63 static ULONG connect_timeout
= 60000;
65 static const WCHAR szInternetSettings
[] =
66 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
67 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
68 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
69 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
70 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
71 static const WCHAR szProxyOverride
[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
73 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
75 UINT_PTR handle
= 0, num
;
80 ret
= heap_alloc_zero(size
);
84 list_init(&ret
->children
);
86 EnterCriticalSection( &WININET_cs
);
88 if(!handle_table_size
) {
90 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
93 handle_table_size
= num
;
98 }else if(next_handle
== handle_table_size
) {
99 num
= handle_table_size
* 2;
100 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
103 handle_table_size
= num
;
110 handle
= next_handle
;
111 if(handle_table
[handle
])
112 ERR("handle isn't free but should be\n");
113 handle_table
[handle
] = ret
;
114 ret
->valid_handle
= TRUE
;
116 while(next_handle
< handle_table_size
&& handle_table
[next_handle
])
120 LeaveCriticalSection( &WININET_cs
);
129 ret
->hInternet
= (HINTERNET
)handle
;
132 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
133 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
139 object_header_t
*WININET_AddRef( object_header_t
*info
)
141 ULONG refs
= InterlockedIncrement(&info
->refs
);
142 TRACE("%p -> refcount = %d\n", info
, refs
);
146 object_header_t
*get_handle_object( HINTERNET hinternet
)
148 object_header_t
*info
= NULL
;
149 UINT_PTR handle
= (UINT_PTR
) hinternet
;
151 EnterCriticalSection( &WININET_cs
);
153 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
154 info
= WININET_AddRef(handle_table
[handle
]);
156 LeaveCriticalSection( &WININET_cs
);
158 TRACE("handle %ld -> %p\n", handle
, info
);
163 static void invalidate_handle(object_header_t
*info
)
165 object_header_t
*child
, *next
;
167 if(!info
->valid_handle
)
169 info
->valid_handle
= FALSE
;
171 /* Free all children as native does */
172 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
174 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
175 invalidate_handle( child
);
178 WININET_Release(info
);
181 BOOL
WININET_Release( object_header_t
*info
)
183 ULONG refs
= InterlockedDecrement(&info
->refs
);
184 TRACE( "object %p refcount = %d\n", info
, refs
);
187 invalidate_handle(info
);
188 if ( info
->vtbl
->CloseConnection
)
190 TRACE( "closing connection %p\n", info
);
191 info
->vtbl
->CloseConnection( info
);
193 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
194 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
195 || !(info
->dwInternalFlags
& INET_OPENURL
))
197 INTERNET_SendCallback(info
, info
->dwContext
,
198 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
201 TRACE( "destroying object %p\n", info
);
202 if ( info
->htype
!= WH_HINIT
)
203 list_remove( &info
->entry
);
204 info
->vtbl
->Destroy( info
);
206 if(info
->hInternet
) {
207 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
209 EnterCriticalSection( &WININET_cs
);
211 handle_table
[handle
] = NULL
;
212 if(next_handle
> handle
)
213 next_handle
= handle
;
215 LeaveCriticalSection( &WININET_cs
);
223 /***********************************************************************
224 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
227 * hinstDLL [I] handle to the DLL's instance
229 * lpvReserved [I] reserved, must be NULL
236 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
238 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
241 case DLL_PROCESS_ATTACH
:
243 g_dwTlsErrIndex
= TlsAlloc();
245 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
250 TlsFree(g_dwTlsErrIndex
);
254 WININET_hModule
= hinstDLL
;
257 case DLL_THREAD_ATTACH
:
260 case DLL_THREAD_DETACH
:
261 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
263 heap_free(TlsGetValue(g_dwTlsErrIndex
));
267 case DLL_PROCESS_DETACH
:
268 if (lpvReserved
) break;
269 collect_connections(COLLECT_CLEANUP
);
274 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
276 heap_free(TlsGetValue(g_dwTlsErrIndex
));
277 TlsFree(g_dwTlsErrIndex
);
284 /***********************************************************************
285 * DllInstall (WININET.@)
287 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
289 FIXME("(%x %s): stub\n", bInstall
, debugstr_w(cmdline
));
293 /***********************************************************************
294 * INTERNET_SaveProxySettings
296 * Stores the proxy settings given by lpwai into the registry
299 * ERROR_SUCCESS if no error, or error code on fail
301 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
306 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
309 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
317 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
325 if ((ret
= RegDeleteValueW( key
, szProxyServer
)) && ret
!= ERROR_FILE_NOT_FOUND
)
333 return ERROR_SUCCESS
;
336 /***********************************************************************
337 * INTERNET_FindProxyForProtocol
339 * Searches the proxy string for a proxy of the given protocol.
340 * Returns the found proxy, or the default proxy if none of the given
344 * szProxy [In] proxy string to search
345 * proto [In] protocol to search for, e.g. "http"
346 * foundProxy [Out] found proxy
347 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
350 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
351 * *foundProxyLen is set to the required size in WCHARs, including the
352 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
354 WCHAR
*INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
)
359 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
361 /* First, look for the specified protocol (proto=scheme://host:port) */
362 for (ptr
= szProxy
; ptr
&& *ptr
; )
366 if (!(end
= strchrW(ptr
, ' ')))
367 end
= ptr
+ strlenW(ptr
);
368 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
369 equal
- ptr
== strlenW(proto
) &&
370 !strncmpiW(proto
, ptr
, strlenW(proto
)))
372 ret
= heap_strndupW(equal
+ 1, end
- equal
- 1);
373 TRACE("found proxy for %s: %s\n", debugstr_w(proto
), debugstr_w(ret
));
382 /* It wasn't found: look for no protocol */
383 for (ptr
= szProxy
; ptr
&& *ptr
; )
387 if (!(end
= strchrW(ptr
, ' ')))
388 end
= ptr
+ strlenW(ptr
);
389 if (!strchrW(ptr
, '='))
391 ret
= heap_strndupW(ptr
, end
- ptr
);
392 TRACE("found proxy for %s: %s\n", debugstr_w(proto
), debugstr_w(ret
));
404 /***********************************************************************
405 * InternetInitializeAutoProxyDll (WININET.@)
407 * Setup the internal proxy
416 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
419 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
423 /***********************************************************************
424 * DetectAutoProxyUrl (WININET.@)
426 * Auto detect the proxy url
432 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
433 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
436 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
440 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
442 heap_free(lpwpi
->proxy
);
443 heap_free(lpwpi
->proxyBypass
);
444 heap_free(lpwpi
->proxyUsername
);
445 heap_free(lpwpi
->proxyPassword
);
448 static proxyinfo_t
*global_proxy
;
450 static void free_global_proxy( void )
452 EnterCriticalSection( &WININET_cs
);
455 FreeProxyInfo( global_proxy
);
456 heap_free( global_proxy
);
458 LeaveCriticalSection( &WININET_cs
);
461 static BOOL
parse_proxy_url( proxyinfo_t
*info
, const WCHAR
*url
)
463 static const WCHAR fmt
[] = {'%','.','*','s',':','%','u',0};
464 URL_COMPONENTSW uc
= {sizeof(uc
)};
466 uc
.dwHostNameLength
= 1;
467 uc
.dwUserNameLength
= 1;
468 uc
.dwPasswordLength
= 1;
470 if (!InternetCrackUrlW( url
, 0, 0, &uc
)) return FALSE
;
471 if (!uc
.dwHostNameLength
)
473 if (!(info
->proxy
= heap_strdupW( url
))) return FALSE
;
474 info
->proxyUsername
= NULL
;
475 info
->proxyPassword
= NULL
;
478 if (!(info
->proxy
= heap_alloc( (uc
.dwHostNameLength
+ 12) * sizeof(WCHAR
) ))) return FALSE
;
479 sprintfW( info
->proxy
, fmt
, uc
.dwHostNameLength
, uc
.lpszHostName
, uc
.nPort
);
481 if (!uc
.dwUserNameLength
) info
->proxyUsername
= NULL
;
482 else if (!(info
->proxyUsername
= heap_strndupW( uc
.lpszUserName
, uc
.dwUserNameLength
)))
484 heap_free( info
->proxy
);
487 if (!uc
.dwPasswordLength
) info
->proxyPassword
= NULL
;
488 else if (!(info
->proxyPassword
= heap_strndupW( uc
.lpszPassword
, uc
.dwPasswordLength
)))
490 heap_free( info
->proxyUsername
);
491 heap_free( info
->proxy
);
497 /***********************************************************************
498 * INTERNET_LoadProxySettings
500 * Loads proxy information from process-wide global settings, the registry,
501 * or the environment into lpwpi.
503 * The caller should call FreeProxyInfo when done with lpwpi.
506 * The proxy may be specified in the form 'http=proxy.my.org'
507 * Presumably that means there can be ftp=ftpproxy.my.org too.
509 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
516 memset( lpwpi
, 0, sizeof(*lpwpi
) );
518 EnterCriticalSection( &WININET_cs
);
521 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
522 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
523 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
525 LeaveCriticalSection( &WININET_cs
);
527 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
529 FreeProxyInfo( lpwpi
);
534 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
536 lpwpi
->proxyEnabled
= 0;
537 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
539 FreeProxyInfo( lpwpi
);
545 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
547 /* figure out how much memory the proxy setting takes */
548 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
551 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
553 if (!(szProxy
= heap_alloc(len
)))
556 FreeProxyInfo( lpwpi
);
557 return ERROR_OUTOFMEMORY
;
559 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
561 /* find the http proxy, and strip away everything else */
562 p
= strstrW( szProxy
, szHttp
);
565 p
+= lstrlenW( szHttp
);
566 lstrcpyW( szProxy
, p
);
568 p
= strchrW( szProxy
, ';' );
571 FreeProxyInfo( lpwpi
);
572 lpwpi
->proxy
= szProxy
;
573 lpwpi
->proxyBypass
= NULL
;
575 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi
->proxy
));
579 TRACE("No proxy server settings in registry.\n");
580 FreeProxyInfo( lpwpi
);
582 lpwpi
->proxyBypass
= NULL
;
589 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
590 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
593 return ERROR_OUTOFMEMORY
;
595 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
597 FreeProxyInfo( lpwpi
);
598 if (parse_proxy_url( lpwpi
, envproxyW
))
600 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
601 lpwpi
->proxyEnabled
= 1;
602 lpwpi
->proxyBypass
= NULL
;
606 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW
));
607 lpwpi
->proxyEnabled
= 0;
609 lpwpi
->proxyBypass
= NULL
;
611 heap_free( envproxyW
);
614 if (lpwpi
->proxyEnabled
)
616 TRACE("Proxy is enabled.\n");
618 if (!(envproxy
= getenv( "no_proxy" )))
620 /* figure out how much memory the proxy setting takes */
621 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
625 if (!(szProxy
= heap_alloc(len
)))
628 return ERROR_OUTOFMEMORY
;
630 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
632 heap_free( lpwpi
->proxyBypass
);
633 lpwpi
->proxyBypass
= szProxy
;
635 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
639 heap_free( lpwpi
->proxyBypass
);
640 lpwpi
->proxyBypass
= NULL
;
642 TRACE("No proxy bypass server settings in registry.\n");
649 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
650 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
653 return ERROR_OUTOFMEMORY
;
655 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
657 heap_free( lpwpi
->proxyBypass
);
658 lpwpi
->proxyBypass
= envproxyW
;
660 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
663 else TRACE("Proxy is disabled.\n");
666 return ERROR_SUCCESS
;
669 /***********************************************************************
670 * INTERNET_ConfigureProxy
672 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
676 if (INTERNET_LoadProxySettings( &wpi
))
679 if (wpi
.proxyEnabled
)
681 TRACE("http proxy = %s bypass = %s\n", debugstr_w(wpi
.proxy
), debugstr_w(wpi
.proxyBypass
));
683 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
684 lpwai
->proxy
= wpi
.proxy
;
685 lpwai
->proxyBypass
= wpi
.proxyBypass
;
686 lpwai
->proxyUsername
= wpi
.proxyUsername
;
687 lpwai
->proxyPassword
= wpi
.proxyPassword
;
691 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
696 /***********************************************************************
697 * dump_INTERNET_FLAGS
699 * Helper function to TRACE the internet flags.
705 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
707 #define FE(x) { x, #x }
708 static const wininet_flag_info flag
[] = {
709 FE(INTERNET_FLAG_RELOAD
),
710 FE(INTERNET_FLAG_RAW_DATA
),
711 FE(INTERNET_FLAG_EXISTING_CONNECT
),
712 FE(INTERNET_FLAG_ASYNC
),
713 FE(INTERNET_FLAG_PASSIVE
),
714 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
715 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
716 FE(INTERNET_FLAG_FROM_CACHE
),
717 FE(INTERNET_FLAG_SECURE
),
718 FE(INTERNET_FLAG_KEEP_CONNECTION
),
719 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
720 FE(INTERNET_FLAG_READ_PREFETCH
),
721 FE(INTERNET_FLAG_NO_COOKIES
),
722 FE(INTERNET_FLAG_NO_AUTH
),
723 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
724 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
725 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
726 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
727 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
728 FE(INTERNET_FLAG_RESYNCHRONIZE
),
729 FE(INTERNET_FLAG_HYPERLINK
),
730 FE(INTERNET_FLAG_NO_UI
),
731 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
732 FE(INTERNET_FLAG_CACHE_ASYNC
),
733 FE(INTERNET_FLAG_FORMS_SUBMIT
),
734 FE(INTERNET_FLAG_NEED_FILE
),
735 FE(INTERNET_FLAG_TRANSFER_ASCII
),
736 FE(INTERNET_FLAG_TRANSFER_BINARY
)
741 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
742 if (flag
[i
].val
& dwFlags
) {
743 TRACE(" %s", flag
[i
].name
);
744 dwFlags
&= ~flag
[i
].val
;
748 TRACE(" Unknown flags (%08x)\n", dwFlags
);
753 /***********************************************************************
754 * INTERNET_CloseHandle (internal)
756 * Close internet handle
759 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
761 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
765 heap_free(lpwai
->agent
);
766 heap_free(lpwai
->proxy
);
767 heap_free(lpwai
->proxyBypass
);
768 heap_free(lpwai
->proxyUsername
);
769 heap_free(lpwai
->proxyPassword
);
772 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
774 appinfo_t
*ai
= (appinfo_t
*)hdr
;
777 case INTERNET_OPTION_HANDLE_TYPE
:
778 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
780 if (*size
< sizeof(ULONG
))
781 return ERROR_INSUFFICIENT_BUFFER
;
783 *size
= sizeof(DWORD
);
784 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
785 return ERROR_SUCCESS
;
787 case INTERNET_OPTION_USER_AGENT
: {
790 TRACE("INTERNET_OPTION_USER_AGENT\n");
795 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
797 *size
= (len
+ 1) * sizeof(WCHAR
);
798 if(!buffer
|| bufsize
< *size
)
799 return ERROR_INSUFFICIENT_BUFFER
;
802 strcpyW(buffer
, ai
->agent
);
804 *(WCHAR
*)buffer
= 0;
805 /* If the buffer is copied, the returned length doesn't include
806 * the NULL terminator.
811 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
814 if(!buffer
|| bufsize
< *size
)
815 return ERROR_INSUFFICIENT_BUFFER
;
818 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
821 /* If the buffer is copied, the returned length doesn't include
822 * the NULL terminator.
827 return ERROR_SUCCESS
;
830 case INTERNET_OPTION_PROXY
:
831 if(!size
) return ERROR_INVALID_PARAMETER
;
833 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
834 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
835 LPWSTR proxy
, proxy_bypass
;
838 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
840 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
841 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
843 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
844 return ERROR_INSUFFICIENT_BUFFER
;
846 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
847 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
849 pi
->dwAccessType
= ai
->accessType
;
850 pi
->lpszProxy
= NULL
;
851 pi
->lpszProxyBypass
= NULL
;
853 lstrcpyW(proxy
, ai
->proxy
);
854 pi
->lpszProxy
= proxy
;
857 if (ai
->proxyBypass
) {
858 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
859 pi
->lpszProxyBypass
= proxy_bypass
;
862 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
863 return ERROR_SUCCESS
;
865 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
866 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
867 LPSTR proxy
, proxy_bypass
;
870 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
872 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
873 NULL
, 0, NULL
, NULL
);
874 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
876 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
877 return ERROR_INSUFFICIENT_BUFFER
;
879 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
880 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
882 pi
->dwAccessType
= ai
->accessType
;
883 pi
->lpszProxy
= NULL
;
884 pi
->lpszProxyBypass
= NULL
;
886 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
887 pi
->lpszProxy
= proxy
;
890 if (ai
->proxyBypass
) {
891 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
892 proxyBypassBytesRequired
, NULL
, NULL
);
893 pi
->lpszProxyBypass
= proxy_bypass
;
896 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
897 return ERROR_SUCCESS
;
900 case INTERNET_OPTION_CONNECT_TIMEOUT
:
901 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
903 if (*size
< sizeof(ULONG
))
904 return ERROR_INSUFFICIENT_BUFFER
;
906 *(ULONG
*)buffer
= ai
->connect_timeout
;
907 *size
= sizeof(ULONG
);
909 return ERROR_SUCCESS
;
912 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
915 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
917 appinfo_t
*ai
= (appinfo_t
*)hdr
;
920 case INTERNET_OPTION_CONNECT_TIMEOUT
:
921 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
923 if(size
!= sizeof(connect_timeout
))
924 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
926 return ERROR_BAD_ARGUMENTS
;
928 ai
->connect_timeout
= *(ULONG
*)buf
;
929 return ERROR_SUCCESS
;
930 case INTERNET_OPTION_USER_AGENT
:
931 heap_free(ai
->agent
);
932 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
933 return ERROR_SUCCESS
;
936 return INET_SetOption(hdr
, option
, buf
, size
);
939 static const object_vtbl_t APPINFOVtbl
= {
951 /***********************************************************************
952 * InternetOpenW (WININET.@)
954 * Per-application initialization of wininet
957 * HINTERNET on success
961 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
962 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
964 appinfo_t
*lpwai
= NULL
;
969 if (TRACE_ON(wininet
)) {
970 #define FE(x) { x, #x }
971 static const wininet_flag_info access_type
[] = {
972 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
973 FE(INTERNET_OPEN_TYPE_DIRECT
),
974 FE(INTERNET_OPEN_TYPE_PROXY
),
975 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
979 const char *access_type_str
= "Unknown";
981 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
982 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
983 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
984 if (access_type
[i
].val
== dwAccessType
) {
985 access_type_str
= access_type
[i
].name
;
989 TRACE(" access type : %s\n", access_type_str
);
991 dump_INTERNET_FLAGS(dwFlags
);
994 /* Clear any error information */
995 INTERNET_SetLastError(0);
997 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
998 SetLastError(ERROR_INVALID_PARAMETER
);
1002 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1004 SetLastError(ERROR_OUTOFMEMORY
);
1008 lpwai
->hdr
.htype
= WH_HINIT
;
1009 lpwai
->hdr
.dwFlags
= dwFlags
;
1010 lpwai
->accessType
= dwAccessType
;
1011 lpwai
->proxyUsername
= NULL
;
1012 lpwai
->proxyPassword
= NULL
;
1013 lpwai
->connect_timeout
= connect_timeout
;
1015 lpwai
->agent
= heap_strdupW(lpszAgent
);
1016 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1017 INTERNET_ConfigureProxy( lpwai
);
1018 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1019 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1020 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1023 TRACE("returning %p\n", lpwai
);
1025 return lpwai
->hdr
.hInternet
;
1029 /***********************************************************************
1030 * InternetOpenA (WININET.@)
1032 * Per-application initialization of wininet
1035 * HINTERNET on success
1039 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1040 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1042 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1045 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1046 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1048 szAgent
= heap_strdupAtoW(lpszAgent
);
1049 szProxy
= heap_strdupAtoW(lpszProxy
);
1050 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1052 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1056 heap_free(szBypass
);
1060 /***********************************************************************
1061 * InternetGetLastResponseInfoA (WININET.@)
1063 * Return last wininet error description on the calling thread
1066 * TRUE on success of writing to buffer
1070 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1071 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1073 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1079 *lpdwError
= lpwite
->dwError
;
1080 if (lpwite
->dwError
)
1082 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1083 *lpdwBufferLength
= strlen(lpszBuffer
);
1086 *lpdwBufferLength
= 0;
1091 *lpdwBufferLength
= 0;
1097 /***********************************************************************
1098 * InternetGetLastResponseInfoW (WININET.@)
1100 * Return last wininet error description on the calling thread
1103 * TRUE on success of writing to buffer
1107 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1108 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1110 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1116 *lpdwError
= lpwite
->dwError
;
1117 if (lpwite
->dwError
)
1119 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1120 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1123 *lpdwBufferLength
= 0;
1128 *lpdwBufferLength
= 0;
1134 /***********************************************************************
1135 * InternetGetConnectedState (WININET.@)
1137 * Return connected state
1141 * if lpdwStatus is not null, return the status (off line,
1142 * modem, lan...) in it.
1143 * FALSE if not connected
1145 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1147 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1150 WARN("always returning LAN connection.\n");
1151 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1157 /***********************************************************************
1158 * InternetGetConnectedStateExW (WININET.@)
1160 * Return connected state
1164 * lpdwStatus [O] Flags specifying the status of the internet connection.
1165 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1166 * dwNameLen [I] Size of the buffer, in characters.
1167 * dwReserved [I] Reserved. Must be set to 0.
1171 * if lpdwStatus is not null, return the status (off line,
1172 * modem, lan...) in it.
1173 * FALSE if not connected
1176 * If the system has no available network connections, an empty string is
1177 * stored in lpszConnectionName. If there is a LAN connection, a localized
1178 * "LAN Connection" string is stored. Presumably, if only a dial-up
1179 * connection is available then the name of the dial-up connection is
1180 * returned. Why any application, other than the "Internet Settings" CPL,
1181 * would want to use this function instead of the simpler InternetGetConnectedStateW
1182 * function is beyond me.
1184 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1185 DWORD dwNameLen
, DWORD dwReserved
)
1187 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1194 WARN("always returning LAN connection.\n");
1195 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1198 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1199 * the resource, avoid it as we must not change the buffer in this case */
1200 if(lpszConnectionName
&& dwNameLen
) {
1201 *lpszConnectionName
= '\0';
1202 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1209 /***********************************************************************
1210 * InternetGetConnectedStateExA (WININET.@)
1212 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1213 DWORD dwNameLen
, DWORD dwReserved
)
1215 LPWSTR lpwszConnectionName
= NULL
;
1218 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1220 if (lpszConnectionName
&& dwNameLen
> 0)
1221 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1223 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1225 if (rc
&& lpwszConnectionName
)
1226 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1227 dwNameLen
, NULL
, NULL
);
1229 heap_free(lpwszConnectionName
);
1234 /***********************************************************************
1235 * InternetConnectW (WININET.@)
1237 * Open a ftp, gopher or http session
1240 * HINTERNET a session handle on success
1244 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1245 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1246 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1247 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1250 HINTERNET rc
= NULL
;
1251 DWORD res
= ERROR_SUCCESS
;
1253 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1254 nServerPort
, debugstr_w(lpszUserName
), lpszPassword
, dwService
, dwFlags
, dwContext
);
1256 if (!lpszServerName
)
1258 SetLastError(ERROR_INVALID_PARAMETER
);
1262 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1263 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1265 res
= ERROR_INVALID_HANDLE
;
1271 case INTERNET_SERVICE_FTP
:
1272 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1273 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1275 res
= INTERNET_GetLastError();
1278 case INTERNET_SERVICE_HTTP
:
1279 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1280 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1283 case INTERNET_SERVICE_GOPHER
:
1289 WININET_Release( &hIC
->hdr
);
1291 TRACE("returning %p\n", rc
);
1297 /***********************************************************************
1298 * InternetConnectA (WININET.@)
1300 * Open a ftp, gopher or http session
1303 * HINTERNET a session handle on success
1307 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1308 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1309 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1310 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1312 HINTERNET rc
= NULL
;
1313 LPWSTR szServerName
;
1317 szServerName
= heap_strdupAtoW(lpszServerName
);
1318 szUserName
= heap_strdupAtoW(lpszUserName
);
1319 szPassword
= heap_strdupAtoW(lpszPassword
);
1321 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1322 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1324 heap_free(szServerName
);
1325 heap_free(szUserName
);
1326 heap_free(szPassword
);
1331 /***********************************************************************
1332 * InternetFindNextFileA (WININET.@)
1334 * Continues a file search from a previous call to FindFirstFile
1341 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1344 WIN32_FIND_DATAW fd
;
1346 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1348 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1352 /***********************************************************************
1353 * InternetFindNextFileW (WININET.@)
1355 * Continues a file search from a previous call to FindFirstFile
1362 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1364 object_header_t
*hdr
;
1369 hdr
= get_handle_object(hFind
);
1371 WARN("Invalid handle\n");
1372 SetLastError(ERROR_INVALID_HANDLE
);
1376 if(hdr
->vtbl
->FindNextFileW
) {
1377 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1379 WARN("Handle doesn't support NextFile\n");
1380 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1383 WININET_Release(hdr
);
1385 if(res
!= ERROR_SUCCESS
)
1387 return res
== ERROR_SUCCESS
;
1390 /***********************************************************************
1391 * InternetCloseHandle (WININET.@)
1393 * Generic close handle function
1400 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1402 object_header_t
*obj
;
1404 TRACE("%p\n", hInternet
);
1406 obj
= get_handle_object( hInternet
);
1408 SetLastError(ERROR_INVALID_HANDLE
);
1412 invalidate_handle(obj
);
1413 WININET_Release(obj
);
1418 static BOOL
set_url_component(WCHAR
**component
, DWORD
*component_length
, const WCHAR
*value
, DWORD len
)
1420 TRACE("%s (%d)\n", debugstr_wn(value
, len
), len
);
1422 if (!*component_length
)
1426 *(const WCHAR
**)component
= value
;
1427 *component_length
= len
;
1431 if (*component_length
< len
+1) {
1432 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1436 *component_length
= len
;
1438 memcpy(*component
, value
, len
*sizeof(WCHAR
));
1439 (*component
)[len
] = 0;
1443 static BOOL
set_url_component_WtoA(const WCHAR
*comp_w
, DWORD length
, const WCHAR
*url_w
, char **comp
, DWORD
*ret_length
,
1446 size_t size
, ret_size
= *ret_length
;
1450 size
= WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, NULL
, 0, NULL
, NULL
);
1453 *comp
= comp_w
? (char*)url_a
+ WideCharToMultiByte(CP_ACP
, 0, url_w
, comp_w
-url_w
, NULL
, 0, NULL
, NULL
) : NULL
;
1458 if (size
+1 > ret_size
) {
1459 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1460 *ret_length
= size
+1;
1465 WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, *comp
, ret_size
-1, NULL
, NULL
);
1470 static BOOL
set_url_component_AtoW(const char *comp_a
, DWORD len_a
, WCHAR
**comp_w
, DWORD
*len_w
, WCHAR
**buf
)
1479 if(!(*comp_w
= *buf
= heap_alloc(len_a
*sizeof(WCHAR
)))) {
1480 SetLastError(ERROR_OUTOFMEMORY
);
1487 /***********************************************************************
1488 * InternetCrackUrlA (WININET.@)
1490 * See InternetCrackUrlW.
1492 BOOL WINAPI
InternetCrackUrlA(const char *url
, DWORD url_length
, DWORD flags
, URL_COMPONENTSA
*ret_comp
)
1494 WCHAR
*host
= NULL
, *user
= NULL
, *pass
= NULL
, *path
= NULL
, *scheme
= NULL
, *extra
= NULL
;
1495 URL_COMPONENTSW comp
;
1496 WCHAR
*url_w
= NULL
;
1499 TRACE("(%s %u %x %p)\n", url_length
? debugstr_an(url
, url_length
) : debugstr_a(url
), url_length
, flags
, ret_comp
);
1501 if (!url
|| !*url
|| !ret_comp
|| ret_comp
->dwStructSize
!= sizeof(URL_COMPONENTSA
)) {
1502 SetLastError(ERROR_INVALID_PARAMETER
);
1506 comp
.dwStructSize
= sizeof(comp
);
1508 ret
= set_url_component_AtoW(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
,
1509 &comp
.lpszHostName
, &comp
.dwHostNameLength
, &host
)
1510 && set_url_component_AtoW(ret_comp
->lpszUserName
, ret_comp
->dwUserNameLength
,
1511 &comp
.lpszUserName
, &comp
.dwUserNameLength
, &user
)
1512 && set_url_component_AtoW(ret_comp
->lpszPassword
, ret_comp
->dwPasswordLength
,
1513 &comp
.lpszPassword
, &comp
.dwPasswordLength
, &pass
)
1514 && set_url_component_AtoW(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
,
1515 &comp
.lpszUrlPath
, &comp
.dwUrlPathLength
, &path
)
1516 && set_url_component_AtoW(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
,
1517 &comp
.lpszScheme
, &comp
.dwSchemeLength
, &scheme
)
1518 && set_url_component_AtoW(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
,
1519 &comp
.lpszExtraInfo
, &comp
.dwExtraInfoLength
, &extra
);
1521 if(ret
&& !(url_w
= heap_strndupAtoW(url
, url_length
? url_length
: -1, &url_length
))) {
1522 SetLastError(ERROR_OUTOFMEMORY
);
1526 if (ret
&& (ret
= InternetCrackUrlW(url_w
, url_length
, flags
, &comp
))) {
1527 ret_comp
->nScheme
= comp
.nScheme
;
1528 ret_comp
->nPort
= comp
.nPort
;
1530 ret
= set_url_component_WtoA(comp
.lpszHostName
, comp
.dwHostNameLength
, url_w
,
1531 &ret_comp
->lpszHostName
, &ret_comp
->dwHostNameLength
, url
)
1532 && set_url_component_WtoA(comp
.lpszUserName
, comp
.dwUserNameLength
, url_w
,
1533 &ret_comp
->lpszUserName
, &ret_comp
->dwUserNameLength
, url
)
1534 && set_url_component_WtoA(comp
.lpszPassword
, comp
.dwPasswordLength
, url_w
,
1535 &ret_comp
->lpszPassword
, &ret_comp
->dwPasswordLength
, url
)
1536 && set_url_component_WtoA(comp
.lpszUrlPath
, comp
.dwUrlPathLength
, url_w
,
1537 &ret_comp
->lpszUrlPath
, &ret_comp
->dwUrlPathLength
, url
)
1538 && set_url_component_WtoA(comp
.lpszScheme
, comp
.dwSchemeLength
, url_w
,
1539 &ret_comp
->lpszScheme
, &ret_comp
->dwSchemeLength
, url
)
1540 && set_url_component_WtoA(comp
.lpszExtraInfo
, comp
.dwExtraInfoLength
, url_w
,
1541 &ret_comp
->lpszExtraInfo
, &ret_comp
->dwExtraInfoLength
, url
);
1544 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url
),
1545 debugstr_an(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
),
1546 debugstr_an(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
),
1547 debugstr_an(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
),
1548 debugstr_an(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
));
1561 static const WCHAR url_schemes
[][7] =
1564 {'g','o','p','h','e','r',0},
1565 {'h','t','t','p',0},
1566 {'h','t','t','p','s',0},
1567 {'f','i','l','e',0},
1568 {'n','e','w','s',0},
1569 {'m','a','i','l','t','o',0},
1573 /***********************************************************************
1574 * GetInternetSchemeW (internal)
1580 * INTERNET_SCHEME_UNKNOWN on failure
1583 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1587 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1589 if(lpszScheme
==NULL
)
1590 return INTERNET_SCHEME_UNKNOWN
;
1592 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1593 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1594 return INTERNET_SCHEME_FIRST
+ i
;
1596 return INTERNET_SCHEME_UNKNOWN
;
1599 /***********************************************************************
1600 * InternetCrackUrlW (WININET.@)
1602 * Break up URL into its components
1608 BOOL WINAPI
InternetCrackUrlW(const WCHAR
*lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
, URL_COMPONENTSW
*lpUC
)
1612 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1615 LPCWSTR lpszParam
= NULL
;
1616 BOOL found_colon
= FALSE
;
1618 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1620 TRACE("(%s %u %x %p)\n",
1621 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1622 dwUrlLength
, dwFlags
, lpUC
);
1624 if (!lpszUrl
|| !*lpszUrl
|| !lpUC
)
1626 SetLastError(ERROR_INVALID_PARAMETER
);
1629 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1631 if (dwFlags
& ICU_DECODE
)
1633 WCHAR
*url_tmp
, *buffer
;
1634 DWORD len
= dwUrlLength
+ 1;
1637 if (!(url_tmp
= heap_strndupW(lpszUrl
, dwUrlLength
)))
1639 SetLastError(ERROR_OUTOFMEMORY
);
1644 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1645 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1647 buffer
= heap_alloc(len
* sizeof(WCHAR
));
1650 SetLastError(ERROR_OUTOFMEMORY
);
1654 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1657 ret
= InternetCrackUrlW(buffer
, len
, dwFlags
& ~ICU_DECODE
, lpUC
);
1659 if (buffer
!= url_tmp
) heap_free(buffer
);
1665 /* Determine if the URI is absolute. */
1666 while (lpszap
- lpszUrl
< dwUrlLength
)
1668 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1680 lpszcp
= lpszUrl
; /* Relative url */
1687 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1691 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1692 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1694 /* Parse <params> */
1695 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1697 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1699 if(!set_url_component(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1700 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0))
1704 /* Get scheme first. */
1705 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1706 if(!set_url_component(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, lpszUrl
, lpszcp
- lpszUrl
))
1709 /* Eat ':' in protocol. */
1712 /* double slash indicates the net_loc portion is present */
1713 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1717 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1721 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1723 lpszNetLoc
= lpszParam
;
1725 else if (!lpszNetLoc
)
1726 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1734 /* [<user>[<:password>]@]<host>[:<port>] */
1735 /* First find the user and password if they exist */
1737 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1738 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1740 /* username and password not specified. */
1741 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1742 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1744 else /* Parse out username and password */
1746 LPCWSTR lpszUser
= lpszcp
;
1747 LPCWSTR lpszPasswd
= lpszHost
;
1749 while (lpszcp
< lpszHost
)
1752 lpszPasswd
= lpszcp
;
1757 if(!set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, lpszUser
, lpszPasswd
- lpszUser
))
1760 if (lpszPasswd
!= lpszHost
)
1762 if(!set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1763 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
, lpszHost
- lpszPasswd
))
1766 lpszcp
++; /* Advance to beginning of host */
1769 /* Parse <host><:port> */
1772 lpszPort
= lpszNetLoc
;
1774 /* special case for res:// URLs: there is no port here, so the host is the
1775 entire string up to the first '/' */
1776 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1778 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1784 while (lpszcp
< lpszNetLoc
)
1792 /* If the scheme is "file" and the host is just one letter, it's not a host */
1793 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1796 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1800 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1802 if (lpszPort
!= lpszNetLoc
)
1803 lpUC
->nPort
= atoiW(++lpszPort
);
1804 else switch (lpUC
->nScheme
)
1806 case INTERNET_SCHEME_HTTP
:
1807 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1809 case INTERNET_SCHEME_HTTPS
:
1810 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1812 case INTERNET_SCHEME_FTP
:
1813 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1815 case INTERNET_SCHEME_GOPHER
:
1816 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1827 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1828 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1829 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1832 /* Here lpszcp points to:
1834 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1835 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1837 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1841 /* Only truncate the parameter list if it's already been saved
1842 * in lpUC->lpszExtraInfo.
1844 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1845 len
= lpszParam
- lpszcp
;
1848 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1849 * newlines if necessary.
1851 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1852 if (lpsznewline
!= NULL
)
1853 len
= lpsznewline
- lpszcp
;
1855 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1857 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1858 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1860 WCHAR tmppath
[MAX_PATH
];
1864 PathCreateFromUrlW(lpszUrl
, tmppath
, &len
, 0);
1869 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1870 tmppath
[len
] = '\0';
1879 /* if ends in \. or \.. append a backslash */
1880 if (tmppath
[len
- 1] == '.' &&
1881 (tmppath
[len
- 2] == '\\' ||
1882 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1884 if (len
< MAX_PATH
- 1)
1886 tmppath
[len
] = '\\';
1887 tmppath
[len
+1] = '\0';
1891 if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, tmppath
, len
))
1894 else if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, len
))
1899 set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, 0);
1902 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1903 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1904 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1905 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1906 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1911 /***********************************************************************
1912 * InternetAttemptConnect (WININET.@)
1914 * Attempt to make a connection to the internet
1917 * ERROR_SUCCESS on success
1918 * Error value on failure
1921 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1924 return ERROR_SUCCESS
;
1928 /***********************************************************************
1929 * convert_url_canonicalization_flags
1931 * Helper for InternetCanonicalizeUrl
1934 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1937 * Flags suitable for UrlCanonicalize
1939 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1941 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1943 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1944 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1945 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1946 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1947 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1948 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1949 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1954 /***********************************************************************
1955 * InternetCanonicalizeUrlA (WININET.@)
1957 * Escape unsafe characters and spaces
1964 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1965 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1969 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1970 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1972 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
1973 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1974 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1975 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1980 /***********************************************************************
1981 * InternetCanonicalizeUrlW (WININET.@)
1983 * Escape unsafe characters and spaces
1990 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1991 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1995 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1996 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1998 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
1999 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2000 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2001 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2006 /* #################################################### */
2008 static INTERNET_STATUS_CALLBACK
set_status_callback(
2009 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2011 INTERNET_STATUS_CALLBACK ret
;
2013 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2014 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2016 ret
= lpwh
->lpfnStatusCB
;
2017 lpwh
->lpfnStatusCB
= callback
;
2022 /***********************************************************************
2023 * InternetSetStatusCallbackA (WININET.@)
2025 * Sets up a callback function which is called as progress is made
2026 * during an operation.
2029 * Previous callback or NULL on success
2030 * INTERNET_INVALID_STATUS_CALLBACK on failure
2033 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2034 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2036 INTERNET_STATUS_CALLBACK retVal
;
2037 object_header_t
*lpwh
;
2039 TRACE("%p\n", hInternet
);
2041 if (!(lpwh
= get_handle_object(hInternet
)))
2042 return INTERNET_INVALID_STATUS_CALLBACK
;
2044 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2046 WININET_Release( lpwh
);
2050 /***********************************************************************
2051 * InternetSetStatusCallbackW (WININET.@)
2053 * Sets up a callback function which is called as progress is made
2054 * during an operation.
2057 * Previous callback or NULL on success
2058 * INTERNET_INVALID_STATUS_CALLBACK on failure
2061 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2062 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2064 INTERNET_STATUS_CALLBACK retVal
;
2065 object_header_t
*lpwh
;
2067 TRACE("%p\n", hInternet
);
2069 if (!(lpwh
= get_handle_object(hInternet
)))
2070 return INTERNET_INVALID_STATUS_CALLBACK
;
2072 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2074 WININET_Release( lpwh
);
2078 /***********************************************************************
2079 * InternetSetFilePointer (WININET.@)
2081 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2082 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2084 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2088 /***********************************************************************
2089 * InternetWriteFile (WININET.@)
2091 * Write data to an open internet file
2098 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2099 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2101 object_header_t
*lpwh
;
2104 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2106 lpwh
= get_handle_object( hFile
);
2108 WARN("Invalid handle\n");
2109 SetLastError(ERROR_INVALID_HANDLE
);
2113 if(lpwh
->vtbl
->WriteFile
) {
2114 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2116 WARN("No Writefile method.\n");
2117 res
= ERROR_INVALID_HANDLE
;
2120 WININET_Release( lpwh
);
2122 if(res
!= ERROR_SUCCESS
)
2124 return res
== ERROR_SUCCESS
;
2128 /***********************************************************************
2129 * InternetReadFile (WININET.@)
2131 * Read data from an open internet file
2138 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2139 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2141 object_header_t
*hdr
;
2142 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2144 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2146 hdr
= get_handle_object(hFile
);
2148 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2152 if(hdr
->vtbl
->ReadFile
)
2153 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2155 WININET_Release(hdr
);
2157 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2158 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2160 if(res
!= ERROR_SUCCESS
)
2162 return res
== ERROR_SUCCESS
;
2165 /***********************************************************************
2166 * InternetReadFileExA (WININET.@)
2168 * Read data from an open internet file
2171 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2172 * lpBuffersOut [I/O] Buffer.
2173 * dwFlags [I] Flags. See notes.
2174 * dwContext [I] Context for callbacks.
2181 * The parameter dwFlags include zero or more of the following flags:
2182 *|IRF_ASYNC - Makes the call asynchronous.
2183 *|IRF_SYNC - Makes the call synchronous.
2184 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2185 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2187 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2190 * InternetOpenUrlA(), HttpOpenRequestA()
2192 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2193 DWORD dwFlags
, DWORD_PTR dwContext
)
2195 object_header_t
*hdr
;
2196 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2198 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2200 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2201 SetLastError(ERROR_INVALID_PARAMETER
);
2205 hdr
= get_handle_object(hFile
);
2207 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2211 if(hdr
->vtbl
->ReadFileEx
)
2212 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2213 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2215 WININET_Release(hdr
);
2217 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2218 res
, lpBuffersOut
->dwBufferLength
);
2220 if(res
!= ERROR_SUCCESS
)
2222 return res
== ERROR_SUCCESS
;
2225 /***********************************************************************
2226 * InternetReadFileExW (WININET.@)
2228 * InternetReadFileExA()
2230 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2231 DWORD dwFlags
, DWORD_PTR dwContext
)
2233 object_header_t
*hdr
;
2234 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2236 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2238 if (!lpBuffer
|| lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2239 SetLastError(ERROR_INVALID_PARAMETER
);
2243 hdr
= get_handle_object(hFile
);
2245 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2249 if(hdr
->vtbl
->ReadFileEx
)
2250 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2251 dwFlags
, dwContext
);
2253 WININET_Release(hdr
);
2255 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2256 res
, lpBuffer
->dwBufferLength
);
2258 if(res
!= ERROR_SUCCESS
)
2260 return res
== ERROR_SUCCESS
;
2263 static WCHAR
*get_proxy_autoconfig_url(void)
2265 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2267 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2272 if (!settings
) return NULL
;
2274 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2276 CFRelease( settings
);
2279 len
= CFStringGetLength( ref
);
2281 ret
= heap_alloc( (len
+1) * sizeof(WCHAR
) );
2284 CFStringGetCharacters( ref
, CFRangeMake(0, len
), ret
);
2287 TRACE( "returning %s\n", debugstr_w(ret
) );
2288 CFRelease( settings
);
2292 if (!once
++) FIXME( "no support on this platform\n" );
2297 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2299 /* FIXME: This function currently handles more options than it should. Options requiring
2300 * proper handles should be moved to proper functions */
2302 case INTERNET_OPTION_HTTP_VERSION
:
2303 if (*size
< sizeof(HTTP_VERSION_INFO
))
2304 return ERROR_INSUFFICIENT_BUFFER
;
2307 * Presently hardcoded to 1.1
2309 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2310 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2311 *size
= sizeof(HTTP_VERSION_INFO
);
2313 return ERROR_SUCCESS
;
2315 case INTERNET_OPTION_CONNECTED_STATE
:
2316 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2318 if (*size
< sizeof(ULONG
))
2319 return ERROR_INSUFFICIENT_BUFFER
;
2321 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2322 *size
= sizeof(ULONG
);
2324 return ERROR_SUCCESS
;
2326 case INTERNET_OPTION_PROXY
: {
2330 TRACE("Getting global proxy info\n");
2331 memset(&ai
, 0, sizeof(appinfo_t
));
2332 INTERNET_ConfigureProxy(&ai
);
2334 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2335 APPINFO_Destroy(&ai
.hdr
);
2339 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2340 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2342 if (*size
< sizeof(ULONG
))
2343 return ERROR_INSUFFICIENT_BUFFER
;
2345 *(ULONG
*)buffer
= max_conns
;
2346 *size
= sizeof(ULONG
);
2348 return ERROR_SUCCESS
;
2350 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2351 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2353 if (*size
< sizeof(ULONG
))
2354 return ERROR_INSUFFICIENT_BUFFER
;
2356 *(ULONG
*)buffer
= max_1_0_conns
;
2357 *size
= sizeof(ULONG
);
2359 return ERROR_SUCCESS
;
2361 case INTERNET_OPTION_SECURITY_FLAGS
:
2362 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2363 return ERROR_SUCCESS
;
2365 case INTERNET_OPTION_VERSION
: {
2366 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2368 TRACE("INTERNET_OPTION_VERSION\n");
2370 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2371 return ERROR_INSUFFICIENT_BUFFER
;
2373 memcpy(buffer
, &info
, sizeof(info
));
2374 *size
= sizeof(info
);
2376 return ERROR_SUCCESS
;
2379 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2381 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2382 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2383 DWORD res
= ERROR_SUCCESS
, i
;
2387 TRACE("Getting global proxy info\n");
2388 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2392 WARN("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2394 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2397 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2399 return ERROR_INSUFFICIENT_BUFFER
;
2402 url
= get_proxy_autoconfig_url();
2404 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2405 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2406 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2408 switch (optionW
->dwOption
) {
2409 case INTERNET_PER_CONN_FLAGS
:
2411 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2413 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2415 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2416 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2419 case INTERNET_PER_CONN_PROXY_SERVER
:
2421 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2423 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2426 case INTERNET_PER_CONN_PROXY_BYPASS
:
2428 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2430 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2433 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2435 optionW
->Value
.pszValue
= NULL
;
2437 optionW
->Value
.pszValue
= heap_strdupW(url
);
2439 optionA
->Value
.pszValue
= heap_strdupWtoA(url
);
2442 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2443 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2446 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2447 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2448 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2449 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2450 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2451 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2455 case INTERNET_PER_CONN_FLAGS_UI
:
2456 WARN("Unhandled dwOption %d\n", optionW
->dwOption
);
2461 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2462 res
= ERROR_INVALID_PARAMETER
;
2471 case INTERNET_OPTION_REQUEST_FLAGS
:
2472 case INTERNET_OPTION_USER_AGENT
:
2474 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2475 case INTERNET_OPTION_POLICY
:
2476 return ERROR_INVALID_PARAMETER
;
2477 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2478 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2480 if (*size
< sizeof(ULONG
))
2481 return ERROR_INSUFFICIENT_BUFFER
;
2483 *(ULONG
*)buffer
= connect_timeout
;
2484 *size
= sizeof(ULONG
);
2486 return ERROR_SUCCESS
;
2489 FIXME("Stub for %d\n", option
);
2490 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2493 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2496 case INTERNET_OPTION_CONTEXT_VALUE
:
2498 return ERROR_INVALID_PARAMETER
;
2500 if (*size
< sizeof(DWORD_PTR
)) {
2501 *size
= sizeof(DWORD_PTR
);
2502 return ERROR_INSUFFICIENT_BUFFER
;
2505 return ERROR_INVALID_PARAMETER
;
2507 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2508 *size
= sizeof(DWORD_PTR
);
2509 return ERROR_SUCCESS
;
2511 case INTERNET_OPTION_REQUEST_FLAGS
:
2512 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2513 *size
= sizeof(DWORD
);
2514 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2516 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2517 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2518 WARN("Called on global option %u\n", option
);
2519 return ERROR_INTERNET_INVALID_OPERATION
;
2522 /* FIXME: we shouldn't call it here */
2523 return query_global_option(option
, buffer
, size
, unicode
);
2526 /***********************************************************************
2527 * InternetQueryOptionW (WININET.@)
2529 * Queries an options on the specified handle
2536 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2537 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2539 object_header_t
*hdr
;
2540 DWORD res
= ERROR_INVALID_HANDLE
;
2542 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2545 hdr
= get_handle_object(hInternet
);
2547 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2548 WININET_Release(hdr
);
2551 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2554 if(res
!= ERROR_SUCCESS
)
2556 return res
== ERROR_SUCCESS
;
2559 /***********************************************************************
2560 * InternetQueryOptionA (WININET.@)
2562 * Queries an options on the specified handle
2569 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2570 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2572 object_header_t
*hdr
;
2573 DWORD res
= ERROR_INVALID_HANDLE
;
2575 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2578 hdr
= get_handle_object(hInternet
);
2580 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2581 WININET_Release(hdr
);
2584 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2587 if(res
!= ERROR_SUCCESS
)
2589 return res
== ERROR_SUCCESS
;
2592 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2595 case INTERNET_OPTION_CALLBACK
:
2596 WARN("Not settable option %u\n", option
);
2597 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2598 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2599 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2600 WARN("Called on global option %u\n", option
);
2601 return ERROR_INTERNET_INVALID_OPERATION
;
2604 return ERROR_INTERNET_INVALID_OPTION
;
2607 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2610 case INTERNET_OPTION_CALLBACK
:
2611 WARN("Not global option %u\n", option
);
2612 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2614 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2615 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2617 if(size
!= sizeof(max_conns
))
2618 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2620 return ERROR_BAD_ARGUMENTS
;
2622 max_conns
= *(ULONG
*)buf
;
2623 return ERROR_SUCCESS
;
2625 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2626 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2628 if(size
!= sizeof(max_1_0_conns
))
2629 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2631 return ERROR_BAD_ARGUMENTS
;
2633 max_1_0_conns
= *(ULONG
*)buf
;
2634 return ERROR_SUCCESS
;
2636 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2637 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2639 if(size
!= sizeof(connect_timeout
))
2640 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2642 return ERROR_BAD_ARGUMENTS
;
2644 connect_timeout
= *(ULONG
*)buf
;
2645 return ERROR_SUCCESS
;
2647 case INTERNET_OPTION_SETTINGS_CHANGED
:
2648 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2649 collect_connections(COLLECT_CONNECTIONS
);
2650 return ERROR_SUCCESS
;
2652 case INTERNET_OPTION_SUPPRESS_BEHAVIOR
:
2653 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2655 if(size
!= sizeof(ULONG
))
2656 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2658 FIXME("%08x\n", *(ULONG
*)buf
);
2659 return ERROR_SUCCESS
;
2662 return ERROR_INTERNET_INVALID_OPTION
;
2665 /***********************************************************************
2666 * InternetSetOptionW (WININET.@)
2668 * Sets an options on the specified handle
2675 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2676 LPVOID lpBuffer
, DWORD dwBufferLength
)
2678 object_header_t
*lpwhh
;
2682 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2684 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2686 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2688 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2690 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2692 WININET_Release(lpwhh
);
2694 if(res
!= ERROR_SUCCESS
)
2697 return res
== ERROR_SUCCESS
;
2702 case INTERNET_OPTION_HTTP_VERSION
:
2704 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2705 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2708 case INTERNET_OPTION_ERROR_MASK
:
2711 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2713 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2714 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2715 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2716 SetLastError(ERROR_INVALID_PARAMETER
);
2718 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2719 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2722 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2723 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2726 case INTERNET_OPTION_PROXY
:
2728 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2730 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2732 SetLastError(ERROR_INVALID_PARAMETER
);
2737 EnterCriticalSection( &WININET_cs
);
2738 free_global_proxy();
2739 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2742 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2744 global_proxy
->proxyEnabled
= 1;
2745 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2746 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2750 global_proxy
->proxyEnabled
= 0;
2751 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2754 LeaveCriticalSection( &WININET_cs
);
2758 /* In general, each type of object should handle
2759 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2760 * get silently dropped.
2762 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2763 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2768 case INTERNET_OPTION_CODEPAGE
:
2770 ULONG codepage
= *(ULONG
*)lpBuffer
;
2771 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2774 case INTERNET_OPTION_REQUEST_PRIORITY
:
2776 ULONG priority
= *(ULONG
*)lpBuffer
;
2777 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2780 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2782 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2783 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2786 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2788 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2789 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2792 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2793 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2795 case INTERNET_OPTION_END_BROWSER_SESSION
:
2796 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2799 case INTERNET_OPTION_CONNECTED_STATE
:
2800 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2802 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2803 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2805 case INTERNET_OPTION_SEND_TIMEOUT
:
2806 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2807 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2809 ULONG timeout
= *(ULONG
*)lpBuffer
;
2810 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2813 case INTERNET_OPTION_CONNECT_RETRIES
:
2815 ULONG retries
= *(ULONG
*)lpBuffer
;
2816 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2819 case INTERNET_OPTION_CONTEXT_VALUE
:
2823 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2826 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2828 SetLastError(ERROR_INVALID_PARAMETER
);
2832 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2835 case INTERNET_OPTION_SECURITY_FLAGS
:
2836 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2838 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2839 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2841 case INTERNET_OPTION_HTTP_DECODING
:
2842 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2843 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2846 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2847 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2848 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2851 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2852 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2853 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2856 case INTERNET_OPTION_CODEPAGE_PATH
:
2857 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2858 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2861 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2862 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2863 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2866 case INTERNET_OPTION_IDN
:
2867 FIXME("INTERNET_OPTION_IDN; STUB\n");
2868 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2871 case INTERNET_OPTION_POLICY
:
2872 SetLastError(ERROR_INVALID_PARAMETER
);
2875 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2876 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2881 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2883 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2884 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2886 switch (option
->dwOption
) {
2887 case INTERNET_PER_CONN_PROXY_SERVER
:
2888 heap_free(pi
.proxy
);
2889 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2892 case INTERNET_PER_CONN_FLAGS
:
2893 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2894 pi
.proxyEnabled
= 1;
2897 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2898 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2899 pi
.proxyEnabled
= 0;
2903 case INTERNET_PER_CONN_PROXY_BYPASS
:
2904 heap_free(pi
.proxyBypass
);
2905 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
2908 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2909 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2910 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2911 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2912 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2913 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2914 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2918 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2919 SetLastError(ERROR_INVALID_PARAMETER
);
2924 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2929 ret
= (res
== ERROR_SUCCESS
);
2932 case INTERNET_OPTION_SETTINGS_CHANGED
:
2933 FIXME("INTERNET_OPTION_SETTINGS_CHANGED; STUB\n");
2935 case INTERNET_OPTION_REFRESH
:
2936 FIXME("INTERNET_OPTION_REFRESH; STUB\n");
2939 FIXME("Option %d STUB\n",dwOption
);
2940 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2946 WININET_Release( lpwhh
);
2952 /***********************************************************************
2953 * InternetSetOptionA (WININET.@)
2955 * Sets an options on the specified handle.
2962 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2963 LPVOID lpBuffer
, DWORD dwBufferLength
)
2971 case INTERNET_OPTION_PROXY
:
2973 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2974 LPINTERNET_PROXY_INFOW piw
;
2975 DWORD proxlen
, prbylen
;
2978 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2979 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2980 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2981 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2982 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2983 piw
->dwAccessType
= pi
->dwAccessType
;
2984 prox
= (LPWSTR
) &piw
[1];
2985 prby
= &prox
[proxlen
+1];
2986 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2987 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2988 piw
->lpszProxy
= prox
;
2989 piw
->lpszProxyBypass
= prby
;
2992 case INTERNET_OPTION_USER_AGENT
:
2993 case INTERNET_OPTION_USERNAME
:
2994 case INTERNET_OPTION_PASSWORD
:
2995 case INTERNET_OPTION_PROXY_USERNAME
:
2996 case INTERNET_OPTION_PROXY_PASSWORD
:
2997 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
2998 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
2999 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3001 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3003 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3004 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3005 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3006 wbuffer
= heap_alloc(wlen
);
3009 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3010 if (listA
->pszConnection
)
3012 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3013 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3014 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3017 listW
->pszConnection
= NULL
;
3018 listW
->dwOptionCount
= listA
->dwOptionCount
;
3019 listW
->dwOptionError
= listA
->dwOptionError
;
3020 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3022 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3023 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3024 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3026 optW
->dwOption
= optA
->dwOption
;
3028 switch (optA
->dwOption
) {
3029 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3030 case INTERNET_PER_CONN_PROXY_BYPASS
:
3031 case INTERNET_PER_CONN_PROXY_SERVER
:
3032 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3033 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3034 if (optA
->Value
.pszValue
)
3036 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3037 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3038 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3041 optW
->Value
.pszValue
= NULL
;
3043 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3044 case INTERNET_PER_CONN_FLAGS
:
3045 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3046 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3048 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3049 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3052 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3053 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3061 wlen
= dwBufferLength
;
3064 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3066 if( lpBuffer
!= wbuffer
)
3068 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3070 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3072 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3073 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3074 switch (opt
->dwOption
) {
3075 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3076 case INTERNET_PER_CONN_PROXY_BYPASS
:
3077 case INTERNET_PER_CONN_PROXY_SERVER
:
3078 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3079 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3080 heap_free( opt
->Value
.pszValue
);
3086 heap_free( list
->pOptions
);
3088 heap_free( wbuffer
);
3095 /***********************************************************************
3096 * InternetSetOptionExA (WININET.@)
3098 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3099 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3101 FIXME("Flags %08x ignored\n", dwFlags
);
3102 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3105 /***********************************************************************
3106 * InternetSetOptionExW (WININET.@)
3108 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3109 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3111 FIXME("Flags %08x ignored\n", dwFlags
);
3112 if( dwFlags
& ~ISO_VALID_FLAGS
)
3114 SetLastError( ERROR_INVALID_PARAMETER
);
3117 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3120 static const WCHAR WININET_wkday
[7][4] =
3121 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3122 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3123 static const WCHAR WININET_month
[12][4] =
3124 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3125 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3126 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3128 /***********************************************************************
3129 * InternetTimeFromSystemTimeA (WININET.@)
3131 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3134 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3136 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3138 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3140 SetLastError(ERROR_INVALID_PARAMETER
);
3144 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3146 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3150 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3151 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3156 /***********************************************************************
3157 * InternetTimeFromSystemTimeW (WININET.@)
3159 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3161 static const WCHAR date
[] =
3162 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3163 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3165 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3167 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3169 SetLastError(ERROR_INVALID_PARAMETER
);
3173 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3175 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3179 sprintfW( string
, date
,
3180 WININET_wkday
[time
->wDayOfWeek
],
3182 WININET_month
[time
->wMonth
- 1],
3191 /***********************************************************************
3192 * InternetTimeToSystemTimeA (WININET.@)
3194 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3199 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3201 stringW
= heap_strdupAtoW(string
);
3204 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3205 heap_free( stringW
);
3210 /***********************************************************************
3211 * InternetTimeToSystemTimeW (WININET.@)
3213 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3216 const WCHAR
*s
= string
;
3219 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3221 if (!string
|| !time
) return FALSE
;
3223 /* Windows does this too */
3224 GetSystemTime( time
);
3226 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3227 * a SYSTEMTIME structure.
3230 while (*s
&& !isalphaW( *s
)) s
++;
3231 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3232 time
->wDayOfWeek
= 7;
3234 for (i
= 0; i
< 7; i
++)
3236 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3237 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3238 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3240 time
->wDayOfWeek
= i
;
3245 if (time
->wDayOfWeek
> 6) return TRUE
;
3246 while (*s
&& !isdigitW( *s
)) s
++;
3247 time
->wDay
= strtolW( s
, &end
, 10 );
3250 while (*s
&& !isalphaW( *s
)) s
++;
3251 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3254 for (i
= 0; i
< 12; i
++)
3256 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3257 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3258 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3260 time
->wMonth
= i
+ 1;
3264 if (time
->wMonth
== 0) return TRUE
;
3266 while (*s
&& !isdigitW( *s
)) s
++;
3267 if (*s
== '\0') return TRUE
;
3268 time
->wYear
= strtolW( s
, &end
, 10 );
3271 while (*s
&& !isdigitW( *s
)) s
++;
3272 if (*s
== '\0') return TRUE
;
3273 time
->wHour
= strtolW( s
, &end
, 10 );
3276 while (*s
&& !isdigitW( *s
)) s
++;
3277 if (*s
== '\0') return TRUE
;
3278 time
->wMinute
= strtolW( s
, &end
, 10 );
3281 while (*s
&& !isdigitW( *s
)) s
++;
3282 if (*s
== '\0') return TRUE
;
3283 time
->wSecond
= strtolW( s
, &end
, 10 );
3286 time
->wMilliseconds
= 0;
3290 /***********************************************************************
3291 * InternetCheckConnectionW (WININET.@)
3293 * Pings a requested host to check internet connection
3296 * TRUE on success and FALSE on failure. If a failure then
3297 * ERROR_NOT_CONNECTED is placed into GetLastError
3300 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3303 * this is a kludge which runs the resident ping program and reads the output.
3305 * Anyone have a better idea?
3309 static const CHAR ping
[] = "ping -c 1 ";
3310 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3312 DWORD len
, host_len
;
3316 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl
), dwFlags
, dwReserved
);
3319 * Crack or set the Address
3321 if (lpszUrl
== NULL
)
3324 * According to the doc we are supposed to use the ip for the next
3325 * server in the WnInet internal server database. I have
3326 * no idea what that is or how to get it.
3328 * So someone needs to implement this.
3330 FIXME("Unimplemented with URL of NULL\n");
3335 URL_COMPONENTSW components
= {sizeof(components
)};
3337 components
.dwHostNameLength
= 1;
3339 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3342 host
= components
.lpszHostName
;
3343 host_len
= components
.dwHostNameLength
;
3344 port
= components
.nPort
;
3345 TRACE("host name: %s port: %d\n",debugstr_wn(host
, host_len
), port
);
3348 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3350 struct sockaddr_storage saddr
;
3351 int sa_len
= sizeof(saddr
);
3356 host_z
= heap_strndupW(host
, host_len
);
3360 b
= GetAddress(host_z
, port
, (struct sockaddr
*)&saddr
, &sa_len
, NULL
);
3365 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3368 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3376 * Build our ping command
3380 len
= WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, NULL
, 0, NULL
, NULL
);
3381 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
)+1);
3382 strcpy(command
, ping
);
3383 WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, command
+sizeof(ping
)-1, len
, NULL
, NULL
);
3384 strcpy(command
+sizeof(ping
)-1+len
, redirect
);
3386 TRACE("Ping command is : %s\n",command
);
3388 status
= system(command
);
3389 heap_free( command
);
3391 TRACE("Ping returned a code of %i\n",status
);
3393 /* Ping return code of 0 indicates success */
3400 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3406 /***********************************************************************
3407 * InternetCheckConnectionA (WININET.@)
3409 * Pings a requested host to check internet connection
3412 * TRUE on success and FALSE on failure. If a failure then
3413 * ERROR_NOT_CONNECTED is placed into GetLastError
3416 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3422 url
= heap_strdupAtoW(lpszUrl
);
3427 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3434 /**********************************************************
3435 * INTERNET_InternetOpenUrlW (internal)
3440 * handle of connection or NULL on failure
3442 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3443 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3445 URL_COMPONENTSW urlComponents
= { sizeof(urlComponents
) };
3446 WCHAR
*host
, *user
= NULL
, *pass
= NULL
, *path
;
3447 HINTERNET client
= NULL
, client1
= NULL
;
3450 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3451 dwHeadersLength
, dwFlags
, dwContext
);
3453 urlComponents
.dwHostNameLength
= 1;
3454 urlComponents
.dwUserNameLength
= 1;
3455 urlComponents
.dwPasswordLength
= 1;
3456 urlComponents
.dwUrlPathLength
= 1;
3457 urlComponents
.dwExtraInfoLength
= 1;
3458 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3461 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
&& urlComponents
.dwExtraInfoLength
) {
3462 assert(urlComponents
.lpszUrlPath
+ urlComponents
.dwUrlPathLength
== urlComponents
.lpszExtraInfo
);
3463 urlComponents
.dwUrlPathLength
+= urlComponents
.dwExtraInfoLength
;
3466 host
= heap_strndupW(urlComponents
.lpszHostName
, urlComponents
.dwHostNameLength
);
3467 path
= heap_strndupW(urlComponents
.lpszUrlPath
, urlComponents
.dwUrlPathLength
);
3468 if(urlComponents
.dwUserNameLength
)
3469 user
= heap_strndupW(urlComponents
.lpszUserName
, urlComponents
.dwUserNameLength
);
3470 if(urlComponents
.dwPasswordLength
)
3471 pass
= heap_strndupW(urlComponents
.lpszPassword
, urlComponents
.dwPasswordLength
);
3473 switch(urlComponents
.nScheme
) {
3474 case INTERNET_SCHEME_FTP
:
3475 client
= FTP_Connect(hIC
, host
, urlComponents
.nPort
,
3476 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
);
3479 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3480 if(client1
== NULL
) {
3481 InternetCloseHandle(client
);
3486 case INTERNET_SCHEME_HTTP
:
3487 case INTERNET_SCHEME_HTTPS
: {
3488 static const WCHAR szStars
[] = { '*','/','*', 0 };
3489 LPCWSTR accept
[2] = { szStars
, NULL
};
3491 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3493 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3494 res
= HTTP_Connect(hIC
, host
, urlComponents
.nPort
,
3495 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3496 if(res
!= ERROR_SUCCESS
) {
3497 INTERNET_SetLastError(res
);
3501 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3502 if(client1
== NULL
) {
3503 InternetCloseHandle(client
);
3506 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3507 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3508 GetLastError() != ERROR_IO_PENDING
) {
3509 InternetCloseHandle(client1
);
3514 case INTERNET_SCHEME_GOPHER
:
3515 /* gopher doesn't seem to be implemented in wine, but it's supposed
3516 * to be supported by InternetOpenUrlA. */
3518 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3522 TRACE(" %p <--\n", client1
);
3531 /**********************************************************
3532 * InternetOpenUrlW (WININET.@)
3537 * handle of connection or NULL on failure
3548 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3550 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3552 TRACE("%p\n", task
->hdr
.hdr
);
3554 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3555 task
->headers_len
, task
->flags
, task
->context
);
3556 heap_free(task
->url
);
3557 heap_free(task
->headers
);
3560 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3561 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3563 HINTERNET ret
= NULL
;
3564 appinfo_t
*hIC
= NULL
;
3566 if (TRACE_ON(wininet
)) {
3567 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3568 dwHeadersLength
, dwFlags
, dwContext
);
3570 dump_INTERNET_FLAGS(dwFlags
);
3575 SetLastError(ERROR_INVALID_PARAMETER
);
3579 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3580 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3581 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3585 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3586 open_url_task_t
*task
;
3588 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3589 task
->url
= heap_strdupW(lpszUrl
);
3590 task
->headers
= heap_strdupW(lpszHeaders
);
3591 task
->headers_len
= dwHeadersLength
;
3592 task
->flags
= dwFlags
;
3593 task
->context
= dwContext
;
3595 INTERNET_AsyncCall(&task
->hdr
);
3596 SetLastError(ERROR_IO_PENDING
);
3598 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3603 WININET_Release( &hIC
->hdr
);
3604 TRACE(" %p <--\n", ret
);
3609 /**********************************************************
3610 * InternetOpenUrlA (WININET.@)
3615 * handle of connection or NULL on failure
3617 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3618 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3620 HINTERNET rc
= NULL
;
3621 LPWSTR szUrl
= NULL
;
3622 WCHAR
*headers
= NULL
;
3627 szUrl
= heap_strdupAtoW(lpszUrl
);
3633 headers
= heap_strndupAtoW(lpszHeaders
, dwHeadersLength
, &dwHeadersLength
);
3640 rc
= InternetOpenUrlW(hInternet
, szUrl
, headers
, dwHeadersLength
, dwFlags
, dwContext
);
3648 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3650 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3654 lpwite
->dwError
= 0;
3655 lpwite
->response
[0] = '\0';
3658 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3667 /***********************************************************************
3668 * INTERNET_SetLastError (internal)
3670 * Set last thread specific error
3675 void INTERNET_SetLastError(DWORD dwError
)
3677 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3680 lpwite
= INTERNET_AllocThreadError();
3682 SetLastError(dwError
);
3684 lpwite
->dwError
= dwError
;
3688 /***********************************************************************
3689 * INTERNET_GetLastError (internal)
3691 * Get last thread specific error
3696 DWORD
INTERNET_GetLastError(void)
3698 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3699 if (!lpwite
) return 0;
3700 /* TlsGetValue clears last error, so set it again here */
3701 SetLastError(lpwite
->dwError
);
3702 return lpwite
->dwError
;
3706 /***********************************************************************
3707 * INTERNET_WorkerThreadFunc (internal)
3709 * Worker thread execution function
3714 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3716 task_header_t
*task
= lpvParam
;
3721 WININET_Release(task
->hdr
);
3724 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3726 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3727 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3732 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3734 task_header_t
*task
;
3736 task
= heap_alloc(size
);
3740 task
->hdr
= WININET_AddRef(hdr
);
3745 /***********************************************************************
3746 * INTERNET_AsyncCall (internal)
3748 * Retrieves work request from queue
3753 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3759 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3763 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3765 return ERROR_SUCCESS
;
3769 /***********************************************************************
3770 * INTERNET_GetResponseBuffer (internal)
3775 LPSTR
INTERNET_GetResponseBuffer(void)
3777 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3779 lpwite
= INTERNET_AllocThreadError();
3781 return lpwite
->response
;
3784 /**********************************************************
3785 * InternetQueryDataAvailable (WININET.@)
3787 * Determines how much data is available to be read.
3790 * TRUE on success, FALSE if an error occurred. If
3791 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3792 * no data is presently available, FALSE is returned with
3793 * the last error ERROR_IO_PENDING; a callback with status
3794 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3795 * data is available.
3797 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3798 LPDWORD lpdwNumberOfBytesAvailable
,
3799 DWORD dwFlags
, DWORD_PTR dwContext
)
3801 object_header_t
*hdr
;
3804 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3806 hdr
= get_handle_object( hFile
);
3808 SetLastError(ERROR_INVALID_HANDLE
);
3812 if(hdr
->vtbl
->QueryDataAvailable
) {
3813 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3815 WARN("wrong handle\n");
3816 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3819 WININET_Release(hdr
);
3821 if(res
!= ERROR_SUCCESS
)
3823 return res
== ERROR_SUCCESS
;
3826 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3828 req_file_t
*req_file
;
3830 req_file
= heap_alloc_zero(sizeof(*req_file
));
3832 return ERROR_NOT_ENOUGH_MEMORY
;
3836 req_file
->file_name
= heap_strdupW(file_name
);
3837 if(!req_file
->file_name
) {
3838 heap_free(req_file
);
3839 return ERROR_NOT_ENOUGH_MEMORY
;
3842 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3843 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3844 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
3845 req_file_release(req_file
);
3846 return GetLastError();
3850 return ERROR_SUCCESS
;
3853 void req_file_release(req_file_t
*req_file
)
3855 if(InterlockedDecrement(&req_file
->ref
))
3858 if(!req_file
->is_committed
)
3859 DeleteFileW(req_file
->file_name
);
3860 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
3861 CloseHandle(req_file
->file_handle
);
3862 heap_free(req_file
->file_name
);
3863 heap_free(req_file
->url
);
3864 heap_free(req_file
);
3867 /***********************************************************************
3868 * InternetLockRequestFile (WININET.@)
3870 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
3872 req_file_t
*req_file
= NULL
;
3873 object_header_t
*hdr
;
3876 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
3878 hdr
= get_handle_object(hInternet
);
3880 SetLastError(ERROR_INVALID_HANDLE
);
3884 if(hdr
->vtbl
->LockRequestFile
) {
3885 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
3887 WARN("wrong handle\n");
3888 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3891 WININET_Release(hdr
);
3893 *lphLockReqHandle
= req_file
;
3894 if(res
!= ERROR_SUCCESS
)
3896 return res
== ERROR_SUCCESS
;
3899 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
3901 TRACE("(%p)\n", hLockHandle
);
3903 req_file_release(hLockHandle
);
3908 /***********************************************************************
3909 * InternetAutodial (WININET.@)
3911 * On windows this function is supposed to dial the default internet
3912 * connection. We don't want to have Wine dial out to the internet so
3913 * we return TRUE by default. It might be nice to check if we are connected.
3920 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3924 /* Tell that we are connected to the internet. */
3928 /***********************************************************************
3929 * InternetAutodialHangup (WININET.@)
3931 * Hangs up a connection made with InternetAutodial
3940 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3944 /* we didn't dial, we don't disconnect */
3948 /***********************************************************************
3949 * InternetCombineUrlA (WININET.@)
3951 * Combine a base URL with a relative URL
3959 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3960 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3965 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3967 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3968 dwFlags
^= ICU_NO_ENCODE
;
3969 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3974 /***********************************************************************
3975 * InternetCombineUrlW (WININET.@)
3977 * Combine a base URL with a relative URL
3985 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3986 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3991 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3993 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3994 dwFlags
^= ICU_NO_ENCODE
;
3995 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4000 /* max port num is 65535 => 5 digits */
4001 #define MAX_WORD_DIGITS 5
4003 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4004 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4005 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4006 (url)->dw##component##Length : strlen((url)->lpsz##component))
4008 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4010 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4011 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4013 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4014 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4016 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4017 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4019 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4020 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4023 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4029 /* opaque urls do not fit into the standard url hierarchy and don't have
4030 * two following slashes */
4031 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4033 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4034 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4035 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4036 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4037 (nScheme
!= INTERNET_SCHEME_FILE
);
4040 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4043 if (scheme
< INTERNET_SCHEME_FIRST
)
4045 index
= scheme
- INTERNET_SCHEME_FIRST
;
4046 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4048 return (LPCWSTR
)url_schemes
[index
];
4051 /* we can calculate using ansi strings because we're just
4052 * calculating string length, not size
4054 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4055 LPDWORD lpdwUrlLength
)
4057 INTERNET_SCHEME nScheme
;
4061 if (lpUrlComponents
->lpszScheme
)
4063 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4064 *lpdwUrlLength
+= dwLen
;
4065 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4071 nScheme
= lpUrlComponents
->nScheme
;
4073 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4074 nScheme
= INTERNET_SCHEME_HTTP
;
4075 scheme
= INTERNET_GetSchemeString(nScheme
);
4076 *lpdwUrlLength
+= strlenW(scheme
);
4079 (*lpdwUrlLength
)++; /* ':' */
4080 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4081 *lpdwUrlLength
+= strlen("//");
4083 if (lpUrlComponents
->lpszUserName
)
4085 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4086 *lpdwUrlLength
+= strlen("@");
4090 if (lpUrlComponents
->lpszPassword
)
4092 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4097 if (lpUrlComponents
->lpszPassword
)
4099 *lpdwUrlLength
+= strlen(":");
4100 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4103 if (lpUrlComponents
->lpszHostName
)
4105 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4107 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4109 char szPort
[MAX_WORD_DIGITS
+1];
4111 *lpdwUrlLength
+= sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4112 *lpdwUrlLength
+= strlen(":");
4115 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4116 (*lpdwUrlLength
)++; /* '/' */
4119 if (lpUrlComponents
->lpszUrlPath
)
4120 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4122 if (lpUrlComponents
->lpszExtraInfo
)
4123 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4128 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4132 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4134 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4135 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4136 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4137 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4138 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4139 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4140 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4141 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4142 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4144 if (lpUrlComponents
->lpszScheme
)
4146 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4147 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4148 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4149 -1, urlCompW
->lpszScheme
, len
);
4152 if (lpUrlComponents
->lpszHostName
)
4154 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4155 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4156 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4157 -1, urlCompW
->lpszHostName
, len
);
4160 if (lpUrlComponents
->lpszUserName
)
4162 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4163 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4164 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4165 -1, urlCompW
->lpszUserName
, len
);
4168 if (lpUrlComponents
->lpszPassword
)
4170 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4171 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4172 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4173 -1, urlCompW
->lpszPassword
, len
);
4176 if (lpUrlComponents
->lpszUrlPath
)
4178 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4179 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4180 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4181 -1, urlCompW
->lpszUrlPath
, len
);
4184 if (lpUrlComponents
->lpszExtraInfo
)
4186 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4187 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4188 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4189 -1, urlCompW
->lpszExtraInfo
, len
);
4193 /***********************************************************************
4194 * InternetCreateUrlA (WININET.@)
4196 * See InternetCreateUrlW.
4198 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4199 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4203 URL_COMPONENTSW urlCompW
;
4205 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4207 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4209 SetLastError(ERROR_INVALID_PARAMETER
);
4213 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4216 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4218 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4220 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4221 *lpdwUrlLength
/= sizeof(WCHAR
);
4223 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4224 * minus one, so add one to leave room for NULL terminator
4227 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4229 heap_free(urlCompW
.lpszScheme
);
4230 heap_free(urlCompW
.lpszHostName
);
4231 heap_free(urlCompW
.lpszUserName
);
4232 heap_free(urlCompW
.lpszPassword
);
4233 heap_free(urlCompW
.lpszUrlPath
);
4234 heap_free(urlCompW
.lpszExtraInfo
);
4239 /***********************************************************************
4240 * InternetCreateUrlW (WININET.@)
4242 * Creates a URL from its component parts.
4245 * lpUrlComponents [I] URL Components.
4246 * dwFlags [I] Flags. See notes.
4247 * lpszUrl [I] Buffer in which to store the created URL.
4248 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4249 * lpszUrl in characters. On output, the number of bytes
4250 * required to store the URL including terminator.
4254 * The dwFlags parameter can be zero or more of the following:
4255 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4262 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4263 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4266 INTERNET_SCHEME nScheme
;
4268 static const WCHAR slashSlashW
[] = {'/','/'};
4269 static const WCHAR fmtW
[] = {'%','u',0};
4271 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4273 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4275 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4279 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4282 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4284 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4285 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4289 *lpdwUrlLength
= dwLen
;
4294 if (lpUrlComponents
->lpszScheme
)
4296 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4297 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4300 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4305 nScheme
= lpUrlComponents
->nScheme
;
4307 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4308 nScheme
= INTERNET_SCHEME_HTTP
;
4310 scheme
= INTERNET_GetSchemeString(nScheme
);
4311 dwLen
= strlenW(scheme
);
4312 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4316 /* all schemes are followed by at least a colon */
4320 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4322 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4323 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4326 if (lpUrlComponents
->lpszUserName
)
4328 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4329 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4332 if (lpUrlComponents
->lpszPassword
)
4337 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4338 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4346 if (lpUrlComponents
->lpszHostName
)
4348 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4349 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4352 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4356 lpszUrl
+= sprintfW(lpszUrl
, fmtW
, lpUrlComponents
->nPort
);
4359 /* add slash between hostname and path if necessary */
4360 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4367 if (lpUrlComponents
->lpszUrlPath
)
4369 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4370 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4374 if (lpUrlComponents
->lpszExtraInfo
)
4376 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4377 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4386 /***********************************************************************
4387 * InternetConfirmZoneCrossingA (WININET.@)
4390 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4392 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4393 return ERROR_SUCCESS
;
4396 /***********************************************************************
4397 * InternetConfirmZoneCrossingW (WININET.@)
4400 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4402 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4403 return ERROR_SUCCESS
;
4406 static DWORD zone_preference
= 3;
4408 /***********************************************************************
4409 * PrivacySetZonePreferenceW (WININET.@)
4411 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4413 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4415 zone_preference
= template;
4419 /***********************************************************************
4420 * PrivacyGetZonePreferenceW (WININET.@)
4422 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4423 LPWSTR preference
, LPDWORD length
)
4425 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4427 if (template) *template = zone_preference
;
4431 /***********************************************************************
4432 * InternetGetSecurityInfoByURLA (WININET.@)
4434 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4439 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4441 url
= heap_strdupAtoW(lpszURL
);
4445 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4450 /***********************************************************************
4451 * InternetGetSecurityInfoByURLW (WININET.@)
4453 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4455 URL_COMPONENTSW url
= {sizeof(url
)};
4459 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4461 url
.dwHostNameLength
= 1;
4462 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4463 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4464 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4468 server
= get_server(substr(url
.lpszHostName
, url
.dwHostNameLength
), url
.nPort
, TRUE
, FALSE
);
4470 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4474 if(server
->cert_chain
) {
4475 const CERT_CHAIN_CONTEXT
*chain_dup
;
4477 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4479 *ppCertChain
= chain_dup
;
4480 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4485 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4489 server_release(server
);
4493 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4494 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4496 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4497 lpdwConnection
, dwReserved
);
4498 return ERROR_SUCCESS
;
4501 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4502 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4504 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4505 lpdwConnection
, dwReserved
);
4506 return ERROR_SUCCESS
;
4509 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4511 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4515 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4517 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4521 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4523 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4524 return ERROR_SUCCESS
;
4527 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4530 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4531 debugstr_w(pwszTarget
), pbHexHash
);
4535 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4537 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4541 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4543 FIXME("(%p, %08lx) stub\n", a
, b
);
4547 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4549 FIXME("%p: stub\n", parent
);