4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
58 #include "wine/debug.h"
60 #define NO_SHLWAPI_STREAM
64 #include "wine/exception.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
73 #define RESPONSE_TIMEOUT 30
78 CHAR response
[MAX_REPLY_LEN
];
79 } WITHREADERROR
, *LPWITHREADERROR
;
81 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
82 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
);
84 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
85 static HMODULE WININET_hModule
;
87 #define HANDLE_CHUNK_SIZE 0x10
89 static CRITICAL_SECTION WININET_cs
;
90 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
93 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
94 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
96 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
98 static LPWININETHANDLEHEADER
*WININET_Handles
;
99 static UINT WININET_dwNextHandle
;
100 static UINT WININET_dwMaxHandles
;
102 HINTERNET
WININET_AllocHandle( LPWININETHANDLEHEADER info
)
104 LPWININETHANDLEHEADER
*p
;
105 UINT handle
= 0, num
;
107 list_init( &info
->children
);
109 EnterCriticalSection( &WININET_cs
);
110 if( !WININET_dwMaxHandles
)
112 num
= HANDLE_CHUNK_SIZE
;
113 p
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
118 WININET_dwMaxHandles
= num
;
120 if( WININET_dwMaxHandles
== WININET_dwNextHandle
)
122 num
= WININET_dwMaxHandles
+ HANDLE_CHUNK_SIZE
;
123 p
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
124 WININET_Handles
, sizeof (UINT
)* num
);
128 WININET_dwMaxHandles
= num
;
131 handle
= WININET_dwNextHandle
;
132 if( WININET_Handles
[handle
] )
133 ERR("handle isn't free but should be\n");
134 WININET_Handles
[handle
] = WININET_AddRef( info
);
136 while( WININET_Handles
[WININET_dwNextHandle
] &&
137 (WININET_dwNextHandle
< WININET_dwMaxHandles
) )
138 WININET_dwNextHandle
++;
141 LeaveCriticalSection( &WININET_cs
);
143 return info
->hInternet
= (HINTERNET
) (handle
+1);
146 LPWININETHANDLEHEADER
WININET_AddRef( LPWININETHANDLEHEADER info
)
148 ULONG refs
= InterlockedIncrement(&info
->refs
);
149 TRACE("%p -> refcount = %d\n", info
, refs
);
153 LPWININETHANDLEHEADER
WININET_GetObject( HINTERNET hinternet
)
155 LPWININETHANDLEHEADER info
= NULL
;
156 UINT handle
= (UINT
) hinternet
;
158 EnterCriticalSection( &WININET_cs
);
160 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) &&
161 WININET_Handles
[handle
-1] )
162 info
= WININET_AddRef( WININET_Handles
[handle
-1] );
164 LeaveCriticalSection( &WININET_cs
);
166 TRACE("handle %d -> %p\n", handle
, info
);
171 BOOL
WININET_Release( LPWININETHANDLEHEADER info
)
173 ULONG refs
= InterlockedDecrement(&info
->refs
);
174 TRACE( "object %p refcount = %d\n", info
, refs
);
177 if ( info
->vtbl
->CloseConnection
)
179 TRACE( "closing connection %p\n", info
);
180 info
->vtbl
->CloseConnection( info
);
182 INTERNET_SendCallback(info
, info
->dwContext
,
183 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
185 TRACE( "destroying object %p\n", info
);
186 if ( info
->htype
!= WH_HINIT
)
187 list_remove( &info
->entry
);
188 info
->vtbl
->Destroy( info
);
193 BOOL
WININET_FreeHandle( HINTERNET hinternet
)
196 UINT handle
= (UINT
) hinternet
;
197 LPWININETHANDLEHEADER info
= NULL
, child
, next
;
199 EnterCriticalSection( &WININET_cs
);
201 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) )
204 if( WININET_Handles
[handle
] )
206 info
= WININET_Handles
[handle
];
207 TRACE( "destroying handle %d for object %p\n", handle
+1, info
);
208 WININET_Handles
[handle
] = NULL
;
213 LeaveCriticalSection( &WININET_cs
);
215 /* As on native when the equivalent of WININET_Release is called, the handle
216 * is already invalid, but if a new handle is created at this time it does
217 * not yet get assigned the freed handle number */
220 /* Free all children as native does */
221 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, WININETHANDLEHEADER
, entry
)
223 TRACE( "freeing child handle %d for parent handle %d\n",
224 (UINT
)child
->hInternet
, handle
+1);
225 WININET_FreeHandle( child
->hInternet
);
227 WININET_Release( info
);
230 EnterCriticalSection( &WININET_cs
);
232 if( WININET_dwNextHandle
> handle
&& !WININET_Handles
[handle
] )
233 WININET_dwNextHandle
= handle
;
235 LeaveCriticalSection( &WININET_cs
);
240 /***********************************************************************
241 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
244 * hinstDLL [I] handle to the DLL's instance
246 * lpvReserved [I] reserved, must be NULL
253 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
255 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
258 case DLL_PROCESS_ATTACH
:
260 g_dwTlsErrIndex
= TlsAlloc();
262 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
265 URLCacheContainers_CreateDefaults();
267 WININET_hModule
= hinstDLL
;
269 case DLL_THREAD_ATTACH
:
272 case DLL_THREAD_DETACH
:
273 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
275 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
276 HeapFree(GetProcessHeap(), 0, lpwite
);
280 case DLL_PROCESS_DETACH
:
282 URLCacheContainers_DeleteAll();
284 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
286 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
287 TlsFree(g_dwTlsErrIndex
);
296 /***********************************************************************
297 * InternetInitializeAutoProxyDll (WININET.@)
299 * Setup the internal proxy
308 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
311 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
315 /***********************************************************************
316 * DetectAutoProxyUrl (WININET.@)
318 * Auto detect the proxy url
324 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
325 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
328 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
333 /***********************************************************************
334 * INTERNET_ConfigureProxyFromReg
337 * The proxy may be specified in the form 'http=proxy.my.org'
338 * Presumably that means there can be ftp=ftpproxy.my.org too.
340 static BOOL
INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai
)
343 DWORD r
, keytype
, len
, enabled
;
344 LPCSTR lpszInternetSettings
=
345 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
346 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
348 r
= RegOpenKeyA(HKEY_CURRENT_USER
, lpszInternetSettings
, &key
);
349 if ( r
!= ERROR_SUCCESS
)
352 len
= sizeof enabled
;
353 r
= RegQueryValueExA( key
, "ProxyEnable", NULL
, &keytype
,
354 (BYTE
*)&enabled
, &len
);
355 if( (r
== ERROR_SUCCESS
) && enabled
)
357 TRACE("Proxy is enabled.\n");
359 /* figure out how much memory the proxy setting takes */
360 r
= RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
362 if( (r
== ERROR_SUCCESS
) && len
&& (keytype
== REG_SZ
) )
365 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
367 szProxy
=HeapAlloc( GetProcessHeap(), 0, len
);
368 RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
369 (BYTE
*)szProxy
, &len
);
371 /* find the http proxy, and strip away everything else */
372 p
= strstrW( szProxy
, szHttp
);
375 p
+= lstrlenW(szHttp
);
376 lstrcpyW( szProxy
, p
);
378 p
= strchrW( szProxy
, ' ' );
382 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
383 lpwai
->lpszProxy
= szProxy
;
385 TRACE("http proxy = %s\n", debugstr_w(lpwai
->lpszProxy
));
388 ERR("Couldn't read proxy server settings.\n");
391 TRACE("Proxy is not enabled.\n");
397 /***********************************************************************
398 * dump_INTERNET_FLAGS
400 * Helper function to TRACE the internet flags.
406 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
408 #define FE(x) { x, #x }
409 static const wininet_flag_info flag
[] = {
410 FE(INTERNET_FLAG_RELOAD
),
411 FE(INTERNET_FLAG_RAW_DATA
),
412 FE(INTERNET_FLAG_EXISTING_CONNECT
),
413 FE(INTERNET_FLAG_ASYNC
),
414 FE(INTERNET_FLAG_PASSIVE
),
415 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
416 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
417 FE(INTERNET_FLAG_FROM_CACHE
),
418 FE(INTERNET_FLAG_SECURE
),
419 FE(INTERNET_FLAG_KEEP_CONNECTION
),
420 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
421 FE(INTERNET_FLAG_READ_PREFETCH
),
422 FE(INTERNET_FLAG_NO_COOKIES
),
423 FE(INTERNET_FLAG_NO_AUTH
),
424 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
425 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
426 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
427 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
428 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
429 FE(INTERNET_FLAG_RESYNCHRONIZE
),
430 FE(INTERNET_FLAG_HYPERLINK
),
431 FE(INTERNET_FLAG_NO_UI
),
432 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
433 FE(INTERNET_FLAG_CACHE_ASYNC
),
434 FE(INTERNET_FLAG_FORMS_SUBMIT
),
435 FE(INTERNET_FLAG_NEED_FILE
),
436 FE(INTERNET_FLAG_TRANSFER_ASCII
),
437 FE(INTERNET_FLAG_TRANSFER_BINARY
)
442 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
443 if (flag
[i
].val
& dwFlags
) {
444 TRACE(" %s", flag
[i
].name
);
445 dwFlags
&= ~flag
[i
].val
;
449 TRACE(" Unknown flags (%08x)\n", dwFlags
);
454 /***********************************************************************
455 * INTERNET_CloseHandle (internal)
457 * Close internet handle
460 static VOID
APPINFO_Destroy(WININETHANDLEHEADER
*hdr
)
462 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
466 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
467 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
468 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
469 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
470 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
471 HeapFree(GetProcessHeap(), 0, lpwai
);
474 static DWORD
APPINFO_QueryOption(WININETHANDLEHEADER
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
477 case INTERNET_OPTION_HANDLE_TYPE
:
478 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
480 if (*size
< sizeof(ULONG
))
481 return ERROR_INSUFFICIENT_BUFFER
;
483 *size
= sizeof(DWORD
);
484 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
485 return ERROR_SUCCESS
;
488 FIXME("Not implemented option %d\n", option
);
489 return ERROR_INTERNET_INVALID_OPTION
;
492 static const HANDLEHEADERVtbl APPINFOVtbl
= {
505 /***********************************************************************
506 * InternetOpenW (WININET.@)
508 * Per-application initialization of wininet
511 * HINTERNET on success
515 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
516 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
518 LPWININETAPPINFOW lpwai
= NULL
;
519 HINTERNET handle
= NULL
;
521 if (TRACE_ON(wininet
)) {
522 #define FE(x) { x, #x }
523 static const wininet_flag_info access_type
[] = {
524 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
525 FE(INTERNET_OPEN_TYPE_DIRECT
),
526 FE(INTERNET_OPEN_TYPE_PROXY
),
527 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
531 const char *access_type_str
= "Unknown";
533 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
534 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
535 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
536 if (access_type
[i
].val
== dwAccessType
) {
537 access_type_str
= access_type
[i
].name
;
541 TRACE(" access type : %s\n", access_type_str
);
543 dump_INTERNET_FLAGS(dwFlags
);
546 /* Clear any error information */
547 INTERNET_SetLastError(0);
549 lpwai
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETAPPINFOW
));
552 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
556 lpwai
->hdr
.htype
= WH_HINIT
;
557 lpwai
->hdr
.vtbl
= &APPINFOVtbl
;
558 lpwai
->hdr
.dwFlags
= dwFlags
;
560 lpwai
->dwAccessType
= dwAccessType
;
561 lpwai
->lpszProxyUsername
= NULL
;
562 lpwai
->lpszProxyPassword
= NULL
;
564 handle
= WININET_AllocHandle( &lpwai
->hdr
);
567 HeapFree( GetProcessHeap(), 0, lpwai
);
568 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
572 if (NULL
!= lpszAgent
)
574 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
575 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
576 if (lpwai
->lpszAgent
)
577 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
579 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
580 INTERNET_ConfigureProxyFromReg( lpwai
);
581 else if (NULL
!= lpszProxy
)
583 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
584 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
585 if (lpwai
->lpszProxy
)
586 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
589 if (NULL
!= lpszProxyBypass
)
591 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
592 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
593 if (lpwai
->lpszProxyBypass
)
594 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
599 WININET_Release( &lpwai
->hdr
);
601 TRACE("returning %p\n", lpwai
);
607 /***********************************************************************
608 * InternetOpenA (WININET.@)
610 * Per-application initialization of wininet
613 * HINTERNET on success
617 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
618 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
622 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
624 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
625 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
629 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
630 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
631 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
636 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
637 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
638 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
641 if( lpszProxyBypass
)
643 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
644 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
645 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
648 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
650 HeapFree(GetProcessHeap(), 0, szAgent
);
651 HeapFree(GetProcessHeap(), 0, szProxy
);
652 HeapFree(GetProcessHeap(), 0, szBypass
);
657 /***********************************************************************
658 * InternetGetLastResponseInfoA (WININET.@)
660 * Return last wininet error description on the calling thread
663 * TRUE on success of writing to buffer
667 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
668 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
670 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
676 *lpdwError
= lpwite
->dwError
;
679 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
680 *lpdwBufferLength
= strlen(lpszBuffer
);
683 *lpdwBufferLength
= 0;
688 *lpdwBufferLength
= 0;
694 /***********************************************************************
695 * InternetGetLastResponseInfoW (WININET.@)
697 * Return last wininet error description on the calling thread
700 * TRUE on success of writing to buffer
704 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
705 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
707 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
713 *lpdwError
= lpwite
->dwError
;
716 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
717 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
720 *lpdwBufferLength
= 0;
725 *lpdwBufferLength
= 0;
731 /***********************************************************************
732 * InternetGetConnectedState (WININET.@)
734 * Return connected state
738 * if lpdwStatus is not null, return the status (off line,
739 * modem, lan...) in it.
740 * FALSE if not connected
742 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
744 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
747 FIXME("always returning LAN connection.\n");
748 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
754 /***********************************************************************
755 * InternetGetConnectedStateExW (WININET.@)
757 * Return connected state
761 * lpdwStatus [O] Flags specifying the status of the internet connection.
762 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
763 * dwNameLen [I] Size of the buffer, in characters.
764 * dwReserved [I] Reserved. Must be set to 0.
768 * if lpdwStatus is not null, return the status (off line,
769 * modem, lan...) in it.
770 * FALSE if not connected
773 * If the system has no available network connections, an empty string is
774 * stored in lpszConnectionName. If there is a LAN connection, a localized
775 * "LAN Connection" string is stored. Presumably, if only a dial-up
776 * connection is available then the name of the dial-up connection is
777 * returned. Why any application, other than the "Internet Settings" CPL,
778 * would want to use this function instead of the simpler InternetGetConnectedStateW
779 * function is beyond me.
781 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
782 DWORD dwNameLen
, DWORD dwReserved
)
784 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
791 FIXME("always returning LAN connection.\n");
792 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
794 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
798 /***********************************************************************
799 * InternetGetConnectedStateExA (WININET.@)
801 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
802 DWORD dwNameLen
, DWORD dwReserved
)
804 LPWSTR lpwszConnectionName
= NULL
;
807 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
809 if (lpszConnectionName
&& dwNameLen
> 0)
810 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
812 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
814 if (rc
&& lpwszConnectionName
)
816 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
817 dwNameLen
, NULL
, NULL
);
819 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
826 /***********************************************************************
827 * InternetConnectW (WININET.@)
829 * Open a ftp, gopher or http session
832 * HINTERNET a session handle on success
836 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
837 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
838 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
839 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
841 LPWININETAPPINFOW hIC
;
844 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
845 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
846 dwService
, dwFlags
, dwContext
);
850 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
854 /* Clear any error information */
855 INTERNET_SetLastError(0);
856 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
857 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
859 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
865 case INTERNET_SERVICE_FTP
:
866 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
867 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
870 case INTERNET_SERVICE_HTTP
:
871 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
872 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
875 case INTERNET_SERVICE_GOPHER
:
881 WININET_Release( &hIC
->hdr
);
883 TRACE("returning %p\n", rc
);
888 /***********************************************************************
889 * InternetConnectA (WININET.@)
891 * Open a ftp, gopher or http session
894 * HINTERNET a session handle on success
898 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
899 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
900 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
901 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
905 LPWSTR szServerName
= NULL
;
906 LPWSTR szUserName
= NULL
;
907 LPWSTR szPassword
= NULL
;
911 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
912 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
913 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
917 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
918 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
919 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
923 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
924 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
925 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
929 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
930 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
932 HeapFree(GetProcessHeap(), 0, szServerName
);
933 HeapFree(GetProcessHeap(), 0, szUserName
);
934 HeapFree(GetProcessHeap(), 0, szPassword
);
939 /***********************************************************************
940 * InternetFindNextFileA (WININET.@)
942 * Continues a file search from a previous call to FindFirstFile
949 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
954 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
956 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
960 /***********************************************************************
961 * InternetFindNextFileW (WININET.@)
963 * Continues a file search from a previous call to FindFirstFile
970 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
972 WININETHANDLEHEADER
*hdr
;
977 hdr
= WININET_GetObject(hFind
);
979 WARN("Invalid handle\n");
980 SetLastError(ERROR_INVALID_HANDLE
);
984 if(hdr
->vtbl
->FindNextFileW
) {
985 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
987 WARN("Handle doesn't support NextFile\n");
988 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
991 WININET_Release(hdr
);
993 if(res
!= ERROR_SUCCESS
)
995 return res
== ERROR_SUCCESS
;
998 /***********************************************************************
999 * InternetCloseHandle (WININET.@)
1001 * Generic close handle function
1008 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1010 LPWININETHANDLEHEADER lpwh
;
1012 TRACE("%p\n",hInternet
);
1014 lpwh
= WININET_GetObject( hInternet
);
1017 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1021 WININET_Release( lpwh
);
1022 WININET_FreeHandle( hInternet
);
1028 /***********************************************************************
1029 * ConvertUrlComponentValue (Internal)
1031 * Helper function for InternetCrackUrlW
1034 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1035 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1036 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1038 TRACE("%p %d %p %d %p %p\n", lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1039 if (*dwComponentLen
!= 0)
1041 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1042 if (*lppszComponent
== NULL
)
1044 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1046 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1048 *lppszComponent
= NULL
;
1049 *dwComponentLen
= nASCIILength
;
1053 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1054 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1055 (*lppszComponent
)[ncpylen
]=0;
1056 *dwComponentLen
= ncpylen
;
1062 /***********************************************************************
1063 * InternetCrackUrlA (WININET.@)
1065 * See InternetCrackUrlW.
1067 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1068 LPURL_COMPONENTSA lpUrlComponents
)
1071 URL_COMPONENTSW UCW
;
1074 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl
), dwUrlLength
, dwFlags
, lpUrlComponents
);
1076 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1077 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1079 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1085 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1087 /* if dwUrlLength=-1 then nLength includes null but length to
1088 InternetCrackUrlW should not include it */
1089 if (dwUrlLength
== -1) nLength
--;
1091 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1092 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1094 memset(&UCW
,0,sizeof(UCW
));
1095 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1096 if(lpUrlComponents
->dwHostNameLength
!=0)
1097 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1098 if(lpUrlComponents
->dwUserNameLength
!=0)
1099 UCW
.dwUserNameLength
=lpUrlComponents
->dwUserNameLength
;
1100 if(lpUrlComponents
->dwPasswordLength
!=0)
1101 UCW
.dwPasswordLength
=lpUrlComponents
->dwPasswordLength
;
1102 if(lpUrlComponents
->dwUrlPathLength
!=0)
1103 UCW
.dwUrlPathLength
=lpUrlComponents
->dwUrlPathLength
;
1104 if(lpUrlComponents
->dwSchemeLength
!=0)
1105 UCW
.dwSchemeLength
=lpUrlComponents
->dwSchemeLength
;
1106 if(lpUrlComponents
->dwExtraInfoLength
!=0)
1107 UCW
.dwExtraInfoLength
=lpUrlComponents
->dwExtraInfoLength
;
1108 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
1110 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1114 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1115 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
1117 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1118 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
1120 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1121 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
1123 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1124 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
1126 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1127 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
1129 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1130 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
1132 lpUrlComponents
->nScheme
=UCW
.nScheme
;
1133 lpUrlComponents
->nPort
=UCW
.nPort
;
1134 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1136 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1137 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
1138 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
1139 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
1140 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
1145 static const WCHAR url_schemes
[][7] =
1148 {'g','o','p','h','e','r',0},
1149 {'h','t','t','p',0},
1150 {'h','t','t','p','s',0},
1151 {'f','i','l','e',0},
1152 {'n','e','w','s',0},
1153 {'m','a','i','l','t','o',0},
1157 /***********************************************************************
1158 * GetInternetSchemeW (internal)
1164 * INTERNET_SCHEME_UNKNOWN on failure
1167 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1171 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1173 if(lpszScheme
==NULL
)
1174 return INTERNET_SCHEME_UNKNOWN
;
1176 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1177 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1178 return INTERNET_SCHEME_FIRST
+ i
;
1180 return INTERNET_SCHEME_UNKNOWN
;
1183 /***********************************************************************
1184 * SetUrlComponentValueW (Internal)
1186 * Helper function for InternetCrackUrlW
1189 * lppszComponent [O] Holds the returned string
1190 * dwComponentLen [I] Holds the size of lppszComponent
1191 * [O] Holds the length of the string in lppszComponent without '\0'
1192 * lpszStart [I] Holds the string to copy from
1193 * len [I] Holds the length of lpszStart without '\0'
1200 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1202 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1204 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1207 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1209 if (*lppszComponent
== NULL
)
1211 *lppszComponent
= (LPWSTR
)lpszStart
;
1212 *dwComponentLen
= len
;
1216 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1217 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1218 (*lppszComponent
)[ncpylen
] = '\0';
1219 *dwComponentLen
= ncpylen
;
1226 /***********************************************************************
1227 * InternetCrackUrlW (WININET.@)
1229 * Break up URL into its components
1235 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1236 LPURL_COMPONENTSW lpUC
)
1240 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1243 LPCWSTR lpszParam
= NULL
;
1244 BOOL bIsAbsolute
= FALSE
;
1245 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1246 LPCWSTR lpszcp
= NULL
;
1247 LPWSTR lpszUrl_decode
= NULL
;
1248 DWORD dwUrlLength
= dwUrlLength_orig
;
1249 const WCHAR lpszSeparators
[3]={';','?',0};
1250 const WCHAR lpszSlash
[2]={'/',0};
1252 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl
), dwUrlLength
, dwFlags
, lpUC
);
1254 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1256 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1259 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1261 if (dwFlags
& ICU_DECODE
)
1263 lpszUrl_decode
=HeapAlloc( GetProcessHeap(), 0, dwUrlLength
* sizeof (WCHAR
) );
1264 if( InternetCanonicalizeUrlW(lpszUrl_orig
, lpszUrl_decode
, &dwUrlLength
, dwFlags
))
1266 lpszUrl
= lpszUrl_decode
;
1271 /* Determine if the URI is absolute. */
1272 while (*lpszap
!= '\0')
1274 if (isalnumW(*lpszap
))
1279 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1286 lpszcp
= lpszUrl
; /* Relative url */
1292 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1293 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1295 /* Parse <params> */
1296 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
1297 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1298 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1300 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1304 /* Get scheme first. */
1305 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1306 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1307 lpszUrl
, lpszcp
- lpszUrl
);
1309 /* Eat ':' in protocol. */
1312 /* double slash indicates the net_loc portion is present */
1313 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1317 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
1321 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1323 lpszNetLoc
= lpszParam
;
1325 else if (!lpszNetLoc
)
1326 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1334 /* [<user>[<:password>]@]<host>[:<port>] */
1335 /* First find the user and password if they exist */
1337 lpszHost
= strchrW(lpszcp
, '@');
1338 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1340 /* username and password not specified. */
1341 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1342 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1344 else /* Parse out username and password */
1346 LPCWSTR lpszUser
= lpszcp
;
1347 LPCWSTR lpszPasswd
= lpszHost
;
1349 while (lpszcp
< lpszHost
)
1352 lpszPasswd
= lpszcp
;
1357 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1358 lpszUser
, lpszPasswd
- lpszUser
);
1360 if (lpszPasswd
!= lpszHost
)
1362 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1363 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1364 lpszHost
- lpszPasswd
);
1366 lpszcp
++; /* Advance to beginning of host */
1369 /* Parse <host><:port> */
1372 lpszPort
= lpszNetLoc
;
1374 /* special case for res:// URLs: there is no port here, so the host is the
1375 entire string up to the first '/' */
1376 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1378 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1379 lpszHost
, lpszPort
- lpszHost
);
1384 while (lpszcp
< lpszNetLoc
)
1392 /* If the scheme is "file" and the host is just one letter, it's not a host */
1393 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1396 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1401 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1402 lpszHost
, lpszPort
- lpszHost
);
1403 if (lpszPort
!= lpszNetLoc
)
1404 lpUC
->nPort
= atoiW(++lpszPort
);
1405 else switch (lpUC
->nScheme
)
1407 case INTERNET_SCHEME_HTTP
:
1408 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1410 case INTERNET_SCHEME_HTTPS
:
1411 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1413 case INTERNET_SCHEME_FTP
:
1414 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1416 case INTERNET_SCHEME_GOPHER
:
1417 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1428 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1429 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1430 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1435 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1436 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1437 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1438 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1441 /* Here lpszcp points to:
1443 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1444 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1446 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1450 /* Only truncate the parameter list if it's already been saved
1451 * in lpUC->lpszExtraInfo.
1453 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1454 len
= lpszParam
- lpszcp
;
1457 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1458 * newlines if necessary.
1460 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1461 if (lpsznewline
!= NULL
)
1462 len
= lpsznewline
- lpszcp
;
1464 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1466 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1471 lpUC
->dwUrlPathLength
= 0;
1474 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1475 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1476 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1477 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1478 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1480 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1484 /***********************************************************************
1485 * InternetAttemptConnect (WININET.@)
1487 * Attempt to make a connection to the internet
1490 * ERROR_SUCCESS on success
1491 * Error value on failure
1494 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1497 return ERROR_SUCCESS
;
1501 /***********************************************************************
1502 * InternetCanonicalizeUrlA (WININET.@)
1504 * Escape unsafe characters and spaces
1511 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1512 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1515 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1517 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1518 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1520 if(dwFlags
& ICU_DECODE
)
1522 dwURLFlags
|= URL_UNESCAPE
;
1523 dwFlags
&= ~ICU_DECODE
;
1526 if(dwFlags
& ICU_ESCAPE
)
1528 dwURLFlags
|= URL_UNESCAPE
;
1529 dwFlags
&= ~ICU_ESCAPE
;
1532 if(dwFlags
& ICU_BROWSER_MODE
)
1534 dwURLFlags
|= URL_BROWSER_MODE
;
1535 dwFlags
&= ~ICU_BROWSER_MODE
;
1538 if(dwFlags
& ICU_NO_ENCODE
)
1540 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1541 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1542 dwFlags
&= ~ICU_NO_ENCODE
;
1545 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1547 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1548 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1549 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1551 return (hr
== S_OK
) ? TRUE
: FALSE
;
1554 /***********************************************************************
1555 * InternetCanonicalizeUrlW (WININET.@)
1557 * Escape unsafe characters and spaces
1564 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1565 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1568 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1570 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1571 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1573 if(dwFlags
& ICU_DECODE
)
1575 dwURLFlags
|= URL_UNESCAPE
;
1576 dwFlags
&= ~ICU_DECODE
;
1579 if(dwFlags
& ICU_ESCAPE
)
1581 dwURLFlags
|= URL_UNESCAPE
;
1582 dwFlags
&= ~ICU_ESCAPE
;
1585 if(dwFlags
& ICU_BROWSER_MODE
)
1587 dwURLFlags
|= URL_BROWSER_MODE
;
1588 dwFlags
&= ~ICU_BROWSER_MODE
;
1591 if(dwFlags
& ICU_NO_ENCODE
)
1593 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1594 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1595 dwFlags
&= ~ICU_NO_ENCODE
;
1598 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1600 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1601 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1602 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1604 return (hr
== S_OK
) ? TRUE
: FALSE
;
1607 /* #################################################### */
1609 static INTERNET_STATUS_CALLBACK
set_status_callback(
1610 LPWININETHANDLEHEADER lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
1612 INTERNET_STATUS_CALLBACK ret
;
1614 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1615 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1617 ret
= lpwh
->lpfnStatusCB
;
1618 lpwh
->lpfnStatusCB
= callback
;
1623 /***********************************************************************
1624 * InternetSetStatusCallbackA (WININET.@)
1626 * Sets up a callback function which is called as progress is made
1627 * during an operation.
1630 * Previous callback or NULL on success
1631 * INTERNET_INVALID_STATUS_CALLBACK on failure
1634 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1635 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1637 INTERNET_STATUS_CALLBACK retVal
;
1638 LPWININETHANDLEHEADER lpwh
;
1640 TRACE("0x%08x\n", (ULONG
)hInternet
);
1642 if (!(lpwh
= WININET_GetObject(hInternet
)))
1643 return INTERNET_INVALID_STATUS_CALLBACK
;
1645 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
1647 WININET_Release( lpwh
);
1651 /***********************************************************************
1652 * InternetSetStatusCallbackW (WININET.@)
1654 * Sets up a callback function which is called as progress is made
1655 * during an operation.
1658 * Previous callback or NULL on success
1659 * INTERNET_INVALID_STATUS_CALLBACK on failure
1662 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1663 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1665 INTERNET_STATUS_CALLBACK retVal
;
1666 LPWININETHANDLEHEADER lpwh
;
1668 TRACE("0x%08x\n", (ULONG
)hInternet
);
1670 if (!(lpwh
= WININET_GetObject(hInternet
)))
1671 return INTERNET_INVALID_STATUS_CALLBACK
;
1673 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
1675 WININET_Release( lpwh
);
1679 /***********************************************************************
1680 * InternetSetFilePointer (WININET.@)
1682 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1683 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
1689 /***********************************************************************
1690 * InternetWriteFile (WININET.@)
1692 * Write data to an open internet file
1699 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1700 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1702 LPWININETHANDLEHEADER lpwh
;
1703 BOOL retval
= FALSE
;
1705 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1707 lpwh
= WININET_GetObject( hFile
);
1709 if(lpwh
&& lpwh
->vtbl
->WriteFile
) {
1710 retval
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1712 WARN("Invalid handle\n");
1713 SetLastError(ERROR_INVALID_HANDLE
);
1717 WININET_Release( lpwh
);
1723 /***********************************************************************
1724 * InternetReadFile (WININET.@)
1726 * Read data from an open internet file
1733 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1734 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1736 LPWININETHANDLEHEADER hdr
;
1737 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1739 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1741 hdr
= WININET_GetObject(hFile
);
1743 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1747 if(hdr
->vtbl
->ReadFile
)
1748 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1750 WININET_Release(hdr
);
1752 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
1753 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1755 if(res
!= ERROR_SUCCESS
)
1757 return res
== ERROR_SUCCESS
;
1760 /***********************************************************************
1761 * InternetReadFileExA (WININET.@)
1763 * Read data from an open internet file
1766 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1767 * lpBuffersOut [I/O] Buffer.
1768 * dwFlags [I] Flags. See notes.
1769 * dwContext [I] Context for callbacks.
1776 * The parameter dwFlags include zero or more of the following flags:
1777 *|IRF_ASYNC - Makes the call asynchronous.
1778 *|IRF_SYNC - Makes the call synchronous.
1779 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1780 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1782 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1785 * InternetOpenUrlA(), HttpOpenRequestA()
1787 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1788 DWORD dwFlags
, DWORD_PTR dwContext
)
1790 LPWININETHANDLEHEADER hdr
;
1791 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1793 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1795 hdr
= WININET_GetObject(hFile
);
1797 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1801 if(hdr
->vtbl
->ReadFileExA
)
1802 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
1804 WININET_Release(hdr
);
1806 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
1807 res
, lpBuffersOut
->dwBufferLength
);
1809 if(res
!= ERROR_SUCCESS
)
1811 return res
== ERROR_SUCCESS
;
1814 /***********************************************************************
1815 * InternetReadFileExW (WININET.@)
1817 * Read data from an open internet file.
1820 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1821 * lpBuffersOut [I/O] Buffer.
1822 * dwFlags [I] Flags.
1823 * dwContext [I] Context for callbacks.
1826 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1829 * Not implemented in Wine or native either (as of IE6 SP2).
1832 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1833 DWORD dwFlags
, DWORD_PTR dwContext
)
1835 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
1837 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1841 /***********************************************************************
1842 * INET_QueryOptionHelper (internal)
1844 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1845 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1847 LPWININETHANDLEHEADER lpwhh
;
1848 BOOL bSuccess
= FALSE
;
1850 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1852 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
1856 case INTERNET_OPTION_REQUEST_FLAGS
:
1859 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags
);
1860 if (*lpdwBufferLength
< sizeof(ULONG
))
1861 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1864 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
1867 *lpdwBufferLength
= sizeof(ULONG
);
1871 case INTERNET_OPTION_USER_AGENT
:
1872 FIXME("INTERNET_OPTION_USER_AGENT\n");
1875 case INTERNET_OPTION_DATAFILE_NAME
:
1877 TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
1880 WARN("Invalid hInternet handle\n");
1881 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1884 if (lpwhh
->htype
== WH_HHTTPREQ
)
1886 LPWININETHTTPREQW lpreq
= (LPWININETHTTPREQW
) lpwhh
;
1889 if(!lpreq
->lpszCacheFile
) {
1890 *lpdwBufferLength
= 0;
1891 INTERNET_SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
1895 size
= (lstrlenW(lpreq
->lpszCacheFile
)+1) * sizeof(WCHAR
);
1896 if (*lpdwBufferLength
< size
)
1897 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1900 memcpy(lpBuffer
, lpreq
->lpszCacheFile
, size
);
1903 *lpdwBufferLength
= size
;
1907 size
= WideCharToMultiByte(CP_ACP
, 0, lpreq
->lpszCacheFile
, -1, NULL
, 0, NULL
, NULL
);
1908 if (size
> *lpdwBufferLength
) {
1909 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1911 *lpdwBufferLength
= WideCharToMultiByte(CP_ACP
, 0, lpreq
->lpszCacheFile
,
1912 -1, lpBuffer
, *lpdwBufferLength
, NULL
, NULL
);
1920 case INTERNET_OPTION_HTTP_VERSION
:
1922 if (*lpdwBufferLength
< sizeof(HTTP_VERSION_INFO
))
1923 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1927 * Presently hardcoded to 1.1
1929 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
1930 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
1933 *lpdwBufferLength
= sizeof(HTTP_VERSION_INFO
);
1936 case INTERNET_OPTION_CONNECTED_STATE
:
1938 DWORD
*pdwConnectedState
= (DWORD
*)lpBuffer
;
1939 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
1941 if (*lpdwBufferLength
< sizeof(*pdwConnectedState
))
1942 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1945 *pdwConnectedState
= INTERNET_STATE_CONNECTED
;
1948 *lpdwBufferLength
= sizeof(*pdwConnectedState
);
1951 case INTERNET_OPTION_PROXY
:
1953 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
)lpwhh
;
1954 WININETAPPINFOW wai
;
1958 TRACE("Getting global proxy info\n");
1959 memset(&wai
, 0, sizeof(WININETAPPINFOW
));
1960 INTERNET_ConfigureProxyFromReg( &wai
);
1966 INTERNET_PROXY_INFOW
*pPI
= (INTERNET_PROXY_INFOW
*)lpBuffer
;
1967 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
1969 if (lpwai
->lpszProxy
)
1970 proxyBytesRequired
= (lstrlenW(lpwai
->lpszProxy
) + 1) *
1972 if (lpwai
->lpszProxyBypass
)
1973 proxyBypassBytesRequired
=
1974 (lstrlenW(lpwai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
1975 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOW
) +
1976 proxyBytesRequired
+ proxyBypassBytesRequired
)
1977 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1980 LPWSTR proxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
1981 sizeof(INTERNET_PROXY_INFOW
));
1982 LPWSTR proxy_bypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
1983 sizeof(INTERNET_PROXY_INFOW
) +
1984 proxyBytesRequired
);
1986 pPI
->dwAccessType
= lpwai
->dwAccessType
;
1987 pPI
->lpszProxy
= NULL
;
1988 pPI
->lpszProxyBypass
= NULL
;
1989 if (lpwai
->lpszProxy
)
1991 lstrcpyW(proxy
, lpwai
->lpszProxy
);
1992 pPI
->lpszProxy
= proxy
;
1995 if (lpwai
->lpszProxyBypass
)
1997 lstrcpyW(proxy_bypass
, lpwai
->lpszProxyBypass
);
1998 pPI
->lpszProxyBypass
= proxy_bypass
;
2002 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOW
) +
2003 proxyBytesRequired
+ proxyBypassBytesRequired
;
2007 INTERNET_PROXY_INFOA
*pPI
= (INTERNET_PROXY_INFOA
*)lpBuffer
;
2008 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2010 if (lpwai
->lpszProxy
)
2011 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2012 lpwai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
2013 if (lpwai
->lpszProxyBypass
)
2014 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2015 lpwai
->lpszProxyBypass
, -1, NULL
, 0, NULL
, NULL
);
2016 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOA
) +
2017 proxyBytesRequired
+ proxyBypassBytesRequired
)
2018 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2021 LPSTR proxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2022 sizeof(INTERNET_PROXY_INFOA
));
2023 LPSTR proxy_bypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2024 sizeof(INTERNET_PROXY_INFOA
) +
2025 proxyBytesRequired
);
2027 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2028 pPI
->lpszProxy
= NULL
;
2029 pPI
->lpszProxyBypass
= NULL
;
2030 if (lpwai
->lpszProxy
)
2032 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxy
, -1,
2033 proxy
, proxyBytesRequired
, NULL
, NULL
);
2034 pPI
->lpszProxy
= proxy
;
2037 if (lpwai
->lpszProxyBypass
)
2039 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxyBypass
,
2040 -1, proxy_bypass
, proxyBypassBytesRequired
,
2042 pPI
->lpszProxyBypass
= proxy_bypass
;
2046 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOA
) +
2047 proxyBytesRequired
+ proxyBypassBytesRequired
;
2051 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2054 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn
);
2055 if (*lpdwBufferLength
< sizeof(ULONG
))
2056 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2059 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2062 *lpdwBufferLength
= sizeof(ULONG
);
2065 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2068 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn
);
2069 if (*lpdwBufferLength
< sizeof(ULONG
))
2070 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2073 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2076 *lpdwBufferLength
= sizeof(ULONG
);
2079 case INTERNET_OPTION_SECURITY_FLAGS
:
2080 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2084 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
:
2087 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2090 if (*lpdwBufferLength
< sizeof(INTERNET_CERTIFICATE_INFOW
))
2092 *lpdwBufferLength
= sizeof(INTERNET_CERTIFICATE_INFOW
);
2093 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2095 else if (lpwhh
->htype
== WH_HHTTPREQ
)
2097 LPWININETHTTPREQW lpwhr
;
2098 PCCERT_CONTEXT context
;
2100 lpwhr
= (LPWININETHTTPREQW
)lpwhh
;
2101 context
= (PCCERT_CONTEXT
)NETCON_GetCert(&(lpwhr
->netConnection
));
2104 LPINTERNET_CERTIFICATE_INFOW info
= (LPINTERNET_CERTIFICATE_INFOW
)lpBuffer
;
2107 memset(info
,0,sizeof(INTERNET_CERTIFICATE_INFOW
));
2108 info
->ftExpiry
= context
->pCertInfo
->NotAfter
;
2109 info
->ftStart
= context
->pCertInfo
->NotBefore
;
2112 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2113 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2115 info
->lpszSubjectInfo
= LocalAlloc(0,
2116 strLen
* sizeof(WCHAR
));
2117 if (info
->lpszSubjectInfo
)
2118 CertNameToStrW(context
->dwCertEncodingType
,
2119 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2120 info
->lpszSubjectInfo
, strLen
);
2121 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2122 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2124 info
->lpszIssuerInfo
= LocalAlloc(0,
2125 strLen
* sizeof(WCHAR
));
2126 if (info
->lpszIssuerInfo
)
2127 CertNameToStrW(context
->dwCertEncodingType
,
2128 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2129 info
->lpszIssuerInfo
, strLen
);
2133 LPINTERNET_CERTIFICATE_INFOA infoA
=
2134 (LPINTERNET_CERTIFICATE_INFOA
)info
;
2136 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2137 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2139 infoA
->lpszSubjectInfo
= LocalAlloc(0, strLen
);
2140 if (infoA
->lpszSubjectInfo
)
2141 CertNameToStrA(context
->dwCertEncodingType
,
2142 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2143 infoA
->lpszSubjectInfo
, strLen
);
2144 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2145 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2147 infoA
->lpszIssuerInfo
= LocalAlloc(0, strLen
);
2148 if (infoA
->lpszIssuerInfo
)
2149 CertNameToStrA(context
->dwCertEncodingType
,
2150 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2151 infoA
->lpszIssuerInfo
, strLen
);
2154 * Contrary to MSDN, these do not appear to be set.
2156 * lpszSignatureAlgName
2157 * lpszEncryptionAlgName
2160 CertFreeCertificateContext(context
);
2165 case INTERNET_OPTION_VERSION
:
2167 TRACE("INTERNET_OPTION_VERSION\n");
2168 if (*lpdwBufferLength
< sizeof(INTERNET_VERSION_INFO
))
2169 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2172 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2173 memcpy(lpBuffer
, &info
, sizeof(info
));
2174 *lpdwBufferLength
= sizeof(info
);
2179 case INTERNET_OPTION_PER_CONNECTION_OPTION
:
2180 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2181 if (*lpdwBufferLength
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
))
2182 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2185 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2188 for (x
= 0; x
< con
->dwOptionCount
; ++x
)
2190 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ x
;
2191 switch (option
->dwOption
)
2193 case INTERNET_PER_CONN_FLAGS
:
2194 option
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2197 case INTERNET_PER_CONN_PROXY_SERVER
:
2198 case INTERNET_PER_CONN_PROXY_BYPASS
:
2199 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2200 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2201 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2202 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2203 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2204 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2205 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2206 option
->Value
.dwValue
= 0;
2211 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2217 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2228 res
= lpwhh
->vtbl
->QueryOption(lpwhh
, dwOption
, lpBuffer
, lpdwBufferLength
, bIsUnicode
);
2229 if(res
== ERROR_SUCCESS
)
2234 FIXME("Stub! %d\n", dwOption
);
2240 WININET_Release( lpwhh
);
2245 /***********************************************************************
2246 * InternetQueryOptionW (WININET.@)
2248 * Queries an options on the specified handle
2255 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2256 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2258 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2261 /***********************************************************************
2262 * InternetQueryOptionA (WININET.@)
2264 * Queries an options on the specified handle
2271 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2272 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2274 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2278 /***********************************************************************
2279 * InternetSetOptionW (WININET.@)
2281 * Sets an options on the specified handle
2288 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2289 LPVOID lpBuffer
, DWORD dwBufferLength
)
2291 LPWININETHANDLEHEADER lpwhh
;
2294 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2296 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2297 if(lpwhh
&& lpwhh
->vtbl
->SetOption
) {
2300 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2301 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2302 WININET_Release( lpwhh
);
2304 if(res
!= ERROR_SUCCESS
)
2307 return res
== ERROR_SUCCESS
;
2313 case INTERNET_OPTION_CALLBACK
:
2315 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2316 ret
= (set_status_callback(lpwhh
, callback
, TRUE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2319 case INTERNET_OPTION_HTTP_VERSION
:
2321 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2322 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2325 case INTERNET_OPTION_ERROR_MASK
:
2327 unsigned long flags
=*(unsigned long*)lpBuffer
;
2328 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
2331 case INTERNET_OPTION_CODEPAGE
:
2333 unsigned long codepage
=*(unsigned long*)lpBuffer
;
2334 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
2337 case INTERNET_OPTION_REQUEST_PRIORITY
:
2339 unsigned long priority
=*(unsigned long*)lpBuffer
;
2340 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
2343 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2345 unsigned long connecttimeout
=*(unsigned long*)lpBuffer
;
2346 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout
);
2349 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2351 unsigned long receivetimeout
=*(unsigned long*)lpBuffer
;
2352 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout
);
2355 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2357 unsigned long conns
=*(unsigned long*)lpBuffer
;
2358 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns
);
2361 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2363 unsigned long conns
=*(unsigned long*)lpBuffer
;
2364 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns
);
2367 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2368 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2370 case INTERNET_OPTION_END_BROWSER_SESSION
:
2371 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2373 case INTERNET_OPTION_CONNECTED_STATE
:
2374 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2376 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2377 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2379 case INTERNET_OPTION_SEND_TIMEOUT
:
2380 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2381 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2383 case INTERNET_OPTION_CONNECT_RETRIES
:
2384 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2386 case INTERNET_OPTION_CONTEXT_VALUE
:
2387 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2389 case INTERNET_OPTION_SECURITY_FLAGS
:
2390 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2396 FIXME("Option %d STUB\n",dwOption
);
2397 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2403 WININET_Release( lpwhh
);
2409 /***********************************************************************
2410 * InternetSetOptionA (WININET.@)
2412 * Sets an options on the specified handle.
2419 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2420 LPVOID lpBuffer
, DWORD dwBufferLength
)
2428 case INTERNET_OPTION_CALLBACK
:
2430 LPWININETHANDLEHEADER lpwh
;
2431 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2433 if (!(lpwh
= WININET_GetObject(hInternet
))) return FALSE
;
2434 r
= (set_status_callback(lpwh
, callback
, FALSE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2435 WININET_Release(lpwh
);
2438 case INTERNET_OPTION_PROXY
:
2440 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2441 LPINTERNET_PROXY_INFOW piw
;
2442 DWORD proxlen
, prbylen
;
2445 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2446 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2447 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2448 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2449 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2450 piw
->dwAccessType
= pi
->dwAccessType
;
2451 prox
= (LPWSTR
) &piw
[1];
2452 prby
= &prox
[proxlen
+1];
2453 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2454 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2455 piw
->lpszProxy
= prox
;
2456 piw
->lpszProxyBypass
= prby
;
2459 case INTERNET_OPTION_USER_AGENT
:
2460 case INTERNET_OPTION_USERNAME
:
2461 case INTERNET_OPTION_PASSWORD
:
2462 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2464 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2465 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2470 wlen
= dwBufferLength
;
2473 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2475 if( lpBuffer
!= wbuffer
)
2476 HeapFree( GetProcessHeap(), 0, wbuffer
);
2482 /***********************************************************************
2483 * InternetSetOptionExA (WININET.@)
2485 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2486 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2488 FIXME("Flags %08x ignored\n", dwFlags
);
2489 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2492 /***********************************************************************
2493 * InternetSetOptionExW (WININET.@)
2495 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2496 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2498 FIXME("Flags %08x ignored\n", dwFlags
);
2499 if( dwFlags
& ~ISO_VALID_FLAGS
)
2501 INTERNET_SetLastError( ERROR_INVALID_PARAMETER
);
2504 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2507 static const WCHAR WININET_wkday
[7][4] =
2508 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2509 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2510 static const WCHAR WININET_month
[12][4] =
2511 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2512 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2513 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2515 /***********************************************************************
2516 * InternetTimeFromSystemTimeA (WININET.@)
2518 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2521 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2523 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2525 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2526 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2531 /***********************************************************************
2532 * InternetTimeFromSystemTimeW (WININET.@)
2534 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2536 static const WCHAR date
[] =
2537 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2538 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2540 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2542 if (!time
|| !string
) return FALSE
;
2544 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2547 sprintfW( string
, date
,
2548 WININET_wkday
[time
->wDayOfWeek
],
2550 WININET_month
[time
->wMonth
- 1],
2559 /***********************************************************************
2560 * InternetTimeToSystemTimeA (WININET.@)
2562 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2568 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
2570 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2571 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2575 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2576 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2577 HeapFree( GetProcessHeap(), 0, stringW
);
2582 /***********************************************************************
2583 * InternetTimeToSystemTimeW (WININET.@)
2585 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2588 const WCHAR
*s
= string
;
2591 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
2593 if (!string
|| !time
) return FALSE
;
2595 /* Windows does this too */
2596 GetSystemTime( time
);
2598 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2599 * a SYSTEMTIME structure.
2602 while (*s
&& !isalphaW( *s
)) s
++;
2603 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2604 time
->wDayOfWeek
= 7;
2606 for (i
= 0; i
< 7; i
++)
2608 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2609 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2610 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2612 time
->wDayOfWeek
= i
;
2617 if (time
->wDayOfWeek
> 6) return TRUE
;
2618 while (*s
&& !isdigitW( *s
)) s
++;
2619 time
->wDay
= strtolW( s
, &end
, 10 );
2622 while (*s
&& !isalphaW( *s
)) s
++;
2623 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2626 for (i
= 0; i
< 12; i
++)
2628 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2629 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2630 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2632 time
->wMonth
= i
+ 1;
2636 if (time
->wMonth
== 0) return TRUE
;
2638 while (*s
&& !isdigitW( *s
)) s
++;
2639 if (*s
== '\0') return TRUE
;
2640 time
->wYear
= strtolW( s
, &end
, 10 );
2643 while (*s
&& !isdigitW( *s
)) s
++;
2644 if (*s
== '\0') return TRUE
;
2645 time
->wHour
= strtolW( s
, &end
, 10 );
2648 while (*s
&& !isdigitW( *s
)) s
++;
2649 if (*s
== '\0') return TRUE
;
2650 time
->wMinute
= strtolW( s
, &end
, 10 );
2653 while (*s
&& !isdigitW( *s
)) s
++;
2654 if (*s
== '\0') return TRUE
;
2655 time
->wSecond
= strtolW( s
, &end
, 10 );
2658 time
->wMilliseconds
= 0;
2662 /***********************************************************************
2663 * InternetCheckConnectionW (WININET.@)
2665 * Pings a requested host to check internet connection
2668 * TRUE on success and FALSE on failure. If a failure then
2669 * ERROR_NOT_CONNECTED is placed into GetLastError
2672 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2675 * this is a kludge which runs the resident ping program and reads the output.
2677 * Anyone have a better idea?
2681 static const CHAR ping
[] = "ping -c 1 ";
2682 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2683 CHAR
*command
= NULL
;
2692 * Crack or set the Address
2694 if (lpszUrl
== NULL
)
2697 * According to the doc we are supposed to use the ip for the next
2698 * server in the WnInet internal server database. I have
2699 * no idea what that is or how to get it.
2701 * So someone needs to implement this.
2703 FIXME("Unimplemented with URL of NULL\n");
2708 URL_COMPONENTSW components
;
2710 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2711 components
.lpszHostName
= (LPWSTR
)&hostW
;
2712 components
.dwHostNameLength
= 1024;
2714 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2717 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2718 port
= components
.nPort
;
2719 TRACE("port: %d\n", port
);
2722 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
2724 struct sockaddr_in sin
;
2727 if (!GetAddress(hostW
, port
, &sin
))
2729 fd
= socket(sin
.sin_family
, SOCK_STREAM
, 0);
2732 if (connect(fd
, (struct sockaddr
*)&sin
, sizeof(sin
)) == 0)
2740 * Build our ping command
2742 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2743 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2744 strcpy(command
,ping
);
2745 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2746 strcat(command
,redirect
);
2748 TRACE("Ping command is : %s\n",command
);
2750 status
= system(command
);
2752 TRACE("Ping returned a code of %i\n",status
);
2754 /* Ping return code of 0 indicates success */
2761 HeapFree( GetProcessHeap(), 0, command
);
2763 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
2769 /***********************************************************************
2770 * InternetCheckConnectionA (WININET.@)
2772 * Pings a requested host to check internet connection
2775 * TRUE on success and FALSE on failure. If a failure then
2776 * ERROR_NOT_CONNECTED is placed into GetLastError
2779 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2785 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2786 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2788 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2789 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2790 HeapFree(GetProcessHeap(), 0, szUrl
);
2796 /**********************************************************
2797 * INTERNET_InternetOpenUrlW (internal)
2802 * handle of connection or NULL on failure
2804 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2805 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2807 URL_COMPONENTSW urlComponents
;
2808 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2809 WCHAR password
[1024], path
[2048], extra
[1024];
2810 HINTERNET client
= NULL
, client1
= NULL
;
2812 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2813 dwHeadersLength
, dwFlags
, dwContext
);
2815 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2816 urlComponents
.lpszScheme
= protocol
;
2817 urlComponents
.dwSchemeLength
= 32;
2818 urlComponents
.lpszHostName
= hostName
;
2819 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2820 urlComponents
.lpszUserName
= userName
;
2821 urlComponents
.dwUserNameLength
= 1024;
2822 urlComponents
.lpszPassword
= password
;
2823 urlComponents
.dwPasswordLength
= 1024;
2824 urlComponents
.lpszUrlPath
= path
;
2825 urlComponents
.dwUrlPathLength
= 2048;
2826 urlComponents
.lpszExtraInfo
= extra
;
2827 urlComponents
.dwExtraInfoLength
= 1024;
2828 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2830 switch(urlComponents
.nScheme
) {
2831 case INTERNET_SCHEME_FTP
:
2832 if(urlComponents
.nPort
== 0)
2833 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2834 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2835 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2838 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2839 if(client1
== NULL
) {
2840 InternetCloseHandle(client
);
2845 case INTERNET_SCHEME_HTTP
:
2846 case INTERNET_SCHEME_HTTPS
: {
2847 static const WCHAR szStars
[] = { '*','/','*', 0 };
2848 LPCWSTR accept
[2] = { szStars
, NULL
};
2849 if(urlComponents
.nPort
== 0) {
2850 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2851 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2853 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2855 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2856 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2857 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2861 if (urlComponents
.dwExtraInfoLength
) {
2863 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
2865 if (!(path_extra
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
2867 InternetCloseHandle(client
);
2870 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
2871 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
2872 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2873 HeapFree(GetProcessHeap(), 0, path_extra
);
2876 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2878 if(client1
== NULL
) {
2879 InternetCloseHandle(client
);
2882 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2883 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
2884 GetLastError() != ERROR_IO_PENDING
) {
2885 InternetCloseHandle(client1
);
2890 case INTERNET_SCHEME_GOPHER
:
2891 /* gopher doesn't seem to be implemented in wine, but it's supposed
2892 * to be supported by InternetOpenUrlA. */
2894 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
2898 TRACE(" %p <--\n", client1
);
2903 /**********************************************************
2904 * InternetOpenUrlW (WININET.@)
2909 * handle of connection or NULL on failure
2911 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
2913 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
2914 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
->hdr
;
2918 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
2919 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
2920 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
2921 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
2924 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
2925 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2927 HINTERNET ret
= NULL
;
2928 LPWININETAPPINFOW hIC
= NULL
;
2930 if (TRACE_ON(wininet
)) {
2931 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2932 dwHeadersLength
, dwFlags
, dwContext
);
2934 dump_INTERNET_FLAGS(dwFlags
);
2939 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2943 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
2944 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
2945 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2949 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
2950 WORKREQUEST workRequest
;
2951 struct WORKREQ_INTERNETOPENURLW
*req
;
2953 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
2954 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
2955 req
= &workRequest
.u
.InternetOpenUrlW
;
2956 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
2958 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
2960 req
->lpszHeaders
= 0;
2961 req
->dwHeadersLength
= dwHeadersLength
;
2962 req
->dwFlags
= dwFlags
;
2963 req
->dwContext
= dwContext
;
2965 INTERNET_AsyncCall(&workRequest
);
2967 * This is from windows.
2969 INTERNET_SetLastError(ERROR_IO_PENDING
);
2971 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
2976 WININET_Release( &hIC
->hdr
);
2977 TRACE(" %p <--\n", ret
);
2982 /**********************************************************
2983 * InternetOpenUrlA (WININET.@)
2988 * handle of connection or NULL on failure
2990 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
2991 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2993 HINTERNET rc
= NULL
;
2997 LPWSTR szUrl
= NULL
;
2998 LPWSTR szHeaders
= NULL
;
3003 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
3004 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
3007 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
3011 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3012 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
3014 HeapFree(GetProcessHeap(), 0, szUrl
);
3017 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3020 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3021 lenHeaders
, dwFlags
, dwContext
);
3023 HeapFree(GetProcessHeap(), 0, szUrl
);
3024 HeapFree(GetProcessHeap(), 0, szHeaders
);
3030 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3032 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite
));
3036 lpwite
->dwError
= 0;
3037 lpwite
->response
[0] = '\0';
3040 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3042 HeapFree(GetProcessHeap(), 0, lpwite
);
3050 /***********************************************************************
3051 * INTERNET_SetLastError (internal)
3053 * Set last thread specific error
3058 void INTERNET_SetLastError(DWORD dwError
)
3060 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3063 lpwite
= INTERNET_AllocThreadError();
3065 SetLastError(dwError
);
3067 lpwite
->dwError
= dwError
;
3071 /***********************************************************************
3072 * INTERNET_GetLastError (internal)
3074 * Get last thread specific error
3079 DWORD
INTERNET_GetLastError(void)
3081 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3082 if (!lpwite
) return 0;
3083 /* TlsGetValue clears last error, so set it again here */
3084 SetLastError(lpwite
->dwError
);
3085 return lpwite
->dwError
;
3089 /***********************************************************************
3090 * INTERNET_WorkerThreadFunc (internal)
3092 * Worker thread execution function
3097 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3099 LPWORKREQUEST lpRequest
= lpvParam
;
3100 WORKREQUEST workRequest
;
3104 memcpy(&workRequest
, lpRequest
, sizeof(WORKREQUEST
));
3105 HeapFree(GetProcessHeap(), 0, lpRequest
);
3107 workRequest
.asyncproc(&workRequest
);
3109 WININET_Release( workRequest
.hdr
);
3114 /***********************************************************************
3115 * INTERNET_AsyncCall (internal)
3117 * Retrieves work request from queue
3122 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3125 LPWORKREQUEST lpNewRequest
;
3129 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3133 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
3135 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3138 HeapFree(GetProcessHeap(), 0, lpNewRequest
);
3139 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3146 /***********************************************************************
3147 * INTERNET_GetResponseBuffer (internal)
3152 LPSTR
INTERNET_GetResponseBuffer(void)
3154 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3156 lpwite
= INTERNET_AllocThreadError();
3158 return lpwite
->response
;
3161 /***********************************************************************
3162 * INTERNET_GetNextLine (internal)
3164 * Parse next line in directory string listing
3167 * Pointer to beginning of next line
3172 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3176 BOOL bSuccess
= FALSE
;
3178 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3183 FD_SET(nSocket
, &infd
);
3184 tv
.tv_sec
=RESPONSE_TIMEOUT
;
3187 while (nRecv
< MAX_REPLY_LEN
)
3189 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
3191 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3193 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3197 if (lpszBuffer
[nRecv
] == '\n')
3202 if (lpszBuffer
[nRecv
] != '\r')
3207 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3215 lpszBuffer
[nRecv
] = '\0';
3217 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3226 /**********************************************************
3227 * InternetQueryDataAvailable (WININET.@)
3229 * Determines how much data is available to be read.
3232 * TRUE on success, FALSE if an error occurred. If
3233 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3234 * no data is presently available, FALSE is returned with
3235 * the last error ERROR_IO_PENDING; a callback with status
3236 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3237 * data is available.
3239 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3240 LPDWORD lpdwNumberOfBytesAvailble
,
3241 DWORD dwFlags
, DWORD_PTR dwContext
)
3243 WININETHANDLEHEADER
*hdr
;
3246 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3248 hdr
= WININET_GetObject( hFile
);
3250 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
3254 if(hdr
->vtbl
->QueryDataAvailable
) {
3255 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3257 WARN("wrong handle\n");
3258 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3261 WININET_Release(hdr
);
3263 if(res
!= ERROR_SUCCESS
)
3265 return res
== ERROR_SUCCESS
;
3269 /***********************************************************************
3270 * InternetLockRequestFile (WININET.@)
3272 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3279 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3286 /***********************************************************************
3287 * InternetAutodial (WININET.@)
3289 * On windows this function is supposed to dial the default internet
3290 * connection. We don't want to have Wine dial out to the internet so
3291 * we return TRUE by default. It might be nice to check if we are connected.
3298 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3302 /* Tell that we are connected to the internet. */
3306 /***********************************************************************
3307 * InternetAutodialHangup (WININET.@)
3309 * Hangs up a connection made with InternetAutodial
3318 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3322 /* we didn't dial, we don't disconnect */
3326 /***********************************************************************
3327 * InternetCombineUrlA (WININET.@)
3329 * Combine a base URL with a relative URL
3337 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3338 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3343 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3345 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3346 dwFlags
^= ICU_NO_ENCODE
;
3347 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3352 /***********************************************************************
3353 * InternetCombineUrlW (WININET.@)
3355 * Combine a base URL with a relative URL
3363 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3364 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3369 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3371 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3372 dwFlags
^= ICU_NO_ENCODE
;
3373 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3378 /* max port num is 65535 => 5 digits */
3379 #define MAX_WORD_DIGITS 5
3381 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3382 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3383 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3384 (url)->dw##component##Length : strlen((url)->lpsz##component))
3386 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3388 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3389 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3391 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3392 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3394 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3395 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3397 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3398 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3401 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3407 /* opaque urls do not fit into the standard url hierarchy and don't have
3408 * two following slashes */
3409 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3411 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3412 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3413 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3414 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3415 (nScheme
!= INTERNET_SCHEME_FILE
);
3418 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3421 if (scheme
< INTERNET_SCHEME_FIRST
)
3423 index
= scheme
- INTERNET_SCHEME_FIRST
;
3424 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3426 return (LPCWSTR
)&url_schemes
[index
];
3429 /* we can calculate using ansi strings because we're just
3430 * calculating string length, not size
3432 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3433 LPDWORD lpdwUrlLength
)
3435 INTERNET_SCHEME nScheme
;
3439 if (lpUrlComponents
->lpszScheme
)
3441 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3442 *lpdwUrlLength
+= dwLen
;
3443 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3449 nScheme
= lpUrlComponents
->nScheme
;
3451 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3452 nScheme
= INTERNET_SCHEME_HTTP
;
3453 scheme
= INTERNET_GetSchemeString(nScheme
);
3454 *lpdwUrlLength
+= strlenW(scheme
);
3457 (*lpdwUrlLength
)++; /* ':' */
3458 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3459 *lpdwUrlLength
+= strlen("//");
3461 if (lpUrlComponents
->lpszUserName
)
3463 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3464 *lpdwUrlLength
+= strlen("@");
3468 if (lpUrlComponents
->lpszPassword
)
3470 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3475 if (lpUrlComponents
->lpszPassword
)
3477 *lpdwUrlLength
+= strlen(":");
3478 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3481 if (lpUrlComponents
->lpszHostName
)
3483 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3485 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3487 char szPort
[MAX_WORD_DIGITS
+1];
3489 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3490 *lpdwUrlLength
+= strlen(szPort
);
3491 *lpdwUrlLength
+= strlen(":");
3494 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3495 (*lpdwUrlLength
)++; /* '/' */
3498 if (lpUrlComponents
->lpszUrlPath
)
3499 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3504 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3508 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3510 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3511 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3512 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3513 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3514 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3515 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3516 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3517 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3518 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3520 if (lpUrlComponents
->lpszScheme
)
3522 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
3523 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3524 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3525 -1, urlCompW
->lpszScheme
, len
);
3528 if (lpUrlComponents
->lpszHostName
)
3530 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
3531 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3532 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3533 -1, urlCompW
->lpszHostName
, len
);
3536 if (lpUrlComponents
->lpszUserName
)
3538 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
3539 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3540 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3541 -1, urlCompW
->lpszUserName
, len
);
3544 if (lpUrlComponents
->lpszPassword
)
3546 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
3547 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3548 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3549 -1, urlCompW
->lpszPassword
, len
);
3552 if (lpUrlComponents
->lpszUrlPath
)
3554 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
3555 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3556 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3557 -1, urlCompW
->lpszUrlPath
, len
);
3560 if (lpUrlComponents
->lpszExtraInfo
)
3562 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
3563 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3564 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3565 -1, urlCompW
->lpszExtraInfo
, len
);
3569 /***********************************************************************
3570 * InternetCreateUrlA (WININET.@)
3572 * See InternetCreateUrlW.
3574 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3575 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3579 URL_COMPONENTSW urlCompW
;
3581 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3583 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3585 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3589 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3592 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3594 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3596 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3597 *lpdwUrlLength
/= sizeof(WCHAR
);
3599 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3600 * minus one, so add one to leave room for NULL terminator
3603 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3605 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3606 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3607 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3608 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3609 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3610 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3611 HeapFree(GetProcessHeap(), 0, urlW
);
3616 /***********************************************************************
3617 * InternetCreateUrlW (WININET.@)
3619 * Creates a URL from its component parts.
3622 * lpUrlComponents [I] URL Components.
3623 * dwFlags [I] Flags. See notes.
3624 * lpszUrl [I] Buffer in which to store the created URL.
3625 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3626 * lpszUrl in characters. On output, the number of bytes
3627 * required to store the URL including terminator.
3631 * The dwFlags parameter can be zero or more of the following:
3632 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3639 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3640 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3643 INTERNET_SCHEME nScheme
;
3645 static const WCHAR slashSlashW
[] = {'/','/'};
3646 static const WCHAR percentD
[] = {'%','d',0};
3648 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3650 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3652 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3656 if (!calc_url_length(lpUrlComponents
, &dwLen
))
3659 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3661 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
3662 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3666 *lpdwUrlLength
= dwLen
;
3671 if (lpUrlComponents
->lpszScheme
)
3673 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3674 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
3677 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3682 nScheme
= lpUrlComponents
->nScheme
;
3684 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3685 nScheme
= INTERNET_SCHEME_HTTP
;
3687 scheme
= INTERNET_GetSchemeString(nScheme
);
3688 dwLen
= strlenW(scheme
);
3689 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
3693 /* all schemes are followed by at least a colon */
3697 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3699 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
3700 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
3703 if (lpUrlComponents
->lpszUserName
)
3705 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3706 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
3709 if (lpUrlComponents
->lpszPassword
)
3714 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3715 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
3723 if (lpUrlComponents
->lpszHostName
)
3725 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3726 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
3729 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3731 WCHAR szPort
[MAX_WORD_DIGITS
+1];
3733 sprintfW(szPort
, percentD
, lpUrlComponents
->nPort
);
3736 dwLen
= strlenW(szPort
);
3737 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
3741 /* add slash between hostname and path if necessary */
3742 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3750 if (lpUrlComponents
->lpszUrlPath
)
3752 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3753 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
3762 /***********************************************************************
3763 * InternetConfirmZoneCrossingA (WININET.@)
3766 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
3768 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
3769 return ERROR_SUCCESS
;
3772 /***********************************************************************
3773 * InternetConfirmZoneCrossingW (WININET.@)
3776 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
3778 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
3779 return ERROR_SUCCESS
;
3782 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
3783 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3785 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3786 lpdwConnection
, dwReserved
);
3787 return ERROR_SUCCESS
;
3790 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
3791 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3793 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3794 lpdwConnection
, dwReserved
);
3795 return ERROR_SUCCESS
;
3798 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3800 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
3804 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3806 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
3810 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
3812 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
3813 return ERROR_SUCCESS
;
3816 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
3819 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
3820 debugstr_w(pwszTarget
), pbHexHash
);
3824 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
3826 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
3830 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
3832 FIXME("(%p, %08lx) stub\n", a
, b
);