wined3d: Use a shader for unconverted blits.
[wine.git] / dlls / winhttp / session.c
blob0eca509b7eeb61583759d76cd8d60df87bf5a0c2
1 /*
2 * Copyright 2008 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
20 #include "wine/port.h"
21 #include "wine/debug.h"
23 #include <stdarg.h>
24 #include <stdlib.h>
26 #ifdef HAVE_CORESERVICES_CORESERVICES_H
27 #define GetCurrentThread MacGetCurrentThread
28 #define LoadResource MacLoadResource
29 #include <CoreServices/CoreServices.h>
30 #undef GetCurrentThread
31 #undef LoadResource
32 #undef DPRINTF
33 #endif
35 #include "windef.h"
36 #include "winbase.h"
37 #ifndef __MINGW32__
38 #define USE_WS_PREFIX
39 #endif
40 #include "winsock2.h"
41 #include "ws2ipdef.h"
42 #include "winhttp.h"
43 #include "wincrypt.h"
44 #include "winreg.h"
45 #define COBJMACROS
46 #include "ole2.h"
47 #include "dispex.h"
48 #include "activscp.h"
50 #include "winhttp_private.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
54 #define DEFAULT_RESOLVE_TIMEOUT 0
55 #define DEFAULT_CONNECT_TIMEOUT 20000
56 #define DEFAULT_SEND_TIMEOUT 30000
57 #define DEFAULT_RECEIVE_TIMEOUT 30000
59 void set_last_error( DWORD error )
61 /* FIXME */
62 SetLastError( error );
65 DWORD get_last_error( void )
67 /* FIXME */
68 return GetLastError();
71 void send_callback( object_header_t *hdr, DWORD status, LPVOID info, DWORD buflen )
73 if (hdr->callback && (hdr->notify_mask & status))
75 TRACE("%p, 0x%08x, %p, %u\n", hdr, status, info, buflen);
76 hdr->callback( hdr->handle, hdr->context, status, info, buflen );
77 TRACE("returning from 0x%08x callback\n", status);
81 /***********************************************************************
82 * WinHttpCheckPlatform (winhttp.@)
84 BOOL WINAPI WinHttpCheckPlatform( void )
86 TRACE("\n");
87 return TRUE;
90 /***********************************************************************
91 * session_destroy (internal)
93 static void session_destroy( object_header_t *hdr )
95 session_t *session = (session_t *)hdr;
96 struct list *item, *next;
97 domain_t *domain;
99 TRACE("%p\n", session);
101 LIST_FOR_EACH_SAFE( item, next, &session->cookie_cache )
103 domain = LIST_ENTRY( item, domain_t, entry );
104 delete_domain( domain );
106 heap_free( session->agent );
107 heap_free( session->proxy_server );
108 heap_free( session->proxy_bypass );
109 heap_free( session->proxy_username );
110 heap_free( session->proxy_password );
111 heap_free( session );
114 static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
116 session_t *session = (session_t *)hdr;
118 switch (option)
120 case WINHTTP_OPTION_REDIRECT_POLICY:
122 if (!buffer || *buflen < sizeof(DWORD))
124 *buflen = sizeof(DWORD);
125 set_last_error( ERROR_INSUFFICIENT_BUFFER );
126 return FALSE;
129 *(DWORD *)buffer = hdr->redirect_policy;
130 *buflen = sizeof(DWORD);
131 return TRUE;
133 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
134 *(DWORD *)buffer = session->resolve_timeout;
135 *buflen = sizeof(DWORD);
136 return TRUE;
137 case WINHTTP_OPTION_CONNECT_TIMEOUT:
138 *(DWORD *)buffer = session->connect_timeout;
139 *buflen = sizeof(DWORD);
140 return TRUE;
141 case WINHTTP_OPTION_SEND_TIMEOUT:
142 *(DWORD *)buffer = session->send_timeout;
143 *buflen = sizeof(DWORD);
144 return TRUE;
145 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
146 *(DWORD *)buffer = session->recv_timeout;
147 *buflen = sizeof(DWORD);
148 return TRUE;
149 default:
150 FIXME("unimplemented option %u\n", option);
151 set_last_error( ERROR_INVALID_PARAMETER );
152 return FALSE;
156 static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
158 session_t *session = (session_t *)hdr;
160 switch (option)
162 case WINHTTP_OPTION_PROXY:
164 WINHTTP_PROXY_INFO *pi = buffer;
166 FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
167 return TRUE;
169 case WINHTTP_OPTION_REDIRECT_POLICY:
171 DWORD policy;
173 if (buflen != sizeof(policy))
175 set_last_error( ERROR_INSUFFICIENT_BUFFER );
176 return FALSE;
179 policy = *(DWORD *)buffer;
180 TRACE("0x%x\n", policy);
181 hdr->redirect_policy = policy;
182 return TRUE;
184 case WINHTTP_OPTION_DISABLE_FEATURE:
185 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
186 return FALSE;
187 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
188 session->resolve_timeout = *(DWORD *)buffer;
189 return TRUE;
190 case WINHTTP_OPTION_CONNECT_TIMEOUT:
191 session->connect_timeout = *(DWORD *)buffer;
192 return TRUE;
193 case WINHTTP_OPTION_SEND_TIMEOUT:
194 session->send_timeout = *(DWORD *)buffer;
195 return TRUE;
196 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
197 session->recv_timeout = *(DWORD *)buffer;
198 return TRUE;
199 case WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH:
200 FIXME("WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH: 0x%x\n", *(DWORD *)buffer);
201 return TRUE;
202 default:
203 FIXME("unimplemented option %u\n", option);
204 set_last_error( ERROR_INVALID_PARAMETER );
205 return FALSE;
209 static const object_vtbl_t session_vtbl =
211 session_destroy,
212 session_query_option,
213 session_set_option
216 /***********************************************************************
217 * WinHttpOpen (winhttp.@)
219 HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags )
221 session_t *session;
222 HINTERNET handle = NULL;
224 TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent), access, debugstr_w(proxy), debugstr_w(bypass), flags);
226 if (!(session = heap_alloc_zero( sizeof(session_t) ))) return NULL;
228 session->hdr.type = WINHTTP_HANDLE_TYPE_SESSION;
229 session->hdr.vtbl = &session_vtbl;
230 session->hdr.flags = flags;
231 session->hdr.refs = 1;
232 session->hdr.redirect_policy = WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP;
233 list_init( &session->hdr.children );
234 session->resolve_timeout = DEFAULT_RESOLVE_TIMEOUT;
235 session->connect_timeout = DEFAULT_CONNECT_TIMEOUT;
236 session->send_timeout = DEFAULT_SEND_TIMEOUT;
237 session->recv_timeout = DEFAULT_RECEIVE_TIMEOUT;
238 list_init( &session->cookie_cache );
240 if (agent && !(session->agent = strdupW( agent ))) goto end;
241 if (access == WINHTTP_ACCESS_TYPE_DEFAULT_PROXY)
243 WINHTTP_PROXY_INFO info;
245 WinHttpGetDefaultProxyConfiguration( &info );
246 session->access = info.dwAccessType;
247 if (info.lpszProxy && !(session->proxy_server = strdupW( info.lpszProxy )))
249 GlobalFree( info.lpszProxy );
250 GlobalFree( info.lpszProxyBypass );
251 goto end;
253 if (info.lpszProxyBypass && !(session->proxy_bypass = strdupW( info.lpszProxyBypass )))
255 GlobalFree( info.lpszProxy );
256 GlobalFree( info.lpszProxyBypass );
257 goto end;
260 else if (access == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
262 session->access = access;
263 if (proxy && !(session->proxy_server = strdupW( proxy ))) goto end;
264 if (bypass && !(session->proxy_bypass = strdupW( bypass ))) goto end;
267 if (!(handle = alloc_handle( &session->hdr ))) goto end;
268 session->hdr.handle = handle;
270 end:
271 release_object( &session->hdr );
272 TRACE("returning %p\n", handle);
273 return handle;
276 /***********************************************************************
277 * connect_destroy (internal)
279 static void connect_destroy( object_header_t *hdr )
281 connect_t *connect = (connect_t *)hdr;
283 TRACE("%p\n", connect);
285 release_object( &connect->session->hdr );
287 heap_free( connect->hostname );
288 heap_free( connect->servername );
289 heap_free( connect->username );
290 heap_free( connect->password );
291 heap_free( connect );
294 static BOOL connect_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
296 connect_t *connect = (connect_t *)hdr;
298 switch (option)
300 case WINHTTP_OPTION_PARENT_HANDLE:
302 if (!buffer || *buflen < sizeof(HINTERNET))
304 *buflen = sizeof(HINTERNET);
305 set_last_error( ERROR_INSUFFICIENT_BUFFER );
306 return FALSE;
309 *(HINTERNET *)buffer = ((object_header_t *)connect->session)->handle;
310 *buflen = sizeof(HINTERNET);
311 return TRUE;
313 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
314 *(DWORD *)buffer = connect->session->resolve_timeout;
315 *buflen = sizeof(DWORD);
316 return TRUE;
317 case WINHTTP_OPTION_CONNECT_TIMEOUT:
318 *(DWORD *)buffer = connect->session->connect_timeout;
319 *buflen = sizeof(DWORD);
320 return TRUE;
321 case WINHTTP_OPTION_SEND_TIMEOUT:
322 *(DWORD *)buffer = connect->session->send_timeout;
323 *buflen = sizeof(DWORD);
324 return TRUE;
325 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
326 *(DWORD *)buffer = connect->session->recv_timeout;
327 *buflen = sizeof(DWORD);
328 return TRUE;
329 default:
330 FIXME("unimplemented option %u\n", option);
331 set_last_error( ERROR_INVALID_PARAMETER );
332 return FALSE;
336 static const object_vtbl_t connect_vtbl =
338 connect_destroy,
339 connect_query_option,
340 NULL
343 static BOOL domain_matches(LPCWSTR server, LPCWSTR domain)
345 static const WCHAR localW[] = { '<','l','o','c','a','l','>',0 };
346 BOOL ret = FALSE;
348 if (!strcmpiW( domain, localW ) && !strchrW( server, '.' ))
349 ret = TRUE;
350 else if (*domain == '*')
352 if (domain[1] == '.')
354 LPCWSTR dot;
356 /* For a hostname to match a wildcard, the last domain must match
357 * the wildcard exactly. E.g. if the wildcard is *.a.b, and the
358 * hostname is www.foo.a.b, it matches, but a.b does not.
360 dot = strchrW( server, '.' );
361 if (dot)
363 int len = strlenW( dot + 1 );
365 if (len > strlenW( domain + 2 ))
367 LPCWSTR ptr;
369 /* The server's domain is longer than the wildcard, so it
370 * could be a subdomain. Compare the last portion of the
371 * server's domain.
373 ptr = dot + len + 1 - strlenW( domain + 2 );
374 if (!strcmpiW( ptr, domain + 2 ))
376 /* This is only a match if the preceding character is
377 * a '.', i.e. that it is a matching domain. E.g.
378 * if domain is '*.b.c' and server is 'www.ab.c' they
379 * do not match.
381 ret = *(ptr - 1) == '.';
384 else
385 ret = !strcmpiW( dot + 1, domain + 2 );
389 else
390 ret = !strcmpiW( server, domain );
391 return ret;
394 /* Matches INTERNET_MAX_HOST_NAME_LENGTH in wininet.h, also RFC 1035 */
395 #define MAX_HOST_NAME_LENGTH 256
397 static BOOL should_bypass_proxy(session_t *session, LPCWSTR server)
399 LPCWSTR ptr;
400 BOOL ret = FALSE;
402 if (!session->proxy_bypass) return FALSE;
403 ptr = session->proxy_bypass;
404 do {
405 LPCWSTR tmp = ptr;
407 ptr = strchrW( ptr, ';' );
408 if (!ptr)
409 ptr = strchrW( tmp, ' ' );
410 if (ptr)
412 if (ptr - tmp < MAX_HOST_NAME_LENGTH)
414 WCHAR domain[MAX_HOST_NAME_LENGTH];
416 memcpy( domain, tmp, (ptr - tmp) * sizeof(WCHAR) );
417 domain[ptr - tmp] = 0;
418 ret = domain_matches( server, domain );
420 ptr += 1;
422 else if (*tmp)
423 ret = domain_matches( server, tmp );
424 } while (ptr && !ret);
425 return ret;
428 BOOL set_server_for_hostname( connect_t *connect, LPCWSTR server, INTERNET_PORT port )
430 session_t *session = connect->session;
431 BOOL ret = TRUE;
433 if (session->proxy_server && !should_bypass_proxy(session, server))
435 LPCWSTR colon;
437 if ((colon = strchrW( session->proxy_server, ':' )))
439 if (!connect->servername || strncmpiW( connect->servername,
440 session->proxy_server, colon - session->proxy_server - 1 ))
442 heap_free( connect->servername );
443 connect->resolved = FALSE;
444 if (!(connect->servername = heap_alloc(
445 (colon - session->proxy_server + 1) * sizeof(WCHAR) )))
447 ret = FALSE;
448 goto end;
450 memcpy( connect->servername, session->proxy_server,
451 (colon - session->proxy_server) * sizeof(WCHAR) );
452 connect->servername[colon - session->proxy_server] = 0;
453 if (*(colon + 1))
454 connect->serverport = atoiW( colon + 1 );
455 else
456 connect->serverport = INTERNET_DEFAULT_PORT;
459 else
461 if (!connect->servername || strcmpiW( connect->servername,
462 session->proxy_server ))
464 heap_free( connect->servername );
465 connect->resolved = FALSE;
466 if (!(connect->servername = strdupW( session->proxy_server )))
468 ret = FALSE;
469 goto end;
471 connect->serverport = INTERNET_DEFAULT_PORT;
475 else if (server)
477 heap_free( connect->servername );
478 connect->resolved = FALSE;
479 if (!(connect->servername = strdupW( server )))
481 ret = FALSE;
482 goto end;
484 connect->serverport = port;
486 end:
487 return ret;
490 /***********************************************************************
491 * WinHttpConnect (winhttp.@)
493 HINTERNET WINAPI WinHttpConnect( HINTERNET hsession, LPCWSTR server, INTERNET_PORT port, DWORD reserved )
495 connect_t *connect;
496 session_t *session;
497 HINTERNET hconnect = NULL;
499 TRACE("%p, %s, %u, %x\n", hsession, debugstr_w(server), port, reserved);
501 if (!server)
503 set_last_error( ERROR_INVALID_PARAMETER );
504 return NULL;
506 if (!(session = (session_t *)grab_object( hsession )))
508 set_last_error( ERROR_INVALID_HANDLE );
509 return NULL;
511 if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
513 release_object( &session->hdr );
514 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
515 return NULL;
517 if (!(connect = heap_alloc_zero( sizeof(connect_t) )))
519 release_object( &session->hdr );
520 return NULL;
522 connect->hdr.type = WINHTTP_HANDLE_TYPE_CONNECT;
523 connect->hdr.vtbl = &connect_vtbl;
524 connect->hdr.refs = 1;
525 connect->hdr.flags = session->hdr.flags;
526 connect->hdr.callback = session->hdr.callback;
527 connect->hdr.notify_mask = session->hdr.notify_mask;
528 connect->hdr.context = session->hdr.context;
529 connect->hdr.redirect_policy = session->hdr.redirect_policy;
530 list_init( &connect->hdr.children );
532 addref_object( &session->hdr );
533 connect->session = session;
534 list_add_head( &session->hdr.children, &connect->hdr.entry );
536 if (!(connect->hostname = strdupW( server ))) goto end;
537 connect->hostport = port;
538 if (!set_server_for_hostname( connect, server, port )) goto end;
540 if (!(hconnect = alloc_handle( &connect->hdr ))) goto end;
541 connect->hdr.handle = hconnect;
543 send_callback( &session->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hconnect, sizeof(hconnect) );
545 end:
546 release_object( &connect->hdr );
547 release_object( &session->hdr );
548 TRACE("returning %p\n", hconnect);
549 return hconnect;
552 /***********************************************************************
553 * request_destroy (internal)
555 static void request_destroy( object_header_t *hdr )
557 request_t *request = (request_t *)hdr;
558 unsigned int i;
560 TRACE("%p\n", request);
562 if (request->task_thread)
564 SetEvent( request->task_cancel );
565 WaitForSingleObject( request->task_thread, INFINITE );
566 CloseHandle( request->task_thread );
567 CloseHandle( request->task_cancel );
568 CloseHandle( request->task_wait );
569 DeleteCriticalSection( &request->task_cs );
571 release_object( &request->connect->hdr );
573 destroy_authinfo( request->authinfo );
574 destroy_authinfo( request->proxy_authinfo );
576 heap_free( request->verb );
577 heap_free( request->path );
578 heap_free( request->version );
579 heap_free( request->raw_headers );
580 heap_free( request->status_text );
581 for (i = 0; i < request->num_headers; i++)
583 heap_free( request->headers[i].field );
584 heap_free( request->headers[i].value );
586 heap_free( request->headers );
587 for (i = 0; i < request->num_accept_types; i++) heap_free( request->accept_types[i] );
588 heap_free( request->accept_types );
589 heap_free( request );
592 static void str_to_buffer( WCHAR *buffer, const WCHAR *str, LPDWORD buflen )
594 int len = 0;
595 if (str) len = strlenW( str );
596 if (buffer && *buflen > len)
598 if (str) memcpy( buffer, str, len * sizeof(WCHAR) );
599 buffer[len] = 0;
601 *buflen = len * sizeof(WCHAR);
604 static WCHAR *blob_to_str( DWORD encoding, CERT_NAME_BLOB *blob )
606 WCHAR *ret;
607 DWORD size, format = CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG;
609 size = CertNameToStrW( encoding, blob, format, NULL, 0 );
610 if ((ret = LocalAlloc( 0, size * sizeof(WCHAR) )))
611 CertNameToStrW( encoding, blob, format, ret, size );
613 return ret;
616 static BOOL convert_sockaddr( const struct sockaddr *addr, SOCKADDR_STORAGE *addr_storage )
618 #ifndef __MINGW32__
619 switch (addr->sa_family)
621 case AF_INET:
623 const struct sockaddr_in *addr_unix = (const struct sockaddr_in *)addr;
624 struct WS_sockaddr_in *addr_win = (struct WS_sockaddr_in *)addr_storage;
625 char *p;
627 addr_win->sin_family = WS_AF_INET;
628 addr_win->sin_port = addr_unix->sin_port;
629 memcpy( &addr_win->sin_addr, &addr_unix->sin_addr, 4 );
630 p = (char *)&addr_win->sin_addr + 4;
631 memset( p, 0, sizeof(*addr_storage) - (p - (char *)addr_win) );
632 return TRUE;
634 case AF_INET6:
636 const struct sockaddr_in6 *addr_unix = (const struct sockaddr_in6 *)addr;
637 struct WS_sockaddr_in6 *addr_win = (struct WS_sockaddr_in6 *)addr_storage;
639 addr_win->sin6_family = WS_AF_INET6;
640 addr_win->sin6_port = addr_unix->sin6_port;
641 addr_win->sin6_flowinfo = addr_unix->sin6_flowinfo;
642 memcpy( &addr_win->sin6_addr, &addr_unix->sin6_addr, 16 );
643 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
644 addr_win->sin6_scope_id = addr_unix->sin6_scope_id;
645 #else
646 addr_win->sin6_scope_id = 0;
647 #endif
648 memset( addr_win + 1, 0, sizeof(*addr_storage) - sizeof(*addr_win) );
649 return TRUE;
651 default:
652 ERR("unhandled family %u\n", addr->sa_family);
653 return FALSE;
655 #else
656 switch (addr->sa_family)
658 case AF_INET:
660 struct sockaddr_in *addr_in = (struct sockaddr_in *)addr_storage;
662 memcpy( addr_in, addr, sizeof(*addr_in) );
663 memset( addr_in + 1, 0, sizeof(*addr_storage) - sizeof(*addr_in) );
664 return TRUE;
666 case AF_INET6:
668 struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr_storage;
670 memcpy( addr_in6, addr, sizeof(*addr_in6) );
671 memset( addr_in6 + 1, 0, sizeof(*addr_storage) - sizeof(*addr_in6) );
672 return TRUE;
674 default:
675 ERR("unhandled family %u\n", addr->sa_family);
676 return FALSE;
678 #endif
681 static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
683 request_t *request = (request_t *)hdr;
685 switch (option)
687 case WINHTTP_OPTION_SECURITY_FLAGS:
689 DWORD flags;
690 int bits;
692 if (!buffer || *buflen < sizeof(flags))
694 *buflen = sizeof(flags);
695 set_last_error( ERROR_INSUFFICIENT_BUFFER );
696 return FALSE;
699 flags = 0;
700 if (hdr->flags & WINHTTP_FLAG_SECURE) flags |= SECURITY_FLAG_SECURE;
701 flags |= request->netconn.security_flags;
702 bits = netconn_get_cipher_strength( &request->netconn );
703 if (bits >= 128)
704 flags |= SECURITY_FLAG_STRENGTH_STRONG;
705 else if (bits >= 56)
706 flags |= SECURITY_FLAG_STRENGTH_MEDIUM;
707 else
708 flags |= SECURITY_FLAG_STRENGTH_WEAK;
709 *(DWORD *)buffer = flags;
710 *buflen = sizeof(flags);
711 return TRUE;
713 case WINHTTP_OPTION_SERVER_CERT_CONTEXT:
715 const CERT_CONTEXT *cert;
717 if (!buffer || *buflen < sizeof(cert))
719 *buflen = sizeof(cert);
720 set_last_error( ERROR_INSUFFICIENT_BUFFER );
721 return FALSE;
724 if (!(cert = netconn_get_certificate( &request->netconn ))) return FALSE;
725 *(CERT_CONTEXT **)buffer = (CERT_CONTEXT *)cert;
726 *buflen = sizeof(cert);
727 return TRUE;
729 case WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT:
731 const CERT_CONTEXT *cert;
732 const CRYPT_OID_INFO *oidInfo;
733 WINHTTP_CERTIFICATE_INFO *ci = buffer;
735 FIXME("partial stub\n");
737 if (!buffer || *buflen < sizeof(*ci))
739 *buflen = sizeof(*ci);
740 set_last_error( ERROR_INSUFFICIENT_BUFFER );
741 return FALSE;
743 if (!(cert = netconn_get_certificate( &request->netconn ))) return FALSE;
745 ci->ftExpiry = cert->pCertInfo->NotAfter;
746 ci->ftStart = cert->pCertInfo->NotBefore;
747 ci->lpszSubjectInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Subject );
748 ci->lpszIssuerInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Issuer );
749 ci->lpszProtocolName = NULL;
750 oidInfo = CryptFindOIDInfo( CRYPT_OID_INFO_OID_KEY,
751 cert->pCertInfo->SignatureAlgorithm.pszObjId,
752 0 );
753 if (oidInfo)
754 ci->lpszSignatureAlgName = (LPWSTR)oidInfo->pwszName;
755 else
756 ci->lpszSignatureAlgName = NULL;
757 ci->lpszEncryptionAlgName = NULL;
758 ci->dwKeySize = netconn_get_cipher_strength( &request->netconn );
760 CertFreeCertificateContext( cert );
761 *buflen = sizeof(*ci);
762 return TRUE;
764 case WINHTTP_OPTION_SECURITY_KEY_BITNESS:
766 if (!buffer || *buflen < sizeof(DWORD))
768 *buflen = sizeof(DWORD);
769 set_last_error( ERROR_INSUFFICIENT_BUFFER );
770 return FALSE;
773 *(DWORD *)buffer = netconn_get_cipher_strength( &request->netconn );
774 *buflen = sizeof(DWORD);
775 return TRUE;
777 case WINHTTP_OPTION_CONNECTION_INFO:
779 WINHTTP_CONNECTION_INFO *info = buffer;
780 struct sockaddr local;
781 socklen_t len = sizeof(local);
782 const struct sockaddr *remote = (const struct sockaddr *)&request->connect->sockaddr;
784 if (!buffer || *buflen < sizeof(*info))
786 *buflen = sizeof(*info);
787 set_last_error( ERROR_INSUFFICIENT_BUFFER );
788 return FALSE;
790 if (!netconn_connected( &request->netconn ))
792 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_STATE );
793 return FALSE;
795 if (getsockname( request->netconn.socket, &local, &len )) return FALSE;
796 if (!convert_sockaddr( &local, &info->LocalAddress )) return FALSE;
797 if (!convert_sockaddr( remote, &info->RemoteAddress )) return FALSE;
798 info->cbSize = sizeof(*info);
799 return TRUE;
801 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
802 *(DWORD *)buffer = request->resolve_timeout;
803 *buflen = sizeof(DWORD);
804 return TRUE;
805 case WINHTTP_OPTION_CONNECT_TIMEOUT:
806 *(DWORD *)buffer = request->connect_timeout;
807 *buflen = sizeof(DWORD);
808 return TRUE;
809 case WINHTTP_OPTION_SEND_TIMEOUT:
810 *(DWORD *)buffer = request->send_timeout;
811 *buflen = sizeof(DWORD);
812 return TRUE;
813 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
814 *(DWORD *)buffer = request->recv_timeout;
815 *buflen = sizeof(DWORD);
816 return TRUE;
818 case WINHTTP_OPTION_USERNAME:
819 str_to_buffer( buffer, request->connect->username, buflen );
820 return TRUE;
822 case WINHTTP_OPTION_PASSWORD:
823 str_to_buffer( buffer, request->connect->password, buflen );
824 return TRUE;
826 case WINHTTP_OPTION_PROXY_USERNAME:
827 str_to_buffer( buffer, request->connect->session->proxy_username, buflen );
828 return TRUE;
830 case WINHTTP_OPTION_PROXY_PASSWORD:
831 str_to_buffer( buffer, request->connect->session->proxy_password, buflen );
832 return TRUE;
834 default:
835 FIXME("unimplemented option %u\n", option);
836 set_last_error( ERROR_INVALID_PARAMETER );
837 return FALSE;
841 static WCHAR *buffer_to_str( WCHAR *buffer, DWORD buflen )
843 WCHAR *ret;
844 if ((ret = heap_alloc( (buflen + 1) * sizeof(WCHAR))))
846 memcpy( ret, buffer, buflen * sizeof(WCHAR) );
847 ret[buflen] = 0;
848 return ret;
850 set_last_error( ERROR_OUTOFMEMORY );
851 return NULL;
854 static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
856 request_t *request = (request_t *)hdr;
858 switch (option)
860 case WINHTTP_OPTION_PROXY:
862 WINHTTP_PROXY_INFO *pi = buffer;
864 FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
865 return TRUE;
867 case WINHTTP_OPTION_DISABLE_FEATURE:
869 DWORD disable;
871 if (buflen != sizeof(DWORD))
873 set_last_error( ERROR_INSUFFICIENT_BUFFER );
874 return FALSE;
877 disable = *(DWORD *)buffer;
878 TRACE("0x%x\n", disable);
879 hdr->disable_flags |= disable;
880 return TRUE;
882 case WINHTTP_OPTION_AUTOLOGON_POLICY:
884 DWORD policy;
886 if (buflen != sizeof(DWORD))
888 set_last_error( ERROR_INSUFFICIENT_BUFFER );
889 return FALSE;
892 policy = *(DWORD *)buffer;
893 TRACE("0x%x\n", policy);
894 hdr->logon_policy = policy;
895 return TRUE;
897 case WINHTTP_OPTION_REDIRECT_POLICY:
899 DWORD policy;
901 if (buflen != sizeof(DWORD))
903 set_last_error( ERROR_INSUFFICIENT_BUFFER );
904 return FALSE;
907 policy = *(DWORD *)buffer;
908 TRACE("0x%x\n", policy);
909 hdr->redirect_policy = policy;
910 return TRUE;
912 case WINHTTP_OPTION_SECURITY_FLAGS:
914 DWORD flags;
916 if (buflen < sizeof(DWORD))
918 set_last_error( ERROR_INSUFFICIENT_BUFFER );
919 return FALSE;
921 flags = *(DWORD *)buffer;
922 TRACE("0x%x\n", flags);
923 if (!(flags & (SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
924 SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
925 SECURITY_FLAG_IGNORE_UNKNOWN_CA |
926 SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE)))
928 set_last_error( ERROR_INVALID_PARAMETER );
929 return FALSE;
931 request->netconn.security_flags = flags;
932 return TRUE;
934 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
935 request->resolve_timeout = *(DWORD *)buffer;
936 return TRUE;
937 case WINHTTP_OPTION_CONNECT_TIMEOUT:
938 request->connect_timeout = *(DWORD *)buffer;
939 return TRUE;
940 case WINHTTP_OPTION_SEND_TIMEOUT:
941 request->send_timeout = *(DWORD *)buffer;
942 return TRUE;
943 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
944 request->recv_timeout = *(DWORD *)buffer;
945 return TRUE;
947 case WINHTTP_OPTION_USERNAME:
949 connect_t *connect = request->connect;
951 heap_free( connect->username );
952 if (!(connect->username = buffer_to_str( buffer, buflen ))) return FALSE;
953 return TRUE;
955 case WINHTTP_OPTION_PASSWORD:
957 connect_t *connect = request->connect;
959 heap_free( connect->password );
960 if (!(connect->password = buffer_to_str( buffer, buflen ))) return FALSE;
961 return TRUE;
963 case WINHTTP_OPTION_PROXY_USERNAME:
965 session_t *session = request->connect->session;
967 heap_free( session->proxy_username );
968 if (!(session->proxy_username = buffer_to_str( buffer, buflen ))) return FALSE;
969 return TRUE;
971 case WINHTTP_OPTION_PROXY_PASSWORD:
973 session_t *session = request->connect->session;
975 heap_free( session->proxy_password );
976 if (!(session->proxy_password = buffer_to_str( buffer, buflen ))) return FALSE;
977 return TRUE;
979 default:
980 FIXME("unimplemented option %u\n", option);
981 set_last_error( ERROR_INVALID_PARAMETER );
982 return TRUE;
986 static const object_vtbl_t request_vtbl =
988 request_destroy,
989 request_query_option,
990 request_set_option
993 static BOOL store_accept_types( request_t *request, const WCHAR **accept_types )
995 const WCHAR **types = accept_types;
996 DWORD i;
998 if (!types) return TRUE;
999 while (*types)
1001 request->num_accept_types++;
1002 types++;
1004 if (!request->num_accept_types) return TRUE;
1005 if (!(request->accept_types = heap_alloc( request->num_accept_types * sizeof(WCHAR *))))
1007 request->num_accept_types = 0;
1008 return FALSE;
1010 types = accept_types;
1011 for (i = 0; i < request->num_accept_types; i++)
1013 if (!(request->accept_types[i] = strdupW( *types )))
1015 for ( ; i > 0; --i) heap_free( request->accept_types[i - 1] );
1016 heap_free( request->accept_types );
1017 request->accept_types = NULL;
1018 request->num_accept_types = 0;
1019 return FALSE;
1021 types++;
1023 return TRUE;
1026 /***********************************************************************
1027 * WinHttpOpenRequest (winhttp.@)
1029 HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR object, LPCWSTR version,
1030 LPCWSTR referrer, LPCWSTR *types, DWORD flags )
1032 request_t *request;
1033 connect_t *connect;
1034 HINTERNET hrequest = NULL;
1036 TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect, debugstr_w(verb), debugstr_w(object),
1037 debugstr_w(version), debugstr_w(referrer), types, flags);
1039 if(types && TRACE_ON(winhttp)) {
1040 const WCHAR **iter;
1042 TRACE("accept types:\n");
1043 for(iter = types; *iter; iter++)
1044 TRACE(" %s\n", debugstr_w(*iter));
1047 if (!(connect = (connect_t *)grab_object( hconnect )))
1049 set_last_error( ERROR_INVALID_HANDLE );
1050 return NULL;
1052 if (connect->hdr.type != WINHTTP_HANDLE_TYPE_CONNECT)
1054 release_object( &connect->hdr );
1055 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1056 return NULL;
1058 if (!(request = heap_alloc_zero( sizeof(request_t) )))
1060 release_object( &connect->hdr );
1061 return NULL;
1063 request->hdr.type = WINHTTP_HANDLE_TYPE_REQUEST;
1064 request->hdr.vtbl = &request_vtbl;
1065 request->hdr.refs = 1;
1066 request->hdr.flags = flags;
1067 request->hdr.callback = connect->hdr.callback;
1068 request->hdr.notify_mask = connect->hdr.notify_mask;
1069 request->hdr.context = connect->hdr.context;
1070 request->hdr.redirect_policy = connect->hdr.redirect_policy;
1071 list_init( &request->hdr.children );
1072 list_init( &request->task_queue );
1074 addref_object( &connect->hdr );
1075 request->connect = connect;
1076 list_add_head( &connect->hdr.children, &request->hdr.entry );
1078 if (!netconn_init( &request->netconn )) goto end;
1079 request->resolve_timeout = connect->session->resolve_timeout;
1080 request->connect_timeout = connect->session->connect_timeout;
1081 request->send_timeout = connect->session->send_timeout;
1082 request->recv_timeout = connect->session->recv_timeout;
1084 if (!verb || !verb[0]) verb = getW;
1085 if (!(request->verb = strdupW( verb ))) goto end;
1087 if (object)
1089 WCHAR *path, *p;
1090 unsigned int len;
1092 len = strlenW( object ) + 1;
1093 if (object[0] != '/') len++;
1094 if (!(p = path = heap_alloc( len * sizeof(WCHAR) ))) goto end;
1096 if (object[0] != '/') *p++ = '/';
1097 strcpyW( p, object );
1098 request->path = path;
1100 else if (!(request->path = strdupW( slashW ))) goto end;
1102 if (!version || !version[0]) version = http1_1;
1103 if (!(request->version = strdupW( version ))) goto end;
1104 if (!(store_accept_types( request, types ))) goto end;
1106 if (!(hrequest = alloc_handle( &request->hdr ))) goto end;
1107 request->hdr.handle = hrequest;
1109 send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hrequest, sizeof(hrequest) );
1111 end:
1112 release_object( &request->hdr );
1113 release_object( &connect->hdr );
1114 TRACE("returning %p\n", hrequest);
1115 return hrequest;
1118 /***********************************************************************
1119 * WinHttpCloseHandle (winhttp.@)
1121 BOOL WINAPI WinHttpCloseHandle( HINTERNET handle )
1123 object_header_t *hdr;
1125 TRACE("%p\n", handle);
1127 if (!(hdr = grab_object( handle )))
1129 set_last_error( ERROR_INVALID_HANDLE );
1130 return FALSE;
1132 release_object( hdr );
1133 free_handle( handle );
1134 return TRUE;
1137 static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
1139 BOOL ret = FALSE;
1141 if (!buflen)
1143 set_last_error( ERROR_INVALID_PARAMETER );
1144 return FALSE;
1147 switch (option)
1149 case WINHTTP_OPTION_CONTEXT_VALUE:
1151 if (!buffer || *buflen < sizeof(DWORD_PTR))
1153 *buflen = sizeof(DWORD_PTR);
1154 set_last_error( ERROR_INSUFFICIENT_BUFFER );
1155 return FALSE;
1158 *(DWORD_PTR *)buffer = hdr->context;
1159 *buflen = sizeof(DWORD_PTR);
1160 return TRUE;
1162 default:
1163 if (hdr->vtbl->query_option) ret = hdr->vtbl->query_option( hdr, option, buffer, buflen );
1164 else
1166 FIXME("unimplemented option %u\n", option);
1167 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1168 return FALSE;
1170 break;
1172 return ret;
1175 /***********************************************************************
1176 * WinHttpQueryOption (winhttp.@)
1178 BOOL WINAPI WinHttpQueryOption( HINTERNET handle, DWORD option, LPVOID buffer, LPDWORD buflen )
1180 BOOL ret = FALSE;
1181 object_header_t *hdr;
1183 TRACE("%p, %u, %p, %p\n", handle, option, buffer, buflen);
1185 if (!(hdr = grab_object( handle )))
1187 set_last_error( ERROR_INVALID_HANDLE );
1188 return FALSE;
1191 ret = query_option( hdr, option, buffer, buflen );
1193 release_object( hdr );
1194 return ret;
1197 static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
1199 BOOL ret = TRUE;
1201 if (!buffer)
1203 set_last_error( ERROR_INVALID_PARAMETER );
1204 return FALSE;
1207 switch (option)
1209 case WINHTTP_OPTION_CONTEXT_VALUE:
1211 if (buflen != sizeof(DWORD_PTR))
1213 set_last_error( ERROR_INSUFFICIENT_BUFFER );
1214 return FALSE;
1217 hdr->context = *(DWORD_PTR *)buffer;
1218 return TRUE;
1220 default:
1221 if (hdr->vtbl->set_option) ret = hdr->vtbl->set_option( hdr, option, buffer, buflen );
1222 else
1224 FIXME("unimplemented option %u\n", option);
1225 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1226 return FALSE;
1228 break;
1230 return ret;
1233 /***********************************************************************
1234 * WinHttpSetOption (winhttp.@)
1236 BOOL WINAPI WinHttpSetOption( HINTERNET handle, DWORD option, LPVOID buffer, DWORD buflen )
1238 BOOL ret = FALSE;
1239 object_header_t *hdr;
1241 TRACE("%p, %u, %p, %u\n", handle, option, buffer, buflen);
1243 if (!(hdr = grab_object( handle )))
1245 set_last_error( ERROR_INVALID_HANDLE );
1246 return FALSE;
1249 ret = set_option( hdr, option, buffer, buflen );
1251 release_object( hdr );
1252 return ret;
1255 static char *get_computer_name( COMPUTER_NAME_FORMAT format )
1257 char *ret;
1258 DWORD size = 0;
1260 GetComputerNameExA( format, NULL, &size );
1261 if (GetLastError() != ERROR_MORE_DATA) return NULL;
1262 if (!(ret = heap_alloc( size ))) return NULL;
1263 if (!GetComputerNameExA( format, ret, &size ))
1265 heap_free( ret );
1266 return NULL;
1268 return ret;
1271 static BOOL is_domain_suffix( const char *domain, const char *suffix )
1273 int len_domain = strlen( domain ), len_suffix = strlen( suffix );
1275 if (len_suffix > len_domain) return FALSE;
1276 if (!strcasecmp( domain + len_domain - len_suffix, suffix )) return TRUE;
1277 return FALSE;
1280 static int reverse_lookup( const struct addrinfo *ai, char *hostname, size_t len )
1282 int ret = -1;
1283 #ifdef HAVE_GETNAMEINFO
1284 ret = getnameinfo( ai->ai_addr, ai->ai_addrlen, hostname, len, NULL, 0, 0 );
1285 #endif
1286 return ret;
1289 static WCHAR *build_wpad_url( const char *hostname, const struct addrinfo *ai )
1291 static const WCHAR httpW[] = {'h','t','t','p',':','/','/',0};
1292 static const WCHAR wpadW[] = {'/','w','p','a','d','.','d','a','t',0};
1293 char name[NI_MAXHOST];
1294 WCHAR *ret, *p;
1295 int len;
1297 while (ai && ai->ai_family != AF_INET && ai->ai_family != AF_INET6) ai = ai->ai_next;
1298 if (!ai) return NULL;
1300 if (!reverse_lookup( ai, name, sizeof(name) )) hostname = name;
1302 len = strlenW( httpW ) + strlen( hostname ) + strlenW( wpadW );
1303 if (!(ret = p = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) return NULL;
1304 strcpyW( p, httpW );
1305 p += strlenW( httpW );
1306 while (*hostname) { *p++ = *hostname++; }
1307 strcpyW( p, wpadW );
1308 return ret;
1311 static BOOL get_system_proxy_autoconfig_url( char *buf, DWORD buflen )
1313 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1314 CFDictionaryRef settings = CFNetworkCopySystemProxySettings();
1315 const void *ref;
1316 BOOL ret = FALSE;
1318 if (!settings) return FALSE;
1320 if (!(ref = CFDictionaryGetValue( settings, kCFNetworkProxiesProxyAutoConfigURLString )))
1322 CFRelease( settings );
1323 return FALSE;
1325 if (CFStringGetCString( ref, buf, buflen, kCFStringEncodingASCII ))
1327 TRACE( "returning %s\n", debugstr_a(buf) );
1328 ret = TRUE;
1330 CFRelease( settings );
1331 return ret;
1332 #else
1333 FIXME( "no support on this platform\n" );
1334 return FALSE;
1335 #endif
1338 #define INTERNET_MAX_URL_LENGTH 2084
1340 /***********************************************************************
1341 * WinHttpDetectAutoProxyConfigUrl (winhttp.@)
1343 BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url )
1345 BOOL ret = FALSE;
1346 char system_url[INTERNET_MAX_URL_LENGTH + 1];
1348 TRACE("0x%08x, %p\n", flags, url);
1350 if (!flags || !url)
1352 set_last_error( ERROR_INVALID_PARAMETER );
1353 return FALSE;
1355 if (get_system_proxy_autoconfig_url( system_url, sizeof(system_url) ))
1357 WCHAR *urlW;
1359 if (!(urlW = strdupAW( system_url ))) return FALSE;
1360 *url = urlW;
1361 return TRUE;
1363 if (flags & WINHTTP_AUTO_DETECT_TYPE_DHCP)
1365 static int fixme_shown;
1366 if (!fixme_shown++) FIXME("discovery via DHCP not supported\n");
1368 if (flags & WINHTTP_AUTO_DETECT_TYPE_DNS_A)
1370 #ifdef HAVE_GETADDRINFO
1371 char *fqdn, *domain, *p;
1373 if (!(fqdn = get_computer_name( ComputerNamePhysicalDnsFullyQualified ))) return FALSE;
1374 if (!(domain = get_computer_name( ComputerNamePhysicalDnsDomain )))
1376 heap_free( fqdn );
1377 return FALSE;
1379 p = fqdn;
1380 while ((p = strchr( p, '.' )) && is_domain_suffix( p + 1, domain ))
1382 struct addrinfo *ai;
1383 char *name;
1384 int res;
1386 if (!(name = heap_alloc( sizeof("wpad") + strlen(p) )))
1388 heap_free( fqdn );
1389 heap_free( domain );
1390 return FALSE;
1392 strcpy( name, "wpad" );
1393 strcat( name, p );
1394 res = getaddrinfo( name, NULL, NULL, &ai );
1395 if (!res)
1397 *url = build_wpad_url( name, ai );
1398 freeaddrinfo( ai );
1399 if (*url)
1401 TRACE("returning %s\n", debugstr_w(*url));
1402 heap_free( name );
1403 ret = TRUE;
1404 break;
1407 heap_free( name );
1408 p++;
1410 heap_free( domain );
1411 heap_free( fqdn );
1412 #else
1413 FIXME("getaddrinfo not found at build time\n");
1414 #endif
1416 if (!ret)
1418 set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED );
1419 *url = NULL;
1421 return ret;
1424 static const WCHAR Connections[] = {
1425 'S','o','f','t','w','a','r','e','\\',
1426 'M','i','c','r','o','s','o','f','t','\\',
1427 'W','i','n','d','o','w','s','\\',
1428 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1429 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
1430 'C','o','n','n','e','c','t','i','o','n','s',0 };
1431 static const WCHAR WinHttpSettings[] = {
1432 'W','i','n','H','t','t','p','S','e','t','t','i','n','g','s',0 };
1433 static const DWORD WINHTTP_SETTINGS_MAGIC = 0x18;
1434 static const DWORD WININET_SETTINGS_MAGIC = 0x46;
1435 static const DWORD PROXY_TYPE_DIRECT = 1;
1436 static const DWORD PROXY_TYPE_PROXY = 2;
1437 static const DWORD PROXY_USE_PAC_SCRIPT = 4;
1438 static const DWORD PROXY_AUTODETECT_SETTINGS = 8;
1440 struct connection_settings_header
1442 DWORD magic;
1443 DWORD unknown; /* always zero? */
1444 DWORD flags; /* one or more of PROXY_* */
1447 static inline void copy_char_to_wchar_sz(const BYTE *src, DWORD len, WCHAR *dst)
1449 const BYTE *begin;
1451 for (begin = src; src - begin < len; src++, dst++)
1452 *dst = *src;
1453 *dst = 0;
1456 /***********************************************************************
1457 * WinHttpGetDefaultProxyConfiguration (winhttp.@)
1459 BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
1461 LONG l;
1462 HKEY key;
1463 BOOL got_from_reg = FALSE, direct = TRUE;
1464 char *envproxy;
1466 TRACE("%p\n", info);
1468 l = RegOpenKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, KEY_READ, &key );
1469 if (!l)
1471 DWORD type, size = 0;
1473 l = RegQueryValueExW( key, WinHttpSettings, NULL, &type, NULL, &size );
1474 if (!l && type == REG_BINARY &&
1475 size >= sizeof(struct connection_settings_header) + 2 * sizeof(DWORD))
1477 BYTE *buf = heap_alloc( size );
1479 if (buf)
1481 struct connection_settings_header *hdr =
1482 (struct connection_settings_header *)buf;
1483 DWORD *len = (DWORD *)(hdr + 1);
1485 l = RegQueryValueExW( key, WinHttpSettings, NULL, NULL, buf,
1486 &size );
1487 if (!l && hdr->magic == WINHTTP_SETTINGS_MAGIC &&
1488 hdr->unknown == 0)
1490 if (hdr->flags & PROXY_TYPE_PROXY)
1492 BOOL sane = FALSE;
1493 LPWSTR proxy = NULL;
1494 LPWSTR proxy_bypass = NULL;
1496 /* Sanity-check length of proxy string */
1497 if ((BYTE *)len - buf + *len <= size)
1499 sane = TRUE;
1500 proxy = GlobalAlloc( 0, (*len + 1) * sizeof(WCHAR) );
1501 if (proxy)
1502 copy_char_to_wchar_sz( (BYTE *)(len + 1), *len, proxy );
1503 len = (DWORD *)((BYTE *)(len + 1) + *len);
1505 if (sane)
1507 /* Sanity-check length of proxy bypass string */
1508 if ((BYTE *)len - buf + *len <= size)
1510 proxy_bypass = GlobalAlloc( 0, (*len + 1) * sizeof(WCHAR) );
1511 if (proxy_bypass)
1512 copy_char_to_wchar_sz( (BYTE *)(len + 1), *len, proxy_bypass );
1514 else
1516 sane = FALSE;
1517 GlobalFree( proxy );
1518 proxy = NULL;
1521 info->lpszProxy = proxy;
1522 info->lpszProxyBypass = proxy_bypass;
1523 if (sane)
1525 got_from_reg = TRUE;
1526 direct = FALSE;
1527 info->dwAccessType =
1528 WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1529 TRACE("http proxy (from registry) = %s, bypass = %s\n",
1530 debugstr_w(info->lpszProxy),
1531 debugstr_w(info->lpszProxyBypass));
1535 heap_free( buf );
1538 RegCloseKey( key );
1540 if (!got_from_reg && (envproxy = getenv( "http_proxy" )))
1542 char *colon, *http_proxy;
1544 if ((colon = strchr( envproxy, ':' )))
1546 if (*(colon + 1) == '/' && *(colon + 2) == '/')
1548 static const char http[] = "http://";
1550 /* It's a scheme, check that it's http */
1551 if (!strncmp( envproxy, http, strlen( http ) ))
1552 http_proxy = envproxy + strlen( http );
1553 else
1555 WARN("unsupported scheme in $http_proxy: %s\n", envproxy);
1556 http_proxy = NULL;
1559 else
1560 http_proxy = envproxy;
1562 else
1563 http_proxy = envproxy;
1564 if (http_proxy)
1566 WCHAR *http_proxyW;
1567 int len;
1569 len = MultiByteToWideChar( CP_UNIXCP, 0, http_proxy, -1, NULL, 0 );
1570 if ((http_proxyW = GlobalAlloc( 0, len * sizeof(WCHAR))))
1572 MultiByteToWideChar( CP_UNIXCP, 0, http_proxy, -1, http_proxyW, len );
1573 direct = FALSE;
1574 info->dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1575 info->lpszProxy = http_proxyW;
1576 info->lpszProxyBypass = NULL;
1577 TRACE("http proxy (from environment) = %s\n",
1578 debugstr_w(info->lpszProxy));
1582 if (direct)
1584 info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
1585 info->lpszProxy = NULL;
1586 info->lpszProxyBypass = NULL;
1588 return TRUE;
1591 /***********************************************************************
1592 * WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
1594 BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *config )
1596 static const WCHAR settingsW[] =
1597 {'D','e','f','a','u','l','t','C','o','n','n','e','c','t','i','o','n','S','e','t','t','i','n','g','s',0};
1598 HKEY hkey = NULL;
1599 struct connection_settings_header *hdr = NULL;
1600 DWORD type, offset, len, size = 0;
1601 BOOL ret = FALSE;
1603 TRACE("%p\n", config);
1605 if (!config)
1607 set_last_error( ERROR_INVALID_PARAMETER );
1608 return FALSE;
1610 memset( config, 0, sizeof(*config) );
1611 config->fAutoDetect = TRUE;
1613 if (RegOpenKeyExW( HKEY_CURRENT_USER, Connections, 0, KEY_READ, &hkey ) ||
1614 RegQueryValueExW( hkey, settingsW, NULL, &type, NULL, &size ) ||
1615 type != REG_BINARY || size < sizeof(struct connection_settings_header))
1617 ret = TRUE;
1618 goto done;
1620 if (!(hdr = heap_alloc( size ))) goto done;
1621 if (RegQueryValueExW( hkey, settingsW, NULL, &type, (BYTE *)hdr, &size ) ||
1622 hdr->magic != WININET_SETTINGS_MAGIC)
1624 ret = TRUE;
1625 goto done;
1628 config->fAutoDetect = (hdr->flags & PROXY_AUTODETECT_SETTINGS) != 0;
1629 offset = sizeof(*hdr);
1630 if (offset + sizeof(DWORD) > size) goto done;
1631 len = *(DWORD *)((char *)hdr + offset);
1632 offset += sizeof(DWORD);
1633 if (len && hdr->flags & PROXY_TYPE_PROXY)
1635 if (!(config->lpszProxy = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
1636 copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszProxy );
1638 offset += len;
1639 if (offset + sizeof(DWORD) > size) goto done;
1640 len = *(DWORD *)((char *)hdr + offset);
1641 offset += sizeof(DWORD);
1642 if (len && (hdr->flags & PROXY_TYPE_PROXY))
1644 if (!(config->lpszProxyBypass = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
1645 copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszProxyBypass );
1647 offset += len;
1648 if (offset + sizeof(DWORD) > size) goto done;
1649 len = *(DWORD *)((char *)hdr + offset);
1650 offset += sizeof(DWORD);
1651 if (len && (hdr->flags & PROXY_USE_PAC_SCRIPT))
1653 if (!(config->lpszAutoConfigUrl = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
1654 copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszAutoConfigUrl );
1656 ret = TRUE;
1658 done:
1659 RegCloseKey( hkey );
1660 heap_free( hdr );
1661 if (!ret)
1663 GlobalFree( config->lpszAutoConfigUrl );
1664 config->lpszAutoConfigUrl = NULL;
1665 GlobalFree( config->lpszProxy );
1666 config->lpszProxy = NULL;
1667 GlobalFree( config->lpszProxyBypass );
1668 config->lpszProxyBypass = NULL;
1670 return ret;
1673 static BOOL parse_script_result( const char *result, WINHTTP_PROXY_INFO *info )
1675 const char *p;
1676 WCHAR *q;
1677 int len;
1679 info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
1680 info->lpszProxy = NULL;
1681 info->lpszProxyBypass = NULL;
1683 TRACE("%s\n", debugstr_a( result ));
1685 p = result;
1686 while (*p == ' ') p++;
1687 len = strlen( p );
1688 if (len >= 5 && !strncasecmp( p, "PROXY", sizeof("PROXY") - 1 ))
1690 p += 5;
1691 while (*p == ' ') p++;
1692 if (!*p || *p == ';') return TRUE;
1693 if (!(info->lpszProxy = q = strdupAW( p ))) return FALSE;
1694 info->dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1695 for (; *q; q++)
1697 if (*q == ' ' || *q == ';')
1699 *q = 0;
1700 break;
1704 return TRUE;
1707 static char *download_script( const WCHAR *url, DWORD *out_size )
1709 static const WCHAR typeW[] = {'*','/','*',0};
1710 static const WCHAR *acceptW[] = {typeW, NULL};
1711 HINTERNET ses, con = NULL, req = NULL;
1712 WCHAR *hostname;
1713 URL_COMPONENTSW uc;
1714 DWORD status, size = sizeof(status), offset, to_read, bytes_read, flags = 0;
1715 char *tmp, *buffer = NULL;
1717 *out_size = 0;
1719 memset( &uc, 0, sizeof(uc) );
1720 uc.dwStructSize = sizeof(uc);
1721 if (!WinHttpCrackUrl( url, 0, 0, &uc )) return NULL;
1722 if (!(hostname = heap_alloc( (uc.dwHostNameLength + 1) * sizeof(WCHAR) ))) return NULL;
1723 memcpy( hostname, uc.lpszHostName, uc.dwHostNameLength * sizeof(WCHAR) );
1724 hostname[uc.dwHostNameLength] = 0;
1726 if (!(ses = WinHttpOpen( NULL, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0 ))) goto done;
1727 if (!(con = WinHttpConnect( ses, hostname, uc.nPort, 0 ))) goto done;
1728 if (uc.nScheme == INTERNET_SCHEME_HTTPS) flags |= WINHTTP_FLAG_SECURE;
1729 if (!(req = WinHttpOpenRequest( con, NULL, uc.lpszUrlPath, NULL, NULL, acceptW, flags ))) goto done;
1730 if (!WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 )) goto done;
1732 if (!(WinHttpReceiveResponse( req, 0 ))) goto done;
1733 if (!WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status,
1734 &size, NULL ) || status != HTTP_STATUS_OK) goto done;
1736 size = 4096;
1737 if (!(buffer = heap_alloc( size ))) goto done;
1738 to_read = size;
1739 offset = 0;
1740 for (;;)
1742 if (!WinHttpReadData( req, buffer + offset, to_read, &bytes_read )) goto done;
1743 if (!bytes_read) break;
1744 to_read -= bytes_read;
1745 offset += bytes_read;
1746 *out_size += bytes_read;
1747 if (!to_read)
1749 to_read = size;
1750 size *= 2;
1751 if (!(tmp = heap_realloc( buffer, size ))) goto done;
1752 buffer = tmp;
1756 done:
1757 WinHttpCloseHandle( req );
1758 WinHttpCloseHandle( con );
1759 WinHttpCloseHandle( ses );
1760 heap_free( hostname );
1761 if (!buffer) set_last_error( ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT );
1762 return buffer;
1765 struct AUTO_PROXY_SCRIPT_BUFFER
1767 DWORD dwStructSize;
1768 LPSTR lpszScriptBuffer;
1769 DWORD dwScriptBufferSize;
1772 BOOL WINAPI InternetDeInitializeAutoProxyDll(LPSTR, DWORD);
1773 BOOL WINAPI InternetGetProxyInfo(LPCSTR, DWORD, LPSTR, DWORD, LPSTR *, LPDWORD);
1774 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD, LPSTR, LPSTR, void *, struct AUTO_PROXY_SCRIPT_BUFFER *);
1776 static BOOL run_script( char *script, DWORD size, const WCHAR *url, WINHTTP_PROXY_INFO *info )
1778 BOOL ret;
1779 char *result, *urlA;
1780 DWORD len_result;
1781 struct AUTO_PROXY_SCRIPT_BUFFER buffer;
1783 buffer.dwStructSize = sizeof(buffer);
1784 buffer.lpszScriptBuffer = script;
1785 buffer.dwScriptBufferSize = size;
1787 if (!(urlA = strdupWA( url ))) return FALSE;
1788 if (!(ret = InternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buffer )))
1790 heap_free( urlA );
1791 return FALSE;
1793 if ((ret = InternetGetProxyInfo( urlA, strlen(urlA), NULL, 0, &result, &len_result )))
1795 ret = parse_script_result( result, info );
1796 heap_free( result );
1798 heap_free( urlA );
1799 return InternetDeInitializeAutoProxyDll( NULL, 0 );
1802 /***********************************************************************
1803 * WinHttpGetProxyForUrl (winhttp.@)
1805 BOOL WINAPI WinHttpGetProxyForUrl( HINTERNET hsession, LPCWSTR url, WINHTTP_AUTOPROXY_OPTIONS *options,
1806 WINHTTP_PROXY_INFO *info )
1808 WCHAR *detected_pac_url = NULL;
1809 const WCHAR *pac_url;
1810 session_t *session;
1811 char *script;
1812 DWORD size;
1813 BOOL ret = FALSE;
1815 TRACE("%p, %s, %p, %p\n", hsession, debugstr_w(url), options, info);
1817 if (!(session = (session_t *)grab_object( hsession )))
1819 set_last_error( ERROR_INVALID_HANDLE );
1820 return FALSE;
1822 if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
1824 release_object( &session->hdr );
1825 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1826 return FALSE;
1828 if (!url || !options || !info ||
1829 !(options->dwFlags & (WINHTTP_AUTOPROXY_AUTO_DETECT|WINHTTP_AUTOPROXY_CONFIG_URL)) ||
1830 ((options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT) && !options->dwAutoDetectFlags) ||
1831 ((options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT) &&
1832 (options->dwFlags & WINHTTP_AUTOPROXY_CONFIG_URL)))
1834 release_object( &session->hdr );
1835 set_last_error( ERROR_INVALID_PARAMETER );
1836 return FALSE;
1838 if (options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT &&
1839 !WinHttpDetectAutoProxyConfigUrl( options->dwAutoDetectFlags, &detected_pac_url ))
1840 goto done;
1842 if (options->dwFlags & WINHTTP_AUTOPROXY_CONFIG_URL) pac_url = options->lpszAutoConfigUrl;
1843 else pac_url = detected_pac_url;
1845 if ((script = download_script( pac_url, &size )))
1847 ret = run_script( script, size, url, info );
1848 heap_free( script );
1851 done:
1852 GlobalFree( detected_pac_url );
1853 release_object( &session->hdr );
1854 return ret;
1857 /***********************************************************************
1858 * WinHttpSetDefaultProxyConfiguration (winhttp.@)
1860 BOOL WINAPI WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
1862 LONG l;
1863 HKEY key;
1864 BOOL ret = FALSE;
1865 const WCHAR *src;
1867 TRACE("%p\n", info);
1869 if (!info)
1871 set_last_error( ERROR_INVALID_PARAMETER );
1872 return FALSE;
1874 switch (info->dwAccessType)
1876 case WINHTTP_ACCESS_TYPE_NO_PROXY:
1877 break;
1878 case WINHTTP_ACCESS_TYPE_NAMED_PROXY:
1879 if (!info->lpszProxy)
1881 set_last_error( ERROR_INVALID_PARAMETER );
1882 return FALSE;
1884 /* Only ASCII characters are allowed */
1885 for (src = info->lpszProxy; *src; src++)
1886 if (*src > 0x7f)
1888 set_last_error( ERROR_INVALID_PARAMETER );
1889 return FALSE;
1891 if (info->lpszProxyBypass)
1893 for (src = info->lpszProxyBypass; *src; src++)
1894 if (*src > 0x7f)
1896 set_last_error( ERROR_INVALID_PARAMETER );
1897 return FALSE;
1900 break;
1901 default:
1902 set_last_error( ERROR_INVALID_PARAMETER );
1903 return FALSE;
1906 l = RegCreateKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, NULL, 0,
1907 KEY_WRITE, NULL, &key, NULL );
1908 if (!l)
1910 DWORD size = sizeof(struct connection_settings_header) + 2 * sizeof(DWORD);
1911 BYTE *buf;
1913 if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
1915 size += strlenW( info->lpszProxy );
1916 if (info->lpszProxyBypass)
1917 size += strlenW( info->lpszProxyBypass );
1919 buf = heap_alloc( size );
1920 if (buf)
1922 struct connection_settings_header *hdr =
1923 (struct connection_settings_header *)buf;
1924 DWORD *len = (DWORD *)(hdr + 1);
1926 hdr->magic = WINHTTP_SETTINGS_MAGIC;
1927 hdr->unknown = 0;
1928 if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
1930 BYTE *dst;
1932 hdr->flags = PROXY_TYPE_PROXY;
1933 *len++ = strlenW( info->lpszProxy );
1934 for (dst = (BYTE *)len, src = info->lpszProxy; *src;
1935 src++, dst++)
1936 *dst = *src;
1937 len = (DWORD *)dst;
1938 if (info->lpszProxyBypass)
1940 *len++ = strlenW( info->lpszProxyBypass );
1941 for (dst = (BYTE *)len, src = info->lpszProxyBypass; *src;
1942 src++, dst++)
1943 *dst = *src;
1945 else
1946 *len++ = 0;
1948 else
1950 hdr->flags = PROXY_TYPE_DIRECT;
1951 *len++ = 0;
1952 *len++ = 0;
1954 l = RegSetValueExW( key, WinHttpSettings, 0, REG_BINARY, buf, size );
1955 if (!l)
1956 ret = TRUE;
1957 heap_free( buf );
1959 RegCloseKey( key );
1961 return ret;
1964 /***********************************************************************
1965 * WinHttpSetStatusCallback (winhttp.@)
1967 WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback( HINTERNET handle, WINHTTP_STATUS_CALLBACK callback,
1968 DWORD flags, DWORD_PTR reserved )
1970 object_header_t *hdr;
1971 WINHTTP_STATUS_CALLBACK ret;
1973 TRACE("%p, %p, 0x%08x, 0x%lx\n", handle, callback, flags, reserved);
1975 if (!(hdr = grab_object( handle )))
1977 set_last_error( ERROR_INVALID_HANDLE );
1978 return WINHTTP_INVALID_STATUS_CALLBACK;
1980 ret = hdr->callback;
1981 hdr->callback = callback;
1982 hdr->notify_mask = flags;
1984 release_object( hdr );
1985 return ret;
1988 /***********************************************************************
1989 * WinHttpSetTimeouts (winhttp.@)
1991 BOOL WINAPI WinHttpSetTimeouts( HINTERNET handle, int resolve, int connect, int send, int receive )
1993 BOOL ret = TRUE;
1994 object_header_t *hdr;
1995 request_t *request;
1996 session_t *session;
1998 TRACE("%p, %d, %d, %d, %d\n", handle, resolve, connect, send, receive);
2000 if (resolve < -1 || connect < -1 || send < -1 || receive < -1)
2002 set_last_error( ERROR_INVALID_PARAMETER );
2003 return FALSE;
2006 if (!(hdr = grab_object( handle )))
2008 set_last_error( ERROR_INVALID_HANDLE );
2009 return FALSE;
2012 switch(hdr->type)
2014 case WINHTTP_HANDLE_TYPE_REQUEST:
2015 request = (request_t *)hdr;
2016 request->connect_timeout = connect;
2018 if (resolve < 0) resolve = 0;
2019 request->resolve_timeout = resolve;
2021 if (send < 0) send = 0;
2022 request->send_timeout = send;
2024 if (receive < 0) receive = 0;
2025 request->recv_timeout = receive;
2027 if (netconn_connected( &request->netconn ))
2029 if (netconn_set_timeout( &request->netconn, TRUE, send )) ret = FALSE;
2030 if (netconn_set_timeout( &request->netconn, FALSE, receive )) ret = FALSE;
2033 release_object( &request->hdr );
2034 break;
2036 case WINHTTP_HANDLE_TYPE_SESSION:
2037 session = (session_t *)hdr;
2038 session->connect_timeout = connect;
2040 if (resolve < 0) resolve = 0;
2041 session->resolve_timeout = resolve;
2043 if (send < 0) send = 0;
2044 session->send_timeout = send;
2046 if (receive < 0) receive = 0;
2047 session->recv_timeout = receive;
2048 break;
2050 default:
2051 release_object( hdr );
2052 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
2053 return FALSE;
2055 return ret;
2058 static const WCHAR wkday[7][4] =
2059 {{'S','u','n', 0}, {'M','o','n', 0}, {'T','u','e', 0}, {'W','e','d', 0},
2060 {'T','h','u', 0}, {'F','r','i', 0}, {'S','a','t', 0}};
2061 static const WCHAR month[12][4] =
2062 {{'J','a','n', 0}, {'F','e','b', 0}, {'M','a','r', 0}, {'A','p','r', 0},
2063 {'M','a','y', 0}, {'J','u','n', 0}, {'J','u','l', 0}, {'A','u','g', 0},
2064 {'S','e','p', 0}, {'O','c','t', 0}, {'N','o','v', 0}, {'D','e','c', 0}};
2066 /***********************************************************************
2067 * WinHttpTimeFromSystemTime (WININET.@)
2069 BOOL WINAPI WinHttpTimeFromSystemTime( const SYSTEMTIME *time, LPWSTR string )
2071 static const WCHAR format[] =
2072 {'%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2073 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0};
2075 TRACE("%p, %p\n", time, string);
2077 if (!time || !string) return FALSE;
2079 sprintfW( string, format,
2080 wkday[time->wDayOfWeek],
2081 time->wDay,
2082 month[time->wMonth - 1],
2083 time->wYear,
2084 time->wHour,
2085 time->wMinute,
2086 time->wSecond );
2088 return TRUE;
2091 /***********************************************************************
2092 * WinHttpTimeToSystemTime (WININET.@)
2094 BOOL WINAPI WinHttpTimeToSystemTime( LPCWSTR string, SYSTEMTIME *time )
2096 unsigned int i;
2097 const WCHAR *s = string;
2098 WCHAR *end;
2100 TRACE("%s, %p\n", debugstr_w(string), time);
2102 if (!string || !time) return FALSE;
2104 /* Windows does this too */
2105 GetSystemTime( time );
2107 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2108 * a SYSTEMTIME structure.
2111 while (*s && !isalphaW( *s )) s++;
2112 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2113 time->wDayOfWeek = 7;
2115 for (i = 0; i < 7; i++)
2117 if (toupperW( wkday[i][0] ) == toupperW( s[0] ) &&
2118 toupperW( wkday[i][1] ) == toupperW( s[1] ) &&
2119 toupperW( wkday[i][2] ) == toupperW( s[2] ) )
2121 time->wDayOfWeek = i;
2122 break;
2126 if (time->wDayOfWeek > 6) return TRUE;
2127 while (*s && !isdigitW( *s )) s++;
2128 time->wDay = strtolW( s, &end, 10 );
2129 s = end;
2131 while (*s && !isalphaW( *s )) s++;
2132 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2133 time->wMonth = 0;
2135 for (i = 0; i < 12; i++)
2137 if (toupperW( month[i][0]) == toupperW( s[0] ) &&
2138 toupperW( month[i][1]) == toupperW( s[1] ) &&
2139 toupperW( month[i][2]) == toupperW( s[2] ) )
2141 time->wMonth = i + 1;
2142 break;
2145 if (time->wMonth == 0) return TRUE;
2147 while (*s && !isdigitW( *s )) s++;
2148 if (*s == '\0') return TRUE;
2149 time->wYear = strtolW( s, &end, 10 );
2150 s = end;
2152 while (*s && !isdigitW( *s )) s++;
2153 if (*s == '\0') return TRUE;
2154 time->wHour = strtolW( s, &end, 10 );
2155 s = end;
2157 while (*s && !isdigitW( *s )) s++;
2158 if (*s == '\0') return TRUE;
2159 time->wMinute = strtolW( s, &end, 10 );
2160 s = end;
2162 while (*s && !isdigitW( *s )) s++;
2163 if (*s == '\0') return TRUE;
2164 time->wSecond = strtolW( s, &end, 10 );
2166 time->wMilliseconds = 0;
2167 return TRUE;