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
)) && ret
!= ERROR_FILE_NOT_FOUND
)
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(wpi
.proxy
), debugstr_w(wpi
.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, %u, %s, %p, %u, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1321 nServerPort
, debugstr_w(lpszUserName
), lpszPassword
, dwService
, dwFlags
, dwContext
);
1323 if (!lpszServerName
)
1325 SetLastError(ERROR_INVALID_PARAMETER
);
1329 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1330 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1332 res
= ERROR_INVALID_HANDLE
;
1338 case INTERNET_SERVICE_FTP
:
1339 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1340 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1342 res
= INTERNET_GetLastError();
1345 case INTERNET_SERVICE_HTTP
:
1346 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1347 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1350 case INTERNET_SERVICE_GOPHER
:
1356 WININET_Release( &hIC
->hdr
);
1358 TRACE("returning %p\n", rc
);
1364 /***********************************************************************
1365 * InternetConnectA (WININET.@)
1367 * Open a ftp, gopher or http session
1370 * HINTERNET a session handle on success
1374 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1375 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1376 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1377 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1379 HINTERNET rc
= NULL
;
1380 LPWSTR szServerName
;
1384 szServerName
= heap_strdupAtoW(lpszServerName
);
1385 szUserName
= heap_strdupAtoW(lpszUserName
);
1386 szPassword
= heap_strdupAtoW(lpszPassword
);
1388 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1389 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1391 heap_free(szServerName
);
1392 heap_free(szUserName
);
1393 heap_free(szPassword
);
1398 /***********************************************************************
1399 * InternetFindNextFileA (WININET.@)
1401 * Continues a file search from a previous call to FindFirstFile
1408 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1411 WIN32_FIND_DATAW fd
;
1413 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1415 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1419 /***********************************************************************
1420 * InternetFindNextFileW (WININET.@)
1422 * Continues a file search from a previous call to FindFirstFile
1429 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1431 object_header_t
*hdr
;
1436 hdr
= get_handle_object(hFind
);
1438 WARN("Invalid handle\n");
1439 SetLastError(ERROR_INVALID_HANDLE
);
1443 if(hdr
->vtbl
->FindNextFileW
) {
1444 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1446 WARN("Handle doesn't support NextFile\n");
1447 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1450 WININET_Release(hdr
);
1452 if(res
!= ERROR_SUCCESS
)
1454 return res
== ERROR_SUCCESS
;
1457 /***********************************************************************
1458 * InternetCloseHandle (WININET.@)
1460 * Generic close handle function
1467 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1469 object_header_t
*obj
;
1471 TRACE("%p\n", hInternet
);
1473 obj
= get_handle_object( hInternet
);
1475 SetLastError(ERROR_INVALID_HANDLE
);
1479 invalidate_handle(obj
);
1480 WININET_Release(obj
);
1486 /***********************************************************************
1487 * ConvertUrlComponentValue (Internal)
1489 * Helper function for InternetCrackUrlA
1492 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1493 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1494 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1496 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1497 if (*dwComponentLen
!= 0)
1499 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1500 if (*lppszComponent
== NULL
)
1504 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1505 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1508 *lppszComponent
= NULL
;
1510 *dwComponentLen
= nASCIILength
;
1514 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1515 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1516 (*lppszComponent
)[ncpylen
]=0;
1517 *dwComponentLen
= ncpylen
;
1523 /***********************************************************************
1524 * InternetCrackUrlA (WININET.@)
1526 * See InternetCrackUrlW.
1528 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1529 LPURL_COMPONENTSA lpUrlComponents
)
1532 URL_COMPONENTSW UCW
;
1534 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1535 *scheme
= NULL
, *extra
= NULL
;
1537 TRACE("(%s %u %x %p)\n",
1538 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1539 dwUrlLength
, dwFlags
, lpUrlComponents
);
1541 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1542 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1544 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1550 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1552 /* if dwUrlLength=-1 then nLength includes null but length to
1553 InternetCrackUrlW should not include it */
1554 if (dwUrlLength
== -1) nLength
--;
1556 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1557 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1558 lpwszUrl
[nLength
] = '\0';
1560 memset(&UCW
,0,sizeof(UCW
));
1561 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1562 if (lpUrlComponents
->dwHostNameLength
)
1564 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1565 if (lpUrlComponents
->lpszHostName
)
1567 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1568 UCW
.lpszHostName
= hostname
;
1571 if (lpUrlComponents
->dwUserNameLength
)
1573 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1574 if (lpUrlComponents
->lpszUserName
)
1576 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1577 UCW
.lpszUserName
= username
;
1580 if (lpUrlComponents
->dwPasswordLength
)
1582 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1583 if (lpUrlComponents
->lpszPassword
)
1585 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1586 UCW
.lpszPassword
= password
;
1589 if (lpUrlComponents
->dwUrlPathLength
)
1591 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1592 if (lpUrlComponents
->lpszUrlPath
)
1594 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1595 UCW
.lpszUrlPath
= path
;
1598 if (lpUrlComponents
->dwSchemeLength
)
1600 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1601 if (lpUrlComponents
->lpszScheme
)
1603 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1604 UCW
.lpszScheme
= scheme
;
1607 if (lpUrlComponents
->dwExtraInfoLength
)
1609 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1610 if (lpUrlComponents
->lpszExtraInfo
)
1612 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1613 UCW
.lpszExtraInfo
= extra
;
1616 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1618 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1619 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1620 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1621 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1622 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1623 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1624 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1625 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1626 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1627 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1628 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1629 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1631 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1632 lpUrlComponents
->nPort
= UCW
.nPort
;
1634 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1635 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1636 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1637 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1638 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1640 heap_free(lpwszUrl
);
1641 heap_free(hostname
);
1642 heap_free(username
);
1643 heap_free(password
);
1650 static const WCHAR url_schemes
[][7] =
1653 {'g','o','p','h','e','r',0},
1654 {'h','t','t','p',0},
1655 {'h','t','t','p','s',0},
1656 {'f','i','l','e',0},
1657 {'n','e','w','s',0},
1658 {'m','a','i','l','t','o',0},
1662 /***********************************************************************
1663 * GetInternetSchemeW (internal)
1669 * INTERNET_SCHEME_UNKNOWN on failure
1672 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1676 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1678 if(lpszScheme
==NULL
)
1679 return INTERNET_SCHEME_UNKNOWN
;
1681 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1682 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1683 return INTERNET_SCHEME_FIRST
+ i
;
1685 return INTERNET_SCHEME_UNKNOWN
;
1688 /***********************************************************************
1689 * SetUrlComponentValueW (Internal)
1691 * Helper function for InternetCrackUrlW
1694 * lppszComponent [O] Holds the returned string
1695 * dwComponentLen [I] Holds the size of lppszComponent
1696 * [O] Holds the length of the string in lppszComponent without '\0'
1697 * lpszStart [I] Holds the string to copy from
1698 * len [I] Holds the length of lpszStart without '\0'
1705 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1707 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1709 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1712 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1714 if (*lppszComponent
== NULL
)
1716 *lppszComponent
= (LPWSTR
)lpszStart
;
1717 *dwComponentLen
= len
;
1721 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1722 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1723 (*lppszComponent
)[ncpylen
] = '\0';
1724 *dwComponentLen
= ncpylen
;
1731 /***********************************************************************
1732 * InternetCrackUrlW (WININET.@)
1734 * Break up URL into its components
1740 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1741 LPURL_COMPONENTSW lpUC
)
1745 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1748 LPCWSTR lpszParam
= NULL
;
1749 BOOL found_colon
= FALSE
;
1750 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1751 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1752 LPWSTR lpszUrl_decode
= NULL
;
1753 DWORD dwUrlLength
= dwUrlLength_orig
;
1755 TRACE("(%s %u %x %p)\n",
1756 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1757 dwUrlLength
, dwFlags
, lpUC
);
1759 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1761 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1764 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1766 if (dwFlags
& ICU_DECODE
)
1769 DWORD len
= dwUrlLength
+ 1;
1771 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1773 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1776 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1777 url_tmp
[dwUrlLength
] = 0;
1778 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1781 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1784 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1787 lpszUrl
= lpszUrl_decode
;
1793 /* Determine if the URI is absolute. */
1794 while (lpszap
- lpszUrl
< dwUrlLength
)
1796 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1808 lpszcp
= lpszUrl
; /* Relative url */
1815 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1819 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1820 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1822 /* Parse <params> */
1823 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1825 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1827 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1828 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1831 /* Get scheme first. */
1832 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1833 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1834 lpszUrl
, lpszcp
- lpszUrl
);
1836 /* Eat ':' in protocol. */
1839 /* double slash indicates the net_loc portion is present */
1840 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1844 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1848 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1850 lpszNetLoc
= lpszParam
;
1852 else if (!lpszNetLoc
)
1853 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1861 /* [<user>[<:password>]@]<host>[:<port>] */
1862 /* First find the user and password if they exist */
1864 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1865 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1867 /* username and password not specified. */
1868 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1869 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1871 else /* Parse out username and password */
1873 LPCWSTR lpszUser
= lpszcp
;
1874 LPCWSTR lpszPasswd
= lpszHost
;
1876 while (lpszcp
< lpszHost
)
1879 lpszPasswd
= lpszcp
;
1884 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1885 lpszUser
, lpszPasswd
- lpszUser
);
1887 if (lpszPasswd
!= lpszHost
)
1889 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1890 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1891 lpszHost
- lpszPasswd
);
1893 lpszcp
++; /* Advance to beginning of host */
1896 /* Parse <host><:port> */
1899 lpszPort
= lpszNetLoc
;
1901 /* special case for res:// URLs: there is no port here, so the host is the
1902 entire string up to the first '/' */
1903 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1905 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1906 lpszHost
, lpszPort
- lpszHost
);
1911 while (lpszcp
< lpszNetLoc
)
1919 /* If the scheme is "file" and the host is just one letter, it's not a host */
1920 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1923 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1928 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1929 lpszHost
, lpszPort
- lpszHost
);
1930 if (lpszPort
!= lpszNetLoc
)
1931 lpUC
->nPort
= atoiW(++lpszPort
);
1932 else switch (lpUC
->nScheme
)
1934 case INTERNET_SCHEME_HTTP
:
1935 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1937 case INTERNET_SCHEME_HTTPS
:
1938 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1940 case INTERNET_SCHEME_FTP
:
1941 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1943 case INTERNET_SCHEME_GOPHER
:
1944 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1955 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1956 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1957 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1960 /* Here lpszcp points to:
1962 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1963 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1965 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1969 /* Only truncate the parameter list if it's already been saved
1970 * in lpUC->lpszExtraInfo.
1972 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1973 len
= lpszParam
- lpszcp
;
1976 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1977 * newlines if necessary.
1979 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1980 if (lpsznewline
!= NULL
)
1981 len
= lpsznewline
- lpszcp
;
1983 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1985 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1986 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1988 WCHAR tmppath
[MAX_PATH
];
1992 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1997 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1998 tmppath
[len
] = '\0';
2007 /* if ends in \. or \.. append a backslash */
2008 if (tmppath
[len
- 1] == '.' &&
2009 (tmppath
[len
- 2] == '\\' ||
2010 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
2012 if (len
< MAX_PATH
- 1)
2014 tmppath
[len
] = '\\';
2015 tmppath
[len
+1] = '\0';
2019 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
2023 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
2028 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
2029 lpUC
->lpszUrlPath
[0] = 0;
2030 lpUC
->dwUrlPathLength
= 0;
2033 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
2034 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
2035 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
2036 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
2037 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
2039 heap_free( lpszUrl_decode
);
2043 /***********************************************************************
2044 * InternetAttemptConnect (WININET.@)
2046 * Attempt to make a connection to the internet
2049 * ERROR_SUCCESS on success
2050 * Error value on failure
2053 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
2056 return ERROR_SUCCESS
;
2060 /***********************************************************************
2061 * convert_url_canonicalization_flags
2063 * Helper for InternetCanonicalizeUrl
2066 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2069 * Flags suitable for UrlCanonicalize
2071 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
2073 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2075 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
2076 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
2077 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
2078 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
2079 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2080 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
2081 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
2086 /***********************************************************************
2087 * InternetCanonicalizeUrlA (WININET.@)
2089 * Escape unsafe characters and spaces
2096 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2097 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2101 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2102 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2104 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2105 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2106 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2107 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2112 /***********************************************************************
2113 * InternetCanonicalizeUrlW (WININET.@)
2115 * Escape unsafe characters and spaces
2122 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2123 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2127 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2128 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2130 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2131 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2132 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2133 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2138 /* #################################################### */
2140 static INTERNET_STATUS_CALLBACK
set_status_callback(
2141 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2143 INTERNET_STATUS_CALLBACK ret
;
2145 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2146 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2148 ret
= lpwh
->lpfnStatusCB
;
2149 lpwh
->lpfnStatusCB
= callback
;
2154 /***********************************************************************
2155 * InternetSetStatusCallbackA (WININET.@)
2157 * Sets up a callback function which is called as progress is made
2158 * during an operation.
2161 * Previous callback or NULL on success
2162 * INTERNET_INVALID_STATUS_CALLBACK on failure
2165 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2166 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2168 INTERNET_STATUS_CALLBACK retVal
;
2169 object_header_t
*lpwh
;
2171 TRACE("%p\n", hInternet
);
2173 if (!(lpwh
= get_handle_object(hInternet
)))
2174 return INTERNET_INVALID_STATUS_CALLBACK
;
2176 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2178 WININET_Release( lpwh
);
2182 /***********************************************************************
2183 * InternetSetStatusCallbackW (WININET.@)
2185 * Sets up a callback function which is called as progress is made
2186 * during an operation.
2189 * Previous callback or NULL on success
2190 * INTERNET_INVALID_STATUS_CALLBACK on failure
2193 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2194 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2196 INTERNET_STATUS_CALLBACK retVal
;
2197 object_header_t
*lpwh
;
2199 TRACE("%p\n", hInternet
);
2201 if (!(lpwh
= get_handle_object(hInternet
)))
2202 return INTERNET_INVALID_STATUS_CALLBACK
;
2204 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2206 WININET_Release( lpwh
);
2210 /***********************************************************************
2211 * InternetSetFilePointer (WININET.@)
2213 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2214 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2216 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2220 /***********************************************************************
2221 * InternetWriteFile (WININET.@)
2223 * Write data to an open internet file
2230 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2231 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2233 object_header_t
*lpwh
;
2236 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2238 lpwh
= get_handle_object( hFile
);
2240 WARN("Invalid handle\n");
2241 SetLastError(ERROR_INVALID_HANDLE
);
2245 if(lpwh
->vtbl
->WriteFile
) {
2246 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2248 WARN("No Writefile method.\n");
2249 res
= ERROR_INVALID_HANDLE
;
2252 WININET_Release( lpwh
);
2254 if(res
!= ERROR_SUCCESS
)
2256 return res
== ERROR_SUCCESS
;
2260 /***********************************************************************
2261 * InternetReadFile (WININET.@)
2263 * Read data from an open internet file
2270 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2271 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2273 object_header_t
*hdr
;
2274 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2276 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2278 hdr
= get_handle_object(hFile
);
2280 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2284 if(hdr
->vtbl
->ReadFile
)
2285 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2287 WININET_Release(hdr
);
2289 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2290 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2292 if(res
!= ERROR_SUCCESS
)
2294 return res
== ERROR_SUCCESS
;
2297 /***********************************************************************
2298 * InternetReadFileExA (WININET.@)
2300 * Read data from an open internet file
2303 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2304 * lpBuffersOut [I/O] Buffer.
2305 * dwFlags [I] Flags. See notes.
2306 * dwContext [I] Context for callbacks.
2313 * The parameter dwFlags include zero or more of the following flags:
2314 *|IRF_ASYNC - Makes the call asynchronous.
2315 *|IRF_SYNC - Makes the call synchronous.
2316 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2317 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2319 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2322 * InternetOpenUrlA(), HttpOpenRequestA()
2324 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2325 DWORD dwFlags
, DWORD_PTR dwContext
)
2327 object_header_t
*hdr
;
2328 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2330 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2332 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2333 SetLastError(ERROR_INVALID_PARAMETER
);
2337 hdr
= get_handle_object(hFile
);
2339 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2343 if(hdr
->vtbl
->ReadFileEx
)
2344 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2345 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2347 WININET_Release(hdr
);
2349 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2350 res
, lpBuffersOut
->dwBufferLength
);
2352 if(res
!= ERROR_SUCCESS
)
2354 return res
== ERROR_SUCCESS
;
2357 /***********************************************************************
2358 * InternetReadFileExW (WININET.@)
2360 * InternetReadFileExA()
2362 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2363 DWORD dwFlags
, DWORD_PTR dwContext
)
2365 object_header_t
*hdr
;
2366 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2368 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2370 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2371 SetLastError(ERROR_INVALID_PARAMETER
);
2375 hdr
= get_handle_object(hFile
);
2377 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2381 if(hdr
->vtbl
->ReadFileEx
)
2382 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2383 dwFlags
, dwContext
);
2385 WININET_Release(hdr
);
2387 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2388 res
, lpBuffer
->dwBufferLength
);
2390 if(res
!= ERROR_SUCCESS
)
2392 return res
== ERROR_SUCCESS
;
2395 static BOOL
get_proxy_autoconfig_url( char *buf
, DWORD buflen
)
2397 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2399 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2403 if (!settings
) return FALSE
;
2405 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2407 CFRelease( settings
);
2410 if (CFStringGetCString( ref
, buf
, buflen
, kCFStringEncodingASCII
))
2412 TRACE( "returning %s\n", debugstr_a(buf
) );
2415 CFRelease( settings
);
2418 FIXME( "no support on this platform\n" );
2423 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2425 /* FIXME: This function currently handles more options than it should. Options requiring
2426 * proper handles should be moved to proper functions */
2428 case INTERNET_OPTION_HTTP_VERSION
:
2429 if (*size
< sizeof(HTTP_VERSION_INFO
))
2430 return ERROR_INSUFFICIENT_BUFFER
;
2433 * Presently hardcoded to 1.1
2435 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2436 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2437 *size
= sizeof(HTTP_VERSION_INFO
);
2439 return ERROR_SUCCESS
;
2441 case INTERNET_OPTION_CONNECTED_STATE
:
2442 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2444 if (*size
< sizeof(ULONG
))
2445 return ERROR_INSUFFICIENT_BUFFER
;
2447 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2448 *size
= sizeof(ULONG
);
2450 return ERROR_SUCCESS
;
2452 case INTERNET_OPTION_PROXY
: {
2456 TRACE("Getting global proxy info\n");
2457 memset(&ai
, 0, sizeof(appinfo_t
));
2458 INTERNET_ConfigureProxy(&ai
);
2460 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2461 APPINFO_Destroy(&ai
.hdr
);
2465 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2466 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2468 if (*size
< sizeof(ULONG
))
2469 return ERROR_INSUFFICIENT_BUFFER
;
2471 *(ULONG
*)buffer
= max_conns
;
2472 *size
= sizeof(ULONG
);
2474 return ERROR_SUCCESS
;
2476 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2477 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2479 if (*size
< sizeof(ULONG
))
2480 return ERROR_INSUFFICIENT_BUFFER
;
2482 *(ULONG
*)buffer
= max_1_0_conns
;
2483 *size
= sizeof(ULONG
);
2485 return ERROR_SUCCESS
;
2487 case INTERNET_OPTION_SECURITY_FLAGS
:
2488 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2489 return ERROR_SUCCESS
;
2491 case INTERNET_OPTION_VERSION
: {
2492 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2494 TRACE("INTERNET_OPTION_VERSION\n");
2496 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2497 return ERROR_INSUFFICIENT_BUFFER
;
2499 memcpy(buffer
, &info
, sizeof(info
));
2500 *size
= sizeof(info
);
2502 return ERROR_SUCCESS
;
2505 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2506 char url
[INTERNET_MAX_URL_LENGTH
+ 1];
2507 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2508 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2509 DWORD res
= ERROR_SUCCESS
, i
;
2514 TRACE("Getting global proxy info\n");
2515 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2518 have_url
= get_proxy_autoconfig_url(url
, sizeof(url
));
2520 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2522 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2524 return ERROR_INSUFFICIENT_BUFFER
;
2527 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2528 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2529 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2531 switch (optionW
->dwOption
) {
2532 case INTERNET_PER_CONN_FLAGS
:
2534 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2536 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2538 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2539 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2542 case INTERNET_PER_CONN_PROXY_SERVER
:
2544 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2546 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2549 case INTERNET_PER_CONN_PROXY_BYPASS
:
2551 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2553 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2556 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2558 optionW
->Value
.pszValue
= NULL
;
2560 optionW
->Value
.pszValue
= heap_strdupAtoW(url
);
2562 optionA
->Value
.pszValue
= heap_strdupA(url
);
2565 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2566 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2569 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2570 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2571 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2572 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2573 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2574 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2578 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2579 res
= ERROR_INVALID_PARAMETER
;
2587 case INTERNET_OPTION_REQUEST_FLAGS
:
2588 case INTERNET_OPTION_USER_AGENT
:
2590 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2591 case INTERNET_OPTION_POLICY
:
2592 return ERROR_INVALID_PARAMETER
;
2593 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2594 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2596 if (*size
< sizeof(ULONG
))
2597 return ERROR_INSUFFICIENT_BUFFER
;
2599 *(ULONG
*)buffer
= connect_timeout
;
2600 *size
= sizeof(ULONG
);
2602 return ERROR_SUCCESS
;
2605 FIXME("Stub for %d\n", option
);
2606 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2609 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2612 case INTERNET_OPTION_CONTEXT_VALUE
:
2614 return ERROR_INVALID_PARAMETER
;
2616 if (*size
< sizeof(DWORD_PTR
)) {
2617 *size
= sizeof(DWORD_PTR
);
2618 return ERROR_INSUFFICIENT_BUFFER
;
2621 return ERROR_INVALID_PARAMETER
;
2623 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2624 *size
= sizeof(DWORD_PTR
);
2625 return ERROR_SUCCESS
;
2627 case INTERNET_OPTION_REQUEST_FLAGS
:
2628 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2629 *size
= sizeof(DWORD
);
2630 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2632 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2633 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2634 WARN("Called on global option %u\n", option
);
2635 return ERROR_INTERNET_INVALID_OPERATION
;
2638 /* FIXME: we shouldn't call it here */
2639 return query_global_option(option
, buffer
, size
, unicode
);
2642 /***********************************************************************
2643 * InternetQueryOptionW (WININET.@)
2645 * Queries an options on the specified handle
2652 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2653 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2655 object_header_t
*hdr
;
2656 DWORD res
= ERROR_INVALID_HANDLE
;
2658 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2661 hdr
= get_handle_object(hInternet
);
2663 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2664 WININET_Release(hdr
);
2667 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2670 if(res
!= ERROR_SUCCESS
)
2672 return res
== ERROR_SUCCESS
;
2675 /***********************************************************************
2676 * InternetQueryOptionA (WININET.@)
2678 * Queries an options on the specified handle
2685 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2686 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2688 object_header_t
*hdr
;
2689 DWORD res
= ERROR_INVALID_HANDLE
;
2691 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2694 hdr
= get_handle_object(hInternet
);
2696 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2697 WININET_Release(hdr
);
2700 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2703 if(res
!= ERROR_SUCCESS
)
2705 return res
== ERROR_SUCCESS
;
2708 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2711 case INTERNET_OPTION_CALLBACK
:
2712 WARN("Not settable option %u\n", option
);
2713 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2714 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2715 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2716 WARN("Called on global option %u\n", option
);
2717 return ERROR_INTERNET_INVALID_OPERATION
;
2720 return ERROR_INTERNET_INVALID_OPTION
;
2723 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2726 case INTERNET_OPTION_CALLBACK
:
2727 WARN("Not global option %u\n", option
);
2728 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2730 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2731 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2733 if(size
!= sizeof(max_conns
))
2734 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2736 return ERROR_BAD_ARGUMENTS
;
2738 max_conns
= *(ULONG
*)buf
;
2739 return ERROR_SUCCESS
;
2741 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2742 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2744 if(size
!= sizeof(max_1_0_conns
))
2745 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2747 return ERROR_BAD_ARGUMENTS
;
2749 max_1_0_conns
= *(ULONG
*)buf
;
2750 return ERROR_SUCCESS
;
2752 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2753 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2755 if(size
!= sizeof(connect_timeout
))
2756 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2758 return ERROR_BAD_ARGUMENTS
;
2760 connect_timeout
= *(ULONG
*)buf
;
2761 return ERROR_SUCCESS
;
2763 case INTERNET_OPTION_SETTINGS_CHANGED
:
2764 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2765 collect_connections(COLLECT_CONNECTIONS
);
2766 return ERROR_SUCCESS
;
2768 case INTERNET_OPTION_SUPPRESS_BEHAVIOR
:
2769 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2771 if(size
!= sizeof(ULONG
))
2772 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2774 FIXME("%08x\n", *(ULONG
*)buf
);
2775 return ERROR_SUCCESS
;
2778 return ERROR_INTERNET_INVALID_OPTION
;
2781 /***********************************************************************
2782 * InternetSetOptionW (WININET.@)
2784 * Sets an options on the specified handle
2791 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2792 LPVOID lpBuffer
, DWORD dwBufferLength
)
2794 object_header_t
*lpwhh
;
2798 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2800 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2802 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2804 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2806 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2808 WININET_Release(lpwhh
);
2810 if(res
!= ERROR_SUCCESS
)
2813 return res
== ERROR_SUCCESS
;
2818 case INTERNET_OPTION_HTTP_VERSION
:
2820 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2821 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2824 case INTERNET_OPTION_ERROR_MASK
:
2827 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2829 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2830 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2831 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2832 SetLastError(ERROR_INVALID_PARAMETER
);
2834 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2835 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2838 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2839 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2842 case INTERNET_OPTION_PROXY
:
2844 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2846 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2848 SetLastError(ERROR_INVALID_PARAMETER
);
2853 EnterCriticalSection( &WININET_cs
);
2854 free_global_proxy();
2855 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2858 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2860 global_proxy
->proxyEnabled
= 1;
2861 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2862 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2866 global_proxy
->proxyEnabled
= 0;
2867 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2870 LeaveCriticalSection( &WININET_cs
);
2874 /* In general, each type of object should handle
2875 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2876 * get silently dropped.
2878 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2879 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2884 case INTERNET_OPTION_CODEPAGE
:
2886 ULONG codepage
= *(ULONG
*)lpBuffer
;
2887 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2890 case INTERNET_OPTION_REQUEST_PRIORITY
:
2892 ULONG priority
= *(ULONG
*)lpBuffer
;
2893 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2896 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2898 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2899 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2902 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2904 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2905 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2908 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2909 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2911 case INTERNET_OPTION_END_BROWSER_SESSION
:
2912 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2914 case INTERNET_OPTION_CONNECTED_STATE
:
2915 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2917 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2918 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2920 case INTERNET_OPTION_SEND_TIMEOUT
:
2921 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2922 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2924 ULONG timeout
= *(ULONG
*)lpBuffer
;
2925 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2928 case INTERNET_OPTION_CONNECT_RETRIES
:
2930 ULONG retries
= *(ULONG
*)lpBuffer
;
2931 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2934 case INTERNET_OPTION_CONTEXT_VALUE
:
2938 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2941 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2943 SetLastError(ERROR_INVALID_PARAMETER
);
2947 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2950 case INTERNET_OPTION_SECURITY_FLAGS
:
2951 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2953 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2954 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2956 case INTERNET_OPTION_HTTP_DECODING
:
2957 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2958 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2961 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2962 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2963 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2966 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2967 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2968 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2971 case INTERNET_OPTION_CODEPAGE_PATH
:
2972 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2973 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2976 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2977 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2978 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2981 case INTERNET_OPTION_IDN
:
2982 FIXME("INTERNET_OPTION_IDN; STUB\n");
2983 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2986 case INTERNET_OPTION_POLICY
:
2987 SetLastError(ERROR_INVALID_PARAMETER
);
2990 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2991 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2996 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2998 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2999 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
3001 switch (option
->dwOption
) {
3002 case INTERNET_PER_CONN_PROXY_SERVER
:
3003 heap_free(pi
.proxy
);
3004 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
3007 case INTERNET_PER_CONN_FLAGS
:
3008 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
3009 pi
.proxyEnabled
= 1;
3012 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
3013 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
3014 pi
.proxyEnabled
= 0;
3018 case INTERNET_PER_CONN_PROXY_BYPASS
:
3019 heap_free(pi
.proxyBypass
);
3020 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
3023 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3024 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3025 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3026 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3027 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3028 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3029 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
3033 FIXME("Unknown dwOption %d\n", option
->dwOption
);
3034 SetLastError(ERROR_INVALID_PARAMETER
);
3039 if ((res
= INTERNET_SaveProxySettings(&pi
)))
3044 ret
= (res
== ERROR_SUCCESS
);
3048 FIXME("Option %d STUB\n",dwOption
);
3049 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3055 WININET_Release( lpwhh
);
3061 /***********************************************************************
3062 * InternetSetOptionA (WININET.@)
3064 * Sets an options on the specified handle.
3071 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3072 LPVOID lpBuffer
, DWORD dwBufferLength
)
3080 case INTERNET_OPTION_PROXY
:
3082 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3083 LPINTERNET_PROXY_INFOW piw
;
3084 DWORD proxlen
, prbylen
;
3087 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3088 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3089 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3090 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3091 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3092 piw
->dwAccessType
= pi
->dwAccessType
;
3093 prox
= (LPWSTR
) &piw
[1];
3094 prby
= &prox
[proxlen
+1];
3095 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3096 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3097 piw
->lpszProxy
= prox
;
3098 piw
->lpszProxyBypass
= prby
;
3101 case INTERNET_OPTION_USER_AGENT
:
3102 case INTERNET_OPTION_USERNAME
:
3103 case INTERNET_OPTION_PASSWORD
:
3104 case INTERNET_OPTION_PROXY_USERNAME
:
3105 case INTERNET_OPTION_PROXY_PASSWORD
:
3106 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3107 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3108 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3110 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3112 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3113 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3114 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3115 wbuffer
= heap_alloc(wlen
);
3118 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3119 if (listA
->pszConnection
)
3121 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3122 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3123 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3126 listW
->pszConnection
= NULL
;
3127 listW
->dwOptionCount
= listA
->dwOptionCount
;
3128 listW
->dwOptionError
= listA
->dwOptionError
;
3129 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3131 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3132 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3133 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3135 optW
->dwOption
= optA
->dwOption
;
3137 switch (optA
->dwOption
) {
3138 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3139 case INTERNET_PER_CONN_PROXY_BYPASS
:
3140 case INTERNET_PER_CONN_PROXY_SERVER
:
3141 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3142 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3143 if (optA
->Value
.pszValue
)
3145 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3146 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3147 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3150 optW
->Value
.pszValue
= NULL
;
3152 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3153 case INTERNET_PER_CONN_FLAGS
:
3154 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3155 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3157 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3158 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3161 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3162 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3170 wlen
= dwBufferLength
;
3173 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3175 if( lpBuffer
!= wbuffer
)
3177 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3179 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3181 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3182 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3183 switch (opt
->dwOption
) {
3184 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3185 case INTERNET_PER_CONN_PROXY_BYPASS
:
3186 case INTERNET_PER_CONN_PROXY_SERVER
:
3187 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3188 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3189 heap_free( opt
->Value
.pszValue
);
3195 heap_free( list
->pOptions
);
3197 heap_free( wbuffer
);
3204 /***********************************************************************
3205 * InternetSetOptionExA (WININET.@)
3207 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3208 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3210 FIXME("Flags %08x ignored\n", dwFlags
);
3211 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3214 /***********************************************************************
3215 * InternetSetOptionExW (WININET.@)
3217 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3218 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3220 FIXME("Flags %08x ignored\n", dwFlags
);
3221 if( dwFlags
& ~ISO_VALID_FLAGS
)
3223 SetLastError( ERROR_INVALID_PARAMETER
);
3226 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3229 static const WCHAR WININET_wkday
[7][4] =
3230 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3231 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3232 static const WCHAR WININET_month
[12][4] =
3233 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3234 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3235 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3237 /***********************************************************************
3238 * InternetTimeFromSystemTimeA (WININET.@)
3240 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3243 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3245 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3247 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3249 SetLastError(ERROR_INVALID_PARAMETER
);
3253 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3255 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3259 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3260 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3265 /***********************************************************************
3266 * InternetTimeFromSystemTimeW (WININET.@)
3268 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3270 static const WCHAR date
[] =
3271 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3272 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3274 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3276 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3278 SetLastError(ERROR_INVALID_PARAMETER
);
3282 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3284 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3288 sprintfW( string
, date
,
3289 WININET_wkday
[time
->wDayOfWeek
],
3291 WININET_month
[time
->wMonth
- 1],
3300 /***********************************************************************
3301 * InternetTimeToSystemTimeA (WININET.@)
3303 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3308 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3310 stringW
= heap_strdupAtoW(string
);
3313 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3314 heap_free( stringW
);
3319 /***********************************************************************
3320 * InternetTimeToSystemTimeW (WININET.@)
3322 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3325 const WCHAR
*s
= string
;
3328 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3330 if (!string
|| !time
) return FALSE
;
3332 /* Windows does this too */
3333 GetSystemTime( time
);
3335 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3336 * a SYSTEMTIME structure.
3339 while (*s
&& !isalphaW( *s
)) s
++;
3340 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3341 time
->wDayOfWeek
= 7;
3343 for (i
= 0; i
< 7; i
++)
3345 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3346 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3347 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3349 time
->wDayOfWeek
= i
;
3354 if (time
->wDayOfWeek
> 6) return TRUE
;
3355 while (*s
&& !isdigitW( *s
)) s
++;
3356 time
->wDay
= strtolW( s
, &end
, 10 );
3359 while (*s
&& !isalphaW( *s
)) s
++;
3360 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3363 for (i
= 0; i
< 12; i
++)
3365 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3366 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3367 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3369 time
->wMonth
= i
+ 1;
3373 if (time
->wMonth
== 0) return TRUE
;
3375 while (*s
&& !isdigitW( *s
)) s
++;
3376 if (*s
== '\0') return TRUE
;
3377 time
->wYear
= strtolW( s
, &end
, 10 );
3380 while (*s
&& !isdigitW( *s
)) s
++;
3381 if (*s
== '\0') return TRUE
;
3382 time
->wHour
= strtolW( s
, &end
, 10 );
3385 while (*s
&& !isdigitW( *s
)) s
++;
3386 if (*s
== '\0') return TRUE
;
3387 time
->wMinute
= strtolW( s
, &end
, 10 );
3390 while (*s
&& !isdigitW( *s
)) s
++;
3391 if (*s
== '\0') return TRUE
;
3392 time
->wSecond
= strtolW( s
, &end
, 10 );
3395 time
->wMilliseconds
= 0;
3399 /***********************************************************************
3400 * InternetCheckConnectionW (WININET.@)
3402 * Pings a requested host to check internet connection
3405 * TRUE on success and FALSE on failure. If a failure then
3406 * ERROR_NOT_CONNECTED is placed into GetLastError
3409 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3412 * this is a kludge which runs the resident ping program and reads the output.
3414 * Anyone have a better idea?
3418 static const CHAR ping
[] = "ping -c 1 ";
3419 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3420 CHAR
*command
= NULL
;
3421 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3429 * Crack or set the Address
3431 if (lpszUrl
== NULL
)
3434 * According to the doc we are supposed to use the ip for the next
3435 * server in the WnInet internal server database. I have
3436 * no idea what that is or how to get it.
3438 * So someone needs to implement this.
3440 FIXME("Unimplemented with URL of NULL\n");
3445 URL_COMPONENTSW components
;
3447 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3448 components
.lpszHostName
= (LPWSTR
)hostW
;
3449 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3451 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3454 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3455 port
= components
.nPort
;
3456 TRACE("port: %d\n", port
);
3459 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3461 struct sockaddr_storage saddr
;
3462 socklen_t sa_len
= sizeof(saddr
);
3465 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
, NULL
))
3468 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3471 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3479 * Build our ping command
3481 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3482 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3483 strcpy(command
,ping
);
3484 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3485 strcat(command
,redirect
);
3487 TRACE("Ping command is : %s\n",command
);
3489 status
= system(command
);
3491 TRACE("Ping returned a code of %i\n",status
);
3493 /* Ping return code of 0 indicates success */
3499 heap_free( command
);
3501 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3507 /***********************************************************************
3508 * InternetCheckConnectionA (WININET.@)
3510 * Pings a requested host to check internet connection
3513 * TRUE on success and FALSE on failure. If a failure then
3514 * ERROR_NOT_CONNECTED is placed into GetLastError
3517 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3523 url
= heap_strdupAtoW(lpszUrl
);
3528 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3535 /**********************************************************
3536 * INTERNET_InternetOpenUrlW (internal)
3541 * handle of connection or NULL on failure
3543 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3544 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3546 URL_COMPONENTSW urlComponents
;
3547 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3548 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3549 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3550 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3551 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3553 HINTERNET client
= NULL
, client1
= NULL
;
3556 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3557 dwHeadersLength
, dwFlags
, dwContext
);
3559 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3560 urlComponents
.lpszScheme
= protocol
;
3561 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3562 urlComponents
.lpszHostName
= hostName
;
3563 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3564 urlComponents
.lpszUserName
= userName
;
3565 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3566 urlComponents
.lpszPassword
= password
;
3567 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3568 urlComponents
.lpszUrlPath
= path
;
3569 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3570 urlComponents
.lpszExtraInfo
= extra
;
3571 urlComponents
.dwExtraInfoLength
= 1024;
3572 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3574 switch(urlComponents
.nScheme
) {
3575 case INTERNET_SCHEME_FTP
:
3576 if(urlComponents
.nPort
== 0)
3577 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3578 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3579 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3582 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3583 if(client1
== NULL
) {
3584 InternetCloseHandle(client
);
3589 case INTERNET_SCHEME_HTTP
:
3590 case INTERNET_SCHEME_HTTPS
: {
3591 static const WCHAR szStars
[] = { '*','/','*', 0 };
3592 LPCWSTR accept
[2] = { szStars
, NULL
};
3593 if(urlComponents
.nPort
== 0) {
3594 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3595 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3597 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3599 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3601 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3602 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3603 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3604 if(res
!= ERROR_SUCCESS
) {
3605 INTERNET_SetLastError(res
);
3609 if (urlComponents
.dwExtraInfoLength
) {
3611 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3613 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3615 InternetCloseHandle(client
);
3618 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3619 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3620 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3621 heap_free(path_extra
);
3624 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3626 if(client1
== NULL
) {
3627 InternetCloseHandle(client
);
3630 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3631 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3632 GetLastError() != ERROR_IO_PENDING
) {
3633 InternetCloseHandle(client1
);
3638 case INTERNET_SCHEME_GOPHER
:
3639 /* gopher doesn't seem to be implemented in wine, but it's supposed
3640 * to be supported by InternetOpenUrlA. */
3642 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3646 TRACE(" %p <--\n", client1
);
3651 /**********************************************************
3652 * InternetOpenUrlW (WININET.@)
3657 * handle of connection or NULL on failure
3668 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3670 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3672 TRACE("%p\n", task
->hdr
.hdr
);
3674 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3675 task
->headers_len
, task
->flags
, task
->context
);
3676 heap_free(task
->url
);
3677 heap_free(task
->headers
);
3680 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3681 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3683 HINTERNET ret
= NULL
;
3684 appinfo_t
*hIC
= NULL
;
3686 if (TRACE_ON(wininet
)) {
3687 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3688 dwHeadersLength
, dwFlags
, dwContext
);
3690 dump_INTERNET_FLAGS(dwFlags
);
3695 SetLastError(ERROR_INVALID_PARAMETER
);
3699 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3700 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3701 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3705 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3706 open_url_task_t
*task
;
3708 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3709 task
->url
= heap_strdupW(lpszUrl
);
3710 task
->headers
= heap_strdupW(lpszHeaders
);
3711 task
->headers_len
= dwHeadersLength
;
3712 task
->flags
= dwFlags
;
3713 task
->context
= dwContext
;
3715 INTERNET_AsyncCall(&task
->hdr
);
3716 SetLastError(ERROR_IO_PENDING
);
3718 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3723 WININET_Release( &hIC
->hdr
);
3724 TRACE(" %p <--\n", ret
);
3729 /**********************************************************
3730 * InternetOpenUrlA (WININET.@)
3735 * handle of connection or NULL on failure
3737 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3738 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3740 HINTERNET rc
= NULL
;
3741 DWORD lenHeaders
= 0;
3742 LPWSTR szUrl
= NULL
;
3743 LPWSTR szHeaders
= NULL
;
3748 szUrl
= heap_strdupAtoW(lpszUrl
);
3754 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3755 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3760 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3763 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3764 lenHeaders
, dwFlags
, dwContext
);
3767 heap_free(szHeaders
);
3772 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3774 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3778 lpwite
->dwError
= 0;
3779 lpwite
->response
[0] = '\0';
3782 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3791 /***********************************************************************
3792 * INTERNET_SetLastError (internal)
3794 * Set last thread specific error
3799 void INTERNET_SetLastError(DWORD dwError
)
3801 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3804 lpwite
= INTERNET_AllocThreadError();
3806 SetLastError(dwError
);
3808 lpwite
->dwError
= dwError
;
3812 /***********************************************************************
3813 * INTERNET_GetLastError (internal)
3815 * Get last thread specific error
3820 DWORD
INTERNET_GetLastError(void)
3822 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3823 if (!lpwite
) return 0;
3824 /* TlsGetValue clears last error, so set it again here */
3825 SetLastError(lpwite
->dwError
);
3826 return lpwite
->dwError
;
3830 /***********************************************************************
3831 * INTERNET_WorkerThreadFunc (internal)
3833 * Worker thread execution function
3838 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3840 task_header_t
*task
= lpvParam
;
3845 WININET_Release(task
->hdr
);
3848 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3850 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3851 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3856 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3858 task_header_t
*task
;
3860 task
= heap_alloc(size
);
3864 task
->hdr
= WININET_AddRef(hdr
);
3869 /***********************************************************************
3870 * INTERNET_AsyncCall (internal)
3872 * Retrieves work request from queue
3877 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3883 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3887 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3889 return ERROR_SUCCESS
;
3893 /***********************************************************************
3894 * INTERNET_GetResponseBuffer (internal)
3899 LPSTR
INTERNET_GetResponseBuffer(void)
3901 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3903 lpwite
= INTERNET_AllocThreadError();
3905 return lpwite
->response
;
3908 /**********************************************************
3909 * InternetQueryDataAvailable (WININET.@)
3911 * Determines how much data is available to be read.
3914 * TRUE on success, FALSE if an error occurred. If
3915 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3916 * no data is presently available, FALSE is returned with
3917 * the last error ERROR_IO_PENDING; a callback with status
3918 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3919 * data is available.
3921 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3922 LPDWORD lpdwNumberOfBytesAvailable
,
3923 DWORD dwFlags
, DWORD_PTR dwContext
)
3925 object_header_t
*hdr
;
3928 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3930 hdr
= get_handle_object( hFile
);
3932 SetLastError(ERROR_INVALID_HANDLE
);
3936 if(hdr
->vtbl
->QueryDataAvailable
) {
3937 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3939 WARN("wrong handle\n");
3940 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3943 WININET_Release(hdr
);
3945 if(res
!= ERROR_SUCCESS
)
3947 return res
== ERROR_SUCCESS
;
3950 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3952 req_file_t
*req_file
;
3954 req_file
= heap_alloc_zero(sizeof(*req_file
));
3956 return ERROR_NOT_ENOUGH_MEMORY
;
3960 req_file
->file_name
= heap_strdupW(file_name
);
3961 if(!req_file
->file_name
) {
3962 heap_free(req_file
);
3963 return ERROR_NOT_ENOUGH_MEMORY
;
3966 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3967 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3968 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
3969 req_file_release(req_file
);
3970 return GetLastError();
3974 return ERROR_SUCCESS
;
3977 void req_file_release(req_file_t
*req_file
)
3979 if(InterlockedDecrement(&req_file
->ref
))
3982 if(!req_file
->is_committed
)
3983 DeleteFileW(req_file
->file_name
);
3984 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
3985 CloseHandle(req_file
->file_handle
);
3986 heap_free(req_file
->file_name
);
3987 heap_free(req_file
);
3990 /***********************************************************************
3991 * InternetLockRequestFile (WININET.@)
3993 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
3995 req_file_t
*req_file
= NULL
;
3996 object_header_t
*hdr
;
3999 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
4001 hdr
= get_handle_object(hInternet
);
4003 SetLastError(ERROR_INVALID_HANDLE
);
4007 if(hdr
->vtbl
->LockRequestFile
) {
4008 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
4010 WARN("wrong handle\n");
4011 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4014 WININET_Release(hdr
);
4016 *lphLockReqHandle
= req_file
;
4017 if(res
!= ERROR_SUCCESS
)
4019 return res
== ERROR_SUCCESS
;
4022 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
4024 TRACE("(%p)\n", hLockHandle
);
4026 req_file_release(hLockHandle
);
4031 /***********************************************************************
4032 * InternetAutodial (WININET.@)
4034 * On windows this function is supposed to dial the default internet
4035 * connection. We don't want to have Wine dial out to the internet so
4036 * we return TRUE by default. It might be nice to check if we are connected.
4043 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
4047 /* Tell that we are connected to the internet. */
4051 /***********************************************************************
4052 * InternetAutodialHangup (WININET.@)
4054 * Hangs up a connection made with InternetAutodial
4063 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
4067 /* we didn't dial, we don't disconnect */
4071 /***********************************************************************
4072 * InternetCombineUrlA (WININET.@)
4074 * Combine a base URL with a relative URL
4082 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
4083 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4088 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4090 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4091 dwFlags
^= ICU_NO_ENCODE
;
4092 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4097 /***********************************************************************
4098 * InternetCombineUrlW (WININET.@)
4100 * Combine a base URL with a relative URL
4108 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4109 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4114 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4116 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4117 dwFlags
^= ICU_NO_ENCODE
;
4118 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4123 /* max port num is 65535 => 5 digits */
4124 #define MAX_WORD_DIGITS 5
4126 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4127 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4128 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4129 (url)->dw##component##Length : strlen((url)->lpsz##component))
4131 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4133 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4134 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4136 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4137 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4139 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4140 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4142 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4143 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4146 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4152 /* opaque urls do not fit into the standard url hierarchy and don't have
4153 * two following slashes */
4154 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4156 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4157 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4158 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4159 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4160 (nScheme
!= INTERNET_SCHEME_FILE
);
4163 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4166 if (scheme
< INTERNET_SCHEME_FIRST
)
4168 index
= scheme
- INTERNET_SCHEME_FIRST
;
4169 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4171 return (LPCWSTR
)url_schemes
[index
];
4174 /* we can calculate using ansi strings because we're just
4175 * calculating string length, not size
4177 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4178 LPDWORD lpdwUrlLength
)
4180 INTERNET_SCHEME nScheme
;
4184 if (lpUrlComponents
->lpszScheme
)
4186 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4187 *lpdwUrlLength
+= dwLen
;
4188 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4194 nScheme
= lpUrlComponents
->nScheme
;
4196 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4197 nScheme
= INTERNET_SCHEME_HTTP
;
4198 scheme
= INTERNET_GetSchemeString(nScheme
);
4199 *lpdwUrlLength
+= strlenW(scheme
);
4202 (*lpdwUrlLength
)++; /* ':' */
4203 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4204 *lpdwUrlLength
+= strlen("//");
4206 if (lpUrlComponents
->lpszUserName
)
4208 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4209 *lpdwUrlLength
+= strlen("@");
4213 if (lpUrlComponents
->lpszPassword
)
4215 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4220 if (lpUrlComponents
->lpszPassword
)
4222 *lpdwUrlLength
+= strlen(":");
4223 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4226 if (lpUrlComponents
->lpszHostName
)
4228 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4230 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4232 char szPort
[MAX_WORD_DIGITS
+1];
4234 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4235 *lpdwUrlLength
+= strlen(szPort
);
4236 *lpdwUrlLength
+= strlen(":");
4239 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4240 (*lpdwUrlLength
)++; /* '/' */
4243 if (lpUrlComponents
->lpszUrlPath
)
4244 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4246 if (lpUrlComponents
->lpszExtraInfo
)
4247 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4252 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4256 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4258 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4259 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4260 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4261 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4262 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4263 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4264 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4265 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4266 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4268 if (lpUrlComponents
->lpszScheme
)
4270 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4271 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4272 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4273 -1, urlCompW
->lpszScheme
, len
);
4276 if (lpUrlComponents
->lpszHostName
)
4278 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4279 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4280 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4281 -1, urlCompW
->lpszHostName
, len
);
4284 if (lpUrlComponents
->lpszUserName
)
4286 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4287 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4288 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4289 -1, urlCompW
->lpszUserName
, len
);
4292 if (lpUrlComponents
->lpszPassword
)
4294 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4295 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4296 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4297 -1, urlCompW
->lpszPassword
, len
);
4300 if (lpUrlComponents
->lpszUrlPath
)
4302 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4303 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4304 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4305 -1, urlCompW
->lpszUrlPath
, len
);
4308 if (lpUrlComponents
->lpszExtraInfo
)
4310 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4311 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4312 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4313 -1, urlCompW
->lpszExtraInfo
, len
);
4317 /***********************************************************************
4318 * InternetCreateUrlA (WININET.@)
4320 * See InternetCreateUrlW.
4322 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4323 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4327 URL_COMPONENTSW urlCompW
;
4329 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4331 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4333 SetLastError(ERROR_INVALID_PARAMETER
);
4337 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4340 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4342 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4344 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4345 *lpdwUrlLength
/= sizeof(WCHAR
);
4347 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4348 * minus one, so add one to leave room for NULL terminator
4351 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4353 heap_free(urlCompW
.lpszScheme
);
4354 heap_free(urlCompW
.lpszHostName
);
4355 heap_free(urlCompW
.lpszUserName
);
4356 heap_free(urlCompW
.lpszPassword
);
4357 heap_free(urlCompW
.lpszUrlPath
);
4358 heap_free(urlCompW
.lpszExtraInfo
);
4363 /***********************************************************************
4364 * InternetCreateUrlW (WININET.@)
4366 * Creates a URL from its component parts.
4369 * lpUrlComponents [I] URL Components.
4370 * dwFlags [I] Flags. See notes.
4371 * lpszUrl [I] Buffer in which to store the created URL.
4372 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4373 * lpszUrl in characters. On output, the number of bytes
4374 * required to store the URL including terminator.
4378 * The dwFlags parameter can be zero or more of the following:
4379 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4386 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4387 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4390 INTERNET_SCHEME nScheme
;
4392 static const WCHAR slashSlashW
[] = {'/','/'};
4393 static const WCHAR fmtW
[] = {'%','u',0};
4395 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4397 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4399 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4403 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4406 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4408 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4409 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4413 *lpdwUrlLength
= dwLen
;
4418 if (lpUrlComponents
->lpszScheme
)
4420 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4421 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4424 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4429 nScheme
= lpUrlComponents
->nScheme
;
4431 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4432 nScheme
= INTERNET_SCHEME_HTTP
;
4434 scheme
= INTERNET_GetSchemeString(nScheme
);
4435 dwLen
= strlenW(scheme
);
4436 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4440 /* all schemes are followed by at least a colon */
4444 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4446 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4447 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4450 if (lpUrlComponents
->lpszUserName
)
4452 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4453 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4456 if (lpUrlComponents
->lpszPassword
)
4461 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4462 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4470 if (lpUrlComponents
->lpszHostName
)
4472 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4473 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4476 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4478 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4480 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4483 dwLen
= strlenW(szPort
);
4484 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4488 /* add slash between hostname and path if necessary */
4489 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4496 if (lpUrlComponents
->lpszUrlPath
)
4498 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4499 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4503 if (lpUrlComponents
->lpszExtraInfo
)
4505 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4506 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4515 /***********************************************************************
4516 * InternetConfirmZoneCrossingA (WININET.@)
4519 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4521 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4522 return ERROR_SUCCESS
;
4525 /***********************************************************************
4526 * InternetConfirmZoneCrossingW (WININET.@)
4529 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4531 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4532 return ERROR_SUCCESS
;
4535 static DWORD zone_preference
= 3;
4537 /***********************************************************************
4538 * PrivacySetZonePreferenceW (WININET.@)
4540 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4542 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4544 zone_preference
= template;
4548 /***********************************************************************
4549 * PrivacyGetZonePreferenceW (WININET.@)
4551 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4552 LPWSTR preference
, LPDWORD length
)
4554 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4556 if (template) *template = zone_preference
;
4560 /***********************************************************************
4561 * InternetGetSecurityInfoByURLA (WININET.@)
4563 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4568 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4570 url
= heap_strdupAtoW(lpszURL
);
4574 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4579 /***********************************************************************
4580 * InternetGetSecurityInfoByURLW (WININET.@)
4582 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4584 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4585 URL_COMPONENTSW url
= {sizeof(url
)};
4589 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4591 url
.lpszHostName
= hostname
;
4592 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4594 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4595 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4596 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4600 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4602 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4606 if(server
->cert_chain
) {
4607 const CERT_CHAIN_CONTEXT
*chain_dup
;
4609 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4611 *ppCertChain
= chain_dup
;
4612 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4617 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4621 server_release(server
);
4625 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR 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 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4634 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4636 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4637 lpdwConnection
, dwReserved
);
4638 return ERROR_SUCCESS
;
4641 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4643 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4647 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4649 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4653 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4655 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4656 return ERROR_SUCCESS
;
4659 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4662 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4663 debugstr_w(pwszTarget
), pbHexHash
);
4667 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4669 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4673 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4675 FIXME("(%p, %08lx) stub\n", a
, b
);
4679 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4681 FIXME("%p: stub\n", parent
);