wininet: Move InternetQueryOption(INTERNET_OPTION_URL) to vtbl.
[wine.git] / dlls / wininet / internet.c
blob748c518c84f7a468ce08a394e4290f6cad7d1c31
1 /*
2 * Wininet
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
10 * Ulrich Czekalla
11 * Aric Stewart
12 * David Hammerton
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
29 #include "config.h"
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
34 #include <string.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
40 #endif
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
43 #endif
44 #include <stdlib.h>
45 #include <ctype.h>
46 #ifdef HAVE_UNISTD_H
47 # include <unistd.h>
48 #endif
49 #include <assert.h>
51 #include "windef.h"
52 #include "winbase.h"
53 #include "winreg.h"
54 #include "winuser.h"
55 #include "wininet.h"
56 #include "winineti.h"
57 #include "winnls.h"
58 #include "wine/debug.h"
59 #include "winerror.h"
60 #define NO_SHLWAPI_STREAM
61 #include "shlwapi.h"
62 #include "wincrypt.h"
64 #include "wine/exception.h"
66 #include "internet.h"
67 #include "resource.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define RESPONSE_TIMEOUT 30
75 typedef struct
77 DWORD dwError;
78 CHAR response[MAX_REPLY_LEN];
79 } WITHREADERROR, *LPWITHREADERROR;
81 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
82 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext);
84 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
85 static HMODULE WININET_hModule;
87 #define HANDLE_CHUNK_SIZE 0x10
89 static CRITICAL_SECTION WININET_cs;
90 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
92 0, 0, &WININET_cs,
93 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
94 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
96 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
98 static LPWININETHANDLEHEADER *WININET_Handles;
99 static UINT WININET_dwNextHandle;
100 static UINT WININET_dwMaxHandles;
102 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
104 LPWININETHANDLEHEADER *p;
105 UINT handle = 0, num;
107 list_init( &info->children );
109 EnterCriticalSection( &WININET_cs );
110 if( !WININET_dwMaxHandles )
112 num = HANDLE_CHUNK_SIZE;
113 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
114 sizeof (UINT)* num);
115 if( !p )
116 goto end;
117 WININET_Handles = p;
118 WININET_dwMaxHandles = num;
120 if( WININET_dwMaxHandles == WININET_dwNextHandle )
122 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
123 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
124 WININET_Handles, sizeof (UINT)* num);
125 if( !p )
126 goto end;
127 WININET_Handles = p;
128 WININET_dwMaxHandles = num;
131 handle = WININET_dwNextHandle;
132 if( WININET_Handles[handle] )
133 ERR("handle isn't free but should be\n");
134 WININET_Handles[handle] = WININET_AddRef( info );
136 while( WININET_Handles[WININET_dwNextHandle] &&
137 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
138 WININET_dwNextHandle++;
140 end:
141 LeaveCriticalSection( &WININET_cs );
143 return info->hInternet = (HINTERNET) (handle+1);
146 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
148 ULONG refs = InterlockedIncrement(&info->refs);
149 TRACE("%p -> refcount = %d\n", info, refs );
150 return info;
153 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
155 LPWININETHANDLEHEADER info = NULL;
156 UINT handle = (UINT) hinternet;
158 EnterCriticalSection( &WININET_cs );
160 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
161 WININET_Handles[handle-1] )
162 info = WININET_AddRef( WININET_Handles[handle-1] );
164 LeaveCriticalSection( &WININET_cs );
166 TRACE("handle %d -> %p\n", handle, info);
168 return info;
171 BOOL WININET_Release( LPWININETHANDLEHEADER info )
173 ULONG refs = InterlockedDecrement(&info->refs);
174 TRACE( "object %p refcount = %d\n", info, refs );
175 if( !refs )
177 if ( info->vtbl->CloseConnection )
179 TRACE( "closing connection %p\n", info);
180 info->vtbl->CloseConnection( info );
182 INTERNET_SendCallback(info, info->dwContext,
183 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
184 sizeof(HINTERNET));
185 TRACE( "destroying object %p\n", info);
186 if ( info->htype != WH_HINIT )
187 list_remove( &info->entry );
188 info->vtbl->Destroy( info );
190 return TRUE;
193 BOOL WININET_FreeHandle( HINTERNET hinternet )
195 BOOL ret = FALSE;
196 UINT handle = (UINT) hinternet;
197 LPWININETHANDLEHEADER info = NULL, child, next;
199 EnterCriticalSection( &WININET_cs );
201 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
203 handle--;
204 if( WININET_Handles[handle] )
206 info = WININET_Handles[handle];
207 TRACE( "destroying handle %d for object %p\n", handle+1, info);
208 WININET_Handles[handle] = NULL;
209 ret = TRUE;
213 LeaveCriticalSection( &WININET_cs );
215 /* As on native when the equivalent of WININET_Release is called, the handle
216 * is already invalid, but if a new handle is created at this time it does
217 * not yet get assigned the freed handle number */
218 if( info )
220 /* Free all children as native does */
221 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, WININETHANDLEHEADER, entry )
223 TRACE( "freeing child handle %d for parent handle %d\n",
224 (UINT)child->hInternet, handle+1);
225 WININET_FreeHandle( child->hInternet );
227 WININET_Release( info );
230 EnterCriticalSection( &WININET_cs );
232 if( WININET_dwNextHandle > handle && !WININET_Handles[handle] )
233 WININET_dwNextHandle = handle;
235 LeaveCriticalSection( &WININET_cs );
237 return ret;
240 /***********************************************************************
241 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
243 * PARAMS
244 * hinstDLL [I] handle to the DLL's instance
245 * fdwReason [I]
246 * lpvReserved [I] reserved, must be NULL
248 * RETURNS
249 * Success: TRUE
250 * Failure: FALSE
253 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
255 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
257 switch (fdwReason) {
258 case DLL_PROCESS_ATTACH:
260 g_dwTlsErrIndex = TlsAlloc();
262 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
263 return FALSE;
265 URLCacheContainers_CreateDefaults();
267 WININET_hModule = hinstDLL;
269 case DLL_THREAD_ATTACH:
270 break;
272 case DLL_THREAD_DETACH:
273 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
275 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
276 HeapFree(GetProcessHeap(), 0, lpwite);
278 break;
280 case DLL_PROCESS_DETACH:
282 URLCacheContainers_DeleteAll();
284 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
286 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
287 TlsFree(g_dwTlsErrIndex);
289 break;
292 return TRUE;
296 /***********************************************************************
297 * InternetInitializeAutoProxyDll (WININET.@)
299 * Setup the internal proxy
301 * PARAMETERS
302 * dwReserved
304 * RETURNS
305 * FALSE on failure
308 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
310 FIXME("STUB\n");
311 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
312 return FALSE;
315 /***********************************************************************
316 * DetectAutoProxyUrl (WININET.@)
318 * Auto detect the proxy url
320 * RETURNS
321 * FALSE on failure
324 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
325 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
327 FIXME("STUB\n");
328 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
329 return FALSE;
333 /***********************************************************************
334 * INTERNET_ConfigureProxyFromReg
336 * FIXME:
337 * The proxy may be specified in the form 'http=proxy.my.org'
338 * Presumably that means there can be ftp=ftpproxy.my.org too.
340 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
342 HKEY key;
343 DWORD r, keytype, len, enabled;
344 LPCSTR lpszInternetSettings =
345 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
346 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
348 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
349 if ( r != ERROR_SUCCESS )
350 return FALSE;
352 len = sizeof enabled;
353 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
354 (BYTE*)&enabled, &len);
355 if( (r == ERROR_SUCCESS) && enabled )
357 TRACE("Proxy is enabled.\n");
359 /* figure out how much memory the proxy setting takes */
360 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
361 NULL, &len);
362 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
364 LPWSTR szProxy, p;
365 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
367 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
368 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
369 (BYTE*)szProxy, &len);
371 /* find the http proxy, and strip away everything else */
372 p = strstrW( szProxy, szHttp );
373 if( p )
375 p += lstrlenW(szHttp);
376 lstrcpyW( szProxy, p );
378 p = strchrW( szProxy, ' ' );
379 if( p )
380 *p = 0;
382 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
383 lpwai->lpszProxy = szProxy;
385 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
387 else
388 ERR("Couldn't read proxy server settings.\n");
390 else
391 TRACE("Proxy is not enabled.\n");
392 RegCloseKey(key);
394 return enabled;
397 /***********************************************************************
398 * dump_INTERNET_FLAGS
400 * Helper function to TRACE the internet flags.
402 * RETURNS
403 * None
406 static void dump_INTERNET_FLAGS(DWORD dwFlags)
408 #define FE(x) { x, #x }
409 static const wininet_flag_info flag[] = {
410 FE(INTERNET_FLAG_RELOAD),
411 FE(INTERNET_FLAG_RAW_DATA),
412 FE(INTERNET_FLAG_EXISTING_CONNECT),
413 FE(INTERNET_FLAG_ASYNC),
414 FE(INTERNET_FLAG_PASSIVE),
415 FE(INTERNET_FLAG_NO_CACHE_WRITE),
416 FE(INTERNET_FLAG_MAKE_PERSISTENT),
417 FE(INTERNET_FLAG_FROM_CACHE),
418 FE(INTERNET_FLAG_SECURE),
419 FE(INTERNET_FLAG_KEEP_CONNECTION),
420 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
421 FE(INTERNET_FLAG_READ_PREFETCH),
422 FE(INTERNET_FLAG_NO_COOKIES),
423 FE(INTERNET_FLAG_NO_AUTH),
424 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
425 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
426 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
427 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
428 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
429 FE(INTERNET_FLAG_RESYNCHRONIZE),
430 FE(INTERNET_FLAG_HYPERLINK),
431 FE(INTERNET_FLAG_NO_UI),
432 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
433 FE(INTERNET_FLAG_CACHE_ASYNC),
434 FE(INTERNET_FLAG_FORMS_SUBMIT),
435 FE(INTERNET_FLAG_NEED_FILE),
436 FE(INTERNET_FLAG_TRANSFER_ASCII),
437 FE(INTERNET_FLAG_TRANSFER_BINARY)
439 #undef FE
440 int i;
442 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
443 if (flag[i].val & dwFlags) {
444 TRACE(" %s", flag[i].name);
445 dwFlags &= ~flag[i].val;
448 if (dwFlags)
449 TRACE(" Unknown flags (%08x)\n", dwFlags);
450 else
451 TRACE("\n");
454 /***********************************************************************
455 * INTERNET_CloseHandle (internal)
457 * Close internet handle
460 static VOID APPINFO_Destroy(WININETHANDLEHEADER *hdr)
462 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
464 TRACE("%p\n",lpwai);
466 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
467 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
468 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
469 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
470 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
471 HeapFree(GetProcessHeap(), 0, lpwai);
474 static DWORD APPINFO_QueryOption(WININETHANDLEHEADER *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
476 switch(option) {
477 case INTERNET_OPTION_HANDLE_TYPE:
478 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
480 if (*size < sizeof(ULONG))
481 return ERROR_INSUFFICIENT_BUFFER;
483 *size = sizeof(DWORD);
484 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
485 return ERROR_SUCCESS;
488 FIXME("Not implemented option %d\n", option);
489 return ERROR_INTERNET_INVALID_OPTION;
492 static const HANDLEHEADERVtbl APPINFOVtbl = {
493 APPINFO_Destroy,
494 NULL,
495 APPINFO_QueryOption,
496 NULL,
497 NULL,
498 NULL,
499 NULL,
500 NULL,
501 NULL
505 /***********************************************************************
506 * InternetOpenW (WININET.@)
508 * Per-application initialization of wininet
510 * RETURNS
511 * HINTERNET on success
512 * NULL on failure
515 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
516 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
518 LPWININETAPPINFOW lpwai = NULL;
519 HINTERNET handle = NULL;
521 if (TRACE_ON(wininet)) {
522 #define FE(x) { x, #x }
523 static const wininet_flag_info access_type[] = {
524 FE(INTERNET_OPEN_TYPE_PRECONFIG),
525 FE(INTERNET_OPEN_TYPE_DIRECT),
526 FE(INTERNET_OPEN_TYPE_PROXY),
527 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
529 #undef FE
530 DWORD i;
531 const char *access_type_str = "Unknown";
533 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
534 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
535 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
536 if (access_type[i].val == dwAccessType) {
537 access_type_str = access_type[i].name;
538 break;
541 TRACE(" access type : %s\n", access_type_str);
542 TRACE(" flags :");
543 dump_INTERNET_FLAGS(dwFlags);
546 /* Clear any error information */
547 INTERNET_SetLastError(0);
549 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETAPPINFOW));
550 if (NULL == lpwai)
552 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
553 goto lend;
556 lpwai->hdr.htype = WH_HINIT;
557 lpwai->hdr.vtbl = &APPINFOVtbl;
558 lpwai->hdr.dwFlags = dwFlags;
559 lpwai->hdr.refs = 1;
560 lpwai->dwAccessType = dwAccessType;
561 lpwai->lpszProxyUsername = NULL;
562 lpwai->lpszProxyPassword = NULL;
564 handle = WININET_AllocHandle( &lpwai->hdr );
565 if( !handle )
567 HeapFree( GetProcessHeap(), 0, lpwai );
568 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
569 goto lend;
572 if (NULL != lpszAgent)
574 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
575 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
576 if (lpwai->lpszAgent)
577 lstrcpyW( lpwai->lpszAgent, lpszAgent );
579 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
580 INTERNET_ConfigureProxyFromReg( lpwai );
581 else if (NULL != lpszProxy)
583 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
584 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
585 if (lpwai->lpszProxy)
586 lstrcpyW( lpwai->lpszProxy, lpszProxy );
589 if (NULL != lpszProxyBypass)
591 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
592 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
593 if (lpwai->lpszProxyBypass)
594 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
597 lend:
598 if( lpwai )
599 WININET_Release( &lpwai->hdr );
601 TRACE("returning %p\n", lpwai);
603 return handle;
607 /***********************************************************************
608 * InternetOpenA (WININET.@)
610 * Per-application initialization of wininet
612 * RETURNS
613 * HINTERNET on success
614 * NULL on failure
617 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
618 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
620 HINTERNET rc = NULL;
621 INT len;
622 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
624 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
625 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
627 if( lpszAgent )
629 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
630 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
631 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
634 if( lpszProxy )
636 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
637 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
638 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
641 if( lpszProxyBypass )
643 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
644 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
645 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
648 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
650 HeapFree(GetProcessHeap(), 0, szAgent);
651 HeapFree(GetProcessHeap(), 0, szProxy);
652 HeapFree(GetProcessHeap(), 0, szBypass);
654 return rc;
657 /***********************************************************************
658 * InternetGetLastResponseInfoA (WININET.@)
660 * Return last wininet error description on the calling thread
662 * RETURNS
663 * TRUE on success of writing to buffer
664 * FALSE on failure
667 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
668 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
670 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
672 TRACE("\n");
674 if (lpwite)
676 *lpdwError = lpwite->dwError;
677 if (lpwite->dwError)
679 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
680 *lpdwBufferLength = strlen(lpszBuffer);
682 else
683 *lpdwBufferLength = 0;
685 else
687 *lpdwError = 0;
688 *lpdwBufferLength = 0;
691 return TRUE;
694 /***********************************************************************
695 * InternetGetLastResponseInfoW (WININET.@)
697 * Return last wininet error description on the calling thread
699 * RETURNS
700 * TRUE on success of writing to buffer
701 * FALSE on failure
704 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
705 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
707 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
709 TRACE("\n");
711 if (lpwite)
713 *lpdwError = lpwite->dwError;
714 if (lpwite->dwError)
716 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
717 *lpdwBufferLength = lstrlenW(lpszBuffer);
719 else
720 *lpdwBufferLength = 0;
722 else
724 *lpdwError = 0;
725 *lpdwBufferLength = 0;
728 return TRUE;
731 /***********************************************************************
732 * InternetGetConnectedState (WININET.@)
734 * Return connected state
736 * RETURNS
737 * TRUE if connected
738 * if lpdwStatus is not null, return the status (off line,
739 * modem, lan...) in it.
740 * FALSE if not connected
742 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
744 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
746 if (lpdwStatus) {
747 FIXME("always returning LAN connection.\n");
748 *lpdwStatus = INTERNET_CONNECTION_LAN;
750 return TRUE;
754 /***********************************************************************
755 * InternetGetConnectedStateExW (WININET.@)
757 * Return connected state
759 * PARAMS
761 * lpdwStatus [O] Flags specifying the status of the internet connection.
762 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
763 * dwNameLen [I] Size of the buffer, in characters.
764 * dwReserved [I] Reserved. Must be set to 0.
766 * RETURNS
767 * TRUE if connected
768 * if lpdwStatus is not null, return the status (off line,
769 * modem, lan...) in it.
770 * FALSE if not connected
772 * NOTES
773 * If the system has no available network connections, an empty string is
774 * stored in lpszConnectionName. If there is a LAN connection, a localized
775 * "LAN Connection" string is stored. Presumably, if only a dial-up
776 * connection is available then the name of the dial-up connection is
777 * returned. Why any application, other than the "Internet Settings" CPL,
778 * would want to use this function instead of the simpler InternetGetConnectedStateW
779 * function is beyond me.
781 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
782 DWORD dwNameLen, DWORD dwReserved)
784 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
786 /* Must be zero */
787 if(dwReserved)
788 return FALSE;
790 if (lpdwStatus) {
791 FIXME("always returning LAN connection.\n");
792 *lpdwStatus = INTERNET_CONNECTION_LAN;
794 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
798 /***********************************************************************
799 * InternetGetConnectedStateExA (WININET.@)
801 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
802 DWORD dwNameLen, DWORD dwReserved)
804 LPWSTR lpwszConnectionName = NULL;
805 BOOL rc;
807 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
809 if (lpszConnectionName && dwNameLen > 0)
810 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
812 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
813 dwReserved);
814 if (rc && lpwszConnectionName)
816 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
817 dwNameLen, NULL, NULL);
819 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
822 return rc;
826 /***********************************************************************
827 * InternetConnectW (WININET.@)
829 * Open a ftp, gopher or http session
831 * RETURNS
832 * HINTERNET a session handle on success
833 * NULL on failure
836 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
837 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
838 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
839 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
841 LPWININETAPPINFOW hIC;
842 HINTERNET rc = NULL;
844 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
845 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
846 dwService, dwFlags, dwContext);
848 if (!lpszServerName)
850 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
851 return NULL;
854 /* Clear any error information */
855 INTERNET_SetLastError(0);
856 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
857 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
859 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
860 goto lend;
863 switch (dwService)
865 case INTERNET_SERVICE_FTP:
866 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
867 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
868 break;
870 case INTERNET_SERVICE_HTTP:
871 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
872 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
873 break;
875 case INTERNET_SERVICE_GOPHER:
876 default:
877 break;
879 lend:
880 if( hIC )
881 WININET_Release( &hIC->hdr );
883 TRACE("returning %p\n", rc);
884 return rc;
888 /***********************************************************************
889 * InternetConnectA (WININET.@)
891 * Open a ftp, gopher or http session
893 * RETURNS
894 * HINTERNET a session handle on success
895 * NULL on failure
898 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
899 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
900 LPCSTR lpszUserName, LPCSTR lpszPassword,
901 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
903 HINTERNET rc = NULL;
904 INT len = 0;
905 LPWSTR szServerName = NULL;
906 LPWSTR szUserName = NULL;
907 LPWSTR szPassword = NULL;
909 if (lpszServerName)
911 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
912 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
913 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
915 if (lpszUserName)
917 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
918 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
919 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
921 if (lpszPassword)
923 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
924 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
925 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
929 rc = InternetConnectW(hInternet, szServerName, nServerPort,
930 szUserName, szPassword, dwService, dwFlags, dwContext);
932 HeapFree(GetProcessHeap(), 0, szServerName);
933 HeapFree(GetProcessHeap(), 0, szUserName);
934 HeapFree(GetProcessHeap(), 0, szPassword);
935 return rc;
939 /***********************************************************************
940 * InternetFindNextFileA (WININET.@)
942 * Continues a file search from a previous call to FindFirstFile
944 * RETURNS
945 * TRUE on success
946 * FALSE on failure
949 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
951 BOOL ret;
952 WIN32_FIND_DATAW fd;
954 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
955 if(lpvFindData)
956 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
957 return ret;
960 /***********************************************************************
961 * InternetFindNextFileW (WININET.@)
963 * Continues a file search from a previous call to FindFirstFile
965 * RETURNS
966 * TRUE on success
967 * FALSE on failure
970 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
972 WININETHANDLEHEADER *hdr;
973 DWORD res;
975 TRACE("\n");
977 hdr = WININET_GetObject(hFind);
978 if(!hdr) {
979 WARN("Invalid handle\n");
980 SetLastError(ERROR_INVALID_HANDLE);
981 return FALSE;
984 if(hdr->vtbl->FindNextFileW) {
985 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
986 }else {
987 WARN("Handle doesn't support NextFile\n");
988 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
991 WININET_Release(hdr);
993 if(res != ERROR_SUCCESS)
994 SetLastError(res);
995 return res == ERROR_SUCCESS;
998 /***********************************************************************
999 * InternetCloseHandle (WININET.@)
1001 * Generic close handle function
1003 * RETURNS
1004 * TRUE on success
1005 * FALSE on failure
1008 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1010 LPWININETHANDLEHEADER lpwh;
1012 TRACE("%p\n",hInternet);
1014 lpwh = WININET_GetObject( hInternet );
1015 if (NULL == lpwh)
1017 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1018 return FALSE;
1021 WININET_Release( lpwh );
1022 WININET_FreeHandle( hInternet );
1024 return TRUE;
1028 /***********************************************************************
1029 * ConvertUrlComponentValue (Internal)
1031 * Helper function for InternetCrackUrlW
1034 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1035 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1036 LPCSTR lpszStart, LPCWSTR lpwszStart)
1038 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1039 if (*dwComponentLen != 0)
1041 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1042 if (*lppszComponent == NULL)
1044 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1045 if (lpwszComponent)
1046 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1047 else
1048 *lppszComponent = NULL;
1049 *dwComponentLen = nASCIILength;
1051 else
1053 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1054 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1055 (*lppszComponent)[ncpylen]=0;
1056 *dwComponentLen = ncpylen;
1062 /***********************************************************************
1063 * InternetCrackUrlA (WININET.@)
1065 * See InternetCrackUrlW.
1067 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1068 LPURL_COMPONENTSA lpUrlComponents)
1070 DWORD nLength;
1071 URL_COMPONENTSW UCW;
1072 WCHAR* lpwszUrl;
1074 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1076 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1077 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1079 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1080 return FALSE;
1083 if(dwUrlLength<=0)
1084 dwUrlLength=-1;
1085 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1087 /* if dwUrlLength=-1 then nLength includes null but length to
1088 InternetCrackUrlW should not include it */
1089 if (dwUrlLength == -1) nLength--;
1091 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1092 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1094 memset(&UCW,0,sizeof(UCW));
1095 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1096 if(lpUrlComponents->dwHostNameLength!=0)
1097 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1098 if(lpUrlComponents->dwUserNameLength!=0)
1099 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1100 if(lpUrlComponents->dwPasswordLength!=0)
1101 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1102 if(lpUrlComponents->dwUrlPathLength!=0)
1103 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1104 if(lpUrlComponents->dwSchemeLength!=0)
1105 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1106 if(lpUrlComponents->dwExtraInfoLength!=0)
1107 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1108 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1110 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1111 return FALSE;
1114 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1115 UCW.lpszHostName, UCW.dwHostNameLength,
1116 lpszUrl, lpwszUrl);
1117 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1118 UCW.lpszUserName, UCW.dwUserNameLength,
1119 lpszUrl, lpwszUrl);
1120 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1121 UCW.lpszPassword, UCW.dwPasswordLength,
1122 lpszUrl, lpwszUrl);
1123 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1124 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1125 lpszUrl, lpwszUrl);
1126 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1127 UCW.lpszScheme, UCW.dwSchemeLength,
1128 lpszUrl, lpwszUrl);
1129 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1130 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1131 lpszUrl, lpwszUrl);
1132 lpUrlComponents->nScheme=UCW.nScheme;
1133 lpUrlComponents->nPort=UCW.nPort;
1134 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1136 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1137 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1138 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1139 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1140 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1142 return TRUE;
1145 static const WCHAR url_schemes[][7] =
1147 {'f','t','p',0},
1148 {'g','o','p','h','e','r',0},
1149 {'h','t','t','p',0},
1150 {'h','t','t','p','s',0},
1151 {'f','i','l','e',0},
1152 {'n','e','w','s',0},
1153 {'m','a','i','l','t','o',0},
1154 {'r','e','s',0},
1157 /***********************************************************************
1158 * GetInternetSchemeW (internal)
1160 * Get scheme of url
1162 * RETURNS
1163 * scheme on success
1164 * INTERNET_SCHEME_UNKNOWN on failure
1167 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1169 int i;
1171 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1173 if(lpszScheme==NULL)
1174 return INTERNET_SCHEME_UNKNOWN;
1176 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1177 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1178 return INTERNET_SCHEME_FIRST + i;
1180 return INTERNET_SCHEME_UNKNOWN;
1183 /***********************************************************************
1184 * SetUrlComponentValueW (Internal)
1186 * Helper function for InternetCrackUrlW
1188 * PARAMS
1189 * lppszComponent [O] Holds the returned string
1190 * dwComponentLen [I] Holds the size of lppszComponent
1191 * [O] Holds the length of the string in lppszComponent without '\0'
1192 * lpszStart [I] Holds the string to copy from
1193 * len [I] Holds the length of lpszStart without '\0'
1195 * RETURNS
1196 * TRUE on success
1197 * FALSE on failure
1200 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1202 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1204 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1205 return FALSE;
1207 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1209 if (*lppszComponent == NULL)
1211 *lppszComponent = (LPWSTR)lpszStart;
1212 *dwComponentLen = len;
1214 else
1216 DWORD ncpylen = min((*dwComponentLen)-1, len);
1217 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1218 (*lppszComponent)[ncpylen] = '\0';
1219 *dwComponentLen = ncpylen;
1223 return TRUE;
1226 /***********************************************************************
1227 * InternetCrackUrlW (WININET.@)
1229 * Break up URL into its components
1231 * RETURNS
1232 * TRUE on success
1233 * FALSE on failure
1235 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1236 LPURL_COMPONENTSW lpUC)
1239 * RFC 1808
1240 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1243 LPCWSTR lpszParam = NULL;
1244 BOOL bIsAbsolute = FALSE;
1245 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1246 LPCWSTR lpszcp = NULL;
1247 LPWSTR lpszUrl_decode = NULL;
1248 DWORD dwUrlLength = dwUrlLength_orig;
1249 const WCHAR lpszSeparators[3]={';','?',0};
1250 const WCHAR lpszSlash[2]={'/',0};
1252 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1254 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1256 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1257 return FALSE;
1259 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1261 if (dwFlags & ICU_DECODE)
1263 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1264 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1266 lpszUrl = lpszUrl_decode;
1269 lpszap = lpszUrl;
1271 /* Determine if the URI is absolute. */
1272 while (*lpszap != '\0')
1274 if (isalnumW(*lpszap))
1276 lpszap++;
1277 continue;
1279 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1281 bIsAbsolute = TRUE;
1282 lpszcp = lpszap;
1284 else
1286 lpszcp = lpszUrl; /* Relative url */
1289 break;
1292 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1293 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1295 /* Parse <params> */
1296 lpszParam = strpbrkW(lpszap, lpszSeparators);
1297 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1298 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1300 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1302 LPCWSTR lpszNetLoc;
1304 /* Get scheme first. */
1305 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1306 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1307 lpszUrl, lpszcp - lpszUrl);
1309 /* Eat ':' in protocol. */
1310 lpszcp++;
1312 /* double slash indicates the net_loc portion is present */
1313 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1315 lpszcp += 2;
1317 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1318 if (lpszParam)
1320 if (lpszNetLoc)
1321 lpszNetLoc = min(lpszNetLoc, lpszParam);
1322 else
1323 lpszNetLoc = lpszParam;
1325 else if (!lpszNetLoc)
1326 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1328 /* Parse net-loc */
1329 if (lpszNetLoc)
1331 LPCWSTR lpszHost;
1332 LPCWSTR lpszPort;
1334 /* [<user>[<:password>]@]<host>[:<port>] */
1335 /* First find the user and password if they exist */
1337 lpszHost = strchrW(lpszcp, '@');
1338 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1340 /* username and password not specified. */
1341 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1342 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1344 else /* Parse out username and password */
1346 LPCWSTR lpszUser = lpszcp;
1347 LPCWSTR lpszPasswd = lpszHost;
1349 while (lpszcp < lpszHost)
1351 if (*lpszcp == ':')
1352 lpszPasswd = lpszcp;
1354 lpszcp++;
1357 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1358 lpszUser, lpszPasswd - lpszUser);
1360 if (lpszPasswd != lpszHost)
1361 lpszPasswd++;
1362 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1363 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1364 lpszHost - lpszPasswd);
1366 lpszcp++; /* Advance to beginning of host */
1369 /* Parse <host><:port> */
1371 lpszHost = lpszcp;
1372 lpszPort = lpszNetLoc;
1374 /* special case for res:// URLs: there is no port here, so the host is the
1375 entire string up to the first '/' */
1376 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1378 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1379 lpszHost, lpszPort - lpszHost);
1380 lpszcp=lpszNetLoc;
1382 else
1384 while (lpszcp < lpszNetLoc)
1386 if (*lpszcp == ':')
1387 lpszPort = lpszcp;
1389 lpszcp++;
1392 /* If the scheme is "file" and the host is just one letter, it's not a host */
1393 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1395 lpszcp=lpszHost;
1396 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1397 NULL, 0);
1399 else
1401 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1402 lpszHost, lpszPort - lpszHost);
1403 if (lpszPort != lpszNetLoc)
1404 lpUC->nPort = atoiW(++lpszPort);
1405 else switch (lpUC->nScheme)
1407 case INTERNET_SCHEME_HTTP:
1408 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1409 break;
1410 case INTERNET_SCHEME_HTTPS:
1411 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1412 break;
1413 case INTERNET_SCHEME_FTP:
1414 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1415 break;
1416 case INTERNET_SCHEME_GOPHER:
1417 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1418 break;
1419 default:
1420 break;
1426 else
1428 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1429 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1430 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1433 else
1435 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1436 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1437 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1438 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1441 /* Here lpszcp points to:
1443 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1444 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1446 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1448 INT len;
1450 /* Only truncate the parameter list if it's already been saved
1451 * in lpUC->lpszExtraInfo.
1453 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1454 len = lpszParam - lpszcp;
1455 else
1457 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1458 * newlines if necessary.
1460 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1461 if (lpsznewline != NULL)
1462 len = lpsznewline - lpszcp;
1463 else
1464 len = dwUrlLength-(lpszcp-lpszUrl);
1466 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1467 lpszcp, len);
1469 else
1471 lpUC->dwUrlPathLength = 0;
1474 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1475 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1476 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1477 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1478 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1480 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1481 return TRUE;
1484 /***********************************************************************
1485 * InternetAttemptConnect (WININET.@)
1487 * Attempt to make a connection to the internet
1489 * RETURNS
1490 * ERROR_SUCCESS on success
1491 * Error value on failure
1494 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1496 FIXME("Stub\n");
1497 return ERROR_SUCCESS;
1501 /***********************************************************************
1502 * InternetCanonicalizeUrlA (WININET.@)
1504 * Escape unsafe characters and spaces
1506 * RETURNS
1507 * TRUE on success
1508 * FALSE on failure
1511 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1512 LPDWORD lpdwBufferLength, DWORD dwFlags)
1514 HRESULT hr;
1515 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1517 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1518 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1520 if(dwFlags & ICU_DECODE)
1522 dwURLFlags |= URL_UNESCAPE;
1523 dwFlags &= ~ICU_DECODE;
1526 if(dwFlags & ICU_ESCAPE)
1528 dwURLFlags |= URL_UNESCAPE;
1529 dwFlags &= ~ICU_ESCAPE;
1532 if(dwFlags & ICU_BROWSER_MODE)
1534 dwURLFlags |= URL_BROWSER_MODE;
1535 dwFlags &= ~ICU_BROWSER_MODE;
1538 if(dwFlags & ICU_NO_ENCODE)
1540 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1541 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1542 dwFlags &= ~ICU_NO_ENCODE;
1545 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1547 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1548 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1549 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1551 return (hr == S_OK) ? TRUE : FALSE;
1554 /***********************************************************************
1555 * InternetCanonicalizeUrlW (WININET.@)
1557 * Escape unsafe characters and spaces
1559 * RETURNS
1560 * TRUE on success
1561 * FALSE on failure
1564 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1565 LPDWORD lpdwBufferLength, DWORD dwFlags)
1567 HRESULT hr;
1568 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1570 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1571 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1573 if(dwFlags & ICU_DECODE)
1575 dwURLFlags |= URL_UNESCAPE;
1576 dwFlags &= ~ICU_DECODE;
1579 if(dwFlags & ICU_ESCAPE)
1581 dwURLFlags |= URL_UNESCAPE;
1582 dwFlags &= ~ICU_ESCAPE;
1585 if(dwFlags & ICU_BROWSER_MODE)
1587 dwURLFlags |= URL_BROWSER_MODE;
1588 dwFlags &= ~ICU_BROWSER_MODE;
1591 if(dwFlags & ICU_NO_ENCODE)
1593 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1594 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1595 dwFlags &= ~ICU_NO_ENCODE;
1598 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1600 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1601 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1602 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1604 return (hr == S_OK) ? TRUE : FALSE;
1607 /* #################################################### */
1609 static INTERNET_STATUS_CALLBACK set_status_callback(
1610 LPWININETHANDLEHEADER lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1612 INTERNET_STATUS_CALLBACK ret;
1614 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1615 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1617 ret = lpwh->lpfnStatusCB;
1618 lpwh->lpfnStatusCB = callback;
1620 return ret;
1623 /***********************************************************************
1624 * InternetSetStatusCallbackA (WININET.@)
1626 * Sets up a callback function which is called as progress is made
1627 * during an operation.
1629 * RETURNS
1630 * Previous callback or NULL on success
1631 * INTERNET_INVALID_STATUS_CALLBACK on failure
1634 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1635 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1637 INTERNET_STATUS_CALLBACK retVal;
1638 LPWININETHANDLEHEADER lpwh;
1640 TRACE("0x%08x\n", (ULONG)hInternet);
1642 if (!(lpwh = WININET_GetObject(hInternet)))
1643 return INTERNET_INVALID_STATUS_CALLBACK;
1645 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1647 WININET_Release( lpwh );
1648 return retVal;
1651 /***********************************************************************
1652 * InternetSetStatusCallbackW (WININET.@)
1654 * Sets up a callback function which is called as progress is made
1655 * during an operation.
1657 * RETURNS
1658 * Previous callback or NULL on success
1659 * INTERNET_INVALID_STATUS_CALLBACK on failure
1662 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1663 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1665 INTERNET_STATUS_CALLBACK retVal;
1666 LPWININETHANDLEHEADER lpwh;
1668 TRACE("0x%08x\n", (ULONG)hInternet);
1670 if (!(lpwh = WININET_GetObject(hInternet)))
1671 return INTERNET_INVALID_STATUS_CALLBACK;
1673 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
1675 WININET_Release( lpwh );
1676 return retVal;
1679 /***********************************************************************
1680 * InternetSetFilePointer (WININET.@)
1682 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1683 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
1685 FIXME("stub\n");
1686 return FALSE;
1689 /***********************************************************************
1690 * InternetWriteFile (WININET.@)
1692 * Write data to an open internet file
1694 * RETURNS
1695 * TRUE on success
1696 * FALSE on failure
1699 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
1700 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1702 LPWININETHANDLEHEADER lpwh;
1703 BOOL retval = FALSE;
1705 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1707 lpwh = WININET_GetObject( hFile );
1709 if(lpwh && lpwh->vtbl->WriteFile) {
1710 retval = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1711 }else {
1712 WARN("Invalid handle\n");
1713 SetLastError(ERROR_INVALID_HANDLE);
1714 retval = FALSE;
1717 WININET_Release( lpwh );
1719 return retval;
1723 /***********************************************************************
1724 * InternetReadFile (WININET.@)
1726 * Read data from an open internet file
1728 * RETURNS
1729 * TRUE on success
1730 * FALSE on failure
1733 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1734 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1736 LPWININETHANDLEHEADER hdr;
1737 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1739 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1741 hdr = WININET_GetObject(hFile);
1742 if (!hdr) {
1743 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1744 return FALSE;
1747 if(hdr->vtbl->ReadFile)
1748 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1750 WININET_Release(hdr);
1752 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
1753 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1755 if(res != ERROR_SUCCESS)
1756 SetLastError(res);
1757 return res == ERROR_SUCCESS;
1760 /***********************************************************************
1761 * InternetReadFileExA (WININET.@)
1763 * Read data from an open internet file
1765 * PARAMS
1766 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1767 * lpBuffersOut [I/O] Buffer.
1768 * dwFlags [I] Flags. See notes.
1769 * dwContext [I] Context for callbacks.
1771 * RETURNS
1772 * TRUE on success
1773 * FALSE on failure
1775 * NOTES
1776 * The parameter dwFlags include zero or more of the following flags:
1777 *|IRF_ASYNC - Makes the call asynchronous.
1778 *|IRF_SYNC - Makes the call synchronous.
1779 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1780 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1782 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1784 * SEE
1785 * InternetOpenUrlA(), HttpOpenRequestA()
1787 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1788 DWORD dwFlags, DWORD_PTR dwContext)
1790 LPWININETHANDLEHEADER hdr;
1791 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1793 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1795 hdr = WININET_GetObject(hFile);
1796 if (!hdr) {
1797 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1798 return FALSE;
1801 if(hdr->vtbl->ReadFileExA)
1802 res = hdr->vtbl->ReadFileExA(hdr, lpBuffersOut, dwFlags, dwContext);
1804 WININET_Release(hdr);
1806 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
1807 res, lpBuffersOut->dwBufferLength);
1809 if(res != ERROR_SUCCESS)
1810 SetLastError(res);
1811 return res == ERROR_SUCCESS;
1814 /***********************************************************************
1815 * InternetReadFileExW (WININET.@)
1817 * Read data from an open internet file.
1819 * PARAMS
1820 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1821 * lpBuffersOut [I/O] Buffer.
1822 * dwFlags [I] Flags.
1823 * dwContext [I] Context for callbacks.
1825 * RETURNS
1826 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1828 * NOTES
1829 * Not implemented in Wine or native either (as of IE6 SP2).
1832 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1833 DWORD dwFlags, DWORD_PTR dwContext)
1835 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1837 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1838 return FALSE;
1841 /***********************************************************************
1842 * INET_QueryOptionHelper (internal)
1844 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1845 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1847 LPWININETHANDLEHEADER lpwhh;
1848 BOOL bSuccess = FALSE;
1850 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1852 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1854 switch (dwOption)
1856 case INTERNET_OPTION_REQUEST_FLAGS:
1858 ULONG flags = 4;
1859 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
1860 if (*lpdwBufferLength < sizeof(ULONG))
1861 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1862 else
1864 memcpy(lpBuffer, &flags, sizeof(ULONG));
1865 bSuccess = TRUE;
1867 *lpdwBufferLength = sizeof(ULONG);
1868 break;
1871 case INTERNET_OPTION_USER_AGENT:
1872 FIXME("INTERNET_OPTION_USER_AGENT\n");
1873 break;
1875 case INTERNET_OPTION_DATAFILE_NAME:
1877 TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
1878 if (!lpwhh)
1880 WARN("Invalid hInternet handle\n");
1881 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1882 return FALSE;
1884 if (lpwhh->htype == WH_HHTTPREQ)
1886 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
1887 DWORD size;
1889 if(!lpreq->lpszCacheFile) {
1890 *lpdwBufferLength = 0;
1891 INTERNET_SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
1893 else if(bIsUnicode)
1895 size = (lstrlenW(lpreq->lpszCacheFile)+1) * sizeof(WCHAR);
1896 if (*lpdwBufferLength < size)
1897 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1898 else
1900 memcpy(lpBuffer, lpreq->lpszCacheFile, size);
1901 bSuccess = TRUE;
1903 *lpdwBufferLength = size;
1905 else
1907 size = WideCharToMultiByte(CP_ACP, 0, lpreq->lpszCacheFile, -1, NULL, 0, NULL, NULL);
1908 if (size > *lpdwBufferLength) {
1909 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1910 }else {
1911 *lpdwBufferLength = WideCharToMultiByte(CP_ACP, 0, lpreq->lpszCacheFile,
1912 -1, lpBuffer, *lpdwBufferLength, NULL, NULL);
1913 bSuccess = TRUE;
1917 break;
1920 case INTERNET_OPTION_HTTP_VERSION:
1922 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
1923 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1924 else
1927 * Presently hardcoded to 1.1
1929 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
1930 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
1931 bSuccess = TRUE;
1933 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
1934 break;
1936 case INTERNET_OPTION_CONNECTED_STATE:
1938 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
1939 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
1941 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
1942 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1943 else
1945 *pdwConnectedState = INTERNET_STATE_CONNECTED;
1946 bSuccess = TRUE;
1948 *lpdwBufferLength = sizeof(*pdwConnectedState);
1949 break;
1951 case INTERNET_OPTION_PROXY:
1953 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
1954 WININETAPPINFOW wai;
1956 if (lpwai == NULL)
1958 TRACE("Getting global proxy info\n");
1959 memset(&wai, 0, sizeof(WININETAPPINFOW));
1960 INTERNET_ConfigureProxyFromReg( &wai );
1961 lpwai = &wai;
1964 if (bIsUnicode)
1966 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
1967 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
1969 if (lpwai->lpszProxy)
1970 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
1971 sizeof(WCHAR);
1972 if (lpwai->lpszProxyBypass)
1973 proxyBypassBytesRequired =
1974 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
1975 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
1976 proxyBytesRequired + proxyBypassBytesRequired)
1977 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1978 else
1980 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
1981 sizeof(INTERNET_PROXY_INFOW));
1982 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
1983 sizeof(INTERNET_PROXY_INFOW) +
1984 proxyBytesRequired);
1986 pPI->dwAccessType = lpwai->dwAccessType;
1987 pPI->lpszProxy = NULL;
1988 pPI->lpszProxyBypass = NULL;
1989 if (lpwai->lpszProxy)
1991 lstrcpyW(proxy, lpwai->lpszProxy);
1992 pPI->lpszProxy = proxy;
1995 if (lpwai->lpszProxyBypass)
1997 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
1998 pPI->lpszProxyBypass = proxy_bypass;
2000 bSuccess = TRUE;
2002 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2003 proxyBytesRequired + proxyBypassBytesRequired;
2005 else
2007 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2008 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2010 if (lpwai->lpszProxy)
2011 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2012 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2013 if (lpwai->lpszProxyBypass)
2014 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2015 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2016 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2017 proxyBytesRequired + proxyBypassBytesRequired)
2018 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2019 else
2021 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2022 sizeof(INTERNET_PROXY_INFOA));
2023 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2024 sizeof(INTERNET_PROXY_INFOA) +
2025 proxyBytesRequired);
2027 pPI->dwAccessType = lpwai->dwAccessType;
2028 pPI->lpszProxy = NULL;
2029 pPI->lpszProxyBypass = NULL;
2030 if (lpwai->lpszProxy)
2032 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2033 proxy, proxyBytesRequired, NULL, NULL);
2034 pPI->lpszProxy = proxy;
2037 if (lpwai->lpszProxyBypass)
2039 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2040 -1, proxy_bypass, proxyBypassBytesRequired,
2041 NULL, NULL);
2042 pPI->lpszProxyBypass = proxy_bypass;
2044 bSuccess = TRUE;
2046 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2047 proxyBytesRequired + proxyBypassBytesRequired;
2049 break;
2051 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2053 ULONG conn = 2;
2054 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2055 if (*lpdwBufferLength < sizeof(ULONG))
2056 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2057 else
2059 memcpy(lpBuffer, &conn, sizeof(ULONG));
2060 bSuccess = TRUE;
2062 *lpdwBufferLength = sizeof(ULONG);
2063 break;
2065 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2067 ULONG conn = 4;
2068 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2069 if (*lpdwBufferLength < sizeof(ULONG))
2070 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2071 else
2073 memcpy(lpBuffer, &conn, sizeof(ULONG));
2074 bSuccess = TRUE;
2076 *lpdwBufferLength = sizeof(ULONG);
2077 break;
2079 case INTERNET_OPTION_SECURITY_FLAGS:
2080 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2081 bSuccess = TRUE;
2082 break;
2084 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2085 if (!lpwhh)
2087 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2088 return FALSE;
2090 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2092 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2093 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2095 else if (lpwhh->htype == WH_HHTTPREQ)
2097 LPWININETHTTPREQW lpwhr;
2098 PCCERT_CONTEXT context;
2100 lpwhr = (LPWININETHTTPREQW)lpwhh;
2101 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2102 if (context)
2104 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2105 DWORD strLen;
2107 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2108 info->ftExpiry = context->pCertInfo->NotAfter;
2109 info->ftStart = context->pCertInfo->NotBefore;
2110 if (bIsUnicode)
2112 strLen = CertNameToStrW(context->dwCertEncodingType,
2113 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2114 NULL, 0);
2115 info->lpszSubjectInfo = LocalAlloc(0,
2116 strLen * sizeof(WCHAR));
2117 if (info->lpszSubjectInfo)
2118 CertNameToStrW(context->dwCertEncodingType,
2119 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2120 info->lpszSubjectInfo, strLen);
2121 strLen = CertNameToStrW(context->dwCertEncodingType,
2122 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2123 NULL, 0);
2124 info->lpszIssuerInfo = LocalAlloc(0,
2125 strLen * sizeof(WCHAR));
2126 if (info->lpszIssuerInfo)
2127 CertNameToStrW(context->dwCertEncodingType,
2128 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2129 info->lpszIssuerInfo, strLen);
2131 else
2133 LPINTERNET_CERTIFICATE_INFOA infoA =
2134 (LPINTERNET_CERTIFICATE_INFOA)info;
2136 strLen = CertNameToStrA(context->dwCertEncodingType,
2137 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2138 NULL, 0);
2139 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2140 if (infoA->lpszSubjectInfo)
2141 CertNameToStrA(context->dwCertEncodingType,
2142 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2143 infoA->lpszSubjectInfo, strLen);
2144 strLen = CertNameToStrA(context->dwCertEncodingType,
2145 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2146 NULL, 0);
2147 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2148 if (infoA->lpszIssuerInfo)
2149 CertNameToStrA(context->dwCertEncodingType,
2150 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2151 infoA->lpszIssuerInfo, strLen);
2154 * Contrary to MSDN, these do not appear to be set.
2155 * lpszProtocolName
2156 * lpszSignatureAlgName
2157 * lpszEncryptionAlgName
2158 * dwKeySize
2160 CertFreeCertificateContext(context);
2161 bSuccess = TRUE;
2164 break;
2165 case INTERNET_OPTION_VERSION:
2167 TRACE("INTERNET_OPTION_VERSION\n");
2168 if (*lpdwBufferLength < sizeof(INTERNET_VERSION_INFO))
2169 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2170 else
2172 static const INTERNET_VERSION_INFO info = { 1, 2 };
2173 memcpy(lpBuffer, &info, sizeof(info));
2174 *lpdwBufferLength = sizeof(info);
2175 bSuccess = TRUE;
2177 break;
2179 case INTERNET_OPTION_PER_CONNECTION_OPTION:
2180 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2181 if (*lpdwBufferLength < sizeof(INTERNET_PER_CONN_OPTION_LISTW))
2182 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2183 else
2185 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2186 int x;
2187 bSuccess = TRUE;
2188 for (x = 0; x < con->dwOptionCount; ++x)
2190 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + x;
2191 switch (option->dwOption)
2193 case INTERNET_PER_CONN_FLAGS:
2194 option->Value.dwValue = PROXY_TYPE_DIRECT;
2195 break;
2197 case INTERNET_PER_CONN_PROXY_SERVER:
2198 case INTERNET_PER_CONN_PROXY_BYPASS:
2199 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2200 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2201 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2202 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2203 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2204 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2205 FIXME("Unhandled dwOption %d\n", option->dwOption);
2206 option->Value.dwValue = 0;
2207 bSuccess = FALSE;
2208 break;
2210 default:
2211 FIXME("Unknown dwOption %d\n", option->dwOption);
2212 bSuccess = FALSE;
2213 break;
2216 if (!bSuccess)
2217 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2219 break;
2220 case 66:
2221 FIXME("66\n");
2222 bSuccess = TRUE;
2223 break;
2224 default: {
2225 if(lpwhh) {
2226 DWORD res;
2228 res = lpwhh->vtbl->QueryOption(lpwhh, dwOption, lpBuffer, lpdwBufferLength, bIsUnicode);
2229 if(res == ERROR_SUCCESS)
2230 bSuccess = TRUE;
2231 else
2232 SetLastError(res);
2233 }else {
2234 FIXME("Stub! %d\n", dwOption);
2235 break;
2239 if (lpwhh)
2240 WININET_Release( lpwhh );
2242 return bSuccess;
2245 /***********************************************************************
2246 * InternetQueryOptionW (WININET.@)
2248 * Queries an options on the specified handle
2250 * RETURNS
2251 * TRUE on success
2252 * FALSE on failure
2255 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2256 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2258 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2261 /***********************************************************************
2262 * InternetQueryOptionA (WININET.@)
2264 * Queries an options on the specified handle
2266 * RETURNS
2267 * TRUE on success
2268 * FALSE on failure
2271 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2272 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2274 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2278 /***********************************************************************
2279 * InternetSetOptionW (WININET.@)
2281 * Sets an options on the specified handle
2283 * RETURNS
2284 * TRUE on success
2285 * FALSE on failure
2288 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2289 LPVOID lpBuffer, DWORD dwBufferLength)
2291 LPWININETHANDLEHEADER lpwhh;
2292 BOOL ret = TRUE;
2294 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2296 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2297 if(lpwhh && lpwhh->vtbl->SetOption) {
2298 DWORD res;
2300 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2301 if(res != ERROR_INTERNET_INVALID_OPTION) {
2302 WININET_Release( lpwhh );
2304 if(res != ERROR_SUCCESS)
2305 SetLastError(res);
2307 return res == ERROR_SUCCESS;
2311 switch (dwOption)
2313 case INTERNET_OPTION_CALLBACK:
2315 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2316 ret = (set_status_callback(lpwhh, callback, TRUE) != INTERNET_INVALID_STATUS_CALLBACK);
2317 break;
2319 case INTERNET_OPTION_HTTP_VERSION:
2321 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2322 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2324 break;
2325 case INTERNET_OPTION_ERROR_MASK:
2327 unsigned long flags=*(unsigned long*)lpBuffer;
2328 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2330 break;
2331 case INTERNET_OPTION_CODEPAGE:
2333 unsigned long codepage=*(unsigned long*)lpBuffer;
2334 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2336 break;
2337 case INTERNET_OPTION_REQUEST_PRIORITY:
2339 unsigned long priority=*(unsigned long*)lpBuffer;
2340 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2342 break;
2343 case INTERNET_OPTION_CONNECT_TIMEOUT:
2345 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2346 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2348 break;
2349 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2351 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2352 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2354 break;
2355 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2357 unsigned long conns=*(unsigned long*)lpBuffer;
2358 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2360 break;
2361 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2363 unsigned long conns=*(unsigned long*)lpBuffer;
2364 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2366 break;
2367 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2368 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2369 break;
2370 case INTERNET_OPTION_END_BROWSER_SESSION:
2371 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2372 break;
2373 case INTERNET_OPTION_CONNECTED_STATE:
2374 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2375 break;
2376 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2377 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2378 break;
2379 case INTERNET_OPTION_SEND_TIMEOUT:
2380 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2381 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2382 break;
2383 case INTERNET_OPTION_CONNECT_RETRIES:
2384 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2385 break;
2386 case INTERNET_OPTION_CONTEXT_VALUE:
2387 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2388 break;
2389 case INTERNET_OPTION_SECURITY_FLAGS:
2390 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2391 break;
2392 case 86:
2393 FIXME("86\n");
2394 break;
2395 default:
2396 FIXME("Option %d STUB\n",dwOption);
2397 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2398 ret = FALSE;
2399 break;
2402 if(lpwhh)
2403 WININET_Release( lpwhh );
2405 return ret;
2409 /***********************************************************************
2410 * InternetSetOptionA (WININET.@)
2412 * Sets an options on the specified handle.
2414 * RETURNS
2415 * TRUE on success
2416 * FALSE on failure
2419 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2420 LPVOID lpBuffer, DWORD dwBufferLength)
2422 LPVOID wbuffer;
2423 DWORD wlen;
2424 BOOL r;
2426 switch( dwOption )
2428 case INTERNET_OPTION_CALLBACK:
2430 LPWININETHANDLEHEADER lpwh;
2431 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2433 if (!(lpwh = WININET_GetObject(hInternet))) return FALSE;
2434 r = (set_status_callback(lpwh, callback, FALSE) != INTERNET_INVALID_STATUS_CALLBACK);
2435 WININET_Release(lpwh);
2436 return r;
2438 case INTERNET_OPTION_PROXY:
2440 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2441 LPINTERNET_PROXY_INFOW piw;
2442 DWORD proxlen, prbylen;
2443 LPWSTR prox, prby;
2445 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2446 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2447 wlen = sizeof(*piw) + proxlen + prbylen;
2448 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2449 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2450 piw->dwAccessType = pi->dwAccessType;
2451 prox = (LPWSTR) &piw[1];
2452 prby = &prox[proxlen+1];
2453 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2454 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2455 piw->lpszProxy = prox;
2456 piw->lpszProxyBypass = prby;
2458 break;
2459 case INTERNET_OPTION_USER_AGENT:
2460 case INTERNET_OPTION_USERNAME:
2461 case INTERNET_OPTION_PASSWORD:
2462 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2463 NULL, 0 );
2464 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2465 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2466 wbuffer, wlen );
2467 break;
2468 default:
2469 wbuffer = lpBuffer;
2470 wlen = dwBufferLength;
2473 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2475 if( lpBuffer != wbuffer )
2476 HeapFree( GetProcessHeap(), 0, wbuffer );
2478 return r;
2482 /***********************************************************************
2483 * InternetSetOptionExA (WININET.@)
2485 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2486 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2488 FIXME("Flags %08x ignored\n", dwFlags);
2489 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2492 /***********************************************************************
2493 * InternetSetOptionExW (WININET.@)
2495 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2496 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2498 FIXME("Flags %08x ignored\n", dwFlags);
2499 if( dwFlags & ~ISO_VALID_FLAGS )
2501 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2502 return FALSE;
2504 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2507 static const WCHAR WININET_wkday[7][4] =
2508 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2509 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2510 static const WCHAR WININET_month[12][4] =
2511 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2512 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2513 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2515 /***********************************************************************
2516 * InternetTimeFromSystemTimeA (WININET.@)
2518 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2520 BOOL ret;
2521 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2523 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2525 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2526 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2528 return ret;
2531 /***********************************************************************
2532 * InternetTimeFromSystemTimeW (WININET.@)
2534 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2536 static const WCHAR date[] =
2537 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2538 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2540 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2542 if (!time || !string) return FALSE;
2544 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2545 return FALSE;
2547 sprintfW( string, date,
2548 WININET_wkday[time->wDayOfWeek],
2549 time->wDay,
2550 WININET_month[time->wMonth - 1],
2551 time->wYear,
2552 time->wHour,
2553 time->wMinute,
2554 time->wSecond );
2556 return TRUE;
2559 /***********************************************************************
2560 * InternetTimeToSystemTimeA (WININET.@)
2562 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2564 BOOL ret = FALSE;
2565 WCHAR *stringW;
2566 int len;
2568 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2570 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2571 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2573 if (stringW)
2575 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2576 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2577 HeapFree( GetProcessHeap(), 0, stringW );
2579 return ret;
2582 /***********************************************************************
2583 * InternetTimeToSystemTimeW (WININET.@)
2585 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2587 unsigned int i;
2588 const WCHAR *s = string;
2589 WCHAR *end;
2591 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2593 if (!string || !time) return FALSE;
2595 /* Windows does this too */
2596 GetSystemTime( time );
2598 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2599 * a SYSTEMTIME structure.
2602 while (*s && !isalphaW( *s )) s++;
2603 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2604 time->wDayOfWeek = 7;
2606 for (i = 0; i < 7; i++)
2608 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2609 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2610 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2612 time->wDayOfWeek = i;
2613 break;
2617 if (time->wDayOfWeek > 6) return TRUE;
2618 while (*s && !isdigitW( *s )) s++;
2619 time->wDay = strtolW( s, &end, 10 );
2620 s = end;
2622 while (*s && !isalphaW( *s )) s++;
2623 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2624 time->wMonth = 0;
2626 for (i = 0; i < 12; i++)
2628 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2629 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2630 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2632 time->wMonth = i + 1;
2633 break;
2636 if (time->wMonth == 0) return TRUE;
2638 while (*s && !isdigitW( *s )) s++;
2639 if (*s == '\0') return TRUE;
2640 time->wYear = strtolW( s, &end, 10 );
2641 s = end;
2643 while (*s && !isdigitW( *s )) s++;
2644 if (*s == '\0') return TRUE;
2645 time->wHour = strtolW( s, &end, 10 );
2646 s = end;
2648 while (*s && !isdigitW( *s )) s++;
2649 if (*s == '\0') return TRUE;
2650 time->wMinute = strtolW( s, &end, 10 );
2651 s = end;
2653 while (*s && !isdigitW( *s )) s++;
2654 if (*s == '\0') return TRUE;
2655 time->wSecond = strtolW( s, &end, 10 );
2656 s = end;
2658 time->wMilliseconds = 0;
2659 return TRUE;
2662 /***********************************************************************
2663 * InternetCheckConnectionW (WININET.@)
2665 * Pings a requested host to check internet connection
2667 * RETURNS
2668 * TRUE on success and FALSE on failure. If a failure then
2669 * ERROR_NOT_CONNECTED is placed into GetLastError
2672 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2675 * this is a kludge which runs the resident ping program and reads the output.
2677 * Anyone have a better idea?
2680 BOOL rc = FALSE;
2681 static const CHAR ping[] = "ping -c 1 ";
2682 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2683 CHAR *command = NULL;
2684 WCHAR hostW[1024];
2685 DWORD len;
2686 INTERNET_PORT port;
2687 int status = -1;
2689 FIXME("\n");
2692 * Crack or set the Address
2694 if (lpszUrl == NULL)
2697 * According to the doc we are supposed to use the ip for the next
2698 * server in the WnInet internal server database. I have
2699 * no idea what that is or how to get it.
2701 * So someone needs to implement this.
2703 FIXME("Unimplemented with URL of NULL\n");
2704 return TRUE;
2706 else
2708 URL_COMPONENTSW components;
2710 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2711 components.lpszHostName = (LPWSTR)&hostW;
2712 components.dwHostNameLength = 1024;
2714 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2715 goto End;
2717 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2718 port = components.nPort;
2719 TRACE("port: %d\n", port);
2722 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
2724 struct sockaddr_in sin;
2725 int fd;
2727 if (!GetAddress(hostW, port, &sin))
2728 goto End;
2729 fd = socket(sin.sin_family, SOCK_STREAM, 0);
2730 if (fd != -1)
2732 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == 0)
2733 rc = TRUE;
2734 close(fd);
2737 else
2740 * Build our ping command
2742 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2743 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2744 strcpy(command,ping);
2745 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2746 strcat(command,redirect);
2748 TRACE("Ping command is : %s\n",command);
2750 status = system(command);
2752 TRACE("Ping returned a code of %i\n",status);
2754 /* Ping return code of 0 indicates success */
2755 if (status == 0)
2756 rc = TRUE;
2759 End:
2761 HeapFree( GetProcessHeap(), 0, command );
2762 if (rc == FALSE)
2763 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2765 return rc;
2769 /***********************************************************************
2770 * InternetCheckConnectionA (WININET.@)
2772 * Pings a requested host to check internet connection
2774 * RETURNS
2775 * TRUE on success and FALSE on failure. If a failure then
2776 * ERROR_NOT_CONNECTED is placed into GetLastError
2779 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2781 WCHAR *szUrl;
2782 INT len;
2783 BOOL rc;
2785 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2786 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2787 return FALSE;
2788 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2789 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2790 HeapFree(GetProcessHeap(), 0, szUrl);
2792 return rc;
2796 /**********************************************************
2797 * INTERNET_InternetOpenUrlW (internal)
2799 * Opens an URL
2801 * RETURNS
2802 * handle of connection or NULL on failure
2804 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2805 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2807 URL_COMPONENTSW urlComponents;
2808 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2809 WCHAR password[1024], path[2048], extra[1024];
2810 HINTERNET client = NULL, client1 = NULL;
2812 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2813 dwHeadersLength, dwFlags, dwContext);
2815 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2816 urlComponents.lpszScheme = protocol;
2817 urlComponents.dwSchemeLength = 32;
2818 urlComponents.lpszHostName = hostName;
2819 urlComponents.dwHostNameLength = MAXHOSTNAME;
2820 urlComponents.lpszUserName = userName;
2821 urlComponents.dwUserNameLength = 1024;
2822 urlComponents.lpszPassword = password;
2823 urlComponents.dwPasswordLength = 1024;
2824 urlComponents.lpszUrlPath = path;
2825 urlComponents.dwUrlPathLength = 2048;
2826 urlComponents.lpszExtraInfo = extra;
2827 urlComponents.dwExtraInfoLength = 1024;
2828 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2829 return NULL;
2830 switch(urlComponents.nScheme) {
2831 case INTERNET_SCHEME_FTP:
2832 if(urlComponents.nPort == 0)
2833 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2834 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2835 userName, password, dwFlags, dwContext, INET_OPENURL);
2836 if(client == NULL)
2837 break;
2838 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2839 if(client1 == NULL) {
2840 InternetCloseHandle(client);
2841 break;
2843 break;
2845 case INTERNET_SCHEME_HTTP:
2846 case INTERNET_SCHEME_HTTPS: {
2847 static const WCHAR szStars[] = { '*','/','*', 0 };
2848 LPCWSTR accept[2] = { szStars, NULL };
2849 if(urlComponents.nPort == 0) {
2850 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2851 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2852 else
2853 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2855 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2856 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2857 userName, password, dwFlags, dwContext, INET_OPENURL);
2858 if(client == NULL)
2859 break;
2861 if (urlComponents.dwExtraInfoLength) {
2862 WCHAR *path_extra;
2863 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
2865 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
2867 InternetCloseHandle(client);
2868 break;
2870 strcpyW(path_extra, urlComponents.lpszUrlPath);
2871 strcatW(path_extra, urlComponents.lpszExtraInfo);
2872 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
2873 HeapFree(GetProcessHeap(), 0, path_extra);
2875 else
2876 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2878 if(client1 == NULL) {
2879 InternetCloseHandle(client);
2880 break;
2882 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2883 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2884 GetLastError() != ERROR_IO_PENDING) {
2885 InternetCloseHandle(client1);
2886 client1 = NULL;
2887 break;
2890 case INTERNET_SCHEME_GOPHER:
2891 /* gopher doesn't seem to be implemented in wine, but it's supposed
2892 * to be supported by InternetOpenUrlA. */
2893 default:
2894 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2895 break;
2898 TRACE(" %p <--\n", client1);
2900 return client1;
2903 /**********************************************************
2904 * InternetOpenUrlW (WININET.@)
2906 * Opens an URL
2908 * RETURNS
2909 * handle of connection or NULL on failure
2911 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
2913 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
2914 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
2916 TRACE("%p\n", hIC);
2918 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
2919 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2920 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2921 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2924 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2925 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2927 HINTERNET ret = NULL;
2928 LPWININETAPPINFOW hIC = NULL;
2930 if (TRACE_ON(wininet)) {
2931 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2932 dwHeadersLength, dwFlags, dwContext);
2933 TRACE(" flags :");
2934 dump_INTERNET_FLAGS(dwFlags);
2937 if (!lpszUrl)
2939 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2940 goto lend;
2943 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2944 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2945 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2946 goto lend;
2949 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2950 WORKREQUEST workRequest;
2951 struct WORKREQ_INTERNETOPENURLW *req;
2953 workRequest.asyncproc = AsyncInternetOpenUrlProc;
2954 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2955 req = &workRequest.u.InternetOpenUrlW;
2956 req->lpszUrl = WININET_strdupW(lpszUrl);
2957 if (lpszHeaders)
2958 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2959 else
2960 req->lpszHeaders = 0;
2961 req->dwHeadersLength = dwHeadersLength;
2962 req->dwFlags = dwFlags;
2963 req->dwContext = dwContext;
2965 INTERNET_AsyncCall(&workRequest);
2967 * This is from windows.
2969 INTERNET_SetLastError(ERROR_IO_PENDING);
2970 } else {
2971 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2974 lend:
2975 if( hIC )
2976 WININET_Release( &hIC->hdr );
2977 TRACE(" %p <--\n", ret);
2979 return ret;
2982 /**********************************************************
2983 * InternetOpenUrlA (WININET.@)
2985 * Opens an URL
2987 * RETURNS
2988 * handle of connection or NULL on failure
2990 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2991 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2993 HINTERNET rc = NULL;
2995 INT lenUrl;
2996 INT lenHeaders = 0;
2997 LPWSTR szUrl = NULL;
2998 LPWSTR szHeaders = NULL;
3000 TRACE("\n");
3002 if(lpszUrl) {
3003 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3004 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3005 if(!szUrl)
3006 return NULL;
3007 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3010 if(lpszHeaders) {
3011 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3012 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3013 if(!szHeaders) {
3014 HeapFree(GetProcessHeap(), 0, szUrl);
3015 return NULL;
3017 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3020 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3021 lenHeaders, dwFlags, dwContext);
3023 HeapFree(GetProcessHeap(), 0, szUrl);
3024 HeapFree(GetProcessHeap(), 0, szHeaders);
3026 return rc;
3030 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3032 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3034 if (lpwite)
3036 lpwite->dwError = 0;
3037 lpwite->response[0] = '\0';
3040 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3042 HeapFree(GetProcessHeap(), 0, lpwite);
3043 return NULL;
3046 return lpwite;
3050 /***********************************************************************
3051 * INTERNET_SetLastError (internal)
3053 * Set last thread specific error
3055 * RETURNS
3058 void INTERNET_SetLastError(DWORD dwError)
3060 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3062 if (!lpwite)
3063 lpwite = INTERNET_AllocThreadError();
3065 SetLastError(dwError);
3066 if(lpwite)
3067 lpwite->dwError = dwError;
3071 /***********************************************************************
3072 * INTERNET_GetLastError (internal)
3074 * Get last thread specific error
3076 * RETURNS
3079 DWORD INTERNET_GetLastError(void)
3081 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3082 if (!lpwite) return 0;
3083 /* TlsGetValue clears last error, so set it again here */
3084 SetLastError(lpwite->dwError);
3085 return lpwite->dwError;
3089 /***********************************************************************
3090 * INTERNET_WorkerThreadFunc (internal)
3092 * Worker thread execution function
3094 * RETURNS
3097 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3099 LPWORKREQUEST lpRequest = lpvParam;
3100 WORKREQUEST workRequest;
3102 TRACE("\n");
3104 memcpy(&workRequest, lpRequest, sizeof(WORKREQUEST));
3105 HeapFree(GetProcessHeap(), 0, lpRequest);
3107 workRequest.asyncproc(&workRequest);
3109 WININET_Release( workRequest.hdr );
3110 return TRUE;
3114 /***********************************************************************
3115 * INTERNET_AsyncCall (internal)
3117 * Retrieves work request from queue
3119 * RETURNS
3122 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3124 BOOL bSuccess;
3125 LPWORKREQUEST lpNewRequest;
3127 TRACE("\n");
3129 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3130 if (!lpNewRequest)
3131 return FALSE;
3133 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3135 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3136 if (!bSuccess)
3138 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3139 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3142 return bSuccess;
3146 /***********************************************************************
3147 * INTERNET_GetResponseBuffer (internal)
3149 * RETURNS
3152 LPSTR INTERNET_GetResponseBuffer(void)
3154 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3155 if (!lpwite)
3156 lpwite = INTERNET_AllocThreadError();
3157 TRACE("\n");
3158 return lpwite->response;
3161 /***********************************************************************
3162 * INTERNET_GetNextLine (internal)
3164 * Parse next line in directory string listing
3166 * RETURNS
3167 * Pointer to beginning of next line
3168 * NULL on failure
3172 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3174 struct timeval tv;
3175 fd_set infd;
3176 BOOL bSuccess = FALSE;
3177 INT nRecv = 0;
3178 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3180 TRACE("\n");
3182 FD_ZERO(&infd);
3183 FD_SET(nSocket, &infd);
3184 tv.tv_sec=RESPONSE_TIMEOUT;
3185 tv.tv_usec=0;
3187 while (nRecv < MAX_REPLY_LEN)
3189 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3191 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3193 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3194 goto lend;
3197 if (lpszBuffer[nRecv] == '\n')
3199 bSuccess = TRUE;
3200 break;
3202 if (lpszBuffer[nRecv] != '\r')
3203 nRecv++;
3205 else
3207 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3208 goto lend;
3212 lend:
3213 if (bSuccess)
3215 lpszBuffer[nRecv] = '\0';
3216 *dwLen = nRecv - 1;
3217 TRACE(":%d %s\n", nRecv, lpszBuffer);
3218 return lpszBuffer;
3220 else
3222 return NULL;
3226 /**********************************************************
3227 * InternetQueryDataAvailable (WININET.@)
3229 * Determines how much data is available to be read.
3231 * RETURNS
3232 * TRUE on success, FALSE if an error occurred. If
3233 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3234 * no data is presently available, FALSE is returned with
3235 * the last error ERROR_IO_PENDING; a callback with status
3236 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3237 * data is available.
3239 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3240 LPDWORD lpdwNumberOfBytesAvailble,
3241 DWORD dwFlags, DWORD_PTR dwContext)
3243 WININETHANDLEHEADER *hdr;
3244 DWORD res;
3246 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3248 hdr = WININET_GetObject( hFile );
3249 if (!hdr) {
3250 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
3251 return FALSE;
3254 if(hdr->vtbl->QueryDataAvailable) {
3255 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3256 }else {
3257 WARN("wrong handle\n");
3258 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3261 WININET_Release(hdr);
3263 if(res != ERROR_SUCCESS)
3264 SetLastError(res);
3265 return res == ERROR_SUCCESS;
3269 /***********************************************************************
3270 * InternetLockRequestFile (WININET.@)
3272 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3273 *lphLockReqHandle)
3275 FIXME("STUB\n");
3276 return FALSE;
3279 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3281 FIXME("STUB\n");
3282 return FALSE;
3286 /***********************************************************************
3287 * InternetAutodial (WININET.@)
3289 * On windows this function is supposed to dial the default internet
3290 * connection. We don't want to have Wine dial out to the internet so
3291 * we return TRUE by default. It might be nice to check if we are connected.
3293 * RETURNS
3294 * TRUE on success
3295 * FALSE on failure
3298 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3300 FIXME("STUB\n");
3302 /* Tell that we are connected to the internet. */
3303 return TRUE;
3306 /***********************************************************************
3307 * InternetAutodialHangup (WININET.@)
3309 * Hangs up a connection made with InternetAutodial
3311 * PARAM
3312 * dwReserved
3313 * RETURNS
3314 * TRUE on success
3315 * FALSE on failure
3318 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3320 FIXME("STUB\n");
3322 /* we didn't dial, we don't disconnect */
3323 return TRUE;
3326 /***********************************************************************
3327 * InternetCombineUrlA (WININET.@)
3329 * Combine a base URL with a relative URL
3331 * RETURNS
3332 * TRUE on success
3333 * FALSE on failure
3337 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3338 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3339 DWORD dwFlags)
3341 HRESULT hr=S_OK;
3343 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3345 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3346 dwFlags ^= ICU_NO_ENCODE;
3347 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3349 return (hr==S_OK);
3352 /***********************************************************************
3353 * InternetCombineUrlW (WININET.@)
3355 * Combine a base URL with a relative URL
3357 * RETURNS
3358 * TRUE on success
3359 * FALSE on failure
3363 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3364 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3365 DWORD dwFlags)
3367 HRESULT hr=S_OK;
3369 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3371 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3372 dwFlags ^= ICU_NO_ENCODE;
3373 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3375 return (hr==S_OK);
3378 /* max port num is 65535 => 5 digits */
3379 #define MAX_WORD_DIGITS 5
3381 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3382 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3383 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3384 (url)->dw##component##Length : strlen((url)->lpsz##component))
3386 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3388 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3389 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3390 return TRUE;
3391 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3392 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3393 return TRUE;
3394 if ((nScheme == INTERNET_SCHEME_FTP) &&
3395 (nPort == INTERNET_DEFAULT_FTP_PORT))
3396 return TRUE;
3397 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3398 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3399 return TRUE;
3401 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3402 return TRUE;
3404 return FALSE;
3407 /* opaque urls do not fit into the standard url hierarchy and don't have
3408 * two following slashes */
3409 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3411 return (nScheme != INTERNET_SCHEME_FTP) &&
3412 (nScheme != INTERNET_SCHEME_GOPHER) &&
3413 (nScheme != INTERNET_SCHEME_HTTP) &&
3414 (nScheme != INTERNET_SCHEME_HTTPS) &&
3415 (nScheme != INTERNET_SCHEME_FILE);
3418 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3420 int index;
3421 if (scheme < INTERNET_SCHEME_FIRST)
3422 return NULL;
3423 index = scheme - INTERNET_SCHEME_FIRST;
3424 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3425 return NULL;
3426 return (LPCWSTR)&url_schemes[index];
3429 /* we can calculate using ansi strings because we're just
3430 * calculating string length, not size
3432 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3433 LPDWORD lpdwUrlLength)
3435 INTERNET_SCHEME nScheme;
3437 *lpdwUrlLength = 0;
3439 if (lpUrlComponents->lpszScheme)
3441 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3442 *lpdwUrlLength += dwLen;
3443 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3445 else
3447 LPCWSTR scheme;
3449 nScheme = lpUrlComponents->nScheme;
3451 if (nScheme == INTERNET_SCHEME_DEFAULT)
3452 nScheme = INTERNET_SCHEME_HTTP;
3453 scheme = INTERNET_GetSchemeString(nScheme);
3454 *lpdwUrlLength += strlenW(scheme);
3457 (*lpdwUrlLength)++; /* ':' */
3458 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3459 *lpdwUrlLength += strlen("//");
3461 if (lpUrlComponents->lpszUserName)
3463 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3464 *lpdwUrlLength += strlen("@");
3466 else
3468 if (lpUrlComponents->lpszPassword)
3470 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3471 return FALSE;
3475 if (lpUrlComponents->lpszPassword)
3477 *lpdwUrlLength += strlen(":");
3478 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3481 if (lpUrlComponents->lpszHostName)
3483 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3485 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3487 char szPort[MAX_WORD_DIGITS+1];
3489 sprintf(szPort, "%d", lpUrlComponents->nPort);
3490 *lpdwUrlLength += strlen(szPort);
3491 *lpdwUrlLength += strlen(":");
3494 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3495 (*lpdwUrlLength)++; /* '/' */
3498 if (lpUrlComponents->lpszUrlPath)
3499 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3501 return TRUE;
3504 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3506 INT len;
3508 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3510 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3511 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3512 urlCompW->nScheme = lpUrlComponents->nScheme;
3513 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3514 urlCompW->nPort = lpUrlComponents->nPort;
3515 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3516 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3517 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3518 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3520 if (lpUrlComponents->lpszScheme)
3522 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3523 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3524 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3525 -1, urlCompW->lpszScheme, len);
3528 if (lpUrlComponents->lpszHostName)
3530 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3531 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3532 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3533 -1, urlCompW->lpszHostName, len);
3536 if (lpUrlComponents->lpszUserName)
3538 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3539 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3540 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3541 -1, urlCompW->lpszUserName, len);
3544 if (lpUrlComponents->lpszPassword)
3546 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3547 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3548 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3549 -1, urlCompW->lpszPassword, len);
3552 if (lpUrlComponents->lpszUrlPath)
3554 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3555 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3556 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3557 -1, urlCompW->lpszUrlPath, len);
3560 if (lpUrlComponents->lpszExtraInfo)
3562 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3563 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3564 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3565 -1, urlCompW->lpszExtraInfo, len);
3569 /***********************************************************************
3570 * InternetCreateUrlA (WININET.@)
3572 * See InternetCreateUrlW.
3574 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3575 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3577 BOOL ret;
3578 LPWSTR urlW = NULL;
3579 URL_COMPONENTSW urlCompW;
3581 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3583 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3585 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3586 return FALSE;
3589 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3591 if (lpszUrl)
3592 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3594 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3596 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3597 *lpdwUrlLength /= sizeof(WCHAR);
3599 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3600 * minus one, so add one to leave room for NULL terminator
3602 if (ret)
3603 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3605 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3606 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3607 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3608 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3609 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3610 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3611 HeapFree(GetProcessHeap(), 0, urlW);
3613 return ret;
3616 /***********************************************************************
3617 * InternetCreateUrlW (WININET.@)
3619 * Creates a URL from its component parts.
3621 * PARAMS
3622 * lpUrlComponents [I] URL Components.
3623 * dwFlags [I] Flags. See notes.
3624 * lpszUrl [I] Buffer in which to store the created URL.
3625 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3626 * lpszUrl in characters. On output, the number of bytes
3627 * required to store the URL including terminator.
3629 * NOTES
3631 * The dwFlags parameter can be zero or more of the following:
3632 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3634 * RETURNS
3635 * TRUE on success
3636 * FALSE on failure
3639 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3640 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3642 DWORD dwLen;
3643 INTERNET_SCHEME nScheme;
3645 static const WCHAR slashSlashW[] = {'/','/'};
3646 static const WCHAR percentD[] = {'%','d',0};
3648 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3650 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3652 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3653 return FALSE;
3656 if (!calc_url_length(lpUrlComponents, &dwLen))
3657 return FALSE;
3659 if (!lpszUrl || *lpdwUrlLength < dwLen)
3661 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3662 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3663 return FALSE;
3666 *lpdwUrlLength = dwLen;
3667 lpszUrl[0] = 0x00;
3669 dwLen = 0;
3671 if (lpUrlComponents->lpszScheme)
3673 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3674 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3675 lpszUrl += dwLen;
3677 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3679 else
3681 LPCWSTR scheme;
3682 nScheme = lpUrlComponents->nScheme;
3684 if (nScheme == INTERNET_SCHEME_DEFAULT)
3685 nScheme = INTERNET_SCHEME_HTTP;
3687 scheme = INTERNET_GetSchemeString(nScheme);
3688 dwLen = strlenW(scheme);
3689 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3690 lpszUrl += dwLen;
3693 /* all schemes are followed by at least a colon */
3694 *lpszUrl = ':';
3695 lpszUrl++;
3697 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3699 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3700 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3703 if (lpUrlComponents->lpszUserName)
3705 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3706 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3707 lpszUrl += dwLen;
3709 if (lpUrlComponents->lpszPassword)
3711 *lpszUrl = ':';
3712 lpszUrl++;
3714 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3715 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3716 lpszUrl += dwLen;
3719 *lpszUrl = '@';
3720 lpszUrl++;
3723 if (lpUrlComponents->lpszHostName)
3725 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3726 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3727 lpszUrl += dwLen;
3729 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3731 WCHAR szPort[MAX_WORD_DIGITS+1];
3733 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3734 *lpszUrl = ':';
3735 lpszUrl++;
3736 dwLen = strlenW(szPort);
3737 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3738 lpszUrl += dwLen;
3741 /* add slash between hostname and path if necessary */
3742 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3744 *lpszUrl = '/';
3745 lpszUrl++;
3750 if (lpUrlComponents->lpszUrlPath)
3752 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3753 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3754 lpszUrl += dwLen;
3757 *lpszUrl = '\0';
3759 return TRUE;
3762 /***********************************************************************
3763 * InternetConfirmZoneCrossingA (WININET.@)
3766 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3768 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3769 return ERROR_SUCCESS;
3772 /***********************************************************************
3773 * InternetConfirmZoneCrossingW (WININET.@)
3776 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3778 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3779 return ERROR_SUCCESS;
3782 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3783 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3785 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3786 lpdwConnection, dwReserved);
3787 return ERROR_SUCCESS;
3790 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3791 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3793 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3794 lpdwConnection, dwReserved);
3795 return ERROR_SUCCESS;
3798 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3800 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3801 return TRUE;
3804 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3806 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3807 return TRUE;
3810 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
3812 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
3813 return ERROR_SUCCESS;
3816 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3817 PBYTE pbHexHash )
3819 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3820 debugstr_w(pwszTarget), pbHexHash);
3821 return FALSE;
3824 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3826 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
3827 return FALSE;
3830 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
3832 FIXME("(%p, %08lx) stub\n", a, b);
3833 return 0;