4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #if defined(__MINGW32__) || defined (_MSC_VER)
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 # include <sys/socket.h>
46 #ifdef HAVE_SYS_POLL_H
47 # include <sys/poll.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
66 #include "wine/debug.h"
68 #define NO_SHLWAPI_STREAM
71 #include "wine/exception.h"
76 #include "wine/unicode.h"
78 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
80 #define RESPONSE_TIMEOUT 30
85 CHAR response
[MAX_REPLY_LEN
];
86 } WITHREADERROR
, *LPWITHREADERROR
;
88 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
89 HMODULE WININET_hModule
;
91 static CRITICAL_SECTION WININET_cs
;
92 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
95 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
96 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
98 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
100 static object_header_t
**handle_table
;
101 static UINT_PTR next_handle
;
102 static UINT_PTR handle_table_size
;
111 static ULONG max_conns
= 2, max_1_0_conns
= 4;
112 static ULONG connect_timeout
= 60000;
114 static const WCHAR szInternetSettings
[] =
115 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
116 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
117 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
118 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
119 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
121 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
123 UINT_PTR handle
= 0, num
;
124 object_header_t
*ret
;
128 ret
= heap_alloc_zero(size
);
132 list_init(&ret
->children
);
134 EnterCriticalSection( &WININET_cs
);
136 if(!handle_table_size
) {
138 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
141 handle_table_size
= num
;
146 }else if(next_handle
== handle_table_size
) {
147 num
= handle_table_size
* 2;
148 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
151 handle_table_size
= num
;
158 handle
= next_handle
;
159 if(handle_table
[handle
])
160 ERR("handle isn't free but should be\n");
161 handle_table
[handle
] = ret
;
162 ret
->valid_handle
= TRUE
;
164 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
168 LeaveCriticalSection( &WININET_cs
);
177 ret
->hInternet
= (HINTERNET
)handle
;
180 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
181 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
187 object_header_t
*WININET_AddRef( object_header_t
*info
)
189 ULONG refs
= InterlockedIncrement(&info
->refs
);
190 TRACE("%p -> refcount = %d\n", info
, refs
);
194 object_header_t
*get_handle_object( HINTERNET hinternet
)
196 object_header_t
*info
= NULL
;
197 UINT_PTR handle
= (UINT_PTR
) hinternet
;
199 EnterCriticalSection( &WININET_cs
);
201 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
202 info
= WININET_AddRef(handle_table
[handle
]);
204 LeaveCriticalSection( &WININET_cs
);
206 TRACE("handle %ld -> %p\n", handle
, info
);
211 static void invalidate_handle(object_header_t
*info
)
213 object_header_t
*child
, *next
;
215 if(!info
->valid_handle
)
217 info
->valid_handle
= FALSE
;
219 /* Free all children as native does */
220 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
222 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
223 invalidate_handle( child
);
226 WININET_Release(info
);
229 BOOL
WININET_Release( object_header_t
*info
)
231 ULONG refs
= InterlockedDecrement(&info
->refs
);
232 TRACE( "object %p refcount = %d\n", info
, refs
);
235 invalidate_handle(info
);
236 if ( info
->vtbl
->CloseConnection
)
238 TRACE( "closing connection %p\n", info
);
239 info
->vtbl
->CloseConnection( info
);
241 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
242 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
243 || !(info
->dwInternalFlags
& INET_OPENURL
))
245 INTERNET_SendCallback(info
, info
->dwContext
,
246 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
249 TRACE( "destroying object %p\n", info
);
250 if ( info
->htype
!= WH_HINIT
)
251 list_remove( &info
->entry
);
252 info
->vtbl
->Destroy( info
);
254 if(info
->hInternet
) {
255 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
257 EnterCriticalSection( &WININET_cs
);
259 handle_table
[handle
] = NULL
;
260 if(next_handle
> handle
)
261 next_handle
= handle
;
263 LeaveCriticalSection( &WININET_cs
);
271 /***********************************************************************
272 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
275 * hinstDLL [I] handle to the DLL's instance
277 * lpvReserved [I] reserved, must be NULL
284 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
286 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
289 case DLL_PROCESS_ATTACH
:
291 g_dwTlsErrIndex
= TlsAlloc();
293 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
296 URLCacheContainers_CreateDefaults();
298 WININET_hModule
= hinstDLL
;
301 case DLL_THREAD_ATTACH
:
304 case DLL_THREAD_DETACH
:
305 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
307 heap_free(TlsGetValue(g_dwTlsErrIndex
));
311 case DLL_PROCESS_DETACH
:
312 collect_connections(COLLECT_CLEANUP
);
314 URLCacheContainers_DeleteAll();
316 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
318 heap_free(TlsGetValue(g_dwTlsErrIndex
));
319 TlsFree(g_dwTlsErrIndex
);
326 /***********************************************************************
327 * INTERNET_SaveProxySettings
329 * Stores the proxy settings given by lpwai into the registry
332 * ERROR_SUCCESS if no error, or error code on fail
334 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
339 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
342 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
350 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
358 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
366 return ERROR_SUCCESS
;
369 /***********************************************************************
370 * INTERNET_FindProxyForProtocol
372 * Searches the proxy string for a proxy of the given protocol.
373 * Returns the found proxy, or the default proxy if none of the given
377 * szProxy [In] proxy string to search
378 * proto [In] protocol to search for, e.g. "http"
379 * foundProxy [Out] found proxy
380 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
383 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
384 * *foundProxyLen is set to the required size in WCHARs, including the
385 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
387 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
392 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
394 /* First, look for the specified protocol (proto=scheme://host:port) */
395 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
399 if (!(end
= strchrW(ptr
, ' ')))
400 end
= ptr
+ strlenW(ptr
);
401 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
402 equal
- ptr
== strlenW(proto
) &&
403 !strncmpiW(proto
, ptr
, strlenW(proto
)))
405 if (end
- equal
> *foundProxyLen
)
407 WARN("buffer too short for %s\n",
408 debugstr_wn(equal
+ 1, end
- equal
- 1));
409 *foundProxyLen
= end
- equal
;
410 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
414 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
415 foundProxy
[end
- equal
] = 0;
426 /* It wasn't found: look for no protocol */
427 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
431 if (!(end
= strchrW(ptr
, ' ')))
432 end
= ptr
+ strlenW(ptr
);
433 if (!(equal
= strchrW(ptr
, '=')))
435 if (end
- ptr
+ 1 > *foundProxyLen
)
437 WARN("buffer too short for %s\n",
438 debugstr_wn(ptr
, end
- ptr
));
439 *foundProxyLen
= end
- ptr
+ 1;
440 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
444 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
445 foundProxy
[end
- ptr
] = 0;
456 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
457 debugstr_w(foundProxy
));
461 /***********************************************************************
462 * InternetInitializeAutoProxyDll (WININET.@)
464 * Setup the internal proxy
473 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
476 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
480 /***********************************************************************
481 * DetectAutoProxyUrl (WININET.@)
483 * Auto detect the proxy url
489 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
490 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
493 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
497 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
499 heap_free(lpwpi
->proxy
);
500 heap_free(lpwpi
->proxyBypass
);
503 static proxyinfo_t
*global_proxy
;
505 static void free_global_proxy( void )
507 EnterCriticalSection( &WININET_cs
);
510 FreeProxyInfo( global_proxy
);
511 heap_free( global_proxy
);
513 LeaveCriticalSection( &WININET_cs
);
516 /***********************************************************************
517 * INTERNET_LoadProxySettings
519 * Loads proxy information from process-wide global settings, the registry,
520 * or the environment into lpwpi.
522 * The caller should call FreeProxyInfo when done with lpwpi.
525 * The proxy may be specified in the form 'http=proxy.my.org'
526 * Presumably that means there can be ftp=ftpproxy.my.org too.
528 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
535 EnterCriticalSection( &WININET_cs
);
538 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
539 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
540 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
542 LeaveCriticalSection( &WININET_cs
);
544 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
548 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
550 lpwpi
->proxyEnabled
= 0;
551 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
558 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
560 TRACE("Proxy is enabled.\n");
562 /* figure out how much memory the proxy setting takes */
563 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
566 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
568 if (!(szProxy
= heap_alloc(len
)))
571 return ERROR_OUTOFMEMORY
;
573 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
575 /* find the http proxy, and strip away everything else */
576 p
= strstrW( szProxy
, szHttp
);
579 p
+= lstrlenW( szHttp
);
580 lstrcpyW( szProxy
, p
);
582 p
= strchrW( szProxy
, ' ' );
585 lpwpi
->proxy
= szProxy
;
587 TRACE("http proxy = %s\n", debugstr_w(lpwpi
->proxy
));
591 TRACE("No proxy server settings in registry.\n");
599 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
600 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
601 return ERROR_OUTOFMEMORY
;
602 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
604 lpwpi
->proxyEnabled
= 1;
605 lpwpi
->proxy
= envproxyW
;
607 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
611 lpwpi
->proxyBypass
= NULL
;
613 return ERROR_SUCCESS
;
616 /***********************************************************************
617 * INTERNET_ConfigureProxy
619 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
623 if (INTERNET_LoadProxySettings( &wpi
))
626 if (wpi
.proxyEnabled
)
628 WCHAR proxyurl
[INTERNET_MAX_URL_LENGTH
];
629 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
];
630 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
631 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
632 URL_COMPONENTSW UrlComponents
;
634 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
635 UrlComponents
.dwSchemeLength
= 0;
636 UrlComponents
.lpszHostName
= hostname
;
637 UrlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
638 UrlComponents
.lpszUserName
= username
;
639 UrlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
640 UrlComponents
.lpszPassword
= password
;
641 UrlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
642 UrlComponents
.dwUrlPathLength
= 0;
643 UrlComponents
.dwExtraInfoLength
= 0;
645 if(InternetCrackUrlW(wpi
.proxy
, 0, 0, &UrlComponents
))
647 static const WCHAR szFormat
[] = { 'h','t','t','p',':','/','/','%','s',':','%','u',0 };
649 if(UrlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
650 UrlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
651 sprintfW(proxyurl
, szFormat
, hostname
, UrlComponents
.nPort
);
653 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
654 lpwai
->proxy
= heap_strdupW(proxyurl
);
655 if (UrlComponents
.dwUserNameLength
)
657 lpwai
->proxyUsername
= heap_strdupW(UrlComponents
.lpszUserName
);
658 lpwai
->proxyPassword
= heap_strdupW(UrlComponents
.lpszPassword
);
661 TRACE("http proxy = %s\n", debugstr_w(lpwai
->proxy
));
666 TRACE("Failed to parse proxy: %s\n", debugstr_w(wpi
.proxy
));
671 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
675 /***********************************************************************
676 * dump_INTERNET_FLAGS
678 * Helper function to TRACE the internet flags.
684 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
686 #define FE(x) { x, #x }
687 static const wininet_flag_info flag
[] = {
688 FE(INTERNET_FLAG_RELOAD
),
689 FE(INTERNET_FLAG_RAW_DATA
),
690 FE(INTERNET_FLAG_EXISTING_CONNECT
),
691 FE(INTERNET_FLAG_ASYNC
),
692 FE(INTERNET_FLAG_PASSIVE
),
693 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
694 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
695 FE(INTERNET_FLAG_FROM_CACHE
),
696 FE(INTERNET_FLAG_SECURE
),
697 FE(INTERNET_FLAG_KEEP_CONNECTION
),
698 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
699 FE(INTERNET_FLAG_READ_PREFETCH
),
700 FE(INTERNET_FLAG_NO_COOKIES
),
701 FE(INTERNET_FLAG_NO_AUTH
),
702 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
703 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
704 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
705 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
706 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
707 FE(INTERNET_FLAG_RESYNCHRONIZE
),
708 FE(INTERNET_FLAG_HYPERLINK
),
709 FE(INTERNET_FLAG_NO_UI
),
710 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
711 FE(INTERNET_FLAG_CACHE_ASYNC
),
712 FE(INTERNET_FLAG_FORMS_SUBMIT
),
713 FE(INTERNET_FLAG_NEED_FILE
),
714 FE(INTERNET_FLAG_TRANSFER_ASCII
),
715 FE(INTERNET_FLAG_TRANSFER_BINARY
)
720 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
721 if (flag
[i
].val
& dwFlags
) {
722 TRACE(" %s", flag
[i
].name
);
723 dwFlags
&= ~flag
[i
].val
;
727 TRACE(" Unknown flags (%08x)\n", dwFlags
);
732 /***********************************************************************
733 * INTERNET_CloseHandle (internal)
735 * Close internet handle
738 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
740 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
744 heap_free(lpwai
->agent
);
745 heap_free(lpwai
->proxy
);
746 heap_free(lpwai
->proxyBypass
);
747 heap_free(lpwai
->proxyUsername
);
748 heap_free(lpwai
->proxyPassword
);
751 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
753 appinfo_t
*ai
= (appinfo_t
*)hdr
;
756 case INTERNET_OPTION_HANDLE_TYPE
:
757 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
759 if (*size
< sizeof(ULONG
))
760 return ERROR_INSUFFICIENT_BUFFER
;
762 *size
= sizeof(DWORD
);
763 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
764 return ERROR_SUCCESS
;
766 case INTERNET_OPTION_USER_AGENT
: {
769 TRACE("INTERNET_OPTION_USER_AGENT\n");
774 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
776 *size
= (len
+ 1) * sizeof(WCHAR
);
777 if(!buffer
|| bufsize
< *size
)
778 return ERROR_INSUFFICIENT_BUFFER
;
781 strcpyW(buffer
, ai
->agent
);
783 *(WCHAR
*)buffer
= 0;
784 /* If the buffer is copied, the returned length doesn't include
785 * the NULL terminator.
787 *size
= len
* sizeof(WCHAR
);
790 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
793 if(!buffer
|| bufsize
< *size
)
794 return ERROR_INSUFFICIENT_BUFFER
;
797 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
800 /* If the buffer is copied, the returned length doesn't include
801 * the NULL terminator.
806 return ERROR_SUCCESS
;
809 case INTERNET_OPTION_PROXY
:
810 if(!size
) return ERROR_INVALID_PARAMETER
;
812 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
813 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
814 LPWSTR proxy
, proxy_bypass
;
817 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
819 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
820 if (*size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
822 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
823 return ERROR_INSUFFICIENT_BUFFER
;
825 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
826 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
828 pi
->dwAccessType
= ai
->accessType
;
829 pi
->lpszProxy
= NULL
;
830 pi
->lpszProxyBypass
= NULL
;
832 lstrcpyW(proxy
, ai
->proxy
);
833 pi
->lpszProxy
= proxy
;
836 if (ai
->proxyBypass
) {
837 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
838 pi
->lpszProxyBypass
= proxy_bypass
;
841 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
842 return ERROR_SUCCESS
;
844 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
845 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
846 LPSTR proxy
, proxy_bypass
;
849 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
851 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
852 NULL
, 0, NULL
, NULL
);
853 if (*size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
855 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
856 return ERROR_INSUFFICIENT_BUFFER
;
858 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
859 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
861 pi
->dwAccessType
= ai
->accessType
;
862 pi
->lpszProxy
= NULL
;
863 pi
->lpszProxyBypass
= NULL
;
865 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
866 pi
->lpszProxy
= proxy
;
869 if (ai
->proxyBypass
) {
870 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
871 proxyBypassBytesRequired
, NULL
, NULL
);
872 pi
->lpszProxyBypass
= proxy_bypass
;
875 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
876 return ERROR_SUCCESS
;
879 case INTERNET_OPTION_CONNECT_TIMEOUT
:
880 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
882 if (*size
< sizeof(ULONG
))
883 return ERROR_INSUFFICIENT_BUFFER
;
885 *(ULONG
*)buffer
= ai
->connect_timeout
;
886 *size
= sizeof(ULONG
);
888 return ERROR_SUCCESS
;
891 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
894 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
896 appinfo_t
*ai
= (appinfo_t
*)hdr
;
899 case INTERNET_OPTION_CONNECT_TIMEOUT
:
900 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
902 if(size
!= sizeof(connect_timeout
))
903 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
905 return ERROR_BAD_ARGUMENTS
;
907 ai
->connect_timeout
= *(ULONG
*)buf
;
908 return ERROR_SUCCESS
;
909 case INTERNET_OPTION_USER_AGENT
:
910 heap_free(ai
->agent
);
911 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
912 return ERROR_SUCCESS
;
915 return INET_SetOption(hdr
, option
, buf
, size
);
918 static const object_vtbl_t APPINFOVtbl
= {
931 /***********************************************************************
932 * InternetOpenW (WININET.@)
934 * Per-application initialization of wininet
937 * HINTERNET on success
941 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
942 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
944 appinfo_t
*lpwai
= NULL
;
946 if (TRACE_ON(wininet
)) {
947 #define FE(x) { x, #x }
948 static const wininet_flag_info access_type
[] = {
949 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
950 FE(INTERNET_OPEN_TYPE_DIRECT
),
951 FE(INTERNET_OPEN_TYPE_PROXY
),
952 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
956 const char *access_type_str
= "Unknown";
958 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
959 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
960 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
961 if (access_type
[i
].val
== dwAccessType
) {
962 access_type_str
= access_type
[i
].name
;
966 TRACE(" access type : %s\n", access_type_str
);
968 dump_INTERNET_FLAGS(dwFlags
);
971 /* Clear any error information */
972 INTERNET_SetLastError(0);
974 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
976 SetLastError(ERROR_OUTOFMEMORY
);
980 lpwai
->hdr
.htype
= WH_HINIT
;
981 lpwai
->hdr
.dwFlags
= dwFlags
;
982 lpwai
->accessType
= dwAccessType
;
983 lpwai
->proxyUsername
= NULL
;
984 lpwai
->proxyPassword
= NULL
;
985 lpwai
->connect_timeout
= connect_timeout
;
987 lpwai
->agent
= heap_strdupW(lpszAgent
);
988 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
989 INTERNET_ConfigureProxy( lpwai
);
991 lpwai
->proxy
= heap_strdupW(lpszProxy
);
992 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
994 TRACE("returning %p\n", lpwai
);
996 return lpwai
->hdr
.hInternet
;
1000 /***********************************************************************
1001 * InternetOpenA (WININET.@)
1003 * Per-application initialization of wininet
1006 * HINTERNET on success
1010 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1011 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1013 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1016 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1017 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1019 szAgent
= heap_strdupAtoW(lpszAgent
);
1020 szProxy
= heap_strdupAtoW(lpszProxy
);
1021 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1023 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1027 heap_free(szBypass
);
1031 /***********************************************************************
1032 * InternetGetLastResponseInfoA (WININET.@)
1034 * Return last wininet error description on the calling thread
1037 * TRUE on success of writing to buffer
1041 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1042 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1044 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1050 *lpdwError
= lpwite
->dwError
;
1051 if (lpwite
->dwError
)
1053 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1054 *lpdwBufferLength
= strlen(lpszBuffer
);
1057 *lpdwBufferLength
= 0;
1062 *lpdwBufferLength
= 0;
1068 /***********************************************************************
1069 * InternetGetLastResponseInfoW (WININET.@)
1071 * Return last wininet error description on the calling thread
1074 * TRUE on success of writing to buffer
1078 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1079 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1081 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1087 *lpdwError
= lpwite
->dwError
;
1088 if (lpwite
->dwError
)
1090 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1091 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1094 *lpdwBufferLength
= 0;
1099 *lpdwBufferLength
= 0;
1105 /***********************************************************************
1106 * InternetGetConnectedState (WININET.@)
1108 * Return connected state
1112 * if lpdwStatus is not null, return the status (off line,
1113 * modem, lan...) in it.
1114 * FALSE if not connected
1116 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1118 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1121 WARN("always returning LAN connection.\n");
1122 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1128 /***********************************************************************
1129 * InternetGetConnectedStateExW (WININET.@)
1131 * Return connected state
1135 * lpdwStatus [O] Flags specifying the status of the internet connection.
1136 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1137 * dwNameLen [I] Size of the buffer, in characters.
1138 * dwReserved [I] Reserved. Must be set to 0.
1142 * if lpdwStatus is not null, return the status (off line,
1143 * modem, lan...) in it.
1144 * FALSE if not connected
1147 * If the system has no available network connections, an empty string is
1148 * stored in lpszConnectionName. If there is a LAN connection, a localized
1149 * "LAN Connection" string is stored. Presumably, if only a dial-up
1150 * connection is available then the name of the dial-up connection is
1151 * returned. Why any application, other than the "Internet Settings" CPL,
1152 * would want to use this function instead of the simpler InternetGetConnectedStateW
1153 * function is beyond me.
1155 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1156 DWORD dwNameLen
, DWORD dwReserved
)
1158 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1165 WARN("always returning LAN connection.\n");
1166 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1168 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1172 /***********************************************************************
1173 * InternetGetConnectedStateExA (WININET.@)
1175 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1176 DWORD dwNameLen
, DWORD dwReserved
)
1178 LPWSTR lpwszConnectionName
= NULL
;
1181 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1183 if (lpszConnectionName
&& dwNameLen
> 0)
1184 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1186 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1188 if (rc
&& lpwszConnectionName
)
1190 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1191 dwNameLen
, NULL
, NULL
);
1192 heap_free(lpwszConnectionName
);
1198 /***********************************************************************
1199 * InternetConnectW (WININET.@)
1201 * Open a ftp, gopher or http session
1204 * HINTERNET a session handle on success
1208 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1209 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1210 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1211 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1214 HINTERNET rc
= NULL
;
1215 DWORD res
= ERROR_SUCCESS
;
1217 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1218 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1219 dwService
, dwFlags
, dwContext
);
1221 if (!lpszServerName
)
1223 SetLastError(ERROR_INVALID_PARAMETER
);
1227 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1228 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1230 res
= ERROR_INVALID_HANDLE
;
1236 case INTERNET_SERVICE_FTP
:
1237 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1238 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1240 res
= INTERNET_GetLastError();
1243 case INTERNET_SERVICE_HTTP
:
1244 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1245 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1248 case INTERNET_SERVICE_GOPHER
:
1254 WININET_Release( &hIC
->hdr
);
1256 TRACE("returning %p\n", rc
);
1262 /***********************************************************************
1263 * InternetConnectA (WININET.@)
1265 * Open a ftp, gopher or http session
1268 * HINTERNET a session handle on success
1272 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1273 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1274 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1275 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1277 HINTERNET rc
= NULL
;
1278 LPWSTR szServerName
;
1282 szServerName
= heap_strdupAtoW(lpszServerName
);
1283 szUserName
= heap_strdupAtoW(lpszUserName
);
1284 szPassword
= heap_strdupAtoW(lpszPassword
);
1286 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1287 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1289 heap_free(szServerName
);
1290 heap_free(szUserName
);
1291 heap_free(szPassword
);
1296 /***********************************************************************
1297 * InternetFindNextFileA (WININET.@)
1299 * Continues a file search from a previous call to FindFirstFile
1306 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1309 WIN32_FIND_DATAW fd
;
1311 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1313 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1317 /***********************************************************************
1318 * InternetFindNextFileW (WININET.@)
1320 * Continues a file search from a previous call to FindFirstFile
1327 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1329 object_header_t
*hdr
;
1334 hdr
= get_handle_object(hFind
);
1336 WARN("Invalid handle\n");
1337 SetLastError(ERROR_INVALID_HANDLE
);
1341 if(hdr
->vtbl
->FindNextFileW
) {
1342 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1344 WARN("Handle doesn't support NextFile\n");
1345 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1348 WININET_Release(hdr
);
1350 if(res
!= ERROR_SUCCESS
)
1352 return res
== ERROR_SUCCESS
;
1355 /***********************************************************************
1356 * InternetCloseHandle (WININET.@)
1358 * Generic close handle function
1365 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1367 object_header_t
*obj
;
1369 TRACE("%p\n", hInternet
);
1371 obj
= get_handle_object( hInternet
);
1373 SetLastError(ERROR_INVALID_HANDLE
);
1377 invalidate_handle(obj
);
1378 WININET_Release(obj
);
1384 /***********************************************************************
1385 * ConvertUrlComponentValue (Internal)
1387 * Helper function for InternetCrackUrlA
1390 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1391 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1392 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1394 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1395 if (*dwComponentLen
!= 0)
1397 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1398 if (*lppszComponent
== NULL
)
1402 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1403 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1406 *lppszComponent
= NULL
;
1408 *dwComponentLen
= nASCIILength
;
1412 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1413 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1414 (*lppszComponent
)[ncpylen
]=0;
1415 *dwComponentLen
= ncpylen
;
1421 /***********************************************************************
1422 * InternetCrackUrlA (WININET.@)
1424 * See InternetCrackUrlW.
1426 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1427 LPURL_COMPONENTSA lpUrlComponents
)
1430 URL_COMPONENTSW UCW
;
1432 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1433 *scheme
= NULL
, *extra
= NULL
;
1435 TRACE("(%s %u %x %p)\n",
1436 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1437 dwUrlLength
, dwFlags
, lpUrlComponents
);
1439 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1440 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1442 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1448 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1450 /* if dwUrlLength=-1 then nLength includes null but length to
1451 InternetCrackUrlW should not include it */
1452 if (dwUrlLength
== -1) nLength
--;
1454 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1455 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1456 lpwszUrl
[nLength
] = '\0';
1458 memset(&UCW
,0,sizeof(UCW
));
1459 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1460 if (lpUrlComponents
->dwHostNameLength
)
1462 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1463 if (lpUrlComponents
->lpszHostName
)
1465 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1466 UCW
.lpszHostName
= hostname
;
1469 if (lpUrlComponents
->dwUserNameLength
)
1471 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1472 if (lpUrlComponents
->lpszUserName
)
1474 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1475 UCW
.lpszUserName
= username
;
1478 if (lpUrlComponents
->dwPasswordLength
)
1480 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1481 if (lpUrlComponents
->lpszPassword
)
1483 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1484 UCW
.lpszPassword
= password
;
1487 if (lpUrlComponents
->dwUrlPathLength
)
1489 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1490 if (lpUrlComponents
->lpszUrlPath
)
1492 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1493 UCW
.lpszUrlPath
= path
;
1496 if (lpUrlComponents
->dwSchemeLength
)
1498 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1499 if (lpUrlComponents
->lpszScheme
)
1501 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1502 UCW
.lpszScheme
= scheme
;
1505 if (lpUrlComponents
->dwExtraInfoLength
)
1507 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1508 if (lpUrlComponents
->lpszExtraInfo
)
1510 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1511 UCW
.lpszExtraInfo
= extra
;
1514 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1516 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1517 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1518 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1519 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1520 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1521 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1522 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1523 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1524 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1525 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1526 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1527 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1529 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1530 lpUrlComponents
->nPort
= UCW
.nPort
;
1532 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1533 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1534 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1535 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1536 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1538 heap_free(lpwszUrl
);
1539 heap_free(hostname
);
1540 heap_free(username
);
1541 heap_free(password
);
1548 static const WCHAR url_schemes
[][7] =
1551 {'g','o','p','h','e','r',0},
1552 {'h','t','t','p',0},
1553 {'h','t','t','p','s',0},
1554 {'f','i','l','e',0},
1555 {'n','e','w','s',0},
1556 {'m','a','i','l','t','o',0},
1560 /***********************************************************************
1561 * GetInternetSchemeW (internal)
1567 * INTERNET_SCHEME_UNKNOWN on failure
1570 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1574 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1576 if(lpszScheme
==NULL
)
1577 return INTERNET_SCHEME_UNKNOWN
;
1579 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1580 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1581 return INTERNET_SCHEME_FIRST
+ i
;
1583 return INTERNET_SCHEME_UNKNOWN
;
1586 /***********************************************************************
1587 * SetUrlComponentValueW (Internal)
1589 * Helper function for InternetCrackUrlW
1592 * lppszComponent [O] Holds the returned string
1593 * dwComponentLen [I] Holds the size of lppszComponent
1594 * [O] Holds the length of the string in lppszComponent without '\0'
1595 * lpszStart [I] Holds the string to copy from
1596 * len [I] Holds the length of lpszStart without '\0'
1603 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1605 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1607 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1610 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1612 if (*lppszComponent
== NULL
)
1614 *lppszComponent
= (LPWSTR
)lpszStart
;
1615 *dwComponentLen
= len
;
1619 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1620 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1621 (*lppszComponent
)[ncpylen
] = '\0';
1622 *dwComponentLen
= ncpylen
;
1629 /***********************************************************************
1630 * InternetCrackUrlW (WININET.@)
1632 * Break up URL into its components
1638 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1639 LPURL_COMPONENTSW lpUC
)
1643 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1646 LPCWSTR lpszParam
= NULL
;
1647 BOOL bIsAbsolute
= FALSE
;
1648 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1649 LPCWSTR lpszcp
= NULL
;
1650 LPWSTR lpszUrl_decode
= NULL
;
1651 DWORD dwUrlLength
= dwUrlLength_orig
;
1653 TRACE("(%s %u %x %p)\n",
1654 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1655 dwUrlLength
, dwFlags
, lpUC
);
1657 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1659 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1662 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1664 if (dwFlags
& ICU_DECODE
)
1667 DWORD len
= dwUrlLength
+ 1;
1669 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1671 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1674 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1675 url_tmp
[dwUrlLength
] = 0;
1676 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1679 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1682 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1685 lpszUrl
= lpszUrl_decode
;
1691 /* Determine if the URI is absolute. */
1692 while (lpszap
- lpszUrl
< dwUrlLength
)
1694 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1699 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1706 lpszcp
= lpszUrl
; /* Relative url */
1712 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1713 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1715 /* Parse <params> */
1716 lpszParam
= memchrW(lpszap
, ';', dwUrlLength
- (lpszap
- lpszUrl
));
1718 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1720 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1722 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1723 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1725 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1729 /* Get scheme first. */
1730 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1731 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1732 lpszUrl
, lpszcp
- lpszUrl
);
1734 /* Eat ':' in protocol. */
1737 /* double slash indicates the net_loc portion is present */
1738 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1742 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1746 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1748 lpszNetLoc
= lpszParam
;
1750 else if (!lpszNetLoc
)
1751 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1759 /* [<user>[<:password>]@]<host>[:<port>] */
1760 /* First find the user and password if they exist */
1762 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1763 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1765 /* username and password not specified. */
1766 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1767 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1769 else /* Parse out username and password */
1771 LPCWSTR lpszUser
= lpszcp
;
1772 LPCWSTR lpszPasswd
= lpszHost
;
1774 while (lpszcp
< lpszHost
)
1777 lpszPasswd
= lpszcp
;
1782 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1783 lpszUser
, lpszPasswd
- lpszUser
);
1785 if (lpszPasswd
!= lpszHost
)
1787 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1788 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1789 lpszHost
- lpszPasswd
);
1791 lpszcp
++; /* Advance to beginning of host */
1794 /* Parse <host><:port> */
1797 lpszPort
= lpszNetLoc
;
1799 /* special case for res:// URLs: there is no port here, so the host is the
1800 entire string up to the first '/' */
1801 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1803 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1804 lpszHost
, lpszPort
- lpszHost
);
1809 while (lpszcp
< lpszNetLoc
)
1817 /* If the scheme is "file" and the host is just one letter, it's not a host */
1818 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1821 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1826 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1827 lpszHost
, lpszPort
- lpszHost
);
1828 if (lpszPort
!= lpszNetLoc
)
1829 lpUC
->nPort
= atoiW(++lpszPort
);
1830 else switch (lpUC
->nScheme
)
1832 case INTERNET_SCHEME_HTTP
:
1833 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1835 case INTERNET_SCHEME_HTTPS
:
1836 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1838 case INTERNET_SCHEME_FTP
:
1839 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1841 case INTERNET_SCHEME_GOPHER
:
1842 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1853 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1854 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1855 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1860 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1861 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1862 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1863 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1866 /* Here lpszcp points to:
1868 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1869 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1871 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1875 /* Only truncate the parameter list if it's already been saved
1876 * in lpUC->lpszExtraInfo.
1878 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1879 len
= lpszParam
- lpszcp
;
1882 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1883 * newlines if necessary.
1885 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1886 if (lpsznewline
!= NULL
)
1887 len
= lpsznewline
- lpszcp
;
1889 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1891 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1892 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1894 WCHAR tmppath
[MAX_PATH
];
1898 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1903 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1904 tmppath
[len
] = '\0';
1913 /* if ends in \. or \.. append a backslash */
1914 if (tmppath
[len
- 1] == '.' &&
1915 (tmppath
[len
- 2] == '\\' ||
1916 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1918 if (len
< MAX_PATH
- 1)
1920 tmppath
[len
] = '\\';
1921 tmppath
[len
+1] = '\0';
1925 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1929 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1934 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1935 lpUC
->lpszUrlPath
[0] = 0;
1936 lpUC
->dwUrlPathLength
= 0;
1939 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1940 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1941 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1942 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1943 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1945 heap_free( lpszUrl_decode
);
1949 /***********************************************************************
1950 * InternetAttemptConnect (WININET.@)
1952 * Attempt to make a connection to the internet
1955 * ERROR_SUCCESS on success
1956 * Error value on failure
1959 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1962 return ERROR_SUCCESS
;
1966 /***********************************************************************
1967 * InternetCanonicalizeUrlA (WININET.@)
1969 * Escape unsafe characters and spaces
1976 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1977 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1980 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1982 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1983 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1985 if(dwFlags
& ICU_DECODE
)
1987 dwURLFlags
|= URL_UNESCAPE
;
1988 dwFlags
&= ~ICU_DECODE
;
1991 if(dwFlags
& ICU_ESCAPE
)
1993 dwURLFlags
|= URL_UNESCAPE
;
1994 dwFlags
&= ~ICU_ESCAPE
;
1997 if(dwFlags
& ICU_BROWSER_MODE
)
1999 dwURLFlags
|= URL_BROWSER_MODE
;
2000 dwFlags
&= ~ICU_BROWSER_MODE
;
2003 if(dwFlags
& ICU_NO_ENCODE
)
2005 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2006 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
2007 dwFlags
&= ~ICU_NO_ENCODE
;
2010 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
2012 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
2013 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2014 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2016 return (hr
== S_OK
) ? TRUE
: FALSE
;
2019 /***********************************************************************
2020 * InternetCanonicalizeUrlW (WININET.@)
2022 * Escape unsafe characters and spaces
2029 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2030 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2033 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2035 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2036 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2038 if(dwFlags
& ICU_DECODE
)
2040 dwURLFlags
|= URL_UNESCAPE
;
2041 dwFlags
&= ~ICU_DECODE
;
2044 if(dwFlags
& ICU_ESCAPE
)
2046 dwURLFlags
|= URL_UNESCAPE
;
2047 dwFlags
&= ~ICU_ESCAPE
;
2050 if(dwFlags
& ICU_BROWSER_MODE
)
2052 dwURLFlags
|= URL_BROWSER_MODE
;
2053 dwFlags
&= ~ICU_BROWSER_MODE
;
2056 if(dwFlags
& ICU_NO_ENCODE
)
2058 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2059 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
2060 dwFlags
&= ~ICU_NO_ENCODE
;
2063 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
2065 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
2066 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2067 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2069 return (hr
== S_OK
) ? TRUE
: FALSE
;
2072 /* #################################################### */
2074 static INTERNET_STATUS_CALLBACK
set_status_callback(
2075 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2077 INTERNET_STATUS_CALLBACK ret
;
2079 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2080 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2082 ret
= lpwh
->lpfnStatusCB
;
2083 lpwh
->lpfnStatusCB
= callback
;
2088 /***********************************************************************
2089 * InternetSetStatusCallbackA (WININET.@)
2091 * Sets up a callback function which is called as progress is made
2092 * during an operation.
2095 * Previous callback or NULL on success
2096 * INTERNET_INVALID_STATUS_CALLBACK on failure
2099 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2100 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2102 INTERNET_STATUS_CALLBACK retVal
;
2103 object_header_t
*lpwh
;
2105 TRACE("%p\n", hInternet
);
2107 if (!(lpwh
= get_handle_object(hInternet
)))
2108 return INTERNET_INVALID_STATUS_CALLBACK
;
2110 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2112 WININET_Release( lpwh
);
2116 /***********************************************************************
2117 * InternetSetStatusCallbackW (WININET.@)
2119 * Sets up a callback function which is called as progress is made
2120 * during an operation.
2123 * Previous callback or NULL on success
2124 * INTERNET_INVALID_STATUS_CALLBACK on failure
2127 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2128 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2130 INTERNET_STATUS_CALLBACK retVal
;
2131 object_header_t
*lpwh
;
2133 TRACE("%p\n", hInternet
);
2135 if (!(lpwh
= get_handle_object(hInternet
)))
2136 return INTERNET_INVALID_STATUS_CALLBACK
;
2138 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2140 WININET_Release( lpwh
);
2144 /***********************************************************************
2145 * InternetSetFilePointer (WININET.@)
2147 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2148 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2150 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2154 /***********************************************************************
2155 * InternetWriteFile (WININET.@)
2157 * Write data to an open internet file
2164 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2165 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2167 object_header_t
*lpwh
;
2170 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2172 lpwh
= get_handle_object( hFile
);
2174 WARN("Invalid handle\n");
2175 SetLastError(ERROR_INVALID_HANDLE
);
2179 if(lpwh
->vtbl
->WriteFile
) {
2180 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2182 WARN("No Writefile method.\n");
2183 res
= ERROR_INVALID_HANDLE
;
2186 WININET_Release( lpwh
);
2188 if(res
!= ERROR_SUCCESS
)
2190 return res
== ERROR_SUCCESS
;
2194 /***********************************************************************
2195 * InternetReadFile (WININET.@)
2197 * Read data from an open internet file
2204 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2205 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2207 object_header_t
*hdr
;
2208 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2210 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2212 hdr
= get_handle_object(hFile
);
2214 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2218 if(hdr
->vtbl
->ReadFile
)
2219 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2221 WININET_Release(hdr
);
2223 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2224 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2226 if(res
!= ERROR_SUCCESS
)
2228 return res
== ERROR_SUCCESS
;
2231 /***********************************************************************
2232 * InternetReadFileExA (WININET.@)
2234 * Read data from an open internet file
2237 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2238 * lpBuffersOut [I/O] Buffer.
2239 * dwFlags [I] Flags. See notes.
2240 * dwContext [I] Context for callbacks.
2247 * The parameter dwFlags include zero or more of the following flags:
2248 *|IRF_ASYNC - Makes the call asynchronous.
2249 *|IRF_SYNC - Makes the call synchronous.
2250 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2251 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2253 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2256 * InternetOpenUrlA(), HttpOpenRequestA()
2258 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2259 DWORD dwFlags
, DWORD_PTR dwContext
)
2261 object_header_t
*hdr
;
2262 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2264 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2266 hdr
= get_handle_object(hFile
);
2268 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2272 if(hdr
->vtbl
->ReadFileExA
)
2273 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
2275 WININET_Release(hdr
);
2277 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2278 res
, lpBuffersOut
->dwBufferLength
);
2280 if(res
!= ERROR_SUCCESS
)
2282 return res
== ERROR_SUCCESS
;
2285 /***********************************************************************
2286 * InternetReadFileExW (WININET.@)
2288 * InternetReadFileExA()
2290 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2291 DWORD dwFlags
, DWORD_PTR dwContext
)
2293 object_header_t
*hdr
;
2294 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2296 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2298 hdr
= get_handle_object(hFile
);
2300 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2304 if(hdr
->vtbl
->ReadFileExW
)
2305 res
= hdr
->vtbl
->ReadFileExW(hdr
, lpBuffer
, dwFlags
, dwContext
);
2307 WININET_Release(hdr
);
2309 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2310 res
, lpBuffer
->dwBufferLength
);
2312 if(res
!= ERROR_SUCCESS
)
2314 return res
== ERROR_SUCCESS
;
2317 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2319 /* FIXME: This function currently handles more options than it should. Options requiring
2320 * proper handles should be moved to proper functions */
2322 case INTERNET_OPTION_HTTP_VERSION
:
2323 if (*size
< sizeof(HTTP_VERSION_INFO
))
2324 return ERROR_INSUFFICIENT_BUFFER
;
2327 * Presently hardcoded to 1.1
2329 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2330 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2331 *size
= sizeof(HTTP_VERSION_INFO
);
2333 return ERROR_SUCCESS
;
2335 case INTERNET_OPTION_CONNECTED_STATE
:
2336 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2338 if (*size
< sizeof(ULONG
))
2339 return ERROR_INSUFFICIENT_BUFFER
;
2341 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2342 *size
= sizeof(ULONG
);
2344 return ERROR_SUCCESS
;
2346 case INTERNET_OPTION_PROXY
: {
2350 TRACE("Getting global proxy info\n");
2351 memset(&ai
, 0, sizeof(appinfo_t
));
2352 INTERNET_ConfigureProxy(&ai
);
2354 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2355 APPINFO_Destroy(&ai
.hdr
);
2359 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2360 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2362 if (*size
< sizeof(ULONG
))
2363 return ERROR_INSUFFICIENT_BUFFER
;
2365 *(ULONG
*)buffer
= max_conns
;
2366 *size
= sizeof(ULONG
);
2368 return ERROR_SUCCESS
;
2370 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2371 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2373 if (*size
< sizeof(ULONG
))
2374 return ERROR_INSUFFICIENT_BUFFER
;
2376 *(ULONG
*)buffer
= max_1_0_conns
;
2377 *size
= sizeof(ULONG
);
2379 return ERROR_SUCCESS
;
2381 case INTERNET_OPTION_SECURITY_FLAGS
:
2382 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2383 return ERROR_SUCCESS
;
2385 case INTERNET_OPTION_VERSION
: {
2386 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2388 TRACE("INTERNET_OPTION_VERSION\n");
2390 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2391 return ERROR_INSUFFICIENT_BUFFER
;
2393 memcpy(buffer
, &info
, sizeof(info
));
2394 *size
= sizeof(info
);
2396 return ERROR_SUCCESS
;
2399 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2400 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2401 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2402 DWORD res
= ERROR_SUCCESS
, i
;
2406 TRACE("Getting global proxy info\n");
2407 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2410 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2412 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2414 return ERROR_INSUFFICIENT_BUFFER
;
2417 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2418 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2419 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2421 switch (optionW
->dwOption
) {
2422 case INTERNET_PER_CONN_FLAGS
:
2424 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2426 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2429 case INTERNET_PER_CONN_PROXY_SERVER
:
2431 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2433 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2436 case INTERNET_PER_CONN_PROXY_BYPASS
:
2438 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2440 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2443 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2444 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2445 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2446 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2447 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2448 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2449 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2450 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2454 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2455 res
= ERROR_INVALID_PARAMETER
;
2463 case INTERNET_OPTION_REQUEST_FLAGS
:
2464 case INTERNET_OPTION_USER_AGENT
:
2466 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2467 case INTERNET_OPTION_POLICY
:
2468 return ERROR_INVALID_PARAMETER
;
2469 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2470 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2472 if (*size
< sizeof(ULONG
))
2473 return ERROR_INSUFFICIENT_BUFFER
;
2475 *(ULONG
*)buffer
= connect_timeout
;
2476 *size
= sizeof(ULONG
);
2478 return ERROR_SUCCESS
;
2481 FIXME("Stub for %d\n", option
);
2482 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2485 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2488 case INTERNET_OPTION_CONTEXT_VALUE
:
2490 return ERROR_INVALID_PARAMETER
;
2492 if (*size
< sizeof(DWORD_PTR
)) {
2493 *size
= sizeof(DWORD_PTR
);
2494 return ERROR_INSUFFICIENT_BUFFER
;
2497 return ERROR_INVALID_PARAMETER
;
2499 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2500 *size
= sizeof(DWORD_PTR
);
2501 return ERROR_SUCCESS
;
2503 case INTERNET_OPTION_REQUEST_FLAGS
:
2504 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2505 *size
= sizeof(DWORD
);
2506 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2508 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2509 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2510 WARN("Called on global option %u\n", option
);
2511 return ERROR_INTERNET_INVALID_OPERATION
;
2514 /* FIXME: we shouldn't call it here */
2515 return query_global_option(option
, buffer
, size
, unicode
);
2518 /***********************************************************************
2519 * InternetQueryOptionW (WININET.@)
2521 * Queries an options on the specified handle
2528 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2529 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2531 object_header_t
*hdr
;
2532 DWORD res
= ERROR_INVALID_HANDLE
;
2534 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2537 hdr
= get_handle_object(hInternet
);
2539 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2540 WININET_Release(hdr
);
2543 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2546 if(res
!= ERROR_SUCCESS
)
2548 return res
== ERROR_SUCCESS
;
2551 /***********************************************************************
2552 * InternetQueryOptionA (WININET.@)
2554 * Queries an options on the specified handle
2561 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2562 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2564 object_header_t
*hdr
;
2565 DWORD res
= ERROR_INVALID_HANDLE
;
2567 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2570 hdr
= get_handle_object(hInternet
);
2572 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2573 WININET_Release(hdr
);
2576 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2579 if(res
!= ERROR_SUCCESS
)
2581 return res
== ERROR_SUCCESS
;
2584 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2587 case INTERNET_OPTION_CALLBACK
:
2588 WARN("Not settable option %u\n", option
);
2589 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2590 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2591 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2592 WARN("Called on global option %u\n", option
);
2593 return ERROR_INTERNET_INVALID_OPERATION
;
2596 return ERROR_INTERNET_INVALID_OPTION
;
2599 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2602 case INTERNET_OPTION_CALLBACK
:
2603 WARN("Not global option %u\n", option
);
2604 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2606 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2607 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2609 if(size
!= sizeof(max_conns
))
2610 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2612 return ERROR_BAD_ARGUMENTS
;
2614 max_conns
= *(ULONG
*)buf
;
2615 return ERROR_SUCCESS
;
2617 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2618 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2620 if(size
!= sizeof(max_1_0_conns
))
2621 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2623 return ERROR_BAD_ARGUMENTS
;
2625 max_1_0_conns
= *(ULONG
*)buf
;
2626 return ERROR_SUCCESS
;
2628 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2629 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2631 if(size
!= sizeof(connect_timeout
))
2632 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2634 return ERROR_BAD_ARGUMENTS
;
2636 connect_timeout
= *(ULONG
*)buf
;
2637 return ERROR_SUCCESS
;
2639 case INTERNET_OPTION_SETTINGS_CHANGED
:
2640 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2641 collect_connections(COLLECT_CONNECTIONS
);
2642 return ERROR_SUCCESS
;
2645 return ERROR_INTERNET_INVALID_OPTION
;
2648 /***********************************************************************
2649 * InternetSetOptionW (WININET.@)
2651 * Sets an options on the specified handle
2658 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2659 LPVOID lpBuffer
, DWORD dwBufferLength
)
2661 object_header_t
*lpwhh
;
2665 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2667 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2669 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2671 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2673 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2675 WININET_Release(lpwhh
);
2677 if(res
!= ERROR_SUCCESS
)
2680 return res
== ERROR_SUCCESS
;
2685 case INTERNET_OPTION_HTTP_VERSION
:
2687 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2688 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2691 case INTERNET_OPTION_ERROR_MASK
:
2694 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2696 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2697 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2698 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2699 SetLastError(ERROR_INVALID_PARAMETER
);
2701 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2702 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2705 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2706 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2709 case INTERNET_OPTION_PROXY
:
2711 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2713 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2715 SetLastError(ERROR_INVALID_PARAMETER
);
2720 EnterCriticalSection( &WININET_cs
);
2721 free_global_proxy();
2722 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2725 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2727 global_proxy
->proxyEnabled
= 1;
2728 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2729 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2733 global_proxy
->proxyEnabled
= 0;
2734 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2737 LeaveCriticalSection( &WININET_cs
);
2741 /* In general, each type of object should handle
2742 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2743 * get silently dropped.
2745 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2746 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2751 case INTERNET_OPTION_CODEPAGE
:
2753 ULONG codepage
= *(ULONG
*)lpBuffer
;
2754 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2757 case INTERNET_OPTION_REQUEST_PRIORITY
:
2759 ULONG priority
= *(ULONG
*)lpBuffer
;
2760 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2763 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2765 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2766 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2769 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2771 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2772 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2775 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2776 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2778 case INTERNET_OPTION_END_BROWSER_SESSION
:
2779 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2781 case INTERNET_OPTION_CONNECTED_STATE
:
2782 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2784 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2785 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2787 case INTERNET_OPTION_SEND_TIMEOUT
:
2788 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2789 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2791 ULONG timeout
= *(ULONG
*)lpBuffer
;
2792 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2795 case INTERNET_OPTION_CONNECT_RETRIES
:
2797 ULONG retries
= *(ULONG
*)lpBuffer
;
2798 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2801 case INTERNET_OPTION_CONTEXT_VALUE
:
2805 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2808 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2810 SetLastError(ERROR_INVALID_PARAMETER
);
2814 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2817 case INTERNET_OPTION_SECURITY_FLAGS
:
2818 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2820 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2821 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2823 case INTERNET_OPTION_HTTP_DECODING
:
2824 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2825 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2828 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2829 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2830 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2833 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2834 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2835 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2838 case INTERNET_OPTION_CODEPAGE_PATH
:
2839 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2840 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2843 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2844 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2845 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2848 case INTERNET_OPTION_IDN
:
2849 FIXME("INTERNET_OPTION_IDN; STUB\n");
2850 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2853 case INTERNET_OPTION_POLICY
:
2854 SetLastError(ERROR_INVALID_PARAMETER
);
2857 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2858 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2863 INTERNET_LoadProxySettings(&pi
);
2865 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2866 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2868 switch (option
->dwOption
) {
2869 case INTERNET_PER_CONN_PROXY_SERVER
:
2870 heap_free(pi
.proxy
);
2871 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2874 case INTERNET_PER_CONN_FLAGS
:
2875 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2876 pi
.proxyEnabled
= 1;
2879 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2880 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2881 pi
.proxyEnabled
= 0;
2885 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2886 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2887 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2888 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2889 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2890 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2891 case INTERNET_PER_CONN_PROXY_BYPASS
:
2892 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2896 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2897 SetLastError(ERROR_INVALID_PARAMETER
);
2902 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2907 ret
= (res
== ERROR_SUCCESS
);
2911 FIXME("Option %d STUB\n",dwOption
);
2912 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2918 WININET_Release( lpwhh
);
2924 /***********************************************************************
2925 * InternetSetOptionA (WININET.@)
2927 * Sets an options on the specified handle.
2934 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2935 LPVOID lpBuffer
, DWORD dwBufferLength
)
2943 case INTERNET_OPTION_PROXY
:
2945 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2946 LPINTERNET_PROXY_INFOW piw
;
2947 DWORD proxlen
, prbylen
;
2950 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2951 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2952 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2953 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2954 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2955 piw
->dwAccessType
= pi
->dwAccessType
;
2956 prox
= (LPWSTR
) &piw
[1];
2957 prby
= &prox
[proxlen
+1];
2958 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2959 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2960 piw
->lpszProxy
= prox
;
2961 piw
->lpszProxyBypass
= prby
;
2964 case INTERNET_OPTION_USER_AGENT
:
2965 case INTERNET_OPTION_USERNAME
:
2966 case INTERNET_OPTION_PASSWORD
:
2967 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2969 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2970 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2973 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2975 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
2976 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
2977 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2978 wbuffer
= heap_alloc(wlen
);
2981 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2982 if (listA
->pszConnection
)
2984 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
2985 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
2986 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
2989 listW
->pszConnection
= NULL
;
2990 listW
->dwOptionCount
= listA
->dwOptionCount
;
2991 listW
->dwOptionError
= listA
->dwOptionError
;
2992 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
2994 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
2995 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
2996 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
2998 optW
->dwOption
= optA
->dwOption
;
3000 switch (optA
->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 if (optA
->Value
.pszValue
)
3008 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3009 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3010 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3013 optW
->Value
.pszValue
= NULL
;
3015 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3016 case INTERNET_PER_CONN_FLAGS
:
3017 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3018 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3020 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3021 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3024 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3025 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3033 wlen
= dwBufferLength
;
3036 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3038 if( lpBuffer
!= wbuffer
)
3040 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3042 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3044 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3045 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3046 switch (opt
->dwOption
) {
3047 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3048 case INTERNET_PER_CONN_PROXY_BYPASS
:
3049 case INTERNET_PER_CONN_PROXY_SERVER
:
3050 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3051 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3052 heap_free( opt
->Value
.pszValue
);
3058 heap_free( list
->pOptions
);
3060 heap_free( wbuffer
);
3067 /***********************************************************************
3068 * InternetSetOptionExA (WININET.@)
3070 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3071 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3073 FIXME("Flags %08x ignored\n", dwFlags
);
3074 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3077 /***********************************************************************
3078 * InternetSetOptionExW (WININET.@)
3080 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3081 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3083 FIXME("Flags %08x ignored\n", dwFlags
);
3084 if( dwFlags
& ~ISO_VALID_FLAGS
)
3086 SetLastError( ERROR_INVALID_PARAMETER
);
3089 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3092 static const WCHAR WININET_wkday
[7][4] =
3093 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3094 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3095 static const WCHAR WININET_month
[12][4] =
3096 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3097 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3098 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3100 /***********************************************************************
3101 * InternetTimeFromSystemTimeA (WININET.@)
3103 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3106 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3108 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3110 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3112 SetLastError(ERROR_INVALID_PARAMETER
);
3116 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3118 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3122 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3123 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3128 /***********************************************************************
3129 * InternetTimeFromSystemTimeW (WININET.@)
3131 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3133 static const WCHAR date
[] =
3134 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3135 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3137 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3139 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3141 SetLastError(ERROR_INVALID_PARAMETER
);
3145 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3147 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3151 sprintfW( string
, date
,
3152 WININET_wkday
[time
->wDayOfWeek
],
3154 WININET_month
[time
->wMonth
- 1],
3163 /***********************************************************************
3164 * InternetTimeToSystemTimeA (WININET.@)
3166 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3171 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3173 stringW
= heap_strdupAtoW(string
);
3176 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3177 heap_free( stringW
);
3182 /***********************************************************************
3183 * InternetTimeToSystemTimeW (WININET.@)
3185 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3188 const WCHAR
*s
= string
;
3191 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3193 if (!string
|| !time
) return FALSE
;
3195 /* Windows does this too */
3196 GetSystemTime( time
);
3198 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3199 * a SYSTEMTIME structure.
3202 while (*s
&& !isalphaW( *s
)) s
++;
3203 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3204 time
->wDayOfWeek
= 7;
3206 for (i
= 0; i
< 7; i
++)
3208 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3209 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3210 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3212 time
->wDayOfWeek
= i
;
3217 if (time
->wDayOfWeek
> 6) return TRUE
;
3218 while (*s
&& !isdigitW( *s
)) s
++;
3219 time
->wDay
= strtolW( s
, &end
, 10 );
3222 while (*s
&& !isalphaW( *s
)) s
++;
3223 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3226 for (i
= 0; i
< 12; i
++)
3228 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3229 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3230 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3232 time
->wMonth
= i
+ 1;
3236 if (time
->wMonth
== 0) return TRUE
;
3238 while (*s
&& !isdigitW( *s
)) s
++;
3239 if (*s
== '\0') return TRUE
;
3240 time
->wYear
= strtolW( s
, &end
, 10 );
3243 while (*s
&& !isdigitW( *s
)) s
++;
3244 if (*s
== '\0') return TRUE
;
3245 time
->wHour
= strtolW( s
, &end
, 10 );
3248 while (*s
&& !isdigitW( *s
)) s
++;
3249 if (*s
== '\0') return TRUE
;
3250 time
->wMinute
= strtolW( s
, &end
, 10 );
3253 while (*s
&& !isdigitW( *s
)) s
++;
3254 if (*s
== '\0') return TRUE
;
3255 time
->wSecond
= strtolW( s
, &end
, 10 );
3258 time
->wMilliseconds
= 0;
3262 /***********************************************************************
3263 * InternetCheckConnectionW (WININET.@)
3265 * Pings a requested host to check internet connection
3268 * TRUE on success and FALSE on failure. If a failure then
3269 * ERROR_NOT_CONNECTED is placed into GetLastError
3272 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3275 * this is a kludge which runs the resident ping program and reads the output.
3277 * Anyone have a better idea?
3281 static const CHAR ping
[] = "ping -c 1 ";
3282 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3283 CHAR
*command
= NULL
;
3284 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3292 * Crack or set the Address
3294 if (lpszUrl
== NULL
)
3297 * According to the doc we are supposed to use the ip for the next
3298 * server in the WnInet internal server database. I have
3299 * no idea what that is or how to get it.
3301 * So someone needs to implement this.
3303 FIXME("Unimplemented with URL of NULL\n");
3308 URL_COMPONENTSW components
;
3310 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3311 components
.lpszHostName
= (LPWSTR
)hostW
;
3312 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3314 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3317 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3318 port
= components
.nPort
;
3319 TRACE("port: %d\n", port
);
3322 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3324 struct sockaddr_storage saddr
;
3325 socklen_t sa_len
= sizeof(saddr
);
3328 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3330 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3333 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3341 * Build our ping command
3343 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3344 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3345 strcpy(command
,ping
);
3346 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3347 strcat(command
,redirect
);
3349 TRACE("Ping command is : %s\n",command
);
3351 status
= system(command
);
3353 TRACE("Ping returned a code of %i\n",status
);
3355 /* Ping return code of 0 indicates success */
3361 heap_free( command
);
3363 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3369 /***********************************************************************
3370 * InternetCheckConnectionA (WININET.@)
3372 * Pings a requested host to check internet connection
3375 * TRUE on success and FALSE on failure. If a failure then
3376 * ERROR_NOT_CONNECTED is placed into GetLastError
3379 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3385 url
= heap_strdupAtoW(lpszUrl
);
3390 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3397 /**********************************************************
3398 * INTERNET_InternetOpenUrlW (internal)
3403 * handle of connection or NULL on failure
3405 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3406 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3408 URL_COMPONENTSW urlComponents
;
3409 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3410 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3411 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3412 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3413 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3415 HINTERNET client
= NULL
, client1
= NULL
;
3418 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3419 dwHeadersLength
, dwFlags
, dwContext
);
3421 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3422 urlComponents
.lpszScheme
= protocol
;
3423 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3424 urlComponents
.lpszHostName
= hostName
;
3425 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3426 urlComponents
.lpszUserName
= userName
;
3427 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3428 urlComponents
.lpszPassword
= password
;
3429 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3430 urlComponents
.lpszUrlPath
= path
;
3431 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3432 urlComponents
.lpszExtraInfo
= extra
;
3433 urlComponents
.dwExtraInfoLength
= 1024;
3434 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3436 switch(urlComponents
.nScheme
) {
3437 case INTERNET_SCHEME_FTP
:
3438 if(urlComponents
.nPort
== 0)
3439 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3440 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3441 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3444 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3445 if(client1
== NULL
) {
3446 InternetCloseHandle(client
);
3451 case INTERNET_SCHEME_HTTP
:
3452 case INTERNET_SCHEME_HTTPS
: {
3453 static const WCHAR szStars
[] = { '*','/','*', 0 };
3454 LPCWSTR accept
[2] = { szStars
, NULL
};
3455 if(urlComponents
.nPort
== 0) {
3456 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3457 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3459 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3461 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3463 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3464 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3465 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3466 if(res
!= ERROR_SUCCESS
) {
3467 INTERNET_SetLastError(res
);
3471 if (urlComponents
.dwExtraInfoLength
) {
3473 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3475 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3477 InternetCloseHandle(client
);
3480 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3481 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3482 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3483 heap_free(path_extra
);
3486 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3488 if(client1
== NULL
) {
3489 InternetCloseHandle(client
);
3492 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3493 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3494 GetLastError() != ERROR_IO_PENDING
) {
3495 InternetCloseHandle(client1
);
3500 case INTERNET_SCHEME_GOPHER
:
3501 /* gopher doesn't seem to be implemented in wine, but it's supposed
3502 * to be supported by InternetOpenUrlA. */
3504 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3508 TRACE(" %p <--\n", client1
);
3513 /**********************************************************
3514 * InternetOpenUrlW (WININET.@)
3519 * handle of connection or NULL on failure
3521 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3523 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3524 appinfo_t
*hIC
= (appinfo_t
*) workRequest
->hdr
;
3528 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3529 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3530 heap_free(req
->lpszUrl
);
3531 heap_free(req
->lpszHeaders
);
3534 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3535 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3537 HINTERNET ret
= NULL
;
3538 appinfo_t
*hIC
= NULL
;
3540 if (TRACE_ON(wininet
)) {
3541 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3542 dwHeadersLength
, dwFlags
, dwContext
);
3544 dump_INTERNET_FLAGS(dwFlags
);
3549 SetLastError(ERROR_INVALID_PARAMETER
);
3553 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3554 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3555 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3559 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3560 WORKREQUEST workRequest
;
3561 struct WORKREQ_INTERNETOPENURLW
*req
;
3563 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3564 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3565 req
= &workRequest
.u
.InternetOpenUrlW
;
3566 req
->lpszUrl
= heap_strdupW(lpszUrl
);
3567 req
->lpszHeaders
= heap_strdupW(lpszHeaders
);
3568 req
->dwHeadersLength
= dwHeadersLength
;
3569 req
->dwFlags
= dwFlags
;
3570 req
->dwContext
= dwContext
;
3572 INTERNET_AsyncCall(&workRequest
);
3574 * This is from windows.
3576 SetLastError(ERROR_IO_PENDING
);
3578 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3583 WININET_Release( &hIC
->hdr
);
3584 TRACE(" %p <--\n", ret
);
3589 /**********************************************************
3590 * InternetOpenUrlA (WININET.@)
3595 * handle of connection or NULL on failure
3597 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3598 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3600 HINTERNET rc
= NULL
;
3601 DWORD lenHeaders
= 0;
3602 LPWSTR szUrl
= NULL
;
3603 LPWSTR szHeaders
= NULL
;
3608 szUrl
= heap_strdupAtoW(lpszUrl
);
3614 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3615 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3620 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3623 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3624 lenHeaders
, dwFlags
, dwContext
);
3627 heap_free(szHeaders
);
3632 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3634 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3638 lpwite
->dwError
= 0;
3639 lpwite
->response
[0] = '\0';
3642 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3651 /***********************************************************************
3652 * INTERNET_SetLastError (internal)
3654 * Set last thread specific error
3659 void INTERNET_SetLastError(DWORD dwError
)
3661 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3664 lpwite
= INTERNET_AllocThreadError();
3666 SetLastError(dwError
);
3668 lpwite
->dwError
= dwError
;
3672 /***********************************************************************
3673 * INTERNET_GetLastError (internal)
3675 * Get last thread specific error
3680 DWORD
INTERNET_GetLastError(void)
3682 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3683 if (!lpwite
) return 0;
3684 /* TlsGetValue clears last error, so set it again here */
3685 SetLastError(lpwite
->dwError
);
3686 return lpwite
->dwError
;
3690 /***********************************************************************
3691 * INTERNET_WorkerThreadFunc (internal)
3693 * Worker thread execution function
3698 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3700 LPWORKREQUEST lpRequest
= lpvParam
;
3701 WORKREQUEST workRequest
;
3705 workRequest
= *lpRequest
;
3706 heap_free(lpRequest
);
3708 workRequest
.asyncproc(&workRequest
);
3709 WININET_Release( workRequest
.hdr
);
3711 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3713 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3714 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3720 /***********************************************************************
3721 * INTERNET_AsyncCall (internal)
3723 * Retrieves work request from queue
3728 DWORD
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3731 LPWORKREQUEST lpNewRequest
;
3735 lpNewRequest
= heap_alloc(sizeof(WORKREQUEST
));
3737 return ERROR_OUTOFMEMORY
;
3739 *lpNewRequest
= *lpWorkRequest
;
3741 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3744 heap_free(lpNewRequest
);
3745 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3747 return ERROR_SUCCESS
;
3751 /***********************************************************************
3752 * INTERNET_GetResponseBuffer (internal)
3757 LPSTR
INTERNET_GetResponseBuffer(void)
3759 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3761 lpwite
= INTERNET_AllocThreadError();
3763 return lpwite
->response
;
3766 /***********************************************************************
3767 * INTERNET_GetNextLine (internal)
3769 * Parse next line in directory string listing
3772 * Pointer to beginning of next line
3777 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3780 BOOL bSuccess
= FALSE
;
3782 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3787 pfd
.events
= POLLIN
;
3789 while (nRecv
< MAX_REPLY_LEN
)
3791 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3793 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3795 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3799 if (lpszBuffer
[nRecv
] == '\n')
3804 if (lpszBuffer
[nRecv
] != '\r')
3809 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3817 lpszBuffer
[nRecv
] = '\0';
3819 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3828 /**********************************************************
3829 * InternetQueryDataAvailable (WININET.@)
3831 * Determines how much data is available to be read.
3834 * TRUE on success, FALSE if an error occurred. If
3835 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3836 * no data is presently available, FALSE is returned with
3837 * the last error ERROR_IO_PENDING; a callback with status
3838 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3839 * data is available.
3841 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3842 LPDWORD lpdwNumberOfBytesAvailable
,
3843 DWORD dwFlags
, DWORD_PTR dwContext
)
3845 object_header_t
*hdr
;
3848 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3850 hdr
= get_handle_object( hFile
);
3852 SetLastError(ERROR_INVALID_HANDLE
);
3856 if(hdr
->vtbl
->QueryDataAvailable
) {
3857 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3859 WARN("wrong handle\n");
3860 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3863 WININET_Release(hdr
);
3865 if(res
!= ERROR_SUCCESS
)
3867 return res
== ERROR_SUCCESS
;
3871 /***********************************************************************
3872 * InternetLockRequestFile (WININET.@)
3874 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3881 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3888 /***********************************************************************
3889 * InternetAutodial (WININET.@)
3891 * On windows this function is supposed to dial the default internet
3892 * connection. We don't want to have Wine dial out to the internet so
3893 * we return TRUE by default. It might be nice to check if we are connected.
3900 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3904 /* Tell that we are connected to the internet. */
3908 /***********************************************************************
3909 * InternetAutodialHangup (WININET.@)
3911 * Hangs up a connection made with InternetAutodial
3920 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3924 /* we didn't dial, we don't disconnect */
3928 /***********************************************************************
3929 * InternetCombineUrlA (WININET.@)
3931 * Combine a base URL with a relative URL
3939 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3940 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3945 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3947 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3948 dwFlags
^= ICU_NO_ENCODE
;
3949 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3954 /***********************************************************************
3955 * InternetCombineUrlW (WININET.@)
3957 * Combine a base URL with a relative URL
3965 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3966 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3971 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3973 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3974 dwFlags
^= ICU_NO_ENCODE
;
3975 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3980 /* max port num is 65535 => 5 digits */
3981 #define MAX_WORD_DIGITS 5
3983 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3984 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3985 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3986 (url)->dw##component##Length : strlen((url)->lpsz##component))
3988 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3990 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3991 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3993 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3994 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3996 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3997 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3999 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
4000 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4003 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4009 /* opaque urls do not fit into the standard url hierarchy and don't have
4010 * two following slashes */
4011 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4013 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4014 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4015 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4016 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4017 (nScheme
!= INTERNET_SCHEME_FILE
);
4020 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4023 if (scheme
< INTERNET_SCHEME_FIRST
)
4025 index
= scheme
- INTERNET_SCHEME_FIRST
;
4026 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4028 return (LPCWSTR
)url_schemes
[index
];
4031 /* we can calculate using ansi strings because we're just
4032 * calculating string length, not size
4034 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4035 LPDWORD lpdwUrlLength
)
4037 INTERNET_SCHEME nScheme
;
4041 if (lpUrlComponents
->lpszScheme
)
4043 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4044 *lpdwUrlLength
+= dwLen
;
4045 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4051 nScheme
= lpUrlComponents
->nScheme
;
4053 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4054 nScheme
= INTERNET_SCHEME_HTTP
;
4055 scheme
= INTERNET_GetSchemeString(nScheme
);
4056 *lpdwUrlLength
+= strlenW(scheme
);
4059 (*lpdwUrlLength
)++; /* ':' */
4060 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4061 *lpdwUrlLength
+= strlen("//");
4063 if (lpUrlComponents
->lpszUserName
)
4065 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4066 *lpdwUrlLength
+= strlen("@");
4070 if (lpUrlComponents
->lpszPassword
)
4072 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4077 if (lpUrlComponents
->lpszPassword
)
4079 *lpdwUrlLength
+= strlen(":");
4080 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4083 if (lpUrlComponents
->lpszHostName
)
4085 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4087 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4089 char szPort
[MAX_WORD_DIGITS
+1];
4091 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4092 *lpdwUrlLength
+= strlen(szPort
);
4093 *lpdwUrlLength
+= strlen(":");
4096 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4097 (*lpdwUrlLength
)++; /* '/' */
4100 if (lpUrlComponents
->lpszUrlPath
)
4101 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4103 if (lpUrlComponents
->lpszExtraInfo
)
4104 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4109 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4113 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4115 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4116 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4117 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4118 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4119 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4120 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4121 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4122 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4123 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4125 if (lpUrlComponents
->lpszScheme
)
4127 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4128 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4129 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4130 -1, urlCompW
->lpszScheme
, len
);
4133 if (lpUrlComponents
->lpszHostName
)
4135 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4136 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4137 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4138 -1, urlCompW
->lpszHostName
, len
);
4141 if (lpUrlComponents
->lpszUserName
)
4143 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4144 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4145 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4146 -1, urlCompW
->lpszUserName
, len
);
4149 if (lpUrlComponents
->lpszPassword
)
4151 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4152 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4153 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4154 -1, urlCompW
->lpszPassword
, len
);
4157 if (lpUrlComponents
->lpszUrlPath
)
4159 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4160 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4161 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4162 -1, urlCompW
->lpszUrlPath
, len
);
4165 if (lpUrlComponents
->lpszExtraInfo
)
4167 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4168 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4169 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4170 -1, urlCompW
->lpszExtraInfo
, len
);
4174 /***********************************************************************
4175 * InternetCreateUrlA (WININET.@)
4177 * See InternetCreateUrlW.
4179 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4180 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4184 URL_COMPONENTSW urlCompW
;
4186 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4188 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4190 SetLastError(ERROR_INVALID_PARAMETER
);
4194 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4197 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4199 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4201 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4202 *lpdwUrlLength
/= sizeof(WCHAR
);
4204 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4205 * minus one, so add one to leave room for NULL terminator
4208 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4210 heap_free(urlCompW
.lpszScheme
);
4211 heap_free(urlCompW
.lpszHostName
);
4212 heap_free(urlCompW
.lpszUserName
);
4213 heap_free(urlCompW
.lpszPassword
);
4214 heap_free(urlCompW
.lpszUrlPath
);
4215 heap_free(urlCompW
.lpszExtraInfo
);
4220 /***********************************************************************
4221 * InternetCreateUrlW (WININET.@)
4223 * Creates a URL from its component parts.
4226 * lpUrlComponents [I] URL Components.
4227 * dwFlags [I] Flags. See notes.
4228 * lpszUrl [I] Buffer in which to store the created URL.
4229 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4230 * lpszUrl in characters. On output, the number of bytes
4231 * required to store the URL including terminator.
4235 * The dwFlags parameter can be zero or more of the following:
4236 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4243 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4244 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4247 INTERNET_SCHEME nScheme
;
4249 static const WCHAR slashSlashW
[] = {'/','/'};
4250 static const WCHAR fmtW
[] = {'%','u',0};
4252 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4254 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4256 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4260 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4263 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4265 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4266 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4270 *lpdwUrlLength
= dwLen
;
4275 if (lpUrlComponents
->lpszScheme
)
4277 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4278 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4281 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4286 nScheme
= lpUrlComponents
->nScheme
;
4288 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4289 nScheme
= INTERNET_SCHEME_HTTP
;
4291 scheme
= INTERNET_GetSchemeString(nScheme
);
4292 dwLen
= strlenW(scheme
);
4293 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4297 /* all schemes are followed by at least a colon */
4301 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4303 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4304 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4307 if (lpUrlComponents
->lpszUserName
)
4309 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4310 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4313 if (lpUrlComponents
->lpszPassword
)
4318 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4319 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4327 if (lpUrlComponents
->lpszHostName
)
4329 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4330 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4333 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4335 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4337 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4340 dwLen
= strlenW(szPort
);
4341 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4345 /* add slash between hostname and path if necessary */
4346 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4353 if (lpUrlComponents
->lpszUrlPath
)
4355 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4356 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4360 if (lpUrlComponents
->lpszExtraInfo
)
4362 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4363 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4372 /***********************************************************************
4373 * InternetConfirmZoneCrossingA (WININET.@)
4376 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4378 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4379 return ERROR_SUCCESS
;
4382 /***********************************************************************
4383 * InternetConfirmZoneCrossingW (WININET.@)
4386 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4388 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4389 return ERROR_SUCCESS
;
4392 static DWORD zone_preference
= 3;
4394 /***********************************************************************
4395 * PrivacySetZonePreferenceW (WININET.@)
4397 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4399 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4401 zone_preference
= template;
4405 /***********************************************************************
4406 * PrivacyGetZonePreferenceW (WININET.@)
4408 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4409 LPWSTR preference
, LPDWORD length
)
4411 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4413 if (template) *template = zone_preference
;
4417 /***********************************************************************
4418 * InternetGetSecurityInfoByURLA (WININET.@)
4420 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4422 FIXME("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4426 /***********************************************************************
4427 * InternetGetSecurityInfoByURLW (WININET.@)
4429 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4431 FIXME("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4435 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4436 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4438 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4439 lpdwConnection
, dwReserved
);
4440 return ERROR_SUCCESS
;
4443 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4444 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4446 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4447 lpdwConnection
, dwReserved
);
4448 return ERROR_SUCCESS
;
4451 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4453 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4457 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4459 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4463 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4465 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4466 return ERROR_SUCCESS
;
4469 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4472 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4473 debugstr_w(pwszTarget
), pbHexHash
);
4477 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4479 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4483 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4485 FIXME("(%p, %08lx) stub\n", a
, b
);
4489 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4491 FIXME("%p: stub\n", parent
);