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;
117 static const WCHAR szInternetSettings
[] =
118 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
119 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
120 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
121 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
122 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
124 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
126 UINT_PTR handle
= 0, num
;
127 object_header_t
*ret
;
131 ret
= heap_alloc_zero(size
);
135 list_init(&ret
->children
);
137 EnterCriticalSection( &WININET_cs
);
139 if(!handle_table_size
) {
141 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
144 handle_table_size
= num
;
149 }else if(next_handle
== handle_table_size
) {
150 num
= handle_table_size
* 2;
151 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
154 handle_table_size
= num
;
161 handle
= next_handle
;
162 if(handle_table
[handle
])
163 ERR("handle isn't free but should be\n");
164 handle_table
[handle
] = ret
;
165 ret
->valid_handle
= TRUE
;
167 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
171 LeaveCriticalSection( &WININET_cs
);
180 ret
->hInternet
= (HINTERNET
)handle
;
183 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
184 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
190 object_header_t
*WININET_AddRef( object_header_t
*info
)
192 ULONG refs
= InterlockedIncrement(&info
->refs
);
193 TRACE("%p -> refcount = %d\n", info
, refs
);
197 object_header_t
*get_handle_object( HINTERNET hinternet
)
199 object_header_t
*info
= NULL
;
200 UINT_PTR handle
= (UINT_PTR
) hinternet
;
202 EnterCriticalSection( &WININET_cs
);
204 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
205 info
= WININET_AddRef(handle_table
[handle
]);
207 LeaveCriticalSection( &WININET_cs
);
209 TRACE("handle %ld -> %p\n", handle
, info
);
214 static void invalidate_handle(object_header_t
*info
)
216 object_header_t
*child
, *next
;
218 if(!info
->valid_handle
)
220 info
->valid_handle
= FALSE
;
222 /* Free all children as native does */
223 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
225 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
226 invalidate_handle( child
);
229 WININET_Release(info
);
232 BOOL
WININET_Release( object_header_t
*info
)
234 ULONG refs
= InterlockedDecrement(&info
->refs
);
235 TRACE( "object %p refcount = %d\n", info
, refs
);
238 invalidate_handle(info
);
239 if ( info
->vtbl
->CloseConnection
)
241 TRACE( "closing connection %p\n", info
);
242 info
->vtbl
->CloseConnection( info
);
244 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
245 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
246 || !(info
->dwInternalFlags
& INET_OPENURL
))
248 INTERNET_SendCallback(info
, info
->dwContext
,
249 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
252 TRACE( "destroying object %p\n", info
);
253 if ( info
->htype
!= WH_HINIT
)
254 list_remove( &info
->entry
);
255 info
->vtbl
->Destroy( info
);
257 if(info
->hInternet
) {
258 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
260 EnterCriticalSection( &WININET_cs
);
262 handle_table
[handle
] = NULL
;
263 if(next_handle
> handle
)
264 next_handle
= handle
;
266 LeaveCriticalSection( &WININET_cs
);
274 /***********************************************************************
275 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
278 * hinstDLL [I] handle to the DLL's instance
280 * lpvReserved [I] reserved, must be NULL
287 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
289 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
292 case DLL_PROCESS_ATTACH
:
294 g_dwTlsErrIndex
= TlsAlloc();
296 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
300 URLCacheContainers_CreateDefaults();
303 WININET_hModule
= hinstDLL
;
306 case DLL_THREAD_ATTACH
:
309 case DLL_THREAD_DETACH
:
310 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
312 heap_free(TlsGetValue(g_dwTlsErrIndex
));
316 case DLL_PROCESS_DETACH
:
317 collect_connections(TRUE
);
319 URLCacheContainers_DeleteAll();
321 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
323 heap_free(TlsGetValue(g_dwTlsErrIndex
));
324 TlsFree(g_dwTlsErrIndex
);
331 /***********************************************************************
332 * INTERNET_SaveProxySettings
334 * Stores the proxy settings given by lpwai into the registry
337 * ERROR_SUCCESS if no error, or error code on fail
339 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
344 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
347 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
355 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
363 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
371 return ERROR_SUCCESS
;
374 /***********************************************************************
375 * INTERNET_FindProxyForProtocol
377 * Searches the proxy string for a proxy of the given protocol.
378 * Returns the found proxy, or the default proxy if none of the given
382 * szProxy [In] proxy string to search
383 * proto [In] protocol to search for, e.g. "http"
384 * foundProxy [Out] found proxy
385 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
388 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
389 * *foundProxyLen is set to the required size in WCHARs, including the
390 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
392 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
397 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
399 /* First, look for the specified protocol (proto=scheme://host:port) */
400 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
404 if (!(end
= strchrW(ptr
, ' ')))
405 end
= ptr
+ strlenW(ptr
);
406 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
407 equal
- ptr
== strlenW(proto
) &&
408 !strncmpiW(proto
, ptr
, strlenW(proto
)))
410 if (end
- equal
> *foundProxyLen
)
412 WARN("buffer too short for %s\n",
413 debugstr_wn(equal
+ 1, end
- equal
- 1));
414 *foundProxyLen
= end
- equal
;
415 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
419 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
420 foundProxy
[end
- equal
] = 0;
431 /* It wasn't found: look for no protocol */
432 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
436 if (!(end
= strchrW(ptr
, ' ')))
437 end
= ptr
+ strlenW(ptr
);
438 if (!(equal
= strchrW(ptr
, '=')))
440 if (end
- ptr
+ 1 > *foundProxyLen
)
442 WARN("buffer too short for %s\n",
443 debugstr_wn(ptr
, end
- ptr
));
444 *foundProxyLen
= end
- ptr
+ 1;
445 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
449 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
450 foundProxy
[end
- ptr
] = 0;
461 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
462 debugstr_w(foundProxy
));
466 /***********************************************************************
467 * InternetInitializeAutoProxyDll (WININET.@)
469 * Setup the internal proxy
478 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
481 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
485 /***********************************************************************
486 * DetectAutoProxyUrl (WININET.@)
488 * Auto detect the proxy url
494 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
495 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
498 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
502 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
504 heap_free(lpwpi
->proxy
);
505 heap_free(lpwpi
->proxyBypass
);
508 static proxyinfo_t
*global_proxy
;
510 static void free_global_proxy( void )
512 EnterCriticalSection( &WININET_cs
);
515 FreeProxyInfo( global_proxy
);
516 heap_free( global_proxy
);
518 LeaveCriticalSection( &WININET_cs
);
521 /***********************************************************************
522 * INTERNET_LoadProxySettings
524 * Loads proxy information from process-wide global settings, the registry,
525 * or the environment into lpwpi.
527 * The caller should call FreeProxyInfo when done with lpwpi.
530 * The proxy may be specified in the form 'http=proxy.my.org'
531 * Presumably that means there can be ftp=ftpproxy.my.org too.
533 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
540 EnterCriticalSection( &WININET_cs
);
543 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
544 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
545 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
547 LeaveCriticalSection( &WININET_cs
);
549 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
553 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
555 lpwpi
->proxyEnabled
= 0;
556 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
563 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
565 TRACE("Proxy is enabled.\n");
567 /* figure out how much memory the proxy setting takes */
568 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
571 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
573 if (!(szProxy
= heap_alloc(len
)))
576 return ERROR_OUTOFMEMORY
;
578 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
580 /* find the http proxy, and strip away everything else */
581 p
= strstrW( szProxy
, szHttp
);
584 p
+= lstrlenW( szHttp
);
585 lstrcpyW( szProxy
, p
);
587 p
= strchrW( szProxy
, ' ' );
590 lpwpi
->proxy
= szProxy
;
592 TRACE("http proxy = %s\n", debugstr_w(lpwpi
->proxy
));
596 TRACE("No proxy server settings in registry.\n");
604 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
605 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
606 return ERROR_OUTOFMEMORY
;
607 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
609 lpwpi
->proxyEnabled
= 1;
610 lpwpi
->proxy
= envproxyW
;
612 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
616 lpwpi
->proxyBypass
= NULL
;
618 return ERROR_SUCCESS
;
621 /***********************************************************************
622 * INTERNET_ConfigureProxy
624 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
628 if (INTERNET_LoadProxySettings( &wpi
))
631 if (wpi
.proxyEnabled
)
633 WCHAR proxyurl
[INTERNET_MAX_URL_LENGTH
];
634 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
];
635 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
636 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
637 URL_COMPONENTSW UrlComponents
;
639 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
640 UrlComponents
.dwSchemeLength
= 0;
641 UrlComponents
.lpszHostName
= hostname
;
642 UrlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
643 UrlComponents
.lpszUserName
= username
;
644 UrlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
645 UrlComponents
.lpszPassword
= password
;
646 UrlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
647 UrlComponents
.dwUrlPathLength
= 0;
648 UrlComponents
.dwExtraInfoLength
= 0;
650 if(InternetCrackUrlW(wpi
.proxy
, 0, 0, &UrlComponents
))
652 static const WCHAR szFormat
[] = { 'h','t','t','p',':','/','/','%','s',':','%','u',0 };
654 if(UrlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
655 UrlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
656 sprintfW(proxyurl
, szFormat
, hostname
, UrlComponents
.nPort
);
658 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
659 lpwai
->proxy
= heap_strdupW(proxyurl
);
660 if (UrlComponents
.dwUserNameLength
)
662 lpwai
->proxyUsername
= heap_strdupW(UrlComponents
.lpszUserName
);
663 lpwai
->proxyPassword
= heap_strdupW(UrlComponents
.lpszPassword
);
666 TRACE("http proxy = %s\n", debugstr_w(lpwai
->proxy
));
671 TRACE("Failed to parse proxy: %s\n", debugstr_w(wpi
.proxy
));
676 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
680 /***********************************************************************
681 * dump_INTERNET_FLAGS
683 * Helper function to TRACE the internet flags.
689 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
691 #define FE(x) { x, #x }
692 static const wininet_flag_info flag
[] = {
693 FE(INTERNET_FLAG_RELOAD
),
694 FE(INTERNET_FLAG_RAW_DATA
),
695 FE(INTERNET_FLAG_EXISTING_CONNECT
),
696 FE(INTERNET_FLAG_ASYNC
),
697 FE(INTERNET_FLAG_PASSIVE
),
698 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
699 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
700 FE(INTERNET_FLAG_FROM_CACHE
),
701 FE(INTERNET_FLAG_SECURE
),
702 FE(INTERNET_FLAG_KEEP_CONNECTION
),
703 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
704 FE(INTERNET_FLAG_READ_PREFETCH
),
705 FE(INTERNET_FLAG_NO_COOKIES
),
706 FE(INTERNET_FLAG_NO_AUTH
),
707 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
708 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
709 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
710 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
711 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
712 FE(INTERNET_FLAG_RESYNCHRONIZE
),
713 FE(INTERNET_FLAG_HYPERLINK
),
714 FE(INTERNET_FLAG_NO_UI
),
715 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
716 FE(INTERNET_FLAG_CACHE_ASYNC
),
717 FE(INTERNET_FLAG_FORMS_SUBMIT
),
718 FE(INTERNET_FLAG_NEED_FILE
),
719 FE(INTERNET_FLAG_TRANSFER_ASCII
),
720 FE(INTERNET_FLAG_TRANSFER_BINARY
)
725 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
726 if (flag
[i
].val
& dwFlags
) {
727 TRACE(" %s", flag
[i
].name
);
728 dwFlags
&= ~flag
[i
].val
;
732 TRACE(" Unknown flags (%08x)\n", dwFlags
);
737 /***********************************************************************
738 * INTERNET_CloseHandle (internal)
740 * Close internet handle
743 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
745 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
749 heap_free(lpwai
->agent
);
750 heap_free(lpwai
->proxy
);
751 heap_free(lpwai
->proxyBypass
);
752 heap_free(lpwai
->proxyUsername
);
753 heap_free(lpwai
->proxyPassword
);
759 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
761 appinfo_t
*ai
= (appinfo_t
*)hdr
;
764 case INTERNET_OPTION_HANDLE_TYPE
:
765 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
767 if (*size
< sizeof(ULONG
))
768 return ERROR_INSUFFICIENT_BUFFER
;
770 *size
= sizeof(DWORD
);
771 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
772 return ERROR_SUCCESS
;
774 case INTERNET_OPTION_USER_AGENT
: {
777 TRACE("INTERNET_OPTION_USER_AGENT\n");
782 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
784 *size
= (len
+ 1) * sizeof(WCHAR
);
785 if(!buffer
|| bufsize
< *size
)
786 return ERROR_INSUFFICIENT_BUFFER
;
789 strcpyW(buffer
, ai
->agent
);
791 *(WCHAR
*)buffer
= 0;
792 /* If the buffer is copied, the returned length doesn't include
793 * the NULL terminator.
795 *size
= len
* sizeof(WCHAR
);
798 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
801 if(!buffer
|| bufsize
< *size
)
802 return ERROR_INSUFFICIENT_BUFFER
;
805 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
808 /* If the buffer is copied, the returned length doesn't include
809 * the NULL terminator.
814 return ERROR_SUCCESS
;
817 case INTERNET_OPTION_PROXY
:
818 if(!size
) return ERROR_INVALID_PARAMETER
;
820 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
821 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
822 LPWSTR proxy
, proxy_bypass
;
825 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
827 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
828 if (*size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
830 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
831 return ERROR_INSUFFICIENT_BUFFER
;
833 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
834 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
836 pi
->dwAccessType
= ai
->accessType
;
837 pi
->lpszProxy
= NULL
;
838 pi
->lpszProxyBypass
= NULL
;
840 lstrcpyW(proxy
, ai
->proxy
);
841 pi
->lpszProxy
= proxy
;
844 if (ai
->proxyBypass
) {
845 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
846 pi
->lpszProxyBypass
= proxy_bypass
;
849 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
850 return ERROR_SUCCESS
;
852 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
853 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
854 LPSTR proxy
, proxy_bypass
;
857 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
859 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
860 NULL
, 0, NULL
, NULL
);
861 if (*size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
863 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
864 return ERROR_INSUFFICIENT_BUFFER
;
866 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
867 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
869 pi
->dwAccessType
= ai
->accessType
;
870 pi
->lpszProxy
= NULL
;
871 pi
->lpszProxyBypass
= NULL
;
873 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
874 pi
->lpszProxy
= proxy
;
877 if (ai
->proxyBypass
) {
878 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
879 proxyBypassBytesRequired
, NULL
, NULL
);
880 pi
->lpszProxyBypass
= proxy_bypass
;
883 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
884 return ERROR_SUCCESS
;
888 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
891 static const object_vtbl_t APPINFOVtbl
= {
904 /***********************************************************************
905 * InternetOpenW (WININET.@)
907 * Per-application initialization of wininet
910 * HINTERNET on success
914 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
915 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
917 appinfo_t
*lpwai
= NULL
;
920 int error
= WSAStartup(MAKEWORD(2, 2), &wsaData
);
921 if (error
) ERR("WSAStartup failed: %d\n", error
);
924 if (TRACE_ON(wininet
)) {
925 #define FE(x) { x, #x }
926 static const wininet_flag_info access_type
[] = {
927 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
928 FE(INTERNET_OPEN_TYPE_DIRECT
),
929 FE(INTERNET_OPEN_TYPE_PROXY
),
930 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
934 const char *access_type_str
= "Unknown";
936 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
937 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
938 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
939 if (access_type
[i
].val
== dwAccessType
) {
940 access_type_str
= access_type
[i
].name
;
944 TRACE(" access type : %s\n", access_type_str
);
946 dump_INTERNET_FLAGS(dwFlags
);
949 /* Clear any error information */
950 INTERNET_SetLastError(0);
952 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
954 SetLastError(ERROR_OUTOFMEMORY
);
958 lpwai
->hdr
.htype
= WH_HINIT
;
959 lpwai
->hdr
.dwFlags
= dwFlags
;
960 lpwai
->accessType
= dwAccessType
;
961 lpwai
->proxyUsername
= NULL
;
962 lpwai
->proxyPassword
= NULL
;
964 lpwai
->agent
= heap_strdupW(lpszAgent
);
965 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
966 INTERNET_ConfigureProxy( lpwai
);
968 lpwai
->proxy
= heap_strdupW(lpszProxy
);
969 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
971 TRACE("returning %p\n", lpwai
);
973 return lpwai
->hdr
.hInternet
;
977 /***********************************************************************
978 * InternetOpenA (WININET.@)
980 * Per-application initialization of wininet
983 * HINTERNET on success
987 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
988 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
990 WCHAR
*szAgent
, *szProxy
, *szBypass
;
993 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
994 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
996 szAgent
= heap_strdupAtoW(lpszAgent
);
997 szProxy
= heap_strdupAtoW(lpszProxy
);
998 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1000 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1004 heap_free(szBypass
);
1008 /***********************************************************************
1009 * InternetGetLastResponseInfoA (WININET.@)
1011 * Return last wininet error description on the calling thread
1014 * TRUE on success of writing to buffer
1018 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1019 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1021 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1027 *lpdwError
= lpwite
->dwError
;
1028 if (lpwite
->dwError
)
1030 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1031 *lpdwBufferLength
= strlen(lpszBuffer
);
1034 *lpdwBufferLength
= 0;
1039 *lpdwBufferLength
= 0;
1045 /***********************************************************************
1046 * InternetGetLastResponseInfoW (WININET.@)
1048 * Return last wininet error description on the calling thread
1051 * TRUE on success of writing to buffer
1055 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1056 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1058 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1064 *lpdwError
= lpwite
->dwError
;
1065 if (lpwite
->dwError
)
1067 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1068 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1071 *lpdwBufferLength
= 0;
1076 *lpdwBufferLength
= 0;
1082 /***********************************************************************
1083 * InternetGetConnectedState (WININET.@)
1085 * Return connected state
1089 * if lpdwStatus is not null, return the status (off line,
1090 * modem, lan...) in it.
1091 * FALSE if not connected
1093 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1095 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1098 WARN("always returning LAN connection.\n");
1099 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1105 /***********************************************************************
1106 * InternetGetConnectedStateExW (WININET.@)
1108 * Return connected state
1112 * lpdwStatus [O] Flags specifying the status of the internet connection.
1113 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1114 * dwNameLen [I] Size of the buffer, in characters.
1115 * dwReserved [I] Reserved. Must be set to 0.
1119 * if lpdwStatus is not null, return the status (off line,
1120 * modem, lan...) in it.
1121 * FALSE if not connected
1124 * If the system has no available network connections, an empty string is
1125 * stored in lpszConnectionName. If there is a LAN connection, a localized
1126 * "LAN Connection" string is stored. Presumably, if only a dial-up
1127 * connection is available then the name of the dial-up connection is
1128 * returned. Why any application, other than the "Internet Settings" CPL,
1129 * would want to use this function instead of the simpler InternetGetConnectedStateW
1130 * function is beyond me.
1132 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1133 DWORD dwNameLen
, DWORD dwReserved
)
1135 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1142 WARN("always returning LAN connection.\n");
1143 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1145 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1149 /***********************************************************************
1150 * InternetGetConnectedStateExA (WININET.@)
1152 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1153 DWORD dwNameLen
, DWORD dwReserved
)
1155 LPWSTR lpwszConnectionName
= NULL
;
1158 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1160 if (lpszConnectionName
&& dwNameLen
> 0)
1161 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1163 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1165 if (rc
&& lpwszConnectionName
)
1167 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1168 dwNameLen
, NULL
, NULL
);
1169 heap_free(lpwszConnectionName
);
1175 /***********************************************************************
1176 * InternetConnectW (WININET.@)
1178 * Open a ftp, gopher or http session
1181 * HINTERNET a session handle on success
1185 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1186 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1187 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1188 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1191 HINTERNET rc
= NULL
;
1192 DWORD res
= ERROR_SUCCESS
;
1194 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1195 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1196 dwService
, dwFlags
, dwContext
);
1198 if (!lpszServerName
)
1200 SetLastError(ERROR_INVALID_PARAMETER
);
1204 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1205 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1207 res
= ERROR_INVALID_HANDLE
;
1213 case INTERNET_SERVICE_FTP
:
1214 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1215 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1217 res
= INTERNET_GetLastError();
1220 case INTERNET_SERVICE_HTTP
:
1221 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1222 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1225 case INTERNET_SERVICE_GOPHER
:
1231 WININET_Release( &hIC
->hdr
);
1233 TRACE("returning %p\n", rc
);
1239 /***********************************************************************
1240 * InternetConnectA (WININET.@)
1242 * Open a ftp, gopher or http session
1245 * HINTERNET a session handle on success
1249 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1250 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1251 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1252 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1254 HINTERNET rc
= NULL
;
1255 LPWSTR szServerName
;
1259 szServerName
= heap_strdupAtoW(lpszServerName
);
1260 szUserName
= heap_strdupAtoW(lpszUserName
);
1261 szPassword
= heap_strdupAtoW(lpszPassword
);
1263 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1264 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1266 heap_free(szServerName
);
1267 heap_free(szUserName
);
1268 heap_free(szPassword
);
1273 /***********************************************************************
1274 * InternetFindNextFileA (WININET.@)
1276 * Continues a file search from a previous call to FindFirstFile
1283 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1286 WIN32_FIND_DATAW fd
;
1288 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1290 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1294 /***********************************************************************
1295 * InternetFindNextFileW (WININET.@)
1297 * Continues a file search from a previous call to FindFirstFile
1304 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1306 object_header_t
*hdr
;
1311 hdr
= get_handle_object(hFind
);
1313 WARN("Invalid handle\n");
1314 SetLastError(ERROR_INVALID_HANDLE
);
1318 if(hdr
->vtbl
->FindNextFileW
) {
1319 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1321 WARN("Handle doesn't support NextFile\n");
1322 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1325 WININET_Release(hdr
);
1327 if(res
!= ERROR_SUCCESS
)
1329 return res
== ERROR_SUCCESS
;
1332 /***********************************************************************
1333 * InternetCloseHandle (WININET.@)
1335 * Generic close handle function
1342 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1344 object_header_t
*obj
;
1346 TRACE("%p\n", hInternet
);
1348 obj
= get_handle_object( hInternet
);
1350 SetLastError(ERROR_INVALID_HANDLE
);
1354 invalidate_handle(obj
);
1355 WININET_Release(obj
);
1361 /***********************************************************************
1362 * ConvertUrlComponentValue (Internal)
1364 * Helper function for InternetCrackUrlA
1367 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1368 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1369 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1371 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1372 if (*dwComponentLen
!= 0)
1374 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1375 if (*lppszComponent
== NULL
)
1379 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1380 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1383 *lppszComponent
= NULL
;
1385 *dwComponentLen
= nASCIILength
;
1389 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1390 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1391 (*lppszComponent
)[ncpylen
]=0;
1392 *dwComponentLen
= ncpylen
;
1398 /***********************************************************************
1399 * InternetCrackUrlA (WININET.@)
1401 * See InternetCrackUrlW.
1403 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1404 LPURL_COMPONENTSA lpUrlComponents
)
1407 URL_COMPONENTSW UCW
;
1409 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1410 *scheme
= NULL
, *extra
= NULL
;
1412 TRACE("(%s %u %x %p)\n",
1413 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1414 dwUrlLength
, dwFlags
, lpUrlComponents
);
1416 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1417 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1419 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1425 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1427 /* if dwUrlLength=-1 then nLength includes null but length to
1428 InternetCrackUrlW should not include it */
1429 if (dwUrlLength
== -1) nLength
--;
1431 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1432 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1433 lpwszUrl
[nLength
] = '\0';
1435 memset(&UCW
,0,sizeof(UCW
));
1436 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1437 if (lpUrlComponents
->dwHostNameLength
)
1439 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1440 if (lpUrlComponents
->lpszHostName
)
1442 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1443 UCW
.lpszHostName
= hostname
;
1446 if (lpUrlComponents
->dwUserNameLength
)
1448 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1449 if (lpUrlComponents
->lpszUserName
)
1451 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1452 UCW
.lpszUserName
= username
;
1455 if (lpUrlComponents
->dwPasswordLength
)
1457 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1458 if (lpUrlComponents
->lpszPassword
)
1460 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1461 UCW
.lpszPassword
= password
;
1464 if (lpUrlComponents
->dwUrlPathLength
)
1466 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1467 if (lpUrlComponents
->lpszUrlPath
)
1469 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1470 UCW
.lpszUrlPath
= path
;
1473 if (lpUrlComponents
->dwSchemeLength
)
1475 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1476 if (lpUrlComponents
->lpszScheme
)
1478 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1479 UCW
.lpszScheme
= scheme
;
1482 if (lpUrlComponents
->dwExtraInfoLength
)
1484 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1485 if (lpUrlComponents
->lpszExtraInfo
)
1487 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1488 UCW
.lpszExtraInfo
= extra
;
1491 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1493 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1494 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1495 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1496 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1497 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1498 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1499 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1500 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1501 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1502 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1503 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1504 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1506 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1507 lpUrlComponents
->nPort
= UCW
.nPort
;
1509 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1510 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1511 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1512 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1513 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1515 heap_free(lpwszUrl
);
1516 heap_free(hostname
);
1517 heap_free(username
);
1518 heap_free(password
);
1525 static const WCHAR url_schemes
[][7] =
1528 {'g','o','p','h','e','r',0},
1529 {'h','t','t','p',0},
1530 {'h','t','t','p','s',0},
1531 {'f','i','l','e',0},
1532 {'n','e','w','s',0},
1533 {'m','a','i','l','t','o',0},
1537 /***********************************************************************
1538 * GetInternetSchemeW (internal)
1544 * INTERNET_SCHEME_UNKNOWN on failure
1547 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1551 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1553 if(lpszScheme
==NULL
)
1554 return INTERNET_SCHEME_UNKNOWN
;
1556 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1557 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1558 return INTERNET_SCHEME_FIRST
+ i
;
1560 return INTERNET_SCHEME_UNKNOWN
;
1563 /***********************************************************************
1564 * SetUrlComponentValueW (Internal)
1566 * Helper function for InternetCrackUrlW
1569 * lppszComponent [O] Holds the returned string
1570 * dwComponentLen [I] Holds the size of lppszComponent
1571 * [O] Holds the length of the string in lppszComponent without '\0'
1572 * lpszStart [I] Holds the string to copy from
1573 * len [I] Holds the length of lpszStart without '\0'
1580 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1582 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1584 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1587 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1589 if (*lppszComponent
== NULL
)
1591 *lppszComponent
= (LPWSTR
)lpszStart
;
1592 *dwComponentLen
= len
;
1596 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1597 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1598 (*lppszComponent
)[ncpylen
] = '\0';
1599 *dwComponentLen
= ncpylen
;
1606 /***********************************************************************
1607 * InternetCrackUrlW (WININET.@)
1609 * Break up URL into its components
1615 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1616 LPURL_COMPONENTSW lpUC
)
1620 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1623 LPCWSTR lpszParam
= NULL
;
1624 BOOL bIsAbsolute
= FALSE
;
1625 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1626 LPCWSTR lpszcp
= NULL
;
1627 LPWSTR lpszUrl_decode
= NULL
;
1628 DWORD dwUrlLength
= dwUrlLength_orig
;
1630 TRACE("(%s %u %x %p)\n",
1631 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1632 dwUrlLength
, dwFlags
, lpUC
);
1634 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1636 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1639 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1641 if (dwFlags
& ICU_DECODE
)
1644 DWORD len
= dwUrlLength
+ 1;
1646 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1648 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1651 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1652 url_tmp
[dwUrlLength
] = 0;
1653 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1656 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1659 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1662 lpszUrl
= lpszUrl_decode
;
1668 /* Determine if the URI is absolute. */
1669 while (lpszap
- lpszUrl
< dwUrlLength
)
1671 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1676 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1683 lpszcp
= lpszUrl
; /* Relative url */
1689 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1690 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1692 /* Parse <params> */
1693 lpszParam
= memchrW(lpszap
, ';', dwUrlLength
- (lpszap
- lpszUrl
));
1695 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1697 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1699 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1700 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1702 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1706 /* Get scheme first. */
1707 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1708 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1709 lpszUrl
, lpszcp
- lpszUrl
);
1711 /* Eat ':' in protocol. */
1714 /* double slash indicates the net_loc portion is present */
1715 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1719 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1723 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1725 lpszNetLoc
= lpszParam
;
1727 else if (!lpszNetLoc
)
1728 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1736 /* [<user>[<:password>]@]<host>[:<port>] */
1737 /* First find the user and password if they exist */
1739 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1740 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1742 /* username and password not specified. */
1743 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1744 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1746 else /* Parse out username and password */
1748 LPCWSTR lpszUser
= lpszcp
;
1749 LPCWSTR lpszPasswd
= lpszHost
;
1751 while (lpszcp
< lpszHost
)
1754 lpszPasswd
= lpszcp
;
1759 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1760 lpszUser
, lpszPasswd
- lpszUser
);
1762 if (lpszPasswd
!= lpszHost
)
1764 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1765 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1766 lpszHost
- lpszPasswd
);
1768 lpszcp
++; /* Advance to beginning of host */
1771 /* Parse <host><:port> */
1774 lpszPort
= lpszNetLoc
;
1776 /* special case for res:// URLs: there is no port here, so the host is the
1777 entire string up to the first '/' */
1778 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1780 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1781 lpszHost
, lpszPort
- lpszHost
);
1786 while (lpszcp
< lpszNetLoc
)
1794 /* If the scheme is "file" and the host is just one letter, it's not a host */
1795 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1798 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1803 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1804 lpszHost
, lpszPort
- lpszHost
);
1805 if (lpszPort
!= lpszNetLoc
)
1806 lpUC
->nPort
= atoiW(++lpszPort
);
1807 else switch (lpUC
->nScheme
)
1809 case INTERNET_SCHEME_HTTP
:
1810 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1812 case INTERNET_SCHEME_HTTPS
:
1813 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1815 case INTERNET_SCHEME_FTP
:
1816 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1818 case INTERNET_SCHEME_GOPHER
:
1819 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1830 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1831 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1832 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1837 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1838 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1839 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1840 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1843 /* Here lpszcp points to:
1845 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1846 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1848 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1852 /* Only truncate the parameter list if it's already been saved
1853 * in lpUC->lpszExtraInfo.
1855 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1856 len
= lpszParam
- lpszcp
;
1859 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1860 * newlines if necessary.
1862 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1863 if (lpsznewline
!= NULL
)
1864 len
= lpsznewline
- lpszcp
;
1866 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1868 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1869 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1871 WCHAR tmppath
[MAX_PATH
];
1875 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1880 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1881 tmppath
[len
] = '\0';
1890 /* if ends in \. or \.. append a backslash */
1891 if (tmppath
[len
- 1] == '.' &&
1892 (tmppath
[len
- 2] == '\\' ||
1893 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1895 if (len
< MAX_PATH
- 1)
1897 tmppath
[len
] = '\\';
1898 tmppath
[len
+1] = '\0';
1902 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1906 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1911 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1912 lpUC
->lpszUrlPath
[0] = 0;
1913 lpUC
->dwUrlPathLength
= 0;
1916 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1917 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1918 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1919 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1920 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1922 heap_free( lpszUrl_decode
);
1926 /***********************************************************************
1927 * InternetAttemptConnect (WININET.@)
1929 * Attempt to make a connection to the internet
1932 * ERROR_SUCCESS on success
1933 * Error value on failure
1936 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1939 return ERROR_SUCCESS
;
1943 /***********************************************************************
1944 * InternetCanonicalizeUrlA (WININET.@)
1946 * Escape unsafe characters and spaces
1953 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1954 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1957 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1959 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1960 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1962 if(dwFlags
& ICU_DECODE
)
1964 dwURLFlags
|= URL_UNESCAPE
;
1965 dwFlags
&= ~ICU_DECODE
;
1968 if(dwFlags
& ICU_ESCAPE
)
1970 dwURLFlags
|= URL_UNESCAPE
;
1971 dwFlags
&= ~ICU_ESCAPE
;
1974 if(dwFlags
& ICU_BROWSER_MODE
)
1976 dwURLFlags
|= URL_BROWSER_MODE
;
1977 dwFlags
&= ~ICU_BROWSER_MODE
;
1980 if(dwFlags
& ICU_NO_ENCODE
)
1982 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1983 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1984 dwFlags
&= ~ICU_NO_ENCODE
;
1987 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1989 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1990 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1991 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1993 return (hr
== S_OK
) ? TRUE
: FALSE
;
1996 /***********************************************************************
1997 * InternetCanonicalizeUrlW (WININET.@)
1999 * Escape unsafe characters and spaces
2006 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2007 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2010 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2012 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2013 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2015 if(dwFlags
& ICU_DECODE
)
2017 dwURLFlags
|= URL_UNESCAPE
;
2018 dwFlags
&= ~ICU_DECODE
;
2021 if(dwFlags
& ICU_ESCAPE
)
2023 dwURLFlags
|= URL_UNESCAPE
;
2024 dwFlags
&= ~ICU_ESCAPE
;
2027 if(dwFlags
& ICU_BROWSER_MODE
)
2029 dwURLFlags
|= URL_BROWSER_MODE
;
2030 dwFlags
&= ~ICU_BROWSER_MODE
;
2033 if(dwFlags
& ICU_NO_ENCODE
)
2035 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2036 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
2037 dwFlags
&= ~ICU_NO_ENCODE
;
2040 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
2042 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
2043 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2044 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2046 return (hr
== S_OK
) ? TRUE
: FALSE
;
2049 /* #################################################### */
2051 static INTERNET_STATUS_CALLBACK
set_status_callback(
2052 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2054 INTERNET_STATUS_CALLBACK ret
;
2056 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2057 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2059 ret
= lpwh
->lpfnStatusCB
;
2060 lpwh
->lpfnStatusCB
= callback
;
2065 /***********************************************************************
2066 * InternetSetStatusCallbackA (WININET.@)
2068 * Sets up a callback function which is called as progress is made
2069 * during an operation.
2072 * Previous callback or NULL on success
2073 * INTERNET_INVALID_STATUS_CALLBACK on failure
2076 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2077 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2079 INTERNET_STATUS_CALLBACK retVal
;
2080 object_header_t
*lpwh
;
2082 TRACE("%p\n", hInternet
);
2084 if (!(lpwh
= get_handle_object(hInternet
)))
2085 return INTERNET_INVALID_STATUS_CALLBACK
;
2087 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2089 WININET_Release( lpwh
);
2093 /***********************************************************************
2094 * InternetSetStatusCallbackW (WININET.@)
2096 * Sets up a callback function which is called as progress is made
2097 * during an operation.
2100 * Previous callback or NULL on success
2101 * INTERNET_INVALID_STATUS_CALLBACK on failure
2104 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2105 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2107 INTERNET_STATUS_CALLBACK retVal
;
2108 object_header_t
*lpwh
;
2110 TRACE("%p\n", hInternet
);
2112 if (!(lpwh
= get_handle_object(hInternet
)))
2113 return INTERNET_INVALID_STATUS_CALLBACK
;
2115 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2117 WININET_Release( lpwh
);
2121 /***********************************************************************
2122 * InternetSetFilePointer (WININET.@)
2124 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2125 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2127 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2131 /***********************************************************************
2132 * InternetWriteFile (WININET.@)
2134 * Write data to an open internet file
2141 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2142 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2144 object_header_t
*lpwh
;
2147 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2149 lpwh
= get_handle_object( hFile
);
2151 WARN("Invalid handle\n");
2152 SetLastError(ERROR_INVALID_HANDLE
);
2156 if(lpwh
->vtbl
->WriteFile
) {
2157 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2159 WARN("No Writefile method.\n");
2160 res
= ERROR_INVALID_HANDLE
;
2163 WININET_Release( lpwh
);
2165 if(res
!= ERROR_SUCCESS
)
2167 return res
== ERROR_SUCCESS
;
2171 /***********************************************************************
2172 * InternetReadFile (WININET.@)
2174 * Read data from an open internet file
2181 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2182 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2184 object_header_t
*hdr
;
2185 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2187 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2189 hdr
= get_handle_object(hFile
);
2191 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2195 if(hdr
->vtbl
->ReadFile
)
2196 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2198 WININET_Release(hdr
);
2200 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2201 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2203 if(res
!= ERROR_SUCCESS
)
2205 return res
== ERROR_SUCCESS
;
2208 /***********************************************************************
2209 * InternetReadFileExA (WININET.@)
2211 * Read data from an open internet file
2214 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2215 * lpBuffersOut [I/O] Buffer.
2216 * dwFlags [I] Flags. See notes.
2217 * dwContext [I] Context for callbacks.
2224 * The parameter dwFlags include zero or more of the following flags:
2225 *|IRF_ASYNC - Makes the call asynchronous.
2226 *|IRF_SYNC - Makes the call synchronous.
2227 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2228 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2230 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2233 * InternetOpenUrlA(), HttpOpenRequestA()
2235 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2236 DWORD dwFlags
, DWORD_PTR dwContext
)
2238 object_header_t
*hdr
;
2239 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2241 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2243 hdr
= get_handle_object(hFile
);
2245 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2249 if(hdr
->vtbl
->ReadFileExA
)
2250 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
2252 WININET_Release(hdr
);
2254 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2255 res
, lpBuffersOut
->dwBufferLength
);
2257 if(res
!= ERROR_SUCCESS
)
2259 return res
== ERROR_SUCCESS
;
2262 /***********************************************************************
2263 * InternetReadFileExW (WININET.@)
2265 * InternetReadFileExA()
2267 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2268 DWORD dwFlags
, DWORD_PTR dwContext
)
2270 object_header_t
*hdr
;
2271 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2273 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2275 hdr
= get_handle_object(hFile
);
2277 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2281 if(hdr
->vtbl
->ReadFileExW
)
2282 res
= hdr
->vtbl
->ReadFileExW(hdr
, lpBuffer
, dwFlags
, dwContext
);
2284 WININET_Release(hdr
);
2286 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2287 res
, lpBuffer
->dwBufferLength
);
2289 if(res
!= ERROR_SUCCESS
)
2291 return res
== ERROR_SUCCESS
;
2294 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2296 /* FIXME: This function currently handles more options than it should. Options requiring
2297 * proper handles should be moved to proper functions */
2299 case INTERNET_OPTION_REQUEST_FLAGS
:
2300 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2302 if (*size
< sizeof(ULONG
))
2303 return ERROR_INSUFFICIENT_BUFFER
;
2305 *(ULONG
*)buffer
= 4;
2306 *size
= sizeof(ULONG
);
2308 return ERROR_SUCCESS
;
2310 case INTERNET_OPTION_HTTP_VERSION
:
2311 if (*size
< sizeof(HTTP_VERSION_INFO
))
2312 return ERROR_INSUFFICIENT_BUFFER
;
2315 * Presently hardcoded to 1.1
2317 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2318 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2319 *size
= sizeof(HTTP_VERSION_INFO
);
2321 return ERROR_SUCCESS
;
2323 case INTERNET_OPTION_CONNECTED_STATE
:
2324 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2326 if (*size
< sizeof(ULONG
))
2327 return ERROR_INSUFFICIENT_BUFFER
;
2329 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2330 *size
= sizeof(ULONG
);
2332 return ERROR_SUCCESS
;
2334 case INTERNET_OPTION_PROXY
: {
2338 TRACE("Getting global proxy info\n");
2339 memset(&ai
, 0, sizeof(appinfo_t
));
2340 INTERNET_ConfigureProxy(&ai
);
2342 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2343 APPINFO_Destroy(&ai
.hdr
);
2347 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2348 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2350 if (*size
< sizeof(ULONG
))
2351 return ERROR_INSUFFICIENT_BUFFER
;
2353 *(ULONG
*)buffer
= max_conns
;
2354 *size
= sizeof(ULONG
);
2356 return ERROR_SUCCESS
;
2358 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2359 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2361 if (*size
< sizeof(ULONG
))
2362 return ERROR_INSUFFICIENT_BUFFER
;
2364 *(ULONG
*)buffer
= max_1_0_conns
;
2365 *size
= sizeof(ULONG
);
2367 return ERROR_SUCCESS
;
2369 case INTERNET_OPTION_SECURITY_FLAGS
:
2370 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2371 return ERROR_SUCCESS
;
2373 case INTERNET_OPTION_VERSION
: {
2374 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2376 TRACE("INTERNET_OPTION_VERSION\n");
2378 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2379 return ERROR_INSUFFICIENT_BUFFER
;
2381 memcpy(buffer
, &info
, sizeof(info
));
2382 *size
= sizeof(info
);
2384 return ERROR_SUCCESS
;
2387 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2388 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2389 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2390 DWORD res
= ERROR_SUCCESS
, i
;
2394 TRACE("Getting global proxy info\n");
2395 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2398 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2400 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2402 return ERROR_INSUFFICIENT_BUFFER
;
2405 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2406 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2407 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2409 switch (optionW
->dwOption
) {
2410 case INTERNET_PER_CONN_FLAGS
:
2412 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2414 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2417 case INTERNET_PER_CONN_PROXY_SERVER
:
2419 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2421 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2424 case INTERNET_PER_CONN_PROXY_BYPASS
:
2426 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2428 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2431 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2432 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2433 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2434 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2435 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2436 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2437 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2438 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2442 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2443 res
= ERROR_INVALID_PARAMETER
;
2451 case INTERNET_OPTION_USER_AGENT
:
2452 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2453 case INTERNET_OPTION_POLICY
:
2454 return ERROR_INVALID_PARAMETER
;
2457 FIXME("Stub for %d\n", option
);
2458 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2461 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2464 case INTERNET_OPTION_CONTEXT_VALUE
:
2466 return ERROR_INVALID_PARAMETER
;
2468 if (*size
< sizeof(DWORD_PTR
)) {
2469 *size
= sizeof(DWORD_PTR
);
2470 return ERROR_INSUFFICIENT_BUFFER
;
2473 return ERROR_INVALID_PARAMETER
;
2475 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2476 *size
= sizeof(DWORD_PTR
);
2477 return ERROR_SUCCESS
;
2479 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2480 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2481 WARN("Called on global option %u\n", option
);
2482 return ERROR_INTERNET_INVALID_OPERATION
;
2485 /* FIXME: we shouldn't call it here */
2486 return query_global_option(option
, buffer
, size
, unicode
);
2489 /***********************************************************************
2490 * InternetQueryOptionW (WININET.@)
2492 * Queries an options on the specified handle
2499 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2500 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2502 object_header_t
*hdr
;
2503 DWORD res
= ERROR_INVALID_HANDLE
;
2505 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2508 hdr
= get_handle_object(hInternet
);
2510 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2511 WININET_Release(hdr
);
2514 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2517 if(res
!= ERROR_SUCCESS
)
2519 return res
== ERROR_SUCCESS
;
2522 /***********************************************************************
2523 * InternetQueryOptionA (WININET.@)
2525 * Queries an options on the specified handle
2532 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2533 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2535 object_header_t
*hdr
;
2536 DWORD res
= ERROR_INVALID_HANDLE
;
2538 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2541 hdr
= get_handle_object(hInternet
);
2543 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2544 WININET_Release(hdr
);
2547 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2550 if(res
!= ERROR_SUCCESS
)
2552 return res
== ERROR_SUCCESS
;
2555 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2558 case INTERNET_OPTION_CALLBACK
:
2559 WARN("Not settable option %u\n", option
);
2560 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2561 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2562 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2563 WARN("Called on global option %u\n", option
);
2564 return ERROR_INTERNET_INVALID_OPERATION
;
2567 return ERROR_INTERNET_INVALID_OPTION
;
2570 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2573 case INTERNET_OPTION_CALLBACK
:
2574 WARN("Not global option %u\n", option
);
2575 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2577 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2578 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2580 if(size
!= sizeof(max_conns
))
2581 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2583 return ERROR_BAD_ARGUMENTS
;
2585 max_conns
= *(ULONG
*)buf
;
2586 return ERROR_SUCCESS
;
2588 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2589 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2591 if(size
!= sizeof(max_1_0_conns
))
2592 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2594 return ERROR_BAD_ARGUMENTS
;
2596 max_1_0_conns
= *(ULONG
*)buf
;
2597 return ERROR_SUCCESS
;
2600 return ERROR_INTERNET_INVALID_OPTION
;
2603 /***********************************************************************
2604 * InternetSetOptionW (WININET.@)
2606 * Sets an options on the specified handle
2613 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2614 LPVOID lpBuffer
, DWORD dwBufferLength
)
2616 object_header_t
*lpwhh
;
2620 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2622 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2624 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2626 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2628 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2630 WININET_Release(lpwhh
);
2632 if(res
!= ERROR_SUCCESS
)
2635 return res
== ERROR_SUCCESS
;
2640 case INTERNET_OPTION_HTTP_VERSION
:
2642 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2643 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2646 case INTERNET_OPTION_ERROR_MASK
:
2649 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2651 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2652 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2653 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2654 SetLastError(ERROR_INVALID_PARAMETER
);
2656 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2657 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2660 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2663 case INTERNET_OPTION_PROXY
:
2665 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2667 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2669 SetLastError(ERROR_INVALID_PARAMETER
);
2674 EnterCriticalSection( &WININET_cs
);
2675 free_global_proxy();
2676 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2679 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2681 global_proxy
->proxyEnabled
= 1;
2682 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2683 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2687 global_proxy
->proxyEnabled
= 0;
2688 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2691 LeaveCriticalSection( &WININET_cs
);
2695 /* In general, each type of object should handle
2696 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2697 * get silently dropped.
2699 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2700 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2705 case INTERNET_OPTION_CODEPAGE
:
2707 ULONG codepage
= *(ULONG
*)lpBuffer
;
2708 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2711 case INTERNET_OPTION_REQUEST_PRIORITY
:
2713 ULONG priority
= *(ULONG
*)lpBuffer
;
2714 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2717 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2719 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2720 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2723 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2725 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2726 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2729 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2730 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2732 case INTERNET_OPTION_END_BROWSER_SESSION
:
2733 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2735 case INTERNET_OPTION_CONNECTED_STATE
:
2736 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2738 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2739 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2741 case INTERNET_OPTION_SEND_TIMEOUT
:
2742 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2743 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2745 ULONG timeout
= *(ULONG
*)lpBuffer
;
2746 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2749 case INTERNET_OPTION_CONNECT_RETRIES
:
2751 ULONG retries
= *(ULONG
*)lpBuffer
;
2752 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2755 case INTERNET_OPTION_CONTEXT_VALUE
:
2759 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2762 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2764 SetLastError(ERROR_INVALID_PARAMETER
);
2768 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2771 case INTERNET_OPTION_SECURITY_FLAGS
:
2772 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2774 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2775 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2777 case INTERNET_OPTION_HTTP_DECODING
:
2778 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2779 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2782 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2783 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2784 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2787 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2788 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2789 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2792 case INTERNET_OPTION_CODEPAGE_PATH
:
2793 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2794 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2797 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2798 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2799 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2802 case INTERNET_OPTION_IDN
:
2803 FIXME("INTERNET_OPTION_IDN; STUB\n");
2804 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2807 case INTERNET_OPTION_POLICY
:
2808 SetLastError(ERROR_INVALID_PARAMETER
);
2811 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2812 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2817 INTERNET_LoadProxySettings(&pi
);
2819 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2820 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2822 switch (option
->dwOption
) {
2823 case INTERNET_PER_CONN_PROXY_SERVER
:
2824 heap_free(pi
.proxy
);
2825 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2828 case INTERNET_PER_CONN_FLAGS
:
2829 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2830 pi
.proxyEnabled
= 1;
2833 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2834 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2835 pi
.proxyEnabled
= 0;
2839 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2840 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2841 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2842 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2843 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2844 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2845 case INTERNET_PER_CONN_PROXY_BYPASS
:
2846 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2850 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2851 SetLastError(ERROR_INVALID_PARAMETER
);
2856 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2861 ret
= (res
== ERROR_SUCCESS
);
2865 FIXME("Option %d STUB\n",dwOption
);
2866 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2872 WININET_Release( lpwhh
);
2878 /***********************************************************************
2879 * InternetSetOptionA (WININET.@)
2881 * Sets an options on the specified handle.
2888 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2889 LPVOID lpBuffer
, DWORD dwBufferLength
)
2897 case INTERNET_OPTION_PROXY
:
2899 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2900 LPINTERNET_PROXY_INFOW piw
;
2901 DWORD proxlen
, prbylen
;
2904 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2905 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2906 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2907 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2908 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2909 piw
->dwAccessType
= pi
->dwAccessType
;
2910 prox
= (LPWSTR
) &piw
[1];
2911 prby
= &prox
[proxlen
+1];
2912 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2913 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2914 piw
->lpszProxy
= prox
;
2915 piw
->lpszProxyBypass
= prby
;
2918 case INTERNET_OPTION_USER_AGENT
:
2919 case INTERNET_OPTION_USERNAME
:
2920 case INTERNET_OPTION_PASSWORD
:
2921 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2923 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2924 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2927 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2929 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
2930 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
2931 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2932 wbuffer
= heap_alloc(wlen
);
2935 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2936 if (listA
->pszConnection
)
2938 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
2939 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
2940 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
2943 listW
->pszConnection
= NULL
;
2944 listW
->dwOptionCount
= listA
->dwOptionCount
;
2945 listW
->dwOptionError
= listA
->dwOptionError
;
2946 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
2948 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
2949 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
2950 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
2952 optW
->dwOption
= optA
->dwOption
;
2954 switch (optA
->dwOption
) {
2955 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2956 case INTERNET_PER_CONN_PROXY_BYPASS
:
2957 case INTERNET_PER_CONN_PROXY_SERVER
:
2958 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2959 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2960 if (optA
->Value
.pszValue
)
2962 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
2963 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
2964 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
2967 optW
->Value
.pszValue
= NULL
;
2969 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2970 case INTERNET_PER_CONN_FLAGS
:
2971 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2972 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
2974 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2975 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
2978 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
2979 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
2987 wlen
= dwBufferLength
;
2990 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2992 if( lpBuffer
!= wbuffer
)
2994 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
2996 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
2998 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
2999 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3000 switch (opt
->dwOption
) {
3001 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3002 case INTERNET_PER_CONN_PROXY_BYPASS
:
3003 case INTERNET_PER_CONN_PROXY_SERVER
:
3004 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3005 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3006 heap_free( opt
->Value
.pszValue
);
3012 heap_free( list
->pOptions
);
3014 heap_free( wbuffer
);
3021 /***********************************************************************
3022 * InternetSetOptionExA (WININET.@)
3024 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3025 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3027 FIXME("Flags %08x ignored\n", dwFlags
);
3028 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3031 /***********************************************************************
3032 * InternetSetOptionExW (WININET.@)
3034 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3035 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3037 FIXME("Flags %08x ignored\n", dwFlags
);
3038 if( dwFlags
& ~ISO_VALID_FLAGS
)
3040 SetLastError( ERROR_INVALID_PARAMETER
);
3043 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3046 static const WCHAR WININET_wkday
[7][4] =
3047 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3048 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3049 static const WCHAR WININET_month
[12][4] =
3050 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3051 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3052 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3054 /***********************************************************************
3055 * InternetTimeFromSystemTimeA (WININET.@)
3057 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3060 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3062 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3064 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3066 SetLastError(ERROR_INVALID_PARAMETER
);
3070 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3072 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3076 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3077 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3082 /***********************************************************************
3083 * InternetTimeFromSystemTimeW (WININET.@)
3085 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3087 static const WCHAR date
[] =
3088 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3089 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3091 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3093 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3095 SetLastError(ERROR_INVALID_PARAMETER
);
3099 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3101 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3105 sprintfW( string
, date
,
3106 WININET_wkday
[time
->wDayOfWeek
],
3108 WININET_month
[time
->wMonth
- 1],
3117 /***********************************************************************
3118 * InternetTimeToSystemTimeA (WININET.@)
3120 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3125 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3127 stringW
= heap_strdupAtoW(string
);
3130 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3131 heap_free( stringW
);
3136 /***********************************************************************
3137 * InternetTimeToSystemTimeW (WININET.@)
3139 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3142 const WCHAR
*s
= string
;
3145 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3147 if (!string
|| !time
) return FALSE
;
3149 /* Windows does this too */
3150 GetSystemTime( time
);
3152 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3153 * a SYSTEMTIME structure.
3156 while (*s
&& !isalphaW( *s
)) s
++;
3157 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3158 time
->wDayOfWeek
= 7;
3160 for (i
= 0; i
< 7; i
++)
3162 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3163 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3164 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3166 time
->wDayOfWeek
= i
;
3171 if (time
->wDayOfWeek
> 6) return TRUE
;
3172 while (*s
&& !isdigitW( *s
)) s
++;
3173 time
->wDay
= strtolW( s
, &end
, 10 );
3176 while (*s
&& !isalphaW( *s
)) s
++;
3177 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3180 for (i
= 0; i
< 12; i
++)
3182 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3183 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3184 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3186 time
->wMonth
= i
+ 1;
3190 if (time
->wMonth
== 0) return TRUE
;
3192 while (*s
&& !isdigitW( *s
)) s
++;
3193 if (*s
== '\0') return TRUE
;
3194 time
->wYear
= strtolW( s
, &end
, 10 );
3197 while (*s
&& !isdigitW( *s
)) s
++;
3198 if (*s
== '\0') return TRUE
;
3199 time
->wHour
= strtolW( s
, &end
, 10 );
3202 while (*s
&& !isdigitW( *s
)) s
++;
3203 if (*s
== '\0') return TRUE
;
3204 time
->wMinute
= strtolW( s
, &end
, 10 );
3207 while (*s
&& !isdigitW( *s
)) s
++;
3208 if (*s
== '\0') return TRUE
;
3209 time
->wSecond
= strtolW( s
, &end
, 10 );
3212 time
->wMilliseconds
= 0;
3216 /***********************************************************************
3217 * InternetCheckConnectionW (WININET.@)
3219 * Pings a requested host to check internet connection
3222 * TRUE on success and FALSE on failure. If a failure then
3223 * ERROR_NOT_CONNECTED is placed into GetLastError
3226 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3229 * this is a kludge which runs the resident ping program and reads the output.
3231 * Anyone have a better idea?
3235 static const CHAR ping
[] = "ping -c 1 ";
3236 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3237 CHAR
*command
= NULL
;
3238 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3246 * Crack or set the Address
3248 if (lpszUrl
== NULL
)
3251 * According to the doc we are supposed to use the ip for the next
3252 * server in the WnInet internal server database. I have
3253 * no idea what that is or how to get it.
3255 * So someone needs to implement this.
3257 FIXME("Unimplemented with URL of NULL\n");
3262 URL_COMPONENTSW components
;
3264 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3265 components
.lpszHostName
= (LPWSTR
)hostW
;
3266 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3268 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3271 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3272 port
= components
.nPort
;
3273 TRACE("port: %d\n", port
);
3276 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3278 struct sockaddr_storage saddr
;
3279 socklen_t sa_len
= sizeof(saddr
);
3282 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3284 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3287 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3295 * Build our ping command
3297 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3298 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3299 strcpy(command
,ping
);
3300 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3301 strcat(command
,redirect
);
3303 TRACE("Ping command is : %s\n",command
);
3305 status
= system(command
);
3307 TRACE("Ping returned a code of %i\n",status
);
3309 /* Ping return code of 0 indicates success */
3315 heap_free( command
);
3317 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3323 /***********************************************************************
3324 * InternetCheckConnectionA (WININET.@)
3326 * Pings a requested host to check internet connection
3329 * TRUE on success and FALSE on failure. If a failure then
3330 * ERROR_NOT_CONNECTED is placed into GetLastError
3333 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3339 url
= heap_strdupAtoW(lpszUrl
);
3344 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3351 /**********************************************************
3352 * INTERNET_InternetOpenUrlW (internal)
3357 * handle of connection or NULL on failure
3359 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3360 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3362 URL_COMPONENTSW urlComponents
;
3363 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3364 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3365 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3366 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3367 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3369 HINTERNET client
= NULL
, client1
= NULL
;
3372 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3373 dwHeadersLength
, dwFlags
, dwContext
);
3375 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3376 urlComponents
.lpszScheme
= protocol
;
3377 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3378 urlComponents
.lpszHostName
= hostName
;
3379 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3380 urlComponents
.lpszUserName
= userName
;
3381 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3382 urlComponents
.lpszPassword
= password
;
3383 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3384 urlComponents
.lpszUrlPath
= path
;
3385 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3386 urlComponents
.lpszExtraInfo
= extra
;
3387 urlComponents
.dwExtraInfoLength
= 1024;
3388 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3390 switch(urlComponents
.nScheme
) {
3391 case INTERNET_SCHEME_FTP
:
3392 if(urlComponents
.nPort
== 0)
3393 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3394 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3395 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3398 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3399 if(client1
== NULL
) {
3400 InternetCloseHandle(client
);
3405 case INTERNET_SCHEME_HTTP
:
3406 case INTERNET_SCHEME_HTTPS
: {
3407 static const WCHAR szStars
[] = { '*','/','*', 0 };
3408 LPCWSTR accept
[2] = { szStars
, NULL
};
3409 if(urlComponents
.nPort
== 0) {
3410 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3411 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3413 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3415 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3417 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3418 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3419 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3420 if(res
!= ERROR_SUCCESS
) {
3421 INTERNET_SetLastError(res
);
3425 if (urlComponents
.dwExtraInfoLength
) {
3427 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3429 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3431 InternetCloseHandle(client
);
3434 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3435 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3436 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3437 heap_free(path_extra
);
3440 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3442 if(client1
== NULL
) {
3443 InternetCloseHandle(client
);
3446 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3447 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3448 GetLastError() != ERROR_IO_PENDING
) {
3449 InternetCloseHandle(client1
);
3454 case INTERNET_SCHEME_GOPHER
:
3455 /* gopher doesn't seem to be implemented in wine, but it's supposed
3456 * to be supported by InternetOpenUrlA. */
3458 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3462 TRACE(" %p <--\n", client1
);
3467 /**********************************************************
3468 * InternetOpenUrlW (WININET.@)
3473 * handle of connection or NULL on failure
3475 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3477 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3478 appinfo_t
*hIC
= (appinfo_t
*) workRequest
->hdr
;
3482 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3483 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3484 heap_free(req
->lpszUrl
);
3485 heap_free(req
->lpszHeaders
);
3488 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3489 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3491 HINTERNET ret
= NULL
;
3492 appinfo_t
*hIC
= NULL
;
3494 if (TRACE_ON(wininet
)) {
3495 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3496 dwHeadersLength
, dwFlags
, dwContext
);
3498 dump_INTERNET_FLAGS(dwFlags
);
3503 SetLastError(ERROR_INVALID_PARAMETER
);
3507 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3508 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3509 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3513 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3514 WORKREQUEST workRequest
;
3515 struct WORKREQ_INTERNETOPENURLW
*req
;
3517 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3518 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3519 req
= &workRequest
.u
.InternetOpenUrlW
;
3520 req
->lpszUrl
= heap_strdupW(lpszUrl
);
3521 req
->lpszHeaders
= heap_strdupW(lpszHeaders
);
3522 req
->dwHeadersLength
= dwHeadersLength
;
3523 req
->dwFlags
= dwFlags
;
3524 req
->dwContext
= dwContext
;
3526 INTERNET_AsyncCall(&workRequest
);
3528 * This is from windows.
3530 SetLastError(ERROR_IO_PENDING
);
3532 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3537 WININET_Release( &hIC
->hdr
);
3538 TRACE(" %p <--\n", ret
);
3543 /**********************************************************
3544 * InternetOpenUrlA (WININET.@)
3549 * handle of connection or NULL on failure
3551 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3552 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3554 HINTERNET rc
= NULL
;
3555 DWORD lenHeaders
= 0;
3556 LPWSTR szUrl
= NULL
;
3557 LPWSTR szHeaders
= NULL
;
3562 szUrl
= heap_strdupAtoW(lpszUrl
);
3568 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3569 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3574 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3577 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3578 lenHeaders
, dwFlags
, dwContext
);
3581 heap_free(szHeaders
);
3586 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3588 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3592 lpwite
->dwError
= 0;
3593 lpwite
->response
[0] = '\0';
3596 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3605 /***********************************************************************
3606 * INTERNET_SetLastError (internal)
3608 * Set last thread specific error
3613 void INTERNET_SetLastError(DWORD dwError
)
3615 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3618 lpwite
= INTERNET_AllocThreadError();
3620 SetLastError(dwError
);
3622 lpwite
->dwError
= dwError
;
3626 /***********************************************************************
3627 * INTERNET_GetLastError (internal)
3629 * Get last thread specific error
3634 DWORD
INTERNET_GetLastError(void)
3636 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3637 if (!lpwite
) return 0;
3638 /* TlsGetValue clears last error, so set it again here */
3639 SetLastError(lpwite
->dwError
);
3640 return lpwite
->dwError
;
3644 /***********************************************************************
3645 * INTERNET_WorkerThreadFunc (internal)
3647 * Worker thread execution function
3652 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3654 LPWORKREQUEST lpRequest
= lpvParam
;
3655 WORKREQUEST workRequest
;
3659 workRequest
= *lpRequest
;
3660 heap_free(lpRequest
);
3662 workRequest
.asyncproc(&workRequest
);
3663 WININET_Release( workRequest
.hdr
);
3665 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3667 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3668 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3674 /***********************************************************************
3675 * INTERNET_AsyncCall (internal)
3677 * Retrieves work request from queue
3682 DWORD
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3685 LPWORKREQUEST lpNewRequest
;
3689 lpNewRequest
= heap_alloc(sizeof(WORKREQUEST
));
3691 return ERROR_OUTOFMEMORY
;
3693 *lpNewRequest
= *lpWorkRequest
;
3695 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3698 heap_free(lpNewRequest
);
3699 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3701 return ERROR_SUCCESS
;
3705 /***********************************************************************
3706 * INTERNET_GetResponseBuffer (internal)
3711 LPSTR
INTERNET_GetResponseBuffer(void)
3713 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3715 lpwite
= INTERNET_AllocThreadError();
3717 return lpwite
->response
;
3720 /***********************************************************************
3721 * INTERNET_GetNextLine (internal)
3723 * Parse next line in directory string listing
3726 * Pointer to beginning of next line
3731 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3733 // ReactOS: use select instead of poll
3736 BOOL bSuccess
= FALSE
;
3738 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3743 FD_SET(nSocket
,&infd
);
3744 tv
.tv_sec
= RESPONSE_TIMEOUT
;
3747 while (nRecv
< MAX_REPLY_LEN
)
3749 if (select(0, &infd
, NULL
, NULL
, &tv
) > 0)
3751 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3753 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3757 if (lpszBuffer
[nRecv
] == '\n')
3762 if (lpszBuffer
[nRecv
] != '\r')
3767 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3775 lpszBuffer
[nRecv
] = '\0';
3777 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3786 /**********************************************************
3787 * InternetQueryDataAvailable (WININET.@)
3789 * Determines how much data is available to be read.
3792 * TRUE on success, FALSE if an error occurred. If
3793 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3794 * no data is presently available, FALSE is returned with
3795 * the last error ERROR_IO_PENDING; a callback with status
3796 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3797 * data is available.
3799 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3800 LPDWORD lpdwNumberOfBytesAvailble
,
3801 DWORD dwFlags
, DWORD_PTR dwContext
)
3803 object_header_t
*hdr
;
3806 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3808 hdr
= get_handle_object( hFile
);
3810 SetLastError(ERROR_INVALID_HANDLE
);
3814 if(hdr
->vtbl
->QueryDataAvailable
) {
3815 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3817 WARN("wrong handle\n");
3818 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3821 WININET_Release(hdr
);
3823 if(res
!= ERROR_SUCCESS
)
3825 return res
== ERROR_SUCCESS
;
3829 /***********************************************************************
3830 * InternetLockRequestFile (WININET.@)
3832 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3839 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3846 /***********************************************************************
3847 * InternetAutodial (WININET.@)
3849 * On windows this function is supposed to dial the default internet
3850 * connection. We don't want to have Wine dial out to the internet so
3851 * we return TRUE by default. It might be nice to check if we are connected.
3858 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3862 /* Tell that we are connected to the internet. */
3866 /***********************************************************************
3867 * InternetAutodialHangup (WININET.@)
3869 * Hangs up a connection made with InternetAutodial
3878 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3882 /* we didn't dial, we don't disconnect */
3886 /***********************************************************************
3887 * InternetCombineUrlA (WININET.@)
3889 * Combine a base URL with a relative URL
3897 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3898 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3903 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3905 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3906 dwFlags
^= ICU_NO_ENCODE
;
3907 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3912 /***********************************************************************
3913 * InternetCombineUrlW (WININET.@)
3915 * Combine a base URL with a relative URL
3923 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3924 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3929 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3931 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3932 dwFlags
^= ICU_NO_ENCODE
;
3933 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3938 /* max port num is 65535 => 5 digits */
3939 #define MAX_WORD_DIGITS 5
3941 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3942 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3943 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3944 (url)->dw##component##Length : strlen((url)->lpsz##component))
3946 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3948 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3949 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3951 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3952 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3954 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3955 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3957 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3958 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3961 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3967 /* opaque urls do not fit into the standard url hierarchy and don't have
3968 * two following slashes */
3969 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3971 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3972 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3973 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3974 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3975 (nScheme
!= INTERNET_SCHEME_FILE
);
3978 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3981 if (scheme
< INTERNET_SCHEME_FIRST
)
3983 index
= scheme
- INTERNET_SCHEME_FIRST
;
3984 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3986 return (LPCWSTR
)url_schemes
[index
];
3989 /* we can calculate using ansi strings because we're just
3990 * calculating string length, not size
3992 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3993 LPDWORD lpdwUrlLength
)
3995 INTERNET_SCHEME nScheme
;
3999 if (lpUrlComponents
->lpszScheme
)
4001 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4002 *lpdwUrlLength
+= dwLen
;
4003 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4009 nScheme
= lpUrlComponents
->nScheme
;
4011 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4012 nScheme
= INTERNET_SCHEME_HTTP
;
4013 scheme
= INTERNET_GetSchemeString(nScheme
);
4014 *lpdwUrlLength
+= strlenW(scheme
);
4017 (*lpdwUrlLength
)++; /* ':' */
4018 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4019 *lpdwUrlLength
+= strlen("//");
4021 if (lpUrlComponents
->lpszUserName
)
4023 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4024 *lpdwUrlLength
+= strlen("@");
4028 if (lpUrlComponents
->lpszPassword
)
4030 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4035 if (lpUrlComponents
->lpszPassword
)
4037 *lpdwUrlLength
+= strlen(":");
4038 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4041 if (lpUrlComponents
->lpszHostName
)
4043 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4045 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4047 char szPort
[MAX_WORD_DIGITS
+1];
4049 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4050 *lpdwUrlLength
+= strlen(szPort
);
4051 *lpdwUrlLength
+= strlen(":");
4054 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4055 (*lpdwUrlLength
)++; /* '/' */
4058 if (lpUrlComponents
->lpszUrlPath
)
4059 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4061 if (lpUrlComponents
->lpszExtraInfo
)
4062 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4067 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4071 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4073 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4074 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4075 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4076 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4077 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4078 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4079 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4080 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4081 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4083 if (lpUrlComponents
->lpszScheme
)
4085 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4086 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4087 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4088 -1, urlCompW
->lpszScheme
, len
);
4091 if (lpUrlComponents
->lpszHostName
)
4093 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4094 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4095 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4096 -1, urlCompW
->lpszHostName
, len
);
4099 if (lpUrlComponents
->lpszUserName
)
4101 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4102 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4103 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4104 -1, urlCompW
->lpszUserName
, len
);
4107 if (lpUrlComponents
->lpszPassword
)
4109 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4110 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4111 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4112 -1, urlCompW
->lpszPassword
, len
);
4115 if (lpUrlComponents
->lpszUrlPath
)
4117 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4118 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4119 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4120 -1, urlCompW
->lpszUrlPath
, len
);
4123 if (lpUrlComponents
->lpszExtraInfo
)
4125 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4126 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4127 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4128 -1, urlCompW
->lpszExtraInfo
, len
);
4132 /***********************************************************************
4133 * InternetCreateUrlA (WININET.@)
4135 * See InternetCreateUrlW.
4137 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4138 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4142 URL_COMPONENTSW urlCompW
;
4144 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4146 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4148 SetLastError(ERROR_INVALID_PARAMETER
);
4152 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4155 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4157 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4159 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4160 *lpdwUrlLength
/= sizeof(WCHAR
);
4162 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4163 * minus one, so add one to leave room for NULL terminator
4166 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4168 heap_free(urlCompW
.lpszScheme
);
4169 heap_free(urlCompW
.lpszHostName
);
4170 heap_free(urlCompW
.lpszUserName
);
4171 heap_free(urlCompW
.lpszPassword
);
4172 heap_free(urlCompW
.lpszUrlPath
);
4173 heap_free(urlCompW
.lpszExtraInfo
);
4178 /***********************************************************************
4179 * InternetCreateUrlW (WININET.@)
4181 * Creates a URL from its component parts.
4184 * lpUrlComponents [I] URL Components.
4185 * dwFlags [I] Flags. See notes.
4186 * lpszUrl [I] Buffer in which to store the created URL.
4187 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4188 * lpszUrl in characters. On output, the number of bytes
4189 * required to store the URL including terminator.
4193 * The dwFlags parameter can be zero or more of the following:
4194 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4201 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4202 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4205 INTERNET_SCHEME nScheme
;
4207 static const WCHAR slashSlashW
[] = {'/','/'};
4208 static const WCHAR fmtW
[] = {'%','u',0};
4210 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4212 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4214 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4218 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4221 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4223 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4224 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4228 *lpdwUrlLength
= dwLen
;
4233 if (lpUrlComponents
->lpszScheme
)
4235 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4236 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4239 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4244 nScheme
= lpUrlComponents
->nScheme
;
4246 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4247 nScheme
= INTERNET_SCHEME_HTTP
;
4249 scheme
= INTERNET_GetSchemeString(nScheme
);
4250 dwLen
= strlenW(scheme
);
4251 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4255 /* all schemes are followed by at least a colon */
4259 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4261 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4262 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4265 if (lpUrlComponents
->lpszUserName
)
4267 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4268 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4271 if (lpUrlComponents
->lpszPassword
)
4276 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4277 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4285 if (lpUrlComponents
->lpszHostName
)
4287 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4288 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4291 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4293 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4295 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4298 dwLen
= strlenW(szPort
);
4299 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4303 /* add slash between hostname and path if necessary */
4304 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4311 if (lpUrlComponents
->lpszUrlPath
)
4313 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4314 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4318 if (lpUrlComponents
->lpszExtraInfo
)
4320 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4321 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4330 /***********************************************************************
4331 * InternetConfirmZoneCrossingA (WININET.@)
4334 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4336 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4337 return ERROR_SUCCESS
;
4340 /***********************************************************************
4341 * InternetConfirmZoneCrossingW (WININET.@)
4344 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4346 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4347 return ERROR_SUCCESS
;
4350 static DWORD zone_preference
= 3;
4352 /***********************************************************************
4353 * PrivacySetZonePreferenceW (WININET.@)
4355 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4357 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4359 zone_preference
= template;
4363 /***********************************************************************
4364 * PrivacyGetZonePreferenceW (WININET.@)
4366 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4367 LPWSTR preference
, LPDWORD length
)
4369 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4371 if (template) *template = zone_preference
;
4375 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4376 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4378 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4379 lpdwConnection
, dwReserved
);
4380 return ERROR_SUCCESS
;
4383 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4384 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4386 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4387 lpdwConnection
, dwReserved
);
4388 return ERROR_SUCCESS
;
4391 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4393 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4397 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4399 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4403 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4405 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4406 return ERROR_SUCCESS
;
4409 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4412 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4413 debugstr_w(pwszTarget
), pbHexHash
);
4417 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4419 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4423 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4425 FIXME("(%p, %08lx) stub\n", a
, b
);
4429 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4431 FIXME("%p: stub\n", parent
);