[CLT2012]
[reactos.git] / dll / win32 / wininet / internet.c
1 /*
2 * Wininet
3 *
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
9 *
10 * Ulrich Czekalla
11 * Aric Stewart
12 * David Hammerton
13 *
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.
18 *
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.
23 *
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
27 */
28
29 #include "config.h"
30 #include "wine/port.h"
31
32 #define MAXHOSTNAME 100 /* from http.c */
33
34 #if defined(__MINGW32__) || defined (_MSC_VER)
35 #include <ws2tcpip.h>
36 #endif
37
38 #include <string.h>
39 #include <stdarg.h>
40 #include <stdio.h>
41 #include <sys/types.h>
42 #ifdef HAVE_SYS_SOCKET_H
43 # include <sys/socket.h>
44 #endif
45 #ifdef HAVE_POLL_H
46 #include <poll.h>
47 #endif
48 #ifdef HAVE_SYS_POLL_H
49 # include <sys/poll.h>
50 #endif
51 #ifdef HAVE_SYS_TIME_H
52 # include <sys/time.h>
53 #endif
54 #include <stdlib.h>
55 #include <ctype.h>
56 #ifdef HAVE_UNISTD_H
57 # include <unistd.h>
58 #endif
59 #include <assert.h>
60
61 #include "windef.h"
62 #include "winbase.h"
63 #include "winreg.h"
64 #include "winuser.h"
65 #include "wininet.h"
66 #include "winineti.h"
67 #include "winnls.h"
68 #include "wine/debug.h"
69 #include "winerror.h"
70 #define NO_SHLWAPI_STREAM
71 #include "shlwapi.h"
72
73 #include "wine/exception.h"
74
75 #include "internet.h"
76 #include "resource.h"
77
78 #include "wine/unicode.h"
79
80 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
81
82 #define RESPONSE_TIMEOUT 30
83
84 typedef struct
85 {
86 DWORD dwError;
87 CHAR response[MAX_REPLY_LEN];
88 } WITHREADERROR, *LPWITHREADERROR;
89
90 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
91 HMODULE WININET_hModule;
92
93 static CRITICAL_SECTION WININET_cs;
94 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
95 {
96 0, 0, &WININET_cs,
97 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
98 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
99 };
100 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
101
102 static object_header_t **handle_table;
103 static UINT_PTR next_handle;
104 static UINT_PTR handle_table_size;
105
106 typedef struct
107 {
108 DWORD dwProxyEnabled;
109 LPWSTR lpszProxyServer;
110 LPWSTR lpszProxyBypass;
111 } proxyinfo_t;
112
113 static const WCHAR szInternetSettings[] =
114 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
115 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
116 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
117 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
118 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
119
120 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
121 {
122 UINT_PTR handle = 0, num;
123 object_header_t *ret;
124 object_header_t **p;
125 BOOL res = TRUE;
126
127 ret = heap_alloc_zero(size);
128 if(!ret)
129 return NULL;
130
131 list_init(&ret->children);
132
133 EnterCriticalSection( &WININET_cs );
134
135 if(!handle_table_size) {
136 num = 16;
137 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
138 if(p) {
139 handle_table = p;
140 handle_table_size = num;
141 next_handle = 1;
142 }else {
143 res = FALSE;
144 }
145 }else if(next_handle == handle_table_size) {
146 num = handle_table_size * 2;
147 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
148 if(p) {
149 handle_table = p;
150 handle_table_size = num;
151 }else {
152 res = FALSE;
153 }
154 }
155
156 if(res) {
157 handle = next_handle;
158 if(handle_table[handle])
159 ERR("handle isn't free but should be\n");
160 handle_table[handle] = ret;
161 ret->valid_handle = TRUE;
162
163 while(handle_table[next_handle] && next_handle < handle_table_size)
164 next_handle++;
165 }
166
167 LeaveCriticalSection( &WININET_cs );
168
169 if(!res) {
170 heap_free(ret);
171 return NULL;
172 }
173
174 ret->vtbl = vtbl;
175 ret->refs = 1;
176 ret->hInternet = (HINTERNET)handle;
177
178 if(parent) {
179 ret->lpfnStatusCB = parent->lpfnStatusCB;
180 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
181 }
182
183 return ret;
184 }
185
186 object_header_t *WININET_AddRef( object_header_t *info )
187 {
188 ULONG refs = InterlockedIncrement(&info->refs);
189 TRACE("%p -> refcount = %d\n", info, refs );
190 return info;
191 }
192
193 object_header_t *get_handle_object( HINTERNET hinternet )
194 {
195 object_header_t *info = NULL;
196 UINT_PTR handle = (UINT_PTR) hinternet;
197
198 EnterCriticalSection( &WININET_cs );
199
200 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
201 info = WININET_AddRef(handle_table[handle]);
202
203 LeaveCriticalSection( &WININET_cs );
204
205 TRACE("handle %ld -> %p\n", handle, info);
206
207 return info;
208 }
209
210 static void invalidate_handle(object_header_t *info)
211 {
212 object_header_t *child, *next;
213
214 if(!info->valid_handle)
215 return;
216 info->valid_handle = FALSE;
217
218 /* Free all children as native does */
219 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
220 {
221 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
222 invalidate_handle( child );
223 }
224
225 WININET_Release(info);
226 }
227
228 BOOL WININET_Release( object_header_t *info )
229 {
230 ULONG refs = InterlockedDecrement(&info->refs);
231 TRACE( "object %p refcount = %d\n", info, refs );
232 if( !refs )
233 {
234 invalidate_handle(info);
235 if ( info->vtbl->CloseConnection )
236 {
237 TRACE( "closing connection %p\n", info);
238 info->vtbl->CloseConnection( info );
239 }
240 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
241 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
242 || !(info->dwInternalFlags & INET_OPENURL))
243 {
244 INTERNET_SendCallback(info, info->dwContext,
245 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
246 sizeof(HINTERNET));
247 }
248 TRACE( "destroying object %p\n", info);
249 if ( info->htype != WH_HINIT )
250 list_remove( &info->entry );
251 info->vtbl->Destroy( info );
252
253 if(info->hInternet) {
254 UINT_PTR handle = (UINT_PTR)info->hInternet;
255
256 EnterCriticalSection( &WININET_cs );
257
258 handle_table[handle] = NULL;
259 if(next_handle > handle)
260 next_handle = handle;
261
262 LeaveCriticalSection( &WININET_cs );
263 }
264
265 heap_free(info);
266 }
267 return TRUE;
268 }
269
270 /***********************************************************************
271 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
272 *
273 * PARAMS
274 * hinstDLL [I] handle to the DLL's instance
275 * fdwReason [I]
276 * lpvReserved [I] reserved, must be NULL
277 *
278 * RETURNS
279 * Success: TRUE
280 * Failure: FALSE
281 */
282
283 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
284 {
285 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
286
287 switch (fdwReason) {
288 case DLL_PROCESS_ATTACH:
289
290 g_dwTlsErrIndex = TlsAlloc();
291
292 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
293 return FALSE;
294
295 WININET_hModule = hinstDLL;
296
297 case DLL_THREAD_ATTACH:
298 break;
299
300 case DLL_THREAD_DETACH:
301 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
302 {
303 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
304 HeapFree(GetProcessHeap(), 0, lpwite);
305 }
306 break;
307
308 case DLL_PROCESS_DETACH:
309 collect_connections(TRUE);
310 NETCON_unload();
311
312 URLCacheContainers_DeleteAll();
313
314 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
315 {
316 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
317 TlsFree(g_dwTlsErrIndex);
318 }
319 break;
320 }
321
322 return TRUE;
323 }
324
325 /***********************************************************************
326 * INTERNET_SaveProxySettings
327 *
328 * Stores the proxy settings given by lpwai into the registry
329 *
330 * RETURNS
331 * ERROR_SUCCESS if no error, or error code on fail
332 */
333 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
334 {
335 HKEY key;
336 LONG ret;
337
338 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
339 return ret;
340
341 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->dwProxyEnabled, sizeof(DWORD))))
342 {
343 RegCloseKey( key );
344 return ret;
345 }
346
347 if (lpwpi->lpszProxyServer)
348 {
349 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->lpszProxyServer, sizeof(WCHAR) * (lstrlenW(lpwpi->lpszProxyServer) + 1))))
350 {
351 RegCloseKey( key );
352 return ret;
353 }
354 }
355 else
356 {
357 if ((ret = RegDeleteValueW( key, szProxyServer )))
358 {
359 RegCloseKey( key );
360 return ret;
361 }
362 }
363
364 RegCloseKey(key);
365 return ERROR_SUCCESS;
366 }
367
368 /***********************************************************************
369 * INTERNET_FindProxyForProtocol
370 *
371 * Searches the proxy string for a proxy of the given protocol.
372 * Returns the found proxy, or the default proxy if none of the given
373 * protocol is found.
374 *
375 * PARAMETERS
376 * szProxy [In] proxy string to search
377 * proto [In] protocol to search for, e.g. "http"
378 * foundProxy [Out] found proxy
379 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
380 *
381 * RETURNS
382 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
383 * *foundProxyLen is set to the required size in WCHARs, including the
384 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
385 */
386 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen)
387 {
388 LPCWSTR ptr;
389 BOOL ret = FALSE;
390
391 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
392
393 /* First, look for the specified protocol (proto=scheme://host:port) */
394 for (ptr = szProxy; !ret && ptr && *ptr; )
395 {
396 LPCWSTR end, equal;
397
398 if (!(end = strchrW(ptr, ' ')))
399 end = ptr + strlenW(ptr);
400 if ((equal = strchrW(ptr, '=')) && equal < end &&
401 equal - ptr == strlenW(proto) &&
402 !strncmpiW(proto, ptr, strlenW(proto)))
403 {
404 if (end - equal > *foundProxyLen)
405 {
406 WARN("buffer too short for %s\n",
407 debugstr_wn(equal + 1, end - equal - 1));
408 *foundProxyLen = end - equal;
409 SetLastError(ERROR_INSUFFICIENT_BUFFER);
410 }
411 else
412 {
413 memcpy(foundProxy, equal + 1, (end - equal) * sizeof(WCHAR));
414 foundProxy[end - equal] = 0;
415 ret = TRUE;
416 }
417 }
418 if (*end == ' ')
419 ptr = end + 1;
420 else
421 ptr = end;
422 }
423 if (!ret)
424 {
425 /* It wasn't found: look for no protocol */
426 for (ptr = szProxy; !ret && ptr && *ptr; )
427 {
428 LPCWSTR end, equal;
429
430 if (!(end = strchrW(ptr, ' ')))
431 end = ptr + strlenW(ptr);
432 if (!(equal = strchrW(ptr, '=')))
433 {
434 if (end - ptr + 1 > *foundProxyLen)
435 {
436 WARN("buffer too short for %s\n",
437 debugstr_wn(ptr, end - ptr));
438 *foundProxyLen = end - ptr + 1;
439 SetLastError(ERROR_INSUFFICIENT_BUFFER);
440 }
441 else
442 {
443 memcpy(foundProxy, ptr, (end - ptr) * sizeof(WCHAR));
444 foundProxy[end - ptr] = 0;
445 ret = TRUE;
446 }
447 }
448 if (*end == ' ')
449 ptr = end + 1;
450 else
451 ptr = end;
452 }
453 }
454 if (ret)
455 TRACE("found proxy for %s: %s\n", debugstr_w(proto),
456 debugstr_w(foundProxy));
457 return ret;
458 }
459
460 /***********************************************************************
461 * InternetInitializeAutoProxyDll (WININET.@)
462 *
463 * Setup the internal proxy
464 *
465 * PARAMETERS
466 * dwReserved
467 *
468 * RETURNS
469 * FALSE on failure
470 *
471 */
472 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
473 {
474 FIXME("STUB\n");
475 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
476 return FALSE;
477 }
478
479 /***********************************************************************
480 * DetectAutoProxyUrl (WININET.@)
481 *
482 * Auto detect the proxy url
483 *
484 * RETURNS
485 * FALSE on failure
486 *
487 */
488 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
489 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
490 {
491 FIXME("STUB\n");
492 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
493 return FALSE;
494 }
495
496 static void FreeProxyInfo( proxyinfo_t *lpwpi )
497 {
498 HeapFree(GetProcessHeap(), 0, lpwpi->lpszProxyServer);
499 HeapFree(GetProcessHeap(), 0, lpwpi->lpszProxyBypass);
500 }
501
502 /***********************************************************************
503 * INTERNET_LoadProxySettings
504 *
505 * Loads proxy information from the registry or environment into lpwpi.
506 *
507 * The caller should call FreeProxyInfo when done with lpwpi.
508 *
509 * FIXME:
510 * The proxy may be specified in the form 'http=proxy.my.org'
511 * Presumably that means there can be ftp=ftpproxy.my.org too.
512 */
513 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
514 {
515 HKEY key;
516 DWORD type, len;
517 LPCSTR envproxy;
518 LONG ret;
519
520 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
521 return ret;
522
523 len = sizeof(DWORD);
524 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->dwProxyEnabled, &len ) || type != REG_DWORD)
525 {
526 lpwpi->dwProxyEnabled = 0;
527 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->dwProxyEnabled, sizeof(DWORD) )))
528 {
529 RegCloseKey( key );
530 return ret;
531 }
532 }
533
534 if (!(envproxy = getenv( "http_proxy" )) || lpwpi->dwProxyEnabled)
535 {
536 TRACE("Proxy is enabled.\n");
537
538 /* figure out how much memory the proxy setting takes */
539 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
540 {
541 LPWSTR szProxy, p;
542 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
543
544 if (!(szProxy = heap_alloc(len)))
545 {
546 RegCloseKey( key );
547 return ERROR_OUTOFMEMORY;
548 }
549 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
550
551 /* find the http proxy, and strip away everything else */
552 p = strstrW( szProxy, szHttp );
553 if (p)
554 {
555 p += lstrlenW( szHttp );
556 lstrcpyW( szProxy, p );
557 }
558 p = strchrW( szProxy, ' ' );
559 if (p) *p = 0;
560
561 lpwpi->lpszProxyServer = szProxy;
562
563 TRACE("http proxy = %s\n", debugstr_w(lpwpi->lpszProxyServer));
564 }
565 else
566 {
567 TRACE("No proxy server settings in registry.\n");
568 lpwpi->lpszProxyServer = NULL;
569 }
570 }
571 else if (envproxy)
572 {
573 WCHAR *envproxyW;
574
575 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
576 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
577 return ERROR_OUTOFMEMORY;
578 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
579
580 lpwpi->dwProxyEnabled = 1;
581 lpwpi->lpszProxyServer = envproxyW;
582
583 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->lpszProxyServer));
584 }
585 RegCloseKey( key );
586
587 lpwpi->lpszProxyBypass = NULL;
588
589 return ERROR_SUCCESS;
590 }
591
592 /***********************************************************************
593 * INTERNET_ConfigureProxy
594 */
595 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
596 {
597 proxyinfo_t wpi;
598
599 if (INTERNET_LoadProxySettings( &wpi ))
600 return FALSE;
601
602 if (wpi.dwProxyEnabled)
603 {
604 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
605 lpwai->proxy = wpi.lpszProxyServer;
606 return TRUE;
607 }
608
609 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
610 return FALSE;
611 }
612
613 /***********************************************************************
614 * dump_INTERNET_FLAGS
615 *
616 * Helper function to TRACE the internet flags.
617 *
618 * RETURNS
619 * None
620 *
621 */
622 static void dump_INTERNET_FLAGS(DWORD dwFlags)
623 {
624 #define FE(x) { x, #x }
625 static const wininet_flag_info flag[] = {
626 FE(INTERNET_FLAG_RELOAD),
627 FE(INTERNET_FLAG_RAW_DATA),
628 FE(INTERNET_FLAG_EXISTING_CONNECT),
629 FE(INTERNET_FLAG_ASYNC),
630 FE(INTERNET_FLAG_PASSIVE),
631 FE(INTERNET_FLAG_NO_CACHE_WRITE),
632 FE(INTERNET_FLAG_MAKE_PERSISTENT),
633 FE(INTERNET_FLAG_FROM_CACHE),
634 FE(INTERNET_FLAG_SECURE),
635 FE(INTERNET_FLAG_KEEP_CONNECTION),
636 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
637 FE(INTERNET_FLAG_READ_PREFETCH),
638 FE(INTERNET_FLAG_NO_COOKIES),
639 FE(INTERNET_FLAG_NO_AUTH),
640 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
641 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
642 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
643 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
644 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
645 FE(INTERNET_FLAG_RESYNCHRONIZE),
646 FE(INTERNET_FLAG_HYPERLINK),
647 FE(INTERNET_FLAG_NO_UI),
648 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
649 FE(INTERNET_FLAG_CACHE_ASYNC),
650 FE(INTERNET_FLAG_FORMS_SUBMIT),
651 FE(INTERNET_FLAG_NEED_FILE),
652 FE(INTERNET_FLAG_TRANSFER_ASCII),
653 FE(INTERNET_FLAG_TRANSFER_BINARY)
654 };
655 #undef FE
656 unsigned int i;
657
658 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
659 if (flag[i].val & dwFlags) {
660 TRACE(" %s", flag[i].name);
661 dwFlags &= ~flag[i].val;
662 }
663 }
664 if (dwFlags)
665 TRACE(" Unknown flags (%08x)\n", dwFlags);
666 else
667 TRACE("\n");
668 }
669
670 /***********************************************************************
671 * INTERNET_CloseHandle (internal)
672 *
673 * Close internet handle
674 *
675 */
676 static VOID APPINFO_Destroy(object_header_t *hdr)
677 {
678 appinfo_t *lpwai = (appinfo_t*)hdr;
679
680 TRACE("%p\n",lpwai);
681
682 HeapFree(GetProcessHeap(), 0, lpwai->agent);
683 HeapFree(GetProcessHeap(), 0, lpwai->proxy);
684 HeapFree(GetProcessHeap(), 0, lpwai->proxyBypass);
685 HeapFree(GetProcessHeap(), 0, lpwai->proxyUsername);
686 HeapFree(GetProcessHeap(), 0, lpwai->proxyPassword);
687 }
688
689 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
690 {
691 appinfo_t *ai = (appinfo_t*)hdr;
692
693 switch(option) {
694 case INTERNET_OPTION_HANDLE_TYPE:
695 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
696
697 if (*size < sizeof(ULONG))
698 return ERROR_INSUFFICIENT_BUFFER;
699
700 *size = sizeof(DWORD);
701 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
702 return ERROR_SUCCESS;
703
704 case INTERNET_OPTION_USER_AGENT: {
705 DWORD bufsize;
706
707 TRACE("INTERNET_OPTION_USER_AGENT\n");
708
709 bufsize = *size;
710
711 if (unicode) {
712 DWORD len = ai->agent ? strlenW(ai->agent) : 0;
713
714 *size = (len + 1) * sizeof(WCHAR);
715 if(!buffer || bufsize < *size)
716 return ERROR_INSUFFICIENT_BUFFER;
717
718 if (ai->agent)
719 strcpyW(buffer, ai->agent);
720 else
721 *(WCHAR *)buffer = 0;
722 /* If the buffer is copied, the returned length doesn't include
723 * the NULL terminator.
724 */
725 *size = len * sizeof(WCHAR);
726 }else {
727 if (ai->agent)
728 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
729 else
730 *size = 1;
731 if(!buffer || bufsize < *size)
732 return ERROR_INSUFFICIENT_BUFFER;
733
734 if (ai->agent)
735 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
736 else
737 *(char *)buffer = 0;
738 /* If the buffer is copied, the returned length doesn't include
739 * the NULL terminator.
740 */
741 *size -= 1;
742 }
743
744 return ERROR_SUCCESS;
745 }
746
747 case INTERNET_OPTION_PROXY:
748 if (unicode) {
749 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
750 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
751 LPWSTR proxy, proxy_bypass;
752
753 if (ai->proxy)
754 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
755 if (ai->proxyBypass)
756 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
757 if (*size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
758 {
759 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
760 return ERROR_INSUFFICIENT_BUFFER;
761 }
762 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
763 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
764
765 pi->dwAccessType = ai->accessType;
766 pi->lpszProxy = NULL;
767 pi->lpszProxyBypass = NULL;
768 if (ai->proxy) {
769 lstrcpyW(proxy, ai->proxy);
770 pi->lpszProxy = proxy;
771 }
772
773 if (ai->proxyBypass) {
774 lstrcpyW(proxy_bypass, ai->proxyBypass);
775 pi->lpszProxyBypass = proxy_bypass;
776 }
777
778 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
779 return ERROR_SUCCESS;
780 }else {
781 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
782 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
783 LPSTR proxy, proxy_bypass;
784
785 if (ai->proxy)
786 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
787 if (ai->proxyBypass)
788 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
789 NULL, 0, NULL, NULL);
790 if (*size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
791 {
792 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
793 return ERROR_INSUFFICIENT_BUFFER;
794 }
795 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
796 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
797
798 pi->dwAccessType = ai->accessType;
799 pi->lpszProxy = NULL;
800 pi->lpszProxyBypass = NULL;
801 if (ai->proxy) {
802 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
803 pi->lpszProxy = proxy;
804 }
805
806 if (ai->proxyBypass) {
807 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
808 proxyBypassBytesRequired, NULL, NULL);
809 pi->lpszProxyBypass = proxy_bypass;
810 }
811
812 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
813 return ERROR_SUCCESS;
814 }
815 }
816
817 return INET_QueryOption(hdr, option, buffer, size, unicode);
818 }
819
820 static const object_vtbl_t APPINFOVtbl = {
821 APPINFO_Destroy,
822 NULL,
823 APPINFO_QueryOption,
824 NULL,
825 NULL,
826 NULL,
827 NULL,
828 NULL,
829 NULL
830 };
831
832
833 /***********************************************************************
834 * InternetOpenW (WININET.@)
835 *
836 * Per-application initialization of wininet
837 *
838 * RETURNS
839 * HINTERNET on success
840 * NULL on failure
841 *
842 */
843 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
844 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
845 {
846 appinfo_t *lpwai = NULL;
847
848 if (TRACE_ON(wininet)) {
849 #define FE(x) { x, #x }
850 static const wininet_flag_info access_type[] = {
851 FE(INTERNET_OPEN_TYPE_PRECONFIG),
852 FE(INTERNET_OPEN_TYPE_DIRECT),
853 FE(INTERNET_OPEN_TYPE_PROXY),
854 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
855 };
856 #undef FE
857 DWORD i;
858 const char *access_type_str = "Unknown";
859
860 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
861 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
862 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
863 if (access_type[i].val == dwAccessType) {
864 access_type_str = access_type[i].name;
865 break;
866 }
867 }
868 TRACE(" access type : %s\n", access_type_str);
869 TRACE(" flags :");
870 dump_INTERNET_FLAGS(dwFlags);
871 }
872
873 /* Clear any error information */
874 INTERNET_SetLastError(0);
875
876 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
877 if (!lpwai) {
878 SetLastError(ERROR_OUTOFMEMORY);
879 return NULL;
880 }
881
882 lpwai->hdr.htype = WH_HINIT;
883 lpwai->hdr.dwFlags = dwFlags;
884 lpwai->accessType = dwAccessType;
885 lpwai->proxyUsername = NULL;
886 lpwai->proxyPassword = NULL;
887
888 lpwai->agent = heap_strdupW(lpszAgent);
889 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
890 INTERNET_ConfigureProxy( lpwai );
891 else
892 lpwai->proxy = heap_strdupW(lpszProxy);
893 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
894
895 TRACE("returning %p\n", lpwai);
896
897 return lpwai->hdr.hInternet;
898 }
899
900
901 /***********************************************************************
902 * InternetOpenA (WININET.@)
903 *
904 * Per-application initialization of wininet
905 *
906 * RETURNS
907 * HINTERNET on success
908 * NULL on failure
909 *
910 */
911 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
912 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
913 {
914 WCHAR *szAgent, *szProxy, *szBypass;
915 HINTERNET rc;
916
917 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
918 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
919
920 szAgent = heap_strdupAtoW(lpszAgent);
921 szProxy = heap_strdupAtoW(lpszProxy);
922 szBypass = heap_strdupAtoW(lpszProxyBypass);
923
924 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
925
926 HeapFree(GetProcessHeap(), 0, szAgent);
927 HeapFree(GetProcessHeap(), 0, szProxy);
928 HeapFree(GetProcessHeap(), 0, szBypass);
929
930 return rc;
931 }
932
933 /***********************************************************************
934 * InternetGetLastResponseInfoA (WININET.@)
935 *
936 * Return last wininet error description on the calling thread
937 *
938 * RETURNS
939 * TRUE on success of writing to buffer
940 * FALSE on failure
941 *
942 */
943 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
944 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
945 {
946 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
947
948 TRACE("\n");
949
950 if (lpwite)
951 {
952 *lpdwError = lpwite->dwError;
953 if (lpwite->dwError)
954 {
955 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
956 *lpdwBufferLength = strlen(lpszBuffer);
957 }
958 else
959 *lpdwBufferLength = 0;
960 }
961 else
962 {
963 *lpdwError = 0;
964 *lpdwBufferLength = 0;
965 }
966
967 return TRUE;
968 }
969
970 /***********************************************************************
971 * InternetGetLastResponseInfoW (WININET.@)
972 *
973 * Return last wininet error description on the calling thread
974 *
975 * RETURNS
976 * TRUE on success of writing to buffer
977 * FALSE on failure
978 *
979 */
980 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
981 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
982 {
983 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
984
985 TRACE("\n");
986
987 if (lpwite)
988 {
989 *lpdwError = lpwite->dwError;
990 if (lpwite->dwError)
991 {
992 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
993 *lpdwBufferLength = lstrlenW(lpszBuffer);
994 }
995 else
996 *lpdwBufferLength = 0;
997 }
998 else
999 {
1000 *lpdwError = 0;
1001 *lpdwBufferLength = 0;
1002 }
1003
1004 return TRUE;
1005 }
1006
1007 /***********************************************************************
1008 * InternetGetConnectedState (WININET.@)
1009 *
1010 * Return connected state
1011 *
1012 * RETURNS
1013 * TRUE if connected
1014 * if lpdwStatus is not null, return the status (off line,
1015 * modem, lan...) in it.
1016 * FALSE if not connected
1017 */
1018 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1019 {
1020 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1021
1022 if (lpdwStatus) {
1023 WARN("always returning LAN connection.\n");
1024 *lpdwStatus = INTERNET_CONNECTION_LAN;
1025 }
1026 return TRUE;
1027 }
1028
1029
1030 /***********************************************************************
1031 * InternetGetConnectedStateExW (WININET.@)
1032 *
1033 * Return connected state
1034 *
1035 * PARAMS
1036 *
1037 * lpdwStatus [O] Flags specifying the status of the internet connection.
1038 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1039 * dwNameLen [I] Size of the buffer, in characters.
1040 * dwReserved [I] Reserved. Must be set to 0.
1041 *
1042 * RETURNS
1043 * TRUE if connected
1044 * if lpdwStatus is not null, return the status (off line,
1045 * modem, lan...) in it.
1046 * FALSE if not connected
1047 *
1048 * NOTES
1049 * If the system has no available network connections, an empty string is
1050 * stored in lpszConnectionName. If there is a LAN connection, a localized
1051 * "LAN Connection" string is stored. Presumably, if only a dial-up
1052 * connection is available then the name of the dial-up connection is
1053 * returned. Why any application, other than the "Internet Settings" CPL,
1054 * would want to use this function instead of the simpler InternetGetConnectedStateW
1055 * function is beyond me.
1056 */
1057 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1058 DWORD dwNameLen, DWORD dwReserved)
1059 {
1060 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1061
1062 /* Must be zero */
1063 if(dwReserved)
1064 return FALSE;
1065
1066 if (lpdwStatus) {
1067 WARN("always returning LAN connection.\n");
1068 *lpdwStatus = INTERNET_CONNECTION_LAN;
1069 }
1070 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1071 }
1072
1073
1074 /***********************************************************************
1075 * InternetGetConnectedStateExA (WININET.@)
1076 */
1077 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1078 DWORD dwNameLen, DWORD dwReserved)
1079 {
1080 LPWSTR lpwszConnectionName = NULL;
1081 BOOL rc;
1082
1083 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1084
1085 if (lpszConnectionName && dwNameLen > 0)
1086 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1087
1088 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1089 dwReserved);
1090 if (rc && lpwszConnectionName)
1091 {
1092 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1093 dwNameLen, NULL, NULL);
1094
1095 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
1096 }
1097
1098 return rc;
1099 }
1100
1101
1102 /***********************************************************************
1103 * InternetConnectW (WININET.@)
1104 *
1105 * Open a ftp, gopher or http session
1106 *
1107 * RETURNS
1108 * HINTERNET a session handle on success
1109 * NULL on failure
1110 *
1111 */
1112 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1113 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1114 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1115 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1116 {
1117 appinfo_t *hIC;
1118 HINTERNET rc = NULL;
1119 DWORD res = ERROR_SUCCESS;
1120
1121 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
1122 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
1123 dwService, dwFlags, dwContext);
1124
1125 if (!lpszServerName)
1126 {
1127 SetLastError(ERROR_INVALID_PARAMETER);
1128 return NULL;
1129 }
1130
1131 hIC = (appinfo_t*)get_handle_object( hInternet );
1132 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1133 {
1134 res = ERROR_INVALID_HANDLE;
1135 goto lend;
1136 }
1137
1138 switch (dwService)
1139 {
1140 case INTERNET_SERVICE_FTP:
1141 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1142 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1143 if(!rc)
1144 res = INTERNET_GetLastError();
1145 break;
1146
1147 case INTERNET_SERVICE_HTTP:
1148 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1149 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1150 break;
1151
1152 case INTERNET_SERVICE_GOPHER:
1153 default:
1154 break;
1155 }
1156 lend:
1157 if( hIC )
1158 WININET_Release( &hIC->hdr );
1159
1160 TRACE("returning %p\n", rc);
1161 SetLastError(res);
1162 return rc;
1163 }
1164
1165
1166 /***********************************************************************
1167 * InternetConnectA (WININET.@)
1168 *
1169 * Open a ftp, gopher or http session
1170 *
1171 * RETURNS
1172 * HINTERNET a session handle on success
1173 * NULL on failure
1174 *
1175 */
1176 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1177 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1178 LPCSTR lpszUserName, LPCSTR lpszPassword,
1179 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1180 {
1181 HINTERNET rc = NULL;
1182 LPWSTR szServerName;
1183 LPWSTR szUserName;
1184 LPWSTR szPassword;
1185
1186 szServerName = heap_strdupAtoW(lpszServerName);
1187 szUserName = heap_strdupAtoW(lpszUserName);
1188 szPassword = heap_strdupAtoW(lpszPassword);
1189
1190 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1191 szUserName, szPassword, dwService, dwFlags, dwContext);
1192
1193 HeapFree(GetProcessHeap(), 0, szServerName);
1194 HeapFree(GetProcessHeap(), 0, szUserName);
1195 HeapFree(GetProcessHeap(), 0, szPassword);
1196 return rc;
1197 }
1198
1199
1200 /***********************************************************************
1201 * InternetFindNextFileA (WININET.@)
1202 *
1203 * Continues a file search from a previous call to FindFirstFile
1204 *
1205 * RETURNS
1206 * TRUE on success
1207 * FALSE on failure
1208 *
1209 */
1210 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1211 {
1212 BOOL ret;
1213 WIN32_FIND_DATAW fd;
1214
1215 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1216 if(lpvFindData)
1217 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1218 return ret;
1219 }
1220
1221 /***********************************************************************
1222 * InternetFindNextFileW (WININET.@)
1223 *
1224 * Continues a file search from a previous call to FindFirstFile
1225 *
1226 * RETURNS
1227 * TRUE on success
1228 * FALSE on failure
1229 *
1230 */
1231 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1232 {
1233 object_header_t *hdr;
1234 DWORD res;
1235
1236 TRACE("\n");
1237
1238 hdr = get_handle_object(hFind);
1239 if(!hdr) {
1240 WARN("Invalid handle\n");
1241 SetLastError(ERROR_INVALID_HANDLE);
1242 return FALSE;
1243 }
1244
1245 if(hdr->vtbl->FindNextFileW) {
1246 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1247 }else {
1248 WARN("Handle doesn't support NextFile\n");
1249 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1250 }
1251
1252 WININET_Release(hdr);
1253
1254 if(res != ERROR_SUCCESS)
1255 SetLastError(res);
1256 return res == ERROR_SUCCESS;
1257 }
1258
1259 /***********************************************************************
1260 * InternetCloseHandle (WININET.@)
1261 *
1262 * Generic close handle function
1263 *
1264 * RETURNS
1265 * TRUE on success
1266 * FALSE on failure
1267 *
1268 */
1269 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1270 {
1271 object_header_t *obj;
1272
1273 TRACE("%p\n", hInternet);
1274
1275 obj = get_handle_object( hInternet );
1276 if (!obj) {
1277 SetLastError(ERROR_INVALID_HANDLE);
1278 return FALSE;
1279 }
1280
1281 invalidate_handle(obj);
1282 WININET_Release(obj);
1283
1284 return TRUE;
1285 }
1286
1287
1288 /***********************************************************************
1289 * ConvertUrlComponentValue (Internal)
1290 *
1291 * Helper function for InternetCrackUrlA
1292 *
1293 */
1294 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1295 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1296 LPCSTR lpszStart, LPCWSTR lpwszStart)
1297 {
1298 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1299 if (*dwComponentLen != 0)
1300 {
1301 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1302 if (*lppszComponent == NULL)
1303 {
1304 if (lpwszComponent)
1305 {
1306 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1307 *lppszComponent = (LPSTR)lpszStart + offset;
1308 }
1309 else
1310 *lppszComponent = NULL;
1311
1312 *dwComponentLen = nASCIILength;
1313 }
1314 else
1315 {
1316 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1317 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1318 (*lppszComponent)[ncpylen]=0;
1319 *dwComponentLen = ncpylen;
1320 }
1321 }
1322 }
1323
1324
1325 /***********************************************************************
1326 * InternetCrackUrlA (WININET.@)
1327 *
1328 * See InternetCrackUrlW.
1329 */
1330 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1331 LPURL_COMPONENTSA lpUrlComponents)
1332 {
1333 DWORD nLength;
1334 URL_COMPONENTSW UCW;
1335 BOOL ret = FALSE;
1336 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1337 *scheme = NULL, *extra = NULL;
1338
1339 TRACE("(%s %u %x %p)\n",
1340 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1341 dwUrlLength, dwFlags, lpUrlComponents);
1342
1343 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1344 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1345 {
1346 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1347 return FALSE;
1348 }
1349
1350 if(dwUrlLength<=0)
1351 dwUrlLength=-1;
1352 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1353
1354 /* if dwUrlLength=-1 then nLength includes null but length to
1355 InternetCrackUrlW should not include it */
1356 if (dwUrlLength == -1) nLength--;
1357
1358 lpwszUrl = heap_alloc((nLength + 1) * sizeof(WCHAR));
1359 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength + 1);
1360 lpwszUrl[nLength] = '\0';
1361
1362 memset(&UCW,0,sizeof(UCW));
1363 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1364 if (lpUrlComponents->dwHostNameLength)
1365 {
1366 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1367 if (lpUrlComponents->lpszHostName)
1368 {
1369 hostname = heap_alloc(UCW.dwHostNameLength * sizeof(WCHAR));
1370 UCW.lpszHostName = hostname;
1371 }
1372 }
1373 if (lpUrlComponents->dwUserNameLength)
1374 {
1375 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1376 if (lpUrlComponents->lpszUserName)
1377 {
1378 username = heap_alloc(UCW.dwUserNameLength * sizeof(WCHAR));
1379 UCW.lpszUserName = username;
1380 }
1381 }
1382 if (lpUrlComponents->dwPasswordLength)
1383 {
1384 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1385 if (lpUrlComponents->lpszPassword)
1386 {
1387 password = heap_alloc(UCW.dwPasswordLength * sizeof(WCHAR));
1388 UCW.lpszPassword = password;
1389 }
1390 }
1391 if (lpUrlComponents->dwUrlPathLength)
1392 {
1393 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1394 if (lpUrlComponents->lpszUrlPath)
1395 {
1396 path = heap_alloc(UCW.dwUrlPathLength * sizeof(WCHAR));
1397 UCW.lpszUrlPath = path;
1398 }
1399 }
1400 if (lpUrlComponents->dwSchemeLength)
1401 {
1402 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1403 if (lpUrlComponents->lpszScheme)
1404 {
1405 scheme = heap_alloc(UCW.dwSchemeLength * sizeof(WCHAR));
1406 UCW.lpszScheme = scheme;
1407 }
1408 }
1409 if (lpUrlComponents->dwExtraInfoLength)
1410 {
1411 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1412 if (lpUrlComponents->lpszExtraInfo)
1413 {
1414 extra = heap_alloc(UCW.dwExtraInfoLength * sizeof(WCHAR));
1415 UCW.lpszExtraInfo = extra;
1416 }
1417 }
1418 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1419 {
1420 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1421 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1422 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1423 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1424 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1425 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1426 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1427 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1428 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1429 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1430 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1431 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1432
1433 lpUrlComponents->nScheme = UCW.nScheme;
1434 lpUrlComponents->nPort = UCW.nPort;
1435
1436 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl),
1437 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1438 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1439 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1440 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1441 }
1442 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1443 HeapFree(GetProcessHeap(), 0, hostname);
1444 HeapFree(GetProcessHeap(), 0, username);
1445 HeapFree(GetProcessHeap(), 0, password);
1446 HeapFree(GetProcessHeap(), 0, path);
1447 HeapFree(GetProcessHeap(), 0, scheme);
1448 HeapFree(GetProcessHeap(), 0, extra);
1449 return ret;
1450 }
1451
1452 static const WCHAR url_schemes[][7] =
1453 {
1454 {'f','t','p',0},
1455 {'g','o','p','h','e','r',0},
1456 {'h','t','t','p',0},
1457 {'h','t','t','p','s',0},
1458 {'f','i','l','e',0},
1459 {'n','e','w','s',0},
1460 {'m','a','i','l','t','o',0},
1461 {'r','e','s',0},
1462 };
1463
1464 /***********************************************************************
1465 * GetInternetSchemeW (internal)
1466 *
1467 * Get scheme of url
1468 *
1469 * RETURNS
1470 * scheme on success
1471 * INTERNET_SCHEME_UNKNOWN on failure
1472 *
1473 */
1474 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1475 {
1476 int i;
1477
1478 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1479
1480 if(lpszScheme==NULL)
1481 return INTERNET_SCHEME_UNKNOWN;
1482
1483 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1484 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1485 return INTERNET_SCHEME_FIRST + i;
1486
1487 return INTERNET_SCHEME_UNKNOWN;
1488 }
1489
1490 /***********************************************************************
1491 * SetUrlComponentValueW (Internal)
1492 *
1493 * Helper function for InternetCrackUrlW
1494 *
1495 * PARAMS
1496 * lppszComponent [O] Holds the returned string
1497 * dwComponentLen [I] Holds the size of lppszComponent
1498 * [O] Holds the length of the string in lppszComponent without '\0'
1499 * lpszStart [I] Holds the string to copy from
1500 * len [I] Holds the length of lpszStart without '\0'
1501 *
1502 * RETURNS
1503 * TRUE on success
1504 * FALSE on failure
1505 *
1506 */
1507 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1508 {
1509 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1510
1511 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1512 return FALSE;
1513
1514 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1515 {
1516 if (*lppszComponent == NULL)
1517 {
1518 *lppszComponent = (LPWSTR)lpszStart;
1519 *dwComponentLen = len;
1520 }
1521 else
1522 {
1523 DWORD ncpylen = min((*dwComponentLen)-1, len);
1524 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1525 (*lppszComponent)[ncpylen] = '\0';
1526 *dwComponentLen = ncpylen;
1527 }
1528 }
1529
1530 return TRUE;
1531 }
1532
1533 /***********************************************************************
1534 * InternetCrackUrlW (WININET.@)
1535 *
1536 * Break up URL into its components
1537 *
1538 * RETURNS
1539 * TRUE on success
1540 * FALSE on failure
1541 */
1542 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1543 LPURL_COMPONENTSW lpUC)
1544 {
1545 /*
1546 * RFC 1808
1547 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1548 *
1549 */
1550 LPCWSTR lpszParam = NULL;
1551 BOOL bIsAbsolute = FALSE;
1552 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1553 LPCWSTR lpszcp = NULL;
1554 LPWSTR lpszUrl_decode = NULL;
1555 DWORD dwUrlLength = dwUrlLength_orig;
1556
1557 TRACE("(%s %u %x %p)\n",
1558 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1559 dwUrlLength, dwFlags, lpUC);
1560
1561 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1562 {
1563 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1564 return FALSE;
1565 }
1566 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1567
1568 if (dwFlags & ICU_DECODE)
1569 {
1570 WCHAR *url_tmp;
1571 DWORD len = dwUrlLength + 1;
1572
1573 if (!(url_tmp = heap_alloc(len * sizeof(WCHAR))))
1574 {
1575 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1576 return FALSE;
1577 }
1578 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1579 url_tmp[dwUrlLength] = 0;
1580 if (!(lpszUrl_decode = heap_alloc(len * sizeof(WCHAR))))
1581 {
1582 HeapFree(GetProcessHeap(), 0, url_tmp);
1583 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1584 return FALSE;
1585 }
1586 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1587 {
1588 dwUrlLength = len;
1589 lpszUrl = lpszUrl_decode;
1590 }
1591 HeapFree(GetProcessHeap(), 0, url_tmp);
1592 }
1593 lpszap = lpszUrl;
1594
1595 /* Determine if the URI is absolute. */
1596 while (lpszap - lpszUrl < dwUrlLength)
1597 {
1598 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1599 {
1600 lpszap++;
1601 continue;
1602 }
1603 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1604 {
1605 bIsAbsolute = TRUE;
1606 lpszcp = lpszap;
1607 }
1608 else
1609 {
1610 lpszcp = lpszUrl; /* Relative url */
1611 }
1612
1613 break;
1614 }
1615
1616 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1617 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1618
1619 /* Parse <params> */
1620 lpszParam = memchrW(lpszap, ';', dwUrlLength - (lpszap - lpszUrl));
1621 if(!lpszParam)
1622 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1623 if(!lpszParam)
1624 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1625
1626 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1627 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1628
1629 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1630 {
1631 LPCWSTR lpszNetLoc;
1632
1633 /* Get scheme first. */
1634 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1635 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1636 lpszUrl, lpszcp - lpszUrl);
1637
1638 /* Eat ':' in protocol. */
1639 lpszcp++;
1640
1641 /* double slash indicates the net_loc portion is present */
1642 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1643 {
1644 lpszcp += 2;
1645
1646 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1647 if (lpszParam)
1648 {
1649 if (lpszNetLoc)
1650 lpszNetLoc = min(lpszNetLoc, lpszParam);
1651 else
1652 lpszNetLoc = lpszParam;
1653 }
1654 else if (!lpszNetLoc)
1655 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1656
1657 /* Parse net-loc */
1658 if (lpszNetLoc)
1659 {
1660 LPCWSTR lpszHost;
1661 LPCWSTR lpszPort;
1662
1663 /* [<user>[<:password>]@]<host>[:<port>] */
1664 /* First find the user and password if they exist */
1665
1666 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1667 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1668 {
1669 /* username and password not specified. */
1670 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1671 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1672 }
1673 else /* Parse out username and password */
1674 {
1675 LPCWSTR lpszUser = lpszcp;
1676 LPCWSTR lpszPasswd = lpszHost;
1677
1678 while (lpszcp < lpszHost)
1679 {
1680 if (*lpszcp == ':')
1681 lpszPasswd = lpszcp;
1682
1683 lpszcp++;
1684 }
1685
1686 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1687 lpszUser, lpszPasswd - lpszUser);
1688
1689 if (lpszPasswd != lpszHost)
1690 lpszPasswd++;
1691 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1692 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1693 lpszHost - lpszPasswd);
1694
1695 lpszcp++; /* Advance to beginning of host */
1696 }
1697
1698 /* Parse <host><:port> */
1699
1700 lpszHost = lpszcp;
1701 lpszPort = lpszNetLoc;
1702
1703 /* special case for res:// URLs: there is no port here, so the host is the
1704 entire string up to the first '/' */
1705 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1706 {
1707 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1708 lpszHost, lpszPort - lpszHost);
1709 lpszcp=lpszNetLoc;
1710 }
1711 else
1712 {
1713 while (lpszcp < lpszNetLoc)
1714 {
1715 if (*lpszcp == ':')
1716 lpszPort = lpszcp;
1717
1718 lpszcp++;
1719 }
1720
1721 /* If the scheme is "file" and the host is just one letter, it's not a host */
1722 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1723 {
1724 lpszcp=lpszHost;
1725 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1726 NULL, 0);
1727 }
1728 else
1729 {
1730 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1731 lpszHost, lpszPort - lpszHost);
1732 if (lpszPort != lpszNetLoc)
1733 lpUC->nPort = atoiW(++lpszPort);
1734 else switch (lpUC->nScheme)
1735 {
1736 case INTERNET_SCHEME_HTTP:
1737 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1738 break;
1739 case INTERNET_SCHEME_HTTPS:
1740 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1741 break;
1742 case INTERNET_SCHEME_FTP:
1743 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1744 break;
1745 case INTERNET_SCHEME_GOPHER:
1746 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1747 break;
1748 default:
1749 break;
1750 }
1751 }
1752 }
1753 }
1754 }
1755 else
1756 {
1757 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1758 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1759 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1760 }
1761 }
1762 else
1763 {
1764 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1765 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1766 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1767 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1768 }
1769
1770 /* Here lpszcp points to:
1771 *
1772 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1773 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1774 */
1775 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1776 {
1777 DWORD len;
1778
1779 /* Only truncate the parameter list if it's already been saved
1780 * in lpUC->lpszExtraInfo.
1781 */
1782 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1783 len = lpszParam - lpszcp;
1784 else
1785 {
1786 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1787 * newlines if necessary.
1788 */
1789 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1790 if (lpsznewline != NULL)
1791 len = lpsznewline - lpszcp;
1792 else
1793 len = dwUrlLength-(lpszcp-lpszUrl);
1794 }
1795 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1796 lpUC->nScheme == INTERNET_SCHEME_FILE)
1797 {
1798 WCHAR tmppath[MAX_PATH];
1799 if (*lpszcp == '/')
1800 {
1801 len = MAX_PATH;
1802 PathCreateFromUrlW(lpszUrl_orig, tmppath, &len, 0);
1803 }
1804 else
1805 {
1806 WCHAR *iter;
1807 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1808 tmppath[len] = '\0';
1809
1810 iter = tmppath;
1811 while (*iter) {
1812 if (*iter == '/')
1813 *iter = '\\';
1814 ++iter;
1815 }
1816 }
1817 /* if ends in \. or \.. append a backslash */
1818 if (tmppath[len - 1] == '.' &&
1819 (tmppath[len - 2] == '\\' ||
1820 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
1821 {
1822 if (len < MAX_PATH - 1)
1823 {
1824 tmppath[len] = '\\';
1825 tmppath[len+1] = '\0';
1826 ++len;
1827 }
1828 }
1829 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1830 tmppath, len);
1831 }
1832 else
1833 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1834 lpszcp, len);
1835 }
1836 else
1837 {
1838 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
1839 lpUC->lpszUrlPath[0] = 0;
1840 lpUC->dwUrlPathLength = 0;
1841 }
1842
1843 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1844 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1845 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1846 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1847 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1848
1849 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1850 return TRUE;
1851 }
1852
1853 /***********************************************************************
1854 * InternetAttemptConnect (WININET.@)
1855 *
1856 * Attempt to make a connection to the internet
1857 *
1858 * RETURNS
1859 * ERROR_SUCCESS on success
1860 * Error value on failure
1861 *
1862 */
1863 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1864 {
1865 FIXME("Stub\n");
1866 return ERROR_SUCCESS;
1867 }
1868
1869
1870 /***********************************************************************
1871 * InternetCanonicalizeUrlA (WININET.@)
1872 *
1873 * Escape unsafe characters and spaces
1874 *
1875 * RETURNS
1876 * TRUE on success
1877 * FALSE on failure
1878 *
1879 */
1880 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1881 LPDWORD lpdwBufferLength, DWORD dwFlags)
1882 {
1883 HRESULT hr;
1884 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1885
1886 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1887 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1888
1889 if(dwFlags & ICU_DECODE)
1890 {
1891 dwURLFlags |= URL_UNESCAPE;
1892 dwFlags &= ~ICU_DECODE;
1893 }
1894
1895 if(dwFlags & ICU_ESCAPE)
1896 {
1897 dwURLFlags |= URL_UNESCAPE;
1898 dwFlags &= ~ICU_ESCAPE;
1899 }
1900
1901 if(dwFlags & ICU_BROWSER_MODE)
1902 {
1903 dwURLFlags |= URL_BROWSER_MODE;
1904 dwFlags &= ~ICU_BROWSER_MODE;
1905 }
1906
1907 if(dwFlags & ICU_NO_ENCODE)
1908 {
1909 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1910 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1911 dwFlags &= ~ICU_NO_ENCODE;
1912 }
1913
1914 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1915
1916 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1917 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1918 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1919
1920 return (hr == S_OK) ? TRUE : FALSE;
1921 }
1922
1923 /***********************************************************************
1924 * InternetCanonicalizeUrlW (WININET.@)
1925 *
1926 * Escape unsafe characters and spaces
1927 *
1928 * RETURNS
1929 * TRUE on success
1930 * FALSE on failure
1931 *
1932 */
1933 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1934 LPDWORD lpdwBufferLength, DWORD dwFlags)
1935 {
1936 HRESULT hr;
1937 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1938
1939 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1940 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1941
1942 if(dwFlags & ICU_DECODE)
1943 {
1944 dwURLFlags |= URL_UNESCAPE;
1945 dwFlags &= ~ICU_DECODE;
1946 }
1947
1948 if(dwFlags & ICU_ESCAPE)
1949 {
1950 dwURLFlags |= URL_UNESCAPE;
1951 dwFlags &= ~ICU_ESCAPE;
1952 }
1953
1954 if(dwFlags & ICU_BROWSER_MODE)
1955 {
1956 dwURLFlags |= URL_BROWSER_MODE;
1957 dwFlags &= ~ICU_BROWSER_MODE;
1958 }
1959
1960 if(dwFlags & ICU_NO_ENCODE)
1961 {
1962 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1963 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1964 dwFlags &= ~ICU_NO_ENCODE;
1965 }
1966
1967 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1968
1969 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1970 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1971 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1972
1973 return (hr == S_OK) ? TRUE : FALSE;
1974 }
1975
1976 /* #################################################### */
1977
1978 static INTERNET_STATUS_CALLBACK set_status_callback(
1979 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1980 {
1981 INTERNET_STATUS_CALLBACK ret;
1982
1983 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1984 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1985
1986 ret = lpwh->lpfnStatusCB;
1987 lpwh->lpfnStatusCB = callback;
1988
1989 return ret;
1990 }
1991
1992 /***********************************************************************
1993 * InternetSetStatusCallbackA (WININET.@)
1994 *
1995 * Sets up a callback function which is called as progress is made
1996 * during an operation.
1997 *
1998 * RETURNS
1999 * Previous callback or NULL on success
2000 * INTERNET_INVALID_STATUS_CALLBACK on failure
2001 *
2002 */
2003 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2004 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2005 {
2006 INTERNET_STATUS_CALLBACK retVal;
2007 object_header_t *lpwh;
2008
2009 TRACE("%p\n", hInternet);
2010
2011 if (!(lpwh = get_handle_object(hInternet)))
2012 return INTERNET_INVALID_STATUS_CALLBACK;
2013
2014 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2015
2016 WININET_Release( lpwh );
2017 return retVal;
2018 }
2019
2020 /***********************************************************************
2021 * InternetSetStatusCallbackW (WININET.@)
2022 *
2023 * Sets up a callback function which is called as progress is made
2024 * during an operation.
2025 *
2026 * RETURNS
2027 * Previous callback or NULL on success
2028 * INTERNET_INVALID_STATUS_CALLBACK on failure
2029 *
2030 */
2031 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2032 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2033 {
2034 INTERNET_STATUS_CALLBACK retVal;
2035 object_header_t *lpwh;
2036
2037 TRACE("%p\n", hInternet);
2038
2039 if (!(lpwh = get_handle_object(hInternet)))
2040 return INTERNET_INVALID_STATUS_CALLBACK;
2041
2042 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2043
2044 WININET_Release( lpwh );
2045 return retVal;
2046 }
2047
2048 /***********************************************************************
2049 * InternetSetFilePointer (WININET.@)
2050 */
2051 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2052 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2053 {
2054 FIXME("stub\n");
2055 return FALSE;
2056 }
2057
2058 /***********************************************************************
2059 * InternetWriteFile (WININET.@)
2060 *
2061 * Write data to an open internet file
2062 *
2063 * RETURNS
2064 * TRUE on success
2065 * FALSE on failure
2066 *
2067 */
2068 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2069 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2070 {
2071 object_header_t *lpwh;
2072 BOOL res;
2073
2074 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2075
2076 lpwh = get_handle_object( hFile );
2077 if (!lpwh) {
2078 WARN("Invalid handle\n");
2079 SetLastError(ERROR_INVALID_HANDLE);
2080 return FALSE;
2081 }
2082
2083 if(lpwh->vtbl->WriteFile) {
2084 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2085 }else {
2086 WARN("No Writefile method.\n");
2087 res = ERROR_INVALID_HANDLE;
2088 }
2089
2090 WININET_Release( lpwh );
2091
2092 if(res != ERROR_SUCCESS)
2093 SetLastError(res);
2094 return res == ERROR_SUCCESS;
2095 }
2096
2097
2098 /***********************************************************************
2099 * InternetReadFile (WININET.@)
2100 *
2101 * Read data from an open internet file
2102 *
2103 * RETURNS
2104 * TRUE on success
2105 * FALSE on failure
2106 *
2107 */
2108 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2109 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2110 {
2111 object_header_t *hdr;
2112 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2113
2114 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2115
2116 hdr = get_handle_object(hFile);
2117 if (!hdr) {
2118 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2119 return FALSE;
2120 }
2121
2122 if(hdr->vtbl->ReadFile)
2123 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2124
2125 WININET_Release(hdr);
2126
2127 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2128 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2129
2130 if(res != ERROR_SUCCESS)
2131 SetLastError(res);
2132 return res == ERROR_SUCCESS;
2133 }
2134
2135 /***********************************************************************
2136 * InternetReadFileExA (WININET.@)
2137 *
2138 * Read data from an open internet file
2139 *
2140 * PARAMS
2141 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2142 * lpBuffersOut [I/O] Buffer.
2143 * dwFlags [I] Flags. See notes.
2144 * dwContext [I] Context for callbacks.
2145 *
2146 * RETURNS
2147 * TRUE on success
2148 * FALSE on failure
2149 *
2150 * NOTES
2151 * The parameter dwFlags include zero or more of the following flags:
2152 *|IRF_ASYNC - Makes the call asynchronous.
2153 *|IRF_SYNC - Makes the call synchronous.
2154 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2155 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2156 *
2157 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2158 *
2159 * SEE
2160 * InternetOpenUrlA(), HttpOpenRequestA()
2161 */
2162 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2163 DWORD dwFlags, DWORD_PTR dwContext)
2164 {
2165 object_header_t *hdr;
2166 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2167
2168 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2169
2170 hdr = get_handle_object(hFile);
2171 if (!hdr) {
2172 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2173 return FALSE;
2174 }
2175
2176 if(hdr->vtbl->ReadFileExA)
2177 res = hdr->vtbl->ReadFileExA(hdr, lpBuffersOut, dwFlags, dwContext);
2178
2179 WININET_Release(hdr);
2180
2181 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2182 res, lpBuffersOut->dwBufferLength);
2183
2184 if(res != ERROR_SUCCESS)
2185 SetLastError(res);
2186 return res == ERROR_SUCCESS;
2187 }
2188
2189 /***********************************************************************
2190 * InternetReadFileExW (WININET.@)
2191 * SEE
2192 * InternetReadFileExA()
2193 */
2194 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2195 DWORD dwFlags, DWORD_PTR dwContext)
2196 {
2197 object_header_t *hdr;
2198 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2199
2200 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2201
2202 hdr = get_handle_object(hFile);
2203 if (!hdr) {
2204 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2205 return FALSE;
2206 }
2207
2208 if(hdr->vtbl->ReadFileExW)
2209 res = hdr->vtbl->ReadFileExW(hdr, lpBuffer, dwFlags, dwContext);
2210
2211 WININET_Release(hdr);
2212
2213 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2214 res, lpBuffer->dwBufferLength);
2215
2216 if(res != ERROR_SUCCESS)
2217 SetLastError(res);
2218 return res == ERROR_SUCCESS;
2219 }
2220
2221 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2222 {
2223 static BOOL warn = TRUE;
2224
2225 switch(option) {
2226 case INTERNET_OPTION_REQUEST_FLAGS:
2227 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2228
2229 if (*size < sizeof(ULONG))
2230 return ERROR_INSUFFICIENT_BUFFER;
2231
2232 *(ULONG*)buffer = 4;
2233 *size = sizeof(ULONG);
2234
2235 return ERROR_SUCCESS;
2236
2237 case INTERNET_OPTION_HTTP_VERSION:
2238 if (*size < sizeof(HTTP_VERSION_INFO))
2239 return ERROR_INSUFFICIENT_BUFFER;
2240
2241 /*
2242 * Presently hardcoded to 1.1
2243 */
2244 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2245 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2246 *size = sizeof(HTTP_VERSION_INFO);
2247
2248 return ERROR_SUCCESS;
2249
2250 case INTERNET_OPTION_CONNECTED_STATE:
2251 if (warn) {
2252 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2253 warn = FALSE;
2254 }
2255 if (*size < sizeof(ULONG))
2256 return ERROR_INSUFFICIENT_BUFFER;
2257
2258 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2259 *size = sizeof(ULONG);
2260
2261 return ERROR_SUCCESS;
2262
2263 case INTERNET_OPTION_PROXY: {
2264 appinfo_t ai;
2265 BOOL ret;
2266
2267 TRACE("Getting global proxy info\n");
2268 memset(&ai, 0, sizeof(appinfo_t));
2269 INTERNET_ConfigureProxy(&ai);
2270
2271 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2272 APPINFO_Destroy(&ai.hdr);
2273 return ret;
2274 }
2275
2276 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2277 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2278
2279 if (*size < sizeof(ULONG))
2280 return ERROR_INSUFFICIENT_BUFFER;
2281
2282 *(ULONG*)buffer = 2;
2283 *size = sizeof(ULONG);
2284
2285 return ERROR_SUCCESS;
2286
2287 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2288 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2289
2290 if (*size < sizeof(ULONG))
2291 return ERROR_INSUFFICIENT_BUFFER;
2292
2293 *(ULONG*)buffer = 4;
2294 *size = sizeof(ULONG);
2295
2296 return ERROR_SUCCESS;
2297
2298 case INTERNET_OPTION_SECURITY_FLAGS:
2299 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2300 return ERROR_SUCCESS;
2301
2302 case INTERNET_OPTION_VERSION: {
2303 static const INTERNET_VERSION_INFO info = { 1, 2 };
2304
2305 TRACE("INTERNET_OPTION_VERSION\n");
2306
2307 if (*size < sizeof(INTERNET_VERSION_INFO))
2308 return ERROR_INSUFFICIENT_BUFFER;
2309
2310 memcpy(buffer, &info, sizeof(info));
2311 *size = sizeof(info);
2312
2313 return ERROR_SUCCESS;
2314 }
2315
2316 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2317 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2318 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2319 DWORD res = ERROR_SUCCESS, i;
2320 proxyinfo_t pi;
2321 LONG ret;
2322
2323 TRACE("Getting global proxy info\n");
2324 if((ret = INTERNET_LoadProxySettings(&pi)))
2325 return ret;
2326
2327 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2328
2329 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2330 FreeProxyInfo(&pi);
2331 return ERROR_INSUFFICIENT_BUFFER;
2332 }
2333
2334 for (i = 0; i < con->dwOptionCount; i++) {
2335 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2336 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2337
2338 switch (optionW->dwOption) {
2339 case INTERNET_PER_CONN_FLAGS:
2340 if(pi.dwProxyEnabled)
2341 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2342 else
2343 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2344 break;
2345
2346 case INTERNET_PER_CONN_PROXY_SERVER:
2347 if (unicode)
2348 optionW->Value.pszValue = heap_strdupW(pi.lpszProxyServer);
2349 else
2350 optionA->Value.pszValue = heap_strdupWtoA(pi.lpszProxyServer);
2351 break;
2352
2353 case INTERNET_PER_CONN_PROXY_BYPASS:
2354 if (unicode)
2355 optionW->Value.pszValue = heap_strdupW(pi.lpszProxyBypass);
2356 else
2357 optionA->Value.pszValue = heap_strdupWtoA(pi.lpszProxyBypass);
2358 break;
2359
2360 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2361 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2362 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2363 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2364 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2365 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2366 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2367 memset(&optionW->Value, 0, sizeof(optionW->Value));
2368 break;
2369
2370 default:
2371 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2372 res = ERROR_INVALID_PARAMETER;
2373 break;
2374 }
2375 }
2376 FreeProxyInfo(&pi);
2377
2378 return res;
2379 }
2380 case INTERNET_OPTION_USER_AGENT:
2381 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2382 case INTERNET_OPTION_POLICY:
2383 return ERROR_INVALID_PARAMETER;
2384 case INTERNET_OPTION_CONTEXT_VALUE:
2385 {
2386 if (!hdr)
2387 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2388 if (!size)
2389 return ERROR_INVALID_PARAMETER;
2390
2391 if (*size < sizeof(DWORD_PTR))
2392 {
2393 *size = sizeof(DWORD_PTR);
2394 return ERROR_INSUFFICIENT_BUFFER;
2395 }
2396 if (!buffer)
2397 return ERROR_INVALID_PARAMETER;
2398
2399 *(DWORD_PTR *)buffer = hdr->dwContext;
2400 *size = sizeof(DWORD_PTR);
2401 return ERROR_SUCCESS;
2402 }
2403 }
2404
2405 FIXME("Stub for %d\n", option);
2406 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2407 }
2408
2409 /***********************************************************************
2410 * InternetQueryOptionW (WININET.@)
2411 *
2412 * Queries an options on the specified handle
2413 *
2414 * RETURNS
2415 * TRUE on success
2416 * FALSE on failure
2417 *
2418 */
2419 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2420 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2421 {
2422 object_header_t *hdr;
2423 DWORD res = ERROR_INVALID_HANDLE;
2424
2425 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2426
2427 if(hInternet) {
2428 hdr = get_handle_object(hInternet);
2429 if (hdr) {
2430 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2431 WININET_Release(hdr);
2432 }
2433 }else {
2434 res = INET_QueryOption(NULL, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2435 }
2436
2437 if(res != ERROR_SUCCESS)
2438 SetLastError(res);
2439 return res == ERROR_SUCCESS;
2440 }
2441
2442 /***********************************************************************
2443 * InternetQueryOptionA (WININET.@)
2444 *
2445 * Queries an options on the specified handle
2446 *
2447 * RETURNS
2448 * TRUE on success
2449 * FALSE on failure
2450 *
2451 */
2452 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2453 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2454 {
2455 object_header_t *hdr;
2456 DWORD res = ERROR_INVALID_HANDLE;
2457
2458 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2459
2460 if(hInternet) {
2461 hdr = get_handle_object(hInternet);
2462 if (hdr) {
2463 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2464 WININET_Release(hdr);
2465 }
2466 }else {
2467 res = INET_QueryOption(NULL, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2468 }
2469
2470 if(res != ERROR_SUCCESS)
2471 SetLastError(res);
2472 return res == ERROR_SUCCESS;
2473 }
2474
2475
2476 /***********************************************************************
2477 * InternetSetOptionW (WININET.@)
2478 *
2479 * Sets an options on the specified handle
2480 *
2481 * RETURNS
2482 * TRUE on success
2483 * FALSE on failure
2484 *
2485 */
2486 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2487 LPVOID lpBuffer, DWORD dwBufferLength)
2488 {
2489 object_header_t *lpwhh;
2490 BOOL ret = TRUE;
2491
2492 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2493
2494 lpwhh = (object_header_t*) get_handle_object( hInternet );
2495 if(lpwhh && lpwhh->vtbl->SetOption) {
2496 DWORD res;
2497
2498 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2499 if(res != ERROR_INTERNET_INVALID_OPTION) {
2500 WININET_Release( lpwhh );
2501
2502 if(res != ERROR_SUCCESS)
2503 SetLastError(res);
2504
2505 return res == ERROR_SUCCESS;
2506 }
2507 }
2508
2509 switch (dwOption)
2510 {
2511 case INTERNET_OPTION_CALLBACK:
2512 {
2513 if (!lpwhh)
2514 {
2515 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2516 return FALSE;
2517 }
2518 WININET_Release(lpwhh);
2519 SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2520 return FALSE;
2521 }
2522 case INTERNET_OPTION_HTTP_VERSION:
2523 {
2524 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2525 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2526 }
2527 break;
2528 case INTERNET_OPTION_ERROR_MASK:
2529 {
2530 if(!lpwhh) {
2531 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2532 return FALSE;
2533 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2534 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2535 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2536 SetLastError(ERROR_INVALID_PARAMETER);
2537 ret = FALSE;
2538 } else if(dwBufferLength != sizeof(ULONG)) {
2539 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2540 ret = FALSE;
2541 } else
2542 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2543 }
2544 break;
2545 case INTERNET_OPTION_CODEPAGE:
2546 {
2547 ULONG codepage = *(ULONG *)lpBuffer;
2548 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2549 }
2550 break;
2551 case INTERNET_OPTION_REQUEST_PRIORITY:
2552 {
2553 ULONG priority = *(ULONG *)lpBuffer;
2554 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2555 }
2556 break;
2557 case INTERNET_OPTION_CONNECT_TIMEOUT:
2558 {
2559 ULONG connecttimeout = *(ULONG *)lpBuffer;
2560 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2561 }
2562 break;
2563 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2564 {
2565 ULONG receivetimeout = *(ULONG *)lpBuffer;
2566 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2567 }
2568 break;
2569 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2570 {
2571 ULONG conns = *(ULONG *)lpBuffer;
2572 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns);
2573 }
2574 break;
2575 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2576 {
2577 ULONG conns = *(ULONG *)lpBuffer;
2578 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns);
2579 }
2580 break;
2581 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2582 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2583 break;
2584 case INTERNET_OPTION_END_BROWSER_SESSION:
2585 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2586 break;
2587 case INTERNET_OPTION_CONNECTED_STATE:
2588 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2589 break;
2590 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2591 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2592 break;
2593 case INTERNET_OPTION_SEND_TIMEOUT:
2594 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2595 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2596 {
2597 ULONG timeout = *(ULONG *)lpBuffer;
2598 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2599 break;
2600 }
2601 case INTERNET_OPTION_CONNECT_RETRIES:
2602 {
2603 ULONG retries = *(ULONG *)lpBuffer;
2604 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2605 break;
2606 }
2607 case INTERNET_OPTION_CONTEXT_VALUE:
2608 {
2609 if (!lpwhh)
2610 {
2611 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2612 return FALSE;
2613 }
2614 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2615 {
2616 SetLastError(ERROR_INVALID_PARAMETER);
2617 ret = FALSE;
2618 }
2619 else
2620 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2621 break;
2622 }
2623 case INTERNET_OPTION_SECURITY_FLAGS:
2624 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2625 break;
2626 case INTERNET_OPTION_DISABLE_AUTODIAL:
2627 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2628 break;
2629 case INTERNET_OPTION_HTTP_DECODING:
2630 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2631 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2632 ret = FALSE;
2633 break;
2634 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2635 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2636 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2637 ret = FALSE;
2638 break;
2639 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2640 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2641 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2642 ret = FALSE;
2643 break;
2644 case INTERNET_OPTION_CODEPAGE_PATH:
2645 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2646 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2647 ret = FALSE;
2648 break;
2649 case INTERNET_OPTION_CODEPAGE_EXTRA:
2650 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2651 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2652 ret = FALSE;
2653 break;
2654 case INTERNET_OPTION_IDN:
2655 FIXME("INTERNET_OPTION_IDN; STUB\n");
2656 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2657 ret = FALSE;
2658 break;
2659 case INTERNET_OPTION_POLICY:
2660 SetLastError(ERROR_INVALID_PARAMETER);
2661 ret = FALSE;
2662 break;
2663 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2664 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2665 LONG res;
2666 int i;
2667 proxyinfo_t pi;
2668
2669 INTERNET_LoadProxySettings(&pi);
2670
2671 for (i = 0; i < con->dwOptionCount; i++) {
2672 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2673
2674 switch (option->dwOption) {
2675 case INTERNET_PER_CONN_PROXY_SERVER:
2676 HeapFree(GetProcessHeap(), 0, pi.lpszProxyServer);
2677 pi.lpszProxyServer = heap_strdupW(option->Value.pszValue);
2678 break;
2679
2680 case INTERNET_PER_CONN_FLAGS:
2681 if(option->Value.dwValue & PROXY_TYPE_PROXY)
2682 pi.dwProxyEnabled = 1;
2683 else
2684 {
2685 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
2686 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
2687 pi.dwProxyEnabled = 0;
2688 }
2689 break;
2690
2691 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2692 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2693 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2694 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2695 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2696 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2697 case INTERNET_PER_CONN_PROXY_BYPASS:
2698 FIXME("Unhandled dwOption %d\n", option->dwOption);
2699 break;
2700
2701 default:
2702 FIXME("Unknown dwOption %d\n", option->dwOption);
2703 SetLastError(ERROR_INVALID_PARAMETER);
2704 break;
2705 }
2706 }
2707
2708 if ((res = INTERNET_SaveProxySettings(&pi)))
2709 SetLastError(res);
2710
2711 FreeProxyInfo(&pi);
2712
2713 ret = (res == ERROR_SUCCESS);
2714 break;
2715 }
2716 default:
2717 FIXME("Option %d STUB\n",dwOption);
2718 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2719 ret = FALSE;
2720 break;
2721 }
2722
2723 if(lpwhh)
2724 WININET_Release( lpwhh );
2725
2726 return ret;
2727 }
2728
2729
2730 /***********************************************************************
2731 * InternetSetOptionA (WININET.@)
2732 *
2733 * Sets an options on the specified handle.
2734 *
2735 * RETURNS
2736 * TRUE on success
2737 * FALSE on failure
2738 *
2739 */
2740 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2741 LPVOID lpBuffer, DWORD dwBufferLength)
2742 {
2743 LPVOID wbuffer;
2744 DWORD wlen;
2745 BOOL r;
2746
2747 switch( dwOption )
2748 {
2749 case INTERNET_OPTION_CALLBACK:
2750 {
2751 object_header_t *lpwh;
2752
2753 if (!(lpwh = get_handle_object(hInternet)))
2754 {
2755 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2756 return FALSE;
2757 }
2758 WININET_Release(lpwh);
2759 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2760 return FALSE;
2761 }
2762 case INTERNET_OPTION_PROXY:
2763 {
2764 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2765 LPINTERNET_PROXY_INFOW piw;
2766 DWORD proxlen, prbylen;
2767 LPWSTR prox, prby;
2768
2769 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2770 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2771 wlen = sizeof(*piw) + proxlen + prbylen;
2772 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
2773 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2774 piw->dwAccessType = pi->dwAccessType;
2775 prox = (LPWSTR) &piw[1];
2776 prby = &prox[proxlen+1];
2777 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2778 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2779 piw->lpszProxy = prox;
2780 piw->lpszProxyBypass = prby;
2781 }
2782 break;
2783 case INTERNET_OPTION_USER_AGENT:
2784 case INTERNET_OPTION_USERNAME:
2785 case INTERNET_OPTION_PASSWORD:
2786 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2787 NULL, 0 );
2788 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
2789 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2790 wbuffer, wlen );
2791 break;
2792 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2793 int i;
2794 INTERNET_PER_CONN_OPTION_LISTW *listW;
2795 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
2796 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2797 wbuffer = heap_alloc(wlen);
2798 listW = wbuffer;
2799
2800 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2801 if (listA->pszConnection)
2802 {
2803 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
2804 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
2805 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
2806 }
2807 else
2808 listW->pszConnection = NULL;
2809 listW->dwOptionCount = listA->dwOptionCount;
2810 listW->dwOptionError = listA->dwOptionError;
2811 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
2812
2813 for (i = 0; i < listA->dwOptionCount; ++i) {
2814 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
2815 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
2816
2817 optW->dwOption = optA->dwOption;
2818
2819 switch (optA->dwOption) {
2820 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2821 case INTERNET_PER_CONN_PROXY_BYPASS:
2822 case INTERNET_PER_CONN_PROXY_SERVER:
2823 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2824 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2825 if (optA->Value.pszValue)
2826 {
2827 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
2828 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
2829 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
2830 }
2831 else
2832 optW->Value.pszValue = NULL;
2833 break;
2834 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2835 case INTERNET_PER_CONN_FLAGS:
2836 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2837 optW->Value.dwValue = optA->Value.dwValue;
2838 break;
2839 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2840 optW->Value.ftValue = optA->Value.ftValue;
2841 break;
2842 default:
2843 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
2844 optW->Value.dwValue = optA->Value.dwValue;
2845 break;
2846 }
2847 }
2848 }
2849 break;
2850 default:
2851 wbuffer = lpBuffer;
2852 wlen = dwBufferLength;
2853 }
2854
2855 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2856
2857 if( lpBuffer != wbuffer )
2858 {
2859 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
2860 {
2861 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
2862 int i;
2863 for (i = 0; i < list->dwOptionCount; ++i) {
2864 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
2865 switch (opt->dwOption) {
2866 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2867 case INTERNET_PER_CONN_PROXY_BYPASS:
2868 case INTERNET_PER_CONN_PROXY_SERVER:
2869 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2870 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2871 HeapFree( GetProcessHeap(), 0, opt->Value.pszValue );
2872 break;
2873 default:
2874 break;
2875 }
2876 }
2877 HeapFree( GetProcessHeap(), 0, list->pOptions );
2878 }
2879 HeapFree( GetProcessHeap(), 0, wbuffer );
2880 }
2881
2882 return r;
2883 }
2884
2885
2886 /***********************************************************************
2887 * InternetSetOptionExA (WININET.@)
2888 */
2889 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2890 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2891 {
2892 FIXME("Flags %08x ignored\n", dwFlags);
2893 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2894 }
2895
2896 /***********************************************************************
2897 * InternetSetOptionExW (WININET.@)
2898 */
2899 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2900 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2901 {
2902 FIXME("Flags %08x ignored\n", dwFlags);
2903 if( dwFlags & ~ISO_VALID_FLAGS )
2904 {
2905 SetLastError( ERROR_INVALID_PARAMETER );
2906 return FALSE;
2907 }
2908 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2909 }
2910
2911 static const WCHAR WININET_wkday[7][4] =
2912 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2913 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2914 static const WCHAR WININET_month[12][4] =
2915 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2916 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2917 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2918
2919 /***********************************************************************
2920 * InternetTimeFromSystemTimeA (WININET.@)
2921 */
2922 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2923 {
2924 BOOL ret;
2925 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2926
2927 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2928
2929 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2930 {
2931 SetLastError(ERROR_INVALID_PARAMETER);
2932 return FALSE;
2933 }
2934
2935 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2936 {
2937 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2938 return FALSE;
2939 }
2940
2941 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2942 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2943
2944 return ret;
2945 }
2946
2947 /***********************************************************************
2948 * InternetTimeFromSystemTimeW (WININET.@)
2949 */
2950 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2951 {
2952 static const WCHAR date[] =
2953 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2954 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2955
2956 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2957
2958 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2959 {
2960 SetLastError(ERROR_INVALID_PARAMETER);
2961 return FALSE;
2962 }
2963
2964 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2965 {
2966 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2967 return FALSE;
2968 }
2969
2970 sprintfW( string, date,
2971 WININET_wkday[time->wDayOfWeek],
2972 time->wDay,
2973 WININET_month[time->wMonth - 1],
2974 time->wYear,
2975 time->wHour,
2976 time->wMinute,
2977 time->wSecond );
2978
2979 return TRUE;
2980 }
2981
2982 /***********************************************************************
2983 * InternetTimeToSystemTimeA (WININET.@)
2984 */
2985 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2986 {
2987 BOOL ret = FALSE;
2988 WCHAR *stringW;
2989
2990 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2991
2992 stringW = heap_strdupAtoW(string);
2993 if (stringW)
2994 {
2995 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2996 HeapFree( GetProcessHeap(), 0, stringW );
2997 }
2998 return ret;
2999 }
3000
3001 /***********************************************************************
3002 * InternetTimeToSystemTimeW (WININET.@)
3003 */
3004 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3005 {
3006 unsigned int i;
3007 const WCHAR *s = string;
3008 WCHAR *end;
3009
3010 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3011
3012 if (!string || !time) return FALSE;
3013
3014 /* Windows does this too */
3015 GetSystemTime( time );
3016
3017 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3018 * a SYSTEMTIME structure.
3019 */
3020
3021 while (*s && !isalphaW( *s )) s++;
3022 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3023 time->wDayOfWeek = 7;
3024
3025 for (i = 0; i < 7; i++)
3026 {
3027 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
3028 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
3029 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
3030 {
3031 time->wDayOfWeek = i;
3032 break;
3033 }
3034 }
3035
3036 if (time->wDayOfWeek > 6) return TRUE;
3037 while (*s && !isdigitW( *s )) s++;
3038 time->wDay = strtolW( s, &end, 10 );
3039 s = end;
3040
3041 while (*s && !isalphaW( *s )) s++;
3042 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3043 time->wMonth = 0;
3044
3045 for (i = 0; i < 12; i++)
3046 {
3047 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
3048 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
3049 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
3050 {
3051 time->wMonth = i + 1;
3052 break;
3053 }
3054 }
3055 if (time->wMonth == 0) return TRUE;
3056
3057 while (*s && !isdigitW( *s )) s++;
3058 if (*s == '\0') return TRUE;
3059 time->wYear = strtolW( s, &end, 10 );
3060 s = end;
3061
3062 while (*s && !isdigitW( *s )) s++;
3063 if (*s == '\0') return TRUE;
3064 time->wHour = strtolW( s, &end, 10 );
3065 s = end;
3066
3067 while (*s && !isdigitW( *s )) s++;
3068 if (*s == '\0') return TRUE;
3069 time->wMinute = strtolW( s, &end, 10 );
3070 s = end;
3071
3072 while (*s && !isdigitW( *s )) s++;
3073 if (*s == '\0') return TRUE;
3074 time->wSecond = strtolW( s, &end, 10 );
3075 s = end;
3076
3077 time->wMilliseconds = 0;
3078 return TRUE;
3079 }
3080
3081 /***********************************************************************
3082 * InternetCheckConnectionW (WININET.@)
3083 *
3084 * Pings a requested host to check internet connection
3085 *
3086 * RETURNS
3087 * TRUE on success and FALSE on failure. If a failure then
3088 * ERROR_NOT_CONNECTED is placed into GetLastError
3089 *
3090 */
3091 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3092 {
3093 /*
3094 * this is a kludge which runs the resident ping program and reads the output.
3095 *
3096 * Anyone have a better idea?
3097 */
3098
3099 BOOL rc = FALSE;
3100 static const CHAR ping[] = "ping -c 1 ";
3101 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3102 CHAR *command = NULL;
3103 WCHAR hostW[1024];
3104 DWORD len;
3105 INTERNET_PORT port;
3106 int status = -1;
3107
3108 FIXME("\n");
3109
3110 /*
3111 * Crack or set the Address
3112 */
3113 if (lpszUrl == NULL)
3114 {
3115 /*
3116 * According to the doc we are supposed to use the ip for the next
3117 * server in the WnInet internal server database. I have
3118 * no idea what that is or how to get it.
3119 *
3120 * So someone needs to implement this.
3121 */
3122 FIXME("Unimplemented with URL of NULL\n");
3123 return TRUE;
3124 }
3125 else
3126 {
3127 URL_COMPONENTSW components;
3128
3129 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3130 components.lpszHostName = (LPWSTR)hostW;
3131 components.dwHostNameLength = 1024;
3132
3133 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3134 goto End;
3135
3136 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3137 port = components.nPort;
3138 TRACE("port: %d\n", port);
3139 }
3140
3141 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3142 {
3143 struct sockaddr_storage saddr;
3144 socklen_t sa_len = sizeof(saddr);
3145 int fd;
3146
3147 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
3148 goto End;
3149 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3150 if (fd != -1)
3151 {
3152 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3153 rc = TRUE;
3154 close(fd);
3155 }
3156 }
3157 else
3158 {
3159 /*
3160 * Build our ping command
3161 */
3162 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3163 command = heap_alloc(strlen(ping)+len+strlen(redirect));
3164 strcpy(command,ping);
3165 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3166 strcat(command,redirect);
3167
3168 TRACE("Ping command is : %s\n",command);
3169
3170 status = system(command);
3171
3172 TRACE("Ping returned a code of %i\n",status);
3173
3174 /* Ping return code of 0 indicates success */
3175 if (status == 0)
3176 rc = TRUE;
3177 }
3178
3179 End:
3180
3181 HeapFree( GetProcessHeap(), 0, command );
3182 if (rc == FALSE)
3183 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3184
3185 return rc;
3186 }
3187
3188
3189 /***********************************************************************
3190 * InternetCheckConnectionA (WININET.@)
3191 *
3192 * Pings a requested host to check internet connection
3193 *
3194 * RETURNS
3195 * TRUE on success and FALSE on failure. If a failure then
3196 * ERROR_NOT_CONNECTED is placed into GetLastError
3197 *
3198 */
3199 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3200 {
3201 WCHAR *url = NULL;
3202 BOOL rc;
3203
3204 if(lpszUrl) {
3205 url = heap_strdupAtoW(lpszUrl);
3206 if(!url)
3207 return FALSE;
3208 }
3209
3210 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3211
3212 HeapFree(GetProcessHeap(), 0, url);
3213 return rc;
3214 }
3215
3216
3217 /**********************************************************
3218 * INTERNET_InternetOpenUrlW (internal)
3219 *
3220 * Opens an URL
3221 *
3222 * RETURNS
3223 * handle of connection or NULL on failure
3224 */
3225 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3226 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3227 {
3228 URL_COMPONENTSW urlComponents;
3229 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
3230 WCHAR password[1024], path[2048], extra[1024];
3231 HINTERNET client = NULL, client1 = NULL;
3232 DWORD res;
3233
3234 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3235 dwHeadersLength, dwFlags, dwContext);
3236
3237 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3238 urlComponents.lpszScheme = protocol;
3239 urlComponents.dwSchemeLength = 32;
3240 urlComponents.lpszHostName = hostName;
3241 urlComponents.dwHostNameLength = MAXHOSTNAME;
3242 urlComponents.lpszUserName = userName;
3243 urlComponents.dwUserNameLength = 1024;
3244 urlComponents.lpszPassword = password;
3245 urlComponents.dwPasswordLength = 1024;
3246 urlComponents.lpszUrlPath = path;
3247 urlComponents.dwUrlPathLength = 2048;
3248 urlComponents.lpszExtraInfo = extra;
3249 urlComponents.dwExtraInfoLength = 1024;
3250 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3251 return NULL;
3252 switch(urlComponents.nScheme) {
3253 case INTERNET_SCHEME_FTP:
3254 if(urlComponents.nPort == 0)
3255 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3256 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3257 userName, password, dwFlags, dwContext, INET_OPENURL);
3258 if(client == NULL)
3259 break;
3260 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3261 if(client1 == NULL) {
3262 InternetCloseHandle(client);
3263 break;
3264 }
3265 break;
3266
3267 case INTERNET_SCHEME_HTTP:
3268 case INTERNET_SCHEME_HTTPS: {
3269 static const WCHAR szStars[] = { '*','/','*', 0 };
3270 LPCWSTR accept[2] = { szStars, NULL };
3271 if(urlComponents.nPort == 0) {
3272 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3273 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3274 else
3275 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3276 }
3277 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3278
3279 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3280 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3281 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3282 if(res != ERROR_SUCCESS) {
3283 INTERNET_SetLastError(res);
3284 break;
3285 }
3286
3287 if (urlComponents.dwExtraInfoLength) {
3288 WCHAR *path_extra;
3289 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3290
3291 if (!(path_extra = heap_alloc(len * sizeof(WCHAR))))
3292 {
3293 InternetCloseHandle(client);
3294 break;
3295 }
3296 strcpyW(path_extra, urlComponents.lpszUrlPath);
3297 strcatW(path_extra, urlComponents.lpszExtraInfo);
3298 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3299 HeapFree(GetProcessHeap(), 0, path_extra);
3300 }
3301 else
3302 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3303
3304 if(client1 == NULL) {
3305 InternetCloseHandle(client);
3306 break;
3307 }
3308 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3309 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3310 GetLastError() != ERROR_IO_PENDING) {
3311 InternetCloseHandle(client1);
3312 client1 = NULL;
3313 break;
3314 }
3315 }
3316 case INTERNET_SCHEME_GOPHER:
3317 /* gopher doesn't seem to be implemented in wine, but it's supposed
3318 * to be supported by InternetOpenUrlA. */
3319 default:
3320 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3321 break;
3322 }
3323
3324 TRACE(" %p <--\n", client1);
3325
3326 return client1;
3327 }
3328
3329 /**********************************************************
3330 * InternetOpenUrlW (WININET.@)
3331 *
3332 * Opens an URL
3333 *
3334 * RETURNS
3335 * handle of connection or NULL on failure
3336 */
3337 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3338 {
3339 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3340 appinfo_t *hIC = (appinfo_t*) workRequest->hdr;
3341
3342 TRACE("%p\n", hIC);
3343
3344 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3345 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3346 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3347 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3348 }
3349
3350 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3351 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3352 {
3353 HINTERNET ret = NULL;
3354 appinfo_t *hIC = NULL;
3355
3356 if (TRACE_ON(wininet)) {
3357 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3358 dwHeadersLength, dwFlags, dwContext);
3359 TRACE(" flags :");
3360 dump_INTERNET_FLAGS(dwFlags);
3361 }
3362
3363 if (!lpszUrl)
3364 {
3365 SetLastError(ERROR_INVALID_PARAMETER);
3366 goto lend;
3367 }
3368
3369 hIC = (appinfo_t*)get_handle_object( hInternet );
3370 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3371 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3372 goto lend;
3373 }
3374
3375 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3376 WORKREQUEST workRequest;
3377 struct WORKREQ_INTERNETOPENURLW *req;
3378
3379 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3380 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3381 req = &workRequest.u.InternetOpenUrlW;
3382 req->lpszUrl = heap_strdupW(lpszUrl);
3383 req->lpszHeaders = heap_strdupW(lpszHeaders);
3384 req->dwHeadersLength = dwHeadersLength;
3385 req->dwFlags = dwFlags;
3386 req->dwContext = dwContext;
3387
3388 INTERNET_AsyncCall(&workRequest);
3389 /*
3390 * This is from windows.
3391 */
3392 SetLastError(ERROR_IO_PENDING);
3393 } else {
3394 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3395 }
3396
3397 lend:
3398 if( hIC )
3399 WININET_Release( &hIC->hdr );
3400 TRACE(" %p <--\n", ret);
3401
3402 return ret;
3403 }
3404
3405 /**********************************************************
3406 * InternetOpenUrlA (WININET.@)
3407 *
3408 * Opens an URL
3409 *
3410 * RETURNS
3411 * handle of connection or NULL on failure
3412 */
3413 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3414 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3415 {
3416 HINTERNET rc = NULL;
3417 DWORD lenHeaders = 0;
3418 LPWSTR szUrl = NULL;
3419 LPWSTR szHeaders = NULL;
3420
3421 TRACE("\n");
3422
3423 if(lpszUrl) {
3424 szUrl = heap_strdupAtoW(lpszUrl);
3425 if(!szUrl)
3426 return NULL;
3427 }
3428
3429 if(lpszHeaders) {
3430 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3431 szHeaders = heap_alloc(lenHeaders*sizeof(WCHAR));
3432 if(!szHeaders) {
3433 HeapFree(GetProcessHeap(), 0, szUrl);
3434 return NULL;
3435 }
3436 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3437 }
3438
3439 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3440 lenHeaders, dwFlags, dwContext);
3441
3442 HeapFree(GetProcessHeap(), 0, szUrl);
3443 HeapFree(GetProcessHeap(), 0, szHeaders);
3444
3445 return rc;
3446 }
3447
3448
3449 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3450 {
3451 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3452
3453 if (lpwite)
3454 {
3455 lpwite->dwError = 0;
3456 lpwite->response[0] = '\0';
3457 }
3458
3459 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3460 {
3461 HeapFree(GetProcessHeap(), 0, lpwite);
3462 return NULL;
3463 }
3464
3465 return lpwite;
3466 }
3467
3468
3469 /***********************************************************************
3470 * INTERNET_SetLastError (internal)
3471 *
3472 * Set last thread specific error
3473 *
3474 * RETURNS
3475 *
3476 */
3477 void INTERNET_SetLastError(DWORD dwError)
3478 {
3479 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3480
3481 if (!lpwite)
3482 lpwite = INTERNET_AllocThreadError();
3483
3484 SetLastError(dwError);
3485 if(lpwite)
3486 lpwite->dwError = dwError;
3487 }
3488
3489
3490 /***********************************************************************
3491 * INTERNET_GetLastError (internal)
3492 *
3493 * Get last thread specific error
3494 *
3495 * RETURNS
3496 *
3497 */
3498 DWORD INTERNET_GetLastError(void)
3499 {
3500 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3501 if (!lpwite) return 0;
3502 /* TlsGetValue clears last error, so set it again here */
3503 SetLastError(lpwite->dwError);
3504 return lpwite->dwError;
3505 }
3506
3507
3508 /***********************************************************************
3509 * INTERNET_WorkerThreadFunc (internal)
3510 *
3511 * Worker thread execution function
3512 *
3513 * RETURNS
3514 *
3515 */
3516 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3517 {
3518 LPWORKREQUEST lpRequest = lpvParam;
3519 WORKREQUEST workRequest;
3520
3521 TRACE("\n");
3522
3523 workRequest = *lpRequest;
3524 HeapFree(GetProcessHeap(), 0, lpRequest);
3525
3526 workRequest.asyncproc(&workRequest);
3527 WININET_Release( workRequest.hdr );
3528
3529 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3530 {
3531 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
3532 TlsSetValue(g_dwTlsErrIndex, NULL);
3533 }
3534 return TRUE;
3535 }
3536
3537
3538 /***********************************************************************
3539 * INTERNET_AsyncCall (internal)
3540 *
3541 * Retrieves work request from queue
3542 *
3543 * RETURNS
3544 *
3545 */
3546 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3547 {
3548 BOOL bSuccess;
3549 LPWORKREQUEST lpNewRequest;
3550
3551 TRACE("\n");
3552
3553 lpNewRequest = heap_alloc(sizeof(WORKREQUEST));
3554 if (!lpNewRequest)
3555 return ERROR_OUTOFMEMORY;
3556
3557 *lpNewRequest = *lpWorkRequest;
3558
3559 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3560 if (!bSuccess)
3561 {
3562 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3563 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3564 }
3565
3566 return ERROR_SUCCESS;
3567 }
3568
3569
3570 /***********************************************************************
3571 * INTERNET_GetResponseBuffer (internal)
3572 *
3573 * RETURNS
3574 *
3575 */
3576 LPSTR INTERNET_GetResponseBuffer(void)
3577 {
3578 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3579 if (!lpwite)
3580 lpwite = INTERNET_AllocThreadError();
3581 TRACE("\n");
3582 return lpwite->response;
3583 }
3584
3585 /***********************************************************************
3586 * INTERNET_GetNextLine (internal)
3587 *
3588 * Parse next line in directory string listing
3589 *
3590 * RETURNS
3591 * Pointer to beginning of next line
3592 * NULL on failure
3593 *
3594 */
3595
3596 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3597 {
3598 fd_set infd;
3599 struct timeval tv;
3600 BOOL bSuccess = FALSE;
3601 INT nRecv = 0;
3602 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3603
3604 TRACE("\n");
3605
3606 FD_ZERO(&infd);
3607 FD_SET(nSocket,&infd);
3608 tv.tv_sec = RESPONSE_TIMEOUT;
3609 tv.tv_usec = 0;
3610
3611 while (nRecv < MAX_REPLY_LEN)
3612 {
3613 if (select(0, &infd, NULL, NULL, &tv) > 0)
3614 {
3615 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3616 {
3617 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3618 goto lend;
3619 }
3620
3621 if (lpszBuffer[nRecv] == '\n')
3622 {
3623 bSuccess = TRUE;
3624 break;
3625 }
3626 if (lpszBuffer[nRecv] != '\r')
3627 nRecv++;
3628 }
3629 else
3630 {
3631 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3632 goto lend;
3633 }
3634 }
3635
3636 lend:
3637 if (bSuccess)
3638 {
3639 lpszBuffer[nRecv] = '\0';
3640 *dwLen = nRecv - 1;
3641 TRACE(":%d %s\n", nRecv, lpszBuffer);
3642 return lpszBuffer;
3643 }
3644 else
3645 {
3646 return NULL;
3647 }
3648 }
3649
3650 /**********************************************************
3651 * InternetQueryDataAvailable (WININET.@)
3652 *
3653 * Determines how much data is available to be read.
3654 *
3655 * RETURNS
3656 * TRUE on success, FALSE if an error occurred. If
3657 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3658 * no data is presently available, FALSE is returned with
3659 * the last error ERROR_IO_PENDING; a callback with status
3660 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3661 * data is available.
3662 */
3663 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3664 LPDWORD lpdwNumberOfBytesAvailble,
3665 DWORD dwFlags, DWORD_PTR dwContext)
3666 {
3667 object_header_t *hdr;
3668 DWORD res;
3669
3670 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3671
3672 hdr = get_handle_object( hFile );
3673 if (!hdr) {
3674 SetLastError(ERROR_INVALID_HANDLE);
3675 return FALSE;
3676 }
3677
3678 if(hdr->vtbl->QueryDataAvailable) {
3679 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3680 }else {
3681 WARN("wrong handle\n");
3682 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3683 }
3684
3685 WININET_Release(hdr);
3686
3687 if(res != ERROR_SUCCESS)
3688 SetLastError(res);
3689 return res == ERROR_SUCCESS;
3690 }
3691
3692
3693 /***********************************************************************
3694 * InternetLockRequestFile (WININET.@)
3695 */
3696 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3697 *lphLockReqHandle)
3698 {
3699 FIXME("STUB\n");
3700 return FALSE;
3701 }
3702
3703 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3704 {
3705 FIXME("STUB\n");
3706 return FALSE;
3707 }
3708
3709
3710 /***********************************************************************
3711 * InternetAutodial (WININET.@)
3712 *
3713 * On windows this function is supposed to dial the default internet
3714 * connection. We don't want to have Wine dial out to the internet so
3715 * we return TRUE by default. It might be nice to check if we are connected.
3716 *
3717 * RETURNS
3718 * TRUE on success
3719 * FALSE on failure
3720 *
3721 */
3722 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3723 {
3724 FIXME("STUB\n");
3725
3726 /* Tell that we are connected to the internet. */
3727 return TRUE;
3728 }
3729
3730 /***********************************************************************
3731 * InternetAutodialHangup (WININET.@)
3732 *
3733 * Hangs up a connection made with InternetAutodial
3734 *
3735 * PARAM
3736 * dwReserved
3737 * RETURNS
3738 * TRUE on success
3739 * FALSE on failure
3740 *
3741 */
3742 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3743 {
3744 FIXME("STUB\n");
3745
3746 /* we didn't dial, we don't disconnect */
3747 return TRUE;
3748 }
3749
3750 /***********************************************************************
3751 * InternetCombineUrlA (WININET.@)
3752 *
3753 * Combine a base URL with a relative URL
3754 *
3755 * RETURNS
3756 * TRUE on success
3757 * FALSE on failure
3758 *
3759 */
3760
3761 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3762 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3763 DWORD dwFlags)
3764 {
3765 HRESULT hr=S_OK;
3766
3767 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3768
3769 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3770 dwFlags ^= ICU_NO_ENCODE;
3771 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3772
3773 return (hr==S_OK);
3774 }
3775
3776 /***********************************************************************
3777 * InternetCombineUrlW (WININET.@)
3778 *
3779 * Combine a base URL with a relative URL
3780 *
3781 * RETURNS
3782 * TRUE on success
3783 * FALSE on failure
3784 *
3785 */
3786
3787 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3788 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3789 DWORD dwFlags)
3790 {
3791 HRESULT hr=S_OK;
3792
3793 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3794
3795 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3796 dwFlags ^= ICU_NO_ENCODE;
3797 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3798
3799 return (hr==S_OK);
3800 }
3801
3802 /* max port num is 65535 => 5 digits */
3803 #define MAX_WORD_DIGITS 5
3804
3805 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3806 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3807 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3808 (url)->dw##component##Length : strlen((url)->lpsz##component))
3809
3810 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3811 {
3812 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3813 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3814 return TRUE;
3815 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3816 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3817 return TRUE;
3818 if ((nScheme == INTERNET_SCHEME_FTP) &&
3819 (nPort == INTERNET_DEFAULT_FTP_PORT))
3820 return TRUE;
3821 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3822 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3823 return TRUE;
3824
3825 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3826 return TRUE;
3827
3828 return FALSE;
3829 }
3830
3831 /* opaque urls do not fit into the standard url hierarchy and don't have
3832 * two following slashes */
3833 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3834 {
3835 return (nScheme != INTERNET_SCHEME_FTP) &&
3836 (nScheme != INTERNET_SCHEME_GOPHER) &&
3837 (nScheme != INTERNET_SCHEME_HTTP) &&
3838 (nScheme != INTERNET_SCHEME_HTTPS) &&
3839 (nScheme != INTERNET_SCHEME_FILE);
3840 }
3841
3842 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3843 {
3844 int index;
3845 if (scheme < INTERNET_SCHEME_FIRST)
3846 return NULL;
3847 index = scheme - INTERNET_SCHEME_FIRST;
3848 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3849 return NULL;
3850 return (LPCWSTR)url_schemes[index];
3851 }
3852
3853 /* we can calculate using ansi strings because we're just
3854 * calculating string length, not size
3855 */
3856 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3857 LPDWORD lpdwUrlLength)
3858 {
3859 INTERNET_SCHEME nScheme;
3860
3861 *lpdwUrlLength = 0;
3862
3863 if (lpUrlComponents->lpszScheme)
3864 {
3865 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3866 *lpdwUrlLength += dwLen;
3867 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3868 }
3869 else
3870 {
3871 LPCWSTR scheme;
3872
3873 nScheme = lpUrlComponents->nScheme;
3874
3875 if (nScheme == INTERNET_SCHEME_DEFAULT)
3876 nScheme = INTERNET_SCHEME_HTTP;
3877 scheme = INTERNET_GetSchemeString(nScheme);
3878 *lpdwUrlLength += strlenW(scheme);
3879 }
3880
3881 (*lpdwUrlLength)++; /* ':' */
3882 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3883 *lpdwUrlLength += strlen("//");
3884
3885 if (lpUrlComponents->lpszUserName)
3886 {
3887 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3888 *lpdwUrlLength += strlen("@");
3889 }
3890 else
3891 {
3892 if (lpUrlComponents->lpszPassword)
3893 {
3894 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3895 return FALSE;
3896 }
3897 }
3898
3899 if (lpUrlComponents->lpszPassword)
3900 {
3901 *lpdwUrlLength += strlen(":");
3902 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3903 }
3904
3905 if (lpUrlComponents->lpszHostName)
3906 {
3907 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3908
3909 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3910 {
3911 char szPort[MAX_WORD_DIGITS+1];
3912
3913 sprintf(szPort, "%d", lpUrlComponents->nPort);
3914 *lpdwUrlLength += strlen(szPort);
3915 *lpdwUrlLength += strlen(":");
3916 }
3917
3918 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3919 (*lpdwUrlLength)++; /* '/' */
3920 }
3921
3922 if (lpUrlComponents->lpszUrlPath)
3923 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3924
3925 if (lpUrlComponents->lpszExtraInfo)
3926 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
3927
3928 return TRUE;
3929 }
3930
3931 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3932 {
3933 INT len;
3934
3935 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3936
3937 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3938 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3939 urlCompW->nScheme = lpUrlComponents->nScheme;
3940 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3941 urlCompW->nPort = lpUrlComponents->nPort;
3942 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3943 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3944 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3945 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3946
3947 if (lpUrlComponents->lpszScheme)
3948 {
3949 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3950 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
3951 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3952 -1, urlCompW->lpszScheme, len);
3953 }
3954
3955 if (lpUrlComponents->lpszHostName)
3956 {
3957 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3958 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
3959 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3960 -1, urlCompW->lpszHostName, len);
3961 }
3962
3963 if (lpUrlComponents->lpszUserName)
3964 {
3965 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3966 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
3967 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3968 -1, urlCompW->lpszUserName, len);
3969 }
3970
3971 if (lpUrlComponents->lpszPassword)
3972 {
3973 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3974 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
3975 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3976 -1, urlCompW->lpszPassword, len);
3977 }
3978
3979 if (lpUrlComponents->lpszUrlPath)
3980 {
3981 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3982 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
3983 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3984 -1, urlCompW->lpszUrlPath, len);
3985 }
3986
3987 if (lpUrlComponents->lpszExtraInfo)
3988 {
3989 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3990 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
3991 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3992 -1, urlCompW->lpszExtraInfo, len);
3993 }
3994 }
3995
3996 /***********************************************************************
3997 * InternetCreateUrlA (WININET.@)
3998 *
3999 * See InternetCreateUrlW.
4000 */
4001 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4002 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4003 {
4004 BOOL ret;
4005 LPWSTR urlW = NULL;
4006 URL_COMPONENTSW urlCompW;
4007
4008 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4009
4010 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4011 {
4012 SetLastError(ERROR_INVALID_PARAMETER);
4013 return FALSE;
4014 }
4015
4016 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4017
4018 if (lpszUrl)
4019 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4020
4021 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4022
4023 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4024 *lpdwUrlLength /= sizeof(WCHAR);
4025
4026 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4027 * minus one, so add one to leave room for NULL terminator
4028 */
4029 if (ret)
4030 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4031
4032 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
4033 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
4034 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
4035 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
4036 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
4037 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
4038 HeapFree(GetProcessHeap(), 0, urlW);
4039
4040 return ret;
4041 }
4042
4043 /***********************************************************************
4044 * InternetCreateUrlW (WININET.@)
4045 *
4046 * Creates a URL from its component parts.
4047 *
4048 * PARAMS
4049 * lpUrlComponents [I] URL Components.
4050 * dwFlags [I] Flags. See notes.
4051 * lpszUrl [I] Buffer in which to store the created URL.
4052 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4053 * lpszUrl in characters. On output, the number of bytes
4054 * required to store the URL including terminator.
4055 *
4056 * NOTES
4057 *
4058 * The dwFlags parameter can be zero or more of the following:
4059 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4060 *
4061 * RETURNS
4062 * TRUE on success
4063 * FALSE on failure
4064 *
4065 */
4066 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4067 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4068 {
4069 DWORD dwLen;
4070 INTERNET_SCHEME nScheme;
4071
4072 static const WCHAR slashSlashW[] = {'/','/'};
4073 static const WCHAR fmtW[] = {'%','u',0};
4074
4075 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4076
4077 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4078 {
4079 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4080 return FALSE;
4081 }
4082
4083 if (!calc_url_length(lpUrlComponents, &dwLen))
4084 return FALSE;
4085
4086 if (!lpszUrl || *lpdwUrlLength < dwLen)
4087 {
4088 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4089 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4090 return FALSE;
4091 }
4092
4093 *lpdwUrlLength = dwLen;
4094 lpszUrl[0] = 0x00;
4095
4096 dwLen = 0;
4097
4098 if (lpUrlComponents->lpszScheme)
4099 {
4100 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4101 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4102 lpszUrl += dwLen;
4103
4104 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4105 }
4106 else
4107 {
4108 LPCWSTR scheme;
4109 nScheme = lpUrlComponents->nScheme;
4110
4111 if (nScheme == INTERNET_SCHEME_DEFAULT)
4112 nScheme = INTERNET_SCHEME_HTTP;
4113
4114 scheme = INTERNET_GetSchemeString(nScheme);
4115 dwLen = strlenW(scheme);
4116 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4117 lpszUrl += dwLen;
4118 }
4119
4120 /* all schemes are followed by at least a colon */
4121 *lpszUrl = ':';
4122 lpszUrl++;
4123
4124 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4125 {
4126 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4127 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4128 }
4129
4130 if (lpUrlComponents->lpszUserName)
4131 {
4132 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4133 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4134 lpszUrl += dwLen;
4135
4136 if (lpUrlComponents->lpszPassword)
4137 {
4138 *lpszUrl = ':';
4139 lpszUrl++;
4140
4141 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4142 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4143 lpszUrl += dwLen;
4144 }
4145
4146 *lpszUrl = '@';
4147 lpszUrl++;
4148 }
4149
4150 if (lpUrlComponents->lpszHostName)
4151 {
4152 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4153 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4154 lpszUrl += dwLen;
4155
4156 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4157 {
4158 WCHAR szPort[MAX_WORD_DIGITS+1];
4159
4160 sprintfW(szPort, fmtW, lpUrlComponents->nPort);
4161 *lpszUrl = ':';
4162 lpszUrl++;
4163 dwLen = strlenW(szPort);
4164 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4165 lpszUrl += dwLen;
4166 }
4167
4168 /* add slash between hostname and path if necessary */
4169 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4170 {
4171 *lpszUrl = '/';
4172 lpszUrl++;
4173 }
4174 }
4175
4176 if (lpUrlComponents->lpszUrlPath)
4177 {
4178 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4179 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4180 lpszUrl += dwLen;
4181 }
4182
4183 if (lpUrlComponents->lpszExtraInfo)
4184 {
4185 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4186 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4187 lpszUrl += dwLen;
4188 }
4189
4190 *lpszUrl = '\0';
4191
4192 return TRUE;
4193 }
4194
4195 /***********************************************************************
4196 * InternetConfirmZoneCrossingA (WININET.@)
4197 *
4198 */
4199 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4200 {
4201 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4202 return ERROR_SUCCESS;
4203 }
4204
4205 /***********************************************************************
4206 * InternetConfirmZoneCrossingW (WININET.@)
4207 *
4208 */
4209 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4210 {
4211 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4212 return ERROR_SUCCESS;
4213 }
4214
4215 static DWORD zone_preference = 3;
4216
4217 /***********************************************************************
4218 * PrivacySetZonePreferenceW (WININET.@)
4219 */
4220 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4221 {
4222 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4223
4224 zone_preference = template;
4225 return 0;
4226 }
4227
4228 /***********************************************************************
4229 * PrivacyGetZonePreferenceW (WININET.@)
4230 */
4231 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4232 LPWSTR preference, LPDWORD length )
4233 {
4234 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4235
4236 if (template) *template = zone_preference;
4237 return 0;
4238 }
4239
4240 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4241 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4242 {
4243 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4244 lpdwConnection, dwReserved);
4245 return ERROR_SUCCESS;
4246 }
4247
4248 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4249 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4250 {
4251 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4252 lpdwConnection, dwReserved);
4253 return ERROR_SUCCESS;
4254 }
4255
4256 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4257 {
4258 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4259 return TRUE;
4260 }
4261
4262 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4263 {
4264 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4265 return TRUE;
4266 }
4267
4268 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4269 {
4270 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4271 return ERROR_SUCCESS;
4272 }
4273
4274 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4275 PBYTE pbHexHash )
4276 {
4277 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4278 debugstr_w(pwszTarget), pbHexHash);
4279 return FALSE;
4280 }
4281
4282 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4283 {
4284 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4285 return FALSE;
4286 }
4287
4288 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4289 {
4290 FIXME("(%p, %08lx) stub\n", a, b);
4291 return 0;
4292 }