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
31 #define RESPONSE_TIMEOUT 30
36 CHAR response
[MAX_REPLY_LEN
];
37 } WITHREADERROR
, *LPWITHREADERROR
;
39 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
40 HMODULE WININET_hModule
;
42 static CRITICAL_SECTION WININET_cs
;
43 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
46 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
47 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
49 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
51 static object_header_t
**handle_table
;
52 static UINT_PTR next_handle
;
53 static UINT_PTR handle_table_size
;
62 static ULONG max_conns
= 2, max_1_0_conns
= 4;
63 static ULONG connect_timeout
= 60000;
65 static const WCHAR szInternetSettings
[] =
66 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
67 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
68 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
69 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
70 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
71 static const WCHAR szProxyOverride
[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
73 void *alloc_object(object_header_t
*parent
, const object_vtbl_t
*vtbl
, size_t size
)
75 UINT_PTR handle
= 0, num
;
80 ret
= heap_alloc_zero(size
);
84 list_init(&ret
->children
);
86 EnterCriticalSection( &WININET_cs
);
88 if(!handle_table_size
) {
90 p
= heap_alloc_zero(sizeof(handle_table
[0]) * num
);
93 handle_table_size
= num
;
98 }else if(next_handle
== handle_table_size
) {
99 num
= handle_table_size
* 2;
100 p
= heap_realloc_zero(handle_table
, sizeof(handle_table
[0]) * num
);
103 handle_table_size
= num
;
110 handle
= next_handle
;
111 if(handle_table
[handle
])
112 ERR("handle isn't free but should be\n");
113 handle_table
[handle
] = ret
;
114 ret
->valid_handle
= TRUE
;
116 while(handle_table
[next_handle
] && next_handle
< handle_table_size
)
120 LeaveCriticalSection( &WININET_cs
);
129 ret
->hInternet
= (HINTERNET
)handle
;
132 ret
->lpfnStatusCB
= parent
->lpfnStatusCB
;
133 ret
->dwInternalFlags
= parent
->dwInternalFlags
& INET_CALLBACKW
;
139 object_header_t
*WININET_AddRef( object_header_t
*info
)
141 ULONG refs
= InterlockedIncrement(&info
->refs
);
142 TRACE("%p -> refcount = %d\n", info
, refs
);
146 object_header_t
*get_handle_object( HINTERNET hinternet
)
148 object_header_t
*info
= NULL
;
149 UINT_PTR handle
= (UINT_PTR
) hinternet
;
151 EnterCriticalSection( &WININET_cs
);
153 if(handle
> 0 && handle
< handle_table_size
&& handle_table
[handle
] && handle_table
[handle
]->valid_handle
)
154 info
= WININET_AddRef(handle_table
[handle
]);
156 LeaveCriticalSection( &WININET_cs
);
158 TRACE("handle %ld -> %p\n", handle
, info
);
163 static void invalidate_handle(object_header_t
*info
)
165 object_header_t
*child
, *next
;
167 if(!info
->valid_handle
)
169 info
->valid_handle
= FALSE
;
171 /* Free all children as native does */
172 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, object_header_t
, entry
)
174 TRACE("invalidating child handle %p for parent %p\n", child
->hInternet
, info
);
175 invalidate_handle( child
);
178 WININET_Release(info
);
181 BOOL
WININET_Release( object_header_t
*info
)
183 ULONG refs
= InterlockedDecrement(&info
->refs
);
184 TRACE( "object %p refcount = %d\n", info
, refs
);
187 invalidate_handle(info
);
188 if ( info
->vtbl
->CloseConnection
)
190 TRACE( "closing connection %p\n", info
);
191 info
->vtbl
->CloseConnection( info
);
193 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
194 if ((info
->htype
!= WH_HHTTPSESSION
&& info
->htype
!= WH_HFTPSESSION
)
195 || !(info
->dwInternalFlags
& INET_OPENURL
))
197 INTERNET_SendCallback(info
, info
->dwContext
,
198 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
201 TRACE( "destroying object %p\n", info
);
202 if ( info
->htype
!= WH_HINIT
)
203 list_remove( &info
->entry
);
204 info
->vtbl
->Destroy( info
);
206 if(info
->hInternet
) {
207 UINT_PTR handle
= (UINT_PTR
)info
->hInternet
;
209 EnterCriticalSection( &WININET_cs
);
211 handle_table
[handle
] = NULL
;
212 if(next_handle
> handle
)
213 next_handle
= handle
;
215 LeaveCriticalSection( &WININET_cs
);
223 /***********************************************************************
224 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
227 * hinstDLL [I] handle to the DLL's instance
229 * lpvReserved [I] reserved, must be NULL
236 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
238 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
241 case DLL_PROCESS_ATTACH
:
243 g_dwTlsErrIndex
= TlsAlloc();
245 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
249 URLCacheContainers_CreateDefaults();
252 WININET_hModule
= hinstDLL
;
255 case DLL_THREAD_ATTACH
:
258 case DLL_THREAD_DETACH
:
259 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
261 heap_free(TlsGetValue(g_dwTlsErrIndex
));
265 case DLL_PROCESS_DETACH
:
266 if (lpvReserved
) break;
267 collect_connections(COLLECT_CLEANUP
);
272 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
274 heap_free(TlsGetValue(g_dwTlsErrIndex
));
275 TlsFree(g_dwTlsErrIndex
);
282 /***********************************************************************
283 * INTERNET_SaveProxySettings
285 * Stores the proxy settings given by lpwai into the registry
288 * ERROR_SUCCESS if no error, or error code on fail
290 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
295 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
298 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
306 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
314 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
322 return ERROR_SUCCESS
;
325 /***********************************************************************
326 * INTERNET_FindProxyForProtocol
328 * Searches the proxy string for a proxy of the given protocol.
329 * Returns the found proxy, or the default proxy if none of the given
333 * szProxy [In] proxy string to search
334 * proto [In] protocol to search for, e.g. "http"
335 * foundProxy [Out] found proxy
336 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
339 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
340 * *foundProxyLen is set to the required size in WCHARs, including the
341 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
343 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
348 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
350 /* First, look for the specified protocol (proto=scheme://host:port) */
351 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
355 if (!(end
= strchrW(ptr
, ' ')))
356 end
= ptr
+ strlenW(ptr
);
357 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
358 equal
- ptr
== strlenW(proto
) &&
359 !strncmpiW(proto
, ptr
, strlenW(proto
)))
361 if (end
- equal
> *foundProxyLen
)
363 WARN("buffer too short for %s\n",
364 debugstr_wn(equal
+ 1, end
- equal
- 1));
365 *foundProxyLen
= end
- equal
;
366 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
370 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
371 foundProxy
[end
- equal
] = 0;
382 /* It wasn't found: look for no protocol */
383 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
387 if (!(end
= strchrW(ptr
, ' ')))
388 end
= ptr
+ strlenW(ptr
);
389 if (!strchrW(ptr
, '='))
391 if (end
- ptr
+ 1 > *foundProxyLen
)
393 WARN("buffer too short for %s\n",
394 debugstr_wn(ptr
, end
- ptr
));
395 *foundProxyLen
= end
- ptr
+ 1;
396 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
400 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
401 foundProxy
[end
- ptr
] = 0;
412 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
413 debugstr_w(foundProxy
));
417 /***********************************************************************
418 * InternetInitializeAutoProxyDll (WININET.@)
420 * Setup the internal proxy
429 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
432 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
436 /***********************************************************************
437 * DetectAutoProxyUrl (WININET.@)
439 * Auto detect the proxy url
445 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
446 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
449 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
453 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
455 heap_free(lpwpi
->proxy
);
456 heap_free(lpwpi
->proxyBypass
);
459 static proxyinfo_t
*global_proxy
;
461 static void free_global_proxy( void )
463 EnterCriticalSection( &WININET_cs
);
466 FreeProxyInfo( global_proxy
);
467 heap_free( global_proxy
);
469 LeaveCriticalSection( &WININET_cs
);
472 /***********************************************************************
473 * INTERNET_LoadProxySettings
475 * Loads proxy information from process-wide global settings, the registry,
476 * or the environment into lpwpi.
478 * The caller should call FreeProxyInfo when done with lpwpi.
481 * The proxy may be specified in the form 'http=proxy.my.org'
482 * Presumably that means there can be ftp=ftpproxy.my.org too.
484 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
491 EnterCriticalSection( &WININET_cs
);
494 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
495 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
496 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
498 LeaveCriticalSection( &WININET_cs
);
500 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
504 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
506 lpwpi
->proxyEnabled
= 0;
507 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
514 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
516 TRACE("Proxy is enabled.\n");
518 /* figure out how much memory the proxy setting takes */
519 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
522 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
524 if (!(szProxy
= heap_alloc(len
)))
527 return ERROR_OUTOFMEMORY
;
529 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
531 /* find the http proxy, and strip away everything else */
532 p
= strstrW( szProxy
, szHttp
);
535 p
+= lstrlenW( szHttp
);
536 lstrcpyW( szProxy
, p
);
538 p
= strchrW( szProxy
, ' ' );
541 lpwpi
->proxy
= szProxy
;
543 TRACE("http proxy = %s\n", debugstr_w(lpwpi
->proxy
));
547 TRACE("No proxy server settings in registry.\n");
555 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
556 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
557 return ERROR_OUTOFMEMORY
;
558 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
560 lpwpi
->proxyEnabled
= 1;
561 lpwpi
->proxy
= envproxyW
;
563 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
566 lpwpi
->proxyBypass
= NULL
;
567 if (lpwpi
->proxyEnabled
)
569 if (!(envproxy
= getenv( "no_proxy" )))
571 /* figure out how much memory the proxy setting takes */
572 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
576 if (!(szProxy
= heap_alloc(len
)))
579 return ERROR_OUTOFMEMORY
;
581 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
583 lpwpi
->proxyBypass
= szProxy
;
585 TRACE("http proxy bypass = %s\n", debugstr_w(lpwpi
->proxyBypass
));
589 TRACE("No proxy bypass server settings in registry.\n");
596 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
597 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
598 return ERROR_OUTOFMEMORY
;
599 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
601 lpwpi
->proxyBypass
= envproxyW
;
603 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
609 return ERROR_SUCCESS
;
612 /***********************************************************************
613 * INTERNET_ConfigureProxy
615 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
617 proxyinfo_t wpi
= {0};
619 if (INTERNET_LoadProxySettings( &wpi
))
622 if (wpi
.proxyEnabled
)
624 WCHAR proxyurl
[INTERNET_MAX_URL_LENGTH
];
625 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
];
626 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
627 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
628 URL_COMPONENTSW UrlComponents
;
630 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
631 UrlComponents
.dwSchemeLength
= 0;
632 UrlComponents
.lpszHostName
= hostname
;
633 UrlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
634 UrlComponents
.lpszUserName
= username
;
635 UrlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
636 UrlComponents
.lpszPassword
= password
;
637 UrlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
638 UrlComponents
.dwUrlPathLength
= 0;
639 UrlComponents
.dwExtraInfoLength
= 0;
641 if(InternetCrackUrlW(wpi
.proxy
, 0, 0, &UrlComponents
))
643 static const WCHAR szFormat
[] = { 'h','t','t','p',':','/','/','%','s',':','%','u',0 };
645 if(UrlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
646 UrlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
647 sprintfW(proxyurl
, szFormat
, hostname
, UrlComponents
.nPort
);
649 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
650 lpwai
->proxy
= heap_strdupW(proxyurl
);
651 lpwai
->proxyBypass
= heap_strdupW(wpi
.proxyBypass
);
652 if (UrlComponents
.dwUserNameLength
)
654 lpwai
->proxyUsername
= heap_strdupW(UrlComponents
.lpszUserName
);
655 lpwai
->proxyPassword
= heap_strdupW(UrlComponents
.lpszPassword
);
658 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai
->proxy
), debugstr_w(lpwai
->proxyBypass
));
664 TRACE("Failed to parse proxy: %s\n", debugstr_w(wpi
.proxy
));
669 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
674 /***********************************************************************
675 * dump_INTERNET_FLAGS
677 * Helper function to TRACE the internet flags.
683 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
685 #define FE(x) { x, #x }
686 static const wininet_flag_info flag
[] = {
687 FE(INTERNET_FLAG_RELOAD
),
688 FE(INTERNET_FLAG_RAW_DATA
),
689 FE(INTERNET_FLAG_EXISTING_CONNECT
),
690 FE(INTERNET_FLAG_ASYNC
),
691 FE(INTERNET_FLAG_PASSIVE
),
692 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
693 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
694 FE(INTERNET_FLAG_FROM_CACHE
),
695 FE(INTERNET_FLAG_SECURE
),
696 FE(INTERNET_FLAG_KEEP_CONNECTION
),
697 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
698 FE(INTERNET_FLAG_READ_PREFETCH
),
699 FE(INTERNET_FLAG_NO_COOKIES
),
700 FE(INTERNET_FLAG_NO_AUTH
),
701 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
702 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
703 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
704 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
705 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
706 FE(INTERNET_FLAG_RESYNCHRONIZE
),
707 FE(INTERNET_FLAG_HYPERLINK
),
708 FE(INTERNET_FLAG_NO_UI
),
709 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
710 FE(INTERNET_FLAG_CACHE_ASYNC
),
711 FE(INTERNET_FLAG_FORMS_SUBMIT
),
712 FE(INTERNET_FLAG_NEED_FILE
),
713 FE(INTERNET_FLAG_TRANSFER_ASCII
),
714 FE(INTERNET_FLAG_TRANSFER_BINARY
)
719 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
720 if (flag
[i
].val
& dwFlags
) {
721 TRACE(" %s", flag
[i
].name
);
722 dwFlags
&= ~flag
[i
].val
;
726 TRACE(" Unknown flags (%08x)\n", dwFlags
);
731 /***********************************************************************
732 * INTERNET_CloseHandle (internal)
734 * Close internet handle
737 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
739 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
743 heap_free(lpwai
->agent
);
744 heap_free(lpwai
->proxy
);
745 heap_free(lpwai
->proxyBypass
);
746 heap_free(lpwai
->proxyUsername
);
747 heap_free(lpwai
->proxyPassword
);
753 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
755 appinfo_t
*ai
= (appinfo_t
*)hdr
;
758 case INTERNET_OPTION_HANDLE_TYPE
:
759 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
761 if (*size
< sizeof(ULONG
))
762 return ERROR_INSUFFICIENT_BUFFER
;
764 *size
= sizeof(DWORD
);
765 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
766 return ERROR_SUCCESS
;
768 case INTERNET_OPTION_USER_AGENT
: {
771 TRACE("INTERNET_OPTION_USER_AGENT\n");
776 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
778 *size
= (len
+ 1) * sizeof(WCHAR
);
779 if(!buffer
|| bufsize
< *size
)
780 return ERROR_INSUFFICIENT_BUFFER
;
783 strcpyW(buffer
, ai
->agent
);
785 *(WCHAR
*)buffer
= 0;
786 /* If the buffer is copied, the returned length doesn't include
787 * the NULL terminator.
792 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
795 if(!buffer
|| bufsize
< *size
)
796 return ERROR_INSUFFICIENT_BUFFER
;
799 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
802 /* If the buffer is copied, the returned length doesn't include
803 * the NULL terminator.
808 return ERROR_SUCCESS
;
811 case INTERNET_OPTION_PROXY
:
812 if(!size
) return ERROR_INVALID_PARAMETER
;
814 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
815 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
816 LPWSTR proxy
, proxy_bypass
;
819 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
821 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
822 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
824 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
825 return ERROR_INSUFFICIENT_BUFFER
;
827 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
828 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
830 pi
->dwAccessType
= ai
->accessType
;
831 pi
->lpszProxy
= NULL
;
832 pi
->lpszProxyBypass
= NULL
;
834 lstrcpyW(proxy
, ai
->proxy
);
835 pi
->lpszProxy
= proxy
;
838 if (ai
->proxyBypass
) {
839 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
840 pi
->lpszProxyBypass
= proxy_bypass
;
843 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
844 return ERROR_SUCCESS
;
846 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
847 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
848 LPSTR proxy
, proxy_bypass
;
851 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
853 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
854 NULL
, 0, NULL
, NULL
);
855 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
857 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
858 return ERROR_INSUFFICIENT_BUFFER
;
860 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
861 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
863 pi
->dwAccessType
= ai
->accessType
;
864 pi
->lpszProxy
= NULL
;
865 pi
->lpszProxyBypass
= NULL
;
867 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
868 pi
->lpszProxy
= proxy
;
871 if (ai
->proxyBypass
) {
872 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
873 proxyBypassBytesRequired
, NULL
, NULL
);
874 pi
->lpszProxyBypass
= proxy_bypass
;
877 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
878 return ERROR_SUCCESS
;
881 case INTERNET_OPTION_CONNECT_TIMEOUT
:
882 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
884 if (*size
< sizeof(ULONG
))
885 return ERROR_INSUFFICIENT_BUFFER
;
887 *(ULONG
*)buffer
= ai
->connect_timeout
;
888 *size
= sizeof(ULONG
);
890 return ERROR_SUCCESS
;
893 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
896 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
898 appinfo_t
*ai
= (appinfo_t
*)hdr
;
901 case INTERNET_OPTION_CONNECT_TIMEOUT
:
902 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
904 if(size
!= sizeof(connect_timeout
))
905 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
907 return ERROR_BAD_ARGUMENTS
;
909 ai
->connect_timeout
= *(ULONG
*)buf
;
910 return ERROR_SUCCESS
;
911 case INTERNET_OPTION_USER_AGENT
:
912 heap_free(ai
->agent
);
913 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
914 return ERROR_SUCCESS
;
917 return INET_SetOption(hdr
, option
, buf
, size
);
920 static const object_vtbl_t APPINFOVtbl
= {
932 /***********************************************************************
933 * InternetOpenW (WININET.@)
935 * Per-application initialization of wininet
938 * HINTERNET on success
942 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
943 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
945 appinfo_t
*lpwai
= NULL
;
948 int error
= WSAStartup(MAKEWORD(2, 2), &wsaData
);
949 if (error
) ERR("WSAStartup failed: %d\n", error
);
952 if (TRACE_ON(wininet
)) {
953 #define FE(x) { x, #x }
954 static const wininet_flag_info access_type
[] = {
955 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
956 FE(INTERNET_OPEN_TYPE_DIRECT
),
957 FE(INTERNET_OPEN_TYPE_PROXY
),
958 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
962 const char *access_type_str
= "Unknown";
964 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
965 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
966 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
967 if (access_type
[i
].val
== dwAccessType
) {
968 access_type_str
= access_type
[i
].name
;
972 TRACE(" access type : %s\n", access_type_str
);
974 dump_INTERNET_FLAGS(dwFlags
);
977 /* Clear any error information */
978 INTERNET_SetLastError(0);
980 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
981 SetLastError(ERROR_INVALID_PARAMETER
);
985 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
987 SetLastError(ERROR_OUTOFMEMORY
);
991 lpwai
->hdr
.htype
= WH_HINIT
;
992 lpwai
->hdr
.dwFlags
= dwFlags
;
993 lpwai
->accessType
= dwAccessType
;
994 lpwai
->proxyUsername
= NULL
;
995 lpwai
->proxyPassword
= NULL
;
996 lpwai
->connect_timeout
= connect_timeout
;
998 lpwai
->agent
= heap_strdupW(lpszAgent
);
999 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1000 INTERNET_ConfigureProxy( lpwai
);
1001 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1002 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1003 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1006 TRACE("returning %p\n", lpwai
);
1008 return lpwai
->hdr
.hInternet
;
1012 /***********************************************************************
1013 * InternetOpenA (WININET.@)
1015 * Per-application initialization of wininet
1018 * HINTERNET on success
1022 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1023 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1025 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1028 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1029 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1031 szAgent
= heap_strdupAtoW(lpszAgent
);
1032 szProxy
= heap_strdupAtoW(lpszProxy
);
1033 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1035 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1039 heap_free(szBypass
);
1043 /***********************************************************************
1044 * InternetGetLastResponseInfoA (WININET.@)
1046 * Return last wininet error description on the calling thread
1049 * TRUE on success of writing to buffer
1053 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1054 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1056 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1062 *lpdwError
= lpwite
->dwError
;
1063 if (lpwite
->dwError
)
1065 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1066 *lpdwBufferLength
= strlen(lpszBuffer
);
1069 *lpdwBufferLength
= 0;
1074 *lpdwBufferLength
= 0;
1080 /***********************************************************************
1081 * InternetGetLastResponseInfoW (WININET.@)
1083 * Return last wininet error description on the calling thread
1086 * TRUE on success of writing to buffer
1090 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1091 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1093 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1099 *lpdwError
= lpwite
->dwError
;
1100 if (lpwite
->dwError
)
1102 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1103 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1106 *lpdwBufferLength
= 0;
1111 *lpdwBufferLength
= 0;
1117 /***********************************************************************
1118 * InternetGetConnectedState (WININET.@)
1120 * Return connected state
1124 * if lpdwStatus is not null, return the status (off line,
1125 * modem, lan...) in it.
1126 * FALSE if not connected
1128 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1130 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1133 WARN("always returning LAN connection.\n");
1134 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1140 /***********************************************************************
1141 * InternetGetConnectedStateExW (WININET.@)
1143 * Return connected state
1147 * lpdwStatus [O] Flags specifying the status of the internet connection.
1148 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1149 * dwNameLen [I] Size of the buffer, in characters.
1150 * dwReserved [I] Reserved. Must be set to 0.
1154 * if lpdwStatus is not null, return the status (off line,
1155 * modem, lan...) in it.
1156 * FALSE if not connected
1159 * If the system has no available network connections, an empty string is
1160 * stored in lpszConnectionName. If there is a LAN connection, a localized
1161 * "LAN Connection" string is stored. Presumably, if only a dial-up
1162 * connection is available then the name of the dial-up connection is
1163 * returned. Why any application, other than the "Internet Settings" CPL,
1164 * would want to use this function instead of the simpler InternetGetConnectedStateW
1165 * function is beyond me.
1167 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1168 DWORD dwNameLen
, DWORD dwReserved
)
1170 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1177 WARN("always returning LAN connection.\n");
1178 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1180 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1184 /***********************************************************************
1185 * InternetGetConnectedStateExA (WININET.@)
1187 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1188 DWORD dwNameLen
, DWORD dwReserved
)
1190 LPWSTR lpwszConnectionName
= NULL
;
1193 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1195 if (lpszConnectionName
&& dwNameLen
> 0)
1196 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1198 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1200 if (rc
&& lpwszConnectionName
)
1202 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1203 dwNameLen
, NULL
, NULL
);
1204 heap_free(lpwszConnectionName
);
1210 /***********************************************************************
1211 * InternetConnectW (WININET.@)
1213 * Open a ftp, gopher or http session
1216 * HINTERNET a session handle on success
1220 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1221 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1222 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1223 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1226 HINTERNET rc
= NULL
;
1227 DWORD res
= ERROR_SUCCESS
;
1229 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1230 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1231 dwService
, dwFlags
, dwContext
);
1233 if (!lpszServerName
)
1235 SetLastError(ERROR_INVALID_PARAMETER
);
1239 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1240 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1242 res
= ERROR_INVALID_HANDLE
;
1248 case INTERNET_SERVICE_FTP
:
1249 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1250 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1252 res
= INTERNET_GetLastError();
1255 case INTERNET_SERVICE_HTTP
:
1256 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1257 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1260 case INTERNET_SERVICE_GOPHER
:
1266 WININET_Release( &hIC
->hdr
);
1268 TRACE("returning %p\n", rc
);
1274 /***********************************************************************
1275 * InternetConnectA (WININET.@)
1277 * Open a ftp, gopher or http session
1280 * HINTERNET a session handle on success
1284 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1285 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1286 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1287 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1289 HINTERNET rc
= NULL
;
1290 LPWSTR szServerName
;
1294 szServerName
= heap_strdupAtoW(lpszServerName
);
1295 szUserName
= heap_strdupAtoW(lpszUserName
);
1296 szPassword
= heap_strdupAtoW(lpszPassword
);
1298 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1299 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1301 heap_free(szServerName
);
1302 heap_free(szUserName
);
1303 heap_free(szPassword
);
1308 /***********************************************************************
1309 * InternetFindNextFileA (WININET.@)
1311 * Continues a file search from a previous call to FindFirstFile
1318 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1321 WIN32_FIND_DATAW fd
;
1323 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1325 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1329 /***********************************************************************
1330 * InternetFindNextFileW (WININET.@)
1332 * Continues a file search from a previous call to FindFirstFile
1339 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1341 object_header_t
*hdr
;
1346 hdr
= get_handle_object(hFind
);
1348 WARN("Invalid handle\n");
1349 SetLastError(ERROR_INVALID_HANDLE
);
1353 if(hdr
->vtbl
->FindNextFileW
) {
1354 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1356 WARN("Handle doesn't support NextFile\n");
1357 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1360 WININET_Release(hdr
);
1362 if(res
!= ERROR_SUCCESS
)
1364 return res
== ERROR_SUCCESS
;
1367 /***********************************************************************
1368 * InternetCloseHandle (WININET.@)
1370 * Generic close handle function
1377 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1379 object_header_t
*obj
;
1381 TRACE("%p\n", hInternet
);
1383 obj
= get_handle_object( hInternet
);
1385 SetLastError(ERROR_INVALID_HANDLE
);
1389 invalidate_handle(obj
);
1390 WININET_Release(obj
);
1396 /***********************************************************************
1397 * ConvertUrlComponentValue (Internal)
1399 * Helper function for InternetCrackUrlA
1402 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1403 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1404 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1406 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1407 if (*dwComponentLen
!= 0)
1409 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1410 if (*lppszComponent
== NULL
)
1414 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1415 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1418 *lppszComponent
= NULL
;
1420 *dwComponentLen
= nASCIILength
;
1424 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1425 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1426 (*lppszComponent
)[ncpylen
]=0;
1427 *dwComponentLen
= ncpylen
;
1433 /***********************************************************************
1434 * InternetCrackUrlA (WININET.@)
1436 * See InternetCrackUrlW.
1438 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1439 LPURL_COMPONENTSA lpUrlComponents
)
1442 URL_COMPONENTSW UCW
;
1444 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1445 *scheme
= NULL
, *extra
= NULL
;
1447 TRACE("(%s %u %x %p)\n",
1448 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1449 dwUrlLength
, dwFlags
, lpUrlComponents
);
1451 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1452 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1454 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1460 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1462 /* if dwUrlLength=-1 then nLength includes null but length to
1463 InternetCrackUrlW should not include it */
1464 if (dwUrlLength
== -1) nLength
--;
1466 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1467 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1468 lpwszUrl
[nLength
] = '\0';
1470 memset(&UCW
,0,sizeof(UCW
));
1471 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1472 if (lpUrlComponents
->dwHostNameLength
)
1474 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1475 if (lpUrlComponents
->lpszHostName
)
1477 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1478 UCW
.lpszHostName
= hostname
;
1481 if (lpUrlComponents
->dwUserNameLength
)
1483 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1484 if (lpUrlComponents
->lpszUserName
)
1486 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1487 UCW
.lpszUserName
= username
;
1490 if (lpUrlComponents
->dwPasswordLength
)
1492 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1493 if (lpUrlComponents
->lpszPassword
)
1495 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1496 UCW
.lpszPassword
= password
;
1499 if (lpUrlComponents
->dwUrlPathLength
)
1501 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1502 if (lpUrlComponents
->lpszUrlPath
)
1504 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1505 UCW
.lpszUrlPath
= path
;
1508 if (lpUrlComponents
->dwSchemeLength
)
1510 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1511 if (lpUrlComponents
->lpszScheme
)
1513 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1514 UCW
.lpszScheme
= scheme
;
1517 if (lpUrlComponents
->dwExtraInfoLength
)
1519 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1520 if (lpUrlComponents
->lpszExtraInfo
)
1522 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1523 UCW
.lpszExtraInfo
= extra
;
1526 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1528 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1529 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1530 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1531 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1532 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1533 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1534 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1535 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1536 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1537 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1538 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1539 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1541 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1542 lpUrlComponents
->nPort
= UCW
.nPort
;
1544 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1545 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1546 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1547 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1548 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1550 heap_free(lpwszUrl
);
1551 heap_free(hostname
);
1552 heap_free(username
);
1553 heap_free(password
);
1560 static const WCHAR url_schemes
[][7] =
1563 {'g','o','p','h','e','r',0},
1564 {'h','t','t','p',0},
1565 {'h','t','t','p','s',0},
1566 {'f','i','l','e',0},
1567 {'n','e','w','s',0},
1568 {'m','a','i','l','t','o',0},
1572 /***********************************************************************
1573 * GetInternetSchemeW (internal)
1579 * INTERNET_SCHEME_UNKNOWN on failure
1582 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1586 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1588 if(lpszScheme
==NULL
)
1589 return INTERNET_SCHEME_UNKNOWN
;
1591 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1592 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1593 return INTERNET_SCHEME_FIRST
+ i
;
1595 return INTERNET_SCHEME_UNKNOWN
;
1598 /***********************************************************************
1599 * SetUrlComponentValueW (Internal)
1601 * Helper function for InternetCrackUrlW
1604 * lppszComponent [O] Holds the returned string
1605 * dwComponentLen [I] Holds the size of lppszComponent
1606 * [O] Holds the length of the string in lppszComponent without '\0'
1607 * lpszStart [I] Holds the string to copy from
1608 * len [I] Holds the length of lpszStart without '\0'
1615 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1617 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1619 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1622 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1624 if (*lppszComponent
== NULL
)
1626 *lppszComponent
= (LPWSTR
)lpszStart
;
1627 *dwComponentLen
= len
;
1631 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1632 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1633 (*lppszComponent
)[ncpylen
] = '\0';
1634 *dwComponentLen
= ncpylen
;
1641 /***********************************************************************
1642 * InternetCrackUrlW (WININET.@)
1644 * Break up URL into its components
1650 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1651 LPURL_COMPONENTSW lpUC
)
1655 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1658 LPCWSTR lpszParam
= NULL
;
1659 BOOL found_colon
= FALSE
;
1660 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1661 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1662 LPWSTR lpszUrl_decode
= NULL
;
1663 DWORD dwUrlLength
= dwUrlLength_orig
;
1665 TRACE("(%s %u %x %p)\n",
1666 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1667 dwUrlLength
, dwFlags
, lpUC
);
1669 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1671 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1674 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1676 if (dwFlags
& ICU_DECODE
)
1679 DWORD len
= dwUrlLength
+ 1;
1681 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1683 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1686 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1687 url_tmp
[dwUrlLength
] = 0;
1688 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1691 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1694 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1697 lpszUrl
= lpszUrl_decode
;
1703 /* Determine if the URI is absolute. */
1704 while (lpszap
- lpszUrl
< dwUrlLength
)
1706 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1718 lpszcp
= lpszUrl
; /* Relative url */
1725 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1729 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1730 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1732 /* Parse <params> */
1733 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1735 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1737 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1738 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1741 /* Get scheme first. */
1742 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1743 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1744 lpszUrl
, lpszcp
- lpszUrl
);
1746 /* Eat ':' in protocol. */
1749 /* double slash indicates the net_loc portion is present */
1750 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1754 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1758 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1760 lpszNetLoc
= lpszParam
;
1762 else if (!lpszNetLoc
)
1763 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1771 /* [<user>[<:password>]@]<host>[:<port>] */
1772 /* First find the user and password if they exist */
1774 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1775 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1777 /* username and password not specified. */
1778 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1779 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1781 else /* Parse out username and password */
1783 LPCWSTR lpszUser
= lpszcp
;
1784 LPCWSTR lpszPasswd
= lpszHost
;
1786 while (lpszcp
< lpszHost
)
1789 lpszPasswd
= lpszcp
;
1794 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1795 lpszUser
, lpszPasswd
- lpszUser
);
1797 if (lpszPasswd
!= lpszHost
)
1799 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1800 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1801 lpszHost
- lpszPasswd
);
1803 lpszcp
++; /* Advance to beginning of host */
1806 /* Parse <host><:port> */
1809 lpszPort
= lpszNetLoc
;
1811 /* special case for res:// URLs: there is no port here, so the host is the
1812 entire string up to the first '/' */
1813 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1815 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1816 lpszHost
, lpszPort
- lpszHost
);
1821 while (lpszcp
< lpszNetLoc
)
1829 /* If the scheme is "file" and the host is just one letter, it's not a host */
1830 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1833 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1838 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1839 lpszHost
, lpszPort
- lpszHost
);
1840 if (lpszPort
!= lpszNetLoc
)
1841 lpUC
->nPort
= atoiW(++lpszPort
);
1842 else switch (lpUC
->nScheme
)
1844 case INTERNET_SCHEME_HTTP
:
1845 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1847 case INTERNET_SCHEME_HTTPS
:
1848 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1850 case INTERNET_SCHEME_FTP
:
1851 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1853 case INTERNET_SCHEME_GOPHER
:
1854 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
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 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2243 SetLastError(ERROR_INVALID_PARAMETER
);
2247 hdr
= get_handle_object(hFile
);
2249 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2253 if(hdr
->vtbl
->ReadFileEx
)
2254 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2255 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2257 WININET_Release(hdr
);
2259 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2260 res
, lpBuffersOut
->dwBufferLength
);
2262 if(res
!= ERROR_SUCCESS
)
2264 return res
== ERROR_SUCCESS
;
2267 /***********************************************************************
2268 * InternetReadFileExW (WININET.@)
2270 * InternetReadFileExA()
2272 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2273 DWORD dwFlags
, DWORD_PTR dwContext
)
2275 object_header_t
*hdr
;
2276 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2278 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2280 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2281 SetLastError(ERROR_INVALID_PARAMETER
);
2285 hdr
= get_handle_object(hFile
);
2287 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2291 if(hdr
->vtbl
->ReadFileEx
)
2292 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2293 dwFlags
, dwContext
);
2295 WININET_Release(hdr
);
2297 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2298 res
, lpBuffer
->dwBufferLength
);
2300 if(res
!= ERROR_SUCCESS
)
2302 return res
== ERROR_SUCCESS
;
2305 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2307 /* FIXME: This function currently handles more options than it should. Options requiring
2308 * proper handles should be moved to proper functions */
2310 case INTERNET_OPTION_HTTP_VERSION
:
2311 if (*size
< sizeof(HTTP_VERSION_INFO
))
2312 return ERROR_INSUFFICIENT_BUFFER
;
2315 * Presently hardcoded to 1.1
2317 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2318 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2319 *size
= sizeof(HTTP_VERSION_INFO
);
2321 return ERROR_SUCCESS
;
2323 case INTERNET_OPTION_CONNECTED_STATE
:
2324 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2326 if (*size
< sizeof(ULONG
))
2327 return ERROR_INSUFFICIENT_BUFFER
;
2329 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2330 *size
= sizeof(ULONG
);
2332 return ERROR_SUCCESS
;
2334 case INTERNET_OPTION_PROXY
: {
2338 TRACE("Getting global proxy info\n");
2339 memset(&ai
, 0, sizeof(appinfo_t
));
2340 INTERNET_ConfigureProxy(&ai
);
2342 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2343 APPINFO_Destroy(&ai
.hdr
);
2347 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2348 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2350 if (*size
< sizeof(ULONG
))
2351 return ERROR_INSUFFICIENT_BUFFER
;
2353 *(ULONG
*)buffer
= max_conns
;
2354 *size
= sizeof(ULONG
);
2356 return ERROR_SUCCESS
;
2358 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2359 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2361 if (*size
< sizeof(ULONG
))
2362 return ERROR_INSUFFICIENT_BUFFER
;
2364 *(ULONG
*)buffer
= max_1_0_conns
;
2365 *size
= sizeof(ULONG
);
2367 return ERROR_SUCCESS
;
2369 case INTERNET_OPTION_SECURITY_FLAGS
:
2370 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2371 return ERROR_SUCCESS
;
2373 case INTERNET_OPTION_VERSION
: {
2374 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2376 TRACE("INTERNET_OPTION_VERSION\n");
2378 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2379 return ERROR_INSUFFICIENT_BUFFER
;
2381 memcpy(buffer
, &info
, sizeof(info
));
2382 *size
= sizeof(info
);
2384 return ERROR_SUCCESS
;
2387 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2388 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2389 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2390 DWORD res
= ERROR_SUCCESS
, i
;
2394 TRACE("Getting global proxy info\n");
2395 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2398 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2400 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2402 return ERROR_INSUFFICIENT_BUFFER
;
2405 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2406 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2407 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2409 switch (optionW
->dwOption
) {
2410 case INTERNET_PER_CONN_FLAGS
:
2412 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2414 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2417 case INTERNET_PER_CONN_PROXY_SERVER
:
2419 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2421 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2424 case INTERNET_PER_CONN_PROXY_BYPASS
:
2426 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2428 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2431 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2432 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2433 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2434 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2435 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2436 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2437 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2438 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2442 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2443 res
= ERROR_INVALID_PARAMETER
;
2451 case INTERNET_OPTION_REQUEST_FLAGS
:
2452 case INTERNET_OPTION_USER_AGENT
:
2454 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2455 case INTERNET_OPTION_POLICY
:
2456 return ERROR_INVALID_PARAMETER
;
2457 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2458 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2460 if (*size
< sizeof(ULONG
))
2461 return ERROR_INSUFFICIENT_BUFFER
;
2463 *(ULONG
*)buffer
= connect_timeout
;
2464 *size
= sizeof(ULONG
);
2466 return ERROR_SUCCESS
;
2469 FIXME("Stub for %d\n", option
);
2470 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2473 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2476 case INTERNET_OPTION_CONTEXT_VALUE
:
2478 return ERROR_INVALID_PARAMETER
;
2480 if (*size
< sizeof(DWORD_PTR
)) {
2481 *size
= sizeof(DWORD_PTR
);
2482 return ERROR_INSUFFICIENT_BUFFER
;
2485 return ERROR_INVALID_PARAMETER
;
2487 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2488 *size
= sizeof(DWORD_PTR
);
2489 return ERROR_SUCCESS
;
2491 case INTERNET_OPTION_REQUEST_FLAGS
:
2492 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2493 *size
= sizeof(DWORD
);
2494 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2496 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2497 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2498 WARN("Called on global option %u\n", option
);
2499 return ERROR_INTERNET_INVALID_OPERATION
;
2502 /* FIXME: we shouldn't call it here */
2503 return query_global_option(option
, buffer
, size
, unicode
);
2506 /***********************************************************************
2507 * InternetQueryOptionW (WININET.@)
2509 * Queries an options on the specified handle
2516 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2517 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2519 object_header_t
*hdr
;
2520 DWORD res
= ERROR_INVALID_HANDLE
;
2522 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2525 hdr
= get_handle_object(hInternet
);
2527 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2528 WININET_Release(hdr
);
2531 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2534 if(res
!= ERROR_SUCCESS
)
2536 return res
== ERROR_SUCCESS
;
2539 /***********************************************************************
2540 * InternetQueryOptionA (WININET.@)
2542 * Queries an options on the specified handle
2549 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2550 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2552 object_header_t
*hdr
;
2553 DWORD res
= ERROR_INVALID_HANDLE
;
2555 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2558 hdr
= get_handle_object(hInternet
);
2560 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2561 WININET_Release(hdr
);
2564 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2567 if(res
!= ERROR_SUCCESS
)
2569 return res
== ERROR_SUCCESS
;
2572 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2575 case INTERNET_OPTION_CALLBACK
:
2576 WARN("Not settable option %u\n", option
);
2577 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2578 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2579 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2580 WARN("Called on global option %u\n", option
);
2581 return ERROR_INTERNET_INVALID_OPERATION
;
2584 return ERROR_INTERNET_INVALID_OPTION
;
2587 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2590 case INTERNET_OPTION_CALLBACK
:
2591 WARN("Not global option %u\n", option
);
2592 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2594 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2595 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2597 if(size
!= sizeof(max_conns
))
2598 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2600 return ERROR_BAD_ARGUMENTS
;
2602 max_conns
= *(ULONG
*)buf
;
2603 return ERROR_SUCCESS
;
2605 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2606 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2608 if(size
!= sizeof(max_1_0_conns
))
2609 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2611 return ERROR_BAD_ARGUMENTS
;
2613 max_1_0_conns
= *(ULONG
*)buf
;
2614 return ERROR_SUCCESS
;
2616 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2617 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2619 if(size
!= sizeof(connect_timeout
))
2620 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2622 return ERROR_BAD_ARGUMENTS
;
2624 connect_timeout
= *(ULONG
*)buf
;
2625 return ERROR_SUCCESS
;
2627 case INTERNET_OPTION_SETTINGS_CHANGED
:
2628 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2629 collect_connections(COLLECT_CONNECTIONS
);
2630 return ERROR_SUCCESS
;
2633 return ERROR_INTERNET_INVALID_OPTION
;
2636 /***********************************************************************
2637 * InternetSetOptionW (WININET.@)
2639 * Sets an options on the specified handle
2646 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2647 LPVOID lpBuffer
, DWORD dwBufferLength
)
2649 object_header_t
*lpwhh
;
2653 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2655 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2657 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2659 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2661 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2663 WININET_Release(lpwhh
);
2665 if(res
!= ERROR_SUCCESS
)
2668 return res
== ERROR_SUCCESS
;
2673 case INTERNET_OPTION_HTTP_VERSION
:
2675 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2676 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2679 case INTERNET_OPTION_ERROR_MASK
:
2682 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2684 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2685 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2686 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2687 SetLastError(ERROR_INVALID_PARAMETER
);
2689 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2690 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2693 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2694 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2697 case INTERNET_OPTION_PROXY
:
2699 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2701 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2703 SetLastError(ERROR_INVALID_PARAMETER
);
2708 EnterCriticalSection( &WININET_cs
);
2709 free_global_proxy();
2710 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2713 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2715 global_proxy
->proxyEnabled
= 1;
2716 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2717 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2721 global_proxy
->proxyEnabled
= 0;
2722 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2725 LeaveCriticalSection( &WININET_cs
);
2729 /* In general, each type of object should handle
2730 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2731 * get silently dropped.
2733 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2734 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2739 case INTERNET_OPTION_CODEPAGE
:
2741 ULONG codepage
= *(ULONG
*)lpBuffer
;
2742 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2745 case INTERNET_OPTION_REQUEST_PRIORITY
:
2747 ULONG priority
= *(ULONG
*)lpBuffer
;
2748 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2751 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2753 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2754 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2757 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2759 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2760 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2763 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2764 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2766 case INTERNET_OPTION_END_BROWSER_SESSION
:
2767 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2769 case INTERNET_OPTION_CONNECTED_STATE
:
2770 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2772 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2773 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2775 case INTERNET_OPTION_SEND_TIMEOUT
:
2776 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2777 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2779 ULONG timeout
= *(ULONG
*)lpBuffer
;
2780 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2783 case INTERNET_OPTION_CONNECT_RETRIES
:
2785 ULONG retries
= *(ULONG
*)lpBuffer
;
2786 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2789 case INTERNET_OPTION_CONTEXT_VALUE
:
2793 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2796 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2798 SetLastError(ERROR_INVALID_PARAMETER
);
2802 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2805 case INTERNET_OPTION_SECURITY_FLAGS
:
2806 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2808 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2809 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2811 case INTERNET_OPTION_HTTP_DECODING
:
2812 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2813 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2816 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2817 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2818 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2821 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2822 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2823 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2826 case INTERNET_OPTION_CODEPAGE_PATH
:
2827 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2828 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2831 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2832 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2833 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2836 case INTERNET_OPTION_IDN
:
2837 FIXME("INTERNET_OPTION_IDN; STUB\n");
2838 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2841 case INTERNET_OPTION_POLICY
:
2842 SetLastError(ERROR_INVALID_PARAMETER
);
2845 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2846 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2851 INTERNET_LoadProxySettings(&pi
);
2853 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2854 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2856 switch (option
->dwOption
) {
2857 case INTERNET_PER_CONN_PROXY_SERVER
:
2858 heap_free(pi
.proxy
);
2859 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2862 case INTERNET_PER_CONN_FLAGS
:
2863 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2864 pi
.proxyEnabled
= 1;
2867 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2868 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2869 pi
.proxyEnabled
= 0;
2873 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2874 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2875 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2876 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2877 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2878 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2879 case INTERNET_PER_CONN_PROXY_BYPASS
:
2880 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2884 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2885 SetLastError(ERROR_INVALID_PARAMETER
);
2890 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2895 ret
= (res
== ERROR_SUCCESS
);
2899 FIXME("Option %d STUB\n",dwOption
);
2900 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2906 WININET_Release( lpwhh
);
2912 /***********************************************************************
2913 * InternetSetOptionA (WININET.@)
2915 * Sets an options on the specified handle.
2922 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2923 LPVOID lpBuffer
, DWORD dwBufferLength
)
2931 case INTERNET_OPTION_PROXY
:
2933 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2934 LPINTERNET_PROXY_INFOW piw
;
2935 DWORD proxlen
, prbylen
;
2938 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2939 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2940 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2941 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
2942 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2943 piw
->dwAccessType
= pi
->dwAccessType
;
2944 prox
= (LPWSTR
) &piw
[1];
2945 prby
= &prox
[proxlen
+1];
2946 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2947 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2948 piw
->lpszProxy
= prox
;
2949 piw
->lpszProxyBypass
= prby
;
2952 case INTERNET_OPTION_USER_AGENT
:
2953 case INTERNET_OPTION_USERNAME
:
2954 case INTERNET_OPTION_PASSWORD
:
2955 case INTERNET_OPTION_PROXY_USERNAME
:
2956 case INTERNET_OPTION_PROXY_PASSWORD
:
2957 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
2958 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
2959 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
2961 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2963 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
2964 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
2965 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2966 wbuffer
= heap_alloc(wlen
);
2969 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
2970 if (listA
->pszConnection
)
2972 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
2973 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
2974 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
2977 listW
->pszConnection
= NULL
;
2978 listW
->dwOptionCount
= listA
->dwOptionCount
;
2979 listW
->dwOptionError
= listA
->dwOptionError
;
2980 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
2982 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
2983 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
2984 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
2986 optW
->dwOption
= optA
->dwOption
;
2988 switch (optA
->dwOption
) {
2989 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2990 case INTERNET_PER_CONN_PROXY_BYPASS
:
2991 case INTERNET_PER_CONN_PROXY_SERVER
:
2992 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2993 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2994 if (optA
->Value
.pszValue
)
2996 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
2997 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
2998 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3001 optW
->Value
.pszValue
= NULL
;
3003 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3004 case INTERNET_PER_CONN_FLAGS
:
3005 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3006 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3008 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3009 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3012 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3013 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3021 wlen
= dwBufferLength
;
3024 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3026 if( lpBuffer
!= wbuffer
)
3028 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3030 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3032 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3033 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3034 switch (opt
->dwOption
) {
3035 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3036 case INTERNET_PER_CONN_PROXY_BYPASS
:
3037 case INTERNET_PER_CONN_PROXY_SERVER
:
3038 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3039 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3040 heap_free( opt
->Value
.pszValue
);
3046 heap_free( list
->pOptions
);
3048 heap_free( wbuffer
);
3055 /***********************************************************************
3056 * InternetSetOptionExA (WININET.@)
3058 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
3059 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3061 FIXME("Flags %08x ignored\n", dwFlags
);
3062 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3065 /***********************************************************************
3066 * InternetSetOptionExW (WININET.@)
3068 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
3069 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
3071 FIXME("Flags %08x ignored\n", dwFlags
);
3072 if( dwFlags
& ~ISO_VALID_FLAGS
)
3074 SetLastError( ERROR_INVALID_PARAMETER
);
3077 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
3080 static const WCHAR WININET_wkday
[7][4] =
3081 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3082 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3083 static const WCHAR WININET_month
[12][4] =
3084 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3085 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3086 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3088 /***********************************************************************
3089 * InternetTimeFromSystemTimeA (WININET.@)
3091 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
3094 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
3096 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3098 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3100 SetLastError(ERROR_INVALID_PARAMETER
);
3104 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3106 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3110 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
3111 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
3116 /***********************************************************************
3117 * InternetTimeFromSystemTimeW (WININET.@)
3119 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
3121 static const WCHAR date
[] =
3122 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3123 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3125 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
3127 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
3129 SetLastError(ERROR_INVALID_PARAMETER
);
3133 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
3135 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3139 sprintfW( string
, date
,
3140 WININET_wkday
[time
->wDayOfWeek
],
3142 WININET_month
[time
->wMonth
- 1],
3151 /***********************************************************************
3152 * InternetTimeToSystemTimeA (WININET.@)
3154 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3159 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
3161 stringW
= heap_strdupAtoW(string
);
3164 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
3165 heap_free( stringW
);
3170 /***********************************************************************
3171 * InternetTimeToSystemTimeW (WININET.@)
3173 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
3176 const WCHAR
*s
= string
;
3179 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
3181 if (!string
|| !time
) return FALSE
;
3183 /* Windows does this too */
3184 GetSystemTime( time
);
3186 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3187 * a SYSTEMTIME structure.
3190 while (*s
&& !isalphaW( *s
)) s
++;
3191 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3192 time
->wDayOfWeek
= 7;
3194 for (i
= 0; i
< 7; i
++)
3196 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
3197 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
3198 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
3200 time
->wDayOfWeek
= i
;
3205 if (time
->wDayOfWeek
> 6) return TRUE
;
3206 while (*s
&& !isdigitW( *s
)) s
++;
3207 time
->wDay
= strtolW( s
, &end
, 10 );
3210 while (*s
&& !isalphaW( *s
)) s
++;
3211 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
3214 for (i
= 0; i
< 12; i
++)
3216 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
3217 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
3218 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
3220 time
->wMonth
= i
+ 1;
3224 if (time
->wMonth
== 0) return TRUE
;
3226 while (*s
&& !isdigitW( *s
)) s
++;
3227 if (*s
== '\0') return TRUE
;
3228 time
->wYear
= strtolW( s
, &end
, 10 );
3231 while (*s
&& !isdigitW( *s
)) s
++;
3232 if (*s
== '\0') return TRUE
;
3233 time
->wHour
= strtolW( s
, &end
, 10 );
3236 while (*s
&& !isdigitW( *s
)) s
++;
3237 if (*s
== '\0') return TRUE
;
3238 time
->wMinute
= strtolW( s
, &end
, 10 );
3241 while (*s
&& !isdigitW( *s
)) s
++;
3242 if (*s
== '\0') return TRUE
;
3243 time
->wSecond
= strtolW( s
, &end
, 10 );
3246 time
->wMilliseconds
= 0;
3250 /***********************************************************************
3251 * InternetCheckConnectionW (WININET.@)
3253 * Pings a requested host to check internet connection
3256 * TRUE on success and FALSE on failure. If a failure then
3257 * ERROR_NOT_CONNECTED is placed into GetLastError
3260 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3263 * this is a kludge which runs the resident ping program and reads the output.
3265 * Anyone have a better idea?
3269 static const CHAR ping
[] = "ping -c 1 ";
3270 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
3271 CHAR
*command
= NULL
;
3272 WCHAR hostW
[INTERNET_MAX_HOST_NAME_LENGTH
];
3280 * Crack or set the Address
3282 if (lpszUrl
== NULL
)
3285 * According to the doc we are supposed to use the ip for the next
3286 * server in the WnInet internal server database. I have
3287 * no idea what that is or how to get it.
3289 * So someone needs to implement this.
3291 FIXME("Unimplemented with URL of NULL\n");
3296 URL_COMPONENTSW components
;
3298 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
3299 components
.lpszHostName
= (LPWSTR
)hostW
;
3300 components
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3302 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
3305 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
3306 port
= components
.nPort
;
3307 TRACE("port: %d\n", port
);
3310 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
3312 struct sockaddr_storage saddr
;
3313 socklen_t sa_len
= sizeof(saddr
);
3316 if (!GetAddress(hostW
, port
, (struct sockaddr
*)&saddr
, &sa_len
))
3318 fd
= socket(saddr
.ss_family
, SOCK_STREAM
, 0);
3321 if (connect(fd
, (struct sockaddr
*)&saddr
, sa_len
) == 0)
3329 * Build our ping command
3331 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
3332 command
= heap_alloc(strlen(ping
)+len
+strlen(redirect
));
3333 strcpy(command
,ping
);
3334 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
3335 strcat(command
,redirect
);
3337 TRACE("Ping command is : %s\n",command
);
3339 status
= system(command
);
3341 TRACE("Ping returned a code of %i\n",status
);
3343 /* Ping return code of 0 indicates success */
3349 heap_free( command
);
3351 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
3357 /***********************************************************************
3358 * InternetCheckConnectionA (WININET.@)
3360 * Pings a requested host to check internet connection
3363 * TRUE on success and FALSE on failure. If a failure then
3364 * ERROR_NOT_CONNECTED is placed into GetLastError
3367 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
3373 url
= heap_strdupAtoW(lpszUrl
);
3378 rc
= InternetCheckConnectionW(url
, dwFlags
, dwReserved
);
3385 /**********************************************************
3386 * INTERNET_InternetOpenUrlW (internal)
3391 * handle of connection or NULL on failure
3393 static HINTERNET
INTERNET_InternetOpenUrlW(appinfo_t
*hIC
, LPCWSTR lpszUrl
,
3394 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3396 URL_COMPONENTSW urlComponents
;
3397 WCHAR protocol
[INTERNET_MAX_SCHEME_LENGTH
];
3398 WCHAR hostName
[INTERNET_MAX_HOST_NAME_LENGTH
];
3399 WCHAR userName
[INTERNET_MAX_USER_NAME_LENGTH
];
3400 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
3401 WCHAR path
[INTERNET_MAX_PATH_LENGTH
];
3403 HINTERNET client
= NULL
, client1
= NULL
;
3406 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3407 dwHeadersLength
, dwFlags
, dwContext
);
3409 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
3410 urlComponents
.lpszScheme
= protocol
;
3411 urlComponents
.dwSchemeLength
= INTERNET_MAX_SCHEME_LENGTH
;
3412 urlComponents
.lpszHostName
= hostName
;
3413 urlComponents
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
3414 urlComponents
.lpszUserName
= userName
;
3415 urlComponents
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
3416 urlComponents
.lpszPassword
= password
;
3417 urlComponents
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
3418 urlComponents
.lpszUrlPath
= path
;
3419 urlComponents
.dwUrlPathLength
= INTERNET_MAX_PATH_LENGTH
;
3420 urlComponents
.lpszExtraInfo
= extra
;
3421 urlComponents
.dwExtraInfoLength
= 1024;
3422 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3424 switch(urlComponents
.nScheme
) {
3425 case INTERNET_SCHEME_FTP
:
3426 if(urlComponents
.nPort
== 0)
3427 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3428 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3429 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3432 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3433 if(client1
== NULL
) {
3434 InternetCloseHandle(client
);
3439 case INTERNET_SCHEME_HTTP
:
3440 case INTERNET_SCHEME_HTTPS
: {
3441 static const WCHAR szStars
[] = { '*','/','*', 0 };
3442 LPCWSTR accept
[2] = { szStars
, NULL
};
3443 if(urlComponents
.nPort
== 0) {
3444 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3445 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3447 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3449 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) dwFlags
|= INTERNET_FLAG_SECURE
;
3451 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3452 res
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3453 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
, &client
);
3454 if(res
!= ERROR_SUCCESS
) {
3455 INTERNET_SetLastError(res
);
3459 if (urlComponents
.dwExtraInfoLength
) {
3461 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3463 if (!(path_extra
= heap_alloc(len
* sizeof(WCHAR
))))
3465 InternetCloseHandle(client
);
3468 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3469 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3470 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3471 heap_free(path_extra
);
3474 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3476 if(client1
== NULL
) {
3477 InternetCloseHandle(client
);
3480 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3481 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3482 GetLastError() != ERROR_IO_PENDING
) {
3483 InternetCloseHandle(client1
);
3488 case INTERNET_SCHEME_GOPHER
:
3489 /* gopher doesn't seem to be implemented in wine, but it's supposed
3490 * to be supported by InternetOpenUrlA. */
3492 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3496 TRACE(" %p <--\n", client1
);
3501 /**********************************************************
3502 * InternetOpenUrlW (WININET.@)
3507 * handle of connection or NULL on failure
3518 static void AsyncInternetOpenUrlProc(task_header_t
*hdr
)
3520 open_url_task_t
*task
= (open_url_task_t
*)hdr
;
3522 TRACE("%p\n", task
->hdr
.hdr
);
3524 INTERNET_InternetOpenUrlW((appinfo_t
*)task
->hdr
.hdr
, task
->url
, task
->headers
,
3525 task
->headers_len
, task
->flags
, task
->context
);
3526 heap_free(task
->url
);
3527 heap_free(task
->headers
);
3530 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3531 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3533 HINTERNET ret
= NULL
;
3534 appinfo_t
*hIC
= NULL
;
3536 if (TRACE_ON(wininet
)) {
3537 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3538 dwHeadersLength
, dwFlags
, dwContext
);
3540 dump_INTERNET_FLAGS(dwFlags
);
3545 SetLastError(ERROR_INVALID_PARAMETER
);
3549 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
3550 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3551 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3555 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3556 open_url_task_t
*task
;
3558 task
= alloc_async_task(&hIC
->hdr
, AsyncInternetOpenUrlProc
, sizeof(*task
));
3559 task
->url
= heap_strdupW(lpszUrl
);
3560 task
->headers
= heap_strdupW(lpszHeaders
);
3561 task
->headers_len
= dwHeadersLength
;
3562 task
->flags
= dwFlags
;
3563 task
->context
= dwContext
;
3565 INTERNET_AsyncCall(&task
->hdr
);
3566 SetLastError(ERROR_IO_PENDING
);
3568 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3573 WININET_Release( &hIC
->hdr
);
3574 TRACE(" %p <--\n", ret
);
3579 /**********************************************************
3580 * InternetOpenUrlA (WININET.@)
3585 * handle of connection or NULL on failure
3587 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3588 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3590 HINTERNET rc
= NULL
;
3591 DWORD lenHeaders
= 0;
3592 LPWSTR szUrl
= NULL
;
3593 LPWSTR szHeaders
= NULL
;
3598 szUrl
= heap_strdupAtoW(lpszUrl
);
3604 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3605 szHeaders
= heap_alloc(lenHeaders
*sizeof(WCHAR
));
3610 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3613 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3614 lenHeaders
, dwFlags
, dwContext
);
3617 heap_free(szHeaders
);
3622 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3624 LPWITHREADERROR lpwite
= heap_alloc(sizeof(*lpwite
));
3628 lpwite
->dwError
= 0;
3629 lpwite
->response
[0] = '\0';
3632 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3641 /***********************************************************************
3642 * INTERNET_SetLastError (internal)
3644 * Set last thread specific error
3649 void INTERNET_SetLastError(DWORD dwError
)
3651 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3654 lpwite
= INTERNET_AllocThreadError();
3656 SetLastError(dwError
);
3658 lpwite
->dwError
= dwError
;
3662 /***********************************************************************
3663 * INTERNET_GetLastError (internal)
3665 * Get last thread specific error
3670 DWORD
INTERNET_GetLastError(void)
3672 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3673 if (!lpwite
) return 0;
3674 /* TlsGetValue clears last error, so set it again here */
3675 SetLastError(lpwite
->dwError
);
3676 return lpwite
->dwError
;
3680 /***********************************************************************
3681 * INTERNET_WorkerThreadFunc (internal)
3683 * Worker thread execution function
3688 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3690 task_header_t
*task
= lpvParam
;
3695 WININET_Release(task
->hdr
);
3698 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
3700 heap_free(TlsGetValue(g_dwTlsErrIndex
));
3701 TlsSetValue(g_dwTlsErrIndex
, NULL
);
3706 void *alloc_async_task(object_header_t
*hdr
, async_task_proc_t proc
, size_t size
)
3708 task_header_t
*task
;
3710 task
= heap_alloc(size
);
3714 task
->hdr
= WININET_AddRef(hdr
);
3719 /***********************************************************************
3720 * INTERNET_AsyncCall (internal)
3722 * Retrieves work request from queue
3727 DWORD
INTERNET_AsyncCall(task_header_t
*task
)
3733 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, task
, WT_EXECUTELONGFUNCTION
);
3737 return ERROR_INTERNET_ASYNC_THREAD_FAILED
;
3739 return ERROR_SUCCESS
;
3743 /***********************************************************************
3744 * INTERNET_GetResponseBuffer (internal)
3749 LPSTR
INTERNET_GetResponseBuffer(void)
3751 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3753 lpwite
= INTERNET_AllocThreadError();
3755 return lpwite
->response
;
3758 /***********************************************************************
3759 * INTERNET_GetNextLine (internal)
3761 * Parse next line in directory string listing
3764 * Pointer to beginning of next line
3769 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3771 // ReactOS: use select instead of poll
3774 BOOL bSuccess
= FALSE
;
3776 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3781 FD_SET(nSocket
,&infd
);
3782 tv
.tv_sec
= RESPONSE_TIMEOUT
;
3785 while (nRecv
< MAX_REPLY_LEN
)
3787 if (select(0, &infd
, NULL
, NULL
, &tv
) > 0)
3789 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3791 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3795 if (lpszBuffer
[nRecv
] == '\n')
3800 if (lpszBuffer
[nRecv
] != '\r')
3805 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3813 lpszBuffer
[nRecv
] = '\0';
3815 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3824 /**********************************************************
3825 * InternetQueryDataAvailable (WININET.@)
3827 * Determines how much data is available to be read.
3830 * TRUE on success, FALSE if an error occurred. If
3831 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3832 * no data is presently available, FALSE is returned with
3833 * the last error ERROR_IO_PENDING; a callback with status
3834 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3835 * data is available.
3837 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3838 LPDWORD lpdwNumberOfBytesAvailable
,
3839 DWORD dwFlags
, DWORD_PTR dwContext
)
3841 object_header_t
*hdr
;
3844 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3846 hdr
= get_handle_object( hFile
);
3848 SetLastError(ERROR_INVALID_HANDLE
);
3852 if(hdr
->vtbl
->QueryDataAvailable
) {
3853 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailable
, dwFlags
, dwContext
);
3855 WARN("wrong handle\n");
3856 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3859 WININET_Release(hdr
);
3861 if(res
!= ERROR_SUCCESS
)
3863 return res
== ERROR_SUCCESS
;
3867 /***********************************************************************
3868 * InternetLockRequestFile (WININET.@)
3870 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3877 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3884 /***********************************************************************
3885 * InternetAutodial (WININET.@)
3887 * On windows this function is supposed to dial the default internet
3888 * connection. We don't want to have Wine dial out to the internet so
3889 * we return TRUE by default. It might be nice to check if we are connected.
3896 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3900 /* Tell that we are connected to the internet. */
3904 /***********************************************************************
3905 * InternetAutodialHangup (WININET.@)
3907 * Hangs up a connection made with InternetAutodial
3916 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3920 /* we didn't dial, we don't disconnect */
3924 /***********************************************************************
3925 * InternetCombineUrlA (WININET.@)
3927 * Combine a base URL with a relative URL
3935 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3936 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3941 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3943 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3944 dwFlags
^= ICU_NO_ENCODE
;
3945 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3950 /***********************************************************************
3951 * InternetCombineUrlW (WININET.@)
3953 * Combine a base URL with a relative URL
3961 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3962 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3967 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3969 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3970 dwFlags
^= ICU_NO_ENCODE
;
3971 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3976 /* max port num is 65535 => 5 digits */
3977 #define MAX_WORD_DIGITS 5
3979 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3980 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3981 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3982 (url)->dw##component##Length : strlen((url)->lpsz##component))
3984 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3986 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3987 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3989 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3990 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3992 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3993 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3995 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3996 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3999 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
4005 /* opaque urls do not fit into the standard url hierarchy and don't have
4006 * two following slashes */
4007 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
4009 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
4010 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
4011 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
4012 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
4013 (nScheme
!= INTERNET_SCHEME_FILE
);
4016 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
4019 if (scheme
< INTERNET_SCHEME_FIRST
)
4021 index
= scheme
- INTERNET_SCHEME_FIRST
;
4022 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
4024 return (LPCWSTR
)url_schemes
[index
];
4027 /* we can calculate using ansi strings because we're just
4028 * calculating string length, not size
4030 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
4031 LPDWORD lpdwUrlLength
)
4033 INTERNET_SCHEME nScheme
;
4037 if (lpUrlComponents
->lpszScheme
)
4039 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4040 *lpdwUrlLength
+= dwLen
;
4041 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4047 nScheme
= lpUrlComponents
->nScheme
;
4049 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4050 nScheme
= INTERNET_SCHEME_HTTP
;
4051 scheme
= INTERNET_GetSchemeString(nScheme
);
4052 *lpdwUrlLength
+= strlenW(scheme
);
4055 (*lpdwUrlLength
)++; /* ':' */
4056 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4057 *lpdwUrlLength
+= strlen("//");
4059 if (lpUrlComponents
->lpszUserName
)
4061 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4062 *lpdwUrlLength
+= strlen("@");
4066 if (lpUrlComponents
->lpszPassword
)
4068 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4073 if (lpUrlComponents
->lpszPassword
)
4075 *lpdwUrlLength
+= strlen(":");
4076 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4079 if (lpUrlComponents
->lpszHostName
)
4081 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4083 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4085 char szPort
[MAX_WORD_DIGITS
+1];
4087 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
4088 *lpdwUrlLength
+= strlen(szPort
);
4089 *lpdwUrlLength
+= strlen(":");
4092 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4093 (*lpdwUrlLength
)++; /* '/' */
4096 if (lpUrlComponents
->lpszUrlPath
)
4097 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4099 if (lpUrlComponents
->lpszExtraInfo
)
4100 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4105 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
4109 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
4111 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
4112 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
4113 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
4114 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
4115 urlCompW
->nPort
= lpUrlComponents
->nPort
;
4116 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
4117 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
4118 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
4119 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
4121 if (lpUrlComponents
->lpszScheme
)
4123 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
4124 urlCompW
->lpszScheme
= heap_alloc(len
* sizeof(WCHAR
));
4125 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
4126 -1, urlCompW
->lpszScheme
, len
);
4129 if (lpUrlComponents
->lpszHostName
)
4131 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
4132 urlCompW
->lpszHostName
= heap_alloc(len
* sizeof(WCHAR
));
4133 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
4134 -1, urlCompW
->lpszHostName
, len
);
4137 if (lpUrlComponents
->lpszUserName
)
4139 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
4140 urlCompW
->lpszUserName
= heap_alloc(len
* sizeof(WCHAR
));
4141 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
4142 -1, urlCompW
->lpszUserName
, len
);
4145 if (lpUrlComponents
->lpszPassword
)
4147 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
4148 urlCompW
->lpszPassword
= heap_alloc(len
* sizeof(WCHAR
));
4149 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
4150 -1, urlCompW
->lpszPassword
, len
);
4153 if (lpUrlComponents
->lpszUrlPath
)
4155 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
4156 urlCompW
->lpszUrlPath
= heap_alloc(len
* sizeof(WCHAR
));
4157 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
4158 -1, urlCompW
->lpszUrlPath
, len
);
4161 if (lpUrlComponents
->lpszExtraInfo
)
4163 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
4164 urlCompW
->lpszExtraInfo
= heap_alloc(len
* sizeof(WCHAR
));
4165 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
4166 -1, urlCompW
->lpszExtraInfo
, len
);
4170 /***********************************************************************
4171 * InternetCreateUrlA (WININET.@)
4173 * See InternetCreateUrlW.
4175 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
4176 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4180 URL_COMPONENTSW urlCompW
;
4182 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4184 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4186 SetLastError(ERROR_INVALID_PARAMETER
);
4190 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
4193 urlW
= heap_alloc(*lpdwUrlLength
* sizeof(WCHAR
));
4195 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
4197 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
4198 *lpdwUrlLength
/= sizeof(WCHAR
);
4200 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4201 * minus one, so add one to leave room for NULL terminator
4204 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
4206 heap_free(urlCompW
.lpszScheme
);
4207 heap_free(urlCompW
.lpszHostName
);
4208 heap_free(urlCompW
.lpszUserName
);
4209 heap_free(urlCompW
.lpszPassword
);
4210 heap_free(urlCompW
.lpszUrlPath
);
4211 heap_free(urlCompW
.lpszExtraInfo
);
4216 /***********************************************************************
4217 * InternetCreateUrlW (WININET.@)
4219 * Creates a URL from its component parts.
4222 * lpUrlComponents [I] URL Components.
4223 * dwFlags [I] Flags. See notes.
4224 * lpszUrl [I] Buffer in which to store the created URL.
4225 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4226 * lpszUrl in characters. On output, the number of bytes
4227 * required to store the URL including terminator.
4231 * The dwFlags parameter can be zero or more of the following:
4232 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4239 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
4240 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
4243 INTERNET_SCHEME nScheme
;
4245 static const WCHAR slashSlashW
[] = {'/','/'};
4246 static const WCHAR fmtW
[] = {'%','u',0};
4248 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
4250 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
4252 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
4256 if (!calc_url_length(lpUrlComponents
, &dwLen
))
4259 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
4261 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
4262 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
4266 *lpdwUrlLength
= dwLen
;
4271 if (lpUrlComponents
->lpszScheme
)
4273 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
4274 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
4277 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
4282 nScheme
= lpUrlComponents
->nScheme
;
4284 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
4285 nScheme
= INTERNET_SCHEME_HTTP
;
4287 scheme
= INTERNET_GetSchemeString(nScheme
);
4288 dwLen
= strlenW(scheme
);
4289 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
4293 /* all schemes are followed by at least a colon */
4297 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
4299 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
4300 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
4303 if (lpUrlComponents
->lpszUserName
)
4305 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
4306 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
4309 if (lpUrlComponents
->lpszPassword
)
4314 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
4315 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
4323 if (lpUrlComponents
->lpszHostName
)
4325 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
4326 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
4329 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
4331 WCHAR szPort
[MAX_WORD_DIGITS
+1];
4333 sprintfW(szPort
, fmtW
, lpUrlComponents
->nPort
);
4336 dwLen
= strlenW(szPort
);
4337 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
4341 /* add slash between hostname and path if necessary */
4342 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
4349 if (lpUrlComponents
->lpszUrlPath
)
4351 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
4352 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
4356 if (lpUrlComponents
->lpszExtraInfo
)
4358 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
4359 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
4368 /***********************************************************************
4369 * InternetConfirmZoneCrossingA (WININET.@)
4372 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
4374 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
4375 return ERROR_SUCCESS
;
4378 /***********************************************************************
4379 * InternetConfirmZoneCrossingW (WININET.@)
4382 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
4384 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
4385 return ERROR_SUCCESS
;
4388 static DWORD zone_preference
= 3;
4390 /***********************************************************************
4391 * PrivacySetZonePreferenceW (WININET.@)
4393 DWORD WINAPI
PrivacySetZonePreferenceW( DWORD zone
, DWORD type
, DWORD
template, LPCWSTR preference
)
4395 FIXME( "%x %x %x %s: stub\n", zone
, type
, template, debugstr_w(preference
) );
4397 zone_preference
= template;
4401 /***********************************************************************
4402 * PrivacyGetZonePreferenceW (WININET.@)
4404 DWORD WINAPI
PrivacyGetZonePreferenceW( DWORD zone
, DWORD type
, LPDWORD
template,
4405 LPWSTR preference
, LPDWORD length
)
4407 FIXME( "%x %x %p %p %p: stub\n", zone
, type
, template, preference
, length
);
4409 if (template) *template = zone_preference
;
4413 /***********************************************************************
4414 * InternetGetSecurityInfoByURLA (WININET.@)
4416 BOOL WINAPI
InternetGetSecurityInfoByURLA(LPSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4421 TRACE("(%s %p %p)\n", debugstr_a(lpszURL
), ppCertChain
, pdwSecureFlags
);
4423 url
= heap_strdupAtoW(lpszURL
);
4427 res
= InternetGetSecurityInfoByURLW(url
, ppCertChain
, pdwSecureFlags
);
4432 /***********************************************************************
4433 * InternetGetSecurityInfoByURLW (WININET.@)
4435 BOOL WINAPI
InternetGetSecurityInfoByURLW(LPCWSTR lpszURL
, PCCERT_CHAIN_CONTEXT
*ppCertChain
, DWORD
*pdwSecureFlags
)
4437 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
4438 URL_COMPONENTSW url
= {sizeof(url
)};
4442 TRACE("(%s %p %p)\n", debugstr_w(lpszURL
), ppCertChain
, pdwSecureFlags
);
4444 url
.lpszHostName
= hostname
;
4445 url
.dwHostNameLength
= sizeof(hostname
)/sizeof(WCHAR
);
4447 res
= InternetCrackUrlW(lpszURL
, 0, 0, &url
);
4448 if(!res
|| url
.nScheme
!= INTERNET_SCHEME_HTTPS
) {
4449 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4453 server
= get_server(hostname
, url
.nPort
, TRUE
, FALSE
);
4455 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4459 if(server
->cert_chain
) {
4460 const CERT_CHAIN_CONTEXT
*chain_dup
;
4462 chain_dup
= CertDuplicateCertificateChain(server
->cert_chain
);
4464 *ppCertChain
= chain_dup
;
4465 *pdwSecureFlags
= server
->security_flags
& _SECURITY_ERROR_FLAGS_MASK
;
4470 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
4474 server_release(server
);
4478 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
4479 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4481 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4482 lpdwConnection
, dwReserved
);
4483 return ERROR_SUCCESS
;
4486 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
4487 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
4489 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
4490 lpdwConnection
, dwReserved
);
4491 return ERROR_SUCCESS
;
4494 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4496 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
4500 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
4502 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
4506 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
4508 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
4509 return ERROR_SUCCESS
;
4512 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
4515 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
4516 debugstr_w(pwszTarget
), pbHexHash
);
4520 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4522 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4526 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4528 FIXME("(%p, %08lx) stub\n", a
, b
);
4532 DWORD WINAPI
ShowClientAuthCerts(HWND parent
)
4534 FIXME("%p: stub\n", parent
);