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
= {
950 /***********************************************************************
951 * InternetOpenW (WININET.@)
953 * Per-application initialization of wininet
956 * HINTERNET on success
960 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
961 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
963 appinfo_t
*lpwai
= NULL
;
968 if (TRACE_ON(wininet
)) {
969 #define FE(x) { x, #x }
970 static const wininet_flag_info access_type
[] = {
971 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
972 FE(INTERNET_OPEN_TYPE_DIRECT
),
973 FE(INTERNET_OPEN_TYPE_PROXY
),
974 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
978 const char *access_type_str
= "Unknown";
980 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
981 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
982 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
983 if (access_type
[i
].val
== dwAccessType
) {
984 access_type_str
= access_type
[i
].name
;
988 TRACE(" access type : %s\n", access_type_str
);
990 dump_INTERNET_FLAGS(dwFlags
);
993 /* Clear any error information */
994 INTERNET_SetLastError(0);
996 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
997 SetLastError(ERROR_INVALID_PARAMETER
);
1001 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1003 SetLastError(ERROR_OUTOFMEMORY
);
1007 lpwai
->hdr
.htype
= WH_HINIT
;
1008 lpwai
->hdr
.dwFlags
= dwFlags
;
1009 lpwai
->accessType
= dwAccessType
;
1010 lpwai
->proxyUsername
= NULL
;
1011 lpwai
->proxyPassword
= NULL
;
1012 lpwai
->connect_timeout
= connect_timeout
;
1014 lpwai
->agent
= heap_strdupW(lpszAgent
);
1015 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1016 INTERNET_ConfigureProxy( lpwai
);
1017 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1018 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1019 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1022 TRACE("returning %p\n", lpwai
);
1024 return lpwai
->hdr
.hInternet
;
1028 /***********************************************************************
1029 * InternetOpenA (WININET.@)
1031 * Per-application initialization of wininet
1034 * HINTERNET on success
1038 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1039 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1041 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1044 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1045 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1047 szAgent
= heap_strdupAtoW(lpszAgent
);
1048 szProxy
= heap_strdupAtoW(lpszProxy
);
1049 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1051 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1055 heap_free(szBypass
);
1059 /***********************************************************************
1060 * InternetGetLastResponseInfoA (WININET.@)
1062 * Return last wininet error description on the calling thread
1065 * TRUE on success of writing to buffer
1069 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1070 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1072 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1078 *lpdwError
= lpwite
->dwError
;
1079 if (lpwite
->dwError
)
1081 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1082 *lpdwBufferLength
= strlen(lpszBuffer
);
1085 *lpdwBufferLength
= 0;
1090 *lpdwBufferLength
= 0;
1096 /***********************************************************************
1097 * InternetGetLastResponseInfoW (WININET.@)
1099 * Return last wininet error description on the calling thread
1102 * TRUE on success of writing to buffer
1106 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1107 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1109 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1115 *lpdwError
= lpwite
->dwError
;
1116 if (lpwite
->dwError
)
1118 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1119 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1122 *lpdwBufferLength
= 0;
1127 *lpdwBufferLength
= 0;
1133 /***********************************************************************
1134 * InternetGetConnectedState (WININET.@)
1136 * Return connected state
1140 * if lpdwStatus is not null, return the status (off line,
1141 * modem, lan...) in it.
1142 * FALSE if not connected
1144 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1146 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1148 return InternetGetConnectedStateExW(lpdwStatus
, NULL
, 0, dwReserved
);
1152 /***********************************************************************
1153 * InternetGetConnectedStateExW (WININET.@)
1155 * Return connected state
1159 * lpdwStatus [O] Flags specifying the status of the internet connection.
1160 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1161 * dwNameLen [I] Size of the buffer, in characters.
1162 * dwReserved [I] Reserved. Must be set to 0.
1166 * if lpdwStatus is not null, return the status (off line,
1167 * modem, lan...) in it.
1168 * FALSE if not connected
1171 * If the system has no available network connections, an empty string is
1172 * stored in lpszConnectionName. If there is a LAN connection, a localized
1173 * "LAN Connection" string is stored. Presumably, if only a dial-up
1174 * connection is available then the name of the dial-up connection is
1175 * returned. Why any application, other than the "Internet Settings" CPL,
1176 * would want to use this function instead of the simpler InternetGetConnectedStateW
1177 * function is beyond me.
1179 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1180 DWORD dwNameLen
, DWORD dwReserved
)
1182 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1189 WARN("always returning LAN connection.\n");
1190 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1193 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1194 * the resource, avoid it as we must not change the buffer in this case */
1195 if(lpszConnectionName
&& dwNameLen
) {
1196 *lpszConnectionName
= '\0';
1197 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1204 /***********************************************************************
1205 * InternetGetConnectedStateExA (WININET.@)
1207 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1208 DWORD dwNameLen
, DWORD dwReserved
)
1210 LPWSTR lpwszConnectionName
= NULL
;
1213 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1215 if (lpszConnectionName
&& dwNameLen
> 0)
1216 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1218 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1220 if (rc
&& lpwszConnectionName
)
1221 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1222 dwNameLen
, NULL
, NULL
);
1224 heap_free(lpwszConnectionName
);
1229 /***********************************************************************
1230 * InternetConnectW (WININET.@)
1232 * Open a ftp, gopher or http session
1235 * HINTERNET a session handle on success
1239 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1240 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1241 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1242 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1245 HINTERNET rc
= NULL
;
1246 DWORD res
= ERROR_SUCCESS
;
1248 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1249 nServerPort
, debugstr_w(lpszUserName
), lpszPassword
, dwService
, dwFlags
, dwContext
);
1251 if (!lpszServerName
)
1253 SetLastError(ERROR_INVALID_PARAMETER
);
1257 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1258 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1260 res
= ERROR_INVALID_HANDLE
;
1266 case INTERNET_SERVICE_FTP
:
1267 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1268 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1270 res
= INTERNET_GetLastError();
1273 case INTERNET_SERVICE_HTTP
:
1274 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1275 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1278 case INTERNET_SERVICE_GOPHER
:
1284 WININET_Release( &hIC
->hdr
);
1286 TRACE("returning %p\n", rc
);
1292 /***********************************************************************
1293 * InternetConnectA (WININET.@)
1295 * Open a ftp, gopher or http session
1298 * HINTERNET a session handle on success
1302 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1303 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1304 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1305 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1307 HINTERNET rc
= NULL
;
1308 LPWSTR szServerName
;
1312 szServerName
= heap_strdupAtoW(lpszServerName
);
1313 szUserName
= heap_strdupAtoW(lpszUserName
);
1314 szPassword
= heap_strdupAtoW(lpszPassword
);
1316 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1317 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1319 heap_free(szServerName
);
1320 heap_free(szUserName
);
1321 heap_free(szPassword
);
1326 /***********************************************************************
1327 * InternetFindNextFileA (WININET.@)
1329 * Continues a file search from a previous call to FindFirstFile
1336 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1339 WIN32_FIND_DATAW fd
;
1341 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1343 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1347 /***********************************************************************
1348 * InternetFindNextFileW (WININET.@)
1350 * Continues a file search from a previous call to FindFirstFile
1357 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1359 object_header_t
*hdr
;
1364 hdr
= get_handle_object(hFind
);
1366 WARN("Invalid handle\n");
1367 SetLastError(ERROR_INVALID_HANDLE
);
1371 if(hdr
->vtbl
->FindNextFileW
) {
1372 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1374 WARN("Handle doesn't support NextFile\n");
1375 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1378 WININET_Release(hdr
);
1380 if(res
!= ERROR_SUCCESS
)
1382 return res
== ERROR_SUCCESS
;
1385 /***********************************************************************
1386 * InternetCloseHandle (WININET.@)
1388 * Generic close handle function
1395 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1397 object_header_t
*obj
;
1399 TRACE("%p\n", hInternet
);
1401 obj
= get_handle_object( hInternet
);
1403 SetLastError(ERROR_INVALID_HANDLE
);
1407 invalidate_handle(obj
);
1408 WININET_Release(obj
);
1413 static BOOL
set_url_component(WCHAR
**component
, DWORD
*component_length
, const WCHAR
*value
, DWORD len
)
1415 TRACE("%s (%d)\n", debugstr_wn(value
, len
), len
);
1417 if (!*component_length
)
1421 *(const WCHAR
**)component
= value
;
1422 *component_length
= len
;
1426 if (*component_length
< len
+1) {
1427 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1431 *component_length
= len
;
1433 memcpy(*component
, value
, len
*sizeof(WCHAR
));
1434 (*component
)[len
] = 0;
1438 static BOOL
set_url_component_WtoA(const WCHAR
*comp_w
, DWORD length
, const WCHAR
*url_w
, char **comp
, DWORD
*ret_length
,
1441 size_t size
, ret_size
= *ret_length
;
1445 size
= WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, NULL
, 0, NULL
, NULL
);
1448 *comp
= comp_w
? (char*)url_a
+ WideCharToMultiByte(CP_ACP
, 0, url_w
, comp_w
-url_w
, NULL
, 0, NULL
, NULL
) : NULL
;
1453 if (size
+1 > ret_size
) {
1454 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1455 *ret_length
= size
+1;
1460 WideCharToMultiByte(CP_ACP
, 0, comp_w
, length
, *comp
, ret_size
-1, NULL
, NULL
);
1465 static BOOL
set_url_component_AtoW(const char *comp_a
, DWORD len_a
, WCHAR
**comp_w
, DWORD
*len_w
, WCHAR
**buf
)
1474 if(!(*comp_w
= *buf
= heap_alloc(len_a
*sizeof(WCHAR
)))) {
1475 SetLastError(ERROR_OUTOFMEMORY
);
1482 /***********************************************************************
1483 * InternetCrackUrlA (WININET.@)
1485 * See InternetCrackUrlW.
1487 BOOL WINAPI
InternetCrackUrlA(const char *url
, DWORD url_length
, DWORD flags
, URL_COMPONENTSA
*ret_comp
)
1489 WCHAR
*host
= NULL
, *user
= NULL
, *pass
= NULL
, *path
= NULL
, *scheme
= NULL
, *extra
= NULL
;
1490 URL_COMPONENTSW comp
;
1491 WCHAR
*url_w
= NULL
;
1494 TRACE("(%s %u %x %p)\n", url_length
? debugstr_an(url
, url_length
) : debugstr_a(url
), url_length
, flags
, ret_comp
);
1496 if (!url
|| !*url
|| !ret_comp
|| ret_comp
->dwStructSize
!= sizeof(URL_COMPONENTSA
)) {
1497 SetLastError(ERROR_INVALID_PARAMETER
);
1501 comp
.dwStructSize
= sizeof(comp
);
1503 ret
= set_url_component_AtoW(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
,
1504 &comp
.lpszHostName
, &comp
.dwHostNameLength
, &host
)
1505 && set_url_component_AtoW(ret_comp
->lpszUserName
, ret_comp
->dwUserNameLength
,
1506 &comp
.lpszUserName
, &comp
.dwUserNameLength
, &user
)
1507 && set_url_component_AtoW(ret_comp
->lpszPassword
, ret_comp
->dwPasswordLength
,
1508 &comp
.lpszPassword
, &comp
.dwPasswordLength
, &pass
)
1509 && set_url_component_AtoW(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
,
1510 &comp
.lpszUrlPath
, &comp
.dwUrlPathLength
, &path
)
1511 && set_url_component_AtoW(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
,
1512 &comp
.lpszScheme
, &comp
.dwSchemeLength
, &scheme
)
1513 && set_url_component_AtoW(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
,
1514 &comp
.lpszExtraInfo
, &comp
.dwExtraInfoLength
, &extra
);
1516 if(ret
&& !(url_w
= heap_strndupAtoW(url
, url_length
? url_length
: -1, &url_length
))) {
1517 SetLastError(ERROR_OUTOFMEMORY
);
1521 if (ret
&& (ret
= InternetCrackUrlW(url_w
, url_length
, flags
, &comp
))) {
1522 ret_comp
->nScheme
= comp
.nScheme
;
1523 ret_comp
->nPort
= comp
.nPort
;
1525 ret
= set_url_component_WtoA(comp
.lpszHostName
, comp
.dwHostNameLength
, url_w
,
1526 &ret_comp
->lpszHostName
, &ret_comp
->dwHostNameLength
, url
)
1527 && set_url_component_WtoA(comp
.lpszUserName
, comp
.dwUserNameLength
, url_w
,
1528 &ret_comp
->lpszUserName
, &ret_comp
->dwUserNameLength
, url
)
1529 && set_url_component_WtoA(comp
.lpszPassword
, comp
.dwPasswordLength
, url_w
,
1530 &ret_comp
->lpszPassword
, &ret_comp
->dwPasswordLength
, url
)
1531 && set_url_component_WtoA(comp
.lpszUrlPath
, comp
.dwUrlPathLength
, url_w
,
1532 &ret_comp
->lpszUrlPath
, &ret_comp
->dwUrlPathLength
, url
)
1533 && set_url_component_WtoA(comp
.lpszScheme
, comp
.dwSchemeLength
, url_w
,
1534 &ret_comp
->lpszScheme
, &ret_comp
->dwSchemeLength
, url
)
1535 && set_url_component_WtoA(comp
.lpszExtraInfo
, comp
.dwExtraInfoLength
, url_w
,
1536 &ret_comp
->lpszExtraInfo
, &ret_comp
->dwExtraInfoLength
, url
);
1539 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url
),
1540 debugstr_an(ret_comp
->lpszScheme
, ret_comp
->dwSchemeLength
),
1541 debugstr_an(ret_comp
->lpszHostName
, ret_comp
->dwHostNameLength
),
1542 debugstr_an(ret_comp
->lpszUrlPath
, ret_comp
->dwUrlPathLength
),
1543 debugstr_an(ret_comp
->lpszExtraInfo
, ret_comp
->dwExtraInfoLength
));
1556 static const WCHAR url_schemes
[][7] =
1559 {'g','o','p','h','e','r',0},
1560 {'h','t','t','p',0},
1561 {'h','t','t','p','s',0},
1562 {'f','i','l','e',0},
1563 {'n','e','w','s',0},
1564 {'m','a','i','l','t','o',0},
1568 /***********************************************************************
1569 * GetInternetSchemeW (internal)
1575 * INTERNET_SCHEME_UNKNOWN on failure
1578 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1582 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1584 if(lpszScheme
==NULL
)
1585 return INTERNET_SCHEME_UNKNOWN
;
1587 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1588 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1589 return INTERNET_SCHEME_FIRST
+ i
;
1591 return INTERNET_SCHEME_UNKNOWN
;
1594 /***********************************************************************
1595 * InternetCrackUrlW (WININET.@)
1597 * Break up URL into its components
1603 BOOL WINAPI
InternetCrackUrlW(const WCHAR
*lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
, URL_COMPONENTSW
*lpUC
)
1607 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1610 LPCWSTR lpszParam
= NULL
;
1611 BOOL found_colon
= FALSE
;
1613 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1615 TRACE("(%s %u %x %p)\n",
1616 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1617 dwUrlLength
, dwFlags
, lpUC
);
1619 if (!lpszUrl
|| !*lpszUrl
|| !lpUC
)
1621 SetLastError(ERROR_INVALID_PARAMETER
);
1624 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1626 if (dwFlags
& ICU_DECODE
)
1628 WCHAR
*url_tmp
, *buffer
;
1629 DWORD len
= dwUrlLength
+ 1;
1632 if (!(url_tmp
= heap_strndupW(lpszUrl
, dwUrlLength
)))
1634 SetLastError(ERROR_OUTOFMEMORY
);
1639 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1640 if (!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1642 buffer
= heap_alloc(len
* sizeof(WCHAR
));
1645 SetLastError(ERROR_OUTOFMEMORY
);
1649 ret
= InternetCanonicalizeUrlW(url_tmp
, buffer
, &len
, ICU_DECODE
| ICU_NO_ENCODE
);
1652 ret
= InternetCrackUrlW(buffer
, len
, dwFlags
& ~ICU_DECODE
, lpUC
);
1654 if (buffer
!= url_tmp
) heap_free(buffer
);
1660 /* Determine if the URI is absolute. */
1661 while (lpszap
- lpszUrl
< dwUrlLength
)
1663 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1675 lpszcp
= lpszUrl
; /* Relative url */
1682 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1686 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1687 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1689 /* Parse <params> */
1690 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1692 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1694 if(!set_url_component(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1695 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0))
1699 /* Get scheme first. */
1700 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1701 if(!set_url_component(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, lpszUrl
, lpszcp
- lpszUrl
))
1704 /* Eat ':' in protocol. */
1707 /* double slash indicates the net_loc portion is present */
1708 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1712 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1716 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1718 lpszNetLoc
= lpszParam
;
1720 else if (!lpszNetLoc
)
1721 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1729 /* [<user>[<:password>]@]<host>[:<port>] */
1730 /* First find the user and password if they exist */
1732 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1733 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1735 /* username and password not specified. */
1736 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1737 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1739 else /* Parse out username and password */
1741 LPCWSTR lpszUser
= lpszcp
;
1742 LPCWSTR lpszPasswd
= lpszHost
;
1744 while (lpszcp
< lpszHost
)
1747 lpszPasswd
= lpszcp
;
1752 if(!set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, lpszUser
, lpszPasswd
- lpszUser
))
1755 if (lpszPasswd
!= lpszHost
)
1757 if(!set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1758 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
, lpszHost
- lpszPasswd
))
1761 lpszcp
++; /* Advance to beginning of host */
1764 /* Parse <host><:port> */
1767 lpszPort
= lpszNetLoc
;
1769 /* special case for res:// URLs: there is no port here, so the host is the
1770 entire string up to the first '/' */
1771 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1773 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1779 while (lpszcp
< lpszNetLoc
)
1787 /* If the scheme is "file" and the host is just one letter, it's not a host */
1788 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1791 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1795 if(!set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
))
1797 if (lpszPort
!= lpszNetLoc
)
1798 lpUC
->nPort
= atoiW(++lpszPort
);
1799 else switch (lpUC
->nScheme
)
1801 case INTERNET_SCHEME_HTTP
:
1802 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1804 case INTERNET_SCHEME_HTTPS
:
1805 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1807 case INTERNET_SCHEME_FTP
:
1808 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1810 case INTERNET_SCHEME_GOPHER
:
1811 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1822 set_url_component(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1823 set_url_component(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1824 set_url_component(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1827 /* Here lpszcp points to:
1829 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1830 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1832 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1836 /* Only truncate the parameter list if it's already been saved
1837 * in lpUC->lpszExtraInfo.
1839 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1840 len
= lpszParam
- lpszcp
;
1843 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1844 * newlines if necessary.
1846 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1847 if (lpsznewline
!= NULL
)
1848 len
= lpsznewline
- lpszcp
;
1850 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1852 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1853 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1855 WCHAR tmppath
[MAX_PATH
];
1859 PathCreateFromUrlW(lpszUrl
, tmppath
, &len
, 0);
1864 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1865 tmppath
[len
] = '\0';
1874 /* if ends in \. or \.. append a backslash */
1875 if (tmppath
[len
- 1] == '.' &&
1876 (tmppath
[len
- 2] == '\\' ||
1877 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1879 if (len
< MAX_PATH
- 1)
1881 tmppath
[len
] = '\\';
1882 tmppath
[len
+1] = '\0';
1886 if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, tmppath
, len
))
1889 else if(!set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, len
))
1894 set_url_component(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
, lpszcp
, 0);
1897 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1898 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1899 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1900 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1901 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1906 /***********************************************************************
1907 * InternetAttemptConnect (WININET.@)
1909 * Attempt to make a connection to the internet
1912 * ERROR_SUCCESS on success
1913 * Error value on failure
1916 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1919 return ERROR_SUCCESS
;
1923 /***********************************************************************
1924 * convert_url_canonicalization_flags
1926 * Helper for InternetCanonicalizeUrl
1929 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1932 * Flags suitable for UrlCanonicalize
1934 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1936 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1938 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1939 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1940 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1941 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1942 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1943 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1944 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1949 /***********************************************************************
1950 * InternetCanonicalizeUrlA (WININET.@)
1952 * Escape unsafe characters and spaces
1959 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1960 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1964 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1965 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1967 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
1968 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1969 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1970 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1975 /***********************************************************************
1976 * InternetCanonicalizeUrlW (WININET.@)
1978 * Escape unsafe characters and spaces
1985 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1986 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1990 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1991 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1993 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
1994 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1995 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1996 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2001 /* #################################################### */
2003 static INTERNET_STATUS_CALLBACK
set_status_callback(
2004 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2006 INTERNET_STATUS_CALLBACK ret
;
2008 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2009 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2011 ret
= lpwh
->lpfnStatusCB
;
2012 lpwh
->lpfnStatusCB
= callback
;
2017 /***********************************************************************
2018 * InternetSetStatusCallbackA (WININET.@)
2020 * Sets up a callback function which is called as progress is made
2021 * during an operation.
2024 * Previous callback or NULL on success
2025 * INTERNET_INVALID_STATUS_CALLBACK on failure
2028 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2029 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2031 INTERNET_STATUS_CALLBACK retVal
;
2032 object_header_t
*lpwh
;
2034 TRACE("%p\n", hInternet
);
2036 if (!(lpwh
= get_handle_object(hInternet
)))
2037 return INTERNET_INVALID_STATUS_CALLBACK
;
2039 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2041 WININET_Release( lpwh
);
2045 /***********************************************************************
2046 * InternetSetStatusCallbackW (WININET.@)
2048 * Sets up a callback function which is called as progress is made
2049 * during an operation.
2052 * Previous callback or NULL on success
2053 * INTERNET_INVALID_STATUS_CALLBACK on failure
2056 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2057 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2059 INTERNET_STATUS_CALLBACK retVal
;
2060 object_header_t
*lpwh
;
2062 TRACE("%p\n", hInternet
);
2064 if (!(lpwh
= get_handle_object(hInternet
)))
2065 return INTERNET_INVALID_STATUS_CALLBACK
;
2067 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2069 WININET_Release( lpwh
);
2073 /***********************************************************************
2074 * InternetSetFilePointer (WININET.@)
2076 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2077 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2079 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2083 /***********************************************************************
2084 * InternetWriteFile (WININET.@)
2086 * Write data to an open internet file
2093 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2094 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2096 object_header_t
*lpwh
;
2099 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2101 lpwh
= get_handle_object( hFile
);
2103 WARN("Invalid handle\n");
2104 SetLastError(ERROR_INVALID_HANDLE
);
2108 if(lpwh
->vtbl
->WriteFile
) {
2109 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2111 WARN("No Writefile method.\n");
2112 res
= ERROR_INVALID_HANDLE
;
2115 WININET_Release( lpwh
);
2117 if(res
!= ERROR_SUCCESS
)
2119 return res
== ERROR_SUCCESS
;
2123 /***********************************************************************
2124 * InternetReadFile (WININET.@)
2126 * Read data from an open internet file
2133 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2134 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2136 object_header_t
*hdr
;
2137 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2139 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2141 hdr
= get_handle_object(hFile
);
2143 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2147 if(hdr
->vtbl
->ReadFile
) {
2148 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, 0, 0);
2149 if(res
== ERROR_IO_PENDING
)
2150 *pdwNumOfBytesRead
= 0;
2153 WININET_Release(hdr
);
2155 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2156 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2158 if(res
!= ERROR_SUCCESS
)
2160 return res
== ERROR_SUCCESS
;
2163 /***********************************************************************
2164 * InternetReadFileExA (WININET.@)
2166 * Read data from an open internet file
2169 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2170 * lpBuffersOut [I/O] Buffer.
2171 * dwFlags [I] Flags. See notes.
2172 * dwContext [I] Context for callbacks.
2179 * The parameter dwFlags include zero or more of the following flags:
2180 *|IRF_ASYNC - Makes the call asynchronous.
2181 *|IRF_SYNC - Makes the call synchronous.
2182 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2183 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2185 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2188 * InternetOpenUrlA(), HttpOpenRequestA()
2190 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2191 DWORD dwFlags
, DWORD_PTR dwContext
)
2193 object_header_t
*hdr
;
2194 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2196 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2198 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2199 SetLastError(ERROR_INVALID_PARAMETER
);
2203 hdr
= get_handle_object(hFile
);
2205 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2209 if(hdr
->vtbl
->ReadFile
)
2210 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2211 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2213 WININET_Release(hdr
);
2215 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2216 res
, lpBuffersOut
->dwBufferLength
);
2218 if(res
!= ERROR_SUCCESS
)
2220 return res
== ERROR_SUCCESS
;
2223 /***********************************************************************
2224 * InternetReadFileExW (WININET.@)
2226 * InternetReadFileExA()
2228 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2229 DWORD dwFlags
, DWORD_PTR dwContext
)
2231 object_header_t
*hdr
;
2232 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2234 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2236 if (!lpBuffer
|| lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2237 SetLastError(ERROR_INVALID_PARAMETER
);
2241 hdr
= get_handle_object(hFile
);
2243 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2247 if(hdr
->vtbl
->ReadFile
)
2248 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2249 dwFlags
, dwContext
);
2251 WININET_Release(hdr
);
2253 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2254 res
, lpBuffer
->dwBufferLength
);
2256 if(res
!= ERROR_SUCCESS
)
2258 return res
== ERROR_SUCCESS
;
2261 static WCHAR
*get_proxy_autoconfig_url(void)
2263 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2265 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2270 if (!settings
) return NULL
;
2272 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2274 CFRelease( settings
);
2277 len
= CFStringGetLength( ref
);
2279 ret
= heap_alloc( (len
+1) * sizeof(WCHAR
) );
2282 CFStringGetCharacters( ref
, CFRangeMake(0, len
), ret
);
2285 TRACE( "returning %s\n", debugstr_w(ret
) );
2286 CFRelease( settings
);
2290 if (!once
++) FIXME( "no support on this platform\n" );
2295 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2297 /* FIXME: This function currently handles more options than it should. Options requiring
2298 * proper handles should be moved to proper functions */
2300 case INTERNET_OPTION_HTTP_VERSION
:
2301 if (*size
< sizeof(HTTP_VERSION_INFO
))
2302 return ERROR_INSUFFICIENT_BUFFER
;
2305 * Presently hardcoded to 1.1
2307 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2308 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2309 *size
= sizeof(HTTP_VERSION_INFO
);
2311 return ERROR_SUCCESS
;
2313 case INTERNET_OPTION_CONNECTED_STATE
:
2314 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2316 if (*size
< sizeof(ULONG
))
2317 return ERROR_INSUFFICIENT_BUFFER
;
2319 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2320 *size
= sizeof(ULONG
);
2322 return ERROR_SUCCESS
;
2324 case INTERNET_OPTION_PROXY
: {
2328 TRACE("Getting global proxy info\n");
2329 memset(&ai
, 0, sizeof(appinfo_t
));
2330 INTERNET_ConfigureProxy(&ai
);
2332 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2333 APPINFO_Destroy(&ai
.hdr
);
2337 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2338 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2340 if (*size
< sizeof(ULONG
))
2341 return ERROR_INSUFFICIENT_BUFFER
;
2343 *(ULONG
*)buffer
= max_conns
;
2344 *size
= sizeof(ULONG
);
2346 return ERROR_SUCCESS
;
2348 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2349 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2351 if (*size
< sizeof(ULONG
))
2352 return ERROR_INSUFFICIENT_BUFFER
;
2354 *(ULONG
*)buffer
= max_1_0_conns
;
2355 *size
= sizeof(ULONG
);
2357 return ERROR_SUCCESS
;
2359 case INTERNET_OPTION_SECURITY_FLAGS
:
2360 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2361 return ERROR_SUCCESS
;
2363 case INTERNET_OPTION_VERSION
: {
2364 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2366 TRACE("INTERNET_OPTION_VERSION\n");
2368 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2369 return ERROR_INSUFFICIENT_BUFFER
;
2371 memcpy(buffer
, &info
, sizeof(info
));
2372 *size
= sizeof(info
);
2374 return ERROR_SUCCESS
;
2377 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2379 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2380 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2381 DWORD res
= ERROR_SUCCESS
, i
;
2385 TRACE("Getting global proxy info\n");
2386 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2390 WARN("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2392 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2395 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2397 return ERROR_INSUFFICIENT_BUFFER
;
2400 url
= get_proxy_autoconfig_url();
2402 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2403 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2404 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2406 switch (optionW
->dwOption
) {
2407 case INTERNET_PER_CONN_FLAGS
:
2409 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2411 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2413 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2414 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2417 case INTERNET_PER_CONN_PROXY_SERVER
:
2419 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2421 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2424 case INTERNET_PER_CONN_PROXY_BYPASS
:
2426 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2428 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2431 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2433 optionW
->Value
.pszValue
= NULL
;
2435 optionW
->Value
.pszValue
= heap_strdupW(url
);
2437 optionA
->Value
.pszValue
= heap_strdupWtoA(url
);
2440 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2441 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2444 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2445 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2446 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2447 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2448 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2449 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2453 case INTERNET_PER_CONN_FLAGS_UI
:
2454 WARN("Unhandled dwOption %d\n", optionW
->dwOption
);
2459 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2460 res
= ERROR_INVALID_PARAMETER
;
2469 case INTERNET_OPTION_REQUEST_FLAGS
:
2470 case INTERNET_OPTION_USER_AGENT
:
2472 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2473 case INTERNET_OPTION_POLICY
:
2474 return ERROR_INVALID_PARAMETER
;
2475 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2476 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2478 if (*size
< sizeof(ULONG
))
2479 return ERROR_INSUFFICIENT_BUFFER
;
2481 *(ULONG
*)buffer
= connect_timeout
;
2482 *size
= sizeof(ULONG
);
2484 return ERROR_SUCCESS
;
2487 FIXME("Stub for %d\n", option
);
2488 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2491 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2494 case INTERNET_OPTION_CONTEXT_VALUE
:
2496 return ERROR_INVALID_PARAMETER
;
2498 if (*size
< sizeof(DWORD_PTR
)) {
2499 *size
= sizeof(DWORD_PTR
);
2500 return ERROR_INSUFFICIENT_BUFFER
;
2503 return ERROR_INVALID_PARAMETER
;
2505 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2506 *size
= sizeof(DWORD_PTR
);
2507 return ERROR_SUCCESS
;
2509 case INTERNET_OPTION_REQUEST_FLAGS
:
2510 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2511 *size
= sizeof(DWORD
);
2512 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2514 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2515 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2516 WARN("Called on global option %u\n", option
);
2517 return ERROR_INTERNET_INVALID_OPERATION
;
2520 /* FIXME: we shouldn't call it here */
2521 return query_global_option(option
, buffer
, size
, unicode
);
2524 /***********************************************************************
2525 * InternetQueryOptionW (WININET.@)
2527 * Queries an options on the specified handle
2534 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2535 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2537 object_header_t
*hdr
;
2538 DWORD res
= ERROR_INVALID_HANDLE
;
2540 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2543 hdr
= get_handle_object(hInternet
);
2545 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2546 WININET_Release(hdr
);
2549 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2552 if(res
!= ERROR_SUCCESS
)
2554 return res
== ERROR_SUCCESS
;
2557 /***********************************************************************
2558 * InternetQueryOptionA (WININET.@)
2560 * Queries an options on the specified handle
2567 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2568 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2570 object_header_t
*hdr
;
2571 DWORD res
= ERROR_INVALID_HANDLE
;
2573 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2576 hdr
= get_handle_object(hInternet
);
2578 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2579 WININET_Release(hdr
);
2582 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2585 if(res
!= ERROR_SUCCESS
)
2587 return res
== ERROR_SUCCESS
;
2590 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2593 case INTERNET_OPTION_CALLBACK
:
2594 WARN("Not settable option %u\n", option
);
2595 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2596 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2597 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2598 WARN("Called on global option %u\n", option
);
2599 return ERROR_INTERNET_INVALID_OPERATION
;
2602 return ERROR_INTERNET_INVALID_OPTION
;
2605 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2608 case INTERNET_OPTION_CALLBACK
:
2609 WARN("Not global option %u\n", option
);
2610 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2612 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2613 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2615 if(size
!= sizeof(max_conns
))
2616 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2618 return ERROR_BAD_ARGUMENTS
;
2620 max_conns
= *(ULONG
*)buf
;
2621 return ERROR_SUCCESS
;
2623 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2624 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2626 if(size
!= sizeof(max_1_0_conns
))
2627 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2629 return ERROR_BAD_ARGUMENTS
;
2631 max_1_0_conns
= *(ULONG
*)buf
;
2632 return ERROR_SUCCESS
;
2634 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2635 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2637 if(size
!= sizeof(connect_timeout
))
2638 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2640 return ERROR_BAD_ARGUMENTS
;
2642 connect_timeout
= *(ULONG
*)buf
;
2643 return ERROR_SUCCESS
;
2645 case INTERNET_OPTION_SETTINGS_CHANGED
:
2646 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2647 collect_connections(COLLECT_CONNECTIONS
);
2648 return ERROR_SUCCESS
;
2650 case INTERNET_OPTION_SUPPRESS_BEHAVIOR
:
2651 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2653 if(size
!= sizeof(ULONG
))
2654 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2656 FIXME("%08x\n", *(ULONG
*)buf
);
2657 return ERROR_SUCCESS
;
2660 return ERROR_INTERNET_INVALID_OPTION
;
2663 /***********************************************************************
2664 * InternetSetOptionW (WININET.@)
2666 * Sets an options on the specified handle
2673 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2674 LPVOID lpBuffer
, DWORD dwBufferLength
)
2676 object_header_t
*lpwhh
;
2680 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2682 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2684 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2686 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2688 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2690 WININET_Release(lpwhh
);
2692 if(res
!= ERROR_SUCCESS
)
2695 return res
== ERROR_SUCCESS
;
2700 case INTERNET_OPTION_HTTP_VERSION
:
2702 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2703 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2706 case INTERNET_OPTION_ERROR_MASK
:
2709 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2711 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2712 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2713 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2714 SetLastError(ERROR_INVALID_PARAMETER
);
2716 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2717 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2720 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2721 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2724 case INTERNET_OPTION_PROXY
:
2726 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2728 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2730 SetLastError(ERROR_INVALID_PARAMETER
);
2735 EnterCriticalSection( &WININET_cs
);
2736 free_global_proxy();
2737 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2740 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2742 global_proxy
->proxyEnabled
= 1;
2743 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2744 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2748 global_proxy
->proxyEnabled
= 0;
2749 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2752 LeaveCriticalSection( &WININET_cs
);
2756 /* In general, each type of object should handle
2757 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2758 * get silently dropped.
2760 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2761 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2766 case INTERNET_OPTION_CODEPAGE
:
2768 ULONG codepage
= *(ULONG
*)lpBuffer
;
2769 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2772 case INTERNET_OPTION_REQUEST_PRIORITY
:
2774 ULONG priority
= *(ULONG
*)lpBuffer
;
2775 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2778 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2780 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2781 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2784 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2786 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2787 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2790 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2791 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2793 case INTERNET_OPTION_END_BROWSER_SESSION
:
2794 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2797 case INTERNET_OPTION_CONNECTED_STATE
:
2798 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2800 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2801 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2803 case INTERNET_OPTION_SEND_TIMEOUT
:
2804 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2805 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2807 ULONG timeout
= *(ULONG
*)lpBuffer
;
2808 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2811 case INTERNET_OPTION_CONNECT_RETRIES
:
2813 ULONG retries
= *(ULONG
*)lpBuffer
;
2814 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2817 case INTERNET_OPTION_CONTEXT_VALUE
:
2821 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2824 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2826 SetLastError(ERROR_INVALID_PARAMETER
);
2830 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2833 case INTERNET_OPTION_SECURITY_FLAGS
:
2834 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2836 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2837 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2839 case INTERNET_OPTION_HTTP_DECODING
:
2843 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2846 if (!lpBuffer
|| dwBufferLength
!= sizeof(BOOL
))
2848 SetLastError(ERROR_INVALID_PARAMETER
);
2852 lpwhh
->decoding
= *(BOOL
*)lpBuffer
;
2855 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2856 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2857 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2860 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2861 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2862 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2865 case INTERNET_OPTION_CODEPAGE_PATH
:
2866 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2867 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2870 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2871 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2872 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2875 case INTERNET_OPTION_IDN
:
2876 FIXME("INTERNET_OPTION_IDN; STUB\n");
2877 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2880 case INTERNET_OPTION_POLICY
:
2881 SetLastError(ERROR_INVALID_PARAMETER
);
2884 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2885 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2890 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2892 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2893 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2895 switch (option
->dwOption
) {
2896 case INTERNET_PER_CONN_PROXY_SERVER
:
2897 heap_free(pi
.proxy
);
2898 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2901 case INTERNET_PER_CONN_FLAGS
:
2902 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2903 pi
.proxyEnabled
= 1;
2906 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2907 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2908 pi
.proxyEnabled
= 0;
2912 case INTERNET_PER_CONN_PROXY_BYPASS
:
2913 heap_free(pi
.proxyBypass
);
2914 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
2917 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2918 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2919 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2920 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2921 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2922 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2923 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2927 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2928 SetLastError(ERROR_INVALID_PARAMETER
);
2933 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2938 ret
= (res
== ERROR_SUCCESS
);
2941 case INTERNET_OPTION_SETTINGS_CHANGED
:
2942 FIXME("INTERNET_OPTION_SETTINGS_CHANGED; STUB\n");
2944 case INTERNET_OPTION_REFRESH
:
2945 FIXME("INTERNET_OPTION_REFRESH; STUB\n");
2948 FIXME("Option %d STUB\n",dwOption
);
2949 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2955 WININET_Release( lpwhh
);
2961 /***********************************************************************
2962 * InternetSetOptionA (WININET.@)
2964 * Sets an options on the specified handle.
2971 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2972 LPVOID lpBuffer
, DWORD dwBufferLength
)
2980 case INTERNET_OPTION_PROXY
:
2982 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2983 LPINTERNET_PROXY_INFOW piw
;
2984 DWORD proxlen
, prbylen
;
2987 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2988 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2989 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2990 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2991 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2992 piw
->dwAccessType
= pi
->dwAccessType
;
2993 prox
= (LPWSTR
) &piw
[1];
2994 prby
= &prox
[proxlen
+1];
2995 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2996 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2997 piw
->lpszProxy
= prox
;
2998 piw
->lpszProxyBypass
= prby
;
3001 case INTERNET_OPTION_USER_AGENT
:
3002 case INTERNET_OPTION_USERNAME
:
3003 case INTERNET_OPTION_PASSWORD
:
3004 case INTERNET_OPTION_PROXY_USERNAME
:
3005 case INTERNET_OPTION_PROXY_PASSWORD
:
3006 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3007 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3008 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3010 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3012 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3013 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3014 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3015 wbuffer
= heap_alloc(wlen
);
3018 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3019 if (listA
->pszConnection
)
3021 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3022 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3023 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3026 listW
->pszConnection
= NULL
;
3027 listW
->dwOptionCount
= listA
->dwOptionCount
;
3028 listW
->dwOptionError
= listA
->dwOptionError
;
3029 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3031 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3032 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3033 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3035 optW
->dwOption
= optA
->dwOption
;
3037 switch (optA
->dwOption
) {
3038 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3039 case INTERNET_PER_CONN_PROXY_BYPASS
:
3040 case INTERNET_PER_CONN_PROXY_SERVER
:
3041 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3042 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3043 if (optA
->Value
.pszValue
)
3045 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3046 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3047 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3050 optW
->Value
.pszValue
= NULL
;
3052 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3053 case INTERNET_PER_CONN_FLAGS
:
3054 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3055 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3057 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3058 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3061 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3062 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3070 wlen
= dwBufferLength
;
3073 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3075 if( lpBuffer
!= wbuffer
)
3077 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3079 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3081 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3082 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3083 switch (opt
->dwOption
) {
3084 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3085 case INTERNET_PER_CONN_PROXY_BYPASS
:
3086 case INTERNET_PER_CONN_PROXY_SERVER
:
3087 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3088 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3089 heap_free( opt
->Value
.pszValue
);
3095 heap_free( list
->pOptions
);
3097 heap_free( wbuffer
);
3104 /***********************************************************************
3105 * InternetSetOptionExA (WININET.@)
3107 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3108 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3110 FIXME("Flags %08x ignored\n", dwFlags
);
3111 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3114 /***********************************************************************
3115 * InternetSetOptionExW (WININET.@)
3117 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3118 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3120 FIXME("Flags %08x ignored\n", dwFlags
);
3121 if( dwFlags
& ~ISO_VALID_FLAGS
)
3123 SetLastError( ERROR_INVALID_PARAMETER
);
3126 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3129 static const WCHAR WININET_wkday
[7][4] =
3130 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3131 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3132 static const WCHAR WININET_month
[12][4] =
3133 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3134 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3135 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3137 /***********************************************************************
3138 * InternetTimeFromSystemTimeA (WININET.@)
3140 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3143 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3145 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3147 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3149 SetLastError(ERROR_INVALID_PARAMETER
);
3153 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3155 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3159 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3160 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3165 /***********************************************************************
3166 * InternetTimeFromSystemTimeW (WININET.@)
3168 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3170 static const WCHAR date
[] =
3171 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3172 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3174 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3176 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3178 SetLastError(ERROR_INVALID_PARAMETER
);
3182 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3184 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3188 sprintfW( string
, date
,
3189 WININET_wkday
[time
->wDayOfWeek
],
3191 WININET_month
[time
->wMonth
- 1],
3200 /***********************************************************************
3201 * InternetTimeToSystemTimeA (WININET.@)
3203 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3208 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3210 stringW
= heap_strdupAtoW(string
);
3213 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3214 heap_free( stringW
);
3219 /***********************************************************************
3220 * InternetTimeToSystemTimeW (WININET.@)
3222 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3225 const WCHAR
*s
= string
;
3228 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3230 if (!string
|| !time
) return FALSE
;
3232 /* Windows does this too */
3233 GetSystemTime( time
);
3235 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3236 * a SYSTEMTIME structure.
3239 while (*s
&& !isalphaW( *s
)) s
++;
3240 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3241 time
->wDayOfWeek
= 7;
3243 for (i
= 0; i
< 7; i
++)
3245 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3246 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3247 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3249 time
->wDayOfWeek
= i
;
3254 if (time
->wDayOfWeek
> 6) return TRUE
;
3255 while (*s
&& !isdigitW( *s
)) s
++;
3256 time
->wDay
= strtolW( s
, &end
, 10 );
3259 while (*s
&& !isalphaW( *s
)) s
++;
3260 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3263 for (i
= 0; i
< 12; i
++)
3265 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3266 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3267 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3269 time
->wMonth
= i
+ 1;
3273 if (time
->wMonth
== 0) return TRUE
;
3275 while (*s
&& !isdigitW( *s
)) s
++;
3276 if (*s
== '\0') return TRUE
;
3277 time
->wYear
= strtolW( s
, &end
, 10 );
3280 while (*s
&& !isdigitW( *s
)) s
++;
3281 if (*s
== '\0') return TRUE
;
3282 time
->wHour
= strtolW( s
, &end
, 10 );
3285 while (*s
&& !isdigitW( *s
)) s
++;
3286 if (*s
== '\0') return TRUE
;
3287 time
->wMinute
= strtolW( s
, &end
, 10 );
3290 while (*s
&& !isdigitW( *s
)) s
++;
3291 if (*s
== '\0') return TRUE
;
3292 time
->wSecond
= strtolW( s
, &end
, 10 );
3295 time
->wMilliseconds
= 0;
3299 /***********************************************************************
3300 * InternetCheckConnectionW (WININET.@)
3302 * Pings a requested host to check internet connection
3305 * TRUE on success and FALSE on failure. If a failure then
3306 * ERROR_NOT_CONNECTED is placed into GetLastError
3309 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3312 * this is a kludge which runs the resident ping program and reads the output.
3314 * Anyone have a better idea?
3318 static const CHAR ping
[] = "ping -c 1 ";
3319 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3321 DWORD len
, host_len
;
3325 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl
), dwFlags
, dwReserved
);
3328 * Crack or set the Address
3330 if (lpszUrl
== NULL
)
3333 * According to the doc we are supposed to use the ip for the next
3334 * server in the WnInet internal server database. I have
3335 * no idea what that is or how to get it.
3337 * So someone needs to implement this.
3339 FIXME("Unimplemented with URL of NULL\n");
3344 URL_COMPONENTSW components
= {sizeof(components
)};
3346 components
.dwHostNameLength
= 1;
3348 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3351 host
= components
.lpszHostName
;
3352 host_len
= components
.dwHostNameLength
;
3353 port
= components
.nPort
;
3354 TRACE("host name: %s port: %d\n",debugstr_wn(host
, host_len
), port
);
3357 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3359 struct sockaddr_storage saddr
;
3360 int sa_len
= sizeof(saddr
);
3365 host_z
= heap_strndupW(host
, host_len
);
3369 b
= GetAddress(host_z
, port
, (struct sockaddr
*)&saddr
, &sa_len
, NULL
);
3374 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3377 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3385 * Build our ping command
3389 len
= WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, NULL
, 0, NULL
, NULL
);
3390 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
)+1);
3391 strcpy(command
, ping
);
3392 WideCharToMultiByte(CP_UNIXCP
, 0, host
, host_len
, command
+sizeof(ping
)-1, len
, NULL
, NULL
);
3393 strcpy(command
+sizeof(ping
)-1+len
, redirect
);
3395 TRACE("Ping command is : %s\n",command
);
3397 status
= system(command
);
3398 heap_free( command
);
3400 TRACE("Ping returned a code of %i\n",status
);
3402 /* Ping return code of 0 indicates success */
3409 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3415 /***********************************************************************
3416 * InternetCheckConnectionA (WININET.@)
3418 * Pings a requested host to check internet connection
3421 * TRUE on success and FALSE on failure. If a failure then
3422 * ERROR_NOT_CONNECTED is placed into GetLastError
3425 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3431 url
= heap_strdupAtoW(lpszUrl
);
3436 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3443 /**********************************************************
3444 * INTERNET_InternetOpenUrlW (internal)
3449 * handle of connection or NULL on failure
3451 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3452 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3454 URL_COMPONENTSW urlComponents
= { sizeof(urlComponents
) };
3455 WCHAR
*host
, *user
= NULL
, *pass
= NULL
, *path
;
3456 HINTERNET client
= NULL
, client1
= NULL
;
3459 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3460 dwHeadersLength
, dwFlags
, dwContext
);
3462 urlComponents
.dwHostNameLength
= 1;
3463 urlComponents
.dwUserNameLength
= 1;
3464 urlComponents
.dwPasswordLength
= 1;
3465 urlComponents
.dwUrlPathLength
= 1;
3466 urlComponents
.dwExtraInfoLength
= 1;
3467 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3470 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
3471 urlComponents
.dwExtraInfoLength
)
3473 assert(urlComponents
.lpszUrlPath
+ urlComponents
.dwUrlPathLength
== urlComponents
.lpszExtraInfo
);
3474 urlComponents
.dwUrlPathLength
+= urlComponents
.dwExtraInfoLength
;
3477 host
= heap_strndupW(urlComponents
.lpszHostName
, urlComponents
.dwHostNameLength
);
3478 path
= heap_strndupW(urlComponents
.lpszUrlPath
, urlComponents
.dwUrlPathLength
);
3479 if(urlComponents
.dwUserNameLength
)
3480 user
= heap_strndupW(urlComponents
.lpszUserName
, urlComponents
.dwUserNameLength
);
3481 if(urlComponents
.dwPasswordLength
)
3482 pass
= heap_strndupW(urlComponents
.lpszPassword
, urlComponents
.dwPasswordLength
);
3484 switch(urlComponents
.nScheme
) {
3485 case INTERNET_SCHEME_FTP
:
3486 client
= FTP_Connect(hIC
, host
, urlComponents
.nPort
,
3487 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
);
3490 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3491 if(client1
== NULL
) {
3492 InternetCloseHandle(client
);
3497 case INTERNET_SCHEME_HTTP
:
3498 case INTERNET_SCHEME_HTTPS
: {
3499 static const WCHAR szStars
[] = { '*','/','*', 0 };
3500 LPCWSTR accept
[2] = { szStars
, NULL
};
3502 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3504 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3505 res
= HTTP_Connect(hIC
, host
, urlComponents
.nPort
,
3506 user
, pass
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3507 if(res
!= ERROR_SUCCESS
) {
3508 INTERNET_SetLastError(res
);
3512 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3513 if(client1
== NULL
) {
3514 InternetCloseHandle(client
);
3517 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3518 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3519 GetLastError() != ERROR_IO_PENDING
) {
3520 InternetCloseHandle(client1
);
3525 case INTERNET_SCHEME_GOPHER
:
3526 /* gopher doesn't seem to be implemented in wine, but it's supposed
3527 * to be supported by InternetOpenUrlA. */
3529 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3533 TRACE(" %p <--\n", client1
);
3542 /**********************************************************
3543 * InternetOpenUrlW (WININET.@)
3548 * handle of connection or NULL on failure
3559 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3561 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3563 TRACE("%p\n", task
->hdr
.hdr
);
3565 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3566 task
->headers_len
, task
->flags
, task
->context
);
3567 heap_free(task
->url
);
3568 heap_free(task
->headers
);
3571 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3572 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3574 HINTERNET ret
= NULL
;
3575 appinfo_t
*hIC
= NULL
;
3577 if (TRACE_ON(wininet
)) {
3578 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3579 dwHeadersLength
, dwFlags
, dwContext
);
3581 dump_INTERNET_FLAGS(dwFlags
);
3586 SetLastError(ERROR_INVALID_PARAMETER
);
3590 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3591 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3592 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3596 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3597 open_url_task_t
*task
;
3599 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3600 task
->url
= heap_strdupW(lpszUrl
);
3601 task
->headers
= heap_strdupW(lpszHeaders
);
3602 task
->headers_len
= dwHeadersLength
;
3603 task
->flags
= dwFlags
;
3604 task
->context
= dwContext
;
3606 INTERNET_AsyncCall(&task
->hdr
);
3607 SetLastError(ERROR_IO_PENDING
);
3609 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3614 WININET_Release( &hIC
->hdr
);
3615 TRACE(" %p <--\n", ret
);
3620 /**********************************************************
3621 * InternetOpenUrlA (WININET.@)
3626 * handle of connection or NULL on failure
3628 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3629 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3631 HINTERNET rc
= NULL
;
3632 LPWSTR szUrl
= NULL
;
3633 WCHAR
*headers
= NULL
;
3638 szUrl
= heap_strdupAtoW(lpszUrl
);
3644 headers
= heap_strndupAtoW(lpszHeaders
, dwHeadersLength
, &dwHeadersLength
);
3651 rc
= InternetOpenUrlW(hInternet
, szUrl
, headers
, dwHeadersLength
, dwFlags
, dwContext
);
3659 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3661 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3665 lpwite
->dwError
= 0;
3666 lpwite
->response
[0] = '\0';
3669 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3678 /***********************************************************************
3679 * INTERNET_SetLastError (internal)
3681 * Set last thread specific error
3686 void INTERNET_SetLastError(DWORD dwError
)
3688 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3691 lpwite
= INTERNET_AllocThreadError();
3693 SetLastError(dwError
);
3695 lpwite
->dwError
= dwError
;
3699 /***********************************************************************
3700 * INTERNET_GetLastError (internal)
3702 * Get last thread specific error
3707 DWORD
INTERNET_GetLastError(void)
3709 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3710 if (!lpwite
) return 0;
3711 /* TlsGetValue clears last error, so set it again here */
3712 SetLastError(lpwite
->dwError
);
3713 return lpwite
->dwError
;
3717 /***********************************************************************
3718 * INTERNET_WorkerThreadFunc (internal)
3720 * Worker thread execution function
3725 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3727 task_header_t
*task
= lpvParam
;
3732 WININET_Release(task
->hdr
);
3735 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3737 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3738 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3743 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3745 task_header_t
*task
;
3747 task
= heap_alloc(size
);
3751 task
->hdr
= WININET_AddRef(hdr
);
3756 /***********************************************************************
3757 * INTERNET_AsyncCall (internal)
3759 * Retrieves work request from queue
3764 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3770 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3774 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3776 return ERROR_SUCCESS
;
3780 /***********************************************************************
3781 * INTERNET_GetResponseBuffer (internal)
3786 LPSTR
INTERNET_GetResponseBuffer(void)
3788 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3790 lpwite
= INTERNET_AllocThreadError();
3792 return lpwite
->response
;
3795 /**********************************************************
3796 * InternetQueryDataAvailable (WININET.@)
3798 * Determines how much data is available to be read.
3801 * TRUE on success, FALSE if an error occurred. If
3802 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3803 * no data is presently available, FALSE is returned with
3804 * the last error ERROR_IO_PENDING; a callback with status
3805 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3806 * data is available.
3808 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3809 LPDWORD lpdwNumberOfBytesAvailable
,
3810 DWORD dwFlags
, DWORD_PTR dwContext
)
3812 object_header_t
*hdr
;
3815 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3817 hdr
= get_handle_object( hFile
);
3819 SetLastError(ERROR_INVALID_HANDLE
);
3823 if(hdr
->vtbl
->QueryDataAvailable
) {
3824 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3826 WARN("wrong handle\n");
3827 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3830 WININET_Release(hdr
);
3832 if(res
!= ERROR_SUCCESS
)
3834 return res
== ERROR_SUCCESS
;
3837 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3839 req_file_t
*req_file
;
3841 req_file
= heap_alloc_zero(sizeof(*req_file
));
3843 return ERROR_NOT_ENOUGH_MEMORY
;
3847 req_file
->file_name
= heap_strdupW(file_name
);
3848 if(!req_file
->file_name
) {
3849 heap_free(req_file
);
3850 return ERROR_NOT_ENOUGH_MEMORY
;
3853 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3854 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3855 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
3856 req_file_release(req_file
);
3857 return GetLastError();
3861 return ERROR_SUCCESS
;
3864 void req_file_release(req_file_t
*req_file
)
3866 if(InterlockedDecrement(&req_file
->ref
))
3869 if(!req_file
->is_committed
)
3870 DeleteFileW(req_file
->file_name
);
3871 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
3872 CloseHandle(req_file
->file_handle
);
3873 heap_free(req_file
->file_name
);
3874 heap_free(req_file
->url
);
3875 heap_free(req_file
);
3878 /***********************************************************************
3879 * InternetLockRequestFile (WININET.@)
3881 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
3883 req_file_t
*req_file
= NULL
;
3884 object_header_t
*hdr
;
3887 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
3889 hdr
= get_handle_object(hInternet
);
3891 SetLastError(ERROR_INVALID_HANDLE
);
3895 if(hdr
->vtbl
->LockRequestFile
) {
3896 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
3898 WARN("wrong handle\n");
3899 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3902 WININET_Release(hdr
);
3904 *lphLockReqHandle
= req_file
;
3905 if(res
!= ERROR_SUCCESS
)
3907 return res
== ERROR_SUCCESS
;
3910 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
3912 TRACE("(%p)\n", hLockHandle
);
3914 req_file_release(hLockHandle
);
3919 /***********************************************************************
3920 * InternetAutodial (WININET.@)
3922 * On windows this function is supposed to dial the default internet
3923 * connection. We don't want to have Wine dial out to the internet so
3924 * we return TRUE by default. It might be nice to check if we are connected.
3931 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3935 /* Tell that we are connected to the internet. */
3939 /***********************************************************************
3940 * InternetAutodialHangup (WININET.@)
3942 * Hangs up a connection made with InternetAutodial
3951 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3955 /* we didn't dial, we don't disconnect */
3959 /***********************************************************************
3960 * InternetCombineUrlA (WININET.@)
3962 * Combine a base URL with a relative URL
3970 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3971 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3976 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3978 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3979 dwFlags
^= ICU_NO_ENCODE
;
3980 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3985 /***********************************************************************
3986 * InternetCombineUrlW (WININET.@)
3988 * Combine a base URL with a relative URL
3996 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3997 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4002 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4004 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4005 dwFlags
^= ICU_NO_ENCODE
;
4006 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4011 /* max port num is 65535 => 5 digits */
4012 #define MAX_WORD_DIGITS 5
4014 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4015 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4016 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4017 (url)->dw##component##Length : strlen((url)->lpsz##component))
4019 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4021 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4022 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4024 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4025 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4027 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4028 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4030 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4031 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4034 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4040 /* opaque urls do not fit into the standard url hierarchy and don't have
4041 * two following slashes */
4042 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4044 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4045 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4046 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4047 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4048 (nScheme
!= INTERNET_SCHEME_FILE
);
4051 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4054 if (scheme
< INTERNET_SCHEME_FIRST
)
4056 index
= scheme
- INTERNET_SCHEME_FIRST
;
4057 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4059 return (LPCWSTR
)url_schemes
[index
];
4062 /* we can calculate using ansi strings because we're just
4063 * calculating string length, not size
4065 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4066 LPDWORD lpdwUrlLength
)
4068 INTERNET_SCHEME nScheme
;
4072 if (lpUrlComponents
->lpszScheme
)
4074 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4075 *lpdwUrlLength
+= dwLen
;
4076 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4082 nScheme
= lpUrlComponents
->nScheme
;
4084 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4085 nScheme
= INTERNET_SCHEME_HTTP
;
4086 scheme
= INTERNET_GetSchemeString(nScheme
);
4087 *lpdwUrlLength
+= strlenW(scheme
);
4090 (*lpdwUrlLength
)++; /* ':' */
4091 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4092 *lpdwUrlLength
+= strlen("//");
4094 if (lpUrlComponents
->lpszUserName
)
4096 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4097 *lpdwUrlLength
+= strlen("@");
4101 if (lpUrlComponents
->lpszPassword
)
4103 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4108 if (lpUrlComponents
->lpszPassword
)
4110 *lpdwUrlLength
+= strlen(":");
4111 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4114 if (lpUrlComponents
->lpszHostName
)
4116 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4118 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4120 char szPort
[MAX_WORD_DIGITS
+1];
4122 *lpdwUrlLength
+= sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4123 *lpdwUrlLength
+= strlen(":");
4126 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4127 (*lpdwUrlLength
)++; /* '/' */
4130 if (lpUrlComponents
->lpszUrlPath
)
4131 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4133 if (lpUrlComponents
->lpszExtraInfo
)
4134 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4139 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4143 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4145 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4146 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4147 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4148 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4149 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4150 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4151 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4152 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4153 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4155 if (lpUrlComponents
->lpszScheme
)
4157 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4158 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4159 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4160 -1, urlCompW
->lpszScheme
, len
);
4163 if (lpUrlComponents
->lpszHostName
)
4165 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4166 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4167 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4168 -1, urlCompW
->lpszHostName
, len
);
4171 if (lpUrlComponents
->lpszUserName
)
4173 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4174 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4175 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4176 -1, urlCompW
->lpszUserName
, len
);
4179 if (lpUrlComponents
->lpszPassword
)
4181 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4182 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4183 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4184 -1, urlCompW
->lpszPassword
, len
);
4187 if (lpUrlComponents
->lpszUrlPath
)
4189 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4190 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4191 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4192 -1, urlCompW
->lpszUrlPath
, len
);
4195 if (lpUrlComponents
->lpszExtraInfo
)
4197 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4198 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4199 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4200 -1, urlCompW
->lpszExtraInfo
, len
);
4204 /***********************************************************************
4205 * InternetCreateUrlA (WININET.@)
4207 * See InternetCreateUrlW.
4209 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4210 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4214 URL_COMPONENTSW urlCompW
;
4216 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4218 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4220 SetLastError(ERROR_INVALID_PARAMETER
);
4224 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4227 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4229 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4231 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4232 *lpdwUrlLength
/= sizeof(WCHAR
);
4234 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4235 * minus one, so add one to leave room for NULL terminator
4238 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4240 heap_free(urlCompW
.lpszScheme
);
4241 heap_free(urlCompW
.lpszHostName
);
4242 heap_free(urlCompW
.lpszUserName
);
4243 heap_free(urlCompW
.lpszPassword
);
4244 heap_free(urlCompW
.lpszUrlPath
);
4245 heap_free(urlCompW
.lpszExtraInfo
);
4250 /***********************************************************************
4251 * InternetCreateUrlW (WININET.@)
4253 * Creates a URL from its component parts.
4256 * lpUrlComponents [I] URL Components.
4257 * dwFlags [I] Flags. See notes.
4258 * lpszUrl [I] Buffer in which to store the created URL.
4259 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4260 * lpszUrl in characters. On output, the number of bytes
4261 * required to store the URL including terminator.
4265 * The dwFlags parameter can be zero or more of the following:
4266 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4273 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4274 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4277 INTERNET_SCHEME nScheme
;
4279 static const WCHAR slashSlashW
[] = {'/','/'};
4280 static const WCHAR fmtW
[] = {'%','u',0};
4282 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4284 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4286 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4290 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4293 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4295 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4296 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4300 *lpdwUrlLength
= dwLen
;
4305 if (lpUrlComponents
->lpszScheme
)
4307 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4308 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4311 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4316 nScheme
= lpUrlComponents
->nScheme
;
4318 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4319 nScheme
= INTERNET_SCHEME_HTTP
;
4321 scheme
= INTERNET_GetSchemeString(nScheme
);
4322 dwLen
= strlenW(scheme
);
4323 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4327 /* all schemes are followed by at least a colon */
4331 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4333 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4334 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4337 if (lpUrlComponents
->lpszUserName
)
4339 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4340 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4343 if (lpUrlComponents
->lpszPassword
)
4348 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4349 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4357 if (lpUrlComponents
->lpszHostName
)
4359 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4360 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4363 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4367 lpszUrl
+= sprintfW(lpszUrl
, fmtW
, lpUrlComponents
->nPort
);
4370 /* add slash between hostname and path if necessary */
4371 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4378 if (lpUrlComponents
->lpszUrlPath
)
4380 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4381 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4385 if (lpUrlComponents
->lpszExtraInfo
)
4387 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4388 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4397 /***********************************************************************
4398 * InternetConfirmZoneCrossingA (WININET.@)
4401 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4403 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4404 return ERROR_SUCCESS
;
4407 /***********************************************************************
4408 * InternetConfirmZoneCrossingW (WININET.@)
4411 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4413 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4414 return ERROR_SUCCESS
;
4417 static DWORD zone_preference
= 3;
4419 /***********************************************************************
4420 * PrivacySetZonePreferenceW (WININET.@)
4422 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4424 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4426 zone_preference
= template;
4430 /***********************************************************************
4431 * PrivacyGetZonePreferenceW (WININET.@)
4433 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4434 LPWSTR preference
, LPDWORD length
)
4436 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4438 if (template) *template = zone_preference
;
4442 /***********************************************************************
4443 * InternetGetSecurityInfoByURLA (WININET.@)
4445 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4450 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4452 url
= heap_strdupAtoW(lpszURL
);
4456 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4461 /***********************************************************************
4462 * InternetGetSecurityInfoByURLW (WININET.@)
4464 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4466 URL_COMPONENTSW url
= {sizeof(url
)};
4470 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4472 url
.dwHostNameLength
= 1;
4473 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4474 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4475 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4479 server
= get_server(substr(url
.lpszHostName
, url
.dwHostNameLength
), url
.nPort
, TRUE
, FALSE
);
4481 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4485 if(server
->cert_chain
) {
4486 const CERT_CHAIN_CONTEXT
*chain_dup
;
4488 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4490 *ppCertChain
= chain_dup
;
4491 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4496 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4500 server_release(server
);
4504 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4505 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4507 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4508 lpdwConnection
, dwReserved
);
4509 return ERROR_SUCCESS
;
4512 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4513 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4515 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4516 lpdwConnection
, dwReserved
);
4517 return ERROR_SUCCESS
;
4520 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4522 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4526 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4528 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4532 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4534 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4535 return ERROR_SUCCESS
;
4538 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4541 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4542 debugstr_w(pwszTarget
), pbHexHash
);
4546 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4548 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4552 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4554 FIXME("(%p, %08lx) stub\n", a
, b
);
4558 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4560 FIXME("%p: stub\n", parent
);