4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
44 #ifdef HAVE_SYS_POLL_H
45 # include <sys/poll.h>
47 #ifdef HAVE_SYS_TIME_H
48 # include <sys/time.h>
64 #include "wine/debug.h"
66 #define NO_SHLWAPI_STREAM
69 #include "wine/exception.h"
74 #include "wine/unicode.h"
76 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
78 #define RESPONSE_TIMEOUT 30
83 CHAR response
[MAX_REPLY_LEN
];
84 } WITHREADERROR
, *LPWITHREADERROR
;
86 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
87 static HMODULE WININET_hModule
;
89 #define HANDLE_CHUNK_SIZE 0x10
91 static CRITICAL_SECTION WININET_cs
;
92 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
95 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
96 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
98 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
100 static LPWININETHANDLEHEADER
*WININET_Handles
;
101 static UINT WININET_dwNextHandle
;
102 static UINT WININET_dwMaxHandles
;
104 HINTERNET
WININET_AllocHandle( LPWININETHANDLEHEADER info
)
106 LPWININETHANDLEHEADER
*p
;
107 UINT handle
= 0, num
;
109 list_init( &info
->children
);
111 EnterCriticalSection( &WININET_cs
);
112 if( !WININET_dwMaxHandles
)
114 num
= HANDLE_CHUNK_SIZE
;
115 p
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
120 WININET_dwMaxHandles
= num
;
122 if( WININET_dwMaxHandles
== WININET_dwNextHandle
)
124 num
= WININET_dwMaxHandles
+ HANDLE_CHUNK_SIZE
;
125 p
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
126 WININET_Handles
, sizeof (UINT
)* num
);
130 WININET_dwMaxHandles
= num
;
133 handle
= WININET_dwNextHandle
;
134 if( WININET_Handles
[handle
] )
135 ERR("handle isn't free but should be\n");
136 WININET_Handles
[handle
] = WININET_AddRef( info
);
138 while( WININET_Handles
[WININET_dwNextHandle
] &&
139 (WININET_dwNextHandle
< WININET_dwMaxHandles
) )
140 WININET_dwNextHandle
++;
143 LeaveCriticalSection( &WININET_cs
);
145 return info
->hInternet
= (HINTERNET
) (handle
+1);
148 LPWININETHANDLEHEADER
WININET_AddRef( LPWININETHANDLEHEADER info
)
150 ULONG refs
= InterlockedIncrement(&info
->refs
);
151 TRACE("%p -> refcount = %d\n", info
, refs
);
155 LPWININETHANDLEHEADER
WININET_GetObject( HINTERNET hinternet
)
157 LPWININETHANDLEHEADER info
= NULL
;
158 UINT handle
= (UINT
) hinternet
;
160 EnterCriticalSection( &WININET_cs
);
162 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) &&
163 WININET_Handles
[handle
-1] )
164 info
= WININET_AddRef( WININET_Handles
[handle
-1] );
166 LeaveCriticalSection( &WININET_cs
);
168 TRACE("handle %d -> %p\n", handle
, info
);
173 BOOL
WININET_Release( LPWININETHANDLEHEADER info
)
175 ULONG refs
= InterlockedDecrement(&info
->refs
);
176 TRACE( "object %p refcount = %d\n", info
, refs
);
179 if ( info
->vtbl
->CloseConnection
)
181 TRACE( "closing connection %p\n", info
);
182 info
->vtbl
->CloseConnection( info
);
184 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
185 if (info
->htype
!= WH_HHTTPSESSION
|| !(info
->dwInternalFlags
& INET_OPENURL
))
187 INTERNET_SendCallback(info
, info
->dwContext
,
188 INTERNET_STATUS_HANDLE_CLOSING
, &info
->hInternet
,
191 TRACE( "destroying object %p\n", info
);
192 if ( info
->htype
!= WH_HINIT
)
193 list_remove( &info
->entry
);
194 info
->vtbl
->Destroy( info
);
199 BOOL
WININET_FreeHandle( HINTERNET hinternet
)
202 UINT handle
= (UINT
) hinternet
;
203 LPWININETHANDLEHEADER info
= NULL
, child
, next
;
205 EnterCriticalSection( &WININET_cs
);
207 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) )
210 if( WININET_Handles
[handle
] )
212 info
= WININET_Handles
[handle
];
213 TRACE( "destroying handle %d for object %p\n", handle
+1, info
);
214 WININET_Handles
[handle
] = NULL
;
219 LeaveCriticalSection( &WININET_cs
);
221 /* As on native when the equivalent of WININET_Release is called, the handle
222 * is already invalid, but if a new handle is created at this time it does
223 * not yet get assigned the freed handle number */
226 /* Free all children as native does */
227 LIST_FOR_EACH_ENTRY_SAFE( child
, next
, &info
->children
, WININETHANDLEHEADER
, entry
)
229 TRACE( "freeing child handle %d for parent handle %d\n",
230 (UINT
)child
->hInternet
, handle
+1);
231 WININET_FreeHandle( child
->hInternet
);
233 WININET_Release( info
);
236 EnterCriticalSection( &WININET_cs
);
238 if( WININET_dwNextHandle
> handle
&& !WININET_Handles
[handle
] )
239 WININET_dwNextHandle
= handle
;
241 LeaveCriticalSection( &WININET_cs
);
246 /***********************************************************************
247 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
250 * hinstDLL [I] handle to the DLL's instance
252 * lpvReserved [I] reserved, must be NULL
259 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
261 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
264 case DLL_PROCESS_ATTACH
:
266 g_dwTlsErrIndex
= TlsAlloc();
268 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
271 URLCacheContainers_CreateDefaults();
273 WININET_hModule
= hinstDLL
;
275 case DLL_THREAD_ATTACH
:
278 case DLL_THREAD_DETACH
:
279 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
281 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
282 HeapFree(GetProcessHeap(), 0, lpwite
);
286 case DLL_PROCESS_DETACH
:
288 URLCacheContainers_DeleteAll();
290 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
292 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
293 TlsFree(g_dwTlsErrIndex
);
302 /***********************************************************************
303 * InternetInitializeAutoProxyDll (WININET.@)
305 * Setup the internal proxy
314 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
317 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
321 /***********************************************************************
322 * DetectAutoProxyUrl (WININET.@)
324 * Auto detect the proxy url
330 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
331 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
334 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
339 /***********************************************************************
340 * INTERNET_ConfigureProxy
343 * The proxy may be specified in the form 'http=proxy.my.org'
344 * Presumably that means there can be ftp=ftpproxy.my.org too.
346 static BOOL
INTERNET_ConfigureProxy( LPWININETAPPINFOW lpwai
)
349 DWORD type
, len
, enabled
= 0;
351 static const WCHAR szInternetSettings
[] =
352 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
353 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
354 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
355 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
356 static const WCHAR szProxyEnable
[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
358 if (RegOpenKeyW( HKEY_CURRENT_USER
, szInternetSettings
, &key
)) return FALSE
;
360 len
= sizeof enabled
;
361 if (RegQueryValueExW( key
, szProxyEnable
, NULL
, &type
, (BYTE
*)&enabled
, &len
) || type
!= REG_DWORD
)
362 RegSetValueExW( key
, szProxyEnable
, 0, REG_DWORD
, (BYTE
*)&enabled
, sizeof(REG_DWORD
) );
366 TRACE("Proxy is enabled.\n");
368 /* figure out how much memory the proxy setting takes */
369 if (!RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, NULL
, &len
) && len
&& (type
== REG_SZ
))
372 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
374 if (!(szProxy
= HeapAlloc( GetProcessHeap(), 0, len
)))
379 RegQueryValueExW( key
, szProxyServer
, NULL
, &type
, (BYTE
*)szProxy
, &len
);
381 /* find the http proxy, and strip away everything else */
382 p
= strstrW( szProxy
, szHttp
);
385 p
+= lstrlenW( szHttp
);
386 lstrcpyW( szProxy
, p
);
388 p
= strchrW( szProxy
, ' ' );
391 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
392 lpwai
->lpszProxy
= szProxy
;
394 TRACE("http proxy = %s\n", debugstr_w(lpwai
->lpszProxy
));
397 ERR("Couldn't read proxy server settings from registry.\n");
399 else if ((envproxy
= getenv( "http_proxy" )))
403 len
= MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, NULL
, 0 );
404 if (!(envproxyW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
)))) return FALSE
;
405 MultiByteToWideChar( CP_UNIXCP
, 0, envproxy
, -1, envproxyW
, len
);
407 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
408 lpwai
->lpszProxy
= envproxyW
;
410 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwai
->lpszProxy
));
413 if (!enabled
) TRACE("Proxy is not enabled.\n");
416 return (enabled
> 0);
419 /***********************************************************************
420 * dump_INTERNET_FLAGS
422 * Helper function to TRACE the internet flags.
428 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
430 #define FE(x) { x, #x }
431 static const wininet_flag_info flag
[] = {
432 FE(INTERNET_FLAG_RELOAD
),
433 FE(INTERNET_FLAG_RAW_DATA
),
434 FE(INTERNET_FLAG_EXISTING_CONNECT
),
435 FE(INTERNET_FLAG_ASYNC
),
436 FE(INTERNET_FLAG_PASSIVE
),
437 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
438 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
439 FE(INTERNET_FLAG_FROM_CACHE
),
440 FE(INTERNET_FLAG_SECURE
),
441 FE(INTERNET_FLAG_KEEP_CONNECTION
),
442 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
443 FE(INTERNET_FLAG_READ_PREFETCH
),
444 FE(INTERNET_FLAG_NO_COOKIES
),
445 FE(INTERNET_FLAG_NO_AUTH
),
446 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
447 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
448 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
449 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
450 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
451 FE(INTERNET_FLAG_RESYNCHRONIZE
),
452 FE(INTERNET_FLAG_HYPERLINK
),
453 FE(INTERNET_FLAG_NO_UI
),
454 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
455 FE(INTERNET_FLAG_CACHE_ASYNC
),
456 FE(INTERNET_FLAG_FORMS_SUBMIT
),
457 FE(INTERNET_FLAG_NEED_FILE
),
458 FE(INTERNET_FLAG_TRANSFER_ASCII
),
459 FE(INTERNET_FLAG_TRANSFER_BINARY
)
464 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
465 if (flag
[i
].val
& dwFlags
) {
466 TRACE(" %s", flag
[i
].name
);
467 dwFlags
&= ~flag
[i
].val
;
471 TRACE(" Unknown flags (%08x)\n", dwFlags
);
476 /***********************************************************************
477 * INTERNET_CloseHandle (internal)
479 * Close internet handle
482 static VOID
APPINFO_Destroy(WININETHANDLEHEADER
*hdr
)
484 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
488 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
489 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
490 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
491 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
492 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
493 HeapFree(GetProcessHeap(), 0, lpwai
);
496 static DWORD
APPINFO_QueryOption(WININETHANDLEHEADER
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
498 LPWININETAPPINFOW ai
= (LPWININETAPPINFOW
)hdr
;
501 case INTERNET_OPTION_HANDLE_TYPE
:
502 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
504 if (*size
< sizeof(ULONG
))
505 return ERROR_INSUFFICIENT_BUFFER
;
507 *size
= sizeof(DWORD
);
508 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
509 return ERROR_SUCCESS
;
511 case INTERNET_OPTION_USER_AGENT
: {
514 TRACE("INTERNET_OPTION_USER_AGENT\n");
519 *size
= (strlenW(ai
->lpszAgent
) + 1) * sizeof(WCHAR
);
520 if(!buffer
|| bufsize
< *size
)
521 return ERROR_INSUFFICIENT_BUFFER
;
523 strcpyW(buffer
, ai
->lpszAgent
);
525 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->lpszAgent
, -1, NULL
, 0, NULL
, NULL
);
526 if(!buffer
|| bufsize
< *size
)
527 return ERROR_INSUFFICIENT_BUFFER
;
529 WideCharToMultiByte(CP_ACP
, 0, ai
->lpszAgent
, -1, buffer
, *size
, NULL
, NULL
);
532 return ERROR_SUCCESS
;
536 FIXME("Not implemented option %d\n", option
);
537 return ERROR_INTERNET_INVALID_OPTION
;
540 static const HANDLEHEADERVtbl APPINFOVtbl
= {
553 /***********************************************************************
554 * InternetOpenW (WININET.@)
556 * Per-application initialization of wininet
559 * HINTERNET on success
563 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
564 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
566 LPWININETAPPINFOW lpwai
= NULL
;
567 HINTERNET handle
= NULL
;
569 if (TRACE_ON(wininet
)) {
570 #define FE(x) { x, #x }
571 static const wininet_flag_info access_type
[] = {
572 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
573 FE(INTERNET_OPEN_TYPE_DIRECT
),
574 FE(INTERNET_OPEN_TYPE_PROXY
),
575 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
579 const char *access_type_str
= "Unknown";
581 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
582 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
583 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
584 if (access_type
[i
].val
== dwAccessType
) {
585 access_type_str
= access_type
[i
].name
;
589 TRACE(" access type : %s\n", access_type_str
);
591 dump_INTERNET_FLAGS(dwFlags
);
594 /* Clear any error information */
595 INTERNET_SetLastError(0);
597 lpwai
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETAPPINFOW
));
600 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
604 lpwai
->hdr
.htype
= WH_HINIT
;
605 lpwai
->hdr
.vtbl
= &APPINFOVtbl
;
606 lpwai
->hdr
.dwFlags
= dwFlags
;
608 lpwai
->dwAccessType
= dwAccessType
;
609 lpwai
->lpszProxyUsername
= NULL
;
610 lpwai
->lpszProxyPassword
= NULL
;
612 handle
= WININET_AllocHandle( &lpwai
->hdr
);
615 HeapFree( GetProcessHeap(), 0, lpwai
);
616 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
620 if (NULL
!= lpszAgent
)
622 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
623 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
624 if (lpwai
->lpszAgent
)
625 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
627 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
628 INTERNET_ConfigureProxy( lpwai
);
629 else if (NULL
!= lpszProxy
)
631 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
632 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
633 if (lpwai
->lpszProxy
)
634 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
637 if (NULL
!= lpszProxyBypass
)
639 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
640 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
641 if (lpwai
->lpszProxyBypass
)
642 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
647 WININET_Release( &lpwai
->hdr
);
649 TRACE("returning %p\n", lpwai
);
655 /***********************************************************************
656 * InternetOpenA (WININET.@)
658 * Per-application initialization of wininet
661 * HINTERNET on success
665 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
666 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
670 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
672 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
673 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
677 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
678 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
679 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
684 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
685 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
686 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
689 if( lpszProxyBypass
)
691 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
692 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
693 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
696 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
698 HeapFree(GetProcessHeap(), 0, szAgent
);
699 HeapFree(GetProcessHeap(), 0, szProxy
);
700 HeapFree(GetProcessHeap(), 0, szBypass
);
705 /***********************************************************************
706 * InternetGetLastResponseInfoA (WININET.@)
708 * Return last wininet error description on the calling thread
711 * TRUE on success of writing to buffer
715 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
716 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
718 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
724 *lpdwError
= lpwite
->dwError
;
727 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
728 *lpdwBufferLength
= strlen(lpszBuffer
);
731 *lpdwBufferLength
= 0;
736 *lpdwBufferLength
= 0;
742 /***********************************************************************
743 * InternetGetLastResponseInfoW (WININET.@)
745 * Return last wininet error description on the calling thread
748 * TRUE on success of writing to buffer
752 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
753 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
755 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
761 *lpdwError
= lpwite
->dwError
;
764 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
765 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
768 *lpdwBufferLength
= 0;
773 *lpdwBufferLength
= 0;
779 /***********************************************************************
780 * InternetGetConnectedState (WININET.@)
782 * Return connected state
786 * if lpdwStatus is not null, return the status (off line,
787 * modem, lan...) in it.
788 * FALSE if not connected
790 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
792 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
795 FIXME("always returning LAN connection.\n");
796 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
802 /***********************************************************************
803 * InternetGetConnectedStateExW (WININET.@)
805 * Return connected state
809 * lpdwStatus [O] Flags specifying the status of the internet connection.
810 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
811 * dwNameLen [I] Size of the buffer, in characters.
812 * dwReserved [I] Reserved. Must be set to 0.
816 * if lpdwStatus is not null, return the status (off line,
817 * modem, lan...) in it.
818 * FALSE if not connected
821 * If the system has no available network connections, an empty string is
822 * stored in lpszConnectionName. If there is a LAN connection, a localized
823 * "LAN Connection" string is stored. Presumably, if only a dial-up
824 * connection is available then the name of the dial-up connection is
825 * returned. Why any application, other than the "Internet Settings" CPL,
826 * would want to use this function instead of the simpler InternetGetConnectedStateW
827 * function is beyond me.
829 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
830 DWORD dwNameLen
, DWORD dwReserved
)
832 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
839 FIXME("always returning LAN connection.\n");
840 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
842 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
846 /***********************************************************************
847 * InternetGetConnectedStateExA (WININET.@)
849 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
850 DWORD dwNameLen
, DWORD dwReserved
)
852 LPWSTR lpwszConnectionName
= NULL
;
855 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
857 if (lpszConnectionName
&& dwNameLen
> 0)
858 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
860 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
862 if (rc
&& lpwszConnectionName
)
864 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
865 dwNameLen
, NULL
, NULL
);
867 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
874 /***********************************************************************
875 * InternetConnectW (WININET.@)
877 * Open a ftp, gopher or http session
880 * HINTERNET a session handle on success
884 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
885 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
886 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
887 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
889 LPWININETAPPINFOW hIC
;
892 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
893 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
894 dwService
, dwFlags
, dwContext
);
898 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
902 /* Clear any error information */
903 INTERNET_SetLastError(0);
904 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
905 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
907 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
913 case INTERNET_SERVICE_FTP
:
914 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
915 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
918 case INTERNET_SERVICE_HTTP
:
919 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
920 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
923 case INTERNET_SERVICE_GOPHER
:
929 WININET_Release( &hIC
->hdr
);
931 TRACE("returning %p\n", rc
);
936 /***********************************************************************
937 * InternetConnectA (WININET.@)
939 * Open a ftp, gopher or http session
942 * HINTERNET a session handle on success
946 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
947 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
948 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
949 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
953 LPWSTR szServerName
= NULL
;
954 LPWSTR szUserName
= NULL
;
955 LPWSTR szPassword
= NULL
;
959 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
960 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
961 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
965 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
966 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
967 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
971 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
972 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
973 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
977 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
978 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
980 HeapFree(GetProcessHeap(), 0, szServerName
);
981 HeapFree(GetProcessHeap(), 0, szUserName
);
982 HeapFree(GetProcessHeap(), 0, szPassword
);
987 /***********************************************************************
988 * InternetFindNextFileA (WININET.@)
990 * Continues a file search from a previous call to FindFirstFile
997 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1000 WIN32_FIND_DATAW fd
;
1002 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1004 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1008 /***********************************************************************
1009 * InternetFindNextFileW (WININET.@)
1011 * Continues a file search from a previous call to FindFirstFile
1018 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1020 WININETHANDLEHEADER
*hdr
;
1025 hdr
= WININET_GetObject(hFind
);
1027 WARN("Invalid handle\n");
1028 SetLastError(ERROR_INVALID_HANDLE
);
1032 if(hdr
->vtbl
->FindNextFileW
) {
1033 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1035 WARN("Handle doesn't support NextFile\n");
1036 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1039 WININET_Release(hdr
);
1041 if(res
!= ERROR_SUCCESS
)
1043 return res
== ERROR_SUCCESS
;
1046 /***********************************************************************
1047 * InternetCloseHandle (WININET.@)
1049 * Generic close handle function
1056 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1058 LPWININETHANDLEHEADER lpwh
;
1060 TRACE("%p\n",hInternet
);
1062 lpwh
= WININET_GetObject( hInternet
);
1065 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1069 WININET_Release( lpwh
);
1070 WININET_FreeHandle( hInternet
);
1076 /***********************************************************************
1077 * ConvertUrlComponentValue (Internal)
1079 * Helper function for InternetCrackUrlA
1082 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1083 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1084 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1086 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1087 if (*dwComponentLen
!= 0)
1089 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1090 if (*lppszComponent
== NULL
)
1092 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1094 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1096 *lppszComponent
= NULL
;
1097 *dwComponentLen
= nASCIILength
;
1101 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1102 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1103 (*lppszComponent
)[ncpylen
]=0;
1104 *dwComponentLen
= ncpylen
;
1110 /***********************************************************************
1111 * InternetCrackUrlA (WININET.@)
1113 * See InternetCrackUrlW.
1115 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1116 LPURL_COMPONENTSA lpUrlComponents
)
1119 URL_COMPONENTSW UCW
;
1121 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1122 *scheme
= NULL
, *extra
= NULL
;
1124 TRACE("(%s %u %x %p)\n",
1125 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1126 dwUrlLength
, dwFlags
, lpUrlComponents
);
1128 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1129 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1131 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1137 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1139 /* if dwUrlLength=-1 then nLength includes null but length to
1140 InternetCrackUrlW should not include it */
1141 if (dwUrlLength
== -1) nLength
--;
1143 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1144 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1146 memset(&UCW
,0,sizeof(UCW
));
1147 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1148 if (lpUrlComponents
->dwHostNameLength
)
1150 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1151 if (lpUrlComponents
->lpszHostName
)
1153 hostname
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwHostNameLength
* sizeof(WCHAR
));
1154 UCW
.lpszHostName
= hostname
;
1157 if (lpUrlComponents
->dwUserNameLength
)
1159 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1160 if (lpUrlComponents
->lpszUserName
)
1162 username
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwUserNameLength
* sizeof(WCHAR
));
1163 UCW
.lpszUserName
= username
;
1166 if (lpUrlComponents
->dwPasswordLength
)
1168 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1169 if (lpUrlComponents
->lpszPassword
)
1171 password
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwPasswordLength
* sizeof(WCHAR
));
1172 UCW
.lpszPassword
= password
;
1175 if (lpUrlComponents
->dwUrlPathLength
)
1177 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1178 if (lpUrlComponents
->lpszUrlPath
)
1180 path
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1181 UCW
.lpszUrlPath
= path
;
1184 if (lpUrlComponents
->dwSchemeLength
)
1186 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1187 if (lpUrlComponents
->lpszScheme
)
1189 scheme
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwSchemeLength
* sizeof(WCHAR
));
1190 UCW
.lpszScheme
= scheme
;
1193 if (lpUrlComponents
->dwExtraInfoLength
)
1195 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1196 if (lpUrlComponents
->lpszExtraInfo
)
1198 extra
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1199 UCW
.lpszExtraInfo
= extra
;
1202 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1204 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1205 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1206 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1207 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1208 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1209 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1210 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1211 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1212 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1213 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1214 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1215 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1217 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1218 lpUrlComponents
->nPort
= UCW
.nPort
;
1220 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1221 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1222 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1223 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1224 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1226 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1227 HeapFree(GetProcessHeap(), 0, hostname
);
1228 HeapFree(GetProcessHeap(), 0, username
);
1229 HeapFree(GetProcessHeap(), 0, password
);
1230 HeapFree(GetProcessHeap(), 0, path
);
1231 HeapFree(GetProcessHeap(), 0, scheme
);
1232 HeapFree(GetProcessHeap(), 0, extra
);
1236 static const WCHAR url_schemes
[][7] =
1239 {'g','o','p','h','e','r',0},
1240 {'h','t','t','p',0},
1241 {'h','t','t','p','s',0},
1242 {'f','i','l','e',0},
1243 {'n','e','w','s',0},
1244 {'m','a','i','l','t','o',0},
1248 /***********************************************************************
1249 * GetInternetSchemeW (internal)
1255 * INTERNET_SCHEME_UNKNOWN on failure
1258 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1262 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1264 if(lpszScheme
==NULL
)
1265 return INTERNET_SCHEME_UNKNOWN
;
1267 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1268 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1269 return INTERNET_SCHEME_FIRST
+ i
;
1271 return INTERNET_SCHEME_UNKNOWN
;
1274 /***********************************************************************
1275 * SetUrlComponentValueW (Internal)
1277 * Helper function for InternetCrackUrlW
1280 * lppszComponent [O] Holds the returned string
1281 * dwComponentLen [I] Holds the size of lppszComponent
1282 * [O] Holds the length of the string in lppszComponent without '\0'
1283 * lpszStart [I] Holds the string to copy from
1284 * len [I] Holds the length of lpszStart without '\0'
1291 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1293 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1295 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1298 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1300 if (*lppszComponent
== NULL
)
1302 *lppszComponent
= (LPWSTR
)lpszStart
;
1303 *dwComponentLen
= len
;
1307 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1308 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1309 (*lppszComponent
)[ncpylen
] = '\0';
1310 *dwComponentLen
= ncpylen
;
1317 /***********************************************************************
1318 * InternetCrackUrlW (WININET.@)
1320 * Break up URL into its components
1326 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1327 LPURL_COMPONENTSW lpUC
)
1331 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1334 LPCWSTR lpszParam
= NULL
;
1335 BOOL bIsAbsolute
= FALSE
;
1336 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1337 LPCWSTR lpszcp
= NULL
;
1338 LPWSTR lpszUrl_decode
= NULL
;
1339 DWORD dwUrlLength
= dwUrlLength_orig
;
1341 TRACE("(%s %u %x %p)\n",
1342 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1343 dwUrlLength
, dwFlags
, lpUC
);
1345 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1347 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1350 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1352 if (dwFlags
& ICU_DECODE
)
1355 DWORD len
= dwUrlLength
+ 1;
1357 if (!(url_tmp
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
1359 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1362 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1363 url_tmp
[dwUrlLength
] = 0;
1364 if (!(lpszUrl_decode
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
1366 HeapFree(GetProcessHeap(), 0, url_tmp
);
1367 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1370 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1373 lpszUrl
= lpszUrl_decode
;
1375 HeapFree(GetProcessHeap(), 0, url_tmp
);
1379 /* Determine if the URI is absolute. */
1380 while (lpszap
- lpszUrl
< dwUrlLength
)
1382 if (isalnumW(*lpszap
))
1387 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1394 lpszcp
= lpszUrl
; /* Relative url */
1400 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1401 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1403 /* Parse <params> */
1404 if (!(lpszParam
= memchrW(lpszap
, ';', dwUrlLength
- (lpszap
- lpszUrl
))))
1405 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1407 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1408 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1410 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1414 /* Get scheme first. */
1415 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1416 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1417 lpszUrl
, lpszcp
- lpszUrl
);
1419 /* Eat ':' in protocol. */
1422 /* double slash indicates the net_loc portion is present */
1423 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1427 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1431 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1433 lpszNetLoc
= lpszParam
;
1435 else if (!lpszNetLoc
)
1436 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1444 /* [<user>[<:password>]@]<host>[:<port>] */
1445 /* First find the user and password if they exist */
1447 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1448 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1450 /* username and password not specified. */
1451 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1452 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1454 else /* Parse out username and password */
1456 LPCWSTR lpszUser
= lpszcp
;
1457 LPCWSTR lpszPasswd
= lpszHost
;
1459 while (lpszcp
< lpszHost
)
1462 lpszPasswd
= lpszcp
;
1467 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1468 lpszUser
, lpszPasswd
- lpszUser
);
1470 if (lpszPasswd
!= lpszHost
)
1472 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1473 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1474 lpszHost
- lpszPasswd
);
1476 lpszcp
++; /* Advance to beginning of host */
1479 /* Parse <host><:port> */
1482 lpszPort
= lpszNetLoc
;
1484 /* special case for res:// URLs: there is no port here, so the host is the
1485 entire string up to the first '/' */
1486 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1488 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1489 lpszHost
, lpszPort
- lpszHost
);
1494 while (lpszcp
< lpszNetLoc
)
1502 /* If the scheme is "file" and the host is just one letter, it's not a host */
1503 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1506 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1511 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1512 lpszHost
, lpszPort
- lpszHost
);
1513 if (lpszPort
!= lpszNetLoc
)
1514 lpUC
->nPort
= atoiW(++lpszPort
);
1515 else switch (lpUC
->nScheme
)
1517 case INTERNET_SCHEME_HTTP
:
1518 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1520 case INTERNET_SCHEME_HTTPS
:
1521 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1523 case INTERNET_SCHEME_FTP
:
1524 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1526 case INTERNET_SCHEME_GOPHER
:
1527 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1538 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1539 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1540 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1545 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1546 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1547 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1548 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1551 /* Here lpszcp points to:
1553 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1554 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1556 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
< lpszParam
))
1560 /* Only truncate the parameter list if it's already been saved
1561 * in lpUC->lpszExtraInfo.
1563 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1564 len
= lpszParam
- lpszcp
;
1567 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1568 * newlines if necessary.
1570 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1571 if (lpsznewline
!= NULL
)
1572 len
= lpsznewline
- lpszcp
;
1574 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1576 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1581 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1582 lpUC
->lpszUrlPath
[0] = 0;
1583 lpUC
->dwUrlPathLength
= 0;
1586 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1587 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1588 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1589 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1590 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1592 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1596 /***********************************************************************
1597 * InternetAttemptConnect (WININET.@)
1599 * Attempt to make a connection to the internet
1602 * ERROR_SUCCESS on success
1603 * Error value on failure
1606 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1609 return ERROR_SUCCESS
;
1613 /***********************************************************************
1614 * InternetCanonicalizeUrlA (WININET.@)
1616 * Escape unsafe characters and spaces
1623 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1624 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1627 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1629 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1630 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1632 if(dwFlags
& ICU_DECODE
)
1634 dwURLFlags
|= URL_UNESCAPE
;
1635 dwFlags
&= ~ICU_DECODE
;
1638 if(dwFlags
& ICU_ESCAPE
)
1640 dwURLFlags
|= URL_UNESCAPE
;
1641 dwFlags
&= ~ICU_ESCAPE
;
1644 if(dwFlags
& ICU_BROWSER_MODE
)
1646 dwURLFlags
|= URL_BROWSER_MODE
;
1647 dwFlags
&= ~ICU_BROWSER_MODE
;
1650 if(dwFlags
& ICU_NO_ENCODE
)
1652 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1653 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1654 dwFlags
&= ~ICU_NO_ENCODE
;
1657 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1659 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1660 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1661 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1663 return (hr
== S_OK
) ? TRUE
: FALSE
;
1666 /***********************************************************************
1667 * InternetCanonicalizeUrlW (WININET.@)
1669 * Escape unsafe characters and spaces
1676 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1677 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1680 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1682 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1683 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1685 if(dwFlags
& ICU_DECODE
)
1687 dwURLFlags
|= URL_UNESCAPE
;
1688 dwFlags
&= ~ICU_DECODE
;
1691 if(dwFlags
& ICU_ESCAPE
)
1693 dwURLFlags
|= URL_UNESCAPE
;
1694 dwFlags
&= ~ICU_ESCAPE
;
1697 if(dwFlags
& ICU_BROWSER_MODE
)
1699 dwURLFlags
|= URL_BROWSER_MODE
;
1700 dwFlags
&= ~ICU_BROWSER_MODE
;
1703 if(dwFlags
& ICU_NO_ENCODE
)
1705 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1706 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1707 dwFlags
&= ~ICU_NO_ENCODE
;
1710 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1712 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1713 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1714 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1716 return (hr
== S_OK
) ? TRUE
: FALSE
;
1719 /* #################################################### */
1721 static INTERNET_STATUS_CALLBACK
set_status_callback(
1722 LPWININETHANDLEHEADER lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
1724 INTERNET_STATUS_CALLBACK ret
;
1726 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1727 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1729 ret
= lpwh
->lpfnStatusCB
;
1730 lpwh
->lpfnStatusCB
= callback
;
1735 /***********************************************************************
1736 * InternetSetStatusCallbackA (WININET.@)
1738 * Sets up a callback function which is called as progress is made
1739 * during an operation.
1742 * Previous callback or NULL on success
1743 * INTERNET_INVALID_STATUS_CALLBACK on failure
1746 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1747 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1749 INTERNET_STATUS_CALLBACK retVal
;
1750 LPWININETHANDLEHEADER lpwh
;
1752 TRACE("0x%08x\n", (ULONG
)hInternet
);
1754 if (!(lpwh
= WININET_GetObject(hInternet
)))
1755 return INTERNET_INVALID_STATUS_CALLBACK
;
1757 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
1759 WININET_Release( lpwh
);
1763 /***********************************************************************
1764 * InternetSetStatusCallbackW (WININET.@)
1766 * Sets up a callback function which is called as progress is made
1767 * during an operation.
1770 * Previous callback or NULL on success
1771 * INTERNET_INVALID_STATUS_CALLBACK on failure
1774 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1775 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1777 INTERNET_STATUS_CALLBACK retVal
;
1778 LPWININETHANDLEHEADER lpwh
;
1780 TRACE("0x%08x\n", (ULONG
)hInternet
);
1782 if (!(lpwh
= WININET_GetObject(hInternet
)))
1783 return INTERNET_INVALID_STATUS_CALLBACK
;
1785 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
1787 WININET_Release( lpwh
);
1791 /***********************************************************************
1792 * InternetSetFilePointer (WININET.@)
1794 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1795 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
1801 /***********************************************************************
1802 * InternetWriteFile (WININET.@)
1804 * Write data to an open internet file
1811 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1812 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1814 LPWININETHANDLEHEADER lpwh
;
1815 BOOL retval
= FALSE
;
1817 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1819 lpwh
= WININET_GetObject( hFile
);
1821 WARN("Invalid handle\n");
1822 SetLastError(ERROR_INVALID_HANDLE
);
1826 if(lpwh
->vtbl
->WriteFile
) {
1827 retval
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1829 WARN("No Writefile method.\n");
1830 SetLastError(ERROR_INVALID_HANDLE
);
1834 WININET_Release( lpwh
);
1840 /***********************************************************************
1841 * InternetReadFile (WININET.@)
1843 * Read data from an open internet file
1850 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1851 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1853 LPWININETHANDLEHEADER hdr
;
1854 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1856 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1858 hdr
= WININET_GetObject(hFile
);
1860 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1864 if(hdr
->vtbl
->ReadFile
)
1865 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1867 WININET_Release(hdr
);
1869 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
1870 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1872 if(res
!= ERROR_SUCCESS
)
1874 return res
== ERROR_SUCCESS
;
1877 /***********************************************************************
1878 * InternetReadFileExA (WININET.@)
1880 * Read data from an open internet file
1883 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1884 * lpBuffersOut [I/O] Buffer.
1885 * dwFlags [I] Flags. See notes.
1886 * dwContext [I] Context for callbacks.
1893 * The parameter dwFlags include zero or more of the following flags:
1894 *|IRF_ASYNC - Makes the call asynchronous.
1895 *|IRF_SYNC - Makes the call synchronous.
1896 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1897 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1899 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1902 * InternetOpenUrlA(), HttpOpenRequestA()
1904 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1905 DWORD dwFlags
, DWORD_PTR dwContext
)
1907 LPWININETHANDLEHEADER hdr
;
1908 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1910 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1912 hdr
= WININET_GetObject(hFile
);
1914 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1918 if(hdr
->vtbl
->ReadFileExA
)
1919 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
1921 WININET_Release(hdr
);
1923 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
1924 res
, lpBuffersOut
->dwBufferLength
);
1926 if(res
!= ERROR_SUCCESS
)
1928 return res
== ERROR_SUCCESS
;
1931 /***********************************************************************
1932 * InternetReadFileExW (WININET.@)
1934 * Read data from an open internet file.
1937 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1938 * lpBuffersOut [I/O] Buffer.
1939 * dwFlags [I] Flags.
1940 * dwContext [I] Context for callbacks.
1943 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1946 * Not implemented in Wine or native either (as of IE6 SP2).
1949 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1950 DWORD dwFlags
, DWORD_PTR dwContext
)
1952 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
1954 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1958 /***********************************************************************
1959 * INET_QueryOptionHelper (internal)
1961 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1962 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1964 LPWININETHANDLEHEADER lpwhh
;
1965 BOOL bSuccess
= FALSE
;
1967 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1969 lpwhh
= WININET_GetObject( hInternet
);
1973 case INTERNET_OPTION_REQUEST_FLAGS
:
1976 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags
);
1977 if (*lpdwBufferLength
< sizeof(ULONG
))
1978 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1981 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
1984 *lpdwBufferLength
= sizeof(ULONG
);
1988 case INTERNET_OPTION_HTTP_VERSION
:
1990 if (*lpdwBufferLength
< sizeof(HTTP_VERSION_INFO
))
1991 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1995 * Presently hardcoded to 1.1
1997 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
1998 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
2001 *lpdwBufferLength
= sizeof(HTTP_VERSION_INFO
);
2004 case INTERNET_OPTION_CONNECTED_STATE
:
2006 DWORD
*pdwConnectedState
= (DWORD
*)lpBuffer
;
2007 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2009 if (*lpdwBufferLength
< sizeof(*pdwConnectedState
))
2010 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2013 *pdwConnectedState
= INTERNET_STATE_CONNECTED
;
2016 *lpdwBufferLength
= sizeof(*pdwConnectedState
);
2019 case INTERNET_OPTION_PROXY
:
2021 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
)lpwhh
;
2022 WININETAPPINFOW wai
;
2026 TRACE("Getting global proxy info\n");
2027 memset(&wai
, 0, sizeof(WININETAPPINFOW
));
2028 INTERNET_ConfigureProxy( &wai
);
2034 INTERNET_PROXY_INFOW
*pPI
= (INTERNET_PROXY_INFOW
*)lpBuffer
;
2035 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2037 if (lpwai
->lpszProxy
)
2038 proxyBytesRequired
= (lstrlenW(lpwai
->lpszProxy
) + 1) *
2040 if (lpwai
->lpszProxyBypass
)
2041 proxyBypassBytesRequired
=
2042 (lstrlenW(lpwai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
2043 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOW
) +
2044 proxyBytesRequired
+ proxyBypassBytesRequired
)
2045 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2048 LPWSTR proxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2049 sizeof(INTERNET_PROXY_INFOW
));
2050 LPWSTR proxy_bypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2051 sizeof(INTERNET_PROXY_INFOW
) +
2052 proxyBytesRequired
);
2054 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2055 pPI
->lpszProxy
= NULL
;
2056 pPI
->lpszProxyBypass
= NULL
;
2057 if (lpwai
->lpszProxy
)
2059 lstrcpyW(proxy
, lpwai
->lpszProxy
);
2060 pPI
->lpszProxy
= proxy
;
2063 if (lpwai
->lpszProxyBypass
)
2065 lstrcpyW(proxy_bypass
, lpwai
->lpszProxyBypass
);
2066 pPI
->lpszProxyBypass
= proxy_bypass
;
2070 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOW
) +
2071 proxyBytesRequired
+ proxyBypassBytesRequired
;
2075 INTERNET_PROXY_INFOA
*pPI
= (INTERNET_PROXY_INFOA
*)lpBuffer
;
2076 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2078 if (lpwai
->lpszProxy
)
2079 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2080 lpwai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
2081 if (lpwai
->lpszProxyBypass
)
2082 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2083 lpwai
->lpszProxyBypass
, -1, NULL
, 0, NULL
, NULL
);
2084 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOA
) +
2085 proxyBytesRequired
+ proxyBypassBytesRequired
)
2086 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2089 LPSTR proxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2090 sizeof(INTERNET_PROXY_INFOA
));
2091 LPSTR proxy_bypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2092 sizeof(INTERNET_PROXY_INFOA
) +
2093 proxyBytesRequired
);
2095 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2096 pPI
->lpszProxy
= NULL
;
2097 pPI
->lpszProxyBypass
= NULL
;
2098 if (lpwai
->lpszProxy
)
2100 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxy
, -1,
2101 proxy
, proxyBytesRequired
, NULL
, NULL
);
2102 pPI
->lpszProxy
= proxy
;
2105 if (lpwai
->lpszProxyBypass
)
2107 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxyBypass
,
2108 -1, proxy_bypass
, proxyBypassBytesRequired
,
2110 pPI
->lpszProxyBypass
= proxy_bypass
;
2114 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOA
) +
2115 proxyBytesRequired
+ proxyBypassBytesRequired
;
2119 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2122 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn
);
2123 if (*lpdwBufferLength
< sizeof(ULONG
))
2124 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2127 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2130 *lpdwBufferLength
= sizeof(ULONG
);
2133 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2136 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn
);
2137 if (*lpdwBufferLength
< sizeof(ULONG
))
2138 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2141 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2144 *lpdwBufferLength
= sizeof(ULONG
);
2147 case INTERNET_OPTION_SECURITY_FLAGS
:
2148 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2152 case INTERNET_OPTION_VERSION
:
2154 TRACE("INTERNET_OPTION_VERSION\n");
2155 if (*lpdwBufferLength
< sizeof(INTERNET_VERSION_INFO
))
2156 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2159 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2160 memcpy(lpBuffer
, &info
, sizeof(info
));
2161 *lpdwBufferLength
= sizeof(info
);
2166 case INTERNET_OPTION_PER_CONNECTION_OPTION
:
2167 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2168 if (*lpdwBufferLength
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
))
2169 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2172 INTERNET_PER_CONN_OPTION_LISTW
*con
= lpBuffer
;
2175 for (x
= 0; x
< con
->dwOptionCount
; ++x
)
2177 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ x
;
2178 switch (option
->dwOption
)
2180 case INTERNET_PER_CONN_FLAGS
:
2181 option
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2184 case INTERNET_PER_CONN_PROXY_SERVER
:
2185 case INTERNET_PER_CONN_PROXY_BYPASS
:
2186 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2187 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2188 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2189 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2190 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2191 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2192 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2193 option
->Value
.dwValue
= 0;
2198 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2204 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2215 res
= lpwhh
->vtbl
->QueryOption(lpwhh
, dwOption
, lpBuffer
, lpdwBufferLength
, bIsUnicode
);
2216 if(res
== ERROR_SUCCESS
)
2221 FIXME("Stub! %d\n", dwOption
);
2222 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2228 WININET_Release( lpwhh
);
2233 /***********************************************************************
2234 * InternetQueryOptionW (WININET.@)
2236 * Queries an options on the specified handle
2243 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2244 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2246 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2249 /***********************************************************************
2250 * InternetQueryOptionA (WININET.@)
2252 * Queries an options on the specified handle
2259 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2260 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2262 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2266 /***********************************************************************
2267 * InternetSetOptionW (WININET.@)
2269 * Sets an options on the specified handle
2276 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2277 LPVOID lpBuffer
, DWORD dwBufferLength
)
2279 LPWININETHANDLEHEADER lpwhh
;
2282 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2284 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2285 if(lpwhh
&& lpwhh
->vtbl
->SetOption
) {
2288 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2289 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2290 WININET_Release( lpwhh
);
2292 if(res
!= ERROR_SUCCESS
)
2295 return res
== ERROR_SUCCESS
;
2301 case INTERNET_OPTION_CALLBACK
:
2303 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2304 ret
= (set_status_callback(lpwhh
, callback
, TRUE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2307 case INTERNET_OPTION_HTTP_VERSION
:
2309 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2310 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2313 case INTERNET_OPTION_ERROR_MASK
:
2315 ULONG flags
= *(ULONG
*)lpBuffer
;
2316 FIXME("Option INTERNET_OPTION_ERROR_MASK(%d): STUB\n", flags
);
2319 case INTERNET_OPTION_CODEPAGE
:
2321 ULONG codepage
= *(ULONG
*)lpBuffer
;
2322 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2325 case INTERNET_OPTION_REQUEST_PRIORITY
:
2327 ULONG priority
= *(ULONG
*)lpBuffer
;
2328 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2331 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2333 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2334 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2337 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2339 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2340 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2343 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2345 ULONG conns
= *(ULONG
*)lpBuffer
;
2346 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns
);
2349 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2351 ULONG conns
= *(ULONG
*)lpBuffer
;
2352 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns
);
2355 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2356 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2358 case INTERNET_OPTION_END_BROWSER_SESSION
:
2359 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2361 case INTERNET_OPTION_CONNECTED_STATE
:
2362 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2364 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2365 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2367 case INTERNET_OPTION_SEND_TIMEOUT
:
2368 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2370 ULONG timeout
= *(ULONG
*)lpBuffer
;
2371 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT %d\n", timeout
);
2374 case INTERNET_OPTION_CONNECT_RETRIES
:
2376 ULONG retries
= *(ULONG
*)lpBuffer
;
2377 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2380 case INTERNET_OPTION_CONTEXT_VALUE
:
2381 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2383 case INTERNET_OPTION_SECURITY_FLAGS
:
2384 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2386 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2387 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2393 FIXME("Option %d STUB\n",dwOption
);
2394 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2400 WININET_Release( lpwhh
);
2406 /***********************************************************************
2407 * InternetSetOptionA (WININET.@)
2409 * Sets an options on the specified handle.
2416 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2417 LPVOID lpBuffer
, DWORD dwBufferLength
)
2425 case INTERNET_OPTION_CALLBACK
:
2427 LPWININETHANDLEHEADER lpwh
;
2428 INTERNET_STATUS_CALLBACK callback
= *(INTERNET_STATUS_CALLBACK
*)lpBuffer
;
2430 if (!(lpwh
= WININET_GetObject(hInternet
))) return FALSE
;
2431 r
= (set_status_callback(lpwh
, callback
, FALSE
) != INTERNET_INVALID_STATUS_CALLBACK
);
2432 WININET_Release(lpwh
);
2435 case INTERNET_OPTION_PROXY
:
2437 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2438 LPINTERNET_PROXY_INFOW piw
;
2439 DWORD proxlen
, prbylen
;
2442 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2443 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2444 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2445 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2446 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2447 piw
->dwAccessType
= pi
->dwAccessType
;
2448 prox
= (LPWSTR
) &piw
[1];
2449 prby
= &prox
[proxlen
+1];
2450 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2451 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2452 piw
->lpszProxy
= prox
;
2453 piw
->lpszProxyBypass
= prby
;
2456 case INTERNET_OPTION_USER_AGENT
:
2457 case INTERNET_OPTION_USERNAME
:
2458 case INTERNET_OPTION_PASSWORD
:
2459 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2461 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2462 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2467 wlen
= dwBufferLength
;
2470 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2472 if( lpBuffer
!= wbuffer
)
2473 HeapFree( GetProcessHeap(), 0, wbuffer
);
2479 /***********************************************************************
2480 * InternetSetOptionExA (WININET.@)
2482 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2483 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2485 FIXME("Flags %08x ignored\n", dwFlags
);
2486 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2489 /***********************************************************************
2490 * InternetSetOptionExW (WININET.@)
2492 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2493 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2495 FIXME("Flags %08x ignored\n", dwFlags
);
2496 if( dwFlags
& ~ISO_VALID_FLAGS
)
2498 INTERNET_SetLastError( ERROR_INVALID_PARAMETER
);
2501 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2504 static const WCHAR WININET_wkday
[7][4] =
2505 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2506 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2507 static const WCHAR WININET_month
[12][4] =
2508 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2509 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2510 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2512 /***********************************************************************
2513 * InternetTimeFromSystemTimeA (WININET.@)
2515 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2518 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2520 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2522 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2523 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2528 /***********************************************************************
2529 * InternetTimeFromSystemTimeW (WININET.@)
2531 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2533 static const WCHAR date
[] =
2534 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2535 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2537 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2539 if (!time
|| !string
) return FALSE
;
2541 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2544 sprintfW( string
, date
,
2545 WININET_wkday
[time
->wDayOfWeek
],
2547 WININET_month
[time
->wMonth
- 1],
2556 /***********************************************************************
2557 * InternetTimeToSystemTimeA (WININET.@)
2559 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2565 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
2567 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2568 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2572 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2573 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2574 HeapFree( GetProcessHeap(), 0, stringW
);
2579 /***********************************************************************
2580 * InternetTimeToSystemTimeW (WININET.@)
2582 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2585 const WCHAR
*s
= string
;
2588 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
2590 if (!string
|| !time
) return FALSE
;
2592 /* Windows does this too */
2593 GetSystemTime( time
);
2595 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2596 * a SYSTEMTIME structure.
2599 while (*s
&& !isalphaW( *s
)) s
++;
2600 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2601 time
->wDayOfWeek
= 7;
2603 for (i
= 0; i
< 7; i
++)
2605 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2606 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2607 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2609 time
->wDayOfWeek
= i
;
2614 if (time
->wDayOfWeek
> 6) return TRUE
;
2615 while (*s
&& !isdigitW( *s
)) s
++;
2616 time
->wDay
= strtolW( s
, &end
, 10 );
2619 while (*s
&& !isalphaW( *s
)) s
++;
2620 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2623 for (i
= 0; i
< 12; i
++)
2625 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2626 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2627 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2629 time
->wMonth
= i
+ 1;
2633 if (time
->wMonth
== 0) return TRUE
;
2635 while (*s
&& !isdigitW( *s
)) s
++;
2636 if (*s
== '\0') return TRUE
;
2637 time
->wYear
= strtolW( s
, &end
, 10 );
2640 while (*s
&& !isdigitW( *s
)) s
++;
2641 if (*s
== '\0') return TRUE
;
2642 time
->wHour
= strtolW( s
, &end
, 10 );
2645 while (*s
&& !isdigitW( *s
)) s
++;
2646 if (*s
== '\0') return TRUE
;
2647 time
->wMinute
= strtolW( s
, &end
, 10 );
2650 while (*s
&& !isdigitW( *s
)) s
++;
2651 if (*s
== '\0') return TRUE
;
2652 time
->wSecond
= strtolW( s
, &end
, 10 );
2655 time
->wMilliseconds
= 0;
2659 /***********************************************************************
2660 * InternetCheckConnectionW (WININET.@)
2662 * Pings a requested host to check internet connection
2665 * TRUE on success and FALSE on failure. If a failure then
2666 * ERROR_NOT_CONNECTED is placed into GetLastError
2669 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2672 * this is a kludge which runs the resident ping program and reads the output.
2674 * Anyone have a better idea?
2678 static const CHAR ping
[] = "ping -c 1 ";
2679 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2680 CHAR
*command
= NULL
;
2689 * Crack or set the Address
2691 if (lpszUrl
== NULL
)
2694 * According to the doc we are supposed to use the ip for the next
2695 * server in the WnInet internal server database. I have
2696 * no idea what that is or how to get it.
2698 * So someone needs to implement this.
2700 FIXME("Unimplemented with URL of NULL\n");
2705 URL_COMPONENTSW components
;
2707 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2708 components
.lpszHostName
= (LPWSTR
)hostW
;
2709 components
.dwHostNameLength
= 1024;
2711 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2714 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2715 port
= components
.nPort
;
2716 TRACE("port: %d\n", port
);
2719 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
2721 struct sockaddr_in sin
;
2724 if (!GetAddress(hostW
, port
, &sin
))
2726 fd
= socket(sin
.sin_family
, SOCK_STREAM
, 0);
2729 if (connect(fd
, (struct sockaddr
*)&sin
, sizeof(sin
)) == 0)
2737 * Build our ping command
2739 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2740 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2741 strcpy(command
,ping
);
2742 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2743 strcat(command
,redirect
);
2745 TRACE("Ping command is : %s\n",command
);
2747 status
= system(command
);
2749 TRACE("Ping returned a code of %i\n",status
);
2751 /* Ping return code of 0 indicates success */
2758 HeapFree( GetProcessHeap(), 0, command
);
2760 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
2766 /***********************************************************************
2767 * InternetCheckConnectionA (WININET.@)
2769 * Pings a requested host to check internet connection
2772 * TRUE on success and FALSE on failure. If a failure then
2773 * ERROR_NOT_CONNECTED is placed into GetLastError
2776 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2782 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2783 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2785 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2786 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2787 HeapFree(GetProcessHeap(), 0, szUrl
);
2793 /**********************************************************
2794 * INTERNET_InternetOpenUrlW (internal)
2799 * handle of connection or NULL on failure
2801 static HINTERNET
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2802 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2804 URL_COMPONENTSW urlComponents
;
2805 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2806 WCHAR password
[1024], path
[2048], extra
[1024];
2807 HINTERNET client
= NULL
, client1
= NULL
;
2809 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2810 dwHeadersLength
, dwFlags
, dwContext
);
2812 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2813 urlComponents
.lpszScheme
= protocol
;
2814 urlComponents
.dwSchemeLength
= 32;
2815 urlComponents
.lpszHostName
= hostName
;
2816 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2817 urlComponents
.lpszUserName
= userName
;
2818 urlComponents
.dwUserNameLength
= 1024;
2819 urlComponents
.lpszPassword
= password
;
2820 urlComponents
.dwPasswordLength
= 1024;
2821 urlComponents
.lpszUrlPath
= path
;
2822 urlComponents
.dwUrlPathLength
= 2048;
2823 urlComponents
.lpszExtraInfo
= extra
;
2824 urlComponents
.dwExtraInfoLength
= 1024;
2825 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2827 switch(urlComponents
.nScheme
) {
2828 case INTERNET_SCHEME_FTP
:
2829 if(urlComponents
.nPort
== 0)
2830 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2831 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2832 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2835 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2836 if(client1
== NULL
) {
2837 InternetCloseHandle(client
);
2842 case INTERNET_SCHEME_HTTP
:
2843 case INTERNET_SCHEME_HTTPS
: {
2844 static const WCHAR szStars
[] = { '*','/','*', 0 };
2845 LPCWSTR accept
[2] = { szStars
, NULL
};
2846 if(urlComponents
.nPort
== 0) {
2847 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2848 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2850 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2852 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2853 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2854 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2858 if (urlComponents
.dwExtraInfoLength
) {
2860 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
2862 if (!(path_extra
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
2864 InternetCloseHandle(client
);
2867 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
2868 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
2869 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2870 HeapFree(GetProcessHeap(), 0, path_extra
);
2873 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2875 if(client1
== NULL
) {
2876 InternetCloseHandle(client
);
2879 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2880 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
2881 GetLastError() != ERROR_IO_PENDING
) {
2882 InternetCloseHandle(client1
);
2887 case INTERNET_SCHEME_GOPHER
:
2888 /* gopher doesn't seem to be implemented in wine, but it's supposed
2889 * to be supported by InternetOpenUrlA. */
2891 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
2895 TRACE(" %p <--\n", client1
);
2900 /**********************************************************
2901 * InternetOpenUrlW (WININET.@)
2906 * handle of connection or NULL on failure
2908 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
2910 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
2911 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
->hdr
;
2915 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
2916 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
2917 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
2918 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
2921 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
2922 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2924 HINTERNET ret
= NULL
;
2925 LPWININETAPPINFOW hIC
= NULL
;
2927 if (TRACE_ON(wininet
)) {
2928 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2929 dwHeadersLength
, dwFlags
, dwContext
);
2931 dump_INTERNET_FLAGS(dwFlags
);
2936 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2940 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
2941 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
2942 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2946 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
2947 WORKREQUEST workRequest
;
2948 struct WORKREQ_INTERNETOPENURLW
*req
;
2950 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
2951 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
2952 req
= &workRequest
.u
.InternetOpenUrlW
;
2953 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
2955 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
2957 req
->lpszHeaders
= 0;
2958 req
->dwHeadersLength
= dwHeadersLength
;
2959 req
->dwFlags
= dwFlags
;
2960 req
->dwContext
= dwContext
;
2962 INTERNET_AsyncCall(&workRequest
);
2964 * This is from windows.
2966 INTERNET_SetLastError(ERROR_IO_PENDING
);
2968 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
2973 WININET_Release( &hIC
->hdr
);
2974 TRACE(" %p <--\n", ret
);
2979 /**********************************************************
2980 * InternetOpenUrlA (WININET.@)
2985 * handle of connection or NULL on failure
2987 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
2988 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2990 HINTERNET rc
= NULL
;
2994 LPWSTR szUrl
= NULL
;
2995 LPWSTR szHeaders
= NULL
;
3000 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
3001 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
3004 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
3008 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3009 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
3011 HeapFree(GetProcessHeap(), 0, szUrl
);
3014 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3017 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3018 lenHeaders
, dwFlags
, dwContext
);
3020 HeapFree(GetProcessHeap(), 0, szUrl
);
3021 HeapFree(GetProcessHeap(), 0, szHeaders
);
3027 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3029 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite
));
3033 lpwite
->dwError
= 0;
3034 lpwite
->response
[0] = '\0';
3037 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3039 HeapFree(GetProcessHeap(), 0, lpwite
);
3047 /***********************************************************************
3048 * INTERNET_SetLastError (internal)
3050 * Set last thread specific error
3055 void INTERNET_SetLastError(DWORD dwError
)
3057 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3060 lpwite
= INTERNET_AllocThreadError();
3062 SetLastError(dwError
);
3064 lpwite
->dwError
= dwError
;
3068 /***********************************************************************
3069 * INTERNET_GetLastError (internal)
3071 * Get last thread specific error
3076 DWORD
INTERNET_GetLastError(void)
3078 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3079 if (!lpwite
) return 0;
3080 /* TlsGetValue clears last error, so set it again here */
3081 SetLastError(lpwite
->dwError
);
3082 return lpwite
->dwError
;
3086 /***********************************************************************
3087 * INTERNET_WorkerThreadFunc (internal)
3089 * Worker thread execution function
3094 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3096 LPWORKREQUEST lpRequest
= lpvParam
;
3097 WORKREQUEST workRequest
;
3101 workRequest
= *lpRequest
;
3102 HeapFree(GetProcessHeap(), 0, lpRequest
);
3104 workRequest
.asyncproc(&workRequest
);
3106 WININET_Release( workRequest
.hdr
);
3111 /***********************************************************************
3112 * INTERNET_AsyncCall (internal)
3114 * Retrieves work request from queue
3119 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3122 LPWORKREQUEST lpNewRequest
;
3126 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3130 *lpNewRequest
= *lpWorkRequest
;
3132 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3135 HeapFree(GetProcessHeap(), 0, lpNewRequest
);
3136 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3143 /***********************************************************************
3144 * INTERNET_GetResponseBuffer (internal)
3149 LPSTR
INTERNET_GetResponseBuffer(void)
3151 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3153 lpwite
= INTERNET_AllocThreadError();
3155 return lpwite
->response
;
3158 /***********************************************************************
3159 * INTERNET_GetNextLine (internal)
3161 * Parse next line in directory string listing
3164 * Pointer to beginning of next line
3169 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3172 BOOL bSuccess
= FALSE
;
3174 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3179 pfd
.events
= POLLIN
;
3181 while (nRecv
< MAX_REPLY_LEN
)
3183 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3185 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3187 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3191 if (lpszBuffer
[nRecv
] == '\n')
3196 if (lpszBuffer
[nRecv
] != '\r')
3201 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3209 lpszBuffer
[nRecv
] = '\0';
3211 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3220 /**********************************************************
3221 * InternetQueryDataAvailable (WININET.@)
3223 * Determines how much data is available to be read.
3226 * TRUE on success, FALSE if an error occurred. If
3227 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3228 * no data is presently available, FALSE is returned with
3229 * the last error ERROR_IO_PENDING; a callback with status
3230 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3231 * data is available.
3233 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3234 LPDWORD lpdwNumberOfBytesAvailble
,
3235 DWORD dwFlags
, DWORD_PTR dwContext
)
3237 WININETHANDLEHEADER
*hdr
;
3240 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3242 hdr
= WININET_GetObject( hFile
);
3244 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
3248 if(hdr
->vtbl
->QueryDataAvailable
) {
3249 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3251 WARN("wrong handle\n");
3252 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3255 WININET_Release(hdr
);
3257 if(res
!= ERROR_SUCCESS
)
3259 return res
== ERROR_SUCCESS
;
3263 /***********************************************************************
3264 * InternetLockRequestFile (WININET.@)
3266 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3273 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3280 /***********************************************************************
3281 * InternetAutodial (WININET.@)
3283 * On windows this function is supposed to dial the default internet
3284 * connection. We don't want to have Wine dial out to the internet so
3285 * we return TRUE by default. It might be nice to check if we are connected.
3292 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3296 /* Tell that we are connected to the internet. */
3300 /***********************************************************************
3301 * InternetAutodialHangup (WININET.@)
3303 * Hangs up a connection made with InternetAutodial
3312 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3316 /* we didn't dial, we don't disconnect */
3320 /***********************************************************************
3321 * InternetCombineUrlA (WININET.@)
3323 * Combine a base URL with a relative URL
3331 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3332 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3337 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3339 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3340 dwFlags
^= ICU_NO_ENCODE
;
3341 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3346 /***********************************************************************
3347 * InternetCombineUrlW (WININET.@)
3349 * Combine a base URL with a relative URL
3357 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3358 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3363 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3365 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3366 dwFlags
^= ICU_NO_ENCODE
;
3367 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3372 /* max port num is 65535 => 5 digits */
3373 #define MAX_WORD_DIGITS 5
3375 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3376 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3377 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3378 (url)->dw##component##Length : strlen((url)->lpsz##component))
3380 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3382 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3383 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3385 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3386 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3388 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3389 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3391 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3392 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3395 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3401 /* opaque urls do not fit into the standard url hierarchy and don't have
3402 * two following slashes */
3403 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3405 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3406 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3407 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3408 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3409 (nScheme
!= INTERNET_SCHEME_FILE
);
3412 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3415 if (scheme
< INTERNET_SCHEME_FIRST
)
3417 index
= scheme
- INTERNET_SCHEME_FIRST
;
3418 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3420 return (LPCWSTR
)url_schemes
[index
];
3423 /* we can calculate using ansi strings because we're just
3424 * calculating string length, not size
3426 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3427 LPDWORD lpdwUrlLength
)
3429 INTERNET_SCHEME nScheme
;
3433 if (lpUrlComponents
->lpszScheme
)
3435 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3436 *lpdwUrlLength
+= dwLen
;
3437 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3443 nScheme
= lpUrlComponents
->nScheme
;
3445 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3446 nScheme
= INTERNET_SCHEME_HTTP
;
3447 scheme
= INTERNET_GetSchemeString(nScheme
);
3448 *lpdwUrlLength
+= strlenW(scheme
);
3451 (*lpdwUrlLength
)++; /* ':' */
3452 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3453 *lpdwUrlLength
+= strlen("//");
3455 if (lpUrlComponents
->lpszUserName
)
3457 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3458 *lpdwUrlLength
+= strlen("@");
3462 if (lpUrlComponents
->lpszPassword
)
3464 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3469 if (lpUrlComponents
->lpszPassword
)
3471 *lpdwUrlLength
+= strlen(":");
3472 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3475 if (lpUrlComponents
->lpszHostName
)
3477 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3479 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3481 char szPort
[MAX_WORD_DIGITS
+1];
3483 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3484 *lpdwUrlLength
+= strlen(szPort
);
3485 *lpdwUrlLength
+= strlen(":");
3488 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3489 (*lpdwUrlLength
)++; /* '/' */
3492 if (lpUrlComponents
->lpszUrlPath
)
3493 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3498 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3502 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3504 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3505 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3506 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3507 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3508 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3509 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3510 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3511 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3512 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3514 if (lpUrlComponents
->lpszScheme
)
3516 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
3517 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3518 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3519 -1, urlCompW
->lpszScheme
, len
);
3522 if (lpUrlComponents
->lpszHostName
)
3524 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
3525 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3526 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3527 -1, urlCompW
->lpszHostName
, len
);
3530 if (lpUrlComponents
->lpszUserName
)
3532 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
3533 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3534 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3535 -1, urlCompW
->lpszUserName
, len
);
3538 if (lpUrlComponents
->lpszPassword
)
3540 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
3541 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3542 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3543 -1, urlCompW
->lpszPassword
, len
);
3546 if (lpUrlComponents
->lpszUrlPath
)
3548 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
3549 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3550 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3551 -1, urlCompW
->lpszUrlPath
, len
);
3554 if (lpUrlComponents
->lpszExtraInfo
)
3556 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
3557 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3558 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3559 -1, urlCompW
->lpszExtraInfo
, len
);
3563 /***********************************************************************
3564 * InternetCreateUrlA (WININET.@)
3566 * See InternetCreateUrlW.
3568 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3569 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3573 URL_COMPONENTSW urlCompW
;
3575 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3577 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3579 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3583 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3586 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3588 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3590 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3591 *lpdwUrlLength
/= sizeof(WCHAR
);
3593 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3594 * minus one, so add one to leave room for NULL terminator
3597 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3599 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3600 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3601 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3602 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3603 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3604 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3605 HeapFree(GetProcessHeap(), 0, urlW
);
3610 /***********************************************************************
3611 * InternetCreateUrlW (WININET.@)
3613 * Creates a URL from its component parts.
3616 * lpUrlComponents [I] URL Components.
3617 * dwFlags [I] Flags. See notes.
3618 * lpszUrl [I] Buffer in which to store the created URL.
3619 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3620 * lpszUrl in characters. On output, the number of bytes
3621 * required to store the URL including terminator.
3625 * The dwFlags parameter can be zero or more of the following:
3626 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3633 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3634 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3637 INTERNET_SCHEME nScheme
;
3639 static const WCHAR slashSlashW
[] = {'/','/'};
3640 static const WCHAR percentD
[] = {'%','d',0};
3642 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3644 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3646 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3650 if (!calc_url_length(lpUrlComponents
, &dwLen
))
3653 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3655 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
3656 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3660 *lpdwUrlLength
= dwLen
;
3665 if (lpUrlComponents
->lpszScheme
)
3667 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3668 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
3671 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3676 nScheme
= lpUrlComponents
->nScheme
;
3678 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3679 nScheme
= INTERNET_SCHEME_HTTP
;
3681 scheme
= INTERNET_GetSchemeString(nScheme
);
3682 dwLen
= strlenW(scheme
);
3683 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
3687 /* all schemes are followed by at least a colon */
3691 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3693 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
3694 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
3697 if (lpUrlComponents
->lpszUserName
)
3699 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3700 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
3703 if (lpUrlComponents
->lpszPassword
)
3708 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3709 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
3717 if (lpUrlComponents
->lpszHostName
)
3719 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3720 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
3723 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3725 WCHAR szPort
[MAX_WORD_DIGITS
+1];
3727 sprintfW(szPort
, percentD
, lpUrlComponents
->nPort
);
3730 dwLen
= strlenW(szPort
);
3731 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
3735 /* add slash between hostname and path if necessary */
3736 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3744 if (lpUrlComponents
->lpszUrlPath
)
3746 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3747 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
3756 /***********************************************************************
3757 * InternetConfirmZoneCrossingA (WININET.@)
3760 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
3762 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
3763 return ERROR_SUCCESS
;
3766 /***********************************************************************
3767 * InternetConfirmZoneCrossingW (WININET.@)
3770 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
3772 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
3773 return ERROR_SUCCESS
;
3776 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
3777 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3779 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3780 lpdwConnection
, dwReserved
);
3781 return ERROR_SUCCESS
;
3784 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
3785 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3787 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3788 lpdwConnection
, dwReserved
);
3789 return ERROR_SUCCESS
;
3792 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3794 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
3798 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3800 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
3804 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
3806 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
3807 return ERROR_SUCCESS
;
3810 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
3813 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
3814 debugstr_w(pwszTarget
), pbHexHash
);
3818 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
3820 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
3824 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
3826 FIXME("(%p, %08lx) stub\n", a
, b
);