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
;
1002 if (TRACE_ON(wininet
)) {
1003 #define FE(x) { x, #x }
1004 static const wininet_flag_info access_type
[] = {
1005 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
1006 FE(INTERNET_OPEN_TYPE_DIRECT
),
1007 FE(INTERNET_OPEN_TYPE_PROXY
),
1008 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
1012 const char *access_type_str
= "Unknown";
1014 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
1015 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
1016 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
1017 if (access_type
[i
].val
== dwAccessType
) {
1018 access_type_str
= access_type
[i
].name
;
1022 TRACE(" access type : %s\n", access_type_str
);
1024 dump_INTERNET_FLAGS(dwFlags
);
1027 /* Clear any error information */
1028 INTERNET_SetLastError(0);
1030 if((dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) && !lpszProxy
) {
1031 SetLastError(ERROR_INVALID_PARAMETER
);
1035 lpwai
= alloc_object(NULL
, &APPINFOVtbl
, sizeof(appinfo_t
));
1037 SetLastError(ERROR_OUTOFMEMORY
);
1041 lpwai
->hdr
.htype
= WH_HINIT
;
1042 lpwai
->hdr
.dwFlags
= dwFlags
;
1043 lpwai
->accessType
= dwAccessType
;
1044 lpwai
->proxyUsername
= NULL
;
1045 lpwai
->proxyPassword
= NULL
;
1046 lpwai
->connect_timeout
= connect_timeout
;
1048 lpwai
->agent
= heap_strdupW(lpszAgent
);
1049 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
1050 INTERNET_ConfigureProxy( lpwai
);
1051 else if(dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
1052 lpwai
->proxy
= heap_strdupW(lpszProxy
);
1053 lpwai
->proxyBypass
= heap_strdupW(lpszProxyBypass
);
1056 TRACE("returning %p\n", lpwai
);
1058 return lpwai
->hdr
.hInternet
;
1062 /***********************************************************************
1063 * InternetOpenA (WININET.@)
1065 * Per-application initialization of wininet
1068 * HINTERNET on success
1072 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
1073 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
1075 WCHAR
*szAgent
, *szProxy
, *szBypass
;
1078 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
1079 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
1081 szAgent
= heap_strdupAtoW(lpszAgent
);
1082 szProxy
= heap_strdupAtoW(lpszProxy
);
1083 szBypass
= heap_strdupAtoW(lpszProxyBypass
);
1085 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
1089 heap_free(szBypass
);
1093 /***********************************************************************
1094 * InternetGetLastResponseInfoA (WININET.@)
1096 * Return last wininet error description on the calling thread
1099 * TRUE on success of writing to buffer
1103 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
1104 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1106 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1112 *lpdwError
= lpwite
->dwError
;
1113 if (lpwite
->dwError
)
1115 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1116 *lpdwBufferLength
= strlen(lpszBuffer
);
1119 *lpdwBufferLength
= 0;
1124 *lpdwBufferLength
= 0;
1130 /***********************************************************************
1131 * InternetGetLastResponseInfoW (WININET.@)
1133 * Return last wininet error description on the calling thread
1136 * TRUE on success of writing to buffer
1140 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
1141 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
1143 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
1149 *lpdwError
= lpwite
->dwError
;
1150 if (lpwite
->dwError
)
1152 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
1153 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
1156 *lpdwBufferLength
= 0;
1161 *lpdwBufferLength
= 0;
1167 /***********************************************************************
1168 * InternetGetConnectedState (WININET.@)
1170 * Return connected state
1174 * if lpdwStatus is not null, return the status (off line,
1175 * modem, lan...) in it.
1176 * FALSE if not connected
1178 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
1180 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
1183 WARN("always returning LAN connection.\n");
1184 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1190 /***********************************************************************
1191 * InternetGetConnectedStateExW (WININET.@)
1193 * Return connected state
1197 * lpdwStatus [O] Flags specifying the status of the internet connection.
1198 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1199 * dwNameLen [I] Size of the buffer, in characters.
1200 * dwReserved [I] Reserved. Must be set to 0.
1204 * if lpdwStatus is not null, return the status (off line,
1205 * modem, lan...) in it.
1206 * FALSE if not connected
1209 * If the system has no available network connections, an empty string is
1210 * stored in lpszConnectionName. If there is a LAN connection, a localized
1211 * "LAN Connection" string is stored. Presumably, if only a dial-up
1212 * connection is available then the name of the dial-up connection is
1213 * returned. Why any application, other than the "Internet Settings" CPL,
1214 * would want to use this function instead of the simpler InternetGetConnectedStateW
1215 * function is beyond me.
1217 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
1218 DWORD dwNameLen
, DWORD dwReserved
)
1220 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1227 WARN("always returning LAN connection.\n");
1228 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
1231 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1232 * the resource, avoid it as we must not change the buffer in this case */
1233 if(lpszConnectionName
&& dwNameLen
) {
1234 *lpszConnectionName
= '\0';
1235 LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
1242 /***********************************************************************
1243 * InternetGetConnectedStateExA (WININET.@)
1245 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
1246 DWORD dwNameLen
, DWORD dwReserved
)
1248 LPWSTR lpwszConnectionName
= NULL
;
1251 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
1253 if (lpszConnectionName
&& dwNameLen
> 0)
1254 lpwszConnectionName
= heap_alloc(dwNameLen
* sizeof(WCHAR
));
1256 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
1258 if (rc
&& lpwszConnectionName
)
1259 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
1260 dwNameLen
, NULL
, NULL
);
1262 heap_free(lpwszConnectionName
);
1267 /***********************************************************************
1268 * InternetConnectW (WININET.@)
1270 * Open a ftp, gopher or http session
1273 * HINTERNET a session handle on success
1277 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
1278 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
1279 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
1280 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1283 HINTERNET rc
= NULL
;
1284 DWORD res
= ERROR_SUCCESS
;
1286 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
1287 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
1288 dwService
, dwFlags
, dwContext
);
1290 if (!lpszServerName
)
1292 SetLastError(ERROR_INVALID_PARAMETER
);
1296 hIC
= (appinfo_t
*)get_handle_object( hInternet
);
1297 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
1299 res
= ERROR_INVALID_HANDLE
;
1305 case INTERNET_SERVICE_FTP
:
1306 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
1307 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
1309 res
= INTERNET_GetLastError();
1312 case INTERNET_SERVICE_HTTP
:
1313 res
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
1314 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0, &rc
);
1317 case INTERNET_SERVICE_GOPHER
:
1323 WININET_Release( &hIC
->hdr
);
1325 TRACE("returning %p\n", rc
);
1331 /***********************************************************************
1332 * InternetConnectA (WININET.@)
1334 * Open a ftp, gopher or http session
1337 * HINTERNET a session handle on success
1341 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1342 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1343 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1344 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1346 HINTERNET rc
= NULL
;
1347 LPWSTR szServerName
;
1351 szServerName
= heap_strdupAtoW(lpszServerName
);
1352 szUserName
= heap_strdupAtoW(lpszUserName
);
1353 szPassword
= heap_strdupAtoW(lpszPassword
);
1355 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1356 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1358 heap_free(szServerName
);
1359 heap_free(szUserName
);
1360 heap_free(szPassword
);
1365 /***********************************************************************
1366 * InternetFindNextFileA (WININET.@)
1368 * Continues a file search from a previous call to FindFirstFile
1375 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1378 WIN32_FIND_DATAW fd
;
1380 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1382 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1386 /***********************************************************************
1387 * InternetFindNextFileW (WININET.@)
1389 * Continues a file search from a previous call to FindFirstFile
1396 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1398 object_header_t
*hdr
;
1403 hdr
= get_handle_object(hFind
);
1405 WARN("Invalid handle\n");
1406 SetLastError(ERROR_INVALID_HANDLE
);
1410 if(hdr
->vtbl
->FindNextFileW
) {
1411 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1413 WARN("Handle doesn't support NextFile\n");
1414 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1417 WININET_Release(hdr
);
1419 if(res
!= ERROR_SUCCESS
)
1421 return res
== ERROR_SUCCESS
;
1424 /***********************************************************************
1425 * InternetCloseHandle (WININET.@)
1427 * Generic close handle function
1434 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1436 object_header_t
*obj
;
1438 TRACE("%p\n", hInternet
);
1440 obj
= get_handle_object( hInternet
);
1442 SetLastError(ERROR_INVALID_HANDLE
);
1446 invalidate_handle(obj
);
1447 WININET_Release(obj
);
1453 /***********************************************************************
1454 * ConvertUrlComponentValue (Internal)
1456 * Helper function for InternetCrackUrlA
1459 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1460 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1461 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1463 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1464 if (*dwComponentLen
!= 0)
1466 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1467 if (*lppszComponent
== NULL
)
1471 int offset
= WideCharToMultiByte(CP_ACP
, 0, lpwszStart
, lpwszComponent
-lpwszStart
, NULL
, 0, NULL
, NULL
);
1472 *lppszComponent
= (LPSTR
)lpszStart
+ offset
;
1475 *lppszComponent
= NULL
;
1477 *dwComponentLen
= nASCIILength
;
1481 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1482 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1483 (*lppszComponent
)[ncpylen
]=0;
1484 *dwComponentLen
= ncpylen
;
1490 /***********************************************************************
1491 * InternetCrackUrlA (WININET.@)
1493 * See InternetCrackUrlW.
1495 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1496 LPURL_COMPONENTSA lpUrlComponents
)
1499 URL_COMPONENTSW UCW
;
1501 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1502 *scheme
= NULL
, *extra
= NULL
;
1504 TRACE("(%s %u %x %p)\n",
1505 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1506 dwUrlLength
, dwFlags
, lpUrlComponents
);
1508 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1509 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1511 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1517 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1519 /* if dwUrlLength=-1 then nLength includes null but length to
1520 InternetCrackUrlW should not include it */
1521 if (dwUrlLength
== -1) nLength
--;
1523 lpwszUrl
= heap_alloc((nLength
+ 1) * sizeof(WCHAR
));
1524 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
+ 1);
1525 lpwszUrl
[nLength
] = '\0';
1527 memset(&UCW
,0,sizeof(UCW
));
1528 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1529 if (lpUrlComponents
->dwHostNameLength
)
1531 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1532 if (lpUrlComponents
->lpszHostName
)
1534 hostname
= heap_alloc(UCW
.dwHostNameLength
* sizeof(WCHAR
));
1535 UCW
.lpszHostName
= hostname
;
1538 if (lpUrlComponents
->dwUserNameLength
)
1540 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1541 if (lpUrlComponents
->lpszUserName
)
1543 username
= heap_alloc(UCW
.dwUserNameLength
* sizeof(WCHAR
));
1544 UCW
.lpszUserName
= username
;
1547 if (lpUrlComponents
->dwPasswordLength
)
1549 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1550 if (lpUrlComponents
->lpszPassword
)
1552 password
= heap_alloc(UCW
.dwPasswordLength
* sizeof(WCHAR
));
1553 UCW
.lpszPassword
= password
;
1556 if (lpUrlComponents
->dwUrlPathLength
)
1558 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1559 if (lpUrlComponents
->lpszUrlPath
)
1561 path
= heap_alloc(UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1562 UCW
.lpszUrlPath
= path
;
1565 if (lpUrlComponents
->dwSchemeLength
)
1567 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1568 if (lpUrlComponents
->lpszScheme
)
1570 scheme
= heap_alloc(UCW
.dwSchemeLength
* sizeof(WCHAR
));
1571 UCW
.lpszScheme
= scheme
;
1574 if (lpUrlComponents
->dwExtraInfoLength
)
1576 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1577 if (lpUrlComponents
->lpszExtraInfo
)
1579 extra
= heap_alloc(UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1580 UCW
.lpszExtraInfo
= extra
;
1583 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1585 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1586 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1587 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1588 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1589 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1590 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1591 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1592 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1593 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1594 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1595 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1596 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1598 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1599 lpUrlComponents
->nPort
= UCW
.nPort
;
1601 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl
),
1602 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1603 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1604 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1605 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1607 heap_free(lpwszUrl
);
1608 heap_free(hostname
);
1609 heap_free(username
);
1610 heap_free(password
);
1617 static const WCHAR url_schemes
[][7] =
1620 {'g','o','p','h','e','r',0},
1621 {'h','t','t','p',0},
1622 {'h','t','t','p','s',0},
1623 {'f','i','l','e',0},
1624 {'n','e','w','s',0},
1625 {'m','a','i','l','t','o',0},
1629 /***********************************************************************
1630 * GetInternetSchemeW (internal)
1636 * INTERNET_SCHEME_UNKNOWN on failure
1639 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1643 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1645 if(lpszScheme
==NULL
)
1646 return INTERNET_SCHEME_UNKNOWN
;
1648 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1649 if (!strncmpiW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1650 return INTERNET_SCHEME_FIRST
+ i
;
1652 return INTERNET_SCHEME_UNKNOWN
;
1655 /***********************************************************************
1656 * SetUrlComponentValueW (Internal)
1658 * Helper function for InternetCrackUrlW
1661 * lppszComponent [O] Holds the returned string
1662 * dwComponentLen [I] Holds the size of lppszComponent
1663 * [O] Holds the length of the string in lppszComponent without '\0'
1664 * lpszStart [I] Holds the string to copy from
1665 * len [I] Holds the length of lpszStart without '\0'
1672 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1674 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1676 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1679 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1681 if (*lppszComponent
== NULL
)
1683 *lppszComponent
= (LPWSTR
)lpszStart
;
1684 *dwComponentLen
= len
;
1688 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1689 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1690 (*lppszComponent
)[ncpylen
] = '\0';
1691 *dwComponentLen
= ncpylen
;
1698 /***********************************************************************
1699 * InternetCrackUrlW (WININET.@)
1701 * Break up URL into its components
1707 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1708 LPURL_COMPONENTSW lpUC
)
1712 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1715 LPCWSTR lpszParam
= NULL
;
1716 BOOL found_colon
= FALSE
;
1717 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1718 LPCWSTR lpszcp
= NULL
, lpszNetLoc
;
1719 LPWSTR lpszUrl_decode
= NULL
;
1720 DWORD dwUrlLength
= dwUrlLength_orig
;
1722 TRACE("(%s %u %x %p)\n",
1723 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1724 dwUrlLength
, dwFlags
, lpUC
);
1726 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1728 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1731 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1733 if (dwFlags
& ICU_DECODE
)
1736 DWORD len
= dwUrlLength
+ 1;
1738 if (!(url_tmp
= heap_alloc(len
* sizeof(WCHAR
))))
1740 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1743 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1744 url_tmp
[dwUrlLength
] = 0;
1745 if (!(lpszUrl_decode
= heap_alloc(len
* sizeof(WCHAR
))))
1748 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1751 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1754 lpszUrl
= lpszUrl_decode
;
1760 /* Determine if the URI is absolute. */
1761 while (lpszap
- lpszUrl
< dwUrlLength
)
1763 if (isalnumW(*lpszap
) || *lpszap
== '+' || *lpszap
== '.' || *lpszap
== '-')
1775 lpszcp
= lpszUrl
; /* Relative url */
1782 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
1786 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1787 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1789 /* Parse <params> */
1790 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1792 lpszParam
= memchrW(lpszap
, '#', dwUrlLength
- (lpszap
- lpszUrl
));
1794 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1795 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1798 /* Get scheme first. */
1799 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1800 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1801 lpszUrl
, lpszcp
- lpszUrl
);
1803 /* Eat ':' in protocol. */
1806 /* double slash indicates the net_loc portion is present */
1807 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1811 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1815 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1817 lpszNetLoc
= lpszParam
;
1819 else if (!lpszNetLoc
)
1820 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1828 /* [<user>[<:password>]@]<host>[:<port>] */
1829 /* First find the user and password if they exist */
1831 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1832 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1834 /* username and password not specified. */
1835 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1836 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1838 else /* Parse out username and password */
1840 LPCWSTR lpszUser
= lpszcp
;
1841 LPCWSTR lpszPasswd
= lpszHost
;
1843 while (lpszcp
< lpszHost
)
1846 lpszPasswd
= lpszcp
;
1851 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1852 lpszUser
, lpszPasswd
- lpszUser
);
1854 if (lpszPasswd
!= lpszHost
)
1856 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1857 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1858 lpszHost
- lpszPasswd
);
1860 lpszcp
++; /* Advance to beginning of host */
1863 /* Parse <host><:port> */
1866 lpszPort
= lpszNetLoc
;
1868 /* special case for res:// URLs: there is no port here, so the host is the
1869 entire string up to the first '/' */
1870 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1872 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1873 lpszHost
, lpszPort
- lpszHost
);
1878 while (lpszcp
< lpszNetLoc
)
1886 /* If the scheme is "file" and the host is just one letter, it's not a host */
1887 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& lpszPort
<= lpszHost
+1)
1890 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1895 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1896 lpszHost
, lpszPort
- lpszHost
);
1897 if (lpszPort
!= lpszNetLoc
)
1898 lpUC
->nPort
= atoiW(++lpszPort
);
1899 else switch (lpUC
->nScheme
)
1901 case INTERNET_SCHEME_HTTP
:
1902 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1904 case INTERNET_SCHEME_HTTPS
:
1905 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1907 case INTERNET_SCHEME_FTP
:
1908 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1910 case INTERNET_SCHEME_GOPHER
:
1911 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1922 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1923 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1924 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1927 /* Here lpszcp points to:
1929 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1930 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1932 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
<= lpszParam
))
1936 /* Only truncate the parameter list if it's already been saved
1937 * in lpUC->lpszExtraInfo.
1939 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1940 len
= lpszParam
- lpszcp
;
1943 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1944 * newlines if necessary.
1946 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1947 if (lpsznewline
!= NULL
)
1948 len
= lpsznewline
- lpszcp
;
1950 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1952 if (lpUC
->dwUrlPathLength
&& lpUC
->lpszUrlPath
&&
1953 lpUC
->nScheme
== INTERNET_SCHEME_FILE
)
1955 WCHAR tmppath
[MAX_PATH
];
1959 PathCreateFromUrlW(lpszUrl_orig
, tmppath
, &len
, 0);
1964 memcpy(tmppath
, lpszcp
, len
* sizeof(WCHAR
));
1965 tmppath
[len
] = '\0';
1974 /* if ends in \. or \.. append a backslash */
1975 if (tmppath
[len
- 1] == '.' &&
1976 (tmppath
[len
- 2] == '\\' ||
1977 (tmppath
[len
- 2] == '.' && tmppath
[len
- 3] == '\\')))
1979 if (len
< MAX_PATH
- 1)
1981 tmppath
[len
] = '\\';
1982 tmppath
[len
+1] = '\0';
1986 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1990 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1995 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1996 lpUC
->lpszUrlPath
[0] = 0;
1997 lpUC
->dwUrlPathLength
= 0;
2000 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
2001 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
2002 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
2003 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
2004 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
2006 heap_free( lpszUrl_decode
);
2010 /***********************************************************************
2011 * InternetAttemptConnect (WININET.@)
2013 * Attempt to make a connection to the internet
2016 * ERROR_SUCCESS on success
2017 * Error value on failure
2020 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
2023 return ERROR_SUCCESS
;
2027 /***********************************************************************
2028 * convert_url_canonicalization_flags
2030 * Helper for InternetCanonicalizeUrl
2033 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2036 * Flags suitable for UrlCanonicalize
2038 static DWORD
convert_url_canonicalization_flags(DWORD dwFlags
)
2040 DWORD dwUrlFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
2042 if (dwFlags
& ICU_BROWSER_MODE
) dwUrlFlags
|= URL_BROWSER_MODE
;
2043 if (dwFlags
& ICU_DECODE
) dwUrlFlags
|= URL_UNESCAPE
;
2044 if (dwFlags
& ICU_ENCODE_PERCENT
) dwUrlFlags
|= URL_ESCAPE_PERCENT
;
2045 if (dwFlags
& ICU_ENCODE_SPACES_ONLY
) dwUrlFlags
|= URL_ESCAPE_SPACES_ONLY
;
2046 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2047 if (dwFlags
& ICU_NO_ENCODE
) dwUrlFlags
^= URL_ESCAPE_UNSAFE
;
2048 if (dwFlags
& ICU_NO_META
) dwUrlFlags
|= URL_NO_META
;
2053 /***********************************************************************
2054 * InternetCanonicalizeUrlA (WININET.@)
2056 * Escape unsafe characters and spaces
2063 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
2064 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2068 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
2069 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2071 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2072 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2073 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2074 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2079 /***********************************************************************
2080 * InternetCanonicalizeUrlW (WININET.@)
2082 * Escape unsafe characters and spaces
2089 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
2090 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
2094 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
2095 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
2097 dwFlags
= convert_url_canonicalization_flags(dwFlags
);
2098 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
2099 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2100 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
2105 /* #################################################### */
2107 static INTERNET_STATUS_CALLBACK
set_status_callback(
2108 object_header_t
*lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
2110 INTERNET_STATUS_CALLBACK ret
;
2112 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
2113 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
2115 ret
= lpwh
->lpfnStatusCB
;
2116 lpwh
->lpfnStatusCB
= callback
;
2121 /***********************************************************************
2122 * InternetSetStatusCallbackA (WININET.@)
2124 * Sets up a callback function which is called as progress is made
2125 * during an operation.
2128 * Previous callback or NULL on success
2129 * INTERNET_INVALID_STATUS_CALLBACK on failure
2132 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
2133 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2135 INTERNET_STATUS_CALLBACK retVal
;
2136 object_header_t
*lpwh
;
2138 TRACE("%p\n", hInternet
);
2140 if (!(lpwh
= get_handle_object(hInternet
)))
2141 return INTERNET_INVALID_STATUS_CALLBACK
;
2143 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
2145 WININET_Release( lpwh
);
2149 /***********************************************************************
2150 * InternetSetStatusCallbackW (WININET.@)
2152 * Sets up a callback function which is called as progress is made
2153 * during an operation.
2156 * Previous callback or NULL on success
2157 * INTERNET_INVALID_STATUS_CALLBACK on failure
2160 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
2161 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
2163 INTERNET_STATUS_CALLBACK retVal
;
2164 object_header_t
*lpwh
;
2166 TRACE("%p\n", hInternet
);
2168 if (!(lpwh
= get_handle_object(hInternet
)))
2169 return INTERNET_INVALID_STATUS_CALLBACK
;
2171 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
2173 WININET_Release( lpwh
);
2177 /***********************************************************************
2178 * InternetSetFilePointer (WININET.@)
2180 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
2181 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
2183 FIXME("(%p %d %p %d %lx): stub\n", hFile
, lDistanceToMove
, pReserved
, dwMoveContext
, dwContext
);
2187 /***********************************************************************
2188 * InternetWriteFile (WININET.@)
2190 * Write data to an open internet file
2197 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
2198 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
2200 object_header_t
*lpwh
;
2203 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2205 lpwh
= get_handle_object( hFile
);
2207 WARN("Invalid handle\n");
2208 SetLastError(ERROR_INVALID_HANDLE
);
2212 if(lpwh
->vtbl
->WriteFile
) {
2213 res
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
2215 WARN("No Writefile method.\n");
2216 res
= ERROR_INVALID_HANDLE
;
2219 WININET_Release( lpwh
);
2221 if(res
!= ERROR_SUCCESS
)
2223 return res
== ERROR_SUCCESS
;
2227 /***********************************************************************
2228 * InternetReadFile (WININET.@)
2230 * Read data from an open internet file
2237 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
2238 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
2240 object_header_t
*hdr
;
2241 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2243 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2245 hdr
= get_handle_object(hFile
);
2247 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2251 if(hdr
->vtbl
->ReadFile
)
2252 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
2254 WININET_Release(hdr
);
2256 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
2257 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
2259 if(res
!= ERROR_SUCCESS
)
2261 return res
== ERROR_SUCCESS
;
2264 /***********************************************************************
2265 * InternetReadFileExA (WININET.@)
2267 * Read data from an open internet file
2270 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2271 * lpBuffersOut [I/O] Buffer.
2272 * dwFlags [I] Flags. See notes.
2273 * dwContext [I] Context for callbacks.
2280 * The parameter dwFlags include zero or more of the following flags:
2281 *|IRF_ASYNC - Makes the call asynchronous.
2282 *|IRF_SYNC - Makes the call synchronous.
2283 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2284 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2286 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2289 * InternetOpenUrlA(), HttpOpenRequestA()
2291 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
2292 DWORD dwFlags
, DWORD_PTR dwContext
)
2294 object_header_t
*hdr
;
2295 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2297 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
2299 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
)) {
2300 SetLastError(ERROR_INVALID_PARAMETER
);
2304 hdr
= get_handle_object(hFile
);
2306 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2310 if(hdr
->vtbl
->ReadFileEx
)
2311 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffersOut
->lpvBuffer
, lpBuffersOut
->dwBufferLength
,
2312 &lpBuffersOut
->dwBufferLength
, dwFlags
, dwContext
);
2314 WININET_Release(hdr
);
2316 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2317 res
, lpBuffersOut
->dwBufferLength
);
2319 if(res
!= ERROR_SUCCESS
)
2321 return res
== ERROR_SUCCESS
;
2324 /***********************************************************************
2325 * InternetReadFileExW (WININET.@)
2327 * InternetReadFileExA()
2329 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2330 DWORD dwFlags
, DWORD_PTR dwContext
)
2332 object_header_t
*hdr
;
2333 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2335 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2337 if (lpBuffer
->dwStructSize
!= sizeof(*lpBuffer
)) {
2338 SetLastError(ERROR_INVALID_PARAMETER
);
2342 hdr
= get_handle_object(hFile
);
2344 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2348 if(hdr
->vtbl
->ReadFileEx
)
2349 res
= hdr
->vtbl
->ReadFileEx(hdr
, lpBuffer
->lpvBuffer
, lpBuffer
->dwBufferLength
, &lpBuffer
->dwBufferLength
,
2350 dwFlags
, dwContext
);
2352 WININET_Release(hdr
);
2354 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
2355 res
, lpBuffer
->dwBufferLength
);
2357 if(res
!= ERROR_SUCCESS
)
2359 return res
== ERROR_SUCCESS
;
2362 static BOOL
get_proxy_autoconfig_url( char *buf
, DWORD buflen
)
2364 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2366 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
2370 if (!settings
) return FALSE
;
2372 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
2374 CFRelease( settings
);
2377 if (CFStringGetCString( ref
, buf
, buflen
, kCFStringEncodingASCII
))
2379 TRACE( "returning %s\n", debugstr_a(buf
) );
2382 CFRelease( settings
);
2385 FIXME( "no support on this platform\n" );
2390 static DWORD
query_global_option(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2392 /* FIXME: This function currently handles more options than it should. Options requiring
2393 * proper handles should be moved to proper functions */
2395 case INTERNET_OPTION_HTTP_VERSION
:
2396 if (*size
< sizeof(HTTP_VERSION_INFO
))
2397 return ERROR_INSUFFICIENT_BUFFER
;
2400 * Presently hardcoded to 1.1
2402 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2403 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2404 *size
= sizeof(HTTP_VERSION_INFO
);
2406 return ERROR_SUCCESS
;
2408 case INTERNET_OPTION_CONNECTED_STATE
:
2409 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2411 if (*size
< sizeof(ULONG
))
2412 return ERROR_INSUFFICIENT_BUFFER
;
2414 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2415 *size
= sizeof(ULONG
);
2417 return ERROR_SUCCESS
;
2419 case INTERNET_OPTION_PROXY
: {
2423 TRACE("Getting global proxy info\n");
2424 memset(&ai
, 0, sizeof(appinfo_t
));
2425 INTERNET_ConfigureProxy(&ai
);
2427 ret
= APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2428 APPINFO_Destroy(&ai
.hdr
);
2432 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2433 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2435 if (*size
< sizeof(ULONG
))
2436 return ERROR_INSUFFICIENT_BUFFER
;
2438 *(ULONG
*)buffer
= max_conns
;
2439 *size
= sizeof(ULONG
);
2441 return ERROR_SUCCESS
;
2443 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2444 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2446 if (*size
< sizeof(ULONG
))
2447 return ERROR_INSUFFICIENT_BUFFER
;
2449 *(ULONG
*)buffer
= max_1_0_conns
;
2450 *size
= sizeof(ULONG
);
2452 return ERROR_SUCCESS
;
2454 case INTERNET_OPTION_SECURITY_FLAGS
:
2455 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2456 return ERROR_SUCCESS
;
2458 case INTERNET_OPTION_VERSION
: {
2459 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2461 TRACE("INTERNET_OPTION_VERSION\n");
2463 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2464 return ERROR_INSUFFICIENT_BUFFER
;
2466 memcpy(buffer
, &info
, sizeof(info
));
2467 *size
= sizeof(info
);
2469 return ERROR_SUCCESS
;
2472 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2473 char url
[INTERNET_MAX_URL_LENGTH
+ 1];
2474 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2475 INTERNET_PER_CONN_OPTION_LISTA
*conA
= buffer
;
2476 DWORD res
= ERROR_SUCCESS
, i
;
2481 TRACE("Getting global proxy info\n");
2482 if((ret
= INTERNET_LoadProxySettings(&pi
)))
2485 have_url
= get_proxy_autoconfig_url(url
, sizeof(url
));
2487 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2489 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
)) {
2491 return ERROR_INSUFFICIENT_BUFFER
;
2494 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2495 INTERNET_PER_CONN_OPTIONW
*optionW
= con
->pOptions
+ i
;
2496 INTERNET_PER_CONN_OPTIONA
*optionA
= conA
->pOptions
+ i
;
2498 switch (optionW
->dwOption
) {
2499 case INTERNET_PER_CONN_FLAGS
:
2501 optionW
->Value
.dwValue
= PROXY_TYPE_PROXY
;
2503 optionW
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2505 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2506 optionW
->Value
.dwValue
|= PROXY_TYPE_DIRECT
|PROXY_TYPE_AUTO_PROXY_URL
;
2509 case INTERNET_PER_CONN_PROXY_SERVER
:
2511 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxy
);
2513 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxy
);
2516 case INTERNET_PER_CONN_PROXY_BYPASS
:
2518 optionW
->Value
.pszValue
= heap_strdupW(pi
.proxyBypass
);
2520 optionA
->Value
.pszValue
= heap_strdupWtoA(pi
.proxyBypass
);
2523 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2525 optionW
->Value
.pszValue
= NULL
;
2527 optionW
->Value
.pszValue
= heap_strdupAtoW(url
);
2529 optionA
->Value
.pszValue
= heap_strdupA(url
);
2532 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2533 optionW
->Value
.dwValue
= AUTO_PROXY_FLAG_ALWAYS_DETECT
;
2536 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2537 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2538 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2539 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2540 FIXME("Unhandled dwOption %d\n", optionW
->dwOption
);
2541 memset(&optionW
->Value
, 0, sizeof(optionW
->Value
));
2545 FIXME("Unknown dwOption %d\n", optionW
->dwOption
);
2546 res
= ERROR_INVALID_PARAMETER
;
2554 case INTERNET_OPTION_REQUEST_FLAGS
:
2555 case INTERNET_OPTION_USER_AGENT
:
2557 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2558 case INTERNET_OPTION_POLICY
:
2559 return ERROR_INVALID_PARAMETER
;
2560 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2561 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2563 if (*size
< sizeof(ULONG
))
2564 return ERROR_INSUFFICIENT_BUFFER
;
2566 *(ULONG
*)buffer
= connect_timeout
;
2567 *size
= sizeof(ULONG
);
2569 return ERROR_SUCCESS
;
2572 FIXME("Stub for %d\n", option
);
2573 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2576 DWORD
INET_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2579 case INTERNET_OPTION_CONTEXT_VALUE
:
2581 return ERROR_INVALID_PARAMETER
;
2583 if (*size
< sizeof(DWORD_PTR
)) {
2584 *size
= sizeof(DWORD_PTR
);
2585 return ERROR_INSUFFICIENT_BUFFER
;
2588 return ERROR_INVALID_PARAMETER
;
2590 *(DWORD_PTR
*)buffer
= hdr
->dwContext
;
2591 *size
= sizeof(DWORD_PTR
);
2592 return ERROR_SUCCESS
;
2594 case INTERNET_OPTION_REQUEST_FLAGS
:
2595 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2596 *size
= sizeof(DWORD
);
2597 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2599 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2600 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2601 WARN("Called on global option %u\n", option
);
2602 return ERROR_INTERNET_INVALID_OPERATION
;
2605 /* FIXME: we shouldn't call it here */
2606 return query_global_option(option
, buffer
, size
, unicode
);
2609 /***********************************************************************
2610 * InternetQueryOptionW (WININET.@)
2612 * Queries an options on the specified handle
2619 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2620 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2622 object_header_t
*hdr
;
2623 DWORD res
= ERROR_INVALID_HANDLE
;
2625 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2628 hdr
= get_handle_object(hInternet
);
2630 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2631 WININET_Release(hdr
);
2634 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2637 if(res
!= ERROR_SUCCESS
)
2639 return res
== ERROR_SUCCESS
;
2642 /***********************************************************************
2643 * InternetQueryOptionA (WININET.@)
2645 * Queries an options on the specified handle
2652 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2653 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2655 object_header_t
*hdr
;
2656 DWORD res
= ERROR_INVALID_HANDLE
;
2658 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2661 hdr
= get_handle_object(hInternet
);
2663 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2664 WININET_Release(hdr
);
2667 res
= query_global_option(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2670 if(res
!= ERROR_SUCCESS
)
2672 return res
== ERROR_SUCCESS
;
2675 DWORD
INET_SetOption(object_header_t
*hdr
, DWORD option
, void *buf
, DWORD size
)
2678 case INTERNET_OPTION_CALLBACK
:
2679 WARN("Not settable option %u\n", option
);
2680 return ERROR_INTERNET_OPTION_NOT_SETTABLE
;
2681 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2682 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2683 WARN("Called on global option %u\n", option
);
2684 return ERROR_INTERNET_INVALID_OPERATION
;
2687 return ERROR_INTERNET_INVALID_OPTION
;
2690 static DWORD
set_global_option(DWORD option
, void *buf
, DWORD size
)
2693 case INTERNET_OPTION_CALLBACK
:
2694 WARN("Not global option %u\n", option
);
2695 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2697 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2698 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2700 if(size
!= sizeof(max_conns
))
2701 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2703 return ERROR_BAD_ARGUMENTS
;
2705 max_conns
= *(ULONG
*)buf
;
2706 return ERROR_SUCCESS
;
2708 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2709 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2711 if(size
!= sizeof(max_1_0_conns
))
2712 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2714 return ERROR_BAD_ARGUMENTS
;
2716 max_1_0_conns
= *(ULONG
*)buf
;
2717 return ERROR_SUCCESS
;
2719 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2720 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2722 if(size
!= sizeof(connect_timeout
))
2723 return ERROR_INTERNET_BAD_OPTION_LENGTH
;
2725 return ERROR_BAD_ARGUMENTS
;
2727 connect_timeout
= *(ULONG
*)buf
;
2728 return ERROR_SUCCESS
;
2730 case INTERNET_OPTION_SETTINGS_CHANGED
:
2731 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2732 collect_connections(COLLECT_CONNECTIONS
);
2733 return ERROR_SUCCESS
;
2736 return ERROR_INTERNET_INVALID_OPTION
;
2739 /***********************************************************************
2740 * InternetSetOptionW (WININET.@)
2742 * Sets an options on the specified handle
2749 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2750 LPVOID lpBuffer
, DWORD dwBufferLength
)
2752 object_header_t
*lpwhh
;
2756 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2758 lpwhh
= (object_header_t
*) get_handle_object( hInternet
);
2760 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2762 res
= set_global_option(dwOption
, lpBuffer
, dwBufferLength
);
2764 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2766 WININET_Release(lpwhh
);
2768 if(res
!= ERROR_SUCCESS
)
2771 return res
== ERROR_SUCCESS
;
2776 case INTERNET_OPTION_HTTP_VERSION
:
2778 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2779 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2782 case INTERNET_OPTION_ERROR_MASK
:
2785 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2787 } else if(*(ULONG
*)lpBuffer
& (~(INTERNET_ERROR_MASK_INSERT_CDROM
|
2788 INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|
2789 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
))) {
2790 SetLastError(ERROR_INVALID_PARAMETER
);
2792 } else if(dwBufferLength
!= sizeof(ULONG
)) {
2793 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH
);
2796 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG
*)lpBuffer
);
2797 lpwhh
->ErrorMask
= *(ULONG
*)lpBuffer
;
2800 case INTERNET_OPTION_PROXY
:
2802 INTERNET_PROXY_INFOW
*info
= lpBuffer
;
2804 if (!lpBuffer
|| dwBufferLength
< sizeof(INTERNET_PROXY_INFOW
))
2806 SetLastError(ERROR_INVALID_PARAMETER
);
2811 EnterCriticalSection( &WININET_cs
);
2812 free_global_proxy();
2813 global_proxy
= heap_alloc( sizeof(proxyinfo_t
) );
2816 if (info
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
)
2818 global_proxy
->proxyEnabled
= 1;
2819 global_proxy
->proxy
= heap_strdupW( info
->lpszProxy
);
2820 global_proxy
->proxyBypass
= heap_strdupW( info
->lpszProxyBypass
);
2824 global_proxy
->proxyEnabled
= 0;
2825 global_proxy
->proxy
= global_proxy
->proxyBypass
= NULL
;
2828 LeaveCriticalSection( &WININET_cs
);
2832 /* In general, each type of object should handle
2833 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2834 * get silently dropped.
2836 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2837 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2842 case INTERNET_OPTION_CODEPAGE
:
2844 ULONG codepage
= *(ULONG
*)lpBuffer
;
2845 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2848 case INTERNET_OPTION_REQUEST_PRIORITY
:
2850 ULONG priority
= *(ULONG
*)lpBuffer
;
2851 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2854 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2856 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2857 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2860 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2862 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2863 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2866 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2867 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2869 case INTERNET_OPTION_END_BROWSER_SESSION
:
2870 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2872 case INTERNET_OPTION_CONNECTED_STATE
:
2873 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2875 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2876 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2878 case INTERNET_OPTION_SEND_TIMEOUT
:
2879 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2880 case INTERNET_OPTION_DATA_SEND_TIMEOUT
:
2882 ULONG timeout
= *(ULONG
*)lpBuffer
;
2883 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout
);
2886 case INTERNET_OPTION_CONNECT_RETRIES
:
2888 ULONG retries
= *(ULONG
*)lpBuffer
;
2889 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2892 case INTERNET_OPTION_CONTEXT_VALUE
:
2896 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2899 if (!lpBuffer
|| dwBufferLength
!= sizeof(DWORD_PTR
))
2901 SetLastError(ERROR_INVALID_PARAMETER
);
2905 lpwhh
->dwContext
= *(DWORD_PTR
*)lpBuffer
;
2908 case INTERNET_OPTION_SECURITY_FLAGS
:
2909 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2911 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2912 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2914 case INTERNET_OPTION_HTTP_DECODING
:
2915 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2916 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2919 case INTERNET_OPTION_COOKIES_3RD_PARTY
:
2920 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2921 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2924 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY
:
2925 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2926 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2929 case INTERNET_OPTION_CODEPAGE_PATH
:
2930 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2931 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2934 case INTERNET_OPTION_CODEPAGE_EXTRA
:
2935 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2936 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2939 case INTERNET_OPTION_IDN
:
2940 FIXME("INTERNET_OPTION_IDN; STUB\n");
2941 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2944 case INTERNET_OPTION_POLICY
:
2945 SetLastError(ERROR_INVALID_PARAMETER
);
2948 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2949 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2954 if (INTERNET_LoadProxySettings(&pi
)) return FALSE
;
2956 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2957 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2959 switch (option
->dwOption
) {
2960 case INTERNET_PER_CONN_PROXY_SERVER
:
2961 heap_free(pi
.proxy
);
2962 pi
.proxy
= heap_strdupW(option
->Value
.pszValue
);
2965 case INTERNET_PER_CONN_FLAGS
:
2966 if(option
->Value
.dwValue
& PROXY_TYPE_PROXY
)
2967 pi
.proxyEnabled
= 1;
2970 if(option
->Value
.dwValue
!= PROXY_TYPE_DIRECT
)
2971 FIXME("Unhandled flags: 0x%x\n", option
->Value
.dwValue
);
2972 pi
.proxyEnabled
= 0;
2976 case INTERNET_PER_CONN_PROXY_BYPASS
:
2977 heap_free(pi
.proxyBypass
);
2978 pi
.proxyBypass
= heap_strdupW(option
->Value
.pszValue
);
2981 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2982 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2983 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2984 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2985 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2986 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2987 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2991 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2992 SetLastError(ERROR_INVALID_PARAMETER
);
2997 if ((res
= INTERNET_SaveProxySettings(&pi
)))
3002 ret
= (res
== ERROR_SUCCESS
);
3006 FIXME("Option %d STUB\n",dwOption
);
3007 SetLastError(ERROR_INTERNET_INVALID_OPTION
);
3013 WININET_Release( lpwhh
);
3019 /***********************************************************************
3020 * InternetSetOptionA (WININET.@)
3022 * Sets an options on the specified handle.
3029 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
3030 LPVOID lpBuffer
, DWORD dwBufferLength
)
3038 case INTERNET_OPTION_PROXY
:
3040 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
3041 LPINTERNET_PROXY_INFOW piw
;
3042 DWORD proxlen
, prbylen
;
3045 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
3046 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
3047 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
3048 wbuffer
= heap_alloc(wlen
*sizeof(WCHAR
) );
3049 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
3050 piw
->dwAccessType
= pi
->dwAccessType
;
3051 prox
= (LPWSTR
) &piw
[1];
3052 prby
= &prox
[proxlen
+1];
3053 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
3054 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
3055 piw
->lpszProxy
= prox
;
3056 piw
->lpszProxyBypass
= prby
;
3059 case INTERNET_OPTION_USER_AGENT
:
3060 case INTERNET_OPTION_USERNAME
:
3061 case INTERNET_OPTION_PASSWORD
:
3062 case INTERNET_OPTION_PROXY_USERNAME
:
3063 case INTERNET_OPTION_PROXY_PASSWORD
:
3064 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, NULL
, 0 );
3065 if (!(wbuffer
= heap_alloc( wlen
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
3066 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, -1, wbuffer
, wlen
);
3068 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
3070 INTERNET_PER_CONN_OPTION_LISTW
*listW
;
3071 INTERNET_PER_CONN_OPTION_LISTA
*listA
= lpBuffer
;
3072 wlen
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3073 wbuffer
= heap_alloc(wlen
);
3076 listW
->dwSize
= sizeof(INTERNET_PER_CONN_OPTION_LISTW
);
3077 if (listA
->pszConnection
)
3079 wlen
= MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, NULL
, 0 );
3080 listW
->pszConnection
= heap_alloc(wlen
*sizeof(WCHAR
));
3081 MultiByteToWideChar( CP_ACP
, 0, listA
->pszConnection
, -1, listW
->pszConnection
, wlen
);
3084 listW
->pszConnection
= NULL
;
3085 listW
->dwOptionCount
= listA
->dwOptionCount
;
3086 listW
->dwOptionError
= listA
->dwOptionError
;
3087 listW
->pOptions
= heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW
) * listA
->dwOptionCount
);
3089 for (i
= 0; i
< listA
->dwOptionCount
; ++i
) {
3090 INTERNET_PER_CONN_OPTIONA
*optA
= listA
->pOptions
+ i
;
3091 INTERNET_PER_CONN_OPTIONW
*optW
= listW
->pOptions
+ i
;
3093 optW
->dwOption
= optA
->dwOption
;
3095 switch (optA
->dwOption
) {
3096 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3097 case INTERNET_PER_CONN_PROXY_BYPASS
:
3098 case INTERNET_PER_CONN_PROXY_SERVER
:
3099 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3100 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3101 if (optA
->Value
.pszValue
)
3103 wlen
= MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, NULL
, 0 );
3104 optW
->Value
.pszValue
= heap_alloc(wlen
*sizeof(WCHAR
));
3105 MultiByteToWideChar( CP_ACP
, 0, optA
->Value
.pszValue
, -1, optW
->Value
.pszValue
, wlen
);
3108 optW
->Value
.pszValue
= NULL
;
3110 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
3111 case INTERNET_PER_CONN_FLAGS
:
3112 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
3113 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3115 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
3116 optW
->Value
.ftValue
= optA
->Value
.ftValue
;
3119 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA
->dwOption
);
3120 optW
->Value
.dwValue
= optA
->Value
.dwValue
;
3128 wlen
= dwBufferLength
;
3131 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
3133 if( lpBuffer
!= wbuffer
)
3135 if (dwOption
== INTERNET_OPTION_PER_CONNECTION_OPTION
)
3137 INTERNET_PER_CONN_OPTION_LISTW
*list
= wbuffer
;
3139 for (i
= 0; i
< list
->dwOptionCount
; ++i
) {
3140 INTERNET_PER_CONN_OPTIONW
*opt
= list
->pOptions
+ i
;
3141 switch (opt
->dwOption
) {
3142 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
3143 case INTERNET_PER_CONN_PROXY_BYPASS
:
3144 case INTERNET_PER_CONN_PROXY_SERVER
:
3145 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
3146 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
3147 heap_free( opt
->Value
.pszValue
);
3153 heap_free( list
->pOptions
);
3155 heap_free( wbuffer
);
3162 /***********************************************************************