msvcr110: Add critical_section::try_lock_for implementation.
[wine/multimedia.git] / dlls / winhttp / session.c
blob56e776da8be68fe305dd9c3f390855eb8a749c1f
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 TRACE("%p, 0x%08x, %p, %u\n", hdr, status, info, buflen);
75 if (hdr->callback && (hdr->notify_mask & status)) hdr->callback( hdr->handle, hdr->context, status, info, buflen );
78 /***********************************************************************
79 * WinHttpCheckPlatform (winhttp.@)
81 BOOL WINAPI WinHttpCheckPlatform( void )
83 TRACE("\n");
84 return TRUE;
87 /***********************************************************************
88 * session_destroy (internal)
90 static void session_destroy( object_header_t *hdr )
92 session_t *session = (session_t *)hdr;
93 struct list *item, *next;
94 domain_t *domain;
96 TRACE("%p\n", session);
98 LIST_FOR_EACH_SAFE( item, next, &session->cookie_cache )
100 domain = LIST_ENTRY( item, domain_t, entry );
101 delete_domain( domain );
103 heap_free( session->agent );
104 heap_free( session->proxy_server );
105 heap_free( session->proxy_bypass );
106 heap_free( session->proxy_username );
107 heap_free( session->proxy_password );
108 heap_free( session );
111 static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
113 session_t *session = (session_t *)hdr;
115 switch (option)
117 case WINHTTP_OPTION_REDIRECT_POLICY:
119 if (!buffer || *buflen < sizeof(DWORD))
121 *buflen = sizeof(DWORD);
122 set_last_error( ERROR_INSUFFICIENT_BUFFER );
123 return FALSE;
126 *(DWORD *)buffer = hdr->redirect_policy;
127 *buflen = sizeof(DWORD);
128 return TRUE;
130 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
131 *(DWORD *)buffer = session->resolve_timeout;
132 *buflen = sizeof(DWORD);
133 return TRUE;
134 case WINHTTP_OPTION_CONNECT_TIMEOUT:
135 *(DWORD *)buffer = session->connect_timeout;
136 *buflen = sizeof(DWORD);
137 return TRUE;
138 case WINHTTP_OPTION_SEND_TIMEOUT:
139 *(DWORD *)buffer = session->send_timeout;
140 *buflen = sizeof(DWORD);
141 return TRUE;
142 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
143 *(DWORD *)buffer = session->recv_timeout;
144 *buflen = sizeof(DWORD);
145 return TRUE;
146 default:
147 FIXME("unimplemented option %u\n", option);
148 set_last_error( ERROR_INVALID_PARAMETER );
149 return FALSE;
153 static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
155 session_t *session = (session_t *)hdr;
157 switch (option)
159 case WINHTTP_OPTION_PROXY:
161 WINHTTP_PROXY_INFO *pi = buffer;
163 FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
164 return TRUE;
166 case WINHTTP_OPTION_REDIRECT_POLICY:
168 DWORD policy;
170 if (buflen != sizeof(policy))
172 set_last_error( ERROR_INSUFFICIENT_BUFFER );
173 return FALSE;
176 policy = *(DWORD *)buffer;
177 TRACE("0x%x\n", policy);
178 hdr->redirect_policy = policy;
179 return TRUE;
181 case WINHTTP_OPTION_DISABLE_FEATURE:
182 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
183 return FALSE;
184 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
185 session->resolve_timeout = *(DWORD *)buffer;
186 return TRUE;
187 case WINHTTP_OPTION_CONNECT_TIMEOUT:
188 session->connect_timeout = *(DWORD *)buffer;
189 return TRUE;
190 case WINHTTP_OPTION_SEND_TIMEOUT:
191 session->send_timeout = *(DWORD *)buffer;
192 return TRUE;
193 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
194 session->recv_timeout = *(DWORD *)buffer;
195 return TRUE;
196 case WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH:
197 FIXME("WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH: 0x%x\n", *(DWORD *)buffer);
198 return TRUE;
199 default:
200 FIXME("unimplemented option %u\n", option);
201 set_last_error( ERROR_INVALID_PARAMETER );
202 return FALSE;
206 static const object_vtbl_t session_vtbl =
208 session_destroy,
209 session_query_option,
210 session_set_option
213 /***********************************************************************
214 * WinHttpOpen (winhttp.@)
216 HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags )
218 session_t *session;
219 HINTERNET handle = NULL;
221 TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent), access, debugstr_w(proxy), debugstr_w(bypass), flags);
223 if (!(session = heap_alloc_zero( sizeof(session_t) ))) return NULL;
225 session->hdr.type = WINHTTP_HANDLE_TYPE_SESSION;
226 session->hdr.vtbl = &session_vtbl;
227 session->hdr.flags = flags;
228 session->hdr.refs = 1;
229 session->hdr.redirect_policy = WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP;
230 list_init( &session->hdr.children );
231 session->resolve_timeout = DEFAULT_RESOLVE_TIMEOUT;
232 session->connect_timeout = DEFAULT_CONNECT_TIMEOUT;
233 session->send_timeout = DEFAULT_SEND_TIMEOUT;
234 session->recv_timeout = DEFAULT_RECEIVE_TIMEOUT;
235 list_init( &session->cookie_cache );
237 if (agent && !(session->agent = strdupW( agent ))) goto end;
238 if (access == WINHTTP_ACCESS_TYPE_DEFAULT_PROXY)
240 WINHTTP_PROXY_INFO info;
242 WinHttpGetDefaultProxyConfiguration( &info );
243 session->access = info.dwAccessType;
244 if (info.lpszProxy && !(session->proxy_server = strdupW( info.lpszProxy )))
246 GlobalFree( info.lpszProxy );
247 GlobalFree( info.lpszProxyBypass );
248 goto end;
250 if (info.lpszProxyBypass && !(session->proxy_bypass = strdupW( info.lpszProxyBypass )))
252 GlobalFree( info.lpszProxy );
253 GlobalFree( info.lpszProxyBypass );
254 goto end;
257 else if (access == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
259 session->access = access;
260 if (proxy && !(session->proxy_server = strdupW( proxy ))) goto end;
261 if (bypass && !(session->proxy_bypass = strdupW( bypass ))) goto end;
264 if (!(handle = alloc_handle( &session->hdr ))) goto end;
265 session->hdr.handle = handle;
267 end:
268 release_object( &session->hdr );
269 TRACE("returning %p\n", handle);
270 return handle;
273 /***********************************************************************
274 * connect_destroy (internal)
276 static void connect_destroy( object_header_t *hdr )
278 connect_t *connect = (connect_t *)hdr;
280 TRACE("%p\n", connect);
282 release_object( &connect->session->hdr );
284 heap_free( connect->hostname );
285 heap_free( connect->servername );
286 heap_free( connect->username );
287 heap_free( connect->password );
288 heap_free( connect );
291 static BOOL connect_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
293 connect_t *connect = (connect_t *)hdr;
295 switch (option)
297 case WINHTTP_OPTION_PARENT_HANDLE:
299 if (!buffer || *buflen < sizeof(HINTERNET))
301 *buflen = sizeof(HINTERNET);
302 set_last_error( ERROR_INSUFFICIENT_BUFFER );
303 return FALSE;
306 *(HINTERNET *)buffer = ((object_header_t *)connect->session)->handle;
307 *buflen = sizeof(HINTERNET);
308 return TRUE;
310 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
311 *(DWORD *)buffer = connect->session->resolve_timeout;
312 *buflen = sizeof(DWORD);
313 return TRUE;
314 case WINHTTP_OPTION_CONNECT_TIMEOUT:
315 *(DWORD *)buffer = connect->session->connect_timeout;
316 *buflen = sizeof(DWORD);
317 return TRUE;
318 case WINHTTP_OPTION_SEND_TIMEOUT:
319 *(DWORD *)buffer = connect->session->send_timeout;
320 *buflen = sizeof(DWORD);
321 return TRUE;
322 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
323 *(DWORD *)buffer = connect->session->recv_timeout;
324 *buflen = sizeof(DWORD);
325 return TRUE;
326 default:
327 FIXME("unimplemented option %u\n", option);
328 set_last_error( ERROR_INVALID_PARAMETER );
329 return FALSE;
333 static const object_vtbl_t connect_vtbl =
335 connect_destroy,
336 connect_query_option,
337 NULL
340 static BOOL domain_matches(LPCWSTR server, LPCWSTR domain)
342 static const WCHAR localW[] = { '<','l','o','c','a','l','>',0 };
343 BOOL ret = FALSE;
345 if (!strcmpiW( domain, localW ) && !strchrW( server, '.' ))
346 ret = TRUE;
347 else if (*domain == '*')
349 if (domain[1] == '.')
351 LPCWSTR dot;
353 /* For a hostname to match a wildcard, the last domain must match
354 * the wildcard exactly. E.g. if the wildcard is *.a.b, and the
355 * hostname is www.foo.a.b, it matches, but a.b does not.
357 dot = strchrW( server, '.' );
358 if (dot)
360 int len = strlenW( dot + 1 );
362 if (len > strlenW( domain + 2 ))
364 LPCWSTR ptr;
366 /* The server's domain is longer than the wildcard, so it
367 * could be a subdomain. Compare the last portion of the
368 * server's domain.
370 ptr = dot + len + 1 - strlenW( domain + 2 );
371 if (!strcmpiW( ptr, domain + 2 ))
373 /* This is only a match if the preceding character is
374 * a '.', i.e. that it is a matching domain. E.g.
375 * if domain is '*.b.c' and server is 'www.ab.c' they
376 * do not match.
378 ret = *(ptr - 1) == '.';
381 else
382 ret = !strcmpiW( dot + 1, domain + 2 );
386 else
387 ret = !strcmpiW( server, domain );
388 return ret;
391 /* Matches INTERNET_MAX_HOST_NAME_LENGTH in wininet.h, also RFC 1035 */
392 #define MAX_HOST_NAME_LENGTH 256
394 static BOOL should_bypass_proxy(session_t *session, LPCWSTR server)
396 LPCWSTR ptr;
397 BOOL ret = FALSE;
399 if (!session->proxy_bypass) return FALSE;
400 ptr = session->proxy_bypass;
401 do {
402 LPCWSTR tmp = ptr;
404 ptr = strchrW( ptr, ';' );
405 if (!ptr)
406 ptr = strchrW( tmp, ' ' );
407 if (ptr)
409 if (ptr - tmp < MAX_HOST_NAME_LENGTH)
411 WCHAR domain[MAX_HOST_NAME_LENGTH];
413 memcpy( domain, tmp, (ptr - tmp) * sizeof(WCHAR) );
414 domain[ptr - tmp] = 0;
415 ret = domain_matches( server, domain );
417 ptr += 1;
419 else if (*tmp)
420 ret = domain_matches( server, tmp );
421 } while (ptr && !ret);
422 return ret;
425 BOOL set_server_for_hostname( connect_t *connect, LPCWSTR server, INTERNET_PORT port )
427 session_t *session = connect->session;
428 BOOL ret = TRUE;
430 if (session->proxy_server && !should_bypass_proxy(session, server))
432 LPCWSTR colon;
434 if ((colon = strchrW( session->proxy_server, ':' )))
436 if (!connect->servername || strncmpiW( connect->servername,
437 session->proxy_server, colon - session->proxy_server - 1 ))
439 heap_free( connect->servername );
440 connect->resolved = FALSE;
441 if (!(connect->servername = heap_alloc(
442 (colon - session->proxy_server + 1) * sizeof(WCHAR) )))
444 ret = FALSE;
445 goto end;
447 memcpy( connect->servername, session->proxy_server,
448 (colon - session->proxy_server) * sizeof(WCHAR) );
449 connect->servername[colon - session->proxy_server] = 0;
450 if (*(colon + 1))
451 connect->serverport = atoiW( colon + 1 );
452 else
453 connect->serverport = INTERNET_DEFAULT_PORT;
456 else
458 if (!connect->servername || strcmpiW( connect->servername,
459 session->proxy_server ))
461 heap_free( connect->servername );
462 connect->resolved = FALSE;
463 if (!(connect->servername = strdupW( session->proxy_server )))
465 ret = FALSE;
466 goto end;
468 connect->serverport = INTERNET_DEFAULT_PORT;
472 else if (server)
474 heap_free( connect->servername );
475 connect->resolved = FALSE;
476 if (!(connect->servername = strdupW( server )))
478 ret = FALSE;
479 goto end;
481 connect->serverport = port;
483 end:
484 return ret;
487 /***********************************************************************
488 * WinHttpConnect (winhttp.@)
490 HINTERNET WINAPI WinHttpConnect( HINTERNET hsession, LPCWSTR server, INTERNET_PORT port, DWORD reserved )
492 connect_t *connect;
493 session_t *session;
494 HINTERNET hconnect = NULL;
496 TRACE("%p, %s, %u, %x\n", hsession, debugstr_w(server), port, reserved);
498 if (!server)
500 set_last_error( ERROR_INVALID_PARAMETER );
501 return NULL;
503 if (!(session = (session_t *)grab_object( hsession )))
505 set_last_error( ERROR_INVALID_HANDLE );
506 return NULL;
508 if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
510 release_object( &session->hdr );
511 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
512 return NULL;
514 if (!(connect = heap_alloc_zero( sizeof(connect_t) )))
516 release_object( &session->hdr );
517 return NULL;
519 connect->hdr.type = WINHTTP_HANDLE_TYPE_CONNECT;
520 connect->hdr.vtbl = &connect_vtbl;
521 connect->hdr.refs = 1;
522 connect->hdr.flags = session->hdr.flags;
523 connect->hdr.callback = session->hdr.callback;
524 connect->hdr.notify_mask = session->hdr.notify_mask;
525 connect->hdr.context = session->hdr.context;
526 connect->hdr.redirect_policy = session->hdr.redirect_policy;
527 list_init( &connect->hdr.children );
529 addref_object( &session->hdr );
530 connect->session = session;
531 list_add_head( &session->hdr.children, &connect->hdr.entry );
533 if (!(connect->hostname = strdupW( server ))) goto end;
534 connect->hostport = port;
535 if (!set_server_for_hostname( connect, server, port )) goto end;
537 if (!(hconnect = alloc_handle( &connect->hdr ))) goto end;
538 connect->hdr.handle = hconnect;
540 send_callback( &session->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hconnect, sizeof(hconnect) );
542 end:
543 release_object( &connect->hdr );
544 release_object( &session->hdr );
545 TRACE("returning %p\n", hconnect);
546 return hconnect;
549 /***********************************************************************
550 * request_destroy (internal)
552 static void request_destroy( object_header_t *hdr )
554 request_t *request = (request_t *)hdr;
555 unsigned int i;
557 TRACE("%p\n", request);
559 release_object( &request->connect->hdr );
561 destroy_authinfo( request->authinfo );
562 destroy_authinfo( request->proxy_authinfo );
564 heap_free( request->verb );
565 heap_free( request->path );
566 heap_free( request->version );
567 heap_free( request->raw_headers );
568 heap_free( request->status_text );
569 for (i = 0; i < request->num_headers; i++)
571 heap_free( request->headers[i].field );
572 heap_free( request->headers[i].value );
574 heap_free( request->headers );
575 for (i = 0; i < request->num_accept_types; i++) heap_free( request->accept_types[i] );
576 heap_free( request->accept_types );
577 heap_free( request );
580 static void str_to_buffer( WCHAR *buffer, const WCHAR *str, LPDWORD buflen )
582 int len = 0;
583 if (str) len = strlenW( str );
584 if (buffer && *buflen > len)
586 if (str) memcpy( buffer, str, len * sizeof(WCHAR) );
587 buffer[len] = 0;
589 *buflen = len * sizeof(WCHAR);
592 static WCHAR *blob_to_str( DWORD encoding, CERT_NAME_BLOB *blob )
594 WCHAR *ret;
595 DWORD size, format = CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG;
597 size = CertNameToStrW( encoding, blob, format, NULL, 0 );
598 if ((ret = LocalAlloc( 0, size * sizeof(WCHAR) )))
599 CertNameToStrW( encoding, blob, format, ret, size );
601 return ret;
604 static BOOL convert_sockaddr( const struct sockaddr *addr, SOCKADDR_STORAGE *addr_storage )
606 #ifndef __MINGW32__
607 switch (addr->sa_family)
609 case AF_INET:
611 const struct sockaddr_in *addr_unix = (const struct sockaddr_in *)addr;
612 struct WS_sockaddr_in *addr_win = (struct WS_sockaddr_in *)addr_storage;
613 char *p;
615 addr_win->sin_family = WS_AF_INET;
616 addr_win->sin_port = addr_unix->sin_port;
617 memcpy( &addr_win->sin_addr, &addr_unix->sin_addr, 4 );
618 p = (char *)&addr_win->sin_addr + 4;
619 memset( p, 0, sizeof(*addr_storage) - (p - (char *)addr_win) );
620 return TRUE;
622 case AF_INET6:
624 const struct sockaddr_in6 *addr_unix = (const struct sockaddr_in6 *)addr;
625 struct WS_sockaddr_in6 *addr_win = (struct WS_sockaddr_in6 *)addr_storage;
627 addr_win->sin6_family = WS_AF_INET6;
628 addr_win->sin6_port = addr_unix->sin6_port;
629 addr_win->sin6_flowinfo = addr_unix->sin6_flowinfo;
630 memcpy( &addr_win->sin6_addr, &addr_unix->sin6_addr, 16 );
631 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
632 addr_win->sin6_scope_id = addr_unix->sin6_scope_id;
633 #else
634 addr_win->sin6_scope_id = 0;
635 #endif
636 memset( addr_win + 1, 0, sizeof(*addr_storage) - sizeof(*addr_win) );
637 return TRUE;
639 default:
640 ERR("unhandled family %u\n", addr->sa_family);
641 return FALSE;
643 #else
644 switch (addr->sa_family)
646 case AF_INET:
648 struct sockaddr_in *addr_in = (struct sockaddr_in *)addr_storage;
650 memcpy( addr_in, addr, sizeof(*addr_in) );
651 memset( addr_in + 1, 0, sizeof(*addr_storage) - sizeof(*addr_in) );
652 return TRUE;
654 case AF_INET6:
656 struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr_storage;
658 memcpy( addr_in6, addr, sizeof(*addr_in6) );
659 memset( addr_in6 + 1, 0, sizeof(*addr_storage) - sizeof(*addr_in6) );
660 return TRUE;
662 default:
663 ERR("unhandled family %u\n", addr->sa_family);
664 return FALSE;
666 #endif
669 static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
671 request_t *request = (request_t *)hdr;
673 switch (option)
675 case WINHTTP_OPTION_SECURITY_FLAGS:
677 DWORD flags;
678 int bits;
680 if (!buffer || *buflen < sizeof(flags))
682 *buflen = sizeof(flags);
683 set_last_error( ERROR_INSUFFICIENT_BUFFER );
684 return FALSE;
687 flags = 0;
688 if (hdr->flags & WINHTTP_FLAG_SECURE) flags |= SECURITY_FLAG_SECURE;
689 flags |= request->netconn.security_flags;
690 bits = netconn_get_cipher_strength( &request->netconn );
691 if (bits >= 128)
692 flags |= SECURITY_FLAG_STRENGTH_STRONG;
693 else if (bits >= 56)
694 flags |= SECURITY_FLAG_STRENGTH_MEDIUM;
695 else
696 flags |= SECURITY_FLAG_STRENGTH_WEAK;
697 *(DWORD *)buffer = flags;
698 *buflen = sizeof(flags);
699 return TRUE;
701 case WINHTTP_OPTION_SERVER_CERT_CONTEXT:
703 const CERT_CONTEXT *cert;
705 if (!buffer || *buflen < sizeof(cert))
707 *buflen = sizeof(cert);
708 set_last_error( ERROR_INSUFFICIENT_BUFFER );
709 return FALSE;
712 if (!(cert = netconn_get_certificate( &request->netconn ))) return FALSE;
713 *(CERT_CONTEXT **)buffer = (CERT_CONTEXT *)cert;
714 *buflen = sizeof(cert);
715 return TRUE;
717 case WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT:
719 const CERT_CONTEXT *cert;
720 const CRYPT_OID_INFO *oidInfo;
721 WINHTTP_CERTIFICATE_INFO *ci = buffer;
723 FIXME("partial stub\n");
725 if (!buffer || *buflen < sizeof(*ci))
727 *buflen = sizeof(*ci);
728 set_last_error( ERROR_INSUFFICIENT_BUFFER );
729 return FALSE;
731 if (!(cert = netconn_get_certificate( &request->netconn ))) return FALSE;
733 ci->ftExpiry = cert->pCertInfo->NotAfter;
734 ci->ftStart = cert->pCertInfo->NotBefore;
735 ci->lpszSubjectInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Subject );
736 ci->lpszIssuerInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Issuer );
737 ci->lpszProtocolName = NULL;
738 oidInfo = CryptFindOIDInfo( CRYPT_OID_INFO_OID_KEY,
739 cert->pCertInfo->SignatureAlgorithm.pszObjId,
740 0 );
741 if (oidInfo)
742 ci->lpszSignatureAlgName = (LPWSTR)oidInfo->pwszName;
743 else
744 ci->lpszSignatureAlgName = NULL;
745 ci->lpszEncryptionAlgName = NULL;
746 ci->dwKeySize = netconn_get_cipher_strength( &request->netconn );
748 CertFreeCertificateContext( cert );
749 *buflen = sizeof(*ci);
750 return TRUE;
752 case WINHTTP_OPTION_SECURITY_KEY_BITNESS:
754 if (!buffer || *buflen < sizeof(DWORD))
756 *buflen = sizeof(DWORD);
757 set_last_error( ERROR_INSUFFICIENT_BUFFER );
758 return FALSE;
761 *(DWORD *)buffer = netconn_get_cipher_strength( &request->netconn );
762 *buflen = sizeof(DWORD);
763 return TRUE;
765 case WINHTTP_OPTION_CONNECTION_INFO:
767 WINHTTP_CONNECTION_INFO *info = buffer;
768 struct sockaddr local;
769 socklen_t len = sizeof(local);
770 const struct sockaddr *remote = (const struct sockaddr *)&request->connect->sockaddr;
772 if (!buffer || *buflen < sizeof(*info))
774 *buflen = sizeof(*info);
775 set_last_error( ERROR_INSUFFICIENT_BUFFER );
776 return FALSE;
778 if (!netconn_connected( &request->netconn ))
780 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_STATE );
781 return FALSE;
783 if (getsockname( request->netconn.socket, &local, &len )) return FALSE;
784 if (!convert_sockaddr( &local, &info->LocalAddress )) return FALSE;
785 if (!convert_sockaddr( remote, &info->RemoteAddress )) return FALSE;
786 info->cbSize = sizeof(*info);
787 return TRUE;
789 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
790 *(DWORD *)buffer = request->resolve_timeout;
791 *buflen = sizeof(DWORD);
792 return TRUE;
793 case WINHTTP_OPTION_CONNECT_TIMEOUT:
794 *(DWORD *)buffer = request->connect_timeout;
795 *buflen = sizeof(DWORD);
796 return TRUE;
797 case WINHTTP_OPTION_SEND_TIMEOUT:
798 *(DWORD *)buffer = request->send_timeout;
799 *buflen = sizeof(DWORD);
800 return TRUE;
801 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
802 *(DWORD *)buffer = request->recv_timeout;
803 *buflen = sizeof(DWORD);
804 return TRUE;
806 case WINHTTP_OPTION_USERNAME:
807 str_to_buffer( buffer, request->connect->username, buflen );
808 return TRUE;
810 case WINHTTP_OPTION_PASSWORD:
811 str_to_buffer( buffer, request->connect->password, buflen );
812 return TRUE;
814 case WINHTTP_OPTION_PROXY_USERNAME:
815 str_to_buffer( buffer, request->connect->session->proxy_username, buflen );
816 return TRUE;
818 case WINHTTP_OPTION_PROXY_PASSWORD:
819 str_to_buffer( buffer, request->connect->session->proxy_password, buflen );
820 return TRUE;
822 default:
823 FIXME("unimplemented option %u\n", option);
824 set_last_error( ERROR_INVALID_PARAMETER );
825 return FALSE;
829 static WCHAR *buffer_to_str( WCHAR *buffer, DWORD buflen )
831 WCHAR *ret;
832 if ((ret = heap_alloc( (buflen + 1) * sizeof(WCHAR))))
834 memcpy( ret, buffer, buflen * sizeof(WCHAR) );
835 ret[buflen] = 0;
836 return ret;
838 set_last_error( ERROR_OUTOFMEMORY );
839 return NULL;
842 static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
844 request_t *request = (request_t *)hdr;
846 switch (option)
848 case WINHTTP_OPTION_PROXY:
850 WINHTTP_PROXY_INFO *pi = buffer;
852 FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
853 return TRUE;
855 case WINHTTP_OPTION_DISABLE_FEATURE:
857 DWORD disable;
859 if (buflen != sizeof(DWORD))
861 set_last_error( ERROR_INSUFFICIENT_BUFFER );
862 return FALSE;
865 disable = *(DWORD *)buffer;
866 TRACE("0x%x\n", disable);
867 hdr->disable_flags |= disable;
868 return TRUE;
870 case WINHTTP_OPTION_AUTOLOGON_POLICY:
872 DWORD policy;
874 if (buflen != sizeof(DWORD))
876 set_last_error( ERROR_INSUFFICIENT_BUFFER );
877 return FALSE;
880 policy = *(DWORD *)buffer;
881 TRACE("0x%x\n", policy);
882 hdr->logon_policy = policy;
883 return TRUE;
885 case WINHTTP_OPTION_REDIRECT_POLICY:
887 DWORD policy;
889 if (buflen != sizeof(DWORD))
891 set_last_error( ERROR_INSUFFICIENT_BUFFER );
892 return FALSE;
895 policy = *(DWORD *)buffer;
896 TRACE("0x%x\n", policy);
897 hdr->redirect_policy = policy;
898 return TRUE;
900 case WINHTTP_OPTION_SECURITY_FLAGS:
902 DWORD flags;
904 if (buflen < sizeof(DWORD))
906 set_last_error( ERROR_INSUFFICIENT_BUFFER );
907 return FALSE;
909 flags = *(DWORD *)buffer;
910 TRACE("0x%x\n", flags);
911 if (!(flags & (SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
912 SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
913 SECURITY_FLAG_IGNORE_UNKNOWN_CA |
914 SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE)))
916 set_last_error( ERROR_INVALID_PARAMETER );
917 return FALSE;
919 request->netconn.security_flags = flags;
920 return TRUE;
922 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
923 request->resolve_timeout = *(DWORD *)buffer;
924 return TRUE;
925 case WINHTTP_OPTION_CONNECT_TIMEOUT:
926 request->connect_timeout = *(DWORD *)buffer;
927 return TRUE;
928 case WINHTTP_OPTION_SEND_TIMEOUT:
929 request->send_timeout = *(DWORD *)buffer;
930 return TRUE;
931 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
932 request->recv_timeout = *(DWORD *)buffer;
933 return TRUE;
935 case WINHTTP_OPTION_USERNAME:
937 connect_t *connect = request->connect;
939 heap_free( connect->username );
940 if (!(connect->username = buffer_to_str( buffer, buflen ))) return FALSE;
941 return TRUE;
943 case WINHTTP_OPTION_PASSWORD:
945 connect_t *connect = request->connect;
947 heap_free( connect->password );
948 if (!(connect->password = buffer_to_str( buffer, buflen ))) return FALSE;
949 return TRUE;
951 case WINHTTP_OPTION_PROXY_USERNAME:
953 session_t *session = request->connect->session;
955 heap_free( session->proxy_username );
956 if (!(session->proxy_username = buffer_to_str( buffer, buflen ))) return FALSE;
957 return TRUE;
959 case WINHTTP_OPTION_PROXY_PASSWORD:
961 session_t *session = request->connect->session;
963 heap_free( session->proxy_password );
964 if (!(session->proxy_password = buffer_to_str( buffer, buflen ))) return FALSE;
965 return TRUE;
967 default:
968 FIXME("unimplemented option %u\n", option);
969 set_last_error( ERROR_INVALID_PARAMETER );
970 return TRUE;
974 static const object_vtbl_t request_vtbl =
976 request_destroy,
977 request_query_option,
978 request_set_option
981 static BOOL store_accept_types( request_t *request, const WCHAR **accept_types )
983 const WCHAR **types = accept_types;
984 DWORD i;
986 if (!types) return TRUE;
987 while (*types)
989 request->num_accept_types++;
990 types++;
992 if (!request->num_accept_types) return TRUE;
993 if (!(request->accept_types = heap_alloc( request->num_accept_types * sizeof(WCHAR *))))
995 request->num_accept_types = 0;
996 return FALSE;
998 types = accept_types;
999 for (i = 0; i < request->num_accept_types; i++)
1001 if (!(request->accept_types[i] = strdupW( *types )))
1003 for ( ; i > 0; --i) heap_free( request->accept_types[i - 1] );
1004 heap_free( request->accept_types );
1005 request->accept_types = NULL;
1006 request->num_accept_types = 0;
1007 return FALSE;
1009 types++;
1011 return TRUE;
1014 /***********************************************************************
1015 * WinHttpOpenRequest (winhttp.@)
1017 HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR object, LPCWSTR version,
1018 LPCWSTR referrer, LPCWSTR *types, DWORD flags )
1020 request_t *request;
1021 connect_t *connect;
1022 HINTERNET hrequest = NULL;
1024 TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect, debugstr_w(verb), debugstr_w(object),
1025 debugstr_w(version), debugstr_w(referrer), types, flags);
1027 if(types && TRACE_ON(winhttp)) {
1028 const WCHAR **iter;
1030 TRACE("accept types:\n");
1031 for(iter = types; *iter; iter++)
1032 TRACE(" %s\n", debugstr_w(*iter));
1035 if (!(connect = (connect_t *)grab_object( hconnect )))
1037 set_last_error( ERROR_INVALID_HANDLE );
1038 return NULL;
1040 if (connect->hdr.type != WINHTTP_HANDLE_TYPE_CONNECT)
1042 release_object( &connect->hdr );
1043 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1044 return NULL;
1046 if (!(request = heap_alloc_zero( sizeof(request_t) )))
1048 release_object( &connect->hdr );
1049 return NULL;
1051 request->hdr.type = WINHTTP_HANDLE_TYPE_REQUEST;
1052 request->hdr.vtbl = &request_vtbl;
1053 request->hdr.refs = 1;
1054 request->hdr.flags = flags;
1055 request->hdr.callback = connect->hdr.callback;
1056 request->hdr.notify_mask = connect->hdr.notify_mask;
1057 request->hdr.context = connect->hdr.context;
1058 request->hdr.redirect_policy = connect->hdr.redirect_policy;
1059 list_init( &request->hdr.children );
1061 addref_object( &connect->hdr );
1062 request->connect = connect;
1063 list_add_head( &connect->hdr.children, &request->hdr.entry );
1065 if (!netconn_init( &request->netconn )) goto end;
1066 request->resolve_timeout = connect->session->resolve_timeout;
1067 request->connect_timeout = connect->session->connect_timeout;
1068 request->send_timeout = connect->session->send_timeout;
1069 request->recv_timeout = connect->session->recv_timeout;
1071 if (!verb || !verb[0]) verb = getW;
1072 if (!(request->verb = strdupW( verb ))) goto end;
1074 if (object)
1076 WCHAR *path, *p;
1077 unsigned int len;
1079 len = strlenW( object ) + 1;
1080 if (object[0] != '/') len++;
1081 if (!(p = path = heap_alloc( len * sizeof(WCHAR) ))) goto end;
1083 if (object[0] != '/') *p++ = '/';
1084 strcpyW( p, object );
1085 request->path = path;
1087 else if (!(request->path = strdupW( slashW ))) goto end;
1089 if (!version || !version[0]) version = http1_1;
1090 if (!(request->version = strdupW( version ))) goto end;
1091 if (!(store_accept_types( request, types ))) goto end;
1093 if (!(hrequest = alloc_handle( &request->hdr ))) goto end;
1094 request->hdr.handle = hrequest;
1096 send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hrequest, sizeof(hrequest) );
1098 end:
1099 release_object( &request->hdr );
1100 release_object( &connect->hdr );
1101 TRACE("returning %p\n", hrequest);
1102 return hrequest;
1105 /***********************************************************************
1106 * WinHttpCloseHandle (winhttp.@)
1108 BOOL WINAPI WinHttpCloseHandle( HINTERNET handle )
1110 object_header_t *hdr;
1112 TRACE("%p\n", handle);
1114 if (!(hdr = grab_object( handle )))
1116 set_last_error( ERROR_INVALID_HANDLE );
1117 return FALSE;
1119 release_object( hdr );
1120 free_handle( handle );
1121 return TRUE;
1124 static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
1126 BOOL ret = FALSE;
1128 if (!buflen)
1130 set_last_error( ERROR_INVALID_PARAMETER );
1131 return FALSE;
1134 switch (option)
1136 case WINHTTP_OPTION_CONTEXT_VALUE:
1138 if (!buffer || *buflen < sizeof(DWORD_PTR))
1140 *buflen = sizeof(DWORD_PTR);
1141 set_last_error( ERROR_INSUFFICIENT_BUFFER );
1142 return FALSE;
1145 *(DWORD_PTR *)buffer = hdr->context;
1146 *buflen = sizeof(DWORD_PTR);
1147 return TRUE;
1149 default:
1150 if (hdr->vtbl->query_option) ret = hdr->vtbl->query_option( hdr, option, buffer, buflen );
1151 else
1153 FIXME("unimplemented option %u\n", option);
1154 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1155 return FALSE;
1157 break;
1159 return ret;
1162 /***********************************************************************
1163 * WinHttpQueryOption (winhttp.@)
1165 BOOL WINAPI WinHttpQueryOption( HINTERNET handle, DWORD option, LPVOID buffer, LPDWORD buflen )
1167 BOOL ret = FALSE;
1168 object_header_t *hdr;
1170 TRACE("%p, %u, %p, %p\n", handle, option, buffer, buflen);
1172 if (!(hdr = grab_object( handle )))
1174 set_last_error( ERROR_INVALID_HANDLE );
1175 return FALSE;
1178 ret = query_option( hdr, option, buffer, buflen );
1180 release_object( hdr );
1181 return ret;
1184 static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
1186 BOOL ret = TRUE;
1188 if (!buffer)
1190 set_last_error( ERROR_INVALID_PARAMETER );
1191 return FALSE;
1194 switch (option)
1196 case WINHTTP_OPTION_CONTEXT_VALUE:
1198 if (buflen != sizeof(DWORD_PTR))
1200 set_last_error( ERROR_INSUFFICIENT_BUFFER );
1201 return FALSE;
1204 hdr->context = *(DWORD_PTR *)buffer;
1205 return TRUE;
1207 default:
1208 if (hdr->vtbl->set_option) ret = hdr->vtbl->set_option( hdr, option, buffer, buflen );
1209 else
1211 FIXME("unimplemented option %u\n", option);
1212 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1213 return FALSE;
1215 break;
1217 return ret;
1220 /***********************************************************************
1221 * WinHttpSetOption (winhttp.@)
1223 BOOL WINAPI WinHttpSetOption( HINTERNET handle, DWORD option, LPVOID buffer, DWORD buflen )
1225 BOOL ret = FALSE;
1226 object_header_t *hdr;
1228 TRACE("%p, %u, %p, %u\n", handle, option, buffer, buflen);
1230 if (!(hdr = grab_object( handle )))
1232 set_last_error( ERROR_INVALID_HANDLE );
1233 return FALSE;
1236 ret = set_option( hdr, option, buffer, buflen );
1238 release_object( hdr );
1239 return ret;
1242 static char *get_computer_name( COMPUTER_NAME_FORMAT format )
1244 char *ret;
1245 DWORD size = 0;
1247 GetComputerNameExA( format, NULL, &size );
1248 if (GetLastError() != ERROR_MORE_DATA) return NULL;
1249 if (!(ret = heap_alloc( size ))) return NULL;
1250 if (!GetComputerNameExA( format, ret, &size ))
1252 heap_free( ret );
1253 return NULL;
1255 return ret;
1258 static BOOL is_domain_suffix( const char *domain, const char *suffix )
1260 int len_domain = strlen( domain ), len_suffix = strlen( suffix );
1262 if (len_suffix > len_domain) return FALSE;
1263 if (!strcasecmp( domain + len_domain - len_suffix, suffix )) return TRUE;
1264 return FALSE;
1267 static int reverse_lookup( const struct addrinfo *ai, char *hostname, size_t len )
1269 int ret = -1;
1270 #ifdef HAVE_GETNAMEINFO
1271 ret = getnameinfo( ai->ai_addr, ai->ai_addrlen, hostname, len, NULL, 0, 0 );
1272 #endif
1273 return ret;
1276 static WCHAR *build_wpad_url( const char *hostname, const struct addrinfo *ai )
1278 static const WCHAR httpW[] = {'h','t','t','p',':','/','/',0};
1279 static const WCHAR wpadW[] = {'/','w','p','a','d','.','d','a','t',0};
1280 char name[NI_MAXHOST];
1281 WCHAR *ret, *p;
1282 int len;
1284 while (ai && ai->ai_family != AF_INET && ai->ai_family != AF_INET6) ai = ai->ai_next;
1285 if (!ai) return NULL;
1287 if (!reverse_lookup( ai, name, sizeof(name) )) hostname = name;
1289 len = strlenW( httpW ) + strlen( hostname ) + strlenW( wpadW );
1290 if (!(ret = p = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) return NULL;
1291 strcpyW( p, httpW );
1292 p += strlenW( httpW );
1293 while (*hostname) { *p++ = *hostname++; }
1294 strcpyW( p, wpadW );
1295 return ret;
1298 static BOOL get_system_proxy_autoconfig_url( char *buf, DWORD buflen )
1300 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1301 CFDictionaryRef settings = CFNetworkCopySystemProxySettings();
1302 const void *ref;
1303 BOOL ret = FALSE;
1305 if (!settings) return FALSE;
1307 if (!(ref = CFDictionaryGetValue( settings, kCFNetworkProxiesProxyAutoConfigURLString )))
1309 CFRelease( settings );
1310 return FALSE;
1312 if (CFStringGetCString( ref, buf, buflen, kCFStringEncodingASCII ))
1314 TRACE( "returning %s\n", debugstr_a(buf) );
1315 ret = TRUE;
1317 CFRelease( settings );
1318 return ret;
1319 #else
1320 FIXME( "no support on this platform\n" );
1321 return FALSE;
1322 #endif
1325 #define INTERNET_MAX_URL_LENGTH 2084
1327 /***********************************************************************
1328 * WinHttpDetectAutoProxyConfigUrl (winhttp.@)
1330 BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url )
1332 BOOL ret = FALSE;
1333 char system_url[INTERNET_MAX_URL_LENGTH + 1];
1335 TRACE("0x%08x, %p\n", flags, url);
1337 if (!flags || !url)
1339 set_last_error( ERROR_INVALID_PARAMETER );
1340 return FALSE;
1342 if (get_system_proxy_autoconfig_url( system_url, sizeof(system_url) ))
1344 WCHAR *urlW;
1346 if (!(urlW = strdupAW( system_url ))) return FALSE;
1347 *url = urlW;
1348 return TRUE;
1350 if (flags & WINHTTP_AUTO_DETECT_TYPE_DHCP)
1352 static int fixme_shown;
1353 if (!fixme_shown++) FIXME("discovery via DHCP not supported\n");
1355 if (flags & WINHTTP_AUTO_DETECT_TYPE_DNS_A)
1357 #ifdef HAVE_GETADDRINFO
1358 char *fqdn, *domain, *p;
1360 if (!(fqdn = get_computer_name( ComputerNamePhysicalDnsFullyQualified ))) return FALSE;
1361 if (!(domain = get_computer_name( ComputerNamePhysicalDnsDomain )))
1363 heap_free( fqdn );
1364 return FALSE;
1366 p = fqdn;
1367 while ((p = strchr( p, '.' )) && is_domain_suffix( p + 1, domain ))
1369 struct addrinfo *ai;
1370 char *name;
1371 int res;
1373 if (!(name = heap_alloc( sizeof("wpad") + strlen(p) )))
1375 heap_free( fqdn );
1376 heap_free( domain );
1377 return FALSE;
1379 strcpy( name, "wpad" );
1380 strcat( name, p );
1381 res = getaddrinfo( name, NULL, NULL, &ai );
1382 if (!res)
1384 *url = build_wpad_url( name, ai );
1385 freeaddrinfo( ai );
1386 if (*url)
1388 TRACE("returning %s\n", debugstr_w(*url));
1389 heap_free( name );
1390 ret = TRUE;
1391 break;
1394 heap_free( name );
1395 p++;
1397 heap_free( domain );
1398 heap_free( fqdn );
1399 #else
1400 FIXME("getaddrinfo not found at build time\n");
1401 #endif
1403 if (!ret)
1405 set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED );
1406 *url = NULL;
1408 return ret;
1411 static const WCHAR Connections[] = {
1412 'S','o','f','t','w','a','r','e','\\',
1413 'M','i','c','r','o','s','o','f','t','\\',
1414 'W','i','n','d','o','w','s','\\',
1415 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1416 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
1417 'C','o','n','n','e','c','t','i','o','n','s',0 };
1418 static const WCHAR WinHttpSettings[] = {
1419 'W','i','n','H','t','t','p','S','e','t','t','i','n','g','s',0 };
1420 static const DWORD WINHTTP_SETTINGS_MAGIC = 0x18;
1421 static const DWORD WININET_SETTINGS_MAGIC = 0x46;
1422 static const DWORD PROXY_TYPE_DIRECT = 1;
1423 static const DWORD PROXY_TYPE_PROXY = 2;
1424 static const DWORD PROXY_USE_PAC_SCRIPT = 4;
1425 static const DWORD PROXY_AUTODETECT_SETTINGS = 8;
1427 struct connection_settings_header
1429 DWORD magic;
1430 DWORD unknown; /* always zero? */
1431 DWORD flags; /* one or more of PROXY_* */
1434 static inline void copy_char_to_wchar_sz(const BYTE *src, DWORD len, WCHAR *dst)
1436 const BYTE *begin;
1438 for (begin = src; src - begin < len; src++, dst++)
1439 *dst = *src;
1440 *dst = 0;
1443 /***********************************************************************
1444 * WinHttpGetDefaultProxyConfiguration (winhttp.@)
1446 BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
1448 LONG l;
1449 HKEY key;
1450 BOOL got_from_reg = FALSE, direct = TRUE;
1451 char *envproxy;
1453 TRACE("%p\n", info);
1455 l = RegOpenKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, KEY_READ, &key );
1456 if (!l)
1458 DWORD type, size = 0;
1460 l = RegQueryValueExW( key, WinHttpSettings, NULL, &type, NULL, &size );
1461 if (!l && type == REG_BINARY &&
1462 size >= sizeof(struct connection_settings_header) + 2 * sizeof(DWORD))
1464 BYTE *buf = heap_alloc( size );
1466 if (buf)
1468 struct connection_settings_header *hdr =
1469 (struct connection_settings_header *)buf;
1470 DWORD *len = (DWORD *)(hdr + 1);
1472 l = RegQueryValueExW( key, WinHttpSettings, NULL, NULL, buf,
1473 &size );
1474 if (!l && hdr->magic == WINHTTP_SETTINGS_MAGIC &&
1475 hdr->unknown == 0)
1477 if (hdr->flags & PROXY_TYPE_PROXY)
1479 BOOL sane = FALSE;
1480 LPWSTR proxy = NULL;
1481 LPWSTR proxy_bypass = NULL;
1483 /* Sanity-check length of proxy string */
1484 if ((BYTE *)len - buf + *len <= size)
1486 sane = TRUE;
1487 proxy = GlobalAlloc( 0, (*len + 1) * sizeof(WCHAR) );
1488 if (proxy)
1489 copy_char_to_wchar_sz( (BYTE *)(len + 1), *len, proxy );
1490 len = (DWORD *)((BYTE *)(len + 1) + *len);
1492 if (sane)
1494 /* Sanity-check length of proxy bypass string */
1495 if ((BYTE *)len - buf + *len <= size)
1497 proxy_bypass = GlobalAlloc( 0, (*len + 1) * sizeof(WCHAR) );
1498 if (proxy_bypass)
1499 copy_char_to_wchar_sz( (BYTE *)(len + 1), *len, proxy_bypass );
1501 else
1503 sane = FALSE;
1504 GlobalFree( proxy );
1505 proxy = NULL;
1508 info->lpszProxy = proxy;
1509 info->lpszProxyBypass = proxy_bypass;
1510 if (sane)
1512 got_from_reg = TRUE;
1513 direct = FALSE;
1514 info->dwAccessType =
1515 WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1516 TRACE("http proxy (from registry) = %s, bypass = %s\n",
1517 debugstr_w(info->lpszProxy),
1518 debugstr_w(info->lpszProxyBypass));
1522 heap_free( buf );
1525 RegCloseKey( key );
1527 if (!got_from_reg && (envproxy = getenv( "http_proxy" )))
1529 char *colon, *http_proxy;
1531 if ((colon = strchr( envproxy, ':' )))
1533 if (*(colon + 1) == '/' && *(colon + 2) == '/')
1535 static const char http[] = "http://";
1537 /* It's a scheme, check that it's http */
1538 if (!strncmp( envproxy, http, strlen( http ) ))
1539 http_proxy = envproxy + strlen( http );
1540 else
1542 WARN("unsupported scheme in $http_proxy: %s\n", envproxy);
1543 http_proxy = NULL;
1546 else
1547 http_proxy = envproxy;
1549 else
1550 http_proxy = envproxy;
1551 if (http_proxy)
1553 WCHAR *http_proxyW;
1554 int len;
1556 len = MultiByteToWideChar( CP_UNIXCP, 0, http_proxy, -1, NULL, 0 );
1557 if ((http_proxyW = GlobalAlloc( 0, len * sizeof(WCHAR))))
1559 MultiByteToWideChar( CP_UNIXCP, 0, http_proxy, -1, http_proxyW, len );
1560 direct = FALSE;
1561 info->dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1562 info->lpszProxy = http_proxyW;
1563 info->lpszProxyBypass = NULL;
1564 TRACE("http proxy (from environment) = %s\n",
1565 debugstr_w(info->lpszProxy));
1569 if (direct)
1571 info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
1572 info->lpszProxy = NULL;
1573 info->lpszProxyBypass = NULL;
1575 return TRUE;
1578 /***********************************************************************
1579 * WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
1581 BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *config )
1583 static const WCHAR settingsW[] =
1584 {'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};
1585 HKEY hkey = NULL;
1586 struct connection_settings_header *hdr = NULL;
1587 DWORD type, offset, len, size = 0;
1588 BOOL ret = FALSE;
1590 TRACE("%p\n", config);
1592 if (!config)
1594 set_last_error( ERROR_INVALID_PARAMETER );
1595 return FALSE;
1597 memset( config, 0, sizeof(*config) );
1598 config->fAutoDetect = TRUE;
1600 if (RegOpenKeyExW( HKEY_CURRENT_USER, Connections, 0, KEY_READ, &hkey ) ||
1601 RegQueryValueExW( hkey, settingsW, NULL, &type, NULL, &size ) ||
1602 type != REG_BINARY || size < sizeof(struct connection_settings_header))
1604 ret = TRUE;
1605 goto done;
1607 if (!(hdr = heap_alloc( size ))) goto done;
1608 if (RegQueryValueExW( hkey, settingsW, NULL, &type, (BYTE *)hdr, &size ) ||
1609 hdr->magic != WININET_SETTINGS_MAGIC)
1611 ret = TRUE;
1612 goto done;
1615 config->fAutoDetect = (hdr->flags & PROXY_AUTODETECT_SETTINGS) != 0;
1616 offset = sizeof(*hdr);
1617 if (offset + sizeof(DWORD) > size) goto done;
1618 len = *(DWORD *)((char *)hdr + offset);
1619 offset += sizeof(DWORD);
1620 if (len && hdr->flags & PROXY_TYPE_PROXY)
1622 if (!(config->lpszProxy = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
1623 copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszProxy );
1625 offset += len;
1626 if (offset + sizeof(DWORD) > size) goto done;
1627 len = *(DWORD *)((char *)hdr + offset);
1628 offset += sizeof(DWORD);
1629 if (len && (hdr->flags & PROXY_TYPE_PROXY))
1631 if (!(config->lpszProxyBypass = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
1632 copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszProxyBypass );
1634 offset += len;
1635 if (offset + sizeof(DWORD) > size) goto done;
1636 len = *(DWORD *)((char *)hdr + offset);
1637 offset += sizeof(DWORD);
1638 if (len && (hdr->flags & PROXY_USE_PAC_SCRIPT))
1640 if (!(config->lpszAutoConfigUrl = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
1641 copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszAutoConfigUrl );
1643 ret = TRUE;
1645 done:
1646 RegCloseKey( hkey );
1647 heap_free( hdr );
1648 if (!ret)
1650 GlobalFree( config->lpszAutoConfigUrl );
1651 config->lpszAutoConfigUrl = NULL;
1652 GlobalFree( config->lpszProxy );
1653 config->lpszProxy = NULL;
1654 GlobalFree( config->lpszProxyBypass );
1655 config->lpszProxyBypass = NULL;
1657 return ret;
1660 static BOOL parse_script_result( const char *result, WINHTTP_PROXY_INFO *info )
1662 const char *p;
1663 WCHAR *q;
1664 int len;
1666 info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
1667 info->lpszProxy = NULL;
1668 info->lpszProxyBypass = NULL;
1670 TRACE("%s\n", debugstr_a( result ));
1672 p = result;
1673 while (*p == ' ') p++;
1674 len = strlen( p );
1675 if (len >= 5 && !strncasecmp( p, "PROXY", sizeof("PROXY") - 1 ))
1677 p += 5;
1678 while (*p == ' ') p++;
1679 if (!*p || *p == ';') return TRUE;
1680 if (!(info->lpszProxy = q = strdupAW( p ))) return FALSE;
1681 info->dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1682 for (; *q; q++)
1684 if (*q == ' ' || *q == ';')
1686 *q = 0;
1687 break;
1691 return TRUE;
1694 static char *download_script( const WCHAR *url, DWORD *out_size )
1696 static const WCHAR typeW[] = {'*','/','*',0};
1697 static const WCHAR *acceptW[] = {typeW, NULL};
1698 HINTERNET ses, con = NULL, req = NULL;
1699 WCHAR *hostname;
1700 URL_COMPONENTSW uc;
1701 DWORD status, size = sizeof(status), offset, to_read, bytes_read, flags = 0;
1702 char *tmp, *buffer = NULL;
1704 *out_size = 0;
1706 memset( &uc, 0, sizeof(uc) );
1707 uc.dwStructSize = sizeof(uc);
1708 if (!WinHttpCrackUrl( url, 0, 0, &uc )) return NULL;
1709 if (!(hostname = heap_alloc( (uc.dwHostNameLength + 1) * sizeof(WCHAR) ))) return NULL;
1710 memcpy( hostname, uc.lpszHostName, uc.dwHostNameLength * sizeof(WCHAR) );
1711 hostname[uc.dwHostNameLength] = 0;
1713 if (!(ses = WinHttpOpen( NULL, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0 ))) goto done;
1714 if (!(con = WinHttpConnect( ses, hostname, uc.nPort, 0 ))) goto done;
1715 if (uc.nScheme == INTERNET_SCHEME_HTTPS) flags |= WINHTTP_FLAG_SECURE;
1716 if (!(req = WinHttpOpenRequest( con, NULL, uc.lpszUrlPath, NULL, NULL, acceptW, flags ))) goto done;
1717 if (!WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 )) goto done;
1719 if (!(WinHttpReceiveResponse( req, 0 ))) goto done;
1720 if (!WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status,
1721 &size, NULL ) || status != HTTP_STATUS_OK) goto done;
1723 size = 4096;
1724 if (!(buffer = heap_alloc( size ))) goto done;
1725 to_read = size;
1726 offset = 0;
1727 for (;;)
1729 if (!WinHttpReadData( req, buffer + offset, to_read, &bytes_read )) goto done;
1730 if (!bytes_read) break;
1731 to_read -= bytes_read;
1732 offset += bytes_read;
1733 *out_size += bytes_read;
1734 if (!to_read)
1736 to_read = size;
1737 size *= 2;
1738 if (!(tmp = heap_realloc( buffer, size ))) goto done;
1739 buffer = tmp;
1743 done:
1744 WinHttpCloseHandle( req );
1745 WinHttpCloseHandle( con );
1746 WinHttpCloseHandle( ses );
1747 heap_free( hostname );
1748 if (!buffer) set_last_error( ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT );
1749 return buffer;
1752 struct AUTO_PROXY_SCRIPT_BUFFER
1754 DWORD dwStructSize;
1755 LPSTR lpszScriptBuffer;
1756 DWORD dwScriptBufferSize;
1759 BOOL WINAPI InternetDeInitializeAutoProxyDll(LPSTR, DWORD);
1760 BOOL WINAPI InternetGetProxyInfo(LPCSTR, DWORD, LPSTR, DWORD, LPSTR *, LPDWORD);
1761 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD, LPSTR, LPSTR, void *, struct AUTO_PROXY_SCRIPT_BUFFER *);
1763 static BOOL run_script( char *script, DWORD size, const WCHAR *url, WINHTTP_PROXY_INFO *info )
1765 BOOL ret;
1766 char *result, *urlA;
1767 DWORD len_result;
1768 struct AUTO_PROXY_SCRIPT_BUFFER buffer;
1770 buffer.dwStructSize = sizeof(buffer);
1771 buffer.lpszScriptBuffer = script;
1772 buffer.dwScriptBufferSize = size;
1774 if (!(urlA = strdupWA( url ))) return FALSE;
1775 if (!(ret = InternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buffer )))
1777 heap_free( urlA );
1778 return FALSE;
1780 if ((ret = InternetGetProxyInfo( urlA, strlen(urlA), NULL, 0, &result, &len_result )))
1782 ret = parse_script_result( result, info );
1783 heap_free( result );
1785 heap_free( urlA );
1786 return InternetDeInitializeAutoProxyDll( NULL, 0 );
1789 /***********************************************************************
1790 * WinHttpGetProxyForUrl (winhttp.@)
1792 BOOL WINAPI WinHttpGetProxyForUrl( HINTERNET hsession, LPCWSTR url, WINHTTP_AUTOPROXY_OPTIONS *options,
1793 WINHTTP_PROXY_INFO *info )
1795 WCHAR *detected_pac_url = NULL;
1796 const WCHAR *pac_url;
1797 session_t *session;
1798 char *script;
1799 DWORD size;
1800 BOOL ret = FALSE;
1802 TRACE("%p, %s, %p, %p\n", hsession, debugstr_w(url), options, info);
1804 if (!(session = (session_t *)grab_object( hsession )))
1806 set_last_error( ERROR_INVALID_HANDLE );
1807 return FALSE;
1809 if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
1811 release_object( &session->hdr );
1812 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1813 return FALSE;
1815 if (!url || !options || !info ||
1816 !(options->dwFlags & (WINHTTP_AUTOPROXY_AUTO_DETECT|WINHTTP_AUTOPROXY_CONFIG_URL)) ||
1817 ((options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT) && !options->dwAutoDetectFlags) ||
1818 ((options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT) &&
1819 (options->dwFlags & WINHTTP_AUTOPROXY_CONFIG_URL)))
1821 release_object( &session->hdr );
1822 set_last_error( ERROR_INVALID_PARAMETER );
1823 return FALSE;
1825 if (options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT &&
1826 !WinHttpDetectAutoProxyConfigUrl( options->dwAutoDetectFlags, &detected_pac_url ))
1827 goto done;
1829 if (options->dwFlags & WINHTTP_AUTOPROXY_CONFIG_URL) pac_url = options->lpszAutoConfigUrl;
1830 else pac_url = detected_pac_url;
1832 if ((script = download_script( pac_url, &size )))
1834 ret = run_script( script, size, url, info );
1835 heap_free( script );
1838 done:
1839 GlobalFree( detected_pac_url );
1840 release_object( &session->hdr );
1841 return ret;
1844 /***********************************************************************
1845 * WinHttpSetDefaultProxyConfiguration (winhttp.@)
1847 BOOL WINAPI WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
1849 LONG l;
1850 HKEY key;
1851 BOOL ret = FALSE;
1852 const WCHAR *src;
1854 TRACE("%p\n", info);
1856 if (!info)
1858 set_last_error( ERROR_INVALID_PARAMETER );
1859 return FALSE;
1861 switch (info->dwAccessType)
1863 case WINHTTP_ACCESS_TYPE_NO_PROXY:
1864 break;
1865 case WINHTTP_ACCESS_TYPE_NAMED_PROXY:
1866 if (!info->lpszProxy)
1868 set_last_error( ERROR_INVALID_PARAMETER );
1869 return FALSE;
1871 /* Only ASCII characters are allowed */
1872 for (src = info->lpszProxy; *src; src++)
1873 if (*src > 0x7f)
1875 set_last_error( ERROR_INVALID_PARAMETER );
1876 return FALSE;
1878 if (info->lpszProxyBypass)
1880 for (src = info->lpszProxyBypass; *src; src++)
1881 if (*src > 0x7f)
1883 set_last_error( ERROR_INVALID_PARAMETER );
1884 return FALSE;
1887 break;
1888 default:
1889 set_last_error( ERROR_INVALID_PARAMETER );
1890 return FALSE;
1893 l = RegCreateKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, NULL, 0,
1894 KEY_WRITE, NULL, &key, NULL );
1895 if (!l)
1897 DWORD size = sizeof(struct connection_settings_header) + 2 * sizeof(DWORD);
1898 BYTE *buf;
1900 if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
1902 size += strlenW( info->lpszProxy );
1903 if (info->lpszProxyBypass)
1904 size += strlenW( info->lpszProxyBypass );
1906 buf = heap_alloc( size );
1907 if (buf)
1909 struct connection_settings_header *hdr =
1910 (struct connection_settings_header *)buf;
1911 DWORD *len = (DWORD *)(hdr + 1);
1913 hdr->magic = WINHTTP_SETTINGS_MAGIC;
1914 hdr->unknown = 0;
1915 if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
1917 BYTE *dst;
1919 hdr->flags = PROXY_TYPE_PROXY;
1920 *len++ = strlenW( info->lpszProxy );
1921 for (dst = (BYTE *)len, src = info->lpszProxy; *src;
1922 src++, dst++)
1923 *dst = *src;
1924 len = (DWORD *)dst;
1925 if (info->lpszProxyBypass)
1927 *len++ = strlenW( info->lpszProxyBypass );
1928 for (dst = (BYTE *)len, src = info->lpszProxyBypass; *src;
1929 src++, dst++)
1930 *dst = *src;
1932 else
1933 *len++ = 0;
1935 else
1937 hdr->flags = PROXY_TYPE_DIRECT;
1938 *len++ = 0;
1939 *len++ = 0;
1941 l = RegSetValueExW( key, WinHttpSettings, 0, REG_BINARY, buf, size );
1942 if (!l)
1943 ret = TRUE;
1944 heap_free( buf );
1946 RegCloseKey( key );
1948 return ret;
1951 /***********************************************************************
1952 * WinHttpSetStatusCallback (winhttp.@)
1954 WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback( HINTERNET handle, WINHTTP_STATUS_CALLBACK callback,
1955 DWORD flags, DWORD_PTR reserved )
1957 object_header_t *hdr;
1958 WINHTTP_STATUS_CALLBACK ret;
1960 TRACE("%p, %p, 0x%08x, 0x%lx\n", handle, callback, flags, reserved);
1962 if (!(hdr = grab_object( handle )))
1964 set_last_error( ERROR_INVALID_HANDLE );
1965 return WINHTTP_INVALID_STATUS_CALLBACK;
1967 ret = hdr->callback;
1968 hdr->callback = callback;
1969 hdr->notify_mask = flags;
1971 release_object( hdr );
1972 return ret;
1975 /***********************************************************************
1976 * WinHttpSetTimeouts (winhttp.@)
1978 BOOL WINAPI WinHttpSetTimeouts( HINTERNET handle, int resolve, int connect, int send, int receive )
1980 BOOL ret = TRUE;
1981 object_header_t *hdr;
1982 request_t *request;
1983 session_t *session;
1985 TRACE("%p, %d, %d, %d, %d\n", handle, resolve, connect, send, receive);
1987 if (resolve < -1 || connect < -1 || send < -1 || receive < -1)
1989 set_last_error( ERROR_INVALID_PARAMETER );
1990 return FALSE;
1993 if (!(hdr = grab_object( handle )))
1995 set_last_error( ERROR_INVALID_HANDLE );
1996 return FALSE;
1999 switch(hdr->type)
2001 case WINHTTP_HANDLE_TYPE_REQUEST:
2002 request = (request_t *)hdr;
2003 request->connect_timeout = connect;
2005 if (resolve < 0) resolve = 0;
2006 request->resolve_timeout = resolve;
2008 if (send < 0) send = 0;
2009 request->send_timeout = send;
2011 if (receive < 0) receive = 0;
2012 request->recv_timeout = receive;
2014 if (netconn_connected( &request->netconn ))
2016 if (netconn_set_timeout( &request->netconn, TRUE, send )) ret = FALSE;
2017 if (netconn_set_timeout( &request->netconn, FALSE, receive )) ret = FALSE;
2020 release_object( &request->hdr );
2021 break;
2023 case WINHTTP_HANDLE_TYPE_SESSION:
2024 session = (session_t *)hdr;
2025 session->connect_timeout = connect;
2027 if (resolve < 0) resolve = 0;
2028 session->resolve_timeout = resolve;
2030 if (send < 0) send = 0;
2031 session->send_timeout = send;
2033 if (receive < 0) receive = 0;
2034 session->recv_timeout = receive;
2035 break;
2037 default:
2038 release_object( hdr );
2039 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
2040 return FALSE;
2042 return ret;
2045 static const WCHAR wkday[7][4] =
2046 {{'S','u','n', 0}, {'M','o','n', 0}, {'T','u','e', 0}, {'W','e','d', 0},
2047 {'T','h','u', 0}, {'F','r','i', 0}, {'S','a','t', 0}};
2048 static const WCHAR month[12][4] =
2049 {{'J','a','n', 0}, {'F','e','b', 0}, {'M','a','r', 0}, {'A','p','r', 0},
2050 {'M','a','y', 0}, {'J','u','n', 0}, {'J','u','l', 0}, {'A','u','g', 0},
2051 {'S','e','p', 0}, {'O','c','t', 0}, {'N','o','v', 0}, {'D','e','c', 0}};
2053 /***********************************************************************
2054 * WinHttpTimeFromSystemTime (WININET.@)
2056 BOOL WINAPI WinHttpTimeFromSystemTime( const SYSTEMTIME *time, LPWSTR string )
2058 static const WCHAR format[] =
2059 {'%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2060 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0};
2062 TRACE("%p, %p\n", time, string);
2064 if (!time || !string) return FALSE;
2066 sprintfW( string, format,
2067 wkday[time->wDayOfWeek],
2068 time->wDay,
2069 month[time->wMonth - 1],
2070 time->wYear,
2071 time->wHour,
2072 time->wMinute,
2073 time->wSecond );
2075 return TRUE;
2078 /***********************************************************************
2079 * WinHttpTimeToSystemTime (WININET.@)
2081 BOOL WINAPI WinHttpTimeToSystemTime( LPCWSTR string, SYSTEMTIME *time )
2083 unsigned int i;
2084 const WCHAR *s = string;
2085 WCHAR *end;
2087 TRACE("%s, %p\n", debugstr_w(string), time);
2089 if (!string || !time) return FALSE;
2091 /* Windows does this too */
2092 GetSystemTime( time );
2094 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2095 * a SYSTEMTIME structure.
2098 while (*s && !isalphaW( *s )) s++;
2099 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2100 time->wDayOfWeek = 7;
2102 for (i = 0; i < 7; i++)
2104 if (toupperW( wkday[i][0] ) == toupperW( s[0] ) &&
2105 toupperW( wkday[i][1] ) == toupperW( s[1] ) &&
2106 toupperW( wkday[i][2] ) == toupperW( s[2] ) )
2108 time->wDayOfWeek = i;
2109 break;
2113 if (time->wDayOfWeek > 6) return TRUE;
2114 while (*s && !isdigitW( *s )) s++;
2115 time->wDay = strtolW( s, &end, 10 );
2116 s = end;
2118 while (*s && !isalphaW( *s )) s++;
2119 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2120 time->wMonth = 0;
2122 for (i = 0; i < 12; i++)
2124 if (toupperW( month[i][0]) == toupperW( s[0] ) &&
2125 toupperW( month[i][1]) == toupperW( s[1] ) &&
2126 toupperW( month[i][2]) == toupperW( s[2] ) )
2128 time->wMonth = i + 1;
2129 break;
2132 if (time->wMonth == 0) return TRUE;
2134 while (*s && !isdigitW( *s )) s++;
2135 if (*s == '\0') return TRUE;
2136 time->wYear = strtolW( s, &end, 10 );
2137 s = end;
2139 while (*s && !isdigitW( *s )) s++;
2140 if (*s == '\0') return TRUE;
2141 time->wHour = strtolW( s, &end, 10 );
2142 s = end;
2144 while (*s && !isdigitW( *s )) s++;
2145 if (*s == '\0') return TRUE;
2146 time->wMinute = strtolW( s, &end, 10 );
2147 s = end;
2149 while (*s && !isdigitW( *s )) s++;
2150 if (*s == '\0') return TRUE;
2151 time->wSecond = strtolW( s, &end, 10 );
2153 time->wMilliseconds = 0;
2154 return TRUE;