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
31 #define RESPONSE_TIMEOUT 30
36 CHAR response
[MAX_REPLY_LEN
];
37 } WITHREADERROR
, *LPWITHREADERROR
;
39 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
40 HMODULE WININET_hModule
;
42 static CRITICAL_SECTION WININET_cs
;
43 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
46 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
47 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
49 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
51 static object_header_t
**handle_table
;
52 static UINT_PTR next_handle
;
53 static UINT_PTR handle_table_size
;
64 static ULONG max_conns
= 2, max_1_0_conns
= 4;
65 static ULONG connect_timeout
= 60000;
67 static const WCHAR szInternetSettings
[] =
68 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
69 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
70 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
71 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
72 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
73 static const WCHAR szProxyOverride
[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
75 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
77 UINT_PTR handle
= 0, num
;
82 ret
= heap_alloc_zero(size
);
86 list_init(&ret
->children
);
88 EnterCriticalSection( &WININET_cs
);
90 if(!handle_table_size
) {
92 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
95 handle_table_size
= num
;
100 }else if(next_handle
== handle_table_size
) {
101 num
= handle_table_size
* 2;
102 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
105 handle_table_size
= num
;
112 handle
= next_handle
;
113 if(handle_table
[handle
])
114 ERR("handle isn't free but should be\n");
115 handle_table
[handle
] = ret
;
116 ret
->valid_handle
= TRUE
;
118 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
122 LeaveCriticalSection( &WININET_cs
);
131 ret
->hInternet
= (HINTERNET
)handle
;
134 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
135 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
141 object_header_t
*WININET_AddRef( object_header_t
*info
)
143 ULONG refs
= InterlockedIncrement(&info
->refs
);
144 TRACE("%p -> refcount = %d\n", info
, refs
);
148 object_header_t
*get_handle_object( HINTERNET hinternet
)
150 object_header_t
*info
= NULL
;
151 UINT_PTR handle
= (UINT_PTR
) hinternet
;
153 EnterCriticalSection( &WININET_cs
);
155 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
156 info
= WININET_AddRef(handle_table
[handle
]);
158 LeaveCriticalSection( &WININET_cs
);
160 TRACE("handle %ld -> %p\n", handle
, info
);
165 static void invalidate_handle(object_header_t
*info
)
167 object_header_t
*child
, *next
;
169 if(!info
->valid_handle
)
171 info
->valid_handle
= FALSE
;
173 /* Free all children as native does */
174 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
176 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
177 invalidate_handle( child
);
180 WININET_Release(info
);
183 BOOL
WININET_Release( object_header_t
*info
)
185 ULONG refs
= InterlockedDecrement(&info
->refs
);
186 TRACE( "object %p refcount = %d\n", info
, refs
);
189 invalidate_handle(info
);
190 if ( info
->vtbl
->CloseConnection
)
192 TRACE( "closing connection %p\n", info
);
193 info
->vtbl
->CloseConnection( info
);
195 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
196 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
197 || !(info
->dwInternalFlags
& INET_OPENURL
))
199 INTERNET_SendCallback(info
, info
->dwContext
,
200 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
203 TRACE( "destroying object %p\n", info
);
204 if ( info
->htype
!= WH_HINIT
)
205 list_remove( &info
->entry
);
206 info
->vtbl
->Destroy( info
);
208 if(info
->hInternet
) {
209 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
211 EnterCriticalSection( &WININET_cs
);
213 handle_table
[handle
] = NULL
;
214 if(next_handle
> handle
)
215 next_handle
= handle
;
217 LeaveCriticalSection( &WININET_cs
);
225 /***********************************************************************
226 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
229 * hinstDLL [I] handle to the DLL's instance
231 * lpvReserved [I] reserved, must be NULL
238 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
240 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
243 case DLL_PROCESS_ATTACH
:
245 g_dwTlsErrIndex
= TlsAlloc();
247 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
252 TlsFree(g_dwTlsErrIndex
);
256 WININET_hModule
= hinstDLL
;
259 case DLL_THREAD_ATTACH
:
262 case DLL_THREAD_DETACH
:
263 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
265 heap_free(TlsGetValue(g_dwTlsErrIndex
));
269 case DLL_PROCESS_DETACH
:
270 if (lpvReserved
) break;
271 collect_connections(COLLECT_CLEANUP
);
276 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
278 heap_free(TlsGetValue(g_dwTlsErrIndex
));
279 TlsFree(g_dwTlsErrIndex
);
286 /***********************************************************************
287 * DllInstall (WININET.@)
289 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
291 FIXME("(%x %s): stub\n", bInstall
, debugstr_w(cmdline
));
295 /***********************************************************************
296 * INTERNET_SaveProxySettings
298 * Stores the proxy settings given by lpwai into the registry
301 * ERROR_SUCCESS if no error, or error code on fail
303 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
308 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
311 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
319 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
327 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
335 return ERROR_SUCCESS
;
338 /***********************************************************************
339 * INTERNET_FindProxyForProtocol
341 * Searches the proxy string for a proxy of the given protocol.
342 * Returns the found proxy, or the default proxy if none of the given
346 * szProxy [In] proxy string to search
347 * proto [In] protocol to search for, e.g. "http"
348 * foundProxy [Out] found proxy
349 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
352 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
353 * *foundProxyLen is set to the required size in WCHARs, including the
354 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
356 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
361 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
363 /* First, look for the specified protocol (proto=scheme://host:port) */
364 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
368 if (!(end
= strchrW(ptr
, ' ')))
369 end
= ptr
+ strlenW(ptr
);
370 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
371 equal
- ptr
== strlenW(proto
) &&
372 !strncmpiW(proto
, ptr
, strlenW(proto
)))
374 if (end
- equal
> *foundProxyLen
)
376 WARN("buffer too short for %s\n",
377 debugstr_wn(equal
+ 1, end
- equal
- 1));
378 *foundProxyLen
= end
- equal
;
379 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
383 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
384 foundProxy
[end
- equal
] = 0;
395 /* It wasn't found: look for no protocol */
396 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
400 if (!(end
= strchrW(ptr
, ' ')))
401 end
= ptr
+ strlenW(ptr
);
402 if (!strchrW(ptr
, '='))
404 if (end
- ptr
+ 1 > *foundProxyLen
)
406 WARN("buffer too short for %s\n",
407 debugstr_wn(ptr
, end
- ptr
));
408 *foundProxyLen
= end
- ptr
+ 1;
409 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
413 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
414 foundProxy
[end
- ptr
] = 0;
425 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
426 debugstr_w(foundProxy
));
430 /***********************************************************************
431 * InternetInitializeAutoProxyDll (WININET.@)
433 * Setup the internal proxy
442 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
445 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
449 /***********************************************************************
450 * DetectAutoProxyUrl (WININET.@)
452 * Auto detect the proxy url
458 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
459 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
462 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
466 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
468 heap_free(lpwpi
->proxy
);
469 heap_free(lpwpi
->proxyBypass
);
470 heap_free(lpwpi
->proxyUsername
);
471 heap_free(lpwpi
->proxyPassword
);
474 static proxyinfo_t
*global_proxy
;
476 static void free_global_proxy( void )
478 EnterCriticalSection( &WININET_cs
);
481 FreeProxyInfo( global_proxy
);
482 heap_free( global_proxy
);
484 LeaveCriticalSection( &WININET_cs
);
487 static BOOL
parse_proxy_url( proxyinfo_t
*info
, const WCHAR
*url
)
489 static const WCHAR fmt
[] = {'%','s',':','%','u',0};
490 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
] = {0};
491 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
] = {0};
492 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
] = {0};
495 memset( &uc
, 0, sizeof(uc
) );
496 uc
.dwStructSize
= sizeof(uc
);
497 uc
.lpszHostName
= hostname
;
498 uc
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
499 uc
.lpszUserName
= username
;
500 uc
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
501 uc
.lpszPassword
= password
;
502 uc
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
504 if (!InternetCrackUrlW( url
, 0, 0, &uc
)) return FALSE
;
507 if (!(info
->proxy
= heap_strdupW( url
))) return FALSE
;
508 info
->proxyUsername
= NULL
;
509 info
->proxyPassword
= NULL
;
512 if (!(info
->proxy
= heap_alloc( (strlenW(hostname
) + 12) * sizeof(WCHAR
) ))) return FALSE
;
513 sprintfW( info
->proxy
, fmt
, hostname
, uc
.nPort
);
515 if (!username
[0]) info
->proxyUsername
= NULL
;
516 else if (!(info
->proxyUsername
= heap_strdupW( username
)))
518 heap_free( info
->proxy
);
521 if (!password
[0]) info
->proxyPassword
= NULL
;
522 else if (!(info
->proxyPassword
= heap_strdupW( password
)))
524 heap_free( info
->proxyUsername
);
525 heap_free( info
->proxy
);
531 /***********************************************************************
532 * INTERNET_LoadProxySettings
534 * Loads proxy information from process-wide global settings, the registry,
535 * or the environment into lpwpi.
537 * The caller should call FreeProxyInfo when done with lpwpi.
540 * The proxy may be specified in the form 'http=proxy.my.org'
541 * Presumably that means there can be ftp=ftpproxy.my.org too.
543 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
550 memset( lpwpi
, 0, sizeof(*lpwpi
) );
552 EnterCriticalSection( &WININET_cs
);
555 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
556 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
557 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
559 LeaveCriticalSection( &WININET_cs
);
561 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
563 FreeProxyInfo( lpwpi
);
568 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
570 lpwpi
->proxyEnabled
= 0;
571 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
573 FreeProxyInfo( lpwpi
);
579 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
581 /* figure out how much memory the proxy setting takes */
582 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
585 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
587 if (!(szProxy
= heap_alloc(len
)))
590 FreeProxyInfo( lpwpi
);
591 return ERROR_OUTOFMEMORY
;
593 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
595 /* find the http proxy, and strip away everything else */
596 p
= strstrW( szProxy
, szHttp
);
599 p
+= lstrlenW( szHttp
);
600 lstrcpyW( szProxy
, p
);
602 p
= strchrW( szProxy
, ';' );
605 FreeProxyInfo( lpwpi
);
606 lpwpi
->proxy
= szProxy
;
607 lpwpi
->proxyBypass
= NULL
;
609 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi
->proxy
));
613 TRACE("No proxy server settings in registry.\n");
614 FreeProxyInfo( lpwpi
);
616 lpwpi
->proxyBypass
= NULL
;
623 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
624 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
627 return ERROR_OUTOFMEMORY
;
629 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
631 FreeProxyInfo( lpwpi
);
632 if (parse_proxy_url( lpwpi
, envproxyW
))
634 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
635 lpwpi
->proxyEnabled
= 1;
636 lpwpi
->proxyBypass
= NULL
;
640 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW
));
641 lpwpi
->proxyEnabled
= 0;
643 lpwpi
->proxyBypass
= NULL
;
645 heap_free( envproxyW
);
648 if (lpwpi
->proxyEnabled
)
650 TRACE("Proxy is enabled.\n");
652 if (!(envproxy
= getenv( "no_proxy" )))
654 /* figure out how much memory the proxy setting takes */
655 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
659 if (!(szProxy
= heap_alloc(len
)))
662 return ERROR_OUTOFMEMORY
;
664 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
666 heap_free( lpwpi
->proxyBypass
);
667 lpwpi
->proxyBypass
= szProxy
;
669 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
673 heap_free( lpwpi
->proxyBypass
);
674 lpwpi
->proxyBypass
= NULL
;
676 TRACE("No proxy bypass server settings in registry.\n");
683 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
684 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
687 return ERROR_OUTOFMEMORY
;
689 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
691 heap_free( lpwpi
->proxyBypass
);
692 lpwpi
->proxyBypass
= envproxyW
;
694 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
697 else TRACE("Proxy is disabled.\n");
700 return ERROR_SUCCESS
;
703 /***********************************************************************
704 * INTERNET_ConfigureProxy
706 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
710 if (INTERNET_LoadProxySettings( &wpi
))
713 if (wpi
.proxyEnabled
)
715 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai
->proxy
), debugstr_w(lpwai
->proxyBypass
));
717 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
718 lpwai
->proxy
= wpi
.proxy
;
719 lpwai
->proxyBypass
= wpi
.proxyBypass
;
720 lpwai
->proxyUsername
= wpi
.proxyUsername
;
721 lpwai
->proxyPassword
= wpi
.proxyPassword
;
725 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
730 /***********************************************************************
731 * dump_INTERNET_FLAGS
733 * Helper function to TRACE the internet flags.
739 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
741 #define FE(x) { x, #x }
742 static const wininet_flag_info flag
[] = {
743 FE(INTERNET_FLAG_RELOAD
),
744 FE(INTERNET_FLAG_RAW_DATA
),
745 FE(INTERNET_FLAG_EXISTING_CONNECT
),
746 FE(INTERNET_FLAG_ASYNC
),
747 FE(INTERNET_FLAG_PASSIVE
),
748 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
749 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
750 FE(INTERNET_FLAG_FROM_CACHE
),
751 FE(INTERNET_FLAG_SECURE
),
752 FE(INTERNET_FLAG_KEEP_CONNECTION
),
753 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
754 FE(INTERNET_FLAG_READ_PREFETCH
),
755 FE(INTERNET_FLAG_NO_COOKIES
),
756 FE(INTERNET_FLAG_NO_AUTH
),
757 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
758 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
759 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
760 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
761 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
762 FE(INTERNET_FLAG_RESYNCHRONIZE
),
763 FE(INTERNET_FLAG_HYPERLINK
),
764 FE(INTERNET_FLAG_NO_UI
),
765 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
766 FE(INTERNET_FLAG_CACHE_ASYNC
),
767 FE(INTERNET_FLAG_FORMS_SUBMIT
),
768 FE(INTERNET_FLAG_NEED_FILE
),
769 FE(INTERNET_FLAG_TRANSFER_ASCII
),
770 FE(INTERNET_FLAG_TRANSFER_BINARY
)
775 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
776 if (flag
[i
].val
& dwFlags
) {
777 TRACE(" %s", flag
[i
].name
);
778 dwFlags
&= ~flag
[i
].val
;
782 TRACE(" Unknown flags (%08x)\n", dwFlags
);
787 /***********************************************************************
788 * INTERNET_CloseHandle (internal)
790 * Close internet handle
793 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
795 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
799 heap_free(lpwai
->agent
);
800 heap_free(lpwai
->proxy
);
801 heap_free(lpwai
->proxyBypass
);
802 heap_free(lpwai
->proxyUsername
);
803 heap_free(lpwai
->proxyPassword
);
809 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
811 appinfo_t
*ai
= (appinfo_t
*)hdr
;
814 case INTERNET_OPTION_HANDLE_TYPE
:
815 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
817 if (*size
< sizeof(ULONG
))
818 return ERROR_INSUFFICIENT_BUFFER
;
820 *size
= sizeof(DWORD
);
821 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
822 return ERROR_SUCCESS
;
824 case INTERNET_OPTION_USER_AGENT
: {
827 TRACE("INTERNET_OPTION_USER_AGENT\n");
832 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
834 *size
= (len
+ 1) * sizeof(WCHAR
);
835 if(!buffer
|| bufsize
< *size
)
836 return ERROR_INSUFFICIENT_BUFFER
;
839 strcpyW(buffer
, ai
->agent
);
841 *(WCHAR
*)buffer
= 0;
842 /* If the buffer is copied, the returned length doesn't include
843 * the NULL terminator.
848 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
851 if(!buffer
|| bufsize
< *size
)
852 return ERROR_INSUFFICIENT_BUFFER
;
855 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
858 /* If the buffer is copied, the returned length doesn't include
859 * the NULL terminator.
864 return ERROR_SUCCESS
;
867 case INTERNET_OPTION_PROXY
:
868 if(!size
) return ERROR_INVALID_PARAMETER
;
870 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
871 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
872 LPWSTR proxy
, proxy_bypass
;
875 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
877 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
878 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
880 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
881 return ERROR_INSUFFICIENT_BUFFER
;
883 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
884 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
886 pi
->dwAccessType
= ai
->accessType
;
887 pi
->lpszProxy
= NULL
;
888 pi
->lpszProxyBypass
= NULL
;
890 lstrcpyW(proxy
, ai
->proxy
);
891 pi
->lpszProxy
= proxy
;
894 if (ai
->proxyBypass
) {
895 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
896 pi
->lpszProxyBypass
= proxy_bypass
;
899 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
900 return ERROR_SUCCESS
;
902 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
903 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
904 LPSTR proxy
, proxy_bypass
;
907 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
909 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
910 NULL
, 0, NULL
, NULL
);
911 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
913 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
914 return ERROR_INSUFFICIENT_BUFFER
;
916 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
917 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
919 pi
->dwAccessType
= ai
->accessType
;
920 pi
->lpszProxy
= NULL
;
921 pi
->lpszProxyBypass
= NULL
;
923 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
924 pi
->lpszProxy
= proxy
;
927 if (ai
->proxyBypass
) {
928 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
929 proxyBypassBytesRequired
, NULL
, NULL
);
930 pi
->lpszProxyBypass
= proxy_bypass
;
933 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
934 return ERROR_SUCCESS
;
937 case INTERNET_OPTION_CONNECT_TIMEOUT
:
938 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
940 if (*size
< sizeof(ULONG
))
941 return ERROR_INSUFFICIENT_BUFFER
;
943 *(ULONG
*)buffer
= ai
->connect_timeout
;
944 *size
= sizeof(ULONG
);
946 return ERROR_SUCCESS
;
949 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
952 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
954 appinfo_t
*ai
= (appinfo_t
*)hdr
;
957 case INTERNET_OPTION_CONNECT_TIMEOUT
:
958 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
960 if(size
!= sizeof(connect_timeout
))
961 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
963 return ERROR_BAD_ARGUMENTS
;
965 ai
->connect_timeout
= *(ULONG
*)buf
;
966 return ERROR_SUCCESS
;
967 case INTERNET_OPTION_USER_AGENT
:
968 heap_free(ai
->agent
);
969 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
970 return ERROR_SUCCESS
;
973 return INET_SetOption(hdr
, option
, buf
, size
);
976 static const object_vtbl_t APPINFOVtbl
= {
988 /***********************************************************************
989 * InternetOpenW (WININET.@)
991 * Per-application initialization of wininet
994 * HINTERNET on success
998 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
999 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
1001 appinfo_t
*lpwai
= NULL
;
1004 int error
= WSAStartup(MAKEWORD(2, 2), &wsaData
);
1005 if (error
) ERR("WSAStartup failed: %d\n", error
);
1008 if (TRACE_ON(wininet
)) {
1009 #define FE(x) { x, #x }
1010 static const wininet_flag_info access_type
[] = {
1011 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
1012 FE(INTERNET_OPEN_TYPE_DIRECT
),
1013 FE(INTERNET_OPEN_TYPE_PROXY
),
1014 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
1018 const char *access_type_str
= "Unknown";
1020 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1021 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1022 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
1023 if (access_type
[i
].val
== dwAccessType
) {
1024 access_type_str
= access_type
[i
].name
;
1028 TRACE(" access type : %s\n", access_type_str
);
1030 dump_INTERNET_FLAGS(dwFlags
);
1033 /* Clear any error information */
1034 INTERNET_SetLastError(0);
1036 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1037 SetLastError(ERROR_INVALID_PARAMETER
);
1041 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1043 SetLastError(ERROR_OUTOFMEMORY
);
1047 lpwai
->hdr
.htype
= WH_HINIT
;
1048 lpwai
->hdr
.dwFlags
= dwFlags
;
1049 lpwai
->accessType
= dwAccessType
;
1050 lpwai
->proxyUsername
= NULL
;
1051 lpwai
->proxyPassword
= NULL
;
1052 lpwai
->connect_timeout
= connect_timeout
;
1054 lpwai
->agent
= heap_strdupW(lpszAgent
);
1055 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1056 INTERNET_ConfigureProxy( lpwai
);
1057 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1058 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1059 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1062 TRACE("returning %p\n", lpwai
);
1064 return lpwai
->hdr
.hInternet
;
1068 /***********************************************************************
1069 * InternetOpenA (WININET.@)
1071 * Per-application initialization of wininet
1074 * HINTERNET on success
1078 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1079 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1081 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1084 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1085 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1087 szAgent
= heap_strdupAtoW(lpszAgent
);
1088 szProxy
= heap_strdupAtoW(lpszProxy
);
1089 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1091 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1095 heap_free(szBypass
);
1099 /***********************************************************************
1100 * InternetGetLastResponseInfoA (WININET.@)
1102 * Return last wininet error description on the calling thread
1105 * TRUE on success of writing to buffer
1109 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1110 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1112 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1118 *lpdwError
= lpwite
->dwError
;
1119 if (lpwite
->dwError
)
1121 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1122 *lpdwBufferLength
= strlen(lpszBuffer
);
1125 *lpdwBufferLength
= 0;
1130 *lpdwBufferLength
= 0;
1136 /***********************************************************************
1137 * InternetGetLastResponseInfoW (WININET.@)
1139 * Return last wininet error description on the calling thread
1142 * TRUE on success of writing to buffer
1146 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1147 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1149 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1155 *lpdwError
= lpwite
->dwError
;
1156 if (lpwite
->dwError
)
1158 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1159 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1162 *lpdwBufferLength
= 0;
1167 *lpdwBufferLength
= 0;
1173 /***********************************************************************
1174 * InternetGetConnectedState (WININET.@)
1176 * Return connected state
1180 * if lpdwStatus is not null, return the status (off line,
1181 * modem, lan...) in it.
1182 * FALSE if not connected
1184 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1186 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1189 WARN("always returning LAN connection.\n");
1190 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1196 /***********************************************************************
1197 * InternetGetConnectedStateExW (WININET.@)
1199 * Return connected state
1203 * lpdwStatus [O] Flags specifying the status of the internet connection.
1204 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1205 * dwNameLen [I] Size of the buffer, in characters.
1206 * dwReserved [I] Reserved. Must be set to 0.
1210 * if lpdwStatus is not null, return the status (off line,
1211 * modem, lan...) in it.
1212 * FALSE if not connected
1215 * If the system has no available network connections, an empty string is
1216 * stored in lpszConnectionName. If there is a LAN connection, a localized
1217 * "LAN Connection" string is stored. Presumably, if only a dial-up
1218 * connection is available then the name of the dial-up connection is
1219 * returned. Why any application, other than the "Internet Settings" CPL,
1220 * would want to use this function instead of the simpler InternetGetConnectedStateW
1221 * function is beyond me.
1223 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1224 DWORD dwNameLen
, DWORD dwReserved
)
1226 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1233 WARN("always returning LAN connection.\n");
1234 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1236 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
) > 0;
1240 /***********************************************************************
1241 * InternetGetConnectedStateExA (WININET.@)
1243 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1244 DWORD dwNameLen
, DWORD dwReserved
)
1246 LPWSTR lpwszConnectionName
= NULL
;
1249 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1251 if (lpszConnectionName
&& dwNameLen
> 0)
1252 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1254 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1256 if (rc
&& lpwszConnectionName
)
1257 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1258 dwNameLen
, NULL
, NULL
);
1260 heap_free(lpwszConnectionName
);
1265 /***********************************************************************
1266 * InternetConnectW (WININET.@)
1268 * Open a ftp, gopher or http session
1271 * HINTERNET a session handle on success
1275 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1276 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1277 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1278 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1281 HINTERNET rc
= NULL
;
1282 DWORD res
= ERROR_SUCCESS
;
1284 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1285 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1286 dwService
, dwFlags
, dwContext
);
1288 if (!lpszServerName
)
1290 SetLastError(ERROR_INVALID_PARAMETER
);
1294 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1295 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1297 res
= ERROR_INVALID_HANDLE
;
1303 case INTERNET_SERVICE_FTP
:
1304 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1305 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1307 res
= INTERNET_GetLastError();
1310 case INTERNET_SERVICE_HTTP
:
1311 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1312 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1315 case INTERNET_SERVICE_GOPHER
:
1321 WININET_Release( &hIC
->hdr
);
1323 TRACE("returning %p\n", rc
);
1329 /***********************************************************************
1330 * InternetConnectA (WININET.@)
1332 * Open a ftp, gopher or http session
1335 * HINTERNET a session handle on success
1339 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1340 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1341 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1342 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1344 HINTERNET rc
= NULL
;
1345 LPWSTR szServerName
;
1349 szServerName
= heap_strdupAtoW(lpszServerName
);
1350 szUserName
= heap_strdupAtoW(lpszUserName
);
1351 szPassword
= heap_strdupAtoW(lpszPassword
);
1353 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1354 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1356 heap_free(szServerName
);
1357 heap_free(szUserName
);
1358 heap_free(szPassword
);
1363 /***********************************************************************
1364 * InternetFindNextFileA (WININET.@)
1366 * Continues a file search from a previous call to FindFirstFile
1373 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1376 WIN32_FIND_DATAW fd
;
1378 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1380 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1384 /***********************************************************************
1385 * InternetFindNextFileW (WININET.@)
1387 * Continues a file search from a previous call to FindFirstFile
1394 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1396 object_header_t
*hdr
;
1401 hdr
= get_handle_object(hFind
);
1403 WARN("Invalid handle\n");
1404 SetLastError(ERROR_INVALID_HANDLE
);
1408 if(hdr
->vtbl
->FindNextFileW
) {
1409 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1411 WARN("Handle doesn't support NextFile\n");
1412 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1415 WININET_Release(hdr
);
1417 if(res
!= ERROR_SUCCESS
)
1419 return res
== ERROR_SUCCESS
;
1422 /***********************************************************************
1423 * InternetCloseHandle (WININET.@)
1425 * Generic close handle function
1432 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1434 object_header_t
*obj
;
1436 TRACE("%p\n", hInternet
);
1438 obj
= get_handle_object( hInternet
);
1440 SetLastError(ERROR_INVALID_HANDLE
);
1444 invalidate_handle(obj
);
1445 WININET_Release(obj
);
1451 /***********************************************************************
1452 * ConvertUrlComponentValue (Internal)
1454 * Helper function for InternetCrackUrlA
1457 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1458 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1459 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1461 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1462 if (*dwComponentLen
!= 0)
1464 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1465 if (*lppszComponent
== NULL
)
1469 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1470 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1473 *lppszComponent
= NULL
;
1475 *dwComponentLen
= nASCIILength
;
1479 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1480 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1481 (*lppszComponent
)[ncpylen
]=0;
1482 *dwComponentLen
= ncpylen
;
1488 /***********************************************************************
1489 * InternetCrackUrlA (WININET.@)
1491 * See InternetCrackUrlW.
1493 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1494 LPURL_COMPONENTSA lpUrlComponents
)
1497 URL_COMPONENTSW UCW
;
1499 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1500 *scheme
= NULL
, *extra
= NULL
;
1502 TRACE("(%s %u %x %p)\n",
1503 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1504 dwUrlLength
, dwFlags
, lpUrlComponents
);
1506 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1507 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1509 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1515 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1517 /* if dwUrlLength=-1 then nLength includes null but length to
1518 InternetCrackUrlW should not include it */
1519 if (dwUrlLength
== -1) nLength
--;
1521 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1522 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1523 lpwszUrl
[nLength
] = '\0';
1525 memset(&UCW
,0,sizeof(UCW
));
1526 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1527 if (lpUrlComponents
->dwHostNameLength
)
1529 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1530 if (lpUrlComponents
->lpszHostName
)
1532 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1533 UCW
.lpszHostName
= hostname
;
1536 if (lpUrlComponents
->dwUserNameLength
)
1538 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1539 if (lpUrlComponents
->lpszUserName
)
1541 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1542 UCW
.lpszUserName
= username
;
1545 if (lpUrlComponents
->dwPasswordLength
)
1547 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1548 if (lpUrlComponents
->lpszPassword
)
1550 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1551 UCW
.lpszPassword
= password
;
1554 if (lpUrlComponents
->dwUrlPathLength
)
1556 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1557 if (lpUrlComponents
->lpszUrlPath
)
1559 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1560 UCW
.lpszUrlPath
= path
;
1563 if (lpUrlComponents
->dwSchemeLength
)
1565 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1566 if (lpUrlComponents
->lpszScheme
)
1568 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1569 UCW
.lpszScheme
= scheme
;
1572 if (lpUrlComponents
->dwExtraInfoLength
)
1574 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1575 if (lpUrlComponents
->lpszExtraInfo
)
1577 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1578 UCW
.lpszExtraInfo
= extra
;
1581 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1583 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1584 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1585 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1586 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1587 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1588 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1589 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1590 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1591 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1592 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1593 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1594 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1596 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1597 lpUrlComponents
->nPort
= UCW
.nPort
;
1599 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1600 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1601 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1602 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1603 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1605 heap_free(lpwszUrl
);
1606 heap_free(hostname
);
1607 heap_free(username
);
1608 heap_free(password
);
1615 static const WCHAR url_schemes
[][7] =
1618 {'g','o','p','h','e','r',0},
1619 {'h','t','t','p',0},
1620 {'h','t','t','p','s',0},
1621 {'f','i','l','e',0},
1622 {'n','e','w','s',0},
1623 {'m','a','i','l','t','o',0},
1627 /***********************************************************************
1628 * GetInternetSchemeW (internal)
1634 * INTERNET_SCHEME_UNKNOWN on failure
1637 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1641 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1643 if(lpszScheme
==NULL
)
1644 return INTERNET_SCHEME_UNKNOWN
;
1646 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1647 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1648 return INTERNET_SCHEME_FIRST
+ i
;
1650 return INTERNET_SCHEME_UNKNOWN
;
1653 /***********************************************************************
1654 * SetUrlComponentValueW (Internal)
1656 * Helper function for InternetCrackUrlW
1659 * lppszComponent [O] Holds the returned string
1660 * dwComponentLen [I] Holds the size of lppszComponent
1661 * [O] Holds the length of the string in lppszComponent without '\0'
1662 * lpszStart [I] Holds the string to copy from
1663 * len [I] Holds the length of lpszStart without '\0'
1670 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1672 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1674 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1677 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1679 if (*lppszComponent
== NULL
)
1681 *lppszComponent
= (LPWSTR
)lpszStart
;
1682 *dwComponentLen
= len
;
1686 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1687 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1688 (*lppszComponent
)[ncpylen
] = '\0';
1689 *dwComponentLen
= ncpylen
;
1696 /***********************************************************************
1697 * InternetCrackUrlW (WININET.@)
1699 * Break up URL into its components
1705 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1706 LPURL_COMPONENTSW lpUC
)
1710 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1713 LPCWSTR lpszParam
= NULL
;
1714 BOOL found_colon
= FALSE
;
1715 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1716 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1717 LPWSTR lpszUrl_decode
= NULL
;
1718 DWORD dwUrlLength
= dwUrlLength_orig
;
1720 TRACE("(%s %u %x %p)\n",
1721 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1722 dwUrlLength
, dwFlags
, lpUC
);
1724 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1726 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1729 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1731 if (dwFlags
& ICU_DECODE
)
1734 DWORD len
= dwUrlLength
+ 1;
1736 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1738 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1741 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1742 url_tmp
[dwUrlLength
] = 0;
1743 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1746 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1749 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1752 lpszUrl
= lpszUrl_decode
;
1758 /* Determine if the URI is absolute. */
1759 while (lpszap
- lpszUrl
< dwUrlLength
)
1761 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1773 lpszcp
= lpszUrl
; /* Relative url */
1780 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1784 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1785 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1787 /* Parse <params> */
1788 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1790 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1792 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1793 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1796 /* Get scheme first. */
1797 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1798 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1799 lpszUrl
, lpszcp
- lpszUrl
);
1801 /* Eat ':' in protocol. */
1804 /* double slash indicates the net_loc portion is present */
1805 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1809 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1813 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1815 lpszNetLoc
= lpszParam
;
1817 else if (!lpszNetLoc
)
1818 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1826 /* [<user>[<:password>]@]<host>[:<port>] */
1827 /* First find the user and password if they exist */
1829 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1830 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1832 /* username and password not specified. */
1833 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1834 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1836 else /* Parse out username and password */
1838 LPCWSTR lpszUser
= lpszcp
;
1839 LPCWSTR lpszPasswd
= lpszHost
;
1841 while (lpszcp
< lpszHost
)
1844 lpszPasswd
= lpszcp
;
1849 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1850 lpszUser
, lpszPasswd
- lpszUser
);
1852 if (lpszPasswd
!= lpszHost
)
1854 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1855 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1856 lpszHost
- lpszPasswd
);
1858 lpszcp
++; /* Advance to beginning of host */
1861 /* Parse <host><:port> */
1864 lpszPort
= lpszNetLoc
;
1866 /* special case for res:// URLs: there is no port here, so the host is the
1867 entire string up to the first '/' */
1868 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1870 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1871 lpszHost
, lpszPort
- lpszHost
);
1876 while (lpszcp
< lpszNetLoc
)
1884 /* If the scheme is "file" and the host is just one letter, it's not a host */
1885 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1888 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1893 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1894 lpszHost
, lpszPort
- lpszHost
);
1895 if (lpszPort
!= lpszNetLoc
)
1896 lpUC
->nPort
= atoiW(++lpszPort
);
1897 else switch (lpUC
->nScheme
)
1899 case INTERNET_SCHEME_HTTP
:
1900 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1902 case INTERNET_SCHEME_HTTPS
:
1903 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1905 case INTERNET_SCHEME_FTP
:
1906 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1908 case INTERNET_SCHEME_GOPHER
:
1909 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1920 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1921 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1922 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1925 /* Here lpszcp points to:
1927 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1928 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1930 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1934 /* Only truncate the parameter list if it's already been saved
1935 * in lpUC->lpszExtraInfo.
1937 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1938 len
= lpszParam
- lpszcp
;
1941 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1942 * newlines if necessary.
1944 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1945 if (lpsznewline
!= NULL
)
1946 len
= lpsznewline
- lpszcp
;
1948 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1950 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1951 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1953 WCHAR tmppath
[MAX_PATH
];
1957 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1962 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1963 tmppath
[len
] = '\0';
1972 /* if ends in \. or \.. append a backslash */
1973 if (tmppath
[len
- 1] == '.' &&
1974 (tmppath
[len
- 2] == '\\' ||
1975 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1977 if (len
< MAX_PATH
- 1)
1979 tmppath
[len
] = '\\';
1980 tmppath
[len
+1] = '\0';
1984 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1988 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1993 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1994 lpUC
->lpszUrlPath
[0] = 0;
1995 lpUC
->dwUrlPathLength
= 0;
1998 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1999 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
2000 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
2001 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
2002 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
2004 heap_free( lpszUrl_decode
);
2008 /***********************************************************************
2009 * InternetAttemptConnect (WININET.@)
2011 * Attempt to make a connection to the internet
2014 * ERROR_SUCCESS on success
2015 * Error value on failure
2018 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
2021 return ERROR_SUCCESS
;
2025 /***********************************************************************
2026 * convert_url_canonicalization_flags
2028 * Helper for InternetCanonicalizeUrl
2031 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2034 * Flags suitable for UrlCanonicalize
2036 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
2038 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2040 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
2041 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
2042 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
2043 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
2044 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2045 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
2046 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
2051 /***********************************************************************
2052 * InternetCanonicalizeUrlA (WININET.@)
2054 * Escape unsafe characters and spaces
2061 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2062 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2066 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2067 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2069 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2070 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2071 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2072 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2077 /***********************************************************************
2078 * InternetCanonicalizeUrlW (WININET.@)
2080 * Escape unsafe characters and spaces
2087 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2088 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2092 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2093 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2095 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2096 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2097 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2098 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2103 /* #################################################### */
2105 static INTERNET_STATUS_CALLBACK
set_status_callback(
2106 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2108 INTERNET_STATUS_CALLBACK ret
;
2110 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2111 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2113 ret
= lpwh
->lpfnStatusCB
;
2114 lpwh
->lpfnStatusCB
= callback
;
2119 /***********************************************************************
2120 * InternetSetStatusCallbackA (WININET.@)
2122 * Sets up a callback function which is called as progress is made
2123 * during an operation.
2126 * Previous callback or NULL on success
2127 * INTERNET_INVALID_STATUS_CALLBACK on failure
2130 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2131 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2133 INTERNET_STATUS_CALLBACK retVal
;
2134 object_header_t
*lpwh
;
2136 TRACE("%p\n", hInternet
);
2138 if (!(lpwh
= get_handle_object(hInternet
)))
2139 return INTERNET_INVALID_STATUS_CALLBACK
;
2141 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2143 WININET_Release( lpwh
);
2147 /***********************************************************************
2148 * InternetSetStatusCallbackW (WININET.@)
2150 * Sets up a callback function which is called as progress is made
2151 * during an operation.
2154 * Previous callback or NULL on success
2155 * INTERNET_INVALID_STATUS_CALLBACK on failure
2158 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2159 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2161 INTERNET_STATUS_CALLBACK retVal
;
2162 object_header_t
*lpwh
;
2164 TRACE("%p\n", hInternet
);
2166 if (!(lpwh
= get_handle_object(hInternet
)))
2167 return INTERNET_INVALID_STATUS_CALLBACK
;
2169 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2171 WININET_Release( lpwh
);
2175 /***********************************************************************
2176 * InternetSetFilePointer (WININET.@)
2178 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2179 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2181 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2185 /***********************************************************************
2186 * InternetWriteFile (WININET.@)
2188 * Write data to an open internet file
2195 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2196 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2198 object_header_t
*lpwh
;
2201 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2203 lpwh
= get_handle_object( hFile
);
2205 WARN("Invalid handle\n");
2206 SetLastError(ERROR_INVALID_HANDLE
);
2210 if(lpwh
->vtbl
->WriteFile
) {
2211 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2213 WARN("No Writefile method.\n");
2214 res
= ERROR_INVALID_HANDLE
;
2217 WININET_Release( lpwh
);
2219 if(res
!= ERROR_SUCCESS
)
2221 return res
== ERROR_SUCCESS
;
2225 /***********************************************************************
2226 * InternetReadFile (WININET.@)
2228 * Read data from an open internet file
2235 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2236 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2238 object_header_t
*hdr
;
2239 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2241 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2243 hdr
= get_handle_object(hFile
);
2245 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2249 if(hdr
->vtbl
->ReadFile
)
2250 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2252 WININET_Release(hdr
);
2254 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2255 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2257 if(res
!= ERROR_SUCCESS
)
2259 return res
== ERROR_SUCCESS
;
2262 /***********************************************************************
2263 * InternetReadFileExA (WININET.@)
2265 * Read data from an open internet file
2268 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2269 * lpBuffersOut [I/O] Buffer.
2270 * dwFlags [I] Flags. See notes.
2271 * dwContext [I] Context for callbacks.
2278 * The parameter dwFlags include zero or more of the following flags:
2279 *|IRF_ASYNC - Makes the call asynchronous.
2280 *|IRF_SYNC - Makes the call synchronous.
2281 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2282 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2284 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2287 * InternetOpenUrlA(), HttpOpenRequestA()
2289 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2290 DWORD dwFlags
, DWORD_PTR dwContext
)
2292 object_header_t
*hdr
;
2293 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2295 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2297 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2298 SetLastError(ERROR_INVALID_PARAMETER
);
2302 hdr
= get_handle_object(hFile
);
2304 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2308 if(hdr
->vtbl
->ReadFileEx
)
2309 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2310 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2312 WININET_Release(hdr
);
2314 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2315 res
, lpBuffersOut
->dwBufferLength
);
2317 if(res
!= ERROR_SUCCESS
)
2319 return res
== ERROR_SUCCESS
;
2322 /***********************************************************************
2323 * InternetReadFileExW (WININET.@)
2325 * InternetReadFileExA()
2327 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2328 DWORD dwFlags
, DWORD_PTR dwContext
)
2330 object_header_t
*hdr
;
2331 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2333 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2335 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2336 SetLastError(ERROR_INVALID_PARAMETER
);
2340 hdr
= get_handle_object(hFile
);
2342 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2346 if(hdr
->vtbl
->ReadFileEx
)
2347 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2348 dwFlags
, dwContext
);
2350 WININET_Release(hdr
);
2352 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2353 res
, lpBuffer
->dwBufferLength
);
2355 if(res
!= ERROR_SUCCESS
)
2357 return res
== ERROR_SUCCESS
;
2360 static BOOL
get_proxy_autoconfig_url( char *buf
, DWORD buflen
)
2362 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2364 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2368 if (!settings
) return FALSE
;
2370 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2372 CFRelease( settings
);
2375 if (CFStringGetCString( ref
, buf
, buflen
, kCFStringEncodingASCII
))
2377 TRACE( "returning %s\n", debugstr_a(buf
) );
2380 CFRelease( settings
);
2383 FIXME( "no support on this platform\n" );
2388 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2390 /* FIXME: This function currently handles more options than it should. Options requiring
2391 * proper handles should be moved to proper functions */
2393 case INTERNET_OPTION_HTTP_VERSION
:
2394 if (*size
< sizeof(HTTP_VERSION_INFO
))
2395 return ERROR_INSUFFICIENT_BUFFER
;
2398 * Presently hardcoded to 1.1
2400 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2401 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2402 *size
= sizeof(HTTP_VERSION_INFO
);
2404 return ERROR_SUCCESS
;
2406 case INTERNET_OPTION_CONNECTED_STATE
:
2407 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2409 if (*size
< sizeof(ULONG
))
2410 return ERROR_INSUFFICIENT_BUFFER
;
2412 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2413 *size
= sizeof(ULONG
);
2415 return ERROR_SUCCESS
;
2417 case INTERNET_OPTION_PROXY
: {
2421 TRACE("Getting global proxy info\n");
2422 memset(&ai
, 0, sizeof(appinfo_t
));
2423 INTERNET_ConfigureProxy(&ai
);
2425 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2426 APPINFO_Destroy(&ai
.hdr
);
2430 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2431 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2433 if (*size
< sizeof(ULONG
))
2434 return ERROR_INSUFFICIENT_BUFFER
;
2436 *(ULONG
*)buffer
= max_conns
;
2437 *size
= sizeof(ULONG
);
2439 return ERROR_SUCCESS
;
2441 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2442 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2444 if (*size
< sizeof(ULONG
))
2445 return ERROR_INSUFFICIENT_BUFFER
;
2447 *(ULONG
*)buffer
= max_1_0_conns
;
2448 *size
= sizeof(ULONG
);
2450 return ERROR_SUCCESS
;
2452 case INTERNET_OPTION_SECURITY_FLAGS
:
2453 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2454 return ERROR_SUCCESS
;
2456 case INTERNET_OPTION_VERSION
: {
2457 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2459 TRACE("INTERNET_OPTION_VERSION\n");
2461 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2462 return ERROR_INSUFFICIENT_BUFFER
;
2464 memcpy(buffer
, &info
, sizeof(info
));
2465 *size
= sizeof(info
);
2467 return ERROR_SUCCESS
;
2470 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2471 char url
[INTERNET_MAX_URL_LENGTH
+ 1];
2472 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2473 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2474 DWORD res
= ERROR_SUCCESS
, i
;
2479 TRACE("Getting global proxy info\n");
2480 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2483 have_url
= get_proxy_autoconfig_url(url
, sizeof(url
));
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
;
2503 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2504 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2507 case INTERNET_PER_CONN_PROXY_SERVER
:
2509 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2511 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2514 case INTERNET_PER_CONN_PROXY_BYPASS
:
2516 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2518 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2521 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2523 optionW
->Value
.pszValue
= NULL
;
2525 optionW
->Value
.pszValue
= heap_strdupAtoW(url
);
2527 optionA
->Value
.pszValue
= heap_strdupA(url
);
2530 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2531 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2534 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2535 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2536 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2537 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2538 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2539 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2543 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2544 res
= ERROR_INVALID_PARAMETER
;
2552 case INTERNET_OPTION_REQUEST_FLAGS
:
2553 case INTERNET_OPTION_USER_AGENT
:
2555 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2556 case INTERNET_OPTION_POLICY
:
2557 return ERROR_INVALID_PARAMETER
;
2558 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2559 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2561 if (*size
< sizeof(ULONG
))
2562 return ERROR_INSUFFICIENT_BUFFER
;
2564 *(ULONG
*)buffer
= connect_timeout
;
2565 *size
= sizeof(ULONG
);
2567 return ERROR_SUCCESS
;
2570 FIXME("Stub for %d\n", option
);
2571 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2574 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2577 case INTERNET_OPTION_CONTEXT_VALUE
:
2579 return ERROR_INVALID_PARAMETER
;
2581 if (*size
< sizeof(DWORD_PTR
)) {
2582 *size
= sizeof(DWORD_PTR
);
2583 return ERROR_INSUFFICIENT_BUFFER
;
2586 return ERROR_INVALID_PARAMETER
;
2588 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2589 *size
= sizeof(DWORD_PTR
);
2590 return ERROR_SUCCESS
;
2592 case INTERNET_OPTION_REQUEST_FLAGS
:
2593 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2594 *size
= sizeof(DWORD
);
2595 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2597 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2598 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2599 WARN("Called on global option %u\n", option
);
2600 return ERROR_INTERNET_INVALID_OPERATION
;
2603 /* FIXME: we shouldn't call it here */
2604 return query_global_option(option
, buffer
, size
, unicode
);
2607 /***********************************************************************
2608 * InternetQueryOptionW (WININET.@)
2610 * Queries an options on the specified handle
2617 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2618 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2620 object_header_t
*hdr
;
2621 DWORD res
= ERROR_INVALID_HANDLE
;
2623 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2626 hdr
= get_handle_object(hInternet
);
2628 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2629 WININET_Release(hdr
);
2632 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2635 if(res
!= ERROR_SUCCESS
)
2637 return res
== ERROR_SUCCESS
;
2640 /***********************************************************************
2641 * InternetQueryOptionA (WININET.@)
2643 * Queries an options on the specified handle
2650 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2651 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2653 object_header_t
*hdr
;
2654 DWORD res
= ERROR_INVALID_HANDLE
;
2656 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2659 hdr
= get_handle_object(hInternet
);
2661 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2662 WININET_Release(hdr
);
2665 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2668 if(res
!= ERROR_SUCCESS
)
2670 return res
== ERROR_SUCCESS
;
2673 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2676 case INTERNET_OPTION_CALLBACK
:
2677 WARN("Not settable option %u\n", option
);
2678 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2679 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2680 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2681 WARN("Called on global option %u\n", option
);
2682 return ERROR_INTERNET_INVALID_OPERATION
;
2685 return ERROR_INTERNET_INVALID_OPTION
;
2688 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2691 case INTERNET_OPTION_CALLBACK
:
2692 WARN("Not global option %u\n", option
);
2693 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2695 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2696 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2698 if(size
!= sizeof(max_conns
))
2699 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2701 return ERROR_BAD_ARGUMENTS
;
2703 max_conns
= *(ULONG
*)buf
;
2704 return ERROR_SUCCESS
;
2706 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2707 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2709 if(size
!= sizeof(max_1_0_conns
))
2710 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2712 return ERROR_BAD_ARGUMENTS
;
2714 max_1_0_conns
= *(ULONG
*)buf
;
2715 return ERROR_SUCCESS
;
2717 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2718 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2720 if(size
!= sizeof(connect_timeout
))
2721 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2723 return ERROR_BAD_ARGUMENTS
;
2725 connect_timeout
= *(ULONG
*)buf
;
2726 return ERROR_SUCCESS
;
2728 case INTERNET_OPTION_SETTINGS_CHANGED
:
2729 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2730 collect_connections(COLLECT_CONNECTIONS
);
2731 return ERROR_SUCCESS
;
2734 return ERROR_INTERNET_INVALID_OPTION
;
2737 /***********************************************************************
2738 * InternetSetOptionW (WININET.@)
2740 * Sets an options on the specified handle
2747 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2748 LPVOID lpBuffer
, DWORD dwBufferLength
)
2750 object_header_t
*lpwhh
;
2754 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2756 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2758 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2760 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2762 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2764 WININET_Release(lpwhh
);
2766 if(res
!= ERROR_SUCCESS
)
2769 return res
== ERROR_SUCCESS
;
2774 case INTERNET_OPTION_HTTP_VERSION
:
2776 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2777 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2780 case INTERNET_OPTION_ERROR_MASK
:
2783 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2785 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2786 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2787 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2788 SetLastError(ERROR_INVALID_PARAMETER
);
2790 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2791 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2794 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2795 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2798 case INTERNET_OPTION_PROXY
:
2800 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2802 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2804 SetLastError(ERROR_INVALID_PARAMETER
);
2809 EnterCriticalSection( &WININET_cs
);
2810 free_global_proxy();
2811 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2814 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2816 global_proxy
->proxyEnabled
= 1;
2817 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2818 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2822 global_proxy
->proxyEnabled
= 0;
2823 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2826 LeaveCriticalSection( &WININET_cs
);
2830 /* In general, each type of object should handle
2831 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2832 * get silently dropped.
2834 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2835 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2840 case INTERNET_OPTION_CODEPAGE
:
2842 ULONG codepage
= *(ULONG
*)lpBuffer
;
2843 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2846 case INTERNET_OPTION_REQUEST_PRIORITY
:
2848 ULONG priority
= *(ULONG
*)lpBuffer
;
2849 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2852 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2854 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2855 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2858 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2860 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2861 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2864 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2865 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2867 case INTERNET_OPTION_END_BROWSER_SESSION
:
2868 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2870 case INTERNET_OPTION_CONNECTED_STATE
:
2871 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2873 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2874 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2876 case INTERNET_OPTION_SEND_TIMEOUT
:
2877 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2878 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2880 ULONG timeout
= *(ULONG
*)lpBuffer
;
2881 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2884 case INTERNET_OPTION_CONNECT_RETRIES
:
2886 ULONG retries
= *(ULONG
*)lpBuffer
;
2887 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2890 case INTERNET_OPTION_CONTEXT_VALUE
:
2894 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2897 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2899 SetLastError(ERROR_INVALID_PARAMETER
);
2903 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2906 case INTERNET_OPTION_SECURITY_FLAGS
:
2907 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2909 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2910 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2912 case INTERNET_OPTION_HTTP_DECODING
:
2913 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2914 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2917 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2918 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2919 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2922 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2923 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2924 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2927 case INTERNET_OPTION_CODEPAGE_PATH
:
2928 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2929 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2932 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2933 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2934 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2937 case INTERNET_OPTION_IDN
:
2938 FIXME("INTERNET_OPTION_IDN; STUB\n");
2939 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2942 case INTERNET_OPTION_POLICY
:
2943 SetLastError(ERROR_INVALID_PARAMETER
);
2946 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2947 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2952 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2954 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2955 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2957 switch (option
->dwOption
) {
2958 case INTERNET_PER_CONN_PROXY_SERVER
:
2959 heap_free(pi
.proxy
);
2960 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2963 case INTERNET_PER_CONN_FLAGS
:
2964 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2965 pi
.proxyEnabled
= 1;
2968 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2969 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2970 pi
.proxyEnabled
= 0;
2974 case INTERNET_PER_CONN_PROXY_BYPASS
:
2975 heap_free(pi
.proxyBypass
);
2976 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
2979 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2980 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2981 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2982 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2983 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2984 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2985 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2989 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2990 SetLastError(ERROR_INVALID_PARAMETER
);
2995 if ((res
= INTERNET_SaveProxySettings(&pi
)))
3000 ret
= (res
== ERROR_SUCCESS
);
3004 FIXME("Option %d STUB\n",dwOption
);
3005 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3011 WININET_Release( lpwhh
);
3017 /***********************************************************************
3018 * InternetSetOptionA (WININET.@)
3020 * Sets an options on the specified handle.
3027 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3028 LPVOID lpBuffer
, DWORD dwBufferLength
)
3036 case INTERNET_OPTION_PROXY
:
3038 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3039 LPINTERNET_PROXY_INFOW piw
;
3040 DWORD proxlen
, prbylen
;
3043 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3044 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3045 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3046 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3047 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3048 piw
->dwAccessType
= pi
->dwAccessType
;
3049 prox
= (LPWSTR
) &piw
[1];
3050 prby
= &prox
[proxlen
+1];
3051 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3052 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3053 piw
->lpszProxy
= prox
;
3054 piw
->lpszProxyBypass
= prby
;
3057 case INTERNET_OPTION_USER_AGENT
:
3058 case INTERNET_OPTION_USERNAME
:
3059 case INTERNET_OPTION_PASSWORD
:
3060 case INTERNET_OPTION_PROXY_USERNAME
:
3061 case INTERNET_OPTION_PROXY_PASSWORD
:
3062 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3063 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3064 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3066 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3068 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3069 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3070 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3071 wbuffer
= heap_alloc(wlen
);
3074 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3075 if (listA
->pszConnection
)
3077 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3078 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3079 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3082 listW
->pszConnection
= NULL
;
3083 listW
->dwOptionCount
= listA
->dwOptionCount
;
3084 listW
->dwOptionError
= listA
->dwOptionError
;
3085 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3087 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3088 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3089 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3091 optW
->dwOption
= optA
->dwOption
;
3093 switch (optA
->dwOption
) {
3094 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3095 case INTERNET_PER_CONN_PROXY_BYPASS
:
3096 case INTERNET_PER_CONN_PROXY_SERVER
:
3097 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3098 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3099 if (optA
->Value
.pszValue
)
3101 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3102 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3103 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3106 optW
->Value
.pszValue
= NULL
;
3108 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3109 case INTERNET_PER_CONN_FLAGS
:
3110 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3111 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3113 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3114 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3117 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3118 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3126 wlen
= dwBufferLength
;
3129 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3131 if( lpBuffer
!= wbuffer
)
3133 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3135 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3137 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3138 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3139 switch (opt
->dwOption
) {
3140 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3141 case INTERNET_PER_CONN_PROXY_BYPASS
:
3142 case INTERNET_PER_CONN_PROXY_SERVER
:
3143 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3144 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3145 heap_free( opt
->Value
.pszValue
);
3151 heap_free( list
->pOptions
);
3153 heap_free( wbuffer
);
3160 /***********************************************************************
3161 * InternetSetOptionExA (WININET.@)
3163 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3164 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3166 FIXME("Flags %08x ignored\n", dwFlags
);
3167 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3170 /***********************************************************************
3171 * InternetSetOptionExW (WININET.@)
3173 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3174 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3176 FIXME("Flags %08x ignored\n", dwFlags
);
3177 if( dwFlags
& ~ISO_VALID_FLAGS
)
3179 SetLastError( ERROR_INVALID_PARAMETER
);
3182 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3185 static const WCHAR WININET_wkday
[7][4] =
3186 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3187 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3188 static const WCHAR WININET_month
[12][4] =
3189 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3190 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3191 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3193 /***********************************************************************
3194 * InternetTimeFromSystemTimeA (WININET.@)
3196 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3199 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3201 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3203 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3205 SetLastError(ERROR_INVALID_PARAMETER
);
3209 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3211 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3215 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3216 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3221 /***********************************************************************
3222 * InternetTimeFromSystemTimeW (WININET.@)
3224 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3226 static const WCHAR date
[] =
3227 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3228 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3230 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3232 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3234 SetLastError(ERROR_INVALID_PARAMETER
);
3238 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3240 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3244 sprintfW( string
, date
,
3245 WININET_wkday
[time
->wDayOfWeek
],
3247 WININET_month
[time
->wMonth
- 1],
3256 /***********************************************************************
3257 * InternetTimeToSystemTimeA (WININET.@)
3259 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3264 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3266 stringW
= heap_strdupAtoW(string
);
3269 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3270 heap_free( stringW
);
3275 /***********************************************************************
3276 * InternetTimeToSystemTimeW (WININET.@)
3278 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3281 const WCHAR
*s
= string
;
3284 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3286 if (!string
|| !time
) return FALSE
;
3288 /* Windows does this too */
3289 GetSystemTime( time
);
3291 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3292 * a SYSTEMTIME structure.
3295 while (*s
&& !isalphaW( *s
)) s
++;
3296 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3297 time
->wDayOfWeek
= 7;
3299 for (i
= 0; i
< 7; i
++)
3301 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3302 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3303 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3305 time
->wDayOfWeek
= i
;
3310 if (time
->wDayOfWeek
> 6) return TRUE
;
3311 while (*s
&& !isdigitW( *s
)) s
++;
3312 time
->wDay
= strtolW( s
, &end
, 10 );
3315 while (*s
&& !isalphaW( *s
)) s
++;
3316 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3319 for (i
= 0; i
< 12; i
++)
3321 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3322 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3323 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3325 time
->wMonth
= i
+ 1;
3329 if (time
->wMonth
== 0) return TRUE
;
3331 while (*s
&& !isdigitW( *s
)) s
++;
3332 if (*s
== '\0') return TRUE
;
3333 time
->wYear
= strtolW( s
, &end
, 10 );
3336 while (*s
&& !isdigitW( *s
)) s
++;
3337 if (*s
== '\0') return TRUE
;
3338 time
->wHour
= strtolW( s
, &end
, 10 );
3341 while (*s
&& !isdigitW( *s
)) s
++;
3342 if (*s
== '\0') return TRUE
;
3343 time
->wMinute
= strtolW( s
, &end
, 10 );
3346 while (*s
&& !isdigitW( *s
)) s
++;
3347 if (*s
== '\0') return TRUE
;
3348 time
->wSecond
= strtolW( s
, &end
, 10 );
3351 time
->wMilliseconds
= 0;
3355 /***********************************************************************
3356 * InternetCheckConnectionW (WININET.@)
3358 * Pings a requested host to check internet connection
3361 * TRUE on success and FALSE on failure. If a failure then
3362 * ERROR_NOT_CONNECTED is placed into GetLastError
3365 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3368 * this is a kludge which runs the resident ping program and reads the output.
3370 * Anyone have a better idea?
3374 static const CHAR ping
[] = "ping -c 1 ";
3375 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3376 CHAR
*command
= NULL
;
3377 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3385 * Crack or set the Address
3387 if (lpszUrl
== NULL
)
3390 * According to the doc we are supposed to use the ip for the next
3391 * server in the WnInet internal server database. I have
3392 * no idea what that is or how to get it.
3394 * So someone needs to implement this.
3396 FIXME("Unimplemented with URL of NULL\n");
3401 URL_COMPONENTSW components
;
3403 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3404 components
.lpszHostName
= (LPWSTR
)hostW
;
3405 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3407 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3410 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3411 port
= components
.nPort
;
3412 TRACE("port: %d\n", port
);
3415 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3417 struct sockaddr_storage saddr
;
3418 socklen_t sa_len
= sizeof(saddr
);
3421 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3423 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3426 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3434 * Build our ping command
3436 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3437 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3438 strcpy(command
,ping
);
3439 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3440 strcat(command
,redirect
);
3442 TRACE("Ping command is : %s\n",command
);
3444 status
= system(command
);
3446 TRACE("Ping returned a code of %i\n",status
);
3448 /* Ping return code of 0 indicates success */
3454 heap_free( command
);
3456 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3462 /***********************************************************************
3463 * InternetCheckConnectionA (WININET.@)
3465 * Pings a requested host to check internet connection
3468 * TRUE on success and FALSE on failure. If a failure then
3469 * ERROR_NOT_CONNECTED is placed into GetLastError
3472 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3478 url
= heap_strdupAtoW(lpszUrl
);
3483 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3490 /**********************************************************
3491 * INTERNET_InternetOpenUrlW (internal)
3496 * handle of connection or NULL on failure
3498 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3499 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3501 URL_COMPONENTSW urlComponents
;
3502 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3503 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3504 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3505 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3506 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3508 HINTERNET client
= NULL
, client1
= NULL
;
3511 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3512 dwHeadersLength
, dwFlags
, dwContext
);
3514 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3515 urlComponents
.lpszScheme
= protocol
;
3516 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3517 urlComponents
.lpszHostName
= hostName
;
3518 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3519 urlComponents
.lpszUserName
= userName
;
3520 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3521 urlComponents
.lpszPassword
= password
;
3522 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3523 urlComponents
.lpszUrlPath
= path
;
3524 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3525 urlComponents
.lpszExtraInfo
= extra
;
3526 urlComponents
.dwExtraInfoLength
= 1024;
3527 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3529 switch(urlComponents
.nScheme
) {
3530 case INTERNET_SCHEME_FTP
:
3531 if(urlComponents
.nPort
== 0)
3532 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3533 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3534 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3537 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3538 if(client1
== NULL
) {
3539 InternetCloseHandle(client
);
3544 case INTERNET_SCHEME_HTTP
:
3545 case INTERNET_SCHEME_HTTPS
: {
3546 static const WCHAR szStars
[] = { '*','/','*', 0 };
3547 LPCWSTR accept
[2] = { szStars
, NULL
};
3548 if(urlComponents
.nPort
== 0) {
3549 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3550 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3552 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3554 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3556 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3557 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3558 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3559 if(res
!= ERROR_SUCCESS
) {
3560 INTERNET_SetLastError(res
);
3564 if (urlComponents
.dwExtraInfoLength
) {
3566 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3568 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3570 InternetCloseHandle(client
);
3573 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3574 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3575 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3576 heap_free(path_extra
);
3579 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3581 if(client1
== NULL
) {
3582 InternetCloseHandle(client
);
3585 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3586 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3587 GetLastError() != ERROR_IO_PENDING
) {
3588 InternetCloseHandle(client1
);
3593 case INTERNET_SCHEME_GOPHER
:
3594 /* gopher doesn't seem to be implemented in wine, but it's supposed
3595 * to be supported by InternetOpenUrlA. */
3597 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3601 TRACE(" %p <--\n", client1
);
3606 /**********************************************************
3607 * InternetOpenUrlW (WININET.@)
3612 * handle of connection or NULL on failure
3623 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3625 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3627 TRACE("%p\n", task
->hdr
.hdr
);
3629 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3630 task
->headers_len
, task
->flags
, task
->context
);
3631 heap_free(task
->url
);
3632 heap_free(task
->headers
);
3635 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3636 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3638 HINTERNET ret
= NULL
;
3639 appinfo_t
*hIC
= NULL
;
3641 if (TRACE_ON(wininet
)) {
3642 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3643 dwHeadersLength
, dwFlags
, dwContext
);
3645 dump_INTERNET_FLAGS(dwFlags
);
3650 SetLastError(ERROR_INVALID_PARAMETER
);
3654 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3655 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3656 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3660 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3661 open_url_task_t
*task
;
3663 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3664 task
->url
= heap_strdupW(lpszUrl
);
3665 task
->headers
= heap_strdupW(lpszHeaders
);
3666 task
->headers_len
= dwHeadersLength
;
3667 task
->flags
= dwFlags
;
3668 task
->context
= dwContext
;
3670 INTERNET_AsyncCall(&task
->hdr
);
3671 SetLastError(ERROR_IO_PENDING
);
3673 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3678 WININET_Release( &hIC
->hdr
);
3679 TRACE(" %p <--\n", ret
);
3684 /**********************************************************
3685 * InternetOpenUrlA (WININET.@)
3690 * handle of connection or NULL on failure
3692 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3693 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3695 HINTERNET rc
= NULL
;
3696 DWORD lenHeaders
= 0;
3697 LPWSTR szUrl
= NULL
;
3698 LPWSTR szHeaders
= NULL
;
3703 szUrl
= heap_strdupAtoW(lpszUrl
);
3709 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3710 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3715 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3718 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3719 lenHeaders
, dwFlags
, dwContext
);
3722 heap_free(szHeaders
);
3727 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3729 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3733 lpwite
->dwError
= 0;
3734 lpwite
->response
[0] = '\0';
3737 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3746 /***********************************************************************
3747 * INTERNET_SetLastError (internal)
3749 * Set last thread specific error
3754 void INTERNET_SetLastError(DWORD dwError
)
3756 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3759 lpwite
= INTERNET_AllocThreadError();
3761 SetLastError(dwError
);
3763 lpwite
->dwError
= dwError
;
3767 /***********************************************************************
3768 * INTERNET_GetLastError (internal)
3770 * Get last thread specific error
3775 DWORD
INTERNET_GetLastError(void)
3777 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3778 if (!lpwite
) return 0;
3779 /* TlsGetValue clears last error, so set it again here */
3780 SetLastError(lpwite
->dwError
);
3781 return lpwite
->dwError
;
3785 /***********************************************************************
3786 * INTERNET_WorkerThreadFunc (internal)
3788 * Worker thread execution function
3793 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3795 task_header_t
*task
= lpvParam
;
3800 WININET_Release(task
->hdr
);
3803 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3805 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3806 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3811 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3813 task_header_t
*task
;
3815 task
= heap_alloc(size
);
3819 task
->hdr
= WININET_AddRef(hdr
);
3824 /***********************************************************************
3825 * INTERNET_AsyncCall (internal)
3827 * Retrieves work request from queue
3832 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3838 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3842 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3844 return ERROR_SUCCESS
;
3848 /***********************************************************************
3849 * INTERNET_GetResponseBuffer (internal)
3854 LPSTR
INTERNET_GetResponseBuffer(void)
3856 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3858 lpwite
= INTERNET_AllocThreadError();
3860 return lpwite
->response
;
3863 /***********************************************************************
3864 * INTERNET_GetNextLine (internal)
3866 * Parse next line in directory string listing
3869 * Pointer to beginning of next line
3874 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3876 /* ReactOS: use select instead of poll */
3879 BOOL bSuccess
= FALSE
;
3881 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3886 FD_SET(nSocket
,&infd
);
3887 tv
.tv_sec
= RESPONSE_TIMEOUT
;
3890 while (nRecv
< MAX_REPLY_LEN
)
3892 if (select(0, &infd
, NULL
, NULL
, &tv
) > 0)
3894 if (sock_recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3896 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3900 if (lpszBuffer
[nRecv
] == '\n')
3905 if (lpszBuffer
[nRecv
] != '\r')
3910 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3918 lpszBuffer
[nRecv
] = '\0';
3920 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3929 /**********************************************************
3930 * InternetQueryDataAvailable (WININET.@)
3932 * Determines how much data is available to be read.
3935 * TRUE on success, FALSE if an error occurred. If
3936 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3937 * no data is presently available, FALSE is returned with
3938 * the last error ERROR_IO_PENDING; a callback with status
3939 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3940 * data is available.
3942 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3943 LPDWORD lpdwNumberOfBytesAvailable
,
3944 DWORD dwFlags
, DWORD_PTR dwContext
)
3946 object_header_t
*hdr
;
3949 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3951 hdr
= get_handle_object( hFile
);
3953 SetLastError(ERROR_INVALID_HANDLE
);
3957 if(hdr
->vtbl
->QueryDataAvailable
) {
3958 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3960 WARN("wrong handle\n");
3961 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3964 WININET_Release(hdr
);
3966 if(res
!= ERROR_SUCCESS
)
3968 return res
== ERROR_SUCCESS
;
3971 DWORD
create_req_file(const WCHAR
*file_name
, req_file_t
**ret
)
3973 req_file_t
*req_file
;
3975 req_file
= heap_alloc_zero(sizeof(*req_file
));
3977 return ERROR_NOT_ENOUGH_MEMORY
;
3981 req_file
->file_name
= heap_strdupW(file_name
);
3982 if(!req_file
->file_name
) {
3983 heap_free(req_file
);
3984 return ERROR_NOT_ENOUGH_MEMORY
;
3987 req_file
->file_handle
= CreateFileW(req_file
->file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
3988 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
3989 if(req_file
->file_handle
== INVALID_HANDLE_VALUE
) {
3990 req_file_release(req_file
);
3991 return GetLastError();
3995 return ERROR_SUCCESS
;
3998 void req_file_release(req_file_t
*req_file
)
4000 if(InterlockedDecrement(&req_file
->ref
))
4003 if(!req_file
->is_committed
)
4004 DeleteFileW(req_file
->file_name
);
4005 if(req_file
->file_handle
&& req_file
->file_handle
!= INVALID_HANDLE_VALUE
)
4006 CloseHandle(req_file
->file_handle
);
4007 heap_free(req_file
->file_name
);
4008 heap_free(req_file
);
4011 /***********************************************************************
4012 * InternetLockRequestFile (WININET.@)
4014 BOOL WINAPI
InternetLockRequestFile(HINTERNET hInternet
, HANDLE
*lphLockReqHandle
)
4016 req_file_t
*req_file
= NULL
;
4017 object_header_t
*hdr
;
4020 TRACE("(%p %p)\n", hInternet
, lphLockReqHandle
);
4022 hdr
= get_handle_object(hInternet
);
4024 SetLastError(ERROR_INVALID_HANDLE
);
4028 if(hdr
->vtbl
->LockRequestFile
) {
4029 res
= hdr
->vtbl
->LockRequestFile(hdr
, &req_file
);
4031 WARN("wrong handle\n");
4032 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
4035 WININET_Release(hdr
);
4037 *lphLockReqHandle
= req_file
;
4038 if(res
!= ERROR_SUCCESS
)
4040 return res
== ERROR_SUCCESS
;
4043 BOOL WINAPI
InternetUnlockRequestFile(HANDLE hLockHandle
)
4045 TRACE("(%p)\n", hLockHandle
);
4047 req_file_release(hLockHandle
);
4052 /***********************************************************************
4053 * InternetAutodial (WININET.@)
4055 * On windows this function is supposed to dial the default internet
4056 * connection. We don't want to have Wine dial out to the internet so
4057 * we return TRUE by default. It might be nice to check if we are connected.
4064 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
4068 /* Tell that we are connected to the internet. */
4072 /***********************************************************************
4073 * InternetAutodialHangup (WININET.@)
4075 * Hangs up a connection made with InternetAutodial
4084 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
4088 /* we didn't dial, we don't disconnect */
4092 /***********************************************************************
4093 * InternetCombineUrlA (WININET.@)
4095 * Combine a base URL with a relative URL
4103 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
4104 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4109 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4111 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4112 dwFlags
^= ICU_NO_ENCODE
;
4113 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4118 /***********************************************************************
4119 * InternetCombineUrlW (WININET.@)
4121 * Combine a base URL with a relative URL
4129 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4130 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4135 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4137 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4138 dwFlags
^= ICU_NO_ENCODE
;
4139 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4144 /* max port num is 65535 => 5 digits */
4145 #define MAX_WORD_DIGITS 5
4147 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4148 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4149 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4150 (url)->dw##component##Length : strlen((url)->lpsz##component))
4152 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4154 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4155 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4157 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4158 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4160 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4161 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4163 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4164 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4167 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4173 /* opaque urls do not fit into the standard url hierarchy and don't have
4174 * two following slashes */
4175 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4177 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4178 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4179 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4180 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4181 (nScheme
!= INTERNET_SCHEME_FILE
);
4184 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4187 if (scheme
< INTERNET_SCHEME_FIRST
)
4189 index
= scheme
- INTERNET_SCHEME_FIRST
;
4190 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4192 return (LPCWSTR
)url_schemes
[index
];
4195 /* we can calculate using ansi strings because we're just
4196 * calculating string length, not size
4198 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4199 LPDWORD lpdwUrlLength
)
4201 INTERNET_SCHEME nScheme
;
4205 if (lpUrlComponents
->lpszScheme
)
4207 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4208 *lpdwUrlLength
+= dwLen
;
4209 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4215 nScheme
= lpUrlComponents
->nScheme
;
4217 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4218 nScheme
= INTERNET_SCHEME_HTTP
;
4219 scheme
= INTERNET_GetSchemeString(nScheme
);
4220 *lpdwUrlLength
+= strlenW(scheme
);
4223 (*lpdwUrlLength
)++; /* ':' */
4224 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4225 *lpdwUrlLength
+= strlen("//");
4227 if (lpUrlComponents
->lpszUserName
)
4229 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4230 *lpdwUrlLength
+= strlen("@");
4234 if (lpUrlComponents
->lpszPassword
)
4236 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4241 if (lpUrlComponents
->lpszPassword
)
4243 *lpdwUrlLength
+= strlen(":");
4244 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4247 if (lpUrlComponents
->lpszHostName
)
4249 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4251 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4253 char szPort
[MAX_WORD_DIGITS
+1];
4255 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4256 *lpdwUrlLength
+= strlen(szPort
);
4257 *lpdwUrlLength
+= strlen(":");
4260 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4261 (*lpdwUrlLength
)++; /* '/' */
4264 if (lpUrlComponents
->lpszUrlPath
)
4265 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4267 if (lpUrlComponents
->lpszExtraInfo
)
4268 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4273 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4277 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4279 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4280 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4281 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4282 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4283 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4284 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4285 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4286 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4287 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4289 if (lpUrlComponents
->lpszScheme
)
4291 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4292 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4293 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4294 -1, urlCompW
->lpszScheme
, len
);
4297 if (lpUrlComponents
->lpszHostName
)
4299 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4300 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4301 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4302 -1, urlCompW
->lpszHostName
, len
);
4305 if (lpUrlComponents
->lpszUserName
)
4307 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4308 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4309 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4310 -1, urlCompW
->lpszUserName
, len
);
4313 if (lpUrlComponents
->lpszPassword
)
4315 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4316 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4317 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4318 -1, urlCompW
->lpszPassword
, len
);
4321 if (lpUrlComponents
->lpszUrlPath
)
4323 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4324 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4325 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4326 -1, urlCompW
->lpszUrlPath
, len
);
4329 if (lpUrlComponents
->lpszExtraInfo
)
4331 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4332 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4333 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4334 -1, urlCompW
->lpszExtraInfo
, len
);
4338 /***********************************************************************
4339 * InternetCreateUrlA (WININET.@)
4341 * See InternetCreateUrlW.
4343 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4344 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4348 URL_COMPONENTSW urlCompW
;
4350 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4352 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4354 SetLastError(ERROR_INVALID_PARAMETER
);
4358 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4361 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4363 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4365 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4366 *lpdwUrlLength
/= sizeof(WCHAR
);
4368 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4369 * minus one, so add one to leave room for NULL terminator
4372 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4374 heap_free(urlCompW
.lpszScheme
);
4375 heap_free(urlCompW
.lpszHostName
);
4376 heap_free(urlCompW
.lpszUserName
);
4377 heap_free(urlCompW
.lpszPassword
);
4378 heap_free(urlCompW
.lpszUrlPath
);
4379 heap_free(urlCompW
.lpszExtraInfo
);
4384 /***********************************************************************
4385 * InternetCreateUrlW (WININET.@)
4387 * Creates a URL from its component parts.
4390 * lpUrlComponents [I] URL Components.
4391 * dwFlags [I] Flags. See notes.
4392 * lpszUrl [I] Buffer in which to store the created URL.
4393 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4394 * lpszUrl in characters. On output, the number of bytes
4395 * required to store the URL including terminator.
4399 * The dwFlags parameter can be zero or more of the following:
4400 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4407 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4408 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4411 INTERNET_SCHEME nScheme
;
4413 static const WCHAR slashSlashW
[] = {'/','/'};
4414 static const WCHAR fmtW
[] = {'%','u',0};
4416 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4418 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4420 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4424 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4427 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4429 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4430 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4434 *lpdwUrlLength
= dwLen
;
4439 if (lpUrlComponents
->lpszScheme
)
4441 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4442 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4445 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4450 nScheme
= lpUrlComponents
->nScheme
;
4452 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4453 nScheme
= INTERNET_SCHEME_HTTP
;
4455 scheme
= INTERNET_GetSchemeString(nScheme
);
4456 dwLen
= strlenW(scheme
);
4457 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4461 /* all schemes are followed by at least a colon */
4465 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4467 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4468 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4471 if (lpUrlComponents
->lpszUserName
)
4473 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4474 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4477 if (lpUrlComponents
->lpszPassword
)
4482 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4483 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4491 if (lpUrlComponents
->lpszHostName
)
4493 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4494 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4497 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4499 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4501 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4504 dwLen
= strlenW(szPort
);
4505 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4509 /* add slash between hostname and path if necessary */
4510 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4517 if (lpUrlComponents
->lpszUrlPath
)
4519 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4520 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4524 if (lpUrlComponents
->lpszExtraInfo
)
4526 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4527 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4536 /***********************************************************************
4537 * InternetConfirmZoneCrossingA (WININET.@)
4540 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4542 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4543 return ERROR_SUCCESS
;
4546 /***********************************************************************
4547 * InternetConfirmZoneCrossingW (WININET.@)
4550 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4552 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4553 return ERROR_SUCCESS
;
4556 static DWORD zone_preference
= 3;
4558 /***********************************************************************
4559 * PrivacySetZonePreferenceW (WININET.@)
4561 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4563 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4565 zone_preference
= template;
4569 /***********************************************************************
4570 * PrivacyGetZonePreferenceW (WININET.@)
4572 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4573 LPWSTR preference
, LPDWORD length
)
4575 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4577 if (template) *template = zone_preference
;
4581 /***********************************************************************
4582 * InternetGetSecurityInfoByURLA (WININET.@)
4584 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4589 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4591 url
= heap_strdupAtoW(lpszURL
);
4595 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4600 /***********************************************************************
4601 * InternetGetSecurityInfoByURLW (WININET.@)
4603 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4605 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4606 URL_COMPONENTSW url
= {sizeof(url
)};
4610 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4612 url
.lpszHostName
= hostname
;
4613 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4615 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4616 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4617 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4621 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4623 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4627 if(server
->cert_chain
) {
4628 const CERT_CHAIN_CONTEXT
*chain_dup
;
4630 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4632 *ppCertChain
= chain_dup
;
4633 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4638 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4642 server_release(server
);
4646 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4647 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4649 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4650 lpdwConnection
, dwReserved
);
4651 return ERROR_SUCCESS
;
4654 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4655 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4657 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4658 lpdwConnection
, dwReserved
);
4659 return ERROR_SUCCESS
;
4662 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4664 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4668 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4670 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4674 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4676 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4677 return ERROR_SUCCESS
;
4680 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4683 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4684 debugstr_w(pwszTarget
), pbHexHash
);
4688 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4690 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4694 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4696 FIXME("(%p, %08lx) stub\n", a
, b
);
4700 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4702 FIXME("%p: stub\n", parent
);