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
29 #define WIN32_NO_STATUS
31 #define COM_NO_WINDOWS_H
34 //#include "wine/port.h"
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>
64 //#include "winineti.h"
66 #include <wine/debug.h>
67 //#include "winerror.h"
68 #define NO_SHLWAPI_STREAM
71 #if defined(__MINGW32__) || defined (_MSC_VER)
75 //#include "wine/exception.h"
80 //#include "wine/unicode.h"
82 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
84 #define RESPONSE_TIMEOUT 30
89 CHAR response
[MAX_REPLY_LEN
];
90 } WITHREADERROR
, *LPWITHREADERROR
;
92 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
93 HMODULE WININET_hModule
;
95 static CRITICAL_SECTION WININET_cs
;
96 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
99 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
100 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
102 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
104 static object_header_t
**handle_table
;
105 static UINT_PTR next_handle
;
106 static UINT_PTR handle_table_size
;
115 static ULONG max_conns
= 2, max_1_0_conns
= 4;
116 static ULONG connect_timeout
= 60000;
118 static const WCHAR szInternetSettings
[] =
119 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
120 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
121 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
122 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
123 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
124 static const WCHAR szProxyOverride
[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
126 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
128 UINT_PTR handle
= 0, num
;
129 object_header_t
*ret
;
133 ret
= heap_alloc_zero(size
);
137 list_init(&ret
->children
);
139 EnterCriticalSection( &WININET_cs
);
141 if(!handle_table_size
) {
143 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
146 handle_table_size
= num
;
151 }else if(next_handle
== handle_table_size
) {
152 num
= handle_table_size
* 2;
153 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
156 handle_table_size
= num
;
163 handle
= next_handle
;
164 if(handle_table
[handle
])
165 ERR("handle isn't free but should be\n");
166 handle_table
[handle
] = ret
;
167 ret
->valid_handle
= TRUE
;
169 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
173 LeaveCriticalSection( &WININET_cs
);
182 ret
->hInternet
= (HINTERNET
)handle
;
185 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
186 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
192 object_header_t
*WININET_AddRef( object_header_t
*info
)
194 ULONG refs
= InterlockedIncrement(&info
->refs
);
195 TRACE("%p -> refcount = %d\n", info
, refs
);
199 object_header_t
*get_handle_object( HINTERNET hinternet
)
201 object_header_t
*info
= NULL
;
202 UINT_PTR handle
= (UINT_PTR
) hinternet
;
204 EnterCriticalSection( &WININET_cs
);
206 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
207 info
= WININET_AddRef(handle_table
[handle
]);
209 LeaveCriticalSection( &WININET_cs
);
211 TRACE("handle %ld -> %p\n", handle
, info
);
216 static void invalidate_handle(object_header_t
*info
)
218 object_header_t
*child
, *next
;
220 if(!info
->valid_handle
)
222 info
->valid_handle
= FALSE
;
224 /* Free all children as native does */
225 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
227 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
228 invalidate_handle( child
);
231 WININET_Release(info
);
234 BOOL
WININET_Release( object_header_t
*info
)
236 ULONG refs
= InterlockedDecrement(&info
->refs
);
237 TRACE( "object %p refcount = %d\n", info
, refs
);
240 invalidate_handle(info
);
241 if ( info
->vtbl
->CloseConnection
)
243 TRACE( "closing connection %p\n", info
);
244 info
->vtbl
->CloseConnection( info
);
246 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
247 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
248 || !(info
->dwInternalFlags
& INET_OPENURL
))
250 INTERNET_SendCallback(info
, info
->dwContext
,
251 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
254 TRACE( "destroying object %p\n", info
);
255 if ( info
->htype
!= WH_HINIT
)
256 list_remove( &info
->entry
);
257 info
->vtbl
->Destroy( info
);
259 if(info
->hInternet
) {
260 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
262 EnterCriticalSection( &WININET_cs
);
264 handle_table
[handle
] = NULL
;
265 if(next_handle
> handle
)
266 next_handle
= handle
;
268 LeaveCriticalSection( &WININET_cs
);
276 /***********************************************************************
277 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
280 * hinstDLL [I] handle to the DLL's instance
282 * lpvReserved [I] reserved, must be NULL
289 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
291 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
294 case DLL_PROCESS_ATTACH
:
296 g_dwTlsErrIndex
= TlsAlloc();
298 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
302 URLCacheContainers_CreateDefaults();
305 WININET_hModule
= hinstDLL
;
308 case DLL_THREAD_ATTACH
:
311 case DLL_THREAD_DETACH
:
312 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
314 heap_free(TlsGetValue(g_dwTlsErrIndex
));
318 case DLL_PROCESS_DETACH
:
319 if (lpvReserved
) break;
320 collect_connections(COLLECT_CLEANUP
);
325 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
327 heap_free(TlsGetValue(g_dwTlsErrIndex
));
328 TlsFree(g_dwTlsErrIndex
);
335 /***********************************************************************
336 * INTERNET_SaveProxySettings
338 * Stores the proxy settings given by lpwai into the registry
341 * ERROR_SUCCESS if no error, or error code on fail
343 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
348 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
351 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
359 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
367 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
375 return ERROR_SUCCESS
;
378 /***********************************************************************
379 * INTERNET_FindProxyForProtocol
381 * Searches the proxy string for a proxy of the given protocol.
382 * Returns the found proxy, or the default proxy if none of the given
386 * szProxy [In] proxy string to search
387 * proto [In] protocol to search for, e.g. "http"
388 * foundProxy [Out] found proxy
389 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
392 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
393 * *foundProxyLen is set to the required size in WCHARs, including the
394 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
396 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
401 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
403 /* First, look for the specified protocol (proto=scheme://host:port) */
404 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
408 if (!(end
= strchrW(ptr
, ' ')))
409 end
= ptr
+ strlenW(ptr
);
410 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
411 equal
- ptr
== strlenW(proto
) &&
412 !strncmpiW(proto
, ptr
, strlenW(proto
)))
414 if (end
- equal
> *foundProxyLen
)
416 WARN("buffer too short for %s\n",
417 debugstr_wn(equal
+ 1, end
- equal
- 1));
418 *foundProxyLen
= end
- equal
;
419 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
423 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
424 foundProxy
[end
- equal
] = 0;
435 /* It wasn't found: look for no protocol */
436 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
440 if (!(end
= strchrW(ptr
, ' ')))
441 end
= ptr
+ strlenW(ptr
);
442 if (!strchrW(ptr
, '='))
444 if (end
- ptr
+ 1 > *foundProxyLen
)
446 WARN("buffer too short for %s\n",
447 debugstr_wn(ptr
, end
- ptr
));
448 *foundProxyLen
= end
- ptr
+ 1;
449 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
453 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
454 foundProxy
[end
- ptr
] = 0;
465 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
466 debugstr_w(foundProxy
));
470 /***********************************************************************
471 * InternetInitializeAutoProxyDll (WININET.@)
473 * Setup the internal proxy
482 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
485 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
489 /***********************************************************************
490 * DetectAutoProxyUrl (WININET.@)
492 * Auto detect the proxy url
498 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
499 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
502 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
506 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
508 heap_free(lpwpi
->proxy
);
509 heap_free(lpwpi
->proxyBypass
);
512 static proxyinfo_t
*global_proxy
;
514 static void free_global_proxy( void )
516 EnterCriticalSection( &WININET_cs
);
519 FreeProxyInfo( global_proxy
);
520 heap_free( global_proxy
);
522 LeaveCriticalSection( &WININET_cs
);
525 /***********************************************************************
526 * INTERNET_LoadProxySettings
528 * Loads proxy information from process-wide global settings, the registry,
529 * or the environment into lpwpi.
531 * The caller should call FreeProxyInfo when done with lpwpi.
534 * The proxy may be specified in the form 'http=proxy.my.org'
535 * Presumably that means there can be ftp=ftpproxy.my.org too.
537 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
544 EnterCriticalSection( &WININET_cs
);
547 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
548 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
549 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
551 LeaveCriticalSection( &WININET_cs
);
553 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
557 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
559 lpwpi
->proxyEnabled
= 0;
560 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
567 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
569 TRACE("Proxy is enabled.\n");
571 /* figure out how much memory the proxy setting takes */
572 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
575 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
577 if (!(szProxy
= heap_alloc(len
)))
580 return ERROR_OUTOFMEMORY
;
582 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
584 /* find the http proxy, and strip away everything else */
585 p
= strstrW( szProxy
, szHttp
);
588 p
+= lstrlenW( szHttp
);
589 lstrcpyW( szProxy
, p
);
591 p
= strchrW( szProxy
, ' ' );
594 lpwpi
->proxy
= szProxy
;
596 TRACE("http proxy = %s\n", debugstr_w(lpwpi
->proxy
));
600 TRACE("No proxy server settings in registry.\n");
608 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
609 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
610 return ERROR_OUTOFMEMORY
;
611 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
613 lpwpi
->proxyEnabled
= 1;
614 lpwpi
->proxy
= envproxyW
;
616 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
619 lpwpi
->proxyBypass
= NULL
;
620 if (lpwpi
->proxyEnabled
)
622 if (!(envproxy
= getenv( "no_proxy" )))
624 /* figure out how much memory the proxy setting takes */
625 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
629 if (!(szProxy
= heap_alloc(len
)))
632 return ERROR_OUTOFMEMORY
;
634 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
636 lpwpi
->proxyBypass
= szProxy
;
638 TRACE("http proxy bypass = %s\n", debugstr_w(lpwpi
->proxyBypass
));
642 TRACE("No proxy bypass server settings in registry.\n");
649 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
650 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
651 return ERROR_OUTOFMEMORY
;
652 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
654 lpwpi
->proxyBypass
= envproxyW
;
656 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
662 return ERROR_SUCCESS
;
665 /***********************************************************************
666 * INTERNET_ConfigureProxy
668 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
670 proxyinfo_t wpi
= {0};
672 if (INTERNET_LoadProxySettings( &wpi
))
675 if (wpi
.proxyEnabled
)
677 WCHAR proxyurl
[INTERNET_MAX_URL_LENGTH
];
678 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
];
679 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
680 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
681 URL_COMPONENTSW UrlComponents
;
683 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
684 UrlComponents
.dwSchemeLength
= 0;
685 UrlComponents
.lpszHostName
= hostname
;
686 UrlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
687 UrlComponents
.lpszUserName
= username
;
688 UrlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
689 UrlComponents
.lpszPassword
= password
;
690 UrlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
691 UrlComponents
.dwUrlPathLength
= 0;
692 UrlComponents
.dwExtraInfoLength
= 0;
694 if(InternetCrackUrlW(wpi
.proxy
, 0, 0, &UrlComponents
))
696 static const WCHAR szFormat
[] = { 'h','t','t','p',':','/','/','%','s',':','%','u',0 };
698 if(UrlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
699 UrlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
700 sprintfW(proxyurl
, szFormat
, hostname
, UrlComponents
.nPort
);
702 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
703 lpwai
->proxy
= heap_strdupW(proxyurl
);
704 lpwai
->proxyBypass
= heap_strdupW(wpi
.proxyBypass
);
705 if (UrlComponents
.dwUserNameLength
)
707 lpwai
->proxyUsername
= heap_strdupW(UrlComponents
.lpszUserName
);
708 lpwai
->proxyPassword
= heap_strdupW(UrlComponents
.lpszPassword
);
711 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai
->proxy
), debugstr_w(lpwai
->proxyBypass
));
717 TRACE("Failed to parse proxy: %s\n", debugstr_w(wpi
.proxy
));
722 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
727 /***********************************************************************
728 * dump_INTERNET_FLAGS
730 * Helper function to TRACE the internet flags.
736 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
738 #define FE(x) { x, #x }
739 static const wininet_flag_info flag
[] = {
740 FE(INTERNET_FLAG_RELOAD
),
741 FE(INTERNET_FLAG_RAW_DATA
),
742 FE(INTERNET_FLAG_EXISTING_CONNECT
),
743 FE(INTERNET_FLAG_ASYNC
),
744 FE(INTERNET_FLAG_PASSIVE
),
745 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
746 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
747 FE(INTERNET_FLAG_FROM_CACHE
),
748 FE(INTERNET_FLAG_SECURE
),
749 FE(INTERNET_FLAG_KEEP_CONNECTION
),
750 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
751 FE(INTERNET_FLAG_READ_PREFETCH
),
752 FE(INTERNET_FLAG_NO_COOKIES
),
753 FE(INTERNET_FLAG_NO_AUTH
),
754 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
755 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
756 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
757 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
758 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
759 FE(INTERNET_FLAG_RESYNCHRONIZE
),
760 FE(INTERNET_FLAG_HYPERLINK
),
761 FE(INTERNET_FLAG_NO_UI
),
762 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
763 FE(INTERNET_FLAG_CACHE_ASYNC
),
764 FE(INTERNET_FLAG_FORMS_SUBMIT
),
765 FE(INTERNET_FLAG_NEED_FILE
),
766 FE(INTERNET_FLAG_TRANSFER_ASCII
),
767 FE(INTERNET_FLAG_TRANSFER_BINARY
)
772 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
773 if (flag
[i
].val
& dwFlags
) {
774 TRACE(" %s", flag
[i
].name
);
775 dwFlags
&= ~flag
[i
].val
;
779 TRACE(" Unknown flags (%08x)\n", dwFlags
);
784 /***********************************************************************
785 * INTERNET_CloseHandle (internal)
787 * Close internet handle
790 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
792 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
796 heap_free(lpwai
->agent
);
797 heap_free(lpwai
->proxy
);
798 heap_free(lpwai
->proxyBypass
);
799 heap_free(lpwai
->proxyUsername
);
800 heap_free(lpwai
->proxyPassword
);
806 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
808 appinfo_t
*ai
= (appinfo_t
*)hdr
;
811 case INTERNET_OPTION_HANDLE_TYPE
:
812 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
814 if (*size
< sizeof(ULONG
))
815 return ERROR_INSUFFICIENT_BUFFER
;
817 *size
= sizeof(DWORD
);
818 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
819 return ERROR_SUCCESS
;
821 case INTERNET_OPTION_USER_AGENT
: {
824 TRACE("INTERNET_OPTION_USER_AGENT\n");
829 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
831 *size
= (len
+ 1) * sizeof(WCHAR
);
832 if(!buffer
|| bufsize
< *size
)
833 return ERROR_INSUFFICIENT_BUFFER
;
836 strcpyW(buffer
, ai
->agent
);
838 *(WCHAR
*)buffer
= 0;
839 /* If the buffer is copied, the returned length doesn't include
840 * the NULL terminator.
845 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
848 if(!buffer
|| bufsize
< *size
)
849 return ERROR_INSUFFICIENT_BUFFER
;
852 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
855 /* If the buffer is copied, the returned length doesn't include
856 * the NULL terminator.
861 return ERROR_SUCCESS
;
864 case INTERNET_OPTION_PROXY
:
865 if(!size
) return ERROR_INVALID_PARAMETER
;
867 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
868 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
869 LPWSTR proxy
, proxy_bypass
;
872 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
874 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
875 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
877 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
878 return ERROR_INSUFFICIENT_BUFFER
;
880 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
881 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
883 pi
->dwAccessType
= ai
->accessType
;
884 pi
->lpszProxy
= NULL
;
885 pi
->lpszProxyBypass
= NULL
;
887 lstrcpyW(proxy
, ai
->proxy
);
888 pi
->lpszProxy
= proxy
;
891 if (ai
->proxyBypass
) {
892 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
893 pi
->lpszProxyBypass
= proxy_bypass
;
896 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
897 return ERROR_SUCCESS
;
899 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
900 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
901 LPSTR proxy
, proxy_bypass
;
904 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
906 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
907 NULL
, 0, NULL
, NULL
);
908 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
910 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
911 return ERROR_INSUFFICIENT_BUFFER
;
913 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
914 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
916 pi
->dwAccessType
= ai
->accessType
;
917 pi
->lpszProxy
= NULL
;
918 pi
->lpszProxyBypass
= NULL
;
920 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
921 pi
->lpszProxy
= proxy
;
924 if (ai
->proxyBypass
) {
925 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
926 proxyBypassBytesRequired
, NULL
, NULL
);
927 pi
->lpszProxyBypass
= proxy_bypass
;
930 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
931 return ERROR_SUCCESS
;
934 case INTERNET_OPTION_CONNECT_TIMEOUT
:
935 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
937 if (*size
< sizeof(ULONG
))
938 return ERROR_INSUFFICIENT_BUFFER
;
940 *(ULONG
*)buffer
= ai
->connect_timeout
;
941 *size
= sizeof(ULONG
);
943 return ERROR_SUCCESS
;
946 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
949 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
951 appinfo_t
*ai
= (appinfo_t
*)hdr
;
954 case INTERNET_OPTION_CONNECT_TIMEOUT
:
955 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
957 if(size
!= sizeof(connect_timeout
))
958 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
960 return ERROR_BAD_ARGUMENTS
;
962 ai
->connect_timeout
= *(ULONG
*)buf
;
963 return ERROR_SUCCESS
;
964 case INTERNET_OPTION_USER_AGENT
:
965 heap_free(ai
->agent
);
966 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
967 return ERROR_SUCCESS
;
970 return INET_SetOption(hdr
, option
, buf
, size
);
973 static const object_vtbl_t APPINFOVtbl
= {
985 /***********************************************************************
986 * InternetOpenW (WININET.@)
988 * Per-application initialization of wininet
991 * HINTERNET on success
995 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
996 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
998 appinfo_t
*lpwai
= NULL
;
1001 int error
= WSAStartup(MAKEWORD(2, 2), &wsaData
);
1002 if (error
) ERR("WSAStartup failed: %d\n", error
);
1005 if (TRACE_ON(wininet
)) {
1006 #define FE(x) { x, #x }
1007 static const wininet_flag_info access_type
[] = {
1008 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
1009 FE(INTERNET_OPEN_TYPE_DIRECT
),
1010 FE(INTERNET_OPEN_TYPE_PROXY
),
1011 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
1015 const char *access_type_str
= "Unknown";
1017 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1018 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1019 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
1020 if (access_type
[i
].val
== dwAccessType
) {
1021 access_type_str
= access_type
[i
].name
;
1025 TRACE(" access type : %s\n", access_type_str
);
1027 dump_INTERNET_FLAGS(dwFlags
);
1030 /* Clear any error information */
1031 INTERNET_SetLastError(0);
1033 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1034 SetLastError(ERROR_INVALID_PARAMETER
);
1038 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1040 SetLastError(ERROR_OUTOFMEMORY
);
1044 lpwai
->hdr
.htype
= WH_HINIT
;
1045 lpwai
->hdr
.dwFlags
= dwFlags
;
1046 lpwai
->accessType
= dwAccessType
;
1047 lpwai
->proxyUsername
= NULL
;
1048 lpwai
->proxyPassword
= NULL
;
1049 lpwai
->connect_timeout
= connect_timeout
;
1051 lpwai
->agent
= heap_strdupW(lpszAgent
);
1052 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1053 INTERNET_ConfigureProxy( lpwai
);
1054 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1055 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1056 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1059 TRACE("returning %p\n", lpwai
);
1061 return lpwai
->hdr
.hInternet
;
1065 /***********************************************************************
1066 * InternetOpenA (WININET.@)
1068 * Per-application initialization of wininet
1071 * HINTERNET on success
1075 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1076 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1078 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1081 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1082 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1084 szAgent
= heap_strdupAtoW(lpszAgent
);
1085 szProxy
= heap_strdupAtoW(lpszProxy
);
1086 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1088 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1092 heap_free(szBypass
);
1096 /***********************************************************************
1097 * InternetGetLastResponseInfoA (WININET.@)
1099 * Return last wininet error description on the calling thread
1102 * TRUE on success of writing to buffer
1106 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1107 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1109 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1115 *lpdwError
= lpwite
->dwError
;
1116 if (lpwite
->dwError
)
1118 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1119 *lpdwBufferLength
= strlen(lpszBuffer
);
1122 *lpdwBufferLength
= 0;
1127 *lpdwBufferLength
= 0;
1133 /***********************************************************************
1134 * InternetGetLastResponseInfoW (WININET.@)
1136 * Return last wininet error description on the calling thread
1139 * TRUE on success of writing to buffer
1143 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1144 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1146 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1152 *lpdwError
= lpwite
->dwError
;
1153 if (lpwite
->dwError
)
1155 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1156 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1159 *lpdwBufferLength
= 0;
1164 *lpdwBufferLength
= 0;
1170 /***********************************************************************
1171 * InternetGetConnectedState (WININET.@)
1173 * Return connected state
1177 * if lpdwStatus is not null, return the status (off line,
1178 * modem, lan...) in it.
1179 * FALSE if not connected
1181 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1183 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1186 WARN("always returning LAN connection.\n");
1187 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1193 /***********************************************************************
1194 * InternetGetConnectedStateExW (WININET.@)
1196 * Return connected state
1200 * lpdwStatus [O] Flags specifying the status of the internet connection.
1201 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1202 * dwNameLen [I] Size of the buffer, in characters.
1203 * dwReserved [I] Reserved. Must be set to 0.
1207 * if lpdwStatus is not null, return the status (off line,
1208 * modem, lan...) in it.
1209 * FALSE if not connected
1212 * If the system has no available network connections, an empty string is
1213 * stored in lpszConnectionName. If there is a LAN connection, a localized
1214 * "LAN Connection" string is stored. Presumably, if only a dial-up
1215 * connection is available then the name of the dial-up connection is
1216 * returned. Why any application, other than the "Internet Settings" CPL,
1217 * would want to use this function instead of the simpler InternetGetConnectedStateW
1218 * function is beyond me.
1220 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1221 DWORD dwNameLen
, DWORD dwReserved
)
1223 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1230 WARN("always returning LAN connection.\n");
1231 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1233 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1237 /***********************************************************************
1238 * InternetGetConnectedStateExA (WININET.@)
1240 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1241 DWORD dwNameLen
, DWORD dwReserved
)
1243 LPWSTR lpwszConnectionName
= NULL
;
1246 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1248 if (lpszConnectionName
&& dwNameLen
> 0)
1249 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1251 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1253 if (rc
&& lpwszConnectionName
)
1255 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1256 dwNameLen
, NULL
, NULL
);
1257 heap_free(lpwszConnectionName
);
1263 /***********************************************************************
1264 * InternetConnectW (WININET.@)
1266 * Open a ftp, gopher or http session
1269 * HINTERNET a session handle on success
1273 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1274 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1275 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1276 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1279 HINTERNET rc
= NULL
;
1280 DWORD res
= ERROR_SUCCESS
;
1282 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1283 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1284 dwService
, dwFlags
, dwContext
);
1286 if (!lpszServerName
)
1288 SetLastError(ERROR_INVALID_PARAMETER
);
1292 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1293 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1295 res
= ERROR_INVALID_HANDLE
;
1301 case INTERNET_SERVICE_FTP
:
1302 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1303 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1305 res
= INTERNET_GetLastError();
1308 case INTERNET_SERVICE_HTTP
:
1309 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1310 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1313 case INTERNET_SERVICE_GOPHER
:
1319 WININET_Release( &hIC
->hdr
);
1321 TRACE("returning %p\n", rc
);
1327 /***********************************************************************
1328 * InternetConnectA (WININET.@)
1330 * Open a ftp, gopher or http session
1333 * HINTERNET a session handle on success
1337 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1338 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1339 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1340 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1342 HINTERNET rc
= NULL
;
1343 LPWSTR szServerName
;
1347 szServerName
= heap_strdupAtoW(lpszServerName
);
1348 szUserName
= heap_strdupAtoW(lpszUserName
);
1349 szPassword
= heap_strdupAtoW(lpszPassword
);
1351 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1352 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1354 heap_free(szServerName
);
1355 heap_free(szUserName
);
1356 heap_free(szPassword
);
1361 /***********************************************************************
1362 * InternetFindNextFileA (WININET.@)
1364 * Continues a file search from a previous call to FindFirstFile
1371 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1374 WIN32_FIND_DATAW fd
;
1376 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1378 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1382 /***********************************************************************
1383 * InternetFindNextFileW (WININET.@)
1385 * Continues a file search from a previous call to FindFirstFile
1392 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1394 object_header_t
*hdr
;
1399 hdr
= get_handle_object(hFind
);
1401 WARN("Invalid handle\n");
1402 SetLastError(ERROR_INVALID_HANDLE
);
1406 if(hdr
->vtbl
->FindNextFileW
) {
1407 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1409 WARN("Handle doesn't support NextFile\n");
1410 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1413 WININET_Release(hdr
);
1415 if(res
!= ERROR_SUCCESS
)
1417 return res
== ERROR_SUCCESS
;
1420 /***********************************************************************
1421 * InternetCloseHandle (WININET.@)
1423 * Generic close handle function
1430 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1432 object_header_t
*obj
;
1434 TRACE("%p\n", hInternet
);
1436 obj
= get_handle_object( hInternet
);
1438 SetLastError(ERROR_INVALID_HANDLE
);
1442 invalidate_handle(obj
);
1443 WININET_Release(obj
);
1449 /***********************************************************************
1450 * ConvertUrlComponentValue (Internal)
1452 * Helper function for InternetCrackUrlA
1455 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1456 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1457 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1459 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1460 if (*dwComponentLen
!= 0)
1462 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1463 if (*lppszComponent
== NULL
)
1467 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1468 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1471 *lppszComponent
= NULL
;
1473 *dwComponentLen
= nASCIILength
;
1477 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1478 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1479 (*lppszComponent
)[ncpylen
]=0;
1480 *dwComponentLen
= ncpylen
;
1486 /***********************************************************************
1487 * InternetCrackUrlA (WININET.@)
1489 * See InternetCrackUrlW.
1491 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1492 LPURL_COMPONENTSA lpUrlComponents
)
1495 URL_COMPONENTSW UCW
;
1497 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1498 *scheme
= NULL
, *extra
= NULL
;
1500 TRACE("(%s %u %x %p)\n",
1501 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1502 dwUrlLength
, dwFlags
, lpUrlComponents
);
1504 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1505 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1507 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1513 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1515 /* if dwUrlLength=-1 then nLength includes null but length to
1516 InternetCrackUrlW should not include it */
1517 if (dwUrlLength
== -1) nLength
--;
1519 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1520 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1521 lpwszUrl
[nLength
] = '\0';
1523 memset(&UCW
,0,sizeof(UCW
));
1524 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1525 if (lpUrlComponents
->dwHostNameLength
)
1527 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1528 if (lpUrlComponents
->lpszHostName
)
1530 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1531 UCW
.lpszHostName
= hostname
;
1534 if (lpUrlComponents
->dwUserNameLength
)
1536 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1537 if (lpUrlComponents
->lpszUserName
)
1539 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1540 UCW
.lpszUserName
= username
;
1543 if (lpUrlComponents
->dwPasswordLength
)
1545 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1546 if (lpUrlComponents
->lpszPassword
)
1548 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1549 UCW
.lpszPassword
= password
;
1552 if (lpUrlComponents
->dwUrlPathLength
)
1554 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1555 if (lpUrlComponents
->lpszUrlPath
)
1557 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1558 UCW
.lpszUrlPath
= path
;
1561 if (lpUrlComponents
->dwSchemeLength
)
1563 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1564 if (lpUrlComponents
->lpszScheme
)
1566 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1567 UCW
.lpszScheme
= scheme
;
1570 if (lpUrlComponents
->dwExtraInfoLength
)
1572 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1573 if (lpUrlComponents
->lpszExtraInfo
)
1575 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1576 UCW
.lpszExtraInfo
= extra
;
1579 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1581 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1582 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1583 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1584 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1585 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1586 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1587 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1588 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1589 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1590 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1591 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1592 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1594 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1595 lpUrlComponents
->nPort
= UCW
.nPort
;
1597 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1598 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1599 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1600 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1601 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1603 heap_free(lpwszUrl
);
1604 heap_free(hostname
);
1605 heap_free(username
);
1606 heap_free(password
);
1613 static const WCHAR url_schemes
[][7] =
1616 {'g','o','p','h','e','r',0},
1617 {'h','t','t','p',0},
1618 {'h','t','t','p','s',0},
1619 {'f','i','l','e',0},
1620 {'n','e','w','s',0},
1621 {'m','a','i','l','t','o',0},
1625 /***********************************************************************
1626 * GetInternetSchemeW (internal)
1632 * INTERNET_SCHEME_UNKNOWN on failure
1635 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1639 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1641 if(lpszScheme
==NULL
)
1642 return INTERNET_SCHEME_UNKNOWN
;
1644 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1645 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1646 return INTERNET_SCHEME_FIRST
+ i
;
1648 return INTERNET_SCHEME_UNKNOWN
;
1651 /***********************************************************************
1652 * SetUrlComponentValueW (Internal)
1654 * Helper function for InternetCrackUrlW
1657 * lppszComponent [O] Holds the returned string
1658 * dwComponentLen [I] Holds the size of lppszComponent
1659 * [O] Holds the length of the string in lppszComponent without '\0'
1660 * lpszStart [I] Holds the string to copy from
1661 * len [I] Holds the length of lpszStart without '\0'
1668 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1670 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1672 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1675 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1677 if (*lppszComponent
== NULL
)
1679 *lppszComponent
= (LPWSTR
)lpszStart
;
1680 *dwComponentLen
= len
;
1684 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1685 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1686 (*lppszComponent
)[ncpylen
] = '\0';
1687 *dwComponentLen
= ncpylen
;
1694 /***********************************************************************
1695 * InternetCrackUrlW (WININET.@)
1697 * Break up URL into its components
1703 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1704 LPURL_COMPONENTSW lpUC
)
1708 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1711 LPCWSTR lpszParam
= NULL
;
1712 BOOL found_colon
= FALSE
;
1713 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1714 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1715 LPWSTR lpszUrl_decode
= NULL
;
1716 DWORD dwUrlLength
= dwUrlLength_orig
;
1718 TRACE("(%s %u %x %p)\n",
1719 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1720 dwUrlLength
, dwFlags
, lpUC
);
1722 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1724 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1727 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1729 if (dwFlags
& ICU_DECODE
)
1732 DWORD len
= dwUrlLength
+ 1;
1734 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1736 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1739 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1740 url_tmp
[dwUrlLength
] = 0;
1741 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1744 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1747 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1750 lpszUrl
= lpszUrl_decode
;
1756 /* Determine if the URI is absolute. */
1757 while (lpszap
- lpszUrl
< dwUrlLength
)
1759 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1771 lpszcp
= lpszUrl
; /* Relative url */
1778 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1782 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1783 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1785 /* Parse <params> */
1786 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1788 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1790 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1791 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1794 /* Get scheme first. */
1795 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1796 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1797 lpszUrl
, lpszcp
- lpszUrl
);
1799 /* Eat ':' in protocol. */
1802 /* double slash indicates the net_loc portion is present */
1803 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1807 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1811 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1813 lpszNetLoc
= lpszParam
;
1815 else if (!lpszNetLoc
)
1816 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1824 /* [<user>[<:password>]@]<host>[:<port>] */
1825 /* First find the user and password if they exist */
1827 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1828 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1830 /* username and password not specified. */
1831 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1832 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1834 else /* Parse out username and password */
1836 LPCWSTR lpszUser
= lpszcp
;
1837 LPCWSTR lpszPasswd
= lpszHost
;
1839 while (lpszcp
< lpszHost
)
1842 lpszPasswd
= lpszcp
;
1847 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1848 lpszUser
, lpszPasswd
- lpszUser
);
1850 if (lpszPasswd
!= lpszHost
)
1852 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1853 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1854 lpszHost
- lpszPasswd
);
1856 lpszcp
++; /* Advance to beginning of host */
1859 /* Parse <host><:port> */
1862 lpszPort
= lpszNetLoc
;
1864 /* special case for res:// URLs: there is no port here, so the host is the
1865 entire string up to the first '/' */
1866 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1868 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1869 lpszHost
, lpszPort
- lpszHost
);
1874 while (lpszcp
< lpszNetLoc
)
1882 /* If the scheme is "file" and the host is just one letter, it's not a host */
1883 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1886 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1891 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1892 lpszHost
, lpszPort
- lpszHost
);
1893 if (lpszPort
!= lpszNetLoc
)
1894 lpUC
->nPort
= atoiW(++lpszPort
);
1895 else switch (lpUC
->nScheme
)
1897 case INTERNET_SCHEME_HTTP
:
1898 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1900 case INTERNET_SCHEME_HTTPS
:
1901 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1903 case INTERNET_SCHEME_FTP
:
1904 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1906 case INTERNET_SCHEME_GOPHER
:
1907 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1918 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1919 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1920 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1923 /* Here lpszcp points to:
1925 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1926 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1928 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1932 /* Only truncate the parameter list if it's already been saved
1933 * in lpUC->lpszExtraInfo.
1935 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1936 len
= lpszParam
- lpszcp
;
1939 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1940 * newlines if necessary.
1942 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1943 if (lpsznewline
!= NULL
)
1944 len
= lpsznewline
- lpszcp
;
1946 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1948 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1949 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1951 WCHAR tmppath
[MAX_PATH
];
1955 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1960 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1961 tmppath
[len
] = '\0';
1970 /* if ends in \. or \.. append a backslash */
1971 if (tmppath
[len
- 1] == '.' &&
1972 (tmppath
[len
- 2] == '\\' ||
1973 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1975 if (len
< MAX_PATH
- 1)
1977 tmppath
[len
] = '\\';
1978 tmppath
[len
+1] = '\0';
1982 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1986 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1991 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1992 lpUC
->lpszUrlPath
[0] = 0;
1993 lpUC
->dwUrlPathLength
= 0;
1996 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1997 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1998 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1999 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
2000 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
2002 heap_free( lpszUrl_decode
);
2006 /***********************************************************************
2007 * InternetAttemptConnect (WININET.@)
2009 * Attempt to make a connection to the internet
2012 * ERROR_SUCCESS on success
2013 * Error value on failure
2016 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
2019 return ERROR_SUCCESS
;
2023 /***********************************************************************
2024 * convert_url_canonicalization_flags
2026 * Helper for InternetCanonicalizeUrl
2029 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2032 * Flags suitable for UrlCanonicalize
2034 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
2036 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2038 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
2039 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
2040 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
2041 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
2042 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2043 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
2044 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
2049 /***********************************************************************
2050 * InternetCanonicalizeUrlA (WININET.@)
2052 * Escape unsafe characters and spaces
2059 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2060 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2064 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2065 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2067 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2068 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2069 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2070 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2075 /***********************************************************************
2076 * InternetCanonicalizeUrlW (WININET.@)
2078 * Escape unsafe characters and spaces
2085 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2086 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2090 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2091 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2093 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2094 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2095 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2096 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2101 /* #################################################### */
2103 static INTERNET_STATUS_CALLBACK
set_status_callback(
2104 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2106 INTERNET_STATUS_CALLBACK ret
;
2108 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2109 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2111 ret
= lpwh
->lpfnStatusCB
;
2112 lpwh
->lpfnStatusCB
= callback
;
2117 /***********************************************************************
2118 * InternetSetStatusCallbackA (WININET.@)
2120 * Sets up a callback function which is called as progress is made
2121 * during an operation.
2124 * Previous callback or NULL on success
2125 * INTERNET_INVALID_STATUS_CALLBACK on failure
2128 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2129 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2131 INTERNET_STATUS_CALLBACK retVal
;
2132 object_header_t
*lpwh
;
2134 TRACE("%p\n", hInternet
);
2136 if (!(lpwh
= get_handle_object(hInternet
)))
2137 return INTERNET_INVALID_STATUS_CALLBACK
;
2139 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2141 WININET_Release( lpwh
);
2145 /***********************************************************************
2146 * InternetSetStatusCallbackW (WININET.@)
2148 * Sets up a callback function which is called as progress is made
2149 * during an operation.
2152 * Previous callback or NULL on success
2153 * INTERNET_INVALID_STATUS_CALLBACK on failure
2156 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2157 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2159 INTERNET_STATUS_CALLBACK retVal
;
2160 object_header_t
*lpwh
;
2162 TRACE("%p\n", hInternet
);
2164 if (!(lpwh
= get_handle_object(hInternet
)))
2165 return INTERNET_INVALID_STATUS_CALLBACK
;
2167 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2169 WININET_Release( lpwh
);
2173 /***********************************************************************
2174 * InternetSetFilePointer (WININET.@)
2176 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2177 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2179 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2183 /***********************************************************************
2184 * InternetWriteFile (WININET.@)
2186 * Write data to an open internet file
2193 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2194 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2196 object_header_t
*lpwh
;
2199 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2201 lpwh
= get_handle_object( hFile
);
2203 WARN("Invalid handle\n");
2204 SetLastError(ERROR_INVALID_HANDLE
);
2208 if(lpwh
->vtbl
->WriteFile
) {
2209 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2211 WARN("No Writefile method.\n");
2212 res
= ERROR_INVALID_HANDLE
;
2215 WININET_Release( lpwh
);
2217 if(res
!= ERROR_SUCCESS
)
2219 return res
== ERROR_SUCCESS
;
2223 /***********************************************************************
2224 * InternetReadFile (WININET.@)
2226 * Read data from an open internet file
2233 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2234 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2236 object_header_t
*hdr
;
2237 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2239 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2241 hdr
= get_handle_object(hFile
);
2243 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2247 if(hdr
->vtbl
->ReadFile
)
2248 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2250 WININET_Release(hdr
);
2252 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2253 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2255 if(res
!= ERROR_SUCCESS
)
2257 return res
== ERROR_SUCCESS
;
2260 /***********************************************************************
2261 * InternetReadFileExA (WININET.@)
2263 * Read data from an open internet file
2266 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2267 * lpBuffersOut [I/O] Buffer.
2268 * dwFlags [I] Flags. See notes.
2269 * dwContext [I] Context for callbacks.
2276 * The parameter dwFlags include zero or more of the following flags:
2277 *|IRF_ASYNC - Makes the call asynchronous.
2278 *|IRF_SYNC - Makes the call synchronous.
2279 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2280 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2282 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2285 * InternetOpenUrlA(), HttpOpenRequestA()
2287 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2288 DWORD dwFlags
, DWORD_PTR dwContext
)
2290 object_header_t
*hdr
;
2291 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2293 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2295 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2296 SetLastError(ERROR_INVALID_PARAMETER
);
2300 hdr
= get_handle_object(hFile
);
2302 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2306 if(hdr
->vtbl
->ReadFileEx
)
2307 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2308 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2310 WININET_Release(hdr
);
2312 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2313 res
, lpBuffersOut
->dwBufferLength
);
2315 if(res
!= ERROR_SUCCESS
)
2317 return res
== ERROR_SUCCESS
;
2320 /***********************************************************************
2321 * InternetReadFileExW (WININET.@)
2323 * InternetReadFileExA()
2325 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2326 DWORD dwFlags
, DWORD_PTR dwContext
)
2328 object_header_t
*hdr
;
2329 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2331 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2333 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2334 SetLastError(ERROR_INVALID_PARAMETER
);
2338 hdr
= get_handle_object(hFile
);
2340 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2344 if(hdr
->vtbl
->ReadFileEx
)
2345 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2346 dwFlags
, dwContext
);
2348 WININET_Release(hdr
);
2350 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2351 res
, lpBuffer
->dwBufferLength
);
2353 if(res
!= ERROR_SUCCESS
)
2355 return res
== ERROR_SUCCESS
;
2358 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2360 /* FIXME: This function currently handles more options than it should. Options requiring
2361 * proper handles should be moved to proper functions */
2363 case INTERNET_OPTION_HTTP_VERSION
:
2364 if (*size
< sizeof(HTTP_VERSION_INFO
))
2365 return ERROR_INSUFFICIENT_BUFFER
;
2368 * Presently hardcoded to 1.1
2370 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2371 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2372 *size
= sizeof(HTTP_VERSION_INFO
);
2374 return ERROR_SUCCESS
;
2376 case INTERNET_OPTION_CONNECTED_STATE
:
2377 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2379 if (*size
< sizeof(ULONG
))
2380 return ERROR_INSUFFICIENT_BUFFER
;
2382 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2383 *size
= sizeof(ULONG
);
2385 return ERROR_SUCCESS
;
2387 case INTERNET_OPTION_PROXY
: {
2391 TRACE("Getting global proxy info\n");
2392 memset(&ai
, 0, sizeof(appinfo_t
));
2393 INTERNET_ConfigureProxy(&ai
);
2395 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2396 APPINFO_Destroy(&ai
.hdr
);
2400 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2401 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2403 if (*size
< sizeof(ULONG
))
2404 return ERROR_INSUFFICIENT_BUFFER
;
2406 *(ULONG
*)buffer
= max_conns
;
2407 *size
= sizeof(ULONG
);
2409 return ERROR_SUCCESS
;
2411 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2412 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2414 if (*size
< sizeof(ULONG
))
2415 return ERROR_INSUFFICIENT_BUFFER
;
2417 *(ULONG
*)buffer
= max_1_0_conns
;
2418 *size
= sizeof(ULONG
);
2420 return ERROR_SUCCESS
;
2422 case INTERNET_OPTION_SECURITY_FLAGS
:
2423 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2424 return ERROR_SUCCESS
;
2426 case INTERNET_OPTION_VERSION
: {
2427 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2429 TRACE("INTERNET_OPTION_VERSION\n");
2431 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2432 return ERROR_INSUFFICIENT_BUFFER
;
2434 memcpy(buffer
, &info
, sizeof(info
));
2435 *size
= sizeof(info
);
2437 return ERROR_SUCCESS
;
2440 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2441 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2442 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2443 DWORD res
= ERROR_SUCCESS
, i
;
2447 TRACE("Getting global proxy info\n");
2448 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2451 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2453 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2455 return ERROR_INSUFFICIENT_BUFFER
;
2458 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2459 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2460 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2462 switch (optionW
->dwOption
) {
2463 case INTERNET_PER_CONN_FLAGS
:
2465 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2467 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2470 case INTERNET_PER_CONN_PROXY_SERVER
:
2472 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2474 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2477 case INTERNET_PER_CONN_PROXY_BYPASS
:
2479 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2481 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2484 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2485 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2486 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2487 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2488 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2489 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2490 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2491 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2495 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2496 res
= ERROR_INVALID_PARAMETER
;
2504 case INTERNET_OPTION_REQUEST_FLAGS
:
2505 case INTERNET_OPTION_USER_AGENT
:
2507 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2508 case INTERNET_OPTION_POLICY
:
2509 return ERROR_INVALID_PARAMETER
;
2510 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2511 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2513 if (*size
< sizeof(ULONG
))
2514 return ERROR_INSUFFICIENT_BUFFER
;
2516 *(ULONG
*)buffer
= connect_timeout
;
2517 *size
= sizeof(ULONG
);
2519 return ERROR_SUCCESS
;
2522 FIXME("Stub for %d\n", option
);
2523 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2526 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2529 case INTERNET_OPTION_CONTEXT_VALUE
:
2531 return ERROR_INVALID_PARAMETER
;
2533 if (*size
< sizeof(DWORD_PTR
)) {
2534 *size
= sizeof(DWORD_PTR
);
2535 return ERROR_INSUFFICIENT_BUFFER
;
2538 return ERROR_INVALID_PARAMETER
;
2540 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2541 *size
= sizeof(DWORD_PTR
);
2542 return ERROR_SUCCESS
;
2544 case INTERNET_OPTION_REQUEST_FLAGS
:
2545 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2546 *size
= sizeof(DWORD
);
2547 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2549 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2550 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2551 WARN("Called on global option %u\n", option
);
2552 return ERROR_INTERNET_INVALID_OPERATION
;
2555 /* FIXME: we shouldn't call it here */
2556 return query_global_option(option
, buffer
, size
, unicode
);
2559 /***********************************************************************
2560 * InternetQueryOptionW (WININET.@)
2562 * Queries an options on the specified handle
2569 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2570 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2572 object_header_t
*hdr
;
2573 DWORD res
= ERROR_INVALID_HANDLE
;
2575 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2578 hdr
= get_handle_object(hInternet
);
2580 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2581 WININET_Release(hdr
);
2584 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2587 if(res
!= ERROR_SUCCESS
)
2589 return res
== ERROR_SUCCESS
;
2592 /***********************************************************************
2593 * InternetQueryOptionA (WININET.@)
2595 * Queries an options on the specified handle
2602 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2603 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2605 object_header_t
*hdr
;
2606 DWORD res
= ERROR_INVALID_HANDLE
;
2608 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2611 hdr
= get_handle_object(hInternet
);
2613 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2614 WININET_Release(hdr
);
2617 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2620 if(res
!= ERROR_SUCCESS
)
2622 return res
== ERROR_SUCCESS
;
2625 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2628 case INTERNET_OPTION_CALLBACK
:
2629 WARN("Not settable option %u\n", option
);
2630 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2631 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2632 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2633 WARN("Called on global option %u\n", option
);
2634 return ERROR_INTERNET_INVALID_OPERATION
;
2637 return ERROR_INTERNET_INVALID_OPTION
;
2640 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2643 case INTERNET_OPTION_CALLBACK
:
2644 WARN("Not global option %u\n", option
);
2645 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2647 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2648 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2650 if(size
!= sizeof(max_conns
))
2651 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2653 return ERROR_BAD_ARGUMENTS
;
2655 max_conns
= *(ULONG
*)buf
;
2656 return ERROR_SUCCESS
;
2658 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2659 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2661 if(size
!= sizeof(max_1_0_conns
))
2662 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2664 return ERROR_BAD_ARGUMENTS
;
2666 max_1_0_conns
= *(ULONG
*)buf
;
2667 return ERROR_SUCCESS
;
2669 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2670 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2672 if(size
!= sizeof(connect_timeout
))
2673 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2675 return ERROR_BAD_ARGUMENTS
;
2677 connect_timeout
= *(ULONG
*)buf
;
2678 return ERROR_SUCCESS
;
2680 case INTERNET_OPTION_SETTINGS_CHANGED
:
2681 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2682 collect_connections(COLLECT_CONNECTIONS
);
2683 return ERROR_SUCCESS
;
2686 return ERROR_INTERNET_INVALID_OPTION
;
2689 /***********************************************************************
2690 * InternetSetOptionW (WININET.@)
2692 * Sets an options on the specified handle
2699 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2700 LPVOID lpBuffer
, DWORD dwBufferLength
)
2702 object_header_t
*lpwhh
;
2706 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2708 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2710 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2712 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2714 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2716 WININET_Release(lpwhh
);
2718 if(res
!= ERROR_SUCCESS
)
2721 return res
== ERROR_SUCCESS
;
2726 case INTERNET_OPTION_HTTP_VERSION
:
2728 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2729 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2732 case INTERNET_OPTION_ERROR_MASK
:
2735 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2737 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2738 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2739 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2740 SetLastError(ERROR_INVALID_PARAMETER
);
2742 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2743 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2746 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2747 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2750 case INTERNET_OPTION_PROXY
:
2752 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2754 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2756 SetLastError(ERROR_INVALID_PARAMETER
);
2761 EnterCriticalSection( &WININET_cs
);
2762 free_global_proxy();
2763 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2766 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2768 global_proxy
->proxyEnabled
= 1;
2769 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2770 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2774 global_proxy
->proxyEnabled
= 0;
2775 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2778 LeaveCriticalSection( &WININET_cs
);
2782 /* In general, each type of object should handle
2783 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2784 * get silently dropped.
2786 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2787 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2792 case INTERNET_OPTION_CODEPAGE
:
2794 ULONG codepage
= *(ULONG
*)lpBuffer
;
2795 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2798 case INTERNET_OPTION_REQUEST_PRIORITY
:
2800 ULONG priority
= *(ULONG
*)lpBuffer
;
2801 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2804 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2806 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2807 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2810 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2812 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2813 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2816 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2817 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2819 case INTERNET_OPTION_END_BROWSER_SESSION
:
2820 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2822 case INTERNET_OPTION_CONNECTED_STATE
:
2823 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2825 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2826 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2828 case INTERNET_OPTION_SEND_TIMEOUT
:
2829 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2830 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2832 ULONG timeout
= *(ULONG
*)lpBuffer
;
2833 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2836 case INTERNET_OPTION_CONNECT_RETRIES
:
2838 ULONG retries
= *(ULONG
*)lpBuffer
;
2839 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2842 case INTERNET_OPTION_CONTEXT_VALUE
:
2846 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2849 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2851 SetLastError(ERROR_INVALID_PARAMETER
);
2855 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2858 case INTERNET_OPTION_SECURITY_FLAGS
:
2859 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2861 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2862 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2864 case INTERNET_OPTION_HTTP_DECODING
:
2865 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2866 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2869 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2870 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2871 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2874 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2875 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2876 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2879 case INTERNET_OPTION_CODEPAGE_PATH
:
2880 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2881 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2884 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2885 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2886 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2889 case INTERNET_OPTION_IDN
:
2890 FIXME("INTERNET_OPTION_IDN; STUB\n");
2891 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2894 case INTERNET_OPTION_POLICY
:
2895 SetLastError(ERROR_INVALID_PARAMETER
);
2898 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2899 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2904 INTERNET_LoadProxySettings(&pi
);
2906 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2907 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2909 switch (option
->dwOption
) {
2910 case INTERNET_PER_CONN_PROXY_SERVER
:
2911 heap_free(pi
.proxy
);
2912 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2915 case INTERNET_PER_CONN_FLAGS
:
2916 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2917 pi
.proxyEnabled
= 1;
2920 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2921 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2922 pi
.proxyEnabled
= 0;
2926 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2927 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2928 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2929 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2930 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2931 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2932 case INTERNET_PER_CONN_PROXY_BYPASS
:
2933 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2937 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2938 SetLastError(ERROR_INVALID_PARAMETER
);
2943 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2948 ret
= (res
== ERROR_SUCCESS
);
2952 FIXME("Option %d STUB\n",dwOption
);
2953 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2959 WININET_Release( lpwhh
);
2965 /***********************************************************************
2966 * InternetSetOptionA (WININET.@)
2968 * Sets an options on the specified handle.
2975 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2976 LPVOID lpBuffer
, DWORD dwBufferLength
)
2984 case INTERNET_OPTION_PROXY
:
2986 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2987 LPINTERNET_PROXY_INFOW piw
;
2988 DWORD proxlen
, prbylen
;
2991 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2992 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2993 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2994 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2995 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2996 piw
->dwAccessType
= pi
->dwAccessType
;
2997 prox
= (LPWSTR
) &piw
[1];
2998 prby
= &prox
[proxlen
+1];
2999 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3000 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3001 piw
->lpszProxy
= prox
;
3002 piw
->lpszProxyBypass
= prby
;
3005 case INTERNET_OPTION_USER_AGENT
:
3006 case INTERNET_OPTION_USERNAME
:
3007 case INTERNET_OPTION_PASSWORD
:
3008 case INTERNET_OPTION_PROXY_USERNAME
:
3009 case INTERNET_OPTION_PROXY_PASSWORD
:
3010 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3011 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3012 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3014 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3016 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3017 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3018 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3019 wbuffer
= heap_alloc(wlen
);
3022 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3023 if (listA
->pszConnection
)
3025 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3026 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3027 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3030 listW
->pszConnection
= NULL
;
3031 listW
->dwOptionCount
= listA
->dwOptionCount
;
3032 listW
->dwOptionError
= listA
->dwOptionError
;
3033 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3035 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3036 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3037 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3039 optW
->dwOption
= optA
->dwOption
;
3041 switch (optA
->dwOption
) {
3042 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3043 case INTERNET_PER_CONN_PROXY_BYPASS
:
3044 case INTERNET_PER_CONN_PROXY_SERVER
:
3045 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3046 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3047 if (optA
->Value
.pszValue
)
3049 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3050 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3051 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3054 optW
->Value
.pszValue
= NULL
;
3056 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3057 case INTERNET_PER_CONN_FLAGS
:
3058 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3059 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3061 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3062 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3065 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3066 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3074 wlen
= dwBufferLength
;
3077 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3079 if( lpBuffer
!= wbuffer
)
3081 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3083 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3085 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3086 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3087 switch (opt
->dwOption
) {
3088 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3089 case INTERNET_PER_CONN_PROXY_BYPASS
:
3090 case INTERNET_PER_CONN_PROXY_SERVER
:
3091 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3092 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3093 heap_free( opt
->Value
.pszValue
);
3099 heap_free( list
->pOptions
);
3101 heap_free( wbuffer
);
3108 /***********************************************************************
3109 * InternetSetOptionExA (WININET.@)
3111 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3112 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3114 FIXME("Flags %08x ignored\n", dwFlags
);
3115 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3118 /***********************************************************************
3119 * InternetSetOptionExW (WININET.@)
3121 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3122 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3124 FIXME("Flags %08x ignored\n", dwFlags
);
3125 if( dwFlags
& ~ISO_VALID_FLAGS
)
3127 SetLastError( ERROR_INVALID_PARAMETER
);
3130 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3133 static const WCHAR WININET_wkday
[7][4] =
3134 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3135 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3136 static const WCHAR WININET_month
[12][4] =
3137 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3138 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3139 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3141 /***********************************************************************
3142 * InternetTimeFromSystemTimeA (WININET.@)
3144 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3147 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3149 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3151 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3153 SetLastError(ERROR_INVALID_PARAMETER
);
3157 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3159 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3163 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3164 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3169 /***********************************************************************
3170 * InternetTimeFromSystemTimeW (WININET.@)
3172 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3174 static const WCHAR date
[] =
3175 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3176 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3178 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3180 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3182 SetLastError(ERROR_INVALID_PARAMETER
);
3186 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3188 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3192 sprintfW( string
, date
,
3193 WININET_wkday
[time
->wDayOfWeek
],
3195 WININET_month
[time
->wMonth
- 1],
3204 /***********************************************************************
3205 * InternetTimeToSystemTimeA (WININET.@)
3207 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3212 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3214 stringW
= heap_strdupAtoW(string
);
3217 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3218 heap_free( stringW
);
3223 /***********************************************************************
3224 * InternetTimeToSystemTimeW (WININET.@)
3226 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3229 const WCHAR
*s
= string
;
3232 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3234 if (!string
|| !time
) return FALSE
;
3236 /* Windows does this too */
3237 GetSystemTime( time
);
3239 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3240 * a SYSTEMTIME structure.
3243 while (*s
&& !isalphaW( *s
)) s
++;
3244 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3245 time
->wDayOfWeek
= 7;
3247 for (i
= 0; i
< 7; i
++)
3249 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3250 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3251 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3253 time
->wDayOfWeek
= i
;
3258 if (time
->wDayOfWeek
> 6) return TRUE
;
3259 while (*s
&& !isdigitW( *s
)) s
++;
3260 time
->wDay
= strtolW( s
, &end
, 10 );
3263 while (*s
&& !isalphaW( *s
)) s
++;
3264 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3267 for (i
= 0; i
< 12; i
++)
3269 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3270 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3271 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3273 time
->wMonth
= i
+ 1;
3277 if (time
->wMonth
== 0) return TRUE
;
3279 while (*s
&& !isdigitW( *s
)) s
++;
3280 if (*s
== '\0') return TRUE
;
3281 time
->wYear
= strtolW( s
, &end
, 10 );
3284 while (*s
&& !isdigitW( *s
)) s
++;
3285 if (*s
== '\0') return TRUE
;
3286 time
->wHour
= strtolW( s
, &end
, 10 );
3289 while (*s
&& !isdigitW( *s
)) s
++;
3290 if (*s
== '\0') return TRUE
;
3291 time
->wMinute
= strtolW( s
, &end
, 10 );
3294 while (*s
&& !isdigitW( *s
)) s
++;
3295 if (*s
== '\0') return TRUE
;
3296 time
->wSecond
= strtolW( s
, &end
, 10 );
3299 time
->wMilliseconds
= 0;
3303 /***********************************************************************
3304 * InternetCheckConnectionW (WININET.@)
3306 * Pings a requested host to check internet connection
3309 * TRUE on success and FALSE on failure. If a failure then
3310 * ERROR_NOT_CONNECTED is placed into GetLastError
3313 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3316 * this is a kludge which runs the resident ping program and reads the output.
3318 * Anyone have a better idea?
3322 static const CHAR ping
[] = "ping -c 1 ";
3323 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3324 CHAR
*command
= NULL
;
3325 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3333 * Crack or set the Address
3335 if (lpszUrl
== NULL
)
3338 * According to the doc we are supposed to use the ip for the next
3339 * server in the WnInet internal server database. I have
3340 * no idea what that is or how to get it.
3342 * So someone needs to implement this.
3344 FIXME("Unimplemented with URL of NULL\n");
3349 URL_COMPONENTSW components
;
3351 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3352 components
.lpszHostName
= (LPWSTR
)hostW
;
3353 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3355 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3358 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3359 port
= components
.nPort
;
3360 TRACE("port: %d\n", port
);
3363 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3365 struct sockaddr_storage saddr
;
3366 socklen_t sa_len
= sizeof(saddr
);
3369 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3371 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3374 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3382 * Build our ping command
3384 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3385 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3386 strcpy(command
,ping
);
3387 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3388 strcat(command
,redirect
);
3390 TRACE("Ping command is : %s\n",command
);
3392 status
= system(command
);
3394 TRACE("Ping returned a code of %i\n",status
);
3396 /* Ping return code of 0 indicates success */
3402 heap_free( command
);
3404 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3410 /***********************************************************************
3411 * InternetCheckConnectionA (WININET.@)
3413 * Pings a requested host to check internet connection
3416 * TRUE on success and FALSE on failure. If a failure then
3417 * ERROR_NOT_CONNECTED is placed into GetLastError
3420 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3426 url
= heap_strdupAtoW(lpszUrl
);
3431 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3438 /**********************************************************
3439 * INTERNET_InternetOpenUrlW (internal)
3444 * handle of connection or NULL on failure
3446 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3447 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3449 URL_COMPONENTSW urlComponents
;
3450 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3451 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3452 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3453 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3454 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3456 HINTERNET client
= NULL
, client1
= NULL
;
3459 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3460 dwHeadersLength
, dwFlags
, dwContext
);
3462 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3463 urlComponents
.lpszScheme
= protocol
;
3464 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3465 urlComponents
.lpszHostName
= hostName
;
3466 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3467 urlComponents
.lpszUserName
= userName
;
3468 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3469 urlComponents
.lpszPassword
= password
;
3470 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3471 urlComponents
.lpszUrlPath
= path
;
3472 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3473 urlComponents
.lpszExtraInfo
= extra
;
3474 urlComponents
.dwExtraInfoLength
= 1024;
3475 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3477 switch(urlComponents
.nScheme
) {
3478 case INTERNET_SCHEME_FTP
:
3479 if(urlComponents
.nPort
== 0)
3480 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3481 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3482 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3485 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3486 if(client1
== NULL
) {
3487 InternetCloseHandle(client
);
3492 case INTERNET_SCHEME_HTTP
:
3493 case INTERNET_SCHEME_HTTPS
: {
3494 static const WCHAR szStars
[] = { '*','/','*', 0 };
3495 LPCWSTR accept
[2] = { szStars
, NULL
};
3496 if(urlComponents
.nPort
== 0) {
3497 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3498 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3500 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3502 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3504 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3505 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3506 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3507 if(res
!= ERROR_SUCCESS
) {
3508 INTERNET_SetLastError(res
);
3512 if (urlComponents
.dwExtraInfoLength
) {
3514 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3516 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3518 InternetCloseHandle(client
);
3521 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3522 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3523 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3524 heap_free(path_extra
);
3527 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3529 if(client1
== NULL
) {
3530 InternetCloseHandle(client
);
3533 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3534 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3535 GetLastError() != ERROR_IO_PENDING
) {
3536 InternetCloseHandle(client1
);
3541 case INTERNET_SCHEME_GOPHER
:
3542 /* gopher doesn't seem to be implemented in wine, but it's supposed
3543 * to be supported by InternetOpenUrlA. */
3545 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3549 TRACE(" %p <--\n", client1
);
3554 /**********************************************************
3555 * InternetOpenUrlW (WININET.@)
3560 * handle of connection or NULL on failure
3571 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3573 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3575 TRACE("%p\n", task
->hdr
.hdr
);
3577 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3578 task
->headers_len
, task
->flags
, task
->context
);
3579 heap_free(task
->url
);
3580 heap_free(task
->headers
);
3583 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3584 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3586 HINTERNET ret
= NULL
;
3587 appinfo_t
*hIC
= NULL
;
3589 if (TRACE_ON(wininet
)) {
3590 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3591 dwHeadersLength
, dwFlags
, dwContext
);
3593 dump_INTERNET_FLAGS(dwFlags
);
3598 SetLastError(ERROR_INVALID_PARAMETER
);
3602 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3603 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3604 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3608 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3609 open_url_task_t
*task
;
3611 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3612 task
->url
= heap_strdupW(lpszUrl
);
3613 task
->headers
= heap_strdupW(lpszHeaders
);
3614 task
->headers_len
= dwHeadersLength
;
3615 task
->flags
= dwFlags
;
3616 task
->context
= dwContext
;
3618 INTERNET_AsyncCall(&task
->hdr
);
3619 SetLastError(ERROR_IO_PENDING
);
3621 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3626 WININET_Release( &hIC
->hdr
);
3627 TRACE(" %p <--\n", ret
);
3632 /**********************************************************
3633 * InternetOpenUrlA (WININET.@)
3638 * handle of connection or NULL on failure
3640 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3641 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3643 HINTERNET rc
= NULL
;
3644 DWORD lenHeaders
= 0;
3645 LPWSTR szUrl
= NULL
;
3646 LPWSTR szHeaders
= NULL
;
3651 szUrl
= heap_strdupAtoW(lpszUrl
);
3657 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3658 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3663 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3666 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3667 lenHeaders
, dwFlags
, dwContext
);
3670 heap_free(szHeaders
);
3675 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3677 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3681 lpwite
->dwError
= 0;
3682 lpwite
->response
[0] = '\0';
3685 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3694 /***********************************************************************
3695 * INTERNET_SetLastError (internal)
3697 * Set last thread specific error
3702 void INTERNET_SetLastError(DWORD dwError
)
3704 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3707 lpwite
= INTERNET_AllocThreadError();
3709 SetLastError(dwError
);
3711 lpwite
->dwError
= dwError
;
3715 /***********************************************************************
3716 * INTERNET_GetLastError (internal)
3718 * Get last thread specific error
3723 DWORD
INTERNET_GetLastError(void)
3725 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3726 if (!lpwite
) return 0;
3727 /* TlsGetValue clears last error, so set it again here */
3728 SetLastError(lpwite
->dwError
);
3729 return lpwite
->dwError
;
3733 /***********************************************************************
3734 * INTERNET_WorkerThreadFunc (internal)
3736 * Worker thread execution function
3741 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3743 task_header_t
*task
= lpvParam
;
3748 WININET_Release(task
->hdr
);
3751 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3753 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3754 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3759 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3761 task_header_t
*task
;
3763 task
= heap_alloc(size
);
3767 task
->hdr
= WININET_AddRef(hdr
);
3772 /***********************************************************************
3773 * INTERNET_AsyncCall (internal)
3775 * Retrieves work request from queue
3780 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3786 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3790 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3792 return ERROR_SUCCESS
;
3796 /***********************************************************************
3797 * INTERNET_GetResponseBuffer (internal)
3802 LPSTR
INTERNET_GetResponseBuffer(void)
3804 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3806 lpwite
= INTERNET_AllocThreadError();
3808 return lpwite
->response
;
3811 /***********************************************************************
3812 * INTERNET_GetNextLine (internal)
3814 * Parse next line in directory string listing
3817 * Pointer to beginning of next line
3822 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3824 // ReactOS: use select instead of poll
3827 BOOL bSuccess
= FALSE
;
3829 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3834 FD_SET(nSocket
,&infd
);
3835 tv
.tv_sec
= RESPONSE_TIMEOUT
;
3838 while (nRecv
< MAX_REPLY_LEN
)
3840 if (select(0, &infd
, NULL
, NULL
, &tv
) > 0)
3842 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3844 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3848 if (lpszBuffer
[nRecv
] == '\n')
3853 if (lpszBuffer
[nRecv
] != '\r')
3858 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3866 lpszBuffer
[nRecv
] = '\0';
3868 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3877 /**********************************************************
3878 * InternetQueryDataAvailable (WININET.@)
3880 * Determines how much data is available to be read.
3883 * TRUE on success, FALSE if an error occurred. If
3884 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3885 * no data is presently available, FALSE is returned with
3886 * the last error ERROR_IO_PENDING; a callback with status
3887 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3888 * data is available.
3890 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3891 LPDWORD lpdwNumberOfBytesAvailable
,
3892 DWORD dwFlags
, DWORD_PTR dwContext
)
3894 object_header_t
*hdr
;
3897 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3899 hdr
= get_handle_object( hFile
);
3901 SetLastError(ERROR_INVALID_HANDLE
);
3905 if(hdr
->vtbl
->QueryDataAvailable
) {
3906 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3908 WARN("wrong handle\n");
3909 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3912 WININET_Release(hdr
);
3914 if(res
!= ERROR_SUCCESS
)
3916 return res
== ERROR_SUCCESS
;
3920 /***********************************************************************
3921 * InternetLockRequestFile (WININET.@)
3923 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3930 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3937 /***********************************************************************
3938 * InternetAutodial (WININET.@)
3940 * On windows this function is supposed to dial the default internet
3941 * connection. We don't want to have Wine dial out to the internet so
3942 * we return TRUE by default. It might be nice to check if we are connected.
3949 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3953 /* Tell that we are connected to the internet. */
3957 /***********************************************************************
3958 * InternetAutodialHangup (WININET.@)
3960 * Hangs up a connection made with InternetAutodial
3969 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3973 /* we didn't dial, we don't disconnect */
3977 /***********************************************************************
3978 * InternetCombineUrlA (WININET.@)
3980 * Combine a base URL with a relative URL
3988 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3989 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3994 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3996 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3997 dwFlags
^= ICU_NO_ENCODE
;
3998 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4003 /***********************************************************************
4004 * InternetCombineUrlW (WININET.@)
4006 * Combine a base URL with a relative URL
4014 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
4015 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
4020 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
4022 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4023 dwFlags
^= ICU_NO_ENCODE
;
4024 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
4029 /* max port num is 65535 => 5 digits */
4030 #define MAX_WORD_DIGITS 5
4032 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4033 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4034 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4035 (url)->dw##component##Length : strlen((url)->lpsz##component))
4037 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
4039 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
4040 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
4042 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
4043 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
4045 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
4046 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
4048 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4049 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4052 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4058 /* opaque urls do not fit into the standard url hierarchy and don't have
4059 * two following slashes */
4060 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4062 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4063 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4064 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4065 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4066 (nScheme
!= INTERNET_SCHEME_FILE
);
4069 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4072 if (scheme
< INTERNET_SCHEME_FIRST
)
4074 index
= scheme
- INTERNET_SCHEME_FIRST
;
4075 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4077 return (LPCWSTR
)url_schemes
[index
];
4080 /* we can calculate using ansi strings because we're just
4081 * calculating string length, not size
4083 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4084 LPDWORD lpdwUrlLength
)
4086 INTERNET_SCHEME nScheme
;
4090 if (lpUrlComponents
->lpszScheme
)
4092 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4093 *lpdwUrlLength
+= dwLen
;
4094 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4100 nScheme
= lpUrlComponents
->nScheme
;
4102 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4103 nScheme
= INTERNET_SCHEME_HTTP
;
4104 scheme
= INTERNET_GetSchemeString(nScheme
);
4105 *lpdwUrlLength
+= strlenW(scheme
);
4108 (*lpdwUrlLength
)++; /* ':' */
4109 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4110 *lpdwUrlLength
+= strlen("//");
4112 if (lpUrlComponents
->lpszUserName
)
4114 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4115 *lpdwUrlLength
+= strlen("@");
4119 if (lpUrlComponents
->lpszPassword
)
4121 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4126 if (lpUrlComponents
->lpszPassword
)
4128 *lpdwUrlLength
+= strlen(":");
4129 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4132 if (lpUrlComponents
->lpszHostName
)
4134 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4136 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4138 char szPort
[MAX_WORD_DIGITS
+1];
4140 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4141 *lpdwUrlLength
+= strlen(szPort
);
4142 *lpdwUrlLength
+= strlen(":");
4145 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4146 (*lpdwUrlLength
)++; /* '/' */
4149 if (lpUrlComponents
->lpszUrlPath
)
4150 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4152 if (lpUrlComponents
->lpszExtraInfo
)
4153 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4158 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4162 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4164 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4165 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4166 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4167 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4168 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4169 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4170 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4171 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4172 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4174 if (lpUrlComponents
->lpszScheme
)
4176 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4177 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4178 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4179 -1, urlCompW
->lpszScheme
, len
);
4182 if (lpUrlComponents
->lpszHostName
)
4184 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4185 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4186 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4187 -1, urlCompW
->lpszHostName
, len
);
4190 if (lpUrlComponents
->lpszUserName
)
4192 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4193 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4194 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4195 -1, urlCompW
->lpszUserName
, len
);
4198 if (lpUrlComponents
->lpszPassword
)
4200 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4201 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4202 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4203 -1, urlCompW
->lpszPassword
, len
);
4206 if (lpUrlComponents
->lpszUrlPath
)
4208 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4209 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4210 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4211 -1, urlCompW
->lpszUrlPath
, len
);
4214 if (lpUrlComponents
->lpszExtraInfo
)
4216 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4217 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4218 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4219 -1, urlCompW
->lpszExtraInfo
, len
);
4223 /***********************************************************************
4224 * InternetCreateUrlA (WININET.@)
4226 * See InternetCreateUrlW.
4228 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4229 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4233 URL_COMPONENTSW urlCompW
;
4235 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4237 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4239 SetLastError(ERROR_INVALID_PARAMETER
);
4243 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4246 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4248 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4250 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4251 *lpdwUrlLength
/= sizeof(WCHAR
);
4253 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4254 * minus one, so add one to leave room for NULL terminator
4257 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4259 heap_free(urlCompW
.lpszScheme
);
4260 heap_free(urlCompW
.lpszHostName
);
4261 heap_free(urlCompW
.lpszUserName
);
4262 heap_free(urlCompW
.lpszPassword
);
4263 heap_free(urlCompW
.lpszUrlPath
);
4264 heap_free(urlCompW
.lpszExtraInfo
);
4269 /***********************************************************************
4270 * InternetCreateUrlW (WININET.@)
4272 * Creates a URL from its component parts.
4275 * lpUrlComponents [I] URL Components.
4276 * dwFlags [I] Flags. See notes.
4277 * lpszUrl [I] Buffer in which to store the created URL.
4278 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4279 * lpszUrl in characters. On output, the number of bytes
4280 * required to store the URL including terminator.
4284 * The dwFlags parameter can be zero or more of the following:
4285 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4292 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4293 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4296 INTERNET_SCHEME nScheme
;
4298 static const WCHAR slashSlashW
[] = {'/','/'};
4299 static const WCHAR fmtW
[] = {'%','u',0};
4301 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4303 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4305 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4309 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4312 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4314 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4315 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4319 *lpdwUrlLength
= dwLen
;
4324 if (lpUrlComponents
->lpszScheme
)
4326 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4327 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4330 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4335 nScheme
= lpUrlComponents
->nScheme
;
4337 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4338 nScheme
= INTERNET_SCHEME_HTTP
;
4340 scheme
= INTERNET_GetSchemeString(nScheme
);
4341 dwLen
= strlenW(scheme
);
4342 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4346 /* all schemes are followed by at least a colon */
4350 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4352 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4353 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4356 if (lpUrlComponents
->lpszUserName
)
4358 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4359 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4362 if (lpUrlComponents
->lpszPassword
)
4367 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4368 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4376 if (lpUrlComponents
->lpszHostName
)
4378 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4379 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4382 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4384 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4386 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4389 dwLen
= strlenW(szPort
);
4390 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4394 /* add slash between hostname and path if necessary */
4395 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4402 if (lpUrlComponents
->lpszUrlPath
)
4404 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4405 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4409 if (lpUrlComponents
->lpszExtraInfo
)
4411 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4412 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4421 /***********************************************************************
4422 * InternetConfirmZoneCrossingA (WININET.@)
4425 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4427 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4428 return ERROR_SUCCESS
;
4431 /***********************************************************************
4432 * InternetConfirmZoneCrossingW (WININET.@)
4435 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4437 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4438 return ERROR_SUCCESS
;
4441 static DWORD zone_preference
= 3;
4443 /***********************************************************************
4444 * PrivacySetZonePreferenceW (WININET.@)
4446 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4448 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4450 zone_preference
= template;
4454 /***********************************************************************
4455 * PrivacyGetZonePreferenceW (WININET.@)
4457 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4458 LPWSTR preference
, LPDWORD length
)
4460 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4462 if (template) *template = zone_preference
;
4466 /***********************************************************************
4467 * InternetGetSecurityInfoByURLA (WININET.@)
4469 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4474 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4476 url
= heap_strdupAtoW(lpszURL
);
4480 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4485 /***********************************************************************
4486 * InternetGetSecurityInfoByURLW (WININET.@)
4488 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4490 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4491 URL_COMPONENTSW url
= {sizeof(url
)};
4495 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4497 url
.lpszHostName
= hostname
;
4498 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4500 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4501 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4502 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4506 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4508 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4512 if(server
->cert_chain
) {
4513 const CERT_CHAIN_CONTEXT
*chain_dup
;
4515 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4517 *ppCertChain
= chain_dup
;
4518 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4523 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4527 server_release(server
);
4531 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4532 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4534 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4535 lpdwConnection
, dwReserved
);
4536 return ERROR_SUCCESS
;
4539 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4540 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4542 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4543 lpdwConnection
, dwReserved
);
4544 return ERROR_SUCCESS
;
4547 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4549 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4553 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4555 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4559 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4561 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4562 return ERROR_SUCCESS
;
4565 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4568 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4569 debugstr_w(pwszTarget
), pbHexHash
);
4573 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4575 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4579 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4581 FIXME("(%p, %08lx) stub\n", a
, b
);
4585 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4587 FIXME("%p: stub\n", parent
);