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
34 CHAR response
[MAX_REPLY_LEN
];
35 } WITHREADERROR
, *LPWITHREADERROR
;
37 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
38 HMODULE WININET_hModule
;
40 static CRITICAL_SECTION WININET_cs
;
41 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
44 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
45 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
47 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
49 static object_header_t
**handle_table
;
50 static UINT_PTR next_handle
;
51 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
)
250 TlsFree(g_dwTlsErrIndex
);
254 WININET_hModule
= hinstDLL
;
257 case DLL_THREAD_ATTACH
:
260 case DLL_THREAD_DETACH
:
261 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
263 heap_free(TlsGetValue(g_dwTlsErrIndex
));
267 case DLL_PROCESS_DETACH
:
268 if (lpvReserved
) break;
269 collect_connections(COLLECT_CLEANUP
);
274 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
276 heap_free(TlsGetValue(g_dwTlsErrIndex
));
277 TlsFree(g_dwTlsErrIndex
);
284 /***********************************************************************
285 * DllInstall (WININET.@)
287 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
289 FIXME("(%x %s): stub\n", bInstall
, debugstr_w(cmdline
));
293 /***********************************************************************
294 * INTERNET_SaveProxySettings
296 * Stores the proxy settings given by lpwai into the registry
299 * ERROR_SUCCESS if no error, or error code on fail
301 static LONG
INTERNET_SaveProxySettings( proxyinfo_t
*lpwpi
)
306 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
309 if ((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
))))
317 if ((ret
= RegSetValueExW( key
, szProxyServer
, 0, REG_SZ
, (BYTE
*)lpwpi
->proxy
, sizeof(WCHAR
) * (lstrlenW(lpwpi
->proxy
) + 1))))
325 if ((ret
= RegDeleteValueW( key
, szProxyServer
)))
333 return ERROR_SUCCESS
;
336 /***********************************************************************
337 * INTERNET_FindProxyForProtocol
339 * Searches the proxy string for a proxy of the given protocol.
340 * Returns the found proxy, or the default proxy if none of the given
344 * szProxy [In] proxy string to search
345 * proto [In] protocol to search for, e.g. "http"
346 * foundProxy [Out] found proxy
347 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
350 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
351 * *foundProxyLen is set to the required size in WCHARs, including the
352 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
354 BOOL
INTERNET_FindProxyForProtocol(LPCWSTR szProxy
, LPCWSTR proto
, WCHAR
*foundProxy
, DWORD
*foundProxyLen
)
359 TRACE("(%s, %s)\n", debugstr_w(szProxy
), debugstr_w(proto
));
361 /* First, look for the specified protocol (proto=scheme://host:port) */
362 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
366 if (!(end
= strchrW(ptr
, ' ')))
367 end
= ptr
+ strlenW(ptr
);
368 if ((equal
= strchrW(ptr
, '=')) && equal
< end
&&
369 equal
- ptr
== strlenW(proto
) &&
370 !strncmpiW(proto
, ptr
, strlenW(proto
)))
372 if (end
- equal
> *foundProxyLen
)
374 WARN("buffer too short for %s\n",
375 debugstr_wn(equal
+ 1, end
- equal
- 1));
376 *foundProxyLen
= end
- equal
;
377 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
381 memcpy(foundProxy
, equal
+ 1, (end
- equal
) * sizeof(WCHAR
));
382 foundProxy
[end
- equal
] = 0;
393 /* It wasn't found: look for no protocol */
394 for (ptr
= szProxy
; !ret
&& ptr
&& *ptr
; )
398 if (!(end
= strchrW(ptr
, ' ')))
399 end
= ptr
+ strlenW(ptr
);
400 if (!strchrW(ptr
, '='))
402 if (end
- ptr
+ 1 > *foundProxyLen
)
404 WARN("buffer too short for %s\n",
405 debugstr_wn(ptr
, end
- ptr
));
406 *foundProxyLen
= end
- ptr
+ 1;
407 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
411 memcpy(foundProxy
, ptr
, (end
- ptr
) * sizeof(WCHAR
));
412 foundProxy
[end
- ptr
] = 0;
423 TRACE("found proxy for %s: %s\n", debugstr_w(proto
),
424 debugstr_w(foundProxy
));
428 /***********************************************************************
429 * InternetInitializeAutoProxyDll (WININET.@)
431 * Setup the internal proxy
440 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
443 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
447 /***********************************************************************
448 * DetectAutoProxyUrl (WININET.@)
450 * Auto detect the proxy url
456 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
457 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
460 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
464 static void FreeProxyInfo( proxyinfo_t
*lpwpi
)
466 heap_free(lpwpi
->proxy
);
467 heap_free(lpwpi
->proxyBypass
);
468 heap_free(lpwpi
->proxyUsername
);
469 heap_free(lpwpi
->proxyPassword
);
472 static proxyinfo_t
*global_proxy
;
474 static void free_global_proxy( void )
476 EnterCriticalSection( &WININET_cs
);
479 FreeProxyInfo( global_proxy
);
480 heap_free( global_proxy
);
482 LeaveCriticalSection( &WININET_cs
);
485 static BOOL
parse_proxy_url( proxyinfo_t
*info
, const WCHAR
*url
)
487 static const WCHAR fmt
[] = {'%','s',':','%','u',0};
488 WCHAR hostname
[INTERNET_MAX_HOST_NAME_LENGTH
];
489 WCHAR username
[INTERNET_MAX_USER_NAME_LENGTH
];
490 WCHAR password
[INTERNET_MAX_PASSWORD_LENGTH
];
493 hostname
[0] = username
[0] = password
[0] = 0;
494 memset( &uc
, 0, sizeof(uc
) );
495 uc
.dwStructSize
= sizeof(uc
);
496 uc
.lpszHostName
= hostname
;
497 uc
.dwHostNameLength
= INTERNET_MAX_HOST_NAME_LENGTH
;
498 uc
.lpszUserName
= username
;
499 uc
.dwUserNameLength
= INTERNET_MAX_USER_NAME_LENGTH
;
500 uc
.lpszPassword
= password
;
501 uc
.dwPasswordLength
= INTERNET_MAX_PASSWORD_LENGTH
;
503 if (!InternetCrackUrlW( url
, 0, 0, &uc
)) return FALSE
;
506 if (!(info
->proxy
= heap_strdupW( url
))) return FALSE
;
507 info
->proxyUsername
= NULL
;
508 info
->proxyPassword
= NULL
;
511 if (!(info
->proxy
= heap_alloc( (strlenW(hostname
) + 12) * sizeof(WCHAR
) ))) return FALSE
;
512 sprintfW( info
->proxy
, fmt
, hostname
, uc
.nPort
);
514 if (!username
[0]) info
->proxyUsername
= NULL
;
515 else if (!(info
->proxyUsername
= heap_strdupW( username
)))
517 heap_free( info
->proxy
);
520 if (!password
[0]) info
->proxyPassword
= NULL
;
521 else if (!(info
->proxyPassword
= heap_strdupW( password
)))
523 heap_free( info
->proxyUsername
);
524 heap_free( info
->proxy
);
530 /***********************************************************************
531 * INTERNET_LoadProxySettings
533 * Loads proxy information from process-wide global settings, the registry,
534 * or the environment into lpwpi.
536 * The caller should call FreeProxyInfo when done with lpwpi.
539 * The proxy may be specified in the form 'http=proxy.my.org'
540 * Presumably that means there can be ftp=ftpproxy.my.org too.
542 static LONG
INTERNET_LoadProxySettings( proxyinfo_t
*lpwpi
)
549 memset( lpwpi
, 0, sizeof(*lpwpi
) );
551 EnterCriticalSection( &WININET_cs
);
554 lpwpi
->proxyEnabled
= global_proxy
->proxyEnabled
;
555 lpwpi
->proxy
= heap_strdupW( global_proxy
->proxy
);
556 lpwpi
->proxyBypass
= heap_strdupW( global_proxy
->proxyBypass
);
558 LeaveCriticalSection( &WININET_cs
);
560 if ((ret
= RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)))
562 FreeProxyInfo( lpwpi
);
567 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&lpwpi
->proxyEnabled
, &len
) || type
!= REG_DWORD
)
569 lpwpi
->proxyEnabled
= 0;
570 if((ret
= RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&lpwpi
->proxyEnabled
, sizeof(DWORD
) )))
572 FreeProxyInfo( lpwpi
);
578 if (!(envproxy
= getenv( "http_proxy" )) || lpwpi
->proxyEnabled
)
580 /* figure out how much memory the proxy setting takes */
581 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
584 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
586 if (!(szProxy
= heap_alloc(len
)))
589 FreeProxyInfo( lpwpi
);
590 return ERROR_OUTOFMEMORY
;
592 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
594 /* find the http proxy, and strip away everything else */
595 p
= strstrW( szProxy
, szHttp
);
598 p
+= lstrlenW( szHttp
);
599 lstrcpyW( szProxy
, p
);
601 p
= strchrW( szProxy
, ';' );
604 FreeProxyInfo( lpwpi
);
605 lpwpi
->proxy
= szProxy
;
606 lpwpi
->proxyBypass
= NULL
;
608 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi
->proxy
));
612 TRACE("No proxy server settings in registry.\n");
613 FreeProxyInfo( lpwpi
);
615 lpwpi
->proxyBypass
= NULL
;
622 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
623 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
626 return ERROR_OUTOFMEMORY
;
628 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
630 FreeProxyInfo( lpwpi
);
631 if (parse_proxy_url( lpwpi
, envproxyW
))
633 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi
->proxy
));
634 lpwpi
->proxyEnabled
= 1;
635 lpwpi
->proxyBypass
= NULL
;
639 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW
));
640 lpwpi
->proxyEnabled
= 0;
642 lpwpi
->proxyBypass
= NULL
;
644 heap_free( envproxyW
);
647 if (lpwpi
->proxyEnabled
)
649 TRACE("Proxy is enabled.\n");
651 if (!(envproxy
= getenv( "no_proxy" )))
653 /* figure out how much memory the proxy setting takes */
654 if (!RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
658 if (!(szProxy
= heap_alloc(len
)))
661 return ERROR_OUTOFMEMORY
;
663 RegQueryValueExW( key
, szProxyOverride
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
665 heap_free( lpwpi
->proxyBypass
);
666 lpwpi
->proxyBypass
= szProxy
;
668 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
672 heap_free( lpwpi
->proxyBypass
);
673 lpwpi
->proxyBypass
= NULL
;
675 TRACE("No proxy bypass server settings in registry.\n");
682 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
683 if (!(envproxyW
= heap_alloc(len
* sizeof(WCHAR
))))
686 return ERROR_OUTOFMEMORY
;
688 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
690 heap_free( lpwpi
->proxyBypass
);
691 lpwpi
->proxyBypass
= envproxyW
;
693 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi
->proxyBypass
));
696 else TRACE("Proxy is disabled.\n");
699 return ERROR_SUCCESS
;
702 /***********************************************************************
703 * INTERNET_ConfigureProxy
705 static BOOL
INTERNET_ConfigureProxy( appinfo_t
*lpwai
)
709 if (INTERNET_LoadProxySettings( &wpi
))
712 if (wpi
.proxyEnabled
)
714 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai
->proxy
), debugstr_w(lpwai
->proxyBypass
));
716 lpwai
->accessType
= INTERNET_OPEN_TYPE_PROXY
;
717 lpwai
->proxy
= wpi
.proxy
;
718 lpwai
->proxyBypass
= wpi
.proxyBypass
;
719 lpwai
->proxyUsername
= wpi
.proxyUsername
;
720 lpwai
->proxyPassword
= wpi
.proxyPassword
;
724 lpwai
->accessType
= INTERNET_OPEN_TYPE_DIRECT
;
729 /***********************************************************************
730 * dump_INTERNET_FLAGS
732 * Helper function to TRACE the internet flags.
738 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
740 #define FE(x) { x, #x }
741 static const wininet_flag_info flag
[] = {
742 FE(INTERNET_FLAG_RELOAD
),
743 FE(INTERNET_FLAG_RAW_DATA
),
744 FE(INTERNET_FLAG_EXISTING_CONNECT
),
745 FE(INTERNET_FLAG_ASYNC
),
746 FE(INTERNET_FLAG_PASSIVE
),
747 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
748 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
749 FE(INTERNET_FLAG_FROM_CACHE
),
750 FE(INTERNET_FLAG_SECURE
),
751 FE(INTERNET_FLAG_KEEP_CONNECTION
),
752 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
753 FE(INTERNET_FLAG_READ_PREFETCH
),
754 FE(INTERNET_FLAG_NO_COOKIES
),
755 FE(INTERNET_FLAG_NO_AUTH
),
756 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
757 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
758 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
759 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
760 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
761 FE(INTERNET_FLAG_RESYNCHRONIZE
),
762 FE(INTERNET_FLAG_HYPERLINK
),
763 FE(INTERNET_FLAG_NO_UI
),
764 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
765 FE(INTERNET_FLAG_CACHE_ASYNC
),
766 FE(INTERNET_FLAG_FORMS_SUBMIT
),
767 FE(INTERNET_FLAG_NEED_FILE
),
768 FE(INTERNET_FLAG_TRANSFER_ASCII
),
769 FE(INTERNET_FLAG_TRANSFER_BINARY
)
774 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
775 if (flag
[i
].val
& dwFlags
) {
776 TRACE(" %s", flag
[i
].name
);
777 dwFlags
&= ~flag
[i
].val
;
781 TRACE(" Unknown flags (%08x)\n", dwFlags
);
786 /***********************************************************************
787 * INTERNET_CloseHandle (internal)
789 * Close internet handle
792 static VOID
APPINFO_Destroy(object_header_t
*hdr
)
794 appinfo_t
*lpwai
= (appinfo_t
*)hdr
;
798 heap_free(lpwai
->agent
);
799 heap_free(lpwai
->proxy
);
800 heap_free(lpwai
->proxyBypass
);
801 heap_free(lpwai
->proxyUsername
);
802 heap_free(lpwai
->proxyPassword
);
805 static DWORD
APPINFO_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
807 appinfo_t
*ai
= (appinfo_t
*)hdr
;
810 case INTERNET_OPTION_HANDLE_TYPE
:
811 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
813 if (*size
< sizeof(ULONG
))
814 return ERROR_INSUFFICIENT_BUFFER
;
816 *size
= sizeof(DWORD
);
817 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
818 return ERROR_SUCCESS
;
820 case INTERNET_OPTION_USER_AGENT
: {
823 TRACE("INTERNET_OPTION_USER_AGENT\n");
828 DWORD len
= ai
->agent
? strlenW(ai
->agent
) : 0;
830 *size
= (len
+ 1) * sizeof(WCHAR
);
831 if(!buffer
|| bufsize
< *size
)
832 return ERROR_INSUFFICIENT_BUFFER
;
835 strcpyW(buffer
, ai
->agent
);
837 *(WCHAR
*)buffer
= 0;
838 /* If the buffer is copied, the returned length doesn't include
839 * the NULL terminator.
844 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, NULL
, 0, NULL
, NULL
);
847 if(!buffer
|| bufsize
< *size
)
848 return ERROR_INSUFFICIENT_BUFFER
;
851 WideCharToMultiByte(CP_ACP
, 0, ai
->agent
, -1, buffer
, *size
, NULL
, NULL
);
854 /* If the buffer is copied, the returned length doesn't include
855 * the NULL terminator.
860 return ERROR_SUCCESS
;
863 case INTERNET_OPTION_PROXY
:
864 if(!size
) return ERROR_INVALID_PARAMETER
;
866 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
867 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
868 LPWSTR proxy
, proxy_bypass
;
871 proxyBytesRequired
= (lstrlenW(ai
->proxy
) + 1) * sizeof(WCHAR
);
873 proxyBypassBytesRequired
= (lstrlenW(ai
->proxyBypass
) + 1) * sizeof(WCHAR
);
874 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
876 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
877 return ERROR_INSUFFICIENT_BUFFER
;
879 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
880 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
882 pi
->dwAccessType
= ai
->accessType
;
883 pi
->lpszProxy
= NULL
;
884 pi
->lpszProxyBypass
= NULL
;
886 lstrcpyW(proxy
, ai
->proxy
);
887 pi
->lpszProxy
= proxy
;
890 if (ai
->proxyBypass
) {
891 lstrcpyW(proxy_bypass
, ai
->proxyBypass
);
892 pi
->lpszProxyBypass
= proxy_bypass
;
895 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
896 return ERROR_SUCCESS
;
898 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
899 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
900 LPSTR proxy
, proxy_bypass
;
903 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, NULL
, 0, NULL
, NULL
);
905 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1,
906 NULL
, 0, NULL
, NULL
);
907 if (!pi
|| *size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
909 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
910 return ERROR_INSUFFICIENT_BUFFER
;
912 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
913 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
915 pi
->dwAccessType
= ai
->accessType
;
916 pi
->lpszProxy
= NULL
;
917 pi
->lpszProxyBypass
= NULL
;
919 WideCharToMultiByte(CP_ACP
, 0, ai
->proxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
920 pi
->lpszProxy
= proxy
;
923 if (ai
->proxyBypass
) {
924 WideCharToMultiByte(CP_ACP
, 0, ai
->proxyBypass
, -1, proxy_bypass
,
925 proxyBypassBytesRequired
, NULL
, NULL
);
926 pi
->lpszProxyBypass
= proxy_bypass
;
929 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
930 return ERROR_SUCCESS
;
933 case INTERNET_OPTION_CONNECT_TIMEOUT
:
934 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
936 if (*size
< sizeof(ULONG
))
937 return ERROR_INSUFFICIENT_BUFFER
;
939 *(ULONG
*)buffer
= ai
->connect_timeout
;
940 *size
= sizeof(ULONG
);
942 return ERROR_SUCCESS
;
945 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
948 static DWORD
APPINFO_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
950 appinfo_t
*ai
= (appinfo_t
*)hdr
;
953 case INTERNET_OPTION_CONNECT_TIMEOUT
:
954 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
956 if(size
!= sizeof(connect_timeout
))
957 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
959 return ERROR_BAD_ARGUMENTS
;
961 ai
->connect_timeout
= *(ULONG
*)buf
;
962 return ERROR_SUCCESS
;
963 case INTERNET_OPTION_USER_AGENT
:
964 heap_free(ai
->agent
);
965 if (!(ai
->agent
= heap_strdupW(buf
))) return ERROR_OUTOFMEMORY
;
966 return ERROR_SUCCESS
;
969 return INET_SetOption(hdr
, option
, buf
, size
);
972 static const object_vtbl_t APPINFOVtbl
= {
984 /***********************************************************************
985 * InternetOpenW (WININET.@)
987 * Per-application initialization of wininet
990 * HINTERNET on success
994 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
995 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
997 appinfo_t
*lpwai
= NULL
;
999 if (TRACE_ON(wininet
)) {
1000 #define FE(x) { x, #x }
1001 static const wininet_flag_info access_type
[] = {
1002 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
1003 FE(INTERNET_OPEN_TYPE_DIRECT
),
1004 FE(INTERNET_OPEN_TYPE_PROXY
),
1005 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
1009 const char *access_type_str
= "Unknown";
1011 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1012 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1013 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
1014 if (access_type
[i
].val
== dwAccessType
) {
1015 access_type_str
= access_type
[i
].name
;
1019 TRACE(" access type : %s\n", access_type_str
);
1021 dump_INTERNET_FLAGS(dwFlags
);
1024 /* Clear any error information */
1025 INTERNET_SetLastError(0);
1027 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1028 SetLastError(ERROR_INVALID_PARAMETER
);
1032 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1034 SetLastError(ERROR_OUTOFMEMORY
);
1038 lpwai
->hdr
.htype
= WH_HINIT
;
1039 lpwai
->hdr
.dwFlags
= dwFlags
;
1040 lpwai
->accessType
= dwAccessType
;
1041 lpwai
->proxyUsername
= NULL
;
1042 lpwai
->proxyPassword
= NULL
;
1043 lpwai
->connect_timeout
= connect_timeout
;
1045 lpwai
->agent
= heap_strdupW(lpszAgent
);
1046 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1047 INTERNET_ConfigureProxy( lpwai
);
1048 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1049 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1050 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1053 TRACE("returning %p\n", lpwai
);
1055 return lpwai
->hdr
.hInternet
;
1059 /***********************************************************************
1060 * InternetOpenA (WININET.@)
1062 * Per-application initialization of wininet
1065 * HINTERNET on success
1069 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1070 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1072 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1075 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1076 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1078 szAgent
= heap_strdupAtoW(lpszAgent
);
1079 szProxy
= heap_strdupAtoW(lpszProxy
);
1080 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1082 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1086 heap_free(szBypass
);
1090 /***********************************************************************
1091 * InternetGetLastResponseInfoA (WININET.@)
1093 * Return last wininet error description on the calling thread
1096 * TRUE on success of writing to buffer
1100 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1101 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1103 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1109 *lpdwError
= lpwite
->dwError
;
1110 if (lpwite
->dwError
)
1112 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1113 *lpdwBufferLength
= strlen(lpszBuffer
);
1116 *lpdwBufferLength
= 0;
1121 *lpdwBufferLength
= 0;
1127 /***********************************************************************
1128 * InternetGetLastResponseInfoW (WININET.@)
1130 * Return last wininet error description on the calling thread
1133 * TRUE on success of writing to buffer
1137 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1138 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1140 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1146 *lpdwError
= lpwite
->dwError
;
1147 if (lpwite
->dwError
)
1149 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1150 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1153 *lpdwBufferLength
= 0;
1158 *lpdwBufferLength
= 0;
1164 /***********************************************************************
1165 * InternetGetConnectedState (WININET.@)
1167 * Return connected state
1171 * if lpdwStatus is not null, return the status (off line,
1172 * modem, lan...) in it.
1173 * FALSE if not connected
1175 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1177 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1180 WARN("always returning LAN connection.\n");
1181 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1187 /***********************************************************************
1188 * InternetGetConnectedStateExW (WININET.@)
1190 * Return connected state
1194 * lpdwStatus [O] Flags specifying the status of the internet connection.
1195 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1196 * dwNameLen [I] Size of the buffer, in characters.
1197 * dwReserved [I] Reserved. Must be set to 0.
1201 * if lpdwStatus is not null, return the status (off line,
1202 * modem, lan...) in it.
1203 * FALSE if not connected
1206 * If the system has no available network connections, an empty string is
1207 * stored in lpszConnectionName. If there is a LAN connection, a localized
1208 * "LAN Connection" string is stored. Presumably, if only a dial-up
1209 * connection is available then the name of the dial-up connection is
1210 * returned. Why any application, other than the "Internet Settings" CPL,
1211 * would want to use this function instead of the simpler InternetGetConnectedStateW
1212 * function is beyond me.
1214 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1215 DWORD dwNameLen
, DWORD dwReserved
)
1217 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1224 WARN("always returning LAN connection.\n");
1225 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1228 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1229 * the resource, avoid it as we must not change the buffer in this case */
1230 if(lpszConnectionName
&& dwNameLen
) {
1231 *lpszConnectionName
= '\0';
1232 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1239 /***********************************************************************
1240 * InternetGetConnectedStateExA (WININET.@)
1242 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1243 DWORD dwNameLen
, DWORD dwReserved
)
1245 LPWSTR lpwszConnectionName
= NULL
;
1248 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1250 if (lpszConnectionName
&& dwNameLen
> 0)
1251 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1253 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1255 if (rc
&& lpwszConnectionName
)
1256 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1257 dwNameLen
, NULL
, NULL
);
1259 heap_free(lpwszConnectionName
);
1264 /***********************************************************************
1265 * InternetConnectW (WININET.@)
1267 * Open a ftp, gopher or http session
1270 * HINTERNET a session handle on success
1274 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1275 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1276 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1277 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1280 HINTERNET rc
= NULL
;
1281 DWORD res
= ERROR_SUCCESS
;
1283 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1284 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1285 dwService
, dwFlags
, dwContext
);
1287 if (!lpszServerName
)
1289 SetLastError(ERROR_INVALID_PARAMETER
);
1293 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1294 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1296 res
= ERROR_INVALID_HANDLE
;
1302 case INTERNET_SERVICE_FTP
:
1303 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1304 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1306 res
= INTERNET_GetLastError();
1309 case INTERNET_SERVICE_HTTP
:
1310 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1311 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1314 case INTERNET_SERVICE_GOPHER
:
1320 WININET_Release( &hIC
->hdr
);
1322 TRACE("returning %p\n", rc
);
1328 /***********************************************************************
1329 * InternetConnectA (WININET.@)
1331 * Open a ftp, gopher or http session
1334 * HINTERNET a session handle on success
1338 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1339 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1340 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1341 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1343 HINTERNET rc
= NULL
;
1344 LPWSTR szServerName
;
1348 szServerName
= heap_strdupAtoW(lpszServerName
);
1349 szUserName
= heap_strdupAtoW(lpszUserName
);
1350 szPassword
= heap_strdupAtoW(lpszPassword
);
1352 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1353 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1355 heap_free(szServerName
);
1356 heap_free(szUserName
);
1357 heap_free(szPassword
);
1362 /***********************************************************************
1363 * InternetFindNextFileA (WININET.@)
1365 * Continues a file search from a previous call to FindFirstFile
1372 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1375 WIN32_FIND_DATAW fd
;
1377 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1379 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1383 /***********************************************************************
1384 * InternetFindNextFileW (WININET.@)
1386 * Continues a file search from a previous call to FindFirstFile
1393 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1395 object_header_t
*hdr
;
1400 hdr
= get_handle_object(hFind
);
1402 WARN("Invalid handle\n");
1403 SetLastError(ERROR_INVALID_HANDLE
);
1407 if(hdr
->vtbl
->FindNextFileW
) {
1408 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1410 WARN("Handle doesn't support NextFile\n");
1411 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1414 WININET_Release(hdr
);
1416 if(res
!= ERROR_SUCCESS
)
1418 return res
== ERROR_SUCCESS
;
1421 /***********************************************************************
1422 * InternetCloseHandle (WININET.@)
1424 * Generic close handle function
1431 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1433 object_header_t
*obj
;
1435 TRACE("%p\n", hInternet
);
1437 obj
= get_handle_object( hInternet
);
1439 SetLastError(ERROR_INVALID_HANDLE
);
1443 invalidate_handle(obj
);
1444 WININET_Release(obj
);
1450 /***********************************************************************
1451 * ConvertUrlComponentValue (Internal)
1453 * Helper function for InternetCrackUrlA
1456 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1457 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1458 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1460 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1461 if (*dwComponentLen
!= 0)
1463 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1464 if (*lppszComponent
== NULL
)
1468 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1469 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1472 *lppszComponent
= NULL
;
1474 *dwComponentLen
= nASCIILength
;
1478 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1479 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1480 (*lppszComponent
)[ncpylen
]=0;
1481 *dwComponentLen
= ncpylen
;
1487 /***********************************************************************
1488 * InternetCrackUrlA (WININET.@)
1490 * See InternetCrackUrlW.
1492 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1493 LPURL_COMPONENTSA lpUrlComponents
)
1496 URL_COMPONENTSW UCW
;
1498 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1499 *scheme
= NULL
, *extra
= NULL
;
1501 TRACE("(%s %u %x %p)\n",
1502 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1503 dwUrlLength
, dwFlags
, lpUrlComponents
);
1505 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1506 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1508 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1514 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1516 /* if dwUrlLength=-1 then nLength includes null but length to
1517 InternetCrackUrlW should not include it */
1518 if (dwUrlLength
== -1) nLength
--;
1520 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1521 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1522 lpwszUrl
[nLength
] = '\0';
1524 memset(&UCW
,0,sizeof(UCW
));
1525 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1526 if (lpUrlComponents
->dwHostNameLength
)
1528 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1529 if (lpUrlComponents
->lpszHostName
)
1531 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1532 UCW
.lpszHostName
= hostname
;
1535 if (lpUrlComponents
->dwUserNameLength
)
1537 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1538 if (lpUrlComponents
->lpszUserName
)
1540 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1541 UCW
.lpszUserName
= username
;
1544 if (lpUrlComponents
->dwPasswordLength
)
1546 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1547 if (lpUrlComponents
->lpszPassword
)
1549 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1550 UCW
.lpszPassword
= password
;
1553 if (lpUrlComponents
->dwUrlPathLength
)
1555 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1556 if (lpUrlComponents
->lpszUrlPath
)
1558 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1559 UCW
.lpszUrlPath
= path
;
1562 if (lpUrlComponents
->dwSchemeLength
)
1564 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1565 if (lpUrlComponents
->lpszScheme
)
1567 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1568 UCW
.lpszScheme
= scheme
;
1571 if (lpUrlComponents
->dwExtraInfoLength
)
1573 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1574 if (lpUrlComponents
->lpszExtraInfo
)
1576 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1577 UCW
.lpszExtraInfo
= extra
;
1580 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1582 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1583 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1584 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1585 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1586 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1587 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1588 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1589 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1590 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1591 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1592 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1593 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1595 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1596 lpUrlComponents
->nPort
= UCW
.nPort
;
1598 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1599 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1600 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1601 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1602 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1604 heap_free(lpwszUrl
);
1605 heap_free(hostname
);
1606 heap_free(username
);
1607 heap_free(password
);
1614 static const WCHAR url_schemes
[][7] =
1617 {'g','o','p','h','e','r',0},
1618 {'h','t','t','p',0},
1619 {'h','t','t','p','s',0},
1620 {'f','i','l','e',0},
1621 {'n','e','w','s',0},
1622 {'m','a','i','l','t','o',0},
1626 /***********************************************************************
1627 * GetInternetSchemeW (internal)
1633 * INTERNET_SCHEME_UNKNOWN on failure
1636 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1640 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1642 if(lpszScheme
==NULL
)
1643 return INTERNET_SCHEME_UNKNOWN
;
1645 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1646 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1647 return INTERNET_SCHEME_FIRST
+ i
;
1649 return INTERNET_SCHEME_UNKNOWN
;
1652 /***********************************************************************
1653 * SetUrlComponentValueW (Internal)
1655 * Helper function for InternetCrackUrlW
1658 * lppszComponent [O] Holds the returned string
1659 * dwComponentLen [I] Holds the size of lppszComponent
1660 * [O] Holds the length of the string in lppszComponent without '\0'
1661 * lpszStart [I] Holds the string to copy from
1662 * len [I] Holds the length of lpszStart without '\0'
1669 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1671 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1673 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1676 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1678 if (*lppszComponent
== NULL
)
1680 *lppszComponent
= (LPWSTR
)lpszStart
;
1681 *dwComponentLen
= len
;
1685 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1686 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1687 (*lppszComponent
)[ncpylen
] = '\0';
1688 *dwComponentLen
= ncpylen
;
1695 /***********************************************************************
1696 * InternetCrackUrlW (WININET.@)
1698 * Break up URL into its components
1704 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1705 LPURL_COMPONENTSW lpUC
)
1709 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1712 LPCWSTR lpszParam
= NULL
;
1713 BOOL found_colon
= FALSE
;
1714 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1715 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1716 LPWSTR lpszUrl_decode
= NULL
;
1717 DWORD dwUrlLength
= dwUrlLength_orig
;
1719 TRACE("(%s %u %x %p)\n",
1720 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1721 dwUrlLength
, dwFlags
, lpUC
);
1723 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1725 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1728 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1730 if (dwFlags
& ICU_DECODE
)
1733 DWORD len
= dwUrlLength
+ 1;
1735 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1737 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1740 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1741 url_tmp
[dwUrlLength
] = 0;
1742 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1745 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1748 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1751 lpszUrl
= lpszUrl_decode
;
1757 /* Determine if the URI is absolute. */
1758 while (lpszap
- lpszUrl
< dwUrlLength
)
1760 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1772 lpszcp
= lpszUrl
; /* Relative url */
1779 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1783 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1784 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1786 /* Parse <params> */
1787 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1789 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1791 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1792 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1795 /* Get scheme first. */
1796 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1797 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1798 lpszUrl
, lpszcp
- lpszUrl
);
1800 /* Eat ':' in protocol. */
1803 /* double slash indicates the net_loc portion is present */
1804 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1808 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1812 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1814 lpszNetLoc
= lpszParam
;
1816 else if (!lpszNetLoc
)
1817 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1825 /* [<user>[<:password>]@]<host>[:<port>] */
1826 /* First find the user and password if they exist */
1828 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1829 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1831 /* username and password not specified. */
1832 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1833 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1835 else /* Parse out username and password */
1837 LPCWSTR lpszUser
= lpszcp
;
1838 LPCWSTR lpszPasswd
= lpszHost
;
1840 while (lpszcp
< lpszHost
)
1843 lpszPasswd
= lpszcp
;
1848 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1849 lpszUser
, lpszPasswd
- lpszUser
);
1851 if (lpszPasswd
!= lpszHost
)
1853 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1854 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1855 lpszHost
- lpszPasswd
);
1857 lpszcp
++; /* Advance to beginning of host */
1860 /* Parse <host><:port> */
1863 lpszPort
= lpszNetLoc
;
1865 /* special case for res:// URLs: there is no port here, so the host is the
1866 entire string up to the first '/' */
1867 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1869 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1870 lpszHost
, lpszPort
- lpszHost
);
1875 while (lpszcp
< lpszNetLoc
)
1883 /* If the scheme is "file" and the host is just one letter, it's not a host */
1884 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1887 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1892 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1893 lpszHost
, lpszPort
- lpszHost
);
1894 if (lpszPort
!= lpszNetLoc
)
1895 lpUC
->nPort
= atoiW(++lpszPort
);
1896 else switch (lpUC
->nScheme
)
1898 case INTERNET_SCHEME_HTTP
:
1899 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1901 case INTERNET_SCHEME_HTTPS
:
1902 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1904 case INTERNET_SCHEME_FTP
:
1905 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1907 case INTERNET_SCHEME_GOPHER
:
1908 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1919 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1920 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1921 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1924 /* Here lpszcp points to:
1926 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1927 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1929 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1933 /* Only truncate the parameter list if it's already been saved
1934 * in lpUC->lpszExtraInfo.
1936 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1937 len
= lpszParam
- lpszcp
;
1940 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1941 * newlines if necessary.
1943 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1944 if (lpsznewline
!= NULL
)
1945 len
= lpsznewline
- lpszcp
;
1947 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1949 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1950 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1952 WCHAR tmppath
[MAX_PATH
];
1956 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1961 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1962 tmppath
[len
] = '\0';
1971 /* if ends in \. or \.. append a backslash */
1972 if (tmppath
[len
- 1] == '.' &&
1973 (tmppath
[len
- 2] == '\\' ||
1974 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1976 if (len
< MAX_PATH
- 1)
1978 tmppath
[len
] = '\\';
1979 tmppath
[len
+1] = '\0';
1983 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1987 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1992 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1993 lpUC
->lpszUrlPath
[0] = 0;
1994 lpUC
->dwUrlPathLength
= 0;
1997 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1998 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1999 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
2000 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
2001 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
2003 heap_free( lpszUrl_decode
);
2007 /***********************************************************************
2008 * InternetAttemptConnect (WININET.@)
2010 * Attempt to make a connection to the internet
2013 * ERROR_SUCCESS on success
2014 * Error value on failure
2017 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
2020 return ERROR_SUCCESS
;
2024 /***********************************************************************
2025 * convert_url_canonicalization_flags
2027 * Helper for InternetCanonicalizeUrl
2030 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2033 * Flags suitable for UrlCanonicalize
2035 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
2037 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2039 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
2040 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
2041 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
2042 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
2043 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2044 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
2045 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
2050 /***********************************************************************
2051 * InternetCanonicalizeUrlA (WININET.@)
2053 * Escape unsafe characters and spaces
2060 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2061 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2065 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2066 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2068 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2069 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2070 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2071 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2076 /***********************************************************************
2077 * InternetCanonicalizeUrlW (WININET.@)
2079 * Escape unsafe characters and spaces
2086 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2087 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2091 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2092 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2094 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2095 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2096 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2097 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2102 /* #################################################### */
2104 static INTERNET_STATUS_CALLBACK
set_status_callback(
2105 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2107 INTERNET_STATUS_CALLBACK ret
;
2109 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2110 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2112 ret
= lpwh
->lpfnStatusCB
;
2113 lpwh
->lpfnStatusCB
= callback
;
2118 /***********************************************************************
2119 * InternetSetStatusCallbackA (WININET.@)
2121 * Sets up a callback function which is called as progress is made
2122 * during an operation.
2125 * Previous callback or NULL on success
2126 * INTERNET_INVALID_STATUS_CALLBACK on failure
2129 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2130 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2132 INTERNET_STATUS_CALLBACK retVal
;
2133 object_header_t
*lpwh
;
2135 TRACE("%p\n", hInternet
);
2137 if (!(lpwh
= get_handle_object(hInternet
)))
2138 return INTERNET_INVALID_STATUS_CALLBACK
;
2140 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2142 WININET_Release( lpwh
);
2146 /***********************************************************************
2147 * InternetSetStatusCallbackW (WININET.@)
2149 * Sets up a callback function which is called as progress is made
2150 * during an operation.
2153 * Previous callback or NULL on success
2154 * INTERNET_INVALID_STATUS_CALLBACK on failure
2157 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2158 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2160 INTERNET_STATUS_CALLBACK retVal
;
2161 object_header_t
*lpwh
;
2163 TRACE("%p\n", hInternet
);
2165 if (!(lpwh
= get_handle_object(hInternet
)))
2166 return INTERNET_INVALID_STATUS_CALLBACK
;
2168 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2170 WININET_Release( lpwh
);
2174 /***********************************************************************
2175 * InternetSetFilePointer (WININET.@)
2177 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2178 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2180 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2184 /***********************************************************************
2185 * InternetWriteFile (WININET.@)
2187 * Write data to an open internet file
2194 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2195 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2197 object_header_t
*lpwh
;
2200 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2202 lpwh
= get_handle_object( hFile
);
2204 WARN("Invalid handle\n");
2205 SetLastError(ERROR_INVALID_HANDLE
);
2209 if(lpwh
->vtbl
->WriteFile
) {
2210 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2212 WARN("No Writefile method.\n");
2213 res
= ERROR_INVALID_HANDLE
;
2216 WININET_Release( lpwh
);
2218 if(res
!= ERROR_SUCCESS
)
2220 return res
== ERROR_SUCCESS
;
2224 /***********************************************************************
2225 * InternetReadFile (WININET.@)
2227 * Read data from an open internet file
2234 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2235 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2237 object_header_t
*hdr
;
2238 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2240 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2242 hdr
= get_handle_object(hFile
);
2244 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2248 if(hdr
->vtbl
->ReadFile
)
2249 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2251 WININET_Release(hdr
);
2253 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2254 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2256 if(res
!= ERROR_SUCCESS
)
2258 return res
== ERROR_SUCCESS
;
2261 /***********************************************************************
2262 * InternetReadFileExA (WININET.@)
2264 * Read data from an open internet file
2267 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2268 * lpBuffersOut [I/O] Buffer.
2269 * dwFlags [I] Flags. See notes.
2270 * dwContext [I] Context for callbacks.
2277 * The parameter dwFlags include zero or more of the following flags:
2278 *|IRF_ASYNC - Makes the call asynchronous.
2279 *|IRF_SYNC - Makes the call synchronous.
2280 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2281 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2283 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2286 * InternetOpenUrlA(), HttpOpenRequestA()
2288 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2289 DWORD dwFlags
, DWORD_PTR dwContext
)
2291 object_header_t
*hdr
;
2292 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2294 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2296 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2297 SetLastError(ERROR_INVALID_PARAMETER
);
2301 hdr
= get_handle_object(hFile
);
2303 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2307 if(hdr
->vtbl
->ReadFileEx
)
2308 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2309 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2311 WININET_Release(hdr
);
2313 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2314 res
, lpBuffersOut
->dwBufferLength
);
2316 if(res
!= ERROR_SUCCESS
)
2318 return res
== ERROR_SUCCESS
;
2321 /***********************************************************************
2322 * InternetReadFileExW (WININET.@)
2324 * InternetReadFileExA()
2326 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2327 DWORD dwFlags
, DWORD_PTR dwContext
)
2329 object_header_t
*hdr
;
2330 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2332 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2334 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2335 SetLastError(ERROR_INVALID_PARAMETER
);
2339 hdr
= get_handle_object(hFile
);
2341 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2345 if(hdr
->vtbl
->ReadFileEx
)
2346 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2347 dwFlags
, dwContext
);
2349 WININET_Release(hdr
);
2351 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2352 res
, lpBuffer
->dwBufferLength
);
2354 if(res
!= ERROR_SUCCESS
)
2356 return res
== ERROR_SUCCESS
;
2359 static BOOL
get_proxy_autoconfig_url( char *buf
, DWORD buflen
)
2361 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2363 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2367 if (!settings
) return FALSE
;
2369 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2371 CFRelease( settings
);
2374 if (CFStringGetCString( ref
, buf
, buflen
, kCFStringEncodingASCII
))
2376 TRACE( "returning %s\n", debugstr_a(buf
) );
2379 CFRelease( settings
);
2382 FIXME( "no support on this platform\n" );
2387 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2389 /* FIXME: This function currently handles more options than it should. Options requiring
2390 * proper handles should be moved to proper functions */
2392 case INTERNET_OPTION_HTTP_VERSION
:
2393 if (*size
< sizeof(HTTP_VERSION_INFO
))
2394 return ERROR_INSUFFICIENT_BUFFER
;
2397 * Presently hardcoded to 1.1
2399 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2400 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2401 *size
= sizeof(HTTP_VERSION_INFO
);
2403 return ERROR_SUCCESS
;
2405 case INTERNET_OPTION_CONNECTED_STATE
:
2406 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2408 if (*size
< sizeof(ULONG
))
2409 return ERROR_INSUFFICIENT_BUFFER
;
2411 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2412 *size
= sizeof(ULONG
);
2414 return ERROR_SUCCESS
;
2416 case INTERNET_OPTION_PROXY
: {
2420 TRACE("Getting global proxy info\n");
2421 memset(&ai
, 0, sizeof(appinfo_t
));
2422 INTERNET_ConfigureProxy(&ai
);
2424 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2425 APPINFO_Destroy(&ai
.hdr
);
2429 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2430 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2432 if (*size
< sizeof(ULONG
))
2433 return ERROR_INSUFFICIENT_BUFFER
;
2435 *(ULONG
*)buffer
= max_conns
;
2436 *size
= sizeof(ULONG
);
2438 return ERROR_SUCCESS
;
2440 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2441 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2443 if (*size
< sizeof(ULONG
))
2444 return ERROR_INSUFFICIENT_BUFFER
;
2446 *(ULONG
*)buffer
= max_1_0_conns
;
2447 *size
= sizeof(ULONG
);
2449 return ERROR_SUCCESS
;
2451 case INTERNET_OPTION_SECURITY_FLAGS
:
2452 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2453 return ERROR_SUCCESS
;
2455 case INTERNET_OPTION_VERSION
: {
2456 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2458 TRACE("INTERNET_OPTION_VERSION\n");
2460 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2461 return ERROR_INSUFFICIENT_BUFFER
;
2463 memcpy(buffer
, &info
, sizeof(info
));
2464 *size
= sizeof(info
);
2466 return ERROR_SUCCESS
;
2469 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2470 char url
[INTERNET_MAX_URL_LENGTH
+ 1];
2471 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2472 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2473 DWORD res
= ERROR_SUCCESS
, i
;
2478 TRACE("Getting global proxy info\n");
2479 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2482 have_url
= get_proxy_autoconfig_url(url
, sizeof(url
));
2484 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2486 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2488 return ERROR_INSUFFICIENT_BUFFER
;
2491 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2492 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2493 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2495 switch (optionW
->dwOption
) {
2496 case INTERNET_PER_CONN_FLAGS
:
2498 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2500 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2502 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2503 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2506 case INTERNET_PER_CONN_PROXY_SERVER
:
2508 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2510 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2513 case INTERNET_PER_CONN_PROXY_BYPASS
:
2515 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2517 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2520 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2522 optionW
->Value
.pszValue
= NULL
;
2524 optionW
->Value
.pszValue
= heap_strdupAtoW(url
);
2526 optionA
->Value
.pszValue
= heap_strdupA(url
);
2529 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2530 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2533 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2534 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2535 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2536 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2537 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2538 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2542 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2543 res
= ERROR_INVALID_PARAMETER
;
2551 case INTERNET_OPTION_REQUEST_FLAGS
:
2552 case INTERNET_OPTION_USER_AGENT
:
2554 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2555 case INTERNET_OPTION_POLICY
:
2556 return ERROR_INVALID_PARAMETER
;
2557 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2558 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2560 if (*size
< sizeof(ULONG
))
2561 return ERROR_INSUFFICIENT_BUFFER
;
2563 *(ULONG
*)buffer
= connect_timeout
;
2564 *size
= sizeof(ULONG
);
2566 return ERROR_SUCCESS
;
2569 FIXME("Stub for %d\n", option
);
2570 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2573 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2576 case INTERNET_OPTION_CONTEXT_VALUE
:
2578 return ERROR_INVALID_PARAMETER
;
2580 if (*size
< sizeof(DWORD_PTR
)) {
2581 *size
= sizeof(DWORD_PTR
);
2582 return ERROR_INSUFFICIENT_BUFFER
;
2585 return ERROR_INVALID_PARAMETER
;
2587 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2588 *size
= sizeof(DWORD_PTR
);
2589 return ERROR_SUCCESS
;
2591 case INTERNET_OPTION_REQUEST_FLAGS
:
2592 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2593 *size
= sizeof(DWORD
);
2594 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2596 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2597 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2598 WARN("Called on global option %u\n", option
);
2599 return ERROR_INTERNET_INVALID_OPERATION
;
2602 /* FIXME: we shouldn't call it here */
2603 return query_global_option(option
, buffer
, size
, unicode
);
2606 /***********************************************************************
2607 * InternetQueryOptionW (WININET.@)
2609 * Queries an options on the specified handle
2616 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2617 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2619 object_header_t
*hdr
;
2620 DWORD res
= ERROR_INVALID_HANDLE
;
2622 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2625 hdr
= get_handle_object(hInternet
);
2627 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2628 WININET_Release(hdr
);
2631 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2634 if(res
!= ERROR_SUCCESS
)
2636 return res
== ERROR_SUCCESS
;
2639 /***********************************************************************
2640 * InternetQueryOptionA (WININET.@)
2642 * Queries an options on the specified handle
2649 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2650 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2652 object_header_t
*hdr
;
2653 DWORD res
= ERROR_INVALID_HANDLE
;
2655 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2658 hdr
= get_handle_object(hInternet
);
2660 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2661 WININET_Release(hdr
);
2664 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2667 if(res
!= ERROR_SUCCESS
)
2669 return res
== ERROR_SUCCESS
;
2672 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2675 case INTERNET_OPTION_CALLBACK
:
2676 WARN("Not settable option %u\n", option
);
2677 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2678 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2679 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2680 WARN("Called on global option %u\n", option
);
2681 return ERROR_INTERNET_INVALID_OPERATION
;
2684 return ERROR_INTERNET_INVALID_OPTION
;
2687 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2690 case INTERNET_OPTION_CALLBACK
:
2691 WARN("Not global option %u\n", option
);
2692 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2694 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2695 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2697 if(size
!= sizeof(max_conns
))
2698 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2700 return ERROR_BAD_ARGUMENTS
;
2702 max_conns
= *(ULONG
*)buf
;
2703 return ERROR_SUCCESS
;
2705 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2706 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2708 if(size
!= sizeof(max_1_0_conns
))
2709 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2711 return ERROR_BAD_ARGUMENTS
;
2713 max_1_0_conns
= *(ULONG
*)buf
;
2714 return ERROR_SUCCESS
;
2716 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2717 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2719 if(size
!= sizeof(connect_timeout
))
2720 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2722 return ERROR_BAD_ARGUMENTS
;
2724 connect_timeout
= *(ULONG
*)buf
;
2725 return ERROR_SUCCESS
;
2727 case INTERNET_OPTION_SETTINGS_CHANGED
:
2728 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2729 collect_connections(COLLECT_CONNECTIONS
);
2730 return ERROR_SUCCESS
;
2733 return ERROR_INTERNET_INVALID_OPTION
;
2736 /***********************************************************************
2737 * InternetSetOptionW (WININET.@)
2739 * Sets an options on the specified handle
2746 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2747 LPVOID lpBuffer
, DWORD dwBufferLength
)
2749 object_header_t
*lpwhh
;
2753 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2755 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2757 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2759 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2761 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2763 WININET_Release(lpwhh
);
2765 if(res
!= ERROR_SUCCESS
)
2768 return res
== ERROR_SUCCESS
;
2773 case INTERNET_OPTION_HTTP_VERSION
:
2775 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2776 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2779 case INTERNET_OPTION_ERROR_MASK
:
2782 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2784 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2785 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2786 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2787 SetLastError(ERROR_INVALID_PARAMETER
);
2789 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2790 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2793 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2794 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2797 case INTERNET_OPTION_PROXY
:
2799 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2801 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2803 SetLastError(ERROR_INVALID_PARAMETER
);
2808 EnterCriticalSection( &WININET_cs
);
2809 free_global_proxy();
2810 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2813 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2815 global_proxy
->proxyEnabled
= 1;
2816 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2817 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2821 global_proxy
->proxyEnabled
= 0;
2822 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2825 LeaveCriticalSection( &WININET_cs
);
2829 /* In general, each type of object should handle
2830 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2831 * get silently dropped.
2833 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2834 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2839 case INTERNET_OPTION_CODEPAGE
:
2841 ULONG codepage
= *(ULONG
*)lpBuffer
;
2842 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2845 case INTERNET_OPTION_REQUEST_PRIORITY
:
2847 ULONG priority
= *(ULONG
*)lpBuffer
;
2848 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2851 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2853 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2854 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2857 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2859 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2860 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2863 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2864 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2866 case INTERNET_OPTION_END_BROWSER_SESSION
:
2867 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2869 case INTERNET_OPTION_CONNECTED_STATE
:
2870 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2872 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2873 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2875 case INTERNET_OPTION_SEND_TIMEOUT
:
2876 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2877 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2879 ULONG timeout
= *(ULONG
*)lpBuffer
;
2880 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2883 case INTERNET_OPTION_CONNECT_RETRIES
:
2885 ULONG retries
= *(ULONG
*)lpBuffer
;
2886 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2889 case INTERNET_OPTION_CONTEXT_VALUE
:
2893 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2896 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2898 SetLastError(ERROR_INVALID_PARAMETER
);
2902 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2905 case INTERNET_OPTION_SECURITY_FLAGS
:
2906 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2908 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2909 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2911 case INTERNET_OPTION_HTTP_DECODING
:
2912 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2913 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2916 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2917 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2918 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2921 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2922 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2923 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2926 case INTERNET_OPTION_CODEPAGE_PATH
:
2927 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2928 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2931 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2932 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2933 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2936 case INTERNET_OPTION_IDN
:
2937 FIXME("INTERNET_OPTION_IDN; STUB\n");
2938 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2941 case INTERNET_OPTION_POLICY
:
2942 SetLastError(ERROR_INVALID_PARAMETER
);
2945 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2946 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2951 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2953 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2954 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2956 switch (option
->dwOption
) {
2957 case INTERNET_PER_CONN_PROXY_SERVER
:
2958 heap_free(pi
.proxy
);
2959 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2962 case INTERNET_PER_CONN_FLAGS
:
2963 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2964 pi
.proxyEnabled
= 1;
2967 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2968 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2969 pi
.proxyEnabled
= 0;
2973 case INTERNET_PER_CONN_PROXY_BYPASS
:
2974 heap_free(pi
.proxyBypass
);
2975 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
2978 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2979 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2980 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2981 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2982 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2983 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2984 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2988 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2989 SetLastError(ERROR_INVALID_PARAMETER
);
2994 if ((res
= INTERNET_SaveProxySettings(&pi
)))
2999 ret
= (res
== ERROR_SUCCESS
);
3003 FIXME("Option %d STUB\n",dwOption
);
3004 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3010 WININET_Release( lpwhh
);
3016 /***********************************************************************
3017 * InternetSetOptionA (WININET.@)
3019 * Sets an options on the specified handle.
3026 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3027 LPVOID lpBuffer
, DWORD dwBufferLength
)
3035 case INTERNET_OPTION_PROXY
:
3037 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3038 LPINTERNET_PROXY_INFOW piw
;
3039 DWORD proxlen
, prbylen
;
3042 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3043 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3044 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3045 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3046 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3047 piw
->dwAccessType
= pi
->dwAccessType
;
3048 prox
= (LPWSTR
) &piw
[1];
3049 prby
= &prox
[proxlen
+1];
3050 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3051 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3052 piw
->lpszProxy
= prox
;
3053 piw
->lpszProxyBypass
= prby
;
3056 case INTERNET_OPTION_USER_AGENT
:
3057 case INTERNET_OPTION_USERNAME
:
3058 case INTERNET_OPTION_PASSWORD
:
3059 case INTERNET_OPTION_PROXY_USERNAME
:
3060 case INTERNET_OPTION_PROXY_PASSWORD
:
3061 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3062 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3063 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3065 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3067 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3068 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3069 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3070 wbuffer
= heap_alloc(wlen
);
3073 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3074 if (listA
->pszConnection
)
3076 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3077 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3078 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3081 listW
->pszConnection
= NULL
;
3082 listW
->dwOptionCount
= listA
->dwOptionCount
;
3083 listW
->dwOptionError
= listA
->dwOptionError
;
3084 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3086 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3087 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3088 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3090 optW
->dwOption
= optA
->dwOption
;
3092 switch (optA
->dwOption
) {
3093 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3094 case INTERNET_PER_CONN_PROXY_BYPASS
:
3095 case INTERNET_PER_CONN_PROXY_SERVER
:
3096 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3097 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3098 if (optA
->Value
.pszValue
)
3100 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3101 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3102 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3105 optW
->Value
.pszValue
= NULL
;
3107 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3108 case INTERNET_PER_CONN_FLAGS
:
3109 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3110 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3112 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3113 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3116 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3117 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3125 wlen
= dwBufferLength
;
3128 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3130 if( lpBuffer
!= wbuffer
)
3132 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3134 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3136 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3137 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3138 switch (opt
->dwOption
) {
3139 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3140 case INTERNET_PER_CONN_PROXY_BYPASS
:
3141 case INTERNET_PER_CONN_PROXY_SERVER
:
3142 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3143 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3144 heap_free( opt
->Value
.pszValue
);
3150 heap_free( list
->pOptions
);
3152 heap_free( wbuffer
);
3159 /***********************************************************************
3160 * InternetSetOptionExA (WININET.@)
3162 BOOL WINAPI
InternetSetOptio