4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
58 #include "wine/debug.h"
60 #define NO_SHLWAPI_STREAM
64 #include "wine/exception.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
73 #define RESPONSE_TIMEOUT 30
78 CHAR response
[MAX_REPLY_LEN
];
79 } WITHREADERROR
, *LPWITHREADERROR
;
81 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
);
82 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
83 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
);
85 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
86 static HMODULE WININET_hModule
;
88 #define HANDLE_CHUNK_SIZE 0x10
90 static CRITICAL_SECTION WININET_cs
;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
94 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
95 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
99 static LPWININETHANDLEHEADER
*WININET_Handles
;
100 static UINT WININET_dwNextHandle
;
101 static UINT WININET_dwMaxHandles
;
103 HINTERNET
WININET_AllocHandle( LPWININETHANDLEHEADER info
)
105 LPWININETHANDLEHEADER
*p
;
106 UINT handle
= 0, num
;
108 list_init( &info
->children
);
110 EnterCriticalSection( &WININET_cs
);
111 if( !WININET_dwMaxHandles
)
113 num
= HANDLE_CHUNK_SIZE
;
114 p
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
119 WININET_dwMaxHandles
= num
;
121 if( WININET_dwMaxHandles
== WININET_dwNextHandle
)
123 num
= WININET_dwMaxHandles
+ HANDLE_CHUNK_SIZE
;
124 p
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
125 WININET_Handles
, sizeof (UINT
)* num
);
129 WININET_dwMaxHandles
= num
;
132 handle
= WININET_dwNextHandle
;
133 if( WININET_Handles
[handle
] )
134 ERR("handle isn't free but should be\n");
135 WININET_Handles
[handle
] = WININET_AddRef( info
);
137 while( WININET_Handles
[WININET_dwNextHandle
] &&
138 (WININET_dwNextHandle
< WININET_dwMaxHandles
) )
139 WININET_dwNextHandle
++;
142 LeaveCriticalSection( &WININET_cs
);
144 return info
->hInternet
= (HINTERNET
) (handle
+1);
147 LPWININETHANDLEHEADER
WININET_AddRef( LPWININETHANDLEHEADER info
)
150 TRACE("%p -> refcount = %d\n", info
, info
->dwRefCount
);
154 LPWININETHANDLEHEADER
WININET_GetObject( HINTERNET hinternet
)
156 LPWININETHANDLEHEADER info
= NULL
;
157 UINT handle
= (UINT
) hinternet
;
159 EnterCriticalSection( &WININET_cs
);
161 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) &&
162 WININET_Handles
[handle
-1] )
163 info
= WININET_AddRef( WININET_Handles
[handle
-1] );
165 LeaveCriticalSection( &WININET_cs
);
167 TRACE("handle %d -> %p\n", handle
, info
);
172 BOOL
WININET_Release( LPWININETHANDLEHEADER info
)
175 TRACE( "object %p refcount = %d\n", info
, info
->dwRefCount
);
176 if( !info
->dwRefCount
)
178 if ( info
->close_connection
)
180 TRACE( "closing connection %p\n", info
);
181 info
->close_connection( info
);
183 INTERNET_SendCallback(info
, info
->dwContext
,
184 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
186 TRACE( "destroying object %p\n", info
);
187 if ( info
->htype
!= WH_HINIT
)
188 list_remove( &info
->entry
);
189 info
->destroy( info
);
194 BOOL
WININET_FreeHandle( HINTERNET hinternet
)
197 UINT handle
= (UINT
) hinternet
;
198 LPWININETHANDLEHEADER info
= NULL
, child
, next
;
200 EnterCriticalSection( &WININET_cs
);
202 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) )
205 if( WININET_Handles
[handle
] )
207 info
= WININET_Handles
[handle
];
208 TRACE( "destroying handle %d for object %p\n", handle
+1, info
);
209 WININET_Handles
[handle
] = NULL
;
214 LeaveCriticalSection( &WININET_cs
);
216 /* As on native when the equivalent of WININET_Release is called, the handle
217 * is already invalid, but if a new handle is created at this time it does
218 * not yet get assigned the freed handle number */
221 /* Free all children as native does */
222 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, WININETHANDLEHEADER
, entry
)
224 TRACE( "freeing child handle %d for parent handle %d\n",
225 (UINT
)child
->hInternet
, handle
+1);
226 WININET_FreeHandle( child
->hInternet
);
228 WININET_Release( info
);
231 EnterCriticalSection( &WININET_cs
);
233 if( WININET_dwNextHandle
> handle
&& !WININET_Handles
[handle
] )
234 WININET_dwNextHandle
= handle
;
236 LeaveCriticalSection( &WININET_cs
);
241 /***********************************************************************
242 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
245 * hinstDLL [I] handle to the DLL's instance
247 * lpvReserved [I] reserved, must be NULL
254 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
256 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
259 case DLL_PROCESS_ATTACH
:
261 g_dwTlsErrIndex
= TlsAlloc();
263 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
266 URLCacheContainers_CreateDefaults();
268 WININET_hModule
= (HMODULE
)hinstDLL
;
270 case DLL_THREAD_ATTACH
:
273 case DLL_THREAD_DETACH
:
274 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
276 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
277 HeapFree(GetProcessHeap(), 0, lpwite
);
281 case DLL_PROCESS_DETACH
:
283 URLCacheContainers_DeleteAll();
285 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
287 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
288 TlsFree(g_dwTlsErrIndex
);
297 /***********************************************************************
298 * InternetInitializeAutoProxyDll (WININET.@)
300 * Setup the internal proxy
309 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
312 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
316 /***********************************************************************
317 * DetectAutoProxyUrl (WININET.@)
319 * Auto detect the proxy url
325 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
326 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
329 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
334 /***********************************************************************
335 * INTERNET_ConfigureProxyFromReg
338 * The proxy may be specified in the form 'http=proxy.my.org'
339 * Presumably that means there can be ftp=ftpproxy.my.org too.
341 static BOOL
INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai
)
344 DWORD r
, keytype
, len
, enabled
;
345 LPCSTR lpszInternetSettings
=
346 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
347 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
349 r
= RegOpenKeyA(HKEY_CURRENT_USER
, lpszInternetSettings
, &key
);
350 if ( r
!= ERROR_SUCCESS
)
353 len
= sizeof enabled
;
354 r
= RegQueryValueExA( key
, "ProxyEnable", NULL
, &keytype
,
355 (BYTE
*)&enabled
, &len
);
356 if( (r
== ERROR_SUCCESS
) && enabled
)
358 TRACE("Proxy is enabled.\n");
360 /* figure out how much memory the proxy setting takes */
361 r
= RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
363 if( (r
== ERROR_SUCCESS
) && len
&& (keytype
== REG_SZ
) )
366 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
368 szProxy
=HeapAlloc( GetProcessHeap(), 0, len
);
369 RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
370 (BYTE
*)szProxy
, &len
);
372 /* find the http proxy, and strip away everything else */
373 p
= strstrW( szProxy
, szHttp
);
376 p
+= lstrlenW(szHttp
);
377 lstrcpyW( szProxy
, p
);
379 p
= strchrW( szProxy
, ' ' );
383 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
384 lpwai
->lpszProxy
= szProxy
;
386 TRACE("http proxy = %s\n", debugstr_w(lpwai
->lpszProxy
));
389 ERR("Couldn't read proxy server settings.\n");
392 TRACE("Proxy is not enabled.\n");
398 /***********************************************************************
399 * dump_INTERNET_FLAGS
401 * Helper function to TRACE the internet flags.
407 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
409 #define FE(x) { x, #x }
410 static const wininet_flag_info flag
[] = {
411 FE(INTERNET_FLAG_RELOAD
),
412 FE(INTERNET_FLAG_RAW_DATA
),
413 FE(INTERNET_FLAG_EXISTING_CONNECT
),
414 FE(INTERNET_FLAG_ASYNC
),
415 FE(INTERNET_FLAG_PASSIVE
),
416 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
417 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
418 FE(INTERNET_FLAG_FROM_CACHE
),
419 FE(INTERNET_FLAG_SECURE
),
420 FE(INTERNET_FLAG_KEEP_CONNECTION
),
421 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
422 FE(INTERNET_FLAG_READ_PREFETCH
),
423 FE(INTERNET_FLAG_NO_COOKIES
),
424 FE(INTERNET_FLAG_NO_AUTH
),
425 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
426 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
427 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
428 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
429 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
430 FE(INTERNET_FLAG_RESYNCHRONIZE
),
431 FE(INTERNET_FLAG_HYPERLINK
),
432 FE(INTERNET_FLAG_NO_UI
),
433 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
434 FE(INTERNET_FLAG_CACHE_ASYNC
),
435 FE(INTERNET_FLAG_FORMS_SUBMIT
),
436 FE(INTERNET_FLAG_NEED_FILE
),
437 FE(INTERNET_FLAG_TRANSFER_ASCII
),
438 FE(INTERNET_FLAG_TRANSFER_BINARY
)
443 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
444 if (flag
[i
].val
& dwFlags
) {
445 TRACE(" %s", flag
[i
].name
);
446 dwFlags
&= ~flag
[i
].val
;
450 TRACE(" Unknown flags (%08x)\n", dwFlags
);
455 /***********************************************************************
456 * InternetOpenW (WININET.@)
458 * Per-application initialization of wininet
461 * HINTERNET on success
465 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
466 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
468 LPWININETAPPINFOW lpwai
= NULL
;
469 HINTERNET handle
= NULL
;
471 if (TRACE_ON(wininet
)) {
472 #define FE(x) { x, #x }
473 static const wininet_flag_info access_type
[] = {
474 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
475 FE(INTERNET_OPEN_TYPE_DIRECT
),
476 FE(INTERNET_OPEN_TYPE_PROXY
),
477 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
481 const char *access_type_str
= "Unknown";
483 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
484 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
485 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
486 if (access_type
[i
].val
== dwAccessType
) {
487 access_type_str
= access_type
[i
].name
;
491 TRACE(" access type : %s\n", access_type_str
);
493 dump_INTERNET_FLAGS(dwFlags
);
496 /* Clear any error information */
497 INTERNET_SetLastError(0);
499 lpwai
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETAPPINFOW
));
502 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
506 lpwai
->hdr
.htype
= WH_HINIT
;
507 lpwai
->hdr
.dwFlags
= dwFlags
;
508 lpwai
->hdr
.dwRefCount
= 1;
509 lpwai
->hdr
.close_connection
= NULL
;
510 lpwai
->hdr
.destroy
= INTERNET_CloseHandle
;
511 lpwai
->dwAccessType
= dwAccessType
;
512 lpwai
->lpszProxyUsername
= NULL
;
513 lpwai
->lpszProxyPassword
= NULL
;
515 handle
= WININET_AllocHandle( &lpwai
->hdr
);
518 HeapFree( GetProcessHeap(), 0, lpwai
);
519 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
523 if (NULL
!= lpszAgent
)
525 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
526 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
527 if (lpwai
->lpszAgent
)
528 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
530 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
531 INTERNET_ConfigureProxyFromReg( lpwai
);
532 else if (NULL
!= lpszProxy
)
534 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
535 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
536 if (lpwai
->lpszProxy
)
537 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
540 if (NULL
!= lpszProxyBypass
)
542 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
543 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
544 if (lpwai
->lpszProxyBypass
)
545 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
550 WININET_Release( &lpwai
->hdr
);
552 TRACE("returning %p\n", lpwai
);
558 /***********************************************************************
559 * InternetOpenA (WININET.@)
561 * Per-application initialization of wininet
564 * HINTERNET on success
568 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
569 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
571 HINTERNET rc
= (HINTERNET
)NULL
;
573 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
575 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
576 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
580 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
581 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
582 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
587 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
588 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
589 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
592 if( lpszProxyBypass
)
594 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
595 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
596 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
599 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
601 HeapFree(GetProcessHeap(), 0, szAgent
);
602 HeapFree(GetProcessHeap(), 0, szProxy
);
603 HeapFree(GetProcessHeap(), 0, szBypass
);
608 /***********************************************************************
609 * InternetGetLastResponseInfoA (WININET.@)
611 * Return last wininet error description on the calling thread
614 * TRUE on success of writing to buffer
618 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
619 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
621 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
627 *lpdwError
= lpwite
->dwError
;
630 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
631 *lpdwBufferLength
= strlen(lpszBuffer
);
634 *lpdwBufferLength
= 0;
639 *lpdwBufferLength
= 0;
645 /***********************************************************************
646 * InternetGetLastResponseInfoW (WININET.@)
648 * Return last wininet error description on the calling thread
651 * TRUE on success of writing to buffer
655 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
656 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
658 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
664 *lpdwError
= lpwite
->dwError
;
667 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
668 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
671 *lpdwBufferLength
= 0;
676 *lpdwBufferLength
= 0;
682 /***********************************************************************
683 * InternetGetConnectedState (WININET.@)
685 * Return connected state
689 * if lpdwStatus is not null, return the status (off line,
690 * modem, lan...) in it.
691 * FALSE if not connected
693 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
695 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
698 FIXME("always returning LAN connection.\n");
699 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
705 /***********************************************************************
706 * InternetGetConnectedStateExW (WININET.@)
708 * Return connected state
712 * lpdwStatus [O] Flags specifying the status of the internet connection.
713 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
714 * dwNameLen [I] Size of the buffer, in characters.
715 * dwReserved [I] Reserved. Must be set to 0.
719 * if lpdwStatus is not null, return the status (off line,
720 * modem, lan...) in it.
721 * FALSE if not connected
724 * If the system has no available network connections, an empty string is
725 * stored in lpszConnectionName. If there is a LAN connection, a localized
726 * "LAN Connection" string is stored. Presumably, if only a dial-up
727 * connection is available then the name of the dial-up connection is
728 * returned. Why any application, other than the "Internet Settings" CPL,
729 * would want to use this function instead of the simpler InternetGetConnectedStateW
730 * function is beyond me.
732 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
733 DWORD dwNameLen
, DWORD dwReserved
)
735 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
742 FIXME("always returning LAN connection.\n");
743 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
745 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
749 /***********************************************************************
750 * InternetGetConnectedStateExA (WININET.@)
752 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
753 DWORD dwNameLen
, DWORD dwReserved
)
755 LPWSTR lpwszConnectionName
= NULL
;
758 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
760 if (lpszConnectionName
&& dwNameLen
> 0)
761 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
763 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
765 if (rc
&& lpwszConnectionName
)
767 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
768 dwNameLen
, NULL
, NULL
);
770 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
777 /***********************************************************************
778 * InternetConnectW (WININET.@)
780 * Open a ftp, gopher or http session
783 * HINTERNET a session handle on success
787 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
788 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
789 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
790 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
792 LPWININETAPPINFOW hIC
;
795 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
796 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
797 dwService
, dwFlags
, dwContext
);
801 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
805 /* Clear any error information */
806 INTERNET_SetLastError(0);
807 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
808 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
810 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
816 case INTERNET_SERVICE_FTP
:
817 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
818 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
821 case INTERNET_SERVICE_HTTP
:
822 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
823 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
826 case INTERNET_SERVICE_GOPHER
:
832 WININET_Release( &hIC
->hdr
);
834 TRACE("returning %p\n", rc
);
839 /***********************************************************************
840 * InternetConnectA (WININET.@)
842 * Open a ftp, gopher or http session
845 * HINTERNET a session handle on success
849 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
850 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
851 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
852 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
854 HINTERNET rc
= (HINTERNET
)NULL
;
856 LPWSTR szServerName
= NULL
;
857 LPWSTR szUserName
= NULL
;
858 LPWSTR szPassword
= NULL
;
862 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
863 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
864 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
868 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
869 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
870 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
874 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
875 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
876 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
880 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
881 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
883 HeapFree(GetProcessHeap(), 0, szServerName
);
884 HeapFree(GetProcessHeap(), 0, szUserName
);
885 HeapFree(GetProcessHeap(), 0, szPassword
);
890 /***********************************************************************
891 * InternetFindNextFileA (WININET.@)
893 * Continues a file search from a previous call to FindFirstFile
900 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
905 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
907 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
911 /***********************************************************************
912 * InternetFindNextFileW (WININET.@)
914 * Continues a file search from a previous call to FindFirstFile
921 static void AsyncFtpFindNextFileProc(WORKREQUEST
*workRequest
)
923 struct WORKREQ_FTPFINDNEXTW
*req
= &workRequest
->u
.FtpFindNextW
;
924 LPWININETFTPFINDNEXTW lpwh
= (LPWININETFTPFINDNEXTW
) workRequest
->hdr
;
928 FTP_FindNextFileW(lpwh
, req
->lpFindFileData
);
931 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
933 LPWININETAPPINFOW hIC
= NULL
;
934 LPWININETFTPFINDNEXTW lpwh
;
935 BOOL bSuccess
= FALSE
;
939 lpwh
= (LPWININETFTPFINDNEXTW
) WININET_GetObject( hFind
);
940 if (NULL
== lpwh
|| lpwh
->hdr
.htype
!= WH_HFTPFINDNEXT
)
942 FIXME("Only FTP supported\n");
943 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
947 hIC
= lpwh
->lpFtpSession
->lpAppInfo
;
948 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
950 WORKREQUEST workRequest
;
951 struct WORKREQ_FTPFINDNEXTW
*req
;
953 workRequest
.asyncproc
= AsyncFtpFindNextFileProc
;
954 workRequest
.hdr
= WININET_AddRef( &lpwh
->hdr
);
955 req
= &workRequest
.u
.FtpFindNextW
;
956 req
->lpFindFileData
= lpvFindData
;
958 bSuccess
= INTERNET_AsyncCall(&workRequest
);
962 bSuccess
= FTP_FindNextFileW(lpwh
, lpvFindData
);
966 WININET_Release( &lpwh
->hdr
);
970 /***********************************************************************
971 * INTERNET_CloseHandle (internal)
973 * Close internet handle
979 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
)
981 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
985 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
986 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
987 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
988 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
989 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
990 HeapFree(GetProcessHeap(), 0, lpwai
);
994 /***********************************************************************
995 * InternetCloseHandle (WININET.@)
997 * Generic close handle function
1004 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1006 LPWININETHANDLEHEADER lpwh
;
1008 TRACE("%p\n",hInternet
);
1010 lpwh
= WININET_GetObject( hInternet
);
1013 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1017 WININET_Release( lpwh
);
1018 WININET_FreeHandle( hInternet
);
1024 /***********************************************************************
1025 * ConvertUrlComponentValue (Internal)
1027 * Helper function for InternetCrackUrlW
1030 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1031 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1032 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1034 TRACE("%p %d %p %d %p %p\n", lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1035 if (*dwComponentLen
!= 0)
1037 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1038 if (*lppszComponent
== NULL
)
1040 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1042 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1044 *lppszComponent
= NULL
;
1045 *dwComponentLen
= nASCIILength
;
1049 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1050 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1051 (*lppszComponent
)[ncpylen
]=0;
1052 *dwComponentLen
= ncpylen
;
1058 /***********************************************************************
1059 * InternetCrackUrlA (WININET.@)
1061 * See InternetCrackUrlW.
1063 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1064 LPURL_COMPONENTSA lpUrlComponents
)
1067 URL_COMPONENTSW UCW
;
1070 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl
), dwUrlLength
, dwFlags
, lpUrlComponents
);
1072 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1073 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1075 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1081 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1083 /* if dwUrlLength=-1 then nLength includes null but length to
1084 InternetCrackUrlW should not include it */
1085 if (dwUrlLength
== -1) nLength
--;
1087 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1088 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1090 memset(&UCW
,0,sizeof(UCW
));
1091 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1092 if(lpUrlComponents
->dwHostNameLength
!=0)
1093 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1094 if(lpUrlComponents
->dwUserNameLength
!=0)
1095 UCW
.dwUserNameLength
=lpUrlComponents
->dwUserNameLength
;
1096 if(lpUrlComponents
->dwPasswordLength
!=0)
1097 UCW
.dwPasswordLength
=lpUrlComponents
->dwPasswordLength
;
1098 if(lpUrlComponents
->dwUrlPathLength
!=0)
1099 UCW
.dwUrlPathLength
=lpUrlComponents
->dwUrlPathLength
;
1100 if(lpUrlComponents
->dwSchemeLength
!=0)
1101 UCW
.dwSchemeLength
=lpUrlComponents
->dwSchemeLength
;
1102 if(lpUrlComponents
->dwExtraInfoLength
!=0)
1103 UCW
.dwExtraInfoLength
=lpUrlComponents
->dwExtraInfoLength
;
1104 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
1106 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1110 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1111 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
1113 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1114 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
1116 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1117 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
1119 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1120 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
1122 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1123 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
1125 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1126 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
1128 lpUrlComponents
->nScheme
=UCW
.nScheme
;
1129 lpUrlComponents
->nPort
=UCW
.nPort
;
1130 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1132 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1133 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
1134 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
1135 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
1136 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
1141 static const WCHAR url_schemes
[][7] =
1144 {'g','o','p','h','e','r',0},
1145 {'h','t','t','p',0},
1146 {'h','t','t','p','s',0},
1147 {'f','i','l','e',0},
1148 {'n','e','w','s',0},
1149 {'m','a','i','l','t','o',0},
1153 /***********************************************************************
1154 * GetInternetSchemeW (internal)
1160 * INTERNET_SCHEME_UNKNOWN on failure
1163 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1167 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1169 if(lpszScheme
==NULL
)
1170 return INTERNET_SCHEME_UNKNOWN
;
1172 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1173 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1174 return INTERNET_SCHEME_FIRST
+ i
;
1176 return INTERNET_SCHEME_UNKNOWN
;
1179 /***********************************************************************
1180 * SetUrlComponentValueW (Internal)
1182 * Helper function for InternetCrackUrlW
1185 * lppszComponent [O] Holds the returned string
1186 * dwComponentLen [I] Holds the size of lppszComponent
1187 * [O] Holds the length of the string in lppszComponent without '\0'
1188 * lpszStart [I] Holds the string to copy from
1189 * len [I] Holds the length of lpszStart without '\0'
1196 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1198 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1200 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1203 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1205 if (*lppszComponent
== NULL
)
1207 *lppszComponent
= (LPWSTR
)lpszStart
;
1208 *dwComponentLen
= len
;
1212 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1213 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1214 (*lppszComponent
)[ncpylen
] = '\0';
1215 *dwComponentLen
= ncpylen
;
1222 /***********************************************************************
1223 * InternetCrackUrlW (WININET.@)
1225 * Break up URL into its components
1231 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1232 LPURL_COMPONENTSW lpUC
)
1236 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1239 LPCWSTR lpszParam
= NULL
;
1240 BOOL bIsAbsolute
= FALSE
;
1241 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1242 LPCWSTR lpszcp
= NULL
;
1243 LPWSTR lpszUrl_decode
= NULL
;
1244 DWORD dwUrlLength
= dwUrlLength_orig
;
1245 const WCHAR lpszSeparators
[3]={';','?',0};
1246 const WCHAR lpszSlash
[2]={'/',0};
1248 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl
), dwUrlLength
, dwFlags
, lpUC
);
1250 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1252 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1255 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1257 if (dwFlags
& ICU_DECODE
)
1259 lpszUrl_decode
=HeapAlloc( GetProcessHeap(), 0, dwUrlLength
* sizeof (WCHAR
) );
1260 if( InternetCanonicalizeUrlW(lpszUrl_orig
, lpszUrl_decode
, &dwUrlLength
, dwFlags
))
1262 lpszUrl
= lpszUrl_decode
;
1267 /* Determine if the URI is absolute. */
1268 while (*lpszap
!= '\0')
1270 if (isalnumW(*lpszap
))
1275 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1282 lpszcp
= lpszUrl
; /* Relative url */
1288 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1289 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1291 /* Parse <params> */
1292 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
1293 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1294 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1296 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1300 /* Get scheme first. */
1301 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1302 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1303 lpszUrl
, lpszcp
- lpszUrl
);
1305 /* Eat ':' in protocol. */
1308 /* double slash indicates the net_loc portion is present */
1309 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1313 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
1317 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1319 lpszNetLoc
= lpszParam
;
1321 else if (!lpszNetLoc
)
1322 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1330 /* [<user>[<:password>]@]<host>[:<port>] */
1331 /* First find the user and password if they exist */
1333 lpszHost
= strchrW(lpszcp
, '@');
1334 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1336 /* username and password not specified. */
1337 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1338 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1340 else /* Parse out username and password */
1342 LPCWSTR lpszUser
= lpszcp
;
1343 LPCWSTR lpszPasswd
= lpszHost
;
1345 while (lpszcp
< lpszHost
)
1348 lpszPasswd
= lpszcp
;
1353 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1354 lpszUser
, lpszPasswd
- lpszUser
);
1356 if (lpszPasswd
!= lpszHost
)
1358 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1359 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1360 lpszHost
- lpszPasswd
);
1362 lpszcp
++; /* Advance to beginning of host */
1365 /* Parse <host><:port> */
1368 lpszPort
= lpszNetLoc
;
1370 /* special case for res:// URLs: there is no port here, so the host is the
1371 entire string up to the first '/' */
1372 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1374 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1375 lpszHost
, lpszPort
- lpszHost
);
1380 while (lpszcp
< lpszNetLoc
)
1388 /* If the scheme is "file" and the host is just one letter, it's not a host */
1389 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1392 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1397 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1398 lpszHost
, lpszPort
- lpszHost
);
1399 if (lpszPort
!= lpszNetLoc
)
1400 lpUC
->nPort
= atoiW(++lpszPort
);
1401 else switch (lpUC
->nScheme
)
1403 case INTERNET_SCHEME_HTTP
:
1404 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1406 case INTERNET_SCHEME_HTTPS
:
1407 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1409 case INTERNET_SCHEME_FTP
:
1410 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1412 case INTERNET_SCHEME_GOPHER
:
1413 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1424 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1425 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1426 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1431 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1432 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1433 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1434 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1437 /* Here lpszcp points to:
1439 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1440 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1442 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1446 /* Only truncate the parameter list if it's already been saved
1447 * in lpUC->lpszExtraInfo.
1449 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1450 len
= lpszParam
- lpszcp
;
1453 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1454 * newlines if necessary.
1456 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1457 if (lpsznewline
!= NULL
)
1458 len
= lpsznewline
- lpszcp
;
1460 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1462 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1467 lpUC
->dwUrlPathLength
= 0;
1470 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1471 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1472 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1473 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1474 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1476 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1480 /***********************************************************************
1481 * InternetAttemptConnect (WININET.@)
1483 * Attempt to make a connection to the internet
1486 * ERROR_SUCCESS on success
1487 * Error value on failure
1490 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1493 return ERROR_SUCCESS
;
1497 /***********************************************************************
1498 * InternetCanonicalizeUrlA (WININET.@)
1500 * Escape unsafe characters and spaces
1507 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1508 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1511 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1513 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1514 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1516 if(dwFlags
& ICU_DECODE
)
1518 dwURLFlags
|= URL_UNESCAPE
;
1519 dwFlags
&= ~ICU_DECODE
;
1522 if(dwFlags
& ICU_ESCAPE
)
1524 dwURLFlags
|= URL_UNESCAPE
;
1525 dwFlags
&= ~ICU_ESCAPE
;
1528 if(dwFlags
& ICU_BROWSER_MODE
)
1530 dwURLFlags
|= URL_BROWSER_MODE
;
1531 dwFlags
&= ~ICU_BROWSER_MODE
;
1534 if(dwFlags
& ICU_NO_ENCODE
)
1536 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1537 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1538 dwFlags
&= ~ICU_NO_ENCODE
;
1541 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1543 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1544 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1545 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1547 return (hr
== S_OK
) ? TRUE
: FALSE
;
1550 /***********************************************************************
1551 * InternetCanonicalizeUrlW (WININET.@)
1553 * Escape unsafe characters and spaces
1560 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1561 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1564 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1566 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1567 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1569 if(dwFlags
& ICU_DECODE
)
1571 dwURLFlags
|= URL_UNESCAPE
;
1572 dwFlags
&= ~ICU_DECODE
;
1575 if(dwFlags
& ICU_ESCAPE
)
1577 dwURLFlags
|= URL_UNESCAPE
;
1578 dwFlags
&= ~ICU_ESCAPE
;
1581 if(dwFlags
& ICU_BROWSER_MODE
)
1583 dwURLFlags
|= URL_BROWSER_MODE
;
1584 dwFlags
&= ~ICU_BROWSER_MODE
;
1587 if(dwFlags
& ICU_NO_ENCODE
)
1589 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1590 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1591 dwFlags
&= ~ICU_NO_ENCODE
;
1594 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1596 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1597 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1598 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1600 return (hr
== S_OK
) ? TRUE
: FALSE
;
1603 /* #################################################### */
1605 static INTERNET_STATUS_CALLBACK
set_status_callback(
1606 LPWININETHANDLEHEADER lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
1608 INTERNET_STATUS_CALLBACK ret
;
1610 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1611 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1613 ret
= lpwh
->lpfnStatusCB
;
1614 lpwh
->lpfnStatusCB
= callback
;
1619 /***********************************************************************
1620 * InternetSetStatusCallbackA (WININET.@)
1622 * Sets up a callback function which is called as progress is made
1623 * during an operation.
1626 * Previous callback or NULL on success
1627 * INTERNET_INVALID_STATUS_CALLBACK on failure
1630 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1631 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1633 INTERNET_STATUS_CALLBACK retVal
;
1634 LPWININETHANDLEHEADER lpwh
;
1636 TRACE("0x%08x\n", (ULONG
)hInternet
);
1638 if (!(lpwh
= WININET_GetObject(hInternet
)))
1639 return INTERNET_INVALID_STATUS_CALLBACK
;
1641 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
1643 WININET_Release( lpwh
);
1647 /***********************************************************************
1648 * InternetSetStatusCallbackW (WININET.@)
1650 * Sets up a callback function which is called as progress is made
1651 * during an operation.
1654 * Previous callback or NULL on success
1655 * INTERNET_INVALID_STATUS_CALLBACK on failure
1658 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1659 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1661 INTERNET_STATUS_CALLBACK retVal
;
1662 LPWININETHANDLEHEADER lpwh
;
1664 TRACE("0x%08x\n", (ULONG
)hInternet
);
1666 if (!(lpwh
= WININET_GetObject(hInternet
)))
1667 return INTERNET_INVALID_STATUS_CALLBACK
;
1669 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
1671 WININET_Release( lpwh
);
1675 /***********************************************************************
1676 * InternetSetFilePointer (WININET.@)
1678 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1679 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
1685 /***********************************************************************
1686 * InternetWriteFile (WININET.@)
1688 * Write data to an open internet file
1695 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1696 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1698 BOOL retval
= FALSE
;
1700 LPWININETHANDLEHEADER lpwh
;
1703 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1707 switch (lpwh
->htype
)
1711 LPWININETHTTPREQW lpwhr
;
1712 lpwhr
= (LPWININETHTTPREQW
)lpwh
;
1714 TRACE("HTTPREQ %i\n",dwNumOfBytesToWrite
);
1715 retval
= NETCON_send(&lpwhr
->netConnection
, lpBuffer
,
1716 dwNumOfBytesToWrite
, 0, (LPINT
)lpdwNumOfBytesWritten
);
1718 WININET_Release( lpwh
);
1724 nSocket
= ((LPWININETFTPFILE
)lpwh
)->nDataSocket
;
1733 int res
= send(nSocket
, lpBuffer
, dwNumOfBytesToWrite
, 0);
1734 retval
= (res
>= 0);
1735 *lpdwNumOfBytesWritten
= retval
? res
: 0;
1737 WININET_Release( lpwh
);
1743 BOOL
INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh
, LPVOID lpBuffer
,
1744 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
,
1745 BOOL bWait
, BOOL bSendCompletionStatus
)
1747 BOOL retval
= FALSE
;
1750 LPWININETHTTPREQW lpwhr
;
1752 /* FIXME: this should use NETCON functions! */
1753 switch (lpwh
->htype
)
1756 lpwhr
= (LPWININETHTTPREQW
)lpwh
;
1758 if (!NETCON_recv(&lpwhr
->netConnection
, lpBuffer
,
1759 min(dwNumOfBytesToRead
, lpwhr
->dwContentLength
- lpwhr
->dwContentRead
),
1760 bWait
? MSG_WAITALL
: 0, &bytes_read
))
1763 if (((lpwhr
->dwContentLength
!= -1) &&
1764 (lpwhr
->dwContentRead
!= lpwhr
->dwContentLength
)))
1765 ERR("not all data received %d/%d\n", lpwhr
->dwContentRead
,
1766 lpwhr
->dwContentLength
);
1768 /* always returns TRUE, even if the network layer returns an
1770 *pdwNumOfBytesRead
= 0;
1771 HTTP_FinishedReading(lpwhr
);
1776 lpwhr
->dwContentRead
+= bytes_read
;
1777 *pdwNumOfBytesRead
= bytes_read
;
1778 if (!bytes_read
&& (lpwhr
->dwContentRead
== lpwhr
->dwContentLength
))
1779 retval
= HTTP_FinishedReading(lpwhr
);
1786 /* FIXME: FTP should use NETCON_ stuff */
1787 nSocket
= ((LPWININETFTPFILE
)lpwh
)->nDataSocket
;
1790 int res
= recv(nSocket
, lpBuffer
, dwNumOfBytesToRead
, bWait
? MSG_WAITALL
: 0);
1791 retval
= (res
>= 0);
1792 *pdwNumOfBytesRead
= retval
? res
: 0;
1800 if (bSendCompletionStatus
)
1802 INTERNET_ASYNC_RESULT iar
;
1804 iar
.dwResult
= retval
;
1805 iar
.dwError
= iar
.dwError
= retval
? ERROR_SUCCESS
:
1806 INTERNET_GetLastError();
1808 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1809 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
1810 sizeof(INTERNET_ASYNC_RESULT
));
1815 /***********************************************************************
1816 * InternetReadFile (WININET.@)
1818 * Read data from an open internet file
1825 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1826 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1828 LPWININETHANDLEHEADER lpwh
;
1831 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1833 lpwh
= WININET_GetObject( hFile
);
1836 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1840 retval
= INTERNET_ReadFile(lpwh
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, TRUE
, FALSE
);
1841 WININET_Release( lpwh
);
1843 TRACE("-- %s (bytes read: %d)\n", retval
? "TRUE": "FALSE", pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1847 /***********************************************************************
1848 * InternetReadFileExA (WININET.@)
1850 * Read data from an open internet file
1853 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1854 * lpBuffersOut [I/O] Buffer.
1855 * dwFlags [I] Flags. See notes.
1856 * dwContext [I] Context for callbacks.
1863 * The parameter dwFlags include zero or more of the following flags:
1864 *|IRF_ASYNC - Makes the call asynchronous.
1865 *|IRF_SYNC - Makes the call synchronous.
1866 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1867 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1869 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1872 * InternetOpenUrlA(), HttpOpenRequestA()
1874 void AsyncInternetReadFileExProc(WORKREQUEST
*workRequest
)
1876 struct WORKREQ_INTERNETREADFILEEXA
const *req
= &workRequest
->u
.InternetReadFileExA
;
1878 TRACE("INTERNETREADFILEEXA %p\n", workRequest
->hdr
);
1880 INTERNET_ReadFile(workRequest
->hdr
, req
->lpBuffersOut
->lpvBuffer
,
1881 req
->lpBuffersOut
->dwBufferLength
,
1882 &req
->lpBuffersOut
->dwBufferLength
, TRUE
, TRUE
);
1885 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1886 DWORD dwFlags
, DWORD_PTR dwContext
)
1888 BOOL retval
= FALSE
;
1889 LPWININETHANDLEHEADER lpwh
;
1891 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1893 if (dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
))
1894 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
));
1896 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
))
1898 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1902 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1905 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1909 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1910 INTERNET_STATUS_RECEIVING_RESPONSE
, NULL
, 0);
1912 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1913 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1914 if (dwFlags
& IRF_ASYNC
)
1916 DWORD dwDataAvailable
= 0;
1918 if (lpwh
->htype
== WH_HHTTPREQ
)
1919 NETCON_query_data_available(&((LPWININETHTTPREQW
)lpwh
)->netConnection
,
1922 if (!dwDataAvailable
)
1924 WORKREQUEST workRequest
;
1925 struct WORKREQ_INTERNETREADFILEEXA
*req
;
1927 workRequest
.asyncproc
= AsyncInternetReadFileExProc
;
1928 workRequest
.hdr
= WININET_AddRef( lpwh
);
1929 req
= &workRequest
.u
.InternetReadFileExA
;
1930 req
->lpBuffersOut
= lpBuffersOut
;
1932 if (!INTERNET_AsyncCall(&workRequest
))
1933 WININET_Release( lpwh
);
1935 INTERNET_SetLastError(ERROR_IO_PENDING
);
1940 retval
= INTERNET_ReadFile(lpwh
, lpBuffersOut
->lpvBuffer
,
1941 lpBuffersOut
->dwBufferLength
, &lpBuffersOut
->dwBufferLength
,
1942 !(dwFlags
& IRF_NO_WAIT
), FALSE
);
1946 DWORD dwBytesReceived
= lpBuffersOut
->dwBufferLength
;
1947 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1948 INTERNET_STATUS_RESPONSE_RECEIVED
, &dwBytesReceived
,
1949 sizeof(dwBytesReceived
));
1953 WININET_Release( lpwh
);
1955 TRACE("-- %s (bytes read: %d)\n", retval
? "TRUE": "FALSE", lpBuffersOut
->dwBufferLength
);
1959 /***********************************************************************
1960 * InternetReadFileExW (WININET.@)
1962 * Read data from an open internet file.
1965 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1966 * lpBuffersOut [I/O] Buffer.
1967 * dwFlags [I] Flags.
1968 * dwContext [I] Context for callbacks.
1971 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1974 * Not implemented in Wine or native either (as of IE6 SP2).
1977 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1978 DWORD dwFlags
, DWORD_PTR dwContext
)
1980 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
1982 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1986 /***********************************************************************
1987 * INET_QueryOptionHelper (internal)
1989 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1990 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1992 LPWININETHANDLEHEADER lpwhh
;
1993 BOOL bSuccess
= FALSE
;
1995 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1997 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2001 case INTERNET_OPTION_HANDLE_TYPE
:
2007 WARN("Invalid hInternet handle\n");
2008 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2012 type
= lpwhh
->htype
;
2014 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type
);
2016 if (*lpdwBufferLength
< sizeof(ULONG
))
2017 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2020 memcpy(lpBuffer
, &type
, sizeof(ULONG
));
2023 *lpdwBufferLength
= sizeof(ULONG
);
2027 case INTERNET_OPTION_REQUEST_FLAGS
:
2030 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags
);
2031 if (*lpdwBufferLength
< sizeof(ULONG
))
2032 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2035 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
2038 *lpdwBufferLength
= sizeof(ULONG
);
2042 case INTERNET_OPTION_URL
:
2043 case INTERNET_OPTION_DATAFILE_NAME
:
2047 WARN("Invalid hInternet handle\n");
2048 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2051 if (lpwhh
->htype
== WH_HHTTPREQ
)
2053 LPWININETHTTPREQW lpreq
= (LPWININETHTTPREQW
) lpwhh
;
2055 static const WCHAR szFmt
[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2056 static const WCHAR szHost
[] = {'H','o','s','t',0};
2060 Host
= HTTP_GetHeader(lpreq
,szHost
);
2061 sprintfW(url
,szFmt
,Host
->lpszValue
,lpreq
->lpszPath
);
2062 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url
));
2065 sizeRequired
= WideCharToMultiByte(CP_ACP
,0,url
,-1,
2066 lpBuffer
,*lpdwBufferLength
,NULL
,NULL
);
2067 if (sizeRequired
> *lpdwBufferLength
)
2068 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2071 *lpdwBufferLength
= sizeRequired
;
2075 sizeRequired
= (lstrlenW(url
)+1) * sizeof(WCHAR
);
2076 if (*lpdwBufferLength
< sizeRequired
)
2077 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2080 strcpyW(lpBuffer
, url
);
2083 *lpdwBufferLength
= sizeRequired
;
2088 case INTERNET_OPTION_HTTP_VERSION
:
2090 if (*lpdwBufferLength
< sizeof(HTTP_VERSION_INFO
))
2091 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2095 * Presently hardcoded to 1.1
2097 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
2098 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
2101 *lpdwBufferLength
= sizeof(HTTP_VERSION_INFO
);
2104 case INTERNET_OPTION_CONNECTED_STATE
:
2106 DWORD
*pdwConnectedState
= (DWORD
*)lpBuffer
;
2107 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2109 if (*lpdwBufferLength
< sizeof(*pdwConnectedState
))
2110 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2113 *pdwConnectedState
= INTERNET_STATE_CONNECTED
;
2116 *lpdwBufferLength
= sizeof(*pdwConnectedState
);
2119 case INTERNET_OPTION_PROXY
:
2121 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
)lpwhh
;
2122 WININETAPPINFOW wai
;
2126 TRACE("Getting global proxy info\n");
2127 memset(&wai
, 0, sizeof(WININETAPPINFOW
));
2128 INTERNET_ConfigureProxyFromReg( &wai
);
2134 INTERNET_PROXY_INFOW
*pPI
= (INTERNET_PROXY_INFOW
*)lpBuffer
;
2135 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2137 if (lpwai
->lpszProxy
)
2138 proxyBytesRequired
= (lstrlenW(lpwai
->lpszProxy
) + 1) *
2140 if (lpwai
->lpszProxyBypass
)
2141 proxyBypassBytesRequired
=
2142 (lstrlenW(lpwai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
2143 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOW
) +
2144 proxyBytesRequired
+ proxyBypassBytesRequired
)
2145 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2148 LPWSTR proxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2149 sizeof(INTERNET_PROXY_INFOW
));
2150 LPWSTR proxy_bypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2151 sizeof(INTERNET_PROXY_INFOW
) +
2152 proxyBytesRequired
);
2154 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2155 pPI
->lpszProxy
= NULL
;
2156 pPI
->lpszProxyBypass
= NULL
;
2157 if (lpwai
->lpszProxy
)
2159 lstrcpyW(proxy
, lpwai
->lpszProxy
);
2160 pPI
->lpszProxy
= proxy
;
2163 if (lpwai
->lpszProxyBypass
)
2165 lstrcpyW(proxy_bypass
, lpwai
->lpszProxyBypass
);
2166 pPI
->lpszProxyBypass
= proxy_bypass
;
2170 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOW
) +
2171 proxyBytesRequired
+ proxyBypassBytesRequired
;
2175 INTERNET_PROXY_INFOA
*pPI
= (INTERNET_PROXY_INFOA
*)lpBuffer
;
2176 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2178 if (lpwai
->lpszProxy
)
2179 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2180 lpwai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
2181 if (lpwai
->lpszProxyBypass
)
2182 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2183 lpwai
->lpszProxyBypass
, -1, NULL
, 0, NULL
, NULL
);
2184 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOA
) +
2185 proxyBytesRequired
+ proxyBypassBytesRequired
)
2186 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2189 LPSTR proxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2190 sizeof(INTERNET_PROXY_INFOA
));
2191 LPSTR proxy_bypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2192 sizeof(INTERNET_PROXY_INFOA
) +
2193 proxyBytesRequired
);
2195 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2196 pPI
->lpszProxy
= NULL
;
2197 pPI
->lpszProxyBypass
= NULL
;
2198 if (lpwai
->lpszProxy
)
2200 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxy
, -1,
2201 proxy
, proxyBytesRequired
, NULL
, NULL
);
2202 pPI
->lpszProxy
= proxy
;
2205 if (lpwai
->lpszProxyBypass
)
2207 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxyBypass
,
2208 -1, proxy_bypass
, proxyBypassBytesRequired
,
2210 pPI
->lpszProxyBypass
= proxy_bypass
;
2214 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOA
) +
2215 proxyBytesRequired
+ proxyBypassBytesRequired
;
2219 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2222 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn
);
2223 if (*lpdwBufferLength
< sizeof(ULONG
))
2224 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2227 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2230 *lpdwBufferLength
= sizeof(ULONG
);
2233 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2236 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn
);
2237 if (*lpdwBufferLength
< sizeof(ULONG
))
2238 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2241 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2244 *lpdwBufferLength
= sizeof(ULONG
);
2247 case INTERNET_OPTION_SECURITY_FLAGS
:
2248 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2252 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
:
2255 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2258 if (*lpdwBufferLength
< sizeof(INTERNET_CERTIFICATE_INFOW
))
2260 *lpdwBufferLength
= sizeof(INTERNET_CERTIFICATE_INFOW
);
2261 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2263 else if (lpwhh
->htype
== WH_HHTTPREQ
)
2265 LPWININETHTTPREQW lpwhr
;
2266 PCCERT_CONTEXT context
;
2268 lpwhr
= (LPWININETHTTPREQW
)lpwhh
;
2269 context
= (PCCERT_CONTEXT
)NETCON_GetCert(&(lpwhr
->netConnection
));
2272 LPINTERNET_CERTIFICATE_INFOW info
= (LPINTERNET_CERTIFICATE_INFOW
)lpBuffer
;
2275 memset(info
,0,sizeof(INTERNET_CERTIFICATE_INFOW
));
2276 info
->ftExpiry
= context
->pCertInfo
->NotAfter
;
2277 info
->ftStart
= context
->pCertInfo
->NotBefore
;
2280 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2281 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2283 info
->lpszSubjectInfo
= LocalAlloc(0,
2284 strLen
* sizeof(WCHAR
));
2285 if (info
->lpszSubjectInfo
)
2286 CertNameToStrW(context
->dwCertEncodingType
,
2287 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2288 info
->lpszSubjectInfo
, strLen
);
2289 strLen
= CertNameToStrW(context
->dwCertEncodingType
,
2290 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2292 info
->lpszIssuerInfo
= LocalAlloc(0,
2293 strLen
* sizeof(WCHAR
));
2294 if (info
->lpszIssuerInfo
)
2295 CertNameToStrW(context
->dwCertEncodingType
,
2296 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2297 info
->lpszIssuerInfo
, strLen
);
2301 LPINTERNET_CERTIFICATE_INFOA infoA
=
2302 (LPINTERNET_CERTIFICATE_INFOA
)info
;
2304 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2305 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2307 infoA
->lpszSubjectInfo
= LocalAlloc(0, strLen
);
2308 if (infoA
->lpszSubjectInfo
)
2309 CertNameToStrA(context
->dwCertEncodingType
,
2310 &context
->pCertInfo
->Subject
, CERT_SIMPLE_NAME_STR
,
2311 infoA
->lpszSubjectInfo
, strLen
);
2312 strLen
= CertNameToStrA(context
->dwCertEncodingType
,
2313 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2315 infoA
->lpszIssuerInfo
= LocalAlloc(0, strLen
);
2316 if (infoA
->lpszIssuerInfo
)
2317 CertNameToStrA(context
->dwCertEncodingType
,
2318 &context
->pCertInfo
->Issuer
, CERT_SIMPLE_NAME_STR
,
2319 infoA
->lpszIssuerInfo
, strLen
);
2322 * Contrary to MSDN, these do not appear to be set.
2324 * lpszSignatureAlgName
2325 * lpszEncryptionAlgName
2328 CertFreeCertificateContext(context
);
2333 case INTERNET_OPTION_VERSION
:
2335 TRACE("INTERNET_OPTION_VERSION\n");
2336 if (*lpdwBufferLength
< sizeof(INTERNET_VERSION_INFO
))
2337 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2340 static const INTERNET_VERSION_INFO info
= { 6, 0 };
2341 memcpy(lpBuffer
, &info
, sizeof(info
));
2342 *lpdwBufferLength
= sizeof(info
);
2348 FIXME("Stub! %d\n", dwOption
);
2352 WININET_Release( lpwhh
);
2357 /***********************************************************************
2358 * InternetQueryOptionW (WININET.@)
2360 * Queries an options on the specified handle
2367 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2368 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2370 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2373 /***********************************************************************
2374 * InternetQueryOptionA (WININET.@)
2376 * Queries an options on the specified handle
2383 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2384 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2386 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2390 /***********************************************************************
2391 * InternetSetOptionW (WININET.@)
2393 * Sets an options on the specified handle
2400 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2401 LPVOID lpBuffer
, DWORD dwBufferLength
)
2403 LPWININETHANDLEHEADER lpwhh
;
2406 TRACE("0x%08x\n", dwOption
);
2408 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2414 case INTERNET_OPTION_CALLBACK
:
2416 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2417 ret
= (set_status_callback(lpwhh
, callback
, TRUE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2420 case INTERNET_OPTION_HTTP_VERSION
:
2422 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2423 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2426 case INTERNET_OPTION_ERROR_MASK
:
2428 unsigned long flags
=*(unsigned long*)lpBuffer
;
2429 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
2432 case INTERNET_OPTION_CODEPAGE
:
2434 unsigned long codepage
=*(unsigned long*)lpBuffer
;
2435 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
2438 case INTERNET_OPTION_REQUEST_PRIORITY
:
2440 unsigned long priority
=*(unsigned long*)lpBuffer
;
2441 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
2444 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2446 unsigned long connecttimeout
=*(unsigned long*)lpBuffer
;
2447 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout
);
2450 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2452 unsigned long receivetimeout
=*(unsigned long*)lpBuffer
;
2453 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout
);
2456 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2458 unsigned long conns
=*(unsigned long*)lpBuffer
;
2459 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns
);
2462 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2464 unsigned long conns
=*(unsigned long*)lpBuffer
;
2465 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns
);
2468 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2469 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2471 case INTERNET_OPTION_END_BROWSER_SESSION
:
2472 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2474 case INTERNET_OPTION_CONNECTED_STATE
:
2475 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2477 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2478 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2480 case INTERNET_OPTION_SEND_TIMEOUT
:
2481 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2482 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2483 if (dwBufferLength
== sizeof(DWORD
))
2485 if (lpwhh
->htype
== WH_HHTTPREQ
)
2486 ret
= NETCON_set_timeout(
2487 &((LPWININETHTTPREQW
)lpwhh
)->netConnection
,
2488 dwOption
== INTERNET_OPTION_SEND_TIMEOUT
,
2489 *(DWORD
*)lpBuffer
);
2492 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2498 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2502 case INTERNET_OPTION_CONNECT_RETRIES
:
2503 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2505 case INTERNET_OPTION_CONTEXT_VALUE
:
2506 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2508 case INTERNET_OPTION_SECURITY_FLAGS
:
2509 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2512 FIXME("Option %d STUB\n",dwOption
);
2513 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2517 WININET_Release( lpwhh
);
2523 /***********************************************************************
2524 * InternetSetOptionA (WININET.@)
2526 * Sets an options on the specified handle.
2533 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2534 LPVOID lpBuffer
, DWORD dwBufferLength
)
2542 case INTERNET_OPTION_CALLBACK
:
2544 LPWININETHANDLEHEADER lpwh
;
2545 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2547 if (!(lpwh
= (LPWININETHANDLEHEADER
)WININET_GetObject(hInternet
))) return FALSE
;
2548 r
= (set_status_callback(lpwh
, callback
, FALSE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2549 WININET_Release(lpwh
);
2552 case INTERNET_OPTION_PROXY
:
2554 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2555 LPINTERNET_PROXY_INFOW piw
;
2556 DWORD proxlen
, prbylen
;
2559 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2560 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2561 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2562 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2563 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2564 piw
->dwAccessType
= pi
->dwAccessType
;
2565 prox
= (LPWSTR
) &piw
[1];
2566 prby
= &prox
[proxlen
+1];
2567 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2568 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2569 piw
->lpszProxy
= prox
;
2570 piw
->lpszProxyBypass
= prby
;
2573 case INTERNET_OPTION_USER_AGENT
:
2574 case INTERNET_OPTION_USERNAME
:
2575 case INTERNET_OPTION_PASSWORD
:
2576 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2578 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2579 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2584 wlen
= dwBufferLength
;
2587 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2589 if( lpBuffer
!= wbuffer
)
2590 HeapFree( GetProcessHeap(), 0, wbuffer
);
2596 /***********************************************************************
2597 * InternetSetOptionExA (WININET.@)
2599 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2600 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2602 FIXME("Flags %08x ignored\n", dwFlags
);
2603 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2606 /***********************************************************************
2607 * InternetSetOptionExW (WININET.@)
2609 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2610 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2612 FIXME("Flags %08x ignored\n", dwFlags
);
2613 if( dwFlags
& ~ISO_VALID_FLAGS
)
2615 INTERNET_SetLastError( ERROR_INVALID_PARAMETER
);
2618 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2621 static const WCHAR WININET_wkday
[7][4] =
2622 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2623 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2624 static const WCHAR WININET_month
[12][4] =
2625 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2626 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2627 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2629 /***********************************************************************
2630 * InternetTimeFromSystemTimeA (WININET.@)
2632 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2635 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2637 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2639 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2640 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2645 /***********************************************************************
2646 * InternetTimeFromSystemTimeW (WININET.@)
2648 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2650 static const WCHAR date
[] =
2651 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2652 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2654 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2656 if (!time
|| !string
) return FALSE
;
2658 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2661 sprintfW( string
, date
,
2662 WININET_wkday
[time
->wDayOfWeek
],
2664 WININET_month
[time
->wMonth
- 1],
2673 /***********************************************************************
2674 * InternetTimeToSystemTimeA (WININET.@)
2676 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2682 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
2684 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2685 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2689 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2690 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2691 HeapFree( GetProcessHeap(), 0, stringW
);
2696 /***********************************************************************
2697 * InternetTimeToSystemTimeW (WININET.@)
2699 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2702 const WCHAR
*s
= string
;
2705 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
2707 if (!string
|| !time
) return FALSE
;
2709 /* Windows does this too */
2710 GetSystemTime( time
);
2712 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2713 * a SYSTEMTIME structure.
2716 while (*s
&& !isalphaW( *s
)) s
++;
2717 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2718 time
->wDayOfWeek
= 7;
2720 for (i
= 0; i
< 7; i
++)
2722 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2723 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2724 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2726 time
->wDayOfWeek
= i
;
2731 if (time
->wDayOfWeek
> 6) return TRUE
;
2732 while (*s
&& !isdigitW( *s
)) s
++;
2733 time
->wDay
= strtolW( s
, &end
, 10 );
2736 while (*s
&& !isalphaW( *s
)) s
++;
2737 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2740 for (i
= 0; i
< 12; i
++)
2742 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2743 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2744 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2746 time
->wMonth
= i
+ 1;
2750 if (time
->wMonth
== 0) return TRUE
;
2752 while (*s
&& !isdigitW( *s
)) s
++;
2753 if (*s
== '\0') return TRUE
;
2754 time
->wYear
= strtolW( s
, &end
, 10 );
2757 while (*s
&& !isdigitW( *s
)) s
++;
2758 if (*s
== '\0') return TRUE
;
2759 time
->wHour
= strtolW( s
, &end
, 10 );
2762 while (*s
&& !isdigitW( *s
)) s
++;
2763 if (*s
== '\0') return TRUE
;
2764 time
->wMinute
= strtolW( s
, &end
, 10 );
2767 while (*s
&& !isdigitW( *s
)) s
++;
2768 if (*s
== '\0') return TRUE
;
2769 time
->wSecond
= strtolW( s
, &end
, 10 );
2772 time
->wMilliseconds
= 0;
2776 /***********************************************************************
2777 * InternetCheckConnectionW (WININET.@)
2779 * Pings a requested host to check internet connection
2782 * TRUE on success and FALSE on failure. If a failure then
2783 * ERROR_NOT_CONNECTED is placed into GetLastError
2786 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2789 * this is a kludge which runs the resident ping program and reads the output.
2791 * Anyone have a better idea?
2795 static const CHAR ping
[] = "ping -c 1 ";
2796 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2797 CHAR
*command
= NULL
;
2806 * Crack or set the Address
2808 if (lpszUrl
== NULL
)
2811 * According to the doc we are supposed to use the ip for the next
2812 * server in the WnInet internal server database. I have
2813 * no idea what that is or how to get it.
2815 * So someone needs to implement this.
2817 FIXME("Unimplemented with URL of NULL\n");
2822 URL_COMPONENTSW components
;
2824 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2825 components
.lpszHostName
= (LPWSTR
)&hostW
;
2826 components
.dwHostNameLength
= 1024;
2828 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2831 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2832 port
= components
.nPort
;
2833 TRACE("port: %d\n", port
);
2836 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
2838 struct sockaddr_in sin
;
2841 if (!GetAddress(hostW
, port
, &sin
))
2843 fd
= socket(sin
.sin_family
, SOCK_STREAM
, 0);
2846 if (connect(fd
, (struct sockaddr
*)&sin
, sizeof(sin
)) == 0)
2854 * Build our ping command
2856 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2857 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2858 strcpy(command
,ping
);
2859 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2860 strcat(command
,redirect
);
2862 TRACE("Ping command is : %s\n",command
);
2864 status
= system(command
);
2866 TRACE("Ping returned a code of %i\n",status
);
2868 /* Ping return code of 0 indicates success */
2875 HeapFree( GetProcessHeap(), 0, command
);
2877 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
2883 /***********************************************************************
2884 * InternetCheckConnectionA (WININET.@)
2886 * Pings a requested host to check internet connection
2889 * TRUE on success and FALSE on failure. If a failure then
2890 * ERROR_NOT_CONNECTED is placed into GetLastError
2893 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2899 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2900 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2902 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2903 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2904 HeapFree(GetProcessHeap(), 0, szUrl
);
2910 /**********************************************************
2911 * INTERNET_InternetOpenUrlW (internal)
2916 * handle of connection or NULL on failure
2918 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2919 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2921 URL_COMPONENTSW urlComponents
;
2922 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2923 WCHAR password
[1024], path
[2048], extra
[1024];
2924 HINTERNET client
= NULL
, client1
= NULL
;
2926 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2927 dwHeadersLength
, dwFlags
, dwContext
);
2929 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2930 urlComponents
.lpszScheme
= protocol
;
2931 urlComponents
.dwSchemeLength
= 32;
2932 urlComponents
.lpszHostName
= hostName
;
2933 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2934 urlComponents
.lpszUserName
= userName
;
2935 urlComponents
.dwUserNameLength
= 1024;
2936 urlComponents
.lpszPassword
= password
;
2937 urlComponents
.dwPasswordLength
= 1024;
2938 urlComponents
.lpszUrlPath
= path
;
2939 urlComponents
.dwUrlPathLength
= 2048;
2940 urlComponents
.lpszExtraInfo
= extra
;
2941 urlComponents
.dwExtraInfoLength
= 1024;
2942 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2944 switch(urlComponents
.nScheme
) {
2945 case INTERNET_SCHEME_FTP
:
2946 if(urlComponents
.nPort
== 0)
2947 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2948 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2949 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2952 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2953 if(client1
== NULL
) {
2954 InternetCloseHandle(client
);
2959 case INTERNET_SCHEME_HTTP
:
2960 case INTERNET_SCHEME_HTTPS
: {
2961 static const WCHAR szStars
[] = { '*','/','*', 0 };
2962 LPCWSTR accept
[2] = { szStars
, NULL
};
2963 if(urlComponents
.nPort
== 0) {
2964 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2965 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2967 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2969 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2970 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2971 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2975 if (urlComponents
.dwExtraInfoLength
) {
2977 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
2979 if (!(path_extra
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
2981 InternetCloseHandle(client
);
2984 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
2985 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
2986 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2987 HeapFree(GetProcessHeap(), 0, path_extra
);
2990 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2992 if(client1
== NULL
) {
2993 InternetCloseHandle(client
);
2996 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2997 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
2998 GetLastError() != ERROR_IO_PENDING
) {
2999 InternetCloseHandle(client1
);
3004 case INTERNET_SCHEME_GOPHER
:
3005 /* gopher doesn't seem to be implemented in wine, but it's supposed
3006 * to be supported by InternetOpenUrlA. */
3008 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
3012 TRACE(" %p <--\n", client1
);
3017 /**********************************************************
3018 * InternetOpenUrlW (WININET.@)
3023 * handle of connection or NULL on failure
3025 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
3027 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
3028 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
->hdr
;
3032 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3033 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3034 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
3035 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
3038 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
3039 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3041 HINTERNET ret
= NULL
;
3042 LPWININETAPPINFOW hIC
= NULL
;
3044 if (TRACE_ON(wininet
)) {
3045 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
3046 dwHeadersLength
, dwFlags
, dwContext
);
3048 dump_INTERNET_FLAGS(dwFlags
);
3053 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3057 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
3058 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
3059 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
3063 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
3064 WORKREQUEST workRequest
;
3065 struct WORKREQ_INTERNETOPENURLW
*req
;
3067 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
3068 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
3069 req
= &workRequest
.u
.InternetOpenUrlW
;
3070 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
3072 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
3074 req
->lpszHeaders
= 0;
3075 req
->dwHeadersLength
= dwHeadersLength
;
3076 req
->dwFlags
= dwFlags
;
3077 req
->dwContext
= dwContext
;
3079 INTERNET_AsyncCall(&workRequest
);
3081 * This is from windows.
3083 INTERNET_SetLastError(ERROR_IO_PENDING
);
3085 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
3090 WININET_Release( &hIC
->hdr
);
3091 TRACE(" %p <--\n", ret
);
3096 /**********************************************************
3097 * InternetOpenUrlA (WININET.@)
3102 * handle of connection or NULL on failure
3104 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
3105 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
3107 HINTERNET rc
= (HINTERNET
)NULL
;
3111 LPWSTR szUrl
= NULL
;
3112 LPWSTR szHeaders
= NULL
;
3117 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
3118 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
3120 return (HINTERNET
)NULL
;
3121 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
3125 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3126 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
3128 HeapFree(GetProcessHeap(), 0, szUrl
);
3129 return (HINTERNET
)NULL
;
3131 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3134 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3135 lenHeaders
, dwFlags
, dwContext
);
3137 HeapFree(GetProcessHeap(), 0, szUrl
);
3138 HeapFree(GetProcessHeap(), 0, szHeaders
);
3144 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3146 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite
));
3150 lpwite
->dwError
= 0;
3151 lpwite
->response
[0] = '\0';
3154 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3156 HeapFree(GetProcessHeap(), 0, lpwite
);
3164 /***********************************************************************
3165 * INTERNET_SetLastError (internal)
3167 * Set last thread specific error
3172 void INTERNET_SetLastError(DWORD dwError
)
3174 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3177 lpwite
= INTERNET_AllocThreadError();
3179 SetLastError(dwError
);
3181 lpwite
->dwError
= dwError
;
3185 /***********************************************************************
3186 * INTERNET_GetLastError (internal)
3188 * Get last thread specific error
3193 DWORD
INTERNET_GetLastError(void)
3195 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3196 if (!lpwite
) return 0;
3197 /* TlsGetValue clears last error, so set it again here */
3198 SetLastError(lpwite
->dwError
);
3199 return lpwite
->dwError
;
3203 /***********************************************************************
3204 * INTERNET_WorkerThreadFunc (internal)
3206 * Worker thread execution function
3211 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3213 LPWORKREQUEST lpRequest
= lpvParam
;
3214 WORKREQUEST workRequest
;
3218 memcpy(&workRequest
, lpRequest
, sizeof(WORKREQUEST
));
3219 HeapFree(GetProcessHeap(), 0, lpRequest
);
3221 workRequest
.asyncproc(&workRequest
);
3223 WININET_Release( workRequest
.hdr
);
3228 /***********************************************************************
3229 * INTERNET_AsyncCall (internal)
3231 * Retrieves work request from queue
3236 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3239 LPWORKREQUEST lpNewRequest
;
3243 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3247 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
3249 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3252 HeapFree(GetProcessHeap(), 0, lpNewRequest
);
3253 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3260 /***********************************************************************
3261 * INTERNET_GetResponseBuffer (internal)
3266 LPSTR
INTERNET_GetResponseBuffer(void)
3268 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3270 lpwite
= INTERNET_AllocThreadError();
3272 return lpwite
->response
;
3275 /***********************************************************************
3276 * INTERNET_GetNextLine (internal)
3278 * Parse next line in directory string listing
3281 * Pointer to beginning of next line
3286 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3290 BOOL bSuccess
= FALSE
;
3292 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3297 FD_SET(nSocket
, &infd
);
3298 tv
.tv_sec
=RESPONSE_TIMEOUT
;
3301 while (nRecv
< MAX_REPLY_LEN
)
3303 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
3305 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3307 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3311 if (lpszBuffer
[nRecv
] == '\n')
3316 if (lpszBuffer
[nRecv
] != '\r')
3321 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3329 lpszBuffer
[nRecv
] = '\0';
3331 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3340 /**********************************************************
3341 * InternetQueryDataAvailable (WININET.@)
3343 * Determines how much data is available to be read.
3346 * TRUE on success, FALSE if an error occurred. If
3347 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3348 * no data is presently available, FALSE is returned with
3349 * the last error ERROR_IO_PENDING; a callback with status
3350 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3351 * data is available.
3353 void AsyncInternetQueryDataAvailableProc(WORKREQUEST
*workRequest
)
3355 LPWININETHTTPREQW lpwhr
;
3356 INTERNET_ASYNC_RESULT iar
;
3359 TRACE("INTERNETQUERYDATAAVAILABLE %p\n", workRequest
->hdr
);
3361 switch (workRequest
->hdr
->htype
)
3364 lpwhr
= (LPWININETHTTPREQW
)workRequest
->hdr
;
3365 iar
.dwResult
= NETCON_recv(&lpwhr
->netConnection
, buffer
,
3367 lpwhr
->dwContentLength
- lpwhr
->dwContentRead
),
3368 MSG_PEEK
, (int *)&iar
.dwError
);
3369 INTERNET_SendCallback(workRequest
->hdr
, workRequest
->hdr
->dwContext
,
3370 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
3371 sizeof(INTERNET_ASYNC_RESULT
));
3375 FIXME("unsupported file type\n");
3380 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3381 LPDWORD lpdwNumberOfBytesAvailble
,
3382 DWORD dwFlags
, DWORD_PTR dwContext
)
3384 LPWININETHTTPREQW lpwhr
;
3385 BOOL retval
= FALSE
;
3388 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hFile
);
3391 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
3395 TRACE("--> %p %i\n",lpwhr
,lpwhr
->hdr
.htype
);
3397 switch (lpwhr
->hdr
.htype
)
3401 if (NETCON_query_data_available(&lpwhr
->netConnection
,
3402 lpdwNumberOfBytesAvailble
) &&
3403 !*lpdwNumberOfBytesAvailble
)
3405 /* Even if we are in async mode, we need to determine whether
3406 * there is actually more data available. We do this by trying
3407 * to peek only a single byte in async mode. */
3408 BOOL async
= (lpwhr
->lpHttpSession
->lpAppInfo
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
);
3409 if (NETCON_recv(&lpwhr
->netConnection
, buffer
,
3410 min(async
? 1 : sizeof(buffer
),
3411 lpwhr
->dwContentLength
- lpwhr
->dwContentRead
),
3412 MSG_PEEK
, (int *)lpdwNumberOfBytesAvailble
) &&
3413 async
&& *lpdwNumberOfBytesAvailble
)
3415 WORKREQUEST workRequest
;
3417 *lpdwNumberOfBytesAvailble
= 0;
3418 workRequest
.asyncproc
= AsyncInternetQueryDataAvailableProc
;
3419 workRequest
.hdr
= WININET_AddRef( &lpwhr
->hdr
);
3421 retval
= INTERNET_AsyncCall(&workRequest
);
3424 WININET_Release( &lpwhr
->hdr
);
3428 INTERNET_SetLastError(ERROR_IO_PENDING
);
3436 FIXME("unsupported file type\n");
3439 WININET_Release( &lpwhr
->hdr
);
3441 TRACE("<-- %i\n",retval
);
3446 /***********************************************************************
3447 * InternetLockRequestFile (WININET.@)
3449 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3456 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3463 /***********************************************************************
3464 * InternetAutodial (WININET.@)
3466 * On windows this function is supposed to dial the default internet
3467 * connection. We don't want to have Wine dial out to the internet so
3468 * we return TRUE by default. It might be nice to check if we are connected.
3475 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3479 /* Tell that we are connected to the internet. */
3483 /***********************************************************************
3484 * InternetAutodialHangup (WININET.@)
3486 * Hangs up a connection made with InternetAutodial
3495 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3499 /* we didn't dial, we don't disconnect */
3503 /***********************************************************************
3504 * InternetCombineUrlA (WININET.@)
3506 * Combine a base URL with a relative URL
3514 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3515 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3520 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3522 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3523 dwFlags
^= ICU_NO_ENCODE
;
3524 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3529 /***********************************************************************
3530 * InternetCombineUrlW (WININET.@)
3532 * Combine a base URL with a relative URL
3540 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3541 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3546 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3548 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3549 dwFlags
^= ICU_NO_ENCODE
;
3550 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3555 /* max port num is 65535 => 5 digits */
3556 #define MAX_WORD_DIGITS 5
3558 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3559 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3560 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3561 (url)->dw##component##Length : strlen((url)->lpsz##component))
3563 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3565 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3566 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3568 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3569 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3571 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3572 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3574 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3575 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3578 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3584 /* opaque urls do not fit into the standard url hierarchy and don't have
3585 * two following slashes */
3586 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3588 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3589 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3590 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3591 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3592 (nScheme
!= INTERNET_SCHEME_FILE
);
3595 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3598 if (scheme
< INTERNET_SCHEME_FIRST
)
3600 index
= scheme
- INTERNET_SCHEME_FIRST
;
3601 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3603 return (LPCWSTR
)&url_schemes
[index
];
3606 /* we can calculate using ansi strings because we're just
3607 * calculating string length, not size
3609 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3610 LPDWORD lpdwUrlLength
)
3612 INTERNET_SCHEME nScheme
;
3616 if (lpUrlComponents
->lpszScheme
)
3618 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3619 *lpdwUrlLength
+= dwLen
;
3620 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3626 nScheme
= lpUrlComponents
->nScheme
;
3628 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3629 nScheme
= INTERNET_SCHEME_HTTP
;
3630 scheme
= INTERNET_GetSchemeString(nScheme
);
3631 *lpdwUrlLength
+= strlenW(scheme
);
3634 (*lpdwUrlLength
)++; /* ':' */
3635 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3636 *lpdwUrlLength
+= strlen("//");
3638 if (lpUrlComponents
->lpszUserName
)
3640 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3641 *lpdwUrlLength
+= strlen("@");
3645 if (lpUrlComponents
->lpszPassword
)
3647 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3652 if (lpUrlComponents
->lpszPassword
)
3654 *lpdwUrlLength
+= strlen(":");
3655 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3658 if (lpUrlComponents
->lpszHostName
)
3660 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3662 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3664 char szPort
[MAX_WORD_DIGITS
+1];
3666 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3667 *lpdwUrlLength
+= strlen(szPort
);
3668 *lpdwUrlLength
+= strlen(":");
3671 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3672 (*lpdwUrlLength
)++; /* '/' */
3675 if (lpUrlComponents
->lpszUrlPath
)
3676 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3681 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3685 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3687 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3688 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3689 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3690 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3691 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3692 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3693 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3694 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3695 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3697 if (lpUrlComponents
->lpszScheme
)
3699 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
3700 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3701 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3702 -1, urlCompW
->lpszScheme
, len
);
3705 if (lpUrlComponents
->lpszHostName
)
3707 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
3708 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3709 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3710 -1, urlCompW
->lpszHostName
, len
);
3713 if (lpUrlComponents
->lpszUserName
)
3715 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
3716 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3717 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3718 -1, urlCompW
->lpszUserName
, len
);
3721 if (lpUrlComponents
->lpszPassword
)
3723 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
3724 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3725 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3726 -1, urlCompW
->lpszPassword
, len
);
3729 if (lpUrlComponents
->lpszUrlPath
)
3731 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
3732 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3733 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3734 -1, urlCompW
->lpszUrlPath
, len
);
3737 if (lpUrlComponents
->lpszExtraInfo
)
3739 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
3740 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3741 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3742 -1, urlCompW
->lpszExtraInfo
, len
);
3746 /***********************************************************************
3747 * InternetCreateUrlA (WININET.@)
3749 * See InternetCreateUrlW.
3751 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3752 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3756 URL_COMPONENTSW urlCompW
;
3758 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3760 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3762 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3766 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3769 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3771 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3773 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3774 *lpdwUrlLength
/= sizeof(WCHAR
);
3776 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3777 * minus one, so add one to leave room for NULL terminator
3780 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3782 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3783 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3784 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3785 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3786 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3787 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3788 HeapFree(GetProcessHeap(), 0, urlW
);
3793 /***********************************************************************
3794 * InternetCreateUrlW (WININET.@)
3796 * Creates a URL from its component parts.
3799 * lpUrlComponents [I] URL Components.
3800 * dwFlags [I] Flags. See notes.
3801 * lpszUrl [I] Buffer in which to store the created URL.
3802 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3803 * lpszUrl in characters. On output, the number of bytes
3804 * required to store the URL including terminator.
3808 * The dwFlags parameter can be zero or more of the following:
3809 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3816 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3817 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3820 INTERNET_SCHEME nScheme
;
3822 static const WCHAR slashSlashW
[] = {'/','/'};
3823 static const WCHAR percentD
[] = {'%','d',0};
3825 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3827 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3829 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3833 if (!calc_url_length(lpUrlComponents
, &dwLen
))
3836 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3838 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
3839 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3843 *lpdwUrlLength
= dwLen
;
3848 if (lpUrlComponents
->lpszScheme
)
3850 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3851 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
3854 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3859 nScheme
= lpUrlComponents
->nScheme
;
3861 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3862 nScheme
= INTERNET_SCHEME_HTTP
;
3864 scheme
= INTERNET_GetSchemeString(nScheme
);
3865 dwLen
= strlenW(scheme
);
3866 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
3870 /* all schemes are followed by at least a colon */
3874 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3876 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
3877 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
3880 if (lpUrlComponents
->lpszUserName
)
3882 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3883 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
3886 if (lpUrlComponents
->lpszPassword
)
3891 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3892 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
3900 if (lpUrlComponents
->lpszHostName
)
3902 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3903 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
3906 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3908 WCHAR szPort
[MAX_WORD_DIGITS
+1];
3910 sprintfW(szPort
, percentD
, lpUrlComponents
->nPort
);
3913 dwLen
= strlenW(szPort
);
3914 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
3918 /* add slash between hostname and path if necessary */
3919 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3927 if (lpUrlComponents
->lpszUrlPath
)
3929 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3930 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
3939 /***********************************************************************
3940 * InternetConfirmZoneCrossingA (WININET.@)
3943 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
3945 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
3946 return ERROR_SUCCESS
;
3949 /***********************************************************************
3950 * InternetConfirmZoneCrossingW (WININET.@)
3953 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
3955 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
3956 return ERROR_SUCCESS
;
3959 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
3960 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3962 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3963 lpdwConnection
, dwReserved
);
3964 return ERROR_SUCCESS
;
3967 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
3968 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3970 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3971 lpdwConnection
, dwReserved
);
3972 return ERROR_SUCCESS
;
3975 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3977 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
3981 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3983 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
3987 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
3989 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
3990 return ERROR_SUCCESS
;
3993 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
3996 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
3997 debugstr_w(pwszTarget
), pbHexHash
);
4001 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4003 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
4007 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
4009 FIXME("(%p, %08lx) stub\n", a
, b
);