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>
44 #ifdef HAVE_SYS_POLL_H
45 # include <sys/poll.h>
47 #ifdef HAVE_SYS_TIME_H
48 # include <sys/time.h>
64 #include "wine/debug.h"
66 #define NO_SHLWAPI_STREAM
69 #include "wine/exception.h"
74 #include "wine/unicode.h"
76 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
78 #define RESPONSE_TIMEOUT 30
83 CHAR response
[MAX_REPLY_LEN
];
84 } WITHREADERROR
, *LPWITHREADERROR
;
86 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
87 static HMODULE WININET_hModule
;
89 #define HANDLE_CHUNK_SIZE 0x10
91 static CRITICAL_SECTION WININET_cs
;
92 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
95 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
96 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
98 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
100 static LPWININETHANDLEHEADER
*WININET_Handles
;
101 static UINT WININET_dwNextHandle
;
102 static UINT WININET_dwMaxHandles
;
104 HINTERNET
WININET_AllocHandle( LPWININETHANDLEHEADER info
)
106 LPWININETHANDLEHEADER
*p
;
107 UINT handle
= 0, num
;
109 list_init( &info
->children
);
111 EnterCriticalSection( &WININET_cs
);
112 if( !WININET_dwMaxHandles
)
114 num
= HANDLE_CHUNK_SIZE
;
115 p
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
120 WININET_dwMaxHandles
= num
;
122 if( WININET_dwMaxHandles
== WININET_dwNextHandle
)
124 num
= WININET_dwMaxHandles
+ HANDLE_CHUNK_SIZE
;
125 p
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
126 WININET_Handles
, sizeof (UINT
)* num
);
130 WININET_dwMaxHandles
= num
;
133 handle
= WININET_dwNextHandle
;
134 if( WININET_Handles
[handle
] )
135 ERR("handle isn't free but should be\n");
136 WININET_Handles
[handle
] = WININET_AddRef( info
);
138 while( WININET_Handles
[WININET_dwNextHandle
] &&
139 (WININET_dwNextHandle
< WININET_dwMaxHandles
) )
140 WININET_dwNextHandle
++;
143 LeaveCriticalSection( &WININET_cs
);
145 return info
->hInternet
= (HINTERNET
) (handle
+1);
148 LPWININETHANDLEHEADER
WININET_AddRef( LPWININETHANDLEHEADER info
)
150 ULONG refs
= InterlockedIncrement(&info
->refs
);
151 TRACE("%p -> refcount = %d\n", info
, refs
);
155 LPWININETHANDLEHEADER
WININET_GetObject( HINTERNET hinternet
)
157 LPWININETHANDLEHEADER info
= NULL
;
158 UINT handle
= (UINT
) hinternet
;
160 EnterCriticalSection( &WININET_cs
);
162 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) &&
163 WININET_Handles
[handle
-1] )
164 info
= WININET_AddRef( WININET_Handles
[handle
-1] );
166 LeaveCriticalSection( &WININET_cs
);
168 TRACE("handle %d -> %p\n", handle
, info
);
173 BOOL
WININET_Release( LPWININETHANDLEHEADER info
)
175 ULONG refs
= InterlockedDecrement(&info
->refs
);
176 TRACE( "object %p refcount = %d\n", info
, refs
);
179 if ( info
->vtbl
->CloseConnection
)
181 TRACE( "closing connection %p\n", info
);
182 info
->vtbl
->CloseConnection( info
);
184 INTERNET_SendCallback(info
, info
->dwContext
,
185 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
187 TRACE( "destroying object %p\n", info
);
188 if ( info
->htype
!= WH_HINIT
)
189 list_remove( &info
->entry
);
190 info
->vtbl
->Destroy( info
);
195 BOOL
WININET_FreeHandle( HINTERNET hinternet
)
198 UINT handle
= (UINT
) hinternet
;
199 LPWININETHANDLEHEADER info
= NULL
, child
, next
;
201 EnterCriticalSection( &WININET_cs
);
203 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) )
206 if( WININET_Handles
[handle
] )
208 info
= WININET_Handles
[handle
];
209 TRACE( "destroying handle %d for object %p\n", handle
+1, info
);
210 WININET_Handles
[handle
] = NULL
;
215 LeaveCriticalSection( &WININET_cs
);
217 /* As on native when the equivalent of WININET_Release is called, the handle
218 * is already invalid, but if a new handle is created at this time it does
219 * not yet get assigned the freed handle number */
222 /* Free all children as native does */
223 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, WININETHANDLEHEADER
, entry
)
225 TRACE( "freeing child handle %d for parent handle %d\n",
226 (UINT
)child
->hInternet
, handle
+1);
227 WININET_FreeHandle( child
->hInternet
);
229 WININET_Release( info
);
232 EnterCriticalSection( &WININET_cs
);
234 if( WININET_dwNextHandle
> handle
&& !WININET_Handles
[handle
] )
235 WININET_dwNextHandle
= handle
;
237 LeaveCriticalSection( &WININET_cs
);
242 /***********************************************************************
243 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
246 * hinstDLL [I] handle to the DLL's instance
248 * lpvReserved [I] reserved, must be NULL
255 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
257 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
260 case DLL_PROCESS_ATTACH
:
262 g_dwTlsErrIndex
= TlsAlloc();
264 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
267 URLCacheContainers_CreateDefaults();
269 WININET_hModule
= hinstDLL
;
271 case DLL_THREAD_ATTACH
:
274 case DLL_THREAD_DETACH
:
275 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
277 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
278 HeapFree(GetProcessHeap(), 0, lpwite
);
282 case DLL_PROCESS_DETACH
:
284 URLCacheContainers_DeleteAll();
286 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
288 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
289 TlsFree(g_dwTlsErrIndex
);
298 /***********************************************************************
299 * InternetInitializeAutoProxyDll (WININET.@)
301 * Setup the internal proxy
310 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
313 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
317 /***********************************************************************
318 * DetectAutoProxyUrl (WININET.@)
320 * Auto detect the proxy url
326 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
327 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
330 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
335 /***********************************************************************
336 * INTERNET_ConfigureProxy
339 * The proxy may be specified in the form 'http=proxy.my.org'
340 * Presumably that means there can be ftp=ftpproxy.my.org too.
342 static BOOL
INTERNET_ConfigureProxy( LPWININETAPPINFOW lpwai
)
345 DWORD type
, len
, enabled
= 0;
347 static const WCHAR szInternetSettings
[] =
348 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
349 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
350 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
351 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
352 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
354 if (RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)) return FALSE
;
356 len
= sizeof enabled
;
357 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&enabled
, &len
) || type
!= REG_DWORD
)
358 RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&enabled
, sizeof(REG_DWORD
) );
362 TRACE("Proxy is enabled.\n");
364 /* figure out how much memory the proxy setting takes */
365 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
368 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
370 if (!(szProxy
= HeapAlloc( GetProcessHeap(), 0, len
)))
375 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
377 /* find the http proxy, and strip away everything else */
378 p
= strstrW( szProxy
, szHttp
);
381 p
+= lstrlenW( szHttp
);
382 lstrcpyW( szProxy
, p
);
384 p
= strchrW( szProxy
, ' ' );
387 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
388 lpwai
->lpszProxy
= szProxy
;
390 TRACE("http proxy = %s\n", debugstr_w(lpwai
->lpszProxy
));
393 ERR("Couldn't read proxy server settings from registry.\n");
395 else if ((envproxy
= getenv( "http_proxy" )))
399 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
400 if (!(envproxyW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
)))) return FALSE
;
401 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
403 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
404 lpwai
->lpszProxy
= envproxyW
;
406 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwai
->lpszProxy
));
409 if (!enabled
) TRACE("Proxy is not enabled.\n");
412 return (enabled
> 0);
415 /***********************************************************************
416 * dump_INTERNET_FLAGS
418 * Helper function to TRACE the internet flags.
424 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
426 #define FE(x) { x, #x }
427 static const wininet_flag_info flag
[] = {
428 FE(INTERNET_FLAG_RELOAD
),
429 FE(INTERNET_FLAG_RAW_DATA
),
430 FE(INTERNET_FLAG_EXISTING_CONNECT
),
431 FE(INTERNET_FLAG_ASYNC
),
432 FE(INTERNET_FLAG_PASSIVE
),
433 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
434 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
435 FE(INTERNET_FLAG_FROM_CACHE
),
436 FE(INTERNET_FLAG_SECURE
),
437 FE(INTERNET_FLAG_KEEP_CONNECTION
),
438 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
439 FE(INTERNET_FLAG_READ_PREFETCH
),
440 FE(INTERNET_FLAG_NO_COOKIES
),
441 FE(INTERNET_FLAG_NO_AUTH
),
442 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
443 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
444 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
445 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
446 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
447 FE(INTERNET_FLAG_RESYNCHRONIZE
),
448 FE(INTERNET_FLAG_HYPERLINK
),
449 FE(INTERNET_FLAG_NO_UI
),
450 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
451 FE(INTERNET_FLAG_CACHE_ASYNC
),
452 FE(INTERNET_FLAG_FORMS_SUBMIT
),
453 FE(INTERNET_FLAG_NEED_FILE
),
454 FE(INTERNET_FLAG_TRANSFER_ASCII
),
455 FE(INTERNET_FLAG_TRANSFER_BINARY
)
460 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
461 if (flag
[i
].val
& dwFlags
) {
462 TRACE(" %s", flag
[i
].name
);
463 dwFlags
&= ~flag
[i
].val
;
467 TRACE(" Unknown flags (%08x)\n", dwFlags
);
472 /***********************************************************************
473 * INTERNET_CloseHandle (internal)
475 * Close internet handle
478 static VOID
APPINFO_Destroy(WININETHANDLEHEADER
*hdr
)
480 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
484 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
485 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
486 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
487 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
488 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
489 HeapFree(GetProcessHeap(), 0, lpwai
);
492 static DWORD
APPINFO_QueryOption(WININETHANDLEHEADER
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
495 case INTERNET_OPTION_HANDLE_TYPE
:
496 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
498 if (*size
< sizeof(ULONG
))
499 return ERROR_INSUFFICIENT_BUFFER
;
501 *size
= sizeof(DWORD
);
502 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
503 return ERROR_SUCCESS
;
506 FIXME("Not implemented option %d\n", option
);
507 return ERROR_INTERNET_INVALID_OPTION
;
510 static const HANDLEHEADERVtbl APPINFOVtbl
= {
523 /***********************************************************************
524 * InternetOpenW (WININET.@)
526 * Per-application initialization of wininet
529 * HINTERNET on success
533 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
534 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
536 LPWININETAPPINFOW lpwai
= NULL
;
537 HINTERNET handle
= NULL
;
539 if (TRACE_ON(wininet
)) {
540 #define FE(x) { x, #x }
541 static const wininet_flag_info access_type
[] = {
542 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
543 FE(INTERNET_OPEN_TYPE_DIRECT
),
544 FE(INTERNET_OPEN_TYPE_PROXY
),
545 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
549 const char *access_type_str
= "Unknown";
551 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
552 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
553 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
554 if (access_type
[i
].val
== dwAccessType
) {
555 access_type_str
= access_type
[i
].name
;
559 TRACE(" access type : %s\n", access_type_str
);
561 dump_INTERNET_FLAGS(dwFlags
);
564 /* Clear any error information */
565 INTERNET_SetLastError(0);
567 lpwai
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETAPPINFOW
));
570 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
574 lpwai
->hdr
.htype
= WH_HINIT
;
575 lpwai
->hdr
.vtbl
= &APPINFOVtbl
;
576 lpwai
->hdr
.dwFlags
= dwFlags
;
578 lpwai
->dwAccessType
= dwAccessType
;
579 lpwai
->lpszProxyUsername
= NULL
;
580 lpwai
->lpszProxyPassword
= NULL
;
582 handle
= WININET_AllocHandle( &lpwai
->hdr
);
585 HeapFree( GetProcessHeap(), 0, lpwai
);
586 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
590 if (NULL
!= lpszAgent
)
592 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
593 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
594 if (lpwai
->lpszAgent
)
595 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
597 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
598 INTERNET_ConfigureProxy( lpwai
);
599 else if (NULL
!= lpszProxy
)
601 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
602 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
603 if (lpwai
->lpszProxy
)
604 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
607 if (NULL
!= lpszProxyBypass
)
609 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
610 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
611 if (lpwai
->lpszProxyBypass
)
612 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
617 WININET_Release( &lpwai
->hdr
);
619 TRACE("returning %p\n", lpwai
);
625 /***********************************************************************
626 * InternetOpenA (WININET.@)
628 * Per-application initialization of wininet
631 * HINTERNET on success
635 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
636 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
640 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
642 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
643 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
647 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
648 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
649 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
654 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
655 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
656 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
659 if( lpszProxyBypass
)
661 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
662 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
663 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
666 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
668 HeapFree(GetProcessHeap(), 0, szAgent
);
669 HeapFree(GetProcessHeap(), 0, szProxy
);
670 HeapFree(GetProcessHeap(), 0, szBypass
);
675 /***********************************************************************
676 * InternetGetLastResponseInfoA (WININET.@)
678 * Return last wininet error description on the calling thread
681 * TRUE on success of writing to buffer
685 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
686 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
688 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
694 *lpdwError
= lpwite
->dwError
;
697 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
698 *lpdwBufferLength
= strlen(lpszBuffer
);
701 *lpdwBufferLength
= 0;
706 *lpdwBufferLength
= 0;
712 /***********************************************************************
713 * InternetGetLastResponseInfoW (WININET.@)
715 * Return last wininet error description on the calling thread
718 * TRUE on success of writing to buffer
722 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
723 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
725 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
731 *lpdwError
= lpwite
->dwError
;
734 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
735 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
738 *lpdwBufferLength
= 0;
743 *lpdwBufferLength
= 0;
749 /***********************************************************************
750 * InternetGetConnectedState (WININET.@)
752 * Return connected state
756 * if lpdwStatus is not null, return the status (off line,
757 * modem, lan...) in it.
758 * FALSE if not connected
760 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
762 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
765 FIXME("always returning LAN connection.\n");
766 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
772 /***********************************************************************
773 * InternetGetConnectedStateExW (WININET.@)
775 * Return connected state
779 * lpdwStatus [O] Flags specifying the status of the internet connection.
780 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
781 * dwNameLen [I] Size of the buffer, in characters.
782 * dwReserved [I] Reserved. Must be set to 0.
786 * if lpdwStatus is not null, return the status (off line,
787 * modem, lan...) in it.
788 * FALSE if not connected
791 * If the system has no available network connections, an empty string is
792 * stored in lpszConnectionName. If there is a LAN connection, a localized
793 * "LAN Connection" string is stored. Presumably, if only a dial-up
794 * connection is available then the name of the dial-up connection is
795 * returned. Why any application, other than the "Internet Settings" CPL,
796 * would want to use this function instead of the simpler InternetGetConnectedStateW
797 * function is beyond me.
799 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
800 DWORD dwNameLen
, DWORD dwReserved
)
802 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
809 FIXME("always returning LAN connection.\n");
810 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
812 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
816 /***********************************************************************
817 * InternetGetConnectedStateExA (WININET.@)
819 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
820 DWORD dwNameLen
, DWORD dwReserved
)
822 LPWSTR lpwszConnectionName
= NULL
;
825 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
827 if (lpszConnectionName
&& dwNameLen
> 0)
828 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
830 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
832 if (rc
&& lpwszConnectionName
)
834 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
835 dwNameLen
, NULL
, NULL
);
837 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
844 /***********************************************************************
845 * InternetConnectW (WININET.@)
847 * Open a ftp, gopher or http session
850 * HINTERNET a session handle on success
854 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
855 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
856 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
857 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
859 LPWININETAPPINFOW hIC
;
862 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
863 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
864 dwService
, dwFlags
, dwContext
);
868 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
872 /* Clear any error information */
873 INTERNET_SetLastError(0);
874 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
875 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
877 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
883 case INTERNET_SERVICE_FTP
:
884 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
885 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
888 case INTERNET_SERVICE_HTTP
:
889 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
890 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
893 case INTERNET_SERVICE_GOPHER
:
899 WININET_Release( &hIC
->hdr
);
901 TRACE("returning %p\n", rc
);
906 /***********************************************************************
907 * InternetConnectA (WININET.@)
909 * Open a ftp, gopher or http session
912 * HINTERNET a session handle on success
916 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
917 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
918 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
919 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
923 LPWSTR szServerName
= NULL
;
924 LPWSTR szUserName
= NULL
;
925 LPWSTR szPassword
= NULL
;
929 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
930 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
931 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
935 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
936 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
937 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
941 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
942 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
943 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
947 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
948 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
950 HeapFree(GetProcessHeap(), 0, szServerName
);
951 HeapFree(GetProcessHeap(), 0, szUserName
);
952 HeapFree(GetProcessHeap(), 0, szPassword
);
957 /***********************************************************************
958 * InternetFindNextFileA (WININET.@)
960 * Continues a file search from a previous call to FindFirstFile
967 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
972 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
974 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
978 /***********************************************************************
979 * InternetFindNextFileW (WININET.@)
981 * Continues a file search from a previous call to FindFirstFile
988 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
990 WININETHANDLEHEADER
*hdr
;
995 hdr
= WININET_GetObject(hFind
);
997 WARN("Invalid handle\n");
998 SetLastError(ERROR_INVALID_HANDLE
);
1002 if(hdr
->vtbl
->FindNextFileW
) {
1003 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1005 WARN("Handle doesn't support NextFile\n");
1006 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1009 WININET_Release(hdr
);
1011 if(res
!= ERROR_SUCCESS
)
1013 return res
== ERROR_SUCCESS
;
1016 /***********************************************************************
1017 * InternetCloseHandle (WININET.@)
1019 * Generic close handle function
1026 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1028 LPWININETHANDLEHEADER lpwh
;
1030 TRACE("%p\n",hInternet
);
1032 lpwh
= WININET_GetObject( hInternet
);
1035 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1039 WININET_Release( lpwh
);
1040 WININET_FreeHandle( hInternet
);
1046 /***********************************************************************
1047 * ConvertUrlComponentValue (Internal)
1049 * Helper function for InternetCrackUrlW
1052 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1053 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1054 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1056 TRACE("%p %d %p %d %p %p\n", lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1057 if (*dwComponentLen
!= 0)
1059 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1060 if (*lppszComponent
== NULL
)
1062 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1064 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1066 *lppszComponent
= NULL
;
1067 *dwComponentLen
= nASCIILength
;
1071 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1072 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1073 (*lppszComponent
)[ncpylen
]=0;
1074 *dwComponentLen
= ncpylen
;
1080 /***********************************************************************
1081 * InternetCrackUrlA (WININET.@)
1083 * See InternetCrackUrlW.
1085 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1086 LPURL_COMPONENTSA lpUrlComponents
)
1089 URL_COMPONENTSW UCW
;
1092 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl
), dwUrlLength
, dwFlags
, lpUrlComponents
);
1094 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1095 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1097 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1103 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1105 /* if dwUrlLength=-1 then nLength includes null but length to
1106 InternetCrackUrlW should not include it */
1107 if (dwUrlLength
== -1) nLength
--;
1109 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1110 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1112 memset(&UCW
,0,sizeof(UCW
));
1113 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1114 if(lpUrlComponents
->dwHostNameLength
!=0)
1115 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1116 if(lpUrlComponents
->dwUserNameLength
!=0)
1117 UCW
.dwUserNameLength
=lpUrlComponents
->dwUserNameLength
;
1118 if(lpUrlComponents
->dwPasswordLength
!=0)
1119 UCW
.dwPasswordLength
=lpUrlComponents
->dwPasswordLength
;
1120 if(lpUrlComponents
->dwUrlPathLength
!=0)
1121 UCW
.dwUrlPathLength
=lpUrlComponents
->dwUrlPathLength
;
1122 if(lpUrlComponents
->dwSchemeLength
!=0)
1123 UCW
.dwSchemeLength
=lpUrlComponents
->dwSchemeLength
;
1124 if(lpUrlComponents
->dwExtraInfoLength
!=0)
1125 UCW
.dwExtraInfoLength
=lpUrlComponents
->dwExtraInfoLength
;
1126 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
1128 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1132 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1133 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
1135 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1136 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
1138 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1139 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
1141 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1142 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
1144 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1145 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
1147 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1148 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
1150 lpUrlComponents
->nScheme
=UCW
.nScheme
;
1151 lpUrlComponents
->nPort
=UCW
.nPort
;
1152 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1154 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1155 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
1156 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
1157 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
1158 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
1163 static const WCHAR url_schemes
[][7] =
1166 {'g','o','p','h','e','r',0},
1167 {'h','t','t','p',0},
1168 {'h','t','t','p','s',0},
1169 {'f','i','l','e',0},
1170 {'n','e','w','s',0},
1171 {'m','a','i','l','t','o',0},
1175 /***********************************************************************
1176 * GetInternetSchemeW (internal)
1182 * INTERNET_SCHEME_UNKNOWN on failure
1185 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1189 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1191 if(lpszScheme
==NULL
)
1192 return INTERNET_SCHEME_UNKNOWN
;
1194 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1195 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1196 return INTERNET_SCHEME_FIRST
+ i
;
1198 return INTERNET_SCHEME_UNKNOWN
;
1201 /***********************************************************************
1202 * SetUrlComponentValueW (Internal)
1204 * Helper function for InternetCrackUrlW
1207 * lppszComponent [O] Holds the returned string
1208 * dwComponentLen [I] Holds the size of lppszComponent
1209 * [O] Holds the length of the string in lppszComponent without '\0'
1210 * lpszStart [I] Holds the string to copy from
1211 * len [I] Holds the length of lpszStart without '\0'
1218 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1220 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1222 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1225 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1227 if (*lppszComponent
== NULL
)
1229 *lppszComponent
= (LPWSTR
)lpszStart
;
1230 *dwComponentLen
= len
;
1234 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1235 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1236 (*lppszComponent
)[ncpylen
] = '\0';
1237 *dwComponentLen
= ncpylen
;
1244 /***********************************************************************
1245 * InternetCrackUrlW (WININET.@)
1247 * Break up URL into its components
1253 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1254 LPURL_COMPONENTSW lpUC
)
1258 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1261 LPCWSTR lpszParam
= NULL
;
1262 BOOL bIsAbsolute
= FALSE
;
1263 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1264 LPCWSTR lpszcp
= NULL
;
1265 LPWSTR lpszUrl_decode
= NULL
;
1266 DWORD dwUrlLength
= dwUrlLength_orig
;
1267 const WCHAR lpszSeparators
[3]={';','?',0};
1268 const WCHAR lpszSlash
[2]={'/',0};
1270 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl
), dwUrlLength
, dwFlags
, lpUC
);
1272 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1274 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1277 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1279 if (dwFlags
& ICU_DECODE
)
1281 lpszUrl_decode
=HeapAlloc( GetProcessHeap(), 0, dwUrlLength
* sizeof (WCHAR
) );
1282 if( InternetCanonicalizeUrlW(lpszUrl_orig
, lpszUrl_decode
, &dwUrlLength
, dwFlags
))
1284 lpszUrl
= lpszUrl_decode
;
1289 /* Determine if the URI is absolute. */
1290 while (*lpszap
!= '\0')
1292 if (isalnumW(*lpszap
))
1297 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1304 lpszcp
= lpszUrl
; /* Relative url */
1310 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1311 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1313 /* Parse <params> */
1314 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
1315 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1316 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1318 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1322 /* Get scheme first. */
1323 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1324 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1325 lpszUrl
, lpszcp
- lpszUrl
);
1327 /* Eat ':' in protocol. */
1330 /* double slash indicates the net_loc portion is present */
1331 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1335 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
1339 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1341 lpszNetLoc
= lpszParam
;
1343 else if (!lpszNetLoc
)
1344 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1352 /* [<user>[<:password>]@]<host>[:<port>] */
1353 /* First find the user and password if they exist */
1355 lpszHost
= strchrW(lpszcp
, '@');
1356 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1358 /* username and password not specified. */
1359 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1360 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1362 else /* Parse out username and password */
1364 LPCWSTR lpszUser
= lpszcp
;
1365 LPCWSTR lpszPasswd
= lpszHost
;
1367 while (lpszcp
< lpszHost
)
1370 lpszPasswd
= lpszcp
;
1375 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1376 lpszUser
, lpszPasswd
- lpszUser
);
1378 if (lpszPasswd
!= lpszHost
)
1380 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1381 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1382 lpszHost
- lpszPasswd
);
1384 lpszcp
++; /* Advance to beginning of host */
1387 /* Parse <host><:port> */
1390 lpszPort
= lpszNetLoc
;
1392 /* special case for res:// URLs: there is no port here, so the host is the
1393 entire string up to the first '/' */
1394 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1396 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1397 lpszHost
, lpszPort
- lpszHost
);
1402 while (lpszcp
< lpszNetLoc
)
1410 /* If the scheme is "file" and the host is just one letter, it's not a host */
1411 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1414 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1419 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1420 lpszHost
, lpszPort
- lpszHost
);
1421 if (lpszPort
!= lpszNetLoc
)
1422 lpUC
->nPort
= atoiW(++lpszPort
);
1423 else switch (lpUC
->nScheme
)
1425 case INTERNET_SCHEME_HTTP
:
1426 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1428 case INTERNET_SCHEME_HTTPS
:
1429 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1431 case INTERNET_SCHEME_FTP
:
1432 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1434 case INTERNET_SCHEME_GOPHER
:
1435 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1446 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1447 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1448 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1453 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1454 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1455 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1456 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1459 /* Here lpszcp points to:
1461 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1462 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1464 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1468 /* Only truncate the parameter list if it's already been saved
1469 * in lpUC->lpszExtraInfo.
1471 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1472 len
= lpszParam
- lpszcp
;
1475 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1476 * newlines if necessary.
1478 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1479 if (lpsznewline
!= NULL
)
1480 len
= lpsznewline
- lpszcp
;
1482 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1484 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1489 lpUC
->dwUrlPathLength
= 0;
1492 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1493 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1494 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1495 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1496 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1498 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1502 /***********************************************************************
1503 * InternetAttemptConnect (WININET.@)
1505 * Attempt to make a connection to the internet
1508 * ERROR_SUCCESS on success
1509 * Error value on failure
1512 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1515 return ERROR_SUCCESS
;
1519 /***********************************************************************
1520 * InternetCanonicalizeUrlA (WININET.@)
1522 * Escape unsafe characters and spaces
1529 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1530 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1533 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1535 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1536 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1538 if(dwFlags
& ICU_DECODE
)
1540 dwURLFlags
|= URL_UNESCAPE
;
1541 dwFlags
&= ~ICU_DECODE
;
1544 if(dwFlags
& ICU_ESCAPE
)
1546 dwURLFlags
|= URL_UNESCAPE
;
1547 dwFlags
&= ~ICU_ESCAPE
;
1550 if(dwFlags
& ICU_BROWSER_MODE
)
1552 dwURLFlags
|= URL_BROWSER_MODE
;
1553 dwFlags
&= ~ICU_BROWSER_MODE
;
1556 if(dwFlags
& ICU_NO_ENCODE
)
1558 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1559 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1560 dwFlags
&= ~ICU_NO_ENCODE
;
1563 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1565 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1566 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1567 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1569 return (hr
== S_OK
) ? TRUE
: FALSE
;
1572 /***********************************************************************
1573 * InternetCanonicalizeUrlW (WININET.@)
1575 * Escape unsafe characters and spaces
1582 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1583 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1586 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1588 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1589 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1591 if(dwFlags
& ICU_DECODE
)
1593 dwURLFlags
|= URL_UNESCAPE
;
1594 dwFlags
&= ~ICU_DECODE
;
1597 if(dwFlags
& ICU_ESCAPE
)
1599 dwURLFlags
|= URL_UNESCAPE
;
1600 dwFlags
&= ~ICU_ESCAPE
;
1603 if(dwFlags
& ICU_BROWSER_MODE
)
1605 dwURLFlags
|= URL_BROWSER_MODE
;
1606 dwFlags
&= ~ICU_BROWSER_MODE
;
1609 if(dwFlags
& ICU_NO_ENCODE
)
1611 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1612 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1613 dwFlags
&= ~ICU_NO_ENCODE
;
1616 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1618 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1619 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1620 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1622 return (hr
== S_OK
) ? TRUE
: FALSE
;
1625 /* #################################################### */
1627 static INTERNET_STATUS_CALLBACK
set_status_callback(
1628 LPWININETHANDLEHEADER lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
1630 INTERNET_STATUS_CALLBACK ret
;
1632 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1633 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1635 ret
= lpwh
->lpfnStatusCB
;
1636 lpwh
->lpfnStatusCB
= callback
;
1641 /***********************************************************************
1642 * InternetSetStatusCallbackA (WININET.@)
1644 * Sets up a callback function which is called as progress is made
1645 * during an operation.
1648 * Previous callback or NULL on success
1649 * INTERNET_INVALID_STATUS_CALLBACK on failure
1652 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1653 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1655 INTERNET_STATUS_CALLBACK retVal
;
1656 LPWININETHANDLEHEADER lpwh
;
1658 TRACE("0x%08x\n", (ULONG
)hInternet
);
1660 if (!(lpwh
= WININET_GetObject(hInternet
)))
1661 return INTERNET_INVALID_STATUS_CALLBACK
;
1663 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
1665 WININET_Release( lpwh
);
1669 /***********************************************************************
1670 * InternetSetStatusCallbackW (WININET.@)
1672 * Sets up a callback function which is called as progress is made
1673 * during an operation.
1676 * Previous callback or NULL on success
1677 * INTERNET_INVALID_STATUS_CALLBACK on failure
1680 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1681 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1683 INTERNET_STATUS_CALLBACK retVal
;
1684 LPWININETHANDLEHEADER lpwh
;
1686 TRACE("0x%08x\n", (ULONG
)hInternet
);
1688 if (!(lpwh
= WININET_GetObject(hInternet
)))
1689 return INTERNET_INVALID_STATUS_CALLBACK
;
1691 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
1693 WININET_Release( lpwh
);
1697 /***********************************************************************
1698 * InternetSetFilePointer (WININET.@)
1700 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1701 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
1707 /***********************************************************************
1708 * InternetWriteFile (WININET.@)
1710 * Write data to an open internet file
1717 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1718 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1720 LPWININETHANDLEHEADER lpwh
;
1721 BOOL retval
= FALSE
;
1723 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1725 lpwh
= WININET_GetObject( hFile
);
1727 WARN("Invalid handle\n");
1728 SetLastError(ERROR_INVALID_HANDLE
);
1732 if(lpwh
->vtbl
->WriteFile
) {
1733 retval
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1735 WARN("No Writefile method.\n");
1736 SetLastError(ERROR_INVALID_HANDLE
);
1740 WININET_Release( lpwh
);
1746 /***********************************************************************
1747 * InternetReadFile (WININET.@)
1749 * Read data from an open internet file
1756 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1757 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1759 LPWININETHANDLEHEADER hdr
;
1760 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1762 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1764 hdr
= WININET_GetObject(hFile
);
1766 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1770 if(hdr
->vtbl
->ReadFile
)
1771 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1773 WININET_Release(hdr
);
1775 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
1776 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1778 if(res
!= ERROR_SUCCESS
)
1780 return res
== ERROR_SUCCESS
;
1783 /***********************************************************************
1784 * InternetReadFileExA (WININET.@)
1786 * Read data from an open internet file
1789 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1790 * lpBuffersOut [I/O] Buffer.
1791 * dwFlags [I] Flags. See notes.
1792 * dwContext [I] Context for callbacks.
1799 * The parameter dwFlags include zero or more of the following flags:
1800 *|IRF_ASYNC - Makes the call asynchronous.
1801 *|IRF_SYNC - Makes the call synchronous.
1802 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1803 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1805 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1808 * InternetOpenUrlA(), HttpOpenRequestA()
1810 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1811 DWORD dwFlags
, DWORD_PTR dwContext
)
1813 LPWININETHANDLEHEADER hdr
;
1814 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1816 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1818 hdr
= WININET_GetObject(hFile
);
1820 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1824 if(hdr
->vtbl
->ReadFileExA
)
1825 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
1827 WININET_Release(hdr
);
1829 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
1830 res
, lpBuffersOut
->dwBufferLength
);
1832 if(res
!= ERROR_SUCCESS
)
1834 return res
== ERROR_SUCCESS
;
1837 /***********************************************************************
1838 * InternetReadFileExW (WININET.@)
1840 * Read data from an open internet file.
1843 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1844 * lpBuffersOut [I/O] Buffer.
1845 * dwFlags [I] Flags.
1846 * dwContext [I] Context for callbacks.
1849 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1852 * Not implemented in Wine or native either (as of IE6 SP2).
1855 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1856 DWORD dwFlags
, DWORD_PTR dwContext
)
1858 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
1860 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1864 /***********************************************************************
1865 * INET_QueryOptionHelper (internal)
1867 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1868 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1870 LPWININETHANDLEHEADER lpwhh
;
1871 BOOL bSuccess
= FALSE
;
1873 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1875 lpwhh
= WININET_GetObject( hInternet
);
1879 case INTERNET_OPTION_REQUEST_FLAGS
:
1882 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags
);
1883 if (*lpdwBufferLength
< sizeof(ULONG
))
1884 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1887 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
1890 *lpdwBufferLength
= sizeof(ULONG
);
1894 case INTERNET_OPTION_USER_AGENT
:
1897 LPWININETAPPINFOW ai
= (LPWININETAPPINFOW
)lpwhh
;
1899 TRACE("INTERNET_OPTION_USER_AGENT\n");
1901 if (lpwhh
->htype
!= INTERNET_HANDLE_TYPE_INTERNET
)
1903 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1908 required
= (strlenW(ai
->lpszAgent
) + 1) * sizeof(WCHAR
);
1909 if (*lpdwBufferLength
< required
)
1910 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1913 strcpyW(lpBuffer
, ai
->lpszAgent
);
1919 required
= WideCharToMultiByte(CP_ACP
, 0, ai
->lpszAgent
, -1, NULL
, 0, NULL
, NULL
);
1920 if (*lpdwBufferLength
< required
)
1921 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1924 WideCharToMultiByte(CP_ACP
, 0, ai
->lpszAgent
, -1, lpBuffer
, required
, NULL
, NULL
);
1928 *lpdwBufferLength
= required
;
1931 case INTERNET_OPTION_HTTP_VERSION
:
1933 if (*lpdwBufferLength
< sizeof(HTTP_VERSION_INFO
))
1934 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1938 * Presently hardcoded to 1.1
1940 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
1941 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
1944 *lpdwBufferLength
= sizeof(HTTP_VERSION_INFO
);
1947 case INTERNET_OPTION_CONNECTED_STATE
:
1949 DWORD
*pdwConnectedState
= (DWORD
*)lpBuffer
;
1950 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
1952 if (*lpdwBufferLength
< sizeof(*pdwConnectedState
))
1953 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1956 *pdwConnectedState
= INTERNET_STATE_CONNECTED
;
1959 *lpdwBufferLength
= sizeof(*pdwConnectedState
);
1962 case INTERNET_OPTION_PROXY
:
1964 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
)lpwhh
;
1965 WININETAPPINFOW wai
;
1969 TRACE("Getting global proxy info\n");
1970 memset(&wai
, 0, sizeof(WININETAPPINFOW
));
1971 INTERNET_ConfigureProxy( &wai
);
1977 INTERNET_PROXY_INFOW
*pPI
= (INTERNET_PROXY_INFOW
*)lpBuffer
;
1978 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
1980 if (lpwai
->lpszProxy
)
1981 proxyBytesRequired
= (lstrlenW(lpwai
->lpszProxy
) + 1) *
1983 if (lpwai
->lpszProxyBypass
)
1984 proxyBypassBytesRequired
=
1985 (lstrlenW(lpwai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
1986 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOW
) +
1987 proxyBytesRequired
+ proxyBypassBytesRequired
)
1988 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1991 LPWSTR proxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
1992 sizeof(INTERNET_PROXY_INFOW
));
1993 LPWSTR proxy_bypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
1994 sizeof(INTERNET_PROXY_INFOW
) +
1995 proxyBytesRequired
);
1997 pPI
->dwAccessType
= lpwai
->dwAccessType
;
1998 pPI
->lpszProxy
= NULL
;
1999 pPI
->lpszProxyBypass
= NULL
;
2000 if (lpwai
->lpszProxy
)
2002 lstrcpyW(proxy
, lpwai
->lpszProxy
);
2003 pPI
->lpszProxy
= proxy
;
2006 if (lpwai
->lpszProxyBypass
)
2008 lstrcpyW(proxy_bypass
, lpwai
->lpszProxyBypass
);
2009 pPI
->lpszProxyBypass
= proxy_bypass
;
2013 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOW
) +
2014 proxyBytesRequired
+ proxyBypassBytesRequired
;
2018 INTERNET_PROXY_INFOA
*pPI
= (INTERNET_PROXY_INFOA
*)lpBuffer
;
2019 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2021 if (lpwai
->lpszProxy
)
2022 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2023 lpwai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
2024 if (lpwai
->lpszProxyBypass
)
2025 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2026 lpwai
->lpszProxyBypass
, -1, NULL
, 0, NULL
, NULL
);
2027 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOA
) +
2028 proxyBytesRequired
+ proxyBypassBytesRequired
)
2029 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2032 LPSTR proxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2033 sizeof(INTERNET_PROXY_INFOA
));
2034 LPSTR proxy_bypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2035 sizeof(INTERNET_PROXY_INFOA
) +
2036 proxyBytesRequired
);
2038 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2039 pPI
->lpszProxy
= NULL
;
2040 pPI
->lpszProxyBypass
= NULL
;
2041 if (lpwai
->lpszProxy
)
2043 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxy
, -1,
2044 proxy
, proxyBytesRequired
, NULL
, NULL
);
2045 pPI
->lpszProxy
= proxy
;
2048 if (lpwai
->lpszProxyBypass
)
2050 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxyBypass
,
2051 -1, proxy_bypass
, proxyBypassBytesRequired
,
2053 pPI
->lpszProxyBypass
= proxy_bypass
;
2057 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOA
) +
2058 proxyBytesRequired
+ proxyBypassBytesRequired
;
2062 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2065 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn
);
2066 if (*lpdwBufferLength
< sizeof(ULONG
))
2067 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2070 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2073 *lpdwBufferLength
= sizeof(ULONG
);
2076 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2079 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn
);
2080 if (*lpdwBufferLength
< sizeof(ULONG
))
2081 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2084 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2087 *lpdwBufferLength
= sizeof(ULONG
);
2090 case INTERNET_OPTION_SECURITY_FLAGS
:
2091 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2095 case INTERNET_OPTION_VERSION
:
2097 TRACE("INTERNET_OPTION_VERSION\n");
2098 if (*lpdwBufferLength
< sizeof(INTERNET_VERSION_INFO
))
2099 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2102 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2103 memcpy(lpBuffer
, &info
, sizeof(info
));
2104 *lpdwBufferLength
= sizeof(info
);
2109 case INTERNET_OPTION_PER_CONNECTION_OPTION
:
2110 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2111 if (*lpdwBufferLength
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
))
2112 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2115 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2118 for (x
= 0; x
< con
->dwOptionCount
; ++x
)
2120 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ x
;
2121 switch (option
->dwOption
)
2123 case INTERNET_PER_CONN_FLAGS
:
2124 option
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2127 case INTERNET_PER_CONN_PROXY_SERVER
:
2128 case INTERNET_PER_CONN_PROXY_BYPASS
:
2129 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2130 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2131 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2132 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2133 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2134 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2135 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2136 option
->Value
.dwValue
= 0;
2141 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2147 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2158 res
= lpwhh
->vtbl
->QueryOption(lpwhh
, dwOption
, lpBuffer
, lpdwBufferLength
, bIsUnicode
);
2159 if(res
== ERROR_SUCCESS
)
2164 FIXME("Stub! %d\n", dwOption
);
2170 WININET_Release( lpwhh
);
2175 /***********************************************************************
2176 * InternetQueryOptionW (WININET.@)
2178 * Queries an options on the specified handle
2185 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2186 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2188 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2191 /***********************************************************************
2192 * InternetQueryOptionA (WININET.@)
2194 * Queries an options on the specified handle
2201 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2202 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2204 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2208 /***********************************************************************
2209 * InternetSetOptionW (WININET.@)
2211 * Sets an options on the specified handle
2218 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2219 LPVOID lpBuffer
, DWORD dwBufferLength
)
2221 LPWININETHANDLEHEADER lpwhh
;
2224 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2226 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2227 if(lpwhh
&& lpwhh
->vtbl
->SetOption
) {
2230 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2231 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2232 WININET_Release( lpwhh
);
2234 if(res
!= ERROR_SUCCESS
)
2237 return res
== ERROR_SUCCESS
;
2243 case INTERNET_OPTION_CALLBACK
:
2245 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2246 ret
= (set_status_callback(lpwhh
, callback
, TRUE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2249 case INTERNET_OPTION_HTTP_VERSION
:
2251 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2252 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2255 case INTERNET_OPTION_ERROR_MASK
:
2257 unsigned long flags
=*(unsigned long*)lpBuffer
;
2258 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
2261 case INTERNET_OPTION_CODEPAGE
:
2263 unsigned long codepage
=*(unsigned long*)lpBuffer
;
2264 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
2267 case INTERNET_OPTION_REQUEST_PRIORITY
:
2269 unsigned long priority
=*(unsigned long*)lpBuffer
;
2270 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
2273 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2275 unsigned long connecttimeout
=*(unsigned long*)lpBuffer
;
2276 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout
);
2279 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2281 unsigned long receivetimeout
=*(unsigned long*)lpBuffer
;
2282 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout
);
2285 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2287 unsigned long conns
=*(unsigned long*)lpBuffer
;
2288 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns
);
2291 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2293 unsigned long conns
=*(unsigned long*)lpBuffer
;
2294 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns
);
2297 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2298 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2300 case INTERNET_OPTION_END_BROWSER_SESSION
:
2301 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2303 case INTERNET_OPTION_CONNECTED_STATE
:
2304 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2306 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2307 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2309 case INTERNET_OPTION_SEND_TIMEOUT
:
2310 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2311 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2313 case INTERNET_OPTION_CONNECT_RETRIES
:
2314 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2316 case INTERNET_OPTION_CONTEXT_VALUE
:
2317 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2319 case INTERNET_OPTION_SECURITY_FLAGS
:
2320 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2326 FIXME("Option %d STUB\n",dwOption
);
2327 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2333 WININET_Release( lpwhh
);
2339 /***********************************************************************
2340 * InternetSetOptionA (WININET.@)
2342 * Sets an options on the specified handle.
2349 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2350 LPVOID lpBuffer
, DWORD dwBufferLength
)
2358 case INTERNET_OPTION_CALLBACK
:
2360 LPWININETHANDLEHEADER lpwh
;
2361 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2363 if (!(lpwh
= WININET_GetObject(hInternet
))) return FALSE
;
2364 r
= (set_status_callback(lpwh
, callback
, FALSE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2365 WININET_Release(lpwh
);
2368 case INTERNET_OPTION_PROXY
:
2370 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2371 LPINTERNET_PROXY_INFOW piw
;
2372 DWORD proxlen
, prbylen
;
2375 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2376 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2377 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2378 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2379 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2380 piw
->dwAccessType
= pi
->dwAccessType
;
2381 prox
= (LPWSTR
) &piw
[1];
2382 prby
= &prox
[proxlen
+1];
2383 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2384 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2385 piw
->lpszProxy
= prox
;
2386 piw
->lpszProxyBypass
= prby
;
2389 case INTERNET_OPTION_USER_AGENT
:
2390 case INTERNET_OPTION_USERNAME
:
2391 case INTERNET_OPTION_PASSWORD
:
2392 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2394 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2395 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2400 wlen
= dwBufferLength
;
2403 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2405 if( lpBuffer
!= wbuffer
)
2406 HeapFree( GetProcessHeap(), 0, wbuffer
);
2412 /***********************************************************************
2413 * InternetSetOptionExA (WININET.@)
2415 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2416 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2418 FIXME("Flags %08x ignored\n", dwFlags
);
2419 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2422 /***********************************************************************
2423 * InternetSetOptionExW (WININET.@)
2425 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2426 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2428 FIXME("Flags %08x ignored\n", dwFlags
);
2429 if( dwFlags
& ~ISO_VALID_FLAGS
)
2431 INTERNET_SetLastError( ERROR_INVALID_PARAMETER
);
2434 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2437 static const WCHAR WININET_wkday
[7][4] =
2438 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2439 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2440 static const WCHAR WININET_month
[12][4] =
2441 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2442 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2443 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2445 /***********************************************************************
2446 * InternetTimeFromSystemTimeA (WININET.@)
2448 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2451 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2453 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2455 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2456 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2461 /***********************************************************************
2462 * InternetTimeFromSystemTimeW (WININET.@)
2464 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2466 static const WCHAR date
[] =
2467 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2468 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2470 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2472 if (!time
|| !string
) return FALSE
;
2474 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2477 sprintfW( string
, date
,
2478 WININET_wkday
[time
->wDayOfWeek
],
2480 WININET_month
[time
->wMonth
- 1],
2489 /***********************************************************************
2490 * InternetTimeToSystemTimeA (WININET.@)
2492 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2498 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
2500 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2501 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2505 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2506 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2507 HeapFree( GetProcessHeap(), 0, stringW
);
2512 /***********************************************************************
2513 * InternetTimeToSystemTimeW (WININET.@)
2515 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2518 const WCHAR
*s
= string
;
2521 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
2523 if (!string
|| !time
) return FALSE
;
2525 /* Windows does this too */
2526 GetSystemTime( time
);
2528 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2529 * a SYSTEMTIME structure.
2532 while (*s
&& !isalphaW( *s
)) s
++;
2533 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2534 time
->wDayOfWeek
= 7;
2536 for (i
= 0; i
< 7; i
++)
2538 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2539 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2540 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2542 time
->wDayOfWeek
= i
;
2547 if (time
->wDayOfWeek
> 6) return TRUE
;
2548 while (*s
&& !isdigitW( *s
)) s
++;
2549 time
->wDay
= strtolW( s
, &end
, 10 );
2552 while (*s
&& !isalphaW( *s
)) s
++;
2553 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2556 for (i
= 0; i
< 12; i
++)
2558 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2559 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2560 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2562 time
->wMonth
= i
+ 1;
2566 if (time
->wMonth
== 0) return TRUE
;
2568 while (*s
&& !isdigitW( *s
)) s
++;
2569 if (*s
== '\0') return TRUE
;
2570 time
->wYear
= strtolW( s
, &end
, 10 );
2573 while (*s
&& !isdigitW( *s
)) s
++;
2574 if (*s
== '\0') return TRUE
;
2575 time
->wHour
= strtolW( s
, &end
, 10 );
2578 while (*s
&& !isdigitW( *s
)) s
++;
2579 if (*s
== '\0') return TRUE
;
2580 time
->wMinute
= strtolW( s
, &end
, 10 );
2583 while (*s
&& !isdigitW( *s
)) s
++;
2584 if (*s
== '\0') return TRUE
;
2585 time
->wSecond
= strtolW( s
, &end
, 10 );
2588 time
->wMilliseconds
= 0;
2592 /***********************************************************************
2593 * InternetCheckConnectionW (WININET.@)
2595 * Pings a requested host to check internet connection
2598 * TRUE on success and FALSE on failure. If a failure then
2599 * ERROR_NOT_CONNECTED is placed into GetLastError
2602 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2605 * this is a kludge which runs the resident ping program and reads the output.
2607 * Anyone have a better idea?
2611 static const CHAR ping
[] = "ping -c 1 ";
2612 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2613 CHAR
*command
= NULL
;
2622 * Crack or set the Address
2624 if (lpszUrl
== NULL
)
2627 * According to the doc we are supposed to use the ip for the next
2628 * server in the WnInet internal server database. I have
2629 * no idea what that is or how to get it.
2631 * So someone needs to implement this.
2633 FIXME("Unimplemented with URL of NULL\n");
2638 URL_COMPONENTSW components
;
2640 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2641 components
.lpszHostName
= (LPWSTR
)&hostW
;
2642 components
.dwHostNameLength
= 1024;
2644 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2647 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2648 port
= components
.nPort
;
2649 TRACE("port: %d\n", port
);
2652 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
2654 struct sockaddr_in sin
;
2657 if (!GetAddress(hostW
, port
, &sin
))
2659 fd
= socket(sin
.sin_family
, SOCK_STREAM
, 0);
2662 if (connect(fd
, (struct sockaddr
*)&sin
, sizeof(sin
)) == 0)
2670 * Build our ping command
2672 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2673 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2674 strcpy(command
,ping
);
2675 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2676 strcat(command
,redirect
);
2678 TRACE("Ping command is : %s\n",command
);
2680 status
= system(command
);
2682 TRACE("Ping returned a code of %i\n",status
);
2684 /* Ping return code of 0 indicates success */
2691 HeapFree( GetProcessHeap(), 0, command
);
2693 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
2699 /***********************************************************************
2700 * InternetCheckConnectionA (WININET.@)
2702 * Pings a requested host to check internet connection
2705 * TRUE on success and FALSE on failure. If a failure then
2706 * ERROR_NOT_CONNECTED is placed into GetLastError
2709 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2715 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2716 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2718 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2719 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2720 HeapFree(GetProcessHeap(), 0, szUrl
);
2726 /**********************************************************
2727 * INTERNET_InternetOpenUrlW (internal)
2732 * handle of connection or NULL on failure
2734 static HINTERNET
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2735 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2737 URL_COMPONENTSW urlComponents
;
2738 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2739 WCHAR password
[1024], path
[2048], extra
[1024];
2740 HINTERNET client
= NULL
, client1
= NULL
;
2742 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2743 dwHeadersLength
, dwFlags
, dwContext
);
2745 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2746 urlComponents
.lpszScheme
= protocol
;
2747 urlComponents
.dwSchemeLength
= 32;
2748 urlComponents
.lpszHostName
= hostName
;
2749 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2750 urlComponents
.lpszUserName
= userName
;
2751 urlComponents
.dwUserNameLength
= 1024;
2752 urlComponents
.lpszPassword
= password
;
2753 urlComponents
.dwPasswordLength
= 1024;
2754 urlComponents
.lpszUrlPath
= path
;
2755 urlComponents
.dwUrlPathLength
= 2048;
2756 urlComponents
.lpszExtraInfo
= extra
;
2757 urlComponents
.dwExtraInfoLength
= 1024;
2758 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2760 switch(urlComponents
.nScheme
) {
2761 case INTERNET_SCHEME_FTP
:
2762 if(urlComponents
.nPort
== 0)
2763 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2764 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2765 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2768 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2769 if(client1
== NULL
) {
2770 InternetCloseHandle(client
);
2775 case INTERNET_SCHEME_HTTP
:
2776 case INTERNET_SCHEME_HTTPS
: {
2777 static const WCHAR szStars
[] = { '*','/','*', 0 };
2778 LPCWSTR accept
[2] = { szStars
, NULL
};
2779 if(urlComponents
.nPort
== 0) {
2780 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2781 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2783 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2785 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2786 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2787 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2791 if (urlComponents
.dwExtraInfoLength
) {
2793 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
2795 if (!(path_extra
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
2797 InternetCloseHandle(client
);
2800 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
2801 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
2802 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2803 HeapFree(GetProcessHeap(), 0, path_extra
);
2806 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2808 if(client1
== NULL
) {
2809 InternetCloseHandle(client
);
2812 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2813 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
2814 GetLastError() != ERROR_IO_PENDING
) {
2815 InternetCloseHandle(client1
);
2820 case INTERNET_SCHEME_GOPHER
:
2821 /* gopher doesn't seem to be implemented in wine, but it's supposed
2822 * to be supported by InternetOpenUrlA. */
2824 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
2828 TRACE(" %p <--\n", client1
);
2833 /**********************************************************
2834 * InternetOpenUrlW (WININET.@)
2839 * handle of connection or NULL on failure
2841 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
2843 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
2844 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
->hdr
;
2848 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
2849 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
2850 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
2851 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
2854 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
2855 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2857 HINTERNET ret
= NULL
;
2858 LPWININETAPPINFOW hIC
= NULL
;
2860 if (TRACE_ON(wininet
)) {
2861 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2862 dwHeadersLength
, dwFlags
, dwContext
);
2864 dump_INTERNET_FLAGS(dwFlags
);
2869 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2873 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
2874 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
2875 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2879 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
2880 WORKREQUEST workRequest
;
2881 struct WORKREQ_INTERNETOPENURLW
*req
;
2883 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
2884 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
2885 req
= &workRequest
.u
.InternetOpenUrlW
;
2886 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
2888 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
2890 req
->lpszHeaders
= 0;
2891 req
->dwHeadersLength
= dwHeadersLength
;
2892 req
->dwFlags
= dwFlags
;
2893 req
->dwContext
= dwContext
;
2895 INTERNET_AsyncCall(&workRequest
);
2897 * This is from windows.
2899 INTERNET_SetLastError(ERROR_IO_PENDING
);
2901 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
2906 WININET_Release( &hIC
->hdr
);
2907 TRACE(" %p <--\n", ret
);
2912 /**********************************************************
2913 * InternetOpenUrlA (WININET.@)
2918 * handle of connection or NULL on failure
2920 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
2921 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2923 HINTERNET rc
= NULL
;
2927 LPWSTR szUrl
= NULL
;
2928 LPWSTR szHeaders
= NULL
;
2933 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
2934 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
2937 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
2941 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
2942 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
2944 HeapFree(GetProcessHeap(), 0, szUrl
);
2947 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
2950 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
2951 lenHeaders
, dwFlags
, dwContext
);
2953 HeapFree(GetProcessHeap(), 0, szUrl
);
2954 HeapFree(GetProcessHeap(), 0, szHeaders
);
2960 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
2962 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite
));
2966 lpwite
->dwError
= 0;
2967 lpwite
->response
[0] = '\0';
2970 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
2972 HeapFree(GetProcessHeap(), 0, lpwite
);
2980 /***********************************************************************
2981 * INTERNET_SetLastError (internal)
2983 * Set last thread specific error
2988 void INTERNET_SetLastError(DWORD dwError
)
2990 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
2993 lpwite
= INTERNET_AllocThreadError();
2995 SetLastError(dwError
);
2997 lpwite
->dwError
= dwError
;
3001 /***********************************************************************
3002 * INTERNET_GetLastError (internal)
3004 * Get last thread specific error
3009 DWORD
INTERNET_GetLastError(void)
3011 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3012 if (!lpwite
) return 0;
3013 /* TlsGetValue clears last error, so set it again here */
3014 SetLastError(lpwite
->dwError
);
3015 return lpwite
->dwError
;
3019 /***********************************************************************
3020 * INTERNET_WorkerThreadFunc (internal)
3022 * Worker thread execution function
3027 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3029 LPWORKREQUEST lpRequest
= lpvParam
;
3030 WORKREQUEST workRequest
;
3034 workRequest
= *lpRequest
;
3035 HeapFree(GetProcessHeap(), 0, lpRequest
);
3037 workRequest
.asyncproc(&workRequest
);
3039 WININET_Release( workRequest
.hdr
);
3044 /***********************************************************************
3045 * INTERNET_AsyncCall (internal)
3047 * Retrieves work request from queue
3052 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3055 LPWORKREQUEST lpNewRequest
;
3059 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3063 *lpNewRequest
= *lpWorkRequest
;
3065 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3068 HeapFree(GetProcessHeap(), 0, lpNewRequest
);
3069 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3076 /***********************************************************************
3077 * INTERNET_GetResponseBuffer (internal)
3082 LPSTR
INTERNET_GetResponseBuffer(void)
3084 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3086 lpwite
= INTERNET_AllocThreadError();
3088 return lpwite
->response
;
3091 /***********************************************************************
3092 * INTERNET_GetNextLine (internal)
3094 * Parse next line in directory string listing
3097 * Pointer to beginning of next line
3102 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3106 BOOL bSuccess
= FALSE
;
3108 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3113 FD_SET(nSocket
, &infd
);
3114 tv
.tv_sec
=RESPONSE_TIMEOUT
;
3117 while (nRecv
< MAX_REPLY_LEN
)
3119 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
3121 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3123 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3127 if (lpszBuffer
[nRecv
] == '\n')
3132 if (lpszBuffer
[nRecv
] != '\r')
3137 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3145 lpszBuffer
[nRecv
] = '\0';
3147 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3156 /**********************************************************
3157 * InternetQueryDataAvailable (WININET.@)
3159 * Determines how much data is available to be read.
3162 * TRUE on success, FALSE if an error occurred. If
3163 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3164 * no data is presently available, FALSE is returned with
3165 * the last error ERROR_IO_PENDING; a callback with status
3166 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3167 * data is available.
3169 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3170 LPDWORD lpdwNumberOfBytesAvailble
,
3171 DWORD dwFlags
, DWORD_PTR dwContext
)
3173 WININETHANDLEHEADER
*hdr
;
3176 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3178 hdr
= WININET_GetObject( hFile
);
3180 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
3184 if(hdr
->vtbl
->QueryDataAvailable
) {
3185 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3187 WARN("wrong handle\n");
3188 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3191 WININET_Release(hdr
);
3193 if(res
!= ERROR_SUCCESS
)
3195 return res
== ERROR_SUCCESS
;
3199 /***********************************************************************
3200 * InternetLockRequestFile (WININET.@)
3202 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3209 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3216 /***********************************************************************
3217 * InternetAutodial (WININET.@)
3219 * On windows this function is supposed to dial the default internet
3220 * connection. We don't want to have Wine dial out to the internet so
3221 * we return TRUE by default. It might be nice to check if we are connected.
3228 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3232 /* Tell that we are connected to the internet. */
3236 /***********************************************************************
3237 * InternetAutodialHangup (WININET.@)
3239 * Hangs up a connection made with InternetAutodial
3248 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3252 /* we didn't dial, we don't disconnect */
3256 /***********************************************************************
3257 * InternetCombineUrlA (WININET.@)
3259 * Combine a base URL with a relative URL
3267 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3268 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3273 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3275 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3276 dwFlags
^= ICU_NO_ENCODE
;
3277 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3282 /***********************************************************************
3283 * InternetCombineUrlW (WININET.@)
3285 * Combine a base URL with a relative URL
3293 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3294 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3299 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3301 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3302 dwFlags
^= ICU_NO_ENCODE
;
3303 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3308 /* max port num is 65535 => 5 digits */
3309 #define MAX_WORD_DIGITS 5
3311 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3312 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3313 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3314 (url)->dw##component##Length : strlen((url)->lpsz##component))
3316 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3318 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3319 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3321 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3322 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3324 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3325 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3327 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3328 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3331 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3337 /* opaque urls do not fit into the standard url hierarchy and don't have
3338 * two following slashes */
3339 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3341 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3342 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3343 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3344 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3345 (nScheme
!= INTERNET_SCHEME_FILE
);
3348 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3351 if (scheme
< INTERNET_SCHEME_FIRST
)
3353 index
= scheme
- INTERNET_SCHEME_FIRST
;
3354 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3356 return (LPCWSTR
)&url_schemes
[index
];
3359 /* we can calculate using ansi strings because we're just
3360 * calculating string length, not size
3362 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3363 LPDWORD lpdwUrlLength
)
3365 INTERNET_SCHEME nScheme
;
3369 if (lpUrlComponents
->lpszScheme
)
3371 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3372 *lpdwUrlLength
+= dwLen
;
3373 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3379 nScheme
= lpUrlComponents
->nScheme
;
3381 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3382 nScheme
= INTERNET_SCHEME_HTTP
;
3383 scheme
= INTERNET_GetSchemeString(nScheme
);
3384 *lpdwUrlLength
+= strlenW(scheme
);
3387 (*lpdwUrlLength
)++; /* ':' */
3388 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3389 *lpdwUrlLength
+= strlen("//");
3391 if (lpUrlComponents
->lpszUserName
)
3393 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3394 *lpdwUrlLength
+= strlen("@");
3398 if (lpUrlComponents
->lpszPassword
)
3400 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3405 if (lpUrlComponents
->lpszPassword
)
3407 *lpdwUrlLength
+= strlen(":");
3408 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3411 if (lpUrlComponents
->lpszHostName
)
3413 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3415 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3417 char szPort
[MAX_WORD_DIGITS
+1];
3419 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3420 *lpdwUrlLength
+= strlen(szPort
);
3421 *lpdwUrlLength
+= strlen(":");
3424 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3425 (*lpdwUrlLength
)++; /* '/' */
3428 if (lpUrlComponents
->lpszUrlPath
)
3429 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3434 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3438 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3440 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3441 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3442 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3443 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3444 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3445 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3446 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3447 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3448 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3450 if (lpUrlComponents
->lpszScheme
)
3452 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
3453 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3454 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3455 -1, urlCompW
->lpszScheme
, len
);
3458 if (lpUrlComponents
->lpszHostName
)
3460 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
3461 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3462 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3463 -1, urlCompW
->lpszHostName
, len
);
3466 if (lpUrlComponents
->lpszUserName
)
3468 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
3469 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3470 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3471 -1, urlCompW
->lpszUserName
, len
);
3474 if (lpUrlComponents
->lpszPassword
)
3476 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
3477 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3478 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3479 -1, urlCompW
->lpszPassword
, len
);
3482 if (lpUrlComponents
->lpszUrlPath
)
3484 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
3485 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3486 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3487 -1, urlCompW
->lpszUrlPath
, len
);
3490 if (lpUrlComponents
->lpszExtraInfo
)
3492 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
3493 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3494 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3495 -1, urlCompW
->lpszExtraInfo
, len
);
3499 /***********************************************************************
3500 * InternetCreateUrlA (WININET.@)
3502 * See InternetCreateUrlW.
3504 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3505 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3509 URL_COMPONENTSW urlCompW
;
3511 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3513 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3515 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3519 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3522 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3524 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3526 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3527 *lpdwUrlLength
/= sizeof(WCHAR
);
3529 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3530 * minus one, so add one to leave room for NULL terminator
3533 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3535 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3536 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3537 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3538 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3539 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3540 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3541 HeapFree(GetProcessHeap(), 0, urlW
);
3546 /***********************************************************************
3547 * InternetCreateUrlW (WININET.@)
3549 * Creates a URL from its component parts.
3552 * lpUrlComponents [I] URL Components.
3553 * dwFlags [I] Flags. See notes.
3554 * lpszUrl [I] Buffer in which to store the created URL.
3555 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3556 * lpszUrl in characters. On output, the number of bytes
3557 * required to store the URL including terminator.
3561 * The dwFlags parameter can be zero or more of the following:
3562 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3569 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3570 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3573 INTERNET_SCHEME nScheme
;
3575 static const WCHAR slashSlashW
[] = {'/','/'};
3576 static const WCHAR percentD
[] = {'%','d',0};
3578 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3580 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3582 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3586 if (!calc_url_length(lpUrlComponents
, &dwLen
))
3589 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3591 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
3592 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3596 *lpdwUrlLength
= dwLen
;
3601 if (lpUrlComponents
->lpszScheme
)
3603 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3604 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
3607 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3612 nScheme
= lpUrlComponents
->nScheme
;
3614 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3615 nScheme
= INTERNET_SCHEME_HTTP
;
3617 scheme
= INTERNET_GetSchemeString(nScheme
);
3618 dwLen
= strlenW(scheme
);
3619 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
3623 /* all schemes are followed by at least a colon */
3627 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3629 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
3630 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
3633 if (lpUrlComponents
->lpszUserName
)
3635 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3636 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
3639 if (lpUrlComponents
->lpszPassword
)