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>
65 #include "wine/debug.h"
67 #define NO_SHLWAPI_STREAM
70 #include "wine/exception.h"
75 #include "wine/unicode.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
79 #define RESPONSE_TIMEOUT 30
84 CHAR response
[MAX_REPLY_LEN
];
85 } WITHREADERROR
, *LPWITHREADERROR
;
87 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
88 HMODULE WININET_hModule
;
90 static CRITICAL_SECTION WININET_cs
;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
94 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
95 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
99 static object_header_t
**handle_table
;
100 static UINT_PTR next_handle
;
101 static UINT_PTR handle_table_size
;
108 LPWSTR proxyUsername
;
109 LPWSTR proxyPassword
;
112 static ULONG max_conns
= 2, max_1_0_conns
= 4;
113 static ULONG connect_timeout
= 60000;
115 static const WCHAR szInternetSettings
[] =
116 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
117 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
118 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
119 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
120 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
121 static const WCHAR szProxyOverride
[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
123 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
125 UINT_PTR handle
= 0, num
;
126 object_header_t
*ret
;
130 ret
= heap_alloc_zero(size
);
134 list_init(&ret
->children
);
136 EnterCriticalSection( &WININET_cs
);
138 if(!handle_table_size
) {
140 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
143 handle_table_size
= num
;
148 }else if(next_handle
== handle_table_size
) {
149 num
= handle_table_size
* 2;
150 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
153 handle_table_size
= num
;
160 handle
= next_handle
;
161 if(handle_table
[handle
])
162 ERR("handle isn't free but should be\n");
163 handle_table
[handle
] = ret
;
164 ret
->valid_handle
= TRUE
;
166 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
170 LeaveCriticalSection( &WININET_cs
);
179 ret
->hInternet
= (HINTERNET
)handle
;
182 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
183 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
189 object_header_t
*WININET_AddRef( object_header_t
*info
)
191 ULONG refs
= InterlockedIncrement(&info
->refs
);
192 TRACE("%p -> refcount = %d\n", info
, refs
);
196 object_header_t
*get_handle_object( HINTERNET hinternet
)
198 object_header_t
*info
= NULL
;
199 UINT_PTR handle
= (UINT_PTR
) hinternet
;
201 EnterCriticalSection( &WININET_cs
);
203 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
204 info
= WININET_AddRef(handle_table
[handle
]);
206 LeaveCriticalSection( &WININET_cs
);
208 TRACE("handle %ld -> %p\n", handle
, info
);
213 static void invalidate_handle(object_header_t
*info
)
215 object_header_t
*child
, *next
;
217 if(!info
->valid_handle
)
219 info
->valid_handle
= FALSE
;
221 /* Free all children as native does */
222 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
224 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
225 invalidate_handle( child
);
228 WININET_Release(info
);
231 BOOL
WININET_Release( object_header_t
*info
)
233 ULONG refs
= InterlockedDecrement(&info
->refs
);
234 TRACE( "object %p refcount = %d\n", info
, refs
);
237 invalidate_handle(info
);
238 if ( info
->vtbl
->CloseConnection
)
240 TRACE( "closing connection %p\n", info
);
241 info
->vtbl
->CloseConnection( info
);
243 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
244 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
245 || !(info
->dwInternalFlags
& INET_OPENURL
))
247 INTERNET_SendCallback(info
, info
->dwContext
,
248 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
251 TRACE( "destroying object %p\n", info
);
252 if ( info
->htype
!= WH_HINIT
)
253 list_remove( &info
->entry
);
254 info
->vtbl
->Destroy( info
);
256 if(info
->hInternet
) {
257 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
259 EnterCriticalSection( &WININET_cs
);
261 handle_table
[handle
] = NULL
;
262 if(next_handle
> handle
)
263 next_handle
= handle
;
265 LeaveCriticalSection( &WININET_cs
);
273 /***********************************************************************
274 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
277 * hinstDLL [I] handle to the DLL's instance
279 * lpvReserved [I] reserved, must be NULL
286 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
288 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
291 case DLL_PROCESS_ATTACH
:
293 g_dwTlsErrIndex
= TlsAlloc();
295 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
300 TlsFree(g_dwTlsErrIndex
);
304 WININET_hModule
= hinstDLL
;
307 case DLL_THREAD_ATTACH
:
310 case DLL_THREAD_DETACH
:
311 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
313 heap_free(TlsGetValue(g_dwTlsErrIndex
));
317 case DLL_PROCESS_DETACH
:
318 if (lpvReserved
) break;
319 collect_connections(COLLECT_CLEANUP
);
324 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
326 heap_free(TlsGetValue(g_dwTlsErrIndex
));
327 TlsFree(g_dwTlsErrIndex
);
334 /***********************************************************************
335 * INTERNET_SaveProxySettings
337 * Stores the proxy settings given by lpwai into the registry
340 * ERROR_SUCCESS if no error, or error code on fail
342 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
347 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
350 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
358 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
366 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
374 return ERROR_SUCCESS
;
377 /***********************************************************************
378 * INTERNET_FindProxyForProtocol
380 * Searches the proxy string for a proxy of the given protocol.
381 * Returns the found proxy, or the default proxy if none of the given
385 * szProxy [In] proxy string to search
386 * proto [In] protocol to search for, e.g. "http"
387 * foundProxy [Out] found proxy
388 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
391 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
392 * *foundProxyLen is set to the required size in WCHARs, including the
393 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
395 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
400 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
402 /* First, look for the specified protocol (proto=scheme://host:port) */
403 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
407 if (!(end
= strchrW(ptr
, ' ')))
408 end
= ptr
+ strlenW(ptr
);
409 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
410 equal
- ptr
== strlenW(proto
) &&
411 !strncmpiW(proto
, ptr
, strlenW(proto
)))
413 if (end
- equal
> *foundProxyLen
)
415 WARN("buffer too short for %s\n",
416 debugstr_wn(equal
+ 1, end
- equal
- 1));
417 *foundProxyLen
= end
- equal
;
418 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
422 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
423 foundProxy
[end
- equal
] = 0;
434 /* It wasn't found: look for no protocol */
435 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
439 if (!(end
= strchrW(ptr
, ' ')))
440 end
= ptr
+ strlenW(ptr
);
441 if (!strchrW(ptr
, '='))
443 if (end
- ptr
+ 1 > *foundProxyLen
)
445 WARN("buffer too short for %s\n",
446 debugstr_wn(ptr
, end
- ptr
));
447 *foundProxyLen
= end
- ptr
+ 1;
448 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
452 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
453 foundProxy
[end
- ptr
] = 0;
464 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
465 debugstr_w(foundProxy
));
469 /***********************************************************************
470 * InternetInitializeAutoProxyDll (WININET.@)
472 * Setup the internal proxy
481 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
484 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
488 /***********************************************************************
489 * DetectAutoProxyUrl (WININET.@)
491 * Auto detect the proxy url
497 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
498 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
501 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
505 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
507 heap_free(lpwpi
->proxy
);
508 heap_free(lpwpi
->proxyBypass
);
509 heap_free(lpwpi
->proxyUsername
);
510 heap_free(lpwpi
->proxyPassword
);
513 static proxyinfo_t
*global_proxy
;
515 static void free_global_proxy( void )
517 EnterCriticalSection( &WININET_cs
);
520 FreeProxyInfo( global_proxy
);
521 heap_free( global_proxy
);
523 LeaveCriticalSection( &WININET_cs
);
526 static BOOL
parse_proxy_url( proxyinfo_t
*info
, const WCHAR
*url
)
528 static const WCHAR fmt
[] = {'%','s',':','%','u',0};
529 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
] = {};
530 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
] = {};
531 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
] = {};
534 memset( &uc
, 0, sizeof(uc
) );
535 uc
.dwStructSize
= sizeof(uc
);
536 uc
.lpszHostName
= hostname
;
537 uc
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
538 uc
.lpszUserName
= username
;
539 uc
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
540 uc
.lpszPassword
= password
;
541 uc
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
543 if (!InternetCrackUrlW( url
, 0, 0, &uc
)) return FALSE
;
546 if (!(info
->proxy
= heap_strdupW( url
))) return FALSE
;
547 info
->proxyUsername
= NULL
;
548 info
->proxyPassword
= NULL
;
551 if (!(info
->proxy
= heap_alloc( (strlenW(hostname
) + 12) * sizeof(WCHAR
) ))) return FALSE
;
552 sprintfW( info
->proxy
, fmt
, hostname
, uc
.nPort
);
554 if (!username
[0]) info
->proxyUsername
= NULL
;
555 else if (!(info
->proxyUsername
= heap_strdupW( username
)))
557 heap_free( info
->proxy
);
560 if (!password
[0]) info
->proxyPassword
= NULL
;
561 else if (!(info
->proxyPassword
= heap_strdupW( password
)))
563 heap_free( info
->proxyUsername
);
564 heap_free( info
->proxy
);
570 /***********************************************************************
571 * INTERNET_LoadProxySettings
573 * Loads proxy information from process-wide global settings, the registry,
574 * or the environment into lpwpi.
576 * The caller should call FreeProxyInfo when done with lpwpi.
579 * The proxy may be specified in the form 'http=proxy.my.org'
580 * Presumably that means there can be ftp=ftpproxy.my.org too.
582 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
589 memset( lpwpi
, 0, sizeof(*lpwpi
) );
591 EnterCriticalSection( &WININET_cs
);
594 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
595 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
596 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
598 LeaveCriticalSection( &WININET_cs
);
600 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
602 FreeProxyInfo( lpwpi
);
607 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
609 lpwpi
->proxyEnabled
= 0;
610 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
612 FreeProxyInfo( lpwpi
);
618 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
620 /* figure out how much memory the proxy setting takes */
621 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
624 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
626 if (!(szProxy
= heap_alloc(len
)))
629 FreeProxyInfo( lpwpi
);
630 return ERROR_OUTOFMEMORY
;
632 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
634 /* find the http proxy, and strip away everything else */
635 p
= strstrW( szProxy
, szHttp
);
638 p
+= lstrlenW( szHttp
);
639 lstrcpyW( szProxy
, p
);
641 p
= strchrW( szProxy
, ';' );
644 FreeProxyInfo( lpwpi
);
645 lpwpi
->proxy
= szProxy
;
646 lpwpi
->proxyBypass
= NULL
;
648 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi
->proxy
));
652 TRACE("No proxy server settings in registry.\n");
653 FreeProxyInfo( lpwpi
);
655 lpwpi
->proxyBypass
= NULL
;
662 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
663 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
666 return ERROR_OUTOFMEMORY
;
668 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
670 FreeProxyInfo( lpwpi
);
671 if (parse_proxy_url( lpwpi
, envproxyW
))
673 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
674 lpwpi
->proxyEnabled
= 1;
675 lpwpi
->proxyBypass
= NULL
;
679 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW
));
680 lpwpi
->proxyEnabled
= 0;
682 lpwpi
->proxyBypass
= NULL
;
684 heap_free( envproxyW
);
687 if (lpwpi
->proxyEnabled
)
689 TRACE("Proxy is enabled.\n");
691 if (!(envproxy
= getenv( "no_proxy" )))
693 /* figure out how much memory the proxy setting takes */
694 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
698 if (!(szProxy
= heap_alloc(len
)))
701 return ERROR_OUTOFMEMORY
;
703 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
705 heap_free( lpwpi
->proxyBypass
);
706 lpwpi
->proxyBypass
= szProxy
;
708 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
712 heap_free( lpwpi
->proxyBypass
);
713 lpwpi
->proxyBypass
= NULL
;
715 TRACE("No proxy bypass server settings in registry.\n");
722 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
723 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
726 return ERROR_OUTOFMEMORY
;
728 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
730 heap_free( lpwpi
->proxyBypass
);
731 lpwpi
->proxyBypass
= envproxyW
;
733 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
736 else TRACE("Proxy is disabled.\n");
739 return ERROR_SUCCESS
;
742 /***********************************************************************
743 * INTERNET_ConfigureProxy
745 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
749 if (INTERNET_LoadProxySettings( &wpi
))
752 if (wpi
.proxyEnabled
)
754 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai
->proxy
), debugstr_w(lpwai
->proxyBypass
));
756 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
757 lpwai
->proxy
= wpi
.proxy
;
758 lpwai
->proxyBypass
= wpi
.proxyBypass
;
759 lpwai
->proxyUsername
= wpi
.proxyUsername
;
760 lpwai
->proxyPassword
= wpi
.proxyPassword
;
764 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
769 /***********************************************************************
770 * dump_INTERNET_FLAGS
772 * Helper function to TRACE the internet flags.
778 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
780 #define FE(x) { x, #x }
781 static const wininet_flag_info flag
[] = {
782 FE(INTERNET_FLAG_RELOAD
),
783 FE(INTERNET_FLAG_RAW_DATA
),
784 FE(INTERNET_FLAG_EXISTING_CONNECT
),
785 FE(INTERNET_FLAG_ASYNC
),
786 FE(INTERNET_FLAG_PASSIVE
),
787 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
788 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
789 FE(INTERNET_FLAG_FROM_CACHE
),
790 FE(INTERNET_FLAG_SECURE
),
791 FE(INTERNET_FLAG_KEEP_CONNECTION
),
792 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
793 FE(INTERNET_FLAG_READ_PREFETCH
),
794 FE(INTERNET_FLAG_NO_COOKIES
),
795 FE(INTERNET_FLAG_NO_AUTH
),
796 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
797 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
798 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
799 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
800 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
801 FE(INTERNET_FLAG_RESYNCHRONIZE
),
802 FE(INTERNET_FLAG_HYPERLINK
),
803 FE(INTERNET_FLAG_NO_UI
),
804 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
805 FE(INTERNET_FLAG_CACHE_ASYNC
),
806 FE(INTERNET_FLAG_FORMS_SUBMIT
),
807 FE(INTERNET_FLAG_NEED_FILE
),
808 FE(INTERNET_FLAG_TRANSFER_ASCII
),
809 FE(INTERNET_FLAG_TRANSFER_BINARY
)
814 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
815 if (flag
[i
].val
& dwFlags
) {
816 TRACE(" %s", flag
[i
].name
);
817 dwFlags
&= ~flag
[i
].val
;
821 TRACE(" Unknown flags (%08x)\n", dwFlags
);
826 /***********************************************************************
827 * INTERNET_CloseHandle (internal)
829 * Close internet handle
832 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
834 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
838 heap_free(lpwai
->agent
);
839 heap_free(lpwai
->proxy
);
840 heap_free(lpwai
->proxyBypass
);
841 heap_free(lpwai
->proxyUsername
);
842 heap_free(lpwai
->proxyPassword
);
845 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
847 appinfo_t
*ai
= (appinfo_t
*)hdr
;
850 case INTERNET_OPTION_HANDLE_TYPE
:
851 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
853 if (*size
< sizeof(ULONG
))
854 return ERROR_INSUFFICIENT_BUFFER
;
856 *size
= sizeof(DWORD
);
857 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
858 return ERROR_SUCCESS
;
860 case INTERNET_OPTION_USER_AGENT
: {
863 TRACE("INTERNET_OPTION_USER_AGENT\n");
868 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
870 *size
= (len
+ 1) * sizeof(WCHAR
);
871 if(!buffer
|| bufsize
< *size
)
872 return ERROR_INSUFFICIENT_BUFFER
;
875 strcpyW(buffer
, ai
->agent
);
877 *(WCHAR
*)buffer
= 0;
878 /* If the buffer is copied, the returned length doesn't include
879 * the NULL terminator.
884 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
887 if(!buffer
|| bufsize
< *size
)
888 return ERROR_INSUFFICIENT_BUFFER
;
891 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
894 /* If the buffer is copied, the returned length doesn't include
895 * the NULL terminator.
900 return ERROR_SUCCESS
;
903 case INTERNET_OPTION_PROXY
:
904 if(!size
) return ERROR_INVALID_PARAMETER
;
906 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
907 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
908 LPWSTR proxy
, proxy_bypass
;
911 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
913 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
914 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
916 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
917 return ERROR_INSUFFICIENT_BUFFER
;
919 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
920 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
922 pi
->dwAccessType
= ai
->accessType
;
923 pi
->lpszProxy
= NULL
;
924 pi
->lpszProxyBypass
= NULL
;
926 lstrcpyW(proxy
, ai
->proxy
);
927 pi
->lpszProxy
= proxy
;
930 if (ai
->proxyBypass
) {
931 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
932 pi
->lpszProxyBypass
= proxy_bypass
;
935 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
936 return ERROR_SUCCESS
;
938 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
939 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
940 LPSTR proxy
, proxy_bypass
;
943 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
945 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
946 NULL
, 0, NULL
, NULL
);
947 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
949 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
950 return ERROR_INSUFFICIENT_BUFFER
;
952 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
953 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
955 pi
->dwAccessType
= ai
->accessType
;
956 pi
->lpszProxy
= NULL
;
957 pi
->lpszProxyBypass
= NULL
;
959 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
960 pi
->lpszProxy
= proxy
;
963 if (ai
->proxyBypass
) {
964 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
965 proxyBypassBytesRequired
, NULL
, NULL
);
966 pi
->lpszProxyBypass
= proxy_bypass
;
969 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
970 return ERROR_SUCCESS
;
973 case INTERNET_OPTION_CONNECT_TIMEOUT
:
974 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
976 if (*size
< sizeof(ULONG
))
977 return ERROR_INSUFFICIENT_BUFFER
;
979 *(ULONG
*)buffer
= ai
->connect_timeout
;
980 *size
= sizeof(ULONG
);
982 return ERROR_SUCCESS
;
985 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
988 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
990 appinfo_t
*ai
= (appinfo_t
*)hdr
;
993 case INTERNET_OPTION_CONNECT_TIMEOUT
:
994 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
996 if(size
!= sizeof(connect_timeout
))
997 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
999 return ERROR_BAD_ARGUMENTS
;
1001 ai
->connect_timeout
= *(ULONG
*)buf
;
1002 return ERROR_SUCCESS
;
1003 case INTERNET_OPTION_USER_AGENT
:
1004 heap_free(ai
->agent
);
1005 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
1006 return ERROR_SUCCESS
;
1009 return INET_SetOption(hdr
, option
, buf
, size
);
1012 static const object_vtbl_t APPINFOVtbl
= {
1015 APPINFO_QueryOption
,
1024 /***********************************************************************
1025 * InternetOpenW (WININET.@)
1027 * Per-application initialization of wininet
1030 * HINTERNET on success
1034 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
1035 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
1037 appinfo_t
*lpwai
= NULL
;
1039 if (TRACE_ON(wininet
)) {
1040 #define FE(x) { x, #x }
1041 static const wininet_flag_info access_type
[] = {
1042 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
1043 FE(INTERNET_OPEN_TYPE_DIRECT
),
1044 FE(INTERNET_OPEN_TYPE_PROXY
),
1045 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
1049 const char *access_type_str
= "Unknown";
1051 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1052 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1053 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
1054 if (access_type
[i
].val
== dwAccessType
) {
1055 access_type_str
= access_type
[i
].name
;
1059 TRACE(" access type : %s\n", access_type_str
);
1061 dump_INTERNET_FLAGS(dwFlags
);
1064 /* Clear any error information */
1065 INTERNET_SetLastError(0);
1067 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1068 SetLastError(ERROR_INVALID_PARAMETER
);
1072 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1074 SetLastError(ERROR_OUTOFMEMORY
);
1078 lpwai
->hdr
.htype
= WH_HINIT
;
1079 lpwai
->hdr
.dwFlags
= dwFlags
;
1080 lpwai
->accessType
= dwAccessType
;
1081 lpwai
->proxyUsername
= NULL
;
1082 lpwai
->proxyPassword
= NULL
;
1083 lpwai
->connect_timeout
= connect_timeout
;
1085 lpwai
->agent
= heap_strdupW(lpszAgent
);
1086 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1087 INTERNET_ConfigureProxy( lpwai
);
1088 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1089 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1090 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1093 TRACE("returning %p\n", lpwai
);
1095 return lpwai
->hdr
.hInternet
;
1099 /***********************************************************************
1100 * InternetOpenA (WININET.@)
1102 * Per-application initialization of wininet
1105 * HINTERNET on success
1109 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1110 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1112 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1115 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1116 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1118 szAgent
= heap_strdupAtoW(lpszAgent
);
1119 szProxy
= heap_strdupAtoW(lpszProxy
);
1120 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1122 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1126 heap_free(szBypass
);
1130 /***********************************************************************
1131 * InternetGetLastResponseInfoA (WININET.@)
1133 * Return last wininet error description on the calling thread
1136 * TRUE on success of writing to buffer
1140 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1141 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1143 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1149 *lpdwError
= lpwite
->dwError
;
1150 if (lpwite
->dwError
)
1152 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1153 *lpdwBufferLength
= strlen(lpszBuffer
);
1156 *lpdwBufferLength
= 0;
1161 *lpdwBufferLength
= 0;
1167 /***********************************************************************
1168 * InternetGetLastResponseInfoW (WININET.@)
1170 * Return last wininet error description on the calling thread
1173 * TRUE on success of writing to buffer
1177 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1178 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1180 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1186 *lpdwError
= lpwite
->dwError
;
1187 if (lpwite
->dwError
)
1189 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1190 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1193 *lpdwBufferLength
= 0;
1198 *lpdwBufferLength
= 0;
1204 /***********************************************************************
1205 * InternetGetConnectedState (WININET.@)
1207 * Return connected state
1211 * if lpdwStatus is not null, return the status (off line,
1212 * modem, lan...) in it.
1213 * FALSE if not connected
1215 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1217 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1220 WARN("always returning LAN connection.\n");
1221 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1227 /***********************************************************************
1228 * InternetGetConnectedStateExW (WININET.@)
1230 * Return connected state
1234 * lpdwStatus [O] Flags specifying the status of the internet connection.
1235 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1236 * dwNameLen [I] Size of the buffer, in characters.
1237 * dwReserved [I] Reserved. Must be set to 0.
1241 * if lpdwStatus is not null, return the status (off line,
1242 * modem, lan...) in it.
1243 * FALSE if not connected
1246 * If the system has no available network connections, an empty string is
1247 * stored in lpszConnectionName. If there is a LAN connection, a localized
1248 * "LAN Connection" string is stored. Presumably, if only a dial-up
1249 * connection is available then the name of the dial-up connection is
1250 * returned. Why any application, other than the "Internet Settings" CPL,
1251 * would want to use this function instead of the simpler InternetGetConnectedStateW
1252 * function is beyond me.
1254 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1255 DWORD dwNameLen
, DWORD dwReserved
)
1257 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1264 WARN("always returning LAN connection.\n");
1265 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1267 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
) > 0;
1271 /***********************************************************************
1272 * InternetGetConnectedStateExA (WININET.@)
1274 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1275 DWORD dwNameLen
, DWORD dwReserved
)
1277 LPWSTR lpwszConnectionName
= NULL
;
1280 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1282 if (lpszConnectionName
&& dwNameLen
> 0)
1283 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1285 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1287 if (rc
&& lpwszConnectionName
)
1289 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1290 dwNameLen
, NULL
, NULL
);
1291 heap_free(lpwszConnectionName
);
1297 /***********************************************************************
1298 * InternetConnectW (WININET.@)
1300 * Open a ftp, gopher or http session
1303 * HINTERNET a session handle on success
1307 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1308 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1309 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1310 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1313 HINTERNET rc
= NULL
;
1314 DWORD res
= ERROR_SUCCESS
;
1316 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1317 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1318 dwService
, dwFlags
, dwContext
);
1320 if (!lpszServerName
)
1322 SetLastError(ERROR_INVALID_PARAMETER
);
1326 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1327 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1329 res
= ERROR_INVALID_HANDLE
;
1335 case INTERNET_SERVICE_FTP
:
1336 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1337 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1339 res
= INTERNET_GetLastError();
1342 case INTERNET_SERVICE_HTTP
:
1343 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1344 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1347 case INTERNET_SERVICE_GOPHER
:
1353 WININET_Release( &hIC
->hdr
);
1355 TRACE("returning %p\n", rc
);
1361 /***********************************************************************
1362 * InternetConnectA (WININET.@)
1364 * Open a ftp, gopher or http session
1367 * HINTERNET a session handle on success
1371 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1372 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1373 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1374 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1376 HINTERNET rc
= NULL
;
1377 LPWSTR szServerName
;
1381 szServerName
= heap_strdupAtoW(lpszServerName
);
1382 szUserName
= heap_strdupAtoW(lpszUserName
);
1383 szPassword
= heap_strdupAtoW(lpszPassword
);
1385 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1386 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1388 heap_free(szServerName
);
1389 heap_free(szUserName
);
1390 heap_free(szPassword
);
1395 /***********************************************************************
1396 * InternetFindNextFileA (WININET.@)
1398 * Continues a file search from a previous call to FindFirstFile
1405 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1408 WIN32_FIND_DATAW fd
;
1410 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1412 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1416 /***********************************************************************
1417 * InternetFindNextFileW (WININET.@)
1419 * Continues a file search from a previous call to FindFirstFile
1426 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1428 object_header_t
*hdr
;
1433 hdr
= get_handle_object(hFind
);
1435 WARN("Invalid handle\n");
1436 SetLastError(ERROR_INVALID_HANDLE
);
1440 if(hdr
->vtbl
->FindNextFileW
) {
1441 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1443 WARN("Handle doesn't support NextFile\n");
1444 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1447 WININET_Release(hdr
);
1449 if(res
!= ERROR_SUCCESS
)
1451 return res
== ERROR_SUCCESS
;
1454 /***********************************************************************
1455 * InternetCloseHandle (WININET.@)
1457 * Generic close handle function
1464 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1466 object_header_t
*obj
;
1468 TRACE("%p\n", hInternet
);
1470 obj
= get_handle_object( hInternet
);
1472 SetLastError(ERROR_INVALID_HANDLE
);
1476 invalidate_handle(obj
);
1477 WININET_Release(obj
);
1483 /***********************************************************************
1484 * ConvertUrlComponentValue (Internal)
1486 * Helper function for InternetCrackUrlA
1489 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1490 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1491 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1493 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1494 if (*dwComponentLen
!= 0)
1496 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1497 if (*lppszComponent
== NULL
)
1501 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1502 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1505 *lppszComponent
= NULL
;
1507 *dwComponentLen
= nASCIILength
;
1511 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1512 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1513 (*lppszComponent
)[ncpylen
]=0;
1514 *dwComponentLen
= ncpylen
;
1520 /***********************************************************************
1521 * InternetCrackUrlA (WININET.@)
1523 * See InternetCrackUrlW.
1525 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1526 LPURL_COMPONENTSA lpUrlComponents
)
1529 URL_COMPONENTSW UCW
;
1531 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1532 *scheme
= NULL
, *extra
= NULL
;
1534 TRACE("(%s %u %x %p)\n",
1535 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1536 dwUrlLength
, dwFlags
, lpUrlComponents
);
1538 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1539 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1541 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1547 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1549 /* if dwUrlLength=-1 then nLength includes null but length to
1550 InternetCrackUrlW should not include it */
1551 if (dwUrlLength
== -1) nLength
--;
1553 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1554 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1555 lpwszUrl
[nLength
] = '\0';
1557 memset(&UCW
,0,sizeof(UCW
));
1558 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1559 if (lpUrlComponents
->dwHostNameLength
)
1561 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1562 if (lpUrlComponents
->lpszHostName
)
1564 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1565 UCW
.lpszHostName
= hostname
;
1568 if (lpUrlComponents
->dwUserNameLength
)
1570 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1571 if (lpUrlComponents
->lpszUserName
)
1573 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1574 UCW
.lpszUserName
= username
;
1577 if (lpUrlComponents
->dwPasswordLength
)
1579 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1580 if (lpUrlComponents
->lpszPassword
)
1582 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1583 UCW
.lpszPassword
= password
;
1586 if (lpUrlComponents
->dwUrlPathLength
)
1588 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1589 if (lpUrlComponents
->lpszUrlPath
)
1591 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1592 UCW
.lpszUrlPath
= path
;
1595 if (lpUrlComponents
->dwSchemeLength
)
1597 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1598 if (lpUrlComponents
->lpszScheme
)
1600 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1601 UCW
.lpszScheme
= scheme
;
1604 if (lpUrlComponents
->dwExtraInfoLength
)
1606 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1607 if (lpUrlComponents
->lpszExtraInfo
)
1609 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1610 UCW
.lpszExtraInfo
= extra
;
1613 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1615 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1616 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1617 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1618 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1619 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1620 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1621 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1622 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1623 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1624 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1625 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1626 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1628 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1629 lpUrlComponents
->nPort
= UCW
.nPort
;
1631 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1632 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1633 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1634 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1635 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1637 heap_free(lpwszUrl
);
1638 heap_free(hostname
);
1639 heap_free(username
);
1640 heap_free(password
);
1647 static const WCHAR url_schemes
[][7] =
1650 {'g','o','p','h','e','r',0},
1651 {'h','t','t','p',0},
1652 {'h','t','t','p','s',0},
1653 {'f','i','l','e',0},
1654 {'n','e','w','s',0},
1655 {'m','a','i','l','t','o',0},
1659 /***********************************************************************
1660 * GetInternetSchemeW (internal)
1666 * INTERNET_SCHEME_UNKNOWN on failure
1669 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1673 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1675 if(lpszScheme
==NULL
)
1676 return INTERNET_SCHEME_UNKNOWN
;
1678 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1679 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1680 return INTERNET_SCHEME_FIRST
+ i
;
1682 return INTERNET_SCHEME_UNKNOWN
;
1685 /***********************************************************************
1686 * SetUrlComponentValueW (Internal)
1688 * Helper function for InternetCrackUrlW
1691 * lppszComponent [O] Holds the returned string
1692 * dwComponentLen [I] Holds the size of lppszComponent
1693 * [O] Holds the length of the string in lppszComponent without '\0'
1694 * lpszStart [I] Holds the string to copy from
1695 * len [I] Holds the length of lpszStart without '\0'
1702 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1704 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1706 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1709 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1711 if (*lppszComponent
== NULL
)
1713 *lppszComponent
= (LPWSTR
)lpszStart
;
1714 *dwComponentLen
= len
;
1718 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1719 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1720 (*lppszComponent
)[ncpylen
] = '\0';
1721 *dwComponentLen
= ncpylen
;
1728 /***********************************************************************
1729 * InternetCrackUrlW (WININET.@)
1731 * Break up URL into its components
1737 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1738 LPURL_COMPONENTSW lpUC
)
1742 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1745 LPCWSTR lpszParam
= NULL
;
1746 BOOL found_colon
= FALSE
;
1747 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1748 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1749 LPWSTR lpszUrl_decode
= NULL
;
1750 DWORD dwUrlLength
= dwUrlLength_orig
;
1752 TRACE("(%s %u %x %p)\n",
1753 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1754 dwUrlLength
, dwFlags
, lpUC
);
1756 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1758 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1761 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1763 if (dwFlags
& ICU_DECODE
)
1766 DWORD len
= dwUrlLength
+ 1;
1768 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1770 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1773 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1774 url_tmp
[dwUrlLength
] = 0;
1775 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1778 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1781 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1784 lpszUrl
= lpszUrl_decode
;
1790 /* Determine if the URI is absolute. */
1791 while (lpszap
- lpszUrl
< dwUrlLength
)
1793 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1805 lpszcp
= lpszUrl
; /* Relative url */
1812 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1816 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1817 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1819 /* Parse <params> */
1820 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1822 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1824 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1825 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1828 /* Get scheme first. */
1829 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1830 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1831 lpszUrl
, lpszcp
- lpszUrl
);
1833 /* Eat ':' in protocol. */
1836 /* double slash indicates the net_loc portion is present */
1837 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1841 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1845 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1847 lpszNetLoc
= lpszParam
;
1849 else if (!lpszNetLoc
)
1850 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1858 /* [<user>[<:password>]@]<host>[:<port>] */
1859 /* First find the user and password if they exist */
1861 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1862 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1864 /* username and password not specified. */
1865 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1866 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1868 else /* Parse out username and password */
1870 LPCWSTR lpszUser
= lpszcp
;
1871 LPCWSTR lpszPasswd
= lpszHost
;
1873 while (lpszcp
< lpszHost
)
1876 lpszPasswd
= lpszcp
;
1881 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1882 lpszUser
, lpszPasswd
- lpszUser
);
1884 if (lpszPasswd
!= lpszHost
)
1886 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1887 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1888 lpszHost
- lpszPasswd
);
1890 lpszcp
++; /* Advance to beginning of host */
1893 /* Parse <host><:port> */
1896 lpszPort
= lpszNetLoc
;
1898 /* special case for res:// URLs: there is no port here, so the host is the
1899 entire string up to the first '/' */
1900 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1902 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1903 lpszHost
, lpszPort
- lpszHost
);
1908 while (lpszcp
< lpszNetLoc
)
1916 /* If the scheme is "file" and the host is just one letter, it's not a host */
1917 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1920 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1925 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1926 lpszHost
, lpszPort
- lpszHost
);
1927 if (lpszPort
!= lpszNetLoc
)
1928 lpUC
->nPort
= atoiW(++lpszPort
);
1929 else switch (lpUC
->nScheme
)
1931 case INTERNET_SCHEME_HTTP
:
1932 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1934 case INTERNET_SCHEME_HTTPS
:
1935 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1937 case INTERNET_SCHEME_FTP
:
1938 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1940 case INTERNET_SCHEME_GOPHER
:
1941 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1952 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1953 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1954 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1957 /* Here lpszcp points to:
1959 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1960 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1962 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1966 /* Only truncate the parameter list if it's already been saved
1967 * in lpUC->lpszExtraInfo.
1969 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1970 len
= lpszParam
- lpszcp
;
1973 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1974 * newlines if necessary.
1976 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1977 if (lpsznewline
!= NULL
)
1978 len
= lpsznewline
- lpszcp
;
1980 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1982 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1983 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1985 WCHAR tmppath
[MAX_PATH
];
1989 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1994 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1995 tmppath
[len
] = '\0';
2004 /* if ends in \. or \.. append a backslash */
2005 if (tmppath
[len
- 1] == '.' &&
2006 (tmppath
[len
- 2] == '\\' ||
2007 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
2009 if (len
< MAX_PATH
- 1)
2011 tmppath
[len
] = '\\';
2012 tmppath
[len
+1] = '\0';
2016 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
2020 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
2025 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
2026 lpUC
->lpszUrlPath
[0] = 0;
2027 lpUC
->dwUrlPathLength
= 0;
2030 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
2031 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
2032 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
2033 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
2034 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
2036 heap_free( lpszUrl_decode
);
2040 /***********************************************************************
2041 * InternetAttemptConnect (WININET.@)
2043 * Attempt to make a connection to the internet
2046 * ERROR_SUCCESS on success
2047 * Error value on failure
2050 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
2053 return ERROR_SUCCESS
;
2057 /***********************************************************************
2058 * convert_url_canonicalization_flags
2060 * Helper for InternetCanonicalizeUrl
2063 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2066 * Flags suitable for UrlCanonicalize
2068 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
2070 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2072 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
2073 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
2074 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
2075 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
2076 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2077 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
2078 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
2083 /***********************************************************************
2084 * InternetCanonicalizeUrlA (WININET.@)
2086 * Escape unsafe characters and spaces
2093 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2094 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2098 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2099 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2101 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2102 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2103 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2104 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2109 /***********************************************************************
2110 * InternetCanonicalizeUrlW (WININET.@)
2112 * Escape unsafe characters and spaces
2119 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2120 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2124 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2125 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2127 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2128 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2129 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2130 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2135 /* #################################################### */
2137 static INTERNET_STATUS_CALLBACK
set_status_callback(
2138 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2140 INTERNET_STATUS_CALLBACK ret
;
2142 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2143 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2145 ret
= lpwh
->lpfnStatusCB
;
2146 lpwh
->lpfnStatusCB
= callback
;
2151 /***********************************************************************
2152 * InternetSetStatusCallbackA (WININET.@)
2154 * Sets up a callback function which is called as progress is made
2155 * during an operation.
2158 * Previous callback or NULL on success
2159 * INTERNET_INVALID_STATUS_CALLBACK on failure
2162 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2163 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2165 INTERNET_STATUS_CALLBACK retVal
;
2166 object_header_t
*lpwh
;
2168 TRACE("%p\n", hInternet
);
2170 if (!(lpwh
= get_handle_object(hInternet
)))
2171 return INTERNET_INVALID_STATUS_CALLBACK
;
2173 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2175 WININET_Release( lpwh
);
2179 /***********************************************************************
2180 * InternetSetStatusCallbackW (WININET.@)
2182 * Sets up a callback function which is called as progress is made
2183 * during an operation.
2186 * Previous callback or NULL on success
2187 * INTERNET_INVALID_STATUS_CALLBACK on failure
2190 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2191 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2193 INTERNET_STATUS_CALLBACK retVal
;
2194 object_header_t
*lpwh
;
2196 TRACE("%p\n", hInternet
);
2198 if (!(lpwh
= get_handle_object(hInternet
)))
2199 return INTERNET_INVALID_STATUS_CALLBACK
;
2201 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2203 WININET_Release( lpwh
);
2207 /***********************************************************************
2208 * InternetSetFilePointer (WININET.@)
2210 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2211 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2213 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2217 /***********************************************************************
2218 * InternetWriteFile (WININET.@)
2220 * Write data to an open internet file
2227 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2228 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2230 object_header_t
*lpwh
;
2233 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2235 lpwh
= get_handle_object( hFile
);
2237 WARN("Invalid handle\n");
2238 SetLastError(ERROR_INVALID_HANDLE
);
2242 if(lpwh
->vtbl
->WriteFile
) {
2243 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2245 WARN("No Writefile method.\n");
2246 res
= ERROR_INVALID_HANDLE
;
2249 WININET_Release( lpwh
);
2251 if(res
!= ERROR_SUCCESS
)
2253 return res
== ERROR_SUCCESS
;
2257 /***********************************************************************
2258 * InternetReadFile (WININET.@)
2260 * Read data from an open internet file
2267 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2268 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2270 object_header_t
*hdr
;
2271 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2273 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2275 hdr
= get_handle_object(hFile
);
2277 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2281 if(hdr
->vtbl
->ReadFile
)
2282 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2284 WININET_Release(hdr
);
2286 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2287 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2289 if(res
!= ERROR_SUCCESS
)
2291 return res
== ERROR_SUCCESS
;
2294 /***********************************************************************
2295 * InternetReadFileExA (WININET.@)
2297 * Read data from an open internet file
2300 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2301 * lpBuffersOut [I/O] Buffer.
2302 * dwFlags [I] Flags. See notes.
2303 * dwContext [I] Context for callbacks.
2310 * The parameter dwFlags include zero or more of the following flags:
2311 *|IRF_ASYNC - Makes the call asynchronous.
2312 *|IRF_SYNC - Makes the call synchronous.
2313 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2314 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2316 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2319 * InternetOpenUrlA(), HttpOpenRequestA()
2321 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2322 DWORD dwFlags
, DWORD_PTR dwContext
)
2324 object_header_t
*hdr
;
2325 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2327 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2329 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2330 SetLastError(ERROR_INVALID_PARAMETER
);
2334 hdr
= get_handle_object(hFile
);
2336 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2340 if(hdr
->vtbl
->ReadFileEx
)
2341 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2342 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2344 WININET_Release(hdr
);
2346 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2347 res
, lpBuffersOut
->dwBufferLength
);
2349 if(res
!= ERROR_SUCCESS
)
2351 return res
== ERROR_SUCCESS
;
2354 /***********************************************************************
2355 * InternetReadFileExW (WININET.@)
2357 * InternetReadFileExA()
2359 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2360 DWORD dwFlags
, DWORD_PTR dwContext
)
2362 object_header_t
*hdr
;
2363 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2365 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2367 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2368 SetLastError(ERROR_INVALID_PARAMETER
);
2372 hdr
= get_handle_object(hFile
);
2374 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2378 if(hdr
->vtbl
->ReadFileEx
)
2379 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2380 dwFlags
, dwContext
);
2382 WININET_Release(hdr
);
2384 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2385 res
, lpBuffer
->dwBufferLength
);
2387 if(res
!= ERROR_SUCCESS
)
2389 return res
== ERROR_SUCCESS
;
2392 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2394 /* FIXME: This function currently handles more options than it should. Options requiring
2395 * proper handles should be moved to proper functions */
2397 case INTERNET_OPTION_HTTP_VERSION
:
2398 if (*size
< sizeof(HTTP_VERSION_INFO
))
2399 return ERROR_INSUFFICIENT_BUFFER
;
2402 * Presently hardcoded to 1.1
2404 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2405 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2406 *size
= sizeof(HTTP_VERSION_INFO
);
2408 return ERROR_SUCCESS
;
2410 case INTERNET_OPTION_CONNECTED_STATE
:
2411 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2413 if (*size
< sizeof(ULONG
))
2414 return ERROR_INSUFFICIENT_BUFFER
;
2416 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2417 *size
= sizeof(ULONG
);
2419 return ERROR_SUCCESS
;
2421 case INTERNET_OPTION_PROXY
: {
2425 TRACE("Getting global proxy info\n");
2426 memset(&ai
, 0, sizeof(appinfo_t
));
2427 INTERNET_ConfigureProxy(&ai
);
2429 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2430 APPINFO_Destroy(&ai
.hdr
);
2434 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2435 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2437 if (*size
< sizeof(ULONG
))
2438 return ERROR_INSUFFICIENT_BUFFER
;
2440 *(ULONG
*)buffer
= max_conns
;
2441 *size
= sizeof(ULONG
);
2443 return ERROR_SUCCESS
;
2445 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2446 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2448 if (*size
< sizeof(ULONG
))
2449 return ERROR_INSUFFICIENT_BUFFER
;
2451 *(ULONG
*)buffer
= max_1_0_conns
;
2452 *size
= sizeof(ULONG
);
2454 return ERROR_SUCCESS
;
2456 case INTERNET_OPTION_SECURITY_FLAGS
:
2457 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2458 return ERROR_SUCCESS
;
2460 case INTERNET_OPTION_VERSION
: {
2461 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2463 TRACE("INTERNET_OPTION_VERSION\n");
2465 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2466 return ERROR_INSUFFICIENT_BUFFER
;
2468 memcpy(buffer
, &info
, sizeof(info
));
2469 *size
= sizeof(info
);
2471 return ERROR_SUCCESS
;
2474 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2475 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2476 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2477 DWORD res
= ERROR_SUCCESS
, i
;
2481 TRACE("Getting global proxy info\n");
2482 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2485 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2487 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2489 return ERROR_INSUFFICIENT_BUFFER
;
2492 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2493 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2494 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2496 switch (optionW
->dwOption
) {
2497 case INTERNET_PER_CONN_FLAGS
:
2499 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2501 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2504 case INTERNET_PER_CONN_PROXY_SERVER
:
2506 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2508 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2511 case INTERNET_PER_CONN_PROXY_BYPASS
:
2513 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2515 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2518 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2519 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2520 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2521 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2522 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2523 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2524 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2525 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2529 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2530 res
= ERROR_INVALID_PARAMETER
;
2538 case INTERNET_OPTION_REQUEST_FLAGS
:
2539 case INTERNET_OPTION_USER_AGENT
:
2541 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2542 case INTERNET_OPTION_POLICY
:
2543 return ERROR_INVALID_PARAMETER
;
2544 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2545 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2547 if (*size
< sizeof(ULONG
))
2548 return ERROR_INSUFFICIENT_BUFFER
;
2550 *(ULONG
*)buffer
= connect_timeout
;
2551 *size
= sizeof(ULONG
);
2553 return ERROR_SUCCESS
;
2556 FIXME("Stub for %d\n", option
);
2557 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2560 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2563 case INTERNET_OPTION_CONTEXT_VALUE
:
2565 return ERROR_INVALID_PARAMETER
;
2567 if (*size
< sizeof(DWORD_PTR
)) {
2568 *size
= sizeof(DWORD_PTR
);
2569 return ERROR_INSUFFICIENT_BUFFER
;
2572 return ERROR_INVALID_PARAMETER
;
2574 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2575 *size
= sizeof(DWORD_PTR
);
2576 return ERROR_SUCCESS
;
2578 case INTERNET_OPTION_REQUEST_FLAGS
:
2579 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2580 *size
= sizeof(DWORD
);
2581 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2583 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2584 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2585 WARN("Called on global option %u\n", option
);
2586 return ERROR_INTERNET_INVALID_OPERATION
;
2589 /* FIXME: we shouldn't call it here */
2590 return query_global_option(option
, buffer
, size
, unicode
);
2593 /***********************************************************************
2594 * InternetQueryOptionW (WININET.@)
2596 * Queries an options on the specified handle
2603 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2604 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2606 object_header_t
*hdr
;
2607 DWORD res
= ERROR_INVALID_HANDLE
;
2609 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2612 hdr
= get_handle_object(hInternet
);
2614 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2615 WININET_Release(hdr
);
2618 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2621 if(res
!= ERROR_SUCCESS
)
2623 return res
== ERROR_SUCCESS
;
2626 /***********************************************************************
2627 * InternetQueryOptionA (WININET.@)
2629 * Queries an options on the specified handle
2636 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2637 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2639 object_header_t
*hdr
;
2640 DWORD res
= ERROR_INVALID_HANDLE
;
2642 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2645 hdr
= get_handle_object(hInternet
);
2647 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2648 WININET_Release(hdr
);
2651 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2654 if(res
!= ERROR_SUCCESS
)
2656 return res
== ERROR_SUCCESS
;
2659 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2662 case INTERNET_OPTION_CALLBACK
:
2663 WARN("Not settable option %u\n", option
);
2664 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2665 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2666 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2667 WARN("Called on global option %u\n", option
);
2668 return ERROR_INTERNET_INVALID_OPERATION
;
2671 return ERROR_INTERNET_INVALID_OPTION
;
2674 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2677 case INTERNET_OPTION_CALLBACK
:
2678 WARN("Not global option %u\n", option
);
2679 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2681 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2682 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2684 if(size
!= sizeof(max_conns
))
2685 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2687 return ERROR_BAD_ARGUMENTS
;
2689 max_conns
= *(ULONG
*)buf
;
2690 return ERROR_SUCCESS
;
2692 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2693 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2695 if(size
!= sizeof(max_1_0_conns
))
2696 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2698 return ERROR_BAD_ARGUMENTS
;
2700 max_1_0_conns
= *(ULONG
*)buf
;
2701 return ERROR_SUCCESS
;
2703 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2704 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2706 if(size
!= sizeof(connect_timeout
))
2707 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2709 return ERROR_BAD_ARGUMENTS
;
2711 connect_timeout
= *(ULONG
*)buf
;
2712 return ERROR_SUCCESS
;
2714 case INTERNET_OPTION_SETTINGS_CHANGED
:
2715 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2716 collect_connections(COLLECT_CONNECTIONS
);
2717 return ERROR_SUCCESS
;
2720 return ERROR_INTERNET_INVALID_OPTION
;
2723 /***********************************************************************
2724 * InternetSetOptionW (WININET.@)
2726 * Sets an options on the specified handle
2733 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2734 LPVOID lpBuffer
, DWORD dwBufferLength
)
2736 object_header_t
*lpwhh
;
2740 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2742 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2744 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2746 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2748 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2750 WININET_Release(lpwhh
);
2752 if(res
!= ERROR_SUCCESS
)
2755 return res
== ERROR_SUCCESS
;
2760 case INTERNET_OPTION_HTTP_VERSION
:
2762 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2763 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2766 case INTERNET_OPTION_ERROR_MASK
:
2769 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2771 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2772 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2773 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2774 SetLastError(ERROR_INVALID_PARAMETER
);
2776 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2777 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2780 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2781 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2784 case INTERNET_OPTION_PROXY
:
2786 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2788 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2790 SetLastError(ERROR_INVALID_PARAMETER
);
2795 EnterCriticalSection( &WININET_cs
);
2796 free_global_proxy();
2797 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2800 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2802 global_proxy
->proxyEnabled
= 1;
2803 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2804 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2808 global_proxy
->proxyEnabled
= 0;
2809 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2812 LeaveCriticalSection( &WININET_cs
);
2816 /* In general, each type of object should handle
2817 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2818 * get silently dropped.
2820 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2821 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2826 case INTERNET_OPTION_CODEPAGE
:
2828 ULONG codepage
= *(ULONG
*)lpBuffer
;
2829 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2832 case INTERNET_OPTION_REQUEST_PRIORITY
:
2834 ULONG priority
= *(ULONG
*)lpBuffer
;
2835 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2838 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2840 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2841 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2844 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2846 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2847 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2850 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2851 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2853 case INTERNET_OPTION_END_BROWSER_SESSION
:
2854 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2856 case INTERNET_OPTION_CONNECTED_STATE
:
2857 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2859 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2860 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2862 case INTERNET_OPTION_SEND_TIMEOUT
:
2863 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2864 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2866 ULONG timeout
= *(ULONG
*)lpBuffer
;
2867 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2870 case INTERNET_OPTION_CONNECT_RETRIES
:
2872 ULONG retries
= *(ULONG
*)lpBuffer
;
2873 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2876 case INTERNET_OPTION_CONTEXT_VALUE
:
2880 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2883 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2885 SetLastError(ERROR_INVALID_PARAMETER
);
2889 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2892 case INTERNET_OPTION_SECURITY_FLAGS
:
2893 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2895 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2896 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2898 case INTERNET_OPTION_HTTP_DECODING
:
2899 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2900 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2903 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2904 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2905 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2908 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2909 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2910 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2913 case INTERNET_OPTION_CODEPAGE_PATH
:
2914 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2915 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2918 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2919 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2920 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2923 case INTERNET_OPTION_IDN
:
2924 FIXME("INTERNET_OPTION_IDN; STUB\n");
2925 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2928 case INTERNET_OPTION_POLICY
:
2929 SetLastError(ERROR_INVALID_PARAMETER
);
2932 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2933 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2938 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2940 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2941 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2943 switch (option
->dwOption
) {
2944 case INTERNET_PER_CONN_PROXY_SERVER
:
2945 heap_free(pi
.proxy
);
2946 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2949 case INTERNET_PER_CONN_FLAGS
:
2950 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2951 pi
.proxyEnabled
= 1;
2954 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2955 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2956 pi
.proxyEnabled
= 0;
2960 case INTERNET_PER_CONN_PROXY_BYPASS
:
2961 heap_free(pi
.proxyBypass
);
2962 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
2965 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2966 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2967 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2968 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2969 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2970 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2971 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2975 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2976 SetLastError(ERROR_INVALID_PARAMETER
);
2981 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2986 ret
= (res
== ERROR_SUCCESS
);
2990 FIXME("Option %d STUB\n",dwOption
);
2991 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2997 WININET_Release( lpwhh
);
3003 /***********************************************************************
3004 * InternetSetOptionA (WININET.@)
3006 * Sets an options on the specified handle.
3013 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3014 LPVOID lpBuffer
, DWORD dwBufferLength
)
3022 case INTERNET_OPTION_PROXY
:
3024 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3025 LPINTERNET_PROXY_INFOW piw
;
3026 DWORD proxlen
, prbylen
;
3029 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3030 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3031 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3032 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3033 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3034 piw
->dwAccessType
= pi
->dwAccessType
;
3035 prox
= (LPWSTR
) &piw
[1];
3036 prby
= &prox
[proxlen
+1];
3037 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3038 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3039 piw
->lpszProxy
= prox
;
3040 piw
->lpszProxyBypass
= prby
;
3043 case INTERNET_OPTION_USER_AGENT
:
3044 case INTERNET_OPTION_USERNAME
:
3045 case INTERNET_OPTION_PASSWORD
:
3046 case INTERNET_OPTION_PROXY_USERNAME
:
3047 case INTERNET_OPTION_PROXY_PASSWORD
:
3048 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3049 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3050 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3052 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3054 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3055 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3056 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3057 wbuffer
= heap_alloc(wlen
);
3060 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3061 if (listA
->pszConnection
)
3063 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3064 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3065 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3068 listW
->pszConnection
= NULL
;
3069 listW
->dwOptionCount
= listA
->dwOptionCount
;
3070 listW
->dwOptionError
= listA
->dwOptionError
;
3071 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3073 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3074 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3075 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3077 optW
->dwOption
= optA
->dwOption
;
3079 switch (optA
->dwOption
) {
3080 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3081 case INTERNET_PER_CONN_PROXY_BYPASS
:
3082 case INTERNET_PER_CONN_PROXY_SERVER
:
3083 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3084 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3085 if (optA
->Value
.pszValue
)
3087 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3088 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3089 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3092 optW
->Value
.pszValue
= NULL
;
3094 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3095 case INTERNET_PER_CONN_FLAGS
:
3096 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3097 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3099 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3100 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3103 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3104 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3112 wlen
= dwBufferLength
;
3115 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3117 if( lpBuffer
!= wbuffer
)
3119 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3121 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3123 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3124 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3125 switch (opt
->dwOption
) {
3126 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3127 case INTERNET_PER_CONN_PROXY_BYPASS
:
3128 case INTERNET_PER_CONN_PROXY_SERVER
:
3129 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3130 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3131 heap_free( opt
->Value
.pszValue
);
3137 heap_free( list
->pOptions
);
3139 heap_free( wbuffer
);
3146 /***********************************************************************
3147 * InternetSetOptionExA (WININET.@)
3149 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3150 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3152 FIXME("Flags %08x ignored\n", dwFlags
);
3153 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3156 /***********************************************************************
3157 * InternetSetOptionExW (WININET.@)
3159 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3160 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3162 FIXME("Flags %08x ignored\n", dwFlags
);
3163 if( dwFlags
& ~ISO_VALID_FLAGS
)
3165 SetLastError( ERROR_INVALID_PARAMETER
);
3168 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3171 static const WCHAR WININET_wkday
[7][4] =
3172 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3173 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3174 static const WCHAR WININET_month
[12][4] =
3175 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3176 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3177 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3179 /***********************************************************************
3180 * InternetTimeFromSystemTimeA (WININET.@)
3182 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3185 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3187 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3189 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3191 SetLastError(ERROR_INVALID_PARAMETER
);
3195 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3197 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3201 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3202 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3207 /***********************************************************************
3208 * InternetTimeFromSystemTimeW (WININET.@)
3210 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3212 static const WCHAR date
[] =
3213 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3214 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3216 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3218 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3220 SetLastError(ERROR_INVALID_PARAMETER
);
3224 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3226 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3230 sprintfW( string
, date
,
3231 WININET_wkday
[time
->wDayOfWeek
],
3233 WININET_month
[time
->wMonth
- 1],
3242 /***********************************************************************
3243 * InternetTimeToSystemTimeA (WININET.@)
3245 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3250 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3252 stringW
= heap_strdupAtoW(string
);
3255 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3256 heap_free( stringW
);
3261 /***********************************************************************
3262 * InternetTimeToSystemTimeW (WININET.@)
3264 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3267 const WCHAR
*s
= string
;
3270 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3272 if (!string
|| !time
) return FALSE
;
3274 /* Windows does this too */
3275 GetSystemTime( time
);
3277 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3278 * a SYSTEMTIME structure.
3281 while (*s
&& !isalphaW( *s
)) s
++;
3282 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3283 time
->wDayOfWeek
= 7;
3285 for (i
= 0; i
< 7; i
++)
3287 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3288 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3289 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3291 time
->wDayOfWeek
= i
;
3296 if (time
->wDayOfWeek
> 6) return TRUE
;
3297 while (*s
&& !isdigitW( *s
)) s
++;
3298 time
->wDay
= strtolW( s
, &end
, 10 );
3301 while (*s
&& !isalphaW( *s
)) s
++;
3302 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3305 for (i
= 0; i
< 12; i
++)
3307 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3308 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3309 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3311 time
->wMonth
= i
+ 1;
3315 if (time
->wMonth
== 0) return TRUE
;
3317 while (*s
&& !isdigitW( *s
)) s
++;
3318 if (*s
== '\0') return TRUE
;
3319 time
->wYear
= strtolW( s
, &end
, 10 );
3322 while (*s
&& !isdigitW( *s
)) s
++;
3323 if (*s
== '\0') return TRUE
;
3324 time
->wHour
= strtolW( s
, &end
, 10 );
3327 while (*s
&& !isdigitW( *s
)) s
++;
3328 if (*s
== '\0') return TRUE
;
3329 time
->wMinute
= strtolW( s
, &end
, 10 );
3332 while (*s
&& !isdigitW( *s
)) s
++;
3333 if (*s
== '\0') return TRUE
;
3334 time
->wSecond
= strtolW( s
, &end
, 10 );
3337 time
->wMilliseconds
= 0;
3341 /***********************************************************************
3342 * InternetCheckConnectionW (WININET.@)
3344 * Pings a requested host to check internet connection
3347 * TRUE on success and FALSE on failure. If a failure then
3348 * ERROR_NOT_CONNECTED is placed into GetLastError
3351 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3354 * this is a kludge which runs the resident ping program and reads the output.
3356 * Anyone have a better idea?
3360 static const CHAR ping
[] = "ping -c 1 ";
3361 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3362 CHAR
*command
= NULL
;
3363 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3371 * Crack or set the Address
3373 if (lpszUrl
== NULL
)
3376 * According to the doc we are supposed to use the ip for the next
3377 * server in the WnInet internal server database. I have
3378 * no idea what that is or how to get it.
3380 * So someone needs to implement this.
3382 FIXME("Unimplemented with URL of NULL\n");
3387 URL_COMPONENTSW components
;
3389 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3390 components
.lpszHostName
= (LPWSTR
)hostW
;
3391 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3393 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3396 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3397 port
= components
.nPort
;
3398 TRACE("port: %d\n", port
);
3401 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3403 struct sockaddr_storage saddr
;
3404 socklen_t sa_len
= sizeof(saddr
);
3407 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3409 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3412 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3420 * Build our ping command
3422 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3423 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3424 strcpy(command
,ping
);
3425 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3426 strcat(command
,redirect
);
3428 TRACE("Ping command is : %s\n",command
);
3430 status
= system(command
);
3432 TRACE("Ping returned a code of %i\n",status
);
3434 /* Ping return code of 0 indicates success */
3440 heap_free( command
);
3442 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3448 /***********************************************************************
3449 * InternetCheckConnectionA (WININET.@)
3451 * Pings a requested host to check internet connection
3454 * TRUE on success and FALSE on failure. If a failure then
3455 * ERROR_NOT_CONNECTED is placed into GetLastError
3458 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3464 url
= heap_strdupAtoW(lpszUrl
);
3469 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3476 /**********************************************************
3477 * INTERNET_InternetOpenUrlW (internal)
3482 * handle of connection or NULL on failure
3484 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3485 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3487 URL_COMPONENTSW urlComponents
;
3488 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3489 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3490 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3491 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3492 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3494 HINTERNET client
= NULL
, client1
= NULL
;
3497 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3498 dwHeadersLength
, dwFlags
, dwContext
);
3500 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3501 urlComponents
.lpszScheme
= protocol
;
3502 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3503 urlComponents
.lpszHostName
= hostName
;
3504 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3505 urlComponents
.lpszUserName
= userName
;
3506 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3507 urlComponents
.lpszPassword
= password
;
3508 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3509 urlComponents
.lpszUrlPath
= path
;
3510 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3511 urlComponents
.lpszExtraInfo
= extra
;
3512 urlComponents
.dwExtraInfoLength
= 1024;
3513 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3515 switch(urlComponents
.nScheme
) {
3516 case INTERNET_SCHEME_FTP
:
3517 if(urlComponents
.nPort
== 0)
3518 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3519 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3520 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3523 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3524 if(client1
== NULL
) {
3525 InternetCloseHandle(client
);
3530 case INTERNET_SCHEME_HTTP
:
3531 case INTERNET_SCHEME_HTTPS
: {
3532 static const WCHAR szStars
[] = { '*','/','*', 0 };
3533 LPCWSTR accept
[2] = { szStars
, NULL
};
3534 if(urlComponents
.nPort
== 0) {
3535 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3536 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3538 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3540 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3542 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3543 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3544 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3545 if(res
!= ERROR_SUCCESS
) {
3546 INTERNET_SetLastError(res
);
3550 if (urlComponents
.dwExtraInfoLength
) {
3552 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3554 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3556 InternetCloseHandle(client
);
3559 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3560 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3561 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3562 heap_free(path_extra
);
3565 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3567 if(client1
== NULL
) {
3568 InternetCloseHandle(client
);
3571 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3572 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3573 GetLastError() != ERROR_IO_PENDING
) {
3574 InternetCloseHandle(client1
);
3579 case INTERNET_SCHEME_GOPHER
:
3580 /* gopher doesn't seem to be implemented in wine, but it's supposed
3581 * to be supported by InternetOpenUrlA. */
3583 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3587 TRACE(" %p <--\n", client1
);
3592 /**********************************************************
3593 * InternetOpenUrlW (WININET.@)
3598 * handle of connection or NULL on failure
3609 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3611 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3613 TRACE("%p\n", task
->hdr
.hdr
);
3615 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3616 task
->headers_len
, task
->flags
, task
->context
);
3617 heap_free(task
->url
);
3618 heap_free(task
->headers
);
3621 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3622 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3624 HINTERNET ret
= NULL
;
3625 appinfo_t
*hIC
= NULL
;
3627 if (TRACE_ON(wininet
)) {
3628 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3629 dwHeadersLength
, dwFlags
, dwContext
);
3631 dump_INTERNET_FLAGS(dwFlags
);
3636 SetLastError(ERROR_INVALID_PARAMETER
);
3640 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3641 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3642 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3646 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3647 open_url_task_t
*task
;
3649 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3650 task
->url
= heap_strdupW(lpszUrl
);
3651 task
->headers
= heap_strdupW(lpszHeaders
);
3652 task
->headers_len
= dwHeadersLength
;
3653 task
->flags
= dwFlags
;
3654 task
->context
= dwContext
;
3656 INTERNET_AsyncCall(&task
->hdr
);
3657 SetLastError(ERROR_IO_PENDING
);
3659 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3664 WININET_Release( &hIC
->hdr
);
3665 TRACE(" %p <--\n", ret
);
3670 /**********************************************************
3671 * InternetOpenUrlA (WININET.@)
3676 * handle of connection or NULL on failure
3678 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3679 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3681 HINTERNET rc
= NULL
;
3682 DWORD lenHeaders
= 0;
3683 LPWSTR szUrl
= NULL
;
3684 LPWSTR szHeaders
= NULL
;
3689 szUrl
= heap_strdupAtoW(lpszUrl
);
3695 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3696 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3701 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3704 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3705 lenHeaders
, dwFlags
, dwContext
);
3708 heap_free(szHeaders
);
3713 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3715 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3719 lpwite
->dwError
= 0;
3720 lpwite
->response
[0] = '\0';
3723 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3732 /***********************************************************************
3733 * INTERNET_SetLastError (internal)
3735 * Set last thread specific error
3740 void INTERNET_SetLastError(DWORD dwError
)
3742 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3745 lpwite
= INTERNET_AllocThreadError();
3747 SetLastError(dwError
);
3749 lpwite
->dwError
= dwError
;
3753 /***********************************************************************
3754 * INTERNET_GetLastError (internal)
3756 * Get last thread specific error
3761 DWORD
INTERNET_GetLastError(void)
3763 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3764 if (!lpwite
) return 0;
3765 /* TlsGetValue clears last error, so set it again here */
3766 SetLastError(lpwite
->dwError
);
3767 return lpwite
->dwError
;
3771 /***********************************************************************
3772 * INTERNET_WorkerThreadFunc (internal)
3774 * Worker thread execution function
3779 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3781 task_header_t
*task
= lpvParam
;
3786 WININET_Release(task
->hdr
);
3789 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3791 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3792 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3797 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3799 task_header_t
*task
;
3801 task
= heap_alloc(size
);
3805 task
->hdr
= WININET_AddRef(hdr
);
3810 /***********************************************************************
3811 * INTERNET_AsyncCall (internal)
3813 * Retrieves work request from queue
3818 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3824 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3828 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3830 return ERROR_SUCCESS
;
3834 /***********************************************************************
3835 * INTERNET_GetResponseBuffer (internal)
3840 LPSTR
INTERNET_GetResponseBuffer(void)
3842 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3844 lpwite
= INTERNET_AllocThreadError();
3846 return lpwite
->response
;
3849 /***********************************************************************
3850 * INTERNET_GetNextLine (internal)
3852 * Parse next line in directory string listing
3855 * Pointer to beginning of next line
3860 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3863 BOOL bSuccess
= FALSE
;
3865 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3870 pfd
.events
= POLLIN
;
3872 while (nRecv
< MAX_REPLY_LEN
)
3874 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3876 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3878 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3882 if (lpszBuffer
[nRecv
] == '\n')
3887 if (lpszBuffer
[nRecv
] != '\r')
3892 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3900 lpszBuffer
[nRecv
] = '\0';
3902 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3911 /**********************************************************
3912 * InternetQueryDataAvailable (WININET.@)
3914 * Determines how much data is available to be read.
3917 * TRUE on success, FALSE if an error occurred. If
3918 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3919 * no data is presently available, FALSE is returned with
3920 * the last error ERROR_IO_PENDING; a callback with status
3921 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3922 * data is available.
3924 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3925 LPDWORD lpdwNumberOfBytesAvailable
,
3926 DWORD dwFlags
, DWORD_PTR dwContext
)
3928 object_header_t
*hdr
;
3931 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3933 hdr
= get_handle_object( hFile
);
3935 SetLastError(ERROR_INVALID_HANDLE
);
3939 if(hdr
->vtbl
->QueryDataAvailable
) {
3940 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3942 WARN("wrong handle\n");
3943 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3946 WININET_Release(hdr
);
3948 if(res
!= ERROR_SUCCESS
)
3950 return res
== ERROR_SUCCESS
;
3953 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3955 req_file_t
*req_file
;
3957 req_file
= heap_alloc_zero(sizeof(*req_file
));
3959 return ERROR_NOT_ENOUGH_MEMORY
;
3963 req_file
->file_name
= heap_strdupW(file_name
);
3964 if(!req_file
->file_name
) {
3965 heap_free(req_file
);
3966 return ERROR_NOT_ENOUGH_MEMORY
;
3969 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3970 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3971 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
3972 req_file_release(req_file
);
3973 return GetLastError();
3977 return ERROR_SUCCESS
;
3980 void req_file_release(req_file_t
*req_file
)
3982 if(InterlockedDecrement(&req_file
->ref
))
3985 if(!req_file
->is_committed
)
3986 DeleteFileW(req_file
->file_name
);
3987 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
3988 CloseHandle(req_file
->file_handle
);
3989 heap_free(req_file
->file_name
);
3990 heap_free(req_file
);
3993 /***********************************************************************
3994 * InternetLockRequestFile (WININET.@)
3996 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
3998 req_file_t
*req_file
= NULL
;
3999 object_header_t
*hdr
;
4002 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
4004 hdr
= get_handle_object(hInternet
);
4006 SetLastError(ERROR_INVALID_HANDLE
);
4010 if(hdr
->vtbl
->LockRequestFile
) {
4011 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
4013 WARN("wrong handle\n");
4014 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4017 WININET_Release(hdr
);
4019 *lphLockReqHandle
= req_file
;
4020 if(res
!= ERROR_SUCCESS
)
4022 return res
== ERROR_SUCCESS
;
4025 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
4027 TRACE("(%p)\n", hLockHandle
);
4029 req_file_release(hLockHandle
);
4034 /***********************************************************************
4035 * InternetAutodial (WININET.@)
4037 * On windows this function is supposed to dial the default internet
4038 * connection. We don't want to have Wine dial out to the internet so
4039 * we return TRUE by default. It might be nice to check if we are connected.
4046 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
4050 /* Tell that we are connected to the internet. */
4054 /***********************************************************************
4055 * InternetAutodialHangup (WININET.@)
4057 * Hangs up a connection made with InternetAutodial
4066 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
4070 /* we didn't dial, we don't disconnect */
4074 /***********************************************************************
4075 * InternetCombineUrlA (WININET.@)
4077 * Combine a base URL with a relative URL
4085 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
4086 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4091 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4093 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4094 dwFlags
^= ICU_NO_ENCODE
;
4095 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4100 /***********************************************************************
4101 * InternetCombineUrlW (WININET.@)
4103 * Combine a base URL with a relative URL
4111 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4112 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4117 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4119 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4120 dwFlags
^= ICU_NO_ENCODE
;
4121 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4126 /* max port num is 65535 => 5 digits */
4127 #define MAX_WORD_DIGITS 5
4129 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4130 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4131 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4132 (url)->dw##component##Length : strlen((url)->lpsz##component))
4134 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4136 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4137 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4139 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4140 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4142 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4143 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4145 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4146 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4149 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4155 /* opaque urls do not fit into the standard url hierarchy and don't have
4156 * two following slashes */
4157 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4159 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4160 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4161 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4162 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4163 (nScheme
!= INTERNET_SCHEME_FILE
);
4166 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4169 if (scheme
< INTERNET_SCHEME_FIRST
)
4171 index
= scheme
- INTERNET_SCHEME_FIRST
;
4172 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4174 return (LPCWSTR
)url_schemes
[index
];
4177 /* we can calculate using ansi strings because we're just
4178 * calculating string length, not size
4180 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4181 LPDWORD lpdwUrlLength
)
4183 INTERNET_SCHEME nScheme
;
4187 if (lpUrlComponents
->lpszScheme
)
4189 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4190 *lpdwUrlLength
+= dwLen
;
4191 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4197 nScheme
= lpUrlComponents
->nScheme
;
4199 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4200 nScheme
= INTERNET_SCHEME_HTTP
;
4201 scheme
= INTERNET_GetSchemeString(nScheme
);
4202 *lpdwUrlLength
+= strlenW(scheme
);
4205 (*lpdwUrlLength
)++; /* ':' */
4206 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4207 *lpdwUrlLength
+= strlen("//");
4209 if (lpUrlComponents
->lpszUserName
)
4211 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4212 *lpdwUrlLength
+= strlen("@");
4216 if (lpUrlComponents
->lpszPassword
)
4218 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4223 if (lpUrlComponents
->lpszPassword
)
4225 *lpdwUrlLength
+= strlen(":");
4226 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4229 if (lpUrlComponents
->lpszHostName
)
4231 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4233 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4235 char szPort
[MAX_WORD_DIGITS
+1];
4237 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4238 *lpdwUrlLength
+= strlen(szPort
);
4239 *lpdwUrlLength
+= strlen(":");
4242 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4243 (*lpdwUrlLength
)++; /* '/' */
4246 if (lpUrlComponents
->lpszUrlPath
)
4247 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4249 if (lpUrlComponents
->lpszExtraInfo
)
4250 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4255 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4259 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4261 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4262 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4263 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4264 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4265 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4266 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4267 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4268 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4269 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4271 if (lpUrlComponents
->lpszScheme
)
4273 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4274 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4275 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4276 -1, urlCompW
->lpszScheme
, len
);
4279 if (lpUrlComponents
->lpszHostName
)
4281 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4282 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4283 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4284 -1, urlCompW
->lpszHostName
, len
);
4287 if (lpUrlComponents
->lpszUserName
)
4289 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4290 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4291 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4292 -1, urlCompW
->lpszUserName
, len
);
4295 if (lpUrlComponents
->lpszPassword
)
4297 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4298 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4299 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4300 -1, urlCompW
->lpszPassword
, len
);
4303 if (lpUrlComponents
->lpszUrlPath
)
4305 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4306 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4307 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4308 -1, urlCompW
->lpszUrlPath
, len
);
4311 if (lpUrlComponents
->lpszExtraInfo
)
4313 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4314 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4315 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4316 -1, urlCompW
->lpszExtraInfo
, len
);
4320 /***********************************************************************
4321 * InternetCreateUrlA (WININET.@)
4323 * See InternetCreateUrlW.
4325 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4326 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4330 URL_COMPONENTSW urlCompW
;
4332 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4334 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4336 SetLastError(ERROR_INVALID_PARAMETER
);
4340 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4343 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4345 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4347 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4348 *lpdwUrlLength
/= sizeof(WCHAR
);
4350 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4351 * minus one, so add one to leave room for NULL terminator
4354 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4356 heap_free(urlCompW
.lpszScheme
);
4357 heap_free(urlCompW
.lpszHostName
);
4358 heap_free(urlCompW
.lpszUserName
);
4359 heap_free(urlCompW
.lpszPassword
);
4360 heap_free(urlCompW
.lpszUrlPath
);
4361 heap_free(urlCompW
.lpszExtraInfo
);
4366 /***********************************************************************
4367 * InternetCreateUrlW (WININET.@)
4369 * Creates a URL from its component parts.
4372 * lpUrlComponents [I] URL Components.
4373 * dwFlags [I] Flags. See notes.
4374 * lpszUrl [I] Buffer in which to store the created URL.
4375 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4376 * lpszUrl in characters. On output, the number of bytes
4377 * required to store the URL including terminator.
4381 * The dwFlags parameter can be zero or more of the following:
4382 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4389 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4390 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4393 INTERNET_SCHEME nScheme
;
4395 static const WCHAR slashSlashW
[] = {'/','/'};
4396 static const WCHAR fmtW
[] = {'%','u',0};
4398 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4400 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4402 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4406 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4409 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4411 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4412 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4416 *lpdwUrlLength
= dwLen
;
4421 if (lpUrlComponents
->lpszScheme
)
4423 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4424 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4427 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4432 nScheme
= lpUrlComponents
->nScheme
;
4434 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4435 nScheme
= INTERNET_SCHEME_HTTP
;
4437 scheme
= INTERNET_GetSchemeString(nScheme
);
4438 dwLen
= strlenW(scheme
);
4439 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4443 /* all schemes are followed by at least a colon */
4447 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4449 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4450 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4453 if (lpUrlComponents
->lpszUserName
)
4455 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4456 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4459 if (lpUrlComponents
->lpszPassword
)
4464 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4465 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4473 if (lpUrlComponents
->lpszHostName
)
4475 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4476 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4479 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4481 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4483 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4486 dwLen
= strlenW(szPort
);
4487 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4491 /* add slash between hostname and path if necessary */
4492 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4499 if (lpUrlComponents
->lpszUrlPath
)
4501 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4502 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4506 if (lpUrlComponents
->lpszExtraInfo
)
4508 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4509 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4518 /***********************************************************************
4519 * InternetConfirmZoneCrossingA (WININET.@)
4522 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4524 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4525 return ERROR_SUCCESS
;
4528 /***********************************************************************
4529 * InternetConfirmZoneCrossingW (WININET.@)
4532 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4534 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4535 return ERROR_SUCCESS
;
4538 static DWORD zone_preference
= 3;
4540 /***********************************************************************
4541 * PrivacySetZonePreferenceW (WININET.@)
4543 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4545 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4547 zone_preference
= template;
4551 /***********************************************************************
4552 * PrivacyGetZonePreferenceW (WININET.@)
4554 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4555 LPWSTR preference
, LPDWORD length
)
4557 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4559 if (template) *template = zone_preference
;
4563 /***********************************************************************
4564 * InternetGetSecurityInfoByURLA (WININET.@)
4566 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4571 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4573 url
= heap_strdupAtoW(lpszURL
);
4577 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4582 /***********************************************************************
4583 * InternetGetSecurityInfoByURLW (WININET.@)
4585 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4587 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4588 URL_COMPONENTSW url
= {sizeof(url
)};
4592 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4594 url
.lpszHostName
= hostname
;
4595 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4597 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4598 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4599 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4603 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4605 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4609 if(server
->cert_chain
) {
4610 const CERT_CHAIN_CONTEXT
*chain_dup
;
4612 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4614 *ppCertChain
= chain_dup
;
4615 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4620 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4624 server_release(server
);
4628 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4629 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4631 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4632 lpdwConnection
, dwReserved
);
4633 return ERROR_SUCCESS
;
4636 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4637 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4639 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4640 lpdwConnection
, dwReserved
);
4641 return ERROR_SUCCESS
;
4644 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4646 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4650 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4652 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4656 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4658 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4659 return ERROR_SUCCESS
;
4662 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4665 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4666 debugstr_w(pwszTarget
), pbHexHash
);
4670 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4672 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4676 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4678 FIXME("(%p, %08lx) stub\n", a
, b
);
4682 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4684 FIXME("%p: stub\n", parent
);