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 #define MAXHOSTNAME 100 /* from http.c */
34 #if defined(__MINGW32__) || defined (_MSC_VER)
41 #include <sys/types.h>
42 #ifdef HAVE_SYS_SOCKET_H
43 # include <sys/socket.h>
48 #ifdef HAVE_SYS_POLL_H
49 # include <sys/poll.h>
51 #ifdef HAVE_SYS_TIME_H
52 # include <sys/time.h>
68 #include "wine/debug.h"
70 #define NO_SHLWAPI_STREAM
73 #include "wine/exception.h"
78 #include "wine/unicode.h"
80 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
82 #define RESPONSE_TIMEOUT 30
87 CHAR response
[MAX_REPLY_LEN
];
88 } WITHREADERROR
, *LPWITHREADERROR
;
90 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
91 static HMODULE WININET_hModule
;
93 #define HANDLE_CHUNK_SIZE 0x10
95 static CRITICAL_SECTION WININET_cs
;
96 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
99 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
100 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
102 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
104 static object_header_t
**WININET_Handles
;
105 static UINT WININET_dwNextHandle
;
106 static UINT WININET_dwMaxHandles
;
110 DWORD dwProxyEnabled
;
111 LPWSTR lpszProxyServer
;
112 LPWSTR lpszProxyBypass
;
115 static const WCHAR szInternetSettings
[] =
116 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
117 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
118 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
119 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
120 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
122 HINTERNET
WININET_AllocHandle( object_header_t
*info
)
125 UINT handle
= 0, num
;
127 list_init( &info
->children
);
129 EnterCriticalSection( &WININET_cs
);
130 if( !WININET_dwMaxHandles
)
132 num
= HANDLE_CHUNK_SIZE
;
133 p
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
134 sizeof (*WININET_Handles
)* num
);
138 WININET_dwMaxHandles
= num
;
140 if( WININET_dwMaxHandles
== WININET_dwNextHandle
)
142 num
= WININET_dwMaxHandles
+ HANDLE_CHUNK_SIZE
;
143 p
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
144 WININET_Handles
, sizeof (*WININET_Handles
)* num
);
148 WININET_dwMaxHandles
= num
;
151 handle
= WININET_dwNextHandle
;
152 if( WININET_Handles
[handle
] )
153 ERR("handle isn't free but should be\n");
154 WININET_Handles
[handle
] = WININET_AddRef( info
);
156 while( WININET_Handles
[WININET_dwNextHandle
] &&
157 (WININET_dwNextHandle
< WININET_dwMaxHandles
) )
158 WININET_dwNextHandle
++;
161 LeaveCriticalSection( &WININET_cs
);
163 return info
->hInternet
= (HINTERNET
) (handle
+1);
166 object_header_t
*WININET_AddRef( object_header_t
*info
)
168 ULONG refs
= InterlockedIncrement(&info
->refs
);
169 TRACE("%p -> refcount = %d\n", info
, refs
);
173 object_header_t
*WININET_GetObject( HINTERNET hinternet
)
175 object_header_t
*info
= NULL
;
176 UINT handle
= (UINT
) hinternet
;
178 EnterCriticalSection( &WININET_cs
);
180 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) &&
181 WININET_Handles
[handle
-1] )
182 info
= WININET_AddRef( WININET_Handles
[handle
-1] );
184 LeaveCriticalSection( &WININET_cs
);
186 TRACE("handle %d -> %p\n", handle
, info
);
191 BOOL
WININET_Release( object_header_t
*info
)
193 ULONG refs
= InterlockedDecrement(&info
->refs
);
194 TRACE( "object %p refcount = %d\n", info
, refs
);
197 if ( info
->vtbl
->CloseConnection
)
199 TRACE( "closing connection %p\n", info
);
200 info
->vtbl
->CloseConnection( info
);
202 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
203 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
204 || !(info
->dwInternalFlags
& INET_OPENURL
))
206 INTERNET_SendCallback(info
, info
->dwContext
,
207 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
210 TRACE( "destroying object %p\n", info
);
211 if ( info
->htype
!= WH_HINIT
)
212 list_remove( &info
->entry
);
213 info
->vtbl
->Destroy( info
);
218 BOOL
WININET_FreeHandle( HINTERNET hinternet
)
221 UINT handle
= (UINT
) hinternet
;
222 object_header_t
*info
= NULL
, *child
, *next
;
224 EnterCriticalSection( &WININET_cs
);
226 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) )
229 if( WININET_Handles
[handle
] )
231 info
= WININET_Handles
[handle
];
232 TRACE( "destroying handle %d for object %p\n", handle
+1, info
);
233 WININET_Handles
[handle
] = NULL
;
238 LeaveCriticalSection( &WININET_cs
);
240 /* As on native when the equivalent of WININET_Release is called, the handle
241 * is already invalid, but if a new handle is created at this time it does
242 * not yet get assigned the freed handle number */
245 /* Free all children as native does */
246 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
248 TRACE( "freeing child handle %d for parent handle %d\n",
249 (UINT
)child
->hInternet
, handle
+1);
250 WININET_FreeHandle( child
->hInternet
);
252 WININET_Release( info
);
255 EnterCriticalSection( &WININET_cs
);
257 if( WININET_dwNextHandle
> handle
&& !WININET_Handles
[handle
] )
258 WININET_dwNextHandle
= handle
;
260 LeaveCriticalSection( &WININET_cs
);
265 /***********************************************************************
266 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
269 * hinstDLL [I] handle to the DLL's instance
271 * lpvReserved [I] reserved, must be NULL
278 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
280 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
283 case DLL_PROCESS_ATTACH
:
285 g_dwTlsErrIndex
= TlsAlloc();
287 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
290 URLCacheContainers_CreateDefaults();
292 WININET_hModule
= hinstDLL
;
294 case DLL_THREAD_ATTACH
:
297 case DLL_THREAD_DETACH
:
298 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
300 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
301 HeapFree(GetProcessHeap(), 0, lpwite
);
305 case DLL_PROCESS_DETACH
:
309 URLCacheContainers_DeleteAll();
311 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
313 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
314 TlsFree(g_dwTlsErrIndex
);
323 /***********************************************************************
324 * InternetInitializeAutoProxyDll (WININET.@)
326 * Setup the internal proxy
335 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
338 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
342 /***********************************************************************
343 * DetectAutoProxyUrl (WININET.@)
345 * Auto detect the proxy url
351 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
352 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
355 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
359 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
361 HeapFree(GetProcessHeap(), 0, lpwpi
->lpszProxyServer
);
362 HeapFree(GetProcessHeap(), 0, lpwpi
->lpszProxyBypass
);
365 /***********************************************************************
366 * INTERNET_LoadProxySettings
368 * Loads proxy information from the registry or environment into lpwpi.
370 * The caller should call FreeProxyInfo when done with lpwpi.
373 * The proxy may be specified in the form 'http=proxy.my.org'
374 * Presumably that means there can be ftp=ftpproxy.my.org too.
376 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
383 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
387 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->dwProxyEnabled
, &len
) || type
!= REG_DWORD
)
389 lpwpi
->dwProxyEnabled
= 0;
390 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->dwProxyEnabled
, sizeof(DWORD
) )))
397 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->dwProxyEnabled
)
399 TRACE("Proxy is enabled.\n");
401 /* figure out how much memory the proxy setting takes */
402 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
405 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
407 if (!(szProxy
= HeapAlloc( GetProcessHeap(), 0, len
)))
410 return ERROR_OUTOFMEMORY
;
412 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
414 /* find the http proxy, and strip away everything else */
415 p
= strstrW( szProxy
, szHttp
);
418 p
+= lstrlenW( szHttp
);
419 lstrcpyW( szProxy
, p
);
421 p
= strchrW( szProxy
, ' ' );
424 lpwpi
->lpszProxyServer
= szProxy
;
426 TRACE("http proxy = %s\n", debugstr_w(lpwpi
->lpszProxyServer
));
430 TRACE("No proxy server settings in registry.\n");
431 lpwpi
->lpszProxyServer
= NULL
;
438 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
439 if (!(envproxyW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
440 return ERROR_OUTOFMEMORY
;
441 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
443 lpwpi
->dwProxyEnabled
= 1;
444 lpwpi
->lpszProxyServer
= envproxyW
;
446 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->lpszProxyServer
));
450 lpwpi
->lpszProxyBypass
= NULL
;
452 return ERROR_SUCCESS
;
455 /***********************************************************************
456 * INTERNET_ConfigureProxy
458 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
462 if (INTERNET_LoadProxySettings( &wpi
))
465 if (wpi
.dwProxyEnabled
)
467 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
468 lpwai
->lpszProxy
= wpi
.lpszProxyServer
;
472 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_DIRECT
;
476 /***********************************************************************
477 * dump_INTERNET_FLAGS
479 * Helper function to TRACE the internet flags.
485 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
487 #define FE(x) { x, #x }
488 static const wininet_flag_info flag
[] = {
489 FE(INTERNET_FLAG_RELOAD
),
490 FE(INTERNET_FLAG_RAW_DATA
),
491 FE(INTERNET_FLAG_EXISTING_CONNECT
),
492 FE(INTERNET_FLAG_ASYNC
),
493 FE(INTERNET_FLAG_PASSIVE
),
494 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
495 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
496 FE(INTERNET_FLAG_FROM_CACHE
),
497 FE(INTERNET_FLAG_SECURE
),
498 FE(INTERNET_FLAG_KEEP_CONNECTION
),
499 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
500 FE(INTERNET_FLAG_READ_PREFETCH
),
501 FE(INTERNET_FLAG_NO_COOKIES
),
502 FE(INTERNET_FLAG_NO_AUTH
),
503 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
504 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
505 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
506 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
507 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
508 FE(INTERNET_FLAG_RESYNCHRONIZE
),
509 FE(INTERNET_FLAG_HYPERLINK
),
510 FE(INTERNET_FLAG_NO_UI
),
511 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
512 FE(INTERNET_FLAG_CACHE_ASYNC
),
513 FE(INTERNET_FLAG_FORMS_SUBMIT
),
514 FE(INTERNET_FLAG_NEED_FILE
),
515 FE(INTERNET_FLAG_TRANSFER_ASCII
),
516 FE(INTERNET_FLAG_TRANSFER_BINARY
)
521 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
522 if (flag
[i
].val
& dwFlags
) {
523 TRACE(" %s", flag
[i
].name
);
524 dwFlags
&= ~flag
[i
].val
;
528 TRACE(" Unknown flags (%08x)\n", dwFlags
);
533 /***********************************************************************
534 * INTERNET_CloseHandle (internal)
536 * Close internet handle
539 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
541 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
545 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
546 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
547 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
548 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
549 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
550 HeapFree(GetProcessHeap(), 0, lpwai
);
553 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
555 appinfo_t
*ai
= (appinfo_t
*)hdr
;
558 case INTERNET_OPTION_HANDLE_TYPE
:
559 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
561 if (*size
< sizeof(ULONG
))
562 return ERROR_INSUFFICIENT_BUFFER
;
564 *size
= sizeof(DWORD
);
565 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
566 return ERROR_SUCCESS
;
568 case INTERNET_OPTION_USER_AGENT
: {
571 TRACE("INTERNET_OPTION_USER_AGENT\n");
576 DWORD len
= ai
->lpszAgent
? strlenW(ai
->lpszAgent
) : 0;
578 *size
= (len
+ 1) * sizeof(WCHAR
);
579 if(!buffer
|| bufsize
< *size
)
580 return ERROR_INSUFFICIENT_BUFFER
;
583 strcpyW(buffer
, ai
->lpszAgent
);
585 *(WCHAR
*)buffer
= 0;
586 /* If the buffer is copied, the returned length doesn't include
587 * the NULL terminator.
589 *size
= len
* sizeof(WCHAR
);
592 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->lpszAgent
, -1, NULL
, 0, NULL
, NULL
);
595 if(!buffer
|| bufsize
< *size
)
596 return ERROR_INSUFFICIENT_BUFFER
;
599 WideCharToMultiByte(CP_ACP
, 0, ai
->lpszAgent
, -1, buffer
, *size
, NULL
, NULL
);
602 /* If the buffer is copied, the returned length doesn't include
603 * the NULL terminator.
608 return ERROR_SUCCESS
;
611 case INTERNET_OPTION_PROXY
:
613 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
614 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
615 LPWSTR proxy
, proxy_bypass
;
618 proxyBytesRequired
= (lstrlenW(ai
->lpszProxy
) + 1) * sizeof(WCHAR
);
619 if (ai
->lpszProxyBypass
)
620 proxyBypassBytesRequired
= (lstrlenW(ai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
621 if (*size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
623 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
624 return ERROR_INSUFFICIENT_BUFFER
;
626 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
627 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
629 pi
->dwAccessType
= ai
->dwAccessType
;
630 pi
->lpszProxy
= NULL
;
631 pi
->lpszProxyBypass
= NULL
;
633 lstrcpyW(proxy
, ai
->lpszProxy
);
634 pi
->lpszProxy
= proxy
;
637 if (ai
->lpszProxyBypass
) {
638 lstrcpyW(proxy_bypass
, ai
->lpszProxyBypass
);
639 pi
->lpszProxyBypass
= proxy_bypass
;
642 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
643 return ERROR_SUCCESS
;
645 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
646 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
647 LPSTR proxy
, proxy_bypass
;
650 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
651 if (ai
->lpszProxyBypass
)
652 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->lpszProxyBypass
, -1,
653 NULL
, 0, NULL
, NULL
);
654 if (*size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
656 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
657 return ERROR_INSUFFICIENT_BUFFER
;
659 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
660 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
662 pi
->dwAccessType
= ai
->dwAccessType
;
663 pi
->lpszProxy
= NULL
;
664 pi
->lpszProxyBypass
= NULL
;
666 WideCharToMultiByte(CP_ACP
, 0, ai
->lpszProxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
667 pi
->lpszProxy
= proxy
;
670 if (ai
->lpszProxyBypass
) {
671 WideCharToMultiByte(CP_ACP
, 0, ai
->lpszProxyBypass
, -1, proxy_bypass
,
672 proxyBypassBytesRequired
, NULL
, NULL
);
673 pi
->lpszProxyBypass
= proxy_bypass
;
676 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
677 return ERROR_SUCCESS
;
681 return INET_QueryOption(option
, buffer
, size
, unicode
);
684 static const object_vtbl_t APPINFOVtbl
= {
697 /***********************************************************************
698 * InternetOpenW (WININET.@)
700 * Per-application initialization of wininet
703 * HINTERNET on success
707 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
708 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
710 appinfo_t
*lpwai
= NULL
;
711 HINTERNET handle
= NULL
;
713 if (TRACE_ON(wininet
)) {
714 #define FE(x) { x, #x }
715 static const wininet_flag_info access_type
[] = {
716 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
717 FE(INTERNET_OPEN_TYPE_DIRECT
),
718 FE(INTERNET_OPEN_TYPE_PROXY
),
719 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
723 const char *access_type_str
= "Unknown";
725 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
726 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
727 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
728 if (access_type
[i
].val
== dwAccessType
) {
729 access_type_str
= access_type
[i
].name
;
733 TRACE(" access type : %s\n", access_type_str
);
735 dump_INTERNET_FLAGS(dwFlags
);
738 /* Clear any error information */
739 INTERNET_SetLastError(0);
741 lpwai
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(appinfo_t
));
744 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
748 lpwai
->hdr
.htype
= WH_HINIT
;
749 lpwai
->hdr
.vtbl
= &APPINFOVtbl
;
750 lpwai
->hdr
.dwFlags
= dwFlags
;
752 lpwai
->dwAccessType
= dwAccessType
;
753 lpwai
->lpszProxyUsername
= NULL
;
754 lpwai
->lpszProxyPassword
= NULL
;
756 handle
= WININET_AllocHandle( &lpwai
->hdr
);
759 HeapFree( GetProcessHeap(), 0, lpwai
);
760 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
764 lpwai
->lpszAgent
= heap_strdupW(lpszAgent
);
765 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
766 INTERNET_ConfigureProxy( lpwai
);
768 lpwai
->lpszProxy
= heap_strdupW(lpszProxy
);
769 lpwai
->lpszProxyBypass
= heap_strdupW(lpszProxyBypass
);
773 WININET_Release( &lpwai
->hdr
);
775 TRACE("returning %p\n", lpwai
);
781 /***********************************************************************
782 * InternetOpenA (WININET.@)
784 * Per-application initialization of wininet
787 * HINTERNET on success
791 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
792 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
794 WCHAR
*szAgent
, *szProxy
, *szBypass
;
797 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
798 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
800 szAgent
= heap_strdupAtoW(lpszAgent
);
801 szProxy
= heap_strdupAtoW(lpszProxy
);
802 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
804 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
806 HeapFree(GetProcessHeap(), 0, szAgent
);
807 HeapFree(GetProcessHeap(), 0, szProxy
);
808 HeapFree(GetProcessHeap(), 0, szBypass
);
813 /***********************************************************************
814 * InternetGetLastResponseInfoA (WININET.@)
816 * Return last wininet error description on the calling thread
819 * TRUE on success of writing to buffer
823 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
824 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
826 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
832 *lpdwError
= lpwite
->dwError
;
835 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
836 *lpdwBufferLength
= strlen(lpszBuffer
);
839 *lpdwBufferLength
= 0;
844 *lpdwBufferLength
= 0;
850 /***********************************************************************
851 * InternetGetLastResponseInfoW (WININET.@)
853 * Return last wininet error description on the calling thread
856 * TRUE on success of writing to buffer
860 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
861 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
863 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
869 *lpdwError
= lpwite
->dwError
;
872 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
873 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
876 *lpdwBufferLength
= 0;
881 *lpdwBufferLength
= 0;
887 /***********************************************************************
888 * InternetGetConnectedState (WININET.@)
890 * Return connected state
894 * if lpdwStatus is not null, return the status (off line,
895 * modem, lan...) in it.
896 * FALSE if not connected
898 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
900 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
903 WARN("always returning LAN connection.\n");
904 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
910 /***********************************************************************
911 * InternetGetConnectedStateExW (WININET.@)
913 * Return connected state
917 * lpdwStatus [O] Flags specifying the status of the internet connection.
918 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
919 * dwNameLen [I] Size of the buffer, in characters.
920 * dwReserved [I] Reserved. Must be set to 0.
924 * if lpdwStatus is not null, return the status (off line,
925 * modem, lan...) in it.
926 * FALSE if not connected
929 * If the system has no available network connections, an empty string is
930 * stored in lpszConnectionName. If there is a LAN connection, a localized
931 * "LAN Connection" string is stored. Presumably, if only a dial-up
932 * connection is available then the name of the dial-up connection is
933 * returned. Why any application, other than the "Internet Settings" CPL,
934 * would want to use this function instead of the simpler InternetGetConnectedStateW
935 * function is beyond me.
937 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
938 DWORD dwNameLen
, DWORD dwReserved
)
940 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
947 WARN("always returning LAN connection.\n");
948 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
950 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
954 /***********************************************************************
955 * InternetGetConnectedStateExA (WININET.@)
957 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
958 DWORD dwNameLen
, DWORD dwReserved
)
960 LPWSTR lpwszConnectionName
= NULL
;
963 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
965 if (lpszConnectionName
&& dwNameLen
> 0)
966 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
968 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
970 if (rc
&& lpwszConnectionName
)
972 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
973 dwNameLen
, NULL
, NULL
);
975 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
982 /***********************************************************************
983 * InternetConnectW (WININET.@)
985 * Open a ftp, gopher or http session
988 * HINTERNET a session handle on success
992 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
993 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
994 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
995 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
999 DWORD res
= ERROR_SUCCESS
;
1001 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1002 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1003 dwService
, dwFlags
, dwContext
);
1005 if (!lpszServerName
)
1007 SetLastError(ERROR_INVALID_PARAMETER
);
1011 hIC
= (appinfo_t
*)WININET_GetObject( hInternet
);
1012 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1014 res
= ERROR_INVALID_HANDLE
;
1020 case INTERNET_SERVICE_FTP
:
1021 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1022 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1024 res
= INTERNET_GetLastError();
1027 case INTERNET_SERVICE_HTTP
:
1028 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1029 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1032 case INTERNET_SERVICE_GOPHER
:
1038 WININET_Release( &hIC
->hdr
);
1040 TRACE("returning %p\n", rc
);
1046 /***********************************************************************
1047 * InternetConnectA (WININET.@)
1049 * Open a ftp, gopher or http session
1052 * HINTERNET a session handle on success
1056 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1057 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1058 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1059 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1061 HINTERNET rc
= NULL
;
1062 LPWSTR szServerName
;
1066 szServerName
= heap_strdupAtoW(lpszServerName
);
1067 szUserName
= heap_strdupAtoW(lpszUserName
);
1068 szPassword
= heap_strdupAtoW(lpszPassword
);
1070 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1071 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1073 HeapFree(GetProcessHeap(), 0, szServerName
);
1074 HeapFree(GetProcessHeap(), 0, szUserName
);
1075 HeapFree(GetProcessHeap(), 0, szPassword
);
1080 /***********************************************************************
1081 * InternetFindNextFileA (WININET.@)
1083 * Continues a file search from a previous call to FindFirstFile
1090 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1093 WIN32_FIND_DATAW fd
;
1095 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1097 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1101 /***********************************************************************
1102 * InternetFindNextFileW (WININET.@)
1104 * Continues a file search from a previous call to FindFirstFile
1111 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1113 object_header_t
*hdr
;
1118 hdr
= WININET_GetObject(hFind
);
1120 WARN("Invalid handle\n");
1121 SetLastError(ERROR_INVALID_HANDLE
);
1125 if(hdr
->vtbl
->FindNextFileW
) {
1126 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1128 WARN("Handle doesn't support NextFile\n");
1129 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1132 WININET_Release(hdr
);
1134 if(res
!= ERROR_SUCCESS
)
1136 return res
== ERROR_SUCCESS
;
1139 /***********************************************************************
1140 * InternetCloseHandle (WININET.@)
1142 * Generic close handle function
1149 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1151 object_header_t
*lpwh
;
1153 TRACE("%p\n",hInternet
);
1155 lpwh
= WININET_GetObject( hInternet
);
1158 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1162 WININET_Release( lpwh
);
1163 WININET_FreeHandle( hInternet
);
1169 /***********************************************************************
1170 * ConvertUrlComponentValue (Internal)
1172 * Helper function for InternetCrackUrlA
1175 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1176 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1177 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1179 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1180 if (*dwComponentLen
!= 0)
1182 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1183 if (*lppszComponent
== NULL
)
1187 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1188 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1191 *lppszComponent
= NULL
;
1193 *dwComponentLen
= nASCIILength
;
1197 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1198 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1199 (*lppszComponent
)[ncpylen
]=0;
1200 *dwComponentLen
= ncpylen
;
1206 /***********************************************************************
1207 * InternetCrackUrlA (WININET.@)
1209 * See InternetCrackUrlW.
1211 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1212 LPURL_COMPONENTSA lpUrlComponents
)
1215 URL_COMPONENTSW UCW
;
1217 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1218 *scheme
= NULL
, *extra
= NULL
;
1220 TRACE("(%s %u %x %p)\n",
1221 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1222 dwUrlLength
, dwFlags
, lpUrlComponents
);
1224 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1225 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1227 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1233 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1235 /* if dwUrlLength=-1 then nLength includes null but length to
1236 InternetCrackUrlW should not include it */
1237 if (dwUrlLength
== -1) nLength
--;
1239 lpwszUrl
= HeapAlloc(GetProcessHeap(), 0, nLength
* sizeof(WCHAR
));
1240 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1242 memset(&UCW
,0,sizeof(UCW
));
1243 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1244 if (lpUrlComponents
->dwHostNameLength
)
1246 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1247 if (lpUrlComponents
->lpszHostName
)
1249 hostname
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwHostNameLength
* sizeof(WCHAR
));
1250 UCW
.lpszHostName
= hostname
;
1253 if (lpUrlComponents
->dwUserNameLength
)
1255 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1256 if (lpUrlComponents
->lpszUserName
)
1258 username
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwUserNameLength
* sizeof(WCHAR
));
1259 UCW
.lpszUserName
= username
;
1262 if (lpUrlComponents
->dwPasswordLength
)
1264 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1265 if (lpUrlComponents
->lpszPassword
)
1267 password
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwPasswordLength
* sizeof(WCHAR
));
1268 UCW
.lpszPassword
= password
;
1271 if (lpUrlComponents
->dwUrlPathLength
)
1273 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1274 if (lpUrlComponents
->lpszUrlPath
)
1276 path
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1277 UCW
.lpszUrlPath
= path
;
1280 if (lpUrlComponents
->dwSchemeLength
)
1282 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1283 if (lpUrlComponents
->lpszScheme
)
1285 scheme
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwSchemeLength
* sizeof(WCHAR
));
1286 UCW
.lpszScheme
= scheme
;
1289 if (lpUrlComponents
->dwExtraInfoLength
)
1291 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1292 if (lpUrlComponents
->lpszExtraInfo
)
1294 extra
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1295 UCW
.lpszExtraInfo
= extra
;
1298 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1300 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1301 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1302 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1303 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1304 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1305 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1306 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1307 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1308 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1309 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1310 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1311 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1313 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1314 lpUrlComponents
->nPort
= UCW
.nPort
;
1316 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1317 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1318 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1319 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1320 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1322 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1323 HeapFree(GetProcessHeap(), 0, hostname
);
1324 HeapFree(GetProcessHeap(), 0, username
);
1325 HeapFree(GetProcessHeap(), 0, password
);
1326 HeapFree(GetProcessHeap(), 0, path
);
1327 HeapFree(GetProcessHeap(), 0, scheme
);
1328 HeapFree(GetProcessHeap(), 0, extra
);
1332 static const WCHAR url_schemes
[][7] =
1335 {'g','o','p','h','e','r',0},
1336 {'h','t','t','p',0},
1337 {'h','t','t','p','s',0},
1338 {'f','i','l','e',0},
1339 {'n','e','w','s',0},
1340 {'m','a','i','l','t','o',0},
1344 /***********************************************************************
1345 * GetInternetSchemeW (internal)
1351 * INTERNET_SCHEME_UNKNOWN on failure
1354 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1358 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1360 if(lpszScheme
==NULL
)
1361 return INTERNET_SCHEME_UNKNOWN
;
1363 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1364 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1365 return INTERNET_SCHEME_FIRST
+ i
;
1367 return INTERNET_SCHEME_UNKNOWN
;
1370 /***********************************************************************
1371 * SetUrlComponentValueW (Internal)
1373 * Helper function for InternetCrackUrlW
1376 * lppszComponent [O] Holds the returned string
1377 * dwComponentLen [I] Holds the size of lppszComponent
1378 * [O] Holds the length of the string in lppszComponent without '\0'
1379 * lpszStart [I] Holds the string to copy from
1380 * len [I] Holds the length of lpszStart without '\0'
1387 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1389 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1391 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1394 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1396 if (*lppszComponent
== NULL
)
1398 *lppszComponent
= (LPWSTR
)lpszStart
;
1399 *dwComponentLen
= len
;
1403 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1404 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1405 (*lppszComponent
)[ncpylen
] = '\0';
1406 *dwComponentLen
= ncpylen
;
1413 /***********************************************************************
1414 * InternetCrackUrlW (WININET.@)
1416 * Break up URL into its components
1422 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1423 LPURL_COMPONENTSW lpUC
)
1427 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1430 LPCWSTR lpszParam
= NULL
;
1431 BOOL bIsAbsolute
= FALSE
;
1432 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1433 LPCWSTR lpszcp
= NULL
;
1434 LPWSTR lpszUrl_decode
= NULL
;
1435 DWORD dwUrlLength
= dwUrlLength_orig
;
1437 TRACE("(%s %u %x %p)\n",
1438 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1439 dwUrlLength
, dwFlags
, lpUC
);
1441 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1443 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1446 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1448 if (dwFlags
& ICU_DECODE
)
1451 DWORD len
= dwUrlLength
+ 1;
1453 if (!(url_tmp
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
1455 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1458 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1459 url_tmp
[dwUrlLength
] = 0;
1460 if (!(lpszUrl_decode
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
1462 HeapFree(GetProcessHeap(), 0, url_tmp
);
1463 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1466 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1469 lpszUrl
= lpszUrl_decode
;
1471 HeapFree(GetProcessHeap(), 0, url_tmp
);
1475 /* Determine if the URI is absolute. */
1476 while (lpszap
- lpszUrl
< dwUrlLength
)
1478 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1483 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1490 lpszcp
= lpszUrl
; /* Relative url */
1496 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1497 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1499 /* Parse <params> */
1500 lpszParam
= memchrW(lpszap
, ';', dwUrlLength
- (lpszap
- lpszUrl
));
1502 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1504 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1506 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1507 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1509 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1513 /* Get scheme first. */
1514 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1515 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1516 lpszUrl
, lpszcp
- lpszUrl
);
1518 /* Eat ':' in protocol. */
1521 /* double slash indicates the net_loc portion is present */
1522 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1526 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1530 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1532 lpszNetLoc
= lpszParam
;
1534 else if (!lpszNetLoc
)
1535 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1543 /* [<user>[<:password>]@]<host>[:<port>] */
1544 /* First find the user and password if they exist */
1546 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1547 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1549 /* username and password not specified. */
1550 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1551 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1553 else /* Parse out username and password */
1555 LPCWSTR lpszUser
= lpszcp
;
1556 LPCWSTR lpszPasswd
= lpszHost
;
1558 while (lpszcp
< lpszHost
)
1561 lpszPasswd
= lpszcp
;
1566 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1567 lpszUser
, lpszPasswd
- lpszUser
);
1569 if (lpszPasswd
!= lpszHost
)
1571 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1572 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1573 lpszHost
- lpszPasswd
);
1575 lpszcp
++; /* Advance to beginning of host */
1578 /* Parse <host><:port> */
1581 lpszPort
= lpszNetLoc
;
1583 /* special case for res:// URLs: there is no port here, so the host is the
1584 entire string up to the first '/' */
1585 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1587 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1588 lpszHost
, lpszPort
- lpszHost
);
1593 while (lpszcp
< lpszNetLoc
)
1601 /* If the scheme is "file" and the host is just one letter, it's not a host */
1602 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1605 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1610 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1611 lpszHost
, lpszPort
- lpszHost
);
1612 if (lpszPort
!= lpszNetLoc
)
1613 lpUC
->nPort
= atoiW(++lpszPort
);
1614 else switch (lpUC
->nScheme
)
1616 case INTERNET_SCHEME_HTTP
:
1617 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1619 case INTERNET_SCHEME_HTTPS
:
1620 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1622 case INTERNET_SCHEME_FTP
:
1623 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1625 case INTERNET_SCHEME_GOPHER
:
1626 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1637 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1638 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1639 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1644 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1645 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1646 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1647 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1650 /* Here lpszcp points to:
1652 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1653 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1655 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1659 /* Only truncate the parameter list if it's already been saved
1660 * in lpUC->lpszExtraInfo.
1662 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1663 len
= lpszParam
- lpszcp
;
1666 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1667 * newlines if necessary.
1669 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1670 if (lpsznewline
!= NULL
)
1671 len
= lpsznewline
- lpszcp
;
1673 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1675 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1680 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1681 lpUC
->lpszUrlPath
[0] = 0;
1682 lpUC
->dwUrlPathLength
= 0;
1685 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1686 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1687 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1688 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1689 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1691 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1695 /***********************************************************************
1696 * InternetAttemptConnect (WININET.@)
1698 * Attempt to make a connection to the internet
1701 * ERROR_SUCCESS on success
1702 * Error value on failure
1705 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1708 return ERROR_SUCCESS
;
1712 /***********************************************************************
1713 * InternetCanonicalizeUrlA (WININET.@)
1715 * Escape unsafe characters and spaces
1722 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1723 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1726 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1728 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1729 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1731 if(dwFlags
& ICU_DECODE
)
1733 dwURLFlags
|= URL_UNESCAPE
;
1734 dwFlags
&= ~ICU_DECODE
;
1737 if(dwFlags
& ICU_ESCAPE
)
1739 dwURLFlags
|= URL_UNESCAPE
;
1740 dwFlags
&= ~ICU_ESCAPE
;
1743 if(dwFlags
& ICU_BROWSER_MODE
)
1745 dwURLFlags
|= URL_BROWSER_MODE
;
1746 dwFlags
&= ~ICU_BROWSER_MODE
;
1749 if(dwFlags
& ICU_NO_ENCODE
)
1751 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1752 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1753 dwFlags
&= ~ICU_NO_ENCODE
;
1756 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1758 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1759 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1760 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1762 return (hr
== S_OK
) ? TRUE
: FALSE
;
1765 /***********************************************************************
1766 * InternetCanonicalizeUrlW (WININET.@)
1768 * Escape unsafe characters and spaces
1775 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1776 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1779 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1781 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1782 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1784 if(dwFlags
& ICU_DECODE
)
1786 dwURLFlags
|= URL_UNESCAPE
;
1787 dwFlags
&= ~ICU_DECODE
;
1790 if(dwFlags
& ICU_ESCAPE
)
1792 dwURLFlags
|= URL_UNESCAPE
;
1793 dwFlags
&= ~ICU_ESCAPE
;
1796 if(dwFlags
& ICU_BROWSER_MODE
)
1798 dwURLFlags
|= URL_BROWSER_MODE
;
1799 dwFlags
&= ~ICU_BROWSER_MODE
;
1802 if(dwFlags
& ICU_NO_ENCODE
)
1804 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1805 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1806 dwFlags
&= ~ICU_NO_ENCODE
;
1809 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1811 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1812 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1813 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1815 return (hr
== S_OK
) ? TRUE
: FALSE
;
1818 /* #################################################### */
1820 static INTERNET_STATUS_CALLBACK
set_status_callback(
1821 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
1823 INTERNET_STATUS_CALLBACK ret
;
1825 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1826 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1828 ret
= lpwh
->lpfnStatusCB
;
1829 lpwh
->lpfnStatusCB
= callback
;
1834 /***********************************************************************
1835 * InternetSetStatusCallbackA (WININET.@)
1837 * Sets up a callback function which is called as progress is made
1838 * during an operation.
1841 * Previous callback or NULL on success
1842 * INTERNET_INVALID_STATUS_CALLBACK on failure
1845 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1846 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1848 INTERNET_STATUS_CALLBACK retVal
;
1849 object_header_t
*lpwh
;
1851 TRACE("%p\n", hInternet
);
1853 if (!(lpwh
= WININET_GetObject(hInternet
)))
1854 return INTERNET_INVALID_STATUS_CALLBACK
;
1856 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
1858 WININET_Release( lpwh
);
1862 /***********************************************************************
1863 * InternetSetStatusCallbackW (WININET.@)
1865 * Sets up a callback function which is called as progress is made
1866 * during an operation.
1869 * Previous callback or NULL on success
1870 * INTERNET_INVALID_STATUS_CALLBACK on failure
1873 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1874 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1876 INTERNET_STATUS_CALLBACK retVal
;
1877 object_header_t
*lpwh
;
1879 TRACE("%p\n", hInternet
);
1881 if (!(lpwh
= WININET_GetObject(hInternet
)))
1882 return INTERNET_INVALID_STATUS_CALLBACK
;
1884 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
1886 WININET_Release( lpwh
);
1890 /***********************************************************************
1891 * InternetSetFilePointer (WININET.@)
1893 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1894 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
1900 /***********************************************************************
1901 * InternetWriteFile (WININET.@)
1903 * Write data to an open internet file
1910 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1911 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1913 object_header_t
*lpwh
;
1916 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1918 lpwh
= WININET_GetObject( hFile
);
1920 WARN("Invalid handle\n");
1921 SetLastError(ERROR_INVALID_HANDLE
);
1925 if(lpwh
->vtbl
->WriteFile
) {
1926 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1928 WARN("No Writefile method.\n");
1929 res
= ERROR_INVALID_HANDLE
;
1932 WININET_Release( lpwh
);
1934 if(res
!= ERROR_SUCCESS
)
1936 return res
== ERROR_SUCCESS
;
1940 /***********************************************************************
1941 * InternetReadFile (WININET.@)
1943 * Read data from an open internet file
1950 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1951 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1953 object_header_t
*hdr
;
1954 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1956 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1958 hdr
= WININET_GetObject(hFile
);
1960 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1964 if(hdr
->vtbl
->ReadFile
)
1965 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1967 WININET_Release(hdr
);
1969 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
1970 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1972 if(res
!= ERROR_SUCCESS
)
1974 return res
== ERROR_SUCCESS
;
1977 /***********************************************************************
1978 * InternetReadFileExA (WININET.@)
1980 * Read data from an open internet file
1983 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1984 * lpBuffersOut [I/O] Buffer.
1985 * dwFlags [I] Flags. See notes.
1986 * dwContext [I] Context for callbacks.
1993 * The parameter dwFlags include zero or more of the following flags:
1994 *|IRF_ASYNC - Makes the call asynchronous.
1995 *|IRF_SYNC - Makes the call synchronous.
1996 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1997 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1999 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2002 * InternetOpenUrlA(), HttpOpenRequestA()
2004 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2005 DWORD dwFlags
, DWORD_PTR dwContext
)
2007 object_header_t
*hdr
;
2008 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2010 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2012 hdr
= WININET_GetObject(hFile
);
2014 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2018 if(hdr
->vtbl
->ReadFileExA
)
2019 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
2021 WININET_Release(hdr
);
2023 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2024 res
, lpBuffersOut
->dwBufferLength
);
2026 if(res
!= ERROR_SUCCESS
)
2028 return res
== ERROR_SUCCESS
;
2031 /***********************************************************************
2032 * InternetReadFileExW (WININET.@)
2034 * InternetReadFileExA()
2036 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2037 DWORD dwFlags
, DWORD_PTR dwContext
)
2039 object_header_t
*hdr
;
2040 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2042 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2044 hdr
= WININET_GetObject(hFile
);
2046 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2050 if(hdr
->vtbl
->ReadFileExW
)
2051 res
= hdr
->vtbl
->ReadFileExW(hdr
, lpBuffer
, dwFlags
, dwContext
);
2053 WININET_Release(hdr
);
2055 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2056 res
, lpBuffer
->dwBufferLength
);
2058 if(res
!= ERROR_SUCCESS
)
2060 return res
== ERROR_SUCCESS
;
2063 DWORD
INET_QueryOption(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2065 static BOOL warn
= TRUE
;
2068 case INTERNET_OPTION_REQUEST_FLAGS
:
2069 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2071 if (*size
< sizeof(ULONG
))
2072 return ERROR_INSUFFICIENT_BUFFER
;
2074 *(ULONG
*)buffer
= 4;
2075 *size
= sizeof(ULONG
);
2077 return ERROR_SUCCESS
;
2079 case INTERNET_OPTION_HTTP_VERSION
:
2080 if (*size
< sizeof(HTTP_VERSION_INFO
))
2081 return ERROR_INSUFFICIENT_BUFFER
;
2084 * Presently hardcoded to 1.1
2086 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2087 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2088 *size
= sizeof(HTTP_VERSION_INFO
);
2090 return ERROR_SUCCESS
;
2092 case INTERNET_OPTION_CONNECTED_STATE
:
2094 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2097 if (*size
< sizeof(ULONG
))
2098 return ERROR_INSUFFICIENT_BUFFER
;
2100 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2101 *size
= sizeof(ULONG
);
2103 return ERROR_SUCCESS
;
2105 case INTERNET_OPTION_PROXY
: {
2109 TRACE("Getting global proxy info\n");
2110 memset(&ai
, 0, sizeof(appinfo_t
));
2111 INTERNET_ConfigureProxy(&ai
);
2113 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2114 APPINFO_Destroy(&ai
.hdr
);
2118 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2119 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2121 if (*size
< sizeof(ULONG
))
2122 return ERROR_INSUFFICIENT_BUFFER
;
2124 *(ULONG
*)buffer
= 2;
2125 *size
= sizeof(ULONG
);
2127 return ERROR_SUCCESS
;
2129 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2130 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2132 if (*size
< sizeof(ULONG
))
2133 return ERROR_INSUFFICIENT_BUFFER
;
2136 *size
= sizeof(ULONG
);
2138 return ERROR_SUCCESS
;
2140 case INTERNET_OPTION_SECURITY_FLAGS
:
2141 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2142 return ERROR_SUCCESS
;
2144 case INTERNET_OPTION_VERSION
: {
2145 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2147 TRACE("INTERNET_OPTION_VERSION\n");
2149 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2150 return ERROR_INSUFFICIENT_BUFFER
;
2152 memcpy(buffer
, &info
, sizeof(info
));
2153 *size
= sizeof(info
);
2155 return ERROR_SUCCESS
;
2158 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2159 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2160 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2161 DWORD res
= ERROR_SUCCESS
, i
;
2165 TRACE("Getting global proxy info\n");
2166 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2169 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2171 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2173 return ERROR_INSUFFICIENT_BUFFER
;
2176 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2177 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2178 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2180 switch (option
->dwOption
) {
2181 case INTERNET_PER_CONN_FLAGS
:
2182 if(pi
.dwProxyEnabled
)
2183 option
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2185 option
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2188 case INTERNET_PER_CONN_PROXY_SERVER
:
2190 option
->Value
.pszValue
= heap_strdupW(pi
.lpszProxyServer
);
2192 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.lpszProxyServer
);
2195 case INTERNET_PER_CONN_PROXY_BYPASS
:
2197 option
->Value
.pszValue
= heap_strdupW(pi
.lpszProxyBypass
);
2199 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.lpszProxyBypass
);
2202 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2203 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2204 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2205 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2206 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2207 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2208 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2209 memset(&option
->Value
, 0, sizeof(option
->Value
));
2213 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2214 res
= ERROR_INVALID_PARAMETER
;
2222 case INTERNET_OPTION_USER_AGENT
:
2223 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2224 case INTERNET_OPTION_POLICY
:
2225 return ERROR_INVALID_PARAMETER
;
2228 FIXME("Stub for %d\n", option
);
2229 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2232 /***********************************************************************
2233 * InternetQueryOptionW (WININET.@)
2235 * Queries an options on the specified handle
2242 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2243 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2245 object_header_t
*hdr
;
2246 DWORD res
= ERROR_INVALID_HANDLE
;
2248 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2251 hdr
= WININET_GetObject(hInternet
);
2253 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2254 WININET_Release(hdr
);
2257 res
= INET_QueryOption(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2260 if(res
!= ERROR_SUCCESS
)
2262 return res
== ERROR_SUCCESS
;
2265 /***********************************************************************
2266 * InternetQueryOptionA (WININET.@)
2268 * Queries an options on the specified handle
2275 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2276 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2278 object_header_t
*hdr
;
2279 DWORD res
= ERROR_INVALID_HANDLE
;
2281 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2284 hdr
= WININET_GetObject(hInternet
);
2286 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2287 WININET_Release(hdr
);
2290 res
= INET_QueryOption(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2293 if(res
!= ERROR_SUCCESS
)
2295 return res
== ERROR_SUCCESS
;
2299 /***********************************************************************
2300 * InternetSetOptionW (WININET.@)
2302 * Sets an options on the specified handle
2309 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2310 LPVOID lpBuffer
, DWORD dwBufferLength
)
2312 object_header_t
*lpwhh
;
2315 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2317 lpwhh
= (object_header_t
*) WININET_GetObject( hInternet
);
2318 if(lpwhh
&& lpwhh
->vtbl
->SetOption
) {
2321 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2322 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2323 WININET_Release( lpwhh
);
2325 if(res
!= ERROR_SUCCESS
)
2328 return res
== ERROR_SUCCESS
;
2334 case INTERNET_OPTION_CALLBACK
:
2338 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2341 WININET_Release(lpwhh
);
2342 SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE
);
2345 case INTERNET_OPTION_HTTP_VERSION
:
2347 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2348 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2351 case INTERNET_OPTION_ERROR_MASK
:
2353 ULONG flags
= *(ULONG
*)lpBuffer
;
2354 FIXME("Option INTERNET_OPTION_ERROR_MASK(%d): STUB\n", flags
);
2357 case INTERNET_OPTION_CODEPAGE
:
2359 ULONG codepage
= *(ULONG
*)lpBuffer
;
2360 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2363 case INTERNET_OPTION_REQUEST_PRIORITY
:
2365 ULONG priority
= *(ULONG
*)lpBuffer
;
2366 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2369 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2371 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2372 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2375 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2377 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2378 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2381 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2383 ULONG conns
= *(ULONG
*)lpBuffer
;
2384 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns
);
2387 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2389 ULONG conns
= *(ULONG
*)lpBuffer
;
2390 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns
);
2393 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2394 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2396 case INTERNET_OPTION_END_BROWSER_SESSION
:
2397 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2399 case INTERNET_OPTION_CONNECTED_STATE
:
2400 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2402 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2403 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2405 case INTERNET_OPTION_SEND_TIMEOUT
:
2406 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2408 ULONG timeout
= *(ULONG
*)lpBuffer
;
2409 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT %d\n", timeout
);
2412 case INTERNET_OPTION_CONNECT_RETRIES
:
2414 ULONG retries
= *(ULONG
*)lpBuffer
;
2415 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2418 case INTERNET_OPTION_CONTEXT_VALUE
:
2419 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2421 case INTERNET_OPTION_SECURITY_FLAGS
:
2422 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2424 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2425 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2427 case INTERNET_OPTION_HTTP_DECODING
:
2428 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2429 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2432 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2433 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2434 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2437 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2438 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2439 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2442 case INTERNET_OPTION_CODEPAGE_PATH
:
2443 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2444 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2447 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2448 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2449 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2452 case INTERNET_OPTION_IDN
:
2453 FIXME("INTERNET_OPTION_IDN; STUB\n");
2454 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2457 case INTERNET_OPTION_POLICY
:
2458 SetLastError(ERROR_INVALID_PARAMETER
);
2462 FIXME("Option %d STUB\n",dwOption
);
2463 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2469 WININET_Release( lpwhh
);
2475 /***********************************************************************
2476 * InternetSetOptionA (WININET.@)
2478 * Sets an options on the specified handle.
2485 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2486 LPVOID lpBuffer
, DWORD dwBufferLength
)
2494 case INTERNET_OPTION_CALLBACK
:
2496 object_header_t
*lpwh
;
2498 if (!(lpwh
= WININET_GetObject(hInternet
)))
2500 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2503 WININET_Release(lpwh
);
2504 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE
);
2507 case INTERNET_OPTION_PROXY
:
2509 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2510 LPINTERNET_PROXY_INFOW piw
;
2511 DWORD proxlen
, prbylen
;
2514 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2515 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2516 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2517 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2518 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2519 piw
->dwAccessType
= pi
->dwAccessType
;
2520 prox
= (LPWSTR
) &piw
[1];
2521 prby
= &prox
[proxlen
+1];
2522 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2523 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2524 piw
->lpszProxy
= prox
;
2525 piw
->lpszProxyBypass
= prby
;
2528 case INTERNET_OPTION_USER_AGENT
:
2529 case INTERNET_OPTION_USERNAME
:
2530 case INTERNET_OPTION_PASSWORD
:
2531 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2533 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2534 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2537 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2539 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
2540 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
2541 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2542 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
);
2545 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2546 if (listA
->pszConnection
)
2548 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
2549 listW
->pszConnection
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2550 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
2553 listW
->pszConnection
= NULL
;
2554 listW
->dwOptionCount
= listA
->dwOptionCount
;
2555 listW
->dwOptionError
= listA
->dwOptionError
;
2556 listW
->pOptions
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
2558 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
2559 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
2560 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
2562 optW
->dwOption
= optA
->dwOption
;
2564 switch (optA
->dwOption
) {
2565 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2566 case INTERNET_PER_CONN_PROXY_BYPASS
:
2567 case INTERNET_PER_CONN_PROXY_SERVER
:
2568 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2569 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2570 if (optA
->Value
.pszValue
)
2572 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
2573 optW
->Value
.pszValue
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2574 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
2577 optW
->Value
.pszValue
= NULL
;
2579 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2580 case INTERNET_PER_CONN_FLAGS
:
2581 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2582 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
2584 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2585 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
2587 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
2588 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
2596 wlen
= dwBufferLength
;
2599 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2601 if( lpBuffer
!= wbuffer
)
2603 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
2605 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
2607 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
2608 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
2609 switch (opt
->dwOption
) {
2610 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2611 case INTERNET_PER_CONN_PROXY_BYPASS
:
2612 case INTERNET_PER_CONN_PROXY_SERVER
:
2613 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2614 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2615 HeapFree( GetProcessHeap(), 0, opt
->Value
.pszValue
);
2621 HeapFree( GetProcessHeap(), 0, list
->pOptions
);
2623 HeapFree( GetProcessHeap(), 0, wbuffer
);
2630 /***********************************************************************
2631 * InternetSetOptionExA (WININET.@)
2633 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2634 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2636 FIXME("Flags %08x ignored\n", dwFlags
);
2637 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2640 /***********************************************************************
2641 * InternetSetOptionExW (WININET.@)
2643 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2644 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2646 FIXME("Flags %08x ignored\n", dwFlags
);
2647 if( dwFlags
& ~ISO_VALID_FLAGS
)
2649 SetLastError( ERROR_INVALID_PARAMETER
);
2652 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2655 static const WCHAR WININET_wkday
[7][4] =
2656 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2657 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2658 static const WCHAR WININET_month
[12][4] =
2659 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2660 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2661 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2663 /***********************************************************************
2664 * InternetTimeFromSystemTimeA (WININET.@)
2666 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2669 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2671 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2673 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
2675 SetLastError(ERROR_INVALID_PARAMETER
);
2679 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
2681 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2685 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2686 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2691 /***********************************************************************
2692 * InternetTimeFromSystemTimeW (WININET.@)
2694 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2696 static const WCHAR date
[] =
2697 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2698 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2700 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2702 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
2704 SetLastError(ERROR_INVALID_PARAMETER
);
2708 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
2710 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2714 sprintfW( string
, date
,
2715 WININET_wkday
[time
->wDayOfWeek
],
2717 WININET_month
[time
->wMonth
- 1],
2726 /***********************************************************************
2727 * InternetTimeToSystemTimeA (WININET.@)
2729 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2734 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
2736 stringW
= heap_strdupAtoW(string
);
2739 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2740 HeapFree( GetProcessHeap(), 0, stringW
);
2745 /***********************************************************************
2746 * InternetTimeToSystemTimeW (WININET.@)
2748 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2751 const WCHAR
*s
= string
;
2754 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
2756 if (!string
|| !time
) return FALSE
;
2758 /* Windows does this too */
2759 GetSystemTime( time
);
2761 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2762 * a SYSTEMTIME structure.
2765 while (*s
&& !isalphaW( *s
)) s
++;
2766 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2767 time
->wDayOfWeek
= 7;
2769 for (i
= 0; i
< 7; i
++)
2771 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2772 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2773 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2775 time
->wDayOfWeek
= i
;
2780 if (time
->wDayOfWeek
> 6) return TRUE
;
2781 while (*s
&& !isdigitW( *s
)) s
++;
2782 time
->wDay
= strtolW( s
, &end
, 10 );
2785 while (*s
&& !isalphaW( *s
)) s
++;
2786 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2789 for (i
= 0; i
< 12; i
++)
2791 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2792 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2793 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2795 time
->wMonth
= i
+ 1;
2799 if (time
->wMonth
== 0) return TRUE
;
2801 while (*s
&& !isdigitW( *s
)) s
++;
2802 if (*s
== '\0') return TRUE
;
2803 time
->wYear
= strtolW( s
, &end
, 10 );
2806 while (*s
&& !isdigitW( *s
)) s
++;
2807 if (*s
== '\0') return TRUE
;
2808 time
->wHour
= strtolW( s
, &end
, 10 );
2811 while (*s
&& !isdigitW( *s
)) s
++;
2812 if (*s
== '\0') return TRUE
;
2813 time
->wMinute
= strtolW( s
, &end
, 10 );
2816 while (*s
&& !isdigitW( *s
)) s
++;
2817 if (*s
== '\0') return TRUE
;
2818 time
->wSecond
= strtolW( s
, &end
, 10 );
2821 time
->wMilliseconds
= 0;
2825 /***********************************************************************
2826 * InternetCheckConnectionW (WININET.@)
2828 * Pings a requested host to check internet connection
2831 * TRUE on success and FALSE on failure. If a failure then
2832 * ERROR_NOT_CONNECTED is placed into GetLastError
2835 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2838 * this is a kludge which runs the resident ping program and reads the output.
2840 * Anyone have a better idea?
2844 static const CHAR ping
[] = "ping -c 1 ";
2845 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2846 CHAR
*command
= NULL
;
2855 * Crack or set the Address
2857 if (lpszUrl
== NULL
)
2860 * According to the doc we are supposed to use the ip for the next
2861 * server in the WnInet internal server database. I have
2862 * no idea what that is or how to get it.
2864 * So someone needs to implement this.
2866 FIXME("Unimplemented with URL of NULL\n");
2871 URL_COMPONENTSW components
;
2873 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2874 components
.lpszHostName
= (LPWSTR
)hostW
;
2875 components
.dwHostNameLength
= 1024;
2877 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2880 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2881 port
= components
.nPort
;
2882 TRACE("port: %d\n", port
);
2885 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
2887 struct sockaddr_storage saddr
;
2888 socklen_t sa_len
= sizeof(saddr
);
2891 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
2893 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
2896 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
2904 * Build our ping command
2906 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2907 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2908 strcpy(command
,ping
);
2909 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2910 strcat(command
,redirect
);
2912 TRACE("Ping command is : %s\n",command
);
2914 status
= system(command
);
2916 TRACE("Ping returned a code of %i\n",status
);
2918 /* Ping return code of 0 indicates success */
2925 HeapFree( GetProcessHeap(), 0, command
);
2927 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
2933 /***********************************************************************
2934 * InternetCheckConnectionA (WININET.@)
2936 * Pings a requested host to check internet connection
2939 * TRUE on success and FALSE on failure. If a failure then
2940 * ERROR_NOT_CONNECTED is placed into GetLastError
2943 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2949 url
= heap_strdupAtoW(lpszUrl
);
2954 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
2956 HeapFree(GetProcessHeap(), 0, url
);
2961 /**********************************************************
2962 * INTERNET_InternetOpenUrlW (internal)
2967 * handle of connection or NULL on failure
2969 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
2970 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2972 URL_COMPONENTSW urlComponents
;
2973 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2974 WCHAR password
[1024], path
[2048], extra
[1024];
2975 HINTERNET client
= NULL
, client1
= NULL
;
2978 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2979 dwHeadersLength
, dwFlags
, dwContext
);
2981 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2982 urlComponents
.lpszScheme
= protocol
;
2983 urlComponents
.dwSchemeLength
= 32;
2984 urlComponents
.lpszHostName
= hostName
;
2985 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2986 urlComponents
.lpszUserName
= userName
;
2987 urlComponents
.dwUserNameLength
= 1024;
2988 urlComponents
.lpszPassword
= password
;
2989 urlComponents
.dwPasswordLength
= 1024;
2990 urlComponents
.lpszUrlPath
= path
;
2991 urlComponents
.dwUrlPathLength
= 2048;
2992 urlComponents
.lpszExtraInfo
= extra
;
2993 urlComponents
.dwExtraInfoLength
= 1024;
2994 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2996 switch(urlComponents
.nScheme
) {
2997 case INTERNET_SCHEME_FTP
:
2998 if(urlComponents
.nPort
== 0)
2999 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3000 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3001 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3004 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3005 if(client1
== NULL
) {
3006 InternetCloseHandle(client
);
3011 case INTERNET_SCHEME_HTTP
:
3012 case INTERNET_SCHEME_HTTPS
: {
3013 static const WCHAR szStars
[] = { '*','/','*', 0 };
3014 LPCWSTR accept
[2] = { szStars
, NULL
};
3015 if(urlComponents
.nPort
== 0) {
3016 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3017 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3019 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3021 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3023 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3024 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3025 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3026 if(res
!= ERROR_SUCCESS
) {
3027 INTERNET_SetLastError(res
);
3031 if (urlComponents
.dwExtraInfoLength
) {
3033 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3035 if (!(path_extra
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
3037 InternetCloseHandle(client
);
3040 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3041 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3042 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3043 HeapFree(GetProcessHeap(), 0, path_extra
);
3046 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3048 if(client1
== NULL
) {
3049 InternetCloseHandle(client
);
3052 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3053 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3054 GetLastError() != ERROR_IO_PENDING
) {
3055 InternetCloseHandle(client1
);
3060 case INTERNET_SCHEME_GOPHER
:
3061 /* gopher doesn't seem to be implemented in wine, but it's supposed
3062 * to be supported by InternetOpenUrlA. */
3064 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3068 TRACE(" %p <--\n", client1
);
3073 /**********************************************************
3074 * InternetOpenUrlW (WININET.@)
3079 * handle of connection or NULL on failure
3081 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3083 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3084 appinfo_t
*hIC
= (appinfo_t
*) workRequest
->hdr
;
3088 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3089 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3090 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
3091 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
3094 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3095 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3097 HINTERNET ret
= NULL
;
3098 appinfo_t
*hIC
= NULL
;
3100 if (TRACE_ON(wininet
)) {
3101 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3102 dwHeadersLength
, dwFlags
, dwContext
);
3104 dump_INTERNET_FLAGS(dwFlags
);
3109 SetLastError(ERROR_INVALID_PARAMETER
);
3113 hIC
= (appinfo_t
*)WININET_GetObject( hInternet
);
3114 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3115 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3119 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3120 WORKREQUEST workRequest
;
3121 struct WORKREQ_INTERNETOPENURLW
*req
;
3123 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3124 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3125 req
= &workRequest
.u
.InternetOpenUrlW
;
3126 req
->lpszUrl
= heap_strdupW(lpszUrl
);
3127 req
->lpszHeaders
= heap_strdupW(lpszHeaders
);
3128 req
->dwHeadersLength
= dwHeadersLength
;
3129 req
->dwFlags
= dwFlags
;
3130 req
->dwContext
= dwContext
;
3132 INTERNET_AsyncCall(&workRequest
);
3134 * This is from windows.
3136 SetLastError(ERROR_IO_PENDING
);
3138 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3143 WININET_Release( &hIC
->hdr
);
3144 TRACE(" %p <--\n", ret
);
3149 /**********************************************************
3150 * InternetOpenUrlA (WININET.@)
3155 * handle of connection or NULL on failure
3157 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3158 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3160 HINTERNET rc
= NULL
;
3161 DWORD lenHeaders
= 0;
3162 LPWSTR szUrl
= NULL
;
3163 LPWSTR szHeaders
= NULL
;
3168 szUrl
= heap_strdupAtoW(lpszUrl
);
3174 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3175 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
3177 HeapFree(GetProcessHeap(), 0, szUrl
);
3180 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3183 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3184 lenHeaders
, dwFlags
, dwContext
);
3186 HeapFree(GetProcessHeap(), 0, szUrl
);
3187 HeapFree(GetProcessHeap(), 0, szHeaders
);
3193 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3195 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite
));
3199 lpwite
->dwError
= 0;
3200 lpwite
->response
[0] = '\0';
3203 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3205 HeapFree(GetProcessHeap(), 0, lpwite
);
3213 /***********************************************************************
3214 * INTERNET_SetLastError (internal)
3216 * Set last thread specific error
3221 void INTERNET_SetLastError(DWORD dwError
)
3223 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3226 lpwite
= INTERNET_AllocThreadError();
3228 SetLastError(dwError
);
3230 lpwite
->dwError
= dwError
;
3234 /***********************************************************************
3235 * INTERNET_GetLastError (internal)
3237 * Get last thread specific error
3242 DWORD
INTERNET_GetLastError(void)
3244 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3245 if (!lpwite
) return 0;
3246 /* TlsGetValue clears last error, so set it again here */
3247 SetLastError(lpwite
->dwError
);
3248 return lpwite
->dwError
;
3252 /***********************************************************************
3253 * INTERNET_WorkerThreadFunc (internal)
3255 * Worker thread execution function
3260 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3262 LPWORKREQUEST lpRequest
= lpvParam
;
3263 WORKREQUEST workRequest
;
3267 workRequest
= *lpRequest
;
3268 HeapFree(GetProcessHeap(), 0, lpRequest
);
3270 workRequest
.asyncproc(&workRequest
);
3271 WININET_Release( workRequest
.hdr
);
3273 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3275 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
3276 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3282 /***********************************************************************
3283 * INTERNET_AsyncCall (internal)
3285 * Retrieves work request from queue
3290 DWORD
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3293 LPWORKREQUEST lpNewRequest
;
3297 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3299 return ERROR_OUTOFMEMORY
;
3301 *lpNewRequest
= *lpWorkRequest
;
3303 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3306 HeapFree(GetProcessHeap(), 0, lpNewRequest
);
3307 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3310 return ERROR_SUCCESS
;
3314 /***********************************************************************
3315 * INTERNET_GetResponseBuffer (internal)
3320 LPSTR
INTERNET_GetResponseBuffer(void)
3322 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3324 lpwite
= INTERNET_AllocThreadError();
3326 return lpwite
->response
;
3329 /***********************************************************************
3330 * INTERNET_GetNextLine (internal)
3332 * Parse next line in directory string listing
3335 * Pointer to beginning of next line
3340 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3343 BOOL bSuccess
= FALSE
;
3345 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3350 pfd
.events
= POLLIN
;
3352 while (nRecv
< MAX_REPLY_LEN
)
3354 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3356 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3358 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3362 if (lpszBuffer
[nRecv
] == '\n')
3367 if (lpszBuffer
[nRecv
] != '\r')
3372 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3380 lpszBuffer
[nRecv
] = '\0';
3382 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3391 /**********************************************************
3392 * InternetQueryDataAvailable (WININET.@)
3394 * Determines how much data is available to be read.
3397 * TRUE on success, FALSE if an error occurred. If
3398 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3399 * no data is presently available, FALSE is returned with
3400 * the last error ERROR_IO_PENDING; a callback with status
3401 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3402 * data is available.
3404 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3405 LPDWORD lpdwNumberOfBytesAvailble
,
3406 DWORD dwFlags
, DWORD_PTR dwContext
)
3408 object_header_t
*hdr
;
3411 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3413 hdr
= WININET_GetObject( hFile
);
3415 SetLastError(ERROR_INVALID_HANDLE
);
3419 if(hdr
->vtbl
->QueryDataAvailable
) {
3420 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3422 WARN("wrong handle\n");
3423 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3426 WININET_Release(hdr
);
3428 if(res
!= ERROR_SUCCESS
)
3430 return res
== ERROR_SUCCESS
;
3434 /***********************************************************************
3435 * InternetLockRequestFile (WININET.@)
3437 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3444 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3451 /***********************************************************************
3452 * InternetAutodial (WININET.@)
3454 * On windows this function is supposed to dial the default internet
3455 * connection. We don't want to have Wine dial out to the internet so
3456 * we return TRUE by default. It might be nice to check if we are connected.
3463 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3467 /* Tell that we are connected to the internet. */
3471 /***********************************************************************
3472 * InternetAutodialHangup (WININET.@)
3474 * Hangs up a connection made with InternetAutodial
3483 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3487 /* we didn't dial, we don't disconnect */
3491 /***********************************************************************
3492 * InternetCombineUrlA (WININET.@)
3494 * Combine a base URL with a relative URL
3502 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3503 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3508 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3510 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3511 dwFlags
^= ICU_NO_ENCODE
;
3512 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3517 /***********************************************************************
3518 * InternetCombineUrlW (WININET.@)
3520 * Combine a base URL with a relative URL
3528 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3529 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3534 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3536 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3537 dwFlags
^= ICU_NO_ENCODE
;
3538 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3543 /* max port num is 65535 => 5 digits */
3544 #define MAX_WORD_DIGITS 5
3546 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3547 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3548 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3549 (url)->dw##component##Length : strlen((url)->lpsz##component))
3551 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3553 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3554 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3556 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3557 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3559 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3560 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3562 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3563 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3566 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3572 /* opaque urls do not fit into the standard url hierarchy and don't have
3573 * two following slashes */
3574 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3576 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3577 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3578 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3579 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3580 (nScheme
!= INTERNET_SCHEME_FILE
);
3583 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3586 if (scheme
< INTERNET_SCHEME_FIRST
)
3588 index
= scheme
- INTERNET_SCHEME_FIRST
;
3589 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3591 return (LPCWSTR
)url_schemes
[index
];
3594 /* we can calculate using ansi strings because we're just
3595 * calculating string length, not size
3597 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3598 LPDWORD lpdwUrlLength
)
3600 INTERNET_SCHEME nScheme
;
3604 if (lpUrlComponents
->lpszScheme
)
3606 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3607 *lpdwUrlLength
+= dwLen
;
3608 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3614 nScheme
= lpUrlComponents
->nScheme
;
3616 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3617 nScheme
= INTERNET_SCHEME_HTTP
;
3618 scheme
= INTERNET_GetSchemeString(nScheme
);
3619 *lpdwUrlLength
+= strlenW(scheme
);
3622 (*lpdwUrlLength
)++; /* ':' */
3623 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3624 *lpdwUrlLength
+= strlen("//");
3626 if (lpUrlComponents
->lpszUserName
)
3628 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3629 *lpdwUrlLength
+= strlen("@");
3633 if (lpUrlComponents
->lpszPassword
)
3635 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3640 if (lpUrlComponents
->lpszPassword
)
3642 *lpdwUrlLength
+= strlen(":");
3643 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3646 if (lpUrlComponents
->lpszHostName
)
3648 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3650 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3652 char szPort
[MAX_WORD_DIGITS
+1];
3654 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3655 *lpdwUrlLength
+= strlen(szPort
);
3656 *lpdwUrlLength
+= strlen(":");
3659 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3660 (*lpdwUrlLength
)++; /* '/' */
3663 if (lpUrlComponents
->lpszUrlPath
)
3664 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3666 if (lpUrlComponents
->lpszExtraInfo
)
3667 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
3672 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3676 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3678 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3679 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3680 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3681 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3682 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3683 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3684 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3685 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3686 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3688 if (lpUrlComponents
->lpszScheme
)
3690 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
3691 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3692 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3693 -1, urlCompW
->lpszScheme
, len
);
3696 if (lpUrlComponents
->lpszHostName
)
3698 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
3699 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3700 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3701 -1, urlCompW
->lpszHostName
, len
);
3704 if (lpUrlComponents
->lpszUserName
)
3706 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
3707 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3708 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3709 -1, urlCompW
->lpszUserName
, len
);
3712 if (lpUrlComponents
->lpszPassword
)
3714 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
3715 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3716 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3717 -1, urlCompW
->lpszPassword
, len
);
3720 if (lpUrlComponents
->lpszUrlPath
)
3722 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
3723 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3724 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3725 -1, urlCompW
->lpszUrlPath
, len
);
3728 if (lpUrlComponents
->lpszExtraInfo
)
3730 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
3731 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3732 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3733 -1, urlCompW
->lpszExtraInfo
, len
);
3737 /***********************************************************************
3738 * InternetCreateUrlA (WININET.@)
3740 * See InternetCreateUrlW.
3742 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3743 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3747 URL_COMPONENTSW urlCompW
;
3749 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3751 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3753 SetLastError(ERROR_INVALID_PARAMETER
);
3757 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3760 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3762 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3764 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3765 *lpdwUrlLength
/= sizeof(WCHAR
);
3767 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3768 * minus one, so add one to leave room for NULL terminator
3771 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3773 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3774 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3775 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3776 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3777 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3778 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3779 HeapFree(GetProcessHeap(), 0, urlW
);
3784 /***********************************************************************
3785 * InternetCreateUrlW (WININET.@)
3787 * Creates a URL from its component parts.
3790 * lpUrlComponents [I] URL Components.
3791 * dwFlags [I] Flags. See notes.
3792 * lpszUrl [I] Buffer in which to store the created URL.
3793 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3794 * lpszUrl in characters. On output, the number of bytes
3795 * required to store the URL including terminator.
3799 * The dwFlags parameter can be zero or more of the following:
3800 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3807 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3808 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3811 INTERNET_SCHEME nScheme
;
3813 static const WCHAR slashSlashW
[] = {'/','/'};
3814 static const WCHAR percentD
[] = {'%','d',0};
3816 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3818 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3820 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3824 if (!calc_url_length(lpUrlComponents
, &dwLen
))
3827 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3829 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
3830 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3834 *lpdwUrlLength
= dwLen
;
3839 if (lpUrlComponents
->lpszScheme
)
3841 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3842 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
3845 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3850 nScheme
= lpUrlComponents
->nScheme
;
3852 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3853 nScheme
= INTERNET_SCHEME_HTTP
;
3855 scheme
= INTERNET_GetSchemeString(nScheme
);
3856 dwLen
= strlenW(scheme
);
3857 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
3861 /* all schemes are followed by at least a colon */
3865 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3867 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
3868 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
3871 if (lpUrlComponents
->lpszUserName
)
3873 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3874 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
3877 if (lpUrlComponents
->lpszPassword
)
3882 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3883 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
3891 if (lpUrlComponents
->lpszHostName
)
3893 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3894 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
3897 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3899 WCHAR szPort
[MAX_WORD_DIGITS
+1];
3901 sprintfW(szPort
, percentD
, lpUrlComponents
->nPort
);
3904 dwLen
= strlenW(szPort
);
3905 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
3909 /* add slash between hostname and path if necessary */
3910 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3917 if (lpUrlComponents
->lpszUrlPath
)
3919 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3920 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
3924 if (lpUrlComponents
->lpszExtraInfo
)
3926 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
3927 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
3936 /***********************************************************************
3937 * InternetConfirmZoneCrossingA (WININET.@)
3940 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
3942 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
3943 return ERROR_SUCCESS
;
3946 /***********************************************************************
3947 * InternetConfirmZoneCrossingW (WININET.@)
3950 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
3952 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
3953 return ERROR_SUCCESS
;
3956 static DWORD zone_preference
= 3;
3958 /***********************************************************************
3959 * PrivacySetZonePreferenceW (WININET.@)
3961 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
3963 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
3965 zone_preference
= template;
3969 /***********************************************************************
3970 * PrivacyGetZonePreferenceW (WININET.@)
3972 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
3973 LPWSTR preference
, LPDWORD length
)
3975 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
3977 if (template) *template = zone_preference
;
3981 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
3982 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3984 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3985 lpdwConnection
, dwReserved
);
3986 return ERROR_SUCCESS
;
3989 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
3990 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3992 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3993 lpdwConnection
, dwReserved
);
3994 return ERROR_SUCCESS
;
3997 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3999 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4003 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4005 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4009 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4011 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4012 return ERROR_SUCCESS
;
4015 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4018 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4019 debugstr_w(pwszTarget
), pbHexHash
);
4023 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4025 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4029 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4031 FIXME("(%p, %08lx) stub\n", a
, b
);