4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #if defined(__MINGW32__) || defined (_MSC_VER)
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 # include <sys/socket.h>
46 #ifdef HAVE_SYS_POLL_H
47 # include <sys/poll.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
65 #include "wine/debug.h"
67 #define NO_SHLWAPI_STREAM
70 #include "wine/exception.h"
75 #include "wine/unicode.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
79 #define RESPONSE_TIMEOUT 30
84 CHAR response
[MAX_REPLY_LEN
];
85 } WITHREADERROR
, *LPWITHREADERROR
;
87 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
88 HMODULE WININET_hModule
;
90 static CRITICAL_SECTION WININET_cs
;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
94 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
95 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
99 static object_header_t
**handle_table
;
100 static UINT_PTR next_handle
;
101 static UINT_PTR handle_table_size
;
110 static ULONG max_conns
= 2, max_1_0_conns
= 4;
111 static ULONG connect_timeout
= 60000;
113 static const WCHAR szInternetSettings
[] =
114 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
115 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
116 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
117 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
118 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
119 static const WCHAR szProxyOverride
[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
121 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
123 UINT_PTR handle
= 0, num
;
124 object_header_t
*ret
;
128 ret
= heap_alloc_zero(size
);
132 list_init(&ret
->children
);
134 EnterCriticalSection( &WININET_cs
);
136 if(!handle_table_size
) {
138 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
141 handle_table_size
= num
;
146 }else if(next_handle
== handle_table_size
) {
147 num
= handle_table_size
* 2;
148 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
151 handle_table_size
= num
;
158 handle
= next_handle
;
159 if(handle_table
[handle
])
160 ERR("handle isn't free but should be\n");
161 handle_table
[handle
] = ret
;
162 ret
->valid_handle
= TRUE
;
164 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
168 LeaveCriticalSection( &WININET_cs
);
177 ret
->hInternet
= (HINTERNET
)handle
;
180 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
181 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
187 object_header_t
*WININET_AddRef( object_header_t
*info
)
189 ULONG refs
= InterlockedIncrement(&info
->refs
);
190 TRACE("%p -> refcount = %d\n", info
, refs
);
194 object_header_t
*get_handle_object( HINTERNET hinternet
)
196 object_header_t
*info
= NULL
;
197 UINT_PTR handle
= (UINT_PTR
) hinternet
;
199 EnterCriticalSection( &WININET_cs
);
201 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
202 info
= WININET_AddRef(handle_table
[handle
]);
204 LeaveCriticalSection( &WININET_cs
);
206 TRACE("handle %ld -> %p\n", handle
, info
);
211 static void invalidate_handle(object_header_t
*info
)
213 object_header_t
*child
, *next
;
215 if(!info
->valid_handle
)
217 info
->valid_handle
= FALSE
;
219 /* Free all children as native does */
220 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
222 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
223 invalidate_handle( child
);
226 WININET_Release(info
);
229 BOOL
WININET_Release( object_header_t
*info
)
231 ULONG refs
= InterlockedDecrement(&info
->refs
);
232 TRACE( "object %p refcount = %d\n", info
, refs
);
235 invalidate_handle(info
);
236 if ( info
->vtbl
->CloseConnection
)
238 TRACE( "closing connection %p\n", info
);
239 info
->vtbl
->CloseConnection( info
);
241 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
242 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
243 || !(info
->dwInternalFlags
& INET_OPENURL
))
245 INTERNET_SendCallback(info
, info
->dwContext
,
246 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
249 TRACE( "destroying object %p\n", info
);
250 if ( info
->htype
!= WH_HINIT
)
251 list_remove( &info
->entry
);
252 info
->vtbl
->Destroy( info
);
254 if(info
->hInternet
) {
255 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
257 EnterCriticalSection( &WININET_cs
);
259 handle_table
[handle
] = NULL
;
260 if(next_handle
> handle
)
261 next_handle
= handle
;
263 LeaveCriticalSection( &WININET_cs
);
271 /***********************************************************************
272 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
275 * hinstDLL [I] handle to the DLL's instance
277 * lpvReserved [I] reserved, must be NULL
284 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
286 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
289 case DLL_PROCESS_ATTACH
:
291 g_dwTlsErrIndex
= TlsAlloc();
293 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
298 TlsFree(g_dwTlsErrIndex
);
302 WININET_hModule
= hinstDLL
;
305 case DLL_THREAD_ATTACH
:
308 case DLL_THREAD_DETACH
:
309 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
311 heap_free(TlsGetValue(g_dwTlsErrIndex
));
315 case DLL_PROCESS_DETACH
:
316 collect_connections(COLLECT_CLEANUP
);
321 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
323 heap_free(TlsGetValue(g_dwTlsErrIndex
));
324 TlsFree(g_dwTlsErrIndex
);
331 /***********************************************************************
332 * INTERNET_SaveProxySettings
334 * Stores the proxy settings given by lpwai into the registry
337 * ERROR_SUCCESS if no error, or error code on fail
339 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
344 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
347 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
355 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
363 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
371 return ERROR_SUCCESS
;
374 /***********************************************************************
375 * INTERNET_FindProxyForProtocol
377 * Searches the proxy string for a proxy of the given protocol.
378 * Returns the found proxy, or the default proxy if none of the given
382 * szProxy [In] proxy string to search
383 * proto [In] protocol to search for, e.g. "http"
384 * foundProxy [Out] found proxy
385 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
388 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
389 * *foundProxyLen is set to the required size in WCHARs, including the
390 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
392 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
397 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
399 /* First, look for the specified protocol (proto=scheme://host:port) */
400 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
404 if (!(end
= strchrW(ptr
, ' ')))
405 end
= ptr
+ strlenW(ptr
);
406 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
407 equal
- ptr
== strlenW(proto
) &&
408 !strncmpiW(proto
, ptr
, strlenW(proto
)))
410 if (end
- equal
> *foundProxyLen
)
412 WARN("buffer too short for %s\n",
413 debugstr_wn(equal
+ 1, end
- equal
- 1));
414 *foundProxyLen
= end
- equal
;
415 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
419 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
420 foundProxy
[end
- equal
] = 0;
431 /* It wasn't found: look for no protocol */
432 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
436 if (!(end
= strchrW(ptr
, ' ')))
437 end
= ptr
+ strlenW(ptr
);
438 if (!strchrW(ptr
, '='))
440 if (end
- ptr
+ 1 > *foundProxyLen
)
442 WARN("buffer too short for %s\n",
443 debugstr_wn(ptr
, end
- ptr
));
444 *foundProxyLen
= end
- ptr
+ 1;
445 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
449 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
450 foundProxy
[end
- ptr
] = 0;
461 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
462 debugstr_w(foundProxy
));
466 /***********************************************************************
467 * InternetInitializeAutoProxyDll (WININET.@)
469 * Setup the internal proxy
478 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
481 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
485 /***********************************************************************
486 * DetectAutoProxyUrl (WININET.@)
488 * Auto detect the proxy url
494 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
495 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
498 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
502 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
504 heap_free(lpwpi
->proxy
);
505 heap_free(lpwpi
->proxyBypass
);
508 static proxyinfo_t
*global_proxy
;
510 static void free_global_proxy( void )
512 EnterCriticalSection( &WININET_cs
);
515 FreeProxyInfo( global_proxy
);
516 heap_free( global_proxy
);
518 LeaveCriticalSection( &WININET_cs
);
521 /***********************************************************************
522 * INTERNET_LoadProxySettings
524 * Loads proxy information from process-wide global settings, the registry,
525 * or the environment into lpwpi.
527 * The caller should call FreeProxyInfo when done with lpwpi.
530 * The proxy may be specified in the form 'http=proxy.my.org'
531 * Presumably that means there can be ftp=ftpproxy.my.org too.
533 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
540 EnterCriticalSection( &WININET_cs
);
543 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
544 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
545 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
547 LeaveCriticalSection( &WININET_cs
);
549 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
553 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
555 lpwpi
->proxyEnabled
= 0;
556 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
563 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
565 TRACE("Proxy is enabled.\n");
567 /* figure out how much memory the proxy setting takes */
568 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
571 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
573 if (!(szProxy
= heap_alloc(len
)))
576 return ERROR_OUTOFMEMORY
;
578 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
580 /* find the http proxy, and strip away everything else */
581 p
= strstrW( szProxy
, szHttp
);
584 p
+= lstrlenW( szHttp
);
585 lstrcpyW( szProxy
, p
);
587 p
= strchrW( szProxy
, ' ' );
590 lpwpi
->proxy
= szProxy
;
592 TRACE("http proxy = %s\n", debugstr_w(lpwpi
->proxy
));
596 TRACE("No proxy server settings in registry.\n");
604 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
605 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
606 return ERROR_OUTOFMEMORY
;
607 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
609 lpwpi
->proxyEnabled
= 1;
610 lpwpi
->proxy
= envproxyW
;
612 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
615 lpwpi
->proxyBypass
= NULL
;
616 if (lpwpi
->proxyEnabled
)
618 if (!(envproxy
= getenv( "no_proxy" )))
620 /* figure out how much memory the proxy setting takes */
621 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
625 if (!(szProxy
= heap_alloc(len
)))
628 return ERROR_OUTOFMEMORY
;
630 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
632 lpwpi
->proxyBypass
= szProxy
;
634 TRACE("http proxy bypass = %s\n", debugstr_w(lpwpi
->proxyBypass
));
638 TRACE("No proxy bypass server settings in registry.\n");
645 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
646 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
647 return ERROR_OUTOFMEMORY
;
648 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
650 lpwpi
->proxyBypass
= envproxyW
;
652 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
658 return ERROR_SUCCESS
;
661 /***********************************************************************
662 * INTERNET_ConfigureProxy
664 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
668 if (INTERNET_LoadProxySettings( &wpi
))
671 if (wpi
.proxyEnabled
)
673 WCHAR proxyurl
[INTERNET_MAX_URL_LENGTH
];
674 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
];
675 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
676 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
677 URL_COMPONENTSW UrlComponents
;
679 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
680 UrlComponents
.dwSchemeLength
= 0;
681 UrlComponents
.lpszHostName
= hostname
;
682 UrlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
683 UrlComponents
.lpszUserName
= username
;
684 UrlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
685 UrlComponents
.lpszPassword
= password
;
686 UrlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
687 UrlComponents
.dwUrlPathLength
= 0;
688 UrlComponents
.dwExtraInfoLength
= 0;
690 if(InternetCrackUrlW(wpi
.proxy
, 0, 0, &UrlComponents
))
692 static const WCHAR szFormat
[] = { 'h','t','t','p',':','/','/','%','s',':','%','u',0 };
694 if(UrlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
695 UrlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
696 sprintfW(proxyurl
, szFormat
, hostname
, UrlComponents
.nPort
);
698 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
699 lpwai
->proxy
= heap_strdupW(proxyurl
);
700 lpwai
->proxyBypass
= heap_strdupW(wpi
.proxyBypass
);
701 if (UrlComponents
.dwUserNameLength
)
703 lpwai
->proxyUsername
= heap_strdupW(UrlComponents
.lpszUserName
);
704 lpwai
->proxyPassword
= heap_strdupW(UrlComponents
.lpszPassword
);
707 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai
->proxy
), debugstr_w(lpwai
->proxyBypass
));
712 TRACE("Failed to parse proxy: %s\n", debugstr_w(wpi
.proxy
));
717 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
721 /***********************************************************************
722 * dump_INTERNET_FLAGS
724 * Helper function to TRACE the internet flags.
730 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
732 #define FE(x) { x, #x }
733 static const wininet_flag_info flag
[] = {
734 FE(INTERNET_FLAG_RELOAD
),
735 FE(INTERNET_FLAG_RAW_DATA
),
736 FE(INTERNET_FLAG_EXISTING_CONNECT
),
737 FE(INTERNET_FLAG_ASYNC
),
738 FE(INTERNET_FLAG_PASSIVE
),
739 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
740 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
741 FE(INTERNET_FLAG_FROM_CACHE
),
742 FE(INTERNET_FLAG_SECURE
),
743 FE(INTERNET_FLAG_KEEP_CONNECTION
),
744 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
745 FE(INTERNET_FLAG_READ_PREFETCH
),
746 FE(INTERNET_FLAG_NO_COOKIES
),
747 FE(INTERNET_FLAG_NO_AUTH
),
748 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
749 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
750 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
751 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
752 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
753 FE(INTERNET_FLAG_RESYNCHRONIZE
),
754 FE(INTERNET_FLAG_HYPERLINK
),
755 FE(INTERNET_FLAG_NO_UI
),
756 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
757 FE(INTERNET_FLAG_CACHE_ASYNC
),
758 FE(INTERNET_FLAG_FORMS_SUBMIT
),
759 FE(INTERNET_FLAG_NEED_FILE
),
760 FE(INTERNET_FLAG_TRANSFER_ASCII
),
761 FE(INTERNET_FLAG_TRANSFER_BINARY
)
766 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
767 if (flag
[i
].val
& dwFlags
) {
768 TRACE(" %s", flag
[i
].name
);
769 dwFlags
&= ~flag
[i
].val
;
773 TRACE(" Unknown flags (%08x)\n", dwFlags
);
778 /***********************************************************************
779 * INTERNET_CloseHandle (internal)
781 * Close internet handle
784 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
786 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
790 heap_free(lpwai
->agent
);
791 heap_free(lpwai
->proxy
);
792 heap_free(lpwai
->proxyBypass
);
793 heap_free(lpwai
->proxyUsername
);
794 heap_free(lpwai
->proxyPassword
);
797 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
799 appinfo_t
*ai
= (appinfo_t
*)hdr
;
802 case INTERNET_OPTION_HANDLE_TYPE
:
803 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
805 if (*size
< sizeof(ULONG
))
806 return ERROR_INSUFFICIENT_BUFFER
;
808 *size
= sizeof(DWORD
);
809 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
810 return ERROR_SUCCESS
;
812 case INTERNET_OPTION_USER_AGENT
: {
815 TRACE("INTERNET_OPTION_USER_AGENT\n");
820 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
822 *size
= (len
+ 1) * sizeof(WCHAR
);
823 if(!buffer
|| bufsize
< *size
)
824 return ERROR_INSUFFICIENT_BUFFER
;
827 strcpyW(buffer
, ai
->agent
);
829 *(WCHAR
*)buffer
= 0;
830 /* If the buffer is copied, the returned length doesn't include
831 * the NULL terminator.
836 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
839 if(!buffer
|| bufsize
< *size
)
840 return ERROR_INSUFFICIENT_BUFFER
;
843 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
846 /* If the buffer is copied, the returned length doesn't include
847 * the NULL terminator.
852 return ERROR_SUCCESS
;
855 case INTERNET_OPTION_PROXY
:
856 if(!size
) return ERROR_INVALID_PARAMETER
;
858 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
859 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
860 LPWSTR proxy
, proxy_bypass
;
863 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
865 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
866 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
868 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
869 return ERROR_INSUFFICIENT_BUFFER
;
871 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
872 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
874 pi
->dwAccessType
= ai
->accessType
;
875 pi
->lpszProxy
= NULL
;
876 pi
->lpszProxyBypass
= NULL
;
878 lstrcpyW(proxy
, ai
->proxy
);
879 pi
->lpszProxy
= proxy
;
882 if (ai
->proxyBypass
) {
883 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
884 pi
->lpszProxyBypass
= proxy_bypass
;
887 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
888 return ERROR_SUCCESS
;
890 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
891 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
892 LPSTR proxy
, proxy_bypass
;
895 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
897 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
898 NULL
, 0, NULL
, NULL
);
899 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
901 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
902 return ERROR_INSUFFICIENT_BUFFER
;
904 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
905 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
907 pi
->dwAccessType
= ai
->accessType
;
908 pi
->lpszProxy
= NULL
;
909 pi
->lpszProxyBypass
= NULL
;
911 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
912 pi
->lpszProxy
= proxy
;
915 if (ai
->proxyBypass
) {
916 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
917 proxyBypassBytesRequired
, NULL
, NULL
);
918 pi
->lpszProxyBypass
= proxy_bypass
;
921 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
922 return ERROR_SUCCESS
;
925 case INTERNET_OPTION_CONNECT_TIMEOUT
:
926 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
928 if (*size
< sizeof(ULONG
))
929 return ERROR_INSUFFICIENT_BUFFER
;
931 *(ULONG
*)buffer
= ai
->connect_timeout
;
932 *size
= sizeof(ULONG
);
934 return ERROR_SUCCESS
;
937 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
940 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
942 appinfo_t
*ai
= (appinfo_t
*)hdr
;
945 case INTERNET_OPTION_CONNECT_TIMEOUT
:
946 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
948 if(size
!= sizeof(connect_timeout
))
949 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
951 return ERROR_BAD_ARGUMENTS
;
953 ai
->connect_timeout
= *(ULONG
*)buf
;
954 return ERROR_SUCCESS
;
955 case INTERNET_OPTION_USER_AGENT
:
956 heap_free(ai
->agent
);
957 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
958 return ERROR_SUCCESS
;
961 return INET_SetOption(hdr
, option
, buf
, size
);
964 static const object_vtbl_t APPINFOVtbl
= {
976 /***********************************************************************
977 * InternetOpenW (WININET.@)
979 * Per-application initialization of wininet
982 * HINTERNET on success
986 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
987 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
989 appinfo_t
*lpwai
= NULL
;
991 if (TRACE_ON(wininet
)) {
992 #define FE(x) { x, #x }
993 static const wininet_flag_info access_type
[] = {
994 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
995 FE(INTERNET_OPEN_TYPE_DIRECT
),
996 FE(INTERNET_OPEN_TYPE_PROXY
),
997 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
1001 const char *access_type_str
= "Unknown";
1003 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1004 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1005 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
1006 if (access_type
[i
].val
== dwAccessType
) {
1007 access_type_str
= access_type
[i
].name
;
1011 TRACE(" access type : %s\n", access_type_str
);
1013 dump_INTERNET_FLAGS(dwFlags
);
1016 /* Clear any error information */
1017 INTERNET_SetLastError(0);
1019 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1020 SetLastError(ERROR_INVALID_PARAMETER
);
1024 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1026 SetLastError(ERROR_OUTOFMEMORY
);
1030 lpwai
->hdr
.htype
= WH_HINIT
;
1031 lpwai
->hdr
.dwFlags
= dwFlags
;
1032 lpwai
->accessType
= dwAccessType
;
1033 lpwai
->proxyUsername
= NULL
;
1034 lpwai
->proxyPassword
= NULL
;
1035 lpwai
->connect_timeout
= connect_timeout
;
1037 lpwai
->agent
= heap_strdupW(lpszAgent
);
1038 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1039 INTERNET_ConfigureProxy( lpwai
);
1040 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1041 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1042 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1045 TRACE("returning %p\n", lpwai
);
1047 return lpwai
->hdr
.hInternet
;
1051 /***********************************************************************
1052 * InternetOpenA (WININET.@)
1054 * Per-application initialization of wininet
1057 * HINTERNET on success
1061 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1062 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1064 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1067 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1068 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1070 szAgent
= heap_strdupAtoW(lpszAgent
);
1071 szProxy
= heap_strdupAtoW(lpszProxy
);
1072 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1074 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1078 heap_free(szBypass
);
1082 /***********************************************************************
1083 * InternetGetLastResponseInfoA (WININET.@)
1085 * Return last wininet error description on the calling thread
1088 * TRUE on success of writing to buffer
1092 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1093 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1095 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1101 *lpdwError
= lpwite
->dwError
;
1102 if (lpwite
->dwError
)
1104 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1105 *lpdwBufferLength
= strlen(lpszBuffer
);
1108 *lpdwBufferLength
= 0;
1113 *lpdwBufferLength
= 0;
1119 /***********************************************************************
1120 * InternetGetLastResponseInfoW (WININET.@)
1122 * Return last wininet error description on the calling thread
1125 * TRUE on success of writing to buffer
1129 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1130 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1132 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1138 *lpdwError
= lpwite
->dwError
;
1139 if (lpwite
->dwError
)
1141 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1142 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1145 *lpdwBufferLength
= 0;
1150 *lpdwBufferLength
= 0;
1156 /***********************************************************************
1157 * InternetGetConnectedState (WININET.@)
1159 * Return connected state
1163 * if lpdwStatus is not null, return the status (off line,
1164 * modem, lan...) in it.
1165 * FALSE if not connected
1167 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1169 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1172 WARN("always returning LAN connection.\n");
1173 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1179 /***********************************************************************
1180 * InternetGetConnectedStateExW (WININET.@)
1182 * Return connected state
1186 * lpdwStatus [O] Flags specifying the status of the internet connection.
1187 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1188 * dwNameLen [I] Size of the buffer, in characters.
1189 * dwReserved [I] Reserved. Must be set to 0.
1193 * if lpdwStatus is not null, return the status (off line,
1194 * modem, lan...) in it.
1195 * FALSE if not connected
1198 * If the system has no available network connections, an empty string is
1199 * stored in lpszConnectionName. If there is a LAN connection, a localized
1200 * "LAN Connection" string is stored. Presumably, if only a dial-up
1201 * connection is available then the name of the dial-up connection is
1202 * returned. Why any application, other than the "Internet Settings" CPL,
1203 * would want to use this function instead of the simpler InternetGetConnectedStateW
1204 * function is beyond me.
1206 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1207 DWORD dwNameLen
, DWORD dwReserved
)
1209 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1216 WARN("always returning LAN connection.\n");
1217 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1219 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1223 /***********************************************************************
1224 * InternetGetConnectedStateExA (WININET.@)
1226 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1227 DWORD dwNameLen
, DWORD dwReserved
)
1229 LPWSTR lpwszConnectionName
= NULL
;
1232 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1234 if (lpszConnectionName
&& dwNameLen
> 0)
1235 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1237 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1239 if (rc
&& lpwszConnectionName
)
1241 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1242 dwNameLen
, NULL
, NULL
);
1243 heap_free(lpwszConnectionName
);
1249 /***********************************************************************
1250 * InternetConnectW (WININET.@)
1252 * Open a ftp, gopher or http session
1255 * HINTERNET a session handle on success
1259 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1260 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1261 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1262 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1265 HINTERNET rc
= NULL
;
1266 DWORD res
= ERROR_SUCCESS
;
1268 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1269 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1270 dwService
, dwFlags
, dwContext
);
1272 if (!lpszServerName
)
1274 SetLastError(ERROR_INVALID_PARAMETER
);
1278 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1279 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1281 res
= ERROR_INVALID_HANDLE
;
1287 case INTERNET_SERVICE_FTP
:
1288 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1289 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1291 res
= INTERNET_GetLastError();
1294 case INTERNET_SERVICE_HTTP
:
1295 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1296 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1299 case INTERNET_SERVICE_GOPHER
:
1305 WININET_Release( &hIC
->hdr
);
1307 TRACE("returning %p\n", rc
);
1313 /***********************************************************************
1314 * InternetConnectA (WININET.@)
1316 * Open a ftp, gopher or http session
1319 * HINTERNET a session handle on success
1323 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1324 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1325 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1326 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1328 HINTERNET rc
= NULL
;
1329 LPWSTR szServerName
;
1333 szServerName
= heap_strdupAtoW(lpszServerName
);
1334 szUserName
= heap_strdupAtoW(lpszUserName
);
1335 szPassword
= heap_strdupAtoW(lpszPassword
);
1337 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1338 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1340 heap_free(szServerName
);
1341 heap_free(szUserName
);
1342 heap_free(szPassword
);
1347 /***********************************************************************
1348 * InternetFindNextFileA (WININET.@)
1350 * Continues a file search from a previous call to FindFirstFile
1357 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1360 WIN32_FIND_DATAW fd
;
1362 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1364 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1368 /***********************************************************************
1369 * InternetFindNextFileW (WININET.@)
1371 * Continues a file search from a previous call to FindFirstFile
1378 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1380 object_header_t
*hdr
;
1385 hdr
= get_handle_object(hFind
);
1387 WARN("Invalid handle\n");
1388 SetLastError(ERROR_INVALID_HANDLE
);
1392 if(hdr
->vtbl
->FindNextFileW
) {
1393 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1395 WARN("Handle doesn't support NextFile\n");
1396 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1399 WININET_Release(hdr
);
1401 if(res
!= ERROR_SUCCESS
)
1403 return res
== ERROR_SUCCESS
;
1406 /***********************************************************************
1407 * InternetCloseHandle (WININET.@)
1409 * Generic close handle function
1416 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1418 object_header_t
*obj
;
1420 TRACE("%p\n", hInternet
);
1422 obj
= get_handle_object( hInternet
);
1424 SetLastError(ERROR_INVALID_HANDLE
);
1428 invalidate_handle(obj
);
1429 WININET_Release(obj
);
1435 /***********************************************************************
1436 * ConvertUrlComponentValue (Internal)
1438 * Helper function for InternetCrackUrlA
1441 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1442 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1443 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1445 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1446 if (*dwComponentLen
!= 0)
1448 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1449 if (*lppszComponent
== NULL
)
1453 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1454 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1457 *lppszComponent
= NULL
;
1459 *dwComponentLen
= nASCIILength
;
1463 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1464 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1465 (*lppszComponent
)[ncpylen
]=0;
1466 *dwComponentLen
= ncpylen
;
1472 /***********************************************************************
1473 * InternetCrackUrlA (WININET.@)
1475 * See InternetCrackUrlW.
1477 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1478 LPURL_COMPONENTSA lpUrlComponents
)
1481 URL_COMPONENTSW UCW
;
1483 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1484 *scheme
= NULL
, *extra
= NULL
;
1486 TRACE("(%s %u %x %p)\n",
1487 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1488 dwUrlLength
, dwFlags
, lpUrlComponents
);
1490 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1491 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1493 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1499 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1501 /* if dwUrlLength=-1 then nLength includes null but length to
1502 InternetCrackUrlW should not include it */
1503 if (dwUrlLength
== -1) nLength
--;
1505 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1506 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1507 lpwszUrl
[nLength
] = '\0';
1509 memset(&UCW
,0,sizeof(UCW
));
1510 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1511 if (lpUrlComponents
->dwHostNameLength
)
1513 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1514 if (lpUrlComponents
->lpszHostName
)
1516 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1517 UCW
.lpszHostName
= hostname
;
1520 if (lpUrlComponents
->dwUserNameLength
)
1522 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1523 if (lpUrlComponents
->lpszUserName
)
1525 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1526 UCW
.lpszUserName
= username
;
1529 if (lpUrlComponents
->dwPasswordLength
)
1531 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1532 if (lpUrlComponents
->lpszPassword
)
1534 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1535 UCW
.lpszPassword
= password
;
1538 if (lpUrlComponents
->dwUrlPathLength
)
1540 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1541 if (lpUrlComponents
->lpszUrlPath
)
1543 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1544 UCW
.lpszUrlPath
= path
;
1547 if (lpUrlComponents
->dwSchemeLength
)
1549 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1550 if (lpUrlComponents
->lpszScheme
)
1552 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1553 UCW
.lpszScheme
= scheme
;
1556 if (lpUrlComponents
->dwExtraInfoLength
)
1558 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1559 if (lpUrlComponents
->lpszExtraInfo
)
1561 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1562 UCW
.lpszExtraInfo
= extra
;
1565 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1567 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1568 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1569 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1570 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1571 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1572 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1573 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1574 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1575 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1576 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1577 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1578 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1580 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1581 lpUrlComponents
->nPort
= UCW
.nPort
;
1583 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1584 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1585 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1586 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1587 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1589 heap_free(lpwszUrl
);
1590 heap_free(hostname
);
1591 heap_free(username
);
1592 heap_free(password
);
1599 static const WCHAR url_schemes
[][7] =
1602 {'g','o','p','h','e','r',0},
1603 {'h','t','t','p',0},
1604 {'h','t','t','p','s',0},
1605 {'f','i','l','e',0},
1606 {'n','e','w','s',0},
1607 {'m','a','i','l','t','o',0},
1611 /***********************************************************************
1612 * GetInternetSchemeW (internal)
1618 * INTERNET_SCHEME_UNKNOWN on failure
1621 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1625 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1627 if(lpszScheme
==NULL
)
1628 return INTERNET_SCHEME_UNKNOWN
;
1630 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1631 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1632 return INTERNET_SCHEME_FIRST
+ i
;
1634 return INTERNET_SCHEME_UNKNOWN
;
1637 /***********************************************************************
1638 * SetUrlComponentValueW (Internal)
1640 * Helper function for InternetCrackUrlW
1643 * lppszComponent [O] Holds the returned string
1644 * dwComponentLen [I] Holds the size of lppszComponent
1645 * [O] Holds the length of the string in lppszComponent without '\0'
1646 * lpszStart [I] Holds the string to copy from
1647 * len [I] Holds the length of lpszStart without '\0'
1654 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1656 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1658 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1661 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1663 if (*lppszComponent
== NULL
)
1665 *lppszComponent
= (LPWSTR
)lpszStart
;
1666 *dwComponentLen
= len
;
1670 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1671 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1672 (*lppszComponent
)[ncpylen
] = '\0';
1673 *dwComponentLen
= ncpylen
;
1680 /***********************************************************************
1681 * InternetCrackUrlW (WININET.@)
1683 * Break up URL into its components
1689 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1690 LPURL_COMPONENTSW lpUC
)
1694 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1697 LPCWSTR lpszParam
= NULL
;
1698 BOOL found_colon
= FALSE
;
1699 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1700 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1701 LPWSTR lpszUrl_decode
= NULL
;
1702 DWORD dwUrlLength
= dwUrlLength_orig
;
1704 TRACE("(%s %u %x %p)\n",
1705 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1706 dwUrlLength
, dwFlags
, lpUC
);
1708 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1710 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1713 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1715 if (dwFlags
& ICU_DECODE
)
1718 DWORD len
= dwUrlLength
+ 1;
1720 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1722 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1725 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1726 url_tmp
[dwUrlLength
] = 0;
1727 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1730 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1733 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1736 lpszUrl
= lpszUrl_decode
;
1742 /* Determine if the URI is absolute. */
1743 while (lpszap
- lpszUrl
< dwUrlLength
)
1745 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1757 lpszcp
= lpszUrl
; /* Relative url */
1764 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1768 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1769 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1771 /* Parse <params> */
1772 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1774 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1776 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1777 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1780 /* Get scheme first. */
1781 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1782 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1783 lpszUrl
, lpszcp
- lpszUrl
);
1785 /* Eat ':' in protocol. */
1788 /* double slash indicates the net_loc portion is present */
1789 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1793 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1797 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1799 lpszNetLoc
= lpszParam
;
1801 else if (!lpszNetLoc
)
1802 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1810 /* [<user>[<:password>]@]<host>[:<port>] */
1811 /* First find the user and password if they exist */
1813 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1814 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1816 /* username and password not specified. */
1817 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1818 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1820 else /* Parse out username and password */
1822 LPCWSTR lpszUser
= lpszcp
;
1823 LPCWSTR lpszPasswd
= lpszHost
;
1825 while (lpszcp
< lpszHost
)
1828 lpszPasswd
= lpszcp
;
1833 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1834 lpszUser
, lpszPasswd
- lpszUser
);
1836 if (lpszPasswd
!= lpszHost
)
1838 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1839 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1840 lpszHost
- lpszPasswd
);
1842 lpszcp
++; /* Advance to beginning of host */
1845 /* Parse <host><:port> */
1848 lpszPort
= lpszNetLoc
;
1850 /* special case for res:// URLs: there is no port here, so the host is the
1851 entire string up to the first '/' */
1852 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1854 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1855 lpszHost
, lpszPort
- lpszHost
);
1860 while (lpszcp
< lpszNetLoc
)
1868 /* If the scheme is "file" and the host is just one letter, it's not a host */
1869 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1872 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1877 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1878 lpszHost
, lpszPort
- lpszHost
);
1879 if (lpszPort
!= lpszNetLoc
)
1880 lpUC
->nPort
= atoiW(++lpszPort
);
1881 else switch (lpUC
->nScheme
)
1883 case INTERNET_SCHEME_HTTP
:
1884 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1886 case INTERNET_SCHEME_HTTPS
:
1887 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1889 case INTERNET_SCHEME_FTP
:
1890 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1892 case INTERNET_SCHEME_GOPHER
:
1893 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1904 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1905 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1906 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1909 /* Here lpszcp points to:
1911 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1912 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1914 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1918 /* Only truncate the parameter list if it's already been saved
1919 * in lpUC->lpszExtraInfo.
1921 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1922 len
= lpszParam
- lpszcp
;
1925 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1926 * newlines if necessary.
1928 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1929 if (lpsznewline
!= NULL
)
1930 len
= lpsznewline
- lpszcp
;
1932 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1934 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1935 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1937 WCHAR tmppath
[MAX_PATH
];
1941 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1946 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1947 tmppath
[len
] = '\0';
1956 /* if ends in \. or \.. append a backslash */
1957 if (tmppath
[len
- 1] == '.' &&
1958 (tmppath
[len
- 2] == '\\' ||
1959 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1961 if (len
< MAX_PATH
- 1)
1963 tmppath
[len
] = '\\';
1964 tmppath
[len
+1] = '\0';
1968 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1972 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1977 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1978 lpUC
->lpszUrlPath
[0] = 0;
1979 lpUC
->dwUrlPathLength
= 0;
1982 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1983 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1984 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1985 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1986 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1988 heap_free( lpszUrl_decode
);
1992 /***********************************************************************
1993 * InternetAttemptConnect (WININET.@)
1995 * Attempt to make a connection to the internet
1998 * ERROR_SUCCESS on success
1999 * Error value on failure
2002 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
2005 return ERROR_SUCCESS
;
2009 /***********************************************************************
2010 * convert_url_canonicalization_flags
2012 * Helper for InternetCanonicalizeUrl
2015 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2018 * Flags suitable for UrlCanonicalize
2020 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
2022 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2024 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
2025 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
2026 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
2027 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
2028 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2029 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
2030 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
2035 /***********************************************************************
2036 * InternetCanonicalizeUrlA (WININET.@)
2038 * Escape unsafe characters and spaces
2045 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2046 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2050 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2051 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2053 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2054 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2055 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2056 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2061 /***********************************************************************
2062 * InternetCanonicalizeUrlW (WININET.@)
2064 * Escape unsafe characters and spaces
2071 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2072 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2076 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2077 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2079 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2080 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2081 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2082 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2087 /* #################################################### */
2089 static INTERNET_STATUS_CALLBACK
set_status_callback(
2090 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2092 INTERNET_STATUS_CALLBACK ret
;
2094 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2095 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2097 ret
= lpwh
->lpfnStatusCB
;
2098 lpwh
->lpfnStatusCB
= callback
;
2103 /***********************************************************************
2104 * InternetSetStatusCallbackA (WININET.@)
2106 * Sets up a callback function which is called as progress is made
2107 * during an operation.
2110 * Previous callback or NULL on success
2111 * INTERNET_INVALID_STATUS_CALLBACK on failure
2114 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2115 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2117 INTERNET_STATUS_CALLBACK retVal
;
2118 object_header_t
*lpwh
;
2120 TRACE("%p\n", hInternet
);
2122 if (!(lpwh
= get_handle_object(hInternet
)))
2123 return INTERNET_INVALID_STATUS_CALLBACK
;
2125 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2127 WININET_Release( lpwh
);
2131 /***********************************************************************
2132 * InternetSetStatusCallbackW (WININET.@)
2134 * Sets up a callback function which is called as progress is made
2135 * during an operation.
2138 * Previous callback or NULL on success
2139 * INTERNET_INVALID_STATUS_CALLBACK on failure
2142 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2143 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2145 INTERNET_STATUS_CALLBACK retVal
;
2146 object_header_t
*lpwh
;
2148 TRACE("%p\n", hInternet
);
2150 if (!(lpwh
= get_handle_object(hInternet
)))
2151 return INTERNET_INVALID_STATUS_CALLBACK
;
2153 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2155 WININET_Release( lpwh
);
2159 /***********************************************************************
2160 * InternetSetFilePointer (WININET.@)
2162 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2163 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2165 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2169 /***********************************************************************
2170 * InternetWriteFile (WININET.@)
2172 * Write data to an open internet file
2179 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2180 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2182 object_header_t
*lpwh
;
2185 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2187 lpwh
= get_handle_object( hFile
);
2189 WARN("Invalid handle\n");
2190 SetLastError(ERROR_INVALID_HANDLE
);
2194 if(lpwh
->vtbl
->WriteFile
) {
2195 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2197 WARN("No Writefile method.\n");
2198 res
= ERROR_INVALID_HANDLE
;
2201 WININET_Release( lpwh
);
2203 if(res
!= ERROR_SUCCESS
)
2205 return res
== ERROR_SUCCESS
;
2209 /***********************************************************************
2210 * InternetReadFile (WININET.@)
2212 * Read data from an open internet file
2219 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2220 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2222 object_header_t
*hdr
;
2223 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2225 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2227 hdr
= get_handle_object(hFile
);
2229 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2233 if(hdr
->vtbl
->ReadFile
)
2234 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2236 WININET_Release(hdr
);
2238 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2239 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2241 if(res
!= ERROR_SUCCESS
)
2243 return res
== ERROR_SUCCESS
;
2246 /***********************************************************************
2247 * InternetReadFileExA (WININET.@)
2249 * Read data from an open internet file
2252 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2253 * lpBuffersOut [I/O] Buffer.
2254 * dwFlags [I] Flags. See notes.
2255 * dwContext [I] Context for callbacks.
2262 * The parameter dwFlags include zero or more of the following flags:
2263 *|IRF_ASYNC - Makes the call asynchronous.
2264 *|IRF_SYNC - Makes the call synchronous.
2265 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2266 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2268 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2271 * InternetOpenUrlA(), HttpOpenRequestA()
2273 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2274 DWORD dwFlags
, DWORD_PTR dwContext
)
2276 object_header_t
*hdr
;
2277 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2279 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2281 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2282 SetLastError(ERROR_INVALID_PARAMETER
);
2286 hdr
= get_handle_object(hFile
);
2288 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2292 if(hdr
->vtbl
->ReadFileEx
)
2293 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2294 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2296 WININET_Release(hdr
);
2298 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2299 res
, lpBuffersOut
->dwBufferLength
);
2301 if(res
!= ERROR_SUCCESS
)
2303 return res
== ERROR_SUCCESS
;
2306 /***********************************************************************
2307 * InternetReadFileExW (WININET.@)
2309 * InternetReadFileExA()
2311 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2312 DWORD dwFlags
, DWORD_PTR dwContext
)
2314 object_header_t
*hdr
;
2315 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2317 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2319 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2320 SetLastError(ERROR_INVALID_PARAMETER
);
2324 hdr
= get_handle_object(hFile
);
2326 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2330 if(hdr
->vtbl
->ReadFileEx
)
2331 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2332 dwFlags
, dwContext
);
2334 WININET_Release(hdr
);
2336 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2337 res
, lpBuffer
->dwBufferLength
);
2339 if(res
!= ERROR_SUCCESS
)
2341 return res
== ERROR_SUCCESS
;
2344 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2346 /* FIXME: This function currently handles more options than it should. Options requiring
2347 * proper handles should be moved to proper functions */
2349 case INTERNET_OPTION_HTTP_VERSION
:
2350 if (*size
< sizeof(HTTP_VERSION_INFO
))
2351 return ERROR_INSUFFICIENT_BUFFER
;
2354 * Presently hardcoded to 1.1
2356 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2357 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2358 *size
= sizeof(HTTP_VERSION_INFO
);
2360 return ERROR_SUCCESS
;
2362 case INTERNET_OPTION_CONNECTED_STATE
:
2363 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2365 if (*size
< sizeof(ULONG
))
2366 return ERROR_INSUFFICIENT_BUFFER
;
2368 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2369 *size
= sizeof(ULONG
);
2371 return ERROR_SUCCESS
;
2373 case INTERNET_OPTION_PROXY
: {
2377 TRACE("Getting global proxy info\n");
2378 memset(&ai
, 0, sizeof(appinfo_t
));
2379 INTERNET_ConfigureProxy(&ai
);
2381 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2382 APPINFO_Destroy(&ai
.hdr
);
2386 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2387 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2389 if (*size
< sizeof(ULONG
))
2390 return ERROR_INSUFFICIENT_BUFFER
;
2392 *(ULONG
*)buffer
= max_conns
;
2393 *size
= sizeof(ULONG
);
2395 return ERROR_SUCCESS
;
2397 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2398 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2400 if (*size
< sizeof(ULONG
))
2401 return ERROR_INSUFFICIENT_BUFFER
;
2403 *(ULONG
*)buffer
= max_1_0_conns
;
2404 *size
= sizeof(ULONG
);
2406 return ERROR_SUCCESS
;
2408 case INTERNET_OPTION_SECURITY_FLAGS
:
2409 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2410 return ERROR_SUCCESS
;
2412 case INTERNET_OPTION_VERSION
: {
2413 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2415 TRACE("INTERNET_OPTION_VERSION\n");
2417 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2418 return ERROR_INSUFFICIENT_BUFFER
;
2420 memcpy(buffer
, &info
, sizeof(info
));
2421 *size
= sizeof(info
);
2423 return ERROR_SUCCESS
;
2426 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2427 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2428 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2429 DWORD res
= ERROR_SUCCESS
, i
;
2433 TRACE("Getting global proxy info\n");
2434 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2437 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2439 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2441 return ERROR_INSUFFICIENT_BUFFER
;
2444 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2445 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2446 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2448 switch (optionW
->dwOption
) {
2449 case INTERNET_PER_CONN_FLAGS
:
2451 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2453 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2456 case INTERNET_PER_CONN_PROXY_SERVER
:
2458 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2460 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2463 case INTERNET_PER_CONN_PROXY_BYPASS
:
2465 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2467 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2470 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2471 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2472 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2473 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2474 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2475 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2476 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2477 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2481 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2482 res
= ERROR_INVALID_PARAMETER
;
2490 case INTERNET_OPTION_REQUEST_FLAGS
:
2491 case INTERNET_OPTION_USER_AGENT
:
2493 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2494 case INTERNET_OPTION_POLICY
:
2495 return ERROR_INVALID_PARAMETER
;
2496 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2497 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2499 if (*size
< sizeof(ULONG
))
2500 return ERROR_INSUFFICIENT_BUFFER
;
2502 *(ULONG
*)buffer
= connect_timeout
;
2503 *size
= sizeof(ULONG
);
2505 return ERROR_SUCCESS
;
2508 FIXME("Stub for %d\n", option
);
2509 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2512 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2515 case INTERNET_OPTION_CONTEXT_VALUE
:
2517 return ERROR_INVALID_PARAMETER
;
2519 if (*size
< sizeof(DWORD_PTR
)) {
2520 *size
= sizeof(DWORD_PTR
);
2521 return ERROR_INSUFFICIENT_BUFFER
;
2524 return ERROR_INVALID_PARAMETER
;
2526 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2527 *size
= sizeof(DWORD_PTR
);
2528 return ERROR_SUCCESS
;
2530 case INTERNET_OPTION_REQUEST_FLAGS
:
2531 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2532 *size
= sizeof(DWORD
);
2533 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2535 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2536 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2537 WARN("Called on global option %u\n", option
);
2538 return ERROR_INTERNET_INVALID_OPERATION
;
2541 /* FIXME: we shouldn't call it here */
2542 return query_global_option(option
, buffer
, size
, unicode
);
2545 /***********************************************************************
2546 * InternetQueryOptionW (WININET.@)
2548 * Queries an options on the specified handle
2555 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2556 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2558 object_header_t
*hdr
;
2559 DWORD res
= ERROR_INVALID_HANDLE
;
2561 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2564 hdr
= get_handle_object(hInternet
);
2566 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2567 WININET_Release(hdr
);
2570 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2573 if(res
!= ERROR_SUCCESS
)
2575 return res
== ERROR_SUCCESS
;
2578 /***********************************************************************
2579 * InternetQueryOptionA (WININET.@)
2581 * Queries an options on the specified handle
2588 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2589 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2591 object_header_t
*hdr
;
2592 DWORD res
= ERROR_INVALID_HANDLE
;
2594 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2597 hdr
= get_handle_object(hInternet
);
2599 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2600 WININET_Release(hdr
);
2603 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2606 if(res
!= ERROR_SUCCESS
)
2608 return res
== ERROR_SUCCESS
;
2611 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2614 case INTERNET_OPTION_CALLBACK
:
2615 WARN("Not settable option %u\n", option
);
2616 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2617 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2618 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2619 WARN("Called on global option %u\n", option
);
2620 return ERROR_INTERNET_INVALID_OPERATION
;
2623 return ERROR_INTERNET_INVALID_OPTION
;
2626 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2629 case INTERNET_OPTION_CALLBACK
:
2630 WARN("Not global option %u\n", option
);
2631 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2633 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2634 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2636 if(size
!= sizeof(max_conns
))
2637 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2639 return ERROR_BAD_ARGUMENTS
;
2641 max_conns
= *(ULONG
*)buf
;
2642 return ERROR_SUCCESS
;
2644 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2645 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2647 if(size
!= sizeof(max_1_0_conns
))
2648 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2650 return ERROR_BAD_ARGUMENTS
;
2652 max_1_0_conns
= *(ULONG
*)buf
;
2653 return ERROR_SUCCESS
;
2655 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2656 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2658 if(size
!= sizeof(connect_timeout
))
2659 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2661 return ERROR_BAD_ARGUMENTS
;
2663 connect_timeout
= *(ULONG
*)buf
;
2664 return ERROR_SUCCESS
;
2666 case INTERNET_OPTION_SETTINGS_CHANGED
:
2667 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2668 collect_connections(COLLECT_CONNECTIONS
);
2669 return ERROR_SUCCESS
;
2672 return ERROR_INTERNET_INVALID_OPTION
;
2675 /***********************************************************************
2676 * InternetSetOptionW (WININET.@)
2678 * Sets an options on the specified handle
2685 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2686 LPVOID lpBuffer
, DWORD dwBufferLength
)
2688 object_header_t
*lpwhh
;
2692 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2694 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2696 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2698 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2700 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2702 WININET_Release(lpwhh
);
2704 if(res
!= ERROR_SUCCESS
)
2707 return res
== ERROR_SUCCESS
;
2712 case INTERNET_OPTION_HTTP_VERSION
:
2714 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2715 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2718 case INTERNET_OPTION_ERROR_MASK
:
2721 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2723 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2724 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2725 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2726 SetLastError(ERROR_INVALID_PARAMETER
);
2728 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2729 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2732 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2733 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2736 case INTERNET_OPTION_PROXY
:
2738 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2740 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2742 SetLastError(ERROR_INVALID_PARAMETER
);
2747 EnterCriticalSection( &WININET_cs
);
2748 free_global_proxy();
2749 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2752 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2754 global_proxy
->proxyEnabled
= 1;
2755 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2756 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2760 global_proxy
->proxyEnabled
= 0;
2761 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2764 LeaveCriticalSection( &WININET_cs
);
2768 /* In general, each type of object should handle
2769 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2770 * get silently dropped.
2772 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2773 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2778 case INTERNET_OPTION_CODEPAGE
:
2780 ULONG codepage
= *(ULONG
*)lpBuffer
;
2781 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2784 case INTERNET_OPTION_REQUEST_PRIORITY
:
2786 ULONG priority
= *(ULONG
*)lpBuffer
;
2787 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2790 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2792 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2793 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2796 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2798 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2799 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2802 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2803 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2805 case INTERNET_OPTION_END_BROWSER_SESSION
:
2806 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2808 case INTERNET_OPTION_CONNECTED_STATE
:
2809 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2811 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2812 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2814 case INTERNET_OPTION_SEND_TIMEOUT
:
2815 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2816 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2818 ULONG timeout
= *(ULONG
*)lpBuffer
;
2819 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2822 case INTERNET_OPTION_CONNECT_RETRIES
:
2824 ULONG retries
= *(ULONG
*)lpBuffer
;
2825 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2828 case INTERNET_OPTION_CONTEXT_VALUE
:
2832 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2835 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2837 SetLastError(ERROR_INVALID_PARAMETER
);
2841 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2844 case INTERNET_OPTION_SECURITY_FLAGS
:
2845 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2847 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2848 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2850 case INTERNET_OPTION_HTTP_DECODING
:
2851 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2852 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2855 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2856 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2857 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2860 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2861 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2862 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2865 case INTERNET_OPTION_CODEPAGE_PATH
:
2866 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2867 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2870 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2871 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2872 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2875 case INTERNET_OPTION_IDN
:
2876 FIXME("INTERNET_OPTION_IDN; STUB\n");
2877 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2880 case INTERNET_OPTION_POLICY
:
2881 SetLastError(ERROR_INVALID_PARAMETER
);
2884 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2885 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2890 INTERNET_LoadProxySettings(&pi
);
2892 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2893 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2895 switch (option
->dwOption
) {
2896 case INTERNET_PER_CONN_PROXY_SERVER
:
2897 heap_free(pi
.proxy
);
2898 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2901 case INTERNET_PER_CONN_FLAGS
:
2902 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2903 pi
.proxyEnabled
= 1;
2906 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2907 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2908 pi
.proxyEnabled
= 0;
2912 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2913 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2914 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2915 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2916 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2917 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2918 case INTERNET_PER_CONN_PROXY_BYPASS
:
2919 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2923 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2924 SetLastError(ERROR_INVALID_PARAMETER
);
2929 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2934 ret
= (res
== ERROR_SUCCESS
);
2938 FIXME("Option %d STUB\n",dwOption
);
2939 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2945 WININET_Release( lpwhh
);
2951 /***********************************************************************
2952 * InternetSetOptionA (WININET.@)
2954 * Sets an options on the specified handle.
2961 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2962 LPVOID lpBuffer
, DWORD dwBufferLength
)
2970 case INTERNET_OPTION_PROXY
:
2972 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2973 LPINTERNET_PROXY_INFOW piw
;
2974 DWORD proxlen
, prbylen
;
2977 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2978 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2979 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2980 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2981 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2982 piw
->dwAccessType
= pi
->dwAccessType
;
2983 prox
= (LPWSTR
) &piw
[1];
2984 prby
= &prox
[proxlen
+1];
2985 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2986 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2987 piw
->lpszProxy
= prox
;
2988 piw
->lpszProxyBypass
= prby
;
2991 case INTERNET_OPTION_USER_AGENT
:
2992 case INTERNET_OPTION_USERNAME
:
2993 case INTERNET_OPTION_PASSWORD
:
2994 case INTERNET_OPTION_PROXY_USERNAME
:
2995 case INTERNET_OPTION_PROXY_PASSWORD
:
2996 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
2997 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
2998 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3000 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3002 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3003 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3004 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3005 wbuffer
= heap_alloc(wlen
);
3008 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3009 if (listA
->pszConnection
)
3011 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3012 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3013 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3016 listW
->pszConnection
= NULL
;
3017 listW
->dwOptionCount
= listA
->dwOptionCount
;
3018 listW
->dwOptionError
= listA
->dwOptionError
;
3019 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3021 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3022 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3023 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3025 optW
->dwOption
= optA
->dwOption
;
3027 switch (optA
->dwOption
) {
3028 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3029 case INTERNET_PER_CONN_PROXY_BYPASS
:
3030 case INTERNET_PER_CONN_PROXY_SERVER
:
3031 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3032 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3033 if (optA
->Value
.pszValue
)
3035 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3036 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3037 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3040 optW
->Value
.pszValue
= NULL
;
3042 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3043 case INTERNET_PER_CONN_FLAGS
:
3044 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3045 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3047 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3048 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3051 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3052 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3060 wlen
= dwBufferLength
;
3063 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3065 if( lpBuffer
!= wbuffer
)
3067 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3069 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3071 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3072 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3073 switch (opt
->dwOption
) {
3074 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3075 case INTERNET_PER_CONN_PROXY_BYPASS
:
3076 case INTERNET_PER_CONN_PROXY_SERVER
:
3077 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3078 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3079 heap_free( opt
->Value
.pszValue
);
3085 heap_free( list
->pOptions
);
3087 heap_free( wbuffer
);
3094 /***********************************************************************
3095 * InternetSetOptionExA (WININET.@)
3097 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3098 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3100 FIXME("Flags %08x ignored\n", dwFlags
);
3101 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3104 /***********************************************************************
3105 * InternetSetOptionExW (WININET.@)
3107 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3108 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3110 FIXME("Flags %08x ignored\n", dwFlags
);
3111 if( dwFlags
& ~ISO_VALID_FLAGS
)
3113 SetLastError( ERROR_INVALID_PARAMETER
);
3116 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3119 static const WCHAR WININET_wkday
[7][4] =
3120 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3121 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3122 static const WCHAR WININET_month
[12][4] =
3123 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3124 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3125 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3127 /***********************************************************************
3128 * InternetTimeFromSystemTimeA (WININET.@)
3130 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3133 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3135 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3137 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3139 SetLastError(ERROR_INVALID_PARAMETER
);
3143 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3145 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3149 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3150 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3155 /***********************************************************************
3156 * InternetTimeFromSystemTimeW (WININET.@)
3158 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3160 static const WCHAR date
[] =
3161 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3162 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3164 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3166 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3168 SetLastError(ERROR_INVALID_PARAMETER
);
3172 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3174 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3178 sprintfW( string
, date
,
3179 WININET_wkday
[time
->wDayOfWeek
],
3181 WININET_month
[time
->wMonth
- 1],
3190 /***********************************************************************
3191 * InternetTimeToSystemTimeA (WININET.@)
3193 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3198 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3200 stringW
= heap_strdupAtoW(string
);
3203 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3204 heap_free( stringW
);
3209 /***********************************************************************
3210 * InternetTimeToSystemTimeW (WININET.@)
3212 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3215 const WCHAR
*s
= string
;
3218 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3220 if (!string
|| !time
) return FALSE
;
3222 /* Windows does this too */
3223 GetSystemTime( time
);
3225 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3226 * a SYSTEMTIME structure.
3229 while (*s
&& !isalphaW( *s
)) s
++;
3230 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3231 time
->wDayOfWeek
= 7;
3233 for (i
= 0; i
< 7; i
++)
3235 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3236 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3237 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3239 time
->wDayOfWeek
= i
;
3244 if (time
->wDayOfWeek
> 6) return TRUE
;
3245 while (*s
&& !isdigitW( *s
)) s
++;
3246 time
->wDay
= strtolW( s
, &end
, 10 );
3249 while (*s
&& !isalphaW( *s
)) s
++;
3250 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3253 for (i
= 0; i
< 12; i
++)
3255 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3256 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3257 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3259 time
->wMonth
= i
+ 1;
3263 if (time
->wMonth
== 0) return TRUE
;
3265 while (*s
&& !isdigitW( *s
)) s
++;
3266 if (*s
== '\0') return TRUE
;
3267 time
->wYear
= strtolW( s
, &end
, 10 );
3270 while (*s
&& !isdigitW( *s
)) s
++;
3271 if (*s
== '\0') return TRUE
;
3272 time
->wHour
= strtolW( s
, &end
, 10 );
3275 while (*s
&& !isdigitW( *s
)) s
++;
3276 if (*s
== '\0') return TRUE
;
3277 time
->wMinute
= strtolW( s
, &end
, 10 );
3280 while (*s
&& !isdigitW( *s
)) s
++;
3281 if (*s
== '\0') return TRUE
;
3282 time
->wSecond
= strtolW( s
, &end
, 10 );
3285 time
->wMilliseconds
= 0;
3289 /***********************************************************************
3290 * InternetCheckConnectionW (WININET.@)
3292 * Pings a requested host to check internet connection
3295 * TRUE on success and FALSE on failure. If a failure then
3296 * ERROR_NOT_CONNECTED is placed into GetLastError
3299 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3302 * this is a kludge which runs the resident ping program and reads the output.
3304 * Anyone have a better idea?
3308 static const CHAR ping
[] = "ping -c 1 ";
3309 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3310 CHAR
*command
= NULL
;
3311 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3319 * Crack or set the Address
3321 if (lpszUrl
== NULL
)
3324 * According to the doc we are supposed to use the ip for the next
3325 * server in the WnInet internal server database. I have
3326 * no idea what that is or how to get it.
3328 * So someone needs to implement this.
3330 FIXME("Unimplemented with URL of NULL\n");
3335 URL_COMPONENTSW components
;
3337 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3338 components
.lpszHostName
= (LPWSTR
)hostW
;
3339 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3341 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3344 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3345 port
= components
.nPort
;
3346 TRACE("port: %d\n", port
);
3349 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3351 struct sockaddr_storage saddr
;
3352 socklen_t sa_len
= sizeof(saddr
);
3355 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3357 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3360 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3368 * Build our ping command
3370 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3371 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3372 strcpy(command
,ping
);
3373 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3374 strcat(command
,redirect
);
3376 TRACE("Ping command is : %s\n",command
);
3378 status
= system(command
);
3380 TRACE("Ping returned a code of %i\n",status
);
3382 /* Ping return code of 0 indicates success */
3388 heap_free( command
);
3390 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3396 /***********************************************************************
3397 * InternetCheckConnectionA (WININET.@)
3399 * Pings a requested host to check internet connection
3402 * TRUE on success and FALSE on failure. If a failure then
3403 * ERROR_NOT_CONNECTED is placed into GetLastError
3406 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3412 url
= heap_strdupAtoW(lpszUrl
);
3417 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3424 /**********************************************************
3425 * INTERNET_InternetOpenUrlW (internal)
3430 * handle of connection or NULL on failure
3432 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3433 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3435 URL_COMPONENTSW urlComponents
;
3436 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3437 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3438 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3439 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3440 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3442 HINTERNET client
= NULL
, client1
= NULL
;
3445 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3446 dwHeadersLength
, dwFlags
, dwContext
);
3448 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3449 urlComponents
.lpszScheme
= protocol
;
3450 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3451 urlComponents
.lpszHostName
= hostName
;
3452 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3453 urlComponents
.lpszUserName
= userName
;
3454 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3455 urlComponents
.lpszPassword
= password
;
3456 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3457 urlComponents
.lpszUrlPath
= path
;
3458 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3459 urlComponents
.lpszExtraInfo
= extra
;
3460 urlComponents
.dwExtraInfoLength
= 1024;
3461 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3463 switch(urlComponents
.nScheme
) {
3464 case INTERNET_SCHEME_FTP
:
3465 if(urlComponents
.nPort
== 0)
3466 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3467 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3468 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3471 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3472 if(client1
== NULL
) {
3473 InternetCloseHandle(client
);
3478 case INTERNET_SCHEME_HTTP
:
3479 case INTERNET_SCHEME_HTTPS
: {
3480 static const WCHAR szStars
[] = { '*','/','*', 0 };
3481 LPCWSTR accept
[2] = { szStars
, NULL
};
3482 if(urlComponents
.nPort
== 0) {
3483 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3484 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3486 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3488 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3490 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3491 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3492 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3493 if(res
!= ERROR_SUCCESS
) {
3494 INTERNET_SetLastError(res
);
3498 if (urlComponents
.dwExtraInfoLength
) {
3500 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3502 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3504 InternetCloseHandle(client
);
3507 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3508 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3509 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3510 heap_free(path_extra
);
3513 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3515 if(client1
== NULL
) {
3516 InternetCloseHandle(client
);
3519 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3520 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3521 GetLastError() != ERROR_IO_PENDING
) {
3522 InternetCloseHandle(client1
);
3527 case INTERNET_SCHEME_GOPHER
:
3528 /* gopher doesn't seem to be implemented in wine, but it's supposed
3529 * to be supported by InternetOpenUrlA. */
3531 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3535 TRACE(" %p <--\n", client1
);
3540 /**********************************************************
3541 * InternetOpenUrlW (WININET.@)
3546 * handle of connection or NULL on failure
3557 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3559 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3561 TRACE("%p\n", task
->hdr
.hdr
);
3563 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3564 task
->headers_len
, task
->flags
, task
->context
);
3565 heap_free(task
->url
);
3566 heap_free(task
->headers
);
3569 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3570 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3572 HINTERNET ret
= NULL
;
3573 appinfo_t
*hIC
= NULL
;
3575 if (TRACE_ON(wininet
)) {
3576 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3577 dwHeadersLength
, dwFlags
, dwContext
);
3579 dump_INTERNET_FLAGS(dwFlags
);
3584 SetLastError(ERROR_INVALID_PARAMETER
);
3588 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3589 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3590 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3594 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3595 open_url_task_t
*task
;
3597 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3598 task
->url
= heap_strdupW(lpszUrl
);
3599 task
->headers
= heap_strdupW(lpszHeaders
);
3600 task
->headers_len
= dwHeadersLength
;
3601 task
->flags
= dwFlags
;
3602 task
->context
= dwContext
;
3604 INTERNET_AsyncCall(&task
->hdr
);
3605 SetLastError(ERROR_IO_PENDING
);
3607 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3612 WININET_Release( &hIC
->hdr
);
3613 TRACE(" %p <--\n", ret
);
3618 /**********************************************************
3619 * InternetOpenUrlA (WININET.@)
3624 * handle of connection or NULL on failure
3626 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3627 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3629 HINTERNET rc
= NULL
;
3630 DWORD lenHeaders
= 0;
3631 LPWSTR szUrl
= NULL
;
3632 LPWSTR szHeaders
= NULL
;
3637 szUrl
= heap_strdupAtoW(lpszUrl
);
3643 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3644 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3649 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3652 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3653 lenHeaders
, dwFlags
, dwContext
);
3656 heap_free(szHeaders
);
3661 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3663 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3667 lpwite
->dwError
= 0;
3668 lpwite
->response
[0] = '\0';
3671 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3680 /***********************************************************************
3681 * INTERNET_SetLastError (internal)
3683 * Set last thread specific error
3688 void INTERNET_SetLastError(DWORD dwError
)
3690 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3693 lpwite
= INTERNET_AllocThreadError();
3695 SetLastError(dwError
);
3697 lpwite
->dwError
= dwError
;
3701 /***********************************************************************
3702 * INTERNET_GetLastError (internal)
3704 * Get last thread specific error
3709 DWORD
INTERNET_GetLastError(void)
3711 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3712 if (!lpwite
) return 0;
3713 /* TlsGetValue clears last error, so set it again here */
3714 SetLastError(lpwite
->dwError
);
3715 return lpwite
->dwError
;
3719 /***********************************************************************
3720 * INTERNET_WorkerThreadFunc (internal)
3722 * Worker thread execution function
3727 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3729 task_header_t
*task
= lpvParam
;
3734 WININET_Release(task
->hdr
);
3737 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3739 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3740 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3745 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3747 task_header_t
*task
;
3749 task
= heap_alloc(size
);
3753 task
->hdr
= WININET_AddRef(hdr
);
3758 /***********************************************************************
3759 * INTERNET_AsyncCall (internal)
3761 * Retrieves work request from queue
3766 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3772 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3776 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3778 return ERROR_SUCCESS
;
3782 /***********************************************************************
3783 * INTERNET_GetResponseBuffer (internal)
3788 LPSTR
INTERNET_GetResponseBuffer(void)
3790 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3792 lpwite
= INTERNET_AllocThreadError();
3794 return lpwite
->response
;
3797 /***********************************************************************
3798 * INTERNET_GetNextLine (internal)
3800 * Parse next line in directory string listing
3803 * Pointer to beginning of next line
3808 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3811 BOOL bSuccess
= FALSE
;
3813 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3818 pfd
.events
= POLLIN
;
3820 while (nRecv
< MAX_REPLY_LEN
)
3822 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3824 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3826 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3830 if (lpszBuffer
[nRecv
] == '\n')
3835 if (lpszBuffer
[nRecv
] != '\r')
3840 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3848 lpszBuffer
[nRecv
] = '\0';
3850 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3859 /**********************************************************
3860 * InternetQueryDataAvailable (WININET.@)
3862 * Determines how much data is available to be read.
3865 * TRUE on success, FALSE if an error occurred. If
3866 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3867 * no data is presently available, FALSE is returned with
3868 * the last error ERROR_IO_PENDING; a callback with status
3869 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3870 * data is available.
3872 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3873 LPDWORD lpdwNumberOfBytesAvailable
,
3874 DWORD dwFlags
, DWORD_PTR dwContext
)
3876 object_header_t
*hdr
;
3879 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3881 hdr
= get_handle_object( hFile
);
3883 SetLastError(ERROR_INVALID_HANDLE
);
3887 if(hdr
->vtbl
->QueryDataAvailable
) {
3888 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3890 WARN("wrong handle\n");
3891 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3894 WININET_Release(hdr
);
3896 if(res
!= ERROR_SUCCESS
)
3898 return res
== ERROR_SUCCESS
;
3902 /***********************************************************************
3903 * InternetLockRequestFile (WININET.@)
3905 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3912 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3919 /***********************************************************************
3920 * InternetAutodial (WININET.@)
3922 * On windows this function is supposed to dial the default internet
3923 * connection. We don't want to have Wine dial out to the internet so
3924 * we return TRUE by default. It might be nice to check if we are connected.
3931 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3935 /* Tell that we are connected to the internet. */
3939 /***********************************************************************
3940 * InternetAutodialHangup (WININET.@)
3942 * Hangs up a connection made with InternetAutodial
3951 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3955 /* we didn't dial, we don't disconnect */
3959 /***********************************************************************
3960 * InternetCombineUrlA (WININET.@)
3962 * Combine a base URL with a relative URL
3970 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3971 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3976 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3978 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3979 dwFlags
^= ICU_NO_ENCODE
;
3980 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3985 /***********************************************************************
3986 * InternetCombineUrlW (WININET.@)
3988 * Combine a base URL with a relative URL
3996 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3997 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4002 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4004 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4005 dwFlags
^= ICU_NO_ENCODE
;
4006 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4011 /* max port num is 65535 => 5 digits */
4012 #define MAX_WORD_DIGITS 5
4014 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4015 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4016 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4017 (url)->dw##component##Length : strlen((url)->lpsz##component))
4019 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4021 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4022 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4024 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4025 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4027 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4028 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4030 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4031 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4034 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4040 /* opaque urls do not fit into the standard url hierarchy and don't have
4041 * two following slashes */
4042 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4044 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4045 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4046 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4047 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4048 (nScheme
!= INTERNET_SCHEME_FILE
);
4051 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4054 if (scheme
< INTERNET_SCHEME_FIRST
)
4056 index
= scheme
- INTERNET_SCHEME_FIRST
;
4057 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4059 return (LPCWSTR
)url_schemes
[index
];
4062 /* we can calculate using ansi strings because we're just
4063 * calculating string length, not size
4065 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4066 LPDWORD lpdwUrlLength
)
4068 INTERNET_SCHEME nScheme
;
4072 if (lpUrlComponents
->lpszScheme
)
4074 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4075 *lpdwUrlLength
+= dwLen
;
4076 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4082 nScheme
= lpUrlComponents
->nScheme
;
4084 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4085 nScheme
= INTERNET_SCHEME_HTTP
;
4086 scheme
= INTERNET_GetSchemeString(nScheme
);
4087 *lpdwUrlLength
+= strlenW(scheme
);
4090 (*lpdwUrlLength
)++; /* ':' */
4091 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4092 *lpdwUrlLength
+= strlen("//");
4094 if (lpUrlComponents
->lpszUserName
)
4096 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4097 *lpdwUrlLength
+= strlen("@");
4101 if (lpUrlComponents
->lpszPassword
)
4103 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4108 if (lpUrlComponents
->lpszPassword
)
4110 *lpdwUrlLength
+= strlen(":");
4111 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4114 if (lpUrlComponents
->lpszHostName
)
4116 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4118 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4120 char szPort
[MAX_WORD_DIGITS
+1];
4122 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4123 *lpdwUrlLength
+= strlen(szPort
);
4124 *lpdwUrlLength
+= strlen(":");
4127 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4128 (*lpdwUrlLength
)++; /* '/' */
4131 if (lpUrlComponents
->lpszUrlPath
)
4132 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4134 if (lpUrlComponents
->lpszExtraInfo
)
4135 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4140 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4144 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4146 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4147 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4148 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4149 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4150 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4151 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4152 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4153 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4154 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4156 if (lpUrlComponents
->lpszScheme
)
4158 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4159 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4160 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4161 -1, urlCompW
->lpszScheme
, len
);
4164 if (lpUrlComponents
->lpszHostName
)
4166 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4167 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4168 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4169 -1, urlCompW
->lpszHostName
, len
);
4172 if (lpUrlComponents
->lpszUserName
)
4174 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4175 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4176 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4177 -1, urlCompW
->lpszUserName
, len
);
4180 if (lpUrlComponents
->lpszPassword
)
4182 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4183 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4184 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4185 -1, urlCompW
->lpszPassword
, len
);
4188 if (lpUrlComponents
->lpszUrlPath
)
4190 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4191 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4192 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4193 -1, urlCompW
->lpszUrlPath
, len
);
4196 if (lpUrlComponents
->lpszExtraInfo
)
4198 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4199 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4200 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4201 -1, urlCompW
->lpszExtraInfo
, len
);
4205 /***********************************************************************
4206 * InternetCreateUrlA (WININET.@)
4208 * See InternetCreateUrlW.
4210 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4211 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4215 URL_COMPONENTSW urlCompW
;
4217 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4219 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4221 SetLastError(ERROR_INVALID_PARAMETER
);
4225 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4228 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4230 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4232 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4233 *lpdwUrlLength
/= sizeof(WCHAR
);
4235 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4236 * minus one, so add one to leave room for NULL terminator
4239 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4241 heap_free(urlCompW
.lpszScheme
);
4242 heap_free(urlCompW
.lpszHostName
);
4243 heap_free(urlCompW
.lpszUserName
);
4244 heap_free(urlCompW
.lpszPassword
);
4245 heap_free(urlCompW
.lpszUrlPath
);
4246 heap_free(urlCompW
.lpszExtraInfo
);
4251 /***********************************************************************
4252 * InternetCreateUrlW (WININET.@)
4254 * Creates a URL from its component parts.
4257 * lpUrlComponents [I] URL Components.
4258 * dwFlags [I] Flags. See notes.
4259 * lpszUrl [I] Buffer in which to store the created URL.
4260 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4261 * lpszUrl in characters. On output, the number of bytes
4262 * required to store the URL including terminator.
4266 * The dwFlags parameter can be zero or more of the following:
4267 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4274 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4275 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4278 INTERNET_SCHEME nScheme
;
4280 static const WCHAR slashSlashW
[] = {'/','/'};
4281 static const WCHAR fmtW
[] = {'%','u',0};
4283 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4285 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4287 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4291 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4294 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4296 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4297 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4301 *lpdwUrlLength
= dwLen
;
4306 if (lpUrlComponents
->lpszScheme
)
4308 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4309 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4312 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4317 nScheme
= lpUrlComponents
->nScheme
;
4319 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4320 nScheme
= INTERNET_SCHEME_HTTP
;
4322 scheme
= INTERNET_GetSchemeString(nScheme
);
4323 dwLen
= strlenW(scheme
);
4324 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4328 /* all schemes are followed by at least a colon */
4332 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4334 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4335 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4338 if (lpUrlComponents
->lpszUserName
)
4340 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4341 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4344 if (lpUrlComponents
->lpszPassword
)
4349 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4350 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4358 if (lpUrlComponents
->lpszHostName
)
4360 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4361 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4364 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4366 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4368 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4371 dwLen
= strlenW(szPort
);
4372 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4376 /* add slash between hostname and path if necessary */
4377 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4384 if (lpUrlComponents
->lpszUrlPath
)
4386 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4387 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4391 if (lpUrlComponents
->lpszExtraInfo
)
4393 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4394 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4403 /***********************************************************************
4404 * InternetConfirmZoneCrossingA (WININET.@)
4407 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4409 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4410 return ERROR_SUCCESS
;
4413 /***********************************************************************
4414 * InternetConfirmZoneCrossingW (WININET.@)
4417 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4419 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4420 return ERROR_SUCCESS
;
4423 static DWORD zone_preference
= 3;
4425 /***********************************************************************
4426 * PrivacySetZonePreferenceW (WININET.@)
4428 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4430 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4432 zone_preference
= template;
4436 /***********************************************************************
4437 * PrivacyGetZonePreferenceW (WININET.@)
4439 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4440 LPWSTR preference
, LPDWORD length
)
4442 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4444 if (template) *template = zone_preference
;
4448 /***********************************************************************
4449 * InternetGetSecurityInfoByURLA (WININET.@)
4451 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4456 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4458 url
= heap_strdupAtoW(lpszURL
);
4462 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4467 /***********************************************************************
4468 * InternetGetSecurityInfoByURLW (WININET.@)
4470 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4472 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4473 URL_COMPONENTSW url
= {sizeof(url
)};
4477 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4479 url
.lpszHostName
= hostname
;
4480 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4482 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4483 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4484 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4488 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4490 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4494 if(server
->cert_chain
) {
4495 const CERT_CHAIN_CONTEXT
*chain_dup
;
4497 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4499 *ppCertChain
= chain_dup
;
4500 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4505 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4509 server_release(server
);
4513 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4514 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4516 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4517 lpdwConnection
, dwReserved
);
4518 return ERROR_SUCCESS
;
4521 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4522 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4524 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4525 lpdwConnection
, dwReserved
);
4526 return ERROR_SUCCESS
;
4529 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4531 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4535 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4537 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4541 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4543 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4544 return ERROR_SUCCESS
;
4547 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4550 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4551 debugstr_w(pwszTarget
), pbHexHash
);
4555 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4557 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4561 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4563 FIXME("(%p, %08lx) stub\n", a
, b
);
4567 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4569 FIXME("%p: stub\n", parent
);