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 */
34 #if defined(__MINGW32__) || defined (_MSC_VER)
41 #include <sys/types.h>
42 #ifdef HAVE_SYS_SOCKET_H
43 # include <sys/socket.h>
48 #ifdef HAVE_SYS_POLL_H
49 # include <sys/poll.h>
51 #ifdef HAVE_SYS_TIME_H
52 # include <sys/time.h>
68 #include "wine/debug.h"
70 #define NO_SHLWAPI_STREAM
73 #include "wine/exception.h"
78 #include "wine/unicode.h"
80 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
82 #define RESPONSE_TIMEOUT 30
87 CHAR response[MAX_REPLY_LEN];
88 } WITHREADERROR, *LPWITHREADERROR;
90 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
91 static HMODULE WININET_hModule;
93 #define HANDLE_CHUNK_SIZE 0x10
95 static CRITICAL_SECTION WININET_cs;
96 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
99 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
100 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
102 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
104 static LPWININETHANDLEHEADER *WININET_Handles;
105 static UINT WININET_dwNextHandle;
106 static UINT WININET_dwMaxHandles;
108 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
110 LPWININETHANDLEHEADER *p;
111 UINT handle = 0, num;
113 list_init( &info->children );
115 EnterCriticalSection( &WININET_cs );
116 if( !WININET_dwMaxHandles )
118 num = HANDLE_CHUNK_SIZE;
119 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
120 sizeof (*WININET_Handles)* num);
124 WININET_dwMaxHandles = num;
126 if( WININET_dwMaxHandles == WININET_dwNextHandle )
128 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
129 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
130 WININET_Handles, sizeof (*WININET_Handles)* num);
134 WININET_dwMaxHandles = num;
137 handle = WININET_dwNextHandle;
138 if( WININET_Handles[handle] )
139 ERR("handle isn't free but should be\n");
140 WININET_Handles[handle] = WININET_AddRef( info );
142 while( WININET_Handles[WININET_dwNextHandle] &&
143 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
144 WININET_dwNextHandle++;
147 LeaveCriticalSection( &WININET_cs );
149 return info->hInternet = (HINTERNET) (handle+1);
152 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
154 ULONG refs = InterlockedIncrement(&info->refs);
155 TRACE("%p -> refcount = %d\n", info, refs );
159 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
161 LPWININETHANDLEHEADER info = NULL;
162 UINT handle = (UINT) hinternet;
164 EnterCriticalSection( &WININET_cs );
166 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
167 WININET_Handles[handle-1] )
168 info = WININET_AddRef( WININET_Handles[handle-1] );
170 LeaveCriticalSection( &WININET_cs );
172 TRACE("handle %d -> %p\n", handle, info);
177 BOOL WININET_Release( LPWININETHANDLEHEADER info )
179 ULONG refs = InterlockedDecrement(&info->refs);
180 TRACE( "object %p refcount = %d\n", info, refs );
183 if ( info->vtbl->CloseConnection )
185 TRACE( "closing connection %p\n", info);
186 info->vtbl->CloseConnection( info );
188 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
189 if (info->htype != WH_HHTTPSESSION || !(info->dwInternalFlags & INET_OPENURL))
191 INTERNET_SendCallback(info, info->dwContext,
192 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
195 TRACE( "destroying object %p\n", info);
196 if ( info->htype != WH_HINIT )
197 list_remove( &info->entry );
198 info->vtbl->Destroy( info );
203 BOOL WININET_FreeHandle( HINTERNET hinternet )
206 UINT handle = (UINT) hinternet;
207 LPWININETHANDLEHEADER info = NULL, child, next;
209 EnterCriticalSection( &WININET_cs );
211 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
214 if( WININET_Handles[handle] )
216 info = WININET_Handles[handle];
217 TRACE( "destroying handle %d for object %p\n", handle+1, info);
218 WININET_Handles[handle] = NULL;
223 LeaveCriticalSection( &WININET_cs );
225 /* As on native when the equivalent of WININET_Release is called, the handle
226 * is already invalid, but if a new handle is created at this time it does
227 * not yet get assigned the freed handle number */
230 /* Free all children as native does */
231 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, WININETHANDLEHEADER, entry )
233 TRACE( "freeing child handle %d for parent handle %d\n",
234 (UINT)child->hInternet, handle+1);
235 WININET_FreeHandle( child->hInternet );
237 WININET_Release( info );
240 EnterCriticalSection( &WININET_cs );
242 if( WININET_dwNextHandle > handle && !WININET_Handles[handle] )
243 WININET_dwNextHandle = handle;
245 LeaveCriticalSection( &WININET_cs );
250 /***********************************************************************
251 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
254 * hinstDLL [I] handle to the DLL's instance
256 * lpvReserved [I] reserved, must be NULL
263 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
265 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
268 case DLL_PROCESS_ATTACH:
270 g_dwTlsErrIndex = TlsAlloc();
272 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
275 URLCacheContainers_CreateDefaults();
277 WININET_hModule = hinstDLL;
279 case DLL_THREAD_ATTACH:
282 case DLL_THREAD_DETACH:
283 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
285 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
286 HeapFree(GetProcessHeap(), 0, lpwite);
290 case DLL_PROCESS_DETACH:
292 URLCacheContainers_DeleteAll();
294 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
296 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
297 TlsFree(g_dwTlsErrIndex);
306 /***********************************************************************
307 * InternetInitializeAutoProxyDll (WININET.@)
309 * Setup the internal proxy
318 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
321 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
325 /***********************************************************************
326 * DetectAutoProxyUrl (WININET.@)
328 * Auto detect the proxy url
334 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
335 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
338 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
343 /***********************************************************************
344 * INTERNET_ConfigureProxy
347 * The proxy may be specified in the form 'http=proxy.my.org'
348 * Presumably that means there can be ftp=ftpproxy.my.org too.
350 static BOOL INTERNET_ConfigureProxy( LPWININETAPPINFOW lpwai )
353 DWORD type, len, enabled = 0;
355 static const WCHAR szInternetSettings[] =
356 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
357 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
358 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
359 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
360 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
362 if (RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )) return FALSE;
364 len = sizeof enabled;
365 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&enabled, &len ) || type != REG_DWORD)
366 RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&enabled, sizeof(REG_DWORD) );
370 TRACE("Proxy is enabled.\n");
372 /* figure out how much memory the proxy setting takes */
373 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
376 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
378 if (!(szProxy = HeapAlloc( GetProcessHeap(), 0, len )))
383 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
385 /* find the http proxy, and strip away everything else */
386 p = strstrW( szProxy, szHttp );
389 p += lstrlenW( szHttp );
390 lstrcpyW( szProxy, p );
392 p = strchrW( szProxy, ' ' );
395 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
396 lpwai->lpszProxy = szProxy;
398 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
401 ERR("Couldn't read proxy server settings from registry.\n");
403 else if ((envproxy = getenv( "http_proxy" )))
407 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
408 if (!(envproxyW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR)))) return FALSE;
409 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
411 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
412 lpwai->lpszProxy = envproxyW;
414 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwai->lpszProxy));
419 TRACE("Proxy is not enabled.\n");
420 lpwai->dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
423 return (enabled > 0);
426 /***********************************************************************
427 * dump_INTERNET_FLAGS
429 * Helper function to TRACE the internet flags.
435 static void dump_INTERNET_FLAGS(DWORD dwFlags)
437 #define FE(x) { x, #x }
438 static const wininet_flag_info flag[] = {
439 FE(INTERNET_FLAG_RELOAD),
440 FE(INTERNET_FLAG_RAW_DATA),
441 FE(INTERNET_FLAG_EXISTING_CONNECT),
442 FE(INTERNET_FLAG_ASYNC),
443 FE(INTERNET_FLAG_PASSIVE),
444 FE(INTERNET_FLAG_NO_CACHE_WRITE),
445 FE(INTERNET_FLAG_MAKE_PERSISTENT),
446 FE(INTERNET_FLAG_FROM_CACHE),
447 FE(INTERNET_FLAG_SECURE),
448 FE(INTERNET_FLAG_KEEP_CONNECTION),
449 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
450 FE(INTERNET_FLAG_READ_PREFETCH),
451 FE(INTERNET_FLAG_NO_COOKIES),
452 FE(INTERNET_FLAG_NO_AUTH),
453 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
454 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
455 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
456 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
457 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
458 FE(INTERNET_FLAG_RESYNCHRONIZE),
459 FE(INTERNET_FLAG_HYPERLINK),
460 FE(INTERNET_FLAG_NO_UI),
461 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
462 FE(INTERNET_FLAG_CACHE_ASYNC),
463 FE(INTERNET_FLAG_FORMS_SUBMIT),
464 FE(INTERNET_FLAG_NEED_FILE),
465 FE(INTERNET_FLAG_TRANSFER_ASCII),
466 FE(INTERNET_FLAG_TRANSFER_BINARY)
471 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
472 if (flag[i].val & dwFlags) {
473 TRACE(" %s", flag[i].name);
474 dwFlags &= ~flag[i].val;
478 TRACE(" Unknown flags (%08x)\n", dwFlags);
483 /***********************************************************************
484 * INTERNET_CloseHandle (internal)
486 * Close internet handle
489 static VOID APPINFO_Destroy(WININETHANDLEHEADER *hdr)
491 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
495 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
496 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
497 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
498 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
499 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
500 HeapFree(GetProcessHeap(), 0, lpwai);
503 static DWORD APPINFO_QueryOption(WININETHANDLEHEADER *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
505 LPWININETAPPINFOW ai = (LPWININETAPPINFOW)hdr;
508 case INTERNET_OPTION_HANDLE_TYPE:
509 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
511 if (*size < sizeof(ULONG))
512 return ERROR_INSUFFICIENT_BUFFER;
514 *size = sizeof(DWORD);
515 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
516 return ERROR_SUCCESS;
518 case INTERNET_OPTION_USER_AGENT: {
521 TRACE("INTERNET_OPTION_USER_AGENT\n");
526 *size = (strlenW(ai->lpszAgent) + 1) * sizeof(WCHAR);
527 if(!buffer || bufsize < *size)
528 return ERROR_INSUFFICIENT_BUFFER;
530 strcpyW(buffer, ai->lpszAgent);
532 *size = WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, NULL, 0, NULL, NULL);
533 if(!buffer || bufsize < *size)
534 return ERROR_INSUFFICIENT_BUFFER;
536 WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, buffer, *size, NULL, NULL);
539 return ERROR_SUCCESS;
542 case INTERNET_OPTION_PROXY:
544 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
545 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
546 LPWSTR proxy, proxy_bypass;
549 proxyBytesRequired = (lstrlenW(ai->lpszProxy) + 1) * sizeof(WCHAR);
550 if (ai->lpszProxyBypass)
551 proxyBypassBytesRequired = (lstrlenW(ai->lpszProxyBypass) + 1) * sizeof(WCHAR);
552 if (*size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
554 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
555 return ERROR_INSUFFICIENT_BUFFER;
557 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
558 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
560 pi->dwAccessType = ai->dwAccessType;
561 pi->lpszProxy = NULL;
562 pi->lpszProxyBypass = NULL;
564 lstrcpyW(proxy, ai->lpszProxy);
565 pi->lpszProxy = proxy;
568 if (ai->lpszProxyBypass) {
569 lstrcpyW(proxy_bypass, ai->lpszProxyBypass);
570 pi->lpszProxyBypass = proxy_bypass;
573 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
574 return ERROR_SUCCESS;
576 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
577 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
578 LPSTR proxy, proxy_bypass;
581 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->lpszProxy, -1, NULL, 0, NULL, NULL);
582 if (ai->lpszProxyBypass)
583 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->lpszProxyBypass, -1,
584 NULL, 0, NULL, NULL);
585 if (*size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
587 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
588 return ERROR_INSUFFICIENT_BUFFER;
590 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
591 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
593 pi->dwAccessType = ai->dwAccessType;
594 pi->lpszProxy = NULL;
595 pi->lpszProxyBypass = NULL;
597 WideCharToMultiByte(CP_ACP, 0, ai->lpszProxy, -1, proxy, proxyBytesRequired, NULL, NULL);
598 pi->lpszProxy = proxy;
601 if (ai->lpszProxyBypass) {
602 WideCharToMultiByte(CP_ACP, 0, ai->lpszProxyBypass, -1, proxy_bypass,
603 proxyBypassBytesRequired, NULL, NULL);
604 pi->lpszProxyBypass = proxy_bypass;
607 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
608 return ERROR_SUCCESS;
612 return INET_QueryOption(option, buffer, size, unicode);
615 static const HANDLEHEADERVtbl APPINFOVtbl = {
628 /***********************************************************************
629 * InternetOpenW (WININET.@)
631 * Per-application initialization of wininet
634 * HINTERNET on success
638 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
639 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
641 LPWININETAPPINFOW lpwai = NULL;
642 HINTERNET handle = NULL;
644 if (TRACE_ON(wininet)) {
645 #define FE(x) { x, #x }
646 static const wininet_flag_info access_type[] = {
647 FE(INTERNET_OPEN_TYPE_PRECONFIG),
648 FE(INTERNET_OPEN_TYPE_DIRECT),
649 FE(INTERNET_OPEN_TYPE_PROXY),
650 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
654 const char *access_type_str = "Unknown";
656 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
657 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
658 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
659 if (access_type[i].val == dwAccessType) {
660 access_type_str = access_type[i].name;
664 TRACE(" access type : %s\n", access_type_str);
666 dump_INTERNET_FLAGS(dwFlags);
669 /* Clear any error information */
670 INTERNET_SetLastError(0);
672 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETAPPINFOW));
675 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
679 lpwai->hdr.htype = WH_HINIT;
680 lpwai->hdr.vtbl = &APPINFOVtbl;
681 lpwai->hdr.dwFlags = dwFlags;
683 lpwai->dwAccessType = dwAccessType;
684 lpwai->lpszProxyUsername = NULL;
685 lpwai->lpszProxyPassword = NULL;
687 handle = WININET_AllocHandle( &lpwai->hdr );
690 HeapFree( GetProcessHeap(), 0, lpwai );
691 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
695 if (NULL != lpszAgent)
697 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
698 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
699 if (lpwai->lpszAgent)
700 lstrcpyW( lpwai->lpszAgent, lpszAgent );
702 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
703 INTERNET_ConfigureProxy( lpwai );
704 else if (NULL != lpszProxy)
706 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
707 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
708 if (lpwai->lpszProxy)
709 lstrcpyW( lpwai->lpszProxy, lpszProxy );
712 if (NULL != lpszProxyBypass)
714 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
715 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
716 if (lpwai->lpszProxyBypass)
717 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
722 WININET_Release( &lpwai->hdr );
724 TRACE("returning %p\n", lpwai);
730 /***********************************************************************
731 * InternetOpenA (WININET.@)
733 * Per-application initialization of wininet
736 * HINTERNET on success
740 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
741 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
745 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
747 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
748 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
752 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
753 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
754 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
759 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
760 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
761 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
764 if( lpszProxyBypass )
766 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
767 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
768 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
771 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
773 HeapFree(GetProcessHeap(), 0, szAgent);
774 HeapFree(GetProcessHeap(), 0, szProxy);
775 HeapFree(GetProcessHeap(), 0, szBypass);
780 /***********************************************************************
781 * InternetGetLastResponseInfoA (WININET.@)
783 * Return last wininet error description on the calling thread
786 * TRUE on success of writing to buffer
790 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
791 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
793 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
799 *lpdwError = lpwite->dwError;
802 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
803 *lpdwBufferLength = strlen(lpszBuffer);
806 *lpdwBufferLength = 0;
811 *lpdwBufferLength = 0;
817 /***********************************************************************
818 * InternetGetLastResponseInfoW (WININET.@)
820 * Return last wininet error description on the calling thread
823 * TRUE on success of writing to buffer
827 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
828 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
830 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
836 *lpdwError = lpwite->dwError;
839 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
840 *lpdwBufferLength = lstrlenW(lpszBuffer);
843 *lpdwBufferLength = 0;
848 *lpdwBufferLength = 0;
854 /***********************************************************************
855 * InternetGetConnectedState (WININET.@)
857 * Return connected state
861 * if lpdwStatus is not null, return the status (off line,
862 * modem, lan...) in it.
863 * FALSE if not connected
865 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
867 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
870 WARN("always returning LAN connection.\n");
871 *lpdwStatus = INTERNET_CONNECTION_LAN;
877 /***********************************************************************
878 * InternetGetConnectedStateExW (WININET.@)
880 * Return connected state
884 * lpdwStatus [O] Flags specifying the status of the internet connection.
885 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
886 * dwNameLen [I] Size of the buffer, in characters.
887 * dwReserved [I] Reserved. Must be set to 0.
891 * if lpdwStatus is not null, return the status (off line,
892 * modem, lan...) in it.
893 * FALSE if not connected
896 * If the system has no available network connections, an empty string is
897 * stored in lpszConnectionName. If there is a LAN connection, a localized
898 * "LAN Connection" string is stored. Presumably, if only a dial-up
899 * connection is available then the name of the dial-up connection is
900 * returned. Why any application, other than the "Internet Settings" CPL,
901 * would want to use this function instead of the simpler InternetGetConnectedStateW
902 * function is beyond me.
904 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
905 DWORD dwNameLen, DWORD dwReserved)
907 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
914 WARN("always returning LAN connection.\n");
915 *lpdwStatus = INTERNET_CONNECTION_LAN;
917 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
921 /***********************************************************************
922 * InternetGetConnectedStateExA (WININET.@)
924 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
925 DWORD dwNameLen, DWORD dwReserved)
927 LPWSTR lpwszConnectionName = NULL;
930 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
932 if (lpszConnectionName && dwNameLen > 0)
933 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
935 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
937 if (rc && lpwszConnectionName)
939 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
940 dwNameLen, NULL, NULL);
942 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
949 /***********************************************************************
950 * InternetConnectW (WININET.@)
952 * Open a ftp, gopher or http session
955 * HINTERNET a session handle on success
959 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
960 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
961 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
962 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
964 LPWININETAPPINFOW hIC;
967 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
968 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
969 dwService, dwFlags, dwContext);
973 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
977 /* Clear any error information */
978 INTERNET_SetLastError(0);
979 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
980 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
982 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
988 case INTERNET_SERVICE_FTP:
989 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
990 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
993 case INTERNET_SERVICE_HTTP:
994 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
995 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
998 case INTERNET_SERVICE_GOPHER:
1004 WININET_Release( &hIC->hdr );
1006 TRACE("returning %p\n", rc);
1011 /***********************************************************************
1012 * InternetConnectA (WININET.@)
1014 * Open a ftp, gopher or http session
1017 * HINTERNET a session handle on success
1021 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1022 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1023 LPCSTR lpszUserName, LPCSTR lpszPassword,
1024 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1026 HINTERNET rc = NULL;
1028 LPWSTR szServerName = NULL;
1029 LPWSTR szUserName = NULL;
1030 LPWSTR szPassword = NULL;
1034 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
1035 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1036 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
1040 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
1041 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1042 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
1046 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
1047 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1048 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
1052 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1053 szUserName, szPassword, dwService, dwFlags, dwContext);
1055 HeapFree(GetProcessHeap(), 0, szServerName);
1056 HeapFree(GetProcessHeap(), 0, szUserName);
1057 HeapFree(GetProcessHeap(), 0, szPassword);
1062 /***********************************************************************
1063 * InternetFindNextFileA (WININET.@)
1065 * Continues a file search from a previous call to FindFirstFile
1072 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1075 WIN32_FIND_DATAW fd;
1077 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1079 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1083 /***********************************************************************
1084 * InternetFindNextFileW (WININET.@)
1086 * Continues a file search from a previous call to FindFirstFile
1093 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1095 WININETHANDLEHEADER *hdr;
1100 hdr = WININET_GetObject(hFind);
1102 WARN("Invalid handle\n");
1103 SetLastError(ERROR_INVALID_HANDLE);
1107 if(hdr->vtbl->FindNextFileW) {
1108 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1110 WARN("Handle doesn't support NextFile\n");
1111 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1114 WININET_Release(hdr);
1116 if(res != ERROR_SUCCESS)
1118 return res == ERROR_SUCCESS;
1121 /***********************************************************************
1122 * InternetCloseHandle (WININET.@)
1124 * Generic close handle function
1131 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1133 LPWININETHANDLEHEADER lpwh;
1135 TRACE("%p\n",hInternet);
1137 lpwh = WININET_GetObject( hInternet );
1140 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1144 WININET_Release( lpwh );
1145 WININET_FreeHandle( hInternet );
1151 /***********************************************************************
1152 * ConvertUrlComponentValue (Internal)
1154 * Helper function for InternetCrackUrlA
1157 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1158 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1159 LPCSTR lpszStart, LPCWSTR lpwszStart)
1161 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1162 if (*dwComponentLen != 0)
1164 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1165 if (*lppszComponent == NULL)
1167 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1169 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1171 *lppszComponent = NULL;
1172 *dwComponentLen = nASCIILength;
1176 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1177 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1178 (*lppszComponent)[ncpylen]=0;
1179 *dwComponentLen = ncpylen;
1185 /***********************************************************************
1186 * InternetCrackUrlA (WININET.@)
1188 * See InternetCrackUrlW.
1190 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1191 LPURL_COMPONENTSA lpUrlComponents)
1194 URL_COMPONENTSW UCW;
1196 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1197 *scheme = NULL, *extra = NULL;
1199 TRACE("(%s %u %x %p)\n",
1200 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1201 dwUrlLength, dwFlags, lpUrlComponents);
1203 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1204 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1206 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1212 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1214 /* if dwUrlLength=-1 then nLength includes null but length to
1215 InternetCrackUrlW should not include it */
1216 if (dwUrlLength == -1) nLength--;
1218 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1219 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1221 memset(&UCW,0,sizeof(UCW));
1222 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1223 if (lpUrlComponents->dwHostNameLength)
1225 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1226 if (lpUrlComponents->lpszHostName)
1228 hostname = HeapAlloc(GetProcessHeap(), 0, UCW.dwHostNameLength * sizeof(WCHAR));
1229 UCW.lpszHostName = hostname;
1232 if (lpUrlComponents->dwUserNameLength)
1234 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1235 if (lpUrlComponents->lpszUserName)
1237 username = HeapAlloc(GetProcessHeap(), 0, UCW.dwUserNameLength * sizeof(WCHAR));
1238 UCW.lpszUserName = username;
1241 if (lpUrlComponents->dwPasswordLength)
1243 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1244 if (lpUrlComponents->lpszPassword)
1246 password = HeapAlloc(GetProcessHeap(), 0, UCW.dwPasswordLength * sizeof(WCHAR));
1247 UCW.lpszPassword = password;
1250 if (lpUrlComponents->dwUrlPathLength)
1252 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1253 if (lpUrlComponents->lpszUrlPath)
1255 path = HeapAlloc(GetProcessHeap(), 0, UCW.dwUrlPathLength * sizeof(WCHAR));
1256 UCW.lpszUrlPath = path;
1259 if (lpUrlComponents->dwSchemeLength)
1261 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1262 if (lpUrlComponents->lpszScheme)
1264 scheme = HeapAlloc(GetProcessHeap(), 0, UCW.dwSchemeLength * sizeof(WCHAR));
1265 UCW.lpszScheme = scheme;
1268 if (lpUrlComponents->dwExtraInfoLength)
1270 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1271 if (lpUrlComponents->lpszExtraInfo)
1273 extra = HeapAlloc(GetProcessHeap(), 0, UCW.dwExtraInfoLength * sizeof(WCHAR));
1274 UCW.lpszExtraInfo = extra;
1277 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1279 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1280 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1281 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1282 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1283 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1284 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1285 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1286 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1287 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1288 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1289 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1290 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1292 lpUrlComponents->nScheme = UCW.nScheme;
1293 lpUrlComponents->nPort = UCW.nPort;
1295 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1296 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1297 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1298 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1299 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1301 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1302 HeapFree(GetProcessHeap(), 0, hostname);
1303 HeapFree(GetProcessHeap(), 0, username);
1304 HeapFree(GetProcessHeap(), 0, password);
1305 HeapFree(GetProcessHeap(), 0, path);
1306 HeapFree(GetProcessHeap(), 0, scheme);
1307 HeapFree(GetProcessHeap(), 0, extra);
1311 static const WCHAR url_schemes[][7] =
1314 {'g','o','p','h','e','r',0},
1315 {'h','t','t','p',0},
1316 {'h','t','t','p','s',0},
1317 {'f','i','l','e',0},
1318 {'n','e','w','s',0},
1319 {'m','a','i','l','t','o',0},
1323 /***********************************************************************
1324 * GetInternetSchemeW (internal)
1330 * INTERNET_SCHEME_UNKNOWN on failure
1333 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1337 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1339 if(lpszScheme==NULL)
1340 return INTERNET_SCHEME_UNKNOWN;
1342 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1343 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1344 return INTERNET_SCHEME_FIRST + i;
1346 return INTERNET_SCHEME_UNKNOWN;
1349 /***********************************************************************
1350 * SetUrlComponentValueW (Internal)
1352 * Helper function for InternetCrackUrlW
1355 * lppszComponent [O] Holds the returned string
1356 * dwComponentLen [I] Holds the size of lppszComponent
1357 * [O] Holds the length of the string in lppszComponent without '\0'
1358 * lpszStart [I] Holds the string to copy from
1359 * len [I] Holds the length of lpszStart without '\0'
1366 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1368 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1370 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1373 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1375 if (*lppszComponent == NULL)
1377 *lppszComponent = (LPWSTR)lpszStart;
1378 *dwComponentLen = len;
1382 DWORD ncpylen = min((*dwComponentLen)-1, len);
1383 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1384 (*lppszComponent)[ncpylen] = '\0';
1385 *dwComponentLen = ncpylen;
1392 /***********************************************************************
1393 * InternetCrackUrlW (WININET.@)
1395 * Break up URL into its components
1401 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1402 LPURL_COMPONENTSW lpUC)
1406 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1409 LPCWSTR lpszParam = NULL;
1410 BOOL bIsAbsolute = FALSE;
1411 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1412 LPCWSTR lpszcp = NULL;
1413 LPWSTR lpszUrl_decode = NULL;
1414 DWORD dwUrlLength = dwUrlLength_orig;
1416 TRACE("(%s %u %x %p)\n",
1417 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1418 dwUrlLength, dwFlags, lpUC);
1420 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1422 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1425 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1427 if (dwFlags & ICU_DECODE)
1430 DWORD len = dwUrlLength + 1;
1432 if (!(url_tmp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1434 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1437 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1438 url_tmp[dwUrlLength] = 0;
1439 if (!(lpszUrl_decode = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1441 HeapFree(GetProcessHeap(), 0, url_tmp);
1442 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1445 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1448 lpszUrl = lpszUrl_decode;
1450 HeapFree(GetProcessHeap(), 0, url_tmp);
1454 /* Determine if the URI is absolute. */
1455 while (lpszap - lpszUrl < dwUrlLength)
1457 if (isalnumW(*lpszap))
1462 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1469 lpszcp = lpszUrl; /* Relative url */
1475 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1476 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1478 /* Parse <params> */
1479 if (!(lpszParam = memchrW(lpszap, ';', dwUrlLength - (lpszap - lpszUrl))))
1480 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1482 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1483 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1485 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1489 /* Get scheme first. */
1490 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1491 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1492 lpszUrl, lpszcp - lpszUrl);
1494 /* Eat ':' in protocol. */
1497 /* double slash indicates the net_loc portion is present */
1498 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1502 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1506 lpszNetLoc = min(lpszNetLoc, lpszParam);
1508 lpszNetLoc = lpszParam;
1510 else if (!lpszNetLoc)
1511 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1519 /* [<user>[<:password>]@]<host>[:<port>] */
1520 /* First find the user and password if they exist */
1522 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1523 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1525 /* username and password not specified. */
1526 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1527 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1529 else /* Parse out username and password */
1531 LPCWSTR lpszUser = lpszcp;
1532 LPCWSTR lpszPasswd = lpszHost;
1534 while (lpszcp < lpszHost)
1537 lpszPasswd = lpszcp;
1542 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1543 lpszUser, lpszPasswd - lpszUser);
1545 if (lpszPasswd != lpszHost)
1547 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1548 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1549 lpszHost - lpszPasswd);
1551 lpszcp++; /* Advance to beginning of host */
1554 /* Parse <host><:port> */
1557 lpszPort = lpszNetLoc;
1559 /* special case for res:// URLs: there is no port here, so the host is the
1560 entire string up to the first '/' */
1561 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1563 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1564 lpszHost, lpszPort - lpszHost);
1569 while (lpszcp < lpszNetLoc)
1577 /* If the scheme is "file" and the host is just one letter, it's not a host */
1578 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1581 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1586 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1587 lpszHost, lpszPort - lpszHost);
1588 if (lpszPort != lpszNetLoc)
1589 lpUC->nPort = atoiW(++lpszPort);
1590 else switch (lpUC->nScheme)
1592 case INTERNET_SCHEME_HTTP:
1593 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1595 case INTERNET_SCHEME_HTTPS:
1596 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1598 case INTERNET_SCHEME_FTP:
1599 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1601 case INTERNET_SCHEME_GOPHER:
1602 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1613 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1614 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1615 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1620 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1621 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1622 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1623 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1626 /* Here lpszcp points to:
1628 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1629 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1631 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp < lpszParam))
1635 /* Only truncate the parameter list if it's already been saved
1636 * in lpUC->lpszExtraInfo.
1638 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1639 len = lpszParam - lpszcp;
1642 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1643 * newlines if necessary.
1645 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1646 if (lpsznewline != NULL)
1647 len = lpsznewline - lpszcp;
1649 len = dwUrlLength-(lpszcp-lpszUrl);
1651 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1656 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
1657 lpUC->lpszUrlPath[0] = 0;
1658 lpUC->dwUrlPathLength = 0;
1661 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1662 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1663 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1664 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1665 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1667 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1671 /***********************************************************************
1672 * InternetAttemptConnect (WININET.@)
1674 * Attempt to make a connection to the internet
1677 * ERROR_SUCCESS on success
1678 * Error value on failure
1681 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1684 return ERROR_SUCCESS;
1688 /***********************************************************************
1689 * InternetCanonicalizeUrlA (WININET.@)
1691 * Escape unsafe characters and spaces
1698 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1699 LPDWORD lpdwBufferLength, DWORD dwFlags)
1702 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1704 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1705 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1707 if(dwFlags & ICU_DECODE)
1709 dwURLFlags |= URL_UNESCAPE;
1710 dwFlags &= ~ICU_DECODE;
1713 if(dwFlags & ICU_ESCAPE)
1715 dwURLFlags |= URL_UNESCAPE;
1716 dwFlags &= ~ICU_ESCAPE;
1719 if(dwFlags & ICU_BROWSER_MODE)
1721 dwURLFlags |= URL_BROWSER_MODE;
1722 dwFlags &= ~ICU_BROWSER_MODE;
1725 if(dwFlags & ICU_NO_ENCODE)
1727 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1728 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1729 dwFlags &= ~ICU_NO_ENCODE;
1732 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1734 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1735 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1736 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1738 return (hr == S_OK) ? TRUE : FALSE;
1741 /***********************************************************************
1742 * InternetCanonicalizeUrlW (WININET.@)
1744 * Escape unsafe characters and spaces
1751 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1752 LPDWORD lpdwBufferLength, DWORD dwFlags)
1755 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1757 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1758 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1760 if(dwFlags & ICU_DECODE)
1762 dwURLFlags |= URL_UNESCAPE;
1763 dwFlags &= ~ICU_DECODE;
1766 if(dwFlags & ICU_ESCAPE)
1768 dwURLFlags |= URL_UNESCAPE;
1769 dwFlags &= ~ICU_ESCAPE;
1772 if(dwFlags & ICU_BROWSER_MODE)
1774 dwURLFlags |= URL_BROWSER_MODE;
1775 dwFlags &= ~ICU_BROWSER_MODE;
1778 if(dwFlags & ICU_NO_ENCODE)
1780 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1781 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1782 dwFlags &= ~ICU_NO_ENCODE;
1785 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1787 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1788 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1789 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1791 return (hr == S_OK) ? TRUE : FALSE;
1794 /* #################################################### */
1796 static INTERNET_STATUS_CALLBACK set_status_callback(
1797 LPWININETHANDLEHEADER lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1799 INTERNET_STATUS_CALLBACK ret;
1801 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1802 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1804 ret = lpwh->lpfnStatusCB;
1805 lpwh->lpfnStatusCB = callback;
1810 /***********************************************************************
1811 * InternetSetStatusCallbackA (WININET.@)
1813 * Sets up a callback function which is called as progress is made
1814 * during an operation.
1817 * Previous callback or NULL on success
1818 * INTERNET_INVALID_STATUS_CALLBACK on failure
1821 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1822 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1824 INTERNET_STATUS_CALLBACK retVal;
1825 LPWININETHANDLEHEADER lpwh;
1827 TRACE("%p\n", hInternet);
1829 if (!(lpwh = WININET_GetObject(hInternet)))
1830 return INTERNET_INVALID_STATUS_CALLBACK;
1832 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1834 WININET_Release( lpwh );
1838 /***********************************************************************
1839 * InternetSetStatusCallbackW (WININET.@)
1841 * Sets up a callback function which is called as progress is made
1842 * during an operation.
1845 * Previous callback or NULL on success
1846 * INTERNET_INVALID_STATUS_CALLBACK on failure
1849 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1850 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1852 INTERNET_STATUS_CALLBACK retVal;
1853 LPWININETHANDLEHEADER lpwh;
1855 TRACE("%p\n", hInternet);
1857 if (!(lpwh = WININET_GetObject(hInternet)))
1858 return INTERNET_INVALID_STATUS_CALLBACK;
1860 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
1862 WININET_Release( lpwh );
1866 /***********************************************************************
1867 * InternetSetFilePointer (WININET.@)
1869 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1870 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
1876 /***********************************************************************
1877 * InternetWriteFile (WININET.@)
1879 * Write data to an open internet file
1886 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
1887 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1889 LPWININETHANDLEHEADER lpwh;
1890 BOOL retval = FALSE;
1892 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1894 lpwh = WININET_GetObject( hFile );
1896 WARN("Invalid handle\n");
1897 SetLastError(ERROR_INVALID_HANDLE);
1901 if(lpwh->vtbl->WriteFile) {
1902 retval = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1904 WARN("No Writefile method.\n");
1905 SetLastError(ERROR_INVALID_HANDLE);
1909 WININET_Release( lpwh );
1915 /***********************************************************************
1916 * InternetReadFile (WININET.@)
1918 * Read data from an open internet file
1925 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1926 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1928 LPWININETHANDLEHEADER hdr;
1929 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1931 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1933 hdr = WININET_GetObject(hFile);
1935 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1939 if(hdr->vtbl->ReadFile)
1940 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1942 WININET_Release(hdr);
1944 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
1945 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1947 if(res != ERROR_SUCCESS)
1949 return res == ERROR_SUCCESS;
1952 /***********************************************************************
1953 * InternetReadFileExA (WININET.@)
1955 * Read data from an open internet file
1958 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1959 * lpBuffersOut [I/O] Buffer.
1960 * dwFlags [I] Flags. See notes.
1961 * dwContext [I] Context for callbacks.
1968 * The parameter dwFlags include zero or more of the following flags:
1969 *|IRF_ASYNC - Makes the call asynchronous.
1970 *|IRF_SYNC - Makes the call synchronous.
1971 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1972 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1974 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1977 * InternetOpenUrlA(), HttpOpenRequestA()
1979 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1980 DWORD dwFlags, DWORD_PTR dwContext)
1982 LPWININETHANDLEHEADER hdr;
1983 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1985 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1987 hdr = WININET_GetObject(hFile);
1989 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1993 if(hdr->vtbl->ReadFileExA)
1994 res = hdr->vtbl->ReadFileExA(hdr, lpBuffersOut, dwFlags, dwContext);
1996 WININET_Release(hdr);
1998 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
1999 res, lpBuffersOut->dwBufferLength);
2001 if(res != ERROR_SUCCESS)
2003 return res == ERROR_SUCCESS;
2006 /***********************************************************************
2007 * InternetReadFileExW (WININET.@)
2009 * Read data from an open internet file.
2012 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
2013 * lpBuffersOut [I/O] Buffer.
2014 * dwFlags [I] Flags.
2015 * dwContext [I] Context for callbacks.
2018 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
2021 * Not implemented in Wine or native either (as of IE6 SP2).
2024 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2025 DWORD dwFlags, DWORD_PTR dwContext)
2027 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
2029 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2033 DWORD INET_QueryOption(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2035 static BOOL warn = TRUE;
2038 case INTERNET_OPTION_REQUEST_FLAGS:
2039 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2041 if (*size < sizeof(ULONG))
2042 return ERROR_INSUFFICIENT_BUFFER;
2044 *(ULONG*)buffer = 4;
2045 *size = sizeof(ULONG);
2047 return ERROR_SUCCESS;
2049 case INTERNET_OPTION_HTTP_VERSION:
2050 if (*size < sizeof(HTTP_VERSION_INFO))
2051 return ERROR_INSUFFICIENT_BUFFER;
2054 * Presently hardcoded to 1.1
2056 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2057 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2058 *size = sizeof(HTTP_VERSION_INFO);
2060 return ERROR_SUCCESS;
2062 case INTERNET_OPTION_CONNECTED_STATE:
2065 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2068 if (*size < sizeof(ULONG))
2069 return ERROR_INSUFFICIENT_BUFFER;
2071 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2072 *size = sizeof(ULONG);
2074 return ERROR_SUCCESS;
2076 case INTERNET_OPTION_PROXY: {
2079 TRACE("Getting global proxy info\n");
2080 memset(&ai, 0, sizeof(WININETAPPINFOW));
2081 INTERNET_ConfigureProxy(&ai);
2083 return APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2086 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2087 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2089 if (*size < sizeof(ULONG))
2090 return ERROR_INSUFFICIENT_BUFFER;
2092 *(ULONG*)buffer = 2;
2093 *size = sizeof(ULONG);
2095 return ERROR_SUCCESS;
2097 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2098 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2100 if (*size < sizeof(ULONG))
2101 return ERROR_INSUFFICIENT_BUFFER;
2104 *size = sizeof(ULONG);
2106 return ERROR_SUCCESS;
2108 case INTERNET_OPTION_SECURITY_FLAGS:
2109 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2110 return ERROR_SUCCESS;
2112 case INTERNET_OPTION_VERSION: {
2113 static const INTERNET_VERSION_INFO info = { 1, 2 };
2115 TRACE("INTERNET_OPTION_VERSION\n");
2117 if (*size < sizeof(INTERNET_VERSION_INFO))
2118 return ERROR_INSUFFICIENT_BUFFER;
2120 memcpy(buffer, &info, sizeof(info));
2121 *size = sizeof(info);
2123 return ERROR_SUCCESS;
2126 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2127 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2128 DWORD res = ERROR_SUCCESS, i;
2130 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2132 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW))
2133 return ERROR_INSUFFICIENT_BUFFER;
2135 for (i = 0; i < con->dwOptionCount; i++) {
2136 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2138 switch (option->dwOption) {
2139 case INTERNET_PER_CONN_FLAGS:
2140 option->Value.dwValue = PROXY_TYPE_DIRECT;
2143 case INTERNET_PER_CONN_PROXY_SERVER:
2144 case INTERNET_PER_CONN_PROXY_BYPASS:
2145 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2146 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2147 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2148 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2149 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2150 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2151 FIXME("Unhandled dwOption %d\n", option->dwOption);
2152 option->Value.dwValue = 0;
2153 res = ERROR_INVALID_PARAMETER;
2157 FIXME("Unknown dwOption %d\n", option->dwOption);
2158 res = ERROR_INVALID_PARAMETER;
2167 FIXME("Stub for %d\n", option);
2168 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2171 /***********************************************************************
2172 * InternetQueryOptionW (WININET.@)
2174 * Queries an options on the specified handle
2181 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2182 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2184 LPWININETHANDLEHEADER hdr;
2185 DWORD res = ERROR_INVALID_HANDLE;
2187 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2190 hdr = WININET_GetObject(hInternet);
2192 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2193 WININET_Release(hdr);
2196 res = INET_QueryOption(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2199 if(res != ERROR_SUCCESS)
2201 return res == ERROR_SUCCESS;
2204 /***********************************************************************
2205 * InternetQueryOptionA (WININET.@)
2207 * Queries an options on the specified handle
2214 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2215 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2217 LPWININETHANDLEHEADER hdr;
2218 DWORD res = ERROR_INVALID_HANDLE;
2220 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2223 hdr = WININET_GetObject(hInternet);
2225 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2226 WININET_Release(hdr);
2229 res = INET_QueryOption(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2232 if(res != ERROR_SUCCESS)
2234 return res == ERROR_SUCCESS;
2238 /***********************************************************************
2239 * InternetSetOptionW (WININET.@)
2241 * Sets an options on the specified handle
2248 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2249 LPVOID lpBuffer, DWORD dwBufferLength)
2251 LPWININETHANDLEHEADER lpwhh;
2254 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2256 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2257 if(lpwhh && lpwhh->vtbl->SetOption) {
2260 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2261 if(res != ERROR_INTERNET_INVALID_OPTION) {
2262 WININET_Release( lpwhh );
2264 if(res != ERROR_SUCCESS)
2267 return res == ERROR_SUCCESS;
2273 case INTERNET_OPTION_CALLBACK:
2277 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2280 WININET_Release(lpwhh);
2281 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2284 case INTERNET_OPTION_HTTP_VERSION:
2286 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2287 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2290 case INTERNET_OPTION_ERROR_MASK:
2292 ULONG flags = *(ULONG *)lpBuffer;
2293 FIXME("Option INTERNET_OPTION_ERROR_MASK(%d): STUB\n", flags);
2296 case INTERNET_OPTION_CODEPAGE:
2298 ULONG codepage = *(ULONG *)lpBuffer;
2299 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2302 case INTERNET_OPTION_REQUEST_PRIORITY:
2304 ULONG priority = *(ULONG *)lpBuffer;
2305 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2308 case INTERNET_OPTION_CONNECT_TIMEOUT:
2310 ULONG connecttimeout = *(ULONG *)lpBuffer;
2311 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2314 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2316 ULONG receivetimeout = *(ULONG *)lpBuffer;
2317 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2320 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2322 ULONG conns = *(ULONG *)lpBuffer;
2323 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns);
2326 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2328 ULONG conns = *(ULONG *)lpBuffer;
2329 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns);
2332 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2333 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2335 case INTERNET_OPTION_END_BROWSER_SESSION:
2336 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2338 case INTERNET_OPTION_CONNECTED_STATE:
2339 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2341 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2342 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2344 case INTERNET_OPTION_SEND_TIMEOUT:
2345 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2347 ULONG timeout = *(ULONG *)lpBuffer;
2348 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT %d\n", timeout);
2351 case INTERNET_OPTION_CONNECT_RETRIES:
2353 ULONG retries = *(ULONG *)lpBuffer;
2354 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2357 case INTERNET_OPTION_CONTEXT_VALUE:
2358 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2360 case INTERNET_OPTION_SECURITY_FLAGS:
2361 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2363 case INTERNET_OPTION_DISABLE_AUTODIAL:
2364 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2370 FIXME("Option %d STUB\n",dwOption);
2371 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2377 WININET_Release( lpwhh );
2383 /***********************************************************************
2384 * InternetSetOptionA (WININET.@)
2386 * Sets an options on the specified handle.
2393 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2394 LPVOID lpBuffer, DWORD dwBufferLength)
2402 case INTERNET_OPTION_CALLBACK:
2404 LPWININETHANDLEHEADER lpwh;
2406 if (!(lpwh = WININET_GetObject(hInternet)))
2408 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2411 WININET_Release(lpwh);
2412 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2415 case INTERNET_OPTION_PROXY:
2417 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2418 LPINTERNET_PROXY_INFOW piw;
2419 DWORD proxlen, prbylen;
2422 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2423 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2424 wlen = sizeof(*piw) + proxlen + prbylen;
2425 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2426 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2427 piw->dwAccessType = pi->dwAccessType;
2428 prox = (LPWSTR) &piw[1];
2429 prby = &prox[proxlen+1];
2430 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2431 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2432 piw->lpszProxy = prox;
2433 piw->lpszProxyBypass = prby;
2436 case INTERNET_OPTION_USER_AGENT:
2437 case INTERNET_OPTION_USERNAME:
2438 case INTERNET_OPTION_PASSWORD:
2439 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2441 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2442 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2447 wlen = dwBufferLength;
2450 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2452 if( lpBuffer != wbuffer )
2453 HeapFree( GetProcessHeap(), 0, wbuffer );
2459 /***********************************************************************
2460 * InternetSetOptionExA (WININET.@)
2462 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2463 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2465 FIXME("Flags %08x ignored\n", dwFlags);
2466 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2469 /***********************************************************************
2470 * InternetSetOptionExW (WININET.@)
2472 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2473 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2475 FIXME("Flags %08x ignored\n", dwFlags);
2476 if( dwFlags & ~ISO_VALID_FLAGS )
2478 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2481 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2484 static const WCHAR WININET_wkday[7][4] =
2485 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2486 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2487 static const WCHAR WININET_month[12][4] =
2488 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2489 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2490 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2492 /***********************************************************************
2493 * InternetTimeFromSystemTimeA (WININET.@)
2495 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2498 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2500 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2502 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2504 SetLastError(ERROR_INVALID_PARAMETER);
2508 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2510 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2514 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2515 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2520 /***********************************************************************
2521 * InternetTimeFromSystemTimeW (WININET.@)
2523 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2525 static const WCHAR date[] =
2526 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2527 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2529 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2531 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2533 SetLastError(ERROR_INVALID_PARAMETER);
2537 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2539 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2543 sprintfW( string, date,
2544 WININET_wkday[time->wDayOfWeek],
2546 WININET_month[time->wMonth - 1],
2555 /***********************************************************************
2556 * InternetTimeToSystemTimeA (WININET.@)
2558 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2564 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2566 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2567 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2571 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2572 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2573 HeapFree( GetProcessHeap(), 0, stringW );
2578 /***********************************************************************
2579 * InternetTimeToSystemTimeW (WININET.@)
2581 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2584 const WCHAR *s = string;
2587 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2589 if (!string || !time) return FALSE;
2591 /* Windows does this too */
2592 GetSystemTime( time );
2594 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2595 * a SYSTEMTIME structure.
2598 while (*s && !isalphaW( *s )) s++;
2599 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2600 time->wDayOfWeek = 7;
2602 for (i = 0; i < 7; i++)
2604 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2605 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2606 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2608 time->wDayOfWeek = i;
2613 if (time->wDayOfWeek > 6) return TRUE;
2614 while (*s && !isdigitW( *s )) s++;
2615 time->wDay = strtolW( s, &end, 10 );
2618 while (*s && !isalphaW( *s )) s++;
2619 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2622 for (i = 0; i < 12; i++)
2624 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2625 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2626 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2628 time->wMonth = i + 1;
2632 if (time->wMonth == 0) return TRUE;
2634 while (*s && !isdigitW( *s )) s++;
2635 if (*s == '\0') return TRUE;
2636 time->wYear = strtolW( s, &end, 10 );
2639 while (*s && !isdigitW( *s )) s++;
2640 if (*s == '\0') return TRUE;
2641 time->wHour = strtolW( s, &end, 10 );
2644 while (*s && !isdigitW( *s )) s++;
2645 if (*s == '\0') return TRUE;
2646 time->wMinute = strtolW( s, &end, 10 );
2649 while (*s && !isdigitW( *s )) s++;
2650 if (*s == '\0') return TRUE;
2651 time->wSecond = strtolW( s, &end, 10 );
2654 time->wMilliseconds = 0;
2658 /***********************************************************************
2659 * InternetCheckConnectionW (WININET.@)
2661 * Pings a requested host to check internet connection
2664 * TRUE on success and FALSE on failure. If a failure then
2665 * ERROR_NOT_CONNECTED is placed into GetLastError
2668 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2671 * this is a kludge which runs the resident ping program and reads the output.
2673 * Anyone have a better idea?
2677 static const CHAR ping[] = "ping -c 1 ";
2678 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2679 CHAR *command = NULL;
2688 * Crack or set the Address
2690 if (lpszUrl == NULL)
2693 * According to the doc we are supposed to use the ip for the next
2694 * server in the WnInet internal server database. I have
2695 * no idea what that is or how to get it.
2697 * So someone needs to implement this.
2699 FIXME("Unimplemented with URL of NULL\n");
2704 URL_COMPONENTSW components;
2706 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2707 components.lpszHostName = (LPWSTR)hostW;
2708 components.dwHostNameLength = 1024;
2710 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2713 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2714 port = components.nPort;
2715 TRACE("port: %d\n", port);
2718 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
2720 struct sockaddr_in sin;
2723 if (!GetAddress(hostW, port, &sin))
2725 fd = socket(sin.sin_family, SOCK_STREAM, 0);
2728 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == 0)
2736 * Build our ping command
2738 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2739 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2740 strcpy(command,ping);
2741 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2742 strcat(command,redirect);
2744 TRACE("Ping command is : %s\n",command);
2746 status = system(command);
2748 TRACE("Ping returned a code of %i\n",status);
2750 /* Ping return code of 0 indicates success */
2757 HeapFree( GetProcessHeap(), 0, command );
2759 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2765 /***********************************************************************
2766 * InternetCheckConnectionA (WININET.@)
2768 * Pings a requested host to check internet connection
2771 * TRUE on success and FALSE on failure. If a failure then
2772 * ERROR_NOT_CONNECTED is placed into GetLastError
2775 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2781 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2782 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2784 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2785 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2786 HeapFree(GetProcessHeap(), 0, szUrl);
2792 /**********************************************************
2793 * INTERNET_InternetOpenUrlW (internal)
2798 * handle of connection or NULL on failure
2800 static HINTERNET INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2801 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2803 URL_COMPONENTSW urlComponents;
2804 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2805 WCHAR password[1024], path[2048], extra[1024];
2806 HINTERNET client = NULL, client1 = NULL;
2808 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2809 dwHeadersLength, dwFlags, dwContext);
2811 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2812 urlComponents.lpszScheme = protocol;
2813 urlComponents.dwSchemeLength = 32;
2814 urlComponents.lpszHostName = hostName;
2815 urlComponents.dwHostNameLength = MAXHOSTNAME;
2816 urlComponents.lpszUserName = userName;
2817 urlComponents.dwUserNameLength = 1024;
2818 urlComponents.lpszPassword = password;
2819 urlComponents.dwPasswordLength = 1024;
2820 urlComponents.lpszUrlPath = path;
2821 urlComponents.dwUrlPathLength = 2048;
2822 urlComponents.lpszExtraInfo = extra;
2823 urlComponents.dwExtraInfoLength = 1024;
2824 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2826 switch(urlComponents.nScheme) {
2827 case INTERNET_SCHEME_FTP:
2828 if(urlComponents.nPort == 0)
2829 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2830 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2831 userName, password, dwFlags, dwContext, INET_OPENURL);
2834 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2835 if(client1 == NULL) {
2836 InternetCloseHandle(client);
2841 case INTERNET_SCHEME_HTTP:
2842 case INTERNET_SCHEME_HTTPS: {
2843 static const WCHAR szStars[] = { '*','/','*', 0 };
2844 LPCWSTR accept[2] = { szStars, NULL };
2845 if(urlComponents.nPort == 0) {
2846 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2847 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2849 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2851 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
2853 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2854 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2855 userName, password, dwFlags, dwContext, INET_OPENURL);
2859 if (urlComponents.dwExtraInfoLength) {
2861 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
2863 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
2865 InternetCloseHandle(client);
2868 strcpyW(path_extra, urlComponents.lpszUrlPath);
2869 strcatW(path_extra, urlComponents.lpszExtraInfo);
2870 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
2871 HeapFree(GetProcessHeap(), 0, path_extra);
2874 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2876 if(client1 == NULL) {
2877 InternetCloseHandle(client);
2880 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2881 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2882 GetLastError() != ERROR_IO_PENDING) {
2883 InternetCloseHandle(client1);
2888 case INTERNET_SCHEME_GOPHER:
2889 /* gopher doesn't seem to be implemented in wine, but it's supposed
2890 * to be supported by InternetOpenUrlA. */
2892 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2896 TRACE(" %p <--\n", client1);
2901 /**********************************************************
2902 * InternetOpenUrlW (WININET.@)
2907 * handle of connection or NULL on failure
2909 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
2911 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
2912 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
2916 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
2917 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2918 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2919 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2922 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2923 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2925 HINTERNET ret = NULL;
2926 LPWININETAPPINFOW hIC = NULL;
2928 if (TRACE_ON(wininet)) {
2929 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2930 dwHeadersLength, dwFlags, dwContext);
2932 dump_INTERNET_FLAGS(dwFlags);
2937 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2941 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2942 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2943 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2947 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2948 WORKREQUEST workRequest;
2949 struct WORKREQ_INTERNETOPENURLW *req;
2951 workRequest.asyncproc = AsyncInternetOpenUrlProc;
2952 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2953 req = &workRequest.u.InternetOpenUrlW;
2954 req->lpszUrl = WININET_strdupW(lpszUrl);
2956 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2958 req->lpszHeaders = 0;
2959 req->dwHeadersLength = dwHeadersLength;
2960 req->dwFlags = dwFlags;
2961 req->dwContext = dwContext;
2963 INTERNET_AsyncCall(&workRequest);
2965 * This is from windows.
2967 INTERNET_SetLastError(ERROR_IO_PENDING);
2969 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2974 WININET_Release( &hIC->hdr );
2975 TRACE(" %p <--\n", ret);
2980 /**********************************************************
2981 * InternetOpenUrlA (WININET.@)
2986 * handle of connection or NULL on failure
2988 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2989 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2991 HINTERNET rc = NULL;
2995 LPWSTR szUrl = NULL;
2996 LPWSTR szHeaders = NULL;
3001 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3002 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3005 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3009 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3010 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3012 HeapFree(GetProcessHeap(), 0, szUrl);
3015 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3018 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3019 lenHeaders, dwFlags, dwContext);
3021 HeapFree(GetProcessHeap(), 0, szUrl);
3022 HeapFree(GetProcessHeap(), 0, szHeaders);
3028 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3030 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3034 lpwite->dwError = 0;
3035 lpwite->response[0] = '\0';
3038 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3040 HeapFree(GetProcessHeap(), 0, lpwite);
3048 /***********************************************************************
3049 * INTERNET_SetLastError (internal)
3051 * Set last thread specific error
3056 void INTERNET_SetLastError(DWORD dwError)
3058 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3061 lpwite = INTERNET_AllocThreadError();
3063 SetLastError(dwError);
3065 lpwite->dwError = dwError;
3069 /***********************************************************************
3070 * INTERNET_GetLastError (internal)
3072 * Get last thread specific error
3077 DWORD INTERNET_GetLastError(void)
3079 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3080 if (!lpwite) return 0;
3081 /* TlsGetValue clears last error, so set it again here */
3082 SetLastError(lpwite->dwError);
3083 return lpwite->dwError;
3087 /***********************************************************************
3088 * INTERNET_WorkerThreadFunc (internal)
3090 * Worker thread execution function
3095 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3097 LPWORKREQUEST lpRequest = lpvParam;
3098 WORKREQUEST workRequest;
3102 workRequest = *lpRequest;
3103 HeapFree(GetProcessHeap(), 0, lpRequest);
3105 workRequest.asyncproc(&workRequest);
3107 WININET_Release( workRequest.hdr );
3112 /***********************************************************************
3113 * INTERNET_AsyncCall (internal)
3115 * Retrieves work request from queue
3120 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3123 LPWORKREQUEST lpNewRequest;
3127 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3131 *lpNewRequest = *lpWorkRequest;
3133 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3136 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3137 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3144 /***********************************************************************
3145 * INTERNET_GetResponseBuffer (internal)
3150 LPSTR INTERNET_GetResponseBuffer(void)
3152 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3154 lpwite = INTERNET_AllocThreadError();
3156 return lpwite->response;
3159 /***********************************************************************
3160 * INTERNET_GetNextLine (internal)
3162 * Parse next line in directory string listing
3165 * Pointer to beginning of next line
3170 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3173 BOOL bSuccess = FALSE;
3175 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3180 pfd.events = POLLIN;
3182 while (nRecv < MAX_REPLY_LEN)
3184 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3186 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3188 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3192 if (lpszBuffer[nRecv] == '\n')
3197 if (lpszBuffer[nRecv] != '\r')
3202 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3210 lpszBuffer[nRecv] = '\0';
3212 TRACE(":%d %s\n", nRecv, lpszBuffer);
3221 /**********************************************************
3222 * InternetQueryDataAvailable (WININET.@)
3224 * Determines how much data is available to be read.
3227 * TRUE on success, FALSE if an error occurred. If
3228 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3229 * no data is presently available, FALSE is returned with
3230 * the last error ERROR_IO_PENDING; a callback with status
3231 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3232 * data is available.
3234 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3235 LPDWORD lpdwNumberOfBytesAvailble,
3236 DWORD dwFlags, DWORD_PTR dwContext)
3238 WININETHANDLEHEADER *hdr;
3241 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3243 hdr = WININET_GetObject( hFile );
3245 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
3249 if(hdr->vtbl->QueryDataAvailable) {
3250 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3252 WARN("wrong handle\n");
3253 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3256 WININET_Release(hdr);
3258 if(res != ERROR_SUCCESS)
3260 return res == ERROR_SUCCESS;
3264 /***********************************************************************
3265 * InternetLockRequestFile (WININET.@)
3267 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3274 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3281 /***********************************************************************
3282 * InternetAutodial (WININET.@)
3284 * On windows this function is supposed to dial the default internet
3285 * connection. We don't want to have Wine dial out to the internet so
3286 * we return TRUE by default. It might be nice to check if we are connected.
3293 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3297 /* Tell that we are connected to the internet. */
3301 /***********************************************************************
3302 * InternetAutodialHangup (WININET.@)
3304 * Hangs up a connection made with InternetAutodial
3313 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3317 /* we didn't dial, we don't disconnect */
3321 /***********************************************************************
3322 * InternetCombineUrlA (WININET.@)
3324 * Combine a base URL with a relative URL
3332 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3333 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3338 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3340 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3341 dwFlags ^= ICU_NO_ENCODE;
3342 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3347 /***********************************************************************
3348 * InternetCombineUrlW (WININET.@)
3350 * Combine a base URL with a relative URL
3358 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3359 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3364 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3366 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3367 dwFlags ^= ICU_NO_ENCODE;
3368 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3373 /* max port num is 65535 => 5 digits */
3374 #define MAX_WORD_DIGITS 5
3376 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3377 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3378 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3379 (url)->dw##component##Length : strlen((url)->lpsz##component))
3381 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3383 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3384 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3386 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3387 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3389 if ((nScheme == INTERNET_SCHEME_FTP) &&
3390 (nPort == INTERNET_DEFAULT_FTP_PORT))
3392 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3393 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3396 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3402 /* opaque urls do not fit into the standard url hierarchy and don't have
3403 * two following slashes */
3404 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3406 return (nScheme != INTERNET_SCHEME_FTP) &&
3407 (nScheme != INTERNET_SCHEME_GOPHER) &&
3408 (nScheme != INTERNET_SCHEME_HTTP) &&
3409 (nScheme != INTERNET_SCHEME_HTTPS) &&
3410 (nScheme != INTERNET_SCHEME_FILE);
3413 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3416 if (scheme < INTERNET_SCHEME_FIRST)
3418 index = scheme - INTERNET_SCHEME_FIRST;
3419 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3421 return (LPCWSTR)url_schemes[index];
3424 /* we can calculate using ansi strings because we're just
3425 * calculating string length, not size
3427 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3428 LPDWORD lpdwUrlLength)
3430 INTERNET_SCHEME nScheme;
3434 if (lpUrlComponents->lpszScheme)
3436 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3437 *lpdwUrlLength += dwLen;
3438 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3444 nScheme = lpUrlComponents->nScheme;
3446 if (nScheme == INTERNET_SCHEME_DEFAULT)
3447 nScheme = INTERNET_SCHEME_HTTP;
3448 scheme = INTERNET_GetSchemeString(nScheme);
3449 *lpdwUrlLength += strlenW(scheme);
3452 (*lpdwUrlLength)++; /* ':' */
3453 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3454 *lpdwUrlLength += strlen("//");
3456 if (lpUrlComponents->lpszUserName)
3458 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3459 *lpdwUrlLength += strlen("@");
3463 if (lpUrlComponents->lpszPassword)
3465 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3470 if (lpUrlComponents->lpszPassword)
3472 *lpdwUrlLength += strlen(":");
3473 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3476 if (lpUrlComponents->lpszHostName)
3478 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3480 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3482 char szPort[MAX_WORD_DIGITS+1];
3484 sprintf(szPort, "%d", lpUrlComponents->nPort);
3485 *lpdwUrlLength += strlen(szPort);
3486 *lpdwUrlLength += strlen(":");
3489 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3490 (*lpdwUrlLength)++; /* '/' */
3493 if (lpUrlComponents->lpszUrlPath)
3494 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3496 if (lpUrlComponents->lpszExtraInfo)
3497 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
3502 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3506 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3508 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3509 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3510 urlCompW->nScheme = lpUrlComponents->nScheme;
3511 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3512 urlCompW->nPort = lpUrlComponents->nPort;
3513 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3514 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3515 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3516 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3518 if (lpUrlComponents->lpszScheme)
3520 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3521 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3522 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3523 -1, urlCompW->lpszScheme, len);
3526 if (lpUrlComponents->lpszHostName)
3528 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3529 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3530 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3531 -1, urlCompW->lpszHostName, len);
3534 if (lpUrlComponents->lpszUserName)
3536 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3537 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3538 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3539 -1, urlCompW->lpszUserName, len);
3542 if (lpUrlComponents->lpszPassword)
3544 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3545 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3546 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3547 -1, urlCompW->lpszPassword, len);
3550 if (lpUrlComponents->lpszUrlPath)
3552 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3553 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3554 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3555 -1, urlCompW->lpszUrlPath, len);
3558 if (lpUrlComponents->lpszExtraInfo)
3560 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3561 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3562 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3563 -1, urlCompW->lpszExtraInfo, len);
3567 /***********************************************************************
3568 * InternetCreateUrlA (WININET.@)
3570 * See InternetCreateUrlW.
3572 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3573 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3577 URL_COMPONENTSW urlCompW;
3579 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3581 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3583 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3587 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3590 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3592 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3594 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3595 *lpdwUrlLength /= sizeof(WCHAR);
3597 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3598 * minus one, so add one to leave room for NULL terminator
3601 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3603 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3604 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3605 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3606 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3607 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3608 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3609 HeapFree(GetProcessHeap(), 0, urlW);
3614 /***********************************************************************
3615 * InternetCreateUrlW (WININET.@)
3617 * Creates a URL from its component parts.
3620 * lpUrlComponents [I] URL Components.
3621 * dwFlags [I] Flags. See notes.
3622 * lpszUrl [I] Buffer in which to store the created URL.
3623 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3624 * lpszUrl in characters. On output, the number of bytes
3625 * required to store the URL including terminator.
3629 * The dwFlags parameter can be zero or more of the following:
3630 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3637 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3638 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3641 INTERNET_SCHEME nScheme;
3643 static const WCHAR slashSlashW[] = {'/','/'};
3644 static const WCHAR percentD[] = {'%','d',0};
3646 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3648 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3650 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3654 if (!calc_url_length(lpUrlComponents, &dwLen))
3657 if (!lpszUrl || *lpdwUrlLength < dwLen)
3659 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3660 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3664 *lpdwUrlLength = dwLen;
3669 if (lpUrlComponents->lpszScheme)
3671 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3672 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3675 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3680 nScheme = lpUrlComponents->nScheme;
3682 if (nScheme == INTERNET_SCHEME_DEFAULT)
3683 nScheme = INTERNET_SCHEME_HTTP;
3685 scheme = INTERNET_GetSchemeString(nScheme);
3686 dwLen = strlenW(scheme);
3687 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3691 /* all schemes are followed by at least a colon */
3695 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3697 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3698 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3701 if (lpUrlComponents->lpszUserName)
3703 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3704 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3707 if (lpUrlComponents->lpszPassword)
3712 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3713 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3721 if (lpUrlComponents->lpszHostName)
3723 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3724 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3727 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3729 WCHAR szPort[MAX_WORD_DIGITS+1];
3731 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3734 dwLen = strlenW(szPort);
3735 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3739 /* add slash between hostname and path if necessary */
3740 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3747 if (lpUrlComponents->lpszUrlPath)
3749 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3750 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3754 if (lpUrlComponents->lpszExtraInfo)
3756 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
3757 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
3766 /***********************************************************************
3767 * InternetConfirmZoneCrossingA (WININET.@)
3770 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3772 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3773 return ERROR_SUCCESS;
3776 /***********************************************************************
3777 * InternetConfirmZoneCrossingW (WININET.@)
3780 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3782 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3783 return ERROR_SUCCESS;
3786 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3787 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3789 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3790 lpdwConnection, dwReserved);
3791 return ERROR_SUCCESS;
3794 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3795 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3797 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3798 lpdwConnection, dwReserved);
3799 return ERROR_SUCCESS;
3802 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3804 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3808 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3810 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3814 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
3816 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
3817 return ERROR_SUCCESS;
3820 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3823 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3824 debugstr_w(pwszTarget), pbHexHash);
3828 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3830 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
3834 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
3836 FIXME("(%p, %08lx) stub\n", a, b);