4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #if defined(__MINGW32__) || defined (_MSC_VER)
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 # include <sys/socket.h>
46 #ifdef HAVE_SYS_POLL_H
47 # include <sys/poll.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
65 #include "wine/debug.h"
67 #define NO_SHLWAPI_STREAM
70 #include "wine/exception.h"
75 #include "wine/unicode.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
79 #define RESPONSE_TIMEOUT 30
84 CHAR response
[MAX_REPLY_LEN
];
85 } WITHREADERROR
, *LPWITHREADERROR
;
87 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
88 HMODULE WININET_hModule
;
90 static CRITICAL_SECTION WININET_cs
;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
94 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
95 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
99 static object_header_t
**handle_table
;
100 static UINT_PTR next_handle
;
101 static UINT_PTR handle_table_size
;
110 static ULONG max_conns
= 2, max_1_0_conns
= 4;
111 static ULONG connect_timeout
= 60000;
113 static const WCHAR szInternetSettings
[] =
114 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
115 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
116 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
117 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
118 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
120 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
122 UINT_PTR handle
= 0, num
;
123 object_header_t
*ret
;
127 ret
= heap_alloc_zero(size
);
131 list_init(&ret
->children
);
133 EnterCriticalSection( &WININET_cs
);
135 if(!handle_table_size
) {
137 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
140 handle_table_size
= num
;
145 }else if(next_handle
== handle_table_size
) {
146 num
= handle_table_size
* 2;
147 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
150 handle_table_size
= num
;
157 handle
= next_handle
;
158 if(handle_table
[handle
])
159 ERR("handle isn't free but should be\n");
160 handle_table
[handle
] = ret
;
161 ret
->valid_handle
= TRUE
;
163 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
167 LeaveCriticalSection( &WININET_cs
);
176 ret
->hInternet
= (HINTERNET
)handle
;
179 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
180 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
186 object_header_t
*WININET_AddRef( object_header_t
*info
)
188 ULONG refs
= InterlockedIncrement(&info
->refs
);
189 TRACE("%p -> refcount = %d\n", info
, refs
);
193 object_header_t
*get_handle_object( HINTERNET hinternet
)
195 object_header_t
*info
= NULL
;
196 UINT_PTR handle
= (UINT_PTR
) hinternet
;
198 EnterCriticalSection( &WININET_cs
);
200 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
201 info
= WININET_AddRef(handle_table
[handle
]);
203 LeaveCriticalSection( &WININET_cs
);
205 TRACE("handle %ld -> %p\n", handle
, info
);
210 static void invalidate_handle(object_header_t
*info
)
212 object_header_t
*child
, *next
;
214 if(!info
->valid_handle
)
216 info
->valid_handle
= FALSE
;
218 /* Free all children as native does */
219 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
221 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
222 invalidate_handle( child
);
225 WININET_Release(info
);
228 BOOL
WININET_Release( object_header_t
*info
)
230 ULONG refs
= InterlockedDecrement(&info
->refs
);
231 TRACE( "object %p refcount = %d\n", info
, refs
);
234 invalidate_handle(info
);
235 if ( info
->vtbl
->CloseConnection
)
237 TRACE( "closing connection %p\n", info
);
238 info
->vtbl
->CloseConnection( info
);
240 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
241 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
242 || !(info
->dwInternalFlags
& INET_OPENURL
))
244 INTERNET_SendCallback(info
, info
->dwContext
,
245 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
248 TRACE( "destroying object %p\n", info
);
249 if ( info
->htype
!= WH_HINIT
)
250 list_remove( &info
->entry
);
251 info
->vtbl
->Destroy( info
);
253 if(info
->hInternet
) {
254 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
256 EnterCriticalSection( &WININET_cs
);
258 handle_table
[handle
] = NULL
;
259 if(next_handle
> handle
)
260 next_handle
= handle
;
262 LeaveCriticalSection( &WININET_cs
);
270 /***********************************************************************
271 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
274 * hinstDLL [I] handle to the DLL's instance
276 * lpvReserved [I] reserved, must be NULL
283 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
285 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
288 case DLL_PROCESS_ATTACH
:
290 g_dwTlsErrIndex
= TlsAlloc();
292 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
297 TlsFree(g_dwTlsErrIndex
);
301 WININET_hModule
= hinstDLL
;
304 case DLL_THREAD_ATTACH
:
307 case DLL_THREAD_DETACH
:
308 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
310 heap_free(TlsGetValue(g_dwTlsErrIndex
));
314 case DLL_PROCESS_DETACH
:
315 collect_connections(COLLECT_CLEANUP
);
320 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
322 heap_free(TlsGetValue(g_dwTlsErrIndex
));
323 TlsFree(g_dwTlsErrIndex
);
330 /***********************************************************************
331 * INTERNET_SaveProxySettings
333 * Stores the proxy settings given by lpwai into the registry
336 * ERROR_SUCCESS if no error, or error code on fail
338 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
343 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
346 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
354 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
362 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
370 return ERROR_SUCCESS
;
373 /***********************************************************************
374 * INTERNET_FindProxyForProtocol
376 * Searches the proxy string for a proxy of the given protocol.
377 * Returns the found proxy, or the default proxy if none of the given
381 * szProxy [In] proxy string to search
382 * proto [In] protocol to search for, e.g. "http"
383 * foundProxy [Out] found proxy
384 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
387 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
388 * *foundProxyLen is set to the required size in WCHARs, including the
389 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
391 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
396 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
398 /* First, look for the specified protocol (proto=scheme://host:port) */
399 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
403 if (!(end
= strchrW(ptr
, ' ')))
404 end
= ptr
+ strlenW(ptr
);
405 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
406 equal
- ptr
== strlenW(proto
) &&
407 !strncmpiW(proto
, ptr
, strlenW(proto
)))
409 if (end
- equal
> *foundProxyLen
)
411 WARN("buffer too short for %s\n",
412 debugstr_wn(equal
+ 1, end
- equal
- 1));
413 *foundProxyLen
= end
- equal
;
414 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
418 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
419 foundProxy
[end
- equal
] = 0;
430 /* It wasn't found: look for no protocol */
431 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
435 if (!(end
= strchrW(ptr
, ' ')))
436 end
= ptr
+ strlenW(ptr
);
437 if (!strchrW(ptr
, '='))
439 if (end
- ptr
+ 1 > *foundProxyLen
)
441 WARN("buffer too short for %s\n",
442 debugstr_wn(ptr
, end
- ptr
));
443 *foundProxyLen
= end
- ptr
+ 1;
444 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
448 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
449 foundProxy
[end
- ptr
] = 0;
460 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
461 debugstr_w(foundProxy
));
465 /***********************************************************************
466 * InternetInitializeAutoProxyDll (WININET.@)
468 * Setup the internal proxy
477 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
480 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
484 /***********************************************************************
485 * DetectAutoProxyUrl (WININET.@)
487 * Auto detect the proxy url
493 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
494 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
497 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
501 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
503 heap_free(lpwpi
->proxy
);
504 heap_free(lpwpi
->proxyBypass
);
507 static proxyinfo_t
*global_proxy
;
509 static void free_global_proxy( void )
511 EnterCriticalSection( &WININET_cs
);
514 FreeProxyInfo( global_proxy
);
515 heap_free( global_proxy
);
517 LeaveCriticalSection( &WININET_cs
);
520 /***********************************************************************
521 * INTERNET_LoadProxySettings
523 * Loads proxy information from process-wide global settings, the registry,
524 * or the environment into lpwpi.
526 * The caller should call FreeProxyInfo when done with lpwpi.
529 * The proxy may be specified in the form 'http=proxy.my.org'
530 * Presumably that means there can be ftp=ftpproxy.my.org too.
532 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
539 EnterCriticalSection( &WININET_cs
);
542 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
543 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
544 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
546 LeaveCriticalSection( &WININET_cs
);
548 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
552 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
554 lpwpi
->proxyEnabled
= 0;
555 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
562 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
564 TRACE("Proxy is enabled.\n");
566 /* figure out how much memory the proxy setting takes */
567 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
570 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
572 if (!(szProxy
= heap_alloc(len
)))
575 return ERROR_OUTOFMEMORY
;
577 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
579 /* find the http proxy, and strip away everything else */
580 p
= strstrW( szProxy
, szHttp
);
583 p
+= lstrlenW( szHttp
);
584 lstrcpyW( szProxy
, p
);
586 p
= strchrW( szProxy
, ' ' );
589 lpwpi
->proxy
= szProxy
;
591 TRACE("http proxy = %s\n", debugstr_w(lpwpi
->proxy
));
595 TRACE("No proxy server settings in registry.\n");
603 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
604 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
605 return ERROR_OUTOFMEMORY
;
606 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
608 lpwpi
->proxyEnabled
= 1;
609 lpwpi
->proxy
= envproxyW
;
611 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
615 lpwpi
->proxyBypass
= NULL
;
617 return ERROR_SUCCESS
;
620 /***********************************************************************
621 * INTERNET_ConfigureProxy
623 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
627 if (INTERNET_LoadProxySettings( &wpi
))
630 if (wpi
.proxyEnabled
)
632 WCHAR proxyurl
[INTERNET_MAX_URL_LENGTH
];
633 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
];
634 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
635 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
636 URL_COMPONENTSW UrlComponents
;
638 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
639 UrlComponents
.dwSchemeLength
= 0;
640 UrlComponents
.lpszHostName
= hostname
;
641 UrlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
642 UrlComponents
.lpszUserName
= username
;
643 UrlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
644 UrlComponents
.lpszPassword
= password
;
645 UrlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
646 UrlComponents
.dwUrlPathLength
= 0;
647 UrlComponents
.dwExtraInfoLength
= 0;
649 if(InternetCrackUrlW(wpi
.proxy
, 0, 0, &UrlComponents
))
651 static const WCHAR szFormat
[] = { 'h','t','t','p',':','/','/','%','s',':','%','u',0 };
653 if(UrlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
654 UrlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
655 sprintfW(proxyurl
, szFormat
, hostname
, UrlComponents
.nPort
);
657 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
658 lpwai
->proxy
= heap_strdupW(proxyurl
);
659 if (UrlComponents
.dwUserNameLength
)
661 lpwai
->proxyUsername
= heap_strdupW(UrlComponents
.lpszUserName
);
662 lpwai
->proxyPassword
= heap_strdupW(UrlComponents
.lpszPassword
);
665 TRACE("http proxy = %s\n", debugstr_w(lpwai
->proxy
));
670 TRACE("Failed to parse proxy: %s\n", debugstr_w(wpi
.proxy
));
675 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
679 /***********************************************************************
680 * dump_INTERNET_FLAGS
682 * Helper function to TRACE the internet flags.
688 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
690 #define FE(x) { x, #x }
691 static const wininet_flag_info flag
[] = {
692 FE(INTERNET_FLAG_RELOAD
),
693 FE(INTERNET_FLAG_RAW_DATA
),
694 FE(INTERNET_FLAG_EXISTING_CONNECT
),
695 FE(INTERNET_FLAG_ASYNC
),
696 FE(INTERNET_FLAG_PASSIVE
),
697 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
698 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
699 FE(INTERNET_FLAG_FROM_CACHE
),
700 FE(INTERNET_FLAG_SECURE
),
701 FE(INTERNET_FLAG_KEEP_CONNECTION
),
702 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
703 FE(INTERNET_FLAG_READ_PREFETCH
),
704 FE(INTERNET_FLAG_NO_COOKIES
),
705 FE(INTERNET_FLAG_NO_AUTH
),
706 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
707 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
708 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
709 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
710 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
711 FE(INTERNET_FLAG_RESYNCHRONIZE
),
712 FE(INTERNET_FLAG_HYPERLINK
),
713 FE(INTERNET_FLAG_NO_UI
),
714 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
715 FE(INTERNET_FLAG_CACHE_ASYNC
),
716 FE(INTERNET_FLAG_FORMS_SUBMIT
),
717 FE(INTERNET_FLAG_NEED_FILE
),
718 FE(INTERNET_FLAG_TRANSFER_ASCII
),
719 FE(INTERNET_FLAG_TRANSFER_BINARY
)
724 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
725 if (flag
[i
].val
& dwFlags
) {
726 TRACE(" %s", flag
[i
].name
);
727 dwFlags
&= ~flag
[i
].val
;
731 TRACE(" Unknown flags (%08x)\n", dwFlags
);
736 /***********************************************************************
737 * INTERNET_CloseHandle (internal)
739 * Close internet handle
742 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
744 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
748 heap_free(lpwai
->agent
);
749 heap_free(lpwai
->proxy
);
750 heap_free(lpwai
->proxyBypass
);
751 heap_free(lpwai
->proxyUsername
);
752 heap_free(lpwai
->proxyPassword
);
755 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
757 appinfo_t
*ai
= (appinfo_t
*)hdr
;
760 case INTERNET_OPTION_HANDLE_TYPE
:
761 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
763 if (*size
< sizeof(ULONG
))
764 return ERROR_INSUFFICIENT_BUFFER
;
766 *size
= sizeof(DWORD
);
767 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
768 return ERROR_SUCCESS
;
770 case INTERNET_OPTION_USER_AGENT
: {
773 TRACE("INTERNET_OPTION_USER_AGENT\n");
778 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
780 *size
= (len
+ 1) * sizeof(WCHAR
);
781 if(!buffer
|| bufsize
< *size
)
782 return ERROR_INSUFFICIENT_BUFFER
;
785 strcpyW(buffer
, ai
->agent
);
787 *(WCHAR
*)buffer
= 0;
788 /* If the buffer is copied, the returned length doesn't include
789 * the NULL terminator.
791 *size
= len
* sizeof(WCHAR
);
794 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
797 if(!buffer
|| bufsize
< *size
)
798 return ERROR_INSUFFICIENT_BUFFER
;
801 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
804 /* If the buffer is copied, the returned length doesn't include
805 * the NULL terminator.
810 return ERROR_SUCCESS
;
813 case INTERNET_OPTION_PROXY
:
814 if(!size
) return ERROR_INVALID_PARAMETER
;
816 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
817 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
818 LPWSTR proxy
, proxy_bypass
;
821 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
823 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
824 if (*size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
826 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
827 return ERROR_INSUFFICIENT_BUFFER
;
829 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
830 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
832 pi
->dwAccessType
= ai
->accessType
;
833 pi
->lpszProxy
= NULL
;
834 pi
->lpszProxyBypass
= NULL
;
836 lstrcpyW(proxy
, ai
->proxy
);
837 pi
->lpszProxy
= proxy
;
840 if (ai
->proxyBypass
) {
841 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
842 pi
->lpszProxyBypass
= proxy_bypass
;
845 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
846 return ERROR_SUCCESS
;
848 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
849 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
850 LPSTR proxy
, proxy_bypass
;
853 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
855 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
856 NULL
, 0, NULL
, NULL
);
857 if (*size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
859 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
860 return ERROR_INSUFFICIENT_BUFFER
;
862 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
863 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
865 pi
->dwAccessType
= ai
->accessType
;
866 pi
->lpszProxy
= NULL
;
867 pi
->lpszProxyBypass
= NULL
;
869 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
870 pi
->lpszProxy
= proxy
;
873 if (ai
->proxyBypass
) {
874 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
875 proxyBypassBytesRequired
, NULL
, NULL
);
876 pi
->lpszProxyBypass
= proxy_bypass
;
879 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
880 return ERROR_SUCCESS
;
883 case INTERNET_OPTION_CONNECT_TIMEOUT
:
884 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
886 if (*size
< sizeof(ULONG
))
887 return ERROR_INSUFFICIENT_BUFFER
;
889 *(ULONG
*)buffer
= ai
->connect_timeout
;
890 *size
= sizeof(ULONG
);
892 return ERROR_SUCCESS
;
895 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
898 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
900 appinfo_t
*ai
= (appinfo_t
*)hdr
;
903 case INTERNET_OPTION_CONNECT_TIMEOUT
:
904 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
906 if(size
!= sizeof(connect_timeout
))
907 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
909 return ERROR_BAD_ARGUMENTS
;
911 ai
->connect_timeout
= *(ULONG
*)buf
;
912 return ERROR_SUCCESS
;
913 case INTERNET_OPTION_USER_AGENT
:
914 heap_free(ai
->agent
);
915 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
916 return ERROR_SUCCESS
;
919 return INET_SetOption(hdr
, option
, buf
, size
);
922 static const object_vtbl_t APPINFOVtbl
= {
934 /***********************************************************************
935 * InternetOpenW (WININET.@)
937 * Per-application initialization of wininet
940 * HINTERNET on success
944 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
945 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
947 appinfo_t
*lpwai
= NULL
;
949 if (TRACE_ON(wininet
)) {
950 #define FE(x) { x, #x }
951 static const wininet_flag_info access_type
[] = {
952 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
953 FE(INTERNET_OPEN_TYPE_DIRECT
),
954 FE(INTERNET_OPEN_TYPE_PROXY
),
955 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
959 const char *access_type_str
= "Unknown";
961 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
962 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
963 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
964 if (access_type
[i
].val
== dwAccessType
) {
965 access_type_str
= access_type
[i
].name
;
969 TRACE(" access type : %s\n", access_type_str
);
971 dump_INTERNET_FLAGS(dwFlags
);
974 /* Clear any error information */
975 INTERNET_SetLastError(0);
977 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
979 SetLastError(ERROR_OUTOFMEMORY
);
983 lpwai
->hdr
.htype
= WH_HINIT
;
984 lpwai
->hdr
.dwFlags
= dwFlags
;
985 lpwai
->accessType
= dwAccessType
;
986 lpwai
->proxyUsername
= NULL
;
987 lpwai
->proxyPassword
= NULL
;
988 lpwai
->connect_timeout
= connect_timeout
;
990 lpwai
->agent
= heap_strdupW(lpszAgent
);
991 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
992 INTERNET_ConfigureProxy( lpwai
);
994 lpwai
->proxy
= heap_strdupW(lpszProxy
);
995 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
997 TRACE("returning %p\n", lpwai
);
999 return lpwai
->hdr
.hInternet
;
1003 /***********************************************************************
1004 * InternetOpenA (WININET.@)
1006 * Per-application initialization of wininet
1009 * HINTERNET on success
1013 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1014 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1016 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1019 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1020 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1022 szAgent
= heap_strdupAtoW(lpszAgent
);
1023 szProxy
= heap_strdupAtoW(lpszProxy
);
1024 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1026 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1030 heap_free(szBypass
);
1034 /***********************************************************************
1035 * InternetGetLastResponseInfoA (WININET.@)
1037 * Return last wininet error description on the calling thread
1040 * TRUE on success of writing to buffer
1044 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1045 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1047 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1053 *lpdwError
= lpwite
->dwError
;
1054 if (lpwite
->dwError
)
1056 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1057 *lpdwBufferLength
= strlen(lpszBuffer
);
1060 *lpdwBufferLength
= 0;
1065 *lpdwBufferLength
= 0;
1071 /***********************************************************************
1072 * InternetGetLastResponseInfoW (WININET.@)
1074 * Return last wininet error description on the calling thread
1077 * TRUE on success of writing to buffer
1081 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1082 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1084 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1090 *lpdwError
= lpwite
->dwError
;
1091 if (lpwite
->dwError
)
1093 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1094 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1097 *lpdwBufferLength
= 0;
1102 *lpdwBufferLength
= 0;
1108 /***********************************************************************
1109 * InternetGetConnectedState (WININET.@)
1111 * Return connected state
1115 * if lpdwStatus is not null, return the status (off line,
1116 * modem, lan...) in it.
1117 * FALSE if not connected
1119 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1121 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1124 WARN("always returning LAN connection.\n");
1125 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1131 /***********************************************************************
1132 * InternetGetConnectedStateExW (WININET.@)
1134 * Return connected state
1138 * lpdwStatus [O] Flags specifying the status of the internet connection.
1139 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1140 * dwNameLen [I] Size of the buffer, in characters.
1141 * dwReserved [I] Reserved. Must be set to 0.
1145 * if lpdwStatus is not null, return the status (off line,
1146 * modem, lan...) in it.
1147 * FALSE if not connected
1150 * If the system has no available network connections, an empty string is
1151 * stored in lpszConnectionName. If there is a LAN connection, a localized
1152 * "LAN Connection" string is stored. Presumably, if only a dial-up
1153 * connection is available then the name of the dial-up connection is
1154 * returned. Why any application, other than the "Internet Settings" CPL,
1155 * would want to use this function instead of the simpler InternetGetConnectedStateW
1156 * function is beyond me.
1158 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1159 DWORD dwNameLen
, DWORD dwReserved
)
1161 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1168 WARN("always returning LAN connection.\n");
1169 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1171 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1175 /***********************************************************************
1176 * InternetGetConnectedStateExA (WININET.@)
1178 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1179 DWORD dwNameLen
, DWORD dwReserved
)
1181 LPWSTR lpwszConnectionName
= NULL
;
1184 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1186 if (lpszConnectionName
&& dwNameLen
> 0)
1187 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1189 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1191 if (rc
&& lpwszConnectionName
)
1193 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1194 dwNameLen
, NULL
, NULL
);
1195 heap_free(lpwszConnectionName
);
1201 /***********************************************************************
1202 * InternetConnectW (WININET.@)
1204 * Open a ftp, gopher or http session
1207 * HINTERNET a session handle on success
1211 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1212 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1213 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1214 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1217 HINTERNET rc
= NULL
;
1218 DWORD res
= ERROR_SUCCESS
;
1220 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1221 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1222 dwService
, dwFlags
, dwContext
);
1224 if (!lpszServerName
)
1226 SetLastError(ERROR_INVALID_PARAMETER
);
1230 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1231 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1233 res
= ERROR_INVALID_HANDLE
;
1239 case INTERNET_SERVICE_FTP
:
1240 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1241 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1243 res
= INTERNET_GetLastError();
1246 case INTERNET_SERVICE_HTTP
:
1247 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1248 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1251 case INTERNET_SERVICE_GOPHER
:
1257 WININET_Release( &hIC
->hdr
);
1259 TRACE("returning %p\n", rc
);
1265 /***********************************************************************
1266 * InternetConnectA (WININET.@)
1268 * Open a ftp, gopher or http session
1271 * HINTERNET a session handle on success
1275 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1276 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1277 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1278 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1280 HINTERNET rc
= NULL
;
1281 LPWSTR szServerName
;
1285 szServerName
= heap_strdupAtoW(lpszServerName
);
1286 szUserName
= heap_strdupAtoW(lpszUserName
);
1287 szPassword
= heap_strdupAtoW(lpszPassword
);
1289 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1290 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1292 heap_free(szServerName
);
1293 heap_free(szUserName
);
1294 heap_free(szPassword
);
1299 /***********************************************************************
1300 * InternetFindNextFileA (WININET.@)
1302 * Continues a file search from a previous call to FindFirstFile
1309 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1312 WIN32_FIND_DATAW fd
;
1314 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1316 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1320 /***********************************************************************
1321 * InternetFindNextFileW (WININET.@)
1323 * Continues a file search from a previous call to FindFirstFile
1330 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1332 object_header_t
*hdr
;
1337 hdr
= get_handle_object(hFind
);
1339 WARN("Invalid handle\n");
1340 SetLastError(ERROR_INVALID_HANDLE
);
1344 if(hdr
->vtbl
->FindNextFileW
) {
1345 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1347 WARN("Handle doesn't support NextFile\n");
1348 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1351 WININET_Release(hdr
);
1353 if(res
!= ERROR_SUCCESS
)
1355 return res
== ERROR_SUCCESS
;
1358 /***********************************************************************
1359 * InternetCloseHandle (WININET.@)
1361 * Generic close handle function
1368 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1370 object_header_t
*obj
;
1372 TRACE("%p\n", hInternet
);
1374 obj
= get_handle_object( hInternet
);
1376 SetLastError(ERROR_INVALID_HANDLE
);
1380 invalidate_handle(obj
);
1381 WININET_Release(obj
);
1387 /***********************************************************************
1388 * ConvertUrlComponentValue (Internal)
1390 * Helper function for InternetCrackUrlA
1393 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1394 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1395 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1397 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1398 if (*dwComponentLen
!= 0)
1400 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1401 if (*lppszComponent
== NULL
)
1405 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1406 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1409 *lppszComponent
= NULL
;
1411 *dwComponentLen
= nASCIILength
;
1415 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1416 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1417 (*lppszComponent
)[ncpylen
]=0;
1418 *dwComponentLen
= ncpylen
;
1424 /***********************************************************************
1425 * InternetCrackUrlA (WININET.@)
1427 * See InternetCrackUrlW.
1429 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1430 LPURL_COMPONENTSA lpUrlComponents
)
1433 URL_COMPONENTSW UCW
;
1435 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1436 *scheme
= NULL
, *extra
= NULL
;
1438 TRACE("(%s %u %x %p)\n",
1439 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1440 dwUrlLength
, dwFlags
, lpUrlComponents
);
1442 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1443 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1445 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1451 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1453 /* if dwUrlLength=-1 then nLength includes null but length to
1454 InternetCrackUrlW should not include it */
1455 if (dwUrlLength
== -1) nLength
--;
1457 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1458 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1459 lpwszUrl
[nLength
] = '\0';
1461 memset(&UCW
,0,sizeof(UCW
));
1462 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1463 if (lpUrlComponents
->dwHostNameLength
)
1465 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1466 if (lpUrlComponents
->lpszHostName
)
1468 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1469 UCW
.lpszHostName
= hostname
;
1472 if (lpUrlComponents
->dwUserNameLength
)
1474 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1475 if (lpUrlComponents
->lpszUserName
)
1477 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1478 UCW
.lpszUserName
= username
;
1481 if (lpUrlComponents
->dwPasswordLength
)
1483 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1484 if (lpUrlComponents
->lpszPassword
)
1486 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1487 UCW
.lpszPassword
= password
;
1490 if (lpUrlComponents
->dwUrlPathLength
)
1492 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1493 if (lpUrlComponents
->lpszUrlPath
)
1495 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1496 UCW
.lpszUrlPath
= path
;
1499 if (lpUrlComponents
->dwSchemeLength
)
1501 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1502 if (lpUrlComponents
->lpszScheme
)
1504 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1505 UCW
.lpszScheme
= scheme
;
1508 if (lpUrlComponents
->dwExtraInfoLength
)
1510 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1511 if (lpUrlComponents
->lpszExtraInfo
)
1513 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1514 UCW
.lpszExtraInfo
= extra
;
1517 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1519 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1520 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1521 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1522 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1523 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1524 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1525 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1526 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1527 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1528 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1529 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1530 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1532 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1533 lpUrlComponents
->nPort
= UCW
.nPort
;
1535 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1536 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1537 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1538 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1539 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1541 heap_free(lpwszUrl
);
1542 heap_free(hostname
);
1543 heap_free(username
);
1544 heap_free(password
);
1551 static const WCHAR url_schemes
[][7] =
1554 {'g','o','p','h','e','r',0},
1555 {'h','t','t','p',0},
1556 {'h','t','t','p','s',0},
1557 {'f','i','l','e',0},
1558 {'n','e','w','s',0},
1559 {'m','a','i','l','t','o',0},
1563 /***********************************************************************
1564 * GetInternetSchemeW (internal)
1570 * INTERNET_SCHEME_UNKNOWN on failure
1573 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1577 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1579 if(lpszScheme
==NULL
)
1580 return INTERNET_SCHEME_UNKNOWN
;
1582 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1583 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1584 return INTERNET_SCHEME_FIRST
+ i
;
1586 return INTERNET_SCHEME_UNKNOWN
;
1589 /***********************************************************************
1590 * SetUrlComponentValueW (Internal)
1592 * Helper function for InternetCrackUrlW
1595 * lppszComponent [O] Holds the returned string
1596 * dwComponentLen [I] Holds the size of lppszComponent
1597 * [O] Holds the length of the string in lppszComponent without '\0'
1598 * lpszStart [I] Holds the string to copy from
1599 * len [I] Holds the length of lpszStart without '\0'
1606 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1608 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1610 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1613 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1615 if (*lppszComponent
== NULL
)
1617 *lppszComponent
= (LPWSTR
)lpszStart
;
1618 *dwComponentLen
= len
;
1622 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1623 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1624 (*lppszComponent
)[ncpylen
] = '\0';
1625 *dwComponentLen
= ncpylen
;
1632 /***********************************************************************
1633 * InternetCrackUrlW (WININET.@)
1635 * Break up URL into its components
1641 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1642 LPURL_COMPONENTSW lpUC
)
1646 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1649 LPCWSTR lpszParam
= NULL
;
1650 BOOL found_colon
= FALSE
;
1651 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1652 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1653 LPWSTR lpszUrl_decode
= NULL
;
1654 DWORD dwUrlLength
= dwUrlLength_orig
;
1656 TRACE("(%s %u %x %p)\n",
1657 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1658 dwUrlLength
, dwFlags
, lpUC
);
1660 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1662 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1665 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1667 if (dwFlags
& ICU_DECODE
)
1670 DWORD len
= dwUrlLength
+ 1;
1672 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1674 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1677 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1678 url_tmp
[dwUrlLength
] = 0;
1679 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1682 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1685 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1688 lpszUrl
= lpszUrl_decode
;
1694 /* Determine if the URI is absolute. */
1695 while (lpszap
- lpszUrl
< dwUrlLength
)
1697 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1709 lpszcp
= lpszUrl
; /* Relative url */
1716 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1720 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1721 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1723 /* Parse <params> */
1724 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1726 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1728 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1729 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1732 /* Get scheme first. */
1733 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1734 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1735 lpszUrl
, lpszcp
- lpszUrl
);
1737 /* Eat ':' in protocol. */
1740 /* double slash indicates the net_loc portion is present */
1741 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1745 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1749 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1751 lpszNetLoc
= lpszParam
;
1753 else if (!lpszNetLoc
)
1754 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1762 /* [<user>[<:password>]@]<host>[:<port>] */
1763 /* First find the user and password if they exist */
1765 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1766 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1768 /* username and password not specified. */
1769 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1770 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1772 else /* Parse out username and password */
1774 LPCWSTR lpszUser
= lpszcp
;
1775 LPCWSTR lpszPasswd
= lpszHost
;
1777 while (lpszcp
< lpszHost
)
1780 lpszPasswd
= lpszcp
;
1785 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1786 lpszUser
, lpszPasswd
- lpszUser
);
1788 if (lpszPasswd
!= lpszHost
)
1790 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1791 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1792 lpszHost
- lpszPasswd
);
1794 lpszcp
++; /* Advance to beginning of host */
1797 /* Parse <host><:port> */
1800 lpszPort
= lpszNetLoc
;
1802 /* special case for res:// URLs: there is no port here, so the host is the
1803 entire string up to the first '/' */
1804 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1806 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1807 lpszHost
, lpszPort
- lpszHost
);
1812 while (lpszcp
< lpszNetLoc
)
1820 /* If the scheme is "file" and the host is just one letter, it's not a host */
1821 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1824 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1829 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1830 lpszHost
, lpszPort
- lpszHost
);
1831 if (lpszPort
!= lpszNetLoc
)
1832 lpUC
->nPort
= atoiW(++lpszPort
);
1833 else switch (lpUC
->nScheme
)
1835 case INTERNET_SCHEME_HTTP
:
1836 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1838 case INTERNET_SCHEME_HTTPS
:
1839 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1841 case INTERNET_SCHEME_FTP
:
1842 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1844 case INTERNET_SCHEME_GOPHER
:
1845 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1856 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1857 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1858 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1861 /* Here lpszcp points to:
1863 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1864 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1866 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1870 /* Only truncate the parameter list if it's already been saved
1871 * in lpUC->lpszExtraInfo.
1873 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1874 len
= lpszParam
- lpszcp
;
1877 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1878 * newlines if necessary.
1880 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1881 if (lpsznewline
!= NULL
)
1882 len
= lpsznewline
- lpszcp
;
1884 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1886 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1887 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1889 WCHAR tmppath
[MAX_PATH
];
1893 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1898 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1899 tmppath
[len
] = '\0';
1908 /* if ends in \. or \.. append a backslash */
1909 if (tmppath
[len
- 1] == '.' &&
1910 (tmppath
[len
- 2] == '\\' ||
1911 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1913 if (len
< MAX_PATH
- 1)
1915 tmppath
[len
] = '\\';
1916 tmppath
[len
+1] = '\0';
1920 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1924 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1929 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1930 lpUC
->lpszUrlPath
[0] = 0;
1931 lpUC
->dwUrlPathLength
= 0;
1934 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1935 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1936 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1937 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1938 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1940 heap_free( lpszUrl_decode
);
1944 /***********************************************************************
1945 * InternetAttemptConnect (WININET.@)
1947 * Attempt to make a connection to the internet
1950 * ERROR_SUCCESS on success
1951 * Error value on failure
1954 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1957 return ERROR_SUCCESS
;
1961 /***********************************************************************
1962 * convert_url_canonicalization_flags
1964 * Helper for InternetCanonicalizeUrl
1967 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1970 * Flags suitable for UrlCanonicalize
1972 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1974 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1976 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1977 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1978 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1979 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1980 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1981 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1982 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1987 /***********************************************************************
1988 * InternetCanonicalizeUrlA (WININET.@)
1990 * Escape unsafe characters and spaces
1997 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1998 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2002 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2003 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2005 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2006 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2007 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2008 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2013 /***********************************************************************
2014 * InternetCanonicalizeUrlW (WININET.@)
2016 * Escape unsafe characters and spaces
2023 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2024 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2028 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2029 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2031 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2032 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2033 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2034 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2039 /* #################################################### */
2041 static INTERNET_STATUS_CALLBACK
set_status_callback(
2042 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2044 INTERNET_STATUS_CALLBACK ret
;
2046 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2047 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2049 ret
= lpwh
->lpfnStatusCB
;
2050 lpwh
->lpfnStatusCB
= callback
;
2055 /***********************************************************************
2056 * InternetSetStatusCallbackA (WININET.@)
2058 * Sets up a callback function which is called as progress is made
2059 * during an operation.
2062 * Previous callback or NULL on success
2063 * INTERNET_INVALID_STATUS_CALLBACK on failure
2066 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2067 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2069 INTERNET_STATUS_CALLBACK retVal
;
2070 object_header_t
*lpwh
;
2072 TRACE("%p\n", hInternet
);
2074 if (!(lpwh
= get_handle_object(hInternet
)))
2075 return INTERNET_INVALID_STATUS_CALLBACK
;
2077 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2079 WININET_Release( lpwh
);
2083 /***********************************************************************
2084 * InternetSetStatusCallbackW (WININET.@)
2086 * Sets up a callback function which is called as progress is made
2087 * during an operation.
2090 * Previous callback or NULL on success
2091 * INTERNET_INVALID_STATUS_CALLBACK on failure
2094 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2095 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2097 INTERNET_STATUS_CALLBACK retVal
;
2098 object_header_t
*lpwh
;
2100 TRACE("%p\n", hInternet
);
2102 if (!(lpwh
= get_handle_object(hInternet
)))
2103 return INTERNET_INVALID_STATUS_CALLBACK
;
2105 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2107 WININET_Release( lpwh
);
2111 /***********************************************************************
2112 * InternetSetFilePointer (WININET.@)
2114 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2115 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2117 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2121 /***********************************************************************
2122 * InternetWriteFile (WININET.@)
2124 * Write data to an open internet file
2131 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2132 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2134 object_header_t
*lpwh
;
2137 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2139 lpwh
= get_handle_object( hFile
);
2141 WARN("Invalid handle\n");
2142 SetLastError(ERROR_INVALID_HANDLE
);
2146 if(lpwh
->vtbl
->WriteFile
) {
2147 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2149 WARN("No Writefile method.\n");
2150 res
= ERROR_INVALID_HANDLE
;
2153 WININET_Release( lpwh
);
2155 if(res
!= ERROR_SUCCESS
)
2157 return res
== ERROR_SUCCESS
;
2161 /***********************************************************************
2162 * InternetReadFile (WININET.@)
2164 * Read data from an open internet file
2171 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2172 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2174 object_header_t
*hdr
;
2175 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2177 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2179 hdr
= get_handle_object(hFile
);
2181 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2185 if(hdr
->vtbl
->ReadFile
)
2186 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2188 WININET_Release(hdr
);
2190 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2191 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2193 if(res
!= ERROR_SUCCESS
)
2195 return res
== ERROR_SUCCESS
;
2198 /***********************************************************************
2199 * InternetReadFileExA (WININET.@)
2201 * Read data from an open internet file
2204 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2205 * lpBuffersOut [I/O] Buffer.
2206 * dwFlags [I] Flags. See notes.
2207 * dwContext [I] Context for callbacks.
2214 * The parameter dwFlags include zero or more of the following flags:
2215 *|IRF_ASYNC - Makes the call asynchronous.
2216 *|IRF_SYNC - Makes the call synchronous.
2217 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2218 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2220 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2223 * InternetOpenUrlA(), HttpOpenRequestA()
2225 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2226 DWORD dwFlags
, DWORD_PTR dwContext
)
2228 object_header_t
*hdr
;
2229 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2231 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2233 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2234 SetLastError(ERROR_INVALID_PARAMETER
);
2238 hdr
= get_handle_object(hFile
);
2240 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2244 if(hdr
->vtbl
->ReadFileEx
)
2245 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2246 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2248 WININET_Release(hdr
);
2250 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2251 res
, lpBuffersOut
->dwBufferLength
);
2253 if(res
!= ERROR_SUCCESS
)
2255 return res
== ERROR_SUCCESS
;
2258 /***********************************************************************
2259 * InternetReadFileExW (WININET.@)
2261 * InternetReadFileExA()
2263 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2264 DWORD dwFlags
, DWORD_PTR dwContext
)
2266 object_header_t
*hdr
;
2267 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2269 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2271 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2272 SetLastError(ERROR_INVALID_PARAMETER
);
2276 hdr
= get_handle_object(hFile
);
2278 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2282 if(hdr
->vtbl
->ReadFileEx
)
2283 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2284 dwFlags
, dwContext
);
2286 WININET_Release(hdr
);
2288 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2289 res
, lpBuffer
->dwBufferLength
);
2291 if(res
!= ERROR_SUCCESS
)
2293 return res
== ERROR_SUCCESS
;
2296 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2298 /* FIXME: This function currently handles more options than it should. Options requiring
2299 * proper handles should be moved to proper functions */
2301 case INTERNET_OPTION_HTTP_VERSION
:
2302 if (*size
< sizeof(HTTP_VERSION_INFO
))
2303 return ERROR_INSUFFICIENT_BUFFER
;
2306 * Presently hardcoded to 1.1
2308 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2309 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2310 *size
= sizeof(HTTP_VERSION_INFO
);
2312 return ERROR_SUCCESS
;
2314 case INTERNET_OPTION_CONNECTED_STATE
:
2315 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2317 if (*size
< sizeof(ULONG
))
2318 return ERROR_INSUFFICIENT_BUFFER
;
2320 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2321 *size
= sizeof(ULONG
);
2323 return ERROR_SUCCESS
;
2325 case INTERNET_OPTION_PROXY
: {
2329 TRACE("Getting global proxy info\n");
2330 memset(&ai
, 0, sizeof(appinfo_t
));
2331 INTERNET_ConfigureProxy(&ai
);
2333 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2334 APPINFO_Destroy(&ai
.hdr
);
2338 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2339 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2341 if (*size
< sizeof(ULONG
))
2342 return ERROR_INSUFFICIENT_BUFFER
;
2344 *(ULONG
*)buffer
= max_conns
;
2345 *size
= sizeof(ULONG
);
2347 return ERROR_SUCCESS
;
2349 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2350 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2352 if (*size
< sizeof(ULONG
))
2353 return ERROR_INSUFFICIENT_BUFFER
;
2355 *(ULONG
*)buffer
= max_1_0_conns
;
2356 *size
= sizeof(ULONG
);
2358 return ERROR_SUCCESS
;
2360 case INTERNET_OPTION_SECURITY_FLAGS
:
2361 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2362 return ERROR_SUCCESS
;
2364 case INTERNET_OPTION_VERSION
: {
2365 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2367 TRACE("INTERNET_OPTION_VERSION\n");
2369 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2370 return ERROR_INSUFFICIENT_BUFFER
;
2372 memcpy(buffer
, &info
, sizeof(info
));
2373 *size
= sizeof(info
);
2375 return ERROR_SUCCESS
;
2378 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2379 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2380 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2381 DWORD res
= ERROR_SUCCESS
, i
;
2385 TRACE("Getting global proxy info\n");
2386 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2389 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2391 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2393 return ERROR_INSUFFICIENT_BUFFER
;
2396 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2397 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2398 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2400 switch (optionW
->dwOption
) {
2401 case INTERNET_PER_CONN_FLAGS
:
2403 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2405 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2408 case INTERNET_PER_CONN_PROXY_SERVER
:
2410 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2412 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2415 case INTERNET_PER_CONN_PROXY_BYPASS
:
2417 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2419 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2422 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2423 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2424 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2425 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2426 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2427 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2428 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2429 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2433 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2434 res
= ERROR_INVALID_PARAMETER
;
2442 case INTERNET_OPTION_REQUEST_FLAGS
:
2443 case INTERNET_OPTION_USER_AGENT
:
2445 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2446 case INTERNET_OPTION_POLICY
:
2447 return ERROR_INVALID_PARAMETER
;
2448 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2449 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2451 if (*size
< sizeof(ULONG
))
2452 return ERROR_INSUFFICIENT_BUFFER
;
2454 *(ULONG
*)buffer
= connect_timeout
;
2455 *size
= sizeof(ULONG
);
2457 return ERROR_SUCCESS
;
2460 FIXME("Stub for %d\n", option
);
2461 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2464 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2467 case INTERNET_OPTION_CONTEXT_VALUE
:
2469 return ERROR_INVALID_PARAMETER
;
2471 if (*size
< sizeof(DWORD_PTR
)) {
2472 *size
= sizeof(DWORD_PTR
);
2473 return ERROR_INSUFFICIENT_BUFFER
;
2476 return ERROR_INVALID_PARAMETER
;
2478 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2479 *size
= sizeof(DWORD_PTR
);
2480 return ERROR_SUCCESS
;
2482 case INTERNET_OPTION_REQUEST_FLAGS
:
2483 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2484 *size
= sizeof(DWORD
);
2485 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2487 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2488 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2489 WARN("Called on global option %u\n", option
);
2490 return ERROR_INTERNET_INVALID_OPERATION
;
2493 /* FIXME: we shouldn't call it here */
2494 return query_global_option(option
, buffer
, size
, unicode
);
2497 /***********************************************************************
2498 * InternetQueryOptionW (WININET.@)
2500 * Queries an options on the specified handle
2507 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2508 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2510 object_header_t
*hdr
;
2511 DWORD res
= ERROR_INVALID_HANDLE
;
2513 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2516 hdr
= get_handle_object(hInternet
);
2518 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2519 WININET_Release(hdr
);
2522 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2525 if(res
!= ERROR_SUCCESS
)
2527 return res
== ERROR_SUCCESS
;
2530 /***********************************************************************
2531 * InternetQueryOptionA (WININET.@)
2533 * Queries an options on the specified handle
2540 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2541 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2543 object_header_t
*hdr
;
2544 DWORD res
= ERROR_INVALID_HANDLE
;
2546 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2549 hdr
= get_handle_object(hInternet
);
2551 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2552 WININET_Release(hdr
);
2555 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2558 if(res
!= ERROR_SUCCESS
)
2560 return res
== ERROR_SUCCESS
;
2563 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2566 case INTERNET_OPTION_CALLBACK
:
2567 WARN("Not settable option %u\n", option
);
2568 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2569 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2570 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2571 WARN("Called on global option %u\n", option
);
2572 return ERROR_INTERNET_INVALID_OPERATION
;
2575 return ERROR_INTERNET_INVALID_OPTION
;
2578 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2581 case INTERNET_OPTION_CALLBACK
:
2582 WARN("Not global option %u\n", option
);
2583 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2585 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2586 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2588 if(size
!= sizeof(max_conns
))
2589 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2591 return ERROR_BAD_ARGUMENTS
;
2593 max_conns
= *(ULONG
*)buf
;
2594 return ERROR_SUCCESS
;
2596 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2597 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2599 if(size
!= sizeof(max_1_0_conns
))
2600 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2602 return ERROR_BAD_ARGUMENTS
;
2604 max_1_0_conns
= *(ULONG
*)buf
;
2605 return ERROR_SUCCESS
;
2607 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2608 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2610 if(size
!= sizeof(connect_timeout
))
2611 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2613 return ERROR_BAD_ARGUMENTS
;
2615 connect_timeout
= *(ULONG
*)buf
;
2616 return ERROR_SUCCESS
;
2618 case INTERNET_OPTION_SETTINGS_CHANGED
:
2619 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2620 collect_connections(COLLECT_CONNECTIONS
);
2621 return ERROR_SUCCESS
;
2624 return ERROR_INTERNET_INVALID_OPTION
;
2627 /***********************************************************************
2628 * InternetSetOptionW (WININET.@)
2630 * Sets an options on the specified handle
2637 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2638 LPVOID lpBuffer
, DWORD dwBufferLength
)
2640 object_header_t
*lpwhh
;
2644 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2646 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2648 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2650 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2652 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2654 WININET_Release(lpwhh
);
2656 if(res
!= ERROR_SUCCESS
)
2659 return res
== ERROR_SUCCESS
;
2664 case INTERNET_OPTION_HTTP_VERSION
:
2666 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2667 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2670 case INTERNET_OPTION_ERROR_MASK
:
2673 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2675 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2676 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2677 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2678 SetLastError(ERROR_INVALID_PARAMETER
);
2680 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2681 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2684 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2685 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2688 case INTERNET_OPTION_PROXY
:
2690 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2692 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2694 SetLastError(ERROR_INVALID_PARAMETER
);
2699 EnterCriticalSection( &WININET_cs
);
2700 free_global_proxy();
2701 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2704 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2706 global_proxy
->proxyEnabled
= 1;
2707 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2708 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2712 global_proxy
->proxyEnabled
= 0;
2713 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2716 LeaveCriticalSection( &WININET_cs
);
2720 /* In general, each type of object should handle
2721 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2722 * get silently dropped.
2724 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2725 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2730 case INTERNET_OPTION_CODEPAGE
:
2732 ULONG codepage
= *(ULONG
*)lpBuffer
;
2733 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2736 case INTERNET_OPTION_REQUEST_PRIORITY
:
2738 ULONG priority
= *(ULONG
*)lpBuffer
;
2739 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2742 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2744 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2745 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2748 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2750 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2751 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2754 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2755 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2757 case INTERNET_OPTION_END_BROWSER_SESSION
:
2758 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2760 case INTERNET_OPTION_CONNECTED_STATE
:
2761 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2763 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2764 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2766 case INTERNET_OPTION_SEND_TIMEOUT
:
2767 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2768 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2770 ULONG timeout
= *(ULONG
*)lpBuffer
;
2771 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2774 case INTERNET_OPTION_CONNECT_RETRIES
:
2776 ULONG retries
= *(ULONG
*)lpBuffer
;
2777 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2780 case INTERNET_OPTION_CONTEXT_VALUE
:
2784 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2787 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2789 SetLastError(ERROR_INVALID_PARAMETER
);
2793 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2796 case INTERNET_OPTION_SECURITY_FLAGS
:
2797 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2799 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2800 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2802 case INTERNET_OPTION_HTTP_DECODING
:
2803 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2804 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2807 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2808 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2809 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2812 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2813 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2814 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2817 case INTERNET_OPTION_CODEPAGE_PATH
:
2818 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2819 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2822 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2823 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2824 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2827 case INTERNET_OPTION_IDN
:
2828 FIXME("INTERNET_OPTION_IDN; STUB\n");
2829 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2832 case INTERNET_OPTION_POLICY
:
2833 SetLastError(ERROR_INVALID_PARAMETER
);
2836 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2837 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2842 INTERNET_LoadProxySettings(&pi
);
2844 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2845 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2847 switch (option
->dwOption
) {
2848 case INTERNET_PER_CONN_PROXY_SERVER
:
2849 heap_free(pi
.proxy
);
2850 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2853 case INTERNET_PER_CONN_FLAGS
:
2854 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2855 pi
.proxyEnabled
= 1;
2858 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2859 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2860 pi
.proxyEnabled
= 0;
2864 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2865 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2866 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2867 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2868 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2869 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2870 case INTERNET_PER_CONN_PROXY_BYPASS
:
2871 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2875 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2876 SetLastError(ERROR_INVALID_PARAMETER
);
2881 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2886 ret
= (res
== ERROR_SUCCESS
);
2890 FIXME("Option %d STUB\n",dwOption
);
2891 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2897 WININET_Release( lpwhh
);
2903 /***********************************************************************
2904 * InternetSetOptionA (WININET.@)
2906 * Sets an options on the specified handle.
2913 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2914 LPVOID lpBuffer
, DWORD dwBufferLength
)
2922 case INTERNET_OPTION_PROXY
:
2924 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2925 LPINTERNET_PROXY_INFOW piw
;
2926 DWORD proxlen
, prbylen
;
2929 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2930 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2931 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2932 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2933 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2934 piw
->dwAccessType
= pi
->dwAccessType
;
2935 prox
= (LPWSTR
) &piw
[1];
2936 prby
= &prox
[proxlen
+1];
2937 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2938 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2939 piw
->lpszProxy
= prox
;
2940 piw
->lpszProxyBypass
= prby
;
2943 case INTERNET_OPTION_USER_AGENT
:
2944 case INTERNET_OPTION_USERNAME
:
2945 case INTERNET_OPTION_PASSWORD
:
2946 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2948 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2949 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2952 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2954 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
2955 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
2956 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2957 wbuffer
= heap_alloc(wlen
);
2960 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2961 if (listA
->pszConnection
)
2963 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
2964 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
2965 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
2968 listW
->pszConnection
= NULL
;
2969 listW
->dwOptionCount
= listA
->dwOptionCount
;
2970 listW
->dwOptionError
= listA
->dwOptionError
;
2971 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
2973 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
2974 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
2975 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
2977 optW
->dwOption
= optA
->dwOption
;
2979 switch (optA
->dwOption
) {
2980 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2981 case INTERNET_PER_CONN_PROXY_BYPASS
:
2982 case INTERNET_PER_CONN_PROXY_SERVER
:
2983 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2984 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2985 if (optA
->Value
.pszValue
)
2987 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
2988 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
2989 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
2992 optW
->Value
.pszValue
= NULL
;
2994 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2995 case INTERNET_PER_CONN_FLAGS
:
2996 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2997 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
2999 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3000 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3003 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3004 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3012 wlen
= dwBufferLength
;
3015 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3017 if( lpBuffer
!= wbuffer
)
3019 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3021 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3023 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3024 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3025 switch (opt
->dwOption
) {
3026 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3027 case INTERNET_PER_CONN_PROXY_BYPASS
:
3028 case INTERNET_PER_CONN_PROXY_SERVER
:
3029 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3030 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3031 heap_free( opt
->Value
.pszValue
);
3037 heap_free( list
->pOptions
);
3039 heap_free( wbuffer
);
3046 /***********************************************************************
3047 * InternetSetOptionExA (WININET.@)
3049 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3050 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3052 FIXME("Flags %08x ignored\n", dwFlags
);
3053 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3056 /***********************************************************************
3057 * InternetSetOptionExW (WININET.@)
3059 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3060 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3062 FIXME("Flags %08x ignored\n", dwFlags
);
3063 if( dwFlags
& ~ISO_VALID_FLAGS
)
3065 SetLastError( ERROR_INVALID_PARAMETER
);
3068 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3071 static const WCHAR WININET_wkday
[7][4] =
3072 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3073 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3074 static const WCHAR WININET_month
[12][4] =
3075 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3076 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3077 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3079 /***********************************************************************
3080 * InternetTimeFromSystemTimeA (WININET.@)
3082 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3085 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3087 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3089 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3091 SetLastError(ERROR_INVALID_PARAMETER
);
3095 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3097 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3101 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3102 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3107 /***********************************************************************
3108 * InternetTimeFromSystemTimeW (WININET.@)
3110 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3112 static const WCHAR date
[] =
3113 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3114 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3116 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3118 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3120 SetLastError(ERROR_INVALID_PARAMETER
);
3124 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3126 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3130 sprintfW( string
, date
,
3131 WININET_wkday
[time
->wDayOfWeek
],
3133 WININET_month
[time
->wMonth
- 1],
3142 /***********************************************************************
3143 * InternetTimeToSystemTimeA (WININET.@)
3145 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3150 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3152 stringW
= heap_strdupAtoW(string
);
3155 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3156 heap_free( stringW
);
3161 /***********************************************************************
3162 * InternetTimeToSystemTimeW (WININET.@)
3164 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3167 const WCHAR
*s
= string
;
3170 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3172 if (!string
|| !time
) return FALSE
;
3174 /* Windows does this too */
3175 GetSystemTime( time
);
3177 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3178 * a SYSTEMTIME structure.
3181 while (*s
&& !isalphaW( *s
)) s
++;
3182 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3183 time
->wDayOfWeek
= 7;
3185 for (i
= 0; i
< 7; i
++)
3187 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3188 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3189 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3191 time
->wDayOfWeek
= i
;
3196 if (time
->wDayOfWeek
> 6) return TRUE
;
3197 while (*s
&& !isdigitW( *s
)) s
++;
3198 time
->wDay
= strtolW( s
, &end
, 10 );
3201 while (*s
&& !isalphaW( *s
)) s
++;
3202 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3205 for (i
= 0; i
< 12; i
++)
3207 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3208 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3209 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3211 time
->wMonth
= i
+ 1;
3215 if (time
->wMonth
== 0) return TRUE
;
3217 while (*s
&& !isdigitW( *s
)) s
++;
3218 if (*s
== '\0') return TRUE
;
3219 time
->wYear
= strtolW( s
, &end
, 10 );
3222 while (*s
&& !isdigitW( *s
)) s
++;
3223 if (*s
== '\0') return TRUE
;
3224 time
->wHour
= strtolW( s
, &end
, 10 );
3227 while (*s
&& !isdigitW( *s
)) s
++;
3228 if (*s
== '\0') return TRUE
;
3229 time
->wMinute
= strtolW( s
, &end
, 10 );
3232 while (*s
&& !isdigitW( *s
)) s
++;
3233 if (*s
== '\0') return TRUE
;
3234 time
->wSecond
= strtolW( s
, &end
, 10 );
3237 time
->wMilliseconds
= 0;
3241 /***********************************************************************
3242 * InternetCheckConnectionW (WININET.@)
3244 * Pings a requested host to check internet connection
3247 * TRUE on success and FALSE on failure. If a failure then
3248 * ERROR_NOT_CONNECTED is placed into GetLastError
3251 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3254 * this is a kludge which runs the resident ping program and reads the output.
3256 * Anyone have a better idea?
3260 static const CHAR ping
[] = "ping -c 1 ";
3261 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3262 CHAR
*command
= NULL
;
3263 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3271 * Crack or set the Address
3273 if (lpszUrl
== NULL
)
3276 * According to the doc we are supposed to use the ip for the next
3277 * server in the WnInet internal server database. I have
3278 * no idea what that is or how to get it.
3280 * So someone needs to implement this.
3282 FIXME("Unimplemented with URL of NULL\n");
3287 URL_COMPONENTSW components
;
3289 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3290 components
.lpszHostName
= (LPWSTR
)hostW
;
3291 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3293 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3296 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3297 port
= components
.nPort
;
3298 TRACE("port: %d\n", port
);
3301 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3303 struct sockaddr_storage saddr
;
3304 socklen_t sa_len
= sizeof(saddr
);
3307 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3309 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3312 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3320 * Build our ping command
3322 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3323 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3324 strcpy(command
,ping
);
3325 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3326 strcat(command
,redirect
);
3328 TRACE("Ping command is : %s\n",command
);
3330 status
= system(command
);
3332 TRACE("Ping returned a code of %i\n",status
);
3334 /* Ping return code of 0 indicates success */
3340 heap_free( command
);
3342 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3348 /***********************************************************************
3349 * InternetCheckConnectionA (WININET.@)
3351 * Pings a requested host to check internet connection
3354 * TRUE on success and FALSE on failure. If a failure then
3355 * ERROR_NOT_CONNECTED is placed into GetLastError
3358 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3364 url
= heap_strdupAtoW(lpszUrl
);
3369 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3376 /**********************************************************
3377 * INTERNET_InternetOpenUrlW (internal)
3382 * handle of connection or NULL on failure
3384 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3385 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3387 URL_COMPONENTSW urlComponents
;
3388 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3389 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3390 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3391 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3392 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3394 HINTERNET client
= NULL
, client1
= NULL
;
3397 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3398 dwHeadersLength
, dwFlags
, dwContext
);
3400 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3401 urlComponents
.lpszScheme
= protocol
;
3402 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3403 urlComponents
.lpszHostName
= hostName
;
3404 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3405 urlComponents
.lpszUserName
= userName
;
3406 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3407 urlComponents
.lpszPassword
= password
;
3408 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3409 urlComponents
.lpszUrlPath
= path
;
3410 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3411 urlComponents
.lpszExtraInfo
= extra
;
3412 urlComponents
.dwExtraInfoLength
= 1024;
3413 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3415 switch(urlComponents
.nScheme
) {
3416 case INTERNET_SCHEME_FTP
:
3417 if(urlComponents
.nPort
== 0)
3418 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3419 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3420 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3423 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3424 if(client1
== NULL
) {
3425 InternetCloseHandle(client
);
3430 case INTERNET_SCHEME_HTTP
:
3431 case INTERNET_SCHEME_HTTPS
: {
3432 static const WCHAR szStars
[] = { '*','/','*', 0 };
3433 LPCWSTR accept
[2] = { szStars
, NULL
};
3434 if(urlComponents
.nPort
== 0) {
3435 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3436 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3438 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3440 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3442 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3443 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3444 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3445 if(res
!= ERROR_SUCCESS
) {
3446 INTERNET_SetLastError(res
);
3450 if (urlComponents
.dwExtraInfoLength
) {
3452 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3454 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3456 InternetCloseHandle(client
);
3459 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3460 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3461 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3462 heap_free(path_extra
);
3465 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3467 if(client1
== NULL
) {
3468 InternetCloseHandle(client
);
3471 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3472 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3473 GetLastError() != ERROR_IO_PENDING
) {
3474 InternetCloseHandle(client1
);
3479 case INTERNET_SCHEME_GOPHER
:
3480 /* gopher doesn't seem to be implemented in wine, but it's supposed
3481 * to be supported by InternetOpenUrlA. */
3483 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3487 TRACE(" %p <--\n", client1
);
3492 /**********************************************************
3493 * InternetOpenUrlW (WININET.@)
3498 * handle of connection or NULL on failure
3500 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3502 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3503 appinfo_t
*hIC
= (appinfo_t
*) workRequest
->hdr
;
3507 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3508 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3509 heap_free(req
->lpszUrl
);
3510 heap_free(req
->lpszHeaders
);
3513 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3514 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3516 HINTERNET ret
= NULL
;
3517 appinfo_t
*hIC
= NULL
;
3519 if (TRACE_ON(wininet
)) {
3520 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3521 dwHeadersLength
, dwFlags
, dwContext
);
3523 dump_INTERNET_FLAGS(dwFlags
);
3528 SetLastError(ERROR_INVALID_PARAMETER
);
3532 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3533 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3534 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3538 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3539 WORKREQUEST workRequest
;
3540 struct WORKREQ_INTERNETOPENURLW
*req
;
3542 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3543 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3544 req
= &workRequest
.u
.InternetOpenUrlW
;
3545 req
->lpszUrl
= heap_strdupW(lpszUrl
);
3546 req
->lpszHeaders
= heap_strdupW(lpszHeaders
);
3547 req
->dwHeadersLength
= dwHeadersLength
;
3548 req
->dwFlags
= dwFlags
;
3549 req
->dwContext
= dwContext
;
3551 INTERNET_AsyncCall(&workRequest
);
3553 * This is from windows.
3555 SetLastError(ERROR_IO_PENDING
);
3557 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3562 WININET_Release( &hIC
->hdr
);
3563 TRACE(" %p <--\n", ret
);
3568 /**********************************************************
3569 * InternetOpenUrlA (WININET.@)
3574 * handle of connection or NULL on failure
3576 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3577 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3579 HINTERNET rc
= NULL
;
3580 DWORD lenHeaders
= 0;
3581 LPWSTR szUrl
= NULL
;
3582 LPWSTR szHeaders
= NULL
;
3587 szUrl
= heap_strdupAtoW(lpszUrl
);
3593 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3594 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3599 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3602 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3603 lenHeaders
, dwFlags
, dwContext
);
3606 heap_free(szHeaders
);
3611 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3613 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3617 lpwite
->dwError
= 0;
3618 lpwite
->response
[0] = '\0';
3621 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3630 /***********************************************************************
3631 * INTERNET_SetLastError (internal)
3633 * Set last thread specific error
3638 void INTERNET_SetLastError(DWORD dwError
)
3640 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3643 lpwite
= INTERNET_AllocThreadError();
3645 SetLastError(dwError
);
3647 lpwite
->dwError
= dwError
;
3651 /***********************************************************************
3652 * INTERNET_GetLastError (internal)
3654 * Get last thread specific error
3659 DWORD
INTERNET_GetLastError(void)
3661 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3662 if (!lpwite
) return 0;
3663 /* TlsGetValue clears last error, so set it again here */
3664 SetLastError(lpwite
->dwError
);
3665 return lpwite
->dwError
;
3669 /***********************************************************************
3670 * INTERNET_WorkerThreadFunc (internal)
3672 * Worker thread execution function
3677 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3679 LPWORKREQUEST lpRequest
= lpvParam
;
3680 WORKREQUEST workRequest
;
3684 workRequest
= *lpRequest
;
3685 heap_free(lpRequest
);
3687 workRequest
.asyncproc(&workRequest
);
3688 WININET_Release( workRequest
.hdr
);
3690 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3692 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3693 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3699 /***********************************************************************
3700 * INTERNET_AsyncCall (internal)
3702 * Retrieves work request from queue
3707 DWORD
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3710 LPWORKREQUEST lpNewRequest
;
3714 lpNewRequest
= heap_alloc(sizeof(WORKREQUEST
));
3716 return ERROR_OUTOFMEMORY
;
3718 *lpNewRequest
= *lpWorkRequest
;
3720 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3723 heap_free(lpNewRequest
);
3724 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3726 return ERROR_SUCCESS
;
3730 /***********************************************************************
3731 * INTERNET_GetResponseBuffer (internal)
3736 LPSTR
INTERNET_GetResponseBuffer(void)
3738 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3740 lpwite
= INTERNET_AllocThreadError();
3742 return lpwite
->response
;
3745 /***********************************************************************
3746 * INTERNET_GetNextLine (internal)
3748 * Parse next line in directory string listing
3751 * Pointer to beginning of next line
3756 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3759 BOOL bSuccess
= FALSE
;
3761 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3766 pfd
.events
= POLLIN
;
3768 while (nRecv
< MAX_REPLY_LEN
)
3770 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3772 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3774 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3778 if (lpszBuffer
[nRecv
] == '\n')
3783 if (lpszBuffer
[nRecv
] != '\r')
3788 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3796 lpszBuffer
[nRecv
] = '\0';
3798 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3807 /**********************************************************
3808 * InternetQueryDataAvailable (WININET.@)
3810 * Determines how much data is available to be read.
3813 * TRUE on success, FALSE if an error occurred. If
3814 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3815 * no data is presently available, FALSE is returned with
3816 * the last error ERROR_IO_PENDING; a callback with status
3817 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3818 * data is available.
3820 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3821 LPDWORD lpdwNumberOfBytesAvailable
,
3822 DWORD dwFlags
, DWORD_PTR dwContext
)
3824 object_header_t
*hdr
;
3827 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3829 hdr
= get_handle_object( hFile
);
3831 SetLastError(ERROR_INVALID_HANDLE
);
3835 if(hdr
->vtbl
->QueryDataAvailable
) {
3836 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3838 WARN("wrong handle\n");
3839 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3842 WININET_Release(hdr
);
3844 if(res
!= ERROR_SUCCESS
)
3846 return res
== ERROR_SUCCESS
;
3850 /***********************************************************************
3851 * InternetLockRequestFile (WININET.@)
3853 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3860 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3867 /***********************************************************************
3868 * InternetAutodial (WININET.@)
3870 * On windows this function is supposed to dial the default internet
3871 * connection. We don't want to have Wine dial out to the internet so
3872 * we return TRUE by default. It might be nice to check if we are connected.
3879 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3883 /* Tell that we are connected to the internet. */
3887 /***********************************************************************
3888 * InternetAutodialHangup (WININET.@)
3890 * Hangs up a connection made with InternetAutodial
3899 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3903 /* we didn't dial, we don't disconnect */
3907 /***********************************************************************
3908 * InternetCombineUrlA (WININET.@)
3910 * Combine a base URL with a relative URL
3918 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3919 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3924 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3926 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3927 dwFlags
^= ICU_NO_ENCODE
;
3928 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3933 /***********************************************************************
3934 * InternetCombineUrlW (WININET.@)
3936 * Combine a base URL with a relative URL
3944 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3945 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3950 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3952 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3953 dwFlags
^= ICU_NO_ENCODE
;
3954 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3959 /* max port num is 65535 => 5 digits */
3960 #define MAX_WORD_DIGITS 5
3962 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3963 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3964 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3965 (url)->dw##component##Length : strlen((url)->lpsz##component))
3967 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3969 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3970 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3972 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3973 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3975 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3976 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3978 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3979 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3982 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3988 /* opaque urls do not fit into the standard url hierarchy and don't have
3989 * two following slashes */
3990 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3992 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3993 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3994 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3995 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3996 (nScheme
!= INTERNET_SCHEME_FILE
);
3999 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4002 if (scheme
< INTERNET_SCHEME_FIRST
)
4004 index
= scheme
- INTERNET_SCHEME_FIRST
;
4005 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4007 return (LPCWSTR
)url_schemes
[index
];
4010 /* we can calculate using ansi strings because we're just
4011 * calculating string length, not size
4013 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4014 LPDWORD lpdwUrlLength
)
4016 INTERNET_SCHEME nScheme
;
4020 if (lpUrlComponents
->lpszScheme
)
4022 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4023 *lpdwUrlLength
+= dwLen
;
4024 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4030 nScheme
= lpUrlComponents
->nScheme
;
4032 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4033 nScheme
= INTERNET_SCHEME_HTTP
;
4034 scheme
= INTERNET_GetSchemeString(nScheme
);
4035 *lpdwUrlLength
+= strlenW(scheme
);
4038 (*lpdwUrlLength
)++; /* ':' */
4039 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4040 *lpdwUrlLength
+= strlen("//");
4042 if (lpUrlComponents
->lpszUserName
)
4044 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4045 *lpdwUrlLength
+= strlen("@");
4049 if (lpUrlComponents
->lpszPassword
)
4051 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4056 if (lpUrlComponents
->lpszPassword
)
4058 *lpdwUrlLength
+= strlen(":");
4059 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4062 if (lpUrlComponents
->lpszHostName
)
4064 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4066 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4068 char szPort
[MAX_WORD_DIGITS
+1];
4070 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4071 *lpdwUrlLength
+= strlen(szPort
);
4072 *lpdwUrlLength
+= strlen(":");
4075 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4076 (*lpdwUrlLength
)++; /* '/' */
4079 if (lpUrlComponents
->lpszUrlPath
)
4080 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4082 if (lpUrlComponents
->lpszExtraInfo
)
4083 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4088 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4092 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4094 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4095 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4096 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4097 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4098 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4099 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4100 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4101 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4102 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4104 if (lpUrlComponents
->lpszScheme
)
4106 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4107 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4108 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4109 -1, urlCompW
->lpszScheme
, len
);
4112 if (lpUrlComponents
->lpszHostName
)
4114 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4115 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4116 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4117 -1, urlCompW
->lpszHostName
, len
);
4120 if (lpUrlComponents
->lpszUserName
)
4122 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4123 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4124 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4125 -1, urlCompW
->lpszUserName
, len
);
4128 if (lpUrlComponents
->lpszPassword
)
4130 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4131 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4132 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4133 -1, urlCompW
->lpszPassword
, len
);
4136 if (lpUrlComponents
->lpszUrlPath
)
4138 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4139 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4140 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4141 -1, urlCompW
->lpszUrlPath
, len
);
4144 if (lpUrlComponents
->lpszExtraInfo
)
4146 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4147 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4148 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4149 -1, urlCompW
->lpszExtraInfo
, len
);
4153 /***********************************************************************
4154 * InternetCreateUrlA (WININET.@)
4156 * See InternetCreateUrlW.
4158 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4159 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4163 URL_COMPONENTSW urlCompW
;
4165 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4167 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4169 SetLastError(ERROR_INVALID_PARAMETER
);
4173 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4176 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4178 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4180 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4181 *lpdwUrlLength
/= sizeof(WCHAR
);
4183 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4184 * minus one, so add one to leave room for NULL terminator
4187 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4189 heap_free(urlCompW
.lpszScheme
);
4190 heap_free(urlCompW
.lpszHostName
);
4191 heap_free(urlCompW
.lpszUserName
);
4192 heap_free(urlCompW
.lpszPassword
);
4193 heap_free(urlCompW
.lpszUrlPath
);
4194 heap_free(urlCompW
.lpszExtraInfo
);
4199 /***********************************************************************
4200 * InternetCreateUrlW (WININET.@)
4202 * Creates a URL from its component parts.
4205 * lpUrlComponents [I] URL Components.
4206 * dwFlags [I] Flags. See notes.
4207 * lpszUrl [I] Buffer in which to store the created URL.
4208 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4209 * lpszUrl in characters. On output, the number of bytes
4210 * required to store the URL including terminator.
4214 * The dwFlags parameter can be zero or more of the following:
4215 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4222 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4223 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4226 INTERNET_SCHEME nScheme
;
4228 static const WCHAR slashSlashW
[] = {'/','/'};
4229 static const WCHAR fmtW
[] = {'%','u',0};
4231 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4233 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4235 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4239 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4242 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4244 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4245 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4249 *lpdwUrlLength
= dwLen
;
4254 if (lpUrlComponents
->lpszScheme
)
4256 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4257 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4260 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4265 nScheme
= lpUrlComponents
->nScheme
;
4267 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4268 nScheme
= INTERNET_SCHEME_HTTP
;
4270 scheme
= INTERNET_GetSchemeString(nScheme
);
4271 dwLen
= strlenW(scheme
);
4272 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4276 /* all schemes are followed by at least a colon */
4280 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4282 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4283 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4286 if (lpUrlComponents
->lpszUserName
)
4288 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4289 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4292 if (lpUrlComponents
->lpszPassword
)
4297 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4298 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4306 if (lpUrlComponents
->lpszHostName
)
4308 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4309 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4312 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4314 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4316 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4319 dwLen
= strlenW(szPort
);
4320 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4324 /* add slash between hostname and path if necessary */
4325 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4332 if (lpUrlComponents
->lpszUrlPath
)
4334 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4335 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4339 if (lpUrlComponents
->lpszExtraInfo
)
4341 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4342 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4351 /***********************************************************************
4352 * InternetConfirmZoneCrossingA (WININET.@)
4355 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4357 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4358 return ERROR_SUCCESS
;
4361 /***********************************************************************
4362 * InternetConfirmZoneCrossingW (WININET.@)
4365 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4367 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4368 return ERROR_SUCCESS
;
4371 static DWORD zone_preference
= 3;
4373 /***********************************************************************
4374 * PrivacySetZonePreferenceW (WININET.@)
4376 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4378 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4380 zone_preference
= template;
4384 /***********************************************************************
4385 * PrivacyGetZonePreferenceW (WININET.@)
4387 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4388 LPWSTR preference
, LPDWORD length
)
4390 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4392 if (template) *template = zone_preference
;
4396 /***********************************************************************
4397 * InternetGetSecurityInfoByURLA (WININET.@)
4399 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4404 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4406 url
= heap_strdupAtoW(lpszURL
);
4410 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4415 /***********************************************************************
4416 * InternetGetSecurityInfoByURLW (WININET.@)
4418 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4420 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4421 URL_COMPONENTSW url
= {sizeof(url
)};
4425 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4427 url
.lpszHostName
= hostname
;
4428 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4430 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4431 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4432 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4436 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4438 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4442 if(server
->cert_chain
) {
4443 const CERT_CHAIN_CONTEXT
*chain_dup
;
4445 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4447 *ppCertChain
= chain_dup
;
4448 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4453 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4457 server_release(server
);
4461 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4462 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4464 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4465 lpdwConnection
, dwReserved
);
4466 return ERROR_SUCCESS
;
4469 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4470 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4472 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4473 lpdwConnection
, dwReserved
);
4474 return ERROR_SUCCESS
;
4477 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4479 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4483 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4485 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4489 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4491 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4492 return ERROR_SUCCESS
;
4495 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4498 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4499 debugstr_w(pwszTarget
), pbHexHash
);
4503 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4505 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4509 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4511 FIXME("(%p, %08lx) stub\n", a
, b
);
4515 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4517 FIXME("%p: stub\n", parent
);