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 #ifdef HAVE_CORESERVICES_CORESERVICES_H
2404 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2408 if (!settings
) return FALSE
;
2410 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2412 CFRelease( settings
);
2415 if (CFStringGetCString( ref
, buf
, buflen
, kCFStringEncodingASCII
))
2417 TRACE( "returning %s\n", debugstr_a(buf
) );
2420 CFRelease( settings
);
2423 FIXME( "no support on this platform\n" );
2428 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2430 /* FIXME: This function currently handles more options than it should. Options requiring
2431 * proper handles should be moved to proper functions */
2433 case INTERNET_OPTION_HTTP_VERSION
:
2434 if (*size
< sizeof(HTTP_VERSION_INFO
))
2435 return ERROR_INSUFFICIENT_BUFFER
;
2438 * Presently hardcoded to 1.1
2440 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2441 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2442 *size
= sizeof(HTTP_VERSION_INFO
);
2444 return ERROR_SUCCESS
;
2446 case INTERNET_OPTION_CONNECTED_STATE
:
2447 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2449 if (*size
< sizeof(ULONG
))
2450 return ERROR_INSUFFICIENT_BUFFER
;
2452 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2453 *size
= sizeof(ULONG
);
2455 return ERROR_SUCCESS
;
2457 case INTERNET_OPTION_PROXY
: {
2461 TRACE("Getting global proxy info\n");
2462 memset(&ai
, 0, sizeof(appinfo_t
));
2463 INTERNET_ConfigureProxy(&ai
);
2465 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2466 APPINFO_Destroy(&ai
.hdr
);
2470 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2471 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2473 if (*size
< sizeof(ULONG
))
2474 return ERROR_INSUFFICIENT_BUFFER
;
2476 *(ULONG
*)buffer
= max_conns
;
2477 *size
= sizeof(ULONG
);
2479 return ERROR_SUCCESS
;
2481 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2482 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2484 if (*size
< sizeof(ULONG
))
2485 return ERROR_INSUFFICIENT_BUFFER
;
2487 *(ULONG
*)buffer
= max_1_0_conns
;
2488 *size
= sizeof(ULONG
);
2490 return ERROR_SUCCESS
;
2492 case INTERNET_OPTION_SECURITY_FLAGS
:
2493 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2494 return ERROR_SUCCESS
;
2496 case INTERNET_OPTION_VERSION
: {
2497 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2499 TRACE("INTERNET_OPTION_VERSION\n");
2501 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2502 return ERROR_INSUFFICIENT_BUFFER
;
2504 memcpy(buffer
, &info
, sizeof(info
));
2505 *size
= sizeof(info
);
2507 return ERROR_SUCCESS
;
2510 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2511 char url
[INTERNET_MAX_URL_LENGTH
+ 1];
2512 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2513 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2514 DWORD res
= ERROR_SUCCESS
, i
;
2519 TRACE("Getting global proxy info\n");
2520 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2523 have_url
= get_proxy_autoconfig_url(url
, sizeof(url
));
2525 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2527 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2529 return ERROR_INSUFFICIENT_BUFFER
;
2532 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2533 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2534 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2536 switch (optionW
->dwOption
) {
2537 case INTERNET_PER_CONN_FLAGS
:
2539 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2541 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2543 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2544 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2547 case INTERNET_PER_CONN_PROXY_SERVER
:
2549 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2551 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2554 case INTERNET_PER_CONN_PROXY_BYPASS
:
2556 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2558 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2561 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2563 optionW
->Value
.pszValue
= NULL
;
2565 optionW
->Value
.pszValue
= heap_strdupAtoW(url
);
2567 optionA
->Value
.pszValue
= heap_strdupA(url
);
2570 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2571 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2574 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2575 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2576 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2577 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2578 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2579 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2583 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2584 res
= ERROR_INVALID_PARAMETER
;
2592 case INTERNET_OPTION_REQUEST_FLAGS
:
2593 case INTERNET_OPTION_USER_AGENT
:
2595 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2596 case INTERNET_OPTION_POLICY
:
2597 return ERROR_INVALID_PARAMETER
;
2598 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2599 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2601 if (*size
< sizeof(ULONG
))
2602 return ERROR_INSUFFICIENT_BUFFER
;
2604 *(ULONG
*)buffer
= connect_timeout
;
2605 *size
= sizeof(ULONG
);
2607 return ERROR_SUCCESS
;
2610 FIXME("Stub for %d\n", option
);
2611 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2614 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2617 case INTERNET_OPTION_CONTEXT_VALUE
:
2619 return ERROR_INVALID_PARAMETER
;
2621 if (*size
< sizeof(DWORD_PTR
)) {
2622 *size
= sizeof(DWORD_PTR
);
2623 return ERROR_INSUFFICIENT_BUFFER
;
2626 return ERROR_INVALID_PARAMETER
;
2628 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2629 *size
= sizeof(DWORD_PTR
);
2630 return ERROR_SUCCESS
;
2632 case INTERNET_OPTION_REQUEST_FLAGS
:
2633 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2634 *size
= sizeof(DWORD
);
2635 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2637 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2638 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2639 WARN("Called on global option %u\n", option
);
2640 return ERROR_INTERNET_INVALID_OPERATION
;
2643 /* FIXME: we shouldn't call it here */
2644 return query_global_option(option
, buffer
, size
, unicode
);
2647 /***********************************************************************
2648 * InternetQueryOptionW (WININET.@)
2650 * Queries an options on the specified handle
2657 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2658 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2660 object_header_t
*hdr
;
2661 DWORD res
= ERROR_INVALID_HANDLE
;
2663 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2666 hdr
= get_handle_object(hInternet
);
2668 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2669 WININET_Release(hdr
);
2672 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2675 if(res
!= ERROR_SUCCESS
)
2677 return res
== ERROR_SUCCESS
;
2680 /***********************************************************************
2681 * InternetQueryOptionA (WININET.@)
2683 * Queries an options on the specified handle
2690 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2691 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2693 object_header_t
*hdr
;
2694 DWORD res
= ERROR_INVALID_HANDLE
;
2696 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2699 hdr
= get_handle_object(hInternet
);
2701 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2702 WININET_Release(hdr
);
2705 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2708 if(res
!= ERROR_SUCCESS
)
2710 return res
== ERROR_SUCCESS
;
2713 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2716 case INTERNET_OPTION_CALLBACK
:
2717 WARN("Not settable option %u\n", option
);
2718 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2719 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2720 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2721 WARN("Called on global option %u\n", option
);
2722 return ERROR_INTERNET_INVALID_OPERATION
;
2725 return ERROR_INTERNET_INVALID_OPTION
;
2728 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2731 case INTERNET_OPTION_CALLBACK
:
2732 WARN("Not global option %u\n", option
);
2733 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2735 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2736 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2738 if(size
!= sizeof(max_conns
))
2739 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2741 return ERROR_BAD_ARGUMENTS
;
2743 max_conns
= *(ULONG
*)buf
;
2744 return ERROR_SUCCESS
;
2746 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2747 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2749 if(size
!= sizeof(max_1_0_conns
))
2750 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2752 return ERROR_BAD_ARGUMENTS
;
2754 max_1_0_conns
= *(ULONG
*)buf
;
2755 return ERROR_SUCCESS
;
2757 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2758 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2760 if(size
!= sizeof(connect_timeout
))
2761 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2763 return ERROR_BAD_ARGUMENTS
;
2765 connect_timeout
= *(ULONG
*)buf
;
2766 return ERROR_SUCCESS
;
2768 case INTERNET_OPTION_SETTINGS_CHANGED
:
2769 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2770 collect_connections(COLLECT_CONNECTIONS
);
2771 return ERROR_SUCCESS
;
2774 return ERROR_INTERNET_INVALID_OPTION
;
2777 /***********************************************************************
2778 * InternetSetOptionW (WININET.@)
2780 * Sets an options on the specified handle
2787 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2788 LPVOID lpBuffer
, DWORD dwBufferLength
)
2790 object_header_t
*lpwhh
;
2794 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2796 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2798 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2800 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2802 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2804 WININET_Release(lpwhh
);
2806 if(res
!= ERROR_SUCCESS
)
2809 return res
== ERROR_SUCCESS
;
2814 case INTERNET_OPTION_HTTP_VERSION
:
2816 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2817 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2820 case INTERNET_OPTION_ERROR_MASK
:
2823 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2825 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2826 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2827 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2828 SetLastError(ERROR_INVALID_PARAMETER
);
2830 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2831 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2834 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2835 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2838 case INTERNET_OPTION_PROXY
:
2840 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2842 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2844 SetLastError(ERROR_INVALID_PARAMETER
);
2849 EnterCriticalSection( &WININET_cs
);
2850 free_global_proxy();
2851 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2854 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2856 global_proxy
->proxyEnabled
= 1;
2857 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2858 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2862 global_proxy
->proxyEnabled
= 0;
2863 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2866 LeaveCriticalSection( &WININET_cs
);
2870 /* In general, each type of object should handle
2871 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2872 * get silently dropped.
2874 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2875 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2880 case INTERNET_OPTION_CODEPAGE
:
2882 ULONG codepage
= *(ULONG
*)lpBuffer
;
2883 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2886 case INTERNET_OPTION_REQUEST_PRIORITY
:
2888 ULONG priority
= *(ULONG
*)lpBuffer
;
2889 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2892 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2894 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2895 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2898 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2900 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2901 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2904 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2905 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2907 case INTERNET_OPTION_END_BROWSER_SESSION
:
2908 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2910 case INTERNET_OPTION_CONNECTED_STATE
:
2911 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2913 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2914 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2916 case INTERNET_OPTION_SEND_TIMEOUT
:
2917 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2918 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2920 ULONG timeout
= *(ULONG
*)lpBuffer
;
2921 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2924 case INTERNET_OPTION_CONNECT_RETRIES
:
2926 ULONG retries
= *(ULONG
*)lpBuffer
;
2927 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2930 case INTERNET_OPTION_CONTEXT_VALUE
:
2934 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2937 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2939 SetLastError(ERROR_INVALID_PARAMETER
);
2943 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2946 case INTERNET_OPTION_SECURITY_FLAGS
:
2947 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2949 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2950 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2952 case INTERNET_OPTION_HTTP_DECODING
:
2953 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2954 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2957 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2958 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2959 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2962 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2963 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2964 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2967 case INTERNET_OPTION_CODEPAGE_PATH
:
2968 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2969 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2972 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2973 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2974 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2977 case INTERNET_OPTION_IDN
:
2978 FIXME("INTERNET_OPTION_IDN; STUB\n");
2979 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2982 case INTERNET_OPTION_POLICY
:
2983 SetLastError(ERROR_INVALID_PARAMETER
);
2986 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2987 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2992 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2994 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2995 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2997 switch (option
->dwOption
) {
2998 case INTERNET_PER_CONN_PROXY_SERVER
:
2999 heap_free(pi
.proxy
);
3000 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
3003 case INTERNET_PER_CONN_FLAGS
:
3004 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
3005 pi
.proxyEnabled
= 1;
3008 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
3009 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
3010 pi
.proxyEnabled
= 0;
3014 case INTERNET_PER_CONN_PROXY_BYPASS
:
3015 heap_free(pi
.proxyBypass
);
3016 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
3019 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3020 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3021 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3022 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3023 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3024 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3025 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
3029 FIXME("Unknown dwOption %d\n", option
->dwOption
);
3030 SetLastError(ERROR_INVALID_PARAMETER
);
3035 if ((res
= INTERNET_SaveProxySettings(&pi
)))
3040 ret
= (res
== ERROR_SUCCESS
);
3044 FIXME("Option %d STUB\n",dwOption
);
3045 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3051 WININET_Release( lpwhh
);
3057 /***********************************************************************
3058 * InternetSetOptionA (WININET.@)
3060 * Sets an options on the specified handle.
3067 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3068 LPVOID lpBuffer
, DWORD dwBufferLength
)
3076 case INTERNET_OPTION_PROXY
:
3078 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3079 LPINTERNET_PROXY_INFOW piw
;
3080 DWORD proxlen
, prbylen
;
3083 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3084 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3085 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3086 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3087 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3088 piw
->dwAccessType
= pi
->dwAccessType
;
3089 prox
= (LPWSTR
) &piw
[1];
3090 prby
= &prox
[proxlen
+1];
3091 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3092 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3093 piw
->lpszProxy
= prox
;
3094 piw
->lpszProxyBypass
= prby
;
3097 case INTERNET_OPTION_USER_AGENT
:
3098 case INTERNET_OPTION_USERNAME
:
3099 case INTERNET_OPTION_PASSWORD
:
3100 case INTERNET_OPTION_PROXY_USERNAME
:
3101 case INTERNET_OPTION_PROXY_PASSWORD
:
3102 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3103 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3104 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3106 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3108 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3109 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3110 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3111 wbuffer
= heap_alloc(wlen
);
3114 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3115 if (listA
->pszConnection
)
3117 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3118 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3119 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3122 listW
->pszConnection
= NULL
;
3123 listW
->dwOptionCount
= listA
->dwOptionCount
;
3124 listW
->dwOptionError
= listA
->dwOptionError
;
3125 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3127 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3128 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3129 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3131 optW
->dwOption
= optA
->dwOption
;
3133 switch (optA
->dwOption
) {
3134 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3135 case INTERNET_PER_CONN_PROXY_BYPASS
:
3136 case INTERNET_PER_CONN_PROXY_SERVER
:
3137 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3138 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3139 if (optA
->Value
.pszValue
)
3141 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3142 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3143 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3146 optW
->Value
.pszValue
= NULL
;
3148 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3149 case INTERNET_PER_CONN_FLAGS
:
3150 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3151 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3153 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3154 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3157 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3158 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3166 wlen
= dwBufferLength
;
3169 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3171 if( lpBuffer
!= wbuffer
)
3173 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3175 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3177 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3178 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3179 switch (opt
->dwOption
) {
3180 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3181 case INTERNET_PER_CONN_PROXY_BYPASS
:
3182 case INTERNET_PER_CONN_PROXY_SERVER
:
3183 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3184 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3185 heap_free( opt
->Value
.pszValue
);
3191 heap_free( list
->pOptions
);
3193 heap_free( wbuffer
);
3200 /***********************************************************************
3201 * InternetSetOptionExA (WININET.@)
3203 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3204 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3206 FIXME("Flags %08x ignored\n", dwFlags
);
3207 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3210 /***********************************************************************
3211 * InternetSetOptionExW (WININET.@)
3213 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3214 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3216 FIXME("Flags %08x ignored\n", dwFlags
);
3217 if( dwFlags
& ~ISO_VALID_FLAGS
)
3219 SetLastError( ERROR_INVALID_PARAMETER
);
3222 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3225 static const WCHAR WININET_wkday
[7][4] =
3226 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3227 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3228 static const WCHAR WININET_month
[12][4] =
3229 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3230 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3231 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3233 /***********************************************************************
3234 * InternetTimeFromSystemTimeA (WININET.@)
3236 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3239 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3241 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3243 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3245 SetLastError(ERROR_INVALID_PARAMETER
);
3249 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3251 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3255 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3256 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3261 /***********************************************************************
3262 * InternetTimeFromSystemTimeW (WININET.@)
3264 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3266 static const WCHAR date
[] =
3267 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3268 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3270 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3272 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3274 SetLastError(ERROR_INVALID_PARAMETER
);
3278 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3280 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3284 sprintfW( string
, date
,
3285 WININET_wkday
[time
->wDayOfWeek
],
3287 WININET_month
[time
->wMonth
- 1],
3296 /***********************************************************************
3297 * InternetTimeToSystemTimeA (WININET.@)
3299 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3304 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3306 stringW
= heap_strdupAtoW(string
);
3309 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3310 heap_free( stringW
);
3315 /***********************************************************************
3316 * InternetTimeToSystemTimeW (WININET.@)
3318 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3321 const WCHAR
*s
= string
;
3324 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3326 if (!string
|| !time
) return FALSE
;
3328 /* Windows does this too */
3329 GetSystemTime( time
);
3331 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3332 * a SYSTEMTIME structure.
3335 while (*s
&& !isalphaW( *s
)) s
++;
3336 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3337 time
->wDayOfWeek
= 7;
3339 for (i
= 0; i
< 7; i
++)
3341 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3342 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3343 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3345 time
->wDayOfWeek
= i
;
3350 if (time
->wDayOfWeek
> 6) return TRUE
;
3351 while (*s
&& !isdigitW( *s
)) s
++;
3352 time
->wDay
= strtolW( s
, &end
, 10 );
3355 while (*s
&& !isalphaW( *s
)) s
++;
3356 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3359 for (i
= 0; i
< 12; i
++)
3361 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3362 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3363 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3365 time
->wMonth
= i
+ 1;
3369 if (time
->wMonth
== 0) return TRUE
;
3371 while (*s
&& !isdigitW( *s
)) s
++;
3372 if (*s
== '\0') return TRUE
;
3373 time
->wYear
= strtolW( s
, &end
, 10 );
3376 while (*s
&& !isdigitW( *s
)) s
++;
3377 if (*s
== '\0') return TRUE
;
3378 time
->wHour
= strtolW( s
, &end
, 10 );
3381 while (*s
&& !isdigitW( *s
)) s
++;
3382 if (*s
== '\0') return TRUE
;
3383 time
->wMinute
= strtolW( s
, &end
, 10 );
3386 while (*s
&& !isdigitW( *s
)) s
++;
3387 if (*s
== '\0') return TRUE
;
3388 time
->wSecond
= strtolW( s
, &end
, 10 );
3391 time
->wMilliseconds
= 0;
3395 /***********************************************************************
3396 * InternetCheckConnectionW (WININET.@)
3398 * Pings a requested host to check internet connection
3401 * TRUE on success and FALSE on failure. If a failure then
3402 * ERROR_NOT_CONNECTED is placed into GetLastError
3405 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3408 * this is a kludge which runs the resident ping program and reads the output.
3410 * Anyone have a better idea?
3414 static const CHAR ping
[] = "ping -c 1 ";
3415 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3416 CHAR
*command
= NULL
;
3417 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3425 * Crack or set the Address
3427 if (lpszUrl
== NULL
)
3430 * According to the doc we are supposed to use the ip for the next
3431 * server in the WnInet internal server database. I have
3432 * no idea what that is or how to get it.
3434 * So someone needs to implement this.
3436 FIXME("Unimplemented with URL of NULL\n");
3441 URL_COMPONENTSW components
;
3443 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3444 components
.lpszHostName
= (LPWSTR
)hostW
;
3445 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3447 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3450 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3451 port
= components
.nPort
;
3452 TRACE("port: %d\n", port
);
3455 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3457 struct sockaddr_storage saddr
;
3458 socklen_t sa_len
= sizeof(saddr
);
3461 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3463 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3466 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3474 * Build our ping command
3476 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3477 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3478 strcpy(command
,ping
);
3479 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3480 strcat(command
,redirect
);
3482 TRACE("Ping command is : %s\n",command
);
3484 status
= system(command
);
3486 TRACE("Ping returned a code of %i\n",status
);
3488 /* Ping return code of 0 indicates success */
3494 heap_free( command
);
3496 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3502 /***********************************************************************
3503 * InternetCheckConnectionA (WININET.@)
3505 * Pings a requested host to check internet connection
3508 * TRUE on success and FALSE on failure. If a failure then
3509 * ERROR_NOT_CONNECTED is placed into GetLastError
3512 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3518 url
= heap_strdupAtoW(lpszUrl
);
3523 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3530 /**********************************************************
3531 * INTERNET_InternetOpenUrlW (internal)
3536 * handle of connection or NULL on failure
3538 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3539 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3541 URL_COMPONENTSW urlComponents
;
3542 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3543 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3544 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3545 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3546 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3548 HINTERNET client
= NULL
, client1
= NULL
;
3551 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3552 dwHeadersLength
, dwFlags
, dwContext
);
3554 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3555 urlComponents
.lpszScheme
= protocol
;
3556 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3557 urlComponents
.lpszHostName
= hostName
;
3558 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3559 urlComponents
.lpszUserName
= userName
;
3560 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3561 urlComponents
.lpszPassword
= password
;
3562 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3563 urlComponents
.lpszUrlPath
= path
;
3564 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3565 urlComponents
.lpszExtraInfo
= extra
;
3566 urlComponents
.dwExtraInfoLength
= 1024;
3567 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3569 switch(urlComponents
.nScheme
) {
3570 case INTERNET_SCHEME_FTP
:
3571 if(urlComponents
.nPort
== 0)
3572 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3573 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3574 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3577 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3578 if(client1
== NULL
) {
3579 InternetCloseHandle(client
);
3584 case INTERNET_SCHEME_HTTP
:
3585 case INTERNET_SCHEME_HTTPS
: {
3586 static const WCHAR szStars
[] = { '*','/','*', 0 };
3587 LPCWSTR accept
[2] = { szStars
, NULL
};
3588 if(urlComponents
.nPort
== 0) {
3589 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3590 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3592 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3594 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3596 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3597 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3598 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3599 if(res
!= ERROR_SUCCESS
) {
3600 INTERNET_SetLastError(res
);
3604 if (urlComponents
.dwExtraInfoLength
) {
3606 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3608 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3610 InternetCloseHandle(client
);
3613 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3614 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3615 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3616 heap_free(path_extra
);
3619 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3621 if(client1
== NULL
) {
3622 InternetCloseHandle(client
);
3625 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3626 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3627 GetLastError() != ERROR_IO_PENDING
) {
3628 InternetCloseHandle(client1
);
3633 case INTERNET_SCHEME_GOPHER
:
3634 /* gopher doesn't seem to be implemented in wine, but it's supposed
3635 * to be supported by InternetOpenUrlA. */
3637 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3641 TRACE(" %p <--\n", client1
);
3646 /**********************************************************
3647 * InternetOpenUrlW (WININET.@)
3652 * handle of connection or NULL on failure
3663 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3665 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3667 TRACE("%p\n", task
->hdr
.hdr
);
3669 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3670 task
->headers_len
, task
->flags
, task
->context
);
3671 heap_free(task
->url
);
3672 heap_free(task
->headers
);
3675 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3676 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3678 HINTERNET ret
= NULL
;
3679 appinfo_t
*hIC
= NULL
;
3681 if (TRACE_ON(wininet
)) {
3682 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3683 dwHeadersLength
, dwFlags
, dwContext
);
3685 dump_INTERNET_FLAGS(dwFlags
);
3690 SetLastError(ERROR_INVALID_PARAMETER
);
3694 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3695 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3696 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3700 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3701 open_url_task_t
*task
;
3703 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3704 task
->url
= heap_strdupW(lpszUrl
);
3705 task
->headers
= heap_strdupW(lpszHeaders
);
3706 task
->headers_len
= dwHeadersLength
;
3707 task
->flags
= dwFlags
;
3708 task
->context
= dwContext
;
3710 INTERNET_AsyncCall(&task
->hdr
);
3711 SetLastError(ERROR_IO_PENDING
);
3713 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3718 WININET_Release( &hIC
->hdr
);
3719 TRACE(" %p <--\n", ret
);
3724 /**********************************************************
3725 * InternetOpenUrlA (WININET.@)
3730 * handle of connection or NULL on failure
3732 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3733 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3735 HINTERNET rc
= NULL
;
3736 DWORD lenHeaders
= 0;
3737 LPWSTR szUrl
= NULL
;
3738 LPWSTR szHeaders
= NULL
;
3743 szUrl
= heap_strdupAtoW(lpszUrl
);
3749 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3750 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3755 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3758 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3759 lenHeaders
, dwFlags
, dwContext
);
3762 heap_free(szHeaders
);
3767 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3769 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3773 lpwite
->dwError
= 0;
3774 lpwite
->response
[0] = '\0';
3777 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3786 /***********************************************************************
3787 * INTERNET_SetLastError (internal)
3789 * Set last thread specific error
3794 void INTERNET_SetLastError(DWORD dwError
)
3796 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3799 lpwite
= INTERNET_AllocThreadError();
3801 SetLastError(dwError
);
3803 lpwite
->dwError
= dwError
;
3807 /***********************************************************************
3808 * INTERNET_GetLastError (internal)
3810 * Get last thread specific error
3815 DWORD
INTERNET_GetLastError(void)
3817 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3818 if (!lpwite
) return 0;
3819 /* TlsGetValue clears last error, so set it again here */
3820 SetLastError(lpwite
->dwError
);
3821 return lpwite
->dwError
;
3825 /***********************************************************************
3826 * INTERNET_WorkerThreadFunc (internal)
3828 * Worker thread execution function
3833 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3835 task_header_t
*task
= lpvParam
;
3840 WININET_Release(task
->hdr
);
3843 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3845 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3846 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3851 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3853 task_header_t
*task
;
3855 task
= heap_alloc(size
);
3859 task
->hdr
= WININET_AddRef(hdr
);
3864 /***********************************************************************
3865 * INTERNET_AsyncCall (internal)
3867 * Retrieves work request from queue
3872 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3878 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3882 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3884 return ERROR_SUCCESS
;
3888 /***********************************************************************
3889 * INTERNET_GetResponseBuffer (internal)
3894 LPSTR
INTERNET_GetResponseBuffer(void)
3896 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3898 lpwite
= INTERNET_AllocThreadError();
3900 return lpwite
->response
;
3903 /***********************************************************************
3904 * INTERNET_GetNextLine (internal)
3906 * Parse next line in directory string listing
3909 * Pointer to beginning of next line
3914 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3917 BOOL bSuccess
= FALSE
;
3919 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3924 pfd
.events
= POLLIN
;
3926 while (nRecv
< MAX_REPLY_LEN
)
3928 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3930 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3932 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3936 if (lpszBuffer
[nRecv
] == '\n')
3941 if (lpszBuffer
[nRecv
] != '\r')
3946 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3954 lpszBuffer
[nRecv
] = '\0';
3956 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3965 /**********************************************************
3966 * InternetQueryDataAvailable (WININET.@)
3968 * Determines how much data is available to be read.
3971 * TRUE on success, FALSE if an error occurred. If
3972 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3973 * no data is presently available, FALSE is returned with
3974 * the last error ERROR_IO_PENDING; a callback with status
3975 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3976 * data is available.
3978 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3979 LPDWORD lpdwNumberOfBytesAvailable
,
3980 DWORD dwFlags
, DWORD_PTR dwContext
)
3982 object_header_t
*hdr
;
3985 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3987 hdr
= get_handle_object( hFile
);
3989 SetLastError(ERROR_INVALID_HANDLE
);
3993 if(hdr
->vtbl
->QueryDataAvailable
) {
3994 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3996 WARN("wrong handle\n");
3997 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4000 WININET_Release(hdr
);
4002 if(res
!= ERROR_SUCCESS
)
4004 return res
== ERROR_SUCCESS
;
4007 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
4009 req_file_t
*req_file
;
4011 req_file
= heap_alloc_zero(sizeof(*req_file
));
4013 return ERROR_NOT_ENOUGH_MEMORY
;
4017 req_file
->file_name
= heap_strdupW(file_name
);
4018 if(!req_file
->file_name
) {
4019 heap_free(req_file
);
4020 return ERROR_NOT_ENOUGH_MEMORY
;
4023 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
4024 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
4025 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
4026 req_file_release(req_file
);
4027 return GetLastError();
4031 return ERROR_SUCCESS
;
4034 void req_file_release(req_file_t
*req_file
)
4036 if(InterlockedDecrement(&req_file
->ref
))
4039 if(!req_file
->is_committed
)
4040 DeleteFileW(req_file
->file_name
);
4041 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
4042 CloseHandle(req_file
->file_handle
);
4043 heap_free(req_file
->file_name
);
4044 heap_free(req_file
);
4047 /***********************************************************************
4048 * InternetLockRequestFile (WININET.@)
4050 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
4052 req_file_t
*req_file
= NULL
;
4053 object_header_t
*hdr
;
4056 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
4058 hdr
= get_handle_object(hInternet
);
4060 SetLastError(ERROR_INVALID_HANDLE
);
4064 if(hdr
->vtbl
->LockRequestFile
) {
4065 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
4067 WARN("wrong handle\n");
4068 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4071 WININET_Release(hdr
);
4073 *lphLockReqHandle
= req_file
;
4074 if(res
!= ERROR_SUCCESS
)
4076 return res
== ERROR_SUCCESS
;
4079 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
4081 TRACE("(%p)\n", hLockHandle
);
4083 req_file_release(hLockHandle
);
4088 /***********************************************************************
4089 * InternetAutodial (WININET.@)
4091 * On windows this function is supposed to dial the default internet
4092 * connection. We don't want to have Wine dial out to the internet so
4093 * we return TRUE by default. It might be nice to check if we are connected.
4100 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
4104 /* Tell that we are connected to the internet. */
4108 /***********************************************************************
4109 * InternetAutodialHangup (WININET.@)
4111 * Hangs up a connection made with InternetAutodial
4120 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
4124 /* we didn't dial, we don't disconnect */
4128 /***********************************************************************
4129 * InternetCombineUrlA (WININET.@)
4131 * Combine a base URL with a relative URL
4139 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
4140 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4145 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4147 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4148 dwFlags
^= ICU_NO_ENCODE
;
4149 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4154 /***********************************************************************
4155 * InternetCombineUrlW (WININET.@)
4157 * Combine a base URL with a relative URL
4165 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4166 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4171 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4173 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4174 dwFlags
^= ICU_NO_ENCODE
;
4175 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4180 /* max port num is 65535 => 5 digits */
4181 #define MAX_WORD_DIGITS 5
4183 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4184 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4185 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4186 (url)->dw##component##Length : strlen((url)->lpsz##component))
4188 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4190 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4191 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4193 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4194 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4196 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4197 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4199 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4200 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4203 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4209 /* opaque urls do not fit into the standard url hierarchy and don't have
4210 * two following slashes */
4211 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4213 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4214 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4215 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4216 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4217 (nScheme
!= INTERNET_SCHEME_FILE
);
4220 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4223 if (scheme
< INTERNET_SCHEME_FIRST
)
4225 index
= scheme
- INTERNET_SCHEME_FIRST
;
4226 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4228 return (LPCWSTR
)url_schemes
[index
];
4231 /* we can calculate using ansi strings because we're just
4232 * calculating string length, not size
4234 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4235 LPDWORD lpdwUrlLength
)
4237 INTERNET_SCHEME nScheme
;
4241 if (lpUrlComponents
->lpszScheme
)
4243 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4244 *lpdwUrlLength
+= dwLen
;
4245 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4251 nScheme
= lpUrlComponents
->nScheme
;
4253 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4254 nScheme
= INTERNET_SCHEME_HTTP
;
4255 scheme
= INTERNET_GetSchemeString(nScheme
);
4256 *lpdwUrlLength
+= strlenW(scheme
);
4259 (*lpdwUrlLength
)++; /* ':' */
4260 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4261 *lpdwUrlLength
+= strlen("//");
4263 if (lpUrlComponents
->lpszUserName
)
4265 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4266 *lpdwUrlLength
+= strlen("@");
4270 if (lpUrlComponents
->lpszPassword
)
4272 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4277 if (lpUrlComponents
->lpszPassword
)
4279 *lpdwUrlLength
+= strlen(":");
4280 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4283 if (lpUrlComponents
->lpszHostName
)
4285 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4287 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4289 char szPort
[MAX_WORD_DIGITS
+1];
4291 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4292 *lpdwUrlLength
+= strlen(szPort
);
4293 *lpdwUrlLength
+= strlen(":");
4296 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4297 (*lpdwUrlLength
)++; /* '/' */
4300 if (lpUrlComponents
->lpszUrlPath
)
4301 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4303 if (lpUrlComponents
->lpszExtraInfo
)
4304 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4309 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4313 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4315 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4316 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4317 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4318 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4319 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4320 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4321 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4322 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4323 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4325 if (lpUrlComponents
->lpszScheme
)
4327 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4328 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4329 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4330 -1, urlCompW
->lpszScheme
, len
);
4333 if (lpUrlComponents
->lpszHostName
)
4335 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4336 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4337 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4338 -1, urlCompW
->lpszHostName
, len
);
4341 if (lpUrlComponents
->lpszUserName
)
4343 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4344 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4345 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4346 -1, urlCompW
->lpszUserName
, len
);
4349 if (lpUrlComponents
->lpszPassword
)
4351 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4352 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4353 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4354 -1, urlCompW
->lpszPassword
, len
);
4357 if (lpUrlComponents
->lpszUrlPath
)
4359 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4360 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4361 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4362 -1, urlCompW
->lpszUrlPath
, len
);
4365 if (lpUrlComponents
->lpszExtraInfo
)
4367 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4368 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4369 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4370 -1, urlCompW
->lpszExtraInfo
, len
);
4374 /***********************************************************************
4375 * InternetCreateUrlA (WININET.@)
4377 * See InternetCreateUrlW.
4379 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4380 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4384 URL_COMPONENTSW urlCompW
;
4386 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4388 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4390 SetLastError(ERROR_INVALID_PARAMETER
);
4394 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4397 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4399 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4401 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4402 *lpdwUrlLength
/= sizeof(WCHAR
);
4404 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4405 * minus one, so add one to leave room for NULL terminator
4408 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4410 heap_free(urlCompW
.lpszScheme
);
4411 heap_free(urlCompW
.lpszHostName
);
4412 heap_free(urlCompW
.lpszUserName
);
4413 heap_free(urlCompW
.lpszPassword
);
4414 heap_free(urlCompW
.lpszUrlPath
);
4415 heap_free(urlCompW
.lpszExtraInfo
);
4420 /***********************************************************************
4421 * InternetCreateUrlW (WININET.@)
4423 * Creates a URL from its component parts.
4426 * lpUrlComponents [I] URL Components.
4427 * dwFlags [I] Flags. See notes.
4428 * lpszUrl [I] Buffer in which to store the created URL.
4429 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4430 * lpszUrl in characters. On output, the number of bytes
4431 * required to store the URL including terminator.
4435 * The dwFlags parameter can be zero or more of the following:
4436 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4443 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4444 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4447 INTERNET_SCHEME nScheme
;
4449 static const WCHAR slashSlashW
[] = {'/','/'};
4450 static const WCHAR fmtW
[] = {'%','u',0};
4452 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4454 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4456 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4460 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4463 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4465 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4466 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4470 *lpdwUrlLength
= dwLen
;
4475 if (lpUrlComponents
->lpszScheme
)
4477 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4478 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4481 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4486 nScheme
= lpUrlComponents
->nScheme
;
4488 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4489 nScheme
= INTERNET_SCHEME_HTTP
;
4491 scheme
= INTERNET_GetSchemeString(nScheme
);
4492 dwLen
= strlenW(scheme
);
4493 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4497 /* all schemes are followed by at least a colon */
4501 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4503 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4504 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4507 if (lpUrlComponents
->lpszUserName
)
4509 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4510 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4513 if (lpUrlComponents
->lpszPassword
)
4518 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4519 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4527 if (lpUrlComponents
->lpszHostName
)
4529 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4530 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4533 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4535 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4537 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4540 dwLen
= strlenW(szPort
);
4541 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4545 /* add slash between hostname and path if necessary */
4546 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4553 if (lpUrlComponents
->lpszUrlPath
)
4555 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4556 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4560 if (lpUrlComponents
->lpszExtraInfo
)
4562 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4563 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4572 /***********************************************************************
4573 * InternetConfirmZoneCrossingA (WININET.@)
4576 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4578 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4579 return ERROR_SUCCESS
;
4582 /***********************************************************************
4583 * InternetConfirmZoneCrossingW (WININET.@)
4586 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4588 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4589 return ERROR_SUCCESS
;
4592 static DWORD zone_preference
= 3;
4594 /***********************************************************************
4595 * PrivacySetZonePreferenceW (WININET.@)
4597 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4599 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4601 zone_preference
= template;
4605 /***********************************************************************
4606 * PrivacyGetZonePreferenceW (WININET.@)
4608 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4609 LPWSTR preference
, LPDWORD length
)
4611 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4613 if (template) *template = zone_preference
;
4617 /***********************************************************************
4618 * InternetGetSecurityInfoByURLA (WININET.@)
4620 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4625 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4627 url
= heap_strdupAtoW(lpszURL
);
4631 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4636 /***********************************************************************
4637 * InternetGetSecurityInfoByURLW (WININET.@)
4639 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4641 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4642 URL_COMPONENTSW url
= {sizeof(url
)};
4646 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4648 url
.lpszHostName
= hostname
;
4649 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4651 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4652 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4653 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4657 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4659 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4663 if(server
->cert_chain
) {
4664 const CERT_CHAIN_CONTEXT
*chain_dup
;
4666 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4668 *ppCertChain
= chain_dup
;
4669 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4674 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4678 server_release(server
);
4682 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4683 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4685 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4686 lpdwConnection
, dwReserved
);
4687 return ERROR_SUCCESS
;
4690 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4691 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4693 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4694 lpdwConnection
, dwReserved
);
4695 return ERROR_SUCCESS
;
4698 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4700 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4704 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4706 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4710 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4712 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4713 return ERROR_SUCCESS
;
4716 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4719 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4720 debugstr_w(pwszTarget
), pbHexHash
);
4724 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4726 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4730 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4732 FIXME("(%p, %08lx) stub\n", a
, b
);
4736 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4738 FIXME("%p: stub\n", parent
);