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 (!(equal
= 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
= {
935 /***********************************************************************
936 * InternetOpenW (WININET.@)
938 * Per-application initialization of wininet
941 * HINTERNET on success
945 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
946 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
948 appinfo_t
*lpwai
= NULL
;
950 if (TRACE_ON(wininet
)) {
951 #define FE(x) { x, #x }
952 static const wininet_flag_info access_type
[] = {
953 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
954 FE(INTERNET_OPEN_TYPE_DIRECT
),
955 FE(INTERNET_OPEN_TYPE_PROXY
),
956 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
960 const char *access_type_str
= "Unknown";
962 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
963 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
964 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
965 if (access_type
[i
].val
== dwAccessType
) {
966 access_type_str
= access_type
[i
].name
;
970 TRACE(" access type : %s\n", access_type_str
);
972 dump_INTERNET_FLAGS(dwFlags
);
975 /* Clear any error information */
976 INTERNET_SetLastError(0);
978 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
980 SetLastError(ERROR_OUTOFMEMORY
);
984 lpwai
->hdr
.htype
= WH_HINIT
;
985 lpwai
->hdr
.dwFlags
= dwFlags
;
986 lpwai
->accessType
= dwAccessType
;
987 lpwai
->proxyUsername
= NULL
;
988 lpwai
->proxyPassword
= NULL
;
989 lpwai
->connect_timeout
= connect_timeout
;
991 lpwai
->agent
= heap_strdupW(lpszAgent
);
992 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
993 INTERNET_ConfigureProxy( lpwai
);
995 lpwai
->proxy
= heap_strdupW(lpszProxy
);
996 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
998 TRACE("returning %p\n", lpwai
);
1000 return lpwai
->hdr
.hInternet
;
1004 /***********************************************************************
1005 * InternetOpenA (WININET.@)
1007 * Per-application initialization of wininet
1010 * HINTERNET on success
1014 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1015 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1017 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1020 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1021 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1023 szAgent
= heap_strdupAtoW(lpszAgent
);
1024 szProxy
= heap_strdupAtoW(lpszProxy
);
1025 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1027 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1031 heap_free(szBypass
);
1035 /***********************************************************************
1036 * InternetGetLastResponseInfoA (WININET.@)
1038 * Return last wininet error description on the calling thread
1041 * TRUE on success of writing to buffer
1045 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1046 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1048 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1054 *lpdwError
= lpwite
->dwError
;
1055 if (lpwite
->dwError
)
1057 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1058 *lpdwBufferLength
= strlen(lpszBuffer
);
1061 *lpdwBufferLength
= 0;
1066 *lpdwBufferLength
= 0;
1072 /***********************************************************************
1073 * InternetGetLastResponseInfoW (WININET.@)
1075 * Return last wininet error description on the calling thread
1078 * TRUE on success of writing to buffer
1082 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1083 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1085 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1091 *lpdwError
= lpwite
->dwError
;
1092 if (lpwite
->dwError
)
1094 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1095 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1098 *lpdwBufferLength
= 0;
1103 *lpdwBufferLength
= 0;
1109 /***********************************************************************
1110 * InternetGetConnectedState (WININET.@)
1112 * Return connected state
1116 * if lpdwStatus is not null, return the status (off line,
1117 * modem, lan...) in it.
1118 * FALSE if not connected
1120 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1122 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1125 WARN("always returning LAN connection.\n");
1126 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1132 /***********************************************************************
1133 * InternetGetConnectedStateExW (WININET.@)
1135 * Return connected state
1139 * lpdwStatus [O] Flags specifying the status of the internet connection.
1140 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1141 * dwNameLen [I] Size of the buffer, in characters.
1142 * dwReserved [I] Reserved. Must be set to 0.
1146 * if lpdwStatus is not null, return the status (off line,
1147 * modem, lan...) in it.
1148 * FALSE if not connected
1151 * If the system has no available network connections, an empty string is
1152 * stored in lpszConnectionName. If there is a LAN connection, a localized
1153 * "LAN Connection" string is stored. Presumably, if only a dial-up
1154 * connection is available then the name of the dial-up connection is
1155 * returned. Why any application, other than the "Internet Settings" CPL,
1156 * would want to use this function instead of the simpler InternetGetConnectedStateW
1157 * function is beyond me.
1159 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1160 DWORD dwNameLen
, DWORD dwReserved
)
1162 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1169 WARN("always returning LAN connection.\n");
1170 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1172 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1176 /***********************************************************************
1177 * InternetGetConnectedStateExA (WININET.@)
1179 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1180 DWORD dwNameLen
, DWORD dwReserved
)
1182 LPWSTR lpwszConnectionName
= NULL
;
1185 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1187 if (lpszConnectionName
&& dwNameLen
> 0)
1188 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1190 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1192 if (rc
&& lpwszConnectionName
)
1194 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1195 dwNameLen
, NULL
, NULL
);
1196 heap_free(lpwszConnectionName
);
1202 /***********************************************************************
1203 * InternetConnectW (WININET.@)
1205 * Open a ftp, gopher or http session
1208 * HINTERNET a session handle on success
1212 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1213 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1214 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1215 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1218 HINTERNET rc
= NULL
;
1219 DWORD res
= ERROR_SUCCESS
;
1221 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1222 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1223 dwService
, dwFlags
, dwContext
);
1225 if (!lpszServerName
)
1227 SetLastError(ERROR_INVALID_PARAMETER
);
1231 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1232 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1234 res
= ERROR_INVALID_HANDLE
;
1240 case INTERNET_SERVICE_FTP
:
1241 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1242 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1244 res
= INTERNET_GetLastError();
1247 case INTERNET_SERVICE_HTTP
:
1248 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1249 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1252 case INTERNET_SERVICE_GOPHER
:
1258 WININET_Release( &hIC
->hdr
);
1260 TRACE("returning %p\n", rc
);
1266 /***********************************************************************
1267 * InternetConnectA (WININET.@)
1269 * Open a ftp, gopher or http session
1272 * HINTERNET a session handle on success
1276 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1277 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1278 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1279 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1281 HINTERNET rc
= NULL
;
1282 LPWSTR szServerName
;
1286 szServerName
= heap_strdupAtoW(lpszServerName
);
1287 szUserName
= heap_strdupAtoW(lpszUserName
);
1288 szPassword
= heap_strdupAtoW(lpszPassword
);
1290 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1291 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1293 heap_free(szServerName
);
1294 heap_free(szUserName
);
1295 heap_free(szPassword
);
1300 /***********************************************************************
1301 * InternetFindNextFileA (WININET.@)
1303 * Continues a file search from a previous call to FindFirstFile
1310 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1313 WIN32_FIND_DATAW fd
;
1315 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1317 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1321 /***********************************************************************
1322 * InternetFindNextFileW (WININET.@)
1324 * Continues a file search from a previous call to FindFirstFile
1331 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1333 object_header_t
*hdr
;
1338 hdr
= get_handle_object(hFind
);
1340 WARN("Invalid handle\n");
1341 SetLastError(ERROR_INVALID_HANDLE
);
1345 if(hdr
->vtbl
->FindNextFileW
) {
1346 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1348 WARN("Handle doesn't support NextFile\n");
1349 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1352 WININET_Release(hdr
);
1354 if(res
!= ERROR_SUCCESS
)
1356 return res
== ERROR_SUCCESS
;
1359 /***********************************************************************
1360 * InternetCloseHandle (WININET.@)
1362 * Generic close handle function
1369 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1371 object_header_t
*obj
;
1373 TRACE("%p\n", hInternet
);
1375 obj
= get_handle_object( hInternet
);
1377 SetLastError(ERROR_INVALID_HANDLE
);
1381 invalidate_handle(obj
);
1382 WININET_Release(obj
);
1388 /***********************************************************************
1389 * ConvertUrlComponentValue (Internal)
1391 * Helper function for InternetCrackUrlA
1394 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1395 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1396 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1398 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1399 if (*dwComponentLen
!= 0)
1401 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1402 if (*lppszComponent
== NULL
)
1406 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1407 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1410 *lppszComponent
= NULL
;
1412 *dwComponentLen
= nASCIILength
;
1416 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1417 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1418 (*lppszComponent
)[ncpylen
]=0;
1419 *dwComponentLen
= ncpylen
;
1425 /***********************************************************************
1426 * InternetCrackUrlA (WININET.@)
1428 * See InternetCrackUrlW.
1430 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1431 LPURL_COMPONENTSA lpUrlComponents
)
1434 URL_COMPONENTSW UCW
;
1436 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1437 *scheme
= NULL
, *extra
= NULL
;
1439 TRACE("(%s %u %x %p)\n",
1440 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1441 dwUrlLength
, dwFlags
, lpUrlComponents
);
1443 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1444 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1446 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1452 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1454 /* if dwUrlLength=-1 then nLength includes null but length to
1455 InternetCrackUrlW should not include it */
1456 if (dwUrlLength
== -1) nLength
--;
1458 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1459 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1460 lpwszUrl
[nLength
] = '\0';
1462 memset(&UCW
,0,sizeof(UCW
));
1463 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1464 if (lpUrlComponents
->dwHostNameLength
)
1466 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1467 if (lpUrlComponents
->lpszHostName
)
1469 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1470 UCW
.lpszHostName
= hostname
;
1473 if (lpUrlComponents
->dwUserNameLength
)
1475 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1476 if (lpUrlComponents
->lpszUserName
)
1478 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1479 UCW
.lpszUserName
= username
;
1482 if (lpUrlComponents
->dwPasswordLength
)
1484 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1485 if (lpUrlComponents
->lpszPassword
)
1487 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1488 UCW
.lpszPassword
= password
;
1491 if (lpUrlComponents
->dwUrlPathLength
)
1493 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1494 if (lpUrlComponents
->lpszUrlPath
)
1496 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1497 UCW
.lpszUrlPath
= path
;
1500 if (lpUrlComponents
->dwSchemeLength
)
1502 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1503 if (lpUrlComponents
->lpszScheme
)
1505 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1506 UCW
.lpszScheme
= scheme
;
1509 if (lpUrlComponents
->dwExtraInfoLength
)
1511 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1512 if (lpUrlComponents
->lpszExtraInfo
)
1514 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1515 UCW
.lpszExtraInfo
= extra
;
1518 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1520 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1521 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1522 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1523 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1524 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1525 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1526 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1527 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1528 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1529 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1530 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1531 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1533 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1534 lpUrlComponents
->nPort
= UCW
.nPort
;
1536 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1537 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1538 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1539 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1540 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1542 heap_free(lpwszUrl
);
1543 heap_free(hostname
);
1544 heap_free(username
);
1545 heap_free(password
);
1552 static const WCHAR url_schemes
[][7] =
1555 {'g','o','p','h','e','r',0},
1556 {'h','t','t','p',0},
1557 {'h','t','t','p','s',0},
1558 {'f','i','l','e',0},
1559 {'n','e','w','s',0},
1560 {'m','a','i','l','t','o',0},
1564 /***********************************************************************
1565 * GetInternetSchemeW (internal)
1571 * INTERNET_SCHEME_UNKNOWN on failure
1574 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1578 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1580 if(lpszScheme
==NULL
)
1581 return INTERNET_SCHEME_UNKNOWN
;
1583 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1584 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1585 return INTERNET_SCHEME_FIRST
+ i
;
1587 return INTERNET_SCHEME_UNKNOWN
;
1590 /***********************************************************************
1591 * SetUrlComponentValueW (Internal)
1593 * Helper function for InternetCrackUrlW
1596 * lppszComponent [O] Holds the returned string
1597 * dwComponentLen [I] Holds the size of lppszComponent
1598 * [O] Holds the length of the string in lppszComponent without '\0'
1599 * lpszStart [I] Holds the string to copy from
1600 * len [I] Holds the length of lpszStart without '\0'
1607 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1609 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1611 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1614 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1616 if (*lppszComponent
== NULL
)
1618 *lppszComponent
= (LPWSTR
)lpszStart
;
1619 *dwComponentLen
= len
;
1623 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1624 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1625 (*lppszComponent
)[ncpylen
] = '\0';
1626 *dwComponentLen
= ncpylen
;
1633 /***********************************************************************
1634 * InternetCrackUrlW (WININET.@)
1636 * Break up URL into its components
1642 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1643 LPURL_COMPONENTSW lpUC
)
1647 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1650 LPCWSTR lpszParam
= NULL
;
1651 BOOL bIsAbsolute
= FALSE
;
1652 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1653 LPCWSTR lpszcp
= NULL
;
1654 LPWSTR lpszUrl_decode
= NULL
;
1655 DWORD dwUrlLength
= dwUrlLength_orig
;
1657 TRACE("(%s %u %x %p)\n",
1658 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1659 dwUrlLength
, dwFlags
, lpUC
);
1661 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1663 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1666 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1668 if (dwFlags
& ICU_DECODE
)
1671 DWORD len
= dwUrlLength
+ 1;
1673 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1675 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1678 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1679 url_tmp
[dwUrlLength
] = 0;
1680 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1683 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1686 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1689 lpszUrl
= lpszUrl_decode
;
1695 /* Determine if the URI is absolute. */
1696 while (lpszap
- lpszUrl
< dwUrlLength
)
1698 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1703 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1710 lpszcp
= lpszUrl
; /* Relative url */
1716 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1717 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1719 /* Parse <params> */
1720 lpszParam
= memchrW(lpszap
, ';', dwUrlLength
- (lpszap
- lpszUrl
));
1722 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1724 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1726 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1727 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1729 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1733 /* Get scheme first. */
1734 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1735 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1736 lpszUrl
, lpszcp
- lpszUrl
);
1738 /* Eat ':' in protocol. */
1741 /* double slash indicates the net_loc portion is present */
1742 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1746 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1750 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1752 lpszNetLoc
= lpszParam
;
1754 else if (!lpszNetLoc
)
1755 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1763 /* [<user>[<:password>]@]<host>[:<port>] */
1764 /* First find the user and password if they exist */
1766 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1767 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1769 /* username and password not specified. */
1770 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1771 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1773 else /* Parse out username and password */
1775 LPCWSTR lpszUser
= lpszcp
;
1776 LPCWSTR lpszPasswd
= lpszHost
;
1778 while (lpszcp
< lpszHost
)
1781 lpszPasswd
= lpszcp
;
1786 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1787 lpszUser
, lpszPasswd
- lpszUser
);
1789 if (lpszPasswd
!= lpszHost
)
1791 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1792 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1793 lpszHost
- lpszPasswd
);
1795 lpszcp
++; /* Advance to beginning of host */
1798 /* Parse <host><:port> */
1801 lpszPort
= lpszNetLoc
;
1803 /* special case for res:// URLs: there is no port here, so the host is the
1804 entire string up to the first '/' */
1805 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1807 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1808 lpszHost
, lpszPort
- lpszHost
);
1813 while (lpszcp
< lpszNetLoc
)
1821 /* If the scheme is "file" and the host is just one letter, it's not a host */
1822 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1825 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1830 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1831 lpszHost
, lpszPort
- lpszHost
);
1832 if (lpszPort
!= lpszNetLoc
)
1833 lpUC
->nPort
= atoiW(++lpszPort
);
1834 else switch (lpUC
->nScheme
)
1836 case INTERNET_SCHEME_HTTP
:
1837 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1839 case INTERNET_SCHEME_HTTPS
:
1840 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1842 case INTERNET_SCHEME_FTP
:
1843 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1845 case INTERNET_SCHEME_GOPHER
:
1846 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1857 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1858 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1859 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1864 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1865 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1866 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1867 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1870 /* Here lpszcp points to:
1872 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1873 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1875 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1879 /* Only truncate the parameter list if it's already been saved
1880 * in lpUC->lpszExtraInfo.
1882 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1883 len
= lpszParam
- lpszcp
;
1886 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1887 * newlines if necessary.
1889 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1890 if (lpsznewline
!= NULL
)
1891 len
= lpsznewline
- lpszcp
;
1893 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1895 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1896 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1898 WCHAR tmppath
[MAX_PATH
];
1902 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1907 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1908 tmppath
[len
] = '\0';
1917 /* if ends in \. or \.. append a backslash */
1918 if (tmppath
[len
- 1] == '.' &&
1919 (tmppath
[len
- 2] == '\\' ||
1920 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1922 if (len
< MAX_PATH
- 1)
1924 tmppath
[len
] = '\\';
1925 tmppath
[len
+1] = '\0';
1929 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1933 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1938 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1939 lpUC
->lpszUrlPath
[0] = 0;
1940 lpUC
->dwUrlPathLength
= 0;
1943 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1944 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1945 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1946 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1947 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1949 heap_free( lpszUrl_decode
);
1953 /***********************************************************************
1954 * InternetAttemptConnect (WININET.@)
1956 * Attempt to make a connection to the internet
1959 * ERROR_SUCCESS on success
1960 * Error value on failure
1963 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1966 return ERROR_SUCCESS
;
1970 /***********************************************************************
1971 * convert_url_canonicalization_flags
1973 * Helper for InternetCanonicalizeUrl
1976 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1979 * Flags suitable for UrlCanonicalize
1981 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
1983 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1985 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
1986 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
1987 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
1988 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
1989 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1990 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
1991 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
1996 /***********************************************************************
1997 * InternetCanonicalizeUrlA (WININET.@)
1999 * Escape unsafe characters and spaces
2006 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2007 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2011 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2012 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2014 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2015 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2016 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2017 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2022 /***********************************************************************
2023 * InternetCanonicalizeUrlW (WININET.@)
2025 * Escape unsafe characters and spaces
2032 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2033 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2037 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2038 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2040 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2041 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2042 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2043 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2048 /* #################################################### */
2050 static INTERNET_STATUS_CALLBACK
set_status_callback(
2051 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2053 INTERNET_STATUS_CALLBACK ret
;
2055 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2056 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2058 ret
= lpwh
->lpfnStatusCB
;
2059 lpwh
->lpfnStatusCB
= callback
;
2064 /***********************************************************************
2065 * InternetSetStatusCallbackA (WININET.@)
2067 * Sets up a callback function which is called as progress is made
2068 * during an operation.
2071 * Previous callback or NULL on success
2072 * INTERNET_INVALID_STATUS_CALLBACK on failure
2075 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2076 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2078 INTERNET_STATUS_CALLBACK retVal
;
2079 object_header_t
*lpwh
;
2081 TRACE("%p\n", hInternet
);
2083 if (!(lpwh
= get_handle_object(hInternet
)))
2084 return INTERNET_INVALID_STATUS_CALLBACK
;
2086 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2088 WININET_Release( lpwh
);
2092 /***********************************************************************
2093 * InternetSetStatusCallbackW (WININET.@)
2095 * Sets up a callback function which is called as progress is made
2096 * during an operation.
2099 * Previous callback or NULL on success
2100 * INTERNET_INVALID_STATUS_CALLBACK on failure
2103 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2104 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2106 INTERNET_STATUS_CALLBACK retVal
;
2107 object_header_t
*lpwh
;
2109 TRACE("%p\n", hInternet
);
2111 if (!(lpwh
= get_handle_object(hInternet
)))
2112 return INTERNET_INVALID_STATUS_CALLBACK
;
2114 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2116 WININET_Release( lpwh
);
2120 /***********************************************************************
2121 * InternetSetFilePointer (WININET.@)
2123 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2124 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2126 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2130 /***********************************************************************
2131 * InternetWriteFile (WININET.@)
2133 * Write data to an open internet file
2140 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2141 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2143 object_header_t
*lpwh
;
2146 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2148 lpwh
= get_handle_object( hFile
);
2150 WARN("Invalid handle\n");
2151 SetLastError(ERROR_INVALID_HANDLE
);
2155 if(lpwh
->vtbl
->WriteFile
) {
2156 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2158 WARN("No Writefile method.\n");
2159 res
= ERROR_INVALID_HANDLE
;
2162 WININET_Release( lpwh
);
2164 if(res
!= ERROR_SUCCESS
)
2166 return res
== ERROR_SUCCESS
;
2170 /***********************************************************************
2171 * InternetReadFile (WININET.@)
2173 * Read data from an open internet file
2180 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2181 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2183 object_header_t
*hdr
;
2184 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2186 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2188 hdr
= get_handle_object(hFile
);
2190 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2194 if(hdr
->vtbl
->ReadFile
)
2195 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2197 WININET_Release(hdr
);
2199 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2200 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2202 if(res
!= ERROR_SUCCESS
)
2204 return res
== ERROR_SUCCESS
;
2207 /***********************************************************************
2208 * InternetReadFileExA (WININET.@)
2210 * Read data from an open internet file
2213 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2214 * lpBuffersOut [I/O] Buffer.
2215 * dwFlags [I] Flags. See notes.
2216 * dwContext [I] Context for callbacks.
2223 * The parameter dwFlags include zero or more of the following flags:
2224 *|IRF_ASYNC - Makes the call asynchronous.
2225 *|IRF_SYNC - Makes the call synchronous.
2226 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2227 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2229 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2232 * InternetOpenUrlA(), HttpOpenRequestA()
2234 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2235 DWORD dwFlags
, DWORD_PTR dwContext
)
2237 object_header_t
*hdr
;
2238 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2240 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2242 hdr
= get_handle_object(hFile
);
2244 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2248 if(hdr
->vtbl
->ReadFileExA
)
2249 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
2251 WININET_Release(hdr
);
2253 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2254 res
, lpBuffersOut
->dwBufferLength
);
2256 if(res
!= ERROR_SUCCESS
)
2258 return res
== ERROR_SUCCESS
;
2261 /***********************************************************************
2262 * InternetReadFileExW (WININET.@)
2264 * InternetReadFileExA()
2266 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2267 DWORD dwFlags
, DWORD_PTR dwContext
)
2269 object_header_t
*hdr
;
2270 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2272 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2274 hdr
= get_handle_object(hFile
);
2276 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2280 if(hdr
->vtbl
->ReadFileExW
)
2281 res
= hdr
->vtbl
->ReadFileExW(hdr
, lpBuffer
, dwFlags
, dwContext
);
2283 WININET_Release(hdr
);
2285 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2286 res
, lpBuffer
->dwBufferLength
);
2288 if(res
!= ERROR_SUCCESS
)
2290 return res
== ERROR_SUCCESS
;
2293 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2295 /* FIXME: This function currently handles more options than it should. Options requiring
2296 * proper handles should be moved to proper functions */
2298 case INTERNET_OPTION_HTTP_VERSION
:
2299 if (*size
< sizeof(HTTP_VERSION_INFO
))
2300 return ERROR_INSUFFICIENT_BUFFER
;
2303 * Presently hardcoded to 1.1
2305 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2306 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2307 *size
= sizeof(HTTP_VERSION_INFO
);
2309 return ERROR_SUCCESS
;
2311 case INTERNET_OPTION_CONNECTED_STATE
:
2312 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2314 if (*size
< sizeof(ULONG
))
2315 return ERROR_INSUFFICIENT_BUFFER
;
2317 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2318 *size
= sizeof(ULONG
);
2320 return ERROR_SUCCESS
;
2322 case INTERNET_OPTION_PROXY
: {
2326 TRACE("Getting global proxy info\n");
2327 memset(&ai
, 0, sizeof(appinfo_t
));
2328 INTERNET_ConfigureProxy(&ai
);
2330 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2331 APPINFO_Destroy(&ai
.hdr
);
2335 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2336 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2338 if (*size
< sizeof(ULONG
))
2339 return ERROR_INSUFFICIENT_BUFFER
;
2341 *(ULONG
*)buffer
= max_conns
;
2342 *size
= sizeof(ULONG
);
2344 return ERROR_SUCCESS
;
2346 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2347 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2349 if (*size
< sizeof(ULONG
))
2350 return ERROR_INSUFFICIENT_BUFFER
;
2352 *(ULONG
*)buffer
= max_1_0_conns
;
2353 *size
= sizeof(ULONG
);
2355 return ERROR_SUCCESS
;
2357 case INTERNET_OPTION_SECURITY_FLAGS
:
2358 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2359 return ERROR_SUCCESS
;
2361 case INTERNET_OPTION_VERSION
: {
2362 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2364 TRACE("INTERNET_OPTION_VERSION\n");
2366 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2367 return ERROR_INSUFFICIENT_BUFFER
;
2369 memcpy(buffer
, &info
, sizeof(info
));
2370 *size
= sizeof(info
);
2372 return ERROR_SUCCESS
;
2375 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2376 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2377 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2378 DWORD res
= ERROR_SUCCESS
, i
;
2382 TRACE("Getting global proxy info\n");
2383 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2386 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2388 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2390 return ERROR_INSUFFICIENT_BUFFER
;
2393 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2394 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2395 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2397 switch (optionW
->dwOption
) {
2398 case INTERNET_PER_CONN_FLAGS
:
2400 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2402 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2405 case INTERNET_PER_CONN_PROXY_SERVER
:
2407 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2409 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2412 case INTERNET_PER_CONN_PROXY_BYPASS
:
2414 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2416 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2419 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2420 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2421 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2422 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2423 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2424 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2425 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2426 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2430 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2431 res
= ERROR_INVALID_PARAMETER
;
2439 case INTERNET_OPTION_REQUEST_FLAGS
:
2440 case INTERNET_OPTION_USER_AGENT
:
2442 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2443 case INTERNET_OPTION_POLICY
:
2444 return ERROR_INVALID_PARAMETER
;
2445 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2446 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2448 if (*size
< sizeof(ULONG
))
2449 return ERROR_INSUFFICIENT_BUFFER
;
2451 *(ULONG
*)buffer
= connect_timeout
;
2452 *size
= sizeof(ULONG
);
2454 return ERROR_SUCCESS
;
2457 FIXME("Stub for %d\n", option
);
2458 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2461 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2464 case INTERNET_OPTION_CONTEXT_VALUE
:
2466 return ERROR_INVALID_PARAMETER
;
2468 if (*size
< sizeof(DWORD_PTR
)) {
2469 *size
= sizeof(DWORD_PTR
);
2470 return ERROR_INSUFFICIENT_BUFFER
;
2473 return ERROR_INVALID_PARAMETER
;
2475 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2476 *size
= sizeof(DWORD_PTR
);
2477 return ERROR_SUCCESS
;
2479 case INTERNET_OPTION_REQUEST_FLAGS
:
2480 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2481 *size
= sizeof(DWORD
);
2482 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2484 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2485 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2486 WARN("Called on global option %u\n", option
);
2487 return ERROR_INTERNET_INVALID_OPERATION
;
2490 /* FIXME: we shouldn't call it here */
2491 return query_global_option(option
, buffer
, size
, unicode
);
2494 /***********************************************************************
2495 * InternetQueryOptionW (WININET.@)
2497 * Queries an options on the specified handle
2504 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2505 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2507 object_header_t
*hdr
;
2508 DWORD res
= ERROR_INVALID_HANDLE
;
2510 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2513 hdr
= get_handle_object(hInternet
);
2515 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2516 WININET_Release(hdr
);
2519 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2522 if(res
!= ERROR_SUCCESS
)
2524 return res
== ERROR_SUCCESS
;
2527 /***********************************************************************
2528 * InternetQueryOptionA (WININET.@)
2530 * Queries an options on the specified handle
2537 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2538 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2540 object_header_t
*hdr
;
2541 DWORD res
= ERROR_INVALID_HANDLE
;
2543 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2546 hdr
= get_handle_object(hInternet
);
2548 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2549 WININET_Release(hdr
);
2552 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2555 if(res
!= ERROR_SUCCESS
)
2557 return res
== ERROR_SUCCESS
;
2560 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2563 case INTERNET_OPTION_CALLBACK
:
2564 WARN("Not settable option %u\n", option
);
2565 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2566 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2567 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2568 WARN("Called on global option %u\n", option
);
2569 return ERROR_INTERNET_INVALID_OPERATION
;
2572 return ERROR_INTERNET_INVALID_OPTION
;
2575 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2578 case INTERNET_OPTION_CALLBACK
:
2579 WARN("Not global option %u\n", option
);
2580 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2582 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2583 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2585 if(size
!= sizeof(max_conns
))
2586 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2588 return ERROR_BAD_ARGUMENTS
;
2590 max_conns
= *(ULONG
*)buf
;
2591 return ERROR_SUCCESS
;
2593 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2594 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2596 if(size
!= sizeof(max_1_0_conns
))
2597 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2599 return ERROR_BAD_ARGUMENTS
;
2601 max_1_0_conns
= *(ULONG
*)buf
;
2602 return ERROR_SUCCESS
;
2604 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2605 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2607 if(size
!= sizeof(connect_timeout
))
2608 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2610 return ERROR_BAD_ARGUMENTS
;
2612 connect_timeout
= *(ULONG
*)buf
;
2613 return ERROR_SUCCESS
;
2615 case INTERNET_OPTION_SETTINGS_CHANGED
:
2616 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2617 collect_connections(COLLECT_CONNECTIONS
);
2618 return ERROR_SUCCESS
;
2621 return ERROR_INTERNET_INVALID_OPTION
;
2624 /***********************************************************************
2625 * InternetSetOptionW (WININET.@)
2627 * Sets an options on the specified handle
2634 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2635 LPVOID lpBuffer
, DWORD dwBufferLength
)
2637 object_header_t
*lpwhh
;
2641 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2643 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2645 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2647 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2649 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2651 WININET_Release(lpwhh
);
2653 if(res
!= ERROR_SUCCESS
)
2656 return res
== ERROR_SUCCESS
;
2661 case INTERNET_OPTION_HTTP_VERSION
:
2663 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2664 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2667 case INTERNET_OPTION_ERROR_MASK
:
2670 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2672 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2673 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2674 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2675 SetLastError(ERROR_INVALID_PARAMETER
);
2677 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2678 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2681 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2682 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2685 case INTERNET_OPTION_PROXY
:
2687 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2689 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2691 SetLastError(ERROR_INVALID_PARAMETER
);
2696 EnterCriticalSection( &WININET_cs
);
2697 free_global_proxy();
2698 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2701 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2703 global_proxy
->proxyEnabled
= 1;
2704 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2705 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2709 global_proxy
->proxyEnabled
= 0;
2710 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2713 LeaveCriticalSection( &WININET_cs
);
2717 /* In general, each type of object should handle
2718 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2719 * get silently dropped.
2721 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2722 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2727 case INTERNET_OPTION_CODEPAGE
:
2729 ULONG codepage
= *(ULONG
*)lpBuffer
;
2730 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2733 case INTERNET_OPTION_REQUEST_PRIORITY
:
2735 ULONG priority
= *(ULONG
*)lpBuffer
;
2736 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2739 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2741 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2742 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2745 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2747 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2748 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2751 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2752 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2754 case INTERNET_OPTION_END_BROWSER_SESSION
:
2755 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2757 case INTERNET_OPTION_CONNECTED_STATE
:
2758 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2760 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2761 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2763 case INTERNET_OPTION_SEND_TIMEOUT
:
2764 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2765 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2767 ULONG timeout
= *(ULONG
*)lpBuffer
;
2768 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2771 case INTERNET_OPTION_CONNECT_RETRIES
:
2773 ULONG retries
= *(ULONG
*)lpBuffer
;
2774 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2777 case INTERNET_OPTION_CONTEXT_VALUE
:
2781 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2784 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2786 SetLastError(ERROR_INVALID_PARAMETER
);
2790 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2793 case INTERNET_OPTION_SECURITY_FLAGS
:
2794 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2796 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2797 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2799 case INTERNET_OPTION_HTTP_DECODING
:
2800 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2801 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2804 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2805 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2806 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2809 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2810 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2811 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2814 case INTERNET_OPTION_CODEPAGE_PATH
:
2815 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2816 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2819 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2820 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2821 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2824 case INTERNET_OPTION_IDN
:
2825 FIXME("INTERNET_OPTION_IDN; STUB\n");
2826 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2829 case INTERNET_OPTION_POLICY
:
2830 SetLastError(ERROR_INVALID_PARAMETER
);
2833 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2834 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2839 INTERNET_LoadProxySettings(&pi
);
2841 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2842 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2844 switch (option
->dwOption
) {
2845 case INTERNET_PER_CONN_PROXY_SERVER
:
2846 heap_free(pi
.proxy
);
2847 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2850 case INTERNET_PER_CONN_FLAGS
:
2851 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2852 pi
.proxyEnabled
= 1;
2855 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2856 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2857 pi
.proxyEnabled
= 0;
2861 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2862 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2863 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2864 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2865 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2866 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2867 case INTERNET_PER_CONN_PROXY_BYPASS
:
2868 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2872 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2873 SetLastError(ERROR_INVALID_PARAMETER
);
2878 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2883 ret
= (res
== ERROR_SUCCESS
);
2887 FIXME("Option %d STUB\n",dwOption
);
2888 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2894 WININET_Release( lpwhh
);
2900 /***********************************************************************
2901 * InternetSetOptionA (WININET.@)
2903 * Sets an options on the specified handle.
2910 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2911 LPVOID lpBuffer
, DWORD dwBufferLength
)
2919 case INTERNET_OPTION_PROXY
:
2921 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2922 LPINTERNET_PROXY_INFOW piw
;
2923 DWORD proxlen
, prbylen
;
2926 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2927 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2928 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2929 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2930 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2931 piw
->dwAccessType
= pi
->dwAccessType
;
2932 prox
= (LPWSTR
) &piw
[1];
2933 prby
= &prox
[proxlen
+1];
2934 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2935 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2936 piw
->lpszProxy
= prox
;
2937 piw
->lpszProxyBypass
= prby
;
2940 case INTERNET_OPTION_USER_AGENT
:
2941 case INTERNET_OPTION_USERNAME
:
2942 case INTERNET_OPTION_PASSWORD
:
2943 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2945 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2946 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2949 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2951 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
2952 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
2953 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2954 wbuffer
= heap_alloc(wlen
);
2957 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2958 if (listA
->pszConnection
)
2960 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
2961 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
2962 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
2965 listW
->pszConnection
= NULL
;
2966 listW
->dwOptionCount
= listA
->dwOptionCount
;
2967 listW
->dwOptionError
= listA
->dwOptionError
;
2968 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
2970 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
2971 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
2972 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
2974 optW
->dwOption
= optA
->dwOption
;
2976 switch (optA
->dwOption
) {
2977 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2978 case INTERNET_PER_CONN_PROXY_BYPASS
:
2979 case INTERNET_PER_CONN_PROXY_SERVER
:
2980 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2981 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2982 if (optA
->Value
.pszValue
)
2984 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
2985 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
2986 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
2989 optW
->Value
.pszValue
= NULL
;
2991 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2992 case INTERNET_PER_CONN_FLAGS
:
2993 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2994 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
2996 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2997 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3000 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3001 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3009 wlen
= dwBufferLength
;
3012 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3014 if( lpBuffer
!= wbuffer
)
3016 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3018 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3020 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3021 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3022 switch (opt
->dwOption
) {
3023 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3024 case INTERNET_PER_CONN_PROXY_BYPASS
:
3025 case INTERNET_PER_CONN_PROXY_SERVER
:
3026 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3027 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3028 heap_free( opt
->Value
.pszValue
);
3034 heap_free( list
->pOptions
);
3036 heap_free( wbuffer
);
3043 /***********************************************************************
3044 * InternetSetOptionExA (WININET.@)
3046 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3047 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3049 FIXME("Flags %08x ignored\n", dwFlags
);
3050 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3053 /***********************************************************************
3054 * InternetSetOptionExW (WININET.@)
3056 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3057 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3059 FIXME("Flags %08x ignored\n", dwFlags
);
3060 if( dwFlags
& ~ISO_VALID_FLAGS
)
3062 SetLastError( ERROR_INVALID_PARAMETER
);
3065 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3068 static const WCHAR WININET_wkday
[7][4] =
3069 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3070 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3071 static const WCHAR WININET_month
[12][4] =
3072 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3073 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3074 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3076 /***********************************************************************
3077 * InternetTimeFromSystemTimeA (WININET.@)
3079 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3082 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3084 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3086 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3088 SetLastError(ERROR_INVALID_PARAMETER
);
3092 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3094 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3098 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3099 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3104 /***********************************************************************
3105 * InternetTimeFromSystemTimeW (WININET.@)
3107 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3109 static const WCHAR date
[] =
3110 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3111 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3113 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3115 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3117 SetLastError(ERROR_INVALID_PARAMETER
);
3121 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3123 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3127 sprintfW( string
, date
,
3128 WININET_wkday
[time
->wDayOfWeek
],
3130 WININET_month
[time
->wMonth
- 1],
3139 /***********************************************************************
3140 * InternetTimeToSystemTimeA (WININET.@)
3142 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3147 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3149 stringW
= heap_strdupAtoW(string
);
3152 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3153 heap_free( stringW
);
3158 /***********************************************************************
3159 * InternetTimeToSystemTimeW (WININET.@)
3161 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3164 const WCHAR
*s
= string
;
3167 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3169 if (!string
|| !time
) return FALSE
;
3171 /* Windows does this too */
3172 GetSystemTime( time
);
3174 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3175 * a SYSTEMTIME structure.
3178 while (*s
&& !isalphaW( *s
)) s
++;
3179 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3180 time
->wDayOfWeek
= 7;
3182 for (i
= 0; i
< 7; i
++)
3184 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3185 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3186 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3188 time
->wDayOfWeek
= i
;
3193 if (time
->wDayOfWeek
> 6) return TRUE
;
3194 while (*s
&& !isdigitW( *s
)) s
++;
3195 time
->wDay
= strtolW( s
, &end
, 10 );
3198 while (*s
&& !isalphaW( *s
)) s
++;
3199 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3202 for (i
= 0; i
< 12; i
++)
3204 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3205 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3206 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3208 time
->wMonth
= i
+ 1;
3212 if (time
->wMonth
== 0) return TRUE
;
3214 while (*s
&& !isdigitW( *s
)) s
++;
3215 if (*s
== '\0') return TRUE
;
3216 time
->wYear
= strtolW( s
, &end
, 10 );
3219 while (*s
&& !isdigitW( *s
)) s
++;
3220 if (*s
== '\0') return TRUE
;
3221 time
->wHour
= strtolW( s
, &end
, 10 );
3224 while (*s
&& !isdigitW( *s
)) s
++;
3225 if (*s
== '\0') return TRUE
;
3226 time
->wMinute
= strtolW( s
, &end
, 10 );
3229 while (*s
&& !isdigitW( *s
)) s
++;
3230 if (*s
== '\0') return TRUE
;
3231 time
->wSecond
= strtolW( s
, &end
, 10 );
3234 time
->wMilliseconds
= 0;
3238 /***********************************************************************
3239 * InternetCheckConnectionW (WININET.@)
3241 * Pings a requested host to check internet connection
3244 * TRUE on success and FALSE on failure. If a failure then
3245 * ERROR_NOT_CONNECTED is placed into GetLastError
3248 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3251 * this is a kludge which runs the resident ping program and reads the output.
3253 * Anyone have a better idea?
3257 static const CHAR ping
[] = "ping -c 1 ";
3258 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3259 CHAR
*command
= NULL
;
3260 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3268 * Crack or set the Address
3270 if (lpszUrl
== NULL
)
3273 * According to the doc we are supposed to use the ip for the next
3274 * server in the WnInet internal server database. I have
3275 * no idea what that is or how to get it.
3277 * So someone needs to implement this.
3279 FIXME("Unimplemented with URL of NULL\n");
3284 URL_COMPONENTSW components
;
3286 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3287 components
.lpszHostName
= (LPWSTR
)hostW
;
3288 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3290 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3293 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3294 port
= components
.nPort
;
3295 TRACE("port: %d\n", port
);
3298 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3300 struct sockaddr_storage saddr
;
3301 socklen_t sa_len
= sizeof(saddr
);
3304 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3306 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3309 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3317 * Build our ping command
3319 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3320 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3321 strcpy(command
,ping
);
3322 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3323 strcat(command
,redirect
);
3325 TRACE("Ping command is : %s\n",command
);
3327 status
= system(command
);
3329 TRACE("Ping returned a code of %i\n",status
);
3331 /* Ping return code of 0 indicates success */
3337 heap_free( command
);
3339 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3345 /***********************************************************************
3346 * InternetCheckConnectionA (WININET.@)
3348 * Pings a requested host to check internet connection
3351 * TRUE on success and FALSE on failure. If a failure then
3352 * ERROR_NOT_CONNECTED is placed into GetLastError
3355 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3361 url
= heap_strdupAtoW(lpszUrl
);
3366 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3373 /**********************************************************
3374 * INTERNET_InternetOpenUrlW (internal)
3379 * handle of connection or NULL on failure
3381 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3382 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3384 URL_COMPONENTSW urlComponents
;
3385 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3386 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3387 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3388 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3389 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3391 HINTERNET client
= NULL
, client1
= NULL
;
3394 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3395 dwHeadersLength
, dwFlags
, dwContext
);
3397 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3398 urlComponents
.lpszScheme
= protocol
;
3399 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3400 urlComponents
.lpszHostName
= hostName
;
3401 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3402 urlComponents
.lpszUserName
= userName
;
3403 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3404 urlComponents
.lpszPassword
= password
;
3405 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3406 urlComponents
.lpszUrlPath
= path
;
3407 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3408 urlComponents
.lpszExtraInfo
= extra
;
3409 urlComponents
.dwExtraInfoLength
= 1024;
3410 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3412 switch(urlComponents
.nScheme
) {
3413 case INTERNET_SCHEME_FTP
:
3414 if(urlComponents
.nPort
== 0)
3415 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3416 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3417 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3420 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3421 if(client1
== NULL
) {
3422 InternetCloseHandle(client
);
3427 case INTERNET_SCHEME_HTTP
:
3428 case INTERNET_SCHEME_HTTPS
: {
3429 static const WCHAR szStars
[] = { '*','/','*', 0 };
3430 LPCWSTR accept
[2] = { szStars
, NULL
};
3431 if(urlComponents
.nPort
== 0) {
3432 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3433 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3435 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3437 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3439 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3440 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3441 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3442 if(res
!= ERROR_SUCCESS
) {
3443 INTERNET_SetLastError(res
);
3447 if (urlComponents
.dwExtraInfoLength
) {
3449 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3451 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3453 InternetCloseHandle(client
);
3456 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3457 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3458 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3459 heap_free(path_extra
);
3462 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3464 if(client1
== NULL
) {
3465 InternetCloseHandle(client
);
3468 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3469 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3470 GetLastError() != ERROR_IO_PENDING
) {
3471 InternetCloseHandle(client1
);
3476 case INTERNET_SCHEME_GOPHER
:
3477 /* gopher doesn't seem to be implemented in wine, but it's supposed
3478 * to be supported by InternetOpenUrlA. */
3480 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3484 TRACE(" %p <--\n", client1
);
3489 /**********************************************************
3490 * InternetOpenUrlW (WININET.@)
3495 * handle of connection or NULL on failure
3497 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3499 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3500 appinfo_t
*hIC
= (appinfo_t
*) workRequest
->hdr
;
3504 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3505 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3506 heap_free(req
->lpszUrl
);
3507 heap_free(req
->lpszHeaders
);
3510 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3511 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3513 HINTERNET ret
= NULL
;
3514 appinfo_t
*hIC
= NULL
;
3516 if (TRACE_ON(wininet
)) {
3517 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3518 dwHeadersLength
, dwFlags
, dwContext
);
3520 dump_INTERNET_FLAGS(dwFlags
);
3525 SetLastError(ERROR_INVALID_PARAMETER
);
3529 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3530 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3531 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3535 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3536 WORKREQUEST workRequest
;
3537 struct WORKREQ_INTERNETOPENURLW
*req
;
3539 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3540 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3541 req
= &workRequest
.u
.InternetOpenUrlW
;
3542 req
->lpszUrl
= heap_strdupW(lpszUrl
);
3543 req
->lpszHeaders
= heap_strdupW(lpszHeaders
);
3544 req
->dwHeadersLength
= dwHeadersLength
;
3545 req
->dwFlags
= dwFlags
;
3546 req
->dwContext
= dwContext
;
3548 INTERNET_AsyncCall(&workRequest
);
3550 * This is from windows.
3552 SetLastError(ERROR_IO_PENDING
);
3554 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3559 WININET_Release( &hIC
->hdr
);
3560 TRACE(" %p <--\n", ret
);
3565 /**********************************************************
3566 * InternetOpenUrlA (WININET.@)
3571 * handle of connection or NULL on failure
3573 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3574 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3576 HINTERNET rc
= NULL
;
3577 DWORD lenHeaders
= 0;
3578 LPWSTR szUrl
= NULL
;
3579 LPWSTR szHeaders
= NULL
;
3584 szUrl
= heap_strdupAtoW(lpszUrl
);
3590 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3591 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3596 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3599 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3600 lenHeaders
, dwFlags
, dwContext
);
3603 heap_free(szHeaders
);
3608 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3610 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3614 lpwite
->dwError
= 0;
3615 lpwite
->response
[0] = '\0';
3618 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3627 /***********************************************************************
3628 * INTERNET_SetLastError (internal)
3630 * Set last thread specific error
3635 void INTERNET_SetLastError(DWORD dwError
)
3637 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3640 lpwite
= INTERNET_AllocThreadError();
3642 SetLastError(dwError
);
3644 lpwite
->dwError
= dwError
;
3648 /***********************************************************************
3649 * INTERNET_GetLastError (internal)
3651 * Get last thread specific error
3656 DWORD
INTERNET_GetLastError(void)
3658 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3659 if (!lpwite
) return 0;
3660 /* TlsGetValue clears last error, so set it again here */
3661 SetLastError(lpwite
->dwError
);
3662 return lpwite
->dwError
;
3666 /***********************************************************************
3667 * INTERNET_WorkerThreadFunc (internal)
3669 * Worker thread execution function
3674 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3676 LPWORKREQUEST lpRequest
= lpvParam
;
3677 WORKREQUEST workRequest
;
3681 workRequest
= *lpRequest
;
3682 heap_free(lpRequest
);
3684 workRequest
.asyncproc(&workRequest
);
3685 WININET_Release( workRequest
.hdr
);
3687 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3689 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3690 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3696 /***********************************************************************
3697 * INTERNET_AsyncCall (internal)
3699 * Retrieves work request from queue
3704 DWORD
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3707 LPWORKREQUEST lpNewRequest
;
3711 lpNewRequest
= heap_alloc(sizeof(WORKREQUEST
));
3713 return ERROR_OUTOFMEMORY
;
3715 *lpNewRequest
= *lpWorkRequest
;
3717 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3720 heap_free(lpNewRequest
);
3721 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3723 return ERROR_SUCCESS
;
3727 /***********************************************************************
3728 * INTERNET_GetResponseBuffer (internal)
3733 LPSTR
INTERNET_GetResponseBuffer(void)
3735 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3737 lpwite
= INTERNET_AllocThreadError();
3739 return lpwite
->response
;
3742 /***********************************************************************
3743 * INTERNET_GetNextLine (internal)
3745 * Parse next line in directory string listing
3748 * Pointer to beginning of next line
3753 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3756 BOOL bSuccess
= FALSE
;
3758 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3763 pfd
.events
= POLLIN
;
3765 while (nRecv
< MAX_REPLY_LEN
)
3767 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3769 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3771 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3775 if (lpszBuffer
[nRecv
] == '\n')
3780 if (lpszBuffer
[nRecv
] != '\r')
3785 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3793 lpszBuffer
[nRecv
] = '\0';
3795 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3804 /**********************************************************
3805 * InternetQueryDataAvailable (WININET.@)
3807 * Determines how much data is available to be read.
3810 * TRUE on success, FALSE if an error occurred. If
3811 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3812 * no data is presently available, FALSE is returned with
3813 * the last error ERROR_IO_PENDING; a callback with status
3814 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3815 * data is available.
3817 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3818 LPDWORD lpdwNumberOfBytesAvailable
,
3819 DWORD dwFlags
, DWORD_PTR dwContext
)
3821 object_header_t
*hdr
;
3824 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3826 hdr
= get_handle_object( hFile
);
3828 SetLastError(ERROR_INVALID_HANDLE
);
3832 if(hdr
->vtbl
->QueryDataAvailable
) {
3833 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3835 WARN("wrong handle\n");
3836 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3839 WININET_Release(hdr
);
3841 if(res
!= ERROR_SUCCESS
)
3843 return res
== ERROR_SUCCESS
;
3847 /***********************************************************************
3848 * InternetLockRequestFile (WININET.@)
3850 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3857 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3864 /***********************************************************************
3865 * InternetAutodial (WININET.@)
3867 * On windows this function is supposed to dial the default internet
3868 * connection. We don't want to have Wine dial out to the internet so
3869 * we return TRUE by default. It might be nice to check if we are connected.
3876 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3880 /* Tell that we are connected to the internet. */
3884 /***********************************************************************
3885 * InternetAutodialHangup (WININET.@)
3887 * Hangs up a connection made with InternetAutodial
3896 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3900 /* we didn't dial, we don't disconnect */
3904 /***********************************************************************
3905 * InternetCombineUrlA (WININET.@)
3907 * Combine a base URL with a relative URL
3915 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3916 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3921 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3923 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3924 dwFlags
^= ICU_NO_ENCODE
;
3925 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3930 /***********************************************************************
3931 * InternetCombineUrlW (WININET.@)
3933 * Combine a base URL with a relative URL
3941 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3942 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3947 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3949 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3950 dwFlags
^= ICU_NO_ENCODE
;
3951 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3956 /* max port num is 65535 => 5 digits */
3957 #define MAX_WORD_DIGITS 5
3959 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3960 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3961 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3962 (url)->dw##component##Length : strlen((url)->lpsz##component))
3964 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3966 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3967 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3969 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3970 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3972 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3973 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3975 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3976 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3979 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3985 /* opaque urls do not fit into the standard url hierarchy and don't have
3986 * two following slashes */
3987 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3989 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3990 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3991 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3992 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3993 (nScheme
!= INTERNET_SCHEME_FILE
);
3996 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3999 if (scheme
< INTERNET_SCHEME_FIRST
)
4001 index
= scheme
- INTERNET_SCHEME_FIRST
;
4002 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4004 return (LPCWSTR
)url_schemes
[index
];
4007 /* we can calculate using ansi strings because we're just
4008 * calculating string length, not size
4010 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4011 LPDWORD lpdwUrlLength
)
4013 INTERNET_SCHEME nScheme
;
4017 if (lpUrlComponents
->lpszScheme
)
4019 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4020 *lpdwUrlLength
+= dwLen
;
4021 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4027 nScheme
= lpUrlComponents
->nScheme
;
4029 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4030 nScheme
= INTERNET_SCHEME_HTTP
;
4031 scheme
= INTERNET_GetSchemeString(nScheme
);
4032 *lpdwUrlLength
+= strlenW(scheme
);
4035 (*lpdwUrlLength
)++; /* ':' */
4036 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4037 *lpdwUrlLength
+= strlen("//");
4039 if (lpUrlComponents
->lpszUserName
)
4041 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4042 *lpdwUrlLength
+= strlen("@");
4046 if (lpUrlComponents
->lpszPassword
)
4048 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4053 if (lpUrlComponents
->lpszPassword
)
4055 *lpdwUrlLength
+= strlen(":");
4056 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4059 if (lpUrlComponents
->lpszHostName
)
4061 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4063 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4065 char szPort
[MAX_WORD_DIGITS
+1];
4067 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4068 *lpdwUrlLength
+= strlen(szPort
);
4069 *lpdwUrlLength
+= strlen(":");
4072 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4073 (*lpdwUrlLength
)++; /* '/' */
4076 if (lpUrlComponents
->lpszUrlPath
)
4077 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4079 if (lpUrlComponents
->lpszExtraInfo
)
4080 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4085 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4089 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4091 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4092 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4093 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4094 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4095 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4096 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4097 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4098 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4099 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4101 if (lpUrlComponents
->lpszScheme
)
4103 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4104 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4105 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4106 -1, urlCompW
->lpszScheme
, len
);
4109 if (lpUrlComponents
->lpszHostName
)
4111 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4112 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4113 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4114 -1, urlCompW
->lpszHostName
, len
);
4117 if (lpUrlComponents
->lpszUserName
)
4119 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4120 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4121 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4122 -1, urlCompW
->lpszUserName
, len
);
4125 if (lpUrlComponents
->lpszPassword
)
4127 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4128 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4129 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4130 -1, urlCompW
->lpszPassword
, len
);
4133 if (lpUrlComponents
->lpszUrlPath
)
4135 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4136 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4137 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4138 -1, urlCompW
->lpszUrlPath
, len
);
4141 if (lpUrlComponents
->lpszExtraInfo
)
4143 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4144 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4145 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4146 -1, urlCompW
->lpszExtraInfo
, len
);
4150 /***********************************************************************
4151 * InternetCreateUrlA (WININET.@)
4153 * See InternetCreateUrlW.
4155 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4156 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4160 URL_COMPONENTSW urlCompW
;
4162 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4164 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4166 SetLastError(ERROR_INVALID_PARAMETER
);
4170 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4173 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4175 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4177 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4178 *lpdwUrlLength
/= sizeof(WCHAR
);
4180 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4181 * minus one, so add one to leave room for NULL terminator
4184 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4186 heap_free(urlCompW
.lpszScheme
);
4187 heap_free(urlCompW
.lpszHostName
);
4188 heap_free(urlCompW
.lpszUserName
);
4189 heap_free(urlCompW
.lpszPassword
);
4190 heap_free(urlCompW
.lpszUrlPath
);
4191 heap_free(urlCompW
.lpszExtraInfo
);
4196 /***********************************************************************
4197 * InternetCreateUrlW (WININET.@)
4199 * Creates a URL from its component parts.
4202 * lpUrlComponents [I] URL Components.
4203 * dwFlags [I] Flags. See notes.
4204 * lpszUrl [I] Buffer in which to store the created URL.
4205 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4206 * lpszUrl in characters. On output, the number of bytes
4207 * required to store the URL including terminator.
4211 * The dwFlags parameter can be zero or more of the following:
4212 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4219 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4220 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4223 INTERNET_SCHEME nScheme
;
4225 static const WCHAR slashSlashW
[] = {'/','/'};
4226 static const WCHAR fmtW
[] = {'%','u',0};
4228 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4230 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4232 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4236 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4239 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4241 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4242 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4246 *lpdwUrlLength
= dwLen
;
4251 if (lpUrlComponents
->lpszScheme
)
4253 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4254 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4257 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4262 nScheme
= lpUrlComponents
->nScheme
;
4264 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4265 nScheme
= INTERNET_SCHEME_HTTP
;
4267 scheme
= INTERNET_GetSchemeString(nScheme
);
4268 dwLen
= strlenW(scheme
);
4269 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4273 /* all schemes are followed by at least a colon */
4277 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4279 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4280 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4283 if (lpUrlComponents
->lpszUserName
)
4285 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4286 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4289 if (lpUrlComponents
->lpszPassword
)
4294 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4295 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4303 if (lpUrlComponents
->lpszHostName
)
4305 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4306 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4309 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4311 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4313 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4316 dwLen
= strlenW(szPort
);
4317 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4321 /* add slash between hostname and path if necessary */
4322 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4329 if (lpUrlComponents
->lpszUrlPath
)
4331 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4332 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4336 if (lpUrlComponents
->lpszExtraInfo
)
4338 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4339 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4348 /***********************************************************************
4349 * InternetConfirmZoneCrossingA (WININET.@)
4352 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4354 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4355 return ERROR_SUCCESS
;
4358 /***********************************************************************
4359 * InternetConfirmZoneCrossingW (WININET.@)
4362 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4364 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4365 return ERROR_SUCCESS
;
4368 static DWORD zone_preference
= 3;
4370 /***********************************************************************
4371 * PrivacySetZonePreferenceW (WININET.@)
4373 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4375 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4377 zone_preference
= template;
4381 /***********************************************************************
4382 * PrivacyGetZonePreferenceW (WININET.@)
4384 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4385 LPWSTR preference
, LPDWORD length
)
4387 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4389 if (template) *template = zone_preference
;
4393 /***********************************************************************
4394 * InternetGetSecurityInfoByURLA (WININET.@)
4396 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4401 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4403 url
= heap_strdupAtoW(lpszURL
);
4407 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4412 /***********************************************************************
4413 * InternetGetSecurityInfoByURLW (WININET.@)
4415 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4417 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4418 URL_COMPONENTSW url
= {sizeof(url
)};
4422 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4424 url
.lpszHostName
= hostname
;
4425 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4427 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4428 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4429 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4433 if(url
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
4434 url
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
4436 server
= get_server(hostname
, url
.nPort
, FALSE
);
4438 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4442 if(server
->cert_chain
) {
4443 const CERT_CHAIN_CONTEXT
*chain_dup
;
4445 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4447 *ppCertChain
= chain_dup
;
4448 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4453 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4457 server_release(server
);
4461 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4462 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4464 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4465 lpdwConnection
, dwReserved
);
4466 return ERROR_SUCCESS
;
4469 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4470 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4472 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4473 lpdwConnection
, dwReserved
);
4474 return ERROR_SUCCESS
;
4477 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4479 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4483 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4485 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4489 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4491 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4492 return ERROR_SUCCESS
;
4495 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4498 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4499 debugstr_w(pwszTarget
), pbHexHash
);
4503 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4505 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4509 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4511 FIXME("(%p, %08lx) stub\n", a
, b
);
4515 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4517 FIXME("%p: stub\n", parent
);