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
,
116 sizeof (*WININET_Handles
)* num
);
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 (*WININET_Handles
)* 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
));
415 TRACE("Proxy is not enabled.\n");
416 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_DIRECT
;
419 return (enabled
> 0);
422 /***********************************************************************
423 * dump_INTERNET_FLAGS
425 * Helper function to TRACE the internet flags.
431 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
433 #define FE(x) { x, #x }
434 static const wininet_flag_info flag
[] = {
435 FE(INTERNET_FLAG_RELOAD
),
436 FE(INTERNET_FLAG_RAW_DATA
),
437 FE(INTERNET_FLAG_EXISTING_CONNECT
),
438 FE(INTERNET_FLAG_ASYNC
),
439 FE(INTERNET_FLAG_PASSIVE
),
440 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
441 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
442 FE(INTERNET_FLAG_FROM_CACHE
),
443 FE(INTERNET_FLAG_SECURE
),
444 FE(INTERNET_FLAG_KEEP_CONNECTION
),
445 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
446 FE(INTERNET_FLAG_READ_PREFETCH
),
447 FE(INTERNET_FLAG_NO_COOKIES
),
448 FE(INTERNET_FLAG_NO_AUTH
),
449 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
450 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
451 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
452 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
453 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
454 FE(INTERNET_FLAG_RESYNCHRONIZE
),
455 FE(INTERNET_FLAG_HYPERLINK
),
456 FE(INTERNET_FLAG_NO_UI
),
457 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
458 FE(INTERNET_FLAG_CACHE_ASYNC
),
459 FE(INTERNET_FLAG_FORMS_SUBMIT
),
460 FE(INTERNET_FLAG_NEED_FILE
),
461 FE(INTERNET_FLAG_TRANSFER_ASCII
),
462 FE(INTERNET_FLAG_TRANSFER_BINARY
)
467 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
468 if (flag
[i
].val
& dwFlags
) {
469 TRACE(" %s", flag
[i
].name
);
470 dwFlags
&= ~flag
[i
].val
;
474 TRACE(" Unknown flags (%08x)\n", dwFlags
);
479 /***********************************************************************
480 * INTERNET_CloseHandle (internal)
482 * Close internet handle
485 static VOID
APPINFO_Destroy(WININETHANDLEHEADER
*hdr
)
487 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
491 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
492 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
493 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
494 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
495 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
496 HeapFree(GetProcessHeap(), 0, lpwai
);
499 static DWORD
APPINFO_QueryOption(WININETHANDLEHEADER
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
501 LPWININETAPPINFOW ai
= (LPWININETAPPINFOW
)hdr
;
504 case INTERNET_OPTION_HANDLE_TYPE
:
505 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
507 if (*size
< sizeof(ULONG
))
508 return ERROR_INSUFFICIENT_BUFFER
;
510 *size
= sizeof(DWORD
);
511 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_INTERNET
;
512 return ERROR_SUCCESS
;
514 case INTERNET_OPTION_USER_AGENT
: {
517 TRACE("INTERNET_OPTION_USER_AGENT\n");
522 *size
= (strlenW(ai
->lpszAgent
) + 1) * sizeof(WCHAR
);
523 if(!buffer
|| bufsize
< *size
)
524 return ERROR_INSUFFICIENT_BUFFER
;
526 strcpyW(buffer
, ai
->lpszAgent
);
528 *size
= WideCharToMultiByte(CP_ACP
, 0, ai
->lpszAgent
, -1, NULL
, 0, NULL
, NULL
);
529 if(!buffer
|| bufsize
< *size
)
530 return ERROR_INSUFFICIENT_BUFFER
;
532 WideCharToMultiByte(CP_ACP
, 0, ai
->lpszAgent
, -1, buffer
, *size
, NULL
, NULL
);
535 return ERROR_SUCCESS
;
538 case INTERNET_OPTION_PROXY
:
540 INTERNET_PROXY_INFOW
*pi
= (INTERNET_PROXY_INFOW
*)buffer
;
541 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
542 LPWSTR proxy
, proxy_bypass
;
545 proxyBytesRequired
= (lstrlenW(ai
->lpszProxy
) + 1) * sizeof(WCHAR
);
546 if (ai
->lpszProxyBypass
)
547 proxyBypassBytesRequired
= (lstrlenW(ai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
548 if (*size
< sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
550 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
551 return ERROR_INSUFFICIENT_BUFFER
;
553 proxy
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
));
554 proxy_bypass
= (LPWSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
);
556 pi
->dwAccessType
= ai
->dwAccessType
;
557 pi
->lpszProxy
= NULL
;
558 pi
->lpszProxyBypass
= NULL
;
560 lstrcpyW(proxy
, ai
->lpszProxy
);
561 pi
->lpszProxy
= proxy
;
564 if (ai
->lpszProxyBypass
) {
565 lstrcpyW(proxy_bypass
, ai
->lpszProxyBypass
);
566 pi
->lpszProxyBypass
= proxy_bypass
;
569 *size
= sizeof(INTERNET_PROXY_INFOW
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
570 return ERROR_SUCCESS
;
572 INTERNET_PROXY_INFOA
*pi
= (INTERNET_PROXY_INFOA
*)buffer
;
573 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
574 LPSTR proxy
, proxy_bypass
;
577 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
578 if (ai
->lpszProxyBypass
)
579 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0, ai
->lpszProxyBypass
, -1,
580 NULL
, 0, NULL
, NULL
);
581 if (*size
< sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
)
583 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
584 return ERROR_INSUFFICIENT_BUFFER
;
586 proxy
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
));
587 proxy_bypass
= (LPSTR
)((LPBYTE
)buffer
+ sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
589 pi
->dwAccessType
= ai
->dwAccessType
;
590 pi
->lpszProxy
= NULL
;
591 pi
->lpszProxyBypass
= NULL
;
593 WideCharToMultiByte(CP_ACP
, 0, ai
->lpszProxy
, -1, proxy
, proxyBytesRequired
, NULL
, NULL
);
594 pi
->lpszProxy
= proxy
;
597 if (ai
->lpszProxyBypass
) {
598 WideCharToMultiByte(CP_ACP
, 0, ai
->lpszProxyBypass
, -1, proxy_bypass
,
599 proxyBypassBytesRequired
, NULL
, NULL
);
600 pi
->lpszProxyBypass
= proxy_bypass
;
603 *size
= sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
+ proxyBypassBytesRequired
;
604 return ERROR_SUCCESS
;
608 return INET_QueryOption(option
, buffer
, size
, unicode
);
611 static const HANDLEHEADERVtbl APPINFOVtbl
= {
624 /***********************************************************************
625 * InternetOpenW (WININET.@)
627 * Per-application initialization of wininet
630 * HINTERNET on success
634 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
635 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
637 LPWININETAPPINFOW lpwai
= NULL
;
638 HINTERNET handle
= NULL
;
640 if (TRACE_ON(wininet
)) {
641 #define FE(x) { x, #x }
642 static const wininet_flag_info access_type
[] = {
643 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
644 FE(INTERNET_OPEN_TYPE_DIRECT
),
645 FE(INTERNET_OPEN_TYPE_PROXY
),
646 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
650 const char *access_type_str
= "Unknown";
652 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent
), dwAccessType
,
653 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
654 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
655 if (access_type
[i
].val
== dwAccessType
) {
656 access_type_str
= access_type
[i
].name
;
660 TRACE(" access type : %s\n", access_type_str
);
662 dump_INTERNET_FLAGS(dwFlags
);
665 /* Clear any error information */
666 INTERNET_SetLastError(0);
668 lpwai
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETAPPINFOW
));
671 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
675 lpwai
->hdr
.htype
= WH_HINIT
;
676 lpwai
->hdr
.vtbl
= &APPINFOVtbl
;
677 lpwai
->hdr
.dwFlags
= dwFlags
;
679 lpwai
->dwAccessType
= dwAccessType
;
680 lpwai
->lpszProxyUsername
= NULL
;
681 lpwai
->lpszProxyPassword
= NULL
;
683 handle
= WININET_AllocHandle( &lpwai
->hdr
);
686 HeapFree( GetProcessHeap(), 0, lpwai
);
687 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
691 if (NULL
!= lpszAgent
)
693 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
694 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
695 if (lpwai
->lpszAgent
)
696 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
698 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
699 INTERNET_ConfigureProxy( lpwai
);
700 else if (NULL
!= lpszProxy
)
702 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
703 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
704 if (lpwai
->lpszProxy
)
705 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
708 if (NULL
!= lpszProxyBypass
)
710 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
711 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
712 if (lpwai
->lpszProxyBypass
)
713 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
718 WININET_Release( &lpwai
->hdr
);
720 TRACE("returning %p\n", lpwai
);
726 /***********************************************************************
727 * InternetOpenA (WININET.@)
729 * Per-application initialization of wininet
732 * HINTERNET on success
736 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
737 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
741 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
743 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent
),
744 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
748 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
749 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
750 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
755 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
756 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
757 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
760 if( lpszProxyBypass
)
762 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
763 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
764 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
767 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
769 HeapFree(GetProcessHeap(), 0, szAgent
);
770 HeapFree(GetProcessHeap(), 0, szProxy
);
771 HeapFree(GetProcessHeap(), 0, szBypass
);
776 /***********************************************************************
777 * InternetGetLastResponseInfoA (WININET.@)
779 * Return last wininet error description on the calling thread
782 * TRUE on success of writing to buffer
786 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
787 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
789 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
795 *lpdwError
= lpwite
->dwError
;
798 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
799 *lpdwBufferLength
= strlen(lpszBuffer
);
802 *lpdwBufferLength
= 0;
807 *lpdwBufferLength
= 0;
813 /***********************************************************************
814 * InternetGetLastResponseInfoW (WININET.@)
816 * Return last wininet error description on the calling thread
819 * TRUE on success of writing to buffer
823 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
824 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
826 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
832 *lpdwError
= lpwite
->dwError
;
835 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
836 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
839 *lpdwBufferLength
= 0;
844 *lpdwBufferLength
= 0;
850 /***********************************************************************
851 * InternetGetConnectedState (WININET.@)
853 * Return connected state
857 * if lpdwStatus is not null, return the status (off line,
858 * modem, lan...) in it.
859 * FALSE if not connected
861 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
863 TRACE("(%p, 0x%08x)\n", lpdwStatus
, dwReserved
);
866 WARN("always returning LAN connection.\n");
867 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
873 /***********************************************************************
874 * InternetGetConnectedStateExW (WININET.@)
876 * Return connected state
880 * lpdwStatus [O] Flags specifying the status of the internet connection.
881 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
882 * dwNameLen [I] Size of the buffer, in characters.
883 * dwReserved [I] Reserved. Must be set to 0.
887 * if lpdwStatus is not null, return the status (off line,
888 * modem, lan...) in it.
889 * FALSE if not connected
892 * If the system has no available network connections, an empty string is
893 * stored in lpszConnectionName. If there is a LAN connection, a localized
894 * "LAN Connection" string is stored. Presumably, if only a dial-up
895 * connection is available then the name of the dial-up connection is
896 * returned. Why any application, other than the "Internet Settings" CPL,
897 * would want to use this function instead of the simpler InternetGetConnectedStateW
898 * function is beyond me.
900 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
901 DWORD dwNameLen
, DWORD dwReserved
)
903 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
910 WARN("always returning LAN connection.\n");
911 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
913 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
917 /***********************************************************************
918 * InternetGetConnectedStateExA (WININET.@)
920 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
921 DWORD dwNameLen
, DWORD dwReserved
)
923 LPWSTR lpwszConnectionName
= NULL
;
926 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
928 if (lpszConnectionName
&& dwNameLen
> 0)
929 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
931 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
933 if (rc
&& lpwszConnectionName
)
935 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
936 dwNameLen
, NULL
, NULL
);
938 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
945 /***********************************************************************
946 * InternetConnectW (WININET.@)
948 * Open a ftp, gopher or http session
951 * HINTERNET a session handle on success
955 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
956 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
957 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
958 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
960 LPWININETAPPINFOW hIC
;
963 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet
, debugstr_w(lpszServerName
),
964 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
965 dwService
, dwFlags
, dwContext
);
969 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
973 /* Clear any error information */
974 INTERNET_SetLastError(0);
975 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
976 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
978 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
984 case INTERNET_SERVICE_FTP
:
985 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
986 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
989 case INTERNET_SERVICE_HTTP
:
990 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
991 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
994 case INTERNET_SERVICE_GOPHER
:
1000 WININET_Release( &hIC
->hdr
);
1002 TRACE("returning %p\n", rc
);
1007 /***********************************************************************
1008 * InternetConnectA (WININET.@)
1010 * Open a ftp, gopher or http session
1013 * HINTERNET a session handle on success
1017 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
1018 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
1019 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
1020 DWORD dwService
, DWORD dwFlags
, DWORD_PTR dwContext
)
1022 HINTERNET rc
= NULL
;
1024 LPWSTR szServerName
= NULL
;
1025 LPWSTR szUserName
= NULL
;
1026 LPWSTR szPassword
= NULL
;
1030 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
1031 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1032 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
1036 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
1037 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1038 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
1042 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
1043 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1044 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
1048 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
1049 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
1051 HeapFree(GetProcessHeap(), 0, szServerName
);
1052 HeapFree(GetProcessHeap(), 0, szUserName
);
1053 HeapFree(GetProcessHeap(), 0, szPassword
);
1058 /***********************************************************************
1059 * InternetFindNextFileA (WININET.@)
1061 * Continues a file search from a previous call to FindFirstFile
1068 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
1071 WIN32_FIND_DATAW fd
;
1073 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
1075 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
1079 /***********************************************************************
1080 * InternetFindNextFileW (WININET.@)
1082 * Continues a file search from a previous call to FindFirstFile
1089 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
1091 WININETHANDLEHEADER
*hdr
;
1096 hdr
= WININET_GetObject(hFind
);
1098 WARN("Invalid handle\n");
1099 SetLastError(ERROR_INVALID_HANDLE
);
1103 if(hdr
->vtbl
->FindNextFileW
) {
1104 res
= hdr
->vtbl
->FindNextFileW(hdr
, lpvFindData
);
1106 WARN("Handle doesn't support NextFile\n");
1107 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1110 WININET_Release(hdr
);
1112 if(res
!= ERROR_SUCCESS
)
1114 return res
== ERROR_SUCCESS
;
1117 /***********************************************************************
1118 * InternetCloseHandle (WININET.@)
1120 * Generic close handle function
1127 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1129 LPWININETHANDLEHEADER lpwh
;
1131 TRACE("%p\n",hInternet
);
1133 lpwh
= WININET_GetObject( hInternet
);
1136 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1140 WININET_Release( lpwh
);
1141 WININET_FreeHandle( hInternet
);
1147 /***********************************************************************
1148 * ConvertUrlComponentValue (Internal)
1150 * Helper function for InternetCrackUrlA
1153 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1154 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1155 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1157 TRACE("%p %d %p %d %p %p\n", *lppszComponent
, *dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1158 if (*dwComponentLen
!= 0)
1160 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1161 if (*lppszComponent
== NULL
)
1163 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1165 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1167 *lppszComponent
= NULL
;
1168 *dwComponentLen
= nASCIILength
;
1172 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1173 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1174 (*lppszComponent
)[ncpylen
]=0;
1175 *dwComponentLen
= ncpylen
;
1181 /***********************************************************************
1182 * InternetCrackUrlA (WININET.@)
1184 * See InternetCrackUrlW.
1186 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1187 LPURL_COMPONENTSA lpUrlComponents
)
1190 URL_COMPONENTSW UCW
;
1192 WCHAR
*lpwszUrl
, *hostname
= NULL
, *username
= NULL
, *password
= NULL
, *path
= NULL
,
1193 *scheme
= NULL
, *extra
= NULL
;
1195 TRACE("(%s %u %x %p)\n",
1196 lpszUrl
? debugstr_an(lpszUrl
, dwUrlLength
? dwUrlLength
: strlen(lpszUrl
)) : "(null)",
1197 dwUrlLength
, dwFlags
, lpUrlComponents
);
1199 if (!lpszUrl
|| !*lpszUrl
|| !lpUrlComponents
||
1200 lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSA
))
1202 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1208 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1210 /* if dwUrlLength=-1 then nLength includes null but length to
1211 InternetCrackUrlW should not include it */
1212 if (dwUrlLength
== -1) nLength
--;
1214 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1215 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1217 memset(&UCW
,0,sizeof(UCW
));
1218 UCW
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1219 if (lpUrlComponents
->dwHostNameLength
)
1221 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1222 if (lpUrlComponents
->lpszHostName
)
1224 hostname
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwHostNameLength
* sizeof(WCHAR
));
1225 UCW
.lpszHostName
= hostname
;
1228 if (lpUrlComponents
->dwUserNameLength
)
1230 UCW
.dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
1231 if (lpUrlComponents
->lpszUserName
)
1233 username
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwUserNameLength
* sizeof(WCHAR
));
1234 UCW
.lpszUserName
= username
;
1237 if (lpUrlComponents
->dwPasswordLength
)
1239 UCW
.dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
1240 if (lpUrlComponents
->lpszPassword
)
1242 password
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwPasswordLength
* sizeof(WCHAR
));
1243 UCW
.lpszPassword
= password
;
1246 if (lpUrlComponents
->dwUrlPathLength
)
1248 UCW
.dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
1249 if (lpUrlComponents
->lpszUrlPath
)
1251 path
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwUrlPathLength
* sizeof(WCHAR
));
1252 UCW
.lpszUrlPath
= path
;
1255 if (lpUrlComponents
->dwSchemeLength
)
1257 UCW
.dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
1258 if (lpUrlComponents
->lpszScheme
)
1260 scheme
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwSchemeLength
* sizeof(WCHAR
));
1261 UCW
.lpszScheme
= scheme
;
1264 if (lpUrlComponents
->dwExtraInfoLength
)
1266 UCW
.dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
1267 if (lpUrlComponents
->lpszExtraInfo
)
1269 extra
= HeapAlloc(GetProcessHeap(), 0, UCW
.dwExtraInfoLength
* sizeof(WCHAR
));
1270 UCW
.lpszExtraInfo
= extra
;
1273 if ((ret
= InternetCrackUrlW(lpwszUrl
, nLength
, dwFlags
, &UCW
)))
1275 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1276 UCW
.lpszHostName
, UCW
.dwHostNameLength
, lpszUrl
, lpwszUrl
);
1277 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1278 UCW
.lpszUserName
, UCW
.dwUserNameLength
, lpszUrl
, lpwszUrl
);
1279 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1280 UCW
.lpszPassword
, UCW
.dwPasswordLength
, lpszUrl
, lpwszUrl
);
1281 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1282 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
, lpszUrl
, lpwszUrl
);
1283 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1284 UCW
.lpszScheme
, UCW
.dwSchemeLength
, lpszUrl
, lpwszUrl
);
1285 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1286 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
, lpszUrl
, lpwszUrl
);
1288 lpUrlComponents
->nScheme
= UCW
.nScheme
;
1289 lpUrlComponents
->nPort
= UCW
.nPort
;
1291 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1292 debugstr_an(lpUrlComponents
->lpszScheme
, lpUrlComponents
->dwSchemeLength
),
1293 debugstr_an(lpUrlComponents
->lpszHostName
, lpUrlComponents
->dwHostNameLength
),
1294 debugstr_an(lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->dwUrlPathLength
),
1295 debugstr_an(lpUrlComponents
->lpszExtraInfo
, lpUrlComponents
->dwExtraInfoLength
));
1297 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1298 HeapFree(GetProcessHeap(), 0, hostname
);
1299 HeapFree(GetProcessHeap(), 0, username
);
1300 HeapFree(GetProcessHeap(), 0, password
);
1301 HeapFree(GetProcessHeap(), 0, path
);
1302 HeapFree(GetProcessHeap(), 0, scheme
);
1303 HeapFree(GetProcessHeap(), 0, extra
);
1307 static const WCHAR url_schemes
[][7] =
1310 {'g','o','p','h','e','r',0},
1311 {'h','t','t','p',0},
1312 {'h','t','t','p','s',0},
1313 {'f','i','l','e',0},
1314 {'n','e','w','s',0},
1315 {'m','a','i','l','t','o',0},
1319 /***********************************************************************
1320 * GetInternetSchemeW (internal)
1326 * INTERNET_SCHEME_UNKNOWN on failure
1329 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1333 TRACE("%s %d\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1335 if(lpszScheme
==NULL
)
1336 return INTERNET_SCHEME_UNKNOWN
;
1338 for (i
= 0; i
< sizeof(url_schemes
)/sizeof(url_schemes
[0]); i
++)
1339 if (!strncmpW(lpszScheme
, url_schemes
[i
], nMaxCmp
))
1340 return INTERNET_SCHEME_FIRST
+ i
;
1342 return INTERNET_SCHEME_UNKNOWN
;
1345 /***********************************************************************
1346 * SetUrlComponentValueW (Internal)
1348 * Helper function for InternetCrackUrlW
1351 * lppszComponent [O] Holds the returned string
1352 * dwComponentLen [I] Holds the size of lppszComponent
1353 * [O] Holds the length of the string in lppszComponent without '\0'
1354 * lpszStart [I] Holds the string to copy from
1355 * len [I] Holds the length of lpszStart without '\0'
1362 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1364 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
1366 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1369 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1371 if (*lppszComponent
== NULL
)
1373 *lppszComponent
= (LPWSTR
)lpszStart
;
1374 *dwComponentLen
= len
;
1378 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1379 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1380 (*lppszComponent
)[ncpylen
] = '\0';
1381 *dwComponentLen
= ncpylen
;
1388 /***********************************************************************
1389 * InternetCrackUrlW (WININET.@)
1391 * Break up URL into its components
1397 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1398 LPURL_COMPONENTSW lpUC
)
1402 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1405 LPCWSTR lpszParam
= NULL
;
1406 BOOL bIsAbsolute
= FALSE
;
1407 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1408 LPCWSTR lpszcp
= NULL
;
1409 LPWSTR lpszUrl_decode
= NULL
;
1410 DWORD dwUrlLength
= dwUrlLength_orig
;
1412 TRACE("(%s %u %x %p)\n",
1413 lpszUrl
? debugstr_wn(lpszUrl
, dwUrlLength
? dwUrlLength
: strlenW(lpszUrl
)) : "(null)",
1414 dwUrlLength
, dwFlags
, lpUC
);
1416 if (!lpszUrl_orig
|| !*lpszUrl_orig
|| !lpUC
)
1418 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1421 if (!dwUrlLength
) dwUrlLength
= strlenW(lpszUrl
);
1423 if (dwFlags
& ICU_DECODE
)
1426 DWORD len
= dwUrlLength
+ 1;
1428 if (!(url_tmp
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
1430 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1433 memcpy(url_tmp
, lpszUrl_orig
, dwUrlLength
* sizeof(WCHAR
));
1434 url_tmp
[dwUrlLength
] = 0;
1435 if (!(lpszUrl_decode
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
1437 HeapFree(GetProcessHeap(), 0, url_tmp
);
1438 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1441 if (InternetCanonicalizeUrlW(url_tmp
, lpszUrl_decode
, &len
, ICU_DECODE
| ICU_NO_ENCODE
))
1444 lpszUrl
= lpszUrl_decode
;
1446 HeapFree(GetProcessHeap(), 0, url_tmp
);
1450 /* Determine if the URI is absolute. */
1451 while (lpszap
- lpszUrl
< dwUrlLength
)
1453 if (isalnumW(*lpszap
))
1458 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1465 lpszcp
= lpszUrl
; /* Relative url */
1471 lpUC
->nScheme
= INTERNET_SCHEME_UNKNOWN
;
1472 lpUC
->nPort
= INTERNET_INVALID_PORT_NUMBER
;
1474 /* Parse <params> */
1475 if (!(lpszParam
= memchrW(lpszap
, ';', dwUrlLength
- (lpszap
- lpszUrl
))))
1476 lpszParam
= memchrW(lpszap
, '?', dwUrlLength
- (lpszap
- lpszUrl
));
1478 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1479 lpszParam
, lpszParam
? dwUrlLength
-(lpszParam
-lpszUrl
) : 0);
1481 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1485 /* Get scheme first. */
1486 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1487 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1488 lpszUrl
, lpszcp
- lpszUrl
);
1490 /* Eat ':' in protocol. */
1493 /* double slash indicates the net_loc portion is present */
1494 if ((lpszcp
[0] == '/') && (lpszcp
[1] == '/'))
1498 lpszNetLoc
= memchrW(lpszcp
, '/', dwUrlLength
- (lpszcp
- lpszUrl
));
1502 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1504 lpszNetLoc
= lpszParam
;
1506 else if (!lpszNetLoc
)
1507 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1515 /* [<user>[<:password>]@]<host>[:<port>] */
1516 /* First find the user and password if they exist */
1518 lpszHost
= memchrW(lpszcp
, '@', dwUrlLength
- (lpszcp
- lpszUrl
));
1519 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1521 /* username and password not specified. */
1522 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1523 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1525 else /* Parse out username and password */
1527 LPCWSTR lpszUser
= lpszcp
;
1528 LPCWSTR lpszPasswd
= lpszHost
;
1530 while (lpszcp
< lpszHost
)
1533 lpszPasswd
= lpszcp
;
1538 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1539 lpszUser
, lpszPasswd
- lpszUser
);
1541 if (lpszPasswd
!= lpszHost
)
1543 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1544 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1545 lpszHost
- lpszPasswd
);
1547 lpszcp
++; /* Advance to beginning of host */
1550 /* Parse <host><:port> */
1553 lpszPort
= lpszNetLoc
;
1555 /* special case for res:// URLs: there is no port here, so the host is the
1556 entire string up to the first '/' */
1557 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1559 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1560 lpszHost
, lpszPort
- lpszHost
);
1565 while (lpszcp
< lpszNetLoc
)
1573 /* If the scheme is "file" and the host is just one letter, it's not a host */
1574 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1577 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1582 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1583 lpszHost
, lpszPort
- lpszHost
);
1584 if (lpszPort
!= lpszNetLoc
)
1585 lpUC
->nPort
= atoiW(++lpszPort
);
1586 else switch (lpUC
->nScheme
)
1588 case INTERNET_SCHEME_HTTP
:
1589 lpUC
->nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1591 case INTERNET_SCHEME_HTTPS
:
1592 lpUC
->nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1594 case INTERNET_SCHEME_FTP
:
1595 lpUC
->nPort
= INTERNET_DEFAULT_FTP_PORT
;
1597 case INTERNET_SCHEME_GOPHER
:
1598 lpUC
->nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
1609 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1610 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1611 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1616 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
, NULL
, 0);
1617 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1618 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1619 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1622 /* Here lpszcp points to:
1624 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1625 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1627 if (lpszcp
!= 0 && lpszcp
- lpszUrl
< dwUrlLength
&& (!lpszParam
|| lpszcp
< lpszParam
))
1631 /* Only truncate the parameter list if it's already been saved
1632 * in lpUC->lpszExtraInfo.
1634 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1635 len
= lpszParam
- lpszcp
;
1638 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1639 * newlines if necessary.
1641 LPWSTR lpsznewline
= memchrW(lpszcp
, '\n', dwUrlLength
- (lpszcp
- lpszUrl
));
1642 if (lpsznewline
!= NULL
)
1643 len
= lpsznewline
- lpszcp
;
1645 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1647 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1652 if (lpUC
->lpszUrlPath
&& (lpUC
->dwUrlPathLength
> 0))
1653 lpUC
->lpszUrlPath
[0] = 0;
1654 lpUC
->dwUrlPathLength
= 0;
1657 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1658 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1659 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1660 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1661 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1663 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1667 /***********************************************************************
1668 * InternetAttemptConnect (WININET.@)
1670 * Attempt to make a connection to the internet
1673 * ERROR_SUCCESS on success
1674 * Error value on failure
1677 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1680 return ERROR_SUCCESS
;
1684 /***********************************************************************
1685 * InternetCanonicalizeUrlA (WININET.@)
1687 * Escape unsafe characters and spaces
1694 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1695 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1698 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1700 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl
), lpszBuffer
,
1701 lpdwBufferLength
, lpdwBufferLength
? *lpdwBufferLength
: -1, dwFlags
);
1703 if(dwFlags
& ICU_DECODE
)
1705 dwURLFlags
|= URL_UNESCAPE
;
1706 dwFlags
&= ~ICU_DECODE
;
1709 if(dwFlags
& ICU_ESCAPE
)
1711 dwURLFlags
|= URL_UNESCAPE
;
1712 dwFlags
&= ~ICU_ESCAPE
;
1715 if(dwFlags
& ICU_BROWSER_MODE
)
1717 dwURLFlags
|= URL_BROWSER_MODE
;
1718 dwFlags
&= ~ICU_BROWSER_MODE
;
1721 if(dwFlags
& ICU_NO_ENCODE
)
1723 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1724 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1725 dwFlags
&= ~ICU_NO_ENCODE
;
1728 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1730 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1731 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1732 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1734 return (hr
== S_OK
) ? TRUE
: FALSE
;
1737 /***********************************************************************
1738 * InternetCanonicalizeUrlW (WININET.@)
1740 * Escape unsafe characters and spaces
1747 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1748 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1751 DWORD dwURLFlags
= URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
;
1753 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl
), lpszBuffer
,
1754 lpdwBufferLength
, dwFlags
, lpdwBufferLength
? *lpdwBufferLength
: -1);
1756 if(dwFlags
& ICU_DECODE
)
1758 dwURLFlags
|= URL_UNESCAPE
;
1759 dwFlags
&= ~ICU_DECODE
;
1762 if(dwFlags
& ICU_ESCAPE
)
1764 dwURLFlags
|= URL_UNESCAPE
;
1765 dwFlags
&= ~ICU_ESCAPE
;
1768 if(dwFlags
& ICU_BROWSER_MODE
)
1770 dwURLFlags
|= URL_BROWSER_MODE
;
1771 dwFlags
&= ~ICU_BROWSER_MODE
;
1774 if(dwFlags
& ICU_NO_ENCODE
)
1776 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1777 dwURLFlags
^= URL_ESCAPE_UNSAFE
;
1778 dwFlags
&= ~ICU_NO_ENCODE
;
1781 if (dwFlags
) FIXME("Unhandled flags 0x%08x\n", dwFlags
);
1783 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1784 if (hr
== E_POINTER
) SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1785 if (hr
== E_INVALIDARG
) SetLastError(ERROR_INVALID_PARAMETER
);
1787 return (hr
== S_OK
) ? TRUE
: FALSE
;
1790 /* #################################################### */
1792 static INTERNET_STATUS_CALLBACK
set_status_callback(
1793 LPWININETHANDLEHEADER lpwh
, INTERNET_STATUS_CALLBACK callback
, BOOL unicode
)
1795 INTERNET_STATUS_CALLBACK ret
;
1797 if (unicode
) lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1798 else lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1800 ret
= lpwh
->lpfnStatusCB
;
1801 lpwh
->lpfnStatusCB
= callback
;
1806 /***********************************************************************
1807 * InternetSetStatusCallbackA (WININET.@)
1809 * Sets up a callback function which is called as progress is made
1810 * during an operation.
1813 * Previous callback or NULL on success
1814 * INTERNET_INVALID_STATUS_CALLBACK on failure
1817 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1818 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1820 INTERNET_STATUS_CALLBACK retVal
;
1821 LPWININETHANDLEHEADER lpwh
;
1823 TRACE("0x%08x\n", (ULONG
)hInternet
);
1825 if (!(lpwh
= WININET_GetObject(hInternet
)))
1826 return INTERNET_INVALID_STATUS_CALLBACK
;
1828 retVal
= set_status_callback(lpwh
, lpfnIntCB
, FALSE
);
1830 WININET_Release( lpwh
);
1834 /***********************************************************************
1835 * InternetSetStatusCallbackW (WININET.@)
1837 * Sets up a callback function which is called as progress is made
1838 * during an operation.
1841 * Previous callback or NULL on success
1842 * INTERNET_INVALID_STATUS_CALLBACK on failure
1845 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1846 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1848 INTERNET_STATUS_CALLBACK retVal
;
1849 LPWININETHANDLEHEADER lpwh
;
1851 TRACE("0x%08x\n", (ULONG
)hInternet
);
1853 if (!(lpwh
= WININET_GetObject(hInternet
)))
1854 return INTERNET_INVALID_STATUS_CALLBACK
;
1856 retVal
= set_status_callback(lpwh
, lpfnIntCB
, TRUE
);
1858 WININET_Release( lpwh
);
1862 /***********************************************************************
1863 * InternetSetFilePointer (WININET.@)
1865 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1866 PVOID pReserved
, DWORD dwMoveContext
, DWORD_PTR dwContext
)
1872 /***********************************************************************
1873 * InternetWriteFile (WININET.@)
1875 * Write data to an open internet file
1882 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1883 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1885 LPWININETHANDLEHEADER lpwh
;
1886 BOOL retval
= FALSE
;
1888 TRACE("(%p %p %d %p)\n", hFile
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1890 lpwh
= WININET_GetObject( hFile
);
1892 WARN("Invalid handle\n");
1893 SetLastError(ERROR_INVALID_HANDLE
);
1897 if(lpwh
->vtbl
->WriteFile
) {
1898 retval
= lpwh
->vtbl
->WriteFile(lpwh
, lpBuffer
, dwNumOfBytesToWrite
, lpdwNumOfBytesWritten
);
1900 WARN("No Writefile method.\n");
1901 SetLastError(ERROR_INVALID_HANDLE
);
1905 WININET_Release( lpwh
);
1911 /***********************************************************************
1912 * InternetReadFile (WININET.@)
1914 * Read data from an open internet file
1921 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1922 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1924 LPWININETHANDLEHEADER hdr
;
1925 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1927 TRACE("%p %p %d %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1929 hdr
= WININET_GetObject(hFile
);
1931 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1935 if(hdr
->vtbl
->ReadFile
)
1936 res
= hdr
->vtbl
->ReadFile(hdr
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1938 WININET_Release(hdr
);
1940 TRACE("-- %s (%u) (bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE", res
,
1941 pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1943 if(res
!= ERROR_SUCCESS
)
1945 return res
== ERROR_SUCCESS
;
1948 /***********************************************************************
1949 * InternetReadFileExA (WININET.@)
1951 * Read data from an open internet file
1954 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1955 * lpBuffersOut [I/O] Buffer.
1956 * dwFlags [I] Flags. See notes.
1957 * dwContext [I] Context for callbacks.
1964 * The parameter dwFlags include zero or more of the following flags:
1965 *|IRF_ASYNC - Makes the call asynchronous.
1966 *|IRF_SYNC - Makes the call synchronous.
1967 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1968 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1970 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1973 * InternetOpenUrlA(), HttpOpenRequestA()
1975 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1976 DWORD dwFlags
, DWORD_PTR dwContext
)
1978 LPWININETHANDLEHEADER hdr
;
1979 DWORD res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
1981 TRACE("(%p %p 0x%x 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1983 hdr
= WININET_GetObject(hFile
);
1985 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1989 if(hdr
->vtbl
->ReadFileExA
)
1990 res
= hdr
->vtbl
->ReadFileExA(hdr
, lpBuffersOut
, dwFlags
, dwContext
);
1992 WININET_Release(hdr
);
1994 TRACE("-- %s (%u, bytes read: %d)\n", res
== ERROR_SUCCESS
? "TRUE": "FALSE",
1995 res
, lpBuffersOut
->dwBufferLength
);
1997 if(res
!= ERROR_SUCCESS
)
1999 return res
== ERROR_SUCCESS
;
2002 /***********************************************************************
2003 * InternetReadFileExW (WININET.@)
2005 * Read data from an open internet file.
2008 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
2009 * lpBuffersOut [I/O] Buffer.
2010 * dwFlags [I] Flags.
2011 * dwContext [I] Context for callbacks.
2014 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
2017 * Not implemented in Wine or native either (as of IE6 SP2).
2020 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
2021 DWORD dwFlags
, DWORD_PTR dwContext
)
2023 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
2025 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2029 DWORD
INET_QueryOption(DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2031 static BOOL warn
= TRUE
;
2034 case INTERNET_OPTION_REQUEST_FLAGS
:
2035 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2037 if (*size
< sizeof(ULONG
))
2038 return ERROR_INSUFFICIENT_BUFFER
;
2040 *(ULONG
*)buffer
= 4;
2041 *size
= sizeof(ULONG
);
2043 return ERROR_SUCCESS
;
2045 case INTERNET_OPTION_HTTP_VERSION
:
2046 if (*size
< sizeof(HTTP_VERSION_INFO
))
2047 return ERROR_INSUFFICIENT_BUFFER
;
2050 * Presently hardcoded to 1.1
2052 ((HTTP_VERSION_INFO
*)buffer
)->dwMajorVersion
= 1;
2053 ((HTTP_VERSION_INFO
*)buffer
)->dwMinorVersion
= 1;
2054 *size
= sizeof(HTTP_VERSION_INFO
);
2056 return ERROR_SUCCESS
;
2058 case INTERNET_OPTION_CONNECTED_STATE
:
2061 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2064 if (*size
< sizeof(ULONG
))
2065 return ERROR_INSUFFICIENT_BUFFER
;
2067 *(ULONG
*)buffer
= INTERNET_STATE_CONNECTED
;
2068 *size
= sizeof(ULONG
);
2070 return ERROR_SUCCESS
;
2072 case INTERNET_OPTION_PROXY
: {
2075 TRACE("Getting global proxy info\n");
2076 memset(&ai
, 0, sizeof(WININETAPPINFOW
));
2077 INTERNET_ConfigureProxy(&ai
);
2079 return APPINFO_QueryOption(&ai
.hdr
, INTERNET_OPTION_PROXY
, buffer
, size
, unicode
); /* FIXME */
2082 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2083 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2085 if (*size
< sizeof(ULONG
))
2086 return ERROR_INSUFFICIENT_BUFFER
;
2088 *(ULONG
*)buffer
= 2;
2089 *size
= sizeof(ULONG
);
2091 return ERROR_SUCCESS
;
2093 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2094 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2096 if (*size
< sizeof(ULONG
))
2097 return ERROR_INSUFFICIENT_BUFFER
;
2100 *size
= sizeof(ULONG
);
2102 return ERROR_SUCCESS
;
2104 case INTERNET_OPTION_SECURITY_FLAGS
:
2105 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2106 return ERROR_SUCCESS
;
2108 case INTERNET_OPTION_VERSION
: {
2109 static const INTERNET_VERSION_INFO info
= { 1, 2 };
2111 TRACE("INTERNET_OPTION_VERSION\n");
2113 if (*size
< sizeof(INTERNET_VERSION_INFO
))
2114 return ERROR_INSUFFICIENT_BUFFER
;
2116 memcpy(buffer
, &info
, sizeof(info
));
2117 *size
= sizeof(info
);
2119 return ERROR_SUCCESS
;
2122 case INTERNET_OPTION_PER_CONNECTION_OPTION
: {
2123 INTERNET_PER_CONN_OPTION_LISTW
*con
= buffer
;
2124 DWORD res
= ERROR_SUCCESS
, i
;
2126 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2128 if (*size
< sizeof(INTERNET_PER_CONN_OPTION_LISTW
))
2129 return ERROR_INSUFFICIENT_BUFFER
;
2131 for (i
= 0; i
< con
->dwOptionCount
; i
++) {
2132 INTERNET_PER_CONN_OPTIONW
*option
= con
->pOptions
+ i
;
2134 switch (option
->dwOption
) {
2135 case INTERNET_PER_CONN_FLAGS
:
2136 option
->Value
.dwValue
= PROXY_TYPE_DIRECT
;
2139 case INTERNET_PER_CONN_PROXY_SERVER
:
2140 case INTERNET_PER_CONN_PROXY_BYPASS
:
2141 case INTERNET_PER_CONN_AUTOCONFIG_URL
:
2142 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS
:
2143 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL
:
2144 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS
:
2145 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME
:
2146 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL
:
2147 FIXME("Unhandled dwOption %d\n", option
->dwOption
);
2148 option
->Value
.dwValue
= 0;
2149 res
= ERROR_INVALID_PARAMETER
;
2153 FIXME("Unknown dwOption %d\n", option
->dwOption
);
2154 res
= ERROR_INVALID_PARAMETER
;
2163 FIXME("Stub for %d\n", option
);
2164 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
2167 /***********************************************************************
2168 * InternetQueryOptionW (WININET.@)
2170 * Queries an options on the specified handle
2177 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2178 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2180 LPWININETHANDLEHEADER hdr
;
2181 DWORD res
= ERROR_INVALID_HANDLE
;
2183 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2186 hdr
= WININET_GetObject(hInternet
);
2188 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2189 WININET_Release(hdr
);
2192 res
= INET_QueryOption(dwOption
, lpBuffer
, lpdwBufferLength
, TRUE
);
2195 if(res
!= ERROR_SUCCESS
)
2197 return res
== ERROR_SUCCESS
;
2200 /***********************************************************************
2201 * InternetQueryOptionA (WININET.@)
2203 * Queries an options on the specified handle
2210 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2211 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2213 LPWININETHANDLEHEADER hdr
;
2214 DWORD res
= ERROR_INVALID_HANDLE
;
2216 TRACE("%p %d %p %p\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2219 hdr
= WININET_GetObject(hInternet
);
2221 res
= hdr
->vtbl
->QueryOption(hdr
, dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2222 WININET_Release(hdr
);
2225 res
= INET_QueryOption(dwOption
, lpBuffer
, lpdwBufferLength
, FALSE
);
2228 if(res
!= ERROR_SUCCESS
)
2230 return res
== ERROR_SUCCESS
;
2234 /***********************************************************************
2235 * InternetSetOptionW (WININET.@)
2237 * Sets an options on the specified handle
2244 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2245 LPVOID lpBuffer
, DWORD dwBufferLength
)
2247 LPWININETHANDLEHEADER lpwhh
;
2250 TRACE("(%p %d %p %d)\n", hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2252 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2253 if(lpwhh
&& lpwhh
->vtbl
->SetOption
) {
2256 res
= lpwhh
->vtbl
->SetOption(lpwhh
, dwOption
, lpBuffer
, dwBufferLength
);
2257 if(res
!= ERROR_INTERNET_INVALID_OPTION
) {
2258 WININET_Release( lpwhh
);
2260 if(res
!= ERROR_SUCCESS
)
2263 return res
== ERROR_SUCCESS
;
2269 case INTERNET_OPTION_CALLBACK
:
2273 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2276 WININET_Release(lpwhh
);
2277 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE
);
2280 case INTERNET_OPTION_HTTP_VERSION
:
2282 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2283 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2286 case INTERNET_OPTION_ERROR_MASK
:
2288 ULONG flags
= *(ULONG
*)lpBuffer
;
2289 FIXME("Option INTERNET_OPTION_ERROR_MASK(%d): STUB\n", flags
);
2292 case INTERNET_OPTION_CODEPAGE
:
2294 ULONG codepage
= *(ULONG
*)lpBuffer
;
2295 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage
);
2298 case INTERNET_OPTION_REQUEST_PRIORITY
:
2300 ULONG priority
= *(ULONG
*)lpBuffer
;
2301 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority
);
2304 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2306 ULONG connecttimeout
= *(ULONG
*)lpBuffer
;
2307 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout
);
2310 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2312 ULONG receivetimeout
= *(ULONG
*)lpBuffer
;
2313 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout
);
2316 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2318 ULONG conns
= *(ULONG
*)lpBuffer
;
2319 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns
);
2322 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2324 ULONG conns
= *(ULONG
*)lpBuffer
;
2325 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns
);
2328 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2329 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2331 case INTERNET_OPTION_END_BROWSER_SESSION
:
2332 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2334 case INTERNET_OPTION_CONNECTED_STATE
:
2335 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2337 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2338 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2340 case INTERNET_OPTION_SEND_TIMEOUT
:
2341 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2343 ULONG timeout
= *(ULONG
*)lpBuffer
;
2344 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT %d\n", timeout
);
2347 case INTERNET_OPTION_CONNECT_RETRIES
:
2349 ULONG retries
= *(ULONG
*)lpBuffer
;
2350 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries
);
2353 case INTERNET_OPTION_CONTEXT_VALUE
:
2354 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2356 case INTERNET_OPTION_SECURITY_FLAGS
:
2357 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2359 case INTERNET_OPTION_DISABLE_AUTODIAL
:
2360 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2366 FIXME("Option %d STUB\n",dwOption
);
2367 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION
);
2373 WININET_Release( lpwhh
);
2379 /***********************************************************************
2380 * InternetSetOptionA (WININET.@)
2382 * Sets an options on the specified handle.
2389 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2390 LPVOID lpBuffer
, DWORD dwBufferLength
)
2398 case INTERNET_OPTION_CALLBACK
:
2400 LPWININETHANDLEHEADER lpwh
;
2402 if (!(lpwh
= WININET_GetObject(hInternet
)))
2404 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2407 WININET_Release(lpwh
);
2408 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE
);
2411 case INTERNET_OPTION_PROXY
:
2413 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2414 LPINTERNET_PROXY_INFOW piw
;
2415 DWORD proxlen
, prbylen
;
2418 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2419 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2420 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2421 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2422 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2423 piw
->dwAccessType
= pi
->dwAccessType
;
2424 prox
= (LPWSTR
) &piw
[1];
2425 prby
= &prox
[proxlen
+1];
2426 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2427 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2428 piw
->lpszProxy
= prox
;
2429 piw
->lpszProxyBypass
= prby
;
2432 case INTERNET_OPTION_USER_AGENT
:
2433 case INTERNET_OPTION_USERNAME
:
2434 case INTERNET_OPTION_PASSWORD
:
2435 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2437 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2438 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2443 wlen
= dwBufferLength
;
2446 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2448 if( lpBuffer
!= wbuffer
)
2449 HeapFree( GetProcessHeap(), 0, wbuffer
);
2455 /***********************************************************************
2456 * InternetSetOptionExA (WININET.@)
2458 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2459 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2461 FIXME("Flags %08x ignored\n", dwFlags
);
2462 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2465 /***********************************************************************
2466 * InternetSetOptionExW (WININET.@)
2468 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2469 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2471 FIXME("Flags %08x ignored\n", dwFlags
);
2472 if( dwFlags
& ~ISO_VALID_FLAGS
)
2474 INTERNET_SetLastError( ERROR_INVALID_PARAMETER
);
2477 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2480 static const WCHAR WININET_wkday
[7][4] =
2481 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2482 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2483 static const WCHAR WININET_month
[12][4] =
2484 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2485 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2486 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2488 /***********************************************************************
2489 * InternetTimeFromSystemTimeA (WININET.@)
2491 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2494 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2496 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2498 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
2500 SetLastError(ERROR_INVALID_PARAMETER
);
2504 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
2506 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2510 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2511 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2516 /***********************************************************************
2517 * InternetTimeFromSystemTimeW (WININET.@)
2519 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2521 static const WCHAR date
[] =
2522 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2523 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2525 TRACE( "%p 0x%08x %p 0x%08x\n", time
, format
, string
, size
);
2527 if (!time
|| !string
|| format
!= INTERNET_RFC1123_FORMAT
)
2529 SetLastError(ERROR_INVALID_PARAMETER
);
2533 if (size
< INTERNET_RFC1123_BUFSIZE
* sizeof(*string
))
2535 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2539 sprintfW( string
, date
,
2540 WININET_wkday
[time
->wDayOfWeek
],
2542 WININET_month
[time
->wMonth
- 1],
2551 /***********************************************************************
2552 * InternetTimeToSystemTimeA (WININET.@)
2554 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2560 TRACE( "%s %p 0x%08x\n", debugstr_a(string
), time
, reserved
);
2562 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2563 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2567 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2568 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2569 HeapFree( GetProcessHeap(), 0, stringW
);
2574 /***********************************************************************
2575 * InternetTimeToSystemTimeW (WININET.@)
2577 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2580 const WCHAR
*s
= string
;
2583 TRACE( "%s %p 0x%08x\n", debugstr_w(string
), time
, reserved
);
2585 if (!string
|| !time
) return FALSE
;
2587 /* Windows does this too */
2588 GetSystemTime( time
);
2590 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2591 * a SYSTEMTIME structure.
2594 while (*s
&& !isalphaW( *s
)) s
++;
2595 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2596 time
->wDayOfWeek
= 7;
2598 for (i
= 0; i
< 7; i
++)
2600 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2601 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2602 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2604 time
->wDayOfWeek
= i
;
2609 if (time
->wDayOfWeek
> 6) return TRUE
;
2610 while (*s
&& !isdigitW( *s
)) s
++;
2611 time
->wDay
= strtolW( s
, &end
, 10 );
2614 while (*s
&& !isalphaW( *s
)) s
++;
2615 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2618 for (i
= 0; i
< 12; i
++)
2620 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2621 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2622 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2624 time
->wMonth
= i
+ 1;
2628 if (time
->wMonth
== 0) return TRUE
;
2630 while (*s
&& !isdigitW( *s
)) s
++;
2631 if (*s
== '\0') return TRUE
;
2632 time
->wYear
= strtolW( s
, &end
, 10 );
2635 while (*s
&& !isdigitW( *s
)) s
++;
2636 if (*s
== '\0') return TRUE
;
2637 time
->wHour
= strtolW( s
, &end
, 10 );
2640 while (*s
&& !isdigitW( *s
)) s
++;
2641 if (*s
== '\0') return TRUE
;
2642 time
->wMinute
= strtolW( s
, &end
, 10 );
2645 while (*s
&& !isdigitW( *s
)) s
++;
2646 if (*s
== '\0') return TRUE
;
2647 time
->wSecond
= strtolW( s
, &end
, 10 );
2650 time
->wMilliseconds
= 0;
2654 /***********************************************************************
2655 * InternetCheckConnectionW (WININET.@)
2657 * Pings a requested host to check internet connection
2660 * TRUE on success and FALSE on failure. If a failure then
2661 * ERROR_NOT_CONNECTED is placed into GetLastError
2664 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2667 * this is a kludge which runs the resident ping program and reads the output.
2669 * Anyone have a better idea?
2673 static const CHAR ping
[] = "ping -c 1 ";
2674 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2675 CHAR
*command
= NULL
;
2684 * Crack or set the Address
2686 if (lpszUrl
== NULL
)
2689 * According to the doc we are supposed to use the ip for the next
2690 * server in the WnInet internal server database. I have
2691 * no idea what that is or how to get it.
2693 * So someone needs to implement this.
2695 FIXME("Unimplemented with URL of NULL\n");
2700 URL_COMPONENTSW components
;
2702 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2703 components
.lpszHostName
= (LPWSTR
)hostW
;
2704 components
.dwHostNameLength
= 1024;
2706 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2709 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2710 port
= components
.nPort
;
2711 TRACE("port: %d\n", port
);
2714 if (dwFlags
& FLAG_ICC_FORCE_CONNECTION
)
2716 struct sockaddr_in sin
;
2719 if (!GetAddress(hostW
, port
, &sin
))
2721 fd
= socket(sin
.sin_family
, SOCK_STREAM
, 0);
2724 if (connect(fd
, (struct sockaddr
*)&sin
, sizeof(sin
)) == 0)
2732 * Build our ping command
2734 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2735 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2736 strcpy(command
,ping
);
2737 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2738 strcat(command
,redirect
);
2740 TRACE("Ping command is : %s\n",command
);
2742 status
= system(command
);
2744 TRACE("Ping returned a code of %i\n",status
);
2746 /* Ping return code of 0 indicates success */
2753 HeapFree( GetProcessHeap(), 0, command
);
2755 INTERNET_SetLastError(ERROR_NOT_CONNECTED
);
2761 /***********************************************************************
2762 * InternetCheckConnectionA (WININET.@)
2764 * Pings a requested host to check internet connection
2767 * TRUE on success and FALSE on failure. If a failure then
2768 * ERROR_NOT_CONNECTED is placed into GetLastError
2771 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2777 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2778 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2780 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2781 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2782 HeapFree(GetProcessHeap(), 0, szUrl
);
2788 /**********************************************************
2789 * INTERNET_InternetOpenUrlW (internal)
2794 * handle of connection or NULL on failure
2796 static HINTERNET
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2797 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2799 URL_COMPONENTSW urlComponents
;
2800 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2801 WCHAR password
[1024], path
[2048], extra
[1024];
2802 HINTERNET client
= NULL
, client1
= NULL
;
2804 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2805 dwHeadersLength
, dwFlags
, dwContext
);
2807 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2808 urlComponents
.lpszScheme
= protocol
;
2809 urlComponents
.dwSchemeLength
= 32;
2810 urlComponents
.lpszHostName
= hostName
;
2811 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2812 urlComponents
.lpszUserName
= userName
;
2813 urlComponents
.dwUserNameLength
= 1024;
2814 urlComponents
.lpszPassword
= password
;
2815 urlComponents
.dwPasswordLength
= 1024;
2816 urlComponents
.lpszUrlPath
= path
;
2817 urlComponents
.dwUrlPathLength
= 2048;
2818 urlComponents
.lpszExtraInfo
= extra
;
2819 urlComponents
.dwExtraInfoLength
= 1024;
2820 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2822 switch(urlComponents
.nScheme
) {
2823 case INTERNET_SCHEME_FTP
:
2824 if(urlComponents
.nPort
== 0)
2825 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2826 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2827 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2830 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2831 if(client1
== NULL
) {
2832 InternetCloseHandle(client
);
2837 case INTERNET_SCHEME_HTTP
:
2838 case INTERNET_SCHEME_HTTPS
: {
2839 static const WCHAR szStars
[] = { '*','/','*', 0 };
2840 LPCWSTR accept
[2] = { szStars
, NULL
};
2841 if(urlComponents
.nPort
== 0) {
2842 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2843 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2845 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2847 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2848 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2849 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2853 if (urlComponents
.dwExtraInfoLength
) {
2855 DWORD len
= urlComponents
.dwUrlPathLength
+ urlComponents
.dwExtraInfoLength
+ 1;
2857 if (!(path_extra
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
))))
2859 InternetCloseHandle(client
);
2862 strcpyW(path_extra
, urlComponents
.lpszUrlPath
);
2863 strcatW(path_extra
, urlComponents
.lpszExtraInfo
);
2864 client1
= HttpOpenRequestW(client
, NULL
, path_extra
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2865 HeapFree(GetProcessHeap(), 0, path_extra
);
2868 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2870 if(client1
== NULL
) {
2871 InternetCloseHandle(client
);
2874 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2875 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0) &&
2876 GetLastError() != ERROR_IO_PENDING
) {
2877 InternetCloseHandle(client1
);
2882 case INTERNET_SCHEME_GOPHER
:
2883 /* gopher doesn't seem to be implemented in wine, but it's supposed
2884 * to be supported by InternetOpenUrlA. */
2886 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME
);
2890 TRACE(" %p <--\n", client1
);
2895 /**********************************************************
2896 * InternetOpenUrlW (WININET.@)
2901 * handle of connection or NULL on failure
2903 static void AsyncInternetOpenUrlProc(WORKREQUEST
*workRequest
)
2905 struct WORKREQ_INTERNETOPENURLW
const *req
= &workRequest
->u
.InternetOpenUrlW
;
2906 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
->hdr
;
2910 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
2911 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
2912 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
2913 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
2916 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
2917 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2919 HINTERNET ret
= NULL
;
2920 LPWININETAPPINFOW hIC
= NULL
;
2922 if (TRACE_ON(wininet
)) {
2923 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2924 dwHeadersLength
, dwFlags
, dwContext
);
2926 dump_INTERNET_FLAGS(dwFlags
);
2931 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2935 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
2936 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
2937 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2941 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
2942 WORKREQUEST workRequest
;
2943 struct WORKREQ_INTERNETOPENURLW
*req
;
2945 workRequest
.asyncproc
= AsyncInternetOpenUrlProc
;
2946 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
2947 req
= &workRequest
.u
.InternetOpenUrlW
;
2948 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
2950 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
2952 req
->lpszHeaders
= 0;
2953 req
->dwHeadersLength
= dwHeadersLength
;
2954 req
->dwFlags
= dwFlags
;
2955 req
->dwContext
= dwContext
;
2957 INTERNET_AsyncCall(&workRequest
);
2959 * This is from windows.
2961 INTERNET_SetLastError(ERROR_IO_PENDING
);
2963 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
2968 WININET_Release( &hIC
->hdr
);
2969 TRACE(" %p <--\n", ret
);
2974 /**********************************************************
2975 * InternetOpenUrlA (WININET.@)
2980 * handle of connection or NULL on failure
2982 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
2983 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD_PTR dwContext
)
2985 HINTERNET rc
= NULL
;
2989 LPWSTR szUrl
= NULL
;
2990 LPWSTR szHeaders
= NULL
;
2995 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
2996 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
2999 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
3003 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
3004 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
3006 HeapFree(GetProcessHeap(), 0, szUrl
);
3009 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
3012 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
3013 lenHeaders
, dwFlags
, dwContext
);
3015 HeapFree(GetProcessHeap(), 0, szUrl
);
3016 HeapFree(GetProcessHeap(), 0, szHeaders
);
3022 static LPWITHREADERROR
INTERNET_AllocThreadError(void)
3024 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite
));
3028 lpwite
->dwError
= 0;
3029 lpwite
->response
[0] = '\0';
3032 if (!TlsSetValue(g_dwTlsErrIndex
, lpwite
))
3034 HeapFree(GetProcessHeap(), 0, lpwite
);
3042 /***********************************************************************
3043 * INTERNET_SetLastError (internal)
3045 * Set last thread specific error
3050 void INTERNET_SetLastError(DWORD dwError
)
3052 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3055 lpwite
= INTERNET_AllocThreadError();
3057 SetLastError(dwError
);
3059 lpwite
->dwError
= dwError
;
3063 /***********************************************************************
3064 * INTERNET_GetLastError (internal)
3066 * Get last thread specific error
3071 DWORD
INTERNET_GetLastError(void)
3073 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3074 if (!lpwite
) return 0;
3075 /* TlsGetValue clears last error, so set it again here */
3076 SetLastError(lpwite
->dwError
);
3077 return lpwite
->dwError
;
3081 /***********************************************************************
3082 * INTERNET_WorkerThreadFunc (internal)
3084 * Worker thread execution function
3089 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3091 LPWORKREQUEST lpRequest
= lpvParam
;
3092 WORKREQUEST workRequest
;
3096 workRequest
= *lpRequest
;
3097 HeapFree(GetProcessHeap(), 0, lpRequest
);
3099 workRequest
.asyncproc(&workRequest
);
3101 WININET_Release( workRequest
.hdr
);
3106 /***********************************************************************
3107 * INTERNET_AsyncCall (internal)
3109 * Retrieves work request from queue
3114 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3117 LPWORKREQUEST lpNewRequest
;
3121 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3125 *lpNewRequest
= *lpWorkRequest
;
3127 bSuccess
= QueueUserWorkItem(INTERNET_WorkerThreadFunc
, lpNewRequest
, WT_EXECUTELONGFUNCTION
);
3130 HeapFree(GetProcessHeap(), 0, lpNewRequest
);
3131 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3138 /***********************************************************************
3139 * INTERNET_GetResponseBuffer (internal)
3144 LPSTR
INTERNET_GetResponseBuffer(void)
3146 LPWITHREADERROR lpwite
= TlsGetValue(g_dwTlsErrIndex
);
3148 lpwite
= INTERNET_AllocThreadError();
3150 return lpwite
->response
;
3153 /***********************************************************************
3154 * INTERNET_GetNextLine (internal)
3156 * Parse next line in directory string listing
3159 * Pointer to beginning of next line
3164 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3167 BOOL bSuccess
= FALSE
;
3169 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3174 pfd
.events
= POLLIN
;
3176 while (nRecv
< MAX_REPLY_LEN
)
3178 if (poll(&pfd
,1, RESPONSE_TIMEOUT
* 1000) > 0)
3180 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3182 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3186 if (lpszBuffer
[nRecv
] == '\n')
3191 if (lpszBuffer
[nRecv
] != '\r')
3196 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3204 lpszBuffer
[nRecv
] = '\0';
3206 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3215 /**********************************************************
3216 * InternetQueryDataAvailable (WININET.@)
3218 * Determines how much data is available to be read.
3221 * TRUE on success, FALSE if an error occurred. If
3222 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3223 * no data is presently available, FALSE is returned with
3224 * the last error ERROR_IO_PENDING; a callback with status
3225 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3226 * data is available.
3228 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3229 LPDWORD lpdwNumberOfBytesAvailble
,
3230 DWORD dwFlags
, DWORD_PTR dwContext
)
3232 WININETHANDLEHEADER
*hdr
;
3235 TRACE("(%p %p %x %lx)\n", hFile
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3237 hdr
= WININET_GetObject( hFile
);
3239 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
3243 if(hdr
->vtbl
->QueryDataAvailable
) {
3244 res
= hdr
->vtbl
->QueryDataAvailable(hdr
, lpdwNumberOfBytesAvailble
, dwFlags
, dwContext
);
3246 WARN("wrong handle\n");
3247 res
= ERROR_INTERNET_INCORRECT_HANDLE_TYPE
;
3250 WININET_Release(hdr
);
3252 if(res
!= ERROR_SUCCESS
)
3254 return res
== ERROR_SUCCESS
;
3258 /***********************************************************************
3259 * InternetLockRequestFile (WININET.@)
3261 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3268 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3275 /***********************************************************************
3276 * InternetAutodial (WININET.@)
3278 * On windows this function is supposed to dial the default internet
3279 * connection. We don't want to have Wine dial out to the internet so
3280 * we return TRUE by default. It might be nice to check if we are connected.
3287 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3291 /* Tell that we are connected to the internet. */
3295 /***********************************************************************
3296 * InternetAutodialHangup (WININET.@)
3298 * Hangs up a connection made with InternetAutodial
3307 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3311 /* we didn't dial, we don't disconnect */
3315 /***********************************************************************
3316 * InternetCombineUrlA (WININET.@)
3318 * Combine a base URL with a relative URL
3326 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3327 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3332 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3334 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3335 dwFlags
^= ICU_NO_ENCODE
;
3336 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3341 /***********************************************************************
3342 * InternetCombineUrlW (WININET.@)
3344 * Combine a base URL with a relative URL
3352 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3353 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3358 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3360 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3361 dwFlags
^= ICU_NO_ENCODE
;
3362 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3367 /* max port num is 65535 => 5 digits */
3368 #define MAX_WORD_DIGITS 5
3370 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3371 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3372 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3373 (url)->dw##component##Length : strlen((url)->lpsz##component))
3375 static BOOL
url_uses_default_port(INTERNET_SCHEME nScheme
, INTERNET_PORT nPort
)
3377 if ((nScheme
== INTERNET_SCHEME_HTTP
) &&
3378 (nPort
== INTERNET_DEFAULT_HTTP_PORT
))
3380 if ((nScheme
== INTERNET_SCHEME_HTTPS
) &&
3381 (nPort
== INTERNET_DEFAULT_HTTPS_PORT
))
3383 if ((nScheme
== INTERNET_SCHEME_FTP
) &&
3384 (nPort
== INTERNET_DEFAULT_FTP_PORT
))
3386 if ((nScheme
== INTERNET_SCHEME_GOPHER
) &&
3387 (nPort
== INTERNET_DEFAULT_GOPHER_PORT
))
3390 if (nPort
== INTERNET_INVALID_PORT_NUMBER
)
3396 /* opaque urls do not fit into the standard url hierarchy and don't have
3397 * two following slashes */
3398 static inline BOOL
scheme_is_opaque(INTERNET_SCHEME nScheme
)
3400 return (nScheme
!= INTERNET_SCHEME_FTP
) &&
3401 (nScheme
!= INTERNET_SCHEME_GOPHER
) &&
3402 (nScheme
!= INTERNET_SCHEME_HTTP
) &&
3403 (nScheme
!= INTERNET_SCHEME_HTTPS
) &&
3404 (nScheme
!= INTERNET_SCHEME_FILE
);
3407 static LPCWSTR
INTERNET_GetSchemeString(INTERNET_SCHEME scheme
)
3410 if (scheme
< INTERNET_SCHEME_FIRST
)
3412 index
= scheme
- INTERNET_SCHEME_FIRST
;
3413 if (index
>= sizeof(url_schemes
)/sizeof(url_schemes
[0]))
3415 return (LPCWSTR
)url_schemes
[index
];
3418 /* we can calculate using ansi strings because we're just
3419 * calculating string length, not size
3421 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3422 LPDWORD lpdwUrlLength
)
3424 INTERNET_SCHEME nScheme
;
3428 if (lpUrlComponents
->lpszScheme
)
3430 DWORD dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3431 *lpdwUrlLength
+= dwLen
;
3432 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3438 nScheme
= lpUrlComponents
->nScheme
;
3440 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3441 nScheme
= INTERNET_SCHEME_HTTP
;
3442 scheme
= INTERNET_GetSchemeString(nScheme
);
3443 *lpdwUrlLength
+= strlenW(scheme
);
3446 (*lpdwUrlLength
)++; /* ':' */
3447 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3448 *lpdwUrlLength
+= strlen("//");
3450 if (lpUrlComponents
->lpszUserName
)
3452 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3453 *lpdwUrlLength
+= strlen("@");
3457 if (lpUrlComponents
->lpszPassword
)
3459 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3464 if (lpUrlComponents
->lpszPassword
)
3466 *lpdwUrlLength
+= strlen(":");
3467 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3470 if (lpUrlComponents
->lpszHostName
)
3472 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3474 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3476 char szPort
[MAX_WORD_DIGITS
+1];
3478 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3479 *lpdwUrlLength
+= strlen(szPort
);
3480 *lpdwUrlLength
+= strlen(":");
3483 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3484 (*lpdwUrlLength
)++; /* '/' */
3487 if (lpUrlComponents
->lpszUrlPath
)
3488 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3490 if (lpUrlComponents
->lpszExtraInfo
)
3491 *lpdwUrlLength
+= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
3496 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3500 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3502 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3503 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3504 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3505 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3506 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3507 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3508 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3509 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3510 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3512 if (lpUrlComponents
->lpszScheme
)
3514 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Scheme
) + 1;
3515 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3516 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3517 -1, urlCompW
->lpszScheme
, len
);
3520 if (lpUrlComponents
->lpszHostName
)
3522 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, HostName
) + 1;
3523 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3524 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3525 -1, urlCompW
->lpszHostName
, len
);
3528 if (lpUrlComponents
->lpszUserName
)
3530 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UserName
) + 1;
3531 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3532 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3533 -1, urlCompW
->lpszUserName
, len
);
3536 if (lpUrlComponents
->lpszPassword
)
3538 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, Password
) + 1;
3539 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3540 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3541 -1, urlCompW
->lpszPassword
, len
);
3544 if (lpUrlComponents
->lpszUrlPath
)
3546 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, UrlPath
) + 1;
3547 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3548 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3549 -1, urlCompW
->lpszUrlPath
, len
);
3552 if (lpUrlComponents
->lpszExtraInfo
)
3554 len
= URL_GET_COMP_LENGTHA(lpUrlComponents
, ExtraInfo
) + 1;
3555 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3556 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3557 -1, urlCompW
->lpszExtraInfo
, len
);
3561 /***********************************************************************
3562 * InternetCreateUrlA (WININET.@)
3564 * See InternetCreateUrlW.
3566 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3567 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3571 URL_COMPONENTSW urlCompW
;
3573 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3575 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3577 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3581 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3584 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3586 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3588 if (!ret
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
))
3589 *lpdwUrlLength
/= sizeof(WCHAR
);
3591 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3592 * minus one, so add one to leave room for NULL terminator
3595 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3597 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3598 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3599 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3600 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3601 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3602 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3603 HeapFree(GetProcessHeap(), 0, urlW
);
3608 /***********************************************************************
3609 * InternetCreateUrlW (WININET.@)
3611 * Creates a URL from its component parts.
3614 * lpUrlComponents [I] URL Components.
3615 * dwFlags [I] Flags. See notes.
3616 * lpszUrl [I] Buffer in which to store the created URL.
3617 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3618 * lpszUrl in characters. On output, the number of bytes
3619 * required to store the URL including terminator.
3623 * The dwFlags parameter can be zero or more of the following:
3624 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3631 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3632 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3635 INTERNET_SCHEME nScheme
;
3637 static const WCHAR slashSlashW
[] = {'/','/'};
3638 static const WCHAR percentD
[] = {'%','d',0};
3640 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents
, dwFlags
, lpszUrl
, lpdwUrlLength
);
3642 if (!lpUrlComponents
|| lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3644 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
3648 if (!calc_url_length(lpUrlComponents
, &dwLen
))
3651 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3653 *lpdwUrlLength
= (dwLen
+ 1) * sizeof(WCHAR
);
3654 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3658 *lpdwUrlLength
= dwLen
;
3663 if (lpUrlComponents
->lpszScheme
)
3665 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Scheme
);
3666 memcpy(lpszUrl
, lpUrlComponents
->lpszScheme
, dwLen
* sizeof(WCHAR
));
3669 nScheme
= GetInternetSchemeW(lpUrlComponents
->lpszScheme
, dwLen
);
3674 nScheme
= lpUrlComponents
->nScheme
;
3676 if (nScheme
== INTERNET_SCHEME_DEFAULT
)
3677 nScheme
= INTERNET_SCHEME_HTTP
;
3679 scheme
= INTERNET_GetSchemeString(nScheme
);
3680 dwLen
= strlenW(scheme
);
3681 memcpy(lpszUrl
, scheme
, dwLen
* sizeof(WCHAR
));
3685 /* all schemes are followed by at least a colon */
3689 if (!scheme_is_opaque(nScheme
) || lpUrlComponents
->lpszHostName
)
3691 memcpy(lpszUrl
, slashSlashW
, sizeof(slashSlashW
));
3692 lpszUrl
+= sizeof(slashSlashW
)/sizeof(slashSlashW
[0]);
3695 if (lpUrlComponents
->lpszUserName
)
3697 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UserName
);
3698 memcpy(lpszUrl
, lpUrlComponents
->lpszUserName
, dwLen
* sizeof(WCHAR
));
3701 if (lpUrlComponents
->lpszPassword
)
3706 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, Password
);
3707 memcpy(lpszUrl
, lpUrlComponents
->lpszPassword
, dwLen
* sizeof(WCHAR
));
3715 if (lpUrlComponents
->lpszHostName
)
3717 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, HostName
);
3718 memcpy(lpszUrl
, lpUrlComponents
->lpszHostName
, dwLen
* sizeof(WCHAR
));
3721 if (!url_uses_default_port(nScheme
, lpUrlComponents
->nPort
))
3723 WCHAR szPort
[MAX_WORD_DIGITS
+1];
3725 sprintfW(szPort
, percentD
, lpUrlComponents
->nPort
);
3728 dwLen
= strlenW(szPort
);
3729 memcpy(lpszUrl
, szPort
, dwLen
* sizeof(WCHAR
));
3733 /* add slash between hostname and path if necessary */
3734 if (lpUrlComponents
->lpszUrlPath
&& *lpUrlComponents
->lpszUrlPath
!= '/')
3741 if (lpUrlComponents
->lpszUrlPath
)
3743 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, UrlPath
);
3744 memcpy(lpszUrl
, lpUrlComponents
->lpszUrlPath
, dwLen
* sizeof(WCHAR
));
3748 if (lpUrlComponents
->lpszExtraInfo
)
3750 dwLen
= URL_GET_COMP_LENGTH(lpUrlComponents
, ExtraInfo
);
3751 memcpy(lpszUrl
, lpUrlComponents
->lpszExtraInfo
, dwLen
* sizeof(WCHAR
));
3760 /***********************************************************************
3761 * InternetConfirmZoneCrossingA (WININET.@)
3764 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
3766 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
3767 return ERROR_SUCCESS
;
3770 /***********************************************************************
3771 * InternetConfirmZoneCrossingW (WININET.@)
3774 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
3776 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
3777 return ERROR_SUCCESS
;
3780 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
3781 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3783 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3784 lpdwConnection
, dwReserved
);
3785 return ERROR_SUCCESS
;
3788 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
3789 DWORD_PTR
* lpdwConnection
, DWORD dwReserved
)
3791 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3792 lpdwConnection
, dwReserved
);
3793 return ERROR_SUCCESS
;
3796 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3798 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
3802 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3804 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
3808 DWORD WINAPI
InternetHangUp( DWORD_PTR dwConnection
, DWORD dwReserved
)
3810 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection
, dwReserved
);
3811 return ERROR_SUCCESS
;
3814 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
3817 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
3818 debugstr_w(pwszTarget
), pbHexHash
);
3822 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
3824 FIXME("(%p, 0x%08x) stub\n", hInternet
, dwError
);
3828 BOOL WINAPI
InternetQueryFortezzaStatus(DWORD
*a
, DWORD_PTR b
)
3830 FIXME("(%p, %08lx) stub\n", a
, b
);