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
39 #ifdef HAVE_CORESERVICES_CORESERVICES_H
40 #define GetCurrentThread MacGetCurrentThread
41 #define LoadResource MacLoadResource
42 #include <CoreServices/CoreServices.h>
43 #undef GetCurrentThread
54 #include "wine/debug.h"
56 #define NO_SHLWAPI_STREAM
59 #include "wine/exception.h"
64 #include "wine/unicode.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
71 CHAR response
[MAX_REPLY_LEN
];
72 } WITHREADERROR
, *LPWITHREADERROR
;
74 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
75 HMODULE WININET_hModule
;
77 static CRITICAL_SECTION WININET_cs
;
78 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
81 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
82 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
84 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
86 static object_header_t
**handle_table
;
87 static UINT_PTR next_handle
;
88 static UINT_PTR handle_table_size
;
99 static ULONG max_conns
= 2, max_1_0_conns
= 4;
100 static ULONG connect_timeout
= 60000;
102 static const WCHAR szInternetSettings
[] =
103 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
104 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
105 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
106 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
107 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
108 static const WCHAR szProxyOverride
[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
110 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
112 UINT_PTR handle
= 0, num
;
113 object_header_t
*ret
;
117 ret
= heap_alloc_zero(size
);
121 list_init(&ret
->children
);
123 EnterCriticalSection( &WININET_cs
);
125 if(!handle_table_size
) {
127 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
130 handle_table_size
= num
;
135 }else if(next_handle
== handle_table_size
) {
136 num
= handle_table_size
* 2;
137 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
140 handle_table_size
= num
;
147 handle
= next_handle
;
148 if(handle_table
[handle
])
149 ERR("handle isn't free but should be\n");
150 handle_table
[handle
] = ret
;
151 ret
->valid_handle
= TRUE
;
153 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
157 LeaveCriticalSection( &WININET_cs
);
166 ret
->hInternet
= (HINTERNET
)handle
;
169 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
170 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
176 object_header_t
*WININET_AddRef( object_header_t
*info
)
178 ULONG refs
= InterlockedIncrement(&info
->refs
);
179 TRACE("%p -> refcount = %d\n", info
, refs
);
183 object_header_t
*get_handle_object( HINTERNET hinternet
)
185 object_header_t
*info
= NULL
;
186 UINT_PTR handle
= (UINT_PTR
) hinternet
;
188 EnterCriticalSection( &WININET_cs
);
190 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
191 info
= WININET_AddRef(handle_table
[handle
]);
193 LeaveCriticalSection( &WININET_cs
);
195 TRACE("handle %ld -> %p\n", handle
, info
);
200 static void invalidate_handle(object_header_t
*info
)
202 object_header_t
*child
, *next
;
204 if(!info
->valid_handle
)
206 info
->valid_handle
= FALSE
;
208 /* Free all children as native does */
209 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
211 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
212 invalidate_handle( child
);
215 WININET_Release(info
);
218 BOOL
WININET_Release( object_header_t
*info
)
220 ULONG refs
= InterlockedDecrement(&info
->refs
);
221 TRACE( "object %p refcount = %d\n", info
, refs
);
224 invalidate_handle(info
);
225 if ( info
->vtbl
->CloseConnection
)
227 TRACE( "closing connection %p\n", info
);
228 info
->vtbl
->CloseConnection( info
);
230 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
231 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
232 || !(info
->dwInternalFlags
& INET_OPENURL
))
234 INTERNET_SendCallback(info
, info
->dwContext
,
235 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
238 TRACE( "destroying object %p\n", info
);
239 if ( info
->htype
!= WH_HINIT
)
240 list_remove( &info
->entry
);
241 info
->vtbl
->Destroy( info
);
243 if(info
->hInternet
) {
244 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
246 EnterCriticalSection( &WININET_cs
);
248 handle_table
[handle
] = NULL
;
249 if(next_handle
> handle
)
250 next_handle
= handle
;
252 LeaveCriticalSection( &WININET_cs
);
260 /***********************************************************************
261 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
264 * hinstDLL [I] handle to the DLL's instance
266 * lpvReserved [I] reserved, must be NULL
273 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
275 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
278 case DLL_PROCESS_ATTACH
:
280 g_dwTlsErrIndex
= TlsAlloc();
282 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
287 TlsFree(g_dwTlsErrIndex
);
291 WININET_hModule
= hinstDLL
;
294 case DLL_THREAD_ATTACH
:
297 case DLL_THREAD_DETACH
:
298 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
300 heap_free(TlsGetValue(g_dwTlsErrIndex
));
304 case DLL_PROCESS_DETACH
:
305 if (lpvReserved
) break;
306 collect_connections(COLLECT_CLEANUP
);
311 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
313 heap_free(TlsGetValue(g_dwTlsErrIndex
));
314 TlsFree(g_dwTlsErrIndex
);
321 /***********************************************************************
322 * DllInstall (WININET.@)
324 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
326 FIXME("(%x %s): stub\n", bInstall
, debugstr_w(cmdline
));
330 /***********************************************************************
331 * INTERNET_SaveProxySettings
333 * Stores the proxy settings given by lpwai into the registry
336 * ERROR_SUCCESS if no error, or error code on fail
338 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
343 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
346 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
354 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
362 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
370 return ERROR_SUCCESS
;
373 /***********************************************************************
374 * INTERNET_FindProxyForProtocol
376 * Searches the proxy string for a proxy of the given protocol.
377 * Returns the found proxy, or the default proxy if none of the given
381 * szProxy [In] proxy string to search
382 * proto [In] protocol to search for, e.g. "http"
383 * foundProxy [Out] found proxy
384 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
387 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
388 * *foundProxyLen is set to the required size in WCHARs, including the
389 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
391 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
396 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
398 /* First, look for the specified protocol (proto=scheme://host:port) */
399 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
403 if (!(end
= strchrW(ptr
, ' ')))
404 end
= ptr
+ strlenW(ptr
);
405 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
406 equal
- ptr
== strlenW(proto
) &&
407 !strncmpiW(proto
, ptr
, strlenW(proto
)))
409 if (end
- equal
> *foundProxyLen
)
411 WARN("buffer too short for %s\n",
412 debugstr_wn(equal
+ 1, end
- equal
- 1));
413 *foundProxyLen
= end
- equal
;
414 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
418 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
419 foundProxy
[end
- equal
] = 0;
430 /* It wasn't found: look for no protocol */
431 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
435 if (!(end
= strchrW(ptr
, ' ')))
436 end
= ptr
+ strlenW(ptr
);
437 if (!strchrW(ptr
, '='))
439 if (end
- ptr
+ 1 > *foundProxyLen
)
441 WARN("buffer too short for %s\n",
442 debugstr_wn(ptr
, end
- ptr
));
443 *foundProxyLen
= end
- ptr
+ 1;
444 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
448 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
449 foundProxy
[end
- ptr
] = 0;
460 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
461 debugstr_w(foundProxy
));
465 /***********************************************************************
466 * InternetInitializeAutoProxyDll (WININET.@)
468 * Setup the internal proxy
477 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
480 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
484 /***********************************************************************
485 * DetectAutoProxyUrl (WININET.@)
487 * Auto detect the proxy url
493 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
494 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
497 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
501 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
503 heap_free(lpwpi
->proxy
);
504 heap_free(lpwpi
->proxyBypass
);
505 heap_free(lpwpi
->proxyUsername
);
506 heap_free(lpwpi
->proxyPassword
);
509 static proxyinfo_t
*global_proxy
;
511 static void free_global_proxy( void )
513 EnterCriticalSection( &WININET_cs
);
516 FreeProxyInfo( global_proxy
);
517 heap_free( global_proxy
);
519 LeaveCriticalSection( &WININET_cs
);
522 static BOOL
parse_proxy_url( proxyinfo_t
*info
, const WCHAR
*url
)
524 static const WCHAR fmt
[] = {'%','s',':','%','u',0};
525 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
526 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
];
527 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
530 hostname
[0] = username
[0] = password
[0] = 0;
531 memset( &uc
, 0, sizeof(uc
) );
532 uc
.dwStructSize
= sizeof(uc
);
533 uc
.lpszHostName
= hostname
;
534 uc
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
535 uc
.lpszUserName
= username
;
536 uc
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
537 uc
.lpszPassword
= password
;
538 uc
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
540 if (!InternetCrackUrlW( url
, 0, 0, &uc
)) return FALSE
;
543 if (!(info
->proxy
= heap_strdupW( url
))) return FALSE
;
544 info
->proxyUsername
= NULL
;
545 info
->proxyPassword
= NULL
;
548 if (!(info
->proxy
= heap_alloc( (strlenW(hostname
) + 12) * sizeof(WCHAR
) ))) return FALSE
;
549 sprintfW( info
->proxy
, fmt
, hostname
, uc
.nPort
);
551 if (!username
[0]) info
->proxyUsername
= NULL
;
552 else if (!(info
->proxyUsername
= heap_strdupW( username
)))
554 heap_free( info
->proxy
);
557 if (!password
[0]) info
->proxyPassword
= NULL
;
558 else if (!(info
->proxyPassword
= heap_strdupW( password
)))
560 heap_free( info
->proxyUsername
);
561 heap_free( info
->proxy
);
567 /***********************************************************************
568 * INTERNET_LoadProxySettings
570 * Loads proxy information from process-wide global settings, the registry,
571 * or the environment into lpwpi.
573 * The caller should call FreeProxyInfo when done with lpwpi.
576 * The proxy may be specified in the form 'http=proxy.my.org'
577 * Presumably that means there can be ftp=ftpproxy.my.org too.
579 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
586 memset( lpwpi
, 0, sizeof(*lpwpi
) );
588 EnterCriticalSection( &WININET_cs
);
591 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
592 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
593 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
595 LeaveCriticalSection( &WININET_cs
);
597 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
599 FreeProxyInfo( lpwpi
);
604 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
606 lpwpi
->proxyEnabled
= 0;
607 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
609 FreeProxyInfo( lpwpi
);
615 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
617 /* figure out how much memory the proxy setting takes */
618 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
621 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
623 if (!(szProxy
= heap_alloc(len
)))
626 FreeProxyInfo( lpwpi
);
627 return ERROR_OUTOFMEMORY
;
629 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
631 /* find the http proxy, and strip away everything else */
632 p
= strstrW( szProxy
, szHttp
);
635 p
+= lstrlenW( szHttp
);
636 lstrcpyW( szProxy
, p
);
638 p
= strchrW( szProxy
, ';' );
641 FreeProxyInfo( lpwpi
);
642 lpwpi
->proxy
= szProxy
;
643 lpwpi
->proxyBypass
= NULL
;
645 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi
->proxy
));
649 TRACE("No proxy server settings in registry.\n");
650 FreeProxyInfo( lpwpi
);
652 lpwpi
->proxyBypass
= NULL
;
659 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
660 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
663 return ERROR_OUTOFMEMORY
;
665 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
667 FreeProxyInfo( lpwpi
);
668 if (parse_proxy_url( lpwpi
, envproxyW
))
670 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
671 lpwpi
->proxyEnabled
= 1;
672 lpwpi
->proxyBypass
= NULL
;
676 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW
));
677 lpwpi
->proxyEnabled
= 0;
679 lpwpi
->proxyBypass
= NULL
;
681 heap_free( envproxyW
);
684 if (lpwpi
->proxyEnabled
)
686 TRACE("Proxy is enabled.\n");
688 if (!(envproxy
= getenv( "no_proxy" )))
690 /* figure out how much memory the proxy setting takes */
691 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
695 if (!(szProxy
= heap_alloc(len
)))
698 return ERROR_OUTOFMEMORY
;
700 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
702 heap_free( lpwpi
->proxyBypass
);
703 lpwpi
->proxyBypass
= szProxy
;
705 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
709 heap_free( lpwpi
->proxyBypass
);
710 lpwpi
->proxyBypass
= NULL
;
712 TRACE("No proxy bypass server settings in registry.\n");
719 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
720 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
723 return ERROR_OUTOFMEMORY
;
725 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
727 heap_free( lpwpi
->proxyBypass
);
728 lpwpi
->proxyBypass
= envproxyW
;
730 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
733 else TRACE("Proxy is disabled.\n");
736 return ERROR_SUCCESS
;
739 /***********************************************************************
740 * INTERNET_ConfigureProxy
742 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
746 if (INTERNET_LoadProxySettings( &wpi
))
749 if (wpi
.proxyEnabled
)
751 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai
->proxy
), debugstr_w(lpwai
->proxyBypass
));
753 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
754 lpwai
->proxy
= wpi
.proxy
;
755 lpwai
->proxyBypass
= wpi
.proxyBypass
;
756 lpwai
->proxyUsername
= wpi
.proxyUsername
;
757 lpwai
->proxyPassword
= wpi
.proxyPassword
;
761 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
766 /***********************************************************************
767 * dump_INTERNET_FLAGS
769 * Helper function to TRACE the internet flags.
775 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
777 #define FE(x) { x, #x }
778 static const wininet_flag_info flag
[] = {
779 FE(INTERNET_FLAG_RELOAD
),
780 FE(INTERNET_FLAG_RAW_DATA
),
781 FE(INTERNET_FLAG_EXISTING_CONNECT
),
782 FE(INTERNET_FLAG_ASYNC
),
783 FE(INTERNET_FLAG_PASSIVE
),
784 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
785 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
786 FE(INTERNET_FLAG_FROM_CACHE
),
787 FE(INTERNET_FLAG_SECURE
),
788 FE(INTERNET_FLAG_KEEP_CONNECTION
),
789 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
790 FE(INTERNET_FLAG_READ_PREFETCH
),
791 FE(INTERNET_FLAG_NO_COOKIES
),
792 FE(INTERNET_FLAG_NO_AUTH
),
793 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
794 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
795 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
796 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
797 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
798 FE(INTERNET_FLAG_RESYNCHRONIZE
),
799 FE(INTERNET_FLAG_HYPERLINK
),
800 FE(INTERNET_FLAG_NO_UI
),
801 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
802 FE(INTERNET_FLAG_CACHE_ASYNC
),
803 FE(INTERNET_FLAG_FORMS_SUBMIT
),
804 FE(INTERNET_FLAG_NEED_FILE
),
805 FE(INTERNET_FLAG_TRANSFER_ASCII
),
806 FE(INTERNET_FLAG_TRANSFER_BINARY
)
811 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
812 if (flag
[i
].val
& dwFlags
) {
813 TRACE(" %s", flag
[i
].name
);
814 dwFlags
&= ~flag
[i
].val
;
818 TRACE(" Unknown flags (%08x)\n", dwFlags
);
823 /***********************************************************************
824 * INTERNET_CloseHandle (internal)
826 * Close internet handle
829 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
831 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
835 heap_free(lpwai
->agent
);
836 heap_free(lpwai
->proxy
);
837 heap_free(lpwai
->proxyBypass
);
838 heap_free(lpwai
->proxyUsername
);
839 heap_free(lpwai
->proxyPassword
);
842 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
844 appinfo_t
*ai
= (appinfo_t
*)hdr
;
847 case INTERNET_OPTION_HANDLE_TYPE
:
848 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
850 if (*size
< sizeof(ULONG
))
851 return ERROR_INSUFFICIENT_BUFFER
;
853 *size
= sizeof(DWORD
);
854 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
855 return ERROR_SUCCESS
;
857 case INTERNET_OPTION_USER_AGENT
: {
860 TRACE("INTERNET_OPTION_USER_AGENT\n");
865 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
867 *size
= (len
+ 1) * sizeof(WCHAR
);
868 if(!buffer
|| bufsize
< *size
)
869 return ERROR_INSUFFICIENT_BUFFER
;
872 strcpyW(buffer
, ai
->agent
);
874 *(WCHAR
*)buffer
= 0;
875 /* If the buffer is copied, the returned length doesn't include
876 * the NULL terminator.
881 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
884 if(!buffer
|| bufsize
< *size
)
885 return ERROR_INSUFFICIENT_BUFFER
;
888 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
891 /* If the buffer is copied, the returned length doesn't include
892 * the NULL terminator.
897 return ERROR_SUCCESS
;
900 case INTERNET_OPTION_PROXY
:
901 if(!size
) return ERROR_INVALID_PARAMETER
;
903 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
904 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
905 LPWSTR proxy
, proxy_bypass
;
908 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
910 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
911 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
913 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
914 return ERROR_INSUFFICIENT_BUFFER
;
916 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
917 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
919 pi
->dwAccessType
= ai
->accessType
;
920 pi
->lpszProxy
= NULL
;
921 pi
->lpszProxyBypass
= NULL
;
923 lstrcpyW(proxy
, ai
->proxy
);
924 pi
->lpszProxy
= proxy
;
927 if (ai
->proxyBypass
) {
928 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
929 pi
->lpszProxyBypass
= proxy_bypass
;
932 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
933 return ERROR_SUCCESS
;
935 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
936 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
937 LPSTR proxy
, proxy_bypass
;
940 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
942 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
943 NULL
, 0, NULL
, NULL
);
944 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
946 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
947 return ERROR_INSUFFICIENT_BUFFER
;
949 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
950 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
952 pi
->dwAccessType
= ai
->accessType
;
953 pi
->lpszProxy
= NULL
;
954 pi
->lpszProxyBypass
= NULL
;
956 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
957 pi
->lpszProxy
= proxy
;
960 if (ai
->proxyBypass
) {
961 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
962 proxyBypassBytesRequired
, NULL
, NULL
);
963 pi
->lpszProxyBypass
= proxy_bypass
;
966 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
967 return ERROR_SUCCESS
;
970 case INTERNET_OPTION_CONNECT_TIMEOUT
:
971 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
973 if (*size
< sizeof(ULONG
))
974 return ERROR_INSUFFICIENT_BUFFER
;
976 *(ULONG
*)buffer
= ai
->connect_timeout
;
977 *size
= sizeof(ULONG
);
979 return ERROR_SUCCESS
;
982 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
985 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
987 appinfo_t
*ai
= (appinfo_t
*)hdr
;
990 case INTERNET_OPTION_CONNECT_TIMEOUT
:
991 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
993 if(size
!= sizeof(connect_timeout
))
994 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
996 return ERROR_BAD_ARGUMENTS
;
998 ai
->connect_timeout
= *(ULONG
*)buf
;
999 return ERROR_SUCCESS
;
1000 case INTERNET_OPTION_USER_AGENT
:
1001 heap_free(ai
->agent
);
1002 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
1003 return ERROR_SUCCESS
;
1006 return INET_SetOption(hdr
, option
, buf
, size
);
1009 static const object_vtbl_t APPINFOVtbl
= {
1012 APPINFO_QueryOption
,
1021 /***********************************************************************
1022 * InternetOpenW (WININET.@)
1024 * Per-application initialization of wininet
1027 * HINTERNET on success
1031 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
1032 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
1034 appinfo_t
*lpwai
= NULL
;
1036 if (TRACE_ON(wininet
)) {
1037 #define FE(x) { x, #x }
1038 static const wininet_flag_info access_type
[] = {
1039 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
1040 FE(INTERNET_OPEN_TYPE_DIRECT
),
1041 FE(INTERNET_OPEN_TYPE_PROXY
),
1042 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
1046 const char *access_type_str
= "Unknown";
1048 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1049 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1050 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
1051 if (access_type
[i
].val
== dwAccessType
) {
1052 access_type_str
= access_type
[i
].name
;
1056 TRACE(" access type : %s\n", access_type_str
);
1058 dump_INTERNET_FLAGS(dwFlags
);
1061 /* Clear any error information */
1062 INTERNET_SetLastError(0);
1064 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1065 SetLastError(ERROR_INVALID_PARAMETER
);
1069 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1071 SetLastError(ERROR_OUTOFMEMORY
);
1075 lpwai
->hdr
.htype
= WH_HINIT
;
1076 lpwai
->hdr
.dwFlags
= dwFlags
;
1077 lpwai
->accessType
= dwAccessType
;
1078 lpwai
->proxyUsername
= NULL
;
1079 lpwai
->proxyPassword
= NULL
;
1080 lpwai
->connect_timeout
= connect_timeout
;
1082 lpwai
->agent
= heap_strdupW(lpszAgent
);
1083 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1084 INTERNET_ConfigureProxy( lpwai
);
1085 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1086 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1087 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1090 TRACE("returning %p\n", lpwai
);
1092 return lpwai
->hdr
.hInternet
;
1096 /***********************************************************************
1097 * InternetOpenA (WININET.@)
1099 * Per-application initialization of wininet
1102 * HINTERNET on success
1106 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1107 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1109 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1112 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1113 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1115 szAgent
= heap_strdupAtoW(lpszAgent
);
1116 szProxy
= heap_strdupAtoW(lpszProxy
);
1117 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1119 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1123 heap_free(szBypass
);
1127 /***********************************************************************
1128 * InternetGetLastResponseInfoA (WININET.@)
1130 * Return last wininet error description on the calling thread
1133 * TRUE on success of writing to buffer
1137 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1138 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1140 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1146 *lpdwError
= lpwite
->dwError
;
1147 if (lpwite
->dwError
)
1149 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1150 *lpdwBufferLength
= strlen(lpszBuffer
);
1153 *lpdwBufferLength
= 0;
1158 *lpdwBufferLength
= 0;
1164 /***********************************************************************
1165 * InternetGetLastResponseInfoW (WININET.@)
1167 * Return last wininet error description on the calling thread
1170 * TRUE on success of writing to buffer
1174 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1175 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1177 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1183 *lpdwError
= lpwite
->dwError
;
1184 if (lpwite
->dwError
)
1186 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1187 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1190 *lpdwBufferLength
= 0;
1195 *lpdwBufferLength
= 0;
1201 /***********************************************************************
1202 * InternetGetConnectedState (WININET.@)
1204 * Return connected state
1208 * if lpdwStatus is not null, return the status (off line,
1209 * modem, lan...) in it.
1210 * FALSE if not connected
1212 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1214 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1217 WARN("always returning LAN connection.\n");
1218 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1224 /***********************************************************************
1225 * InternetGetConnectedStateExW (WININET.@)
1227 * Return connected state
1231 * lpdwStatus [O] Flags specifying the status of the internet connection.
1232 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1233 * dwNameLen [I] Size of the buffer, in characters.
1234 * dwReserved [I] Reserved. Must be set to 0.
1238 * if lpdwStatus is not null, return the status (off line,
1239 * modem, lan...) in it.
1240 * FALSE if not connected
1243 * If the system has no available network connections, an empty string is
1244 * stored in lpszConnectionName. If there is a LAN connection, a localized
1245 * "LAN Connection" string is stored. Presumably, if only a dial-up
1246 * connection is available then the name of the dial-up connection is
1247 * returned. Why any application, other than the "Internet Settings" CPL,
1248 * would want to use this function instead of the simpler InternetGetConnectedStateW
1249 * function is beyond me.
1251 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1252 DWORD dwNameLen
, DWORD dwReserved
)
1254 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1261 WARN("always returning LAN connection.\n");
1262 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1265 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1266 * the resource, avoid it as we must not change the buffer in this case */
1267 if(lpszConnectionName
&& dwNameLen
) {
1268 *lpszConnectionName
= '\0';
1269 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1276 /***********************************************************************
1277 * InternetGetConnectedStateExA (WININET.@)
1279 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1280 DWORD dwNameLen
, DWORD dwReserved
)
1282 LPWSTR lpwszConnectionName
= NULL
;
1285 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1287 if (lpszConnectionName
&& dwNameLen
> 0)
1288 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1290 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1292 if (rc
&& lpwszConnectionName
)
1293 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1294 dwNameLen
, NULL
, NULL
);
1296 heap_free(lpwszConnectionName
);
1301 /***********************************************************************
1302 * InternetConnectW (WININET.@)
1304 * Open a ftp, gopher or http session
1307 * HINTERNET a session handle on success
1311 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1312 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1313 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1314 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1317 HINTERNET rc
= NULL
;
1318 DWORD res
= ERROR_SUCCESS
;
1320 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1321 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1322 dwService
, dwFlags
, dwContext
);
1324 if (!lpszServerName
)
1326 SetLastError(ERROR_INVALID_PARAMETER
);
1330 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1331 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1333 res
= ERROR_INVALID_HANDLE
;
1339 case INTERNET_SERVICE_FTP
:
1340 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1341 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1343 res
= INTERNET_GetLastError();
1346 case INTERNET_SERVICE_HTTP
:
1347 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1348 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1351 case INTERNET_SERVICE_GOPHER
:
1357 WININET_Release( &hIC
->hdr
);
1359 TRACE("returning %p\n", rc
);
1365 /***********************************************************************
1366 * InternetConnectA (WININET.@)
1368 * Open a ftp, gopher or http session
1371 * HINTERNET a session handle on success
1375 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1376 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1377 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1378 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1380 HINTERNET rc
= NULL
;
1381 LPWSTR szServerName
;
1385 szServerName
= heap_strdupAtoW(lpszServerName
);
1386 szUserName
= heap_strdupAtoW(lpszUserName
);
1387 szPassword
= heap_strdupAtoW(lpszPassword
);
1389 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1390 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1392 heap_free(szServerName
);
1393 heap_free(szUserName
);
1394 heap_free(szPassword
);
1399 /***********************************************************************
1400 * InternetFindNextFileA (WININET.@)
1402 * Continues a file search from a previous call to FindFirstFile
1409 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1412 WIN32_FIND_DATAW fd
;
1414 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1416 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1420 /***********************************************************************
1421 * InternetFindNextFileW (WININET.@)
1423 * Continues a file search from a previous call to FindFirstFile
1430 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1432 object_header_t
*hdr
;
1437 hdr
= get_handle_object(hFind
);
1439 WARN("Invalid handle\n");
1440 SetLastError(ERROR_INVALID_HANDLE
);
1444 if(hdr
->vtbl
->FindNextFileW
) {
1445 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1447 WARN("Handle doesn't support NextFile\n");
1448 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1451 WININET_Release(hdr
);
1453 if(res
!= ERROR_SUCCESS
)
1455 return res
== ERROR_SUCCESS
;
1458 /***********************************************************************
1459 * InternetCloseHandle (WININET.@)
1461 * Generic close handle function
1468 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1470 object_header_t
*obj
;
1472 TRACE("%p\n", hInternet
);
1474 obj
= get_handle_object( hInternet
);
1476 SetLastError(ERROR_INVALID_HANDLE
);
1480 invalidate_handle(obj
);
1481 WININET_Release(obj
);
1487 /***********************************************************************
1488 * ConvertUrlComponentValue (Internal)
1490 * Helper function for InternetCrackUrlA
1493 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1494 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1495 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1497 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1498 if (*dwComponentLen
!= 0)
1500 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1501 if (*lppszComponent
== NULL
)
1505 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1506 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1509 *lppszComponent
= NULL
;
1511 *dwComponentLen
= nASCIILength
;
1515 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1516 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1517 (*lppszComponent
)[ncpylen
]=0;
1518 *dwComponentLen
= ncpylen
;
1524 /***********************************************************************
1525 * InternetCrackUrlA (WININET.@)
1527 * See InternetCrackUrlW.
1529 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1530 LPURL_COMPONENTSA lpUrlComponents
)
1533 URL_COMPONENTSW UCW
;
1535 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1536 *scheme
= NULL
, *extra
= NULL
;
1538 TRACE("(%s %u %x %p)\n",
1539 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1540 dwUrlLength
, dwFlags
, lpUrlComponents
);
1542 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1543 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1545 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1551 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1553 /* if dwUrlLength=-1 then nLength includes null but length to
1554 InternetCrackUrlW should not include it */
1555 if (dwUrlLength
== -1) nLength
--;
1557 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1558 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1559 lpwszUrl
[nLength
] = '\0';
1561 memset(&UCW
,0,sizeof(UCW
));
1562 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1563 if (lpUrlComponents
->dwHostNameLength
)
1565 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1566 if (lpUrlComponents
->lpszHostName
)
1568 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1569 UCW
.lpszHostName
= hostname
;
1572 if (lpUrlComponents
->dwUserNameLength
)
1574 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1575 if (lpUrlComponents
->lpszUserName
)
1577 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1578 UCW
.lpszUserName
= username
;
1581 if (lpUrlComponents
->dwPasswordLength
)
1583 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1584 if (lpUrlComponents
->lpszPassword
)
1586 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1587 UCW
.lpszPassword
= password
;
1590 if (lpUrlComponents
->dwUrlPathLength
)
1592 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1593 if (lpUrlComponents
->lpszUrlPath
)
1595 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1596 UCW
.lpszUrlPath
= path
;
1599 if (lpUrlComponents
->dwSchemeLength
)
1601 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1602 if (lpUrlComponents
->lpszScheme
)
1604 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1605 UCW
.lpszScheme
= scheme
;
1608 if (lpUrlComponents
->dwExtraInfoLength
)
1610 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1611 if (lpUrlComponents
->lpszExtraInfo
)
1613 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1614 UCW
.lpszExtraInfo
= extra
;
1617 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1619 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1620 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1621 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1622 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1623 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1624 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1625 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1626 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1627 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1628 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1629 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1630 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1632 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1633 lpUrlComponents
->nPort
= UCW
.nPort
;
1635 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1636 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1637 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1638 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1639 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1641 heap_free(lpwszUrl
);
1642 heap_free(hostname
);
1643 heap_free(username
);
1644 heap_free(password
);
1651 static const WCHAR url_schemes
[][7] =
1654 {'g','o','p','h','e','r',0},
1655 {'h','t','t','p',0},
1656 {'h','t','t','p','s',0},
1657 {'f','i','l','e',0},
1658 {'n','e','w','s',0},
1659 {'m','a','i','l','t','o',0},
1663 /***********************************************************************
1664 * GetInternetSchemeW (internal)
1670 * INTERNET_SCHEME_UNKNOWN on failure
1673 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1677 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1679 if(lpszScheme
==NULL
)
1680 return INTERNET_SCHEME_UNKNOWN
;
1682 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1683 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1684 return INTERNET_SCHEME_FIRST
+ i
;
1686 return INTERNET_SCHEME_UNKNOWN
;
1689 /***********************************************************************
1690 * SetUrlComponentValueW (Internal)
1692 * Helper function for InternetCrackUrlW
1695 * lppszComponent [O] Holds the returned string
1696 * dwComponentLen [I] Holds the size of lppszComponent
1697 * [O] Holds the length of the string in lppszComponent without '\0'
1698 * lpszStart [I] Holds the string to copy from
1699 * len [I] Holds the length of lpszStart without '\0'
1706 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1708 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1710 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1713 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1715 if (*lppszComponent
== NULL
)
1717 *lppszComponent
= (LPWSTR
)lpszStart
;
1718 *dwComponentLen
= len
;
1722 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1723 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1724 (*lppszComponent
)[ncpylen
] = '\0';
1725 *dwComponentLen
= ncpylen
;
1732 /***********************************************************************
1733 * InternetCrackUrlW (WININET.@)
1735 * Break up URL into its components
1741 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1742 LPURL_COMPONENTSW lpUC
)
1746 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1749 LPCWSTR lpszParam
= NULL
;
1750 BOOL found_colon
= FALSE
;
1751 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1752 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1753 LPWSTR lpszUrl_decode
= NULL
;
1754 DWORD dwUrlLength
= dwUrlLength_orig
;
1756 TRACE("(%s %u %x %p)\n",
1757 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1758 dwUrlLength
, dwFlags
, lpUC
);
1760 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1762 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1765 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1767 if (dwFlags
& ICU_DECODE
)
1770 DWORD len
= dwUrlLength
+ 1;
1772 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1774 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1777 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1778 url_tmp
[dwUrlLength
] = 0;
1779 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1782 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1785 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1788 lpszUrl
= lpszUrl_decode
;
1794 /* Determine if the URI is absolute. */
1795 while (lpszap
- lpszUrl
< dwUrlLength
)
1797 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1809 lpszcp
= lpszUrl
; /* Relative url */
1816 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1820 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1821 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1823 /* Parse <params> */
1824 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1826 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1828 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1829 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1832 /* Get scheme first. */
1833 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1834 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1835 lpszUrl
, lpszcp
- lpszUrl
);
1837 /* Eat ':' in protocol. */
1840 /* double slash indicates the net_loc portion is present */
1841 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1845 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1849 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1851 lpszNetLoc
= lpszParam
;
1853 else if (!lpszNetLoc
)
1854 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1862 /* [<user>[<:password>]@]<host>[:<port>] */
1863 /* First find the user and password if they exist */
1865 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1866 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1868 /* username and password not specified. */
1869 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1870 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1872 else /* Parse out username and password */
1874 LPCWSTR lpszUser
= lpszcp
;
1875 LPCWSTR lpszPasswd
= lpszHost
;
1877 while (lpszcp
< lpszHost
)
1880 lpszPasswd
= lpszcp
;
1885 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1886 lpszUser
, lpszPasswd
- lpszUser
);
1888 if (lpszPasswd
!= lpszHost
)
1890 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1891 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1892 lpszHost
- lpszPasswd
);
1894 lpszcp
++; /* Advance to beginning of host */
1897 /* Parse <host><:port> */
1900 lpszPort
= lpszNetLoc
;
1902 /* special case for res:// URLs: there is no port here, so the host is the
1903 entire string up to the first '/' */
1904 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1906 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1907 lpszHost
, lpszPort
- lpszHost
);
1912 while (lpszcp
< lpszNetLoc
)
1920 /* If the scheme is "file" and the host is just one letter, it's not a host */
1921 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1924 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1929 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1930 lpszHost
, lpszPort
- lpszHost
);
1931 if (lpszPort
!= lpszNetLoc
)
1932 lpUC
->nPort
= atoiW(++lpszPort
);
1933 else switch (lpUC
->nScheme
)
1935 case INTERNET_SCHEME_HTTP
:
1936 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1938 case INTERNET_SCHEME_HTTPS
:
1939 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1941 case INTERNET_SCHEME_FTP
:
1942 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1944 case INTERNET_SCHEME_GOPHER
:
1945 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1956 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1957 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1958 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1961 /* Here lpszcp points to:
1963 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1964 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1966 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1970 /* Only truncate the parameter list if it's already been saved
1971 * in lpUC->lpszExtraInfo.
1973 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1974 len
= lpszParam
- lpszcp
;
1977 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1978 * newlines if necessary.
1980 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1981 if (lpsznewline
!= NULL
)
1982 len
= lpsznewline
- lpszcp
;
1984 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1986 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1987 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1989 WCHAR tmppath
[MAX_PATH
];
1993 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1998 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1999 tmppath
[len
] = '\0';
2008 /* if ends in \. or \.. append a backslash */
2009 if (tmppath
[len
- 1] == '.' &&
2010 (tmppath
[len
- 2] == '\\' ||
2011 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
2013 if (len
< MAX_PATH
- 1)
2015 tmppath
[len
] = '\\';
2016 tmppath
[len
+1] = '\0';
2020 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
2024 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
2029 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
2030 lpUC
->lpszUrlPath
[0] = 0;
2031 lpUC
->dwUrlPathLength
= 0;
2034 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
2035 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
2036 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
2037 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
2038 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
2040 heap_free( lpszUrl_decode
);
2044 /***********************************************************************
2045 * InternetAttemptConnect (WININET.@)
2047 * Attempt to make a connection to the internet
2050 * ERROR_SUCCESS on success
2051 * Error value on failure
2054 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
2057 return ERROR_SUCCESS
;
2061 /***********************************************************************
2062 * convert_url_canonicalization_flags
2064 * Helper for InternetCanonicalizeUrl
2067 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2070 * Flags suitable for UrlCanonicalize
2072 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
2074 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2076 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
2077 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
2078 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
2079 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
2080 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2081 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
2082 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
2087 /***********************************************************************
2088 * InternetCanonicalizeUrlA (WININET.@)
2090 * Escape unsafe characters and spaces
2097 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2098 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2102 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2103 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2105 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2106 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2107 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2108 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2113 /***********************************************************************
2114 * InternetCanonicalizeUrlW (WININET.@)
2116 * Escape unsafe characters and spaces
2123 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2124 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2128 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2129 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2131 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2132 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2133 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2134 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2139 /* #################################################### */
2141 static INTERNET_STATUS_CALLBACK
set_status_callback(
2142 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2144 INTERNET_STATUS_CALLBACK ret
;
2146 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2147 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2149 ret
= lpwh
->lpfnStatusCB
;
2150 lpwh
->lpfnStatusCB
= callback
;
2155 /***********************************************************************
2156 * InternetSetStatusCallbackA (WININET.@)
2158 * Sets up a callback function which is called as progress is made
2159 * during an operation.
2162 * Previous callback or NULL on success
2163 * INTERNET_INVALID_STATUS_CALLBACK on failure
2166 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2167 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2169 INTERNET_STATUS_CALLBACK retVal
;
2170 object_header_t
*lpwh
;
2172 TRACE("%p\n", hInternet
);
2174 if (!(lpwh
= get_handle_object(hInternet
)))
2175 return INTERNET_INVALID_STATUS_CALLBACK
;
2177 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2179 WININET_Release( lpwh
);
2183 /***********************************************************************
2184 * InternetSetStatusCallbackW (WININET.@)
2186 * Sets up a callback function which is called as progress is made
2187 * during an operation.
2190 * Previous callback or NULL on success
2191 * INTERNET_INVALID_STATUS_CALLBACK on failure
2194 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2195 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2197 INTERNET_STATUS_CALLBACK retVal
;
2198 object_header_t
*lpwh
;
2200 TRACE("%p\n", hInternet
);
2202 if (!(lpwh
= get_handle_object(hInternet
)))
2203 return INTERNET_INVALID_STATUS_CALLBACK
;
2205 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2207 WININET_Release( lpwh
);
2211 /***********************************************************************
2212 * InternetSetFilePointer (WININET.@)
2214 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2215 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2217 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2221 /***********************************************************************
2222 * InternetWriteFile (WININET.@)
2224 * Write data to an open internet file
2231 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2232 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2234 object_header_t
*lpwh
;
2237 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2239 lpwh
= get_handle_object( hFile
);
2241 WARN("Invalid handle\n");
2242 SetLastError(ERROR_INVALID_HANDLE
);
2246 if(lpwh
->vtbl
->WriteFile
) {
2247 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2249 WARN("No Writefile method.\n");
2250 res
= ERROR_INVALID_HANDLE
;
2253 WININET_Release( lpwh
);
2255 if(res
!= ERROR_SUCCESS
)
2257 return res
== ERROR_SUCCESS
;
2261 /***********************************************************************
2262 * InternetReadFile (WININET.@)
2264 * Read data from an open internet file
2271 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2272 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2274 object_header_t
*hdr
;
2275 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2277 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2279 hdr
= get_handle_object(hFile
);
2281 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2285 if(hdr
->vtbl
->ReadFile
)
2286 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2288 WININET_Release(hdr
);
2290 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2291 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2293 if(res
!= ERROR_SUCCESS
)
2295 return res
== ERROR_SUCCESS
;
2298 /***********************************************************************
2299 * InternetReadFileExA (WININET.@)
2301 * Read data from an open internet file
2304 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2305 * lpBuffersOut [I/O] Buffer.
2306 * dwFlags [I] Flags. See notes.
2307 * dwContext [I] Context for callbacks.
2314 * The parameter dwFlags include zero or more of the following flags:
2315 *|IRF_ASYNC - Makes the call asynchronous.
2316 *|IRF_SYNC - Makes the call synchronous.
2317 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2318 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2320 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2323 * InternetOpenUrlA(), HttpOpenRequestA()
2325 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2326 DWORD dwFlags
, DWORD_PTR dwContext
)
2328 object_header_t
*hdr
;
2329 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2331 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2333 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2334 SetLastError(ERROR_INVALID_PARAMETER
);
2338 hdr
= get_handle_object(hFile
);
2340 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2344 if(hdr
->vtbl
->ReadFileEx
)
2345 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2346 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2348 WININET_Release(hdr
);
2350 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2351 res
, lpBuffersOut
->dwBufferLength
);
2353 if(res
!= ERROR_SUCCESS
)
2355 return res
== ERROR_SUCCESS
;
2358 /***********************************************************************
2359 * InternetReadFileExW (WININET.@)
2361 * InternetReadFileExA()
2363 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2364 DWORD dwFlags
, DWORD_PTR dwContext
)
2366 object_header_t
*hdr
;
2367 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2369 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2371 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2372 SetLastError(ERROR_INVALID_PARAMETER
);
2376 hdr
= get_handle_object(hFile
);
2378 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2382 if(hdr
->vtbl
->ReadFileEx
)
2383 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2384 dwFlags
, dwContext
);
2386 WININET_Release(hdr
);
2388 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2389 res
, lpBuffer
->dwBufferLength
);
2391 if(res
!= ERROR_SUCCESS
)
2393 return res
== ERROR_SUCCESS
;
2396 static BOOL
get_proxy_autoconfig_url( char *buf
, DWORD buflen
)
2398 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2400 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2404 if (!settings
) return FALSE
;
2406 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2408 CFRelease( settings
);
2411 if (CFStringGetCString( ref
, buf
, buflen
, kCFStringEncodingASCII
))
2413 TRACE( "returning %s\n", debugstr_a(buf
) );
2416 CFRelease( settings
);
2419 FIXME( "no support on this platform\n" );
2424 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2426 /* FIXME: This function currently handles more options than it should. Options requiring
2427 * proper handles should be moved to proper functions */
2429 case INTERNET_OPTION_HTTP_VERSION
:
2430 if (*size
< sizeof(HTTP_VERSION_INFO
))
2431 return ERROR_INSUFFICIENT_BUFFER
;
2434 * Presently hardcoded to 1.1
2436 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2437 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2438 *size
= sizeof(HTTP_VERSION_INFO
);
2440 return ERROR_SUCCESS
;
2442 case INTERNET_OPTION_CONNECTED_STATE
:
2443 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2445 if (*size
< sizeof(ULONG
))
2446 return ERROR_INSUFFICIENT_BUFFER
;
2448 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2449 *size
= sizeof(ULONG
);
2451 return ERROR_SUCCESS
;
2453 case INTERNET_OPTION_PROXY
: {
2457 TRACE("Getting global proxy info\n");
2458 memset(&ai
, 0, sizeof(appinfo_t
));
2459 INTERNET_ConfigureProxy(&ai
);
2461 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2462 APPINFO_Destroy(&ai
.hdr
);
2466 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2467 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2469 if (*size
< sizeof(ULONG
))
2470 return ERROR_INSUFFICIENT_BUFFER
;
2472 *(ULONG
*)buffer
= max_conns
;
2473 *size
= sizeof(ULONG
);
2475 return ERROR_SUCCESS
;
2477 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2478 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2480 if (*size
< sizeof(ULONG
))
2481 return ERROR_INSUFFICIENT_BUFFER
;
2483 *(ULONG
*)buffer
= max_1_0_conns
;
2484 *size
= sizeof(ULONG
);
2486 return ERROR_SUCCESS
;
2488 case INTERNET_OPTION_SECURITY_FLAGS
:
2489 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2490 return ERROR_SUCCESS
;
2492 case INTERNET_OPTION_VERSION
: {
2493 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2495 TRACE("INTERNET_OPTION_VERSION\n");
2497 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2498 return ERROR_INSUFFICIENT_BUFFER
;
2500 memcpy(buffer
, &info
, sizeof(info
));
2501 *size
= sizeof(info
);
2503 return ERROR_SUCCESS
;
2506 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2507 char url
[INTERNET_MAX_URL_LENGTH
+ 1];
2508 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2509 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2510 DWORD res
= ERROR_SUCCESS
, i
;
2515 TRACE("Getting global proxy info\n");
2516 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2519 have_url
= get_proxy_autoconfig_url(url
, sizeof(url
));
2521 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2523 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2525 return ERROR_INSUFFICIENT_BUFFER
;
2528 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2529 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2530 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2532 switch (optionW
->dwOption
) {
2533 case INTERNET_PER_CONN_FLAGS
:
2535 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2537 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2539 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2540 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2543 case INTERNET_PER_CONN_PROXY_SERVER
:
2545 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2547 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2550 case INTERNET_PER_CONN_PROXY_BYPASS
:
2552 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2554 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2557 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2559 optionW
->Value
.pszValue
= NULL
;
2561 optionW
->Value
.pszValue
= heap_strdupAtoW(url
);
2563 optionA
->Value
.pszValue
= heap_strdupA(url
);
2566 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2567 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2570 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2571 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2572 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2573 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2574 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2575 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2579 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2580 res
= ERROR_INVALID_PARAMETER
;
2588 case INTERNET_OPTION_REQUEST_FLAGS
:
2589 case INTERNET_OPTION_USER_AGENT
:
2591 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2592 case INTERNET_OPTION_POLICY
:
2593 return ERROR_INVALID_PARAMETER
;
2594 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2595 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2597 if (*size
< sizeof(ULONG
))
2598 return ERROR_INSUFFICIENT_BUFFER
;
2600 *(ULONG
*)buffer
= connect_timeout
;
2601 *size
= sizeof(ULONG
);
2603 return ERROR_SUCCESS
;
2606 FIXME("Stub for %d\n", option
);
2607 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2610 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2613 case INTERNET_OPTION_CONTEXT_VALUE
:
2615 return ERROR_INVALID_PARAMETER
;
2617 if (*size
< sizeof(DWORD_PTR
)) {
2618 *size
= sizeof(DWORD_PTR
);
2619 return ERROR_INSUFFICIENT_BUFFER
;
2622 return ERROR_INVALID_PARAMETER
;
2624 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2625 *size
= sizeof(DWORD_PTR
);
2626 return ERROR_SUCCESS
;
2628 case INTERNET_OPTION_REQUEST_FLAGS
:
2629 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2630 *size
= sizeof(DWORD
);
2631 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2633 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2634 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2635 WARN("Called on global option %u\n", option
);
2636 return ERROR_INTERNET_INVALID_OPERATION
;
2639 /* FIXME: we shouldn't call it here */
2640 return query_global_option(option
, buffer
, size
, unicode
);
2643 /***********************************************************************
2644 * InternetQueryOptionW (WININET.@)
2646 * Queries an options on the specified handle
2653 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2654 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2656 object_header_t
*hdr
;
2657 DWORD res
= ERROR_INVALID_HANDLE
;
2659 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2662 hdr
= get_handle_object(hInternet
);
2664 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2665 WININET_Release(hdr
);
2668 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2671 if(res
!= ERROR_SUCCESS
)
2673 return res
== ERROR_SUCCESS
;
2676 /***********************************************************************
2677 * InternetQueryOptionA (WININET.@)
2679 * Queries an options on the specified handle
2686 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2687 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2689 object_header_t
*hdr
;
2690 DWORD res
= ERROR_INVALID_HANDLE
;
2692 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2695 hdr
= get_handle_object(hInternet
);
2697 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2698 WININET_Release(hdr
);
2701 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2704 if(res
!= ERROR_SUCCESS
)
2706 return res
== ERROR_SUCCESS
;
2709 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2712 case INTERNET_OPTION_CALLBACK
:
2713 WARN("Not settable option %u\n", option
);
2714 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2715 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2716 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2717 WARN("Called on global option %u\n", option
);
2718 return ERROR_INTERNET_INVALID_OPERATION
;
2721 return ERROR_INTERNET_INVALID_OPTION
;
2724 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2727 case INTERNET_OPTION_CALLBACK
:
2728 WARN("Not global option %u\n", option
);
2729 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2731 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2732 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2734 if(size
!= sizeof(max_conns
))
2735 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2737 return ERROR_BAD_ARGUMENTS
;
2739 max_conns
= *(ULONG
*)buf
;
2740 return ERROR_SUCCESS
;
2742 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2743 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2745 if(size
!= sizeof(max_1_0_conns
))
2746 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2748 return ERROR_BAD_ARGUMENTS
;
2750 max_1_0_conns
= *(ULONG
*)buf
;
2751 return ERROR_SUCCESS
;
2753 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2754 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2756 if(size
!= sizeof(connect_timeout
))
2757 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2759 return ERROR_BAD_ARGUMENTS
;
2761 connect_timeout
= *(ULONG
*)buf
;
2762 return ERROR_SUCCESS
;
2764 case INTERNET_OPTION_SETTINGS_CHANGED
:
2765 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2766 collect_connections(COLLECT_CONNECTIONS
);
2767 return ERROR_SUCCESS
;
2770 return ERROR_INTERNET_INVALID_OPTION
;
2773 /***********************************************************************
2774 * InternetSetOptionW (WININET.@)
2776 * Sets an options on the specified handle
2783 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2784 LPVOID lpBuffer
, DWORD dwBufferLength
)
2786 object_header_t
*lpwhh
;
2790 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2792 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2794 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2796 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2798 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2800 WININET_Release(lpwhh
);
2802 if(res
!= ERROR_SUCCESS
)
2805 return res
== ERROR_SUCCESS
;
2810 case INTERNET_OPTION_HTTP_VERSION
:
2812 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2813 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2816 case INTERNET_OPTION_ERROR_MASK
:
2819 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2821 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2822 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2823 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2824 SetLastError(ERROR_INVALID_PARAMETER
);
2826 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2827 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2830 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2831 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2834 case INTERNET_OPTION_PROXY
:
2836 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2838 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2840 SetLastError(ERROR_INVALID_PARAMETER
);
2845 EnterCriticalSection( &WININET_cs
);
2846 free_global_proxy();
2847 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2850 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2852 global_proxy
->proxyEnabled
= 1;
2853 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2854 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2858 global_proxy
->proxyEnabled
= 0;
2859 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2862 LeaveCriticalSection( &WININET_cs
);
2866 /* In general, each type of object should handle
2867 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2868 * get silently dropped.
2870 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2871 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2876 case INTERNET_OPTION_CODEPAGE
:
2878 ULONG codepage
= *(ULONG
*)lpBuffer
;
2879 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2882 case INTERNET_OPTION_REQUEST_PRIORITY
:
2884 ULONG priority
= *(ULONG
*)lpBuffer
;
2885 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2888 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2890 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2891 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2894 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2896 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2897 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2900 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2901 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2903 case INTERNET_OPTION_END_BROWSER_SESSION
:
2904 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2906 case INTERNET_OPTION_CONNECTED_STATE
:
2907 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2909 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2910 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2912 case INTERNET_OPTION_SEND_TIMEOUT
:
2913 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2914 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2916 ULONG timeout
= *(ULONG
*)lpBuffer
;
2917 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2920 case INTERNET_OPTION_CONNECT_RETRIES
:
2922 ULONG retries
= *(ULONG
*)lpBuffer
;
2923 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2926 case INTERNET_OPTION_CONTEXT_VALUE
:
2930 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2933 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2935 SetLastError(ERROR_INVALID_PARAMETER
);
2939 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2942 case INTERNET_OPTION_SECURITY_FLAGS
:
2943 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2945 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2946 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2948 case INTERNET_OPTION_HTTP_DECODING
:
2949 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2950 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2953 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2954 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2955 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2958 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2959 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2960 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2963 case INTERNET_OPTION_CODEPAGE_PATH
:
2964 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2965 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2968 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2969 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2970 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2973 case INTERNET_OPTION_IDN
:
2974 FIXME("INTERNET_OPTION_IDN; STUB\n");
2975 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2978 case INTERNET_OPTION_POLICY
:
2979 SetLastError(ERROR_INVALID_PARAMETER
);
2982 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2983 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2988 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2990 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2991 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2993 switch (option
->dwOption
) {
2994 case INTERNET_PER_CONN_PROXY_SERVER
:
2995 heap_free(pi
.proxy
);
2996 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2999 case INTERNET_PER_CONN_FLAGS
:
3000 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
3001 pi
.proxyEnabled
= 1;
3004 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
3005 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
3006 pi
.proxyEnabled
= 0;
3010 case INTERNET_PER_CONN_PROXY_BYPASS
:
3011 heap_free(pi
.proxyBypass
);
3012 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
3015 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3016 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3017 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3018 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3019 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3020 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3021 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
3025 FIXME("Unknown dwOption %d\n", option
->dwOption
);
3026 SetLastError(ERROR_INVALID_PARAMETER
);
3031 if ((res
= INTERNET_SaveProxySettings(&pi
)))
3036 ret
= (res
== ERROR_SUCCESS
);
3040 FIXME("Option %d STUB\n",dwOption
);
3041 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3047 WININET_Release( lpwhh
);
3053 /***********************************************************************
3054 * InternetSetOptionA (WININET.@)
3056 * Sets an options on the specified handle.
3063 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3064 LPVOID lpBuffer
, DWORD dwBufferLength
)
3072 case INTERNET_OPTION_PROXY
:
3074 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3075 LPINTERNET_PROXY_INFOW piw
;
3076 DWORD proxlen
, prbylen
;
3079 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3080 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3081 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3082 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3083 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3084 piw
->dwAccessType
= pi
->dwAccessType
;
3085 prox
= (LPWSTR
) &piw
[1];
3086 prby
= &prox
[proxlen
+1];
3087 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3088 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3089 piw
->lpszProxy
= prox
;
3090 piw
->lpszProxyBypass
= prby
;
3093 case INTERNET_OPTION_USER_AGENT
:
3094 case INTERNET_OPTION_USERNAME
:
3095 case INTERNET_OPTION_PASSWORD
:
3096 case INTERNET_OPTION_PROXY_USERNAME
:
3097 case INTERNET_OPTION_PROXY_PASSWORD
:
3098 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3099 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3100 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3102 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3104 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3105 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3106 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3107 wbuffer
= heap_alloc(wlen
);
3110 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3111 if (listA
->pszConnection
)
3113 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3114 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3115 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3118 listW
->pszConnection
= NULL
;
3119 listW
->dwOptionCount
= listA
->dwOptionCount
;
3120 listW
->dwOptionError
= listA
->dwOptionError
;
3121 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3123 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3124 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3125 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3127 optW
->dwOption
= optA
->dwOption
;
3129 switch (optA
->dwOption
) {
3130 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3131 case INTERNET_PER_CONN_PROXY_BYPASS
:
3132 case INTERNET_PER_CONN_PROXY_SERVER
:
3133 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3134 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3135 if (optA
->Value
.pszValue
)
3137 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3138 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3139 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3142 optW
->Value
.pszValue
= NULL
;
3144 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3145 case INTERNET_PER_CONN_FLAGS
:
3146 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3147 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3149 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3150 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3153 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3154 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3162 wlen
= dwBufferLength
;
3165 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3167 if( lpBuffer
!= wbuffer
)
3169 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3171 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3173 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3174 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3175 switch (opt
->dwOption
) {
3176 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3177 case INTERNET_PER_CONN_PROXY_BYPASS
:
3178 case INTERNET_PER_CONN_PROXY_SERVER
:
3179 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3180 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3181 heap_free( opt
->Value
.pszValue
);
3187 heap_free( list
->pOptions
);
3189 heap_free( wbuffer
);
3196 /***********************************************************************
3197 * InternetSetOptionExA (WININET.@)
3199 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3200 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3202 FIXME("Flags %08x ignored\n", dwFlags
);
3203 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3206 /***********************************************************************
3207 * InternetSetOptionExW (WININET.@)
3209 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3210 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3212 FIXME("Flags %08x ignored\n", dwFlags
);
3213 if( dwFlags
& ~ISO_VALID_FLAGS
)
3215 SetLastError( ERROR_INVALID_PARAMETER
);
3218 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3221 static const WCHAR WININET_wkday
[7][4] =
3222 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3223 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3224 static const WCHAR WININET_month
[12][4] =
3225 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3226 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3227 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3229 /***********************************************************************
3230 * InternetTimeFromSystemTimeA (WININET.@)
3232 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3235 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3237 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3239 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3241 SetLastError(ERROR_INVALID_PARAMETER
);
3245 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3247 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3251 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3252 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3257 /***********************************************************************
3258 * InternetTimeFromSystemTimeW (WININET.@)
3260 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3262 static const WCHAR date
[] =
3263 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3264 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3266 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3268 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3270 SetLastError(ERROR_INVALID_PARAMETER
);
3274 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3276 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3280 sprintfW( string
, date
,
3281 WININET_wkday
[time
->wDayOfWeek
],
3283 WININET_month
[time
->wMonth
- 1],
3292 /***********************************************************************
3293 * InternetTimeToSystemTimeA (WININET.@)
3295 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3300 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3302 stringW
= heap_strdupAtoW(string
);
3305 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3306 heap_free( stringW
);
3311 /***********************************************************************
3312 * InternetTimeToSystemTimeW (WININET.@)
3314 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3317 const WCHAR
*s
= string
;
3320 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3322 if (!string
|| !time
) return FALSE
;
3324 /* Windows does this too */
3325 GetSystemTime( time
);
3327 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3328 * a SYSTEMTIME structure.
3331 while (*s
&& !isalphaW( *s
)) s
++;
3332 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3333 time
->wDayOfWeek
= 7;
3335 for (i
= 0; i
< 7; i
++)
3337 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3338 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3339 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3341 time
->wDayOfWeek
= i
;
3346 if (time
->wDayOfWeek
> 6) return TRUE
;
3347 while (*s
&& !isdigitW( *s
)) s
++;
3348 time
->wDay
= strtolW( s
, &end
, 10 );
3351 while (*s
&& !isalphaW( *s
)) s
++;
3352 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3355 for (i
= 0; i
< 12; i
++)
3357 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3358 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3359 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3361 time
->wMonth
= i
+ 1;
3365 if (time
->wMonth
== 0) return TRUE
;
3367 while (*s
&& !isdigitW( *s
)) s
++;
3368 if (*s
== '\0') return TRUE
;
3369 time
->wYear
= strtolW( s
, &end
, 10 );
3372 while (*s
&& !isdigitW( *s
)) s
++;
3373 if (*s
== '\0') return TRUE
;
3374 time
->wHour
= strtolW( s
, &end
, 10 );
3377 while (*s
&& !isdigitW( *s
)) s
++;
3378 if (*s
== '\0') return TRUE
;
3379 time
->wMinute
= strtolW( s
, &end
, 10 );
3382 while (*s
&& !isdigitW( *s
)) s
++;
3383 if (*s
== '\0') return TRUE
;
3384 time
->wSecond
= strtolW( s
, &end
, 10 );
3387 time
->wMilliseconds
= 0;
3391 /***********************************************************************
3392 * InternetCheckConnectionW (WININET.@)
3394 * Pings a requested host to check internet connection
3397 * TRUE on success and FALSE on failure. If a failure then
3398 * ERROR_NOT_CONNECTED is placed into GetLastError
3401 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3404 * this is a kludge which runs the resident ping program and reads the output.
3406 * Anyone have a better idea?
3410 static const CHAR ping
[] = "ping -c 1 ";
3411 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3412 CHAR
*command
= NULL
;
3413 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3421 * Crack or set the Address
3423 if (lpszUrl
== NULL
)
3426 * According to the doc we are supposed to use the ip for the next
3427 * server in the WnInet internal server database. I have
3428 * no idea what that is or how to get it.
3430 * So someone needs to implement this.
3432 FIXME("Unimplemented with URL of NULL\n");
3437 URL_COMPONENTSW components
;
3439 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3440 components
.lpszHostName
= (LPWSTR
)hostW
;
3441 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3443 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3446 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3447 port
= components
.nPort
;
3448 TRACE("port: %d\n", port
);
3451 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3453 struct sockaddr_storage saddr
;
3454 socklen_t sa_len
= sizeof(saddr
);
3457 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
, NULL
))
3460 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3463 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3471 * Build our ping command
3473 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3474 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3475 strcpy(command
,ping
);
3476 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3477 strcat(command
,redirect
);
3479 TRACE("Ping command is : %s\n",command
);
3481 status
= system(command
);
3483 TRACE("Ping returned a code of %i\n",status
);
3485 /* Ping return code of 0 indicates success */
3491 heap_free( command
);
3493 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3499 /***********************************************************************
3500 * InternetCheckConnectionA (WININET.@)
3502 * Pings a requested host to check internet connection
3505 * TRUE on success and FALSE on failure. If a failure then
3506 * ERROR_NOT_CONNECTED is placed into GetLastError
3509 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3515 url
= heap_strdupAtoW(lpszUrl
);
3520 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3527 /**********************************************************
3528 * INTERNET_InternetOpenUrlW (internal)
3533 * handle of connection or NULL on failure
3535 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3536 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3538 URL_COMPONENTSW urlComponents
;
3539 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3540 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3541 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3542 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3543 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3545 HINTERNET client
= NULL
, client1
= NULL
;
3548 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3549 dwHeadersLength
, dwFlags
, dwContext
);
3551 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3552 urlComponents
.lpszScheme
= protocol
;
3553 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3554 urlComponents
.lpszHostName
= hostName
;
3555 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3556 urlComponents
.lpszUserName
= userName
;
3557 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3558 urlComponents
.lpszPassword
= password
;
3559 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3560 urlComponents
.lpszUrlPath
= path
;
3561 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3562 urlComponents
.lpszExtraInfo
= extra
;
3563 urlComponents
.dwExtraInfoLength
= 1024;
3564 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3566 switch(urlComponents
.nScheme
) {
3567 case INTERNET_SCHEME_FTP
:
3568 if(urlComponents
.nPort
== 0)
3569 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3570 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3571 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3574 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3575 if(client1
== NULL
) {
3576 InternetCloseHandle(client
);
3581 case INTERNET_SCHEME_HTTP
:
3582 case INTERNET_SCHEME_HTTPS
: {
3583 static const WCHAR szStars
[] = { '*','/','*', 0 };
3584 LPCWSTR accept
[2] = { szStars
, NULL
};
3585 if(urlComponents
.nPort
== 0) {
3586 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3587 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3589 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3591 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3593 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3594 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3595 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3596 if(res
!= ERROR_SUCCESS
) {
3597 INTERNET_SetLastError(res
);
3601 if (urlComponents
.dwExtraInfoLength
) {
3603 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3605 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3607 InternetCloseHandle(client
);
3610 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3611 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3612 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3613 heap_free(path_extra
);
3616 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3618 if(client1
== NULL
) {
3619 InternetCloseHandle(client
);
3622 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3623 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3624 GetLastError() != ERROR_IO_PENDING
) {
3625 InternetCloseHandle(client1
);
3630 case INTERNET_SCHEME_GOPHER
:
3631 /* gopher doesn't seem to be implemented in wine, but it's supposed
3632 * to be supported by InternetOpenUrlA. */
3634 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3638 TRACE(" %p <--\n", client1
);
3643 /**********************************************************
3644 * InternetOpenUrlW (WININET.@)
3649 * handle of connection or NULL on failure
3660 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3662 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3664 TRACE("%p\n", task
->hdr
.hdr
);
3666 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3667 task
->headers_len
, task
->flags
, task
->context
);
3668 heap_free(task
->url
);
3669 heap_free(task
->headers
);
3672 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3673 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3675 HINTERNET ret
= NULL
;
3676 appinfo_t
*hIC
= NULL
;
3678 if (TRACE_ON(wininet
)) {
3679 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3680 dwHeadersLength
, dwFlags
, dwContext
);
3682 dump_INTERNET_FLAGS(dwFlags
);
3687 SetLastError(ERROR_INVALID_PARAMETER
);
3691 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3692 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3693 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3697 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3698 open_url_task_t
*task
;
3700 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3701 task
->url
= heap_strdupW(lpszUrl
);
3702 task
->headers
= heap_strdupW(lpszHeaders
);
3703 task
->headers_len
= dwHeadersLength
;
3704 task
->flags
= dwFlags
;
3705 task
->context
= dwContext
;
3707 INTERNET_AsyncCall(&task
->hdr
);
3708 SetLastError(ERROR_IO_PENDING
);
3710 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3715 WININET_Release( &hIC
->hdr
);
3716 TRACE(" %p <--\n", ret
);
3721 /**********************************************************
3722 * InternetOpenUrlA (WININET.@)
3727 * handle of connection or NULL on failure
3729 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3730 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3732 HINTERNET rc
= NULL
;
3733 DWORD lenHeaders
= 0;
3734 LPWSTR szUrl
= NULL
;
3735 LPWSTR szHeaders
= NULL
;
3740 szUrl
= heap_strdupAtoW(lpszUrl
);
3746 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3747 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3752 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3755 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3756 lenHeaders
, dwFlags
, dwContext
);
3759 heap_free(szHeaders
);
3764 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3766 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3770 lpwite
->dwError
= 0;
3771 lpwite
->response
[0] = '\0';
3774 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3783 /***********************************************************************
3784 * INTERNET_SetLastError (internal)
3786 * Set last thread specific error
3791 void INTERNET_SetLastError(DWORD dwError
)
3793 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3796 lpwite
= INTERNET_AllocThreadError();
3798 SetLastError(dwError
);
3800 lpwite
->dwError
= dwError
;
3804 /***********************************************************************
3805 * INTERNET_GetLastError (internal)
3807 * Get last thread specific error
3812 DWORD
INTERNET_GetLastError(void)
3814 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3815 if (!lpwite
) return 0;
3816 /* TlsGetValue clears last error, so set it again here */
3817 SetLastError(lpwite
->dwError
);
3818 return lpwite
->dwError
;
3822 /***********************************************************************
3823 * INTERNET_WorkerThreadFunc (internal)
3825 * Worker thread execution function
3830 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3832 task_header_t
*task
= lpvParam
;
3837 WININET_Release(task
->hdr
);
3840 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3842 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3843 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3848 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3850 task_header_t
*task
;
3852 task
= heap_alloc(size
);
3856 task
->hdr
= WININET_AddRef(hdr
);
3861 /***********************************************************************
3862 * INTERNET_AsyncCall (internal)
3864 * Retrieves work request from queue
3869 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3875 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3879 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3881 return ERROR_SUCCESS
;
3885 /***********************************************************************
3886 * INTERNET_GetResponseBuffer (internal)
3891 LPSTR
INTERNET_GetResponseBuffer(void)
3893 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3895 lpwite
= INTERNET_AllocThreadError();
3897 return lpwite
->response
;
3900 /**********************************************************
3901 * InternetQueryDataAvailable (WININET.@)
3903 * Determines how much data is available to be read.
3906 * TRUE on success, FALSE if an error occurred. If
3907 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3908 * no data is presently available, FALSE is returned with
3909 * the last error ERROR_IO_PENDING; a callback with status
3910 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3911 * data is available.
3913 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3914 LPDWORD lpdwNumberOfBytesAvailable
,
3915 DWORD dwFlags
, DWORD_PTR dwContext
)
3917 object_header_t
*hdr
;
3920 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3922 hdr
= get_handle_object( hFile
);
3924 SetLastError(ERROR_INVALID_HANDLE
);
3928 if(hdr
->vtbl
->QueryDataAvailable
) {
3929 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3931 WARN("wrong handle\n");
3932 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3935 WININET_Release(hdr
);
3937 if(res
!= ERROR_SUCCESS
)
3939 return res
== ERROR_SUCCESS
;
3942 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3944 req_file_t
*req_file
;
3946 req_file
= heap_alloc_zero(sizeof(*req_file
));
3948 return ERROR_NOT_ENOUGH_MEMORY
;
3952 req_file
->file_name
= heap_strdupW(file_name
);
3953 if(!req_file
->file_name
) {
3954 heap_free(req_file
);
3955 return ERROR_NOT_ENOUGH_MEMORY
;
3958 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3959 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3960 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
3961 req_file_release(req_file
);
3962 return GetLastError();
3966 return ERROR_SUCCESS
;
3969 void req_file_release(req_file_t
*req_file
)
3971 if(InterlockedDecrement(&req_file
->ref
))
3974 if(!req_file
->is_committed
)
3975 DeleteFileW(req_file
->file_name
);
3976 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
3977 CloseHandle(req_file
->file_handle
);
3978 heap_free(req_file
->file_name
);
3979 heap_free(req_file
);
3982 /***********************************************************************
3983 * InternetLockRequestFile (WININET.@)
3985 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
3987 req_file_t
*req_file
= NULL
;
3988 object_header_t
*hdr
;
3991 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
3993 hdr
= get_handle_object(hInternet
);
3995 SetLastError(ERROR_INVALID_HANDLE
);
3999 if(hdr
->vtbl
->LockRequestFile
) {
4000 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
4002 WARN("wrong handle\n");
4003 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4006 WININET_Release(hdr
);
4008 *lphLockReqHandle
= req_file
;
4009 if(res
!= ERROR_SUCCESS
)
4011 return res
== ERROR_SUCCESS
;
4014 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
4016 TRACE("(%p)\n", hLockHandle
);
4018 req_file_release(hLockHandle
);
4023 /***********************************************************************
4024 * InternetAutodial (WININET.@)
4026 * On windows this function is supposed to dial the default internet
4027 * connection. We don't want to have Wine dial out to the internet so
4028 * we return TRUE by default. It might be nice to check if we are connected.
4035 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
4039 /* Tell that we are connected to the internet. */
4043 /***********************************************************************
4044 * InternetAutodialHangup (WININET.@)
4046 * Hangs up a connection made with InternetAutodial
4055 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
4059 /* we didn't dial, we don't disconnect */
4063 /***********************************************************************
4064 * InternetCombineUrlA (WININET.@)
4066 * Combine a base URL with a relative URL
4074 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
4075 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4080 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4082 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4083 dwFlags
^= ICU_NO_ENCODE
;
4084 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4089 /***********************************************************************
4090 * InternetCombineUrlW (WININET.@)
4092 * Combine a base URL with a relative URL
4100 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4101 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4106 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4108 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4109 dwFlags
^= ICU_NO_ENCODE
;
4110 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4115 /* max port num is 65535 => 5 digits */
4116 #define MAX_WORD_DIGITS 5
4118 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4119 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4120 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4121 (url)->dw##component##Length : strlen((url)->lpsz##component))
4123 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4125 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4126 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4128 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4129 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4131 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4132 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4134 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4135 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4138 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4144 /* opaque urls do not fit into the standard url hierarchy and don't have
4145 * two following slashes */
4146 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4148 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4149 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4150 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4151 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4152 (nScheme
!= INTERNET_SCHEME_FILE
);
4155 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4158 if (scheme
< INTERNET_SCHEME_FIRST
)
4160 index
= scheme
- INTERNET_SCHEME_FIRST
;
4161 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4163 return (LPCWSTR
)url_schemes
[index
];
4166 /* we can calculate using ansi strings because we're just
4167 * calculating string length, not size
4169 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4170 LPDWORD lpdwUrlLength
)
4172 INTERNET_SCHEME nScheme
;
4176 if (lpUrlComponents
->lpszScheme
)
4178 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4179 *lpdwUrlLength
+= dwLen
;
4180 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4186 nScheme
= lpUrlComponents
->nScheme
;
4188 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4189 nScheme
= INTERNET_SCHEME_HTTP
;
4190 scheme
= INTERNET_GetSchemeString(nScheme
);
4191 *lpdwUrlLength
+= strlenW(scheme
);
4194 (*lpdwUrlLength
)++; /* ':' */
4195 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4196 *lpdwUrlLength
+= strlen("//");
4198 if (lpUrlComponents
->lpszUserName
)
4200 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4201 *lpdwUrlLength
+= strlen("@");
4205 if (lpUrlComponents
->lpszPassword
)
4207 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4212 if (lpUrlComponents
->lpszPassword
)
4214 *lpdwUrlLength
+= strlen(":");
4215 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4218 if (lpUrlComponents
->lpszHostName
)
4220 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4222 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4224 char szPort
[MAX_WORD_DIGITS
+1];
4226 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4227 *lpdwUrlLength
+= strlen(szPort
);
4228 *lpdwUrlLength
+= strlen(":");
4231 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4232 (*lpdwUrlLength
)++; /* '/' */
4235 if (lpUrlComponents
->lpszUrlPath
)
4236 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4238 if (lpUrlComponents
->lpszExtraInfo
)
4239 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4244 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4248 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4250 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4251 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4252 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4253 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4254 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4255 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4256 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4257 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4258 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4260 if (lpUrlComponents
->lpszScheme
)
4262 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4263 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4264 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4265 -1, urlCompW
->lpszScheme
, len
);
4268 if (lpUrlComponents
->lpszHostName
)
4270 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4271 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4272 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4273 -1, urlCompW
->lpszHostName
, len
);
4276 if (lpUrlComponents
->lpszUserName
)
4278 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4279 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4280 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4281 -1, urlCompW
->lpszUserName
, len
);
4284 if (lpUrlComponents
->lpszPassword
)
4286 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4287 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4288 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4289 -1, urlCompW
->lpszPassword
, len
);
4292 if (lpUrlComponents
->lpszUrlPath
)
4294 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4295 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4296 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4297 -1, urlCompW
->lpszUrlPath
, len
);
4300 if (lpUrlComponents
->lpszExtraInfo
)
4302 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4303 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4304 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4305 -1, urlCompW
->lpszExtraInfo
, len
);
4309 /***********************************************************************
4310 * InternetCreateUrlA (WININET.@)
4312 * See InternetCreateUrlW.
4314 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4315 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4319 URL_COMPONENTSW urlCompW
;
4321 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4323 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4325 SetLastError(ERROR_INVALID_PARAMETER
);
4329 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4332 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4334 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4336 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4337 *lpdwUrlLength
/= sizeof(WCHAR
);
4339 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4340 * minus one, so add one to leave room for NULL terminator
4343 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4345 heap_free(urlCompW
.lpszScheme
);
4346 heap_free(urlCompW
.lpszHostName
);
4347 heap_free(urlCompW
.lpszUserName
);
4348 heap_free(urlCompW
.lpszPassword
);
4349 heap_free(urlCompW
.lpszUrlPath
);
4350 heap_free(urlCompW
.lpszExtraInfo
);
4355 /***********************************************************************
4356 * InternetCreateUrlW (WININET.@)
4358 * Creates a URL from its component parts.
4361 * lpUrlComponents [I] URL Components.
4362 * dwFlags [I] Flags. See notes.
4363 * lpszUrl [I] Buffer in which to store the created URL.
4364 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4365 * lpszUrl in characters. On output, the number of bytes
4366 * required to store the URL including terminator.
4370 * The dwFlags parameter can be zero or more of the following:
4371 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4378 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4379 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4382 INTERNET_SCHEME nScheme
;
4384 static const WCHAR slashSlashW
[] = {'/','/'};
4385 static const WCHAR fmtW
[] = {'%','u',0};
4387 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4389 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4391 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4395 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4398 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4400 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4401 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4405 *lpdwUrlLength
= dwLen
;
4410 if (lpUrlComponents
->lpszScheme
)
4412 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4413 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4416 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4421 nScheme
= lpUrlComponents
->nScheme
;
4423 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4424 nScheme
= INTERNET_SCHEME_HTTP
;
4426 scheme
= INTERNET_GetSchemeString(nScheme
);
4427 dwLen
= strlenW(scheme
);
4428 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4432 /* all schemes are followed by at least a colon */
4436 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4438 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4439 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4442 if (lpUrlComponents
->lpszUserName
)
4444 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4445 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4448 if (lpUrlComponents
->lpszPassword
)
4453 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4454 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4462 if (lpUrlComponents
->lpszHostName
)
4464 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4465 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4468 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4470 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4472 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4475 dwLen
= strlenW(szPort
);
4476 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4480 /* add slash between hostname and path if necessary */
4481 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4488 if (lpUrlComponents
->lpszUrlPath
)
4490 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4491 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4495 if (lpUrlComponents
->lpszExtraInfo
)
4497 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4498 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4507 /***********************************************************************
4508 * InternetConfirmZoneCrossingA (WININET.@)
4511 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4513 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4514 return ERROR_SUCCESS
;
4517 /***********************************************************************
4518 * InternetConfirmZoneCrossingW (WININET.@)
4521 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4523 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4524 return ERROR_SUCCESS
;
4527 static DWORD zone_preference
= 3;
4529 /***********************************************************************
4530 * PrivacySetZonePreferenceW (WININET.@)
4532 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4534 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4536 zone_preference
= template;
4540 /***********************************************************************
4541 * PrivacyGetZonePreferenceW (WININET.@)
4543 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4544 LPWSTR preference
, LPDWORD length
)
4546 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4548 if (template) *template = zone_preference
;
4552 /***********************************************************************
4553 * InternetGetSecurityInfoByURLA (WININET.@)
4555 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4560 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4562 url
= heap_strdupAtoW(lpszURL
);
4566 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4571 /***********************************************************************
4572 * InternetGetSecurityInfoByURLW (WININET.@)
4574 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4576 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4577 URL_COMPONENTSW url
= {sizeof(url
)};
4581 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4583 url
.lpszHostName
= hostname
;
4584 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4586 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4587 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4588 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4592 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4594 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4598 if(server
->cert_chain
) {
4599 const CERT_CHAIN_CONTEXT
*chain_dup
;
4601 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4603 *ppCertChain
= chain_dup
;
4604 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4609 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4613 server_release(server
);
4617 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4618 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4620 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4621 lpdwConnection
, dwReserved
);
4622 return ERROR_SUCCESS
;
4625 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4626 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4628 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4629 lpdwConnection
, dwReserved
);
4630 return ERROR_SUCCESS
;
4633 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4635 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4639 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4641 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4645 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4647 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4648 return ERROR_SUCCESS
;
4651 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4654 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4655 debugstr_w(pwszTarget
), pbHexHash
);
4659 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4661 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4665 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4667 FIXME("(%p, %08lx) stub\n", a
, b
);
4671 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4673 FIXME("%p: stub\n", parent
);