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 bIsAbsolute
= FALSE
;
1651 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1652 LPCWSTR lpszcp
= NULL
;
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
== '-')
1702 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1709 lpszcp
= lpszUrl
; /* Relative url */
1715 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1716 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1718 /* Parse <params> */
1719 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1721 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1723 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1724 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1726 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1730 /* Get scheme first. */
1731 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1732 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1733 lpszUrl
, lpszcp
- lpszUrl
);
1735 /* Eat ':' in protocol. */
1738 /* double slash indicates the net_loc portion is present */
1739 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1743 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1747 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1749 lpszNetLoc
= lpszParam
;
1751 else if (!lpszNetLoc
)
1752 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1760 /* [<user>[<:password>]@]<host>[:<port>] */
1761 /* First find the user and password if they exist */
1763 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1764 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1766 /* username and password not specified. */
1767 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1768 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1770 else /* Parse out username and password */
1772 LPCWSTR lpszUser
= lpszcp
;
1773 LPCWSTR lpszPasswd
= lpszHost
;
1775 while (lpszcp
< lpszHost
)
1778 lpszPasswd
= lpszcp
;
1783 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1784 lpszUser
, lpszPasswd
- lpszUser
);
1786 if (lpszPasswd
!= lpszHost
)
1788 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1789 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1790 lpszHost
- lpszPasswd
);
1792 lpszcp
++; /* Advance to beginning of host */
1795 /* Parse <host><:port> */
1798 lpszPort
= lpszNetLoc
;
1800 /* special case for res:// URLs: there is no port here, so the host is the
1801 entire string up to the first '/' */
1802 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1804 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1805 lpszHost
, lpszPort
- lpszHost
);
1810 while (lpszcp
< lpszNetLoc
)
1818 /* If the scheme is "file" and the host is just one letter, it's not a host */
1819 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1822 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1827 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1828 lpszHost
, lpszPort
- lpszHost
);
1829 if (lpszPort
!= lpszNetLoc
)
1830 lpUC
->nPort
= atoiW(++lpszPort
);
1831 else switch (lpUC
->nScheme
)
1833 case INTERNET_SCHEME_HTTP
:
1834 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1836 case INTERNET_SCHEME_HTTPS
:
1837 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1839 case INTERNET_SCHEME_FTP
:
1840 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1842 case INTERNET_SCHEME_GOPHER
:
1843 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1854 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1855 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1856 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1861 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1862 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1863 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1864 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1867 /* Here lpszcp points to:
1869 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1870 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1872 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1876 /* Only truncate the parameter list if it's already been saved
1877 * in lpUC->lpszExtraInfo.
1879 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1880 len
= lpszParam
- lpszcp
;
1883 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1884 * newlines if necessary.
1886 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1887 if (lpsznewline
!= NULL
)
1888 len
= lpsznewline
- lpszcp
;
1890 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1892 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1893 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1895 WCHAR tmppath
[MAX_PATH
];
1899 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1904 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1905 tmppath
[len
] = '\0';
1914 /* if ends in \. or \.. append a backslash */
1915 if (tmppath
[len
- 1] == '.' &&
1916 (tmppath
[len
- 2] == '\\' ||
1917 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1919 if (len
< MAX_PATH
- 1)
1921 tmppath
[len
] = '\\';
1922 tmppath
[len
+1] = '\0';
1926 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1930 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1935 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1936 lpUC
->lpszUrlPath
[0] = 0;
1937 lpUC
->dwUrlPathLength
= 0;
1940 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1941 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1942 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1943 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1944 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1946 heap_free( lpszUrl_decode
);
1950 /***********************************************************************
1951 * InternetAttemptConnect (WININET.@)
1953 * Attempt to make a connection to the internet
1956 * ERROR_SUCCESS on success
1957 * Error value on failure
1960 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1963 return ERROR_SUCCESS
;
1967 /***********************************************************************
1968 * convert_url_canonicalization_flags
1970 * Helper for InternetCanonicalizeUrl
1973 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1976 * Flags suitable for UrlCanonicalize
1978 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1980 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1982 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1983 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1984 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1985 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1986 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1987 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1988 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1993 /***********************************************************************
1994 * InternetCanonicalizeUrlA (WININET.@)
1996 * Escape unsafe characters and spaces
2003 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2004 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2008 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2009 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2011 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2012 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2013 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2014 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2019 /***********************************************************************
2020 * InternetCanonicalizeUrlW (WININET.@)
2022 * Escape unsafe characters and spaces
2029 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2030 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2034 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2035 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2037 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2038 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2039 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2040 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2045 /* #################################################### */
2047 static INTERNET_STATUS_CALLBACK
set_status_callback(
2048 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2050 INTERNET_STATUS_CALLBACK ret
;
2052 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2053 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2055 ret
= lpwh
->lpfnStatusCB
;
2056 lpwh
->lpfnStatusCB
= callback
;
2061 /***********************************************************************
2062 * InternetSetStatusCallbackA (WININET.@)
2064 * Sets up a callback function which is called as progress is made
2065 * during an operation.
2068 * Previous callback or NULL on success
2069 * INTERNET_INVALID_STATUS_CALLBACK on failure
2072 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2073 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2075 INTERNET_STATUS_CALLBACK retVal
;
2076 object_header_t
*lpwh
;
2078 TRACE("%p\n", hInternet
);
2080 if (!(lpwh
= get_handle_object(hInternet
)))
2081 return INTERNET_INVALID_STATUS_CALLBACK
;
2083 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2085 WININET_Release( lpwh
);
2089 /***********************************************************************
2090 * InternetSetStatusCallbackW (WININET.@)
2092 * Sets up a callback function which is called as progress is made
2093 * during an operation.
2096 * Previous callback or NULL on success
2097 * INTERNET_INVALID_STATUS_CALLBACK on failure
2100 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2101 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2103 INTERNET_STATUS_CALLBACK retVal
;
2104 object_header_t
*lpwh
;
2106 TRACE("%p\n", hInternet
);
2108 if (!(lpwh
= get_handle_object(hInternet
)))
2109 return INTERNET_INVALID_STATUS_CALLBACK
;
2111 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2113 WININET_Release( lpwh
);
2117 /***********************************************************************
2118 * InternetSetFilePointer (WININET.@)
2120 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2121 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2123 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2127 /***********************************************************************
2128 * InternetWriteFile (WININET.@)
2130 * Write data to an open internet file
2137 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2138 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2140 object_header_t
*lpwh
;
2143 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2145 lpwh
= get_handle_object( hFile
);
2147 WARN("Invalid handle\n");
2148 SetLastError(ERROR_INVALID_HANDLE
);
2152 if(lpwh
->vtbl
->WriteFile
) {
2153 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2155 WARN("No Writefile method.\n");
2156 res
= ERROR_INVALID_HANDLE
;
2159 WININET_Release( lpwh
);
2161 if(res
!= ERROR_SUCCESS
)
2163 return res
== ERROR_SUCCESS
;
2167 /***********************************************************************
2168 * InternetReadFile (WININET.@)
2170 * Read data from an open internet file
2177 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2178 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2180 object_header_t
*hdr
;
2181 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2183 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2185 hdr
= get_handle_object(hFile
);
2187 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2191 if(hdr
->vtbl
->ReadFile
)
2192 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2194 WININET_Release(hdr
);
2196 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2197 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2199 if(res
!= ERROR_SUCCESS
)
2201 return res
== ERROR_SUCCESS
;
2204 /***********************************************************************
2205 * InternetReadFileExA (WININET.@)
2207 * Read data from an open internet file
2210 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2211 * lpBuffersOut [I/O] Buffer.
2212 * dwFlags [I] Flags. See notes.
2213 * dwContext [I] Context for callbacks.
2220 * The parameter dwFlags include zero or more of the following flags:
2221 *|IRF_ASYNC - Makes the call asynchronous.
2222 *|IRF_SYNC - Makes the call synchronous.
2223 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2224 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2226 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2229 * InternetOpenUrlA(), HttpOpenRequestA()
2231 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2232 DWORD dwFlags
, DWORD_PTR dwContext
)
2234 object_header_t
*hdr
;
2235 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2237 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2239 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2240 SetLastError(ERROR_INVALID_PARAMETER
);
2244 hdr
= get_handle_object(hFile
);
2246 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2250 if(hdr
->vtbl
->ReadFileEx
)
2251 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2252 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2254 WININET_Release(hdr
);
2256 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2257 res
, lpBuffersOut
->dwBufferLength
);
2259 if(res
!= ERROR_SUCCESS
)
2261 return res
== ERROR_SUCCESS
;
2264 /***********************************************************************
2265 * InternetReadFileExW (WININET.@)
2267 * InternetReadFileExA()
2269 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2270 DWORD dwFlags
, DWORD_PTR dwContext
)
2272 object_header_t
*hdr
;
2273 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2275 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2277 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2278 SetLastError(ERROR_INVALID_PARAMETER
);
2282 hdr
= get_handle_object(hFile
);
2284 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2288 if(hdr
->vtbl
->ReadFileEx
)
2289 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2290 dwFlags
, dwContext
);
2292 WININET_Release(hdr
);
2294 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2295 res
, lpBuffer
->dwBufferLength
);
2297 if(res
!= ERROR_SUCCESS
)
2299 return res
== ERROR_SUCCESS
;
2302 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2304 /* FIXME: This function currently handles more options than it should. Options requiring
2305 * proper handles should be moved to proper functions */
2307 case INTERNET_OPTION_HTTP_VERSION
:
2308 if (*size
< sizeof(HTTP_VERSION_INFO
))
2309 return ERROR_INSUFFICIENT_BUFFER
;
2312 * Presently hardcoded to 1.1
2314 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2315 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2316 *size
= sizeof(HTTP_VERSION_INFO
);
2318 return ERROR_SUCCESS
;
2320 case INTERNET_OPTION_CONNECTED_STATE
:
2321 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2323 if (*size
< sizeof(ULONG
))
2324 return ERROR_INSUFFICIENT_BUFFER
;
2326 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2327 *size
= sizeof(ULONG
);
2329 return ERROR_SUCCESS
;
2331 case INTERNET_OPTION_PROXY
: {
2335 TRACE("Getting global proxy info\n");
2336 memset(&ai
, 0, sizeof(appinfo_t
));
2337 INTERNET_ConfigureProxy(&ai
);
2339 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2340 APPINFO_Destroy(&ai
.hdr
);
2344 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2345 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2347 if (*size
< sizeof(ULONG
))
2348 return ERROR_INSUFFICIENT_BUFFER
;
2350 *(ULONG
*)buffer
= max_conns
;
2351 *size
= sizeof(ULONG
);
2353 return ERROR_SUCCESS
;
2355 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2356 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2358 if (*size
< sizeof(ULONG
))
2359 return ERROR_INSUFFICIENT_BUFFER
;
2361 *(ULONG
*)buffer
= max_1_0_conns
;
2362 *size
= sizeof(ULONG
);
2364 return ERROR_SUCCESS
;
2366 case INTERNET_OPTION_SECURITY_FLAGS
:
2367 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2368 return ERROR_SUCCESS
;
2370 case INTERNET_OPTION_VERSION
: {
2371 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2373 TRACE("INTERNET_OPTION_VERSION\n");
2375 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2376 return ERROR_INSUFFICIENT_BUFFER
;
2378 memcpy(buffer
, &info
, sizeof(info
));
2379 *size
= sizeof(info
);
2381 return ERROR_SUCCESS
;
2384 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2385 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2386 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2387 DWORD res
= ERROR_SUCCESS
, i
;
2391 TRACE("Getting global proxy info\n");
2392 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2395 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2397 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2399 return ERROR_INSUFFICIENT_BUFFER
;
2402 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2403 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2404 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2406 switch (optionW
->dwOption
) {
2407 case INTERNET_PER_CONN_FLAGS
:
2409 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2411 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2414 case INTERNET_PER_CONN_PROXY_SERVER
:
2416 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2418 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2421 case INTERNET_PER_CONN_PROXY_BYPASS
:
2423 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2425 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2428 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2429 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2430 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2431 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2432 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2433 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2434 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2435 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2439 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2440 res
= ERROR_INVALID_PARAMETER
;
2448 case INTERNET_OPTION_REQUEST_FLAGS
:
2449 case INTERNET_OPTION_USER_AGENT
:
2451 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2452 case INTERNET_OPTION_POLICY
:
2453 return ERROR_INVALID_PARAMETER
;
2454 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2455 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2457 if (*size
< sizeof(ULONG
))
2458 return ERROR_INSUFFICIENT_BUFFER
;
2460 *(ULONG
*)buffer
= connect_timeout
;
2461 *size
= sizeof(ULONG
);
2463 return ERROR_SUCCESS
;
2466 FIXME("Stub for %d\n", option
);
2467 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2470 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2473 case INTERNET_OPTION_CONTEXT_VALUE
:
2475 return ERROR_INVALID_PARAMETER
;
2477 if (*size
< sizeof(DWORD_PTR
)) {
2478 *size
= sizeof(DWORD_PTR
);
2479 return ERROR_INSUFFICIENT_BUFFER
;
2482 return ERROR_INVALID_PARAMETER
;
2484 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2485 *size
= sizeof(DWORD_PTR
);
2486 return ERROR_SUCCESS
;
2488 case INTERNET_OPTION_REQUEST_FLAGS
:
2489 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2490 *size
= sizeof(DWORD
);
2491 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2493 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2494 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2495 WARN("Called on global option %u\n", option
);
2496 return ERROR_INTERNET_INVALID_OPERATION
;
2499 /* FIXME: we shouldn't call it here */
2500 return query_global_option(option
, buffer
, size
, unicode
);
2503 /***********************************************************************
2504 * InternetQueryOptionW (WININET.@)
2506 * Queries an options on the specified handle
2513 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2514 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2516 object_header_t
*hdr
;
2517 DWORD res
= ERROR_INVALID_HANDLE
;
2519 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2522 hdr
= get_handle_object(hInternet
);
2524 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2525 WININET_Release(hdr
);
2528 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2531 if(res
!= ERROR_SUCCESS
)
2533 return res
== ERROR_SUCCESS
;
2536 /***********************************************************************
2537 * InternetQueryOptionA (WININET.@)
2539 * Queries an options on the specified handle
2546 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2547 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2549 object_header_t
*hdr
;
2550 DWORD res
= ERROR_INVALID_HANDLE
;
2552 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2555 hdr
= get_handle_object(hInternet
);
2557 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2558 WININET_Release(hdr
);
2561 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2564 if(res
!= ERROR_SUCCESS
)
2566 return res
== ERROR_SUCCESS
;
2569 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2572 case INTERNET_OPTION_CALLBACK
:
2573 WARN("Not settable option %u\n", option
);
2574 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2575 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2576 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2577 WARN("Called on global option %u\n", option
);
2578 return ERROR_INTERNET_INVALID_OPERATION
;
2581 return ERROR_INTERNET_INVALID_OPTION
;
2584 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2587 case INTERNET_OPTION_CALLBACK
:
2588 WARN("Not global option %u\n", option
);
2589 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2591 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2592 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2594 if(size
!= sizeof(max_conns
))
2595 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2597 return ERROR_BAD_ARGUMENTS
;
2599 max_conns
= *(ULONG
*)buf
;
2600 return ERROR_SUCCESS
;
2602 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2603 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2605 if(size
!= sizeof(max_1_0_conns
))
2606 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2608 return ERROR_BAD_ARGUMENTS
;
2610 max_1_0_conns
= *(ULONG
*)buf
;
2611 return ERROR_SUCCESS
;
2613 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2614 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2616 if(size
!= sizeof(connect_timeout
))
2617 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2619 return ERROR_BAD_ARGUMENTS
;
2621 connect_timeout
= *(ULONG
*)buf
;
2622 return ERROR_SUCCESS
;
2624 case INTERNET_OPTION_SETTINGS_CHANGED
:
2625 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2626 collect_connections(COLLECT_CONNECTIONS
);
2627 return ERROR_SUCCESS
;
2630 return ERROR_INTERNET_INVALID_OPTION
;
2633 /***********************************************************************
2634 * InternetSetOptionW (WININET.@)
2636 * Sets an options on the specified handle
2643 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2644 LPVOID lpBuffer
, DWORD dwBufferLength
)
2646 object_header_t
*lpwhh
;
2650 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2652 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2654 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2656 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2658 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2660 WININET_Release(lpwhh
);
2662 if(res
!= ERROR_SUCCESS
)
2665 return res
== ERROR_SUCCESS
;
2670 case INTERNET_OPTION_HTTP_VERSION
:
2672 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2673 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2676 case INTERNET_OPTION_ERROR_MASK
:
2679 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2681 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2682 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2683 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2684 SetLastError(ERROR_INVALID_PARAMETER
);
2686 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2687 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2690 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2691 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2694 case INTERNET_OPTION_PROXY
:
2696 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2698 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2700 SetLastError(ERROR_INVALID_PARAMETER
);
2705 EnterCriticalSection( &WININET_cs
);
2706 free_global_proxy();
2707 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2710 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2712 global_proxy
->proxyEnabled
= 1;
2713 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2714 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2718 global_proxy
->proxyEnabled
= 0;
2719 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2722 LeaveCriticalSection( &WININET_cs
);
2726 /* In general, each type of object should handle
2727 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2728 * get silently dropped.
2730 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2731 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2736 case INTERNET_OPTION_CODEPAGE
:
2738 ULONG codepage
= *(ULONG
*)lpBuffer
;
2739 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2742 case INTERNET_OPTION_REQUEST_PRIORITY
:
2744 ULONG priority
= *(ULONG
*)lpBuffer
;
2745 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2748 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2750 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2751 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2754 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2756 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2757 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2760 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2761 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2763 case INTERNET_OPTION_END_BROWSER_SESSION
:
2764 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2766 case INTERNET_OPTION_CONNECTED_STATE
:
2767 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2769 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2770 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2772 case INTERNET_OPTION_SEND_TIMEOUT
:
2773 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2774 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2776 ULONG timeout
= *(ULONG
*)lpBuffer
;
2777 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2780 case INTERNET_OPTION_CONNECT_RETRIES
:
2782 ULONG retries
= *(ULONG
*)lpBuffer
;
2783 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2786 case INTERNET_OPTION_CONTEXT_VALUE
:
2790 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2793 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2795 SetLastError(ERROR_INVALID_PARAMETER
);
2799 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2802 case INTERNET_OPTION_SECURITY_FLAGS
:
2803 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2805 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2806 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2808 case INTERNET_OPTION_HTTP_DECODING
:
2809 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2810 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2813 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2814 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2815 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2818 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2819 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2820 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2823 case INTERNET_OPTION_CODEPAGE_PATH
:
2824 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2825 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2828 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2829 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2830 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2833 case INTERNET_OPTION_IDN
:
2834 FIXME("INTERNET_OPTION_IDN; STUB\n");
2835 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2838 case INTERNET_OPTION_POLICY
:
2839 SetLastError(ERROR_INVALID_PARAMETER
);
2842 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2843 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2848 INTERNET_LoadProxySettings(&pi
);
2850 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2851 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2853 switch (option
->dwOption
) {
2854 case INTERNET_PER_CONN_PROXY_SERVER
:
2855 heap_free(pi
.proxy
);
2856 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2859 case INTERNET_PER_CONN_FLAGS
:
2860 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2861 pi
.proxyEnabled
= 1;
2864 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2865 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2866 pi
.proxyEnabled
= 0;
2870 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2871 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2872 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2873 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2874 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2875 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2876 case INTERNET_PER_CONN_PROXY_BYPASS
:
2877 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2881 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2882 SetLastError(ERROR_INVALID_PARAMETER
);
2887 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2892 ret
= (res
== ERROR_SUCCESS
);
2896 FIXME("Option %d STUB\n",dwOption
);
2897 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2903 WININET_Release( lpwhh
);
2909 /***********************************************************************
2910 * InternetSetOptionA (WININET.@)
2912 * Sets an options on the specified handle.
2919 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2920 LPVOID lpBuffer
, DWORD dwBufferLength
)
2928 case INTERNET_OPTION_PROXY
:
2930 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2931 LPINTERNET_PROXY_INFOW piw
;
2932 DWORD proxlen
, prbylen
;
2935 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2936 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2937 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2938 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2939 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2940 piw
->dwAccessType
= pi
->dwAccessType
;
2941 prox
= (LPWSTR
) &piw
[1];
2942 prby
= &prox
[proxlen
+1];
2943 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2944 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2945 piw
->lpszProxy
= prox
;
2946 piw
->lpszProxyBypass
= prby
;
2949 case INTERNET_OPTION_USER_AGENT
:
2950 case INTERNET_OPTION_USERNAME
:
2951 case INTERNET_OPTION_PASSWORD
:
2952 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2954 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2955 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2958 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2960 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
2961 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
2962 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2963 wbuffer
= heap_alloc(wlen
);
2966 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2967 if (listA
->pszConnection
)
2969 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
2970 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
2971 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
2974 listW
->pszConnection
= NULL
;
2975 listW
->dwOptionCount
= listA
->dwOptionCount
;
2976 listW
->dwOptionError
= listA
->dwOptionError
;
2977 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
2979 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
2980 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
2981 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
2983 optW
->dwOption
= optA
->dwOption
;
2985 switch (optA
->dwOption
) {
2986 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2987 case INTERNET_PER_CONN_PROXY_BYPASS
:
2988 case INTERNET_PER_CONN_PROXY_SERVER
:
2989 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2990 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2991 if (optA
->Value
.pszValue
)
2993 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
2994 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
2995 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
2998 optW
->Value
.pszValue
= NULL
;
3000 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3001 case INTERNET_PER_CONN_FLAGS
:
3002 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3003 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3005 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3006 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3009 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3010 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3018 wlen
= dwBufferLength
;
3021 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3023 if( lpBuffer
!= wbuffer
)
3025 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3027 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3029 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3030 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3031 switch (opt
->dwOption
) {
3032 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3033 case INTERNET_PER_CONN_PROXY_BYPASS
:
3034 case INTERNET_PER_CONN_PROXY_SERVER
:
3035 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3036 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3037 heap_free( opt
->Value
.pszValue
);
3043 heap_free( list
->pOptions
);
3045 heap_free( wbuffer
);
3052 /***********************************************************************
3053 * InternetSetOptionExA (WININET.@)
3055 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3056 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3058 FIXME("Flags %08x ignored\n", dwFlags
);
3059 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3062 /***********************************************************************
3063 * InternetSetOptionExW (WININET.@)
3065 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3066 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3068 FIXME("Flags %08x ignored\n", dwFlags
);
3069 if( dwFlags
& ~ISO_VALID_FLAGS
)
3071 SetLastError( ERROR_INVALID_PARAMETER
);
3074 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3077 static const WCHAR WININET_wkday
[7][4] =
3078 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3079 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3080 static const WCHAR WININET_month
[12][4] =
3081 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3082 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3083 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3085 /***********************************************************************
3086 * InternetTimeFromSystemTimeA (WININET.@)
3088 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3091 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3093 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3095 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3097 SetLastError(ERROR_INVALID_PARAMETER
);
3101 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3103 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3107 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3108 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3113 /***********************************************************************
3114 * InternetTimeFromSystemTimeW (WININET.@)
3116 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3118 static const WCHAR date
[] =
3119 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3120 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3122 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3124 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3126 SetLastError(ERROR_INVALID_PARAMETER
);
3130 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3132 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3136 sprintfW( string
, date
,
3137 WININET_wkday
[time
->wDayOfWeek
],
3139 WININET_month
[time
->wMonth
- 1],
3148 /***********************************************************************
3149 * InternetTimeToSystemTimeA (WININET.@)
3151 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3156 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3158 stringW
= heap_strdupAtoW(string
);
3161 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3162 heap_free( stringW
);
3167 /***********************************************************************
3168 * InternetTimeToSystemTimeW (WININET.@)
3170 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3173 const WCHAR
*s
= string
;
3176 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3178 if (!string
|| !time
) return FALSE
;
3180 /* Windows does this too */
3181 GetSystemTime( time
);
3183 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3184 * a SYSTEMTIME structure.
3187 while (*s
&& !isalphaW( *s
)) s
++;
3188 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3189 time
->wDayOfWeek
= 7;
3191 for (i
= 0; i
< 7; i
++)
3193 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3194 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3195 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3197 time
->wDayOfWeek
= i
;
3202 if (time
->wDayOfWeek
> 6) return TRUE
;
3203 while (*s
&& !isdigitW( *s
)) s
++;
3204 time
->wDay
= strtolW( s
, &end
, 10 );
3207 while (*s
&& !isalphaW( *s
)) s
++;
3208 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3211 for (i
= 0; i
< 12; i
++)
3213 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3214 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3215 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3217 time
->wMonth
= i
+ 1;
3221 if (time
->wMonth
== 0) return TRUE
;
3223 while (*s
&& !isdigitW( *s
)) s
++;
3224 if (*s
== '\0') return TRUE
;
3225 time
->wYear
= strtolW( s
, &end
, 10 );
3228 while (*s
&& !isdigitW( *s
)) s
++;
3229 if (*s
== '\0') return TRUE
;
3230 time
->wHour
= strtolW( s
, &end
, 10 );
3233 while (*s
&& !isdigitW( *s
)) s
++;
3234 if (*s
== '\0') return TRUE
;
3235 time
->wMinute
= strtolW( s
, &end
, 10 );
3238 while (*s
&& !isdigitW( *s
)) s
++;
3239 if (*s
== '\0') return TRUE
;
3240 time
->wSecond
= strtolW( s
, &end
, 10 );
3243 time
->wMilliseconds
= 0;
3247 /***********************************************************************
3248 * InternetCheckConnectionW (WININET.@)
3250 * Pings a requested host to check internet connection
3253 * TRUE on success and FALSE on failure. If a failure then
3254 * ERROR_NOT_CONNECTED is placed into GetLastError
3257 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3260 * this is a kludge which runs the resident ping program and reads the output.
3262 * Anyone have a better idea?
3266 static const CHAR ping
[] = "ping -c 1 ";
3267 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3268 CHAR
*command
= NULL
;
3269 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3277 * Crack or set the Address
3279 if (lpszUrl
== NULL
)
3282 * According to the doc we are supposed to use the ip for the next
3283 * server in the WnInet internal server database. I have
3284 * no idea what that is or how to get it.
3286 * So someone needs to implement this.
3288 FIXME("Unimplemented with URL of NULL\n");
3293 URL_COMPONENTSW components
;
3295 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3296 components
.lpszHostName
= (LPWSTR
)hostW
;
3297 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3299 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3302 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3303 port
= components
.nPort
;
3304 TRACE("port: %d\n", port
);
3307 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3309 struct sockaddr_storage saddr
;
3310 socklen_t sa_len
= sizeof(saddr
);
3313 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3315 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3318 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3326 * Build our ping command
3328 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3329 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3330 strcpy(command
,ping
);
3331 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3332 strcat(command
,redirect
);
3334 TRACE("Ping command is : %s\n",command
);
3336 status
= system(command
);
3338 TRACE("Ping returned a code of %i\n",status
);
3340 /* Ping return code of 0 indicates success */
3346 heap_free( command
);
3348 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3354 /***********************************************************************
3355 * InternetCheckConnectionA (WININET.@)
3357 * Pings a requested host to check internet connection
3360 * TRUE on success and FALSE on failure. If a failure then
3361 * ERROR_NOT_CONNECTED is placed into GetLastError
3364 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3370 url
= heap_strdupAtoW(lpszUrl
);
3375 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3382 /**********************************************************
3383 * INTERNET_InternetOpenUrlW (internal)
3388 * handle of connection or NULL on failure
3390 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3391 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3393 URL_COMPONENTSW urlComponents
;
3394 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3395 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3396 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3397 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3398 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3400 HINTERNET client
= NULL
, client1
= NULL
;
3403 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3404 dwHeadersLength
, dwFlags
, dwContext
);
3406 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3407 urlComponents
.lpszScheme
= protocol
;
3408 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3409 urlComponents
.lpszHostName
= hostName
;
3410 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3411 urlComponents
.lpszUserName
= userName
;
3412 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3413 urlComponents
.lpszPassword
= password
;
3414 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3415 urlComponents
.lpszUrlPath
= path
;
3416 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3417 urlComponents
.lpszExtraInfo
= extra
;
3418 urlComponents
.dwExtraInfoLength
= 1024;
3419 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3421 switch(urlComponents
.nScheme
) {
3422 case INTERNET_SCHEME_FTP
:
3423 if(urlComponents
.nPort
== 0)
3424 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3425 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3426 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3429 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3430 if(client1
== NULL
) {
3431 InternetCloseHandle(client
);
3436 case INTERNET_SCHEME_HTTP
:
3437 case INTERNET_SCHEME_HTTPS
: {
3438 static const WCHAR szStars
[] = { '*','/','*', 0 };
3439 LPCWSTR accept
[2] = { szStars
, NULL
};
3440 if(urlComponents
.nPort
== 0) {
3441 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3442 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3444 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3446 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3448 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3449 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3450 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3451 if(res
!= ERROR_SUCCESS
) {
3452 INTERNET_SetLastError(res
);
3456 if (urlComponents
.dwExtraInfoLength
) {
3458 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3460 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3462 InternetCloseHandle(client
);
3465 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3466 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3467 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3468 heap_free(path_extra
);
3471 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3473 if(client1
== NULL
) {
3474 InternetCloseHandle(client
);
3477 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3478 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3479 GetLastError() != ERROR_IO_PENDING
) {
3480 InternetCloseHandle(client1
);
3485 case INTERNET_SCHEME_GOPHER
:
3486 /* gopher doesn't seem to be implemented in wine, but it's supposed
3487 * to be supported by InternetOpenUrlA. */
3489 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3493 TRACE(" %p <--\n", client1
);
3498 /**********************************************************
3499 * InternetOpenUrlW (WININET.@)
3504 * handle of connection or NULL on failure
3506 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3508 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3509 appinfo_t
*hIC
= (appinfo_t
*) workRequest
->hdr
;
3513 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3514 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3515 heap_free(req
->lpszUrl
);
3516 heap_free(req
->lpszHeaders
);
3519 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3520 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3522 HINTERNET ret
= NULL
;
3523 appinfo_t
*hIC
= NULL
;
3525 if (TRACE_ON(wininet
)) {
3526 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3527 dwHeadersLength
, dwFlags
, dwContext
);
3529 dump_INTERNET_FLAGS(dwFlags
);
3534 SetLastError(ERROR_INVALID_PARAMETER
);
3538 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3539 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3540 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3544 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3545 WORKREQUEST workRequest
;
3546 struct WORKREQ_INTERNETOPENURLW
*req
;
3548 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3549 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3550 req
= &workRequest
.u
.InternetOpenUrlW
;
3551 req
->lpszUrl
= heap_strdupW(lpszUrl
);
3552 req
->lpszHeaders
= heap_strdupW(lpszHeaders
);
3553 req
->dwHeadersLength
= dwHeadersLength
;
3554 req
->dwFlags
= dwFlags
;
3555 req
->dwContext
= dwContext
;
3557 INTERNET_AsyncCall(&workRequest
);
3559 * This is from windows.
3561 SetLastError(ERROR_IO_PENDING
);
3563 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3568 WININET_Release( &hIC
->hdr
);
3569 TRACE(" %p <--\n", ret
);
3574 /**********************************************************
3575 * InternetOpenUrlA (WININET.@)
3580 * handle of connection or NULL on failure
3582 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3583 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3585 HINTERNET rc
= NULL
;
3586 DWORD lenHeaders
= 0;
3587 LPWSTR szUrl
= NULL
;
3588 LPWSTR szHeaders
= NULL
;
3593 szUrl
= heap_strdupAtoW(lpszUrl
);
3599 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3600 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3605 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3608 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3609 lenHeaders
, dwFlags
, dwContext
);
3612 heap_free(szHeaders
);
3617 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3619 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3623 lpwite
->dwError
= 0;
3624 lpwite
->response
[0] = '\0';
3627 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3636 /***********************************************************************
3637 * INTERNET_SetLastError (internal)
3639 * Set last thread specific error
3644 void INTERNET_SetLastError(DWORD dwError
)
3646 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3649 lpwite
= INTERNET_AllocThreadError();
3651 SetLastError(dwError
);
3653 lpwite
->dwError
= dwError
;
3657 /***********************************************************************
3658 * INTERNET_GetLastError (internal)
3660 * Get last thread specific error
3665 DWORD
INTERNET_GetLastError(void)
3667 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3668 if (!lpwite
) return 0;
3669 /* TlsGetValue clears last error, so set it again here */
3670 SetLastError(lpwite
->dwError
);
3671 return lpwite
->dwError
;
3675 /***********************************************************************
3676 * INTERNET_WorkerThreadFunc (internal)
3678 * Worker thread execution function
3683 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3685 LPWORKREQUEST lpRequest
= lpvParam
;
3686 WORKREQUEST workRequest
;
3690 workRequest
= *lpRequest
;
3691 heap_free(lpRequest
);
3693 workRequest
.asyncproc(&workRequest
);
3694 WININET_Release( workRequest
.hdr
);
3696 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3698 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3699 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3705 /***********************************************************************
3706 * INTERNET_AsyncCall (internal)
3708 * Retrieves work request from queue
3713 DWORD
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3716 LPWORKREQUEST lpNewRequest
;
3720 lpNewRequest
= heap_alloc(sizeof(WORKREQUEST
));
3722 return ERROR_OUTOFMEMORY
;
3724 *lpNewRequest
= *lpWorkRequest
;
3726 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3729 heap_free(lpNewRequest
);
3730 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3732 return ERROR_SUCCESS
;
3736 /***********************************************************************
3737 * INTERNET_GetResponseBuffer (internal)
3742 LPSTR
INTERNET_GetResponseBuffer(void)
3744 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3746 lpwite
= INTERNET_AllocThreadError();
3748 return lpwite
->response
;
3751 /***********************************************************************
3752 * INTERNET_GetNextLine (internal)
3754 * Parse next line in directory string listing
3757 * Pointer to beginning of next line
3762 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3765 BOOL bSuccess
= FALSE
;
3767 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3772 pfd
.events
= POLLIN
;
3774 while (nRecv
< MAX_REPLY_LEN
)
3776 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3778 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3780 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3784 if (lpszBuffer
[nRecv
] == '\n')
3789 if (lpszBuffer
[nRecv
] != '\r')
3794 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3802 lpszBuffer
[nRecv
] = '\0';
3804 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3813 /**********************************************************
3814 * InternetQueryDataAvailable (WININET.@)
3816 * Determines how much data is available to be read.
3819 * TRUE on success, FALSE if an error occurred. If
3820 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3821 * no data is presently available, FALSE is returned with
3822 * the last error ERROR_IO_PENDING; a callback with status
3823 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3824 * data is available.
3826 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3827 LPDWORD lpdwNumberOfBytesAvailable
,
3828 DWORD dwFlags
, DWORD_PTR dwContext
)
3830 object_header_t
*hdr
;
3833 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3835 hdr
= get_handle_object( hFile
);
3837 SetLastError(ERROR_INVALID_HANDLE
);
3841 if(hdr
->vtbl
->QueryDataAvailable
) {
3842 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3844 WARN("wrong handle\n");
3845 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3848 WININET_Release(hdr
);
3850 if(res
!= ERROR_SUCCESS
)
3852 return res
== ERROR_SUCCESS
;
3856 /***********************************************************************
3857 * InternetLockRequestFile (WININET.@)
3859 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3866 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3873 /***********************************************************************
3874 * InternetAutodial (WININET.@)
3876 * On windows this function is supposed to dial the default internet
3877 * connection. We don't want to have Wine dial out to the internet so
3878 * we return TRUE by default. It might be nice to check if we are connected.
3885 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3889 /* Tell that we are connected to the internet. */
3893 /***********************************************************************
3894 * InternetAutodialHangup (WININET.@)
3896 * Hangs up a connection made with InternetAutodial
3905 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3909 /* we didn't dial, we don't disconnect */
3913 /***********************************************************************
3914 * InternetCombineUrlA (WININET.@)
3916 * Combine a base URL with a relative URL
3924 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3925 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3930 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3932 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3933 dwFlags
^= ICU_NO_ENCODE
;
3934 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3939 /***********************************************************************
3940 * InternetCombineUrlW (WININET.@)
3942 * Combine a base URL with a relative URL
3950 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3951 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3956 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3958 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3959 dwFlags
^= ICU_NO_ENCODE
;
3960 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3965 /* max port num is 65535 => 5 digits */
3966 #define MAX_WORD_DIGITS 5
3968 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3969 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3970 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3971 (url)->dw##component##Length : strlen((url)->lpsz##component))
3973 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3975 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3976 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3978 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3979 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3981 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3982 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3984 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3985 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3988 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3994 /* opaque urls do not fit into the standard url hierarchy and don't have
3995 * two following slashes */
3996 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3998 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3999 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4000 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4001 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4002 (nScheme
!= INTERNET_SCHEME_FILE
);
4005 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4008 if (scheme
< INTERNET_SCHEME_FIRST
)
4010 index
= scheme
- INTERNET_SCHEME_FIRST
;
4011 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4013 return (LPCWSTR
)url_schemes
[index
];
4016 /* we can calculate using ansi strings because we're just
4017 * calculating string length, not size
4019 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4020 LPDWORD lpdwUrlLength
)
4022 INTERNET_SCHEME nScheme
;
4026 if (lpUrlComponents
->lpszScheme
)
4028 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4029 *lpdwUrlLength
+= dwLen
;
4030 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4036 nScheme
= lpUrlComponents
->nScheme
;
4038 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4039 nScheme
= INTERNET_SCHEME_HTTP
;
4040 scheme
= INTERNET_GetSchemeString(nScheme
);
4041 *lpdwUrlLength
+= strlenW(scheme
);
4044 (*lpdwUrlLength
)++; /* ':' */
4045 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4046 *lpdwUrlLength
+= strlen("//");
4048 if (lpUrlComponents
->lpszUserName
)
4050 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4051 *lpdwUrlLength
+= strlen("@");
4055 if (lpUrlComponents
->lpszPassword
)
4057 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4062 if (lpUrlComponents
->lpszPassword
)
4064 *lpdwUrlLength
+= strlen(":");
4065 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4068 if (lpUrlComponents
->lpszHostName
)
4070 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4072 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4074 char szPort
[MAX_WORD_DIGITS
+1];
4076 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4077 *lpdwUrlLength
+= strlen(szPort
);
4078 *lpdwUrlLength
+= strlen(":");
4081 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4082 (*lpdwUrlLength
)++; /* '/' */
4085 if (lpUrlComponents
->lpszUrlPath
)
4086 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4088 if (lpUrlComponents
->lpszExtraInfo
)
4089 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4094 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4098 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4100 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4101 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4102 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4103 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4104 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4105 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4106 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4107 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4108 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4110 if (lpUrlComponents
->lpszScheme
)
4112 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4113 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4114 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4115 -1, urlCompW
->lpszScheme
, len
);
4118 if (lpUrlComponents
->lpszHostName
)
4120 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4121 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4122 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4123 -1, urlCompW
->lpszHostName
, len
);
4126 if (lpUrlComponents
->lpszUserName
)
4128 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4129 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4130 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4131 -1, urlCompW
->lpszUserName
, len
);
4134 if (lpUrlComponents
->lpszPassword
)
4136 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4137 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4138 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4139 -1, urlCompW
->lpszPassword
, len
);
4142 if (lpUrlComponents
->lpszUrlPath
)
4144 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4145 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4146 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4147 -1, urlCompW
->lpszUrlPath
, len
);
4150 if (lpUrlComponents
->lpszExtraInfo
)
4152 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4153 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4154 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4155 -1, urlCompW
->lpszExtraInfo
, len
);
4159 /***********************************************************************
4160 * InternetCreateUrlA (WININET.@)
4162 * See InternetCreateUrlW.
4164 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4165 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4169 URL_COMPONENTSW urlCompW
;
4171 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4173 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4175 SetLastError(ERROR_INVALID_PARAMETER
);
4179 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4182 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4184 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4186 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4187 *lpdwUrlLength
/= sizeof(WCHAR
);
4189 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4190 * minus one, so add one to leave room for NULL terminator
4193 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4195 heap_free(urlCompW
.lpszScheme
);
4196 heap_free(urlCompW
.lpszHostName
);
4197 heap_free(urlCompW
.lpszUserName
);
4198 heap_free(urlCompW
.lpszPassword
);
4199 heap_free(urlCompW
.lpszUrlPath
);
4200 heap_free(urlCompW
.lpszExtraInfo
);
4205 /***********************************************************************
4206 * InternetCreateUrlW (WININET.@)
4208 * Creates a URL from its component parts.
4211 * lpUrlComponents [I] URL Components.
4212 * dwFlags [I] Flags. See notes.
4213 * lpszUrl [I] Buffer in which to store the created URL.
4214 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4215 * lpszUrl in characters. On output, the number of bytes
4216 * required to store the URL including terminator.
4220 * The dwFlags parameter can be zero or more of the following:
4221 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4228 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4229 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4232 INTERNET_SCHEME nScheme
;
4234 static const WCHAR slashSlashW
[] = {'/','/'};
4235 static const WCHAR fmtW
[] = {'%','u',0};
4237 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4239 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4241 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4245 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4248 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4250 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4251 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4255 *lpdwUrlLength
= dwLen
;
4260 if (lpUrlComponents
->lpszScheme
)
4262 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4263 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4266 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4271 nScheme
= lpUrlComponents
->nScheme
;
4273 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4274 nScheme
= INTERNET_SCHEME_HTTP
;
4276 scheme
= INTERNET_GetSchemeString(nScheme
);
4277 dwLen
= strlenW(scheme
);
4278 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4282 /* all schemes are followed by at least a colon */
4286 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4288 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4289 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4292 if (lpUrlComponents
->lpszUserName
)
4294 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4295 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4298 if (lpUrlComponents
->lpszPassword
)
4303 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4304 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4312 if (lpUrlComponents
->lpszHostName
)
4314 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4315 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4318 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4320 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4322 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4325 dwLen
= strlenW(szPort
);
4326 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4330 /* add slash between hostname and path if necessary */
4331 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4338 if (lpUrlComponents
->lpszUrlPath
)
4340 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4341 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4345 if (lpUrlComponents
->lpszExtraInfo
)
4347 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4348 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4357 /***********************************************************************
4358 * InternetConfirmZoneCrossingA (WININET.@)
4361 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4363 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4364 return ERROR_SUCCESS
;
4367 /***********************************************************************
4368 * InternetConfirmZoneCrossingW (WININET.@)
4371 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4373 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4374 return ERROR_SUCCESS
;
4377 static DWORD zone_preference
= 3;
4379 /***********************************************************************
4380 * PrivacySetZonePreferenceW (WININET.@)
4382 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4384 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4386 zone_preference
= template;
4390 /***********************************************************************
4391 * PrivacyGetZonePreferenceW (WININET.@)
4393 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4394 LPWSTR preference
, LPDWORD length
)
4396 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4398 if (template) *template = zone_preference
;
4402 /***********************************************************************
4403 * InternetGetSecurityInfoByURLA (WININET.@)
4405 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4410 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4412 url
= heap_strdupAtoW(lpszURL
);
4416 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4421 /***********************************************************************
4422 * InternetGetSecurityInfoByURLW (WININET.@)
4424 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4426 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4427 URL_COMPONENTSW url
= {sizeof(url
)};
4431 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4433 url
.lpszHostName
= hostname
;
4434 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4436 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4437 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4438 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4442 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4444 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4448 if(server
->cert_chain
) {
4449 const CERT_CHAIN_CONTEXT
*chain_dup
;
4451 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4453 *ppCertChain
= chain_dup
;
4454 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4459 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4463 server_release(server
);
4467 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4468 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4470 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4471 lpdwConnection
, dwReserved
);
4472 return ERROR_SUCCESS
;
4475 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4476 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4478 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4479 lpdwConnection
, dwReserved
);
4480 return ERROR_SUCCESS
;
4483 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4485 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4489 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4491 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4495 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4497 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4498 return ERROR_SUCCESS
;
4501 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4504 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4505 debugstr_w(pwszTarget
), pbHexHash
);
4509 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4511 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4515 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4517 FIXME("(%p, %08lx) stub\n", a
, b
);
4521 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4523 FIXME("%p: stub\n", parent
);