4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
58 #include "wine/debug.h"
60 #define NO_SHLWAPI_STREAM
64 #include "wine/exception.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
73 #define RESPONSE_TIMEOUT 30
78 CHAR response
[MAX_REPLY_LEN
];
79 } WITHREADERROR
, *LPWITHREADERROR
;
81 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
82 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
);
84 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
85 static HMODULE WININET_hModule
;
87 #define HANDLE_CHUNK_SIZE 0x10
89 static CRITICAL_SECTION WININET_cs
;
90 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
93 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
94 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
96 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
98 static LPWININETHANDLEHEADER
*WININET_Handles
;
99 static UINT WININET_dwNextHandle
;
100 static UINT WININET_dwMaxHandles
;
102 HINTERNET
WININET_AllocHandle( LPWININETHANDLEHEADER info
)
104 LPWININETHANDLEHEADER
*p
;
105 UINT handle
= 0, num
;
107 list_init( &info
->children
);
109 EnterCriticalSection( &WININET_cs
);
110 if( !WININET_dwMaxHandles
)
112 num
= HANDLE_CHUNK_SIZE
;
113 p
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
118 WININET_dwMaxHandles
= num
;
120 if( WININET_dwMaxHandles
== WININET_dwNextHandle
)
122 num
= WININET_dwMaxHandles
+ HANDLE_CHUNK_SIZE
;
123 p
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
124 WININET_Handles
, sizeof (UINT
)* num
);
128 WININET_dwMaxHandles
= num
;
131 handle
= WININET_dwNextHandle
;
132 if( WININET_Handles
[handle
] )
133 ERR("handle isn't free but should be\n");
134 WININET_Handles
[handle
] = WININET_AddRef( info
);
136 while( WININET_Handles
[WININET_dwNextHandle
] &&
137 (WININET_dwNextHandle
< WININET_dwMaxHandles
) )
138 WININET_dwNextHandle
++;
141 LeaveCriticalSection( &WININET_cs
);
143 return info
->hInternet
= (HINTERNET
) (handle
+1);
146 LPWININETHANDLEHEADER
WININET_AddRef( LPWININETHANDLEHEADER info
)
148 ULONG refs
= InterlockedIncrement(&info
->refs
);
149 TRACE("%p -> refcount = %d\n", info
, refs
);
153 LPWININETHANDLEHEADER
WININET_GetObject( HINTERNET hinternet
)
155 LPWININETHANDLEHEADER info
= NULL
;
156 UINT handle
= (UINT
) hinternet
;
158 EnterCriticalSection( &WININET_cs
);
160 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) &&
161 WININET_Handles
[handle
-1] )
162 info
= WININET_AddRef( WININET_Handles
[handle
-1] );
164 LeaveCriticalSection( &WININET_cs
);
166 TRACE("handle %d -> %p\n", handle
, info
);
171 BOOL
WININET_Release( LPWININETHANDLEHEADER info
)
173 ULONG refs
= InterlockedDecrement(&info
->refs
);
174 TRACE( "object %p refcount = %d\n", info
, refs
);
177 if ( info
->vtbl
->CloseConnection
)
179 TRACE( "closing connection %p\n", info
);
180 info
->vtbl
->CloseConnection( info
);
182 INTERNET_SendCallback(info
, info
->dwContext
,
183 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
185 TRACE( "destroying object %p\n", info
);
186 if ( info
->htype
!= WH_HINIT
)
187 list_remove( &info
->entry
);
188 info
->vtbl
->Destroy( info
);
193 BOOL
WININET_FreeHandle( HINTERNET hinternet
)
196 UINT handle
= (UINT
) hinternet
;
197 LPWININETHANDLEHEADER info
= NULL
, child
, next
;
199 EnterCriticalSection( &WININET_cs
);
201 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) )
204 if( WININET_Handles
[handle
] )
206 info
= WININET_Handles
[handle
];
207 TRACE( "destroying handle %d for object %p\n", handle
+1, info
);
208 WININET_Handles
[handle
] = NULL
;
213 LeaveCriticalSection( &WININET_cs
);
215 /* As on native when the equivalent of WININET_Release is called, the handle
216 * is already invalid, but if a new handle is created at this time it does
217 * not yet get assigned the freed handle number */
220 /* Free all children as native does */
221 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, WININETHANDLEHEADER
, entry
)
223 TRACE( "freeing child handle %d for parent handle %d\n",
224 (UINT
)child
->hInternet
, handle
+1);
225 WININET_FreeHandle( child
->hInternet
);
227 WININET_Release( info
);
230 EnterCriticalSection( &WININET_cs
);
232 if( WININET_dwNextHandle
> handle
&& !WININET_Handles
[handle
] )
233 WININET_dwNextHandle
= handle
;
235 LeaveCriticalSection( &WININET_cs
);
240 /***********************************************************************
241 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
244 * hinstDLL [I] handle to the DLL's instance
246 * lpvReserved [I] reserved, must be NULL
253 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
255 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
258 case DLL_PROCESS_ATTACH
:
260 g_dwTlsErrIndex
= TlsAlloc();
262 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
265 URLCacheContainers_CreateDefaults();
267 WININET_hModule
= hinstDLL
;
269 case DLL_THREAD_ATTACH
:
272 case DLL_THREAD_DETACH
:
273 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
275 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
276 HeapFree(GetProcessHeap(), 0, lpwite
);
280 case DLL_PROCESS_DETACH
:
282 URLCacheContainers_DeleteAll();
284 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
286 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
287 TlsFree(g_dwTlsErrIndex
);
296 /***********************************************************************
297 * InternetInitializeAutoProxyDll (WININET.@)
299 * Setup the internal proxy
308 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
311 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
315 /***********************************************************************
316 * DetectAutoProxyUrl (WININET.@)
318 * Auto detect the proxy url
324 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
325 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
328 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
333 /***********************************************************************
334 * INTERNET_ConfigureProxyFromReg
337 * The proxy may be specified in the form 'http=proxy.my.org'
338 * Presumably that means there can be ftp=ftpproxy.my.org too.
340 static BOOL
INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai
)
343 DWORD r
, keytype
, len
, enabled
;
344 LPCSTR lpszInternetSettings
=
345 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
346 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
348 r
= RegOpenKeyA(HKEY_CURRENT_USER
, lpszInternetSettings
, &key
);
349 if ( r
!= ERROR_SUCCESS
)
352 len
= sizeof enabled
;
353 r
= RegQueryValueExA( key
, "ProxyEnable", NULL
, &keytype
,
354 (BYTE
*)&enabled
, &len
);
355 if( (r
== ERROR_SUCCESS
) && enabled
)
357 TRACE("Proxy is enabled.\n");
359 /* figure out how much memory the proxy setting takes */
360 r
= RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
362 if( (r
== ERROR_SUCCESS
) && len
&& (keytype
== REG_SZ
) )
365 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
367 szProxy
=HeapAlloc( GetProcessHeap(), 0, len
);
368 RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
369 (BYTE
*)szProxy
, &len
);
371 /* find the http proxy, and strip away everything else */
372 p
= strstrW( szProxy
, szHttp
);
375 p
+= lstrlenW(szHttp
);
376 lstrcpyW( szProxy
, p
);
378 p
= strchrW( szProxy
, ' ' );
382 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
383 lpwai
->lpszProxy
= szProxy
;
385 TRACE("http proxy = %s\n", debugstr_w(lpwai
->lpszProxy
));
388 ERR("Couldn't read proxy server settings.\n");
391 TRACE("Proxy is not enabled.\n");
397 /***********************************************************************
398 * dump_INTERNET_FLAGS
400 * Helper function to TRACE the internet flags.
406 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
408 #define FE(x) { x, #x }
409 static const wininet_flag_info flag
[] = {
410 FE(INTERNET_FLAG_RELOAD
),
411 FE(INTERNET_FLAG_RAW_DATA
),
412 FE(INTERNET_FLAG_EXISTING_CONNECT
),
413 FE(INTERNET_FLAG_ASYNC
),
414 FE(INTERNET_FLAG_PASSIVE
),
415 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
416 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
417 FE(INTERNET_FLAG_FROM_CACHE
),
418 FE(INTERNET_FLAG_SECURE
),
419 FE(INTERNET_FLAG_KEEP_CONNECTION
),
420 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
421 FE(INTERNET_FLAG_READ_PREFETCH
),
422 FE(INTERNET_FLAG_NO_COOKIES
),
423 FE(INTERNET_FLAG_NO_AUTH
),
424 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
425 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
426 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
427 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
428 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
429 FE(INTERNET_FLAG_RESYNCHRONIZE
),
430 FE(INTERNET_FLAG_HYPERLINK
),
431 FE(INTERNET_FLAG_NO_UI
),
432 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
433 FE(INTERNET_FLAG_CACHE_ASYNC
),
434 FE(INTERNET_FLAG_FORMS_SUBMIT
),
435 FE(INTERNET_FLAG_NEED_FILE
),
436 FE(INTERNET_FLAG_TRANSFER_ASCII
),
437 FE(INTERNET_FLAG_TRANSFER_BINARY
)
442 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
443 if (flag
[i
].val
& dwFlags
) {
444 TRACE(" %s", flag
[i
].name
);
445 dwFlags
&= ~flag
[i
].val
;
449 TRACE(" Unknown flags (%08x)\n", dwFlags
);
454 /***********************************************************************
455 * INTERNET_CloseHandle (internal)
457 * Close internet handle
460 static VOID
APPINFO_Destroy(WININETHANDLEHEADER
*hdr
)
462 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
466 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
467 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
468 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
469 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
470 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
471 HeapFree(GetProcessHeap(), 0, lpwai
);
474 static DWORD
APPINFO_QueryOption(WININETHANDLEHEADER
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
477 case INTERNET_OPTION_HANDLE_TYPE
:
478 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
480 if (*size
< sizeof(ULONG
))
481 return ERROR_INSUFFICIENT_BUFFER
;
483 *size
= sizeof(DWORD
);
484 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
485 return ERROR_SUCCESS
;
488 FIXME("Not implemented option %d\n", option
);
489 return ERROR_INTERNET_INVALID_OPTION
;
492 static const HANDLEHEADERVtbl APPINFOVtbl
= {
505 /***********************************************************************
506 * InternetOpenW (WININET.@)
508 * Per-application initialization of wininet
511 * HINTERNET on success
515 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
516 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
518 LPWININETAPPINFOW lpwai
= NULL
;
519 HINTERNET handle
= NULL
;
521 if (TRACE_ON(wininet
)) {
522 #define FE(x) { x, #x }
523 static const wininet_flag_info access_type
[] = {
524 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
525 FE(INTERNET_OPEN_TYPE_DIRECT
),
526 FE(INTERNET_OPEN_TYPE_PROXY
),
527 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
531 const char *access_type_str
= "Unknown";
533 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
534 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
535 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
536 if (access_type
[i
].val
== dwAccessType
) {
537 access_type_str
= access_type
[i
].name
;
541 TRACE(" access type : %s\n", access_type_str
);
543 dump_INTERNET_FLAGS(dwFlags
);
546 /* Clear any error information */
547 INTERNET_SetLastError(0);
549 lpwai
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETAPPINFOW
));
552 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
556 lpwai
->hdr
.htype
= WH_HINIT
;
557 lpwai
->hdr
.vtbl
= &APPINFOVtbl
;
558 lpwai
->hdr
.dwFlags
= dwFlags
;
560 lpwai
->dwAccessType
= dwAccessType
;
561 lpwai
->lpszProxyUsername
= NULL
;
562 lpwai
->lpszProxyPassword
= NULL
;
564 handle
= WININET_AllocHandle( &lpwai
->hdr
);
567 HeapFree( GetProcessHeap(), 0, lpwai
);
568 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
572 if (NULL
!= lpszAgent
)
574 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
575 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
576 if (lpwai
->lpszAgent
)
577 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
579 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
580 INTERNET_ConfigureProxyFromReg( lpwai
);
581 else if (NULL
!= lpszProxy
)
583 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
584 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
585 if (lpwai
->lpszProxy
)
586 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
589 if (NULL
!= lpszProxyBypass
)
591 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
592 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
593 if (lpwai
->lpszProxyBypass
)
594 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
599 WININET_Release( &lpwai
->hdr
);
601 TRACE("returning %p\n", lpwai
);
607 /***********************************************************************
608 * InternetOpenA (WININET.@)
610 * Per-application initialization of wininet
613 * HINTERNET on success
617 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
618 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
622 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
624 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
625 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
629 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
630 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
631 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
636 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
637 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
638 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
641 if( lpszProxyBypass
)
643 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
644 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
645 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
648 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
650 HeapFree(GetProcessHeap(), 0, szAgent
);
651 HeapFree(GetProcessHeap(), 0, szProxy
);
652 HeapFree(GetProcessHeap(), 0, szBypass
);
657 /***********************************************************************
658 * InternetGetLastResponseInfoA (WININET.@)
660 * Return last wininet error description on the calling thread
663 * TRUE on success of writing to buffer
667 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
668 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
670 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
676 *lpdwError
= lpwite
->dwError
;
679 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
680 *lpdwBufferLength
= strlen(lpszBuffer
);
683 *lpdwBufferLength
= 0;
688 *lpdwBufferLength
= 0;
694 /***********************************************************************
695 * InternetGetLastResponseInfoW (WININET.@)
697 * Return last wininet error description on the calling thread
700 * TRUE on success of writing to buffer
704 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
705 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
707 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
713 *lpdwError
= lpwite
->dwError
;
716 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
717 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
720 *lpdwBufferLength
= 0;
725 *lpdwBufferLength
= 0;
731 /***********************************************************************
732 * InternetGetConnectedState (WININET.@)
734 * Return connected state
738 * if lpdwStatus is not null, return the status (off line,
739 * modem, lan...) in it.
740 * FALSE if not connected
742 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
744 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
747 FIXME("always returning LAN connection.\n");
748 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
754 /***********************************************************************
755 * InternetGetConnectedStateExW (WININET.@)
757 * Return connected state
761 * lpdwStatus [O] Flags specifying the status of the internet connection.
762 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
763 * dwNameLen [I] Size of the buffer, in characters.
764 * dwReserved [I] Reserved. Must be set to 0.
768 * if lpdwStatus is not null, return the status (off line,
769 * modem, lan...) in it.
770 * FALSE if not connected
773 * If the system has no available network connections, an empty string is
774 * stored in lpszConnectionName. If there is a LAN connection, a localized
775 * "LAN Connection" string is stored. Presumably, if only a dial-up
776 * connection is available then the name of the dial-up connection is
777 * returned. Why any application, other than the "Internet Settings" CPL,
778 * would want to use this function instead of the simpler InternetGetConnectedStateW
779 * function is beyond me.
781 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
782 DWORD dwNameLen
, DWORD dwReserved
)
784 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
791 FIXME("always returning LAN connection.\n");
792 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
794 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
798 /***********************************************************************
799 * InternetGetConnectedStateExA (WININET.@)
801 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
802 DWORD dwNameLen
, DWORD dwReserved
)
804 LPWSTR lpwszConnectionName
= NULL
;
807 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
809 if (lpszConnectionName
&& dwNameLen
> 0)
810 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
812 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
814 if (rc
&& lpwszConnectionName
)
816 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
817 dwNameLen
, NULL
, NULL
);
819 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
826 /***********************************************************************
827 * InternetConnectW (WININET.@)
829 * Open a ftp, gopher or http session
832 * HINTERNET a session handle on success
836 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
837 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
838 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
839 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
841 LPWININETAPPINFOW hIC
;
844 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
845 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
846 dwService
, dwFlags
, dwContext
);
850 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
854 /* Clear any error information */
855 INTERNET_SetLastError(0);
856 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
857 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
859 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
865 case INTERNET_SERVICE_FTP
:
866 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
867 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
870 case INTERNET_SERVICE_HTTP
:
871 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
872 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
875 case INTERNET_SERVICE_GOPHER
:
881 WININET_Release( &hIC
->hdr
);
883 TRACE("returning %p\n", rc
);
888 /***********************************************************************
889 * InternetConnectA (WININET.@)
891 * Open a ftp, gopher or http session
894 * HINTERNET a session handle on success
898 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
899 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
900 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
901 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
905 LPWSTR szServerName
= NULL
;
906 LPWSTR szUserName
= NULL
;
907 LPWSTR szPassword
= NULL
;
911 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
912 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
913 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
917 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
918 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
919 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
923 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
924 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
925 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
929 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
930 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
932 HeapFree(GetProcessHeap(), 0, szServerName
);
933 HeapFree(GetProcessHeap(), 0, szUserName
);
934 HeapFree(GetProcessHeap(), 0, szPassword
);
939 /***********************************************************************
940 * InternetFindNextFileA (WININET.@)
942 * Continues a file search from a previous call to FindFirstFile
949 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
954 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
956 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
960 /***********************************************************************
961 * InternetFindNextFileW (WININET.@)
963 * Continues a file search from a previous call to FindFirstFile
970 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
972 WININETHANDLEHEADER
*hdr
;
977 hdr
= WININET_GetObject(hFind
);
979 WARN("Invalid handle\n");
980 SetLastError(ERROR_INVALID_HANDLE
);
984 if(hdr
->vtbl
->FindNextFileW
) {
985 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
987 WARN("Handle doesn't support NextFile\n");
988 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
991 WININET_Release(hdr
);
993 if(res
!= ERROR_SUCCESS
)
995 return res
== ERROR_SUCCESS
;
998 /***********************************************************************
999 * InternetCloseHandle (WININET.@)
1001 * Generic close handle function
1008 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1010 LPWININETHANDLEHEADER lpwh
;
1012 TRACE("%p\n",hInternet
);
1014 lpwh
= WININET_GetObject( hInternet
);
1017 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1021 WININET_Release( lpwh
);
1022 WININET_FreeHandle( hInternet
);
1028 /***********************************************************************
1029 * ConvertUrlComponentValue (Internal)
1031 * Helper function for InternetCrackUrlW
1034 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1035 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1036 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1038 TRACE("%p %d %p %d %p %p\n", lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1039 if (*dwComponentLen
!= 0)
1041 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1042 if (*lppszComponent
== NULL
)
1044 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1046 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1048 *lppszComponent
= NULL
;
1049 *dwComponentLen
= nASCIILength
;
1053 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1054 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1055 (*lppszComponent
)[ncpylen
]=0;
1056 *dwComponentLen
= ncpylen
;
1062 /***********************************************************************
1063 * InternetCrackUrlA (WININET.@)
1065 * See InternetCrackUrlW.
1067 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1068 LPURL_COMPONENTSA lpUrlComponents
)
1071 URL_COMPONENTSW UCW
;
1074 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl
), dwUrlLength
, dwFlags
, lpUrlComponents
);
1076 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1077 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1079 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1085 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1087 /* if dwUrlLength=-1 then nLength includes null but length to
1088 InternetCrackUrlW should not include it */
1089 if (dwUrlLength
== -1) nLength
--;
1091 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1092 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1094 memset(&UCW
,0,sizeof(UCW
));
1095 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1096 if(lpUrlComponents
->dwHostNameLength
!=0)
1097 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1098 if(lpUrlComponents
->dwUserNameLength
!=0)
1099 UCW
.dwUserNameLength
=lpUrlComponents
->dwUserNameLength
;
1100 if(lpUrlComponents
->dwPasswordLength
!=0)
1101 UCW
.dwPasswordLength
=lpUrlComponents
->dwPasswordLength
;
1102 if(lpUrlComponents
->dwUrlPathLength
!=0)
1103 UCW
.dwUrlPathLength
=lpUrlComponents
->dwUrlPathLength
;
1104 if(lpUrlComponents
->dwSchemeLength
!=0)
1105 UCW
.dwSchemeLength
=lpUrlComponents
->dwSchemeLength
;
1106 if(lpUrlComponents
->dwExtraInfoLength
!=0)
1107 UCW
.dwExtraInfoLength
=lpUrlComponents
->dwExtraInfoLength
;
1108 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
1110 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1114 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1115 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
1117 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1118 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
1120 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1121 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
1123 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1124 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
1126 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1127 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
1129 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1130 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
1132 lpUrlComponents
->nScheme
=UCW
.nScheme
;
1133 lpUrlComponents
->nPort
=UCW
.nPort
;
1134 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1136 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1137 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
1138 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
1139 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
1140 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
1145 static const WCHAR url_schemes
[][7] =
1148 {'g','o','p','h','e','r',0},
1149 {'h','t','t','p',0},
1150 {'h','t','t','p','s',0},
1151 {'f','i','l','e',0},
1152 {'n','e','w','s',0},
1153 {'m','a','i','l','t','o',0},
1157 /***********************************************************************
1158 * GetInternetSchemeW (internal)
1164 * INTERNET_SCHEME_UNKNOWN on failure
1167 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1171 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1173 if(lpszScheme
==NULL
)
1174 return INTERNET_SCHEME_UNKNOWN
;
1176 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1177 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1178 return INTERNET_SCHEME_FIRST
+ i
;
1180 return INTERNET_SCHEME_UNKNOWN
;
1183 /***********************************************************************
1184 * SetUrlComponentValueW (Internal)
1186 * Helper function for InternetCrackUrlW
1189 * lppszComponent [O] Holds the returned string
1190 * dwComponentLen [I] Holds the size of lppszComponent
1191 * [O] Holds the length of the string in lppszComponent without '\0'
1192 * lpszStart [I] Holds the string to copy from
1193 * len [I] Holds the length of lpszStart without '\0'
1200 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1202 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1204 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1207 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1209 if (*lppszComponent
== NULL
)
1211 *lppszComponent
= (LPWSTR
)lpszStart
;
1212 *dwComponentLen
= len
;
1216 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1217 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1218 (*lppszComponent
)[ncpylen
] = '\0';
1219 *dwComponentLen
= ncpylen
;
1226 /***********************************************************************
1227 * InternetCrackUrlW (WININET.@)
1229 * Break up URL into its components
1235 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1236 LPURL_COMPONENTSW lpUC
)
1240 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1243 LPCWSTR lpszParam
= NULL
;
1244 BOOL bIsAbsolute
= FALSE
;
1245 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1246 LPCWSTR lpszcp
= NULL
;
1247 LPWSTR lpszUrl_decode
= NULL
;
1248 DWORD dwUrlLength
= dwUrlLength_orig
;
1249 const WCHAR lpszSeparators
[3]={';','?',0};
1250 const WCHAR lpszSlash
[2]={'/',0};
1252 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl
), dwUrlLength
, dwFlags
, lpUC
);
1254 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1256 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1259 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1261 if (dwFlags
& ICU_DECODE
)
1263 lpszUrl_decode
=HeapAlloc( GetProcessHeap(), 0, dwUrlLength
* sizeof (WCHAR
) );
1264 if( InternetCanonicalizeUrlW(lpszUrl_orig
, lpszUrl_decode
, &dwUrlLength
, dwFlags
))
1266 lpszUrl
= lpszUrl_decode
;
1271 /* Determine if the URI is absolute. */
1272 while (*lpszap
!= '\0')
1274 if (isalnumW(*lpszap
))
1279 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1286 lpszcp
= lpszUrl
; /* Relative url */
1292 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1293 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1295 /* Parse <params> */
1296 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
1297 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1298 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1300 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1304 /* Get scheme first. */
1305 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1306 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1307 lpszUrl
, lpszcp
- lpszUrl
);
1309 /* Eat ':' in protocol. */
1312 /* double slash indicates the net_loc portion is present */
1313 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1317 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
1321 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1323 lpszNetLoc
= lpszParam
;
1325 else if (!lpszNetLoc
)
1326 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1334 /* [<user>[<:password>]@]<host>[:<port>] */
1335 /* First find the user and password if they exist */
1337 lpszHost
= strchrW(lpszcp
, '@');
1338 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1340 /* username and password not specified. */
1341 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1342 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1344 else /* Parse out username and password */
1346 LPCWSTR lpszUser
= lpszcp
;
1347 LPCWSTR lpszPasswd
= lpszHost
;
1349 while (lpszcp
< lpszHost
)
1352 lpszPasswd
= lpszcp
;
1357 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1358 lpszUser
, lpszPasswd
- lpszUser
);
1360 if (lpszPasswd
!= lpszHost
)
1362 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1363 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1364 lpszHost
- lpszPasswd
);
1366 lpszcp
++; /* Advance to beginning of host */
1369 /* Parse <host><:port> */
1372 lpszPort
= lpszNetLoc
;
1374 /* special case for res:// URLs: there is no port here, so the host is the
1375 entire string up to the first '/' */
1376 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1378 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1379 lpszHost
, lpszPort
- lpszHost
);
1384 while (lpszcp
< lpszNetLoc
)
1392 /* If the scheme is "file" and the host is just one letter, it's not a host */
1393 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1396 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1401 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1402 lpszHost
, lpszPort
- lpszHost
);
1403 if (lpszPort
!= lpszNetLoc
)
1404 lpUC
->nPort
= atoiW(++lpszPort
);
1405 else switch (lpUC
->nScheme
)
1407 case INTERNET_SCHEME_HTTP
:
1408 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1410 case INTERNET_SCHEME_HTTPS
:
1411 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1413 case INTERNET_SCHEME_FTP
:
1414 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1416 case INTERNET_SCHEME_GOPHER
:
1417 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1428 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1429 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1430 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1435 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1436 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1437 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1438 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1441 /* Here lpszcp points to:
1443 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1444 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1446 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1450 /* Only truncate the parameter list if it's already been saved
1451 * in lpUC->lpszExtraInfo.
1453 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1454 len
= lpszParam
- lpszcp
;
1457 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1458 * newlines if necessary.
1460 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1461 if (lpsznewline
!= NULL
)
1462 len
= lpsznewline
- lpszcp
;
1464 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1466 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1471 lpUC
->dwUrlPathLength
= 0;
1474 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1475 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1476 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1477 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1478 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1480 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1484 /***********************************************************************
1485 * InternetAttemptConnect (WININET.@)
1487 * Attempt to make a connection to the internet
1490 * ERROR_SUCCESS on success
1491 * Error value on failure
1494 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1497 return ERROR_SUCCESS
;
1501 /***********************************************************************
1502 * InternetCanonicalizeUrlA (WININET.@)
1504 * Escape unsafe characters and spaces
1511 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1512 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1515 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1517 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1518 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1520 if(dwFlags
& ICU_DECODE
)
1522 dwURLFlags
|= URL_UNESCAPE
;
1523 dwFlags
&= ~ICU_DECODE
;
1526 if(dwFlags
& ICU_ESCAPE
)
1528 dwURLFlags
|= URL_UNESCAPE
;
1529 dwFlags
&= ~ICU_ESCAPE
;
1532 if(dwFlags
& ICU_BROWSER_MODE
)
1534 dwURLFlags
|= URL_BROWSER_MODE
;
1535 dwFlags
&= ~ICU_BROWSER_MODE
;
1538 if(dwFlags
& ICU_NO_ENCODE
)
1540 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1541 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1542 dwFlags
&= ~ICU_NO_ENCODE
;
1545 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1547 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1548 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1549 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1551 return (hr
== S_OK
) ? TRUE
: FALSE
;
1554 /***********************************************************************
1555 * InternetCanonicalizeUrlW (WININET.@)
1557 * Escape unsafe characters and spaces
1564 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1565 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1568 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1570 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1571 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1573 if(dwFlags
& ICU_DECODE
)
1575 dwURLFlags
|= URL_UNESCAPE
;
1576 dwFlags
&= ~ICU_DECODE
;
1579 if(dwFlags
& ICU_ESCAPE
)
1581 dwURLFlags
|= URL_UNESCAPE
;
1582 dwFlags
&= ~ICU_ESCAPE
;
1585 if(dwFlags
& ICU_BROWSER_MODE
)
1587 dwURLFlags
|= URL_BROWSER_MODE
;
1588 dwFlags
&= ~ICU_BROWSER_MODE
;
1591 if(dwFlags
& ICU_NO_ENCODE
)
1593 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1594 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1595 dwFlags
&= ~ICU_NO_ENCODE
;
1598 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1600 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1601 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1602 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1604 return (hr
== S_OK
) ? TRUE
: FALSE
;
1607 /* #################################################### */
1609 static INTERNET_STATUS_CALLBACK
set_status_callback(
1610 LPWININETHANDLEHEADER lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
1612 INTERNET_STATUS_CALLBACK ret
;
1614 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1615 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1617 ret
= lpwh
->lpfnStatusCB
;
1618 lpwh
->lpfnStatusCB
= callback
;
1623 /***********************************************************************
1624 * InternetSetStatusCallbackA (WININET.@)
1626 * Sets up a callback function which is called as progress is made
1627 * during an operation.
1630 * Previous callback or NULL on success
1631 * INTERNET_INVALID_STATUS_CALLBACK on failure
1634 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1635 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1637 INTERNET_STATUS_CALLBACK retVal
;
1638 LPWININETHANDLEHEADER lpwh
;
1640 TRACE("0x%08x\n", (ULONG
)hInternet
);
1642 if (!(lpwh
= WININET_GetObject(hInternet
)))
1643 return INTERNET_INVALID_STATUS_CALLBACK
;
1645 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
1647 WININET_Release( lpwh
);
1651 /***********************************************************************
1652 * InternetSetStatusCallbackW (WININET.@)
1654 * Sets up a callback function which is called as progress is made
1655 * during an operation.
1658 * Previous callback or NULL on success
1659 * INTERNET_INVALID_STATUS_CALLBACK on failure
1662 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1663 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1665 INTERNET_STATUS_CALLBACK retVal
;
1666 LPWININETHANDLEHEADER lpwh
;
1668 TRACE("0x%08x\n", (ULONG
)hInternet
);
1670 if (!(lpwh
= WININET_GetObject(hInternet
)))
1671 return INTERNET_INVALID_STATUS_CALLBACK
;
1673 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
1675 WININET_Release( lpwh
);
1679 /***********************************************************************
1680 * InternetSetFilePointer (WININET.@)
1682 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1683 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
1689 /***********************************************************************
1690 * InternetWriteFile (WININET.@)
1692 * Write data to an open internet file
1699 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1700 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1702 LPWININETHANDLEHEADER lpwh
;
1703 BOOL retval
= FALSE
;
1705 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1707 lpwh
= WININET_GetObject( hFile
);
1709 if(lpwh
&& lpwh
->vtbl
->WriteFile
) {
1710 retval
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1712 WARN("Invalid handle\n");
1713 SetLastError(ERROR_INVALID_HANDLE
);
1717 WININET_Release( lpwh
);
1723 /***********************************************************************
1724 * InternetReadFile (WININET.@)
1726 * Read data from an open internet file
1733 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1734 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1736 LPWININETHANDLEHEADER hdr
;
1737 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1739 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1741 hdr
= WININET_GetObject(hFile
);
1743 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1747 if(hdr
->vtbl
->ReadFile
)
1748 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1750 WININET_Release(hdr
);
1752 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
1753 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1755 if(res
!= ERROR_SUCCESS
)
1757 return res
== ERROR_SUCCESS
;
1760 /***********************************************************************
1761 * InternetReadFileExA (WININET.@)
1763 * Read data from an open internet file
1766 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1767 * lpBuffersOut [I/O] Buffer.
1768 * dwFlags [I] Flags. See notes.
1769 * dwContext [I] Context for callbacks.
1776 * The parameter dwFlags include zero or more of the following flags:
1777 *|IRF_ASYNC - Makes the call asynchronous.
1778 *|IRF_SYNC - Makes the call synchronous.
1779 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1780 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1782 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1785 * InternetOpenUrlA(), HttpOpenRequestA()
1787 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1788 DWORD dwFlags
, DWORD_PTR dwContext
)
1790 LPWININETHANDLEHEADER hdr
;
1791 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1793 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1795 hdr
= WININET_GetObject(hFile
);
1797 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1801 if(hdr
->vtbl
->ReadFileExA
)
1802 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
1804 WININET_Release(hdr
);
1806 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
1807 res
, lpBuffersOut
->dwBufferLength
);
1809 if(res
!= ERROR_SUCCESS
)
1811 return res
== ERROR_SUCCESS
;
1814 /***********************************************************************
1815 * InternetReadFileExW (WININET.@)
1817 * Read data from an open internet file.
1820 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1821 * lpBuffersOut [I/O] Buffer.
1822 * dwFlags [I] Flags.
1823 * dwContext [I] Context for callbacks.
1826 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1829 * Not implemented in Wine or native either (as of IE6 SP2).
1832 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1833 DWORD dwFlags
, DWORD_PTR dwContext
)
1835 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
1837 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1841 /***********************************************************************
1842 * INET_QueryOptionHelper (internal)
1844 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1845 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1847 LPWININETHANDLEHEADER lpwhh
;
1848 BOOL bSuccess
= FALSE
;
1850 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1852 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
1856 case INTERNET_OPTION_REQUEST_FLAGS
:
1859 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags
);
1860 if (*lpdwBufferLength
< sizeof(ULONG
))
1861 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1864 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
1867 *lpdwBufferLength
= sizeof(ULONG
);
1871 case INTERNET_OPTION_USER_AGENT
:
1872 FIXME("INTERNET_OPTION_USER_AGENT\n");
1875 case INTERNET_OPTION_HTTP_VERSION
:
1877 if (*lpdwBufferLength
< sizeof(HTTP_VERSION_INFO
))
1878 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1882 * Presently hardcoded to 1.1
1884 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
1885 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
1888 *lpdwBufferLength
= sizeof(HTTP_VERSION_INFO
);
1891 case INTERNET_OPTION_CONNECTED_STATE
:
1893 DWORD
*pdwConnectedState
= (DWORD
*)lpBuffer
;
1894 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
1896 if (*lpdwBufferLength
< sizeof(*pdwConnectedState
))
1897 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1900 *pdwConnectedState
= INTERNET_STATE_CONNECTED
;
1903 *lpdwBufferLength
= sizeof(*pdwConnectedState
);
1906 case INTERNET_OPTION_PROXY
:
1908 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
)lpwhh
;
1909 WININETAPPINFOW wai
;
1913 TRACE("Getting global proxy info\n");
1914 memset(&wai
, 0, sizeof(WININETAPPINFOW
));
1915 INTERNET_ConfigureProxyFromReg( &wai
);
1921 INTERNET_PROXY_INFOW
*pPI
= (INTERNET_PROXY_INFOW
*)lpBuffer
;
1922 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
1924 if (lpwai
->lpszProxy
)
1925 proxyBytesRequired
= (lstrlenW(lpwai
->lpszProxy
) + 1) *
1927 if (lpwai
->lpszProxyBypass
)
1928 proxyBypassBytesRequired
=
1929 (lstrlenW(lpwai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
1930 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOW
) +
1931 proxyBytesRequired
+ proxyBypassBytesRequired
)
1932 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1935 LPWSTR proxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
1936 sizeof(INTERNET_PROXY_INFOW
));
1937 LPWSTR proxy_bypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
1938 sizeof(INTERNET_PROXY_INFOW
) +
1939 proxyBytesRequired
);
1941 pPI
->dwAccessType
= lpwai
->dwAccessType
;
1942 pPI
->lpszProxy
= NULL
;
1943 pPI
->lpszProxyBypass
= NULL
;
1944 if (lpwai
->lpszProxy
)
1946 lstrcpyW(proxy
, lpwai
->lpszProxy
);
1947 pPI
->lpszProxy
= proxy
;
1950 if (lpwai
->lpszProxyBypass
)
1952 lstrcpyW(proxy_bypass
, lpwai
->lpszProxyBypass
);
1953 pPI
->lpszProxyBypass
= proxy_bypass
;
1957 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOW
) +
1958 proxyBytesRequired
+ proxyBypassBytesRequired
;
1962 INTERNET_PROXY_INFOA
*pPI
= (INTERNET_PROXY_INFOA
*)lpBuffer
;
1963 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
1965 if (lpwai
->lpszProxy
)
1966 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
1967 lpwai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
1968 if (lpwai
->lpszProxyBypass
)
1969 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
1970 lpwai
->lpszProxyBypass
, -1, NULL
, 0, NULL
, NULL
);
1971 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOA
) +
1972 proxyBytesRequired
+ proxyBypassBytesRequired
)
1973 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1976 LPSTR proxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
1977 sizeof(INTERNET_PROXY_INFOA
));
1978 LPSTR proxy_bypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
1979 sizeof(INTERNET_PROXY_INFOA
) +
1980 proxyBytesRequired
);
1982 pPI
->dwAccessType
= lpwai
->dwAccessType
;
1983 pPI
->lpszProxy
= NULL
;
1984 pPI
->lpszProxyBypass
= NULL
;
1985 if (lpwai
->lpszProxy
)
1987 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxy
, -1,
1988 proxy
, proxyBytesRequired
, NULL
, NULL
);
1989 pPI
->lpszProxy
= proxy
;
1992 if (lpwai
->lpszProxyBypass
)
1994 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxyBypass
,
1995 -1, proxy_bypass
, proxyBypassBytesRequired
,
1997 pPI
->lpszProxyBypass
= proxy_bypass
;
2001 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOA
) +
2002 proxyBytesRequired
+ proxyBypassBytesRequired
;
2006 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2009 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn
);
2010 if (*lpdwBufferLength
< sizeof(ULONG
))
2011 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2014 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2017 *lpdwBufferLength
= sizeof(ULONG
);
2020 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2023 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn
);
2024 if (*lpdwBufferLength
< sizeof(ULONG
))
2025 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2028 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2031 *lpdwBufferLength
= sizeof(ULONG
);
2034 case INTERNET_OPTION_SECURITY_FLAGS
:
2035 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2039 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
:
2042 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2045 if (*lpdwBufferLength
< sizeof(INTERNET_CERTIFICATE_INFOW
))
2047 *lpdwBufferLength
= sizeof(INTERNET_CERTIFICATE_INFOW
);
2048 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2050 else if (lpwhh
->htype
== WH_HHTTPREQ
)
2052 LPWININETHTTPREQW lpwhr
;
2053 PCCERT_CONTEXT context
;
2055 lpwhr
= (LPWININETHTTPREQW
)lpwhh
;
2056 context
= (PCCERT_CONTEXT
)NETCON_GetCert(&(lpwhr
->netConnection
));
2059 LPINTERNET_CERTIFICATE_INFOW info
= (LPINTERNET_CERTIFICATE_INFOW
)lpBuffer
;
2062 memset(info
,0,sizeof(INTERNET_CERTIFICATE_INFOW
));
2063 info
->ftExpiry
= context
->pCertInfo
->NotAfter
;
2064 info
->ftStart
= context
->pCertInfo
->NotBefore
;
2067 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2068 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2070 info
->lpszSubjectInfo
= LocalAlloc(0,
2071 strLen
* sizeof(WCHAR
));
2072 if (info
->lpszSubjectInfo
)
2073 CertNameToStrW(context
->dwCertEncodingType
,
2074 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2075 info
->lpszSubjectInfo
, strLen
);
2076 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2077 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2079 info
->lpszIssuerInfo
= LocalAlloc(0,
2080 strLen
* sizeof(WCHAR
));
2081 if (info
->lpszIssuerInfo
)
2082 CertNameToStrW(context
->dwCertEncodingType
,
2083 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2084 info
->lpszIssuerInfo
, strLen
);
2088 LPINTERNET_CERTIFICATE_INFOA infoA
=
2089 (LPINTERNET_CERTIFICATE_INFOA
)info
;
2091 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2092 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2094 infoA
->lpszSubjectInfo
= LocalAlloc(0, strLen
);
2095 if (infoA
->lpszSubjectInfo
)
2096 CertNameToStrA(context
->dwCertEncodingType
,
2097 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2098 infoA
->lpszSubjectInfo
, strLen
);
2099 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2100 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2102 infoA
->lpszIssuerInfo
= LocalAlloc(0, strLen
);
2103 if (infoA
->lpszIssuerInfo
)
2104 CertNameToStrA(context
->dwCertEncodingType
,
2105 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2106 infoA
->lpszIssuerInfo
, strLen
);
2109 * Contrary to MSDN, these do not appear to be set.
2111 * lpszSignatureAlgName
2112 * lpszEncryptionAlgName
2115 CertFreeCertificateContext(context
);
2120 case INTERNET_OPTION_VERSION
:
2122 TRACE("INTERNET_OPTION_VERSION\n");
2123 if (*lpdwBufferLength
< sizeof(INTERNET_VERSION_INFO
))
2124 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2127 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2128 memcpy(lpBuffer
, &info
, sizeof(info
));
2129 *lpdwBufferLength
= sizeof(info
);
2134 case INTERNET_OPTION_PER_CONNECTION_OPTION
:
2135 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2136 if (*lpdwBufferLength
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
))
2137 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2140 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2143 for (x
= 0; x
< con
->dwOptionCount
; ++x
)
2145 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ x
;
2146 switch (option
->dwOption
)
2148 case INTERNET_PER_CONN_FLAGS
:
2149 option
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2152 case INTERNET_PER_CONN_PROXY_SERVER
:
2153 case INTERNET_PER_CONN_PROXY_BYPASS
:
2154 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2155 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2156 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2157 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2158 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2159 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2160 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2161 option
->Value
.dwValue
= 0;
2166 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2172 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2183 res
= lpwhh
->vtbl
->QueryOption(lpwhh
, dwOption
, lpBuffer
, lpdwBufferLength
, bIsUnicode
);
2184 if(res
== ERROR_SUCCESS
)
2189 FIXME("Stub! %d\n", dwOption
);
2195 WININET_Release( lpwhh
);
2200 /***********************************************************************
2201 * InternetQueryOptionW (WININET.@)
2203 * Queries an options on the specified handle
2210 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2211 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2213 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2216 /***********************************************************************
2217 * InternetQueryOptionA (WININET.@)
2219 * Queries an options on the specified handle
2226 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2227 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2229 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2233 /***********************************************************************
2234 * InternetSetOptionW (WININET.@)
2236 * Sets an options on the specified handle
2243 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2244 LPVOID lpBuffer
, DWORD dwBufferLength
)
2246 LPWININETHANDLEHEADER lpwhh
;
2249 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2251 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2252 if(lpwhh
&& lpwhh
->vtbl
->SetOption
) {
2255 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2256 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2257 WININET_Release( lpwhh
);
2259 if(res
!= ERROR_SUCCESS
)
2262 return res
== ERROR_SUCCESS
;
2268 case INTERNET_OPTION_CALLBACK
:
2270 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2271 ret
= (set_status_callback(lpwhh
, callback
, TRUE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2274 case INTERNET_OPTION_HTTP_VERSION
:
2276 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2277 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2280 case INTERNET_OPTION_ERROR_MASK
:
2282 unsigned long flags
=*(unsigned long*)lpBuffer
;
2283 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
2286 case INTERNET_OPTION_CODEPAGE
:
2288 unsigned long codepage
=*(unsigned long*)lpBuffer
;
2289 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
2292 case INTERNET_OPTION_REQUEST_PRIORITY
:
2294 unsigned long priority
=*(unsigned long*)lpBuffer
;
2295 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
2298 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2300 unsigned long connecttimeout
=*(unsigned long*)lpBuffer
;
2301 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout
);
2304 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2306 unsigned long receivetimeout
=*(unsigned long*)lpBuffer
;
2307 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout
);
2310 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2312 unsigned long conns
=*(unsigned long*)lpBuffer
;
2313 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns
);
2316 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2318 unsigned long conns
=*(unsigned long*)lpBuffer
;
2319 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns
);
2322 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2323 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2325 case INTERNET_OPTION_END_BROWSER_SESSION
:
2326 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2328 case INTERNET_OPTION_CONNECTED_STATE
:
2329 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2331 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2332 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2334 case INTERNET_OPTION_SEND_TIMEOUT
:
2335 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2336 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2338 case INTERNET_OPTION_CONNECT_RETRIES
:
2339 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2341 case INTERNET_OPTION_CONTEXT_VALUE
:
2342 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2344 case INTERNET_OPTION_SECURITY_FLAGS
:
2345 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2351 FIXME("Option %d STUB\n",dwOption
);
2352 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2358 WININET_Release( lpwhh
);
2364 /***********************************************************************
2365 * InternetSetOptionA (WININET.@)
2367 * Sets an options on the specified handle.
2374 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2375 LPVOID lpBuffer
, DWORD dwBufferLength
)
2383 case INTERNET_OPTION_CALLBACK
:
2385 LPWININETHANDLEHEADER lpwh
;
2386 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2388 if (!(lpwh
= WININET_GetObject(hInternet
))) return FALSE
;
2389 r
= (set_status_callback(lpwh
, callback
, FALSE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2390 WININET_Release(lpwh
);
2393 case INTERNET_OPTION_PROXY
:
2395 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2396 LPINTERNET_PROXY_INFOW piw
;
2397 DWORD proxlen
, prbylen
;
2400 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2401 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2402 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2403 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2404 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2405 piw
->dwAccessType
= pi
->dwAccessType
;
2406 prox
= (LPWSTR
) &piw
[1];
2407 prby
= &prox
[proxlen
+1];
2408 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2409 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2410 piw
->lpszProxy
= prox
;
2411 piw
->lpszProxyBypass
= prby
;
2414 case INTERNET_OPTION_USER_AGENT
:
2415 case INTERNET_OPTION_USERNAME
:
2416 case INTERNET_OPTION_PASSWORD
:
2417 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2419 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2420 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2425 wlen
= dwBufferLength
;
2428 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2430 if( lpBuffer
!= wbuffer
)
2431 HeapFree( GetProcessHeap(), 0, wbuffer
);
2437 /***********************************************************************
2438 * InternetSetOptionExA (WININET.@)
2440 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2441 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2443 FIXME("Flags %08x ignored\n", dwFlags
);
2444 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2447 /***********************************************************************
2448 * InternetSetOptionExW (WININET.@)
2450 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2451 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2453 FIXME("Flags %08x ignored\n", dwFlags
);
2454 if( dwFlags
& ~ISO_VALID_FLAGS
)
2456 INTERNET_SetLastError( ERROR_INVALID_PARAMETER
);
2459 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2462 static const WCHAR WININET_wkday
[7][4] =
2463 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2464 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2465 static const WCHAR WININET_month
[12][4] =
2466 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2467 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2468 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2470 /***********************************************************************
2471 * InternetTimeFromSystemTimeA (WININET.@)
2473 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2476 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2478 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2480 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2481 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2486 /***********************************************************************
2487 * InternetTimeFromSystemTimeW (WININET.@)
2489 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2491 static const WCHAR date
[] =
2492 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2493 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2495 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2497 if (!time
|| !string
) return FALSE
;
2499 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2502 sprintfW( string
, date
,
2503 WININET_wkday
[time
->wDayOfWeek
],
2505 WININET_month
[time
->wMonth
- 1],
2514 /***********************************************************************
2515 * InternetTimeToSystemTimeA (WININET.@)
2517 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2523 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
2525 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2526 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2530 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2531 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2532 HeapFree( GetProcessHeap(), 0, stringW
);
2537 /***********************************************************************
2538 * InternetTimeToSystemTimeW (WININET.@)
2540 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2543 const WCHAR
*s
= string
;
2546 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
2548 if (!string
|| !time
) return FALSE
;
2550 /* Windows does this too */
2551 GetSystemTime( time
);
2553 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2554 * a SYSTEMTIME structure.
2557 while (*s
&& !isalphaW( *s
)) s
++;
2558 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2559 time
->wDayOfWeek
= 7;
2561 for (i
= 0; i
< 7; i
++)
2563 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2564 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2565 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2567 time
->wDayOfWeek
= i
;
2572 if (time
->wDayOfWeek
> 6) return TRUE
;
2573 while (*s
&& !isdigitW( *s
)) s
++;
2574 time
->wDay
= strtolW( s
, &end
, 10 );
2577 while (*s
&& !isalphaW( *s
)) s
++;
2578 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2581 for (i
= 0; i
< 12; i
++)
2583 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2584 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2585 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2587 time
->wMonth
= i
+ 1;
2591 if (time
->wMonth
== 0) return TRUE
;
2593 while (*s
&& !isdigitW( *s
)) s
++;
2594 if (*s
== '\0') return TRUE
;
2595 time
->wYear
= strtolW( s
, &end
, 10 );
2598 while (*s
&& !isdigitW( *s
)) s
++;
2599 if (*s
== '\0') return TRUE
;
2600 time
->wHour
= strtolW( s
, &end
, 10 );
2603 while (*s
&& !isdigitW( *s
)) s
++;
2604 if (*s
== '\0') return TRUE
;
2605 time
->wMinute
= strtolW( s
, &end
, 10 );
2608 while (*s
&& !isdigitW( *s
)) s
++;
2609 if (*s
== '\0') return TRUE
;
2610 time
->wSecond
= strtolW( s
, &end
, 10 );
2613 time
->wMilliseconds
= 0;
2617 /***********************************************************************
2618 * InternetCheckConnectionW (WININET.@)
2620 * Pings a requested host to check internet connection
2623 * TRUE on success and FALSE on failure. If a failure then
2624 * ERROR_NOT_CONNECTED is placed into GetLastError
2627 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2630 * this is a kludge which runs the resident ping program and reads the output.
2632 * Anyone have a better idea?
2636 static const CHAR ping
[] = "ping -c 1 ";
2637 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2638 CHAR
*command
= NULL
;
2647 * Crack or set the Address
2649 if (lpszUrl
== NULL
)
2652 * According to the doc we are supposed to use the ip for the next
2653 * server in the WnInet internal server database. I have
2654 * no idea what that is or how to get it.
2656 * So someone needs to implement this.
2658 FIXME("Unimplemented with URL of NULL\n");
2663 URL_COMPONENTSW components
;
2665 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2666 components
.lpszHostName
= (LPWSTR
)&hostW
;
2667 components
.dwHostNameLength
= 1024;
2669 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2672 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2673 port
= components
.nPort
;
2674 TRACE("port: %d\n", port
);
2677 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
2679 struct sockaddr_in sin
;
2682 if (!GetAddress(hostW
, port
, &sin
))
2684 fd
= socket(sin
.sin_family
, SOCK_STREAM
, 0);
2687 if (connect(fd
, (struct sockaddr
*)&sin
, sizeof(sin
)) == 0)
2695 * Build our ping command
2697 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2698 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2699 strcpy(command
,ping
);
2700 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2701 strcat(command
,redirect
);
2703 TRACE("Ping command is : %s\n",command
);
2705 status
= system(command
);
2707 TRACE("Ping returned a code of %i\n",status
);
2709 /* Ping return code of 0 indicates success */
2716 HeapFree( GetProcessHeap(), 0, command
);
2718 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
2724 /***********************************************************************
2725 * InternetCheckConnectionA (WININET.@)
2727 * Pings a requested host to check internet connection
2730 * TRUE on success and FALSE on failure. If a failure then
2731 * ERROR_NOT_CONNECTED is placed into GetLastError
2734 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2740 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2741 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2743 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2744 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2745 HeapFree(GetProcessHeap(), 0, szUrl
);
2751 /**********************************************************
2752 * INTERNET_InternetOpenUrlW (internal)
2757 * handle of connection or NULL on failure
2759 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2760 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2762 URL_COMPONENTSW urlComponents
;
2763 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2764 WCHAR password
[1024], path
[2048], extra
[1024];
2765 HINTERNET client
= NULL
, client1
= NULL
;
2767 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2768 dwHeadersLength
, dwFlags
, dwContext
);
2770 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2771 urlComponents
.lpszScheme
= protocol
;
2772 urlComponents
.dwSchemeLength
= 32;
2773 urlComponents
.lpszHostName
= hostName
;
2774 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2775 urlComponents
.lpszUserName
= userName
;
2776 urlComponents
.dwUserNameLength
= 1024;
2777 urlComponents
.lpszPassword
= password
;
2778 urlComponents
.dwPasswordLength
= 1024;
2779 urlComponents
.lpszUrlPath
= path
;
2780 urlComponents
.dwUrlPathLength
= 2048;
2781 urlComponents
.lpszExtraInfo
= extra
;
2782 urlComponents
.dwExtraInfoLength
= 1024;
2783 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2785 switch(urlComponents
.nScheme
) {
2786 case INTERNET_SCHEME_FTP
:
2787 if(urlComponents
.nPort
== 0)
2788 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2789 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2790 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2793 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2794 if(client1
== NULL
) {
2795 InternetCloseHandle(client
);
2800 case INTERNET_SCHEME_HTTP
:
2801 case INTERNET_SCHEME_HTTPS
: {
2802 static const WCHAR szStars
[] = { '*','/','*', 0 };
2803 LPCWSTR accept
[2] = { szStars
, NULL
};
2804 if(urlComponents
.nPort
== 0) {
2805 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2806 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2808 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2810 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2811 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2812 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2816 if (urlComponents
.dwExtraInfoLength
) {
2818 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
2820 if (!(path_extra
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
2822 InternetCloseHandle(client
);
2825 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
2826 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
2827 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2828 HeapFree(GetProcessHeap(), 0, path_extra
);
2831 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2833 if(client1
== NULL
) {
2834 InternetCloseHandle(client
);
2837 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2838 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
2839 GetLastError() != ERROR_IO_PENDING
) {
2840 InternetCloseHandle(client1
);
2845 case INTERNET_SCHEME_GOPHER
:
2846 /* gopher doesn't seem to be implemented in wine, but it's supposed
2847 * to be supported by InternetOpenUrlA. */
2849 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
2853 TRACE(" %p <--\n", client1
);
2858 /**********************************************************
2859 * InternetOpenUrlW (WININET.@)
2864 * handle of connection or NULL on failure
2866 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
2868 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
2869 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
->hdr
;
2873 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
2874 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
2875 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
2876 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
2879 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
2880 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2882 HINTERNET ret
= NULL
;
2883 LPWININETAPPINFOW hIC
= NULL
;
2885 if (TRACE_ON(wininet
)) {
2886 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2887 dwHeadersLength
, dwFlags
, dwContext
);
2889 dump_INTERNET_FLAGS(dwFlags
);
2894 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2898 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
2899 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
2900 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2904 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
2905 WORKREQUEST workRequest
;
2906 struct WORKREQ_INTERNETOPENURLW
*req
;
2908 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
2909 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
2910 req
= &workRequest
.u
.InternetOpenUrlW
;
2911 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
2913 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
2915 req
->lpszHeaders
= 0;
2916 req
->dwHeadersLength
= dwHeadersLength
;
2917 req
->dwFlags
= dwFlags
;
2918 req
->dwContext
= dwContext
;
2920 INTERNET_AsyncCall(&workRequest
);
2922 * This is from windows.
2924 INTERNET_SetLastError(ERROR_IO_PENDING
);
2926 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
2931 WININET_Release( &hIC
->hdr
);
2932 TRACE(" %p <--\n", ret
);
2937 /**********************************************************
2938 * InternetOpenUrlA (WININET.@)
2943 * handle of connection or NULL on failure
2945 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
2946 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2948 HINTERNET rc
= NULL
;
2952 LPWSTR szUrl
= NULL
;
2953 LPWSTR szHeaders
= NULL
;
2958 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
2959 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
2962 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
2966 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
2967 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
2969 HeapFree(GetProcessHeap(), 0, szUrl
);
2972 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
2975 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
2976 lenHeaders
, dwFlags
, dwContext
);
2978 HeapFree(GetProcessHeap(), 0, szUrl
);
2979 HeapFree(GetProcessHeap(), 0, szHeaders
);
2985 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
2987 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite
));
2991 lpwite
->dwError
= 0;
2992 lpwite
->response
[0] = '\0';
2995 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
2997 HeapFree(GetProcessHeap(), 0, lpwite
);
3005 /***********************************************************************
3006 * INTERNET_SetLastError (internal)
3008 * Set last thread specific error
3013 void INTERNET_SetLastError(DWORD dwError
)
3015 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3018 lpwite
= INTERNET_AllocThreadError();
3020 SetLastError(dwError
);
3022 lpwite
->dwError
= dwError
;
3026 /***********************************************************************
3027 * INTERNET_GetLastError (internal)
3029 * Get last thread specific error
3034 DWORD
INTERNET_GetLastError(void)
3036 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3037 if (!lpwite
) return 0;
3038 /* TlsGetValue clears last error, so set it again here */
3039 SetLastError(lpwite
->dwError
);
3040 return lpwite
->dwError
;
3044 /***********************************************************************
3045 * INTERNET_WorkerThreadFunc (internal)
3047 * Worker thread execution function
3052 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3054 LPWORKREQUEST lpRequest
= lpvParam
;
3055 WORKREQUEST workRequest
;
3059 memcpy(&workRequest
, lpRequest
, sizeof(WORKREQUEST
));
3060 HeapFree(GetProcessHeap(), 0, lpRequest
);
3062 workRequest
.asyncproc(&workRequest
);
3064 WININET_Release( workRequest
.hdr
);
3069 /***********************************************************************
3070 * INTERNET_AsyncCall (internal)
3072 * Retrieves work request from queue
3077 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3080 LPWORKREQUEST lpNewRequest
;
3084 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3088 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
3090 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3093 HeapFree(GetProcessHeap(), 0, lpNewRequest
);
3094 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3101 /***********************************************************************
3102 * INTERNET_GetResponseBuffer (internal)
3107 LPSTR
INTERNET_GetResponseBuffer(void)
3109 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3111 lpwite
= INTERNET_AllocThreadError();
3113 return lpwite
->response
;
3116 /***********************************************************************
3117 * INTERNET_GetNextLine (internal)
3119 * Parse next line in directory string listing
3122 * Pointer to beginning of next line
3127 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3131 BOOL bSuccess
= FALSE
;
3133 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3138 FD_SET(nSocket
, &infd
);
3139 tv
.tv_sec
=RESPONSE_TIMEOUT
;
3142 while (nRecv
< MAX_REPLY_LEN
)
3144 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
3146 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3148 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3152 if (lpszBuffer
[nRecv
] == '\n')
3157 if (lpszBuffer
[nRecv
] != '\r')
3162 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3170 lpszBuffer
[nRecv
] = '\0';
3172 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3181 /**********************************************************
3182 * InternetQueryDataAvailable (WININET.@)
3184 * Determines how much data is available to be read.
3187 * TRUE on success, FALSE if an error occurred. If
3188 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3189 * no data is presently available, FALSE is returned with
3190 * the last error ERROR_IO_PENDING; a callback with status
3191 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3192 * data is available.
3194 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3195 LPDWORD lpdwNumberOfBytesAvailble
,
3196 DWORD dwFlags
, DWORD_PTR dwContext
)
3198 WININETHANDLEHEADER
*hdr
;
3201 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3203 hdr
= WININET_GetObject( hFile
);
3205 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
3209 if(hdr
->vtbl
->QueryDataAvailable
) {
3210 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3212 WARN("wrong handle\n");
3213 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3216 WININET_Release(hdr
);
3218 if(res
!= ERROR_SUCCESS
)
3220 return res
== ERROR_SUCCESS
;
3224 /***********************************************************************
3225 * InternetLockRequestFile (WININET.@)
3227 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3234 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3241 /***********************************************************************
3242 * InternetAutodial (WININET.@)
3244 * On windows this function is supposed to dial the default internet
3245 * connection. We don't want to have Wine dial out to the internet so
3246 * we return TRUE by default. It might be nice to check if we are connected.
3253 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3257 /* Tell that we are connected to the internet. */
3261 /***********************************************************************
3262 * InternetAutodialHangup (WININET.@)
3264 * Hangs up a connection made with InternetAutodial
3273 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3277 /* we didn't dial, we don't disconnect */
3281 /***********************************************************************
3282 * InternetCombineUrlA (WININET.@)
3284 * Combine a base URL with a relative URL
3292 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3293 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3298 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3300 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3301 dwFlags
^= ICU_NO_ENCODE
;
3302 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3307 /***********************************************************************
3308 * InternetCombineUrlW (WININET.@)
3310 * Combine a base URL with a relative URL
3318 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3319 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3324 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3326 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3327 dwFlags
^= ICU_NO_ENCODE
;
3328 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3333 /* max port num is 65535 => 5 digits */
3334 #define MAX_WORD_DIGITS 5
3336 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3337 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3338 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3339 (url)->dw##component##Length : strlen((url)->lpsz##component))
3341 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3343 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3344 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3346 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3347 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3349 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3350 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3352 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3353 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3356 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3362 /* opaque urls do not fit into the standard url hierarchy and don't have
3363 * two following slashes */
3364 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3366 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3367 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3368 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3369 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3370 (nScheme
!= INTERNET_SCHEME_FILE
);
3373 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3376 if (scheme
< INTERNET_SCHEME_FIRST
)
3378 index
= scheme
- INTERNET_SCHEME_FIRST
;
3379 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3381 return (LPCWSTR
)&url_schemes
[index
];
3384 /* we can calculate using ansi strings because we're just
3385 * calculating string length, not size
3387 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3388 LPDWORD lpdwUrlLength
)
3390 INTERNET_SCHEME nScheme
;
3394 if (lpUrlComponents
->lpszScheme
)
3396 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3397 *lpdwUrlLength
+= dwLen
;
3398 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3404 nScheme
= lpUrlComponents
->nScheme
;
3406 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3407 nScheme
= INTERNET_SCHEME_HTTP
;
3408 scheme
= INTERNET_GetSchemeString(nScheme
);
3409 *lpdwUrlLength
+= strlenW(scheme
);
3412 (*lpdwUrlLength
)++; /* ':' */
3413 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3414 *lpdwUrlLength
+= strlen("//");
3416 if (lpUrlComponents
->lpszUserName
)
3418 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3419 *lpdwUrlLength
+= strlen("@");
3423 if (lpUrlComponents
->lpszPassword
)
3425 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3430 if (lpUrlComponents
->lpszPassword
)
3432 *lpdwUrlLength
+= strlen(":");
3433 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3436 if (lpUrlComponents
->lpszHostName
)
3438 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3440 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3442 char szPort
[MAX_WORD_DIGITS
+1];
3444 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3445 *lpdwUrlLength
+= strlen(szPort
);
3446 *lpdwUrlLength
+= strlen(":");
3449 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3450 (*lpdwUrlLength
)++; /* '/' */
3453 if (lpUrlComponents
->lpszUrlPath
)
3454 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3459 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3463 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3465 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3466 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3467 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3468 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3469 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3470 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3471 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3472 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3473 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3475 if (lpUrlComponents
->lpszScheme
)
3477 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
3478 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3479 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3480 -1, urlCompW
->lpszScheme
, len
);
3483 if (lpUrlComponents
->lpszHostName
)
3485 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
3486 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3487 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3488 -1, urlCompW
->lpszHostName
, len
);
3491 if (lpUrlComponents
->lpszUserName
)
3493 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
3494 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3495 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3496 -1, urlCompW
->lpszUserName
, len
);
3499 if (lpUrlComponents
->lpszPassword
)
3501 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
3502 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3503 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3504 -1, urlCompW
->lpszPassword
, len
);
3507 if (lpUrlComponents
->lpszUrlPath
)
3509 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
3510 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3511 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3512 -1, urlCompW
->lpszUrlPath
, len
);
3515 if (lpUrlComponents
->lpszExtraInfo
)
3517 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
3518 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3519 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3520 -1, urlCompW
->lpszExtraInfo
, len
);
3524 /***********************************************************************
3525 * InternetCreateUrlA (WININET.@)
3527 * See InternetCreateUrlW.
3529 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3530 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3534 URL_COMPONENTSW urlCompW
;
3536 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3538 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3540 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3544 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3547 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3549 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3551 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3552 *lpdwUrlLength
/= sizeof(WCHAR
);
3554 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3555 * minus one, so add one to leave room for NULL terminator
3558 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3560 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3561 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3562 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3563 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3564 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3565 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3566 HeapFree(GetProcessHeap(), 0, urlW
);
3571 /***********************************************************************
3572 * InternetCreateUrlW (WININET.@)
3574 * Creates a URL from its component parts.
3577 * lpUrlComponents [I] URL Components.
3578 * dwFlags [I] Flags. See notes.
3579 * lpszUrl [I] Buffer in which to store the created URL.
3580 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3581 * lpszUrl in characters. On output, the number of bytes
3582 * required to store the URL including terminator.
3586 * The dwFlags parameter can be zero or more of the following:
3587 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3594 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3595 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3598 INTERNET_SCHEME nScheme
;
3600 static const WCHAR slashSlashW
[] = {'/','/'};
3601 static const WCHAR percentD
[] = {'%','d',0};
3603 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3605 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3607 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3611 if (!calc_url_length(lpUrlComponents
, &dwLen
))
3614 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3616 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
3617 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3621 *lpdwUrlLength
= dwLen
;
3626 if (lpUrlComponents
->lpszScheme
)
3628 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3629 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
3632 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3637 nScheme
= lpUrlComponents
->nScheme
;
3639 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3640 nScheme
= INTERNET_SCHEME_HTTP
;
3642 scheme
= INTERNET_GetSchemeString(nScheme
);
3643 dwLen
= strlenW(scheme
);
3644 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
3648 /* all schemes are followed by at least a colon */
3652 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3654 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
3655 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
3658 if (lpUrlComponents
->lpszUserName
)
3660 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3661 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
3664 if (lpUrlComponents
->lpszPassword
)
3669 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3670 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
3678 if (lpUrlComponents
->lpszHostName
)
3680 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3681 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
3684 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3686 WCHAR szPort
[MAX_WORD_DIGITS
+1];
3688 sprintfW(szPort
, percentD
, lpUrlComponents
->nPort
);
3691 dwLen
= strlenW(szPort
);
3692 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
3696 /* add slash between hostname and path if necessary */
3697 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3705 if (lpUrlComponents
->lpszUrlPath
)
3707 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3708 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
3717 /***********************************************************************
3718 * InternetConfirmZoneCrossingA (WININET.@)
3721 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
3723 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
3724 return ERROR_SUCCESS
;
3727 /***********************************************************************
3728 * InternetConfirmZoneCrossingW (WININET.@)
3731 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
3733 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
3734 return ERROR_SUCCESS
;
3737 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
3738 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3740 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3741 lpdwConnection
, dwReserved
);
3742 return ERROR_SUCCESS
;
3745 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
3746 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3748 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3749 lpdwConnection
, dwReserved
);
3750 return ERROR_SUCCESS
;
3753 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3755 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
3759 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3761 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
3765 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
3767 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
3768 return ERROR_SUCCESS
;
3771 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
3774 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
3775 debugstr_w(pwszTarget
), pbHexHash
);
3779 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
3781 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
3785 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
3787 FIXME("(%p, %08lx) stub\n", a
, b
);