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
30 #include "wine/port.h"
32 #if defined(__MINGW32__) || defined (_MSC_VER)
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 # include <sys/socket.h>
46 #ifdef HAVE_SYS_POLL_H
47 # include <sys/poll.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
59 #ifdef HAVE_CORESERVICES_CORESERVICES_H
60 #define GetCurrentThread MacGetCurrentThread
61 #define LoadResource MacLoadResource
62 #include <CoreServices/CoreServices.h>
63 #undef GetCurrentThread
74 #include "wine/debug.h"
76 #define NO_SHLWAPI_STREAM
79 #include "wine/exception.h"
84 #include "wine/unicode.h"
86 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
88 #define RESPONSE_TIMEOUT 30
93 CHAR response
[MAX_REPLY_LEN
];
94 } WITHREADERROR
, *LPWITHREADERROR
;
96 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
97 HMODULE WININET_hModule
;
99 static CRITICAL_SECTION WININET_cs
;
100 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
103 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
104 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
106 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
108 static object_header_t
**handle_table
;
109 static UINT_PTR next_handle
;
110 static UINT_PTR handle_table_size
;
117 LPWSTR proxyUsername
;
118 LPWSTR proxyPassword
;
121 static ULONG max_conns
= 2, max_1_0_conns
= 4;
122 static ULONG connect_timeout
= 60000;
124 static const WCHAR szInternetSettings
[] =
125 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
126 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
127 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
128 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
129 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
130 static const WCHAR szProxyOverride
[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
132 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
134 UINT_PTR handle
= 0, num
;
135 object_header_t
*ret
;
139 ret
= heap_alloc_zero(size
);
143 list_init(&ret
->children
);
145 EnterCriticalSection( &WININET_cs
);
147 if(!handle_table_size
) {
149 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
152 handle_table_size
= num
;
157 }else if(next_handle
== handle_table_size
) {
158 num
= handle_table_size
* 2;
159 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
162 handle_table_size
= num
;
169 handle
= next_handle
;
170 if(handle_table
[handle
])
171 ERR("handle isn't free but should be\n");
172 handle_table
[handle
] = ret
;
173 ret
->valid_handle
= TRUE
;
175 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
179 LeaveCriticalSection( &WININET_cs
);
188 ret
->hInternet
= (HINTERNET
)handle
;
191 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
192 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
198 object_header_t
*WININET_AddRef( object_header_t
*info
)
200 ULONG refs
= InterlockedIncrement(&info
->refs
);
201 TRACE("%p -> refcount = %d\n", info
, refs
);
205 object_header_t
*get_handle_object( HINTERNET hinternet
)
207 object_header_t
*info
= NULL
;
208 UINT_PTR handle
= (UINT_PTR
) hinternet
;
210 EnterCriticalSection( &WININET_cs
);
212 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
213 info
= WININET_AddRef(handle_table
[handle
]);
215 LeaveCriticalSection( &WININET_cs
);
217 TRACE("handle %ld -> %p\n", handle
, info
);
222 static void invalidate_handle(object_header_t
*info
)
224 object_header_t
*child
, *next
;
226 if(!info
->valid_handle
)
228 info
->valid_handle
= FALSE
;
230 /* Free all children as native does */
231 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
233 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
234 invalidate_handle( child
);
237 WININET_Release(info
);
240 BOOL
WININET_Release( object_header_t
*info
)
242 ULONG refs
= InterlockedDecrement(&info
->refs
);
243 TRACE( "object %p refcount = %d\n", info
, refs
);
246 invalidate_handle(info
);
247 if ( info
->vtbl
->CloseConnection
)
249 TRACE( "closing connection %p\n", info
);
250 info
->vtbl
->CloseConnection( info
);
252 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
253 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
254 || !(info
->dwInternalFlags
& INET_OPENURL
))
256 INTERNET_SendCallback(info
, info
->dwContext
,
257 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
260 TRACE( "destroying object %p\n", info
);
261 if ( info
->htype
!= WH_HINIT
)
262 list_remove( &info
->entry
);
263 info
->vtbl
->Destroy( info
);
265 if(info
->hInternet
) {
266 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
268 EnterCriticalSection( &WININET_cs
);
270 handle_table
[handle
] = NULL
;
271 if(next_handle
> handle
)
272 next_handle
= handle
;
274 LeaveCriticalSection( &WININET_cs
);
282 /***********************************************************************
283 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
286 * hinstDLL [I] handle to the DLL's instance
288 * lpvReserved [I] reserved, must be NULL
295 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
297 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
300 case DLL_PROCESS_ATTACH
:
302 g_dwTlsErrIndex
= TlsAlloc();
304 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
309 TlsFree(g_dwTlsErrIndex
);
313 WININET_hModule
= hinstDLL
;
316 case DLL_THREAD_ATTACH
:
319 case DLL_THREAD_DETACH
:
320 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
322 heap_free(TlsGetValue(g_dwTlsErrIndex
));
326 case DLL_PROCESS_DETACH
:
327 if (lpvReserved
) break;
328 collect_connections(COLLECT_CLEANUP
);
333 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
335 heap_free(TlsGetValue(g_dwTlsErrIndex
));
336 TlsFree(g_dwTlsErrIndex
);
343 /***********************************************************************
344 * INTERNET_SaveProxySettings
346 * Stores the proxy settings given by lpwai into the registry
349 * ERROR_SUCCESS if no error, or error code on fail
351 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
356 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
359 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
367 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
375 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
383 return ERROR_SUCCESS
;
386 /***********************************************************************
387 * INTERNET_FindProxyForProtocol
389 * Searches the proxy string for a proxy of the given protocol.
390 * Returns the found proxy, or the default proxy if none of the given
394 * szProxy [In] proxy string to search
395 * proto [In] protocol to search for, e.g. "http"
396 * foundProxy [Out] found proxy
397 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
400 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
401 * *foundProxyLen is set to the required size in WCHARs, including the
402 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
404 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
409 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
411 /* First, look for the specified protocol (proto=scheme://host:port) */
412 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
416 if (!(end
= strchrW(ptr
, ' ')))
417 end
= ptr
+ strlenW(ptr
);
418 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
419 equal
- ptr
== strlenW(proto
) &&
420 !strncmpiW(proto
, ptr
, strlenW(proto
)))
422 if (end
- equal
> *foundProxyLen
)
424 WARN("buffer too short for %s\n",
425 debugstr_wn(equal
+ 1, end
- equal
- 1));
426 *foundProxyLen
= end
- equal
;
427 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
431 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
432 foundProxy
[end
- equal
] = 0;
443 /* It wasn't found: look for no protocol */
444 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
448 if (!(end
= strchrW(ptr
, ' ')))
449 end
= ptr
+ strlenW(ptr
);
450 if (!strchrW(ptr
, '='))
452 if (end
- ptr
+ 1 > *foundProxyLen
)
454 WARN("buffer too short for %s\n",
455 debugstr_wn(ptr
, end
- ptr
));
456 *foundProxyLen
= end
- ptr
+ 1;
457 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
461 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
462 foundProxy
[end
- ptr
] = 0;
473 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
474 debugstr_w(foundProxy
));
478 /***********************************************************************
479 * InternetInitializeAutoProxyDll (WININET.@)
481 * Setup the internal proxy
490 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
493 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
497 /***********************************************************************
498 * DetectAutoProxyUrl (WININET.@)
500 * Auto detect the proxy url
506 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
507 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
510 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
514 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
516 heap_free(lpwpi
->proxy
);
517 heap_free(lpwpi
->proxyBypass
);
518 heap_free(lpwpi
->proxyUsername
);
519 heap_free(lpwpi
->proxyPassword
);
522 static proxyinfo_t
*global_proxy
;
524 static void free_global_proxy( void )
526 EnterCriticalSection( &WININET_cs
);
529 FreeProxyInfo( global_proxy
);
530 heap_free( global_proxy
);
532 LeaveCriticalSection( &WININET_cs
);
535 static BOOL
parse_proxy_url( proxyinfo_t
*info
, const WCHAR
*url
)
537 static const WCHAR fmt
[] = {'%','s',':','%','u',0};
538 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
] = {};
539 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
] = {};
540 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
] = {};
543 memset( &uc
, 0, sizeof(uc
) );
544 uc
.dwStructSize
= sizeof(uc
);
545 uc
.lpszHostName
= hostname
;
546 uc
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
547 uc
.lpszUserName
= username
;
548 uc
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
549 uc
.lpszPassword
= password
;
550 uc
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
552 if (!InternetCrackUrlW( url
, 0, 0, &uc
)) return FALSE
;
555 if (!(info
->proxy
= heap_strdupW( url
))) return FALSE
;
556 info
->proxyUsername
= NULL
;
557 info
->proxyPassword
= NULL
;
560 if (!(info
->proxy
= heap_alloc( (strlenW(hostname
) + 12) * sizeof(WCHAR
) ))) return FALSE
;
561 sprintfW( info
->proxy
, fmt
, hostname
, uc
.nPort
);
563 if (!username
[0]) info
->proxyUsername
= NULL
;
564 else if (!(info
->proxyUsername
= heap_strdupW( username
)))
566 heap_free( info
->proxy
);
569 if (!password
[0]) info
->proxyPassword
= NULL
;
570 else if (!(info
->proxyPassword
= heap_strdupW( password
)))
572 heap_free( info
->proxyUsername
);
573 heap_free( info
->proxy
);
579 /***********************************************************************
580 * INTERNET_LoadProxySettings
582 * Loads proxy information from process-wide global settings, the registry,
583 * or the environment into lpwpi.
585 * The caller should call FreeProxyInfo when done with lpwpi.
588 * The proxy may be specified in the form 'http=proxy.my.org'
589 * Presumably that means there can be ftp=ftpproxy.my.org too.
591 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
598 memset( lpwpi
, 0, sizeof(*lpwpi
) );
600 EnterCriticalSection( &WININET_cs
);
603 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
604 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
605 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
607 LeaveCriticalSection( &WININET_cs
);
609 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
611 FreeProxyInfo( lpwpi
);
616 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
618 lpwpi
->proxyEnabled
= 0;
619 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
621 FreeProxyInfo( lpwpi
);
627 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
629 /* figure out how much memory the proxy setting takes */
630 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
633 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
635 if (!(szProxy
= heap_alloc(len
)))
638 FreeProxyInfo( lpwpi
);
639 return ERROR_OUTOFMEMORY
;
641 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
643 /* find the http proxy, and strip away everything else */
644 p
= strstrW( szProxy
, szHttp
);
647 p
+= lstrlenW( szHttp
);
648 lstrcpyW( szProxy
, p
);
650 p
= strchrW( szProxy
, ';' );
653 FreeProxyInfo( lpwpi
);
654 lpwpi
->proxy
= szProxy
;
655 lpwpi
->proxyBypass
= NULL
;
657 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi
->proxy
));
661 TRACE("No proxy server settings in registry.\n");
662 FreeProxyInfo( lpwpi
);
664 lpwpi
->proxyBypass
= NULL
;
671 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
672 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
675 return ERROR_OUTOFMEMORY
;
677 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
679 FreeProxyInfo( lpwpi
);
680 if (parse_proxy_url( lpwpi
, envproxyW
))
682 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
683 lpwpi
->proxyEnabled
= 1;
684 lpwpi
->proxyBypass
= NULL
;
688 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW
));
689 lpwpi
->proxyEnabled
= 0;
691 lpwpi
->proxyBypass
= NULL
;
693 heap_free( envproxyW
);
696 if (lpwpi
->proxyEnabled
)
698 TRACE("Proxy is enabled.\n");
700 if (!(envproxy
= getenv( "no_proxy" )))
702 /* figure out how much memory the proxy setting takes */
703 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
707 if (!(szProxy
= heap_alloc(len
)))
710 return ERROR_OUTOFMEMORY
;
712 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
714 heap_free( lpwpi
->proxyBypass
);
715 lpwpi
->proxyBypass
= szProxy
;
717 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
721 heap_free( lpwpi
->proxyBypass
);
722 lpwpi
->proxyBypass
= NULL
;
724 TRACE("No proxy bypass server settings in registry.\n");
731 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
732 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
735 return ERROR_OUTOFMEMORY
;
737 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
739 heap_free( lpwpi
->proxyBypass
);
740 lpwpi
->proxyBypass
= envproxyW
;
742 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
745 else TRACE("Proxy is disabled.\n");
748 return ERROR_SUCCESS
;
751 /***********************************************************************
752 * INTERNET_ConfigureProxy
754 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
758 if (INTERNET_LoadProxySettings( &wpi
))
761 if (wpi
.proxyEnabled
)
763 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai
->proxy
), debugstr_w(lpwai
->proxyBypass
));
765 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
766 lpwai
->proxy
= wpi
.proxy
;
767 lpwai
->proxyBypass
= wpi
.proxyBypass
;
768 lpwai
->proxyUsername
= wpi
.proxyUsername
;
769 lpwai
->proxyPassword
= wpi
.proxyPassword
;
773 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
778 /***********************************************************************
779 * dump_INTERNET_FLAGS
781 * Helper function to TRACE the internet flags.
787 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
789 #define FE(x) { x, #x }
790 static const wininet_flag_info flag
[] = {
791 FE(INTERNET_FLAG_RELOAD
),
792 FE(INTERNET_FLAG_RAW_DATA
),
793 FE(INTERNET_FLAG_EXISTING_CONNECT
),
794 FE(INTERNET_FLAG_ASYNC
),
795 FE(INTERNET_FLAG_PASSIVE
),
796 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
797 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
798 FE(INTERNET_FLAG_FROM_CACHE
),
799 FE(INTERNET_FLAG_SECURE
),
800 FE(INTERNET_FLAG_KEEP_CONNECTION
),
801 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
802 FE(INTERNET_FLAG_READ_PREFETCH
),
803 FE(INTERNET_FLAG_NO_COOKIES
),
804 FE(INTERNET_FLAG_NO_AUTH
),
805 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
806 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
807 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
808 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
809 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
810 FE(INTERNET_FLAG_RESYNCHRONIZE
),
811 FE(INTERNET_FLAG_HYPERLINK
),
812 FE(INTERNET_FLAG_NO_UI
),
813 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
814 FE(INTERNET_FLAG_CACHE_ASYNC
),
815 FE(INTERNET_FLAG_FORMS_SUBMIT
),
816 FE(INTERNET_FLAG_NEED_FILE
),
817 FE(INTERNET_FLAG_TRANSFER_ASCII
),
818 FE(INTERNET_FLAG_TRANSFER_BINARY
)
823 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
824 if (flag
[i
].val
& dwFlags
) {
825 TRACE(" %s", flag
[i
].name
);
826 dwFlags
&= ~flag
[i
].val
;
830 TRACE(" Unknown flags (%08x)\n", dwFlags
);
835 /***********************************************************************
836 * INTERNET_CloseHandle (internal)
838 * Close internet handle
841 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
843 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
847 heap_free(lpwai
->agent
);
848 heap_free(lpwai
->proxy
);
849 heap_free(lpwai
->proxyBypass
);
850 heap_free(lpwai
->proxyUsername
);
851 heap_free(lpwai
->proxyPassword
);
854 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
856 appinfo_t
*ai
= (appinfo_t
*)hdr
;
859 case INTERNET_OPTION_HANDLE_TYPE
:
860 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
862 if (*size
< sizeof(ULONG
))
863 return ERROR_INSUFFICIENT_BUFFER
;
865 *size
= sizeof(DWORD
);
866 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
867 return ERROR_SUCCESS
;
869 case INTERNET_OPTION_USER_AGENT
: {
872 TRACE("INTERNET_OPTION_USER_AGENT\n");
877 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
879 *size
= (len
+ 1) * sizeof(WCHAR
);
880 if(!buffer
|| bufsize
< *size
)
881 return ERROR_INSUFFICIENT_BUFFER
;
884 strcpyW(buffer
, ai
->agent
);
886 *(WCHAR
*)buffer
= 0;
887 /* If the buffer is copied, the returned length doesn't include
888 * the NULL terminator.
893 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
896 if(!buffer
|| bufsize
< *size
)
897 return ERROR_INSUFFICIENT_BUFFER
;
900 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
903 /* If the buffer is copied, the returned length doesn't include
904 * the NULL terminator.
909 return ERROR_SUCCESS
;
912 case INTERNET_OPTION_PROXY
:
913 if(!size
) return ERROR_INVALID_PARAMETER
;
915 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
916 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
917 LPWSTR proxy
, proxy_bypass
;
920 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
922 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
923 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
925 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
926 return ERROR_INSUFFICIENT_BUFFER
;
928 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
929 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
931 pi
->dwAccessType
= ai
->accessType
;
932 pi
->lpszProxy
= NULL
;
933 pi
->lpszProxyBypass
= NULL
;
935 lstrcpyW(proxy
, ai
->proxy
);
936 pi
->lpszProxy
= proxy
;
939 if (ai
->proxyBypass
) {
940 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
941 pi
->lpszProxyBypass
= proxy_bypass
;
944 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
945 return ERROR_SUCCESS
;
947 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
948 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
949 LPSTR proxy
, proxy_bypass
;
952 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
954 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
955 NULL
, 0, NULL
, NULL
);
956 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
958 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
959 return ERROR_INSUFFICIENT_BUFFER
;
961 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
962 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
964 pi
->dwAccessType
= ai
->accessType
;
965 pi
->lpszProxy
= NULL
;
966 pi
->lpszProxyBypass
= NULL
;
968 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
969 pi
->lpszProxy
= proxy
;
972 if (ai
->proxyBypass
) {
973 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
974 proxyBypassBytesRequired
, NULL
, NULL
);
975 pi
->lpszProxyBypass
= proxy_bypass
;
978 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
979 return ERROR_SUCCESS
;
982 case INTERNET_OPTION_CONNECT_TIMEOUT
:
983 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
985 if (*size
< sizeof(ULONG
))
986 return ERROR_INSUFFICIENT_BUFFER
;
988 *(ULONG
*)buffer
= ai
->connect_timeout
;
989 *size
= sizeof(ULONG
);
991 return ERROR_SUCCESS
;
994 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
997 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
999 appinfo_t
*ai
= (appinfo_t
*)hdr
;
1002 case INTERNET_OPTION_CONNECT_TIMEOUT
:
1003 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
1005 if(size
!= sizeof(connect_timeout
))
1006 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
1008 return ERROR_BAD_ARGUMENTS
;
1010 ai
->connect_timeout
= *(ULONG
*)buf
;
1011 return ERROR_SUCCESS
;
1012 case INTERNET_OPTION_USER_AGENT
:
1013 heap_free(ai
->agent
);
1014 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
1015 return ERROR_SUCCESS
;
1018 return INET_SetOption(hdr
, option
, buf
, size
);
1021 static const object_vtbl_t APPINFOVtbl
= {
1024 APPINFO_QueryOption
,
1033 /***********************************************************************
1034 * InternetOpenW (WININET.@)
1036 * Per-application initialization of wininet
1039 * HINTERNET on success
1043 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
1044 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
1046 appinfo_t
*lpwai
= NULL
;
1048 if (TRACE_ON(wininet
)) {
1049 #define FE(x) { x, #x }
1050 static const wininet_flag_info access_type
[] = {
1051 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
1052 FE(INTERNET_OPEN_TYPE_DIRECT
),
1053 FE(INTERNET_OPEN_TYPE_PROXY
),
1054 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
1058 const char *access_type_str
= "Unknown";
1060 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1061 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1062 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
1063 if (access_type
[i
].val
== dwAccessType
) {
1064 access_type_str
= access_type
[i
].name
;
1068 TRACE(" access type : %s\n", access_type_str
);
1070 dump_INTERNET_FLAGS(dwFlags
);
1073 /* Clear any error information */
1074 INTERNET_SetLastError(0);
1076 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1077 SetLastError(ERROR_INVALID_PARAMETER
);
1081 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1083 SetLastError(ERROR_OUTOFMEMORY
);
1087 lpwai
->hdr
.htype
= WH_HINIT
;
1088 lpwai
->hdr
.dwFlags
= dwFlags
;
1089 lpwai
->accessType
= dwAccessType
;
1090 lpwai
->proxyUsername
= NULL
;
1091 lpwai
->proxyPassword
= NULL
;
1092 lpwai
->connect_timeout
= connect_timeout
;
1094 lpwai
->agent
= heap_strdupW(lpszAgent
);
1095 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1096 INTERNET_ConfigureProxy( lpwai
);
1097 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1098 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1099 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1102 TRACE("returning %p\n", lpwai
);
1104 return lpwai
->hdr
.hInternet
;
1108 /***********************************************************************
1109 * InternetOpenA (WININET.@)
1111 * Per-application initialization of wininet
1114 * HINTERNET on success
1118 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1119 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1121 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1124 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1125 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1127 szAgent
= heap_strdupAtoW(lpszAgent
);
1128 szProxy
= heap_strdupAtoW(lpszProxy
);
1129 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1131 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1135 heap_free(szBypass
);
1139 /***********************************************************************
1140 * InternetGetLastResponseInfoA (WININET.@)
1142 * Return last wininet error description on the calling thread
1145 * TRUE on success of writing to buffer
1149 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1150 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1152 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1158 *lpdwError
= lpwite
->dwError
;
1159 if (lpwite
->dwError
)
1161 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1162 *lpdwBufferLength
= strlen(lpszBuffer
);
1165 *lpdwBufferLength
= 0;
1170 *lpdwBufferLength
= 0;
1176 /***********************************************************************
1177 * InternetGetLastResponseInfoW (WININET.@)
1179 * Return last wininet error description on the calling thread
1182 * TRUE on success of writing to buffer
1186 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1187 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1189 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1195 *lpdwError
= lpwite
->dwError
;
1196 if (lpwite
->dwError
)
1198 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1199 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1202 *lpdwBufferLength
= 0;
1207 *lpdwBufferLength
= 0;
1213 /***********************************************************************
1214 * InternetGetConnectedState (WININET.@)
1216 * Return connected state
1220 * if lpdwStatus is not null, return the status (off line,
1221 * modem, lan...) in it.
1222 * FALSE if not connected
1224 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1226 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1229 WARN("always returning LAN connection.\n");
1230 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1236 /***********************************************************************
1237 * InternetGetConnectedStateExW (WININET.@)
1239 * Return connected state
1243 * lpdwStatus [O] Flags specifying the status of the internet connection.
1244 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1245 * dwNameLen [I] Size of the buffer, in characters.
1246 * dwReserved [I] Reserved. Must be set to 0.
1250 * if lpdwStatus is not null, return the status (off line,
1251 * modem, lan...) in it.
1252 * FALSE if not connected
1255 * If the system has no available network connections, an empty string is
1256 * stored in lpszConnectionName. If there is a LAN connection, a localized
1257 * "LAN Connection" string is stored. Presumably, if only a dial-up
1258 * connection is available then the name of the dial-up connection is
1259 * returned. Why any application, other than the "Internet Settings" CPL,
1260 * would want to use this function instead of the simpler InternetGetConnectedStateW
1261 * function is beyond me.
1263 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1264 DWORD dwNameLen
, DWORD dwReserved
)
1266 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1273 WARN("always returning LAN connection.\n");
1274 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1276 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
) > 0;
1280 /***********************************************************************
1281 * InternetGetConnectedStateExA (WININET.@)
1283 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1284 DWORD dwNameLen
, DWORD dwReserved
)
1286 LPWSTR lpwszConnectionName
= NULL
;
1289 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1291 if (lpszConnectionName
&& dwNameLen
> 0)
1292 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1294 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1296 if (rc
&& lpwszConnectionName
)
1298 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1299 dwNameLen
, NULL
, NULL
);
1300 heap_free(lpwszConnectionName
);
1306 /***********************************************************************
1307 * InternetConnectW (WININET.@)
1309 * Open a ftp, gopher or http session
1312 * HINTERNET a session handle on success
1316 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1317 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1318 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1319 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1322 HINTERNET rc
= NULL
;
1323 DWORD res
= ERROR_SUCCESS
;
1325 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1326 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1327 dwService
, dwFlags
, dwContext
);
1329 if (!lpszServerName
)
1331 SetLastError(ERROR_INVALID_PARAMETER
);
1335 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1336 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1338 res
= ERROR_INVALID_HANDLE
;
1344 case INTERNET_SERVICE_FTP
:
1345 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1346 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1348 res
= INTERNET_GetLastError();
1351 case INTERNET_SERVICE_HTTP
:
1352 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1353 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1356 case INTERNET_SERVICE_GOPHER
:
1362 WININET_Release( &hIC
->hdr
);
1364 TRACE("returning %p\n", rc
);
1370 /***********************************************************************
1371 * InternetConnectA (WININET.@)
1373 * Open a ftp, gopher or http session
1376 * HINTERNET a session handle on success
1380 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1381 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1382 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1383 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1385 HINTERNET rc
= NULL
;
1386 LPWSTR szServerName
;
1390 szServerName
= heap_strdupAtoW(lpszServerName
);
1391 szUserName
= heap_strdupAtoW(lpszUserName
);
1392 szPassword
= heap_strdupAtoW(lpszPassword
);
1394 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1395 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1397 heap_free(szServerName
);
1398 heap_free(szUserName
);
1399 heap_free(szPassword
);
1404 /***********************************************************************
1405 * InternetFindNextFileA (WININET.@)
1407 * Continues a file search from a previous call to FindFirstFile
1414 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1417 WIN32_FIND_DATAW fd
;
1419 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1421 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1425 /***********************************************************************
1426 * InternetFindNextFileW (WININET.@)
1428 * Continues a file search from a previous call to FindFirstFile
1435 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1437 object_header_t
*hdr
;
1442 hdr
= get_handle_object(hFind
);
1444 WARN("Invalid handle\n");
1445 SetLastError(ERROR_INVALID_HANDLE
);
1449 if(hdr
->vtbl
->FindNextFileW
) {
1450 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1452 WARN("Handle doesn't support NextFile\n");
1453 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1456 WININET_Release(hdr
);
1458 if(res
!= ERROR_SUCCESS
)
1460 return res
== ERROR_SUCCESS
;
1463 /***********************************************************************
1464 * InternetCloseHandle (WININET.@)
1466 * Generic close handle function
1473 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1475 object_header_t
*obj
;
1477 TRACE("%p\n", hInternet
);
1479 obj
= get_handle_object( hInternet
);
1481 SetLastError(ERROR_INVALID_HANDLE
);
1485 invalidate_handle(obj
);
1486 WININET_Release(obj
);
1492 /***********************************************************************
1493 * ConvertUrlComponentValue (Internal)
1495 * Helper function for InternetCrackUrlA
1498 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1499 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1500 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1502 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1503 if (*dwComponentLen
!= 0)
1505 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1506 if (*lppszComponent
== NULL
)
1510 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1511 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1514 *lppszComponent
= NULL
;
1516 *dwComponentLen
= nASCIILength
;
1520 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1521 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1522 (*lppszComponent
)[ncpylen
]=0;
1523 *dwComponentLen
= ncpylen
;
1529 /***********************************************************************
1530 * InternetCrackUrlA (WININET.@)
1532 * See InternetCrackUrlW.
1534 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1535 LPURL_COMPONENTSA lpUrlComponents
)
1538 URL_COMPONENTSW UCW
;
1540 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1541 *scheme
= NULL
, *extra
= NULL
;
1543 TRACE("(%s %u %x %p)\n",
1544 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1545 dwUrlLength
, dwFlags
, lpUrlComponents
);
1547 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1548 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1550 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1556 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1558 /* if dwUrlLength=-1 then nLength includes null but length to
1559 InternetCrackUrlW should not include it */
1560 if (dwUrlLength
== -1) nLength
--;
1562 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1563 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1564 lpwszUrl
[nLength
] = '\0';
1566 memset(&UCW
,0,sizeof(UCW
));
1567 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1568 if (lpUrlComponents
->dwHostNameLength
)
1570 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1571 if (lpUrlComponents
->lpszHostName
)
1573 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1574 UCW
.lpszHostName
= hostname
;
1577 if (lpUrlComponents
->dwUserNameLength
)
1579 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1580 if (lpUrlComponents
->lpszUserName
)
1582 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1583 UCW
.lpszUserName
= username
;
1586 if (lpUrlComponents
->dwPasswordLength
)
1588 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1589 if (lpUrlComponents
->lpszPassword
)
1591 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1592 UCW
.lpszPassword
= password
;
1595 if (lpUrlComponents
->dwUrlPathLength
)
1597 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1598 if (lpUrlComponents
->lpszUrlPath
)
1600 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1601 UCW
.lpszUrlPath
= path
;
1604 if (lpUrlComponents
->dwSchemeLength
)
1606 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1607 if (lpUrlComponents
->lpszScheme
)
1609 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1610 UCW
.lpszScheme
= scheme
;
1613 if (lpUrlComponents
->dwExtraInfoLength
)
1615 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1616 if (lpUrlComponents
->lpszExtraInfo
)
1618 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1619 UCW
.lpszExtraInfo
= extra
;
1622 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1624 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1625 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1626 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1627 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1628 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1629 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1630 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1631 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1632 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1633 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1634 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1635 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1637 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1638 lpUrlComponents
->nPort
= UCW
.nPort
;
1640 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1641 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1642 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1643 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1644 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1646 heap_free(lpwszUrl
);
1647 heap_free(hostname
);
1648 heap_free(username
);
1649 heap_free(password
);
1656 static const WCHAR url_schemes
[][7] =
1659 {'g','o','p','h','e','r',0},
1660 {'h','t','t','p',0},
1661 {'h','t','t','p','s',0},
1662 {'f','i','l','e',0},
1663 {'n','e','w','s',0},
1664 {'m','a','i','l','t','o',0},
1668 /***********************************************************************
1669 * GetInternetSchemeW (internal)
1675 * INTERNET_SCHEME_UNKNOWN on failure
1678 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1682 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1684 if(lpszScheme
==NULL
)
1685 return INTERNET_SCHEME_UNKNOWN
;
1687 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1688 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1689 return INTERNET_SCHEME_FIRST
+ i
;
1691 return INTERNET_SCHEME_UNKNOWN
;
1694 /***********************************************************************
1695 * SetUrlComponentValueW (Internal)
1697 * Helper function for InternetCrackUrlW
1700 * lppszComponent [O] Holds the returned string
1701 * dwComponentLen [I] Holds the size of lppszComponent
1702 * [O] Holds the length of the string in lppszComponent without '\0'
1703 * lpszStart [I] Holds the string to copy from
1704 * len [I] Holds the length of lpszStart without '\0'
1711 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1713 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1715 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1718 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1720 if (*lppszComponent
== NULL
)
1722 *lppszComponent
= (LPWSTR
)lpszStart
;
1723 *dwComponentLen
= len
;
1727 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1728 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1729 (*lppszComponent
)[ncpylen
] = '\0';
1730 *dwComponentLen
= ncpylen
;
1737 /***********************************************************************
1738 * InternetCrackUrlW (WININET.@)
1740 * Break up URL into its components
1746 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1747 LPURL_COMPONENTSW lpUC
)
1751 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1754 LPCWSTR lpszParam
= NULL
;
1755 BOOL found_colon
= FALSE
;
1756 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1757 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1758 LPWSTR lpszUrl_decode
= NULL
;
1759 DWORD dwUrlLength
= dwUrlLength_orig
;
1761 TRACE("(%s %u %x %p)\n",
1762 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1763 dwUrlLength
, dwFlags
, lpUC
);
1765 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1767 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1770 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1772 if (dwFlags
& ICU_DECODE
)
1775 DWORD len
= dwUrlLength
+ 1;
1777 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1779 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1782 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1783 url_tmp
[dwUrlLength
] = 0;
1784 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1787 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1790 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1793 lpszUrl
= lpszUrl_decode
;
1799 /* Determine if the URI is absolute. */
1800 while (lpszap
- lpszUrl
< dwUrlLength
)
1802 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1814 lpszcp
= lpszUrl
; /* Relative url */
1821 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1825 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1826 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1828 /* Parse <params> */
1829 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1831 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1833 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1834 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1837 /* Get scheme first. */
1838 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1839 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1840 lpszUrl
, lpszcp
- lpszUrl
);
1842 /* Eat ':' in protocol. */
1845 /* double slash indicates the net_loc portion is present */
1846 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1850 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1854 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1856 lpszNetLoc
= lpszParam
;
1858 else if (!lpszNetLoc
)
1859 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1867 /* [<user>[<:password>]@]<host>[:<port>] */
1868 /* First find the user and password if they exist */
1870 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1871 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1873 /* username and password not specified. */
1874 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1875 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1877 else /* Parse out username and password */
1879 LPCWSTR lpszUser
= lpszcp
;
1880 LPCWSTR lpszPasswd
= lpszHost
;
1882 while (lpszcp
< lpszHost
)
1885 lpszPasswd
= lpszcp
;
1890 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1891 lpszUser
, lpszPasswd
- lpszUser
);
1893 if (lpszPasswd
!= lpszHost
)
1895 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1896 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1897 lpszHost
- lpszPasswd
);
1899 lpszcp
++; /* Advance to beginning of host */
1902 /* Parse <host><:port> */
1905 lpszPort
= lpszNetLoc
;
1907 /* special case for res:// URLs: there is no port here, so the host is the
1908 entire string up to the first '/' */
1909 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1911 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1912 lpszHost
, lpszPort
- lpszHost
);
1917 while (lpszcp
< lpszNetLoc
)
1925 /* If the scheme is "file" and the host is just one letter, it's not a host */
1926 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1929 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1934 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1935 lpszHost
, lpszPort
- lpszHost
);
1936 if (lpszPort
!= lpszNetLoc
)
1937 lpUC
->nPort
= atoiW(++lpszPort
);
1938 else switch (lpUC
->nScheme
)
1940 case INTERNET_SCHEME_HTTP
:
1941 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1943 case INTERNET_SCHEME_HTTPS
:
1944 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1946 case INTERNET_SCHEME_FTP
:
1947 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1949 case INTERNET_SCHEME_GOPHER
:
1950 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1961 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1962 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1963 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1966 /* Here lpszcp points to:
1968 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1969 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1971 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1975 /* Only truncate the parameter list if it's already been saved
1976 * in lpUC->lpszExtraInfo.
1978 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1979 len
= lpszParam
- lpszcp
;
1982 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1983 * newlines if necessary.
1985 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1986 if (lpsznewline
!= NULL
)
1987 len
= lpsznewline
- lpszcp
;
1989 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1991 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1992 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1994 WCHAR tmppath
[MAX_PATH
];
1998 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
2003 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
2004 tmppath
[len
] = '\0';
2013 /* if ends in \. or \.. append a backslash */
2014 if (tmppath
[len
- 1] == '.' &&
2015 (tmppath
[len
- 2] == '\\' ||
2016 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
2018 if (len
< MAX_PATH
- 1)
2020 tmppath
[len
] = '\\';
2021 tmppath
[len
+1] = '\0';
2025 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
2029 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
2034 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
2035 lpUC
->lpszUrlPath
[0] = 0;
2036 lpUC
->dwUrlPathLength
= 0;
2039 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
2040 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
2041 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
2042 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
2043 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
2045 heap_free( lpszUrl_decode
);
2049 /***********************************************************************
2050 * InternetAttemptConnect (WININET.@)
2052 * Attempt to make a connection to the internet
2055 * ERROR_SUCCESS on success
2056 * Error value on failure
2059 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
2062 return ERROR_SUCCESS
;
2066 /***********************************************************************
2067 * convert_url_canonicalization_flags
2069 * Helper for InternetCanonicalizeUrl
2072 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2075 * Flags suitable for UrlCanonicalize
2077 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
2079 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2081 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
2082 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
2083 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
2084 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
2085 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2086 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
2087 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
2092 /***********************************************************************
2093 * InternetCanonicalizeUrlA (WININET.@)
2095 * Escape unsafe characters and spaces
2102 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2103 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2107 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2108 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2110 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2111 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2112 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2113 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2118 /***********************************************************************
2119 * InternetCanonicalizeUrlW (WININET.@)
2121 * Escape unsafe characters and spaces
2128 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2129 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2133 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2134 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2136 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2137 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2138 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2139 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2144 /* #################################################### */
2146 static INTERNET_STATUS_CALLBACK
set_status_callback(
2147 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2149 INTERNET_STATUS_CALLBACK ret
;
2151 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2152 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2154 ret
= lpwh
->lpfnStatusCB
;
2155 lpwh
->lpfnStatusCB
= callback
;
2160 /***********************************************************************
2161 * InternetSetStatusCallbackA (WININET.@)
2163 * Sets up a callback function which is called as progress is made
2164 * during an operation.
2167 * Previous callback or NULL on success
2168 * INTERNET_INVALID_STATUS_CALLBACK on failure
2171 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2172 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2174 INTERNET_STATUS_CALLBACK retVal
;
2175 object_header_t
*lpwh
;
2177 TRACE("%p\n", hInternet
);
2179 if (!(lpwh
= get_handle_object(hInternet
)))
2180 return INTERNET_INVALID_STATUS_CALLBACK
;
2182 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2184 WININET_Release( lpwh
);
2188 /***********************************************************************
2189 * InternetSetStatusCallbackW (WININET.@)
2191 * Sets up a callback function which is called as progress is made
2192 * during an operation.
2195 * Previous callback or NULL on success
2196 * INTERNET_INVALID_STATUS_CALLBACK on failure
2199 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2200 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2202 INTERNET_STATUS_CALLBACK retVal
;
2203 object_header_t
*lpwh
;
2205 TRACE("%p\n", hInternet
);
2207 if (!(lpwh
= get_handle_object(hInternet
)))
2208 return INTERNET_INVALID_STATUS_CALLBACK
;
2210 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2212 WININET_Release( lpwh
);
2216 /***********************************************************************
2217 * InternetSetFilePointer (WININET.@)
2219 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2220 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2222 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2226 /***********************************************************************
2227 * InternetWriteFile (WININET.@)
2229 * Write data to an open internet file
2236 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2237 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2239 object_header_t
*lpwh
;
2242 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2244 lpwh
= get_handle_object( hFile
);
2246 WARN("Invalid handle\n");
2247 SetLastError(ERROR_INVALID_HANDLE
);
2251 if(lpwh
->vtbl
->WriteFile
) {
2252 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2254 WARN("No Writefile method.\n");
2255 res
= ERROR_INVALID_HANDLE
;
2258 WININET_Release( lpwh
);
2260 if(res
!= ERROR_SUCCESS
)
2262 return res
== ERROR_SUCCESS
;
2266 /***********************************************************************
2267 * InternetReadFile (WININET.@)
2269 * Read data from an open internet file
2276 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2277 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2279 object_header_t
*hdr
;
2280 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2282 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2284 hdr
= get_handle_object(hFile
);
2286 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2290 if(hdr
->vtbl
->ReadFile
)
2291 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2293 WININET_Release(hdr
);
2295 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2296 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2298 if(res
!= ERROR_SUCCESS
)
2300 return res
== ERROR_SUCCESS
;
2303 /***********************************************************************
2304 * InternetReadFileExA (WININET.@)
2306 * Read data from an open internet file
2309 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2310 * lpBuffersOut [I/O] Buffer.
2311 * dwFlags [I] Flags. See notes.
2312 * dwContext [I] Context for callbacks.
2319 * The parameter dwFlags include zero or more of the following flags:
2320 *|IRF_ASYNC - Makes the call asynchronous.
2321 *|IRF_SYNC - Makes the call synchronous.
2322 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2323 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2325 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2328 * InternetOpenUrlA(), HttpOpenRequestA()
2330 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2331 DWORD dwFlags
, DWORD_PTR dwContext
)
2333 object_header_t
*hdr
;
2334 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2336 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2338 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2339 SetLastError(ERROR_INVALID_PARAMETER
);
2343 hdr
= get_handle_object(hFile
);
2345 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2349 if(hdr
->vtbl
->ReadFileEx
)
2350 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2351 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2353 WININET_Release(hdr
);
2355 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2356 res
, lpBuffersOut
->dwBufferLength
);
2358 if(res
!= ERROR_SUCCESS
)
2360 return res
== ERROR_SUCCESS
;
2363 /***********************************************************************
2364 * InternetReadFileExW (WININET.@)
2366 * InternetReadFileExA()
2368 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2369 DWORD dwFlags
, DWORD_PTR dwContext
)
2371 object_header_t
*hdr
;
2372 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2374 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2376 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2377 SetLastError(ERROR_INVALID_PARAMETER
);
2381 hdr
= get_handle_object(hFile
);
2383 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2387 if(hdr
->vtbl
->ReadFileEx
)
2388 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2389 dwFlags
, dwContext
);
2391 WININET_Release(hdr
);
2393 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2394 res
, lpBuffer
->dwBufferLength
);
2396 if(res
!= ERROR_SUCCESS
)
2398 return res
== ERROR_SUCCESS
;
2401 static BOOL
get_proxy_autoconfig_url( char *buf
, DWORD buflen
)
2403 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2405 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2409 if (!settings
) return FALSE
;
2411 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2413 CFRelease( settings
);
2416 if (CFStringGetCString( ref
, buf
, buflen
, kCFStringEncodingASCII
))
2418 TRACE( "returning %s\n", debugstr_a(buf
) );
2421 CFRelease( settings
);
2424 FIXME( "no support on this platform\n" );
2429 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2431 /* FIXME: This function currently handles more options than it should. Options requiring
2432 * proper handles should be moved to proper functions */
2434 case INTERNET_OPTION_HTTP_VERSION
:
2435 if (*size
< sizeof(HTTP_VERSION_INFO
))
2436 return ERROR_INSUFFICIENT_BUFFER
;
2439 * Presently hardcoded to 1.1
2441 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2442 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2443 *size
= sizeof(HTTP_VERSION_INFO
);
2445 return ERROR_SUCCESS
;
2447 case INTERNET_OPTION_CONNECTED_STATE
:
2448 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2450 if (*size
< sizeof(ULONG
))
2451 return ERROR_INSUFFICIENT_BUFFER
;
2453 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2454 *size
= sizeof(ULONG
);
2456 return ERROR_SUCCESS
;
2458 case INTERNET_OPTION_PROXY
: {
2462 TRACE("Getting global proxy info\n");
2463 memset(&ai
, 0, sizeof(appinfo_t
));
2464 INTERNET_ConfigureProxy(&ai
);
2466 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2467 APPINFO_Destroy(&ai
.hdr
);
2471 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2472 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2474 if (*size
< sizeof(ULONG
))
2475 return ERROR_INSUFFICIENT_BUFFER
;
2477 *(ULONG
*)buffer
= max_conns
;
2478 *size
= sizeof(ULONG
);
2480 return ERROR_SUCCESS
;
2482 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2483 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2485 if (*size
< sizeof(ULONG
))
2486 return ERROR_INSUFFICIENT_BUFFER
;
2488 *(ULONG
*)buffer
= max_1_0_conns
;
2489 *size
= sizeof(ULONG
);
2491 return ERROR_SUCCESS
;
2493 case INTERNET_OPTION_SECURITY_FLAGS
:
2494 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2495 return ERROR_SUCCESS
;
2497 case INTERNET_OPTION_VERSION
: {
2498 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2500 TRACE("INTERNET_OPTION_VERSION\n");
2502 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2503 return ERROR_INSUFFICIENT_BUFFER
;
2505 memcpy(buffer
, &info
, sizeof(info
));
2506 *size
= sizeof(info
);
2508 return ERROR_SUCCESS
;
2511 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2512 char url
[INTERNET_MAX_URL_LENGTH
+ 1];
2513 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2514 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2515 DWORD res
= ERROR_SUCCESS
, i
;
2520 TRACE("Getting global proxy info\n");
2521 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2524 have_url
= get_proxy_autoconfig_url(url
, sizeof(url
));
2526 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2528 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2530 return ERROR_INSUFFICIENT_BUFFER
;
2533 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2534 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2535 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2537 switch (optionW
->dwOption
) {
2538 case INTERNET_PER_CONN_FLAGS
:
2540 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2542 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2544 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2545 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2548 case INTERNET_PER_CONN_PROXY_SERVER
:
2550 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2552 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2555 case INTERNET_PER_CONN_PROXY_BYPASS
:
2557 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2559 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2562 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2564 optionW
->Value
.pszValue
= NULL
;
2566 optionW
->Value
.pszValue
= heap_strdupAtoW(url
);
2568 optionA
->Value
.pszValue
= heap_strdupA(url
);
2571 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2572 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2575 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2576 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2577 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2578 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2579 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2580 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2584 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2585 res
= ERROR_INVALID_PARAMETER
;
2593 case INTERNET_OPTION_REQUEST_FLAGS
:
2594 case INTERNET_OPTION_USER_AGENT
:
2596 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2597 case INTERNET_OPTION_POLICY
:
2598 return ERROR_INVALID_PARAMETER
;
2599 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2600 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2602 if (*size
< sizeof(ULONG
))
2603 return ERROR_INSUFFICIENT_BUFFER
;
2605 *(ULONG
*)buffer
= connect_timeout
;
2606 *size
= sizeof(ULONG
);
2608 return ERROR_SUCCESS
;
2611 FIXME("Stub for %d\n", option
);
2612 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2615 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2618 case INTERNET_OPTION_CONTEXT_VALUE
:
2620 return ERROR_INVALID_PARAMETER
;
2622 if (*size
< sizeof(DWORD_PTR
)) {
2623 *size
= sizeof(DWORD_PTR
);
2624 return ERROR_INSUFFICIENT_BUFFER
;
2627 return ERROR_INVALID_PARAMETER
;
2629 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2630 *size
= sizeof(DWORD_PTR
);
2631 return ERROR_SUCCESS
;
2633 case INTERNET_OPTION_REQUEST_FLAGS
:
2634 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2635 *size
= sizeof(DWORD
);
2636 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2638 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2639 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2640 WARN("Called on global option %u\n", option
);
2641 return ERROR_INTERNET_INVALID_OPERATION
;
2644 /* FIXME: we shouldn't call it here */
2645 return query_global_option(option
, buffer
, size
, unicode
);
2648 /***********************************************************************
2649 * InternetQueryOptionW (WININET.@)
2651 * Queries an options on the specified handle
2658 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2659 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2661 object_header_t
*hdr
;
2662 DWORD res
= ERROR_INVALID_HANDLE
;
2664 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2667 hdr
= get_handle_object(hInternet
);
2669 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2670 WININET_Release(hdr
);
2673 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2676 if(res
!= ERROR_SUCCESS
)
2678 return res
== ERROR_SUCCESS
;
2681 /***********************************************************************
2682 * InternetQueryOptionA (WININET.@)
2684 * Queries an options on the specified handle
2691 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2692 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2694 object_header_t
*hdr
;
2695 DWORD res
= ERROR_INVALID_HANDLE
;
2697 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2700 hdr
= get_handle_object(hInternet
);
2702 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2703 WININET_Release(hdr
);
2706 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2709 if(res
!= ERROR_SUCCESS
)
2711 return res
== ERROR_SUCCESS
;
2714 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2717 case INTERNET_OPTION_CALLBACK
:
2718 WARN("Not settable option %u\n", option
);
2719 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2720 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2721 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2722 WARN("Called on global option %u\n", option
);
2723 return ERROR_INTERNET_INVALID_OPERATION
;
2726 return ERROR_INTERNET_INVALID_OPTION
;
2729 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2732 case INTERNET_OPTION_CALLBACK
:
2733 WARN("Not global option %u\n", option
);
2734 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2736 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2737 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2739 if(size
!= sizeof(max_conns
))
2740 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2742 return ERROR_BAD_ARGUMENTS
;
2744 max_conns
= *(ULONG
*)buf
;
2745 return ERROR_SUCCESS
;
2747 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2748 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2750 if(size
!= sizeof(max_1_0_conns
))
2751 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2753 return ERROR_BAD_ARGUMENTS
;
2755 max_1_0_conns
= *(ULONG
*)buf
;
2756 return ERROR_SUCCESS
;
2758 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2759 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2761 if(size
!= sizeof(connect_timeout
))
2762 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2764 return ERROR_BAD_ARGUMENTS
;
2766 connect_timeout
= *(ULONG
*)buf
;
2767 return ERROR_SUCCESS
;
2769 case INTERNET_OPTION_SETTINGS_CHANGED
:
2770 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2771 collect_connections(COLLECT_CONNECTIONS
);
2772 return ERROR_SUCCESS
;
2775 return ERROR_INTERNET_INVALID_OPTION
;
2778 /***********************************************************************
2779 * InternetSetOptionW (WININET.@)
2781 * Sets an options on the specified handle
2788 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2789 LPVOID lpBuffer
, DWORD dwBufferLength
)
2791 object_header_t
*lpwhh
;
2795 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2797 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2799 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2801 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2803 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2805 WININET_Release(lpwhh
);
2807 if(res
!= ERROR_SUCCESS
)
2810 return res
== ERROR_SUCCESS
;
2815 case INTERNET_OPTION_HTTP_VERSION
:
2817 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2818 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2821 case INTERNET_OPTION_ERROR_MASK
:
2824 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2826 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2827 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2828 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2829 SetLastError(ERROR_INVALID_PARAMETER
);
2831 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2832 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2835 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2836 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2839 case INTERNET_OPTION_PROXY
:
2841 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2843 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2845 SetLastError(ERROR_INVALID_PARAMETER
);
2850 EnterCriticalSection( &WININET_cs
);
2851 free_global_proxy();
2852 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2855 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2857 global_proxy
->proxyEnabled
= 1;
2858 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2859 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2863 global_proxy
->proxyEnabled
= 0;
2864 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2867 LeaveCriticalSection( &WININET_cs
);
2871 /* In general, each type of object should handle
2872 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2873 * get silently dropped.
2875 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2876 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2881 case INTERNET_OPTION_CODEPAGE
:
2883 ULONG codepage
= *(ULONG
*)lpBuffer
;
2884 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2887 case INTERNET_OPTION_REQUEST_PRIORITY
:
2889 ULONG priority
= *(ULONG
*)lpBuffer
;
2890 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2893 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2895 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2896 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2899 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2901 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2902 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2905 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2906 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2908 case INTERNET_OPTION_END_BROWSER_SESSION
:
2909 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2911 case INTERNET_OPTION_CONNECTED_STATE
:
2912 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2914 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2915 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2917 case INTERNET_OPTION_SEND_TIMEOUT
:
2918 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2919 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2921 ULONG timeout
= *(ULONG
*)lpBuffer
;
2922 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2925 case INTERNET_OPTION_CONNECT_RETRIES
:
2927 ULONG retries
= *(ULONG
*)lpBuffer
;
2928 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2931 case INTERNET_OPTION_CONTEXT_VALUE
:
2935 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2938 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2940 SetLastError(ERROR_INVALID_PARAMETER
);
2944 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2947 case INTERNET_OPTION_SECURITY_FLAGS
:
2948 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2950 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2951 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2953 case INTERNET_OPTION_HTTP_DECODING
:
2954 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2955 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2958 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2959 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2960 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2963 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2964 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2965 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2968 case INTERNET_OPTION_CODEPAGE_PATH
:
2969 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2970 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2973 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2974 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2975 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2978 case INTERNET_OPTION_IDN
:
2979 FIXME("INTERNET_OPTION_IDN; STUB\n");
2980 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2983 case INTERNET_OPTION_POLICY
:
2984 SetLastError(ERROR_INVALID_PARAMETER
);
2987 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2988 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2993 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2995 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2996 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2998 switch (option
->dwOption
) {
2999 case INTERNET_PER_CONN_PROXY_SERVER
:
3000 heap_free(pi
.proxy
);
3001 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
3004 case INTERNET_PER_CONN_FLAGS
:
3005 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
3006 pi
.proxyEnabled
= 1;
3009 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
3010 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
3011 pi
.proxyEnabled
= 0;
3015 case INTERNET_PER_CONN_PROXY_BYPASS
:
3016 heap_free(pi
.proxyBypass
);
3017 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
3020 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3021 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3022 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3023 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3024 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3025 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3026 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
3030 FIXME("Unknown dwOption %d\n", option
->dwOption
);
3031 SetLastError(ERROR_INVALID_PARAMETER
);
3036 if ((res
= INTERNET_SaveProxySettings(&pi
)))
3041 ret
= (res
== ERROR_SUCCESS
);
3045 FIXME("Option %d STUB\n",dwOption
);
3046 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3052 WININET_Release( lpwhh
);
3058 /***********************************************************************
3059 * InternetSetOptionA (WININET.@)
3061 * Sets an options on the specified handle.
3068 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3069 LPVOID lpBuffer
, DWORD dwBufferLength
)
3077 case INTERNET_OPTION_PROXY
:
3079 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3080 LPINTERNET_PROXY_INFOW piw
;
3081 DWORD proxlen
, prbylen
;
3084 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3085 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3086 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3087 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3088 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3089 piw
->dwAccessType
= pi
->dwAccessType
;
3090 prox
= (LPWSTR
) &piw
[1];
3091 prby
= &prox
[proxlen
+1];
3092 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3093 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3094 piw
->lpszProxy
= prox
;
3095 piw
->lpszProxyBypass
= prby
;
3098 case INTERNET_OPTION_USER_AGENT
:
3099 case INTERNET_OPTION_USERNAME
:
3100 case INTERNET_OPTION_PASSWORD
:
3101 case INTERNET_OPTION_PROXY_USERNAME
:
3102 case INTERNET_OPTION_PROXY_PASSWORD
:
3103 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3104 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3105 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3107 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3109 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3110 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3111 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3112 wbuffer
= heap_alloc(wlen
);
3115 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3116 if (listA
->pszConnection
)
3118 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3119 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3120 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3123 listW
->pszConnection
= NULL
;
3124 listW
->dwOptionCount
= listA
->dwOptionCount
;
3125 listW
->dwOptionError
= listA
->dwOptionError
;
3126 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3128 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3129 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3130 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3132 optW
->dwOption
= optA
->dwOption
;
3134 switch (optA
->dwOption
) {
3135 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3136 case INTERNET_PER_CONN_PROXY_BYPASS
:
3137 case INTERNET_PER_CONN_PROXY_SERVER
:
3138 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3139 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3140 if (optA
->Value
.pszValue
)
3142 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3143 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3144 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3147 optW
->Value
.pszValue
= NULL
;
3149 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3150 case INTERNET_PER_CONN_FLAGS
:
3151 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3152 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3154 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3155 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3158 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3159 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3167 wlen
= dwBufferLength
;
3170 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3172 if( lpBuffer
!= wbuffer
)
3174 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3176 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3178 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3179 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3180 switch (opt
->dwOption
) {
3181 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3182 case INTERNET_PER_CONN_PROXY_BYPASS
:
3183 case INTERNET_PER_CONN_PROXY_SERVER
:
3184 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3185 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3186 heap_free( opt
->Value
.pszValue
);
3192 heap_free( list
->pOptions
);
3194 heap_free( wbuffer
);
3201 /***********************************************************************
3202 * InternetSetOptionExA (WININET.@)
3204 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3205 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3207 FIXME("Flags %08x ignored\n", dwFlags
);
3208 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3211 /***********************************************************************
3212 * InternetSetOptionExW (WININET.@)
3214 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3215 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3217 FIXME("Flags %08x ignored\n", dwFlags
);
3218 if( dwFlags
& ~ISO_VALID_FLAGS
)
3220 SetLastError( ERROR_INVALID_PARAMETER
);
3223 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3226 static const WCHAR WININET_wkday
[7][4] =
3227 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3228 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3229 static const WCHAR WININET_month
[12][4] =
3230 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3231 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3232 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3234 /***********************************************************************
3235 * InternetTimeFromSystemTimeA (WININET.@)
3237 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3240 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3242 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3244 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3246 SetLastError(ERROR_INVALID_PARAMETER
);
3250 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3252 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3256 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3257 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3262 /***********************************************************************
3263 * InternetTimeFromSystemTimeW (WININET.@)
3265 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3267 static const WCHAR date
[] =
3268 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3269 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3271 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3273 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3275 SetLastError(ERROR_INVALID_PARAMETER
);
3279 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3281 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3285 sprintfW( string
, date
,
3286 WININET_wkday
[time
->wDayOfWeek
],
3288 WININET_month
[time
->wMonth
- 1],
3297 /***********************************************************************
3298 * InternetTimeToSystemTimeA (WININET.@)
3300 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3305 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3307 stringW
= heap_strdupAtoW(string
);
3310 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3311 heap_free( stringW
);
3316 /***********************************************************************
3317 * InternetTimeToSystemTimeW (WININET.@)
3319 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3322 const WCHAR
*s
= string
;
3325 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3327 if (!string
|| !time
) return FALSE
;
3329 /* Windows does this too */
3330 GetSystemTime( time
);
3332 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3333 * a SYSTEMTIME structure.
3336 while (*s
&& !isalphaW( *s
)) s
++;
3337 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3338 time
->wDayOfWeek
= 7;
3340 for (i
= 0; i
< 7; i
++)
3342 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3343 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3344 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3346 time
->wDayOfWeek
= i
;
3351 if (time
->wDayOfWeek
> 6) return TRUE
;
3352 while (*s
&& !isdigitW( *s
)) s
++;
3353 time
->wDay
= strtolW( s
, &end
, 10 );
3356 while (*s
&& !isalphaW( *s
)) s
++;
3357 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3360 for (i
= 0; i
< 12; i
++)
3362 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3363 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3364 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3366 time
->wMonth
= i
+ 1;
3370 if (time
->wMonth
== 0) return TRUE
;
3372 while (*s
&& !isdigitW( *s
)) s
++;
3373 if (*s
== '\0') return TRUE
;
3374 time
->wYear
= strtolW( s
, &end
, 10 );
3377 while (*s
&& !isdigitW( *s
)) s
++;
3378 if (*s
== '\0') return TRUE
;
3379 time
->wHour
= strtolW( s
, &end
, 10 );
3382 while (*s
&& !isdigitW( *s
)) s
++;
3383 if (*s
== '\0') return TRUE
;
3384 time
->wMinute
= strtolW( s
, &end
, 10 );
3387 while (*s
&& !isdigitW( *s
)) s
++;
3388 if (*s
== '\0') return TRUE
;
3389 time
->wSecond
= strtolW( s
, &end
, 10 );
3392 time
->wMilliseconds
= 0;
3396 /***********************************************************************
3397 * InternetCheckConnectionW (WININET.@)
3399 * Pings a requested host to check internet connection
3402 * TRUE on success and FALSE on failure. If a failure then
3403 * ERROR_NOT_CONNECTED is placed into GetLastError
3406 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3409 * this is a kludge which runs the resident ping program and reads the output.
3411 * Anyone have a better idea?
3415 static const CHAR ping
[] = "ping -c 1 ";
3416 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3417 CHAR
*command
= NULL
;
3418 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3426 * Crack or set the Address
3428 if (lpszUrl
== NULL
)
3431 * According to the doc we are supposed to use the ip for the next
3432 * server in the WnInet internal server database. I have
3433 * no idea what that is or how to get it.
3435 * So someone needs to implement this.
3437 FIXME("Unimplemented with URL of NULL\n");
3442 URL_COMPONENTSW components
;
3444 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3445 components
.lpszHostName
= (LPWSTR
)hostW
;
3446 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3448 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3451 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3452 port
= components
.nPort
;
3453 TRACE("port: %d\n", port
);
3456 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3458 struct sockaddr_storage saddr
;
3459 socklen_t sa_len
= sizeof(saddr
);
3462 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3464 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3467 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3475 * Build our ping command
3477 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3478 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3479 strcpy(command
,ping
);
3480 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3481 strcat(command
,redirect
);
3483 TRACE("Ping command is : %s\n",command
);
3485 status
= system(command
);
3487 TRACE("Ping returned a code of %i\n",status
);
3489 /* Ping return code of 0 indicates success */
3495 heap_free( command
);
3497 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3503 /***********************************************************************
3504 * InternetCheckConnectionA (WININET.@)
3506 * Pings a requested host to check internet connection
3509 * TRUE on success and FALSE on failure. If a failure then
3510 * ERROR_NOT_CONNECTED is placed into GetLastError
3513 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3519 url
= heap_strdupAtoW(lpszUrl
);
3524 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3531 /**********************************************************
3532 * INTERNET_InternetOpenUrlW (internal)
3537 * handle of connection or NULL on failure
3539 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3540 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3542 URL_COMPONENTSW urlComponents
;
3543 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3544 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3545 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3546 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3547 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3549 HINTERNET client
= NULL
, client1
= NULL
;
3552 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3553 dwHeadersLength
, dwFlags
, dwContext
);
3555 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3556 urlComponents
.lpszScheme
= protocol
;
3557 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3558 urlComponents
.lpszHostName
= hostName
;
3559 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3560 urlComponents
.lpszUserName
= userName
;
3561 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3562 urlComponents
.lpszPassword
= password
;
3563 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3564 urlComponents
.lpszUrlPath
= path
;
3565 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3566 urlComponents
.lpszExtraInfo
= extra
;
3567 urlComponents
.dwExtraInfoLength
= 1024;
3568 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3570 switch(urlComponents
.nScheme
) {
3571 case INTERNET_SCHEME_FTP
:
3572 if(urlComponents
.nPort
== 0)
3573 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3574 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3575 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3578 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3579 if(client1
== NULL
) {
3580 InternetCloseHandle(client
);
3585 case INTERNET_SCHEME_HTTP
:
3586 case INTERNET_SCHEME_HTTPS
: {
3587 static const WCHAR szStars
[] = { '*','/','*', 0 };
3588 LPCWSTR accept
[2] = { szStars
, NULL
};
3589 if(urlComponents
.nPort
== 0) {
3590 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3591 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3593 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3595 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3597 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3598 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3599 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3600 if(res
!= ERROR_SUCCESS
) {
3601 INTERNET_SetLastError(res
);
3605 if (urlComponents
.dwExtraInfoLength
) {
3607 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3609 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3611 InternetCloseHandle(client
);
3614 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3615 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3616 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3617 heap_free(path_extra
);
3620 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3622 if(client1
== NULL
) {
3623 InternetCloseHandle(client
);
3626 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3627 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3628 GetLastError() != ERROR_IO_PENDING
) {
3629 InternetCloseHandle(client1
);
3634 case INTERNET_SCHEME_GOPHER
:
3635 /* gopher doesn't seem to be implemented in wine, but it's supposed
3636 * to be supported by InternetOpenUrlA. */
3638 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3642 TRACE(" %p <--\n", client1
);
3647 /**********************************************************
3648 * InternetOpenUrlW (WININET.@)
3653 * handle of connection or NULL on failure
3664 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3666 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3668 TRACE("%p\n", task
->hdr
.hdr
);
3670 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3671 task
->headers_len
, task
->flags
, task
->context
);
3672 heap_free(task
->url
);
3673 heap_free(task
->headers
);
3676 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3677 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3679 HINTERNET ret
= NULL
;
3680 appinfo_t
*hIC
= NULL
;
3682 if (TRACE_ON(wininet
)) {
3683 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3684 dwHeadersLength
, dwFlags
, dwContext
);
3686 dump_INTERNET_FLAGS(dwFlags
);
3691 SetLastError(ERROR_INVALID_PARAMETER
);
3695 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3696 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3697 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3701 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3702 open_url_task_t
*task
;
3704 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3705 task
->url
= heap_strdupW(lpszUrl
);
3706 task
->headers
= heap_strdupW(lpszHeaders
);
3707 task
->headers_len
= dwHeadersLength
;
3708 task
->flags
= dwFlags
;
3709 task
->context
= dwContext
;
3711 INTERNET_AsyncCall(&task
->hdr
);
3712 SetLastError(ERROR_IO_PENDING
);
3714 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3719 WININET_Release( &hIC
->hdr
);
3720 TRACE(" %p <--\n", ret
);
3725 /**********************************************************
3726 * InternetOpenUrlA (WININET.@)
3731 * handle of connection or NULL on failure
3733 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3734 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3736 HINTERNET rc
= NULL
;
3737 DWORD lenHeaders
= 0;
3738 LPWSTR szUrl
= NULL
;
3739 LPWSTR szHeaders
= NULL
;
3744 szUrl
= heap_strdupAtoW(lpszUrl
);
3750 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3751 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3756 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3759 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3760 lenHeaders
, dwFlags
, dwContext
);
3763 heap_free(szHeaders
);
3768 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3770 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3774 lpwite
->dwError
= 0;
3775 lpwite
->response
[0] = '\0';
3778 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3787 /***********************************************************************
3788 * INTERNET_SetLastError (internal)
3790 * Set last thread specific error
3795 void INTERNET_SetLastError(DWORD dwError
)
3797 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3800 lpwite
= INTERNET_AllocThreadError();
3802 SetLastError(dwError
);
3804 lpwite
->dwError
= dwError
;
3808 /***********************************************************************
3809 * INTERNET_GetLastError (internal)
3811 * Get last thread specific error
3816 DWORD
INTERNET_GetLastError(void)
3818 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3819 if (!lpwite
) return 0;
3820 /* TlsGetValue clears last error, so set it again here */
3821 SetLastError(lpwite
->dwError
);
3822 return lpwite
->dwError
;
3826 /***********************************************************************
3827 * INTERNET_WorkerThreadFunc (internal)
3829 * Worker thread execution function
3834 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3836 task_header_t
*task
= lpvParam
;
3841 WININET_Release(task
->hdr
);
3844 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3846 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3847 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3852 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3854 task_header_t
*task
;
3856 task
= heap_alloc(size
);
3860 task
->hdr
= WININET_AddRef(hdr
);
3865 /***********************************************************************
3866 * INTERNET_AsyncCall (internal)
3868 * Retrieves work request from queue
3873 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3879 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3883 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3885 return ERROR_SUCCESS
;
3889 /***********************************************************************
3890 * INTERNET_GetResponseBuffer (internal)
3895 LPSTR
INTERNET_GetResponseBuffer(void)
3897 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3899 lpwite
= INTERNET_AllocThreadError();
3901 return lpwite
->response
;
3904 /***********************************************************************
3905 * INTERNET_GetNextLine (internal)
3907 * Parse next line in directory string listing
3910 * Pointer to beginning of next line
3915 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3918 BOOL bSuccess
= FALSE
;
3920 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3925 pfd
.events
= POLLIN
;
3927 while (nRecv
< MAX_REPLY_LEN
)
3929 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3931 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3933 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3937 if (lpszBuffer
[nRecv
] == '\n')
3942 if (lpszBuffer
[nRecv
] != '\r')
3947 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3955 lpszBuffer
[nRecv
] = '\0';
3957 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3966 /**********************************************************
3967 * InternetQueryDataAvailable (WININET.@)
3969 * Determines how much data is available to be read.
3972 * TRUE on success, FALSE if an error occurred. If
3973 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3974 * no data is presently available, FALSE is returned with
3975 * the last error ERROR_IO_PENDING; a callback with status
3976 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3977 * data is available.
3979 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3980 LPDWORD lpdwNumberOfBytesAvailable
,
3981 DWORD dwFlags
, DWORD_PTR dwContext
)
3983 object_header_t
*hdr
;
3986 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3988 hdr
= get_handle_object( hFile
);
3990 SetLastError(ERROR_INVALID_HANDLE
);
3994 if(hdr
->vtbl
->QueryDataAvailable
) {
3995 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3997 WARN("wrong handle\n");
3998 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4001 WININET_Release(hdr
);
4003 if(res
!= ERROR_SUCCESS
)
4005 return res
== ERROR_SUCCESS
;
4008 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
4010 req_file_t
*req_file
;
4012 req_file
= heap_alloc_zero(sizeof(*req_file
));
4014 return ERROR_NOT_ENOUGH_MEMORY
;
4018 req_file
->file_name
= heap_strdupW(file_name
);
4019 if(!req_file
->file_name
) {
4020 heap_free(req_file
);
4021 return ERROR_NOT_ENOUGH_MEMORY
;
4024 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
4025 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
4026 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
4027 req_file_release(req_file
);
4028 return GetLastError();
4032 return ERROR_SUCCESS
;
4035 void req_file_release(req_file_t
*req_file
)
4037 if(InterlockedDecrement(&req_file
->ref
))
4040 if(!req_file
->is_committed
)
4041 DeleteFileW(req_file
->file_name
);
4042 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
4043 CloseHandle(req_file
->file_handle
);
4044 heap_free(req_file
->file_name
);
4045 heap_free(req_file
);
4048 /***********************************************************************
4049 * InternetLockRequestFile (WININET.@)
4051 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
4053 req_file_t
*req_file
= NULL
;
4054 object_header_t
*hdr
;
4057 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
4059 hdr
= get_handle_object(hInternet
);
4061 SetLastError(ERROR_INVALID_HANDLE
);
4065 if(hdr
->vtbl
->LockRequestFile
) {
4066 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
4068 WARN("wrong handle\n");
4069 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4072 WININET_Release(hdr
);
4074 *lphLockReqHandle
= req_file
;
4075 if(res
!= ERROR_SUCCESS
)
4077 return res
== ERROR_SUCCESS
;
4080 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
4082 TRACE("(%p)\n", hLockHandle
);
4084 req_file_release(hLockHandle
);
4089 /***********************************************************************
4090 * InternetAutodial (WININET.@)
4092 * On windows this function is supposed to dial the default internet
4093 * connection. We don't want to have Wine dial out to the internet so
4094 * we return TRUE by default. It might be nice to check if we are connected.
4101 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
4105 /* Tell that we are connected to the internet. */
4109 /***********************************************************************
4110 * InternetAutodialHangup (WININET.@)
4112 * Hangs up a connection made with InternetAutodial
4121 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
4125 /* we didn't dial, we don't disconnect */
4129 /***********************************************************************
4130 * InternetCombineUrlA (WININET.@)
4132 * Combine a base URL with a relative URL
4140 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
4141 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4146 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4148 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4149 dwFlags
^= ICU_NO_ENCODE
;
4150 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4155 /***********************************************************************
4156 * InternetCombineUrlW (WININET.@)
4158 * Combine a base URL with a relative URL
4166 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4167 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4172 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4174 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4175 dwFlags
^= ICU_NO_ENCODE
;
4176 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4181 /* max port num is 65535 => 5 digits */
4182 #define MAX_WORD_DIGITS 5
4184 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4185 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4186 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4187 (url)->dw##component##Length : strlen((url)->lpsz##component))
4189 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4191 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4192 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4194 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4195 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4197 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4198 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4200 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4201 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4204 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4210 /* opaque urls do not fit into the standard url hierarchy and don't have
4211 * two following slashes */
4212 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4214 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4215 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4216 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4217 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4218 (nScheme
!= INTERNET_SCHEME_FILE
);
4221 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4224 if (scheme
< INTERNET_SCHEME_FIRST
)
4226 index
= scheme
- INTERNET_SCHEME_FIRST
;
4227 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4229 return (LPCWSTR
)url_schemes
[index
];
4232 /* we can calculate using ansi strings because we're just
4233 * calculating string length, not size
4235 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4236 LPDWORD lpdwUrlLength
)
4238 INTERNET_SCHEME nScheme
;
4242 if (lpUrlComponents
->lpszScheme
)
4244 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4245 *lpdwUrlLength
+= dwLen
;
4246 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4252 nScheme
= lpUrlComponents
->nScheme
;
4254 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4255 nScheme
= INTERNET_SCHEME_HTTP
;
4256 scheme
= INTERNET_GetSchemeString(nScheme
);
4257 *lpdwUrlLength
+= strlenW(scheme
);
4260 (*lpdwUrlLength
)++; /* ':' */
4261 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4262 *lpdwUrlLength
+= strlen("//");
4264 if (lpUrlComponents
->lpszUserName
)
4266 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4267 *lpdwUrlLength
+= strlen("@");
4271 if (lpUrlComponents
->lpszPassword
)
4273 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4278 if (lpUrlComponents
->lpszPassword
)
4280 *lpdwUrlLength
+= strlen(":");
4281 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4284 if (lpUrlComponents
->lpszHostName
)
4286 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4288 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4290 char szPort
[MAX_WORD_DIGITS
+1];
4292 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4293 *lpdwUrlLength
+= strlen(szPort
);
4294 *lpdwUrlLength
+= strlen(":");
4297 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4298 (*lpdwUrlLength
)++; /* '/' */
4301 if (lpUrlComponents
->lpszUrlPath
)
4302 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4304 if (lpUrlComponents
->lpszExtraInfo
)
4305 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4310 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4314 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4316 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4317 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4318 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4319 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4320 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4321 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4322 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4323 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4324 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4326 if (lpUrlComponents
->lpszScheme
)
4328 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4329 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4330 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4331 -1, urlCompW
->lpszScheme
, len
);
4334 if (lpUrlComponents
->lpszHostName
)
4336 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4337 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4338 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4339 -1, urlCompW
->lpszHostName
, len
);
4342 if (lpUrlComponents
->lpszUserName
)
4344 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4345 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4346 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4347 -1, urlCompW
->lpszUserName
, len
);
4350 if (lpUrlComponents
->lpszPassword
)
4352 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4353 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4354 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4355 -1, urlCompW
->lpszPassword
, len
);
4358 if (lpUrlComponents
->lpszUrlPath
)
4360 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4361 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4362 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4363 -1, urlCompW
->lpszUrlPath
, len
);
4366 if (lpUrlComponents
->lpszExtraInfo
)
4368 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4369 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4370 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4371 -1, urlCompW
->lpszExtraInfo
, len
);
4375 /***********************************************************************
4376 * InternetCreateUrlA (WININET.@)
4378 * See InternetCreateUrlW.
4380 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4381 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4385 URL_COMPONENTSW urlCompW
;
4387 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4389 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4391 SetLastError(ERROR_INVALID_PARAMETER
);
4395 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4398 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4400 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4402 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4403 *lpdwUrlLength
/= sizeof(WCHAR
);
4405 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4406 * minus one, so add one to leave room for NULL terminator
4409 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4411 heap_free(urlCompW
.lpszScheme
);
4412 heap_free(urlCompW
.lpszHostName
);
4413 heap_free(urlCompW
.lpszUserName
);
4414 heap_free(urlCompW
.lpszPassword
);
4415 heap_free(urlCompW
.lpszUrlPath
);
4416 heap_free(urlCompW
.lpszExtraInfo
);
4421 /***********************************************************************
4422 * InternetCreateUrlW (WININET.@)
4424 * Creates a URL from its component parts.
4427 * lpUrlComponents [I] URL Components.
4428 * dwFlags [I] Flags. See notes.
4429 * lpszUrl [I] Buffer in which to store the created URL.
4430 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4431 * lpszUrl in characters. On output, the number of bytes
4432 * required to store the URL including terminator.
4436 * The dwFlags parameter can be zero or more of the following:
4437 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4444 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4445 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4448 INTERNET_SCHEME nScheme
;
4450 static const WCHAR slashSlashW
[] = {'/','/'};
4451 static const WCHAR fmtW
[] = {'%','u',0};
4453 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4455 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4457 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4461 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4464 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4466 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4467 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4471 *lpdwUrlLength
= dwLen
;
4476 if (lpUrlComponents
->lpszScheme
)
4478 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4479 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4482 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4487 nScheme
= lpUrlComponents
->nScheme
;
4489 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4490 nScheme
= INTERNET_SCHEME_HTTP
;
4492 scheme
= INTERNET_GetSchemeString(nScheme
);
4493 dwLen
= strlenW(scheme
);
4494 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4498 /* all schemes are followed by at least a colon */
4502 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4504 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4505 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4508 if (lpUrlComponents
->lpszUserName
)
4510 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4511 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4514 if (lpUrlComponents
->lpszPassword
)
4519 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4520 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4528 if (lpUrlComponents
->lpszHostName
)
4530 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4531 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4534 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4536 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4538 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4541 dwLen
= strlenW(szPort
);
4542 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4546 /* add slash between hostname and path if necessary */
4547 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4554 if (lpUrlComponents
->lpszUrlPath
)
4556 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4557 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4561 if (lpUrlComponents
->lpszExtraInfo
)
4563 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4564 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4573 /***********************************************************************
4574 * InternetConfirmZoneCrossingA (WININET.@)
4577 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4579 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4580 return ERROR_SUCCESS
;
4583 /***********************************************************************
4584 * InternetConfirmZoneCrossingW (WININET.@)
4587 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4589 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4590 return ERROR_SUCCESS
;
4593 static DWORD zone_preference
= 3;
4595 /***********************************************************************
4596 * PrivacySetZonePreferenceW (WININET.@)
4598 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4600 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4602 zone_preference
= template;
4606 /***********************************************************************
4607 * PrivacyGetZonePreferenceW (WININET.@)
4609 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4610 LPWSTR preference
, LPDWORD length
)
4612 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4614 if (template) *template = zone_preference
;
4618 /***********************************************************************
4619 * InternetGetSecurityInfoByURLA (WININET.@)
4621 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4626 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4628 url
= heap_strdupAtoW(lpszURL
);
4632 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4637 /***********************************************************************
4638 * InternetGetSecurityInfoByURLW (WININET.@)
4640 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4642 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4643 URL_COMPONENTSW url
= {sizeof(url
)};
4647 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4649 url
.lpszHostName
= hostname
;
4650 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4652 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4653 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4654 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4658 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4660 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4664 if(server
->cert_chain
) {
4665 const CERT_CHAIN_CONTEXT
*chain_dup
;
4667 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4669 *ppCertChain
= chain_dup
;
4670 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4675 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4679 server_release(server
);
4683 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4684 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4686 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4687 lpdwConnection
, dwReserved
);
4688 return ERROR_SUCCESS
;
4691 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4692 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4694 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4695 lpdwConnection
, dwReserved
);
4696 return ERROR_SUCCESS
;
4699 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4701 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4705 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4707 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4711 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4713 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4714 return ERROR_SUCCESS
;
4717 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4720 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4721 debugstr_w(pwszTarget
), pbHexHash
);
4725 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4727 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4731 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4733 FIXME("(%p, %08lx) stub\n", a
, b
);
4737 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4739 FIXME("%p: stub\n", parent
);