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
)
149 TRACE("%p -> refcount = %d\n", info
, info
->dwRefCount
);
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
)
174 TRACE( "object %p refcount = %d\n", info
, info
->dwRefCount
);
175 if( !info
->dwRefCount
)
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 const HANDLEHEADERVtbl APPINFOVtbl
= {
484 /***********************************************************************
485 * InternetOpenW (WININET.@)
487 * Per-application initialization of wininet
490 * HINTERNET on success
494 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
495 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
497 LPWININETAPPINFOW lpwai
= NULL
;
498 HINTERNET handle
= NULL
;
500 if (TRACE_ON(wininet
)) {
501 #define FE(x) { x, #x }
502 static const wininet_flag_info access_type
[] = {
503 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
504 FE(INTERNET_OPEN_TYPE_DIRECT
),
505 FE(INTERNET_OPEN_TYPE_PROXY
),
506 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
510 const char *access_type_str
= "Unknown";
512 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
513 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
514 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
515 if (access_type
[i
].val
== dwAccessType
) {
516 access_type_str
= access_type
[i
].name
;
520 TRACE(" access type : %s\n", access_type_str
);
522 dump_INTERNET_FLAGS(dwFlags
);
525 /* Clear any error information */
526 INTERNET_SetLastError(0);
528 lpwai
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETAPPINFOW
));
531 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
535 lpwai
->hdr
.htype
= WH_HINIT
;
536 lpwai
->hdr
.vtbl
= &APPINFOVtbl
;
537 lpwai
->hdr
.dwFlags
= dwFlags
;
538 lpwai
->hdr
.dwRefCount
= 1;
539 lpwai
->dwAccessType
= dwAccessType
;
540 lpwai
->lpszProxyUsername
= NULL
;
541 lpwai
->lpszProxyPassword
= NULL
;
543 handle
= WININET_AllocHandle( &lpwai
->hdr
);
546 HeapFree( GetProcessHeap(), 0, lpwai
);
547 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
551 if (NULL
!= lpszAgent
)
553 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
554 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
555 if (lpwai
->lpszAgent
)
556 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
558 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
559 INTERNET_ConfigureProxyFromReg( lpwai
);
560 else if (NULL
!= lpszProxy
)
562 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
563 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
564 if (lpwai
->lpszProxy
)
565 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
568 if (NULL
!= lpszProxyBypass
)
570 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
571 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
572 if (lpwai
->lpszProxyBypass
)
573 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
578 WININET_Release( &lpwai
->hdr
);
580 TRACE("returning %p\n", lpwai
);
586 /***********************************************************************
587 * InternetOpenA (WININET.@)
589 * Per-application initialization of wininet
592 * HINTERNET on success
596 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
597 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
601 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
603 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
604 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
608 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
609 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
610 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
615 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
616 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
617 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
620 if( lpszProxyBypass
)
622 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
623 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
624 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
627 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
629 HeapFree(GetProcessHeap(), 0, szAgent
);
630 HeapFree(GetProcessHeap(), 0, szProxy
);
631 HeapFree(GetProcessHeap(), 0, szBypass
);
636 /***********************************************************************
637 * InternetGetLastResponseInfoA (WININET.@)
639 * Return last wininet error description on the calling thread
642 * TRUE on success of writing to buffer
646 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
647 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
649 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
655 *lpdwError
= lpwite
->dwError
;
658 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
659 *lpdwBufferLength
= strlen(lpszBuffer
);
662 *lpdwBufferLength
= 0;
667 *lpdwBufferLength
= 0;
673 /***********************************************************************
674 * InternetGetLastResponseInfoW (WININET.@)
676 * Return last wininet error description on the calling thread
679 * TRUE on success of writing to buffer
683 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
684 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
686 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
692 *lpdwError
= lpwite
->dwError
;
695 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
696 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
699 *lpdwBufferLength
= 0;
704 *lpdwBufferLength
= 0;
710 /***********************************************************************
711 * InternetGetConnectedState (WININET.@)
713 * Return connected state
717 * if lpdwStatus is not null, return the status (off line,
718 * modem, lan...) in it.
719 * FALSE if not connected
721 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
723 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
726 FIXME("always returning LAN connection.\n");
727 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
733 /***********************************************************************
734 * InternetGetConnectedStateExW (WININET.@)
736 * Return connected state
740 * lpdwStatus [O] Flags specifying the status of the internet connection.
741 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
742 * dwNameLen [I] Size of the buffer, in characters.
743 * dwReserved [I] Reserved. Must be set to 0.
747 * if lpdwStatus is not null, return the status (off line,
748 * modem, lan...) in it.
749 * FALSE if not connected
752 * If the system has no available network connections, an empty string is
753 * stored in lpszConnectionName. If there is a LAN connection, a localized
754 * "LAN Connection" string is stored. Presumably, if only a dial-up
755 * connection is available then the name of the dial-up connection is
756 * returned. Why any application, other than the "Internet Settings" CPL,
757 * would want to use this function instead of the simpler InternetGetConnectedStateW
758 * function is beyond me.
760 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
761 DWORD dwNameLen
, DWORD dwReserved
)
763 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
770 FIXME("always returning LAN connection.\n");
771 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
773 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
777 /***********************************************************************
778 * InternetGetConnectedStateExA (WININET.@)
780 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
781 DWORD dwNameLen
, DWORD dwReserved
)
783 LPWSTR lpwszConnectionName
= NULL
;
786 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
788 if (lpszConnectionName
&& dwNameLen
> 0)
789 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
791 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
793 if (rc
&& lpwszConnectionName
)
795 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
796 dwNameLen
, NULL
, NULL
);
798 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
805 /***********************************************************************
806 * InternetConnectW (WININET.@)
808 * Open a ftp, gopher or http session
811 * HINTERNET a session handle on success
815 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
816 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
817 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
818 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
820 LPWININETAPPINFOW hIC
;
823 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
824 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
825 dwService
, dwFlags
, dwContext
);
829 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
833 /* Clear any error information */
834 INTERNET_SetLastError(0);
835 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
836 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
838 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
844 case INTERNET_SERVICE_FTP
:
845 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
846 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
849 case INTERNET_SERVICE_HTTP
:
850 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
851 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
854 case INTERNET_SERVICE_GOPHER
:
860 WININET_Release( &hIC
->hdr
);
862 TRACE("returning %p\n", rc
);
867 /***********************************************************************
868 * InternetConnectA (WININET.@)
870 * Open a ftp, gopher or http session
873 * HINTERNET a session handle on success
877 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
878 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
879 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
880 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
884 LPWSTR szServerName
= NULL
;
885 LPWSTR szUserName
= NULL
;
886 LPWSTR szPassword
= NULL
;
890 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
891 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
892 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
896 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
897 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
898 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
902 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
903 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
904 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
908 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
909 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
911 HeapFree(GetProcessHeap(), 0, szServerName
);
912 HeapFree(GetProcessHeap(), 0, szUserName
);
913 HeapFree(GetProcessHeap(), 0, szPassword
);
918 /***********************************************************************
919 * InternetFindNextFileA (WININET.@)
921 * Continues a file search from a previous call to FindFirstFile
928 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
933 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
935 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
939 /***********************************************************************
940 * InternetFindNextFileW (WININET.@)
942 * Continues a file search from a previous call to FindFirstFile
949 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
951 WININETHANDLEHEADER
*hdr
;
956 hdr
= WININET_GetObject(hFind
);
958 WARN("Invalid handle\n");
959 SetLastError(ERROR_INVALID_HANDLE
);
963 if(hdr
->vtbl
->FindNextFileW
) {
964 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
966 WARN("Handle doesn't support NextFile\n");
967 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
970 WININET_Release(hdr
);
972 if(res
!= ERROR_SUCCESS
)
974 return res
== ERROR_SUCCESS
;
977 /***********************************************************************
978 * InternetCloseHandle (WININET.@)
980 * Generic close handle function
987 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
989 LPWININETHANDLEHEADER lpwh
;
991 TRACE("%p\n",hInternet
);
993 lpwh
= WININET_GetObject( hInternet
);
996 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1000 WININET_Release( lpwh
);
1001 WININET_FreeHandle( hInternet
);
1007 /***********************************************************************
1008 * ConvertUrlComponentValue (Internal)
1010 * Helper function for InternetCrackUrlW
1013 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1014 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1015 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1017 TRACE("%p %d %p %d %p %p\n", lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1018 if (*dwComponentLen
!= 0)
1020 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1021 if (*lppszComponent
== NULL
)
1023 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1025 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1027 *lppszComponent
= NULL
;
1028 *dwComponentLen
= nASCIILength
;
1032 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1033 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1034 (*lppszComponent
)[ncpylen
]=0;
1035 *dwComponentLen
= ncpylen
;
1041 /***********************************************************************
1042 * InternetCrackUrlA (WININET.@)
1044 * See InternetCrackUrlW.
1046 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1047 LPURL_COMPONENTSA lpUrlComponents
)
1050 URL_COMPONENTSW UCW
;
1053 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl
), dwUrlLength
, dwFlags
, lpUrlComponents
);
1055 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1056 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1058 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1064 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1066 /* if dwUrlLength=-1 then nLength includes null but length to
1067 InternetCrackUrlW should not include it */
1068 if (dwUrlLength
== -1) nLength
--;
1070 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1071 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1073 memset(&UCW
,0,sizeof(UCW
));
1074 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1075 if(lpUrlComponents
->dwHostNameLength
!=0)
1076 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1077 if(lpUrlComponents
->dwUserNameLength
!=0)
1078 UCW
.dwUserNameLength
=lpUrlComponents
->dwUserNameLength
;
1079 if(lpUrlComponents
->dwPasswordLength
!=0)
1080 UCW
.dwPasswordLength
=lpUrlComponents
->dwPasswordLength
;
1081 if(lpUrlComponents
->dwUrlPathLength
!=0)
1082 UCW
.dwUrlPathLength
=lpUrlComponents
->dwUrlPathLength
;
1083 if(lpUrlComponents
->dwSchemeLength
!=0)
1084 UCW
.dwSchemeLength
=lpUrlComponents
->dwSchemeLength
;
1085 if(lpUrlComponents
->dwExtraInfoLength
!=0)
1086 UCW
.dwExtraInfoLength
=lpUrlComponents
->dwExtraInfoLength
;
1087 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
1089 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1093 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1094 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
1096 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1097 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
1099 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1100 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
1102 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1103 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
1105 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1106 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
1108 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1109 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
1111 lpUrlComponents
->nScheme
=UCW
.nScheme
;
1112 lpUrlComponents
->nPort
=UCW
.nPort
;
1113 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1115 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1116 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
1117 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
1118 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
1119 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
1124 static const WCHAR url_schemes
[][7] =
1127 {'g','o','p','h','e','r',0},
1128 {'h','t','t','p',0},
1129 {'h','t','t','p','s',0},
1130 {'f','i','l','e',0},
1131 {'n','e','w','s',0},
1132 {'m','a','i','l','t','o',0},
1136 /***********************************************************************
1137 * GetInternetSchemeW (internal)
1143 * INTERNET_SCHEME_UNKNOWN on failure
1146 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1150 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1152 if(lpszScheme
==NULL
)
1153 return INTERNET_SCHEME_UNKNOWN
;
1155 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1156 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1157 return INTERNET_SCHEME_FIRST
+ i
;
1159 return INTERNET_SCHEME_UNKNOWN
;
1162 /***********************************************************************
1163 * SetUrlComponentValueW (Internal)
1165 * Helper function for InternetCrackUrlW
1168 * lppszComponent [O] Holds the returned string
1169 * dwComponentLen [I] Holds the size of lppszComponent
1170 * [O] Holds the length of the string in lppszComponent without '\0'
1171 * lpszStart [I] Holds the string to copy from
1172 * len [I] Holds the length of lpszStart without '\0'
1179 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1181 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1183 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1186 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1188 if (*lppszComponent
== NULL
)
1190 *lppszComponent
= (LPWSTR
)lpszStart
;
1191 *dwComponentLen
= len
;
1195 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1196 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1197 (*lppszComponent
)[ncpylen
] = '\0';
1198 *dwComponentLen
= ncpylen
;
1205 /***********************************************************************
1206 * InternetCrackUrlW (WININET.@)
1208 * Break up URL into its components
1214 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1215 LPURL_COMPONENTSW lpUC
)
1219 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1222 LPCWSTR lpszParam
= NULL
;
1223 BOOL bIsAbsolute
= FALSE
;
1224 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1225 LPCWSTR lpszcp
= NULL
;
1226 LPWSTR lpszUrl_decode
= NULL
;
1227 DWORD dwUrlLength
= dwUrlLength_orig
;
1228 const WCHAR lpszSeparators
[3]={';','?',0};
1229 const WCHAR lpszSlash
[2]={'/',0};
1231 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl
), dwUrlLength
, dwFlags
, lpUC
);
1233 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1235 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1238 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1240 if (dwFlags
& ICU_DECODE
)
1242 lpszUrl_decode
=HeapAlloc( GetProcessHeap(), 0, dwUrlLength
* sizeof (WCHAR
) );
1243 if( InternetCanonicalizeUrlW(lpszUrl_orig
, lpszUrl_decode
, &dwUrlLength
, dwFlags
))
1245 lpszUrl
= lpszUrl_decode
;
1250 /* Determine if the URI is absolute. */
1251 while (*lpszap
!= '\0')
1253 if (isalnumW(*lpszap
))
1258 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1265 lpszcp
= lpszUrl
; /* Relative url */
1271 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1272 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1274 /* Parse <params> */
1275 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
1276 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1277 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1279 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1283 /* Get scheme first. */
1284 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1285 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1286 lpszUrl
, lpszcp
- lpszUrl
);
1288 /* Eat ':' in protocol. */
1291 /* double slash indicates the net_loc portion is present */
1292 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1296 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
1300 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1302 lpszNetLoc
= lpszParam
;
1304 else if (!lpszNetLoc
)
1305 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1313 /* [<user>[<:password>]@]<host>[:<port>] */
1314 /* First find the user and password if they exist */
1316 lpszHost
= strchrW(lpszcp
, '@');
1317 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1319 /* username and password not specified. */
1320 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1321 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1323 else /* Parse out username and password */
1325 LPCWSTR lpszUser
= lpszcp
;
1326 LPCWSTR lpszPasswd
= lpszHost
;
1328 while (lpszcp
< lpszHost
)
1331 lpszPasswd
= lpszcp
;
1336 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1337 lpszUser
, lpszPasswd
- lpszUser
);
1339 if (lpszPasswd
!= lpszHost
)
1341 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1342 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1343 lpszHost
- lpszPasswd
);
1345 lpszcp
++; /* Advance to beginning of host */
1348 /* Parse <host><:port> */
1351 lpszPort
= lpszNetLoc
;
1353 /* special case for res:// URLs: there is no port here, so the host is the
1354 entire string up to the first '/' */
1355 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1357 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1358 lpszHost
, lpszPort
- lpszHost
);
1363 while (lpszcp
< lpszNetLoc
)
1371 /* If the scheme is "file" and the host is just one letter, it's not a host */
1372 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1375 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1380 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1381 lpszHost
, lpszPort
- lpszHost
);
1382 if (lpszPort
!= lpszNetLoc
)
1383 lpUC
->nPort
= atoiW(++lpszPort
);
1384 else switch (lpUC
->nScheme
)
1386 case INTERNET_SCHEME_HTTP
:
1387 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1389 case INTERNET_SCHEME_HTTPS
:
1390 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1392 case INTERNET_SCHEME_FTP
:
1393 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1395 case INTERNET_SCHEME_GOPHER
:
1396 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1407 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1408 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1409 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1414 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1415 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1416 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1417 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1420 /* Here lpszcp points to:
1422 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1423 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1425 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1429 /* Only truncate the parameter list if it's already been saved
1430 * in lpUC->lpszExtraInfo.
1432 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1433 len
= lpszParam
- lpszcp
;
1436 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1437 * newlines if necessary.
1439 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1440 if (lpsznewline
!= NULL
)
1441 len
= lpsznewline
- lpszcp
;
1443 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1445 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1450 lpUC
->dwUrlPathLength
= 0;
1453 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1454 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1455 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1456 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1457 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1459 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1463 /***********************************************************************
1464 * InternetAttemptConnect (WININET.@)
1466 * Attempt to make a connection to the internet
1469 * ERROR_SUCCESS on success
1470 * Error value on failure
1473 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1476 return ERROR_SUCCESS
;
1480 /***********************************************************************
1481 * InternetCanonicalizeUrlA (WININET.@)
1483 * Escape unsafe characters and spaces
1490 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1491 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1494 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1496 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1497 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1499 if(dwFlags
& ICU_DECODE
)
1501 dwURLFlags
|= URL_UNESCAPE
;
1502 dwFlags
&= ~ICU_DECODE
;
1505 if(dwFlags
& ICU_ESCAPE
)
1507 dwURLFlags
|= URL_UNESCAPE
;
1508 dwFlags
&= ~ICU_ESCAPE
;
1511 if(dwFlags
& ICU_BROWSER_MODE
)
1513 dwURLFlags
|= URL_BROWSER_MODE
;
1514 dwFlags
&= ~ICU_BROWSER_MODE
;
1517 if(dwFlags
& ICU_NO_ENCODE
)
1519 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1520 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1521 dwFlags
&= ~ICU_NO_ENCODE
;
1524 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1526 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1527 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1528 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1530 return (hr
== S_OK
) ? TRUE
: FALSE
;
1533 /***********************************************************************
1534 * InternetCanonicalizeUrlW (WININET.@)
1536 * Escape unsafe characters and spaces
1543 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1544 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1547 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1549 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1550 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1552 if(dwFlags
& ICU_DECODE
)
1554 dwURLFlags
|= URL_UNESCAPE
;
1555 dwFlags
&= ~ICU_DECODE
;
1558 if(dwFlags
& ICU_ESCAPE
)
1560 dwURLFlags
|= URL_UNESCAPE
;
1561 dwFlags
&= ~ICU_ESCAPE
;
1564 if(dwFlags
& ICU_BROWSER_MODE
)
1566 dwURLFlags
|= URL_BROWSER_MODE
;
1567 dwFlags
&= ~ICU_BROWSER_MODE
;
1570 if(dwFlags
& ICU_NO_ENCODE
)
1572 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1573 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1574 dwFlags
&= ~ICU_NO_ENCODE
;
1577 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1579 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1580 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1581 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1583 return (hr
== S_OK
) ? TRUE
: FALSE
;
1586 /* #################################################### */
1588 static INTERNET_STATUS_CALLBACK
set_status_callback(
1589 LPWININETHANDLEHEADER lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
1591 INTERNET_STATUS_CALLBACK ret
;
1593 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1594 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1596 ret
= lpwh
->lpfnStatusCB
;
1597 lpwh
->lpfnStatusCB
= callback
;
1602 /***********************************************************************
1603 * InternetSetStatusCallbackA (WININET.@)
1605 * Sets up a callback function which is called as progress is made
1606 * during an operation.
1609 * Previous callback or NULL on success
1610 * INTERNET_INVALID_STATUS_CALLBACK on failure
1613 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1614 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1616 INTERNET_STATUS_CALLBACK retVal
;
1617 LPWININETHANDLEHEADER lpwh
;
1619 TRACE("0x%08x\n", (ULONG
)hInternet
);
1621 if (!(lpwh
= WININET_GetObject(hInternet
)))
1622 return INTERNET_INVALID_STATUS_CALLBACK
;
1624 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
1626 WININET_Release( lpwh
);
1630 /***********************************************************************
1631 * InternetSetStatusCallbackW (WININET.@)
1633 * Sets up a callback function which is called as progress is made
1634 * during an operation.
1637 * Previous callback or NULL on success
1638 * INTERNET_INVALID_STATUS_CALLBACK on failure
1641 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1642 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1644 INTERNET_STATUS_CALLBACK retVal
;
1645 LPWININETHANDLEHEADER lpwh
;
1647 TRACE("0x%08x\n", (ULONG
)hInternet
);
1649 if (!(lpwh
= WININET_GetObject(hInternet
)))
1650 return INTERNET_INVALID_STATUS_CALLBACK
;
1652 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
1654 WININET_Release( lpwh
);
1658 /***********************************************************************
1659 * InternetSetFilePointer (WININET.@)
1661 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1662 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
1668 /***********************************************************************
1669 * InternetWriteFile (WININET.@)
1671 * Write data to an open internet file
1678 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1679 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1681 LPWININETHANDLEHEADER lpwh
;
1682 BOOL retval
= FALSE
;
1684 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1686 lpwh
= WININET_GetObject( hFile
);
1688 if(lpwh
&& lpwh
->vtbl
->WriteFile
) {
1689 retval
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1691 WARN("Invalid handle\n");
1692 SetLastError(ERROR_INVALID_HANDLE
);
1696 WININET_Release( lpwh
);
1702 BOOL
INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh
, LPVOID lpBuffer
,
1703 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
,
1704 BOOL bWait
, BOOL bSendCompletionStatus
)
1706 BOOL retval
= FALSE
;
1709 LPWININETHTTPREQW lpwhr
;
1711 /* FIXME: this should use NETCON functions! */
1712 switch (lpwh
->htype
)
1715 lpwhr
= (LPWININETHTTPREQW
)lpwh
;
1717 if (!NETCON_recv(&lpwhr
->netConnection
, lpBuffer
,
1718 min(dwNumOfBytesToRead
, lpwhr
->dwContentLength
- lpwhr
->dwContentRead
),
1719 bWait
? MSG_WAITALL
: 0, &bytes_read
))
1722 if (((lpwhr
->dwContentLength
!= -1) &&
1723 (lpwhr
->dwContentRead
!= lpwhr
->dwContentLength
)))
1724 ERR("not all data received %d/%d\n", lpwhr
->dwContentRead
,
1725 lpwhr
->dwContentLength
);
1727 /* always returns TRUE, even if the network layer returns an
1729 *pdwNumOfBytesRead
= 0;
1730 HTTP_FinishedReading(lpwhr
);
1735 lpwhr
->dwContentRead
+= bytes_read
;
1736 *pdwNumOfBytesRead
= bytes_read
;
1738 if(lpwhr
->lpszCacheFile
) {
1741 res
= WriteFile(lpwhr
->hCacheFile
, lpBuffer
, bytes_read
, NULL
, NULL
);
1743 WARN("WriteFile failed: %u\n", GetLastError());
1746 if (!bytes_read
&& (lpwhr
->dwContentRead
== lpwhr
->dwContentLength
))
1747 retval
= HTTP_FinishedReading(lpwhr
);
1754 /* FIXME: FTP should use NETCON_ stuff */
1755 nSocket
= ((LPWININETFTPFILE
)lpwh
)->nDataSocket
;
1758 int res
= recv(nSocket
, lpBuffer
, dwNumOfBytesToRead
, bWait
? MSG_WAITALL
: 0);
1759 retval
= (res
>= 0);
1760 *pdwNumOfBytesRead
= retval
? res
: 0;
1768 if (bSendCompletionStatus
)
1770 INTERNET_ASYNC_RESULT iar
;
1772 iar
.dwResult
= retval
;
1773 iar
.dwError
= iar
.dwError
= retval
? ERROR_SUCCESS
:
1774 INTERNET_GetLastError();
1776 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1777 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
1778 sizeof(INTERNET_ASYNC_RESULT
));
1783 /***********************************************************************
1784 * InternetReadFile (WININET.@)
1786 * Read data from an open internet file
1793 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1794 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1796 LPWININETHANDLEHEADER lpwh
;
1799 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1801 lpwh
= WININET_GetObject( hFile
);
1804 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1808 retval
= INTERNET_ReadFile(lpwh
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, TRUE
, FALSE
);
1809 WININET_Release( lpwh
);
1811 TRACE("-- %s (bytes read: %d)\n", retval
? "TRUE": "FALSE", pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1815 /***********************************************************************
1816 * InternetReadFileExA (WININET.@)
1818 * Read data from an open internet file
1821 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1822 * lpBuffersOut [I/O] Buffer.
1823 * dwFlags [I] Flags. See notes.
1824 * dwContext [I] Context for callbacks.
1831 * The parameter dwFlags include zero or more of the following flags:
1832 *|IRF_ASYNC - Makes the call asynchronous.
1833 *|IRF_SYNC - Makes the call synchronous.
1834 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1835 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1837 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1840 * InternetOpenUrlA(), HttpOpenRequestA()
1842 void AsyncInternetReadFileExProc(WORKREQUEST
*workRequest
)
1844 struct WORKREQ_INTERNETREADFILEEXA
const *req
= &workRequest
->u
.InternetReadFileExA
;
1846 TRACE("INTERNETREADFILEEXA %p\n", workRequest
->hdr
);
1848 INTERNET_ReadFile(workRequest
->hdr
, req
->lpBuffersOut
->lpvBuffer
,
1849 req
->lpBuffersOut
->dwBufferLength
,
1850 &req
->lpBuffersOut
->dwBufferLength
, TRUE
, TRUE
);
1853 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1854 DWORD dwFlags
, DWORD_PTR dwContext
)
1856 BOOL retval
= FALSE
;
1857 LPWININETHANDLEHEADER lpwh
;
1859 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1861 if (dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
))
1862 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
));
1864 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
))
1866 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1870 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1873 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1877 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1878 INTERNET_STATUS_RECEIVING_RESPONSE
, NULL
, 0);
1880 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1881 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1882 if (dwFlags
& IRF_ASYNC
)
1884 DWORD dwDataAvailable
= 0;
1886 if (lpwh
->htype
== WH_HHTTPREQ
)
1887 NETCON_query_data_available(&((LPWININETHTTPREQW
)lpwh
)->netConnection
,
1890 if (!dwDataAvailable
)
1892 WORKREQUEST workRequest
;
1893 struct WORKREQ_INTERNETREADFILEEXA
*req
;
1895 workRequest
.asyncproc
= AsyncInternetReadFileExProc
;
1896 workRequest
.hdr
= WININET_AddRef( lpwh
);
1897 req
= &workRequest
.u
.InternetReadFileExA
;
1898 req
->lpBuffersOut
= lpBuffersOut
;
1900 if (!INTERNET_AsyncCall(&workRequest
))
1901 WININET_Release( lpwh
);
1903 INTERNET_SetLastError(ERROR_IO_PENDING
);
1908 retval
= INTERNET_ReadFile(lpwh
, lpBuffersOut
->lpvBuffer
,
1909 lpBuffersOut
->dwBufferLength
, &lpBuffersOut
->dwBufferLength
,
1910 !(dwFlags
& IRF_NO_WAIT
), FALSE
);
1914 DWORD dwBytesReceived
= lpBuffersOut
->dwBufferLength
;
1915 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1916 INTERNET_STATUS_RESPONSE_RECEIVED
, &dwBytesReceived
,
1917 sizeof(dwBytesReceived
));
1921 WININET_Release( lpwh
);
1923 TRACE("-- %s (bytes read: %d)\n", retval
? "TRUE": "FALSE", lpBuffersOut
->dwBufferLength
);
1927 /***********************************************************************
1928 * InternetReadFileExW (WININET.@)
1930 * Read data from an open internet file.
1933 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1934 * lpBuffersOut [I/O] Buffer.
1935 * dwFlags [I] Flags.
1936 * dwContext [I] Context for callbacks.
1939 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1942 * Not implemented in Wine or native either (as of IE6 SP2).
1945 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1946 DWORD dwFlags
, DWORD_PTR dwContext
)
1948 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
1950 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1954 /***********************************************************************
1955 * INET_QueryOptionHelper (internal)
1957 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1958 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1960 LPWININETHANDLEHEADER lpwhh
;
1961 BOOL bSuccess
= FALSE
;
1963 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1965 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
1969 case INTERNET_OPTION_HANDLE_TYPE
:
1975 WARN("Invalid hInternet handle\n");
1976 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1980 type
= lpwhh
->htype
;
1982 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type
);
1984 if (*lpdwBufferLength
< sizeof(ULONG
))
1985 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1988 memcpy(lpBuffer
, &type
, sizeof(ULONG
));
1991 *lpdwBufferLength
= sizeof(ULONG
);
1995 case INTERNET_OPTION_REQUEST_FLAGS
:
1998 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags
);
1999 if (*lpdwBufferLength
< sizeof(ULONG
))
2000 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2003 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
2006 *lpdwBufferLength
= sizeof(ULONG
);
2010 case INTERNET_OPTION_URL
:
2012 TRACE("INTERNET_OPTION_URL\n");
2016 WARN("Invalid hInternet handle\n");
2017 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2020 if (lpwhh
->htype
== WH_HHTTPREQ
)
2022 LPWININETHTTPREQW lpreq
= (LPWININETHTTPREQW
) lpwhh
;
2024 static const WCHAR szFmt
[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2025 static const WCHAR szHost
[] = {'H','o','s','t',0};
2029 Host
= HTTP_GetHeader(lpreq
,szHost
);
2030 sprintfW(url
,szFmt
,Host
->lpszValue
,lpreq
->lpszPath
);
2031 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url
));
2034 sizeRequired
= WideCharToMultiByte(CP_ACP
,0,url
,-1,
2035 lpBuffer
,*lpdwBufferLength
,NULL
,NULL
);
2036 if (sizeRequired
> *lpdwBufferLength
)
2037 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2040 *lpdwBufferLength
= sizeRequired
;
2044 sizeRequired
= (lstrlenW(url
)+1) * sizeof(WCHAR
);
2045 if (*lpdwBufferLength
< sizeRequired
)
2046 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2049 strcpyW(lpBuffer
, url
);
2052 *lpdwBufferLength
= sizeRequired
;
2058 case INTERNET_OPTION_DATAFILE_NAME
:
2060 TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
2063 WARN("Invalid hInternet handle\n");
2064 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2067 if (lpwhh
->htype
== WH_HHTTPREQ
)
2069 LPWININETHTTPREQW lpreq
= (LPWININETHTTPREQW
) lpwhh
;
2072 if(!lpreq
->lpszCacheFile
) {
2073 *lpdwBufferLength
= 0;
2074 INTERNET_SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND
);
2078 size
= (lstrlenW(lpreq
->lpszCacheFile
)+1) * sizeof(WCHAR
);
2079 if (*lpdwBufferLength
< size
)
2080 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2083 memcpy(lpBuffer
, lpreq
->lpszCacheFile
, size
);
2086 *lpdwBufferLength
= size
;
2090 size
= WideCharToMultiByte(CP_ACP
, 0, lpreq
->lpszCacheFile
, -1, NULL
, 0, NULL
, NULL
);
2091 if (size
> *lpdwBufferLength
) {
2092 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2094 *lpdwBufferLength
= WideCharToMultiByte(CP_ACP
, 0, lpreq
->lpszCacheFile
,
2095 -1, lpBuffer
, *lpdwBufferLength
, NULL
, NULL
);
2103 case INTERNET_OPTION_HTTP_VERSION
:
2105 if (*lpdwBufferLength
< sizeof(HTTP_VERSION_INFO
))
2106 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2110 * Presently hardcoded to 1.1
2112 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
2113 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
2116 *lpdwBufferLength
= sizeof(HTTP_VERSION_INFO
);
2119 case INTERNET_OPTION_CONNECTED_STATE
:
2121 DWORD
*pdwConnectedState
= (DWORD
*)lpBuffer
;
2122 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2124 if (*lpdwBufferLength
< sizeof(*pdwConnectedState
))
2125 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2128 *pdwConnectedState
= INTERNET_STATE_CONNECTED
;
2131 *lpdwBufferLength
= sizeof(*pdwConnectedState
);
2134 case INTERNET_OPTION_PROXY
:
2136 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
)lpwhh
;
2137 WININETAPPINFOW wai
;
2141 TRACE("Getting global proxy info\n");
2142 memset(&wai
, 0, sizeof(WININETAPPINFOW
));
2143 INTERNET_ConfigureProxyFromReg( &wai
);
2149 INTERNET_PROXY_INFOW
*pPI
= (INTERNET_PROXY_INFOW
*)lpBuffer
;
2150 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2152 if (lpwai
->lpszProxy
)
2153 proxyBytesRequired
= (lstrlenW(lpwai
->lpszProxy
) + 1) *
2155 if (lpwai
->lpszProxyBypass
)
2156 proxyBypassBytesRequired
=
2157 (lstrlenW(lpwai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
2158 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOW
) +
2159 proxyBytesRequired
+ proxyBypassBytesRequired
)
2160 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2163 LPWSTR proxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2164 sizeof(INTERNET_PROXY_INFOW
));
2165 LPWSTR proxy_bypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2166 sizeof(INTERNET_PROXY_INFOW
) +
2167 proxyBytesRequired
);
2169 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2170 pPI
->lpszProxy
= NULL
;
2171 pPI
->lpszProxyBypass
= NULL
;
2172 if (lpwai
->lpszProxy
)
2174 lstrcpyW(proxy
, lpwai
->lpszProxy
);
2175 pPI
->lpszProxy
= proxy
;
2178 if (lpwai
->lpszProxyBypass
)
2180 lstrcpyW(proxy_bypass
, lpwai
->lpszProxyBypass
);
2181 pPI
->lpszProxyBypass
= proxy_bypass
;
2185 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOW
) +
2186 proxyBytesRequired
+ proxyBypassBytesRequired
;
2190 INTERNET_PROXY_INFOA
*pPI
= (INTERNET_PROXY_INFOA
*)lpBuffer
;
2191 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2193 if (lpwai
->lpszProxy
)
2194 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2195 lpwai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
2196 if (lpwai
->lpszProxyBypass
)
2197 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2198 lpwai
->lpszProxyBypass
, -1, NULL
, 0, NULL
, NULL
);
2199 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOA
) +
2200 proxyBytesRequired
+ proxyBypassBytesRequired
)
2201 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2204 LPSTR proxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2205 sizeof(INTERNET_PROXY_INFOA
));
2206 LPSTR proxy_bypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2207 sizeof(INTERNET_PROXY_INFOA
) +
2208 proxyBytesRequired
);
2210 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2211 pPI
->lpszProxy
= NULL
;
2212 pPI
->lpszProxyBypass
= NULL
;
2213 if (lpwai
->lpszProxy
)
2215 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxy
, -1,
2216 proxy
, proxyBytesRequired
, NULL
, NULL
);
2217 pPI
->lpszProxy
= proxy
;
2220 if (lpwai
->lpszProxyBypass
)
2222 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxyBypass
,
2223 -1, proxy_bypass
, proxyBypassBytesRequired
,
2225 pPI
->lpszProxyBypass
= proxy_bypass
;
2229 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOA
) +
2230 proxyBytesRequired
+ proxyBypassBytesRequired
;
2234 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2237 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn
);
2238 if (*lpdwBufferLength
< sizeof(ULONG
))
2239 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2242 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2245 *lpdwBufferLength
= sizeof(ULONG
);
2248 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2251 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn
);
2252 if (*lpdwBufferLength
< sizeof(ULONG
))
2253 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2256 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2259 *lpdwBufferLength
= sizeof(ULONG
);
2262 case INTERNET_OPTION_SECURITY_FLAGS
:
2263 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2267 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
:
2270 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2273 if (*lpdwBufferLength
< sizeof(INTERNET_CERTIFICATE_INFOW
))
2275 *lpdwBufferLength
= sizeof(INTERNET_CERTIFICATE_INFOW
);
2276 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2278 else if (lpwhh
->htype
== WH_HHTTPREQ
)
2280 LPWININETHTTPREQW lpwhr
;
2281 PCCERT_CONTEXT context
;
2283 lpwhr
= (LPWININETHTTPREQW
)lpwhh
;
2284 context
= (PCCERT_CONTEXT
)NETCON_GetCert(&(lpwhr
->netConnection
));
2287 LPINTERNET_CERTIFICATE_INFOW info
= (LPINTERNET_CERTIFICATE_INFOW
)lpBuffer
;
2290 memset(info
,0,sizeof(INTERNET_CERTIFICATE_INFOW
));
2291 info
->ftExpiry
= context
->pCertInfo
->NotAfter
;
2292 info
->ftStart
= context
->pCertInfo
->NotBefore
;
2295 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2296 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2298 info
->lpszSubjectInfo
= LocalAlloc(0,
2299 strLen
* sizeof(WCHAR
));
2300 if (info
->lpszSubjectInfo
)
2301 CertNameToStrW(context
->dwCertEncodingType
,
2302 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2303 info
->lpszSubjectInfo
, strLen
);
2304 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2305 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2307 info
->lpszIssuerInfo
= LocalAlloc(0,
2308 strLen
* sizeof(WCHAR
));
2309 if (info
->lpszIssuerInfo
)
2310 CertNameToStrW(context
->dwCertEncodingType
,
2311 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2312 info
->lpszIssuerInfo
, strLen
);
2316 LPINTERNET_CERTIFICATE_INFOA infoA
=
2317 (LPINTERNET_CERTIFICATE_INFOA
)info
;
2319 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2320 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2322 infoA
->lpszSubjectInfo
= LocalAlloc(0, strLen
);
2323 if (infoA
->lpszSubjectInfo
)
2324 CertNameToStrA(context
->dwCertEncodingType
,
2325 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2326 infoA
->lpszSubjectInfo
, strLen
);
2327 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2328 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2330 infoA
->lpszIssuerInfo
= LocalAlloc(0, strLen
);
2331 if (infoA
->lpszIssuerInfo
)
2332 CertNameToStrA(context
->dwCertEncodingType
,
2333 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2334 infoA
->lpszIssuerInfo
, strLen
);
2337 * Contrary to MSDN, these do not appear to be set.
2339 * lpszSignatureAlgName
2340 * lpszEncryptionAlgName
2343 CertFreeCertificateContext(context
);
2348 case INTERNET_OPTION_VERSION
:
2350 TRACE("INTERNET_OPTION_VERSION\n");
2351 if (*lpdwBufferLength
< sizeof(INTERNET_VERSION_INFO
))
2352 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2355 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2356 memcpy(lpBuffer
, &info
, sizeof(info
));
2357 *lpdwBufferLength
= sizeof(info
);
2362 case INTERNET_OPTION_PER_CONNECTION_OPTION
:
2363 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2364 if (*lpdwBufferLength
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
))
2365 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2368 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2371 for (x
= 0; x
< con
->dwOptionCount
; ++x
)
2373 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ x
;
2374 switch (option
->dwOption
)
2376 case INTERNET_PER_CONN_FLAGS
:
2377 option
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2380 case INTERNET_PER_CONN_PROXY_SERVER
:
2381 case INTERNET_PER_CONN_PROXY_BYPASS
:
2382 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2383 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2384 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2385 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2386 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2387 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2388 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2389 option
->Value
.dwValue
= 0;
2394 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2400 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2408 FIXME("Stub! %d\n", dwOption
);
2412 WININET_Release( lpwhh
);
2417 /***********************************************************************
2418 * InternetQueryOptionW (WININET.@)
2420 * Queries an options on the specified handle
2427 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2428 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2430 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2433 /***********************************************************************
2434 * InternetQueryOptionA (WININET.@)
2436 * Queries an options on the specified handle
2443 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2444 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2446 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2450 /***********************************************************************
2451 * InternetSetOptionW (WININET.@)
2453 * Sets an options on the specified handle
2460 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2461 LPVOID lpBuffer
, DWORD dwBufferLength
)
2463 LPWININETHANDLEHEADER lpwhh
;
2466 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2468 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2469 if(lpwhh
&& lpwhh
->vtbl
->SetOption
) {
2472 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2473 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2474 WININET_Release( lpwhh
);
2476 if(res
!= ERROR_SUCCESS
)
2479 return res
== ERROR_SUCCESS
;
2485 case INTERNET_OPTION_CALLBACK
:
2487 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2488 ret
= (set_status_callback(lpwhh
, callback
, TRUE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2491 case INTERNET_OPTION_HTTP_VERSION
:
2493 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2494 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2497 case INTERNET_OPTION_ERROR_MASK
:
2499 unsigned long flags
=*(unsigned long*)lpBuffer
;
2500 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
2503 case INTERNET_OPTION_CODEPAGE
:
2505 unsigned long codepage
=*(unsigned long*)lpBuffer
;
2506 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
2509 case INTERNET_OPTION_REQUEST_PRIORITY
:
2511 unsigned long priority
=*(unsigned long*)lpBuffer
;
2512 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
2515 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2517 unsigned long connecttimeout
=*(unsigned long*)lpBuffer
;
2518 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout
);
2521 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2523 unsigned long receivetimeout
=*(unsigned long*)lpBuffer
;
2524 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout
);
2527 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2529 unsigned long conns
=*(unsigned long*)lpBuffer
;
2530 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns
);
2533 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2535 unsigned long conns
=*(unsigned long*)lpBuffer
;
2536 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns
);
2539 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2540 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2542 case INTERNET_OPTION_END_BROWSER_SESSION
:
2543 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2545 case INTERNET_OPTION_CONNECTED_STATE
:
2546 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2548 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2549 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2551 case INTERNET_OPTION_SEND_TIMEOUT
:
2552 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2553 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2555 case INTERNET_OPTION_CONNECT_RETRIES
:
2556 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2558 case INTERNET_OPTION_CONTEXT_VALUE
:
2559 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2561 case INTERNET_OPTION_SECURITY_FLAGS
:
2562 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2568 FIXME("Option %d STUB\n",dwOption
);
2569 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2575 WININET_Release( lpwhh
);
2581 /***********************************************************************
2582 * InternetSetOptionA (WININET.@)
2584 * Sets an options on the specified handle.
2591 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2592 LPVOID lpBuffer
, DWORD dwBufferLength
)
2600 case INTERNET_OPTION_CALLBACK
:
2602 LPWININETHANDLEHEADER lpwh
;
2603 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2605 if (!(lpwh
= WININET_GetObject(hInternet
))) return FALSE
;
2606 r
= (set_status_callback(lpwh
, callback
, FALSE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2607 WININET_Release(lpwh
);
2610 case INTERNET_OPTION_PROXY
:
2612 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2613 LPINTERNET_PROXY_INFOW piw
;
2614 DWORD proxlen
, prbylen
;
2617 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2618 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2619 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2620 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2621 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2622 piw
->dwAccessType
= pi
->dwAccessType
;
2623 prox
= (LPWSTR
) &piw
[1];
2624 prby
= &prox
[proxlen
+1];
2625 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2626 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2627 piw
->lpszProxy
= prox
;
2628 piw
->lpszProxyBypass
= prby
;
2631 case INTERNET_OPTION_USER_AGENT
:
2632 case INTERNET_OPTION_USERNAME
:
2633 case INTERNET_OPTION_PASSWORD
:
2634 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2636 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2637 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2642 wlen
= dwBufferLength
;
2645 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2647 if( lpBuffer
!= wbuffer
)
2648 HeapFree( GetProcessHeap(), 0, wbuffer
);
2654 /***********************************************************************
2655 * InternetSetOptionExA (WININET.@)
2657 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2658 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2660 FIXME("Flags %08x ignored\n", dwFlags
);
2661 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2664 /***********************************************************************
2665 * InternetSetOptionExW (WININET.@)
2667 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2668 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2670 FIXME("Flags %08x ignored\n", dwFlags
);
2671 if( dwFlags
& ~ISO_VALID_FLAGS
)
2673 INTERNET_SetLastError( ERROR_INVALID_PARAMETER
);
2676 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2679 static const WCHAR WININET_wkday
[7][4] =
2680 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2681 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2682 static const WCHAR WININET_month
[12][4] =
2683 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2684 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2685 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2687 /***********************************************************************
2688 * InternetTimeFromSystemTimeA (WININET.@)
2690 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2693 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2695 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2697 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2698 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2703 /***********************************************************************
2704 * InternetTimeFromSystemTimeW (WININET.@)
2706 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2708 static const WCHAR date
[] =
2709 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2710 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2712 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2714 if (!time
|| !string
) return FALSE
;
2716 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2719 sprintfW( string
, date
,
2720 WININET_wkday
[time
->wDayOfWeek
],
2722 WININET_month
[time
->wMonth
- 1],
2731 /***********************************************************************
2732 * InternetTimeToSystemTimeA (WININET.@)
2734 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2740 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
2742 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2743 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2747 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2748 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2749 HeapFree( GetProcessHeap(), 0, stringW
);
2754 /***********************************************************************
2755 * InternetTimeToSystemTimeW (WININET.@)
2757 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2760 const WCHAR
*s
= string
;
2763 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
2765 if (!string
|| !time
) return FALSE
;
2767 /* Windows does this too */
2768 GetSystemTime( time
);
2770 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2771 * a SYSTEMTIME structure.
2774 while (*s
&& !isalphaW( *s
)) s
++;
2775 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2776 time
->wDayOfWeek
= 7;
2778 for (i
= 0; i
< 7; i
++)
2780 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2781 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2782 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2784 time
->wDayOfWeek
= i
;
2789 if (time
->wDayOfWeek
> 6) return TRUE
;
2790 while (*s
&& !isdigitW( *s
)) s
++;
2791 time
->wDay
= strtolW( s
, &end
, 10 );
2794 while (*s
&& !isalphaW( *s
)) s
++;
2795 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2798 for (i
= 0; i
< 12; i
++)
2800 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2801 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2802 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2804 time
->wMonth
= i
+ 1;
2808 if (time
->wMonth
== 0) return TRUE
;
2810 while (*s
&& !isdigitW( *s
)) s
++;
2811 if (*s
== '\0') return TRUE
;
2812 time
->wYear
= strtolW( s
, &end
, 10 );
2815 while (*s
&& !isdigitW( *s
)) s
++;
2816 if (*s
== '\0') return TRUE
;
2817 time
->wHour
= strtolW( s
, &end
, 10 );
2820 while (*s
&& !isdigitW( *s
)) s
++;
2821 if (*s
== '\0') return TRUE
;
2822 time
->wMinute
= strtolW( s
, &end
, 10 );
2825 while (*s
&& !isdigitW( *s
)) s
++;
2826 if (*s
== '\0') return TRUE
;
2827 time
->wSecond
= strtolW( s
, &end
, 10 );
2830 time
->wMilliseconds
= 0;
2834 /***********************************************************************
2835 * InternetCheckConnectionW (WININET.@)
2837 * Pings a requested host to check internet connection
2840 * TRUE on success and FALSE on failure. If a failure then
2841 * ERROR_NOT_CONNECTED is placed into GetLastError
2844 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2847 * this is a kludge which runs the resident ping program and reads the output.
2849 * Anyone have a better idea?
2853 static const CHAR ping
[] = "ping -c 1 ";
2854 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2855 CHAR
*command
= NULL
;
2864 * Crack or set the Address
2866 if (lpszUrl
== NULL
)
2869 * According to the doc we are supposed to use the ip for the next
2870 * server in the WnInet internal server database. I have
2871 * no idea what that is or how to get it.
2873 * So someone needs to implement this.
2875 FIXME("Unimplemented with URL of NULL\n");
2880 URL_COMPONENTSW components
;
2882 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2883 components
.lpszHostName
= (LPWSTR
)&hostW
;
2884 components
.dwHostNameLength
= 1024;
2886 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2889 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2890 port
= components
.nPort
;
2891 TRACE("port: %d\n", port
);
2894 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
2896 struct sockaddr_in sin
;
2899 if (!GetAddress(hostW
, port
, &sin
))
2901 fd
= socket(sin
.sin_family
, SOCK_STREAM
, 0);
2904 if (connect(fd
, (struct sockaddr
*)&sin
, sizeof(sin
)) == 0)
2912 * Build our ping command
2914 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2915 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2916 strcpy(command
,ping
);
2917 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2918 strcat(command
,redirect
);
2920 TRACE("Ping command is : %s\n",command
);
2922 status
= system(command
);
2924 TRACE("Ping returned a code of %i\n",status
);
2926 /* Ping return code of 0 indicates success */
2933 HeapFree( GetProcessHeap(), 0, command
);
2935 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
2941 /***********************************************************************
2942 * InternetCheckConnectionA (WININET.@)
2944 * Pings a requested host to check internet connection
2947 * TRUE on success and FALSE on failure. If a failure then
2948 * ERROR_NOT_CONNECTED is placed into GetLastError
2951 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2957 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2958 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2960 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2961 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2962 HeapFree(GetProcessHeap(), 0, szUrl
);
2968 /**********************************************************
2969 * INTERNET_InternetOpenUrlW (internal)
2974 * handle of connection or NULL on failure
2976 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2977 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2979 URL_COMPONENTSW urlComponents
;
2980 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2981 WCHAR password
[1024], path
[2048], extra
[1024];
2982 HINTERNET client
= NULL
, client1
= NULL
;
2984 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2985 dwHeadersLength
, dwFlags
, dwContext
);
2987 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2988 urlComponents
.lpszScheme
= protocol
;
2989 urlComponents
.dwSchemeLength
= 32;
2990 urlComponents
.lpszHostName
= hostName
;
2991 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2992 urlComponents
.lpszUserName
= userName
;
2993 urlComponents
.dwUserNameLength
= 1024;
2994 urlComponents
.lpszPassword
= password
;
2995 urlComponents
.dwPasswordLength
= 1024;
2996 urlComponents
.lpszUrlPath
= path
;
2997 urlComponents
.dwUrlPathLength
= 2048;
2998 urlComponents
.lpszExtraInfo
= extra
;
2999 urlComponents
.dwExtraInfoLength
= 1024;
3000 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
3002 switch(urlComponents
.nScheme
) {
3003 case INTERNET_SCHEME_FTP
:
3004 if(urlComponents
.nPort
== 0)
3005 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
3006 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3007 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3010 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
3011 if(client1
== NULL
) {
3012 InternetCloseHandle(client
);
3017 case INTERNET_SCHEME_HTTP
:
3018 case INTERNET_SCHEME_HTTPS
: {
3019 static const WCHAR szStars
[] = { '*','/','*', 0 };
3020 LPCWSTR accept
[2] = { szStars
, NULL
};
3021 if(urlComponents
.nPort
== 0) {
3022 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
3023 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
3025 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
3027 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3028 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
3029 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
3033 if (urlComponents
.dwExtraInfoLength
) {
3035 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
3037 if (!(path_extra
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
3039 InternetCloseHandle(client
);
3042 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
3043 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
3044 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3045 HeapFree(GetProcessHeap(), 0, path_extra
);
3048 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
3050 if(client1
== NULL
) {
3051 InternetCloseHandle(client
);
3054 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
3055 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
3056 GetLastError() != ERROR_IO_PENDING
) {
3057 InternetCloseHandle(client1
);
3062 case INTERNET_SCHEME_GOPHER
:
3063 /* gopher doesn't seem to be implemented in wine, but it's supposed
3064 * to be supported by InternetOpenUrlA. */
3066 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3070 TRACE(" %p <--\n", client1
);
3075 /**********************************************************
3076 * InternetOpenUrlW (WININET.@)
3081 * handle of connection or NULL on failure
3083 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3085 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3086 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
->hdr
;
3090 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3091 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3092 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
3093 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
3096 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3097 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3099 HINTERNET ret
= NULL
;
3100 LPWININETAPPINFOW hIC
= NULL
;
3102 if (TRACE_ON(wininet
)) {
3103 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3104 dwHeadersLength
, dwFlags
, dwContext
);
3106 dump_INTERNET_FLAGS(dwFlags
);
3111 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3115 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
3116 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3117 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3121 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3122 WORKREQUEST workRequest
;
3123 struct WORKREQ_INTERNETOPENURLW
*req
;
3125 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3126 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3127 req
= &workRequest
.u
.InternetOpenUrlW
;
3128 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
3130 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
3132 req
->lpszHeaders
= 0;
3133 req
->dwHeadersLength
= dwHeadersLength
;
3134 req
->dwFlags
= dwFlags
;
3135 req
->dwContext
= dwContext
;
3137 INTERNET_AsyncCall(&workRequest
);
3139 * This is from windows.
3141 INTERNET_SetLastError(ERROR_IO_PENDING
);
3143 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3148 WININET_Release( &hIC
->hdr
);
3149 TRACE(" %p <--\n", ret
);
3154 /**********************************************************
3155 * InternetOpenUrlA (WININET.@)
3160 * handle of connection or NULL on failure
3162 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3163 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3165 HINTERNET rc
= NULL
;
3169 LPWSTR szUrl
= NULL
;
3170 LPWSTR szHeaders
= NULL
;
3175 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
3176 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
3179 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
3183 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3184 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
3186 HeapFree(GetProcessHeap(), 0, szUrl
);
3189 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3192 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3193 lenHeaders
, dwFlags
, dwContext
);
3195 HeapFree(GetProcessHeap(), 0, szUrl
);
3196 HeapFree(GetProcessHeap(), 0, szHeaders
);
3202 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3204 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite
));
3208 lpwite
->dwError
= 0;
3209 lpwite
->response
[0] = '\0';
3212 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3214 HeapFree(GetProcessHeap(), 0, lpwite
);
3222 /***********************************************************************
3223 * INTERNET_SetLastError (internal)
3225 * Set last thread specific error
3230 void INTERNET_SetLastError(DWORD dwError
)
3232 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3235 lpwite
= INTERNET_AllocThreadError();
3237 SetLastError(dwError
);
3239 lpwite
->dwError
= dwError
;
3243 /***********************************************************************
3244 * INTERNET_GetLastError (internal)
3246 * Get last thread specific error
3251 DWORD
INTERNET_GetLastError(void)
3253 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3254 if (!lpwite
) return 0;
3255 /* TlsGetValue clears last error, so set it again here */
3256 SetLastError(lpwite
->dwError
);
3257 return lpwite
->dwError
;
3261 /***********************************************************************
3262 * INTERNET_WorkerThreadFunc (internal)
3264 * Worker thread execution function
3269 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3271 LPWORKREQUEST lpRequest
= lpvParam
;
3272 WORKREQUEST workRequest
;
3276 memcpy(&workRequest
, lpRequest
, sizeof(WORKREQUEST
));
3277 HeapFree(GetProcessHeap(), 0, lpRequest
);
3279 workRequest
.asyncproc(&workRequest
);
3281 WININET_Release( workRequest
.hdr
);
3286 /***********************************************************************
3287 * INTERNET_AsyncCall (internal)
3289 * Retrieves work request from queue
3294 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3297 LPWORKREQUEST lpNewRequest
;
3301 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3305 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
3307 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3310 HeapFree(GetProcessHeap(), 0, lpNewRequest
);
3311 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3318 /***********************************************************************
3319 * INTERNET_GetResponseBuffer (internal)
3324 LPSTR
INTERNET_GetResponseBuffer(void)
3326 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3328 lpwite
= INTERNET_AllocThreadError();
3330 return lpwite
->response
;
3333 /***********************************************************************
3334 * INTERNET_GetNextLine (internal)
3336 * Parse next line in directory string listing
3339 * Pointer to beginning of next line
3344 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3348 BOOL bSuccess
= FALSE
;
3350 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3355 FD_SET(nSocket
, &infd
);
3356 tv
.tv_sec
=RESPONSE_TIMEOUT
;
3359 while (nRecv
< MAX_REPLY_LEN
)
3361 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
3363 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3365 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3369 if (lpszBuffer
[nRecv
] == '\n')
3374 if (lpszBuffer
[nRecv
] != '\r')
3379 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3387 lpszBuffer
[nRecv
] = '\0';
3389 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3398 /**********************************************************
3399 * InternetQueryDataAvailable (WININET.@)
3401 * Determines how much data is available to be read.
3404 * TRUE on success, FALSE if an error occurred. If
3405 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3406 * no data is presently available, FALSE is returned with
3407 * the last error ERROR_IO_PENDING; a callback with status
3408 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3409 * data is available.
3411 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3412 LPDWORD lpdwNumberOfBytesAvailble
,
3413 DWORD dwFlags
, DWORD_PTR dwContext
)
3415 WININETHANDLEHEADER
*hdr
;
3418 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3420 hdr
= WININET_GetObject( hFile
);
3422 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
3426 if(hdr
->vtbl
->QueryDataAvailable
) {
3427 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3429 WARN("wrong handle\n");
3430 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3433 WININET_Release(hdr
);
3435 if(res
!= ERROR_SUCCESS
)
3437 return res
== ERROR_SUCCESS
;
3441 /***********************************************************************
3442 * InternetLockRequestFile (WININET.@)
3444 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3451 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3458 /***********************************************************************
3459 * InternetAutodial (WININET.@)
3461 * On windows this function is supposed to dial the default internet
3462 * connection. We don't want to have Wine dial out to the internet so
3463 * we return TRUE by default. It might be nice to check if we are connected.
3470 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3474 /* Tell that we are connected to the internet. */
3478 /***********************************************************************
3479 * InternetAutodialHangup (WININET.@)
3481 * Hangs up a connection made with InternetAutodial
3490 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3494 /* we didn't dial, we don't disconnect */
3498 /***********************************************************************
3499 * InternetCombineUrlA (WININET.@)
3501 * Combine a base URL with a relative URL
3509 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3510 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3515 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3517 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3518 dwFlags
^= ICU_NO_ENCODE
;
3519 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3524 /***********************************************************************
3525 * InternetCombineUrlW (WININET.@)
3527 * Combine a base URL with a relative URL
3535 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3536 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3541 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3543 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3544 dwFlags
^= ICU_NO_ENCODE
;
3545 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3550 /* max port num is 65535 => 5 digits */
3551 #define MAX_WORD_DIGITS 5
3553 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3554 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3555 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3556 (url)->dw##component##Length : strlen((url)->lpsz##component))
3558 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3560 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3561 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3563 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3564 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3566 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3567 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3569 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3570 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3573 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3579 /* opaque urls do not fit into the standard url hierarchy and don't have
3580 * two following slashes */
3581 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3583 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3584 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3585 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3586 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3587 (nScheme
!= INTERNET_SCHEME_FILE
);
3590 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3593 if (scheme
< INTERNET_SCHEME_FIRST
)
3595 index
= scheme
- INTERNET_SCHEME_FIRST
;
3596 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3598 return (LPCWSTR
)&url_schemes
[index
];
3601 /* we can calculate using ansi strings because we're just
3602 * calculating string length, not size
3604 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3605 LPDWORD lpdwUrlLength
)
3607 INTERNET_SCHEME nScheme
;
3611 if (lpUrlComponents
->lpszScheme
)
3613 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3614 *lpdwUrlLength
+= dwLen
;
3615 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3621 nScheme
= lpUrlComponents
->nScheme
;
3623 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3624 nScheme
= INTERNET_SCHEME_HTTP
;
3625 scheme
= INTERNET_GetSchemeString(nScheme
);
3626 *lpdwUrlLength
+= strlenW(scheme
);
3629 (*lpdwUrlLength
)++; /* ':' */
3630 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3631 *lpdwUrlLength
+= strlen("//");
3633 if (lpUrlComponents
->lpszUserName
)
3635 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3636 *lpdwUrlLength
+= strlen("@");
3640 if (lpUrlComponents
->lpszPassword
)
3642 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3647 if (lpUrlComponents
->lpszPassword
)
3649 *lpdwUrlLength
+= strlen(":");
3650 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3653 if (lpUrlComponents
->lpszHostName
)
3655 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3657 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3659 char szPort
[MAX_WORD_DIGITS
+1];
3661 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3662 *lpdwUrlLength
+= strlen(szPort
);
3663 *lpdwUrlLength
+= strlen(":");
3666 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3667 (*lpdwUrlLength
)++; /* '/' */
3670 if (lpUrlComponents
->lpszUrlPath
)
3671 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3676 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3680 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3682 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3683 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3684 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3685 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3686 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3687 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3688 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3689 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3690 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3692 if (lpUrlComponents
->lpszScheme
)
3694 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
3695 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3696 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3697 -1, urlCompW
->lpszScheme
, len
);
3700 if (lpUrlComponents
->lpszHostName
)
3702 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
3703 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3704 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3705 -1, urlCompW
->lpszHostName
, len
);
3708 if (lpUrlComponents
->lpszUserName
)
3710 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
3711 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3712 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3713 -1, urlCompW
->lpszUserName
, len
);
3716 if (lpUrlComponents
->lpszPassword
)
3718 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
3719 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3720 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3721 -1, urlCompW
->lpszPassword
, len
);
3724 if (lpUrlComponents
->lpszUrlPath
)
3726 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
3727 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3728 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3729 -1, urlCompW
->lpszUrlPath
, len
);
3732 if (lpUrlComponents
->lpszExtraInfo
)
3734 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
3735 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3736 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3737 -1, urlCompW
->lpszExtraInfo
, len
);
3741 /***********************************************************************
3742 * InternetCreateUrlA (WININET.@)
3744 * See InternetCreateUrlW.
3746 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3747 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3751 URL_COMPONENTSW urlCompW
;
3753 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3755 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3757 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3761 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3764 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3766 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3768 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3769 *lpdwUrlLength
/= sizeof(WCHAR
);
3771 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3772 * minus one, so add one to leave room for NULL terminator
3775 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3777 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3778 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3779 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3780 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3781 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3782 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3783 HeapFree(GetProcessHeap(), 0, urlW
);
3788 /***********************************************************************
3789 * InternetCreateUrlW (WININET.@)
3791 * Creates a URL from its component parts.
3794 * lpUrlComponents [I] URL Components.
3795 * dwFlags [I] Flags. See notes.
3796 * lpszUrl [I] Buffer in which to store the created URL.
3797 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3798 * lpszUrl in characters. On output, the number of bytes
3799 * required to store the URL including terminator.
3803 * The dwFlags parameter can be zero or more of the following:
3804 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3811 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3812 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3815 INTERNET_SCHEME nScheme
;
3817 static const WCHAR slashSlashW
[] = {'/','/'};
3818 static const WCHAR percentD
[] = {'%','d',0};
3820 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3822 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3824 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3828 if (!calc_url_length(lpUrlComponents
, &dwLen
))
3831 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3833 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
3834 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3838 *lpdwUrlLength
= dwLen
;
3843 if (lpUrlComponents
->lpszScheme
)
3845 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3846 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
3849 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3854 nScheme
= lpUrlComponents
->nScheme
;
3856 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3857 nScheme
= INTERNET_SCHEME_HTTP
;
3859 scheme
= INTERNET_GetSchemeString(nScheme
);
3860 dwLen
= strlenW(scheme
);
3861 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
3865 /* all schemes are followed by at least a colon */
3869 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3871 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
3872 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
3875 if (lpUrlComponents
->lpszUserName
)
3877 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3878 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
3881 if (lpUrlComponents
->lpszPassword
)
3886 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3887 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
3895 if (lpUrlComponents
->lpszHostName
)
3897 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3898 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
3901 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3903 WCHAR szPort
[MAX_WORD_DIGITS
+1];
3905 sprintfW(szPort
, percentD
, lpUrlComponents
->nPort
);
3908 dwLen
= strlenW(szPort
);
3909 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
3913 /* add slash between hostname and path if necessary */
3914 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3922 if (lpUrlComponents
->lpszUrlPath
)
3924 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3925 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
3934 /***********************************************************************
3935 * InternetConfirmZoneCrossingA (WININET.@)
3938 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
3940 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
3941 return ERROR_SUCCESS
;
3944 /***********************************************************************
3945 * InternetConfirmZoneCrossingW (WININET.@)
3948 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
3950 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
3951 return ERROR_SUCCESS
;
3954 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
3955 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3957 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3958 lpdwConnection
, dwReserved
);
3959 return ERROR_SUCCESS
;
3962 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
3963 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3965 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3966 lpdwConnection
, dwReserved
);
3967 return ERROR_SUCCESS
;
3970 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3972 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
3976 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3978 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
3982 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
3984 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
3985 return ERROR_SUCCESS
;
3988 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
3991 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
3992 debugstr_w(pwszTarget
), pbHexHash
);
3996 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
3998 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4002 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4004 FIXME("(%p, %08lx) stub\n", a
, b
);