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>
57 #include "wine/debug.h"
59 #define NO_SHLWAPI_STREAM
62 #include "wine/exception.h"
67 #include "wine/unicode.h"
70 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
72 #define RESPONSE_TIMEOUT 30
77 CHAR response
[MAX_REPLY_LEN
];
78 } WITHREADERROR
, *LPWITHREADERROR
;
80 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
);
81 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
82 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
);
84 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
85 static HMODULE WININET_hModule
;
87 #define HANDLE_CHUNK_SIZE 0x10
89 static CRITICAL_SECTION WININET_cs
;
90 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
93 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
94 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
96 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
98 static LPWININETHANDLEHEADER
*WININET_Handles
;
99 static UINT WININET_dwNextHandle
;
100 static UINT WININET_dwMaxHandles
;
102 HINTERNET
WININET_AllocHandle( LPWININETHANDLEHEADER info
)
104 LPWININETHANDLEHEADER
*p
;
105 UINT handle
= 0, num
;
107 EnterCriticalSection( &WININET_cs
);
108 if( !WININET_dwMaxHandles
)
110 num
= HANDLE_CHUNK_SIZE
;
111 p
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
116 WININET_dwMaxHandles
= num
;
118 if( WININET_dwMaxHandles
== WININET_dwNextHandle
)
120 num
= WININET_dwMaxHandles
+ HANDLE_CHUNK_SIZE
;
121 p
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
122 WININET_Handles
, sizeof (UINT
)* num
);
126 WININET_dwMaxHandles
= num
;
129 handle
= WININET_dwNextHandle
;
130 if( WININET_Handles
[handle
] )
131 ERR("handle isn't free but should be\n");
132 WININET_Handles
[handle
] = WININET_AddRef( info
);
134 while( WININET_Handles
[WININET_dwNextHandle
] &&
135 (WININET_dwNextHandle
< WININET_dwMaxHandles
) )
136 WININET_dwNextHandle
++;
139 LeaveCriticalSection( &WININET_cs
);
141 return info
->hInternet
= (HINTERNET
) (handle
+1);
144 LPWININETHANDLEHEADER
WININET_AddRef( LPWININETHANDLEHEADER info
)
147 TRACE("%p -> refcount = %d\n", info
, info
->dwRefCount
);
151 LPWININETHANDLEHEADER
WININET_GetObject( HINTERNET hinternet
)
153 LPWININETHANDLEHEADER info
= NULL
;
154 UINT handle
= (UINT
) hinternet
;
156 EnterCriticalSection( &WININET_cs
);
158 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) &&
159 WININET_Handles
[handle
-1] )
160 info
= WININET_AddRef( WININET_Handles
[handle
-1] );
162 LeaveCriticalSection( &WININET_cs
);
164 TRACE("handle %d -> %p\n", handle
, info
);
169 BOOL
WININET_Release( LPWININETHANDLEHEADER info
)
172 TRACE( "object %p refcount = %d\n", info
, info
->dwRefCount
);
173 if( !info
->dwRefCount
)
175 TRACE( "destroying object %p\n", info
);
176 info
->destroy( info
);
181 BOOL
WININET_FreeHandle( HINTERNET hinternet
)
184 UINT handle
= (UINT
) hinternet
;
185 LPWININETHANDLEHEADER info
= NULL
;
187 EnterCriticalSection( &WININET_cs
);
189 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) )
192 if( WININET_Handles
[handle
] )
194 info
= WININET_Handles
[handle
];
195 TRACE( "destroying handle %d for object %p\n", handle
+1, info
);
196 WININET_Handles
[handle
] = NULL
;
198 if( WININET_dwNextHandle
> handle
)
199 WININET_dwNextHandle
= handle
;
203 LeaveCriticalSection( &WININET_cs
);
206 WININET_Release( info
);
211 /***********************************************************************
212 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
215 * hinstDLL [I] handle to the DLL's instance
217 * lpvReserved [I] reserved, must be NULL
224 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
226 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
229 case DLL_PROCESS_ATTACH
:
231 g_dwTlsErrIndex
= TlsAlloc();
233 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
236 URLCacheContainers_CreateDefaults();
238 WININET_hModule
= (HMODULE
)hinstDLL
;
240 case DLL_THREAD_ATTACH
:
243 case DLL_THREAD_DETACH
:
244 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
246 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
247 HeapFree(GetProcessHeap(), 0, lpwite
);
251 case DLL_PROCESS_DETACH
:
253 URLCacheContainers_DeleteAll();
255 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
257 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
258 TlsFree(g_dwTlsErrIndex
);
267 /***********************************************************************
268 * InternetInitializeAutoProxyDll (WININET.@)
270 * Setup the internal proxy
279 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
282 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
286 /***********************************************************************
287 * DetectAutoProxyUrl (WININET.@)
289 * Auto detect the proxy url
295 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
296 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
299 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
304 /***********************************************************************
305 * INTERNET_ConfigureProxyFromReg
308 * The proxy may be specified in the form 'http=proxy.my.org'
309 * Presumably that means there can be ftp=ftpproxy.my.org too.
311 static BOOL
INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai
)
314 DWORD r
, keytype
, len
, enabled
;
315 LPCSTR lpszInternetSettings
=
316 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
317 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
319 r
= RegOpenKeyA(HKEY_CURRENT_USER
, lpszInternetSettings
, &key
);
320 if ( r
!= ERROR_SUCCESS
)
323 len
= sizeof enabled
;
324 r
= RegQueryValueExA( key
, "ProxyEnable", NULL
, &keytype
,
325 (BYTE
*)&enabled
, &len
);
326 if( (r
== ERROR_SUCCESS
) && enabled
)
328 TRACE("Proxy is enabled.\n");
330 /* figure out how much memory the proxy setting takes */
331 r
= RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
333 if( (r
== ERROR_SUCCESS
) && len
&& (keytype
== REG_SZ
) )
336 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
338 szProxy
=HeapAlloc( GetProcessHeap(), 0, len
);
339 RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
340 (BYTE
*)szProxy
, &len
);
342 /* find the http proxy, and strip away everything else */
343 p
= strstrW( szProxy
, szHttp
);
346 p
+= lstrlenW(szHttp
);
347 lstrcpyW( szProxy
, p
);
349 p
= strchrW( szProxy
, ' ' );
353 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
354 lpwai
->lpszProxy
= szProxy
;
356 TRACE("http proxy = %s\n", debugstr_w(lpwai
->lpszProxy
));
359 ERR("Couldn't read proxy server settings.\n");
362 TRACE("Proxy is not enabled.\n");
368 /***********************************************************************
369 * dump_INTERNET_FLAGS
371 * Helper function to TRACE the internet flags.
377 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
379 #define FE(x) { x, #x }
380 static const wininet_flag_info flag
[] = {
381 FE(INTERNET_FLAG_RELOAD
),
382 FE(INTERNET_FLAG_RAW_DATA
),
383 FE(INTERNET_FLAG_EXISTING_CONNECT
),
384 FE(INTERNET_FLAG_ASYNC
),
385 FE(INTERNET_FLAG_PASSIVE
),
386 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
387 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
388 FE(INTERNET_FLAG_FROM_CACHE
),
389 FE(INTERNET_FLAG_SECURE
),
390 FE(INTERNET_FLAG_KEEP_CONNECTION
),
391 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
392 FE(INTERNET_FLAG_READ_PREFETCH
),
393 FE(INTERNET_FLAG_NO_COOKIES
),
394 FE(INTERNET_FLAG_NO_AUTH
),
395 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
396 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
397 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
398 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
399 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
400 FE(INTERNET_FLAG_RESYNCHRONIZE
),
401 FE(INTERNET_FLAG_HYPERLINK
),
402 FE(INTERNET_FLAG_NO_UI
),
403 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
404 FE(INTERNET_FLAG_CACHE_ASYNC
),
405 FE(INTERNET_FLAG_FORMS_SUBMIT
),
406 FE(INTERNET_FLAG_NEED_FILE
),
407 FE(INTERNET_FLAG_TRANSFER_ASCII
),
408 FE(INTERNET_FLAG_TRANSFER_BINARY
)
413 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
414 if (flag
[i
].val
& dwFlags
) {
415 TRACE(" %s", flag
[i
].name
);
416 dwFlags
&= ~flag
[i
].val
;
420 TRACE(" Unknown flags (%08x)\n", dwFlags
);
425 /***********************************************************************
426 * InternetOpenW (WININET.@)
428 * Per-application initialization of wininet
431 * HINTERNET on success
435 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
436 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
438 LPWININETAPPINFOW lpwai
= NULL
;
439 HINTERNET handle
= NULL
;
441 if (TRACE_ON(wininet
)) {
442 #define FE(x) { x, #x }
443 static const wininet_flag_info access_type
[] = {
444 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
445 FE(INTERNET_OPEN_TYPE_DIRECT
),
446 FE(INTERNET_OPEN_TYPE_PROXY
),
447 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
451 const char *access_type_str
= "Unknown";
453 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
454 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
455 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
456 if (access_type
[i
].val
== dwAccessType
) {
457 access_type_str
= access_type
[i
].name
;
461 TRACE(" access type : %s\n", access_type_str
);
463 dump_INTERNET_FLAGS(dwFlags
);
466 /* Clear any error information */
467 INTERNET_SetLastError(0);
469 lpwai
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETAPPINFOW
));
472 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
476 lpwai
->hdr
.htype
= WH_HINIT
;
477 lpwai
->hdr
.dwFlags
= dwFlags
;
478 lpwai
->hdr
.dwRefCount
= 1;
479 lpwai
->hdr
.destroy
= INTERNET_CloseHandle
;
480 lpwai
->dwAccessType
= dwAccessType
;
481 lpwai
->lpszProxyUsername
= NULL
;
482 lpwai
->lpszProxyPassword
= NULL
;
484 handle
= WININET_AllocHandle( &lpwai
->hdr
);
487 HeapFree( GetProcessHeap(), 0, lpwai
);
488 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
492 if (NULL
!= lpszAgent
)
494 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
495 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
496 if (lpwai
->lpszAgent
)
497 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
499 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
500 INTERNET_ConfigureProxyFromReg( lpwai
);
501 else if (NULL
!= lpszProxy
)
503 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
504 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
505 if (lpwai
->lpszProxy
)
506 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
509 if (NULL
!= lpszProxyBypass
)
511 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
512 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
513 if (lpwai
->lpszProxyBypass
)
514 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
519 WININET_Release( &lpwai
->hdr
);
521 TRACE("returning %p\n", lpwai
);
527 /***********************************************************************
528 * InternetOpenA (WININET.@)
530 * Per-application initialization of wininet
533 * HINTERNET on success
537 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
538 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
540 HINTERNET rc
= (HINTERNET
)NULL
;
542 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
544 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
545 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
549 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
550 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
551 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
556 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
557 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
558 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
561 if( lpszProxyBypass
)
563 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
564 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
565 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
568 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
570 HeapFree(GetProcessHeap(), 0, szAgent
);
571 HeapFree(GetProcessHeap(), 0, szProxy
);
572 HeapFree(GetProcessHeap(), 0, szBypass
);
577 /***********************************************************************
578 * InternetGetLastResponseInfoA (WININET.@)
580 * Return last wininet error description on the calling thread
583 * TRUE on success of writing to buffer
587 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
588 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
590 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
596 *lpdwError
= lpwite
->dwError
;
599 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
600 *lpdwBufferLength
= strlen(lpszBuffer
);
603 *lpdwBufferLength
= 0;
608 *lpdwBufferLength
= 0;
614 /***********************************************************************
615 * InternetGetLastResponseInfoW (WININET.@)
617 * Return last wininet error description on the calling thread
620 * TRUE on success of writing to buffer
624 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
625 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
627 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
633 *lpdwError
= lpwite
->dwError
;
636 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
637 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
640 *lpdwBufferLength
= 0;
645 *lpdwBufferLength
= 0;
651 /***********************************************************************
652 * InternetGetConnectedState (WININET.@)
654 * Return connected state
658 * if lpdwStatus is not null, return the status (off line,
659 * modem, lan...) in it.
660 * FALSE if not connected
662 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
664 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
667 FIXME("always returning LAN connection.\n");
668 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
674 /***********************************************************************
675 * InternetGetConnectedStateExW (WININET.@)
677 * Return connected state
681 * lpdwStatus [O] Flags specifying the status of the internet connection.
682 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
683 * dwNameLen [I] Size of the buffer, in characters.
684 * dwReserved [I] Reserved. Must be set to 0.
688 * if lpdwStatus is not null, return the status (off line,
689 * modem, lan...) in it.
690 * FALSE if not connected
693 * If the system has no available network connections, an empty string is
694 * stored in lpszConnectionName. If there is a LAN connection, a localized
695 * "LAN Connection" string is stored. Presumably, if only a dial-up
696 * connection is available then the name of the dial-up connection is
697 * returned. Why any application, other than the "Internet Settings" CPL,
698 * would want to use this function instead of the simpler InternetGetConnectedStateW
699 * function is beyond me.
701 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
702 DWORD dwNameLen
, DWORD dwReserved
)
704 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
711 FIXME("always returning LAN connection.\n");
712 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
714 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
718 /***********************************************************************
719 * InternetGetConnectedStateExA (WININET.@)
721 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
722 DWORD dwNameLen
, DWORD dwReserved
)
724 LPWSTR lpwszConnectionName
= NULL
;
727 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
729 if (lpszConnectionName
&& dwNameLen
> 0)
730 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
732 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
734 if (rc
&& lpwszConnectionName
)
736 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
737 dwNameLen
, NULL
, NULL
);
739 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
746 /***********************************************************************
747 * InternetConnectW (WININET.@)
749 * Open a ftp, gopher or http session
752 * HINTERNET a session handle on success
756 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
757 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
758 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
759 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
761 LPWININETAPPINFOW hIC
;
764 TRACE("(%p, %s, %i, %s, %s, %i, %i, %i)\n", hInternet
, debugstr_w(lpszServerName
),
765 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
766 dwService
, dwFlags
, dwContext
);
770 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
774 /* Clear any error information */
775 INTERNET_SetLastError(0);
776 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
777 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
779 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
785 case INTERNET_SERVICE_FTP
:
786 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
787 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
790 case INTERNET_SERVICE_HTTP
:
791 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
792 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
795 case INTERNET_SERVICE_GOPHER
:
801 WININET_Release( &hIC
->hdr
);
803 TRACE("returning %p\n", rc
);
808 /***********************************************************************
809 * InternetConnectA (WININET.@)
811 * Open a ftp, gopher or http session
814 * HINTERNET a session handle on success
818 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
819 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
820 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
821 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
823 HINTERNET rc
= (HINTERNET
)NULL
;
825 LPWSTR szServerName
= NULL
;
826 LPWSTR szUserName
= NULL
;
827 LPWSTR szPassword
= NULL
;
831 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
832 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
833 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
837 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
838 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
839 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
843 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
844 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
845 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
849 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
850 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
852 HeapFree(GetProcessHeap(), 0, szServerName
);
853 HeapFree(GetProcessHeap(), 0, szUserName
);
854 HeapFree(GetProcessHeap(), 0, szPassword
);
859 /***********************************************************************
860 * InternetFindNextFileA (WININET.@)
862 * Continues a file search from a previous call to FindFirstFile
869 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
874 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
876 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
880 /***********************************************************************
881 * InternetFindNextFileW (WININET.@)
883 * Continues a file search from a previous call to FindFirstFile
890 static void AsyncFtpFindNextFileProc(WORKREQUEST
*workRequest
)
892 struct WORKREQ_FTPFINDNEXTW
*req
= &workRequest
->u
.FtpFindNextW
;
893 LPWININETFTPFINDNEXTW lpwh
= (LPWININETFTPFINDNEXTW
) workRequest
->hdr
;
897 FTP_FindNextFileW(lpwh
, req
->lpFindFileData
);
900 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
902 LPWININETAPPINFOW hIC
= NULL
;
903 LPWININETFTPFINDNEXTW lpwh
;
904 BOOL bSuccess
= FALSE
;
908 lpwh
= (LPWININETFTPFINDNEXTW
) WININET_GetObject( hFind
);
909 if (NULL
== lpwh
|| lpwh
->hdr
.htype
!= WH_HFTPFINDNEXT
)
911 FIXME("Only FTP supported\n");
912 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
916 hIC
= lpwh
->lpFtpSession
->lpAppInfo
;
917 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
919 WORKREQUEST workRequest
;
920 struct WORKREQ_FTPFINDNEXTW
*req
;
922 workRequest
.asyncproc
= AsyncFtpFindNextFileProc
;
923 workRequest
.hdr
= WININET_AddRef( &lpwh
->hdr
);
924 req
= &workRequest
.u
.FtpFindNextW
;
925 req
->lpFindFileData
= lpvFindData
;
927 bSuccess
= INTERNET_AsyncCall(&workRequest
);
931 bSuccess
= FTP_FindNextFileW(lpwh
, lpvFindData
);
935 WININET_Release( &lpwh
->hdr
);
939 /***********************************************************************
940 * INTERNET_CloseHandle (internal)
942 * Close internet handle
948 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
)
950 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
954 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
955 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
956 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
957 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
958 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
959 HeapFree(GetProcessHeap(), 0, lpwai
);
963 /***********************************************************************
964 * InternetCloseHandle (WININET.@)
966 * Generic close handle function
973 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
975 LPWININETHANDLEHEADER lpwh
;
977 TRACE("%p\n",hInternet
);
979 lpwh
= WININET_GetObject( hInternet
);
982 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
986 /* FIXME: native appears to send this from the equivalent of
988 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
989 INTERNET_STATUS_HANDLE_CLOSING
, &hInternet
,
992 WININET_FreeHandle( hInternet
);
993 WININET_Release( lpwh
);
999 /***********************************************************************
1000 * ConvertUrlComponentValue (Internal)
1002 * Helper function for InternetCrackUrlW
1005 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1006 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1007 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1009 TRACE("%p %d %p %d %p %p\n", lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1010 if (*dwComponentLen
!= 0)
1012 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1013 if (*lppszComponent
== NULL
)
1015 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1017 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1019 *lppszComponent
= NULL
;
1020 *dwComponentLen
= nASCIILength
;
1024 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1025 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1026 (*lppszComponent
)[ncpylen
]=0;
1027 *dwComponentLen
= ncpylen
;
1033 /***********************************************************************
1034 * InternetCrackUrlA (WININET.@)
1036 * See InternetCrackUrlW.
1038 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1039 LPURL_COMPONENTSA lpUrlComponents
)
1042 URL_COMPONENTSW UCW
;
1045 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl
), dwUrlLength
, dwFlags
, lpUrlComponents
);
1047 if (!lpszUrl
|| !*lpszUrl
)
1049 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1055 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1057 /* if dwUrlLength=-1 then nLength includes null but length to
1058 InternetCrackUrlW should not include it */
1059 if (dwUrlLength
== -1) nLength
--;
1061 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1062 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1064 memset(&UCW
,0,sizeof(UCW
));
1065 if(lpUrlComponents
->dwHostNameLength
!=0)
1066 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1067 if(lpUrlComponents
->dwUserNameLength
!=0)
1068 UCW
.dwUserNameLength
=lpUrlComponents
->dwUserNameLength
;
1069 if(lpUrlComponents
->dwPasswordLength
!=0)
1070 UCW
.dwPasswordLength
=lpUrlComponents
->dwPasswordLength
;
1071 if(lpUrlComponents
->dwUrlPathLength
!=0)
1072 UCW
.dwUrlPathLength
=lpUrlComponents
->dwUrlPathLength
;
1073 if(lpUrlComponents
->dwSchemeLength
!=0)
1074 UCW
.dwSchemeLength
=lpUrlComponents
->dwSchemeLength
;
1075 if(lpUrlComponents
->dwExtraInfoLength
!=0)
1076 UCW
.dwExtraInfoLength
=lpUrlComponents
->dwExtraInfoLength
;
1077 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
1079 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1083 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1084 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
1086 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1087 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
1089 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1090 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
1092 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1093 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
1095 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1096 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
1098 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1099 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
1101 lpUrlComponents
->nScheme
=UCW
.nScheme
;
1102 lpUrlComponents
->nPort
=UCW
.nPort
;
1103 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1105 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1106 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
1107 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
1108 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
1109 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
1114 static const WCHAR url_schemes
[][7] =
1117 {'g','o','p','h','e','r',0},
1118 {'h','t','t','p',0},
1119 {'h','t','t','p','s',0},
1120 {'f','i','l','e',0},
1121 {'n','e','w','s',0},
1122 {'m','a','i','l','t','o',0},
1126 /***********************************************************************
1127 * GetInternetSchemeW (internal)
1133 * INTERNET_SCHEME_UNKNOWN on failure
1136 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1140 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1142 if(lpszScheme
==NULL
)
1143 return INTERNET_SCHEME_UNKNOWN
;
1145 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1146 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1147 return INTERNET_SCHEME_FIRST
+ i
;
1149 return INTERNET_SCHEME_UNKNOWN
;
1152 /***********************************************************************
1153 * SetUrlComponentValueW (Internal)
1155 * Helper function for InternetCrackUrlW
1158 * lppszComponent [O] Holds the returned string
1159 * dwComponentLen [I] Holds the size of lppszComponent
1160 * [O] Holds the length of the string in lppszComponent without '\0'
1161 * lpszStart [I] Holds the string to copy from
1162 * len [I] Holds the length of lpszStart without '\0'
1169 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1171 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1173 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1176 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1178 if (*lppszComponent
== NULL
)
1180 *lppszComponent
= (LPWSTR
)lpszStart
;
1181 *dwComponentLen
= len
;
1185 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1186 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1187 (*lppszComponent
)[ncpylen
] = '\0';
1188 *dwComponentLen
= ncpylen
;
1195 /***********************************************************************
1196 * InternetCrackUrlW (WININET.@)
1198 * Break up URL into its components
1204 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1205 LPURL_COMPONENTSW lpUC
)
1209 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1212 LPCWSTR lpszParam
= NULL
;
1213 BOOL bIsAbsolute
= FALSE
;
1214 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1215 LPCWSTR lpszcp
= NULL
;
1216 LPWSTR lpszUrl_decode
= NULL
;
1217 DWORD dwUrlLength
= dwUrlLength_orig
;
1218 const WCHAR lpszSeparators
[3]={';','?',0};
1219 const WCHAR lpszSlash
[2]={'/',0};
1221 dwUrlLength
=strlenW(lpszUrl
);
1223 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl
), dwUrlLength
, dwFlags
, lpUC
);
1225 if (!lpszUrl_orig
|| !*lpszUrl_orig
)
1227 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1231 if (dwFlags
& ICU_DECODE
)
1233 lpszUrl_decode
=HeapAlloc( GetProcessHeap(), 0, dwUrlLength
* sizeof (WCHAR
) );
1234 if( InternetCanonicalizeUrlW(lpszUrl_orig
, lpszUrl_decode
, &dwUrlLength
, dwFlags
))
1236 lpszUrl
= lpszUrl_decode
;
1241 /* Determine if the URI is absolute. */
1242 while (*lpszap
!= '\0')
1244 if (isalnumW(*lpszap
))
1249 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1256 lpszcp
= lpszUrl
; /* Relative url */
1262 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1263 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1265 /* Parse <params> */
1266 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
1267 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1268 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1270 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1274 /* Get scheme first. */
1275 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1276 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1277 lpszUrl
, lpszcp
- lpszUrl
);
1279 /* Eat ':' in protocol. */
1282 /* double slash indicates the net_loc portion is present */
1283 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1287 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
1291 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1293 lpszNetLoc
= lpszParam
;
1295 else if (!lpszNetLoc
)
1296 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1304 /* [<user>[<:password>]@]<host>[:<port>] */
1305 /* First find the user and password if they exist */
1307 lpszHost
= strchrW(lpszcp
, '@');
1308 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1310 /* username and password not specified. */
1311 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1312 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1314 else /* Parse out username and password */
1316 LPCWSTR lpszUser
= lpszcp
;
1317 LPCWSTR lpszPasswd
= lpszHost
;
1319 while (lpszcp
< lpszHost
)
1322 lpszPasswd
= lpszcp
;
1327 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1328 lpszUser
, lpszPasswd
- lpszUser
);
1330 if (lpszPasswd
!= lpszHost
)
1332 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1333 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1334 lpszHost
- lpszPasswd
);
1336 lpszcp
++; /* Advance to beginning of host */
1339 /* Parse <host><:port> */
1342 lpszPort
= lpszNetLoc
;
1344 /* special case for res:// URLs: there is no port here, so the host is the
1345 entire string up to the first '/' */
1346 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1348 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1349 lpszHost
, lpszPort
- lpszHost
);
1354 while (lpszcp
< lpszNetLoc
)
1362 /* If the scheme is "file" and the host is just one letter, it's not a host */
1363 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1366 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1371 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1372 lpszHost
, lpszPort
- lpszHost
);
1373 if (lpszPort
!= lpszNetLoc
)
1374 lpUC
->nPort
= atoiW(++lpszPort
);
1375 else switch (lpUC
->nScheme
)
1377 case INTERNET_SCHEME_HTTP
:
1378 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1380 case INTERNET_SCHEME_HTTPS
:
1381 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1383 case INTERNET_SCHEME_FTP
:
1384 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1386 case INTERNET_SCHEME_GOPHER
:
1387 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1398 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1399 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1400 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1405 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1406 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1407 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1408 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1411 /* Here lpszcp points to:
1413 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1414 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1416 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1420 /* Only truncate the parameter list if it's already been saved
1421 * in lpUC->lpszExtraInfo.
1423 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1424 len
= lpszParam
- lpszcp
;
1427 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1428 * newlines if necessary.
1430 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1431 if (lpsznewline
!= NULL
)
1432 len
= lpsznewline
- lpszcp
;
1434 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1436 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1441 lpUC
->dwUrlPathLength
= 0;
1444 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1445 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1446 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1447 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1448 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1450 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1454 /***********************************************************************
1455 * InternetAttemptConnect (WININET.@)
1457 * Attempt to make a connection to the internet
1460 * ERROR_SUCCESS on success
1461 * Error value on failure
1464 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1467 return ERROR_SUCCESS
;
1471 /***********************************************************************
1472 * InternetCanonicalizeUrlA (WININET.@)
1474 * Escape unsafe characters and spaces
1481 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1482 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1485 DWORD dwURLFlags
= 0x80000000; /* Don't know what this means */
1486 if(dwFlags
& ICU_DECODE
)
1488 dwURLFlags
|= URL_UNESCAPE
;
1489 dwFlags
&= ~ICU_DECODE
;
1492 if(dwFlags
& ICU_ESCAPE
)
1494 dwURLFlags
|= URL_UNESCAPE
;
1495 dwFlags
&= ~ICU_ESCAPE
;
1497 if(dwFlags
& ICU_BROWSER_MODE
)
1499 dwURLFlags
|= URL_BROWSER_MODE
;
1500 dwFlags
&= ~ICU_BROWSER_MODE
;
1503 FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1504 TRACE("%s %p %p %08x\n", debugstr_a(lpszUrl
), lpszBuffer
,
1505 lpdwBufferLength
, dwURLFlags
);
1507 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1508 dwFlags
^= ICU_NO_ENCODE
;
1510 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1512 return (hr
== S_OK
) ? TRUE
: FALSE
;
1515 /***********************************************************************
1516 * InternetCanonicalizeUrlW (WININET.@)
1518 * Escape unsafe characters and spaces
1525 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1526 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1529 DWORD dwURLFlags
= 0x80000000; /* Don't know what this means */
1530 if(dwFlags
& ICU_DECODE
)
1532 dwURLFlags
|= URL_UNESCAPE
;
1533 dwFlags
&= ~ICU_DECODE
;
1536 if(dwFlags
& ICU_ESCAPE
)
1538 dwURLFlags
|= URL_UNESCAPE
;
1539 dwFlags
&= ~ICU_ESCAPE
;
1541 if(dwFlags
& ICU_BROWSER_MODE
)
1543 dwURLFlags
|= URL_BROWSER_MODE
;
1544 dwFlags
&= ~ICU_BROWSER_MODE
;
1547 FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1548 TRACE("%s %p %p %08x\n", debugstr_w(lpszUrl
), lpszBuffer
,
1549 lpdwBufferLength
, dwURLFlags
);
1551 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1552 dwFlags
^= ICU_NO_ENCODE
;
1554 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1556 return (hr
== S_OK
) ? TRUE
: FALSE
;
1560 /***********************************************************************
1561 * InternetSetStatusCallbackA (WININET.@)
1563 * Sets up a callback function which is called as progress is made
1564 * during an operation.
1567 * Previous callback or NULL on success
1568 * INTERNET_INVALID_STATUS_CALLBACK on failure
1571 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1572 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1574 INTERNET_STATUS_CALLBACK retVal
;
1575 LPWININETHANDLEHEADER lpwh
;
1577 TRACE("0x%08x\n", (ULONG
)hInternet
);
1579 lpwh
= WININET_GetObject(hInternet
);
1581 return INTERNET_INVALID_STATUS_CALLBACK
;
1583 lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1584 retVal
= lpwh
->lpfnStatusCB
;
1585 lpwh
->lpfnStatusCB
= lpfnIntCB
;
1587 WININET_Release( lpwh
);
1592 /***********************************************************************
1593 * InternetSetStatusCallbackW (WININET.@)
1595 * Sets up a callback function which is called as progress is made
1596 * during an operation.
1599 * Previous callback or NULL on success
1600 * INTERNET_INVALID_STATUS_CALLBACK on failure
1603 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1604 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1606 INTERNET_STATUS_CALLBACK retVal
;
1607 LPWININETHANDLEHEADER lpwh
;
1609 TRACE("0x%08x\n", (ULONG
)hInternet
);
1611 lpwh
= WININET_GetObject(hInternet
);
1613 return INTERNET_INVALID_STATUS_CALLBACK
;
1615 lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1616 retVal
= lpwh
->lpfnStatusCB
;
1617 lpwh
->lpfnStatusCB
= lpfnIntCB
;
1619 WININET_Release( lpwh
);
1624 /***********************************************************************
1625 * InternetSetFilePointer (WININET.@)
1627 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1628 PVOID pReserved
, DWORD dwMoveContext
, DWORD dwContext
)
1634 /***********************************************************************
1635 * InternetWriteFile (WININET.@)
1637 * Write data to an open internet file
1644 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1645 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1647 BOOL retval
= FALSE
;
1649 LPWININETHANDLEHEADER lpwh
;
1652 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1656 switch (lpwh
->htype
)
1660 LPWININETHTTPREQW lpwhr
;
1661 lpwhr
= (LPWININETHTTPREQW
)lpwh
;
1663 TRACE("HTTPREQ %i\n",dwNumOfBytesToWrite
);
1664 retval
= NETCON_send(&lpwhr
->netConnection
, lpBuffer
,
1665 dwNumOfBytesToWrite
, 0, (LPINT
)lpdwNumOfBytesWritten
);
1667 WININET_Release( lpwh
);
1673 nSocket
= ((LPWININETFTPFILE
)lpwh
)->nDataSocket
;
1682 int res
= send(nSocket
, lpBuffer
, dwNumOfBytesToWrite
, 0);
1683 retval
= (res
>= 0);
1684 *lpdwNumOfBytesWritten
= retval
? res
: 0;
1686 WININET_Release( lpwh
);
1692 BOOL
INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh
, LPVOID lpBuffer
,
1693 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
,
1694 BOOL bWait
, BOOL bSendCompletionStatus
)
1696 BOOL retval
= FALSE
;
1699 LPWININETHTTPREQW lpwhr
;
1701 /* FIXME: this should use NETCON functions! */
1702 switch (lpwh
->htype
)
1705 lpwhr
= (LPWININETHTTPREQW
)lpwh
;
1707 if (!NETCON_recv(&lpwhr
->netConnection
, lpBuffer
,
1708 min(dwNumOfBytesToRead
, lpwhr
->dwContentLength
- lpwhr
->dwContentRead
),
1709 bWait
? MSG_WAITALL
: 0, &bytes_read
))
1712 if (((lpwhr
->dwContentLength
!= -1) &&
1713 (lpwhr
->dwContentRead
!= lpwhr
->dwContentLength
)))
1714 ERR("not all data received %d/%d\n", lpwhr
->dwContentRead
,
1715 lpwhr
->dwContentLength
);
1717 /* always returns TRUE, even if the network layer returns an
1719 *pdwNumOfBytesRead
= 0;
1720 HTTP_FinishedReading(lpwhr
);
1725 lpwhr
->dwContentRead
+= bytes_read
;
1726 *pdwNumOfBytesRead
= bytes_read
;
1727 if (!bytes_read
&& (lpwhr
->dwContentRead
== lpwhr
->dwContentLength
))
1728 retval
= HTTP_FinishedReading(lpwhr
);
1735 /* FIXME: FTP should use NETCON_ stuff */
1736 nSocket
= ((LPWININETFTPFILE
)lpwh
)->nDataSocket
;
1739 int res
= recv(nSocket
, lpBuffer
, dwNumOfBytesToRead
, bWait
? MSG_WAITALL
: 0);
1740 retval
= (res
>= 0);
1741 *pdwNumOfBytesRead
= retval
? res
: 0;
1749 if (bSendCompletionStatus
)
1751 INTERNET_ASYNC_RESULT iar
;
1753 iar
.dwResult
= retval
;
1754 iar
.dwError
= iar
.dwError
= retval
? ERROR_SUCCESS
:
1755 INTERNET_GetLastError();
1757 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1758 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
1759 sizeof(INTERNET_ASYNC_RESULT
));
1764 /***********************************************************************
1765 * InternetReadFile (WININET.@)
1767 * Read data from an open internet file
1774 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1775 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1777 LPWININETHANDLEHEADER lpwh
;
1780 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1782 lpwh
= WININET_GetObject( hFile
);
1785 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1789 retval
= INTERNET_ReadFile(lpwh
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, TRUE
, FALSE
);
1790 WININET_Release( lpwh
);
1792 TRACE("-- %s (bytes read: %d)\n", retval
? "TRUE": "FALSE", pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1796 /***********************************************************************
1797 * InternetReadFileExA (WININET.@)
1799 * Read data from an open internet file
1802 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1803 * lpBuffersOut [I/O] Buffer.
1804 * dwFlags [I] Flags. See notes.
1805 * dwContext [I] Context for callbacks.
1812 * The parameter dwFlags include zero or more of the following flags:
1813 *|IRF_ASYNC - Makes the call asynchronous.
1814 *|IRF_SYNC - Makes the call synchronous.
1815 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1816 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1818 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1821 * InternetOpenUrlA(), HttpOpenRequestA()
1823 void AsyncInternetReadFileExProc(WORKREQUEST
*workRequest
)
1825 struct WORKREQ_INTERNETREADFILEEXA
const *req
= &workRequest
->u
.InternetReadFileExA
;
1827 TRACE("INTERNETREADFILEEXA %p\n", workRequest
->hdr
);
1829 INTERNET_ReadFile(workRequest
->hdr
, req
->lpBuffersOut
->lpvBuffer
,
1830 req
->lpBuffersOut
->dwBufferLength
,
1831 &req
->lpBuffersOut
->dwBufferLength
, TRUE
, TRUE
);
1834 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1835 DWORD dwFlags
, DWORD dwContext
)
1837 BOOL retval
= FALSE
;
1838 LPWININETHANDLEHEADER lpwh
;
1840 TRACE("(%p %p 0x%x 0x%x)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1842 if (dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
))
1843 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
));
1845 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
))
1847 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1851 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1854 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1858 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1859 INTERNET_STATUS_RECEIVING_RESPONSE
, NULL
, 0);
1861 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1862 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1863 if (dwFlags
& IRF_ASYNC
)
1865 DWORD dwDataAvailable
= 0;
1867 if (lpwh
->htype
== WH_HHTTPREQ
)
1868 NETCON_query_data_available(&((LPWININETHTTPREQW
)lpwh
)->netConnection
,
1871 if (!dwDataAvailable
)
1873 WORKREQUEST workRequest
;
1874 struct WORKREQ_INTERNETREADFILEEXA
*req
;
1876 workRequest
.asyncproc
= AsyncInternetReadFileExProc
;
1877 workRequest
.hdr
= WININET_AddRef( lpwh
);
1878 req
= &workRequest
.u
.InternetReadFileExA
;
1879 req
->lpBuffersOut
= lpBuffersOut
;
1881 retval
= INTERNET_AsyncCall(&workRequest
);
1882 if (!retval
) return FALSE
;
1884 INTERNET_SetLastError(ERROR_IO_PENDING
);
1889 retval
= INTERNET_ReadFile(lpwh
, lpBuffersOut
->lpvBuffer
,
1890 lpBuffersOut
->dwBufferLength
, &lpBuffersOut
->dwBufferLength
,
1891 !(dwFlags
& IRF_NO_WAIT
), FALSE
);
1895 DWORD dwBytesReceived
= lpBuffersOut
->dwBufferLength
;
1896 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1897 INTERNET_STATUS_RESPONSE_RECEIVED
, &dwBytesReceived
,
1898 sizeof(dwBytesReceived
));
1901 WININET_Release( lpwh
);
1903 TRACE("-- %s (bytes read: %d)\n", retval
? "TRUE": "FALSE", lpBuffersOut
->dwBufferLength
);
1907 /***********************************************************************
1908 * InternetReadFileExW (WININET.@)
1910 * Read data from an open internet file.
1913 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1914 * lpBuffersOut [I/O] Buffer.
1915 * dwFlags [I] Flags.
1916 * dwContext [I] Context for callbacks.
1919 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1922 * Not implemented in Wine or native either (as of IE6 SP2).
1925 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1926 DWORD dwFlags
, DWORD dwContext
)
1928 ERR("(%p, %p, 0x%x, 0x%x): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
1930 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1934 /***********************************************************************
1935 * INET_QueryOptionHelper (internal)
1937 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1938 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1940 LPWININETHANDLEHEADER lpwhh
;
1941 BOOL bSuccess
= FALSE
;
1943 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1945 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
1948 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1954 case INTERNET_OPTION_HANDLE_TYPE
:
1960 WARN("Invalid hInternet handle\n");
1961 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1965 type
= lpwhh
->htype
;
1967 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type
);
1969 if (*lpdwBufferLength
< sizeof(ULONG
))
1970 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1973 memcpy(lpBuffer
, &type
, sizeof(ULONG
));
1976 *lpdwBufferLength
= sizeof(ULONG
);
1980 case INTERNET_OPTION_REQUEST_FLAGS
:
1983 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags
);
1984 if (*lpdwBufferLength
< sizeof(ULONG
))
1985 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1988 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
1991 *lpdwBufferLength
= sizeof(ULONG
);
1995 case INTERNET_OPTION_URL
:
1996 case INTERNET_OPTION_DATAFILE_NAME
:
2000 WARN("Invalid hInternet handle\n");
2001 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2004 if (lpwhh
->htype
== WH_HHTTPREQ
)
2006 LPWININETHTTPREQW lpreq
= (LPWININETHTTPREQW
) lpwhh
;
2008 static const WCHAR szFmt
[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2009 static const WCHAR szHost
[] = {'H','o','s','t',0};
2013 Host
= HTTP_GetHeader(lpreq
,szHost
);
2014 sprintfW(url
,szFmt
,Host
->lpszValue
,lpreq
->lpszPath
);
2015 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url
));
2018 sizeRequired
= WideCharToMultiByte(CP_ACP
,0,url
,-1,
2019 lpBuffer
,*lpdwBufferLength
,NULL
,NULL
);
2020 if (sizeRequired
> *lpdwBufferLength
)
2021 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2024 *lpdwBufferLength
= sizeRequired
;
2028 sizeRequired
= (lstrlenW(url
)+1) * sizeof(WCHAR
);
2029 if (*lpdwBufferLength
< sizeRequired
)
2030 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2033 strcpyW(lpBuffer
, url
);
2036 *lpdwBufferLength
= sizeRequired
;
2041 case INTERNET_OPTION_HTTP_VERSION
:
2043 if (*lpdwBufferLength
< sizeof(HTTP_VERSION_INFO
))
2044 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2048 * Presently hardcoded to 1.1
2050 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
2051 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
2054 *lpdwBufferLength
= sizeof(HTTP_VERSION_INFO
);
2057 case INTERNET_OPTION_CONNECTED_STATE
:
2059 DWORD
*pdwConnectedState
= (DWORD
*)lpBuffer
;
2060 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2062 if (*lpdwBufferLength
< sizeof(*pdwConnectedState
))
2063 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2066 *pdwConnectedState
= INTERNET_STATE_CONNECTED
;
2069 *lpdwBufferLength
= sizeof(*pdwConnectedState
);
2072 case INTERNET_OPTION_PROXY
:
2074 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
)lpwhh
;
2075 WININETAPPINFOW wai
;
2079 TRACE("Getting global proxy info\n");
2080 memset(&wai
, 0, sizeof(WININETAPPINFOW
));
2081 INTERNET_ConfigureProxyFromReg( &wai
);
2087 INTERNET_PROXY_INFOW
*pPI
= (INTERNET_PROXY_INFOW
*)lpBuffer
;
2088 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2090 if (lpwai
->lpszProxy
)
2091 proxyBytesRequired
= (lstrlenW(lpwai
->lpszProxy
) + 1) *
2093 if (lpwai
->lpszProxyBypass
)
2094 proxyBypassBytesRequired
=
2095 (lstrlenW(lpwai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
2096 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOW
) +
2097 proxyBytesRequired
+ proxyBypassBytesRequired
)
2098 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2101 LPWSTR proxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2102 sizeof(INTERNET_PROXY_INFOW
));
2103 LPWSTR proxy_bypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2104 sizeof(INTERNET_PROXY_INFOW
) +
2105 proxyBytesRequired
);
2107 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2108 if (lpwai
->lpszProxy
)
2110 lstrcpyW(proxy
, lpwai
->lpszProxy
);
2116 pPI
->lpszProxy
= proxy
;
2118 if (lpwai
->lpszProxyBypass
)
2120 lstrcpyW(proxy_bypass
, lpwai
->lpszProxyBypass
);
2126 pPI
->lpszProxyBypass
= proxy_bypass
;
2129 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOW
) +
2130 proxyBytesRequired
+ proxyBypassBytesRequired
;
2134 INTERNET_PROXY_INFOA
*pPI
= (INTERNET_PROXY_INFOA
*)lpBuffer
;
2135 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2137 if (lpwai
->lpszProxy
)
2138 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2139 lpwai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
2140 if (lpwai
->lpszProxyBypass
)
2141 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2142 lpwai
->lpszProxyBypass
, -1, NULL
, 0, NULL
, NULL
);
2143 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOA
) +
2144 proxyBytesRequired
+ proxyBypassBytesRequired
)
2145 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2148 LPSTR proxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2149 sizeof(INTERNET_PROXY_INFOA
));
2150 LPSTR proxy_bypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2151 sizeof(INTERNET_PROXY_INFOA
) +
2152 proxyBytesRequired
);
2154 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2155 if (lpwai
->lpszProxy
)
2157 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxy
, -1,
2158 proxy
, proxyBytesRequired
, NULL
, NULL
);
2164 pPI
->lpszProxy
= proxy
;
2166 if (lpwai
->lpszProxyBypass
)
2168 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxyBypass
,
2169 -1, proxy_bypass
, proxyBypassBytesRequired
,
2174 *proxy_bypass
= '\0';
2176 pPI
->lpszProxyBypass
= proxy_bypass
;
2179 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOA
) +
2180 proxyBytesRequired
+ proxyBypassBytesRequired
;
2184 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2187 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn
);
2188 if (*lpdwBufferLength
< sizeof(ULONG
))
2189 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2192 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2195 *lpdwBufferLength
= sizeof(ULONG
);
2198 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2201 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn
);
2202 if (*lpdwBufferLength
< sizeof(ULONG
))
2203 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2206 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2209 *lpdwBufferLength
= sizeof(ULONG
);
2212 case INTERNET_OPTION_SECURITY_FLAGS
:
2213 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2216 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
:
2217 if (*lpdwBufferLength
< sizeof(INTERNET_CERTIFICATE_INFOW
))
2219 *lpdwBufferLength
= sizeof(INTERNET_CERTIFICATE_INFOW
);
2220 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2222 else if (lpwhh
->htype
== WH_HHTTPREQ
)
2224 LPWININETHTTPREQW lpwhr
;
2225 PCCERT_CONTEXT context
;
2227 lpwhr
= (LPWININETHTTPREQW
)lpwhh
;
2228 context
= (PCCERT_CONTEXT
)NETCON_GetCert(&(lpwhr
->netConnection
));
2231 LPINTERNET_CERTIFICATE_INFOW info
= (LPINTERNET_CERTIFICATE_INFOW
)lpBuffer
;
2234 memset(info
,0,sizeof(INTERNET_CERTIFICATE_INFOW
));
2235 info
->ftExpiry
= context
->pCertInfo
->NotAfter
;
2236 info
->ftStart
= context
->pCertInfo
->NotBefore
;
2239 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2240 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2242 info
->lpszSubjectInfo
= LocalAlloc(0,
2243 strLen
* sizeof(WCHAR
));
2244 if (info
->lpszSubjectInfo
)
2245 CertNameToStrW(context
->dwCertEncodingType
,
2246 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2247 info
->lpszSubjectInfo
, strLen
);
2248 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2249 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2251 info
->lpszIssuerInfo
= LocalAlloc(0,
2252 strLen
* sizeof(WCHAR
));
2253 if (info
->lpszIssuerInfo
)
2254 CertNameToStrW(context
->dwCertEncodingType
,
2255 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2256 info
->lpszIssuerInfo
, strLen
);
2260 LPINTERNET_CERTIFICATE_INFOA infoA
=
2261 (LPINTERNET_CERTIFICATE_INFOA
)info
;
2263 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2264 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2266 infoA
->lpszSubjectInfo
= LocalAlloc(0, strLen
);
2267 if (infoA
->lpszSubjectInfo
)
2268 CertNameToStrA(context
->dwCertEncodingType
,
2269 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2270 infoA
->lpszSubjectInfo
, strLen
);
2271 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2272 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2274 infoA
->lpszIssuerInfo
= LocalAlloc(0, strLen
);
2275 if (infoA
->lpszIssuerInfo
)
2276 CertNameToStrA(context
->dwCertEncodingType
,
2277 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2278 infoA
->lpszIssuerInfo
, strLen
);
2281 * Contrary to MSDN, these do not appear to be set.
2283 * lpszSignatureAlgName
2284 * lpszEncryptionAlgName
2287 CertFreeCertificateContext(context
);
2293 FIXME("Stub! %d\n", dwOption
);
2297 WININET_Release( lpwhh
);
2302 /***********************************************************************
2303 * InternetQueryOptionW (WININET.@)
2305 * Queries an options on the specified handle
2312 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2313 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2315 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2318 /***********************************************************************
2319 * InternetQueryOptionA (WININET.@)
2321 * Queries an options on the specified handle
2328 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2329 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2331 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2335 /***********************************************************************
2336 * InternetSetOptionW (WININET.@)
2338 * Sets an options on the specified handle
2345 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2346 LPVOID lpBuffer
, DWORD dwBufferLength
)
2348 LPWININETHANDLEHEADER lpwhh
;
2351 TRACE("0x%08x\n", dwOption
);
2353 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2359 case INTERNET_OPTION_HTTP_VERSION
:
2361 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2362 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2365 case INTERNET_OPTION_ERROR_MASK
:
2367 unsigned long flags
=*(unsigned long*)lpBuffer
;
2368 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
2371 case INTERNET_OPTION_CODEPAGE
:
2373 unsigned long codepage
=*(unsigned long*)lpBuffer
;
2374 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
2377 case INTERNET_OPTION_REQUEST_PRIORITY
:
2379 unsigned long priority
=*(unsigned long*)lpBuffer
;
2380 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
2383 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2385 unsigned long connecttimeout
=*(unsigned long*)lpBuffer
;
2386 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout
);
2389 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2391 unsigned long receivetimeout
=*(unsigned long*)lpBuffer
;
2392 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout
);
2395 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2397 unsigned long conns
=*(unsigned long*)lpBuffer
;
2398 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns
);
2401 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2403 unsigned long conns
=*(unsigned long*)lpBuffer
;
2404 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns
);
2407 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2408 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2410 case INTERNET_OPTION_END_BROWSER_SESSION
:
2411 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2413 case INTERNET_OPTION_CONNECTED_STATE
:
2414 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2416 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2417 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2419 case INTERNET_OPTION_SEND_TIMEOUT
:
2420 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2421 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2422 if (dwBufferLength
== sizeof(DWORD
))
2424 if (lpwhh
->htype
== WH_HHTTPREQ
)
2425 ret
= NETCON_set_timeout(
2426 &((LPWININETHTTPREQW
)lpwhh
)->netConnection
,
2427 dwOption
== INTERNET_OPTION_SEND_TIMEOUT
,
2428 *(DWORD
*)lpBuffer
);
2431 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2437 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2441 case INTERNET_OPTION_CONNECT_RETRIES
:
2442 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2444 case INTERNET_OPTION_CONTEXT_VALUE
:
2445 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2447 case INTERNET_OPTION_SECURITY_FLAGS
:
2448 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2451 FIXME("Option %d STUB\n",dwOption
);
2452 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2456 WININET_Release( lpwhh
);
2462 /***********************************************************************
2463 * InternetSetOptionA (WININET.@)
2465 * Sets an options on the specified handle.
2472 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2473 LPVOID lpBuffer
, DWORD dwBufferLength
)
2481 case INTERNET_OPTION_PROXY
:
2483 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2484 LPINTERNET_PROXY_INFOW piw
;
2485 DWORD proxlen
, prbylen
;
2488 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2489 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2490 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2491 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2492 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2493 piw
->dwAccessType
= pi
->dwAccessType
;
2494 prox
= (LPWSTR
) &piw
[1];
2495 prby
= &prox
[proxlen
+1];
2496 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2497 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2498 piw
->lpszProxy
= prox
;
2499 piw
->lpszProxyBypass
= prby
;
2502 case INTERNET_OPTION_USER_AGENT
:
2503 case INTERNET_OPTION_USERNAME
:
2504 case INTERNET_OPTION_PASSWORD
:
2505 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2507 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2508 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2513 wlen
= dwBufferLength
;
2516 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2518 if( lpBuffer
!= wbuffer
)
2519 HeapFree( GetProcessHeap(), 0, wbuffer
);
2525 /***********************************************************************
2526 * InternetSetOptionExA (WININET.@)
2528 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2529 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2531 FIXME("Flags %08x ignored\n", dwFlags
);
2532 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2535 /***********************************************************************
2536 * InternetSetOptionExW (WININET.@)
2538 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2539 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2541 FIXME("Flags %08x ignored\n", dwFlags
);
2542 if( dwFlags
& ~ISO_VALID_FLAGS
)
2544 INTERNET_SetLastError( ERROR_INVALID_PARAMETER
);
2547 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2550 static const WCHAR WININET_wkday
[7][4] =
2551 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2552 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2553 static const WCHAR WININET_month
[12][4] =
2554 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2555 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2556 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2558 /***********************************************************************
2559 * InternetTimeFromSystemTimeA (WININET.@)
2561 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2564 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2566 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2568 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2569 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2574 /***********************************************************************
2575 * InternetTimeFromSystemTimeW (WININET.@)
2577 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2579 static const WCHAR date
[] =
2580 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2581 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2583 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2585 if (!time
|| !string
) return FALSE
;
2587 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2590 sprintfW( string
, date
,
2591 WININET_wkday
[time
->wDayOfWeek
],
2593 WININET_month
[time
->wMonth
- 1],
2602 /***********************************************************************
2603 * InternetTimeToSystemTimeA (WININET.@)
2605 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2611 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
2613 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2614 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2618 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2619 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2620 HeapFree( GetProcessHeap(), 0, stringW
);
2625 /***********************************************************************
2626 * InternetTimeToSystemTimeW (WININET.@)
2628 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2631 const WCHAR
*s
= string
;
2634 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
2636 if (!string
|| !time
) return FALSE
;
2638 /* Windows does this too */
2639 GetSystemTime( time
);
2641 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2642 * a SYSTEMTIME structure.
2645 while (*s
&& !isalphaW( *s
)) s
++;
2646 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2647 time
->wDayOfWeek
= 7;
2649 for (i
= 0; i
< 7; i
++)
2651 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2652 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2653 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2655 time
->wDayOfWeek
= i
;
2660 if (time
->wDayOfWeek
> 6) return TRUE
;
2661 while (*s
&& !isdigitW( *s
)) s
++;
2662 time
->wDay
= strtolW( s
, &end
, 10 );
2665 while (*s
&& !isalphaW( *s
)) s
++;
2666 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2669 for (i
= 0; i
< 12; i
++)
2671 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2672 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2673 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2675 time
->wMonth
= i
+ 1;
2679 if (time
->wMonth
== 0) return TRUE
;
2681 while (*s
&& !isdigitW( *s
)) s
++;
2682 if (*s
== '\0') return TRUE
;
2683 time
->wYear
= strtolW( s
, &end
, 10 );
2686 while (*s
&& !isdigitW( *s
)) s
++;
2687 if (*s
== '\0') return TRUE
;
2688 time
->wHour
= strtolW( s
, &end
, 10 );
2691 while (*s
&& !isdigitW( *s
)) s
++;
2692 if (*s
== '\0') return TRUE
;
2693 time
->wMinute
= strtolW( s
, &end
, 10 );
2696 while (*s
&& !isdigitW( *s
)) s
++;
2697 if (*s
== '\0') return TRUE
;
2698 time
->wSecond
= strtolW( s
, &end
, 10 );
2701 time
->wMilliseconds
= 0;
2705 /***********************************************************************
2706 * InternetCheckConnectionW (WININET.@)
2708 * Pings a requested host to check internet connection
2711 * TRUE on success and FALSE on failure. If a failure then
2712 * ERROR_NOT_CONNECTED is placed into GetLastError
2715 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2718 * this is a kludge which runs the resident ping program and reads the output.
2720 * Anyone have a better idea?
2724 static const CHAR ping
[] = "ping -c 1 ";
2725 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2726 CHAR
*command
= NULL
;
2734 * Crack or set the Address
2736 if (lpszUrl
== NULL
)
2739 * According to the doc we are supost to use the ip for the next
2740 * server in the WnInet internal server database. I have
2741 * no idea what that is or how to get it.
2743 * So someone needs to implement this.
2745 FIXME("Unimplemented with URL of NULL\n");
2750 URL_COMPONENTSW components
;
2752 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2753 components
.lpszHostName
= (LPWSTR
)&hostW
;
2754 components
.dwHostNameLength
= 1024;
2756 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2759 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2763 * Build our ping command
2765 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2766 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2767 strcpy(command
,ping
);
2768 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2769 strcat(command
,redirect
);
2771 TRACE("Ping command is : %s\n",command
);
2773 status
= system(command
);
2775 TRACE("Ping returned a code of %i\n",status
);
2777 /* Ping return code of 0 indicates success */
2783 HeapFree( GetProcessHeap(), 0, command
);
2785 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
2791 /***********************************************************************
2792 * InternetCheckConnectionA (WININET.@)
2794 * Pings a requested host to check internet connection
2797 * TRUE on success and FALSE on failure. If a failure then
2798 * ERROR_NOT_CONNECTED is placed into GetLastError
2801 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2807 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2808 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2810 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2811 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2812 HeapFree(GetProcessHeap(), 0, szUrl
);
2818 /**********************************************************
2819 * INTERNET_InternetOpenUrlW (internal)
2824 * handle of connection or NULL on failure
2826 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2827 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2829 URL_COMPONENTSW urlComponents
;
2830 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2831 WCHAR password
[1024], path
[2048], extra
[1024];
2832 HINTERNET client
= NULL
, client1
= NULL
;
2834 TRACE("(%p, %s, %s, %08x, %08x, %08x)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2835 dwHeadersLength
, dwFlags
, dwContext
);
2837 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2838 urlComponents
.lpszScheme
= protocol
;
2839 urlComponents
.dwSchemeLength
= 32;
2840 urlComponents
.lpszHostName
= hostName
;
2841 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2842 urlComponents
.lpszUserName
= userName
;
2843 urlComponents
.dwUserNameLength
= 1024;
2844 urlComponents
.lpszPassword
= password
;
2845 urlComponents
.dwPasswordLength
= 1024;
2846 urlComponents
.lpszUrlPath
= path
;
2847 urlComponents
.dwUrlPathLength
= 2048;
2848 urlComponents
.lpszExtraInfo
= extra
;
2849 urlComponents
.dwExtraInfoLength
= 1024;
2850 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2852 switch(urlComponents
.nScheme
) {
2853 case INTERNET_SCHEME_FTP
:
2854 if(urlComponents
.nPort
== 0)
2855 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2856 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2857 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2860 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2861 if(client1
== NULL
) {
2862 InternetCloseHandle(client
);
2867 case INTERNET_SCHEME_HTTP
:
2868 case INTERNET_SCHEME_HTTPS
: {
2869 static const WCHAR szStars
[] = { '*','/','*', 0 };
2870 LPCWSTR accept
[2] = { szStars
, NULL
};
2871 if(urlComponents
.nPort
== 0) {
2872 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2873 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2875 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2877 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2878 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2879 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2883 if (urlComponents
.dwExtraInfoLength
) {
2885 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
2887 if (!(path_extra
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
2889 InternetCloseHandle(client
);
2892 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
2893 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
2894 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2895 HeapFree(GetProcessHeap(), 0, path_extra
);
2898 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2900 if(client1
== NULL
) {
2901 InternetCloseHandle(client
);
2904 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2905 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
2906 GetLastError() != ERROR_IO_PENDING
) {
2907 InternetCloseHandle(client1
);
2912 case INTERNET_SCHEME_GOPHER
:
2913 /* gopher doesn't seem to be implemented in wine, but it's supposed
2914 * to be supported by InternetOpenUrlA. */
2916 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
2920 TRACE(" %p <--\n", client1
);
2925 /**********************************************************
2926 * InternetOpenUrlW (WININET.@)
2931 * handle of connection or NULL on failure
2933 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
2935 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
2936 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
->hdr
;
2940 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
2941 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
2942 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
2943 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
2946 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
2947 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2949 HINTERNET ret
= NULL
;
2950 LPWININETAPPINFOW hIC
= NULL
;
2952 if (TRACE_ON(wininet
)) {
2953 TRACE("(%p, %s, %s, %08x, %08x, %08x)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2954 dwHeadersLength
, dwFlags
, dwContext
);
2956 dump_INTERNET_FLAGS(dwFlags
);
2961 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2965 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
2966 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
2967 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2971 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
2972 WORKREQUEST workRequest
;
2973 struct WORKREQ_INTERNETOPENURLW
*req
;
2975 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
2976 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
2977 req
= &workRequest
.u
.InternetOpenUrlW
;
2978 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
2980 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
2982 req
->lpszHeaders
= 0;
2983 req
->dwHeadersLength
= dwHeadersLength
;
2984 req
->dwFlags
= dwFlags
;
2985 req
->dwContext
= dwContext
;
2987 INTERNET_AsyncCall(&workRequest
);
2989 * This is from windows.
2991 INTERNET_SetLastError(ERROR_IO_PENDING
);
2993 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
2998 WININET_Release( &hIC
->hdr
);
2999 TRACE(" %p <--\n", ret
);
3004 /**********************************************************
3005 * InternetOpenUrlA (WININET.@)
3010 * handle of connection or NULL on failure
3012 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3013 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
3015 HINTERNET rc
= (HINTERNET
)NULL
;
3019 LPWSTR szUrl
= NULL
;
3020 LPWSTR szHeaders
= NULL
;
3025 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
3026 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
3028 return (HINTERNET
)NULL
;
3029 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
3033 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3034 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
3036 HeapFree(GetProcessHeap(), 0, szUrl
);
3037 return (HINTERNET
)NULL
;
3039 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3042 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3043 lenHeaders
, dwFlags
, dwContext
);
3045 HeapFree(GetProcessHeap(), 0, szUrl
);
3046 HeapFree(GetProcessHeap(), 0, szHeaders
);
3052 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3054 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite
));
3058 lpwite
->dwError
= 0;
3059 lpwite
->response
[0] = '\0';
3062 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3064 HeapFree(GetProcessHeap(), 0, lpwite
);
3072 /***********************************************************************
3073 * INTERNET_SetLastError (internal)
3075 * Set last thread specific error
3080 void INTERNET_SetLastError(DWORD dwError
)
3082 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3085 lpwite
= INTERNET_AllocThreadError();
3087 SetLastError(dwError
);
3089 lpwite
->dwError
= dwError
;
3093 /***********************************************************************
3094 * INTERNET_GetLastError (internal)
3096 * Get last thread specific error
3101 DWORD
INTERNET_GetLastError(void)
3103 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3104 if (!lpwite
) return 0;
3105 /* TlsGetValue clears last error, so set it again here */
3106 SetLastError(lpwite
->dwError
);
3107 return lpwite
->dwError
;
3111 /***********************************************************************
3112 * INTERNET_WorkerThreadFunc (internal)
3114 * Worker thread execution function
3119 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3121 LPWORKREQUEST lpRequest
= lpvParam
;
3122 WORKREQUEST workRequest
;
3126 memcpy(&workRequest
, lpRequest
, sizeof(WORKREQUEST
));
3127 HeapFree(GetProcessHeap(), 0, lpRequest
);
3129 workRequest
.asyncproc(&workRequest
);
3131 WININET_Release( workRequest
.hdr
);
3136 /***********************************************************************
3137 * INTERNET_AsyncCall (internal)
3139 * Retrieves work request from queue
3144 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3147 LPWORKREQUEST lpNewRequest
;
3151 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3155 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
3157 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3160 HeapFree(GetProcessHeap(), 0, lpNewRequest
);
3161 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3168 /***********************************************************************
3169 * INTERNET_GetResponseBuffer (internal)
3174 LPSTR
INTERNET_GetResponseBuffer(void)
3176 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3178 lpwite
= INTERNET_AllocThreadError();
3180 return lpwite
->response
;
3183 /***********************************************************************
3184 * INTERNET_GetNextLine (internal)
3186 * Parse next line in directory string listing
3189 * Pointer to beginning of next line
3194 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3198 BOOL bSuccess
= FALSE
;
3200 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3205 FD_SET(nSocket
, &infd
);
3206 tv
.tv_sec
=RESPONSE_TIMEOUT
;
3209 while (nRecv
< MAX_REPLY_LEN
)
3211 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
3213 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3215 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3219 if (lpszBuffer
[nRecv
] == '\n')
3224 if (lpszBuffer
[nRecv
] != '\r')
3229 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3237 lpszBuffer
[nRecv
] = '\0';
3239 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3248 /**********************************************************
3249 * InternetQueryDataAvailable (WININET.@)
3251 * Determines how much data is available to be read.
3254 * If there is data available then TRUE, otherwise if there
3255 * is not or an error occurred then FALSE. Use GetLastError() to
3256 * check for ERROR_NO_MORE_FILES to see if it was the former.
3258 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3259 LPDWORD lpdwNumberOfBytesAvailble
,
3260 DWORD dwFlags
, DWORD dwConext
)
3262 LPWININETHTTPREQW lpwhr
;
3263 BOOL retval
= FALSE
;
3266 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hFile
);
3269 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
3273 TRACE("--> %p %i\n",lpwhr
,lpwhr
->hdr
.htype
);
3275 switch (lpwhr
->hdr
.htype
)
3278 if (NETCON_query_data_available(&lpwhr
->netConnection
,
3279 lpdwNumberOfBytesAvailble
))
3281 if (!*lpdwNumberOfBytesAvailble
&&
3282 !NETCON_recv(&lpwhr
->netConnection
, buffer
,
3283 min(sizeof(buffer
), lpwhr
->dwContentLength
- lpwhr
->dwContentRead
),
3284 MSG_PEEK
, (int *)lpdwNumberOfBytesAvailble
))
3286 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
3293 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
3299 FIXME("unsupported file type\n");
3302 WININET_Release( &lpwhr
->hdr
);
3304 TRACE("<-- %i\n",retval
);
3309 /***********************************************************************
3310 * InternetLockRequestFile (WININET.@)
3312 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3319 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3326 /***********************************************************************
3327 * InternetAutodial (WININET.@)
3329 * On windows this function is supposed to dial the default internet
3330 * connection. We don't want to have Wine dial out to the internet so
3331 * we return TRUE by default. It might be nice to check if we are connected.
3338 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3342 /* Tell that we are connected to the internet. */
3346 /***********************************************************************
3347 * InternetAutodialHangup (WININET.@)
3349 * Hangs up a connection made with InternetAutodial
3358 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3362 /* we didn't dial, we don't disconnect */
3366 /***********************************************************************
3367 * InternetCombineUrlA (WININET.@)
3369 * Combine a base URL with a relative URL
3377 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3378 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3383 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3385 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3386 dwFlags
^= ICU_NO_ENCODE
;
3387 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3392 /***********************************************************************
3393 * InternetCombineUrlW (WININET.@)
3395 * Combine a base URL with a relative URL
3403 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3404 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3409 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3411 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3412 dwFlags
^= ICU_NO_ENCODE
;
3413 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3418 /* max port num is 65535 => 5 digits */
3419 #define MAX_WORD_DIGITS 5
3421 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3422 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3423 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3424 (url)->dw##component##Length : strlen((url)->lpsz##component))
3426 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3428 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3429 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3431 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3432 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3434 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3435 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3437 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3438 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3441 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3447 /* opaque urls do not fit into the standard url hierarchy and don't have
3448 * two following slashes */
3449 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3451 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3452 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3453 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3454 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3455 (nScheme
!= INTERNET_SCHEME_FILE
);
3458 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3461 if (scheme
< INTERNET_SCHEME_FIRST
)
3463 index
= scheme
- INTERNET_SCHEME_FIRST
;
3464 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3466 return (LPCWSTR
)&url_schemes
[index
];
3469 /* we can calculate using ansi strings because we're just
3470 * calculating string length, not size
3472 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3473 LPDWORD lpdwUrlLength
)
3475 INTERNET_SCHEME nScheme
;
3479 if (lpUrlComponents
->lpszScheme
)
3481 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3482 *lpdwUrlLength
+= dwLen
;
3483 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3489 nScheme
= lpUrlComponents
->nScheme
;
3491 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3492 nScheme
= INTERNET_SCHEME_HTTP
;
3493 scheme
= INTERNET_GetSchemeString(nScheme
);
3494 *lpdwUrlLength
+= strlenW(scheme
);
3497 (*lpdwUrlLength
)++; /* ':' */
3498 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3499 *lpdwUrlLength
+= strlen("//");
3501 if (lpUrlComponents
->lpszUserName
)
3503 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3504 *lpdwUrlLength
+= strlen("@");
3508 if (lpUrlComponents
->lpszPassword
)
3510 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3515 if (lpUrlComponents
->lpszPassword
)
3517 *lpdwUrlLength
+= strlen(":");
3518 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3521 if (lpUrlComponents
->lpszHostName
)
3523 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3525 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3527 char szPort
[MAX_WORD_DIGITS
+1];
3529 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3530 *lpdwUrlLength
+= strlen(szPort
);
3531 *lpdwUrlLength
+= strlen(":");
3534 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3535 (*lpdwUrlLength
)++; /* '/' */
3538 if (lpUrlComponents
->lpszUrlPath
)
3539 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3544 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3548 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3550 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3551 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3552 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3553 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3554 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3555 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3556 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3557 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3558 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3560 if (lpUrlComponents
->lpszScheme
)
3562 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
3563 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3564 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3565 -1, urlCompW
->lpszScheme
, len
);
3568 if (lpUrlComponents
->lpszHostName
)
3570 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
3571 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3572 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3573 -1, urlCompW
->lpszHostName
, len
);
3576 if (lpUrlComponents
->lpszUserName
)
3578 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
3579 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3580 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3581 -1, urlCompW
->lpszUserName
, len
);
3584 if (lpUrlComponents
->lpszPassword
)
3586 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
3587 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3588 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3589 -1, urlCompW
->lpszPassword
, len
);
3592 if (lpUrlComponents
->lpszUrlPath
)
3594 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
3595 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3596 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3597 -1, urlCompW
->lpszUrlPath
, len
);
3600 if (lpUrlComponents
->lpszExtraInfo
)
3602 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
3603 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3604 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3605 -1, urlCompW
->lpszExtraInfo
, len
);
3609 /***********************************************************************
3610 * InternetCreateUrlA (WININET.@)
3612 * See InternetCreateUrlW.
3614 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3615 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3619 URL_COMPONENTSW urlCompW
;
3621 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3623 if (!lpUrlComponents
)
3626 if (lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3628 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3632 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3635 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3637 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3639 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3640 *lpdwUrlLength
/= sizeof(WCHAR
);
3642 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3643 * minus one, so add one to leave room for NULL terminator
3646 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3648 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3649 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3650 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3651 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3652 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3653 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3654 HeapFree(GetProcessHeap(), 0, urlW
);
3659 /***********************************************************************
3660 * InternetCreateUrlW (WININET.@)
3662 * Creates a URL from its component parts.
3665 * lpUrlComponents [I] URL Components.
3666 * dwFlags [I] Flags. See notes.
3667 * lpszUrl [I] Buffer in which to store the created URL.
3668 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3669 * lpszUrl in characters. On output, the number of bytes
3670 * required to store the URL including terminator.
3674 * The dwFlags parameter can be zero or more of the following:
3675 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3682 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3683 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3686 INTERNET_SCHEME nScheme
;
3688 static const WCHAR slashSlashW
[] = {'/','/'};
3689 static const WCHAR percentD
[] = {'%','d',0};
3691 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3693 if (!lpUrlComponents
)
3696 if (lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3698 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3702 if (!calc_url_length(lpUrlComponents
, &dwLen
))
3705 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3707 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
3708 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3712 *lpdwUrlLength
= dwLen
;
3717 if (lpUrlComponents
->lpszScheme
)
3719 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3720 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
3723 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3728 nScheme
= lpUrlComponents
->nScheme
;
3730 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3731 nScheme
= INTERNET_SCHEME_HTTP
;
3733 scheme
= INTERNET_GetSchemeString(nScheme
);
3734 dwLen
= strlenW(scheme
);
3735 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
3739 /* all schemes are followed by at least a colon */
3743 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3745 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
3746 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
3749 if (lpUrlComponents
->lpszUserName
)
3751 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3752 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
3755 if (lpUrlComponents
->lpszPassword
)
3760 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3761 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
3769 if (lpUrlComponents
->lpszHostName
)
3771 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3772 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
3775 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3777 WCHAR szPort
[MAX_WORD_DIGITS
+1];
3779 sprintfW(szPort
, percentD
, lpUrlComponents
->nPort
);
3782 dwLen
= strlenW(szPort
);
3783 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
3787 /* add slash between hostname and path if necessary */
3788 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3796 if (lpUrlComponents
->lpszUrlPath
)
3798 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3799 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
3808 /***********************************************************************
3809 * InternetConfirmZoneCrossingA (WININET.@)
3812 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
3814 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
3815 return ERROR_SUCCESS
;
3818 /***********************************************************************
3819 * InternetConfirmZoneCrossingW (WININET.@)
3822 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
3824 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
3825 return ERROR_SUCCESS
;
3828 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
3829 LPDWORD lpdwConnection
, DWORD dwReserved
)
3831 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3832 lpdwConnection
, dwReserved
);
3833 return ERROR_SUCCESS
;
3836 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
3837 LPDWORD lpdwConnection
, DWORD dwReserved
)
3839 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3840 lpdwConnection
, dwReserved
);
3841 return ERROR_SUCCESS
;
3844 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3846 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
3850 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3852 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
3856 DWORD WINAPI
InternetHangUp( DWORD dwConnection
, DWORD dwReserved
)
3858 FIXME("(0x%08x, 0x%08x) stub\n", dwConnection
, dwReserved
);
3859 return ERROR_SUCCESS
;
3862 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
3865 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
3866 debugstr_w(pwszTarget
), pbHexHash
);
3870 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
3872 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);