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"
70 #define CP_UNIXCP CP_THREAD_ACP
72 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
74 #define RESPONSE_TIMEOUT 30
79 CHAR response
[MAX_REPLY_LEN
];
80 } WITHREADERROR
, *LPWITHREADERROR
;
82 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
);
83 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
84 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
);
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
)
151 TRACE("%p -> refcount = %d\n", info
, info
->dwRefCount
);
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
)
176 TRACE( "object %p refcount = %d\n", info
, info
->dwRefCount
);
177 if( !info
->dwRefCount
)
179 if ( info
->close_connection
)
181 TRACE( "closing connection %p\n", info
);
182 info
->close_connection( 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
->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
= (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_ConfigureProxyFromReg
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_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai
)
345 DWORD r
, keytype
, len
, enabled
;
346 LPCSTR lpszInternetSettings
=
347 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
348 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
350 r
= RegOpenKeyA(HKEY_CURRENT_USER
, lpszInternetSettings
, &key
);
351 if ( r
!= ERROR_SUCCESS
)
354 len
= sizeof enabled
;
355 r
= RegQueryValueExA( key
, "ProxyEnable", NULL
, &keytype
,
356 (BYTE
*)&enabled
, &len
);
357 if( (r
== ERROR_SUCCESS
) && enabled
)
359 TRACE("Proxy is enabled.\n");
361 /* figure out how much memory the proxy setting takes */
362 r
= RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
364 if( (r
== ERROR_SUCCESS
) && len
&& (keytype
== REG_SZ
) )
367 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
369 szProxy
=HeapAlloc( GetProcessHeap(), 0, len
);
370 RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
371 (BYTE
*)szProxy
, &len
);
373 /* find the http proxy, and strip away everything else */
374 p
= strstrW( szProxy
, szHttp
);
377 p
+= lstrlenW(szHttp
);
378 lstrcpyW( szProxy
, p
);
380 p
= strchrW( szProxy
, ' ' );
384 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
385 lpwai
->lpszProxy
= szProxy
;
387 TRACE("http proxy = %s\n", debugstr_w(lpwai
->lpszProxy
));
390 ERR("Couldn't read proxy server settings.\n");
393 TRACE("Proxy is not enabled.\n");
399 /***********************************************************************
400 * dump_INTERNET_FLAGS
402 * Helper function to TRACE the internet flags.
408 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
410 #define FE(x) { x, #x }
411 static const wininet_flag_info flag
[] = {
412 FE(INTERNET_FLAG_RELOAD
),
413 FE(INTERNET_FLAG_RAW_DATA
),
414 FE(INTERNET_FLAG_EXISTING_CONNECT
),
415 FE(INTERNET_FLAG_ASYNC
),
416 FE(INTERNET_FLAG_PASSIVE
),
417 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
418 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
419 FE(INTERNET_FLAG_FROM_CACHE
),
420 FE(INTERNET_FLAG_SECURE
),
421 FE(INTERNET_FLAG_KEEP_CONNECTION
),
422 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
423 FE(INTERNET_FLAG_READ_PREFETCH
),
424 FE(INTERNET_FLAG_NO_COOKIES
),
425 FE(INTERNET_FLAG_NO_AUTH
),
426 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
427 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
428 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
429 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
430 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
431 FE(INTERNET_FLAG_RESYNCHRONIZE
),
432 FE(INTERNET_FLAG_HYPERLINK
),
433 FE(INTERNET_FLAG_NO_UI
),
434 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
435 FE(INTERNET_FLAG_CACHE_ASYNC
),
436 FE(INTERNET_FLAG_FORMS_SUBMIT
),
437 FE(INTERNET_FLAG_NEED_FILE
),
438 FE(INTERNET_FLAG_TRANSFER_ASCII
),
439 FE(INTERNET_FLAG_TRANSFER_BINARY
)
444 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
445 if (flag
[i
].val
& dwFlags
) {
446 TRACE(" %s", flag
[i
].name
);
447 dwFlags
&= ~flag
[i
].val
;
451 TRACE(" Unknown flags (%08x)\n", dwFlags
);
456 /***********************************************************************
457 * InternetOpenW (WININET.@)
459 * Per-application initialization of wininet
462 * HINTERNET on success
466 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
467 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
469 LPWININETAPPINFOW lpwai
= NULL
;
470 HINTERNET handle
= NULL
;
472 if (TRACE_ON(wininet
)) {
473 #define FE(x) { x, #x }
474 static const wininet_flag_info access_type
[] = {
475 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
476 FE(INTERNET_OPEN_TYPE_DIRECT
),
477 FE(INTERNET_OPEN_TYPE_PROXY
),
478 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
482 const char *access_type_str
= "Unknown";
484 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
485 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
486 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
487 if (access_type
[i
].val
== dwAccessType
) {
488 access_type_str
= access_type
[i
].name
;
492 TRACE(" access type : %s\n", access_type_str
);
494 dump_INTERNET_FLAGS(dwFlags
);
497 /* Clear any error information */
498 INTERNET_SetLastError(0);
500 lpwai
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETAPPINFOW
));
503 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
507 lpwai
->hdr
.htype
= WH_HINIT
;
508 lpwai
->hdr
.dwFlags
= dwFlags
;
509 lpwai
->hdr
.dwRefCount
= 1;
510 lpwai
->hdr
.close_connection
= NULL
;
511 lpwai
->hdr
.destroy
= INTERNET_CloseHandle
;
512 lpwai
->dwAccessType
= dwAccessType
;
513 lpwai
->lpszProxyUsername
= NULL
;
514 lpwai
->lpszProxyPassword
= NULL
;
516 handle
= WININET_AllocHandle( &lpwai
->hdr
);
519 HeapFree( GetProcessHeap(), 0, lpwai
);
520 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
524 if (NULL
!= lpszAgent
)
526 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
527 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
528 if (lpwai
->lpszAgent
)
529 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
531 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
532 INTERNET_ConfigureProxyFromReg( lpwai
);
533 else if (NULL
!= lpszProxy
)
535 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
536 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
537 if (lpwai
->lpszProxy
)
538 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
541 if (NULL
!= lpszProxyBypass
)
543 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
544 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
545 if (lpwai
->lpszProxyBypass
)
546 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
551 WININET_Release( &lpwai
->hdr
);
553 TRACE("returning %p\n", lpwai
);
559 /***********************************************************************
560 * InternetOpenA (WININET.@)
562 * Per-application initialization of wininet
565 * HINTERNET on success
569 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
570 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
572 HINTERNET rc
= (HINTERNET
)NULL
;
574 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
576 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
577 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
581 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
582 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
583 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
588 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
589 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
590 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
593 if( lpszProxyBypass
)
595 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
596 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
597 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
600 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
602 HeapFree(GetProcessHeap(), 0, szAgent
);
603 HeapFree(GetProcessHeap(), 0, szProxy
);
604 HeapFree(GetProcessHeap(), 0, szBypass
);
609 /***********************************************************************
610 * InternetGetLastResponseInfoA (WININET.@)
612 * Return last wininet error description on the calling thread
615 * TRUE on success of writing to buffer
619 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
620 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
622 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
628 *lpdwError
= lpwite
->dwError
;
631 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
632 *lpdwBufferLength
= strlen(lpszBuffer
);
635 *lpdwBufferLength
= 0;
640 *lpdwBufferLength
= 0;
646 /***********************************************************************
647 * InternetGetLastResponseInfoW (WININET.@)
649 * Return last wininet error description on the calling thread
652 * TRUE on success of writing to buffer
656 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
657 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
659 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
665 *lpdwError
= lpwite
->dwError
;
668 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
669 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
672 *lpdwBufferLength
= 0;
677 *lpdwBufferLength
= 0;
683 /***********************************************************************
684 * InternetGetConnectedState (WININET.@)
686 * Return connected state
690 * if lpdwStatus is not null, return the status (off line,
691 * modem, lan...) in it.
692 * FALSE if not connected
694 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
696 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
699 FIXME("always returning LAN connection.\n");
700 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
706 /***********************************************************************
707 * InternetGetConnectedStateExW (WININET.@)
709 * Return connected state
713 * lpdwStatus [O] Flags specifying the status of the internet connection.
714 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
715 * dwNameLen [I] Size of the buffer, in characters.
716 * dwReserved [I] Reserved. Must be set to 0.
720 * if lpdwStatus is not null, return the status (off line,
721 * modem, lan...) in it.
722 * FALSE if not connected
725 * If the system has no available network connections, an empty string is
726 * stored in lpszConnectionName. If there is a LAN connection, a localized
727 * "LAN Connection" string is stored. Presumably, if only a dial-up
728 * connection is available then the name of the dial-up connection is
729 * returned. Why any application, other than the "Internet Settings" CPL,
730 * would want to use this function instead of the simpler InternetGetConnectedStateW
731 * function is beyond me.
733 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
734 DWORD dwNameLen
, DWORD dwReserved
)
736 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
743 FIXME("always returning LAN connection.\n");
744 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
746 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
750 /***********************************************************************
751 * InternetGetConnectedStateExA (WININET.@)
753 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
754 DWORD dwNameLen
, DWORD dwReserved
)
756 LPWSTR lpwszConnectionName
= NULL
;
759 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
761 if (lpszConnectionName
&& dwNameLen
> 0)
762 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
764 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
766 if (rc
&& lpwszConnectionName
)
768 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
769 dwNameLen
, NULL
, NULL
);
771 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
778 /***********************************************************************
779 * InternetConnectW (WININET.@)
781 * Open a ftp, gopher or http session
784 * HINTERNET a session handle on success
788 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
789 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
790 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
791 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
793 LPWININETAPPINFOW hIC
;
796 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
797 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
798 dwService
, dwFlags
, dwContext
);
802 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
806 /* Clear any error information */
807 INTERNET_SetLastError(0);
808 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
809 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
811 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
817 case INTERNET_SERVICE_FTP
:
818 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
819 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
822 case INTERNET_SERVICE_HTTP
:
823 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
824 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
827 case INTERNET_SERVICE_GOPHER
:
833 WININET_Release( &hIC
->hdr
);
835 TRACE("returning %p\n", rc
);
840 /***********************************************************************
841 * InternetConnectA (WININET.@)
843 * Open a ftp, gopher or http session
846 * HINTERNET a session handle on success
850 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
851 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
852 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
853 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
855 HINTERNET rc
= (HINTERNET
)NULL
;
857 LPWSTR szServerName
= NULL
;
858 LPWSTR szUserName
= NULL
;
859 LPWSTR szPassword
= NULL
;
863 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
864 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
865 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
869 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
870 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
871 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
875 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
876 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
877 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
881 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
882 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
884 HeapFree(GetProcessHeap(), 0, szServerName
);
885 HeapFree(GetProcessHeap(), 0, szUserName
);
886 HeapFree(GetProcessHeap(), 0, szPassword
);
891 /***********************************************************************
892 * InternetFindNextFileA (WININET.@)
894 * Continues a file search from a previous call to FindFirstFile
901 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
906 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
908 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
912 /***********************************************************************
913 * InternetFindNextFileW (WININET.@)
915 * Continues a file search from a previous call to FindFirstFile
922 static void AsyncFtpFindNextFileProc(WORKREQUEST
*workRequest
)
924 struct WORKREQ_FTPFINDNEXTW
*req
= &workRequest
->u
.FtpFindNextW
;
925 LPWININETFTPFINDNEXTW lpwh
= (LPWININETFTPFINDNEXTW
) workRequest
->hdr
;
929 FTP_FindNextFileW(lpwh
, req
->lpFindFileData
);
932 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
934 LPWININETAPPINFOW hIC
= NULL
;
935 LPWININETFTPFINDNEXTW lpwh
;
936 BOOL bSuccess
= FALSE
;
940 lpwh
= (LPWININETFTPFINDNEXTW
) WININET_GetObject( hFind
);
941 if (NULL
== lpwh
|| lpwh
->hdr
.htype
!= WH_HFTPFINDNEXT
)
943 FIXME("Only FTP supported\n");
944 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
948 hIC
= lpwh
->lpFtpSession
->lpAppInfo
;
949 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
951 WORKREQUEST workRequest
;
952 struct WORKREQ_FTPFINDNEXTW
*req
;
954 workRequest
.asyncproc
= AsyncFtpFindNextFileProc
;
955 workRequest
.hdr
= WININET_AddRef( &lpwh
->hdr
);
956 req
= &workRequest
.u
.FtpFindNextW
;
957 req
->lpFindFileData
= lpvFindData
;
959 bSuccess
= INTERNET_AsyncCall(&workRequest
);
963 bSuccess
= FTP_FindNextFileW(lpwh
, lpvFindData
);
967 WININET_Release( &lpwh
->hdr
);
971 /***********************************************************************
972 * INTERNET_CloseHandle (internal)
974 * Close internet handle
980 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
)
982 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
986 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
987 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
988 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
989 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
990 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
991 HeapFree(GetProcessHeap(), 0, lpwai
);
995 /***********************************************************************
996 * InternetCloseHandle (WININET.@)
998 * Generic close handle function
1005 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1007 LPWININETHANDLEHEADER lpwh
;
1009 TRACE("%p\n",hInternet
);
1011 lpwh
= WININET_GetObject( hInternet
);
1014 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1018 WININET_Release( lpwh
);
1019 WININET_FreeHandle( hInternet
);
1025 /***********************************************************************
1026 * ConvertUrlComponentValue (Internal)
1028 * Helper function for InternetCrackUrlW
1031 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1032 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1033 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1035 TRACE("%p %d %p %d %p %p\n", lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1036 if (*dwComponentLen
!= 0)
1038 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1039 if (*lppszComponent
== NULL
)
1041 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1043 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1045 *lppszComponent
= NULL
;
1046 *dwComponentLen
= nASCIILength
;
1050 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1051 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1052 (*lppszComponent
)[ncpylen
]=0;
1053 *dwComponentLen
= ncpylen
;
1059 /***********************************************************************
1060 * InternetCrackUrlA (WININET.@)
1062 * See InternetCrackUrlW.
1064 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1065 LPURL_COMPONENTSA lpUrlComponents
)
1068 URL_COMPONENTSW UCW
;
1071 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl
), dwUrlLength
, dwFlags
, lpUrlComponents
);
1073 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1074 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1076 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1082 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1084 /* if dwUrlLength=-1 then nLength includes null but length to
1085 InternetCrackUrlW should not include it */
1086 if (dwUrlLength
== -1) nLength
--;
1088 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1089 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1091 memset(&UCW
,0,sizeof(UCW
));
1092 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1093 if(lpUrlComponents
->dwHostNameLength
!=0)
1094 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1095 if(lpUrlComponents
->dwUserNameLength
!=0)
1096 UCW
.dwUserNameLength
=lpUrlComponents
->dwUserNameLength
;
1097 if(lpUrlComponents
->dwPasswordLength
!=0)
1098 UCW
.dwPasswordLength
=lpUrlComponents
->dwPasswordLength
;
1099 if(lpUrlComponents
->dwUrlPathLength
!=0)
1100 UCW
.dwUrlPathLength
=lpUrlComponents
->dwUrlPathLength
;
1101 if(lpUrlComponents
->dwSchemeLength
!=0)
1102 UCW
.dwSchemeLength
=lpUrlComponents
->dwSchemeLength
;
1103 if(lpUrlComponents
->dwExtraInfoLength
!=0)
1104 UCW
.dwExtraInfoLength
=lpUrlComponents
->dwExtraInfoLength
;
1105 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
1107 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1111 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1112 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
1114 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1115 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
1117 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1118 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
1120 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1121 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
1123 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1124 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
1126 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1127 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
1129 lpUrlComponents
->nScheme
=UCW
.nScheme
;
1130 lpUrlComponents
->nPort
=UCW
.nPort
;
1131 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1133 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1134 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
1135 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
1136 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
1137 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
1142 static const WCHAR url_schemes
[][7] =
1145 {'g','o','p','h','e','r',0},
1146 {'h','t','t','p',0},
1147 {'h','t','t','p','s',0},
1148 {'f','i','l','e',0},
1149 {'n','e','w','s',0},
1150 {'m','a','i','l','t','o',0},
1154 /***********************************************************************
1155 * GetInternetSchemeW (internal)
1161 * INTERNET_SCHEME_UNKNOWN on failure
1164 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1168 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1170 if(lpszScheme
==NULL
)
1171 return INTERNET_SCHEME_UNKNOWN
;
1173 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1174 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1175 return INTERNET_SCHEME_FIRST
+ i
;
1177 return INTERNET_SCHEME_UNKNOWN
;
1180 /***********************************************************************
1181 * SetUrlComponentValueW (Internal)
1183 * Helper function for InternetCrackUrlW
1186 * lppszComponent [O] Holds the returned string
1187 * dwComponentLen [I] Holds the size of lppszComponent
1188 * [O] Holds the length of the string in lppszComponent without '\0'
1189 * lpszStart [I] Holds the string to copy from
1190 * len [I] Holds the length of lpszStart without '\0'
1197 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1199 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1201 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1204 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1206 if (*lppszComponent
== NULL
)
1208 *lppszComponent
= (LPWSTR
)lpszStart
;
1209 *dwComponentLen
= len
;
1213 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1214 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1215 (*lppszComponent
)[ncpylen
] = '\0';
1216 *dwComponentLen
= ncpylen
;
1223 /***********************************************************************
1224 * InternetCrackUrlW (WININET.@)
1226 * Break up URL into its components
1232 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1233 LPURL_COMPONENTSW lpUC
)
1237 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1240 LPCWSTR lpszParam
= NULL
;
1241 BOOL bIsAbsolute
= FALSE
;
1242 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1243 LPCWSTR lpszcp
= NULL
;
1244 LPWSTR lpszUrl_decode
= NULL
;
1245 DWORD dwUrlLength
= dwUrlLength_orig
;
1246 const WCHAR lpszSeparators
[3]={';','?',0};
1247 const WCHAR lpszSlash
[2]={'/',0};
1249 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl
), dwUrlLength
, dwFlags
, lpUC
);
1251 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1253 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1256 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1258 if (dwFlags
& ICU_DECODE
)
1260 lpszUrl_decode
=HeapAlloc( GetProcessHeap(), 0, dwUrlLength
* sizeof (WCHAR
) );
1261 if( InternetCanonicalizeUrlW(lpszUrl_orig
, lpszUrl_decode
, &dwUrlLength
, dwFlags
))
1263 lpszUrl
= lpszUrl_decode
;
1268 /* Determine if the URI is absolute. */
1269 while (*lpszap
!= '\0')
1271 if (isalnumW(*lpszap
))
1276 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1283 lpszcp
= lpszUrl
; /* Relative url */
1289 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1290 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1292 /* Parse <params> */
1293 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
1294 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1295 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1297 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1301 /* Get scheme first. */
1302 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1303 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1304 lpszUrl
, lpszcp
- lpszUrl
);
1306 /* Eat ':' in protocol. */
1309 /* double slash indicates the net_loc portion is present */
1310 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1314 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
1318 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1320 lpszNetLoc
= lpszParam
;
1322 else if (!lpszNetLoc
)
1323 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1331 /* [<user>[<:password>]@]<host>[:<port>] */
1332 /* First find the user and password if they exist */
1334 lpszHost
= strchrW(lpszcp
, '@');
1335 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1337 /* username and password not specified. */
1338 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1339 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1341 else /* Parse out username and password */
1343 LPCWSTR lpszUser
= lpszcp
;
1344 LPCWSTR lpszPasswd
= lpszHost
;
1346 while (lpszcp
< lpszHost
)
1349 lpszPasswd
= lpszcp
;
1354 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1355 lpszUser
, lpszPasswd
- lpszUser
);
1357 if (lpszPasswd
!= lpszHost
)
1359 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1360 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1361 lpszHost
- lpszPasswd
);
1363 lpszcp
++; /* Advance to beginning of host */
1366 /* Parse <host><:port> */
1369 lpszPort
= lpszNetLoc
;
1371 /* special case for res:// URLs: there is no port here, so the host is the
1372 entire string up to the first '/' */
1373 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1375 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1376 lpszHost
, lpszPort
- lpszHost
);
1381 while (lpszcp
< lpszNetLoc
)
1389 /* If the scheme is "file" and the host is just one letter, it's not a host */
1390 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1393 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1398 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1399 lpszHost
, lpszPort
- lpszHost
);
1400 if (lpszPort
!= lpszNetLoc
)
1401 lpUC
->nPort
= atoiW(++lpszPort
);
1402 else switch (lpUC
->nScheme
)
1404 case INTERNET_SCHEME_HTTP
:
1405 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1407 case INTERNET_SCHEME_HTTPS
:
1408 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1410 case INTERNET_SCHEME_FTP
:
1411 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1413 case INTERNET_SCHEME_GOPHER
:
1414 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1425 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1426 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1427 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1432 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1433 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1434 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1435 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1438 /* Here lpszcp points to:
1440 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1441 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1443 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1447 /* Only truncate the parameter list if it's already been saved
1448 * in lpUC->lpszExtraInfo.
1450 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1451 len
= lpszParam
- lpszcp
;
1454 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1455 * newlines if necessary.
1457 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1458 if (lpsznewline
!= NULL
)
1459 len
= lpsznewline
- lpszcp
;
1461 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1463 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1468 lpUC
->dwUrlPathLength
= 0;
1471 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1472 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1473 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1474 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1475 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1477 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1481 /***********************************************************************
1482 * InternetAttemptConnect (WININET.@)
1484 * Attempt to make a connection to the internet
1487 * ERROR_SUCCESS on success
1488 * Error value on failure
1491 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1494 return ERROR_SUCCESS
;
1498 /***********************************************************************
1499 * InternetCanonicalizeUrlA (WININET.@)
1501 * Escape unsafe characters and spaces
1508 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1509 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1512 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1514 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1515 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1517 if(dwFlags
& ICU_DECODE
)
1519 dwURLFlags
|= URL_UNESCAPE
;
1520 dwFlags
&= ~ICU_DECODE
;
1523 if(dwFlags
& ICU_ESCAPE
)
1525 dwURLFlags
|= URL_UNESCAPE
;
1526 dwFlags
&= ~ICU_ESCAPE
;
1529 if(dwFlags
& ICU_BROWSER_MODE
)
1531 dwURLFlags
|= URL_BROWSER_MODE
;
1532 dwFlags
&= ~ICU_BROWSER_MODE
;
1535 if(dwFlags
& ICU_NO_ENCODE
)
1537 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1538 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1539 dwFlags
&= ~ICU_NO_ENCODE
;
1542 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1544 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1545 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1546 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1548 return (hr
== S_OK
) ? TRUE
: FALSE
;
1551 /***********************************************************************
1552 * InternetCanonicalizeUrlW (WININET.@)
1554 * Escape unsafe characters and spaces
1561 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1562 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1565 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1567 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1568 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1570 if(dwFlags
& ICU_DECODE
)
1572 dwURLFlags
|= URL_UNESCAPE
;
1573 dwFlags
&= ~ICU_DECODE
;
1576 if(dwFlags
& ICU_ESCAPE
)
1578 dwURLFlags
|= URL_UNESCAPE
;
1579 dwFlags
&= ~ICU_ESCAPE
;
1582 if(dwFlags
& ICU_BROWSER_MODE
)
1584 dwURLFlags
|= URL_BROWSER_MODE
;
1585 dwFlags
&= ~ICU_BROWSER_MODE
;
1588 if(dwFlags
& ICU_NO_ENCODE
)
1590 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1591 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1592 dwFlags
&= ~ICU_NO_ENCODE
;
1595 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1597 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1598 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1599 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1601 return (hr
== S_OK
) ? TRUE
: FALSE
;
1604 /* #################################################### */
1606 static INTERNET_STATUS_CALLBACK
set_status_callback(
1607 LPWININETHANDLEHEADER lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
1609 INTERNET_STATUS_CALLBACK ret
;
1611 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1612 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1614 ret
= lpwh
->lpfnStatusCB
;
1615 lpwh
->lpfnStatusCB
= callback
;
1620 /***********************************************************************
1621 * InternetSetStatusCallbackA (WININET.@)
1623 * Sets up a callback function which is called as progress is made
1624 * during an operation.
1627 * Previous callback or NULL on success
1628 * INTERNET_INVALID_STATUS_CALLBACK on failure
1631 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1632 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1634 INTERNET_STATUS_CALLBACK retVal
;
1635 LPWININETHANDLEHEADER lpwh
;
1637 TRACE("0x%08x\n", (ULONG
)hInternet
);
1639 if (!(lpwh
= WININET_GetObject(hInternet
)))
1640 return INTERNET_INVALID_STATUS_CALLBACK
;
1642 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
1644 WININET_Release( lpwh
);
1648 /***********************************************************************
1649 * InternetSetStatusCallbackW (WININET.@)
1651 * Sets up a callback function which is called as progress is made
1652 * during an operation.
1655 * Previous callback or NULL on success
1656 * INTERNET_INVALID_STATUS_CALLBACK on failure
1659 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1660 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1662 INTERNET_STATUS_CALLBACK retVal
;
1663 LPWININETHANDLEHEADER lpwh
;
1665 TRACE("0x%08x\n", (ULONG
)hInternet
);
1667 if (!(lpwh
= WININET_GetObject(hInternet
)))
1668 return INTERNET_INVALID_STATUS_CALLBACK
;
1670 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
1672 WININET_Release( lpwh
);
1676 /***********************************************************************
1677 * InternetSetFilePointer (WININET.@)
1679 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1680 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
1686 /***********************************************************************
1687 * InternetWriteFile (WININET.@)
1689 * Write data to an open internet file
1696 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1697 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1699 BOOL retval
= FALSE
;
1701 LPWININETHANDLEHEADER lpwh
;
1704 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1708 switch (lpwh
->htype
)
1712 LPWININETHTTPREQW lpwhr
;
1713 lpwhr
= (LPWININETHTTPREQW
)lpwh
;
1715 TRACE("HTTPREQ %i\n",dwNumOfBytesToWrite
);
1716 retval
= NETCON_send(&lpwhr
->netConnection
, lpBuffer
,
1717 dwNumOfBytesToWrite
, 0, (LPINT
)lpdwNumOfBytesWritten
);
1719 WININET_Release( lpwh
);
1725 nSocket
= ((LPWININETFTPFILE
)lpwh
)->nDataSocket
;
1734 int res
= send(nSocket
, lpBuffer
, dwNumOfBytesToWrite
, 0);
1735 retval
= (res
>= 0);
1736 *lpdwNumOfBytesWritten
= retval
? res
: 0;
1738 WININET_Release( lpwh
);
1744 BOOL
INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh
, LPVOID lpBuffer
,
1745 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
,
1746 BOOL bWait
, BOOL bSendCompletionStatus
)
1748 BOOL retval
= FALSE
;
1751 LPWININETHTTPREQW lpwhr
;
1753 /* FIXME: this should use NETCON functions! */
1754 switch (lpwh
->htype
)
1757 lpwhr
= (LPWININETHTTPREQW
)lpwh
;
1759 if (!NETCON_recv(&lpwhr
->netConnection
, lpBuffer
,
1760 min(dwNumOfBytesToRead
, lpwhr
->dwContentLength
- lpwhr
->dwContentRead
),
1761 bWait
? MSG_WAITALL
: 0, &bytes_read
))
1764 if (((lpwhr
->dwContentLength
!= -1) &&
1765 (lpwhr
->dwContentRead
!= lpwhr
->dwContentLength
)))
1766 ERR("not all data received %d/%d\n", lpwhr
->dwContentRead
,
1767 lpwhr
->dwContentLength
);
1769 /* always returns TRUE, even if the network layer returns an
1771 *pdwNumOfBytesRead
= 0;
1772 HTTP_FinishedReading(lpwhr
);
1777 lpwhr
->dwContentRead
+= bytes_read
;
1778 *pdwNumOfBytesRead
= bytes_read
;
1779 if (!bytes_read
&& (lpwhr
->dwContentRead
== lpwhr
->dwContentLength
))
1780 retval
= HTTP_FinishedReading(lpwhr
);
1787 /* FIXME: FTP should use NETCON_ stuff */
1788 nSocket
= ((LPWININETFTPFILE
)lpwh
)->nDataSocket
;
1791 int res
= recv(nSocket
, lpBuffer
, dwNumOfBytesToRead
, bWait
? MSG_WAITALL
: 0);
1792 retval
= (res
>= 0);
1793 *pdwNumOfBytesRead
= retval
? res
: 0;
1801 if (bSendCompletionStatus
)
1803 INTERNET_ASYNC_RESULT iar
;
1805 iar
.dwResult
= retval
;
1806 iar
.dwError
= iar
.dwError
= retval
? ERROR_SUCCESS
:
1807 INTERNET_GetLastError();
1809 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1810 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
1811 sizeof(INTERNET_ASYNC_RESULT
));
1816 /***********************************************************************
1817 * InternetReadFile (WININET.@)
1819 * Read data from an open internet file
1826 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1827 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1829 LPWININETHANDLEHEADER lpwh
;
1832 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1834 lpwh
= WININET_GetObject( hFile
);
1837 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1841 retval
= INTERNET_ReadFile(lpwh
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, TRUE
, FALSE
);
1842 WININET_Release( lpwh
);
1844 TRACE("-- %s (bytes read: %d)\n", retval
? "TRUE": "FALSE", pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1848 /***********************************************************************
1849 * InternetReadFileExA (WININET.@)
1851 * Read data from an open internet file
1854 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1855 * lpBuffersOut [I/O] Buffer.
1856 * dwFlags [I] Flags. See notes.
1857 * dwContext [I] Context for callbacks.
1864 * The parameter dwFlags include zero or more of the following flags:
1865 *|IRF_ASYNC - Makes the call asynchronous.
1866 *|IRF_SYNC - Makes the call synchronous.
1867 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1868 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1870 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1873 * InternetOpenUrlA(), HttpOpenRequestA()
1875 void AsyncInternetReadFileExProc(WORKREQUEST
*workRequest
)
1877 struct WORKREQ_INTERNETREADFILEEXA
const *req
= &workRequest
->u
.InternetReadFileExA
;
1879 TRACE("INTERNETREADFILEEXA %p\n", workRequest
->hdr
);
1881 INTERNET_ReadFile(workRequest
->hdr
, req
->lpBuffersOut
->lpvBuffer
,
1882 req
->lpBuffersOut
->dwBufferLength
,
1883 &req
->lpBuffersOut
->dwBufferLength
, TRUE
, TRUE
);
1886 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1887 DWORD dwFlags
, DWORD_PTR dwContext
)
1889 BOOL retval
= FALSE
;
1890 LPWININETHANDLEHEADER lpwh
;
1892 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1894 if (dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
))
1895 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
));
1897 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
))
1899 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1903 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1906 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1910 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1911 INTERNET_STATUS_RECEIVING_RESPONSE
, NULL
, 0);
1913 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1914 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1915 if (dwFlags
& IRF_ASYNC
)
1917 DWORD dwDataAvailable
= 0;
1919 if (lpwh
->htype
== WH_HHTTPREQ
)
1920 NETCON_query_data_available(&((LPWININETHTTPREQW
)lpwh
)->netConnection
,
1923 if (!dwDataAvailable
)
1925 WORKREQUEST workRequest
;
1926 struct WORKREQ_INTERNETREADFILEEXA
*req
;
1928 workRequest
.asyncproc
= AsyncInternetReadFileExProc
;
1929 workRequest
.hdr
= WININET_AddRef( lpwh
);
1930 req
= &workRequest
.u
.InternetReadFileExA
;
1931 req
->lpBuffersOut
= lpBuffersOut
;
1933 if (!INTERNET_AsyncCall(&workRequest
))
1934 WININET_Release( lpwh
);
1936 INTERNET_SetLastError(ERROR_IO_PENDING
);
1941 retval
= INTERNET_ReadFile(lpwh
, lpBuffersOut
->lpvBuffer
,
1942 lpBuffersOut
->dwBufferLength
, &lpBuffersOut
->dwBufferLength
,
1943 !(dwFlags
& IRF_NO_WAIT
), FALSE
);
1947 DWORD dwBytesReceived
= lpBuffersOut
->dwBufferLength
;
1948 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1949 INTERNET_STATUS_RESPONSE_RECEIVED
, &dwBytesReceived
,
1950 sizeof(dwBytesReceived
));
1954 WININET_Release( lpwh
);
1956 TRACE("-- %s (bytes read: %d)\n", retval
? "TRUE": "FALSE", lpBuffersOut
->dwBufferLength
);
1960 /***********************************************************************
1961 * InternetReadFileExW (WININET.@)
1963 * Read data from an open internet file.
1966 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1967 * lpBuffersOut [I/O] Buffer.
1968 * dwFlags [I] Flags.
1969 * dwContext [I] Context for callbacks.
1972 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1975 * Not implemented in Wine or native either (as of IE6 SP2).
1978 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1979 DWORD dwFlags
, DWORD_PTR dwContext
)
1981 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
1983 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1987 /***********************************************************************
1988 * INET_QueryOptionHelper (internal)
1990 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1991 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1993 LPWININETHANDLEHEADER lpwhh
;
1994 BOOL bSuccess
= FALSE
;
1996 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1998 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2002 case INTERNET_OPTION_HANDLE_TYPE
:
2008 WARN("Invalid hInternet handle\n");
2009 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2013 type
= lpwhh
->htype
;
2015 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type
);
2017 if (*lpdwBufferLength
< sizeof(ULONG
))
2018 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2021 memcpy(lpBuffer
, &type
, sizeof(ULONG
));
2024 *lpdwBufferLength
= sizeof(ULONG
);
2028 case INTERNET_OPTION_REQUEST_FLAGS
:
2031 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags
);
2032 if (*lpdwBufferLength
< sizeof(ULONG
))
2033 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2036 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
2039 *lpdwBufferLength
= sizeof(ULONG
);
2043 case INTERNET_OPTION_URL
:
2044 case INTERNET_OPTION_DATAFILE_NAME
:
2048 WARN("Invalid hInternet handle\n");
2049 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2052 if (lpwhh
->htype
== WH_HHTTPREQ
)
2054 LPWININETHTTPREQW lpreq
= (LPWININETHTTPREQW
) lpwhh
;
2056 static const WCHAR szFmt
[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2057 static const WCHAR szHost
[] = {'H','o','s','t',0};
2061 Host
= HTTP_GetHeader(lpreq
,szHost
);
2062 sprintfW(url
,szFmt
,Host
->lpszValue
,lpreq
->lpszPath
);
2063 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url
));
2066 sizeRequired
= WideCharToMultiByte(CP_ACP
,0,url
,-1,
2067 lpBuffer
,*lpdwBufferLength
,NULL
,NULL
);
2068 if (sizeRequired
> *lpdwBufferLength
)
2069 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2072 *lpdwBufferLength
= sizeRequired
;
2076 sizeRequired
= (lstrlenW(url
)+1) * sizeof(WCHAR
);
2077 if (*lpdwBufferLength
< sizeRequired
)
2078 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2081 strcpyW(lpBuffer
, url
);
2084 *lpdwBufferLength
= sizeRequired
;
2089 case INTERNET_OPTION_HTTP_VERSION
:
2091 if (*lpdwBufferLength
< sizeof(HTTP_VERSION_INFO
))
2092 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2096 * Presently hardcoded to 1.1
2098 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
2099 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
2102 *lpdwBufferLength
= sizeof(HTTP_VERSION_INFO
);
2105 case INTERNET_OPTION_CONNECTED_STATE
:
2107 DWORD
*pdwConnectedState
= (DWORD
*)lpBuffer
;
2108 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2110 if (*lpdwBufferLength
< sizeof(*pdwConnectedState
))
2111 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2114 *pdwConnectedState
= INTERNET_STATE_CONNECTED
;
2117 *lpdwBufferLength
= sizeof(*pdwConnectedState
);
2120 case INTERNET_OPTION_PROXY
:
2122 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
)lpwhh
;
2123 WININETAPPINFOW wai
;
2127 TRACE("Getting global proxy info\n");
2128 memset(&wai
, 0, sizeof(WININETAPPINFOW
));
2129 INTERNET_ConfigureProxyFromReg( &wai
);
2135 INTERNET_PROXY_INFOW
*pPI
= (INTERNET_PROXY_INFOW
*)lpBuffer
;
2136 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2138 if (lpwai
->lpszProxy
)
2139 proxyBytesRequired
= (lstrlenW(lpwai
->lpszProxy
) + 1) *
2141 if (lpwai
->lpszProxyBypass
)
2142 proxyBypassBytesRequired
=
2143 (lstrlenW(lpwai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
2144 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOW
) +
2145 proxyBytesRequired
+ proxyBypassBytesRequired
)
2146 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2149 LPWSTR proxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2150 sizeof(INTERNET_PROXY_INFOW
));
2151 LPWSTR proxy_bypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2152 sizeof(INTERNET_PROXY_INFOW
) +
2153 proxyBytesRequired
);
2155 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2156 pPI
->lpszProxy
= NULL
;
2157 pPI
->lpszProxyBypass
= NULL
;
2158 if (lpwai
->lpszProxy
)
2160 lstrcpyW(proxy
, lpwai
->lpszProxy
);
2161 pPI
->lpszProxy
= proxy
;
2164 if (lpwai
->lpszProxyBypass
)
2166 lstrcpyW(proxy_bypass
, lpwai
->lpszProxyBypass
);
2167 pPI
->lpszProxyBypass
= proxy_bypass
;
2171 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOW
) +
2172 proxyBytesRequired
+ proxyBypassBytesRequired
;
2176 INTERNET_PROXY_INFOA
*pPI
= (INTERNET_PROXY_INFOA
*)lpBuffer
;
2177 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2179 if (lpwai
->lpszProxy
)
2180 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2181 lpwai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
2182 if (lpwai
->lpszProxyBypass
)
2183 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2184 lpwai
->lpszProxyBypass
, -1, NULL
, 0, NULL
, NULL
);
2185 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOA
) +
2186 proxyBytesRequired
+ proxyBypassBytesRequired
)
2187 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2190 LPSTR proxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2191 sizeof(INTERNET_PROXY_INFOA
));
2192 LPSTR proxy_bypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2193 sizeof(INTERNET_PROXY_INFOA
) +
2194 proxyBytesRequired
);
2196 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2197 pPI
->lpszProxy
= NULL
;
2198 pPI
->lpszProxyBypass
= NULL
;
2199 if (lpwai
->lpszProxy
)
2201 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxy
, -1,
2202 proxy
, proxyBytesRequired
, NULL
, NULL
);
2203 pPI
->lpszProxy
= proxy
;
2206 if (lpwai
->lpszProxyBypass
)
2208 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxyBypass
,
2209 -1, proxy_bypass
, proxyBypassBytesRequired
,
2211 pPI
->lpszProxyBypass
= proxy_bypass
;
2215 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOA
) +
2216 proxyBytesRequired
+ proxyBypassBytesRequired
;
2220 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2223 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn
);
2224 if (*lpdwBufferLength
< sizeof(ULONG
))
2225 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2228 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2231 *lpdwBufferLength
= sizeof(ULONG
);
2234 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2237 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn
);
2238 if (*lpdwBufferLength
< sizeof(ULONG
))
2239 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2242 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2245 *lpdwBufferLength
= sizeof(ULONG
);
2248 case INTERNET_OPTION_SECURITY_FLAGS
:
2249 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2253 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
:
2256 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2259 if (*lpdwBufferLength
< sizeof(INTERNET_CERTIFICATE_INFOW
))
2261 *lpdwBufferLength
= sizeof(INTERNET_CERTIFICATE_INFOW
);
2262 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2264 else if (lpwhh
->htype
== WH_HHTTPREQ
)
2266 LPWININETHTTPREQW lpwhr
;
2267 PCCERT_CONTEXT context
;
2269 lpwhr
= (LPWININETHTTPREQW
)lpwhh
;
2270 context
= (PCCERT_CONTEXT
)NETCON_GetCert(&(lpwhr
->netConnection
));
2273 LPINTERNET_CERTIFICATE_INFOW info
= (LPINTERNET_CERTIFICATE_INFOW
)lpBuffer
;
2276 memset(info
,0,sizeof(INTERNET_CERTIFICATE_INFOW
));
2277 info
->ftExpiry
= context
->pCertInfo
->NotAfter
;
2278 info
->ftStart
= context
->pCertInfo
->NotBefore
;
2281 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2282 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2284 info
->lpszSubjectInfo
= LocalAlloc(0,
2285 strLen
* sizeof(WCHAR
));
2286 if (info
->lpszSubjectInfo
)
2287 CertNameToStrW(context
->dwCertEncodingType
,
2288 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2289 info
->lpszSubjectInfo
, strLen
);
2290 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2291 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2293 info
->lpszIssuerInfo
= LocalAlloc(0,
2294 strLen
* sizeof(WCHAR
));
2295 if (info
->lpszIssuerInfo
)
2296 CertNameToStrW(context
->dwCertEncodingType
,
2297 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2298 info
->lpszIssuerInfo
, strLen
);
2302 LPINTERNET_CERTIFICATE_INFOA infoA
=
2303 (LPINTERNET_CERTIFICATE_INFOA
)info
;
2305 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2306 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2308 infoA
->lpszSubjectInfo
= LocalAlloc(0, strLen
);
2309 if (infoA
->lpszSubjectInfo
)
2310 CertNameToStrA(context
->dwCertEncodingType
,
2311 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2312 infoA
->lpszSubjectInfo
, strLen
);
2313 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2314 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2316 infoA
->lpszIssuerInfo
= LocalAlloc(0, strLen
);
2317 if (infoA
->lpszIssuerInfo
)
2318 CertNameToStrA(context
->dwCertEncodingType
,
2319 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2320 infoA
->lpszIssuerInfo
, strLen
);
2323 * Contrary to MSDN, these do not appear to be set.
2325 * lpszSignatureAlgName
2326 * lpszEncryptionAlgName
2329 CertFreeCertificateContext(context
);
2334 case INTERNET_OPTION_VERSION
:
2336 TRACE("INTERNET_OPTION_VERSION\n");
2337 if (*lpdwBufferLength
< sizeof(INTERNET_VERSION_INFO
))
2338 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2341 static const INTERNET_VERSION_INFO info
= { 6, 0 };
2342 memcpy(lpBuffer
, &info
, sizeof(info
));
2343 *lpdwBufferLength
= sizeof(info
);
2349 FIXME("Stub! %d\n", dwOption
);
2353 WININET_Release( lpwhh
);
2358 /***********************************************************************
2359 * InternetQueryOptionW (WININET.@)
2361 * Queries an options on the specified handle
2368 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2369 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2371 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2374 /***********************************************************************
2375 * InternetQueryOptionA (WININET.@)
2377 * Queries an options on the specified handle
2384 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2385 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2387 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2391 /***********************************************************************
2392 * InternetSetOptionW (WININET.@)
2394 * Sets an options on the specified handle
2401 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2402 LPVOID lpBuffer
, DWORD dwBufferLength
)
2404 LPWININETHANDLEHEADER lpwhh
;
2407 TRACE("0x%08x\n", dwOption
);
2409 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2415 case INTERNET_OPTION_CALLBACK
:
2417 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2418 ret
= (set_status_callback(lpwhh
, callback
, TRUE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2421 case INTERNET_OPTION_HTTP_VERSION
:
2423 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2424 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2427 case INTERNET_OPTION_ERROR_MASK
:
2429 unsigned long flags
=*(unsigned long*)lpBuffer
;
2430 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
2433 case INTERNET_OPTION_CODEPAGE
:
2435 unsigned long codepage
=*(unsigned long*)lpBuffer
;
2436 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
2439 case INTERNET_OPTION_REQUEST_PRIORITY
:
2441 unsigned long priority
=*(unsigned long*)lpBuffer
;
2442 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
2445 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2447 unsigned long connecttimeout
=*(unsigned long*)lpBuffer
;
2448 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout
);
2451 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2453 unsigned long receivetimeout
=*(unsigned long*)lpBuffer
;
2454 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout
);
2457 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2459 unsigned long conns
=*(unsigned long*)lpBuffer
;
2460 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns
);
2463 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2465 unsigned long conns
=*(unsigned long*)lpBuffer
;
2466 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns
);
2469 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2470 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2472 case INTERNET_OPTION_END_BROWSER_SESSION
:
2473 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2475 case INTERNET_OPTION_CONNECTED_STATE
:
2476 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2478 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2479 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2481 case INTERNET_OPTION_SEND_TIMEOUT
:
2482 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2483 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2484 if (dwBufferLength
== sizeof(DWORD
))
2486 if (lpwhh
->htype
== WH_HHTTPREQ
)
2487 ret
= NETCON_set_timeout(
2488 &((LPWININETHTTPREQW
)lpwhh
)->netConnection
,
2489 dwOption
== INTERNET_OPTION_SEND_TIMEOUT
,
2490 *(DWORD
*)lpBuffer
);
2493 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2499 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2503 case INTERNET_OPTION_CONNECT_RETRIES
:
2504 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2506 case INTERNET_OPTION_CONTEXT_VALUE
:
2507 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2509 case INTERNET_OPTION_SECURITY_FLAGS
:
2510 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2513 FIXME("Option %d STUB\n",dwOption
);
2514 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2518 WININET_Release( lpwhh
);
2524 /***********************************************************************
2525 * InternetSetOptionA (WININET.@)
2527 * Sets an options on the specified handle.
2534 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2535 LPVOID lpBuffer
, DWORD dwBufferLength
)
2543 case INTERNET_OPTION_CALLBACK
:
2545 LPWININETHANDLEHEADER lpwh
;
2546 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2548 if (!(lpwh
= (LPWININETHANDLEHEADER
)WININET_GetObject(hInternet
))) return FALSE
;
2549 r
= (set_status_callback(lpwh
, callback
, FALSE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2550 WININET_Release(lpwh
);
2553 case INTERNET_OPTION_PROXY
:
2555 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2556 LPINTERNET_PROXY_INFOW piw
;
2557 DWORD proxlen
, prbylen
;
2560 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2561 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2562 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2563 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2564 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2565 piw
->dwAccessType
= pi
->dwAccessType
;
2566 prox
= (LPWSTR
) &piw
[1];
2567 prby
= &prox
[proxlen
+1];
2568 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2569 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2570 piw
->lpszProxy
= prox
;
2571 piw
->lpszProxyBypass
= prby
;
2574 case INTERNET_OPTION_USER_AGENT
:
2575 case INTERNET_OPTION_USERNAME
:
2576 case INTERNET_OPTION_PASSWORD
:
2577 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2579 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2580 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2585 wlen
= dwBufferLength
;
2588 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2590 if( lpBuffer
!= wbuffer
)
2591 HeapFree( GetProcessHeap(), 0, wbuffer
);
2597 /***********************************************************************
2598 * InternetSetOptionExA (WININET.@)
2600 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2601 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2603 FIXME("Flags %08x ignored\n", dwFlags
);
2604 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2607 /***********************************************************************
2608 * InternetSetOptionExW (WININET.@)
2610 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2611 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2613 FIXME("Flags %08x ignored\n", dwFlags
);
2614 if( dwFlags
& ~ISO_VALID_FLAGS
)
2616 INTERNET_SetLastError( ERROR_INVALID_PARAMETER
);
2619 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2622 static const WCHAR WININET_wkday
[7][4] =
2623 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2624 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2625 static const WCHAR WININET_month
[12][4] =
2626 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2627 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2628 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2630 /***********************************************************************
2631 * InternetTimeFromSystemTimeA (WININET.@)
2633 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2636 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2638 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2640 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2641 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2646 /***********************************************************************
2647 * InternetTimeFromSystemTimeW (WININET.@)
2649 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2651 static const WCHAR date
[] =
2652 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2653 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2655 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2657 if (!time
|| !string
) return FALSE
;
2659 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2662 sprintfW( string
, date
,
2663 WININET_wkday
[time
->wDayOfWeek
],
2665 WININET_month
[time
->wMonth
- 1],
2674 /***********************************************************************
2675 * InternetTimeToSystemTimeA (WININET.@)
2677 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2683 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
2685 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2686 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2690 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2691 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2692 HeapFree( GetProcessHeap(), 0, stringW
);
2697 /***********************************************************************
2698 * InternetTimeToSystemTimeW (WININET.@)
2700 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2703 const WCHAR
*s
= string
;
2706 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
2708 if (!string
|| !time
) return FALSE
;
2710 /* Windows does this too */
2711 GetSystemTime( time
);
2713 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2714 * a SYSTEMTIME structure.
2717 while (*s
&& !isalphaW( *s
)) s
++;
2718 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2719 time
->wDayOfWeek
= 7;
2721 for (i
= 0; i
< 7; i
++)
2723 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2724 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2725 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2727 time
->wDayOfWeek
= i
;
2732 if (time
->wDayOfWeek
> 6) return TRUE
;
2733 while (*s
&& !isdigitW( *s
)) s
++;
2734 time
->wDay
= strtolW( s
, &end
, 10 );
2737 while (*s
&& !isalphaW( *s
)) s
++;
2738 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2741 for (i
= 0; i
< 12; i
++)
2743 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2744 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2745 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2747 time
->wMonth
= i
+ 1;
2751 if (time
->wMonth
== 0) return TRUE
;
2753 while (*s
&& !isdigitW( *s
)) s
++;
2754 if (*s
== '\0') return TRUE
;
2755 time
->wYear
= strtolW( s
, &end
, 10 );
2758 while (*s
&& !isdigitW( *s
)) s
++;
2759 if (*s
== '\0') return TRUE
;
2760 time
->wHour
= strtolW( s
, &end
, 10 );
2763 while (*s
&& !isdigitW( *s
)) s
++;
2764 if (*s
== '\0') return TRUE
;
2765 time
->wMinute
= strtolW( s
, &end
, 10 );
2768 while (*s
&& !isdigitW( *s
)) s
++;
2769 if (*s
== '\0') return TRUE
;
2770 time
->wSecond
= strtolW( s
, &end
, 10 );
2773 time
->wMilliseconds
= 0;
2777 /***********************************************************************
2778 * InternetCheckConnectionW (WININET.@)
2780 * Pings a requested host to check internet connection
2783 * TRUE on success and FALSE on failure. If a failure then
2784 * ERROR_NOT_CONNECTED is placed into GetLastError
2787 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2790 * this is a kludge which runs the resident ping program and reads the output.
2792 * Anyone have a better idea?
2796 static const CHAR ping
[] = "ping -c 1 ";
2797 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2798 CHAR
*command
= NULL
;
2807 * Crack or set the Address
2809 if (lpszUrl
== NULL
)
2812 * According to the doc we are supposed to use the ip for the next
2813 * server in the WnInet internal server database. I have
2814 * no idea what that is or how to get it.
2816 * So someone needs to implement this.
2818 FIXME("Unimplemented with URL of NULL\n");
2823 URL_COMPONENTSW components
;
2825 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2826 components
.lpszHostName
= (LPWSTR
)&hostW
;
2827 components
.dwHostNameLength
= 1024;
2829 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2832 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2833 port
= components
.nPort
;
2834 TRACE("port: %d\n", port
);
2837 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
2839 struct sockaddr_in sin
;
2842 if (!GetAddress(hostW
, port
, &sin
))
2844 fd
= socket(sin
.sin_family
, SOCK_STREAM
, 0);
2847 if (connect(fd
, (struct sockaddr
*)&sin
, sizeof(sin
)) == 0)
2855 * Build our ping command
2857 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2858 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2859 strcpy(command
,ping
);
2860 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2861 strcat(command
,redirect
);
2863 TRACE("Ping command is : %s\n",command
);
2865 status
= system(command
);
2867 TRACE("Ping returned a code of %i\n",status
);
2869 /* Ping return code of 0 indicates success */
2876 HeapFree( GetProcessHeap(), 0, command
);
2878 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
2884 /***********************************************************************
2885 * InternetCheckConnectionA (WININET.@)
2887 * Pings a requested host to check internet connection
2890 * TRUE on success and FALSE on failure. If a failure then
2891 * ERROR_NOT_CONNECTED is placed into GetLastError
2894 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2900 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2901 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2903 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2904 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2905 HeapFree(GetProcessHeap(), 0, szUrl
);
2911 /**********************************************************
2912 * INTERNET_InternetOpenUrlW (internal)
2917 * handle of connection or NULL on failure
2919 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2920 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2922 URL_COMPONENTSW urlComponents
;
2923 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2924 WCHAR password
[1024], path
[2048], extra
[1024];
2925 HINTERNET client
= NULL
, client1
= NULL
;
2927 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2928 dwHeadersLength
, dwFlags
, dwContext
);
2930 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2931 urlComponents
.lpszScheme
= protocol
;
2932 urlComponents
.dwSchemeLength
= 32;
2933 urlComponents
.lpszHostName
= hostName
;
2934 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2935 urlComponents
.lpszUserName
= userName
;
2936 urlComponents
.dwUserNameLength
= 1024;
2937 urlComponents
.lpszPassword
= password
;
2938 urlComponents
.dwPasswordLength
= 1024;
2939 urlComponents
.lpszUrlPath
= path
;
2940 urlComponents
.dwUrlPathLength
= 2048;
2941 urlComponents
.lpszExtraInfo
= extra
;
2942 urlComponents
.dwExtraInfoLength
= 1024;
2943 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2945 switch(urlComponents
.nScheme
) {
2946 case INTERNET_SCHEME_FTP
:
2947 if(urlComponents
.nPort
== 0)
2948 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2949 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2950 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2953 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2954 if(client1
== NULL
) {
2955 InternetCloseHandle(client
);
2960 case INTERNET_SCHEME_HTTP
:
2961 case INTERNET_SCHEME_HTTPS
: {
2962 static const WCHAR szStars
[] = { '*','/','*', 0 };
2963 LPCWSTR accept
[2] = { szStars
, NULL
};
2964 if(urlComponents
.nPort
== 0) {
2965 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2966 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2968 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2970 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2971 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2972 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2976 if (urlComponents
.dwExtraInfoLength
) {
2978 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
2980 if (!(path_extra
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
2982 InternetCloseHandle(client
);
2985 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
2986 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
2987 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2988 HeapFree(GetProcessHeap(), 0, path_extra
);
2991 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2993 if(client1
== NULL
) {
2994 InternetCloseHandle(client
);
2997 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2998 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
2999 GetLastError() != ERROR_IO_PENDING
) {
3000 InternetCloseHandle(client1
);
3005 case INTERNET_SCHEME_GOPHER
:
3006 /* gopher doesn't seem to be implemented in wine, but it's supposed
3007 * to be supported by InternetOpenUrlA. */
3009 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3013 TRACE(" %p <--\n", client1
);
3018 /**********************************************************
3019 * InternetOpenUrlW (WININET.@)
3024 * handle of connection or NULL on failure
3026 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3028 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3029 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
->hdr
;
3033 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3034 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3035 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
3036 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
3039 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3040 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3042 HINTERNET ret
= NULL
;
3043 LPWININETAPPINFOW hIC
= NULL
;
3045 if (TRACE_ON(wininet
)) {
3046 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3047 dwHeadersLength
, dwFlags
, dwContext
);
3049 dump_INTERNET_FLAGS(dwFlags
);
3054 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3058 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
3059 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3060 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3064 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3065 WORKREQUEST workRequest
;
3066 struct WORKREQ_INTERNETOPENURLW
*req
;
3068 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3069 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3070 req
= &workRequest
.u
.InternetOpenUrlW
;
3071 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
3073 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
3075 req
->lpszHeaders
= 0;
3076 req
->dwHeadersLength
= dwHeadersLength
;
3077 req
->dwFlags
= dwFlags
;
3078 req
->dwContext
= dwContext
;
3080 INTERNET_AsyncCall(&workRequest
);
3082 * This is from windows.
3084 INTERNET_SetLastError(ERROR_IO_PENDING
);
3086 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3091 WININET_Release( &hIC
->hdr
);
3092 TRACE(" %p <--\n", ret
);
3097 /**********************************************************
3098 * InternetOpenUrlA (WININET.@)
3103 * handle of connection or NULL on failure
3105 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3106 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3108 HINTERNET rc
= (HINTERNET
)NULL
;
3112 LPWSTR szUrl
= NULL
;
3113 LPWSTR szHeaders
= NULL
;
3118 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
3119 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
3121 return (HINTERNET
)NULL
;
3122 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
3126 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3127 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
3129 HeapFree(GetProcessHeap(), 0, szUrl
);
3130 return (HINTERNET
)NULL
;
3132 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3135 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3136 lenHeaders
, dwFlags
, dwContext
);
3138 HeapFree(GetProcessHeap(), 0, szUrl
);
3139 HeapFree(GetProcessHeap(), 0, szHeaders
);
3145 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3147 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite
));
3151 lpwite
->dwError
= 0;
3152 lpwite
->response
[0] = '\0';
3155 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3157 HeapFree(GetProcessHeap(), 0, lpwite
);
3165 /***********************************************************************
3166 * INTERNET_SetLastError (internal)
3168 * Set last thread specific error
3173 void INTERNET_SetLastError(DWORD dwError
)
3175 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3178 lpwite
= INTERNET_AllocThreadError();
3180 SetLastError(dwError
);
3182 lpwite
->dwError
= dwError
;
3186 /***********************************************************************
3187 * INTERNET_GetLastError (internal)
3189 * Get last thread specific error
3194 DWORD
INTERNET_GetLastError(void)
3196 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3197 if (!lpwite
) return 0;
3198 /* TlsGetValue clears last error, so set it again here */
3199 SetLastError(lpwite
->dwError
);
3200 return lpwite
->dwError
;
3204 /***********************************************************************
3205 * INTERNET_WorkerThreadFunc (internal)
3207 * Worker thread execution function
3212 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3214 LPWORKREQUEST lpRequest
= lpvParam
;
3215 WORKREQUEST workRequest
;
3219 memcpy(&workRequest
, lpRequest
, sizeof(WORKREQUEST
));
3220 HeapFree(GetProcessHeap(), 0, lpRequest
);
3222 workRequest
.asyncproc(&workRequest
);
3224 WININET_Release( workRequest
.hdr
);
3229 /***********************************************************************
3230 * INTERNET_AsyncCall (internal)
3232 * Retrieves work request from queue
3237 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3240 LPWORKREQUEST lpNewRequest
;
3244 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3248 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
3250 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3253 HeapFree(GetProcessHeap(), 0, lpNewRequest
);
3254 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3261 /***********************************************************************
3262 * INTERNET_GetResponseBuffer (internal)
3267 LPSTR
INTERNET_GetResponseBuffer(void)
3269 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3271 lpwite
= INTERNET_AllocThreadError();
3273 return lpwite
->response
;
3276 /***********************************************************************
3277 * INTERNET_GetNextLine (internal)
3279 * Parse next line in directory string listing
3282 * Pointer to beginning of next line
3287 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3291 BOOL bSuccess
= FALSE
;
3293 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3298 FD_SET(nSocket
, &infd
);
3299 tv
.tv_sec
=RESPONSE_TIMEOUT
;
3302 while (nRecv
< MAX_REPLY_LEN
)
3304 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
3306 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3308 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3312 if (lpszBuffer
[nRecv
] == '\n')
3317 if (lpszBuffer
[nRecv
] != '\r')
3322 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3330 lpszBuffer
[nRecv
] = '\0';
3332 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3341 /**********************************************************
3342 * InternetQueryDataAvailable (WININET.@)
3344 * Determines how much data is available to be read.
3347 * TRUE on success, FALSE if an error occurred. If
3348 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3349 * no data is presently available, FALSE is returned with
3350 * the last error ERROR_IO_PENDING; a callback with status
3351 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3352 * data is available.
3354 void AsyncInternetQueryDataAvailableProc(WORKREQUEST
*workRequest
)
3356 LPWININETHTTPREQW lpwhr
;
3357 INTERNET_ASYNC_RESULT iar
;
3360 TRACE("INTERNETQUERYDATAAVAILABLE %p\n", workRequest
->hdr
);
3362 switch (workRequest
->hdr
->htype
)
3365 lpwhr
= (LPWININETHTTPREQW
)workRequest
->hdr
;
3366 iar
.dwResult
= NETCON_recv(&lpwhr
->netConnection
, buffer
,
3368 lpwhr
->dwContentLength
- lpwhr
->dwContentRead
),
3369 MSG_PEEK
, (int *)&iar
.dwError
);
3370 INTERNET_SendCallback(workRequest
->hdr
, workRequest
->hdr
->dwContext
,
3371 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
3372 sizeof(INTERNET_ASYNC_RESULT
));
3376 FIXME("unsupported file type\n");
3381 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3382 LPDWORD lpdwNumberOfBytesAvailble
,
3383 DWORD dwFlags
, DWORD_PTR dwContext
)
3385 LPWININETHTTPREQW lpwhr
;
3386 BOOL retval
= FALSE
;
3389 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hFile
);
3392 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
3396 TRACE("--> %p %i\n",lpwhr
,lpwhr
->hdr
.htype
);
3398 switch (lpwhr
->hdr
.htype
)
3402 if (NETCON_query_data_available(&lpwhr
->netConnection
,
3403 lpdwNumberOfBytesAvailble
) &&
3404 !*lpdwNumberOfBytesAvailble
)
3406 /* Even if we are in async mode, we need to determine whether
3407 * there is actually more data available. We do this by trying
3408 * to peek only a single byte in async mode. */
3409 BOOL async
= (lpwhr
->lpHttpSession
->lpAppInfo
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
);
3410 if (NETCON_recv(&lpwhr
->netConnection
, buffer
,
3411 min(async
? 1 : sizeof(buffer
),
3412 lpwhr
->dwContentLength
- lpwhr
->dwContentRead
),
3413 MSG_PEEK
, (int *)lpdwNumberOfBytesAvailble
) &&
3414 async
&& *lpdwNumberOfBytesAvailble
)
3416 WORKREQUEST workRequest
;
3418 *lpdwNumberOfBytesAvailble
= 0;
3419 workRequest
.asyncproc
= AsyncInternetQueryDataAvailableProc
;
3420 workRequest
.hdr
= WININET_AddRef( &lpwhr
->hdr
);
3422 retval
= INTERNET_AsyncCall(&workRequest
);
3425 WININET_Release( &lpwhr
->hdr
);
3429 INTERNET_SetLastError(ERROR_IO_PENDING
);
3437 FIXME("unsupported file type\n");
3440 WININET_Release( &lpwhr
->hdr
);
3442 TRACE("<-- %i\n",retval
);
3447 /***********************************************************************
3448 * InternetLockRequestFile (WININET.@)
3450 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3457 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3464 /***********************************************************************
3465 * InternetAutodial (WININET.@)
3467 * On windows this function is supposed to dial the default internet
3468 * connection. We don't want to have Wine dial out to the internet so
3469 * we return TRUE by default. It might be nice to check if we are connected.
3476 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3480 /* Tell that we are connected to the internet. */
3484 /***********************************************************************
3485 * InternetAutodialHangup (WININET.@)
3487 * Hangs up a connection made with InternetAutodial
3496 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3500 /* we didn't dial, we don't disconnect */
3504 /***********************************************************************
3505 * InternetCombineUrlA (WININET.@)
3507 * Combine a base URL with a relative URL
3515 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3516 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3521 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3523 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3524 dwFlags
^= ICU_NO_ENCODE
;
3525 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3530 /***********************************************************************
3531 * InternetCombineUrlW (WININET.@)
3533 * Combine a base URL with a relative URL
3541 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3542 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3547 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3549 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3550 dwFlags
^= ICU_NO_ENCODE
;
3551 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3556 /* max port num is 65535 => 5 digits */
3557 #define MAX_WORD_DIGITS 5
3559 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3560 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3561 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3562 (url)->dw##component##Length : strlen((url)->lpsz##component))
3564 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3566 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3567 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3569 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3570 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3572 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3573 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3575 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3576 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3579 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3585 /* opaque urls do not fit into the standard url hierarchy and don't have
3586 * two following slashes */
3587 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3589 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3590 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3591 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3592 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3593 (nScheme
!= INTERNET_SCHEME_FILE
);
3596 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3599 if (scheme
< INTERNET_SCHEME_FIRST
)
3601 index
= scheme
- INTERNET_SCHEME_FIRST
;
3602 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3604 return (LPCWSTR
)&url_schemes
[index
];
3607 /* we can calculate using ansi strings because we're just
3608 * calculating string length, not size
3610 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3611 LPDWORD lpdwUrlLength
)
3613 INTERNET_SCHEME nScheme
;
3617 if (lpUrlComponents
->lpszScheme
)
3619 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3620 *lpdwUrlLength
+= dwLen
;
3621 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3627 nScheme
= lpUrlComponents
->nScheme
;
3629 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3630 nScheme
= INTERNET_SCHEME_HTTP
;
3631 scheme
= INTERNET_GetSchemeString(nScheme
);
3632 *lpdwUrlLength
+= strlenW(scheme
);
3635 (*lpdwUrlLength
)++; /* ':' */
3636 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3637 *lpdwUrlLength
+= strlen("//");
3639 if (lpUrlComponents
->lpszUserName
)
3641 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3642 *lpdwUrlLength
+= strlen("@");
3646 if (lpUrlComponents
->lpszPassword
)
3648 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3653 if (lpUrlComponents
->lpszPassword
)
3655 *lpdwUrlLength
+= strlen(":");
3656 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3659 if (lpUrlComponents
->lpszHostName
)
3661 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3663 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))