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;
113 static const WCHAR szInternetSettings
[] =
114 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
115 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
116 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
117 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
118 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
120 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
122 UINT_PTR handle
= 0, num
;
123 object_header_t
*ret
;
127 ret
= heap_alloc_zero(size
);
131 list_init(&ret
->children
);
133 EnterCriticalSection( &WININET_cs
);
135 if(!handle_table_size
) {
137 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
140 handle_table_size
= num
;
145 }else if(next_handle
== handle_table_size
) {
146 num
= handle_table_size
* 2;
147 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
150 handle_table_size
= num
;
157 handle
= next_handle
;
158 if(handle_table
[handle
])
159 ERR("handle isn't free but should be\n");
160 handle_table
[handle
] = ret
;
161 ret
->valid_handle
= TRUE
;
163 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
167 LeaveCriticalSection( &WININET_cs
);
176 ret
->hInternet
= (HINTERNET
)handle
;
179 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
180 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
186 object_header_t
*WININET_AddRef( object_header_t
*info
)
188 ULONG refs
= InterlockedIncrement(&info
->refs
);
189 TRACE("%p -> refcount = %d\n", info
, refs
);
193 object_header_t
*get_handle_object( HINTERNET hinternet
)
195 object_header_t
*info
= NULL
;
196 UINT_PTR handle
= (UINT_PTR
) hinternet
;
198 EnterCriticalSection( &WININET_cs
);
200 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
201 info
= WININET_AddRef(handle_table
[handle
]);
203 LeaveCriticalSection( &WININET_cs
);
205 TRACE("handle %ld -> %p\n", handle
, info
);
210 static void invalidate_handle(object_header_t
*info
)
212 object_header_t
*child
, *next
;
214 if(!info
->valid_handle
)
216 info
->valid_handle
= FALSE
;
218 /* Free all children as native does */
219 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
221 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
222 invalidate_handle( child
);
225 WININET_Release(info
);
228 BOOL
WININET_Release( object_header_t
*info
)
230 ULONG refs
= InterlockedDecrement(&info
->refs
);
231 TRACE( "object %p refcount = %d\n", info
, refs
);
234 invalidate_handle(info
);
235 if ( info
->vtbl
->CloseConnection
)
237 TRACE( "closing connection %p\n", info
);
238 info
->vtbl
->CloseConnection( info
);
240 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
241 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
242 || !(info
->dwInternalFlags
& INET_OPENURL
))
244 INTERNET_SendCallback(info
, info
->dwContext
,
245 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
248 TRACE( "destroying object %p\n", info
);
249 if ( info
->htype
!= WH_HINIT
)
250 list_remove( &info
->entry
);
251 info
->vtbl
->Destroy( info
);
253 if(info
->hInternet
) {
254 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
256 EnterCriticalSection( &WININET_cs
);
258 handle_table
[handle
] = NULL
;
259 if(next_handle
> handle
)
260 next_handle
= handle
;
262 LeaveCriticalSection( &WININET_cs
);
270 /***********************************************************************
271 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
274 * hinstDLL [I] handle to the DLL's instance
276 * lpvReserved [I] reserved, must be NULL
283 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
285 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
288 case DLL_PROCESS_ATTACH
:
290 g_dwTlsErrIndex
= TlsAlloc();
292 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
295 URLCacheContainers_CreateDefaults();
297 WININET_hModule
= hinstDLL
;
300 case DLL_THREAD_ATTACH
:
303 case DLL_THREAD_DETACH
:
304 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
306 heap_free(TlsGetValue(g_dwTlsErrIndex
));
310 case DLL_PROCESS_DETACH
:
311 collect_connections(TRUE
);
313 URLCacheContainers_DeleteAll();
315 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
317 heap_free(TlsGetValue(g_dwTlsErrIndex
));
318 TlsFree(g_dwTlsErrIndex
);
325 /***********************************************************************
326 * INTERNET_SaveProxySettings
328 * Stores the proxy settings given by lpwai into the registry
331 * ERROR_SUCCESS if no error, or error code on fail
333 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
338 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
341 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
349 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
357 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
365 return ERROR_SUCCESS
;
368 /***********************************************************************
369 * INTERNET_FindProxyForProtocol
371 * Searches the proxy string for a proxy of the given protocol.
372 * Returns the found proxy, or the default proxy if none of the given
376 * szProxy [In] proxy string to search
377 * proto [In] protocol to search for, e.g. "http"
378 * foundProxy [Out] found proxy
379 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
382 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
383 * *foundProxyLen is set to the required size in WCHARs, including the
384 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
386 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
391 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
393 /* First, look for the specified protocol (proto=scheme://host:port) */
394 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
398 if (!(end
= strchrW(ptr
, ' ')))
399 end
= ptr
+ strlenW(ptr
);
400 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
401 equal
- ptr
== strlenW(proto
) &&
402 !strncmpiW(proto
, ptr
, strlenW(proto
)))
404 if (end
- equal
> *foundProxyLen
)
406 WARN("buffer too short for %s\n",
407 debugstr_wn(equal
+ 1, end
- equal
- 1));
408 *foundProxyLen
= end
- equal
;
409 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
413 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
414 foundProxy
[end
- equal
] = 0;
425 /* It wasn't found: look for no protocol */
426 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
430 if (!(end
= strchrW(ptr
, ' ')))
431 end
= ptr
+ strlenW(ptr
);
432 if (!(equal
= strchrW(ptr
, '=')))
434 if (end
- ptr
+ 1 > *foundProxyLen
)
436 WARN("buffer too short for %s\n",
437 debugstr_wn(ptr
, end
- ptr
));
438 *foundProxyLen
= end
- ptr
+ 1;
439 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
443 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
444 foundProxy
[end
- ptr
] = 0;
455 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
456 debugstr_w(foundProxy
));
460 /***********************************************************************
461 * InternetInitializeAutoProxyDll (WININET.@)
463 * Setup the internal proxy
472 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
475 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
479 /***********************************************************************
480 * DetectAutoProxyUrl (WININET.@)
482 * Auto detect the proxy url
488 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
489 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
492 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
496 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
498 heap_free(lpwpi
->proxy
);
499 heap_free(lpwpi
->proxyBypass
);
502 static proxyinfo_t
*global_proxy
;
504 static void free_global_proxy( void )
506 EnterCriticalSection( &WININET_cs
);
509 FreeProxyInfo( global_proxy
);
510 heap_free( global_proxy
);
512 LeaveCriticalSection( &WININET_cs
);
515 /***********************************************************************
516 * INTERNET_LoadProxySettings
518 * Loads proxy information from process-wide global settings, the registry,
519 * or the environment into lpwpi.
521 * The caller should call FreeProxyInfo when done with lpwpi.
524 * The proxy may be specified in the form 'http=proxy.my.org'
525 * Presumably that means there can be ftp=ftpproxy.my.org too.
527 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
534 EnterCriticalSection( &WININET_cs
);
537 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
538 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
539 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
541 LeaveCriticalSection( &WININET_cs
);
543 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
547 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
549 lpwpi
->proxyEnabled
= 0;
550 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
557 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
559 TRACE("Proxy is enabled.\n");
561 /* figure out how much memory the proxy setting takes */
562 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
565 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
567 if (!(szProxy
= heap_alloc(len
)))
570 return ERROR_OUTOFMEMORY
;
572 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
574 /* find the http proxy, and strip away everything else */
575 p
= strstrW( szProxy
, szHttp
);
578 p
+= lstrlenW( szHttp
);
579 lstrcpyW( szProxy
, p
);
581 p
= strchrW( szProxy
, ' ' );
584 lpwpi
->proxy
= szProxy
;
586 TRACE("http proxy = %s\n", debugstr_w(lpwpi
->proxy
));
590 TRACE("No proxy server settings in registry.\n");
598 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
599 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
600 return ERROR_OUTOFMEMORY
;
601 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
603 lpwpi
->proxyEnabled
= 1;
604 lpwpi
->proxy
= envproxyW
;
606 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
610 lpwpi
->proxyBypass
= NULL
;
612 return ERROR_SUCCESS
;
615 /***********************************************************************
616 * INTERNET_ConfigureProxy
618 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
622 if (INTERNET_LoadProxySettings( &wpi
))
625 if (wpi
.proxyEnabled
)
627 WCHAR proxyurl
[INTERNET_MAX_URL_LENGTH
];
628 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
];
629 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
630 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
631 URL_COMPONENTSW UrlComponents
;
633 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
634 UrlComponents
.dwSchemeLength
= 0;
635 UrlComponents
.lpszHostName
= hostname
;
636 UrlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
637 UrlComponents
.lpszUserName
= username
;
638 UrlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
639 UrlComponents
.lpszPassword
= password
;
640 UrlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
641 UrlComponents
.dwUrlPathLength
= 0;
642 UrlComponents
.dwExtraInfoLength
= 0;
644 if(InternetCrackUrlW(wpi
.proxy
, 0, 0, &UrlComponents
))
646 static const WCHAR szFormat
[] = { 'h','t','t','p',':','/','/','%','s',':','%','u',0 };
648 if(UrlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
649 UrlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
650 sprintfW(proxyurl
, szFormat
, hostname
, UrlComponents
.nPort
);
652 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
653 lpwai
->proxy
= heap_strdupW(proxyurl
);
654 if (UrlComponents
.dwUserNameLength
)
656 lpwai
->proxyUsername
= heap_strdupW(UrlComponents
.lpszUserName
);
657 lpwai
->proxyPassword
= heap_strdupW(UrlComponents
.lpszPassword
);
660 TRACE("http proxy = %s\n", debugstr_w(lpwai
->proxy
));
665 TRACE("Failed to parse proxy: %s\n", debugstr_w(wpi
.proxy
));
670 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
674 /***********************************************************************
675 * dump_INTERNET_FLAGS
677 * Helper function to TRACE the internet flags.
683 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
685 #define FE(x) { x, #x }
686 static const wininet_flag_info flag
[] = {
687 FE(INTERNET_FLAG_RELOAD
),
688 FE(INTERNET_FLAG_RAW_DATA
),
689 FE(INTERNET_FLAG_EXISTING_CONNECT
),
690 FE(INTERNET_FLAG_ASYNC
),
691 FE(INTERNET_FLAG_PASSIVE
),
692 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
693 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
694 FE(INTERNET_FLAG_FROM_CACHE
),
695 FE(INTERNET_FLAG_SECURE
),
696 FE(INTERNET_FLAG_KEEP_CONNECTION
),
697 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
698 FE(INTERNET_FLAG_READ_PREFETCH
),
699 FE(INTERNET_FLAG_NO_COOKIES
),
700 FE(INTERNET_FLAG_NO_AUTH
),
701 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
702 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
703 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
704 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
705 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
706 FE(INTERNET_FLAG_RESYNCHRONIZE
),
707 FE(INTERNET_FLAG_HYPERLINK
),
708 FE(INTERNET_FLAG_NO_UI
),
709 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
710 FE(INTERNET_FLAG_CACHE_ASYNC
),
711 FE(INTERNET_FLAG_FORMS_SUBMIT
),
712 FE(INTERNET_FLAG_NEED_FILE
),
713 FE(INTERNET_FLAG_TRANSFER_ASCII
),
714 FE(INTERNET_FLAG_TRANSFER_BINARY
)
719 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
720 if (flag
[i
].val
& dwFlags
) {
721 TRACE(" %s", flag
[i
].name
);
722 dwFlags
&= ~flag
[i
].val
;
726 TRACE(" Unknown flags (%08x)\n", dwFlags
);
731 /***********************************************************************
732 * INTERNET_CloseHandle (internal)
734 * Close internet handle
737 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
739 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
743 heap_free(lpwai
->agent
);
744 heap_free(lpwai
->proxy
);
745 heap_free(lpwai
->proxyBypass
);
746 heap_free(lpwai
->proxyUsername
);
747 heap_free(lpwai
->proxyPassword
);
750 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
752 appinfo_t
*ai
= (appinfo_t
*)hdr
;
755 case INTERNET_OPTION_HANDLE_TYPE
:
756 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
758 if (*size
< sizeof(ULONG
))
759 return ERROR_INSUFFICIENT_BUFFER
;
761 *size
= sizeof(DWORD
);
762 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
763 return ERROR_SUCCESS
;
765 case INTERNET_OPTION_USER_AGENT
: {
768 TRACE("INTERNET_OPTION_USER_AGENT\n");
773 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
775 *size
= (len
+ 1) * sizeof(WCHAR
);
776 if(!buffer
|| bufsize
< *size
)
777 return ERROR_INSUFFICIENT_BUFFER
;
780 strcpyW(buffer
, ai
->agent
);
782 *(WCHAR
*)buffer
= 0;
783 /* If the buffer is copied, the returned length doesn't include
784 * the NULL terminator.
786 *size
= len
* sizeof(WCHAR
);
789 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
792 if(!buffer
|| bufsize
< *size
)
793 return ERROR_INSUFFICIENT_BUFFER
;
796 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
799 /* If the buffer is copied, the returned length doesn't include
800 * the NULL terminator.
805 return ERROR_SUCCESS
;
808 case INTERNET_OPTION_PROXY
:
809 if(!size
) return ERROR_INVALID_PARAMETER
;
811 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
812 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
813 LPWSTR proxy
, proxy_bypass
;
816 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
818 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
819 if (*size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
821 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
822 return ERROR_INSUFFICIENT_BUFFER
;
824 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
825 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
827 pi
->dwAccessType
= ai
->accessType
;
828 pi
->lpszProxy
= NULL
;
829 pi
->lpszProxyBypass
= NULL
;
831 lstrcpyW(proxy
, ai
->proxy
);
832 pi
->lpszProxy
= proxy
;
835 if (ai
->proxyBypass
) {
836 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
837 pi
->lpszProxyBypass
= proxy_bypass
;
840 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
841 return ERROR_SUCCESS
;
843 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
844 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
845 LPSTR proxy
, proxy_bypass
;
848 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
850 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
851 NULL
, 0, NULL
, NULL
);
852 if (*size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
854 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
855 return ERROR_INSUFFICIENT_BUFFER
;
857 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
858 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
860 pi
->dwAccessType
= ai
->accessType
;
861 pi
->lpszProxy
= NULL
;
862 pi
->lpszProxyBypass
= NULL
;
864 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
865 pi
->lpszProxy
= proxy
;
868 if (ai
->proxyBypass
) {
869 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
870 proxyBypassBytesRequired
, NULL
, NULL
);
871 pi
->lpszProxyBypass
= proxy_bypass
;
874 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
875 return ERROR_SUCCESS
;
879 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
882 static const object_vtbl_t APPINFOVtbl
= {
895 /***********************************************************************
896 * InternetOpenW (WININET.@)
898 * Per-application initialization of wininet
901 * HINTERNET on success
905 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
906 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
908 appinfo_t
*lpwai
= NULL
;
910 if (TRACE_ON(wininet
)) {
911 #define FE(x) { x, #x }
912 static const wininet_flag_info access_type
[] = {
913 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
914 FE(INTERNET_OPEN_TYPE_DIRECT
),
915 FE(INTERNET_OPEN_TYPE_PROXY
),
916 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
920 const char *access_type_str
= "Unknown";
922 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
923 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
924 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
925 if (access_type
[i
].val
== dwAccessType
) {
926 access_type_str
= access_type
[i
].name
;
930 TRACE(" access type : %s\n", access_type_str
);
932 dump_INTERNET_FLAGS(dwFlags
);
935 /* Clear any error information */
936 INTERNET_SetLastError(0);
938 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
940 SetLastError(ERROR_OUTOFMEMORY
);
944 lpwai
->hdr
.htype
= WH_HINIT
;
945 lpwai
->hdr
.dwFlags
= dwFlags
;
946 lpwai
->accessType
= dwAccessType
;
947 lpwai
->proxyUsername
= NULL
;
948 lpwai
->proxyPassword
= NULL
;
950 lpwai
->agent
= heap_strdupW(lpszAgent
);
951 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
952 INTERNET_ConfigureProxy( lpwai
);
954 lpwai
->proxy
= heap_strdupW(lpszProxy
);
955 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
957 TRACE("returning %p\n", lpwai
);
959 return lpwai
->hdr
.hInternet
;
963 /***********************************************************************
964 * InternetOpenA (WININET.@)
966 * Per-application initialization of wininet
969 * HINTERNET on success
973 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
974 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
976 WCHAR
*szAgent
, *szProxy
, *szBypass
;
979 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
980 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
982 szAgent
= heap_strdupAtoW(lpszAgent
);
983 szProxy
= heap_strdupAtoW(lpszProxy
);
984 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
986 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
994 /***********************************************************************
995 * InternetGetLastResponseInfoA (WININET.@)
997 * Return last wininet error description on the calling thread
1000 * TRUE on success of writing to buffer
1004 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1005 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1007 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1013 *lpdwError
= lpwite
->dwError
;
1014 if (lpwite
->dwError
)
1016 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1017 *lpdwBufferLength
= strlen(lpszBuffer
);
1020 *lpdwBufferLength
= 0;
1025 *lpdwBufferLength
= 0;
1031 /***********************************************************************
1032 * InternetGetLastResponseInfoW (WININET.@)
1034 * Return last wininet error description on the calling thread
1037 * TRUE on success of writing to buffer
1041 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1042 LPWSTR 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
= lstrlenW(lpszBuffer
);
1057 *lpdwBufferLength
= 0;
1062 *lpdwBufferLength
= 0;
1068 /***********************************************************************
1069 * InternetGetConnectedState (WININET.@)
1071 * Return connected state
1075 * if lpdwStatus is not null, return the status (off line,
1076 * modem, lan...) in it.
1077 * FALSE if not connected
1079 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1081 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1084 WARN("always returning LAN connection.\n");
1085 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1091 /***********************************************************************
1092 * InternetGetConnectedStateExW (WININET.@)
1094 * Return connected state
1098 * lpdwStatus [O] Flags specifying the status of the internet connection.
1099 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1100 * dwNameLen [I] Size of the buffer, in characters.
1101 * dwReserved [I] Reserved. Must be set to 0.
1105 * if lpdwStatus is not null, return the status (off line,
1106 * modem, lan...) in it.
1107 * FALSE if not connected
1110 * If the system has no available network connections, an empty string is
1111 * stored in lpszConnectionName. If there is a LAN connection, a localized
1112 * "LAN Connection" string is stored. Presumably, if only a dial-up
1113 * connection is available then the name of the dial-up connection is
1114 * returned. Why any application, other than the "Internet Settings" CPL,
1115 * would want to use this function instead of the simpler InternetGetConnectedStateW
1116 * function is beyond me.
1118 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1119 DWORD dwNameLen
, DWORD dwReserved
)
1121 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1128 WARN("always returning LAN connection.\n");
1129 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1131 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1135 /***********************************************************************
1136 * InternetGetConnectedStateExA (WININET.@)
1138 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1139 DWORD dwNameLen
, DWORD dwReserved
)
1141 LPWSTR lpwszConnectionName
= NULL
;
1144 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1146 if (lpszConnectionName
&& dwNameLen
> 0)
1147 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1149 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1151 if (rc
&& lpwszConnectionName
)
1153 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1154 dwNameLen
, NULL
, NULL
);
1155 heap_free(lpwszConnectionName
);
1161 /***********************************************************************
1162 * InternetConnectW (WININET.@)
1164 * Open a ftp, gopher or http session
1167 * HINTERNET a session handle on success
1171 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1172 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1173 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1174 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1177 HINTERNET rc
= NULL
;
1178 DWORD res
= ERROR_SUCCESS
;
1180 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1181 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1182 dwService
, dwFlags
, dwContext
);
1184 if (!lpszServerName
)
1186 SetLastError(ERROR_INVALID_PARAMETER
);
1190 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1191 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1193 res
= ERROR_INVALID_HANDLE
;
1199 case INTERNET_SERVICE_FTP
:
1200 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1201 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1203 res
= INTERNET_GetLastError();
1206 case INTERNET_SERVICE_HTTP
:
1207 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1208 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1211 case INTERNET_SERVICE_GOPHER
:
1217 WININET_Release( &hIC
->hdr
);
1219 TRACE("returning %p\n", rc
);
1225 /***********************************************************************
1226 * InternetConnectA (WININET.@)
1228 * Open a ftp, gopher or http session
1231 * HINTERNET a session handle on success
1235 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1236 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1237 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1238 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1240 HINTERNET rc
= NULL
;
1241 LPWSTR szServerName
;
1245 szServerName
= heap_strdupAtoW(lpszServerName
);
1246 szUserName
= heap_strdupAtoW(lpszUserName
);
1247 szPassword
= heap_strdupAtoW(lpszPassword
);
1249 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1250 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1252 heap_free(szServerName
);
1253 heap_free(szUserName
);
1254 heap_free(szPassword
);
1259 /***********************************************************************
1260 * InternetFindNextFileA (WININET.@)
1262 * Continues a file search from a previous call to FindFirstFile
1269 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1272 WIN32_FIND_DATAW fd
;
1274 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1276 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1280 /***********************************************************************
1281 * InternetFindNextFileW (WININET.@)
1283 * Continues a file search from a previous call to FindFirstFile
1290 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1292 object_header_t
*hdr
;
1297 hdr
= get_handle_object(hFind
);
1299 WARN("Invalid handle\n");
1300 SetLastError(ERROR_INVALID_HANDLE
);
1304 if(hdr
->vtbl
->FindNextFileW
) {
1305 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1307 WARN("Handle doesn't support NextFile\n");
1308 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1311 WININET_Release(hdr
);
1313 if(res
!= ERROR_SUCCESS
)
1315 return res
== ERROR_SUCCESS
;
1318 /***********************************************************************
1319 * InternetCloseHandle (WININET.@)
1321 * Generic close handle function
1328 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1330 object_header_t
*obj
;
1332 TRACE("%p\n", hInternet
);
1334 obj
= get_handle_object( hInternet
);
1336 SetLastError(ERROR_INVALID_HANDLE
);
1340 invalidate_handle(obj
);
1341 WININET_Release(obj
);
1347 /***********************************************************************
1348 * ConvertUrlComponentValue (Internal)
1350 * Helper function for InternetCrackUrlA
1353 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1354 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1355 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1357 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1358 if (*dwComponentLen
!= 0)
1360 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1361 if (*lppszComponent
== NULL
)
1365 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1366 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1369 *lppszComponent
= NULL
;
1371 *dwComponentLen
= nASCIILength
;
1375 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1376 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1377 (*lppszComponent
)[ncpylen
]=0;
1378 *dwComponentLen
= ncpylen
;
1384 /***********************************************************************
1385 * InternetCrackUrlA (WININET.@)
1387 * See InternetCrackUrlW.
1389 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1390 LPURL_COMPONENTSA lpUrlComponents
)
1393 URL_COMPONENTSW UCW
;
1395 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1396 *scheme
= NULL
, *extra
= NULL
;
1398 TRACE("(%s %u %x %p)\n",
1399 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1400 dwUrlLength
, dwFlags
, lpUrlComponents
);
1402 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1403 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1405 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1411 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1413 /* if dwUrlLength=-1 then nLength includes null but length to
1414 InternetCrackUrlW should not include it */
1415 if (dwUrlLength
== -1) nLength
--;
1417 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1418 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1419 lpwszUrl
[nLength
] = '\0';
1421 memset(&UCW
,0,sizeof(UCW
));
1422 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1423 if (lpUrlComponents
->dwHostNameLength
)
1425 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1426 if (lpUrlComponents
->lpszHostName
)
1428 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1429 UCW
.lpszHostName
= hostname
;
1432 if (lpUrlComponents
->dwUserNameLength
)
1434 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1435 if (lpUrlComponents
->lpszUserName
)
1437 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1438 UCW
.lpszUserName
= username
;
1441 if (lpUrlComponents
->dwPasswordLength
)
1443 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1444 if (lpUrlComponents
->lpszPassword
)
1446 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1447 UCW
.lpszPassword
= password
;
1450 if (lpUrlComponents
->dwUrlPathLength
)
1452 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1453 if (lpUrlComponents
->lpszUrlPath
)
1455 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1456 UCW
.lpszUrlPath
= path
;
1459 if (lpUrlComponents
->dwSchemeLength
)
1461 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1462 if (lpUrlComponents
->lpszScheme
)
1464 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1465 UCW
.lpszScheme
= scheme
;
1468 if (lpUrlComponents
->dwExtraInfoLength
)
1470 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1471 if (lpUrlComponents
->lpszExtraInfo
)
1473 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1474 UCW
.lpszExtraInfo
= extra
;
1477 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1479 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1480 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1481 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1482 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1483 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1484 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1485 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1486 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1487 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1488 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1489 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1490 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1492 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1493 lpUrlComponents
->nPort
= UCW
.nPort
;
1495 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1496 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1497 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1498 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1499 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1501 heap_free(lpwszUrl
);
1502 heap_free(hostname
);
1503 heap_free(username
);
1504 heap_free(password
);
1511 static const WCHAR url_schemes
[][7] =
1514 {'g','o','p','h','e','r',0},
1515 {'h','t','t','p',0},
1516 {'h','t','t','p','s',0},
1517 {'f','i','l','e',0},
1518 {'n','e','w','s',0},
1519 {'m','a','i','l','t','o',0},
1523 /***********************************************************************
1524 * GetInternetSchemeW (internal)
1530 * INTERNET_SCHEME_UNKNOWN on failure
1533 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1537 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1539 if(lpszScheme
==NULL
)
1540 return INTERNET_SCHEME_UNKNOWN
;
1542 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1543 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1544 return INTERNET_SCHEME_FIRST
+ i
;
1546 return INTERNET_SCHEME_UNKNOWN
;
1549 /***********************************************************************
1550 * SetUrlComponentValueW (Internal)
1552 * Helper function for InternetCrackUrlW
1555 * lppszComponent [O] Holds the returned string
1556 * dwComponentLen [I] Holds the size of lppszComponent
1557 * [O] Holds the length of the string in lppszComponent without '\0'
1558 * lpszStart [I] Holds the string to copy from
1559 * len [I] Holds the length of lpszStart without '\0'
1566 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1568 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1570 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1573 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1575 if (*lppszComponent
== NULL
)
1577 *lppszComponent
= (LPWSTR
)lpszStart
;
1578 *dwComponentLen
= len
;
1582 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1583 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1584 (*lppszComponent
)[ncpylen
] = '\0';
1585 *dwComponentLen
= ncpylen
;
1592 /***********************************************************************
1593 * InternetCrackUrlW (WININET.@)
1595 * Break up URL into its components
1601 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1602 LPURL_COMPONENTSW lpUC
)
1606 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1609 LPCWSTR lpszParam
= NULL
;
1610 BOOL bIsAbsolute
= FALSE
;
1611 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1612 LPCWSTR lpszcp
= NULL
;
1613 LPWSTR lpszUrl_decode
= NULL
;
1614 DWORD dwUrlLength
= dwUrlLength_orig
;
1616 TRACE("(%s %u %x %p)\n",
1617 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1618 dwUrlLength
, dwFlags
, lpUC
);
1620 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1622 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1625 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1627 if (dwFlags
& ICU_DECODE
)
1630 DWORD len
= dwUrlLength
+ 1;
1632 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1634 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1637 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1638 url_tmp
[dwUrlLength
] = 0;
1639 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1642 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1645 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1648 lpszUrl
= lpszUrl_decode
;
1654 /* Determine if the URI is absolute. */
1655 while (lpszap
- lpszUrl
< dwUrlLength
)
1657 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1662 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1669 lpszcp
= lpszUrl
; /* Relative url */
1675 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1676 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1678 /* Parse <params> */
1679 lpszParam
= memchrW(lpszap
, ';', dwUrlLength
- (lpszap
- lpszUrl
));
1681 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1683 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1685 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1686 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1688 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1692 /* Get scheme first. */
1693 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1694 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1695 lpszUrl
, lpszcp
- lpszUrl
);
1697 /* Eat ':' in protocol. */
1700 /* double slash indicates the net_loc portion is present */
1701 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1705 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1709 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1711 lpszNetLoc
= lpszParam
;
1713 else if (!lpszNetLoc
)
1714 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1722 /* [<user>[<:password>]@]<host>[:<port>] */
1723 /* First find the user and password if they exist */
1725 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1726 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1728 /* username and password not specified. */
1729 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1730 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1732 else /* Parse out username and password */
1734 LPCWSTR lpszUser
= lpszcp
;
1735 LPCWSTR lpszPasswd
= lpszHost
;
1737 while (lpszcp
< lpszHost
)
1740 lpszPasswd
= lpszcp
;
1745 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1746 lpszUser
, lpszPasswd
- lpszUser
);
1748 if (lpszPasswd
!= lpszHost
)
1750 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1751 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1752 lpszHost
- lpszPasswd
);
1754 lpszcp
++; /* Advance to beginning of host */
1757 /* Parse <host><:port> */
1760 lpszPort
= lpszNetLoc
;
1762 /* special case for res:// URLs: there is no port here, so the host is the
1763 entire string up to the first '/' */
1764 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1766 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1767 lpszHost
, lpszPort
- lpszHost
);
1772 while (lpszcp
< lpszNetLoc
)
1780 /* If the scheme is "file" and the host is just one letter, it's not a host */
1781 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1784 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1789 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1790 lpszHost
, lpszPort
- lpszHost
);
1791 if (lpszPort
!= lpszNetLoc
)
1792 lpUC
->nPort
= atoiW(++lpszPort
);
1793 else switch (lpUC
->nScheme
)
1795 case INTERNET_SCHEME_HTTP
:
1796 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1798 case INTERNET_SCHEME_HTTPS
:
1799 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1801 case INTERNET_SCHEME_FTP
:
1802 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1804 case INTERNET_SCHEME_GOPHER
:
1805 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1816 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1817 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1818 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1823 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1824 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1825 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1826 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1829 /* Here lpszcp points to:
1831 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1832 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1834 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1838 /* Only truncate the parameter list if it's already been saved
1839 * in lpUC->lpszExtraInfo.
1841 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1842 len
= lpszParam
- lpszcp
;
1845 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1846 * newlines if necessary.
1848 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1849 if (lpsznewline
!= NULL
)
1850 len
= lpsznewline
- lpszcp
;
1852 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1854 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1855 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1857 WCHAR tmppath
[MAX_PATH
];
1861 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1866 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1867 tmppath
[len
] = '\0';
1876 /* if ends in \. or \.. append a backslash */
1877 if (tmppath
[len
- 1] == '.' &&
1878 (tmppath
[len
- 2] == '\\' ||
1879 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1881 if (len
< MAX_PATH
- 1)
1883 tmppath
[len
] = '\\';
1884 tmppath
[len
+1] = '\0';
1888 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1892 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1897 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1898 lpUC
->lpszUrlPath
[0] = 0;
1899 lpUC
->dwUrlPathLength
= 0;
1902 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1903 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1904 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1905 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1906 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1908 heap_free( lpszUrl_decode
);
1912 /***********************************************************************
1913 * InternetAttemptConnect (WININET.@)
1915 * Attempt to make a connection to the internet
1918 * ERROR_SUCCESS on success
1919 * Error value on failure
1922 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1925 return ERROR_SUCCESS
;
1929 /***********************************************************************
1930 * InternetCanonicalizeUrlA (WININET.@)
1932 * Escape unsafe characters and spaces
1939 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1940 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1943 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1945 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1946 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1948 if(dwFlags
& ICU_DECODE
)
1950 dwURLFlags
|= URL_UNESCAPE
;
1951 dwFlags
&= ~ICU_DECODE
;
1954 if(dwFlags
& ICU_ESCAPE
)
1956 dwURLFlags
|= URL_UNESCAPE
;
1957 dwFlags
&= ~ICU_ESCAPE
;
1960 if(dwFlags
& ICU_BROWSER_MODE
)
1962 dwURLFlags
|= URL_BROWSER_MODE
;
1963 dwFlags
&= ~ICU_BROWSER_MODE
;
1966 if(dwFlags
& ICU_NO_ENCODE
)
1968 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1969 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1970 dwFlags
&= ~ICU_NO_ENCODE
;
1973 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1975 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1976 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1977 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1979 return (hr
== S_OK
) ? TRUE
: FALSE
;
1982 /***********************************************************************
1983 * InternetCanonicalizeUrlW (WININET.@)
1985 * Escape unsafe characters and spaces
1992 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1993 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1996 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1998 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1999 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2001 if(dwFlags
& ICU_DECODE
)
2003 dwURLFlags
|= URL_UNESCAPE
;
2004 dwFlags
&= ~ICU_DECODE
;
2007 if(dwFlags
& ICU_ESCAPE
)
2009 dwURLFlags
|= URL_UNESCAPE
;
2010 dwFlags
&= ~ICU_ESCAPE
;
2013 if(dwFlags
& ICU_BROWSER_MODE
)
2015 dwURLFlags
|= URL_BROWSER_MODE
;
2016 dwFlags
&= ~ICU_BROWSER_MODE
;
2019 if(dwFlags
& ICU_NO_ENCODE
)
2021 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2022 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
2023 dwFlags
&= ~ICU_NO_ENCODE
;
2026 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
2028 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
2029 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2030 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2032 return (hr
== S_OK
) ? TRUE
: FALSE
;
2035 /* #################################################### */
2037 static INTERNET_STATUS_CALLBACK
set_status_callback(
2038 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2040 INTERNET_STATUS_CALLBACK ret
;
2042 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2043 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2045 ret
= lpwh
->lpfnStatusCB
;
2046 lpwh
->lpfnStatusCB
= callback
;
2051 /***********************************************************************
2052 * InternetSetStatusCallbackA (WININET.@)
2054 * Sets up a callback function which is called as progress is made
2055 * during an operation.
2058 * Previous callback or NULL on success
2059 * INTERNET_INVALID_STATUS_CALLBACK on failure
2062 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2063 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2065 INTERNET_STATUS_CALLBACK retVal
;
2066 object_header_t
*lpwh
;
2068 TRACE("%p\n", hInternet
);
2070 if (!(lpwh
= get_handle_object(hInternet
)))
2071 return INTERNET_INVALID_STATUS_CALLBACK
;
2073 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2075 WININET_Release( lpwh
);
2079 /***********************************************************************
2080 * InternetSetStatusCallbackW (WININET.@)
2082 * Sets up a callback function which is called as progress is made
2083 * during an operation.
2086 * Previous callback or NULL on success
2087 * INTERNET_INVALID_STATUS_CALLBACK on failure
2090 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2091 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2093 INTERNET_STATUS_CALLBACK retVal
;
2094 object_header_t
*lpwh
;
2096 TRACE("%p\n", hInternet
);
2098 if (!(lpwh
= get_handle_object(hInternet
)))
2099 return INTERNET_INVALID_STATUS_CALLBACK
;
2101 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2103 WININET_Release( lpwh
);
2107 /***********************************************************************
2108 * InternetSetFilePointer (WININET.@)
2110 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2111 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2113 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2117 /***********************************************************************
2118 * InternetWriteFile (WININET.@)
2120 * Write data to an open internet file
2127 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2128 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2130 object_header_t
*lpwh
;
2133 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2135 lpwh
= get_handle_object( hFile
);
2137 WARN("Invalid handle\n");
2138 SetLastError(ERROR_INVALID_HANDLE
);
2142 if(lpwh
->vtbl
->WriteFile
) {
2143 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2145 WARN("No Writefile method.\n");
2146 res
= ERROR_INVALID_HANDLE
;
2149 WININET_Release( lpwh
);
2151 if(res
!= ERROR_SUCCESS
)
2153 return res
== ERROR_SUCCESS
;
2157 /***********************************************************************
2158 * InternetReadFile (WININET.@)
2160 * Read data from an open internet file
2167 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2168 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2170 object_header_t
*hdr
;
2171 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2173 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2175 hdr
= get_handle_object(hFile
);
2177 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2181 if(hdr
->vtbl
->ReadFile
)
2182 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2184 WININET_Release(hdr
);
2186 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2187 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2189 if(res
!= ERROR_SUCCESS
)
2191 return res
== ERROR_SUCCESS
;
2194 /***********************************************************************
2195 * InternetReadFileExA (WININET.@)
2197 * Read data from an open internet file
2200 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2201 * lpBuffersOut [I/O] Buffer.
2202 * dwFlags [I] Flags. See notes.
2203 * dwContext [I] Context for callbacks.
2210 * The parameter dwFlags include zero or more of the following flags:
2211 *|IRF_ASYNC - Makes the call asynchronous.
2212 *|IRF_SYNC - Makes the call synchronous.
2213 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2214 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2216 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2219 * InternetOpenUrlA(), HttpOpenRequestA()
2221 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2222 DWORD dwFlags
, DWORD_PTR dwContext
)
2224 object_header_t
*hdr
;
2225 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2227 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2229 hdr
= get_handle_object(hFile
);
2231 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2235 if(hdr
->vtbl
->ReadFileExA
)
2236 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
2238 WININET_Release(hdr
);
2240 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2241 res
, lpBuffersOut
->dwBufferLength
);
2243 if(res
!= ERROR_SUCCESS
)
2245 return res
== ERROR_SUCCESS
;
2248 /***********************************************************************
2249 * InternetReadFileExW (WININET.@)
2251 * InternetReadFileExA()
2253 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2254 DWORD dwFlags
, DWORD_PTR dwContext
)
2256 object_header_t
*hdr
;
2257 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2259 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2261 hdr
= get_handle_object(hFile
);
2263 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2267 if(hdr
->vtbl
->ReadFileExW
)
2268 res
= hdr
->vtbl
->ReadFileExW(hdr
, lpBuffer
, dwFlags
, dwContext
);
2270 WININET_Release(hdr
);
2272 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2273 res
, lpBuffer
->dwBufferLength
);
2275 if(res
!= ERROR_SUCCESS
)
2277 return res
== ERROR_SUCCESS
;
2280 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2282 /* FIXME: This function currently handles more options than it should. Options requiring
2283 * proper handles should be moved to proper functions */
2285 case INTERNET_OPTION_REQUEST_FLAGS
:
2286 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2288 if (*size
< sizeof(ULONG
))
2289 return ERROR_INSUFFICIENT_BUFFER
;
2291 *(ULONG
*)buffer
= 4;
2292 *size
= sizeof(ULONG
);
2294 return ERROR_SUCCESS
;
2296 case INTERNET_OPTION_HTTP_VERSION
:
2297 if (*size
< sizeof(HTTP_VERSION_INFO
))
2298 return ERROR_INSUFFICIENT_BUFFER
;
2301 * Presently hardcoded to 1.1
2303 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2304 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2305 *size
= sizeof(HTTP_VERSION_INFO
);
2307 return ERROR_SUCCESS
;
2309 case INTERNET_OPTION_CONNECTED_STATE
:
2310 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2312 if (*size
< sizeof(ULONG
))
2313 return ERROR_INSUFFICIENT_BUFFER
;
2315 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2316 *size
= sizeof(ULONG
);
2318 return ERROR_SUCCESS
;
2320 case INTERNET_OPTION_PROXY
: {
2324 TRACE("Getting global proxy info\n");
2325 memset(&ai
, 0, sizeof(appinfo_t
));
2326 INTERNET_ConfigureProxy(&ai
);
2328 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2329 APPINFO_Destroy(&ai
.hdr
);
2333 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2334 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2336 if (*size
< sizeof(ULONG
))
2337 return ERROR_INSUFFICIENT_BUFFER
;
2339 *(ULONG
*)buffer
= max_conns
;
2340 *size
= sizeof(ULONG
);
2342 return ERROR_SUCCESS
;
2344 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2345 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2347 if (*size
< sizeof(ULONG
))
2348 return ERROR_INSUFFICIENT_BUFFER
;
2350 *(ULONG
*)buffer
= max_1_0_conns
;
2351 *size
= sizeof(ULONG
);
2353 return ERROR_SUCCESS
;
2355 case INTERNET_OPTION_SECURITY_FLAGS
:
2356 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2357 return ERROR_SUCCESS
;
2359 case INTERNET_OPTION_VERSION
: {
2360 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2362 TRACE("INTERNET_OPTION_VERSION\n");
2364 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2365 return ERROR_INSUFFICIENT_BUFFER
;
2367 memcpy(buffer
, &info
, sizeof(info
));
2368 *size
= sizeof(info
);
2370 return ERROR_SUCCESS
;
2373 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2374 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2375 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2376 DWORD res
= ERROR_SUCCESS
, i
;
2380 TRACE("Getting global proxy info\n");
2381 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2384 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2386 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2388 return ERROR_INSUFFICIENT_BUFFER
;
2391 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2392 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2393 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2395 switch (optionW
->dwOption
) {
2396 case INTERNET_PER_CONN_FLAGS
:
2398 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2400 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2403 case INTERNET_PER_CONN_PROXY_SERVER
:
2405 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2407 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2410 case INTERNET_PER_CONN_PROXY_BYPASS
:
2412 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2414 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2417 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2418 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2419 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2420 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2421 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2422 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2423 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2424 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2428 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2429 res
= ERROR_INVALID_PARAMETER
;
2437 case INTERNET_OPTION_USER_AGENT
:
2438 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2439 case INTERNET_OPTION_POLICY
:
2440 return ERROR_INVALID_PARAMETER
;
2443 FIXME("Stub for %d\n", option
);
2444 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2447 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2450 case INTERNET_OPTION_CONTEXT_VALUE
:
2452 return ERROR_INVALID_PARAMETER
;
2454 if (*size
< sizeof(DWORD_PTR
)) {
2455 *size
= sizeof(DWORD_PTR
);
2456 return ERROR_INSUFFICIENT_BUFFER
;
2459 return ERROR_INVALID_PARAMETER
;
2461 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2462 *size
= sizeof(DWORD_PTR
);
2463 return ERROR_SUCCESS
;
2465 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2466 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2467 WARN("Called on global option %u\n", option
);
2468 return ERROR_INTERNET_INVALID_OPERATION
;
2471 /* FIXME: we shouldn't call it here */
2472 return query_global_option(option
, buffer
, size
, unicode
);
2475 /***********************************************************************
2476 * InternetQueryOptionW (WININET.@)
2478 * Queries an options on the specified handle
2485 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2486 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2488 object_header_t
*hdr
;
2489 DWORD res
= ERROR_INVALID_HANDLE
;
2491 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2494 hdr
= get_handle_object(hInternet
);
2496 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2497 WININET_Release(hdr
);
2500 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2503 if(res
!= ERROR_SUCCESS
)
2505 return res
== ERROR_SUCCESS
;
2508 /***********************************************************************
2509 * InternetQueryOptionA (WININET.@)
2511 * Queries an options on the specified handle
2518 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2519 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2521 object_header_t
*hdr
;
2522 DWORD res
= ERROR_INVALID_HANDLE
;
2524 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2527 hdr
= get_handle_object(hInternet
);
2529 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2530 WININET_Release(hdr
);
2533 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2536 if(res
!= ERROR_SUCCESS
)
2538 return res
== ERROR_SUCCESS
;
2541 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2544 case INTERNET_OPTION_CALLBACK
:
2545 WARN("Not settable option %u\n", option
);
2546 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2547 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2548 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2549 WARN("Called on global option %u\n", option
);
2550 return ERROR_INTERNET_INVALID_OPERATION
;
2553 return ERROR_INTERNET_INVALID_OPTION
;
2556 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2559 case INTERNET_OPTION_CALLBACK
:
2560 WARN("Not global option %u\n", option
);
2561 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2563 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2564 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2566 if(size
!= sizeof(max_conns
))
2567 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2569 return ERROR_BAD_ARGUMENTS
;
2571 max_conns
= *(ULONG
*)buf
;
2572 return ERROR_SUCCESS
;
2574 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2575 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2577 if(size
!= sizeof(max_1_0_conns
))
2578 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2580 return ERROR_BAD_ARGUMENTS
;
2582 max_1_0_conns
= *(ULONG
*)buf
;
2583 return ERROR_SUCCESS
;
2586 return ERROR_INTERNET_INVALID_OPTION
;
2589 /***********************************************************************
2590 * InternetSetOptionW (WININET.@)
2592 * Sets an options on the specified handle
2599 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2600 LPVOID lpBuffer
, DWORD dwBufferLength
)
2602 object_header_t
*lpwhh
;
2606 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2608 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2610 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2612 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2614 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2616 WININET_Release(lpwhh
);
2618 if(res
!= ERROR_SUCCESS
)
2621 return res
== ERROR_SUCCESS
;
2626 case INTERNET_OPTION_HTTP_VERSION
:
2628 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2629 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2632 case INTERNET_OPTION_ERROR_MASK
:
2635 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2637 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2638 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2639 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2640 SetLastError(ERROR_INVALID_PARAMETER
);
2642 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2643 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2646 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2649 case INTERNET_OPTION_PROXY
:
2651 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2653 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2655 SetLastError(ERROR_INVALID_PARAMETER
);
2660 EnterCriticalSection( &WININET_cs
);
2661 free_global_proxy();
2662 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2665 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2667 global_proxy
->proxyEnabled
= 1;
2668 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2669 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2673 global_proxy
->proxyEnabled
= 0;
2674 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2677 LeaveCriticalSection( &WININET_cs
);
2681 /* In general, each type of object should handle
2682 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2683 * get silently dropped.
2685 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2686 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2691 case INTERNET_OPTION_CODEPAGE
:
2693 ULONG codepage
= *(ULONG
*)lpBuffer
;
2694 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2697 case INTERNET_OPTION_REQUEST_PRIORITY
:
2699 ULONG priority
= *(ULONG
*)lpBuffer
;
2700 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2703 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2705 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2706 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2709 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2711 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2712 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2715 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2716 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2718 case INTERNET_OPTION_END_BROWSER_SESSION
:
2719 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2721 case INTERNET_OPTION_CONNECTED_STATE
:
2722 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2724 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2725 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2727 case INTERNET_OPTION_SEND_TIMEOUT
:
2728 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2729 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2731 ULONG timeout
= *(ULONG
*)lpBuffer
;
2732 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2735 case INTERNET_OPTION_CONNECT_RETRIES
:
2737 ULONG retries
= *(ULONG
*)lpBuffer
;
2738 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2741 case INTERNET_OPTION_CONTEXT_VALUE
:
2745 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2748 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2750 SetLastError(ERROR_INVALID_PARAMETER
);
2754 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2757 case INTERNET_OPTION_SECURITY_FLAGS
:
2758 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2760 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2761 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2763 case INTERNET_OPTION_HTTP_DECODING
:
2764 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2765 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2768 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2769 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2770 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2773 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2774 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2775 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2778 case INTERNET_OPTION_CODEPAGE_PATH
:
2779 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2780 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2783 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2784 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2785 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2788 case INTERNET_OPTION_IDN
:
2789 FIXME("INTERNET_OPTION_IDN; STUB\n");
2790 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2793 case INTERNET_OPTION_POLICY
:
2794 SetLastError(ERROR_INVALID_PARAMETER
);
2797 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2798 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2803 INTERNET_LoadProxySettings(&pi
);
2805 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2806 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2808 switch (option
->dwOption
) {
2809 case INTERNET_PER_CONN_PROXY_SERVER
:
2810 heap_free(pi
.proxy
);
2811 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2814 case INTERNET_PER_CONN_FLAGS
:
2815 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2816 pi
.proxyEnabled
= 1;
2819 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2820 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2821 pi
.proxyEnabled
= 0;
2825 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2826 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2827 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2828 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2829 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2830 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2831 case INTERNET_PER_CONN_PROXY_BYPASS
:
2832 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2836 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2837 SetLastError(ERROR_INVALID_PARAMETER
);
2842 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2847 ret
= (res
== ERROR_SUCCESS
);
2851 FIXME("Option %d STUB\n",dwOption
);
2852 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2858 WININET_Release( lpwhh
);
2864 /***********************************************************************
2865 * InternetSetOptionA (WININET.@)
2867 * Sets an options on the specified handle.
2874 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2875 LPVOID lpBuffer
, DWORD dwBufferLength
)
2883 case INTERNET_OPTION_PROXY
:
2885 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2886 LPINTERNET_PROXY_INFOW piw
;
2887 DWORD proxlen
, prbylen
;
2890 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2891 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2892 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2893 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2894 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2895 piw
->dwAccessType
= pi
->dwAccessType
;
2896 prox
= (LPWSTR
) &piw
[1];
2897 prby
= &prox
[proxlen
+1];
2898 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2899 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2900 piw
->lpszProxy
= prox
;
2901 piw
->lpszProxyBypass
= prby
;
2904 case INTERNET_OPTION_USER_AGENT
:
2905 case INTERNET_OPTION_USERNAME
:
2906 case INTERNET_OPTION_PASSWORD
:
2907 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2909 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2910 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2913 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2915 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
2916 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
2917 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2918 wbuffer
= heap_alloc(wlen
);
2921 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2922 if (listA
->pszConnection
)
2924 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
2925 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
2926 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
2929 listW
->pszConnection
= NULL
;
2930 listW
->dwOptionCount
= listA
->dwOptionCount
;
2931 listW
->dwOptionError
= listA
->dwOptionError
;
2932 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
2934 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
2935 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
2936 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
2938 optW
->dwOption
= optA
->dwOption
;
2940 switch (optA
->dwOption
) {
2941 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2942 case INTERNET_PER_CONN_PROXY_BYPASS
:
2943 case INTERNET_PER_CONN_PROXY_SERVER
:
2944 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2945 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2946 if (optA
->Value
.pszValue
)
2948 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
2949 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
2950 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
2953 optW
->Value
.pszValue
= NULL
;
2955 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2956 case INTERNET_PER_CONN_FLAGS
:
2957 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2958 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
2960 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2961 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
2964 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
2965 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
2973 wlen
= dwBufferLength
;
2976 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2978 if( lpBuffer
!= wbuffer
)
2980 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
2982 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
2984 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
2985 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
2986 switch (opt
->dwOption
) {
2987 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2988 case INTERNET_PER_CONN_PROXY_BYPASS
:
2989 case INTERNET_PER_CONN_PROXY_SERVER
:
2990 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2991 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2992 heap_free( opt
->Value
.pszValue
);
2998 heap_free( list
->pOptions
);
3000 heap_free( wbuffer
);
3007 /***********************************************************************
3008 * InternetSetOptionExA (WININET.@)
3010 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3011 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3013 FIXME("Flags %08x ignored\n", dwFlags
);
3014 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3017 /***********************************************************************
3018 * InternetSetOptionExW (WININET.@)
3020 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3021 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3023 FIXME("Flags %08x ignored\n", dwFlags
);
3024 if( dwFlags
& ~ISO_VALID_FLAGS
)
3026 SetLastError( ERROR_INVALID_PARAMETER
);
3029 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3032 static const WCHAR WININET_wkday
[7][4] =
3033 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3034 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3035 static const WCHAR WININET_month
[12][4] =
3036 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3037 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3038 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3040 /***********************************************************************
3041 * InternetTimeFromSystemTimeA (WININET.@)
3043 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3046 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3048 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3050 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3052 SetLastError(ERROR_INVALID_PARAMETER
);
3056 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3058 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3062 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3063 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3068 /***********************************************************************
3069 * InternetTimeFromSystemTimeW (WININET.@)
3071 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3073 static const WCHAR date
[] =
3074 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3075 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3077 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3079 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3081 SetLastError(ERROR_INVALID_PARAMETER
);
3085 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3087 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3091 sprintfW( string
, date
,
3092 WININET_wkday
[time
->wDayOfWeek
],
3094 WININET_month
[time
->wMonth
- 1],
3103 /***********************************************************************
3104 * InternetTimeToSystemTimeA (WININET.@)
3106 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3111 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3113 stringW
= heap_strdupAtoW(string
);
3116 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3117 heap_free( stringW
);
3122 /***********************************************************************
3123 * InternetTimeToSystemTimeW (WININET.@)
3125 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3128 const WCHAR
*s
= string
;
3131 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3133 if (!string
|| !time
) return FALSE
;
3135 /* Windows does this too */
3136 GetSystemTime( time
);
3138 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3139 * a SYSTEMTIME structure.
3142 while (*s
&& !isalphaW( *s
)) s
++;
3143 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3144 time
->wDayOfWeek
= 7;
3146 for (i
= 0; i
< 7; i
++)
3148 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3149 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3150 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3152 time
->wDayOfWeek
= i
;
3157 if (time
->wDayOfWeek
> 6) return TRUE
;
3158 while (*s
&& !isdigitW( *s
)) s
++;
3159 time
->wDay
= strtolW( s
, &end
, 10 );
3162 while (*s
&& !isalphaW( *s
)) s
++;
3163 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3166 for (i
= 0; i
< 12; i
++)
3168 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3169 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3170 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3172 time
->wMonth
= i
+ 1;
3176 if (time
->wMonth
== 0) return TRUE
;
3178 while (*s
&& !isdigitW( *s
)) s
++;
3179 if (*s
== '\0') return TRUE
;
3180 time
->wYear
= strtolW( s
, &end
, 10 );
3183 while (*s
&& !isdigitW( *s
)) s
++;
3184 if (*s
== '\0') return TRUE
;
3185 time
->wHour
= strtolW( s
, &end
, 10 );
3188 while (*s
&& !isdigitW( *s
)) s
++;
3189 if (*s
== '\0') return TRUE
;
3190 time
->wMinute
= strtolW( s
, &end
, 10 );
3193 while (*s
&& !isdigitW( *s
)) s
++;
3194 if (*s
== '\0') return TRUE
;
3195 time
->wSecond
= strtolW( s
, &end
, 10 );
3198 time
->wMilliseconds
= 0;
3202 /***********************************************************************
3203 * InternetCheckConnectionW (WININET.@)
3205 * Pings a requested host to check internet connection
3208 * TRUE on success and FALSE on failure. If a failure then
3209 * ERROR_NOT_CONNECTED is placed into GetLastError
3212 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3215 * this is a kludge which runs the resident ping program and reads the output.
3217 * Anyone have a better idea?
3221 static const CHAR ping
[] = "ping -c 1 ";
3222 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3223 CHAR
*command
= NULL
;
3224 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3232 * Crack or set the Address
3234 if (lpszUrl
== NULL
)
3237 * According to the doc we are supposed to use the ip for the next
3238 * server in the WnInet internal server database. I have
3239 * no idea what that is or how to get it.
3241 * So someone needs to implement this.
3243 FIXME("Unimplemented with URL of NULL\n");
3248 URL_COMPONENTSW components
;
3250 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3251 components
.lpszHostName
= (LPWSTR
)hostW
;
3252 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3254 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3257 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3258 port
= components
.nPort
;
3259 TRACE("port: %d\n", port
);
3262 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3264 struct sockaddr_storage saddr
;
3265 socklen_t sa_len
= sizeof(saddr
);
3268 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3270 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3273 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3281 * Build our ping command
3283 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3284 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3285 strcpy(command
,ping
);
3286 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3287 strcat(command
,redirect
);
3289 TRACE("Ping command is : %s\n",command
);
3291 status
= system(command
);
3293 TRACE("Ping returned a code of %i\n",status
);
3295 /* Ping return code of 0 indicates success */
3301 heap_free( command
);
3303 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3309 /***********************************************************************
3310 * InternetCheckConnectionA (WININET.@)
3312 * Pings a requested host to check internet connection
3315 * TRUE on success and FALSE on failure. If a failure then
3316 * ERROR_NOT_CONNECTED is placed into GetLastError
3319 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3325 url
= heap_strdupAtoW(lpszUrl
);
3330 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3337 /**********************************************************
3338 * INTERNET_InternetOpenUrlW (internal)
3343 * handle of connection or NULL on failure
3345 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3346 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3348 URL_COMPONENTSW urlComponents
;
3349 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3350 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3351 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3352 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3353 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3355 HINTERNET client
= NULL
, client1
= NULL
;
3358 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3359 dwHeadersLength
, dwFlags
, dwContext
);
3361 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3362 urlComponents
.lpszScheme
= protocol
;
3363 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3364 urlComponents
.lpszHostName
= hostName
;
3365 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3366 urlComponents
.lpszUserName
= userName
;
3367 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3368 urlComponents
.lpszPassword
= password
;
3369 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3370 urlComponents
.lpszUrlPath
= path
;
3371 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3372 urlComponents
.lpszExtraInfo
= extra
;
3373 urlComponents
.dwExtraInfoLength
= 1024;
3374 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3376 switch(urlComponents
.nScheme
) {
3377 case INTERNET_SCHEME_FTP
:
3378 if(urlComponents
.nPort
== 0)
3379 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3380 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3381 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3384 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3385 if(client1
== NULL
) {
3386 InternetCloseHandle(client
);
3391 case INTERNET_SCHEME_HTTP
:
3392 case INTERNET_SCHEME_HTTPS
: {
3393 static const WCHAR szStars
[] = { '*','/','*', 0 };
3394 LPCWSTR accept
[2] = { szStars
, NULL
};
3395 if(urlComponents
.nPort
== 0) {
3396 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3397 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3399 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3401 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3403 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3404 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3405 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3406 if(res
!= ERROR_SUCCESS
) {
3407 INTERNET_SetLastError(res
);
3411 if (urlComponents
.dwExtraInfoLength
) {
3413 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3415 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3417 InternetCloseHandle(client
);
3420 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3421 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3422 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3423 heap_free(path_extra
);
3426 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3428 if(client1
== NULL
) {
3429 InternetCloseHandle(client
);
3432 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3433 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3434 GetLastError() != ERROR_IO_PENDING
) {
3435 InternetCloseHandle(client1
);
3440 case INTERNET_SCHEME_GOPHER
:
3441 /* gopher doesn't seem to be implemented in wine, but it's supposed
3442 * to be supported by InternetOpenUrlA. */
3444 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3448 TRACE(" %p <--\n", client1
);
3453 /**********************************************************
3454 * InternetOpenUrlW (WININET.@)
3459 * handle of connection or NULL on failure
3461 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3463 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3464 appinfo_t
*hIC
= (appinfo_t
*) workRequest
->hdr
;
3468 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3469 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3470 heap_free(req
->lpszUrl
);
3471 heap_free(req
->lpszHeaders
);
3474 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3475 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3477 HINTERNET ret
= NULL
;
3478 appinfo_t
*hIC
= NULL
;
3480 if (TRACE_ON(wininet
)) {
3481 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3482 dwHeadersLength
, dwFlags
, dwContext
);
3484 dump_INTERNET_FLAGS(dwFlags
);
3489 SetLastError(ERROR_INVALID_PARAMETER
);
3493 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3494 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3495 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3499 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3500 WORKREQUEST workRequest
;
3501 struct WORKREQ_INTERNETOPENURLW
*req
;
3503 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3504 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3505 req
= &workRequest
.u
.InternetOpenUrlW
;
3506 req
->lpszUrl
= heap_strdupW(lpszUrl
);
3507 req
->lpszHeaders
= heap_strdupW(lpszHeaders
);
3508 req
->dwHeadersLength
= dwHeadersLength
;
3509 req
->dwFlags
= dwFlags
;
3510 req
->dwContext
= dwContext
;
3512 INTERNET_AsyncCall(&workRequest
);
3514 * This is from windows.
3516 SetLastError(ERROR_IO_PENDING
);
3518 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3523 WININET_Release( &hIC
->hdr
);
3524 TRACE(" %p <--\n", ret
);
3529 /**********************************************************
3530 * InternetOpenUrlA (WININET.@)
3535 * handle of connection or NULL on failure
3537 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3538 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3540 HINTERNET rc
= NULL
;
3541 DWORD lenHeaders
= 0;
3542 LPWSTR szUrl
= NULL
;
3543 LPWSTR szHeaders
= NULL
;
3548 szUrl
= heap_strdupAtoW(lpszUrl
);
3554 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3555 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3560 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3563 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3564 lenHeaders
, dwFlags
, dwContext
);
3567 heap_free(szHeaders
);
3572 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3574 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3578 lpwite
->dwError
= 0;
3579 lpwite
->response
[0] = '\0';
3582 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3591 /***********************************************************************
3592 * INTERNET_SetLastError (internal)
3594 * Set last thread specific error
3599 void INTERNET_SetLastError(DWORD dwError
)
3601 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3604 lpwite
= INTERNET_AllocThreadError();
3606 SetLastError(dwError
);
3608 lpwite
->dwError
= dwError
;
3612 /***********************************************************************
3613 * INTERNET_GetLastError (internal)
3615 * Get last thread specific error
3620 DWORD
INTERNET_GetLastError(void)
3622 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3623 if (!lpwite
) return 0;
3624 /* TlsGetValue clears last error, so set it again here */
3625 SetLastError(lpwite
->dwError
);
3626 return lpwite
->dwError
;
3630 /***********************************************************************
3631 * INTERNET_WorkerThreadFunc (internal)
3633 * Worker thread execution function
3638 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3640 LPWORKREQUEST lpRequest
= lpvParam
;
3641 WORKREQUEST workRequest
;
3645 workRequest
= *lpRequest
;
3646 heap_free(lpRequest
);
3648 workRequest
.asyncproc(&workRequest
);
3649 WININET_Release( workRequest
.hdr
);
3651 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3653 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3654 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3660 /***********************************************************************
3661 * INTERNET_AsyncCall (internal)
3663 * Retrieves work request from queue
3668 DWORD
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3671 LPWORKREQUEST lpNewRequest
;
3675 lpNewRequest
= heap_alloc(sizeof(WORKREQUEST
));
3677 return ERROR_OUTOFMEMORY
;
3679 *lpNewRequest
= *lpWorkRequest
;
3681 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3684 heap_free(lpNewRequest
);
3685 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3687 return ERROR_SUCCESS
;
3691 /***********************************************************************
3692 * INTERNET_GetResponseBuffer (internal)
3697 LPSTR
INTERNET_GetResponseBuffer(void)
3699 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3701 lpwite
= INTERNET_AllocThreadError();
3703 return lpwite
->response
;
3706 /***********************************************************************
3707 * INTERNET_GetNextLine (internal)
3709 * Parse next line in directory string listing
3712 * Pointer to beginning of next line
3717 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3720 BOOL bSuccess
= FALSE
;
3722 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3727 pfd
.events
= POLLIN
;
3729 while (nRecv
< MAX_REPLY_LEN
)
3731 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3733 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3735 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3739 if (lpszBuffer
[nRecv
] == '\n')
3744 if (lpszBuffer
[nRecv
] != '\r')
3749 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3757 lpszBuffer
[nRecv
] = '\0';
3759 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3768 /**********************************************************
3769 * InternetQueryDataAvailable (WININET.@)
3771 * Determines how much data is available to be read.
3774 * TRUE on success, FALSE if an error occurred. If
3775 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3776 * no data is presently available, FALSE is returned with
3777 * the last error ERROR_IO_PENDING; a callback with status
3778 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3779 * data is available.
3781 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3782 LPDWORD lpdwNumberOfBytesAvailble
,
3783 DWORD dwFlags
, DWORD_PTR dwContext
)
3785 object_header_t
*hdr
;
3788 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3790 hdr
= get_handle_object( hFile
);
3792 SetLastError(ERROR_INVALID_HANDLE
);
3796 if(hdr
->vtbl
->QueryDataAvailable
) {
3797 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3799 WARN("wrong handle\n");
3800 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3803 WININET_Release(hdr
);
3805 if(res
!= ERROR_SUCCESS
)
3807 return res
== ERROR_SUCCESS
;
3811 /***********************************************************************
3812 * InternetLockRequestFile (WININET.@)
3814 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3821 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3828 /***********************************************************************
3829 * InternetAutodial (WININET.@)
3831 * On windows this function is supposed to dial the default internet
3832 * connection. We don't want to have Wine dial out to the internet so
3833 * we return TRUE by default. It might be nice to check if we are connected.
3840 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3844 /* Tell that we are connected to the internet. */
3848 /***********************************************************************
3849 * InternetAutodialHangup (WININET.@)
3851 * Hangs up a connection made with InternetAutodial
3860 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3864 /* we didn't dial, we don't disconnect */
3868 /***********************************************************************
3869 * InternetCombineUrlA (WININET.@)
3871 * Combine a base URL with a relative URL
3879 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3880 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3885 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3887 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3888 dwFlags
^= ICU_NO_ENCODE
;
3889 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3894 /***********************************************************************
3895 * InternetCombineUrlW (WININET.@)
3897 * Combine a base URL with a relative URL
3905 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3906 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3911 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3913 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3914 dwFlags
^= ICU_NO_ENCODE
;
3915 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3920 /* max port num is 65535 => 5 digits */
3921 #define MAX_WORD_DIGITS 5
3923 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3924 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3925 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3926 (url)->dw##component##Length : strlen((url)->lpsz##component))
3928 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3930 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3931 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3933 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3934 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3936 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3937 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3939 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3940 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3943 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3949 /* opaque urls do not fit into the standard url hierarchy and don't have
3950 * two following slashes */
3951 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3953 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3954 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3955 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3956 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3957 (nScheme
!= INTERNET_SCHEME_FILE
);
3960 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3963 if (scheme
< INTERNET_SCHEME_FIRST
)
3965 index
= scheme
- INTERNET_SCHEME_FIRST
;
3966 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3968 return (LPCWSTR
)url_schemes
[index
];
3971 /* we can calculate using ansi strings because we're just
3972 * calculating string length, not size
3974 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3975 LPDWORD lpdwUrlLength
)
3977 INTERNET_SCHEME nScheme
;
3981 if (lpUrlComponents
->lpszScheme
)
3983 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3984 *lpdwUrlLength
+= dwLen
;
3985 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3991 nScheme
= lpUrlComponents
->nScheme
;
3993 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3994 nScheme
= INTERNET_SCHEME_HTTP
;
3995 scheme
= INTERNET_GetSchemeString(nScheme
);
3996 *lpdwUrlLength
+= strlenW(scheme
);
3999 (*lpdwUrlLength
)++; /* ':' */
4000 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4001 *lpdwUrlLength
+= strlen("//");
4003 if (lpUrlComponents
->lpszUserName
)
4005 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4006 *lpdwUrlLength
+= strlen("@");
4010 if (lpUrlComponents
->lpszPassword
)
4012 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4017 if (lpUrlComponents
->lpszPassword
)
4019 *lpdwUrlLength
+= strlen(":");
4020 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4023 if (lpUrlComponents
->lpszHostName
)
4025 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4027 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4029 char szPort
[MAX_WORD_DIGITS
+1];
4031 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4032 *lpdwUrlLength
+= strlen(szPort
);
4033 *lpdwUrlLength
+= strlen(":");
4036 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4037 (*lpdwUrlLength
)++; /* '/' */
4040 if (lpUrlComponents
->lpszUrlPath
)
4041 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4043 if (lpUrlComponents
->lpszExtraInfo
)
4044 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4049 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4053 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4055 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4056 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4057 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4058 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4059 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4060 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4061 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4062 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4063 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4065 if (lpUrlComponents
->lpszScheme
)
4067 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4068 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4069 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4070 -1, urlCompW
->lpszScheme
, len
);
4073 if (lpUrlComponents
->lpszHostName
)
4075 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4076 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4077 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4078 -1, urlCompW
->lpszHostName
, len
);
4081 if (lpUrlComponents
->lpszUserName
)
4083 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4084 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4085 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4086 -1, urlCompW
->lpszUserName
, len
);
4089 if (lpUrlComponents
->lpszPassword
)
4091 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4092 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4093 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4094 -1, urlCompW
->lpszPassword
, len
);
4097 if (lpUrlComponents
->lpszUrlPath
)
4099 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4100 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4101 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4102 -1, urlCompW
->lpszUrlPath
, len
);
4105 if (lpUrlComponents
->lpszExtraInfo
)
4107 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4108 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4109 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4110 -1, urlCompW
->lpszExtraInfo
, len
);
4114 /***********************************************************************
4115 * InternetCreateUrlA (WININET.@)
4117 * See InternetCreateUrlW.
4119 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4120 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4124 URL_COMPONENTSW urlCompW
;
4126 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4128 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4130 SetLastError(ERROR_INVALID_PARAMETER
);
4134 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4137 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4139 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4141 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4142 *lpdwUrlLength
/= sizeof(WCHAR
);
4144 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4145 * minus one, so add one to leave room for NULL terminator
4148 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4150 heap_free(urlCompW
.lpszScheme
);
4151 heap_free(urlCompW
.lpszHostName
);
4152 heap_free(urlCompW
.lpszUserName
);
4153 heap_free(urlCompW
.lpszPassword
);
4154 heap_free(urlCompW
.lpszUrlPath
);
4155 heap_free(urlCompW
.lpszExtraInfo
);
4160 /***********************************************************************
4161 * InternetCreateUrlW (WININET.@)
4163 * Creates a URL from its component parts.
4166 * lpUrlComponents [I] URL Components.
4167 * dwFlags [I] Flags. See notes.
4168 * lpszUrl [I] Buffer in which to store the created URL.
4169 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4170 * lpszUrl in characters. On output, the number of bytes
4171 * required to store the URL including terminator.
4175 * The dwFlags parameter can be zero or more of the following:
4176 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4183 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4184 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4187 INTERNET_SCHEME nScheme
;
4189 static const WCHAR slashSlashW
[] = {'/','/'};
4190 static const WCHAR fmtW
[] = {'%','u',0};
4192 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4194 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4196 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4200 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4203 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4205 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4206 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4210 *lpdwUrlLength
= dwLen
;
4215 if (lpUrlComponents
->lpszScheme
)
4217 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4218 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4221 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4226 nScheme
= lpUrlComponents
->nScheme
;
4228 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4229 nScheme
= INTERNET_SCHEME_HTTP
;
4231 scheme
= INTERNET_GetSchemeString(nScheme
);
4232 dwLen
= strlenW(scheme
);
4233 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4237 /* all schemes are followed by at least a colon */
4241 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4243 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4244 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4247 if (lpUrlComponents
->lpszUserName
)
4249 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4250 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4253 if (lpUrlComponents
->lpszPassword
)
4258 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4259 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4267 if (lpUrlComponents
->lpszHostName
)
4269 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4270 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4273 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4275 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4277 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4280 dwLen
= strlenW(szPort
);
4281 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4285 /* add slash between hostname and path if necessary */
4286 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4293 if (lpUrlComponents
->lpszUrlPath
)
4295 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4296 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4300 if (lpUrlComponents
->lpszExtraInfo
)
4302 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4303 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4312 /***********************************************************************
4313 * InternetConfirmZoneCrossingA (WININET.@)
4316 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4318 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4319 return ERROR_SUCCESS
;
4322 /***********************************************************************
4323 * InternetConfirmZoneCrossingW (WININET.@)
4326 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4328 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4329 return ERROR_SUCCESS
;
4332 static DWORD zone_preference
= 3;
4334 /***********************************************************************
4335 * PrivacySetZonePreferenceW (WININET.@)
4337 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4339 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4341 zone_preference
= template;
4345 /***********************************************************************
4346 * PrivacyGetZonePreferenceW (WININET.@)
4348 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4349 LPWSTR preference
, LPDWORD length
)
4351 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4353 if (template) *template = zone_preference
;
4357 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4358 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4360 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4361 lpdwConnection
, dwReserved
);
4362 return ERROR_SUCCESS
;
4365 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4366 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4368 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4369 lpdwConnection
, dwReserved
);
4370 return ERROR_SUCCESS
;
4373 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4375 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4379 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4381 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4385 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4387 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4388 return ERROR_SUCCESS
;
4391 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4394 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4395 debugstr_w(pwszTarget
), pbHexHash
);
4399 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4401 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4405 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4407 FIXME("(%p, %08lx) stub\n", a
, b
);
4411 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4413 FIXME("%p: stub\n", parent
);