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
20 #include "wine/port.h"
21 #include "wine/debug.h"
41 #include "winhttp_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
45 #define DEFAULT_RESOLVE_TIMEOUT 0
46 #define DEFAULT_CONNECT_TIMEOUT 20000
47 #define DEFAULT_SEND_TIMEOUT 30000
48 #define DEFAULT_RECEIVE_TIMEOUT 30000
50 static const WCHAR global_funcsW[] = {'g','l','o','b','a','l','_','f','u','n','c','s',0};
51 static const WCHAR dns_resolveW[] = {'d','n','s','_','r','e','s','o','l','v','e',0};
53 void set_last_error( DWORD error )
56 SetLastError( error );
59 DWORD get_last_error( void )
62 return GetLastError();
65 void send_callback( object_header_t *hdr, DWORD status, LPVOID info, DWORD buflen )
67 TRACE("%p, 0x%08x, %p, %u\n", hdr, status, info, buflen);
69 if (hdr->callback && (hdr->notify_mask & status)) hdr->callback( hdr->handle, hdr->context, status, info, buflen );
72 /***********************************************************************
73 * WinHttpCheckPlatform (winhttp.@)
75 BOOL WINAPI WinHttpCheckPlatform( void )
81 /***********************************************************************
82 * session_destroy (internal)
84 static void session_destroy( object_header_t *hdr )
86 session_t *session = (session_t *)hdr;
87 struct list *item, *next;
90 TRACE("%p\n", session);
92 LIST_FOR_EACH_SAFE( item, next, &session->cookie_cache )
94 domain = LIST_ENTRY( item, domain_t, entry );
95 delete_domain( domain );
97 heap_free( session->agent );
98 heap_free( session->proxy_server );
99 heap_free( session->proxy_bypass );
100 heap_free( session->proxy_username );
101 heap_free( session->proxy_password );
102 heap_free( session );
105 static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
107 session_t *session = (session_t *)hdr;
111 case WINHTTP_OPTION_REDIRECT_POLICY:
113 if (!buffer || *buflen < sizeof(DWORD))
115 *buflen = sizeof(DWORD);
116 set_last_error( ERROR_INSUFFICIENT_BUFFER );
120 *(DWORD *)buffer = hdr->redirect_policy;
121 *buflen = sizeof(DWORD);
124 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
125 *(DWORD *)buffer = session->resolve_timeout;
126 *buflen = sizeof(DWORD);
128 case WINHTTP_OPTION_CONNECT_TIMEOUT:
129 *(DWORD *)buffer = session->connect_timeout;
130 *buflen = sizeof(DWORD);
132 case WINHTTP_OPTION_SEND_TIMEOUT:
133 *(DWORD *)buffer = session->send_timeout;
134 *buflen = sizeof(DWORD);
136 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
137 *(DWORD *)buffer = session->recv_timeout;
138 *buflen = sizeof(DWORD);
141 FIXME("unimplemented option %u\n", option);
142 set_last_error( ERROR_INVALID_PARAMETER );
147 static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
149 session_t *session = (session_t *)hdr;
153 case WINHTTP_OPTION_PROXY:
155 WINHTTP_PROXY_INFO *pi = buffer;
157 FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
160 case WINHTTP_OPTION_REDIRECT_POLICY:
164 if (buflen != sizeof(policy))
166 set_last_error( ERROR_INSUFFICIENT_BUFFER );
170 policy = *(DWORD *)buffer;
171 TRACE("0x%x\n", policy);
172 hdr->redirect_policy = policy;
175 case WINHTTP_OPTION_DISABLE_FEATURE:
176 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
178 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
179 session->resolve_timeout = *(DWORD *)buffer;
181 case WINHTTP_OPTION_CONNECT_TIMEOUT:
182 session->connect_timeout = *(DWORD *)buffer;
184 case WINHTTP_OPTION_SEND_TIMEOUT:
185 session->send_timeout = *(DWORD *)buffer;
187 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
188 session->recv_timeout = *(DWORD *)buffer;
190 case WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH:
191 FIXME("WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH: 0x%x\n", *(DWORD *)buffer);
194 FIXME("unimplemented option %u\n", option);
195 set_last_error( ERROR_INVALID_PARAMETER );
200 static const object_vtbl_t session_vtbl =
203 session_query_option,
207 /***********************************************************************
208 * WinHttpOpen (winhttp.@)
210 HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags )
213 HINTERNET handle = NULL;
215 TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent), access, debugstr_w(proxy), debugstr_w(bypass), flags);
217 if (!(session = heap_alloc_zero( sizeof(session_t) ))) return NULL;
219 session->hdr.type = WINHTTP_HANDLE_TYPE_SESSION;
220 session->hdr.vtbl = &session_vtbl;
221 session->hdr.flags = flags;
222 session->hdr.refs = 1;
223 session->hdr.redirect_policy = WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP;
224 list_init( &session->hdr.children );
225 session->resolve_timeout = DEFAULT_RESOLVE_TIMEOUT;
226 session->connect_timeout = DEFAULT_CONNECT_TIMEOUT;
227 session->send_timeout = DEFAULT_SEND_TIMEOUT;
228 session->recv_timeout = DEFAULT_RECEIVE_TIMEOUT;
229 list_init( &session->cookie_cache );
231 if (agent && !(session->agent = strdupW( agent ))) goto end;
232 if (access == WINHTTP_ACCESS_TYPE_DEFAULT_PROXY)
234 WINHTTP_PROXY_INFO info;
236 WinHttpGetDefaultProxyConfiguration( &info );
237 session->access = info.dwAccessType;
238 if (info.lpszProxy && !(session->proxy_server = strdupW( info.lpszProxy )))
240 GlobalFree( info.lpszProxy );
241 GlobalFree( info.lpszProxyBypass );
244 if (info.lpszProxyBypass && !(session->proxy_bypass = strdupW( info.lpszProxyBypass )))
246 GlobalFree( info.lpszProxy );
247 GlobalFree( info.lpszProxyBypass );
251 else if (access == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
253 session->access = access;
254 if (proxy && !(session->proxy_server = strdupW( proxy ))) goto end;
255 if (bypass && !(session->proxy_bypass = strdupW( bypass ))) goto end;
258 if (!(handle = alloc_handle( &session->hdr ))) goto end;
259 session->hdr.handle = handle;
262 release_object( &session->hdr );
263 TRACE("returning %p\n", handle);
267 /***********************************************************************
268 * connect_destroy (internal)
270 static void connect_destroy( object_header_t *hdr )
272 connect_t *connect = (connect_t *)hdr;
274 TRACE("%p\n", connect);
276 release_object( &connect->session->hdr );
278 heap_free( connect->hostname );
279 heap_free( connect->servername );
280 heap_free( connect->username );
281 heap_free( connect->password );
282 heap_free( connect );
285 static BOOL connect_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
287 connect_t *connect = (connect_t *)hdr;
291 case WINHTTP_OPTION_PARENT_HANDLE:
293 if (!buffer || *buflen < sizeof(HINTERNET))
295 *buflen = sizeof(HINTERNET);
296 set_last_error( ERROR_INSUFFICIENT_BUFFER );
300 *(HINTERNET *)buffer = ((object_header_t *)connect->session)->handle;
301 *buflen = sizeof(HINTERNET);
304 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
305 *(DWORD *)buffer = connect->session->resolve_timeout;
306 *buflen = sizeof(DWORD);
308 case WINHTTP_OPTION_CONNECT_TIMEOUT:
309 *(DWORD *)buffer = connect->session->connect_timeout;
310 *buflen = sizeof(DWORD);
312 case WINHTTP_OPTION_SEND_TIMEOUT:
313 *(DWORD *)buffer = connect->session->send_timeout;
314 *buflen = sizeof(DWORD);
316 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
317 *(DWORD *)buffer = connect->session->recv_timeout;
318 *buflen = sizeof(DWORD);
321 FIXME("unimplemented option %u\n", option);
322 set_last_error( ERROR_INVALID_PARAMETER );
327 static const object_vtbl_t connect_vtbl =
330 connect_query_option,
334 static BOOL domain_matches(LPCWSTR server, LPCWSTR domain)
336 static const WCHAR localW[] = { '<','l','o','c','a','l','>',0 };
339 if (!strcmpiW( domain, localW ) && !strchrW( server, '.' ))
341 else if (*domain == '*')
343 if (domain[1] == '.')
347 /* For a hostname to match a wildcard, the last domain must match
348 * the wildcard exactly. E.g. if the wildcard is *.a.b, and the
349 * hostname is www.foo.a.b, it matches, but a.b does not.
351 dot = strchrW( server, '.' );
354 int len = strlenW( dot + 1 );
356 if (len > strlenW( domain + 2 ))
360 /* The server's domain is longer than the wildcard, so it
361 * could be a subdomain. Compare the last portion of the
364 ptr = dot + len + 1 - strlenW( domain + 2 );
365 if (!strcmpiW( ptr, domain + 2 ))
367 /* This is only a match if the preceding character is
368 * a '.', i.e. that it is a matching domain. E.g.
369 * if domain is '*.b.c' and server is 'www.ab.c' they
372 ret = *(ptr - 1) == '.';
376 ret = !strcmpiW( dot + 1, domain + 2 );
381 ret = !strcmpiW( server, domain );
385 /* Matches INTERNET_MAX_HOST_NAME_LENGTH in wininet.h, also RFC 1035 */
386 #define MAX_HOST_NAME_LENGTH 256
388 static BOOL should_bypass_proxy(session_t *session, LPCWSTR server)
393 if (!session->proxy_bypass) return FALSE;
394 ptr = session->proxy_bypass;
398 ptr = strchrW( ptr, ';' );
400 ptr = strchrW( tmp, ' ' );
403 if (ptr - tmp < MAX_HOST_NAME_LENGTH)
405 WCHAR domain[MAX_HOST_NAME_LENGTH];
407 memcpy( domain, tmp, (ptr - tmp) * sizeof(WCHAR) );
408 domain[ptr - tmp] = 0;
409 ret = domain_matches( server, domain );
414 ret = domain_matches( server, tmp );
415 } while (ptr && !ret);
419 BOOL set_server_for_hostname( connect_t *connect, LPCWSTR server, INTERNET_PORT port )
421 session_t *session = connect->session;
424 if (session->proxy_server && !should_bypass_proxy(session, server))
428 if ((colon = strchrW( session->proxy_server, ':' )))
430 if (!connect->servername || strncmpiW( connect->servername,
431 session->proxy_server, colon - session->proxy_server - 1 ))
433 heap_free( connect->servername );
434 connect->resolved = FALSE;
435 if (!(connect->servername = heap_alloc(
436 (colon - session->proxy_server + 1) * sizeof(WCHAR) )))
441 memcpy( connect->servername, session->proxy_server,
442 (colon - session->proxy_server) * sizeof(WCHAR) );
443 connect->servername[colon - session->proxy_server] = 0;
445 connect->serverport = atoiW( colon + 1 );
447 connect->serverport = INTERNET_DEFAULT_PORT;
452 if (!connect->servername || strcmpiW( connect->servername,
453 session->proxy_server ))
455 heap_free( connect->servername );
456 connect->resolved = FALSE;
457 if (!(connect->servername = strdupW( session->proxy_server )))
462 connect->serverport = INTERNET_DEFAULT_PORT;
468 heap_free( connect->servername );
469 connect->resolved = FALSE;
470 if (!(connect->servername = strdupW( server )))
475 connect->serverport = port;
481 /***********************************************************************
482 * WinHttpConnect (winhttp.@)
484 HINTERNET WINAPI WinHttpConnect( HINTERNET hsession, LPCWSTR server, INTERNET_PORT port, DWORD reserved )
488 HINTERNET hconnect = NULL;
490 TRACE("%p, %s, %u, %x\n", hsession, debugstr_w(server), port, reserved);
494 set_last_error( ERROR_INVALID_PARAMETER );
497 if (!(session = (session_t *)grab_object( hsession )))
499 set_last_error( ERROR_INVALID_HANDLE );
502 if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
504 release_object( &session->hdr );
505 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
508 if (!(connect = heap_alloc_zero( sizeof(connect_t) )))
510 release_object( &session->hdr );
513 connect->hdr.type = WINHTTP_HANDLE_TYPE_CONNECT;
514 connect->hdr.vtbl = &connect_vtbl;
515 connect->hdr.refs = 1;
516 connect->hdr.flags = session->hdr.flags;
517 connect->hdr.callback = session->hdr.callback;
518 connect->hdr.notify_mask = session->hdr.notify_mask;
519 connect->hdr.context = session->hdr.context;
520 connect->hdr.redirect_policy = session->hdr.redirect_policy;
521 list_init( &connect->hdr.children );
523 addref_object( &session->hdr );
524 connect->session = session;
525 list_add_head( &session->hdr.children, &connect->hdr.entry );
527 if (!(connect->hostname = strdupW( server ))) goto end;
528 connect->hostport = port;
529 if (!set_server_for_hostname( connect, server, port )) goto end;
531 if (!(hconnect = alloc_handle( &connect->hdr ))) goto end;
532 connect->hdr.handle = hconnect;
534 send_callback( &session->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hconnect, sizeof(hconnect) );
537 release_object( &connect->hdr );
538 release_object( &session->hdr );
539 TRACE("returning %p\n", hconnect);
543 /***********************************************************************
544 * request_destroy (internal)
546 static void request_destroy( object_header_t *hdr )
548 request_t *request = (request_t *)hdr;
551 TRACE("%p\n", request);
553 release_object( &request->connect->hdr );
555 heap_free( request->verb );
556 heap_free( request->path );
557 heap_free( request->version );
558 heap_free( request->raw_headers );
559 heap_free( request->status_text );
560 for (i = 0; i < request->num_headers; i++)
562 heap_free( request->headers[i].field );
563 heap_free( request->headers[i].value );
565 heap_free( request->headers );
566 for (i = 0; i < request->num_accept_types; i++) heap_free( request->accept_types[i] );
567 heap_free( request->accept_types );
568 heap_free( request );
571 static void str_to_buffer( WCHAR *buffer, const WCHAR *str, LPDWORD buflen )
574 if (str) len = strlenW( str );
575 if (buffer && *buflen > len)
577 if (str) memcpy( buffer, str, len * sizeof(WCHAR) );
580 *buflen = len * sizeof(WCHAR);
583 static WCHAR *blob_to_str( DWORD encoding, CERT_NAME_BLOB *blob )
586 DWORD size, format = CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG;
588 size = CertNameToStrW( encoding, blob, format, NULL, 0 );
589 if ((ret = LocalAlloc( 0, size * sizeof(WCHAR) )))
590 CertNameToStrW( encoding, blob, format, ret, size );
595 static BOOL convert_sockaddr( const struct sockaddr *addr, SOCKADDR_STORAGE *addr_storage )
598 switch (addr->sa_family)
602 const struct sockaddr_in *addr_unix = (const struct sockaddr_in *)addr;
603 struct WS_sockaddr_in *addr_win = (struct WS_sockaddr_in *)addr_storage;
606 addr_win->sin_family = WS_AF_INET;
607 addr_win->sin_port = addr_unix->sin_port;
608 memcpy( &addr_win->sin_addr, &addr_unix->sin_addr, 4 );
609 p = (char *)&addr_win->sin_addr + 4;
610 memset( p, 0, sizeof(*addr_storage) - (p - (char *)addr_win) );
615 const struct sockaddr_in6 *addr_unix = (const struct sockaddr_in6 *)addr;
616 struct WS_sockaddr_in6 *addr_win = (struct WS_sockaddr_in6 *)addr_storage;
618 addr_win->sin6_family = WS_AF_INET6;
619 addr_win->sin6_port = addr_unix->sin6_port;
620 addr_win->sin6_flowinfo = addr_unix->sin6_flowinfo;
621 memcpy( &addr_win->sin6_addr, &addr_unix->sin6_addr, 16 );
622 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
623 addr_win->sin6_scope_id = addr_unix->sin6_scope_id;
625 addr_win->sin6_scope_id = 0;
627 memset( addr_win + 1, 0, sizeof(*addr_storage) - sizeof(*addr_win) );
631 ERR("unhandled family %u\n", addr->sa_family);
635 switch (addr->sa_family)
639 struct sockaddr_in *addr_in = (struct sockaddr_in *)addr_storage;
641 memcpy( addr_in, addr, sizeof(*addr_in) );
642 memset( addr_in + 1, 0, sizeof(*addr_storage) - sizeof(*addr_in) );
647 struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr_storage;
649 memcpy( addr_in6, addr, sizeof(*addr_in6) );
650 memset( addr_in6 + 1, 0, sizeof(*addr_storage) - sizeof(*addr_in6) );
654 ERR("unhandled family %u\n", addr->sa_family);
660 static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
662 request_t *request = (request_t *)hdr;
666 case WINHTTP_OPTION_SECURITY_FLAGS:
671 if (!buffer || *buflen < sizeof(flags))
673 *buflen = sizeof(flags);
674 set_last_error( ERROR_INSUFFICIENT_BUFFER );
679 if (hdr->flags & WINHTTP_FLAG_SECURE) flags |= SECURITY_FLAG_SECURE;
680 flags |= request->netconn.security_flags;
681 bits = netconn_get_cipher_strength( &request->netconn );
683 flags |= SECURITY_FLAG_STRENGTH_STRONG;
685 flags |= SECURITY_FLAG_STRENGTH_MEDIUM;
687 flags |= SECURITY_FLAG_STRENGTH_WEAK;
688 *(DWORD *)buffer = flags;
689 *buflen = sizeof(flags);
692 case WINHTTP_OPTION_SERVER_CERT_CONTEXT:
694 const CERT_CONTEXT *cert;
696 if (!buffer || *buflen < sizeof(cert))
698 *buflen = sizeof(cert);
699 set_last_error( ERROR_INSUFFICIENT_BUFFER );
703 if (!(cert = netconn_get_certificate( &request->netconn ))) return FALSE;
704 *(CERT_CONTEXT **)buffer = (CERT_CONTEXT *)cert;
705 *buflen = sizeof(cert);
708 case WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT:
710 const CERT_CONTEXT *cert;
711 const CRYPT_OID_INFO *oidInfo;
712 WINHTTP_CERTIFICATE_INFO *ci = buffer;
714 FIXME("partial stub\n");
716 if (!buffer || *buflen < sizeof(*ci))
718 *buflen = sizeof(*ci);
719 set_last_error( ERROR_INSUFFICIENT_BUFFER );
722 if (!(cert = netconn_get_certificate( &request->netconn ))) return FALSE;
724 ci->ftExpiry = cert->pCertInfo->NotAfter;
725 ci->ftStart = cert->pCertInfo->NotBefore;
726 ci->lpszSubjectInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Subject );
727 ci->lpszIssuerInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Issuer );
728 ci->lpszProtocolName = NULL;
729 oidInfo = CryptFindOIDInfo( CRYPT_OID_INFO_OID_KEY,
730 cert->pCertInfo->SignatureAlgorithm.pszObjId,
733 ci->lpszSignatureAlgName = (LPWSTR)oidInfo->pwszName;
735 ci->lpszSignatureAlgName = NULL;
736 ci->lpszEncryptionAlgName = NULL;
737 ci->dwKeySize = netconn_get_cipher_strength( &request->netconn );
739 CertFreeCertificateContext( cert );
740 *buflen = sizeof(*ci);
743 case WINHTTP_OPTION_SECURITY_KEY_BITNESS:
745 if (!buffer || *buflen < sizeof(DWORD))
747 *buflen = sizeof(DWORD);
748 set_last_error( ERROR_INSUFFICIENT_BUFFER );
752 *(DWORD *)buffer = netconn_get_cipher_strength( &request->netconn );
753 *buflen = sizeof(DWORD);
756 case WINHTTP_OPTION_CONNECTION_INFO:
758 WINHTTP_CONNECTION_INFO *info = buffer;
759 struct sockaddr local;
760 socklen_t len = sizeof(local);
761 const struct sockaddr *remote = (const struct sockaddr *)&request->connect->sockaddr;
763 if (!buffer || *buflen < sizeof(*info))
765 *buflen = sizeof(*info);
766 set_last_error( ERROR_INSUFFICIENT_BUFFER );
769 if (!netconn_connected( &request->netconn ))
771 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_STATE );
774 if (getsockname( request->netconn.socket, &local, &len )) return FALSE;
775 if (!convert_sockaddr( &local, &info->LocalAddress )) return FALSE;
776 if (!convert_sockaddr( remote, &info->RemoteAddress )) return FALSE;
777 info->cbSize = sizeof(*info);
780 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
781 *(DWORD *)buffer = request->resolve_timeout;
782 *buflen = sizeof(DWORD);
784 case WINHTTP_OPTION_CONNECT_TIMEOUT:
785 *(DWORD *)buffer = request->connect_timeout;
786 *buflen = sizeof(DWORD);
788 case WINHTTP_OPTION_SEND_TIMEOUT:
789 *(DWORD *)buffer = request->send_timeout;
790 *buflen = sizeof(DWORD);
792 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
793 *(DWORD *)buffer = request->recv_timeout;
794 *buflen = sizeof(DWORD);
797 case WINHTTP_OPTION_USERNAME:
798 str_to_buffer( buffer, request->connect->username, buflen );
801 case WINHTTP_OPTION_PASSWORD:
802 str_to_buffer( buffer, request->connect->password, buflen );
805 case WINHTTP_OPTION_PROXY_USERNAME:
806 str_to_buffer( buffer, request->connect->session->proxy_username, buflen );
809 case WINHTTP_OPTION_PROXY_PASSWORD:
810 str_to_buffer( buffer, request->connect->session->proxy_password, buflen );
814 FIXME("unimplemented option %u\n", option);
815 set_last_error( ERROR_INVALID_PARAMETER );
820 static WCHAR *buffer_to_str( WCHAR *buffer, DWORD buflen )
823 if ((ret = heap_alloc( (buflen + 1) * sizeof(WCHAR))))
825 memcpy( ret, buffer, buflen * sizeof(WCHAR) );
829 set_last_error( ERROR_OUTOFMEMORY );
833 static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
835 request_t *request = (request_t *)hdr;
839 case WINHTTP_OPTION_PROXY:
841 WINHTTP_PROXY_INFO *pi = buffer;
843 FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
846 case WINHTTP_OPTION_DISABLE_FEATURE:
850 if (buflen != sizeof(DWORD))
852 set_last_error( ERROR_INSUFFICIENT_BUFFER );
856 disable = *(DWORD *)buffer;
857 TRACE("0x%x\n", disable);
858 hdr->disable_flags |= disable;
861 case WINHTTP_OPTION_AUTOLOGON_POLICY:
865 if (buflen != sizeof(DWORD))
867 set_last_error( ERROR_INSUFFICIENT_BUFFER );
871 policy = *(DWORD *)buffer;
872 TRACE("0x%x\n", policy);
873 hdr->logon_policy = policy;
876 case WINHTTP_OPTION_REDIRECT_POLICY:
880 if (buflen != sizeof(DWORD))
882 set_last_error( ERROR_INSUFFICIENT_BUFFER );
886 policy = *(DWORD *)buffer;
887 TRACE("0x%x\n", policy);
888 hdr->redirect_policy = policy;
891 case WINHTTP_OPTION_SECURITY_FLAGS:
895 if (buflen < sizeof(DWORD))
897 set_last_error( ERROR_INSUFFICIENT_BUFFER );
900 flags = *(DWORD *)buffer;
901 TRACE("0x%x\n", flags);
902 if (!(flags & (SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
903 SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
904 SECURITY_FLAG_IGNORE_UNKNOWN_CA |
905 SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE)))
907 set_last_error( ERROR_INVALID_PARAMETER );
910 request->netconn.security_flags = flags;
913 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
914 request->resolve_timeout = *(DWORD *)buffer;
916 case WINHTTP_OPTION_CONNECT_TIMEOUT:
917 request->connect_timeout = *(DWORD *)buffer;
919 case WINHTTP_OPTION_SEND_TIMEOUT:
920 request->send_timeout = *(DWORD *)buffer;
922 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
923 request->recv_timeout = *(DWORD *)buffer;
926 case WINHTTP_OPTION_USERNAME:
928 connect_t *connect = request->connect;
930 heap_free( connect->username );
931 if (!(connect->username = buffer_to_str( buffer, buflen ))) return FALSE;
934 case WINHTTP_OPTION_PASSWORD:
936 connect_t *connect = request->connect;
938 heap_free( connect->password );
939 if (!(connect->password = buffer_to_str( buffer, buflen ))) return FALSE;
942 case WINHTTP_OPTION_PROXY_USERNAME:
944 session_t *session = request->connect->session;
946 heap_free( session->proxy_username );
947 if (!(session->proxy_username = buffer_to_str( buffer, buflen ))) return FALSE;
950 case WINHTTP_OPTION_PROXY_PASSWORD:
952 session_t *session = request->connect->session;
954 heap_free( session->proxy_password );
955 if (!(session->proxy_password = buffer_to_str( buffer, buflen ))) return FALSE;
959 FIXME("unimplemented option %u\n", option);
960 set_last_error( ERROR_INVALID_PARAMETER );
965 static const object_vtbl_t request_vtbl =
968 request_query_option,
972 static BOOL store_accept_types( request_t *request, const WCHAR **accept_types )
974 const WCHAR **types = accept_types;
977 if (!types) return TRUE;
980 request->num_accept_types++;
983 if (!request->num_accept_types) return TRUE;
984 if (!(request->accept_types = heap_alloc( request->num_accept_types * sizeof(WCHAR *))))
986 request->num_accept_types = 0;
989 types = accept_types;
990 for (i = 0; i < request->num_accept_types; i++)
992 if (!(request->accept_types[i] = strdupW( *types )))
994 for ( ; i > 0; --i) heap_free( request->accept_types[i - 1] );
995 heap_free( request->accept_types );
996 request->accept_types = NULL;
997 request->num_accept_types = 0;
1005 /***********************************************************************
1006 * WinHttpOpenRequest (winhttp.@)
1008 HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR object, LPCWSTR version,
1009 LPCWSTR referrer, LPCWSTR *types, DWORD flags )
1013 HINTERNET hrequest = NULL;
1015 TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect, debugstr_w(verb), debugstr_w(object),
1016 debugstr_w(version), debugstr_w(referrer), types, flags);
1018 if(types && TRACE_ON(winhttp)) {
1021 TRACE("accept types:\n");
1022 for(iter = types; *iter; iter++)
1023 TRACE(" %s\n", debugstr_w(*iter));
1026 if (!(connect = (connect_t *)grab_object( hconnect )))
1028 set_last_error( ERROR_INVALID_HANDLE );
1031 if (connect->hdr.type != WINHTTP_HANDLE_TYPE_CONNECT)
1033 release_object( &connect->hdr );
1034 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1037 if (!(request = heap_alloc_zero( sizeof(request_t) )))
1039 release_object( &connect->hdr );
1042 request->hdr.type = WINHTTP_HANDLE_TYPE_REQUEST;
1043 request->hdr.vtbl = &request_vtbl;
1044 request->hdr.refs = 1;
1045 request->hdr.flags = flags;
1046 request->hdr.callback = connect->hdr.callback;
1047 request->hdr.notify_mask = connect->hdr.notify_mask;
1048 request->hdr.context = connect->hdr.context;
1049 request->hdr.redirect_policy = connect->hdr.redirect_policy;
1050 list_init( &request->hdr.children );
1052 addref_object( &connect->hdr );
1053 request->connect = connect;
1054 list_add_head( &connect->hdr.children, &request->hdr.entry );
1056 if (!netconn_init( &request->netconn )) goto end;
1057 request->resolve_timeout = connect->session->resolve_timeout;
1058 request->connect_timeout = connect->session->connect_timeout;
1059 request->send_timeout = connect->session->send_timeout;
1060 request->recv_timeout = connect->session->recv_timeout;
1062 if (!verb || !verb[0]) verb = getW;
1063 if (!(request->verb = strdupW( verb ))) goto end;
1070 len = strlenW( object ) + 1;
1071 if (object[0] != '/') len++;
1072 if (!(p = path = heap_alloc( len * sizeof(WCHAR) ))) goto end;
1074 if (object[0] != '/') *p++ = '/';
1075 strcpyW( p, object );
1076 request->path = path;
1078 else if (!(request->path = strdupW( slashW ))) goto end;
1080 if (!version || !version[0]) version = http1_1;
1081 if (!(request->version = strdupW( version ))) goto end;
1082 if (!(store_accept_types( request, types ))) goto end;
1084 if (!(hrequest = alloc_handle( &request->hdr ))) goto end;
1085 request->hdr.handle = hrequest;
1087 send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hrequest, sizeof(hrequest) );
1090 release_object( &request->hdr );
1091 release_object( &connect->hdr );
1092 TRACE("returning %p\n", hrequest);
1096 /***********************************************************************
1097 * WinHttpCloseHandle (winhttp.@)
1099 BOOL WINAPI WinHttpCloseHandle( HINTERNET handle )
1101 object_header_t *hdr;
1103 TRACE("%p\n", handle);
1105 if (!(hdr = grab_object( handle )))
1107 set_last_error( ERROR_INVALID_HANDLE );
1110 release_object( hdr );
1111 free_handle( handle );
1115 static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
1121 set_last_error( ERROR_INVALID_PARAMETER );
1127 case WINHTTP_OPTION_CONTEXT_VALUE:
1129 if (!buffer || *buflen < sizeof(DWORD_PTR))
1131 *buflen = sizeof(DWORD_PTR);
1132 set_last_error( ERROR_INSUFFICIENT_BUFFER );
1136 *(DWORD_PTR *)buffer = hdr->context;
1137 *buflen = sizeof(DWORD_PTR);
1141 if (hdr->vtbl->query_option) ret = hdr->vtbl->query_option( hdr, option, buffer, buflen );
1144 FIXME("unimplemented option %u\n", option);
1145 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1153 /***********************************************************************
1154 * WinHttpQueryOption (winhttp.@)
1156 BOOL WINAPI WinHttpQueryOption( HINTERNET handle, DWORD option, LPVOID buffer, LPDWORD buflen )
1159 object_header_t *hdr;
1161 TRACE("%p, %u, %p, %p\n", handle, option, buffer, buflen);
1163 if (!(hdr = grab_object( handle )))
1165 set_last_error( ERROR_INVALID_HANDLE );
1169 ret = query_option( hdr, option, buffer, buflen );
1171 release_object( hdr );
1175 static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
1181 set_last_error( ERROR_INVALID_PARAMETER );
1187 case WINHTTP_OPTION_CONTEXT_VALUE:
1189 if (buflen != sizeof(DWORD_PTR))
1191 set_last_error( ERROR_INSUFFICIENT_BUFFER );
1195 hdr->context = *(DWORD_PTR *)buffer;
1199 if (hdr->vtbl->set_option) ret = hdr->vtbl->set_option( hdr, option, buffer, buflen );
1202 FIXME("unimplemented option %u\n", option);
1203 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1211 /***********************************************************************
1212 * WinHttpSetOption (winhttp.@)
1214 BOOL WINAPI WinHttpSetOption( HINTERNET handle, DWORD option, LPVOID buffer, DWORD buflen )
1217 object_header_t *hdr;
1219 TRACE("%p, %u, %p, %u\n", handle, option, buffer, buflen);
1221 if (!(hdr = grab_object( handle )))
1223 set_last_error( ERROR_INVALID_HANDLE );
1227 ret = set_option( hdr, option, buffer, buflen );
1229 release_object( hdr );
1233 static char *get_computer_name( COMPUTER_NAME_FORMAT format )
1238 GetComputerNameExA( format, NULL, &size );
1239 if (GetLastError() != ERROR_MORE_DATA) return NULL;
1240 if (!(ret = heap_alloc( size ))) return NULL;
1241 if (!GetComputerNameExA( format, ret, &size ))
1249 static BOOL is_domain_suffix( const char *domain, const char *suffix )
1251 int len_domain = strlen( domain ), len_suffix = strlen( suffix );
1253 if (len_suffix > len_domain) return FALSE;
1254 if (!strcasecmp( domain + len_domain - len_suffix, suffix )) return TRUE;
1258 static void printf_addr( const WCHAR *fmt, WCHAR *buf, struct sockaddr_in *addr )
1261 (unsigned int)(ntohl( addr->sin_addr.s_addr ) >> 24 & 0xff),
1262 (unsigned int)(ntohl( addr->sin_addr.s_addr ) >> 16 & 0xff),
1263 (unsigned int)(ntohl( addr->sin_addr.s_addr ) >> 8 & 0xff),
1264 (unsigned int)(ntohl( addr->sin_addr.s_addr ) & 0xff) );
1267 static int reverse_lookup( const struct addrinfo *ai, char *hostname, size_t len )
1270 #ifdef HAVE_GETNAMEINFO
1271 ret = getnameinfo( ai->ai_addr, ai->ai_addrlen, hostname, len, NULL, 0, 0 );
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];
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 );
1298 /***********************************************************************
1299 * WinHttpDetectAutoProxyConfigUrl (winhttp.@)
1301 BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url )
1305 TRACE("0x%08x, %p\n", flags, url);
1309 set_last_error( ERROR_INVALID_PARAMETER );
1312 if (flags & WINHTTP_AUTO_DETECT_TYPE_DHCP)
1314 static int fixme_shown;
1315 if (!fixme_shown++) FIXME("discovery via DHCP not supported\n");
1317 if (flags & WINHTTP_AUTO_DETECT_TYPE_DNS_A)
1319 #ifdef HAVE_GETADDRINFO
1320 char *fqdn, *domain, *p;
1322 if (!(fqdn = get_computer_name( ComputerNamePhysicalDnsFullyQualified ))) return FALSE;
1323 if (!(domain = get_computer_name( ComputerNamePhysicalDnsDomain )))
1329 while ((p = strchr( p, '.' )) && is_domain_suffix( p + 1, domain ))
1331 struct addrinfo *ai;
1335 if (!(name = heap_alloc( sizeof("wpad") + strlen(p) )))
1338 heap_free( domain );
1341 strcpy( name, "wpad" );
1343 res = getaddrinfo( name, NULL, NULL, &ai );
1346 *url = build_wpad_url( name, ai );
1350 TRACE("returning %s\n", debugstr_w(*url));
1359 heap_free( domain );
1362 FIXME("getaddrinfo not found at build time\n");
1365 if (!ret) set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED );
1369 static const WCHAR Connections[] = {
1370 'S','o','f','t','w','a','r','e','\\',
1371 'M','i','c','r','o','s','o','f','t','\\',
1372 'W','i','n','d','o','w','s','\\',
1373 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1374 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
1375 'C','o','n','n','e','c','t','i','o','n','s',0 };
1376 static const WCHAR WinHttpSettings[] = {
1377 'W','i','n','H','t','t','p','S','e','t','t','i','n','g','s',0 };
1378 static const DWORD WINHTTP_SETTINGS_MAGIC = 0x18;
1379 static const DWORD WININET_SETTINGS_MAGIC = 0x46;
1380 static const DWORD PROXY_TYPE_DIRECT = 1;
1381 static const DWORD PROXY_TYPE_PROXY = 2;
1382 static const DWORD PROXY_USE_PAC_SCRIPT = 4;
1383 static const DWORD PROXY_AUTODETECT_SETTINGS = 8;
1385 struct connection_settings_header
1388 DWORD unknown; /* always zero? */
1389 DWORD flags; /* one or more of PROXY_* */
1392 static inline void copy_char_to_wchar_sz(const BYTE *src, DWORD len, WCHAR *dst)
1396 for (begin = src; src - begin < len; src++, dst++)
1401 /***********************************************************************
1402 * WinHttpGetDefaultProxyConfiguration (winhttp.@)
1404 BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
1408 BOOL got_from_reg = FALSE, direct = TRUE;
1411 TRACE("%p\n", info);
1413 l = RegOpenKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, KEY_READ, &key );
1416 DWORD type, size = 0;
1418 l = RegQueryValueExW( key, WinHttpSettings, NULL, &type, NULL, &size );
1419 if (!l && type == REG_BINARY &&
1420 size >= sizeof(struct connection_settings_header) + 2 * sizeof(DWORD))
1422 BYTE *buf = heap_alloc( size );
1426 struct connection_settings_header *hdr =
1427 (struct connection_settings_header *)buf;
1428 DWORD *len = (DWORD *)(hdr + 1);
1430 l = RegQueryValueExW( key, WinHttpSettings, NULL, NULL, buf,
1432 if (!l && hdr->magic == WINHTTP_SETTINGS_MAGIC &&
1435 if (hdr->flags & PROXY_TYPE_PROXY)
1438 LPWSTR proxy = NULL;
1439 LPWSTR proxy_bypass = NULL;
1441 /* Sanity-check length of proxy string */
1442 if ((BYTE *)len - buf + *len <= size)
1445 proxy = GlobalAlloc( 0, (*len + 1) * sizeof(WCHAR) );
1447 copy_char_to_wchar_sz( (BYTE *)(len + 1), *len, proxy );
1448 len = (DWORD *)((BYTE *)(len + 1) + *len);
1452 /* Sanity-check length of proxy bypass string */
1453 if ((BYTE *)len - buf + *len <= size)
1455 proxy_bypass = GlobalAlloc( 0, (*len + 1) * sizeof(WCHAR) );
1457 copy_char_to_wchar_sz( (BYTE *)(len + 1), *len, proxy_bypass );
1462 GlobalFree( proxy );
1466 info->lpszProxy = proxy;
1467 info->lpszProxyBypass = proxy_bypass;
1470 got_from_reg = TRUE;
1472 info->dwAccessType =
1473 WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1474 TRACE("http proxy (from registry) = %s, bypass = %s\n",
1475 debugstr_w(info->lpszProxy),
1476 debugstr_w(info->lpszProxyBypass));
1485 if (!got_from_reg && (envproxy = getenv( "http_proxy" )))
1487 char *colon, *http_proxy;
1489 if ((colon = strchr( envproxy, ':' )))
1491 if (*(colon + 1) == '/' && *(colon + 2) == '/')
1493 static const char http[] = "http://";
1495 /* It's a scheme, check that it's http */
1496 if (!strncmp( envproxy, http, strlen( http ) ))
1497 http_proxy = envproxy + strlen( http );
1500 WARN("unsupported scheme in $http_proxy: %s\n", envproxy);
1505 http_proxy = envproxy;
1508 http_proxy = envproxy;
1514 len = MultiByteToWideChar( CP_UNIXCP, 0, http_proxy, -1, NULL, 0 );
1515 if ((http_proxyW = GlobalAlloc( 0, len * sizeof(WCHAR))))
1517 MultiByteToWideChar( CP_UNIXCP, 0, http_proxy, -1, http_proxyW, len );
1519 info->dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1520 info->lpszProxy = http_proxyW;
1521 info->lpszProxyBypass = NULL;
1522 TRACE("http proxy (from environment) = %s\n",
1523 debugstr_w(info->lpszProxy));
1529 info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
1530 info->lpszProxy = NULL;
1531 info->lpszProxyBypass = NULL;
1536 /***********************************************************************
1537 * WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
1539 BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *config )
1541 static const WCHAR settingsW[] =
1542 {'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};
1544 struct connection_settings_header *hdr = NULL;
1545 DWORD type, offset, len, size = 0;
1548 TRACE("%p\n", config);
1552 set_last_error( ERROR_INVALID_PARAMETER );
1555 memset( config, 0, sizeof(*config) );
1556 config->fAutoDetect = TRUE;
1558 if (RegOpenKeyExW( HKEY_CURRENT_USER, Connections, 0, KEY_READ, &hkey ) ||
1559 RegQueryValueExW( hkey, settingsW, NULL, &type, NULL, &size ) ||
1560 type != REG_BINARY || size < sizeof(struct connection_settings_header))
1565 if (!(hdr = heap_alloc( size ))) goto done;
1566 if (RegQueryValueExW( hkey, settingsW, NULL, &type, (BYTE *)hdr, &size ) ||
1567 hdr->magic != WININET_SETTINGS_MAGIC)
1573 config->fAutoDetect = (hdr->flags & PROXY_AUTODETECT_SETTINGS) != 0;
1574 offset = sizeof(*hdr);
1575 if (offset + sizeof(DWORD) > size) goto done;
1576 len = *(DWORD *)((char *)hdr + offset);
1577 offset += sizeof(DWORD);
1578 if (len && hdr->flags & PROXY_TYPE_PROXY)
1580 if (!(config->lpszProxy = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
1581 copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszProxy );
1584 if (offset + sizeof(DWORD) > size) goto done;
1585 len = *(DWORD *)((char *)hdr + offset);
1586 offset += sizeof(DWORD);
1587 if (len && (hdr->flags & PROXY_TYPE_PROXY))
1589 if (!(config->lpszProxyBypass = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
1590 copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszProxyBypass );
1593 if (offset + sizeof(DWORD) > size) goto done;
1594 len = *(DWORD *)((char *)hdr + offset);
1595 offset += sizeof(DWORD);
1596 if (len && (hdr->flags & PROXY_USE_PAC_SCRIPT))
1598 if (!(config->lpszAutoConfigUrl = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
1599 copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszAutoConfigUrl );
1604 RegCloseKey( hkey );
1608 heap_free( config->lpszAutoConfigUrl );
1609 config->lpszAutoConfigUrl = NULL;
1610 heap_free( config->lpszProxy );
1611 config->lpszProxy = NULL;
1612 heap_free( config->lpszProxyBypass );
1613 config->lpszProxyBypass = NULL;
1618 static HRESULT WINAPI dispex_QueryInterface(
1619 IDispatchEx *iface, REFIID riid, void **ppv )
1623 if (IsEqualGUID( riid, &IID_IUnknown ) ||
1624 IsEqualGUID( riid, &IID_IDispatch ) ||
1625 IsEqualGUID( riid, &IID_IDispatchEx ))
1628 return E_NOINTERFACE;
1633 static ULONG WINAPI dispex_AddRef(
1634 IDispatchEx *iface )
1639 static ULONG WINAPI dispex_Release(
1640 IDispatchEx *iface )
1645 static HRESULT WINAPI dispex_GetTypeInfoCount(
1646 IDispatchEx *iface, UINT *info )
1651 static HRESULT WINAPI dispex_GetTypeInfo(
1652 IDispatchEx *iface, UINT info, LCID lcid, ITypeInfo **type_info )
1657 static HRESULT WINAPI dispex_GetIDsOfNames(
1658 IDispatchEx *iface, REFIID riid, LPOLESTR *names, UINT count, LCID lcid, DISPID *id )
1663 static HRESULT WINAPI dispex_Invoke(
1664 IDispatchEx *iface, DISPID member, REFIID riid, LCID lcid, WORD flags,
1665 DISPPARAMS *params, VARIANT *result, EXCEPINFO *excep, UINT *err )
1670 static HRESULT WINAPI dispex_DeleteMemberByName(
1671 IDispatchEx *iface, BSTR name, DWORD flags )
1676 static HRESULT WINAPI dispex_DeleteMemberByDispID(
1677 IDispatchEx *iface, DISPID id )
1682 static HRESULT WINAPI dispex_GetMemberProperties(
1683 IDispatchEx *iface, DISPID id, DWORD flags_fetch, DWORD *flags )
1688 static HRESULT WINAPI dispex_GetMemberName(
1689 IDispatchEx *iface, DISPID id, BSTR *name )
1694 static HRESULT WINAPI dispex_GetNextDispID(
1695 IDispatchEx *iface, DWORD flags, DISPID id, DISPID *next )
1700 static HRESULT WINAPI dispex_GetNameSpaceParent(
1701 IDispatchEx *iface, IUnknown **unk )
1706 #define DISPID_GLOBAL_DNSRESOLVE 0x1000
1708 static HRESULT WINAPI dispex_GetDispID(
1709 IDispatchEx *iface, BSTR name, DWORD flags, DISPID *id )
1711 if (!strcmpW( name, dns_resolveW ))
1713 *id = DISPID_GLOBAL_DNSRESOLVE;
1716 return DISP_E_UNKNOWNNAME;
1719 static HRESULT dns_resolve( const WCHAR *hostname, VARIANT *result )
1721 #ifdef HAVE_GETADDRINFO
1722 static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1724 struct addrinfo *ai, *elem;
1729 hostnameA = strdupWA( hostname );
1731 hostnameA = get_computer_name( ComputerNamePhysicalDnsFullyQualified );
1733 if (!hostnameA) return E_OUTOFMEMORY;
1734 res = getaddrinfo( hostnameA, NULL, NULL, &ai );
1735 heap_free( hostnameA );
1736 if (res) return S_FALSE;
1739 while (elem && elem->ai_family != AF_INET) elem = elem->ai_next;
1745 printf_addr( fmtW, addr, (struct sockaddr_in *)elem->ai_addr );
1747 V_VT( result ) = VT_BSTR;
1748 V_BSTR( result ) = SysAllocString( addr );
1751 FIXME("getaddrinfo not found at build time\n");
1756 static HRESULT WINAPI dispex_InvokeEx(
1757 IDispatchEx *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1758 VARIANT *result, EXCEPINFO *exep, IServiceProvider *caller )
1760 if (id == DISPID_GLOBAL_DNSRESOLVE)
1762 if (params->cArgs != 1) return DISP_E_BADPARAMCOUNT;
1763 if (V_VT(¶ms->rgvarg[0]) != VT_BSTR) return DISP_E_BADVARTYPE;
1764 return dns_resolve( V_BSTR(¶ms->rgvarg[0]), result );
1766 return DISP_E_MEMBERNOTFOUND;
1769 static const IDispatchExVtbl dispex_vtbl =
1771 dispex_QueryInterface,
1774 dispex_GetTypeInfoCount,
1776 dispex_GetIDsOfNames,
1780 dispex_DeleteMemberByName,
1781 dispex_DeleteMemberByDispID,
1782 dispex_GetMemberProperties,
1783 dispex_GetMemberName,
1784 dispex_GetNextDispID,
1785 dispex_GetNameSpaceParent
1788 static IDispatchEx global_dispex = { &dispex_vtbl };
1790 static HRESULT WINAPI site_QueryInterface(
1791 IActiveScriptSite *iface, REFIID riid, void **ppv )
1795 if (IsEqualGUID( &IID_IUnknown, riid ))
1797 else if (IsEqualGUID( &IID_IActiveScriptSite, riid ))
1800 return E_NOINTERFACE;
1802 IUnknown_AddRef( (IUnknown *)*ppv );
1806 static ULONG WINAPI site_AddRef(
1807 IActiveScriptSite *iface )
1812 static ULONG WINAPI site_Release(
1813 IActiveScriptSite *iface )
1818 static HRESULT WINAPI site_GetLCID(
1819 IActiveScriptSite *iface, LCID *lcid )
1824 static HRESULT WINAPI site_GetItemInfo(
1825 IActiveScriptSite *iface, LPCOLESTR name, DWORD mask,
1826 IUnknown **item, ITypeInfo **type_info )
1828 if (!strcmpW( name, global_funcsW ) && mask == SCRIPTINFO_IUNKNOWN)
1830 *item = (IUnknown *)&global_dispex;
1836 static HRESULT WINAPI site_GetDocVersionString(
1837 IActiveScriptSite *iface, BSTR *version )
1842 static HRESULT WINAPI site_OnScriptTerminate(
1843 IActiveScriptSite *iface, const VARIANT *result, const EXCEPINFO *info )
1848 static HRESULT WINAPI site_OnStateChange(
1849 IActiveScriptSite *iface, SCRIPTSTATE state )
1854 static HRESULT WINAPI site_OnScriptError(
1855 IActiveScriptSite *iface, IActiveScriptError *error )
1860 static HRESULT WINAPI site_OnEnterScript(
1861 IActiveScriptSite *iface )
1866 static HRESULT WINAPI site_OnLeaveScript(
1867 IActiveScriptSite *iface )
1872 static const IActiveScriptSiteVtbl site_vtbl =
1874 site_QueryInterface,
1879 site_GetDocVersionString,
1880 site_OnScriptTerminate,
1887 static IActiveScriptSite script_site = { &site_vtbl };
1889 static BOOL parse_script_result( VARIANT result, WINHTTP_PROXY_INFO *info )
1891 static const WCHAR proxyW[] = {'P','R','O','X','Y'};
1896 info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
1897 info->lpszProxy = NULL;
1898 info->lpszProxyBypass = NULL;
1900 if (V_VT( &result ) != VT_BSTR) return TRUE;
1901 TRACE("%s\n", debugstr_w( V_BSTR( &result ) ));
1903 p = V_BSTR( &result );
1904 while (*p == ' ') p++;
1906 if (len >= 5 && !memicmpW( p, proxyW, sizeof(proxyW)/sizeof(WCHAR) ))
1909 while (*p == ' ') p++;
1910 if (!*p || *p == ';') return TRUE;
1911 if (!(info->lpszProxy = q = strdupW( p ))) return FALSE;
1912 info->dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1915 if (*q == ' ' || *q == ';')
1925 static BSTR include_pac_utils( BSTR script )
1927 static const WCHAR pacjsW[] = {'p','a','c','.','j','s',0};
1928 HMODULE hmod = GetModuleHandleA( "winhttp.dll" );
1935 if (!(rsrc = FindResourceW( hmod, pacjsW, (LPCWSTR)40 ))) return NULL;
1936 size = SizeofResource( hmod, rsrc );
1937 data = LoadResource( hmod, rsrc );
1939 len = MultiByteToWideChar( CP_ACP, 0, data, size, NULL, 0 );
1940 if (!(ret = SysAllocStringLen( NULL, len + SysStringLen( script ) + 1 ))) return NULL;
1941 MultiByteToWideChar( CP_ACP, 0, data, size, ret, len );
1943 strcatW( ret, script );
1948 #define IActiveScriptParse_Release IActiveScriptParse64_Release
1949 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
1950 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
1952 #define IActiveScriptParse_Release IActiveScriptParse32_Release
1953 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
1954 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
1957 static BOOL run_script( const BSTR script, const WCHAR *url, WINHTTP_PROXY_INFO *info )
1959 static const WCHAR jscriptW[] = {'J','S','c','r','i','p','t',0};
1960 static const WCHAR findproxyW[] = {'F','i','n','d','P','r','o','x','y','F','o','r','U','R','L',0};
1961 IActiveScriptParse *parser = NULL;
1962 IActiveScript *engine = NULL;
1963 IDispatch *dispatch = NULL;
1967 BSTR func = NULL, hostname = NULL, full_script = NULL;
1969 VARIANT args[2], result;
1973 memset( &uc, 0, sizeof(uc) );
1974 uc.dwStructSize = sizeof(uc);
1975 if (!WinHttpCrackUrl( url, 0, 0, &uc )) return FALSE;
1976 if (!(hostname = SysAllocStringLen( NULL, uc.dwHostNameLength + 1 ))) return FALSE;
1977 memcpy( hostname, uc.lpszHostName, uc.dwHostNameLength * sizeof(WCHAR) );
1978 hostname[uc.dwHostNameLength] = 0;
1980 init = CoInitialize( NULL );
1981 hr = CLSIDFromProgID( jscriptW, &clsid );
1982 if (hr != S_OK) goto done;
1984 hr = CoCreateInstance( &clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1985 &IID_IActiveScript, (void **)&engine );
1986 if (hr != S_OK) goto done;
1988 hr = IActiveScript_QueryInterface( engine, &IID_IActiveScriptParse, (void **)&parser );
1989 if (hr != S_OK) goto done;
1991 hr = IActiveScriptParse_InitNew( parser );
1992 if (hr != S_OK) goto done;
1994 hr = IActiveScript_SetScriptSite( engine, &script_site );
1995 if (hr != S_OK) goto done;
1997 hr = IActiveScript_AddNamedItem( engine, global_funcsW, SCRIPTITEM_GLOBALMEMBERS );
1998 if (hr != S_OK) goto done;
2000 if (!(full_script = include_pac_utils( script ))) goto done;
2002 hr = IActiveScriptParse_ParseScriptText( parser, full_script, NULL, NULL, NULL, 0, 0, 0, NULL, NULL );
2003 if (hr != S_OK) goto done;
2005 hr = IActiveScript_SetScriptState( engine, SCRIPTSTATE_STARTED );
2006 if (hr != S_OK) goto done;
2008 hr = IActiveScript_GetScriptDispatch( engine, NULL, &dispatch );
2009 if (hr != S_OK) goto done;
2011 if (!(func = SysAllocString( findproxyW ))) goto done;
2012 hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &func, 1, LOCALE_SYSTEM_DEFAULT, &dispid );
2013 if (hr != S_OK) goto done;
2015 V_VT( &args[0] ) = VT_BSTR;
2016 V_BSTR( &args[0] ) = hostname;
2017 V_VT( &args[1] ) = VT_BSTR;
2018 V_BSTR( &args[1] ) = SysAllocString( url );
2020 params.rgvarg = args;
2021 params.rgdispidNamedArgs = NULL;
2023 params.cNamedArgs = 0;
2024 hr = IDispatch_Invoke( dispatch, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD,
2025 ¶ms, &result, NULL, NULL );
2026 VariantClear( &args[1] );
2029 WARN("script failed 0x%08x\n", hr);
2032 ret = parse_script_result( result, info );
2035 SysFreeString( full_script );
2036 SysFreeString( hostname );
2037 SysFreeString( func );
2038 if (dispatch) IDispatch_Release( dispatch );
2039 if (parser) IActiveScriptParse_Release( parser );
2040 if (engine) IActiveScript_Release( engine );
2041 if (SUCCEEDED( init )) CoUninitialize();
2042 if (!ret) set_last_error( ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT );
2046 static BSTR download_script( const WCHAR *url )
2048 static const WCHAR typeW[] = {'*','/','*',0};
2049 static const WCHAR *acceptW[] = {typeW, NULL};
2050 HINTERNET ses, con = NULL, req = NULL;
2053 DWORD status, size = sizeof(status), offset, to_read, bytes_read, flags = 0;
2054 char *tmp, *buffer = NULL;
2058 memset( &uc, 0, sizeof(uc) );
2059 uc.dwStructSize = sizeof(uc);
2060 if (!WinHttpCrackUrl( url, 0, 0, &uc )) return NULL;
2061 if (!(hostname = heap_alloc( (uc.dwHostNameLength + 1) * sizeof(WCHAR) ))) return NULL;
2062 memcpy( hostname, uc.lpszHostName, uc.dwHostNameLength * sizeof(WCHAR) );
2063 hostname[uc.dwHostNameLength] = 0;
2065 if (!(ses = WinHttpOpen( NULL, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0 ))) goto done;
2066 if (!(con = WinHttpConnect( ses, hostname, uc.nPort, 0 ))) goto done;
2067 if (uc.nScheme == INTERNET_SCHEME_HTTPS) flags |= WINHTTP_FLAG_SECURE;
2068 if (!(req = WinHttpOpenRequest( con, NULL, uc.lpszUrlPath, NULL, NULL, acceptW, flags ))) goto done;
2069 if (!WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 )) goto done;
2071 if (!(WinHttpReceiveResponse( req, 0 ))) goto done;
2072 if (!WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status,
2073 &size, NULL ) || status != HTTP_STATUS_OK) goto done;
2076 if (!(buffer = heap_alloc( size ))) goto done;
2081 if (!WinHttpReadData( req, buffer + offset, to_read, &bytes_read )) goto done;
2082 if (!bytes_read) break;
2083 to_read -= bytes_read;
2084 offset += bytes_read;
2089 if (!(tmp = heap_realloc( buffer, size ))) goto done;
2093 len = MultiByteToWideChar( CP_ACP, 0, buffer, offset, NULL, 0 );
2094 if (!(script = SysAllocStringLen( NULL, len ))) goto done;
2095 MultiByteToWideChar( CP_ACP, 0, buffer, offset, script, len );
2099 WinHttpCloseHandle( req );
2100 WinHttpCloseHandle( con );
2101 WinHttpCloseHandle( ses );
2102 heap_free( buffer );
2103 heap_free( hostname );
2104 if (!script) set_last_error( ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT );
2108 /***********************************************************************
2109 * WinHttpGetProxyForUrl (winhttp.@)
2111 BOOL WINAPI WinHttpGetProxyForUrl( HINTERNET hsession, LPCWSTR url, WINHTTP_AUTOPROXY_OPTIONS *options,
2112 WINHTTP_PROXY_INFO *info )
2114 WCHAR *detected_pac_url = NULL;
2115 const WCHAR *pac_url;
2120 TRACE("%p, %s, %p, %p\n", hsession, debugstr_w(url), options, info);
2122 if (!(session = (session_t *)grab_object( hsession )))
2124 set_last_error( ERROR_INVALID_HANDLE );
2127 if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
2129 release_object( &session->hdr );
2130 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
2133 if (!url || !options || !info ||
2134 !(options->dwFlags & (WINHTTP_AUTOPROXY_AUTO_DETECT|WINHTTP_AUTOPROXY_CONFIG_URL)) ||
2135 ((options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT) && !options->dwAutoDetectFlags) ||
2136 ((options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT) &&
2137 (options->dwFlags & WINHTTP_AUTOPROXY_CONFIG_URL)))
2139 release_object( &session->hdr );
2140 set_last_error( ERROR_INVALID_PARAMETER );
2143 if (options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT &&
2144 !WinHttpDetectAutoProxyConfigUrl( options->dwAutoDetectFlags, &detected_pac_url ))
2147 if (options->dwFlags & WINHTTP_AUTOPROXY_CONFIG_URL) pac_url = options->lpszAutoConfigUrl;
2148 else pac_url = detected_pac_url;
2150 if (!(script = download_script( pac_url ))) goto done;
2151 ret = run_script( script, url, info );
2152 SysFreeString( script );
2155 GlobalFree( detected_pac_url );
2156 release_object( &session->hdr );
2160 /***********************************************************************
2161 * WinHttpSetDefaultProxyConfiguration (winhttp.@)
2163 BOOL WINAPI WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
2170 TRACE("%p\n", info);
2174 set_last_error( ERROR_INVALID_PARAMETER );
2177 switch (info->dwAccessType)
2179 case WINHTTP_ACCESS_TYPE_NO_PROXY:
2181 case WINHTTP_ACCESS_TYPE_NAMED_PROXY:
2182 if (!info->lpszProxy)
2184 set_last_error( ERROR_INVALID_PARAMETER );
2187 /* Only ASCII characters are allowed */
2188 for (src = info->lpszProxy; *src; src++)
2191 set_last_error( ERROR_INVALID_PARAMETER );
2194 if (info->lpszProxyBypass)
2196 for (src = info->lpszProxyBypass; *src; src++)
2199 set_last_error( ERROR_INVALID_PARAMETER );
2205 set_last_error( ERROR_INVALID_PARAMETER );
2209 l = RegCreateKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, NULL, 0,
2210 KEY_WRITE, NULL, &key, NULL );
2213 DWORD size = sizeof(struct connection_settings_header) + 2 * sizeof(DWORD);
2216 if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
2218 size += strlenW( info->lpszProxy );
2219 if (info->lpszProxyBypass)
2220 size += strlenW( info->lpszProxyBypass );
2222 buf = heap_alloc( size );
2225 struct connection_settings_header *hdr =
2226 (struct connection_settings_header *)buf;
2227 DWORD *len = (DWORD *)(hdr + 1);
2229 hdr->magic = WINHTTP_SETTINGS_MAGIC;
2231 if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
2235 hdr->flags = PROXY_TYPE_PROXY;
2236 *len++ = strlenW( info->lpszProxy );
2237 for (dst = (BYTE *)len, src = info->lpszProxy; *src;
2241 if (info->lpszProxyBypass)
2243 *len++ = strlenW( info->lpszProxyBypass );
2244 for (dst = (BYTE *)len, src = info->lpszProxyBypass; *src;
2253 hdr->flags = PROXY_TYPE_DIRECT;
2257 l = RegSetValueExW( key, WinHttpSettings, 0, REG_BINARY, buf, size );
2267 /***********************************************************************
2268 * WinHttpSetStatusCallback (winhttp.@)
2270 WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback( HINTERNET handle, WINHTTP_STATUS_CALLBACK callback,
2271 DWORD flags, DWORD_PTR reserved )
2273 object_header_t *hdr;
2274 WINHTTP_STATUS_CALLBACK ret;
2276 TRACE("%p, %p, 0x%08x, 0x%lx\n", handle, callback, flags, reserved);
2278 if (!(hdr = grab_object( handle )))
2280 set_last_error( ERROR_INVALID_HANDLE );
2281 return WINHTTP_INVALID_STATUS_CALLBACK;
2283 ret = hdr->callback;
2284 hdr->callback = callback;
2285 hdr->notify_mask = flags;
2287 release_object( hdr );
2291 /***********************************************************************
2292 * WinHttpSetTimeouts (winhttp.@)
2294 BOOL WINAPI WinHttpSetTimeouts( HINTERNET handle, int resolve, int connect, int send, int receive )
2297 object_header_t *hdr;
2301 TRACE("%p, %d, %d, %d, %d\n", handle, resolve, connect, send, receive);
2303 if (resolve < -1 || connect < -1 || send < -1 || receive < -1)
2305 set_last_error( ERROR_INVALID_PARAMETER );
2309 if (!(hdr = grab_object( handle )))
2311 set_last_error( ERROR_INVALID_HANDLE );
2317 case WINHTTP_HANDLE_TYPE_REQUEST:
2318 request = (request_t *)hdr;
2319 request->connect_timeout = connect;
2321 if (resolve < 0) resolve = 0;
2322 request->resolve_timeout = resolve;
2324 if (send < 0) send = 0;
2325 request->send_timeout = send;
2327 if (receive < 0) receive = 0;
2328 request->recv_timeout = receive;
2330 if (netconn_connected( &request->netconn ))
2332 if (netconn_set_timeout( &request->netconn, TRUE, send )) ret = FALSE;
2333 if (netconn_set_timeout( &request->netconn, FALSE, receive )) ret = FALSE;
2336 release_object( &request->hdr );
2339 case WINHTTP_HANDLE_TYPE_SESSION:
2340 session = (session_t *)hdr;
2341 session->connect_timeout = connect;
2343 if (resolve < 0) resolve = 0;
2344 session->resolve_timeout = resolve;
2346 if (send < 0) send = 0;
2347 session->send_timeout = send;
2349 if (receive < 0) receive = 0;
2350 session->recv_timeout = receive;
2354 release_object( hdr );
2355 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
2361 static const WCHAR wkday[7][4] =
2362 {{'S','u','n', 0}, {'M','o','n', 0}, {'T','u','e', 0}, {'W','e','d', 0},
2363 {'T','h','u', 0}, {'F','r','i', 0}, {'S','a','t', 0}};
2364 static const WCHAR month[12][4] =
2365 {{'J','a','n', 0}, {'F','e','b', 0}, {'M','a','r', 0}, {'A','p','r', 0},
2366 {'M','a','y', 0}, {'J','u','n', 0}, {'J','u','l', 0}, {'A','u','g', 0},
2367 {'S','e','p', 0}, {'O','c','t', 0}, {'N','o','v', 0}, {'D','e','c', 0}};
2369 /***********************************************************************
2370 * WinHttpTimeFromSystemTime (WININET.@)
2372 BOOL WINAPI WinHttpTimeFromSystemTime( const SYSTEMTIME *time, LPWSTR string )
2374 static const WCHAR format[] =
2375 {'%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2376 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0};
2378 TRACE("%p, %p\n", time, string);
2380 if (!time || !string) return FALSE;
2382 sprintfW( string, format,
2383 wkday[time->wDayOfWeek],
2385 month[time->wMonth - 1],
2394 /***********************************************************************
2395 * WinHttpTimeToSystemTime (WININET.@)
2397 BOOL WINAPI WinHttpTimeToSystemTime( LPCWSTR string, SYSTEMTIME *time )
2400 const WCHAR *s = string;
2403 TRACE("%s, %p\n", debugstr_w(string), time);
2405 if (!string || !time) return FALSE;
2407 /* Windows does this too */
2408 GetSystemTime( time );
2410 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2411 * a SYSTEMTIME structure.
2414 while (*s && !isalphaW( *s )) s++;
2415 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2416 time->wDayOfWeek = 7;
2418 for (i = 0; i < 7; i++)
2420 if (toupperW( wkday[i][0] ) == toupperW( s[0] ) &&
2421 toupperW( wkday[i][1] ) == toupperW( s[1] ) &&
2422 toupperW( wkday[i][2] ) == toupperW( s[2] ) )
2424 time->wDayOfWeek = i;
2429 if (time->wDayOfWeek > 6) return TRUE;
2430 while (*s && !isdigitW( *s )) s++;
2431 time->wDay = strtolW( s, &end, 10 );
2434 while (*s && !isalphaW( *s )) s++;
2435 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2438 for (i = 0; i < 12; i++)
2440 if (toupperW( month[i][0]) == toupperW( s[0] ) &&
2441 toupperW( month[i][1]) == toupperW( s[1] ) &&
2442 toupperW( month[i][2]) == toupperW( s[2] ) )
2444 time->wMonth = i + 1;
2448 if (time->wMonth == 0) return TRUE;
2450 while (*s && !isdigitW( *s )) s++;
2451 if (*s == '\0') return TRUE;
2452 time->wYear = strtolW( s, &end, 10 );
2455 while (*s && !isdigitW( *s )) s++;
2456 if (*s == '\0') return TRUE;
2457 time->wHour = strtolW( s, &end, 10 );
2460 while (*s && !isdigitW( *s )) s++;
2461 if (*s == '\0') return TRUE;
2462 time->wMinute = strtolW( s, &end, 10 );
2465 while (*s && !isdigitW( *s )) s++;
2466 if (*s == '\0') return TRUE;
2467 time->wSecond = strtolW( s, &end, 10 );
2469 time->wMilliseconds = 0;