4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #if defined(__MINGW32__) || defined (_MSC_VER)
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 # include <sys/socket.h>
46 #ifdef HAVE_SYS_POLL_H
47 # include <sys/poll.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
65 #include "wine/debug.h"
67 #define NO_SHLWAPI_STREAM
70 #include "wine/exception.h"
75 #include "wine/unicode.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
79 #define RESPONSE_TIMEOUT 30
84 CHAR response
[MAX_REPLY_LEN
];
85 } WITHREADERROR
, *LPWITHREADERROR
;
87 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
88 HMODULE WININET_hModule
;
90 static CRITICAL_SECTION WININET_cs
;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
94 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
95 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
99 static object_header_t
**handle_table
;
100 static UINT_PTR next_handle
;
101 static UINT_PTR handle_table_size
;
110 static ULONG max_conns
= 2, max_1_0_conns
= 4;
111 static ULONG connect_timeout
= 60000;
113 static const WCHAR szInternetSettings
[] =
114 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
115 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
116 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
117 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
118 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
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(COLLECT_CLEANUP
);
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
;
878 case INTERNET_OPTION_CONNECT_TIMEOUT
:
879 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
881 if (*size
< sizeof(ULONG
))
882 return ERROR_INSUFFICIENT_BUFFER
;
884 *(ULONG
*)buffer
= ai
->connect_timeout
;
885 *size
= sizeof(ULONG
);
887 return ERROR_SUCCESS
;
890 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
893 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
895 appinfo_t
*ai
= (appinfo_t
*)hdr
;
898 case INTERNET_OPTION_CONNECT_TIMEOUT
:
899 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
901 if(size
!= sizeof(connect_timeout
))
902 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
904 return ERROR_BAD_ARGUMENTS
;
906 ai
->connect_timeout
= *(ULONG
*)buf
;
907 return ERROR_SUCCESS
;
908 case INTERNET_OPTION_USER_AGENT
:
909 heap_free(ai
->agent
);
910 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
911 return ERROR_SUCCESS
;
914 return INET_SetOption(hdr
, option
, buf
, size
);
917 static const object_vtbl_t APPINFOVtbl
= {
930 /***********************************************************************
931 * InternetOpenW (WININET.@)
933 * Per-application initialization of wininet
936 * HINTERNET on success
940 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
941 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
943 appinfo_t
*lpwai
= NULL
;
945 if (TRACE_ON(wininet
)) {
946 #define FE(x) { x, #x }
947 static const wininet_flag_info access_type
[] = {
948 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
949 FE(INTERNET_OPEN_TYPE_DIRECT
),
950 FE(INTERNET_OPEN_TYPE_PROXY
),
951 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
955 const char *access_type_str
= "Unknown";
957 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
958 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
959 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
960 if (access_type
[i
].val
== dwAccessType
) {
961 access_type_str
= access_type
[i
].name
;
965 TRACE(" access type : %s\n", access_type_str
);
967 dump_INTERNET_FLAGS(dwFlags
);
970 /* Clear any error information */
971 INTERNET_SetLastError(0);
973 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
975 SetLastError(ERROR_OUTOFMEMORY
);
979 lpwai
->hdr
.htype
= WH_HINIT
;
980 lpwai
->hdr
.dwFlags
= dwFlags
;
981 lpwai
->accessType
= dwAccessType
;
982 lpwai
->proxyUsername
= NULL
;
983 lpwai
->proxyPassword
= NULL
;
984 lpwai
->connect_timeout
= connect_timeout
;
986 lpwai
->agent
= heap_strdupW(lpszAgent
);
987 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
988 INTERNET_ConfigureProxy( lpwai
);
990 lpwai
->proxy
= heap_strdupW(lpszProxy
);
991 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
993 TRACE("returning %p\n", lpwai
);
995 return lpwai
->hdr
.hInternet
;
999 /***********************************************************************
1000 * InternetOpenA (WININET.@)
1002 * Per-application initialization of wininet
1005 * HINTERNET on success
1009 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1010 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1012 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1015 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1016 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1018 szAgent
= heap_strdupAtoW(lpszAgent
);
1019 szProxy
= heap_strdupAtoW(lpszProxy
);
1020 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1022 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1026 heap_free(szBypass
);
1030 /***********************************************************************
1031 * InternetGetLastResponseInfoA (WININET.@)
1033 * Return last wininet error description on the calling thread
1036 * TRUE on success of writing to buffer
1040 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1041 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1043 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1049 *lpdwError
= lpwite
->dwError
;
1050 if (lpwite
->dwError
)
1052 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1053 *lpdwBufferLength
= strlen(lpszBuffer
);
1056 *lpdwBufferLength
= 0;
1061 *lpdwBufferLength
= 0;
1067 /***********************************************************************
1068 * InternetGetLastResponseInfoW (WININET.@)
1070 * Return last wininet error description on the calling thread
1073 * TRUE on success of writing to buffer
1077 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1078 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1080 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1086 *lpdwError
= lpwite
->dwError
;
1087 if (lpwite
->dwError
)
1089 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1090 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1093 *lpdwBufferLength
= 0;
1098 *lpdwBufferLength
= 0;
1104 /***********************************************************************
1105 * InternetGetConnectedState (WININET.@)
1107 * Return connected state
1111 * if lpdwStatus is not null, return the status (off line,
1112 * modem, lan...) in it.
1113 * FALSE if not connected
1115 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1117 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1120 WARN("always returning LAN connection.\n");
1121 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1127 /***********************************************************************
1128 * InternetGetConnectedStateExW (WININET.@)
1130 * Return connected state
1134 * lpdwStatus [O] Flags specifying the status of the internet connection.
1135 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1136 * dwNameLen [I] Size of the buffer, in characters.
1137 * dwReserved [I] Reserved. Must be set to 0.
1141 * if lpdwStatus is not null, return the status (off line,
1142 * modem, lan...) in it.
1143 * FALSE if not connected
1146 * If the system has no available network connections, an empty string is
1147 * stored in lpszConnectionName. If there is a LAN connection, a localized
1148 * "LAN Connection" string is stored. Presumably, if only a dial-up
1149 * connection is available then the name of the dial-up connection is
1150 * returned. Why any application, other than the "Internet Settings" CPL,
1151 * would want to use this function instead of the simpler InternetGetConnectedStateW
1152 * function is beyond me.
1154 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1155 DWORD dwNameLen
, DWORD dwReserved
)
1157 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1164 WARN("always returning LAN connection.\n");
1165 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1167 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1171 /***********************************************************************
1172 * InternetGetConnectedStateExA (WININET.@)
1174 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1175 DWORD dwNameLen
, DWORD dwReserved
)
1177 LPWSTR lpwszConnectionName
= NULL
;
1180 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1182 if (lpszConnectionName
&& dwNameLen
> 0)
1183 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1185 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1187 if (rc
&& lpwszConnectionName
)
1189 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1190 dwNameLen
, NULL
, NULL
);
1191 heap_free(lpwszConnectionName
);
1197 /***********************************************************************
1198 * InternetConnectW (WININET.@)
1200 * Open a ftp, gopher or http session
1203 * HINTERNET a session handle on success
1207 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1208 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1209 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1210 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1213 HINTERNET rc
= NULL
;
1214 DWORD res
= ERROR_SUCCESS
;
1216 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1217 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1218 dwService
, dwFlags
, dwContext
);
1220 if (!lpszServerName
)
1222 SetLastError(ERROR_INVALID_PARAMETER
);
1226 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1227 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1229 res
= ERROR_INVALID_HANDLE
;
1235 case INTERNET_SERVICE_FTP
:
1236 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1237 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1239 res
= INTERNET_GetLastError();
1242 case INTERNET_SERVICE_HTTP
:
1243 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1244 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1247 case INTERNET_SERVICE_GOPHER
:
1253 WININET_Release( &hIC
->hdr
);
1255 TRACE("returning %p\n", rc
);
1261 /***********************************************************************
1262 * InternetConnectA (WININET.@)
1264 * Open a ftp, gopher or http session
1267 * HINTERNET a session handle on success
1271 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1272 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1273 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1274 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1276 HINTERNET rc
= NULL
;
1277 LPWSTR szServerName
;
1281 szServerName
= heap_strdupAtoW(lpszServerName
);
1282 szUserName
= heap_strdupAtoW(lpszUserName
);
1283 szPassword
= heap_strdupAtoW(lpszPassword
);
1285 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1286 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1288 heap_free(szServerName
);
1289 heap_free(szUserName
);
1290 heap_free(szPassword
);
1295 /***********************************************************************
1296 * InternetFindNextFileA (WININET.@)
1298 * Continues a file search from a previous call to FindFirstFile
1305 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1308 WIN32_FIND_DATAW fd
;
1310 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1312 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1316 /***********************************************************************
1317 * InternetFindNextFileW (WININET.@)
1319 * Continues a file search from a previous call to FindFirstFile
1326 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1328 object_header_t
*hdr
;
1333 hdr
= get_handle_object(hFind
);
1335 WARN("Invalid handle\n");
1336 SetLastError(ERROR_INVALID_HANDLE
);
1340 if(hdr
->vtbl
->FindNextFileW
) {
1341 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1343 WARN("Handle doesn't support NextFile\n");
1344 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1347 WININET_Release(hdr
);
1349 if(res
!= ERROR_SUCCESS
)
1351 return res
== ERROR_SUCCESS
;
1354 /***********************************************************************
1355 * InternetCloseHandle (WININET.@)
1357 * Generic close handle function
1364 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1366 object_header_t
*obj
;
1368 TRACE("%p\n", hInternet
);
1370 obj
= get_handle_object( hInternet
);
1372 SetLastError(ERROR_INVALID_HANDLE
);
1376 invalidate_handle(obj
);
1377 WININET_Release(obj
);
1383 /***********************************************************************
1384 * ConvertUrlComponentValue (Internal)
1386 * Helper function for InternetCrackUrlA
1389 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1390 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1391 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1393 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1394 if (*dwComponentLen
!= 0)
1396 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1397 if (*lppszComponent
== NULL
)
1401 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1402 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1405 *lppszComponent
= NULL
;
1407 *dwComponentLen
= nASCIILength
;
1411 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1412 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1413 (*lppszComponent
)[ncpylen
]=0;
1414 *dwComponentLen
= ncpylen
;
1420 /***********************************************************************
1421 * InternetCrackUrlA (WININET.@)
1423 * See InternetCrackUrlW.
1425 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1426 LPURL_COMPONENTSA lpUrlComponents
)
1429 URL_COMPONENTSW UCW
;
1431 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1432 *scheme
= NULL
, *extra
= NULL
;
1434 TRACE("(%s %u %x %p)\n",
1435 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1436 dwUrlLength
, dwFlags
, lpUrlComponents
);
1438 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1439 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1441 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1447 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1449 /* if dwUrlLength=-1 then nLength includes null but length to
1450 InternetCrackUrlW should not include it */
1451 if (dwUrlLength
== -1) nLength
--;
1453 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1454 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1455 lpwszUrl
[nLength
] = '\0';
1457 memset(&UCW
,0,sizeof(UCW
));
1458 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1459 if (lpUrlComponents
->dwHostNameLength
)
1461 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1462 if (lpUrlComponents
->lpszHostName
)
1464 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1465 UCW
.lpszHostName
= hostname
;
1468 if (lpUrlComponents
->dwUserNameLength
)
1470 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1471 if (lpUrlComponents
->lpszUserName
)
1473 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1474 UCW
.lpszUserName
= username
;
1477 if (lpUrlComponents
->dwPasswordLength
)
1479 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1480 if (lpUrlComponents
->lpszPassword
)
1482 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1483 UCW
.lpszPassword
= password
;
1486 if (lpUrlComponents
->dwUrlPathLength
)
1488 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1489 if (lpUrlComponents
->lpszUrlPath
)
1491 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1492 UCW
.lpszUrlPath
= path
;
1495 if (lpUrlComponents
->dwSchemeLength
)
1497 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1498 if (lpUrlComponents
->lpszScheme
)
1500 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1501 UCW
.lpszScheme
= scheme
;
1504 if (lpUrlComponents
->dwExtraInfoLength
)
1506 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1507 if (lpUrlComponents
->lpszExtraInfo
)
1509 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1510 UCW
.lpszExtraInfo
= extra
;
1513 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1515 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1516 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1517 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1518 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1519 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1520 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1521 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1522 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1523 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1524 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1525 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1526 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1528 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1529 lpUrlComponents
->nPort
= UCW
.nPort
;
1531 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1532 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1533 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1534 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1535 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1537 heap_free(lpwszUrl
);
1538 heap_free(hostname
);
1539 heap_free(username
);
1540 heap_free(password
);
1547 static const WCHAR url_schemes
[][7] =
1550 {'g','o','p','h','e','r',0},
1551 {'h','t','t','p',0},
1552 {'h','t','t','p','s',0},
1553 {'f','i','l','e',0},
1554 {'n','e','w','s',0},
1555 {'m','a','i','l','t','o',0},
1559 /***********************************************************************
1560 * GetInternetSchemeW (internal)
1566 * INTERNET_SCHEME_UNKNOWN on failure
1569 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1573 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1575 if(lpszScheme
==NULL
)
1576 return INTERNET_SCHEME_UNKNOWN
;
1578 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1579 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1580 return INTERNET_SCHEME_FIRST
+ i
;
1582 return INTERNET_SCHEME_UNKNOWN
;
1585 /***********************************************************************
1586 * SetUrlComponentValueW (Internal)
1588 * Helper function for InternetCrackUrlW
1591 * lppszComponent [O] Holds the returned string
1592 * dwComponentLen [I] Holds the size of lppszComponent
1593 * [O] Holds the length of the string in lppszComponent without '\0'
1594 * lpszStart [I] Holds the string to copy from
1595 * len [I] Holds the length of lpszStart without '\0'
1602 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1604 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1606 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1609 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1611 if (*lppszComponent
== NULL
)
1613 *lppszComponent
= (LPWSTR
)lpszStart
;
1614 *dwComponentLen
= len
;
1618 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1619 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1620 (*lppszComponent
)[ncpylen
] = '\0';
1621 *dwComponentLen
= ncpylen
;
1628 /***********************************************************************
1629 * InternetCrackUrlW (WININET.@)
1631 * Break up URL into its components
1637 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1638 LPURL_COMPONENTSW lpUC
)
1642 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1645 LPCWSTR lpszParam
= NULL
;
1646 BOOL bIsAbsolute
= FALSE
;
1647 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1648 LPCWSTR lpszcp
= NULL
;
1649 LPWSTR lpszUrl_decode
= NULL
;
1650 DWORD dwUrlLength
= dwUrlLength_orig
;
1652 TRACE("(%s %u %x %p)\n",
1653 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1654 dwUrlLength
, dwFlags
, lpUC
);
1656 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1658 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1661 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1663 if (dwFlags
& ICU_DECODE
)
1666 DWORD len
= dwUrlLength
+ 1;
1668 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1670 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1673 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1674 url_tmp
[dwUrlLength
] = 0;
1675 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1678 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1681 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1684 lpszUrl
= lpszUrl_decode
;
1690 /* Determine if the URI is absolute. */
1691 while (lpszap
- lpszUrl
< dwUrlLength
)
1693 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1698 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1705 lpszcp
= lpszUrl
; /* Relative url */
1711 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1712 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1714 /* Parse <params> */
1715 lpszParam
= memchrW(lpszap
, ';', dwUrlLength
- (lpszap
- lpszUrl
));
1717 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1719 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1721 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1722 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1724 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1728 /* Get scheme first. */
1729 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1730 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1731 lpszUrl
, lpszcp
- lpszUrl
);
1733 /* Eat ':' in protocol. */
1736 /* double slash indicates the net_loc portion is present */
1737 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1741 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1745 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1747 lpszNetLoc
= lpszParam
;
1749 else if (!lpszNetLoc
)
1750 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1758 /* [<user>[<:password>]@]<host>[:<port>] */
1759 /* First find the user and password if they exist */
1761 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1762 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1764 /* username and password not specified. */
1765 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1766 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1768 else /* Parse out username and password */
1770 LPCWSTR lpszUser
= lpszcp
;
1771 LPCWSTR lpszPasswd
= lpszHost
;
1773 while (lpszcp
< lpszHost
)
1776 lpszPasswd
= lpszcp
;
1781 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1782 lpszUser
, lpszPasswd
- lpszUser
);
1784 if (lpszPasswd
!= lpszHost
)
1786 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1787 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1788 lpszHost
- lpszPasswd
);
1790 lpszcp
++; /* Advance to beginning of host */
1793 /* Parse <host><:port> */
1796 lpszPort
= lpszNetLoc
;
1798 /* special case for res:// URLs: there is no port here, so the host is the
1799 entire string up to the first '/' */
1800 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1802 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1803 lpszHost
, lpszPort
- lpszHost
);
1808 while (lpszcp
< lpszNetLoc
)
1816 /* If the scheme is "file" and the host is just one letter, it's not a host */
1817 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1820 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1825 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1826 lpszHost
, lpszPort
- lpszHost
);
1827 if (lpszPort
!= lpszNetLoc
)
1828 lpUC
->nPort
= atoiW(++lpszPort
);
1829 else switch (lpUC
->nScheme
)
1831 case INTERNET_SCHEME_HTTP
:
1832 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1834 case INTERNET_SCHEME_HTTPS
:
1835 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1837 case INTERNET_SCHEME_FTP
:
1838 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1840 case INTERNET_SCHEME_GOPHER
:
1841 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1852 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1853 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1854 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1859 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1860 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1861 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1862 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1865 /* Here lpszcp points to:
1867 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1868 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1870 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1874 /* Only truncate the parameter list if it's already been saved
1875 * in lpUC->lpszExtraInfo.
1877 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1878 len
= lpszParam
- lpszcp
;
1881 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1882 * newlines if necessary.
1884 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1885 if (lpsznewline
!= NULL
)
1886 len
= lpsznewline
- lpszcp
;
1888 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1890 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1891 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1893 WCHAR tmppath
[MAX_PATH
];
1897 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1902 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1903 tmppath
[len
] = '\0';
1912 /* if ends in \. or \.. append a backslash */
1913 if (tmppath
[len
- 1] == '.' &&
1914 (tmppath
[len
- 2] == '\\' ||
1915 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1917 if (len
< MAX_PATH
- 1)
1919 tmppath
[len
] = '\\';
1920 tmppath
[len
+1] = '\0';
1924 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1928 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1933 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1934 lpUC
->lpszUrlPath
[0] = 0;
1935 lpUC
->dwUrlPathLength
= 0;
1938 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1939 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1940 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1941 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1942 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1944 heap_free( lpszUrl_decode
);
1948 /***********************************************************************
1949 * InternetAttemptConnect (WININET.@)
1951 * Attempt to make a connection to the internet
1954 * ERROR_SUCCESS on success
1955 * Error value on failure
1958 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1961 return ERROR_SUCCESS
;
1965 /***********************************************************************
1966 * InternetCanonicalizeUrlA (WININET.@)
1968 * Escape unsafe characters and spaces
1975 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1976 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1979 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1981 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1982 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1984 if(dwFlags
& ICU_DECODE
)
1986 dwURLFlags
|= URL_UNESCAPE
;
1987 dwFlags
&= ~ICU_DECODE
;
1990 if(dwFlags
& ICU_ESCAPE
)
1992 dwURLFlags
|= URL_UNESCAPE
;
1993 dwFlags
&= ~ICU_ESCAPE
;
1996 if(dwFlags
& ICU_BROWSER_MODE
)
1998 dwURLFlags
|= URL_BROWSER_MODE
;
1999 dwFlags
&= ~ICU_BROWSER_MODE
;
2002 if(dwFlags
& ICU_NO_ENCODE
)
2004 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2005 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
2006 dwFlags
&= ~ICU_NO_ENCODE
;
2009 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
2011 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
2012 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2013 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2015 return (hr
== S_OK
) ? TRUE
: FALSE
;
2018 /***********************************************************************
2019 * InternetCanonicalizeUrlW (WININET.@)
2021 * Escape unsafe characters and spaces
2028 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2029 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2032 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2034 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2035 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2037 if(dwFlags
& ICU_DECODE
)
2039 dwURLFlags
|= URL_UNESCAPE
;
2040 dwFlags
&= ~ICU_DECODE
;
2043 if(dwFlags
& ICU_ESCAPE
)
2045 dwURLFlags
|= URL_UNESCAPE
;
2046 dwFlags
&= ~ICU_ESCAPE
;
2049 if(dwFlags
& ICU_BROWSER_MODE
)
2051 dwURLFlags
|= URL_BROWSER_MODE
;
2052 dwFlags
&= ~ICU_BROWSER_MODE
;
2055 if(dwFlags
& ICU_NO_ENCODE
)
2057 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2058 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
2059 dwFlags
&= ~ICU_NO_ENCODE
;
2062 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
2064 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
2065 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2066 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2068 return (hr
== S_OK
) ? TRUE
: FALSE
;
2071 /* #################################################### */
2073 static INTERNET_STATUS_CALLBACK
set_status_callback(
2074 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2076 INTERNET_STATUS_CALLBACK ret
;
2078 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2079 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2081 ret
= lpwh
->lpfnStatusCB
;
2082 lpwh
->lpfnStatusCB
= callback
;
2087 /***********************************************************************
2088 * InternetSetStatusCallbackA (WININET.@)
2090 * Sets up a callback function which is called as progress is made
2091 * during an operation.
2094 * Previous callback or NULL on success
2095 * INTERNET_INVALID_STATUS_CALLBACK on failure
2098 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2099 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2101 INTERNET_STATUS_CALLBACK retVal
;
2102 object_header_t
*lpwh
;
2104 TRACE("%p\n", hInternet
);
2106 if (!(lpwh
= get_handle_object(hInternet
)))
2107 return INTERNET_INVALID_STATUS_CALLBACK
;
2109 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2111 WININET_Release( lpwh
);
2115 /***********************************************************************
2116 * InternetSetStatusCallbackW (WININET.@)
2118 * Sets up a callback function which is called as progress is made
2119 * during an operation.
2122 * Previous callback or NULL on success
2123 * INTERNET_INVALID_STATUS_CALLBACK on failure
2126 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2127 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2129 INTERNET_STATUS_CALLBACK retVal
;
2130 object_header_t
*lpwh
;
2132 TRACE("%p\n", hInternet
);
2134 if (!(lpwh
= get_handle_object(hInternet
)))
2135 return INTERNET_INVALID_STATUS_CALLBACK
;
2137 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2139 WININET_Release( lpwh
);
2143 /***********************************************************************
2144 * InternetSetFilePointer (WININET.@)
2146 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2147 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2149 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2153 /***********************************************************************
2154 * InternetWriteFile (WININET.@)
2156 * Write data to an open internet file
2163 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2164 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2166 object_header_t
*lpwh
;
2169 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2171 lpwh
= get_handle_object( hFile
);
2173 WARN("Invalid handle\n");
2174 SetLastError(ERROR_INVALID_HANDLE
);
2178 if(lpwh
->vtbl
->WriteFile
) {
2179 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2181 WARN("No Writefile method.\n");
2182 res
= ERROR_INVALID_HANDLE
;
2185 WININET_Release( lpwh
);
2187 if(res
!= ERROR_SUCCESS
)
2189 return res
== ERROR_SUCCESS
;
2193 /***********************************************************************
2194 * InternetReadFile (WININET.@)
2196 * Read data from an open internet file
2203 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2204 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2206 object_header_t
*hdr
;
2207 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2209 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2211 hdr
= get_handle_object(hFile
);
2213 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2217 if(hdr
->vtbl
->ReadFile
)
2218 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2220 WININET_Release(hdr
);
2222 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2223 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2225 if(res
!= ERROR_SUCCESS
)
2227 return res
== ERROR_SUCCESS
;
2230 /***********************************************************************
2231 * InternetReadFileExA (WININET.@)
2233 * Read data from an open internet file
2236 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2237 * lpBuffersOut [I/O] Buffer.
2238 * dwFlags [I] Flags. See notes.
2239 * dwContext [I] Context for callbacks.
2246 * The parameter dwFlags include zero or more of the following flags:
2247 *|IRF_ASYNC - Makes the call asynchronous.
2248 *|IRF_SYNC - Makes the call synchronous.
2249 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2250 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2252 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2255 * InternetOpenUrlA(), HttpOpenRequestA()
2257 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2258 DWORD dwFlags
, DWORD_PTR dwContext
)
2260 object_header_t
*hdr
;
2261 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2263 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2265 hdr
= get_handle_object(hFile
);
2267 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2271 if(hdr
->vtbl
->ReadFileExA
)
2272 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
2274 WININET_Release(hdr
);
2276 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2277 res
, lpBuffersOut
->dwBufferLength
);
2279 if(res
!= ERROR_SUCCESS
)
2281 return res
== ERROR_SUCCESS
;
2284 /***********************************************************************
2285 * InternetReadFileExW (WININET.@)
2287 * InternetReadFileExA()
2289 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2290 DWORD dwFlags
, DWORD_PTR dwContext
)
2292 object_header_t
*hdr
;
2293 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2295 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2297 hdr
= get_handle_object(hFile
);
2299 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2303 if(hdr
->vtbl
->ReadFileExW
)
2304 res
= hdr
->vtbl
->ReadFileExW(hdr
, lpBuffer
, dwFlags
, dwContext
);
2306 WININET_Release(hdr
);
2308 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2309 res
, lpBuffer
->dwBufferLength
);
2311 if(res
!= ERROR_SUCCESS
)
2313 return res
== ERROR_SUCCESS
;
2316 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2318 /* FIXME: This function currently handles more options than it should. Options requiring
2319 * proper handles should be moved to proper functions */
2321 case INTERNET_OPTION_HTTP_VERSION
:
2322 if (*size
< sizeof(HTTP_VERSION_INFO
))
2323 return ERROR_INSUFFICIENT_BUFFER
;
2326 * Presently hardcoded to 1.1
2328 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2329 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2330 *size
= sizeof(HTTP_VERSION_INFO
);
2332 return ERROR_SUCCESS
;
2334 case INTERNET_OPTION_CONNECTED_STATE
:
2335 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2337 if (*size
< sizeof(ULONG
))
2338 return ERROR_INSUFFICIENT_BUFFER
;
2340 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2341 *size
= sizeof(ULONG
);
2343 return ERROR_SUCCESS
;
2345 case INTERNET_OPTION_PROXY
: {
2349 TRACE("Getting global proxy info\n");
2350 memset(&ai
, 0, sizeof(appinfo_t
));
2351 INTERNET_ConfigureProxy(&ai
);
2353 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2354 APPINFO_Destroy(&ai
.hdr
);
2358 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2359 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2361 if (*size
< sizeof(ULONG
))
2362 return ERROR_INSUFFICIENT_BUFFER
;
2364 *(ULONG
*)buffer
= max_conns
;
2365 *size
= sizeof(ULONG
);
2367 return ERROR_SUCCESS
;
2369 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2370 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2372 if (*size
< sizeof(ULONG
))
2373 return ERROR_INSUFFICIENT_BUFFER
;
2375 *(ULONG
*)buffer
= max_1_0_conns
;
2376 *size
= sizeof(ULONG
);
2378 return ERROR_SUCCESS
;
2380 case INTERNET_OPTION_SECURITY_FLAGS
:
2381 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2382 return ERROR_SUCCESS
;
2384 case INTERNET_OPTION_VERSION
: {
2385 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2387 TRACE("INTERNET_OPTION_VERSION\n");
2389 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2390 return ERROR_INSUFFICIENT_BUFFER
;
2392 memcpy(buffer
, &info
, sizeof(info
));
2393 *size
= sizeof(info
);
2395 return ERROR_SUCCESS
;
2398 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2399 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2400 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2401 DWORD res
= ERROR_SUCCESS
, i
;
2405 TRACE("Getting global proxy info\n");
2406 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2409 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2411 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2413 return ERROR_INSUFFICIENT_BUFFER
;
2416 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2417 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2418 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2420 switch (optionW
->dwOption
) {
2421 case INTERNET_PER_CONN_FLAGS
:
2423 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2425 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2428 case INTERNET_PER_CONN_PROXY_SERVER
:
2430 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2432 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2435 case INTERNET_PER_CONN_PROXY_BYPASS
:
2437 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2439 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2442 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2443 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2444 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2445 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2446 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2447 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2448 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2449 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2453 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2454 res
= ERROR_INVALID_PARAMETER
;
2462 case INTERNET_OPTION_REQUEST_FLAGS
:
2463 case INTERNET_OPTION_USER_AGENT
:
2465 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2466 case INTERNET_OPTION_POLICY
:
2467 return ERROR_INVALID_PARAMETER
;
2468 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2469 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2471 if (*size
< sizeof(ULONG
))
2472 return ERROR_INSUFFICIENT_BUFFER
;
2474 *(ULONG
*)buffer
= connect_timeout
;
2475 *size
= sizeof(ULONG
);
2477 return ERROR_SUCCESS
;
2480 FIXME("Stub for %d\n", option
);
2481 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2484 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2487 case INTERNET_OPTION_CONTEXT_VALUE
:
2489 return ERROR_INVALID_PARAMETER
;
2491 if (*size
< sizeof(DWORD_PTR
)) {
2492 *size
= sizeof(DWORD_PTR
);
2493 return ERROR_INSUFFICIENT_BUFFER
;
2496 return ERROR_INVALID_PARAMETER
;
2498 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2499 *size
= sizeof(DWORD_PTR
);
2500 return ERROR_SUCCESS
;
2502 case INTERNET_OPTION_REQUEST_FLAGS
:
2503 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2504 *size
= sizeof(DWORD
);
2505 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2507 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2508 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2509 WARN("Called on global option %u\n", option
);
2510 return ERROR_INTERNET_INVALID_OPERATION
;
2513 /* FIXME: we shouldn't call it here */
2514 return query_global_option(option
, buffer
, size
, unicode
);
2517 /***********************************************************************
2518 * InternetQueryOptionW (WININET.@)
2520 * Queries an options on the specified handle
2527 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2528 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2530 object_header_t
*hdr
;
2531 DWORD res
= ERROR_INVALID_HANDLE
;
2533 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2536 hdr
= get_handle_object(hInternet
);
2538 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2539 WININET_Release(hdr
);
2542 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2545 if(res
!= ERROR_SUCCESS
)
2547 return res
== ERROR_SUCCESS
;
2550 /***********************************************************************
2551 * InternetQueryOptionA (WININET.@)
2553 * Queries an options on the specified handle
2560 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2561 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2563 object_header_t
*hdr
;
2564 DWORD res
= ERROR_INVALID_HANDLE
;
2566 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2569 hdr
= get_handle_object(hInternet
);
2571 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2572 WININET_Release(hdr
);
2575 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2578 if(res
!= ERROR_SUCCESS
)
2580 return res
== ERROR_SUCCESS
;
2583 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2586 case INTERNET_OPTION_CALLBACK
:
2587 WARN("Not settable option %u\n", option
);
2588 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2589 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2590 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2591 WARN("Called on global option %u\n", option
);
2592 return ERROR_INTERNET_INVALID_OPERATION
;
2595 return ERROR_INTERNET_INVALID_OPTION
;
2598 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2601 case INTERNET_OPTION_CALLBACK
:
2602 WARN("Not global option %u\n", option
);
2603 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2605 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2606 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2608 if(size
!= sizeof(max_conns
))
2609 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2611 return ERROR_BAD_ARGUMENTS
;
2613 max_conns
= *(ULONG
*)buf
;
2614 return ERROR_SUCCESS
;
2616 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2617 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2619 if(size
!= sizeof(max_1_0_conns
))
2620 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2622 return ERROR_BAD_ARGUMENTS
;
2624 max_1_0_conns
= *(ULONG
*)buf
;
2625 return ERROR_SUCCESS
;
2627 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2628 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2630 if(size
!= sizeof(connect_timeout
))
2631 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2633 return ERROR_BAD_ARGUMENTS
;
2635 connect_timeout
= *(ULONG
*)buf
;
2636 return ERROR_SUCCESS
;
2638 case INTERNET_OPTION_SETTINGS_CHANGED
:
2639 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2640 collect_connections(COLLECT_CONNECTIONS
);
2641 return ERROR_SUCCESS
;
2644 return ERROR_INTERNET_INVALID_OPTION
;
2647 /***********************************************************************
2648 * InternetSetOptionW (WININET.@)
2650 * Sets an options on the specified handle
2657 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2658 LPVOID lpBuffer
, DWORD dwBufferLength
)
2660 object_header_t
*lpwhh
;
2664 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2666 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2668 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2670 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2672 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2674 WININET_Release(lpwhh
);
2676 if(res
!= ERROR_SUCCESS
)
2679 return res
== ERROR_SUCCESS
;
2684 case INTERNET_OPTION_HTTP_VERSION
:
2686 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2687 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2690 case INTERNET_OPTION_ERROR_MASK
:
2693 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2695 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2696 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2697 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2698 SetLastError(ERROR_INVALID_PARAMETER
);
2700 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2701 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2704 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2705 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2708 case INTERNET_OPTION_PROXY
:
2710 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2712 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2714 SetLastError(ERROR_INVALID_PARAMETER
);
2719 EnterCriticalSection( &WININET_cs
);
2720 free_global_proxy();
2721 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2724 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2726 global_proxy
->proxyEnabled
= 1;
2727 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2728 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2732 global_proxy
->proxyEnabled
= 0;
2733 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2736 LeaveCriticalSection( &WININET_cs
);
2740 /* In general, each type of object should handle
2741 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2742 * get silently dropped.
2744 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2745 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2750 case INTERNET_OPTION_CODEPAGE
:
2752 ULONG codepage
= *(ULONG
*)lpBuffer
;
2753 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2756 case INTERNET_OPTION_REQUEST_PRIORITY
:
2758 ULONG priority
= *(ULONG
*)lpBuffer
;
2759 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2762 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2764 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2765 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2768 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2770 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2771 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2774 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2775 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2777 case INTERNET_OPTION_END_BROWSER_SESSION
:
2778 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2780 case INTERNET_OPTION_CONNECTED_STATE
:
2781 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2783 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2784 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2786 case INTERNET_OPTION_SEND_TIMEOUT
:
2787 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2788 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2790 ULONG timeout
= *(ULONG
*)lpBuffer
;
2791 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2794 case INTERNET_OPTION_CONNECT_RETRIES
:
2796 ULONG retries
= *(ULONG
*)lpBuffer
;
2797 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2800 case INTERNET_OPTION_CONTEXT_VALUE
:
2804 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2807 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2809 SetLastError(ERROR_INVALID_PARAMETER
);
2813 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2816 case INTERNET_OPTION_SECURITY_FLAGS
:
2817 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2819 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2820 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2822 case INTERNET_OPTION_HTTP_DECODING
:
2823 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2824 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2827 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2828 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2829 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2832 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2833 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2834 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2837 case INTERNET_OPTION_CODEPAGE_PATH
:
2838 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2839 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2842 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2843 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2844 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2847 case INTERNET_OPTION_IDN
:
2848 FIXME("INTERNET_OPTION_IDN; STUB\n");
2849 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2852 case INTERNET_OPTION_POLICY
:
2853 SetLastError(ERROR_INVALID_PARAMETER
);
2856 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2857 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2862 INTERNET_LoadProxySettings(&pi
);
2864 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2865 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2867 switch (option
->dwOption
) {
2868 case INTERNET_PER_CONN_PROXY_SERVER
:
2869 heap_free(pi
.proxy
);
2870 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2873 case INTERNET_PER_CONN_FLAGS
:
2874 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2875 pi
.proxyEnabled
= 1;
2878 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2879 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2880 pi
.proxyEnabled
= 0;
2884 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2885 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2886 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2887 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2888 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2889 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2890 case INTERNET_PER_CONN_PROXY_BYPASS
:
2891 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2895 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2896 SetLastError(ERROR_INVALID_PARAMETER
);
2901 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2906 ret
= (res
== ERROR_SUCCESS
);
2910 FIXME("Option %d STUB\n",dwOption
);
2911 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2917 WININET_Release( lpwhh
);
2923 /***********************************************************************
2924 * InternetSetOptionA (WININET.@)
2926 * Sets an options on the specified handle.
2933 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2934 LPVOID lpBuffer
, DWORD dwBufferLength
)
2942 case INTERNET_OPTION_PROXY
:
2944 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2945 LPINTERNET_PROXY_INFOW piw
;
2946 DWORD proxlen
, prbylen
;
2949 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2950 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2951 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2952 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2953 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2954 piw
->dwAccessType
= pi
->dwAccessType
;
2955 prox
= (LPWSTR
) &piw
[1];
2956 prby
= &prox
[proxlen
+1];
2957 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2958 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2959 piw
->lpszProxy
= prox
;
2960 piw
->lpszProxyBypass
= prby
;
2963 case INTERNET_OPTION_USER_AGENT
:
2964 case INTERNET_OPTION_USERNAME
:
2965 case INTERNET_OPTION_PASSWORD
:
2966 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2968 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2969 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2972 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2974 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
2975 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
2976 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2977 wbuffer
= heap_alloc(wlen
);
2980 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2981 if (listA
->pszConnection
)
2983 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
2984 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
2985 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
2988 listW
->pszConnection
= NULL
;
2989 listW
->dwOptionCount
= listA
->dwOptionCount
;
2990 listW
->dwOptionError
= listA
->dwOptionError
;
2991 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
2993 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
2994 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
2995 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
2997 optW
->dwOption
= optA
->dwOption
;
2999 switch (optA
->dwOption
) {
3000 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3001 case INTERNET_PER_CONN_PROXY_BYPASS
:
3002 case INTERNET_PER_CONN_PROXY_SERVER
:
3003 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3004 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3005 if (optA
->Value
.pszValue
)
3007 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3008 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3009 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3012 optW
->Value
.pszValue
= NULL
;
3014 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3015 case INTERNET_PER_CONN_FLAGS
:
3016 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3017 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3019 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3020 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3023 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3024 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3032 wlen
= dwBufferLength
;
3035 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3037 if( lpBuffer
!= wbuffer
)
3039 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3041 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3043 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3044 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3045 switch (opt
->dwOption
) {
3046 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3047 case INTERNET_PER_CONN_PROXY_BYPASS
:
3048 case INTERNET_PER_CONN_PROXY_SERVER
:
3049 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3050 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3051 heap_free( opt
->Value
.pszValue
);
3057 heap_free( list
->pOptions
);
3059 heap_free( wbuffer
);
3066 /***********************************************************************
3067 * InternetSetOptionExA (WININET.@)
3069 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3070 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3072 FIXME("Flags %08x ignored\n", dwFlags
);
3073 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3076 /***********************************************************************
3077 * InternetSetOptionExW (WININET.@)
3079 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3080 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3082 FIXME("Flags %08x ignored\n", dwFlags
);
3083 if( dwFlags
& ~ISO_VALID_FLAGS
)
3085 SetLastError( ERROR_INVALID_PARAMETER
);
3088 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3091 static const WCHAR WININET_wkday
[7][4] =
3092 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3093 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3094 static const WCHAR WININET_month
[12][4] =
3095 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3096 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3097 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3099 /***********************************************************************
3100 * InternetTimeFromSystemTimeA (WININET.@)
3102 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3105 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3107 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3109 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3111 SetLastError(ERROR_INVALID_PARAMETER
);
3115 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3117 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3121 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3122 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3127 /***********************************************************************
3128 * InternetTimeFromSystemTimeW (WININET.@)
3130 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3132 static const WCHAR date
[] =
3133 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3134 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3136 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3138 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3140 SetLastError(ERROR_INVALID_PARAMETER
);
3144 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3146 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3150 sprintfW( string
, date
,
3151 WININET_wkday
[time
->wDayOfWeek
],
3153 WININET_month
[time
->wMonth
- 1],
3162 /***********************************************************************
3163 * InternetTimeToSystemTimeA (WININET.@)
3165 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3170 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3172 stringW
= heap_strdupAtoW(string
);
3175 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3176 heap_free( stringW
);
3181 /***********************************************************************
3182 * InternetTimeToSystemTimeW (WININET.@)
3184 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3187 const WCHAR
*s
= string
;
3190 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3192 if (!string
|| !time
) return FALSE
;
3194 /* Windows does this too */
3195 GetSystemTime( time
);
3197 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3198 * a SYSTEMTIME structure.
3201 while (*s
&& !isalphaW( *s
)) s
++;
3202 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3203 time
->wDayOfWeek
= 7;
3205 for (i
= 0; i
< 7; i
++)
3207 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3208 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3209 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3211 time
->wDayOfWeek
= i
;
3216 if (time
->wDayOfWeek
> 6) return TRUE
;
3217 while (*s
&& !isdigitW( *s
)) s
++;
3218 time
->wDay
= strtolW( s
, &end
, 10 );
3221 while (*s
&& !isalphaW( *s
)) s
++;
3222 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3225 for (i
= 0; i
< 12; i
++)
3227 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3228 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3229 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3231 time
->wMonth
= i
+ 1;
3235 if (time
->wMonth
== 0) return TRUE
;
3237 while (*s
&& !isdigitW( *s
)) s
++;
3238 if (*s
== '\0') return TRUE
;
3239 time
->wYear
= strtolW( s
, &end
, 10 );
3242 while (*s
&& !isdigitW( *s
)) s
++;
3243 if (*s
== '\0') return TRUE
;
3244 time
->wHour
= strtolW( s
, &end
, 10 );
3247 while (*s
&& !isdigitW( *s
)) s
++;
3248 if (*s
== '\0') return TRUE
;
3249 time
->wMinute
= strtolW( s
, &end
, 10 );
3252 while (*s
&& !isdigitW( *s
)) s
++;
3253 if (*s
== '\0') return TRUE
;
3254 time
->wSecond
= strtolW( s
, &end
, 10 );
3257 time
->wMilliseconds
= 0;
3261 /***********************************************************************
3262 * InternetCheckConnectionW (WININET.@)
3264 * Pings a requested host to check internet connection
3267 * TRUE on success and FALSE on failure. If a failure then
3268 * ERROR_NOT_CONNECTED is placed into GetLastError
3271 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3274 * this is a kludge which runs the resident ping program and reads the output.
3276 * Anyone have a better idea?
3280 static const CHAR ping
[] = "ping -c 1 ";
3281 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3282 CHAR
*command
= NULL
;
3283 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3291 * Crack or set the Address
3293 if (lpszUrl
== NULL
)
3296 * According to the doc we are supposed to use the ip for the next
3297 * server in the WnInet internal server database. I have
3298 * no idea what that is or how to get it.
3300 * So someone needs to implement this.
3302 FIXME("Unimplemented with URL of NULL\n");
3307 URL_COMPONENTSW components
;
3309 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3310 components
.lpszHostName
= (LPWSTR
)hostW
;
3311 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3313 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3316 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3317 port
= components
.nPort
;
3318 TRACE("port: %d\n", port
);
3321 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3323 struct sockaddr_storage saddr
;
3324 socklen_t sa_len
= sizeof(saddr
);
3327 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3329 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3332 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3340 * Build our ping command
3342 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3343 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3344 strcpy(command
,ping
);
3345 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3346 strcat(command
,redirect
);
3348 TRACE("Ping command is : %s\n",command
);
3350 status
= system(command
);
3352 TRACE("Ping returned a code of %i\n",status
);
3354 /* Ping return code of 0 indicates success */
3360 heap_free( command
);
3362 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3368 /***********************************************************************
3369 * InternetCheckConnectionA (WININET.@)
3371 * Pings a requested host to check internet connection
3374 * TRUE on success and FALSE on failure. If a failure then
3375 * ERROR_NOT_CONNECTED is placed into GetLastError
3378 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3384 url
= heap_strdupAtoW(lpszUrl
);
3389 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3396 /**********************************************************
3397 * INTERNET_InternetOpenUrlW (internal)
3402 * handle of connection or NULL on failure
3404 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3405 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3407 URL_COMPONENTSW urlComponents
;
3408 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3409 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3410 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3411 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3412 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3414 HINTERNET client
= NULL
, client1
= NULL
;
3417 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3418 dwHeadersLength
, dwFlags
, dwContext
);
3420 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3421 urlComponents
.lpszScheme
= protocol
;
3422 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3423 urlComponents
.lpszHostName
= hostName
;
3424 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3425 urlComponents
.lpszUserName
= userName
;
3426 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3427 urlComponents
.lpszPassword
= password
;
3428 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3429 urlComponents
.lpszUrlPath
= path
;
3430 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3431 urlComponents
.lpszExtraInfo
= extra
;
3432 urlComponents
.dwExtraInfoLength
= 1024;
3433 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3435 switch(urlComponents
.nScheme
) {
3436 case INTERNET_SCHEME_FTP
:
3437 if(urlComponents
.nPort
== 0)
3438 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3439 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3440 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3443 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3444 if(client1
== NULL
) {
3445 InternetCloseHandle(client
);
3450 case INTERNET_SCHEME_HTTP
:
3451 case INTERNET_SCHEME_HTTPS
: {
3452 static const WCHAR szStars
[] = { '*','/','*', 0 };
3453 LPCWSTR accept
[2] = { szStars
, NULL
};
3454 if(urlComponents
.nPort
== 0) {
3455 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3456 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3458 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3460 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3462 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3463 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3464 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3465 if(res
!= ERROR_SUCCESS
) {
3466 INTERNET_SetLastError(res
);
3470 if (urlComponents
.dwExtraInfoLength
) {
3472 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3474 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3476 InternetCloseHandle(client
);
3479 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3480 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3481 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3482 heap_free(path_extra
);
3485 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3487 if(client1
== NULL
) {
3488 InternetCloseHandle(client
);
3491 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3492 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3493 GetLastError() != ERROR_IO_PENDING
) {
3494 InternetCloseHandle(client1
);
3499 case INTERNET_SCHEME_GOPHER
:
3500 /* gopher doesn't seem to be implemented in wine, but it's supposed
3501 * to be supported by InternetOpenUrlA. */
3503 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3507 TRACE(" %p <--\n", client1
);
3512 /**********************************************************
3513 * InternetOpenUrlW (WININET.@)
3518 * handle of connection or NULL on failure
3520 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3522 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3523 appinfo_t
*hIC
= (appinfo_t
*) workRequest
->hdr
;
3527 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3528 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3529 heap_free(req
->lpszUrl
);
3530 heap_free(req
->lpszHeaders
);
3533 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3534 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3536 HINTERNET ret
= NULL
;
3537 appinfo_t
*hIC
= NULL
;
3539 if (TRACE_ON(wininet
)) {
3540 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3541 dwHeadersLength
, dwFlags
, dwContext
);
3543 dump_INTERNET_FLAGS(dwFlags
);
3548 SetLastError(ERROR_INVALID_PARAMETER
);
3552 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3553 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3554 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3558 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3559 WORKREQUEST workRequest
;
3560 struct WORKREQ_INTERNETOPENURLW
*req
;
3562 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3563 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3564 req
= &workRequest
.u
.InternetOpenUrlW
;
3565 req
->lpszUrl
= heap_strdupW(lpszUrl
);
3566 req
->lpszHeaders
= heap_strdupW(lpszHeaders
);
3567 req
->dwHeadersLength
= dwHeadersLength
;
3568 req
->dwFlags
= dwFlags
;
3569 req
->dwContext
= dwContext
;
3571 INTERNET_AsyncCall(&workRequest
);
3573 * This is from windows.
3575 SetLastError(ERROR_IO_PENDING
);
3577 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3582 WININET_Release( &hIC
->hdr
);
3583 TRACE(" %p <--\n", ret
);
3588 /**********************************************************
3589 * InternetOpenUrlA (WININET.@)
3594 * handle of connection or NULL on failure
3596 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3597 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3599 HINTERNET rc
= NULL
;
3600 DWORD lenHeaders
= 0;
3601 LPWSTR szUrl
= NULL
;
3602 LPWSTR szHeaders
= NULL
;
3607 szUrl
= heap_strdupAtoW(lpszUrl
);
3613 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3614 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3619 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3622 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3623 lenHeaders
, dwFlags
, dwContext
);
3626 heap_free(szHeaders
);
3631 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3633 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3637 lpwite
->dwError
= 0;
3638 lpwite
->response
[0] = '\0';
3641 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3650 /***********************************************************************
3651 * INTERNET_SetLastError (internal)
3653 * Set last thread specific error
3658 void INTERNET_SetLastError(DWORD dwError
)
3660 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3663 lpwite
= INTERNET_AllocThreadError();
3665 SetLastError(dwError
);
3667 lpwite
->dwError
= dwError
;
3671 /***********************************************************************
3672 * INTERNET_GetLastError (internal)
3674 * Get last thread specific error
3679 DWORD
INTERNET_GetLastError(void)
3681 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3682 if (!lpwite
) return 0;
3683 /* TlsGetValue clears last error, so set it again here */
3684 SetLastError(lpwite
->dwError
);
3685 return lpwite
->dwError
;
3689 /***********************************************************************
3690 * INTERNET_WorkerThreadFunc (internal)
3692 * Worker thread execution function
3697 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3699 LPWORKREQUEST lpRequest
= lpvParam
;
3700 WORKREQUEST workRequest
;
3704 workRequest
= *lpRequest
;
3705 heap_free(lpRequest
);
3707 workRequest
.asyncproc(&workRequest
);
3708 WININET_Release( workRequest
.hdr
);
3710 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3712 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3713 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3719 /***********************************************************************
3720 * INTERNET_AsyncCall (internal)
3722 * Retrieves work request from queue
3727 DWORD
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3730 LPWORKREQUEST lpNewRequest
;
3734 lpNewRequest
= heap_alloc(sizeof(WORKREQUEST
));
3736 return ERROR_OUTOFMEMORY
;
3738 *lpNewRequest
= *lpWorkRequest
;
3740 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3743 heap_free(lpNewRequest
);
3744 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3746 return ERROR_SUCCESS
;
3750 /***********************************************************************
3751 * INTERNET_GetResponseBuffer (internal)
3756 LPSTR
INTERNET_GetResponseBuffer(void)
3758 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3760 lpwite
= INTERNET_AllocThreadError();
3762 return lpwite
->response
;
3765 /***********************************************************************
3766 * INTERNET_GetNextLine (internal)
3768 * Parse next line in directory string listing
3771 * Pointer to beginning of next line
3776 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3779 BOOL bSuccess
= FALSE
;
3781 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3786 pfd
.events
= POLLIN
;
3788 while (nRecv
< MAX_REPLY_LEN
)
3790 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3792 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3794 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3798 if (lpszBuffer
[nRecv
] == '\n')
3803 if (lpszBuffer
[nRecv
] != '\r')
3808 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3816 lpszBuffer
[nRecv
] = '\0';
3818 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3827 /**********************************************************
3828 * InternetQueryDataAvailable (WININET.@)
3830 * Determines how much data is available to be read.
3833 * TRUE on success, FALSE if an error occurred. If
3834 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3835 * no data is presently available, FALSE is returned with
3836 * the last error ERROR_IO_PENDING; a callback with status
3837 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3838 * data is available.
3840 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3841 LPDWORD lpdwNumberOfBytesAvailable
,
3842 DWORD dwFlags
, DWORD_PTR dwContext
)
3844 object_header_t
*hdr
;
3847 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3849 hdr
= get_handle_object( hFile
);
3851 SetLastError(ERROR_INVALID_HANDLE
);
3855 if(hdr
->vtbl
->QueryDataAvailable
) {
3856 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3858 WARN("wrong handle\n");
3859 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3862 WININET_Release(hdr
);
3864 if(res
!= ERROR_SUCCESS
)
3866 return res
== ERROR_SUCCESS
;
3870 /***********************************************************************
3871 * InternetLockRequestFile (WININET.@)
3873 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3880 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3887 /***********************************************************************
3888 * InternetAutodial (WININET.@)
3890 * On windows this function is supposed to dial the default internet
3891 * connection. We don't want to have Wine dial out to the internet so
3892 * we return TRUE by default. It might be nice to check if we are connected.
3899 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3903 /* Tell that we are connected to the internet. */
3907 /***********************************************************************
3908 * InternetAutodialHangup (WININET.@)
3910 * Hangs up a connection made with InternetAutodial
3919 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3923 /* we didn't dial, we don't disconnect */
3927 /***********************************************************************
3928 * InternetCombineUrlA (WININET.@)
3930 * Combine a base URL with a relative URL
3938 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3939 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3944 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3946 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3947 dwFlags
^= ICU_NO_ENCODE
;
3948 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3953 /***********************************************************************
3954 * InternetCombineUrlW (WININET.@)
3956 * Combine a base URL with a relative URL
3964 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3965 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3970 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3972 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3973 dwFlags
^= ICU_NO_ENCODE
;
3974 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3979 /* max port num is 65535 => 5 digits */
3980 #define MAX_WORD_DIGITS 5
3982 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3983 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3984 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3985 (url)->dw##component##Length : strlen((url)->lpsz##component))
3987 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3989 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3990 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3992 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3993 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3995 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3996 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3998 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3999 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
4002 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4008 /* opaque urls do not fit into the standard url hierarchy and don't have
4009 * two following slashes */
4010 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4012 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4013 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4014 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4015 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4016 (nScheme
!= INTERNET_SCHEME_FILE
);
4019 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4022 if (scheme
< INTERNET_SCHEME_FIRST
)
4024 index
= scheme
- INTERNET_SCHEME_FIRST
;
4025 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4027 return (LPCWSTR
)url_schemes
[index
];
4030 /* we can calculate using ansi strings because we're just
4031 * calculating string length, not size
4033 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4034 LPDWORD lpdwUrlLength
)
4036 INTERNET_SCHEME nScheme
;
4040 if (lpUrlComponents
->lpszScheme
)
4042 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4043 *lpdwUrlLength
+= dwLen
;
4044 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4050 nScheme
= lpUrlComponents
->nScheme
;
4052 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4053 nScheme
= INTERNET_SCHEME_HTTP
;
4054 scheme
= INTERNET_GetSchemeString(nScheme
);
4055 *lpdwUrlLength
+= strlenW(scheme
);
4058 (*lpdwUrlLength
)++; /* ':' */
4059 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4060 *lpdwUrlLength
+= strlen("//");
4062 if (lpUrlComponents
->lpszUserName
)
4064 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4065 *lpdwUrlLength
+= strlen("@");
4069 if (lpUrlComponents
->lpszPassword
)
4071 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4076 if (lpUrlComponents
->lpszPassword
)
4078 *lpdwUrlLength
+= strlen(":");
4079 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4082 if (lpUrlComponents
->lpszHostName
)
4084 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4086 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4088 char szPort
[MAX_WORD_DIGITS
+1];
4090 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4091 *lpdwUrlLength
+= strlen(szPort
);
4092 *lpdwUrlLength
+= strlen(":");
4095 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4096 (*lpdwUrlLength
)++; /* '/' */
4099 if (lpUrlComponents
->lpszUrlPath
)
4100 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4102 if (lpUrlComponents
->lpszExtraInfo
)
4103 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4108 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4112 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4114 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4115 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4116 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4117 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4118 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4119 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4120 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4121 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4122 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4124 if (lpUrlComponents
->lpszScheme
)
4126 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4127 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4128 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4129 -1, urlCompW
->lpszScheme
, len
);
4132 if (lpUrlComponents
->lpszHostName
)
4134 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4135 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4136 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4137 -1, urlCompW
->lpszHostName
, len
);
4140 if (lpUrlComponents
->lpszUserName
)
4142 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4143 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4144 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4145 -1, urlCompW
->lpszUserName
, len
);
4148 if (lpUrlComponents
->lpszPassword
)
4150 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4151 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4152 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4153 -1, urlCompW
->lpszPassword
, len
);
4156 if (lpUrlComponents
->lpszUrlPath
)
4158 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4159 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4160 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4161 -1, urlCompW
->lpszUrlPath
, len
);
4164 if (lpUrlComponents
->lpszExtraInfo
)
4166 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4167 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4168 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4169 -1, urlCompW
->lpszExtraInfo
, len
);
4173 /***********************************************************************
4174 * InternetCreateUrlA (WININET.@)
4176 * See InternetCreateUrlW.
4178 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4179 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4183 URL_COMPONENTSW urlCompW
;
4185 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4187 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4189 SetLastError(ERROR_INVALID_PARAMETER
);
4193 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4196 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4198 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4200 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4201 *lpdwUrlLength
/= sizeof(WCHAR
);
4203 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4204 * minus one, so add one to leave room for NULL terminator
4207 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4209 heap_free(urlCompW
.lpszScheme
);
4210 heap_free(urlCompW
.lpszHostName
);
4211 heap_free(urlCompW
.lpszUserName
);
4212 heap_free(urlCompW
.lpszPassword
);
4213 heap_free(urlCompW
.lpszUrlPath
);
4214 heap_free(urlCompW
.lpszExtraInfo
);
4219 /***********************************************************************
4220 * InternetCreateUrlW (WININET.@)
4222 * Creates a URL from its component parts.
4225 * lpUrlComponents [I] URL Components.
4226 * dwFlags [I] Flags. See notes.
4227 * lpszUrl [I] Buffer in which to store the created URL.
4228 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4229 * lpszUrl in characters. On output, the number of bytes
4230 * required to store the URL including terminator.
4234 * The dwFlags parameter can be zero or more of the following:
4235 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4242 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4243 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4246 INTERNET_SCHEME nScheme
;
4248 static const WCHAR slashSlashW
[] = {'/','/'};
4249 static const WCHAR fmtW
[] = {'%','u',0};
4251 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4253 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4255 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4259 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4262 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4264 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4265 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4269 *lpdwUrlLength
= dwLen
;
4274 if (lpUrlComponents
->lpszScheme
)
4276 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4277 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4280 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4285 nScheme
= lpUrlComponents
->nScheme
;
4287 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4288 nScheme
= INTERNET_SCHEME_HTTP
;
4290 scheme
= INTERNET_GetSchemeString(nScheme
);
4291 dwLen
= strlenW(scheme
);
4292 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4296 /* all schemes are followed by at least a colon */
4300 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4302 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4303 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4306 if (lpUrlComponents
->lpszUserName
)
4308 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4309 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4312 if (lpUrlComponents
->lpszPassword
)
4317 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4318 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4326 if (lpUrlComponents
->lpszHostName
)
4328 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4329 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4332 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4334 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4336 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4339 dwLen
= strlenW(szPort
);
4340 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4344 /* add slash between hostname and path if necessary */
4345 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4352 if (lpUrlComponents
->lpszUrlPath
)
4354 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4355 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4359 if (lpUrlComponents
->lpszExtraInfo
)
4361 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4362 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4371 /***********************************************************************
4372 * InternetConfirmZoneCrossingA (WININET.@)
4375 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4377 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4378 return ERROR_SUCCESS
;
4381 /***********************************************************************
4382 * InternetConfirmZoneCrossingW (WININET.@)
4385 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4387 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4388 return ERROR_SUCCESS
;
4391 static DWORD zone_preference
= 3;
4393 /***********************************************************************
4394 * PrivacySetZonePreferenceW (WININET.@)
4396 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4398 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4400 zone_preference
= template;
4404 /***********************************************************************
4405 * PrivacyGetZonePreferenceW (WININET.@)
4407 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4408 LPWSTR preference
, LPDWORD length
)
4410 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4412 if (template) *template = zone_preference
;
4416 /***********************************************************************
4417 * InternetGetSecurityInfoByURLA (WININET.@)
4419 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4424 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4426 url
= heap_strdupAtoW(lpszURL
);
4430 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4435 /***********************************************************************
4436 * InternetGetSecurityInfoByURLW (WININET.@)
4438 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4440 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4441 URL_COMPONENTSW url
= {sizeof(url
)};
4445 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4447 url
.lpszHostName
= hostname
;
4448 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4450 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4451 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4452 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4456 if(url
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
4457 url
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
4459 server
= get_server(hostname
, url
.nPort
, FALSE
);
4461 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4465 if(server
->cert_chain
) {
4466 const CERT_CHAIN_CONTEXT
*chain_dup
;
4468 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4470 *ppCertChain
= chain_dup
;
4471 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4476 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4480 server_release(server
);
4484 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4485 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4487 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4488 lpdwConnection
, dwReserved
);
4489 return ERROR_SUCCESS
;
4492 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4493 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4495 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4496 lpdwConnection
, dwReserved
);
4497 return ERROR_SUCCESS
;
4500 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4502 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4506 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4508 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4512 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4514 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4515 return ERROR_SUCCESS
;
4518 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4521 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4522 debugstr_w(pwszTarget
), pbHexHash
);
4526 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4528 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4532 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4534 FIXME("(%p, %08lx) stub\n", a
, b
);
4538 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4540 FIXME("%p: stub\n", parent
);