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"
26 #ifdef HAVE_CORESERVICES_CORESERVICES_H
27 #define GetCurrentThread MacGetCurrentThread
28 #define LoadResource MacLoadResource
29 #include <CoreServices/CoreServices.h>
30 #undef GetCurrentThread
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
)
62 SetLastError( error
);
65 DWORD
get_last_error( void )
68 return GetLastError();
71 void send_callback( object_header_t
*hdr
, DWORD status
, LPVOID info
, DWORD buflen
)
73 if (hdr
->callback
&& (hdr
->notify_mask
& status
))
75 TRACE("%p, 0x%08x, %p, %u\n", hdr
, status
, info
, buflen
);
76 hdr
->callback( hdr
->handle
, hdr
->context
, status
, info
, buflen
);
77 TRACE("returning from 0x%08x callback\n", status
);
81 /***********************************************************************
82 * WinHttpCheckPlatform (winhttp.@)
84 BOOL WINAPI
WinHttpCheckPlatform( void )
90 /***********************************************************************
91 * session_destroy (internal)
93 static void session_destroy( object_header_t
*hdr
)
95 session_t
*session
= (session_t
*)hdr
;
96 struct list
*item
, *next
;
99 TRACE("%p\n", session
);
101 if (session
->unload_event
) SetEvent( session
->unload_event
);
102 if (session
->cred_handle_initialized
) FreeCredentialsHandle( &session
->cred_handle
);
104 LIST_FOR_EACH_SAFE( item
, next
, &session
->cookie_cache
)
106 domain
= LIST_ENTRY( item
, domain_t
, entry
);
107 delete_domain( domain
);
109 heap_free( session
->agent
);
110 heap_free( session
->proxy_server
);
111 heap_free( session
->proxy_bypass
);
112 heap_free( session
->proxy_username
);
113 heap_free( session
->proxy_password
);
114 heap_free( session
);
117 static BOOL
session_query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
119 session_t
*session
= (session_t
*)hdr
;
123 case WINHTTP_OPTION_REDIRECT_POLICY
:
125 if (!buffer
|| *buflen
< sizeof(DWORD
))
127 *buflen
= sizeof(DWORD
);
128 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
132 *(DWORD
*)buffer
= hdr
->redirect_policy
;
133 *buflen
= sizeof(DWORD
);
136 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
137 *(DWORD
*)buffer
= session
->resolve_timeout
;
138 *buflen
= sizeof(DWORD
);
140 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
141 *(DWORD
*)buffer
= session
->connect_timeout
;
142 *buflen
= sizeof(DWORD
);
144 case WINHTTP_OPTION_SEND_TIMEOUT
:
145 *(DWORD
*)buffer
= session
->send_timeout
;
146 *buflen
= sizeof(DWORD
);
148 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
149 *(DWORD
*)buffer
= session
->recv_timeout
;
150 *buflen
= sizeof(DWORD
);
153 FIXME("unimplemented option %u\n", option
);
154 set_last_error( ERROR_INVALID_PARAMETER
);
159 static BOOL
session_set_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, DWORD buflen
)
161 session_t
*session
= (session_t
*)hdr
;
165 case WINHTTP_OPTION_PROXY
:
167 WINHTTP_PROXY_INFO
*pi
= buffer
;
169 FIXME("%u %s %s\n", pi
->dwAccessType
, debugstr_w(pi
->lpszProxy
), debugstr_w(pi
->lpszProxyBypass
));
172 case WINHTTP_OPTION_REDIRECT_POLICY
:
176 if (buflen
!= sizeof(policy
))
178 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
182 policy
= *(DWORD
*)buffer
;
183 TRACE("0x%x\n", policy
);
184 hdr
->redirect_policy
= policy
;
187 case WINHTTP_OPTION_SECURE_PROTOCOLS
:
189 if (buflen
!= sizeof(session
->secure_protocols
))
191 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
194 session
->secure_protocols
= *(DWORD
*)buffer
;
195 TRACE("0x%x\n", session
->secure_protocols
);
198 case WINHTTP_OPTION_DISABLE_FEATURE
:
199 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
201 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
202 session
->resolve_timeout
= *(DWORD
*)buffer
;
204 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
205 session
->connect_timeout
= *(DWORD
*)buffer
;
207 case WINHTTP_OPTION_SEND_TIMEOUT
:
208 session
->send_timeout
= *(DWORD
*)buffer
;
210 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
211 session
->recv_timeout
= *(DWORD
*)buffer
;
213 case WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH
:
214 FIXME("WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH: 0x%x\n", *(DWORD
*)buffer
);
216 case WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT
:
217 TRACE("WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT: %p\n", *(HANDLE
*)buffer
);
218 session
->unload_event
= *(HANDLE
*)buffer
;
220 case WINHTTP_OPTION_MAX_CONNS_PER_SERVER
:
221 FIXME("WINHTTP_OPTION_MAX_CONNS_PER_SERVER: %d\n", *(DWORD
*)buffer
);
223 case WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER
:
224 FIXME("WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER: %d\n", *(DWORD
*)buffer
);
227 FIXME("unimplemented option %u\n", option
);
228 set_last_error( ERROR_INVALID_PARAMETER
);
233 static const object_vtbl_t session_vtbl
=
236 session_query_option
,
240 /***********************************************************************
241 * WinHttpOpen (winhttp.@)
243 HINTERNET WINAPI
WinHttpOpen( LPCWSTR agent
, DWORD access
, LPCWSTR proxy
, LPCWSTR bypass
, DWORD flags
)
246 HINTERNET handle
= NULL
;
248 TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent
), access
, debugstr_w(proxy
), debugstr_w(bypass
), flags
);
250 if (!(session
= heap_alloc_zero( sizeof(session_t
) ))) return NULL
;
252 session
->hdr
.type
= WINHTTP_HANDLE_TYPE_SESSION
;
253 session
->hdr
.vtbl
= &session_vtbl
;
254 session
->hdr
.flags
= flags
;
255 session
->hdr
.refs
= 1;
256 session
->hdr
.redirect_policy
= WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP
;
257 list_init( &session
->hdr
.children
);
258 session
->resolve_timeout
= DEFAULT_RESOLVE_TIMEOUT
;
259 session
->connect_timeout
= DEFAULT_CONNECT_TIMEOUT
;
260 session
->send_timeout
= DEFAULT_SEND_TIMEOUT
;
261 session
->recv_timeout
= DEFAULT_RECEIVE_TIMEOUT
;
262 list_init( &session
->cookie_cache
);
264 if (agent
&& !(session
->agent
= strdupW( agent
))) goto end
;
265 if (access
== WINHTTP_ACCESS_TYPE_DEFAULT_PROXY
)
267 WINHTTP_PROXY_INFO info
;
269 WinHttpGetDefaultProxyConfiguration( &info
);
270 session
->access
= info
.dwAccessType
;
271 if (info
.lpszProxy
&& !(session
->proxy_server
= strdupW( info
.lpszProxy
)))
273 GlobalFree( info
.lpszProxy
);
274 GlobalFree( info
.lpszProxyBypass
);
277 if (info
.lpszProxyBypass
&& !(session
->proxy_bypass
= strdupW( info
.lpszProxyBypass
)))
279 GlobalFree( info
.lpszProxy
);
280 GlobalFree( info
.lpszProxyBypass
);
284 else if (access
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
286 session
->access
= access
;
287 if (proxy
&& !(session
->proxy_server
= strdupW( proxy
))) goto end
;
288 if (bypass
&& !(session
->proxy_bypass
= strdupW( bypass
))) goto end
;
291 if (!(handle
= alloc_handle( &session
->hdr
))) goto end
;
292 session
->hdr
.handle
= handle
;
295 release_object( &session
->hdr
);
296 TRACE("returning %p\n", handle
);
297 if (handle
) set_last_error( ERROR_SUCCESS
);
301 /***********************************************************************
302 * connect_destroy (internal)
304 static void connect_destroy( object_header_t
*hdr
)
306 connect_t
*connect
= (connect_t
*)hdr
;
308 TRACE("%p\n", connect
);
310 release_object( &connect
->session
->hdr
);
312 heap_free( connect
->hostname
);
313 heap_free( connect
->servername
);
314 heap_free( connect
->username
);
315 heap_free( connect
->password
);
316 heap_free( connect
);
319 static BOOL
connect_query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
321 connect_t
*connect
= (connect_t
*)hdr
;
325 case WINHTTP_OPTION_PARENT_HANDLE
:
327 if (!buffer
|| *buflen
< sizeof(HINTERNET
))
329 *buflen
= sizeof(HINTERNET
);
330 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
334 *(HINTERNET
*)buffer
= ((object_header_t
*)connect
->session
)->handle
;
335 *buflen
= sizeof(HINTERNET
);
338 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
339 *(DWORD
*)buffer
= connect
->session
->resolve_timeout
;
340 *buflen
= sizeof(DWORD
);
342 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
343 *(DWORD
*)buffer
= connect
->session
->connect_timeout
;
344 *buflen
= sizeof(DWORD
);
346 case WINHTTP_OPTION_SEND_TIMEOUT
:
347 *(DWORD
*)buffer
= connect
->session
->send_timeout
;
348 *buflen
= sizeof(DWORD
);
350 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
351 *(DWORD
*)buffer
= connect
->session
->recv_timeout
;
352 *buflen
= sizeof(DWORD
);
355 FIXME("unimplemented option %u\n", option
);
356 set_last_error( ERROR_INVALID_PARAMETER
);
361 static const object_vtbl_t connect_vtbl
=
364 connect_query_option
,
368 static BOOL
domain_matches(LPCWSTR server
, LPCWSTR domain
)
370 static const WCHAR localW
[] = { '<','l','o','c','a','l','>',0 };
373 if (!strcmpiW( domain
, localW
) && !strchrW( server
, '.' ))
375 else if (*domain
== '*')
377 if (domain
[1] == '.')
381 /* For a hostname to match a wildcard, the last domain must match
382 * the wildcard exactly. E.g. if the wildcard is *.a.b, and the
383 * hostname is www.foo.a.b, it matches, but a.b does not.
385 dot
= strchrW( server
, '.' );
388 int len
= strlenW( dot
+ 1 );
390 if (len
> strlenW( domain
+ 2 ))
394 /* The server's domain is longer than the wildcard, so it
395 * could be a subdomain. Compare the last portion of the
398 ptr
= dot
+ len
+ 1 - strlenW( domain
+ 2 );
399 if (!strcmpiW( ptr
, domain
+ 2 ))
401 /* This is only a match if the preceding character is
402 * a '.', i.e. that it is a matching domain. E.g.
403 * if domain is '*.b.c' and server is 'www.ab.c' they
406 ret
= *(ptr
- 1) == '.';
410 ret
= !strcmpiW( dot
+ 1, domain
+ 2 );
415 ret
= !strcmpiW( server
, domain
);
419 /* Matches INTERNET_MAX_HOST_NAME_LENGTH in wininet.h, also RFC 1035 */
420 #define MAX_HOST_NAME_LENGTH 256
422 static BOOL
should_bypass_proxy(session_t
*session
, LPCWSTR server
)
427 if (!session
->proxy_bypass
) return FALSE
;
428 ptr
= session
->proxy_bypass
;
432 ptr
= strchrW( ptr
, ';' );
434 ptr
= strchrW( tmp
, ' ' );
437 if (ptr
- tmp
< MAX_HOST_NAME_LENGTH
)
439 WCHAR domain
[MAX_HOST_NAME_LENGTH
];
441 memcpy( domain
, tmp
, (ptr
- tmp
) * sizeof(WCHAR
) );
442 domain
[ptr
- tmp
] = 0;
443 ret
= domain_matches( server
, domain
);
448 ret
= domain_matches( server
, tmp
);
449 } while (ptr
&& !ret
);
453 BOOL
set_server_for_hostname( connect_t
*connect
, LPCWSTR server
, INTERNET_PORT port
)
455 session_t
*session
= connect
->session
;
458 if (session
->proxy_server
&& !should_bypass_proxy(session
, server
))
462 if ((colon
= strchrW( session
->proxy_server
, ':' )))
464 if (!connect
->servername
|| strncmpiW( connect
->servername
,
465 session
->proxy_server
, colon
- session
->proxy_server
- 1 ))
467 heap_free( connect
->servername
);
468 connect
->resolved
= FALSE
;
469 if (!(connect
->servername
= heap_alloc(
470 (colon
- session
->proxy_server
+ 1) * sizeof(WCHAR
) )))
475 memcpy( connect
->servername
, session
->proxy_server
,
476 (colon
- session
->proxy_server
) * sizeof(WCHAR
) );
477 connect
->servername
[colon
- session
->proxy_server
] = 0;
479 connect
->serverport
= atoiW( colon
+ 1 );
481 connect
->serverport
= INTERNET_DEFAULT_PORT
;
486 if (!connect
->servername
|| strcmpiW( connect
->servername
,
487 session
->proxy_server
))
489 heap_free( connect
->servername
);
490 connect
->resolved
= FALSE
;
491 if (!(connect
->servername
= strdupW( session
->proxy_server
)))
496 connect
->serverport
= INTERNET_DEFAULT_PORT
;
502 heap_free( connect
->servername
);
503 connect
->resolved
= FALSE
;
504 if (!(connect
->servername
= strdupW( server
)))
509 connect
->serverport
= port
;
515 /***********************************************************************
516 * WinHttpConnect (winhttp.@)
518 HINTERNET WINAPI
WinHttpConnect( HINTERNET hsession
, LPCWSTR server
, INTERNET_PORT port
, DWORD reserved
)
522 HINTERNET hconnect
= NULL
;
524 TRACE("%p, %s, %u, %x\n", hsession
, debugstr_w(server
), port
, reserved
);
528 set_last_error( ERROR_INVALID_PARAMETER
);
531 if (!(session
= (session_t
*)grab_object( hsession
)))
533 set_last_error( ERROR_INVALID_HANDLE
);
536 if (session
->hdr
.type
!= WINHTTP_HANDLE_TYPE_SESSION
)
538 release_object( &session
->hdr
);
539 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
542 if (!(connect
= heap_alloc_zero( sizeof(connect_t
) )))
544 release_object( &session
->hdr
);
547 connect
->hdr
.type
= WINHTTP_HANDLE_TYPE_CONNECT
;
548 connect
->hdr
.vtbl
= &connect_vtbl
;
549 connect
->hdr
.refs
= 1;
550 connect
->hdr
.flags
= session
->hdr
.flags
;
551 connect
->hdr
.callback
= session
->hdr
.callback
;
552 connect
->hdr
.notify_mask
= session
->hdr
.notify_mask
;
553 connect
->hdr
.context
= session
->hdr
.context
;
554 connect
->hdr
.redirect_policy
= session
->hdr
.redirect_policy
;
555 list_init( &connect
->hdr
.children
);
557 addref_object( &session
->hdr
);
558 connect
->session
= session
;
559 list_add_head( &session
->hdr
.children
, &connect
->hdr
.entry
);
561 if (!(connect
->hostname
= strdupW( server
))) goto end
;
562 connect
->hostport
= port
;
563 if (!set_server_for_hostname( connect
, server
, port
)) goto end
;
565 if (!(hconnect
= alloc_handle( &connect
->hdr
))) goto end
;
566 connect
->hdr
.handle
= hconnect
;
568 send_callback( &session
->hdr
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
, &hconnect
, sizeof(hconnect
) );
571 release_object( &connect
->hdr
);
572 release_object( &session
->hdr
);
573 TRACE("returning %p\n", hconnect
);
574 if (hconnect
) set_last_error( ERROR_SUCCESS
);
578 /***********************************************************************
579 * request_destroy (internal)
581 static void request_destroy( object_header_t
*hdr
)
583 request_t
*request
= (request_t
*)hdr
;
586 TRACE("%p\n", request
);
588 if (request
->task_thread
)
590 /* Signal to the task proc to quit. It will call
591 this again when it does. */
592 HANDLE thread
= request
->task_thread
;
593 request
->task_thread
= 0;
594 SetEvent( request
->task_cancel
);
595 CloseHandle( thread
);
598 release_object( &request
->connect
->hdr
);
600 destroy_authinfo( request
->authinfo
);
601 destroy_authinfo( request
->proxy_authinfo
);
603 heap_free( request
->verb
);
604 heap_free( request
->path
);
605 heap_free( request
->version
);
606 heap_free( request
->raw_headers
);
607 heap_free( request
->status_text
);
608 for (i
= 0; i
< request
->num_headers
; i
++)
610 heap_free( request
->headers
[i
].field
);
611 heap_free( request
->headers
[i
].value
);
613 heap_free( request
->headers
);
614 for (i
= 0; i
< request
->num_accept_types
; i
++) heap_free( request
->accept_types
[i
] );
615 heap_free( request
->accept_types
);
616 for (i
= 0; i
< TARGET_MAX
; i
++)
618 for (j
= 0; j
< SCHEME_MAX
; j
++)
620 heap_free( request
->creds
[i
][j
].username
);
621 heap_free( request
->creds
[i
][j
].password
);
624 heap_free( request
);
627 static void str_to_buffer( WCHAR
*buffer
, const WCHAR
*str
, LPDWORD buflen
)
630 if (str
) len
= strlenW( str
);
631 if (buffer
&& *buflen
> len
)
633 if (str
) memcpy( buffer
, str
, len
* sizeof(WCHAR
) );
636 *buflen
= len
* sizeof(WCHAR
);
639 static WCHAR
*blob_to_str( DWORD encoding
, CERT_NAME_BLOB
*blob
)
642 DWORD size
, format
= CERT_SIMPLE_NAME_STR
| CERT_NAME_STR_CRLF_FLAG
;
644 size
= CertNameToStrW( encoding
, blob
, format
, NULL
, 0 );
645 if ((ret
= LocalAlloc( 0, size
* sizeof(WCHAR
) )))
646 CertNameToStrW( encoding
, blob
, format
, ret
, size
);
651 static BOOL
convert_sockaddr( const struct sockaddr
*addr
, SOCKADDR_STORAGE
*addr_storage
)
654 switch (addr
->sa_family
)
658 const struct sockaddr_in
*addr_unix
= (const struct sockaddr_in
*)addr
;
659 struct WS_sockaddr_in
*addr_win
= (struct WS_sockaddr_in
*)addr_storage
;
662 addr_win
->sin_family
= WS_AF_INET
;
663 addr_win
->sin_port
= addr_unix
->sin_port
;
664 memcpy( &addr_win
->sin_addr
, &addr_unix
->sin_addr
, 4 );
665 p
= (char *)&addr_win
->sin_addr
+ 4;
666 memset( p
, 0, sizeof(*addr_storage
) - (p
- (char *)addr_win
) );
671 const struct sockaddr_in6
*addr_unix
= (const struct sockaddr_in6
*)addr
;
672 struct WS_sockaddr_in6
*addr_win
= (struct WS_sockaddr_in6
*)addr_storage
;
674 addr_win
->sin6_family
= WS_AF_INET6
;
675 addr_win
->sin6_port
= addr_unix
->sin6_port
;
676 addr_win
->sin6_flowinfo
= addr_unix
->sin6_flowinfo
;
677 memcpy( &addr_win
->sin6_addr
, &addr_unix
->sin6_addr
, 16 );
678 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
679 addr_win
->sin6_scope_id
= addr_unix
->sin6_scope_id
;
681 addr_win
->sin6_scope_id
= 0;
683 memset( addr_win
+ 1, 0, sizeof(*addr_storage
) - sizeof(*addr_win
) );
687 ERR("unhandled family %u\n", addr
->sa_family
);
691 switch (addr
->sa_family
)
695 struct sockaddr_in
*addr_in
= (struct sockaddr_in
*)addr_storage
;
697 memcpy( addr_in
, addr
, sizeof(*addr_in
) );
698 memset( addr_in
+ 1, 0, sizeof(*addr_storage
) - sizeof(*addr_in
) );
703 struct sockaddr_in6
*addr_in6
= (struct sockaddr_in6
*)addr_storage
;
705 memcpy( addr_in6
, addr
, sizeof(*addr_in6
) );
706 memset( addr_in6
+ 1, 0, sizeof(*addr_storage
) - sizeof(*addr_in6
) );
710 ERR("unhandled family %u\n", addr
->sa_family
);
716 static BOOL
request_query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
718 request_t
*request
= (request_t
*)hdr
;
722 case WINHTTP_OPTION_SECURITY_FLAGS
:
727 if (!buffer
|| *buflen
< sizeof(flags
))
729 *buflen
= sizeof(flags
);
730 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
735 if (hdr
->flags
& WINHTTP_FLAG_SECURE
) flags
|= SECURITY_FLAG_SECURE
;
736 flags
|= request
->security_flags
;
737 if (request
->netconn
)
739 bits
= netconn_get_cipher_strength( request
->netconn
);
741 flags
|= SECURITY_FLAG_STRENGTH_STRONG
;
743 flags
|= SECURITY_FLAG_STRENGTH_MEDIUM
;
745 flags
|= SECURITY_FLAG_STRENGTH_WEAK
;
747 *(DWORD
*)buffer
= flags
;
748 *buflen
= sizeof(flags
);
751 case WINHTTP_OPTION_SERVER_CERT_CONTEXT
:
753 const CERT_CONTEXT
*cert
;
755 if (!buffer
|| *buflen
< sizeof(cert
))
757 *buflen
= sizeof(cert
);
758 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
762 if (!request
->netconn
|| !(cert
= netconn_get_certificate( request
->netconn
))) return FALSE
;
763 *(CERT_CONTEXT
**)buffer
= (CERT_CONTEXT
*)cert
;
764 *buflen
= sizeof(cert
);
767 case WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT
:
769 const CERT_CONTEXT
*cert
;
770 const CRYPT_OID_INFO
*oidInfo
;
771 WINHTTP_CERTIFICATE_INFO
*ci
= buffer
;
773 FIXME("partial stub\n");
775 if (!buffer
|| *buflen
< sizeof(*ci
))
777 *buflen
= sizeof(*ci
);
778 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
781 if (!request
->netconn
|| !(cert
= netconn_get_certificate( request
->netconn
))) return FALSE
;
783 ci
->ftExpiry
= cert
->pCertInfo
->NotAfter
;
784 ci
->ftStart
= cert
->pCertInfo
->NotBefore
;
785 ci
->lpszSubjectInfo
= blob_to_str( cert
->dwCertEncodingType
, &cert
->pCertInfo
->Subject
);
786 ci
->lpszIssuerInfo
= blob_to_str( cert
->dwCertEncodingType
, &cert
->pCertInfo
->Issuer
);
787 ci
->lpszProtocolName
= NULL
;
788 oidInfo
= CryptFindOIDInfo( CRYPT_OID_INFO_OID_KEY
,
789 cert
->pCertInfo
->SignatureAlgorithm
.pszObjId
,
792 ci
->lpszSignatureAlgName
= (LPWSTR
)oidInfo
->pwszName
;
794 ci
->lpszSignatureAlgName
= NULL
;
795 ci
->lpszEncryptionAlgName
= NULL
;
796 ci
->dwKeySize
= request
->netconn
? netconn_get_cipher_strength( request
->netconn
) : 0;
798 CertFreeCertificateContext( cert
);
799 *buflen
= sizeof(*ci
);
802 case WINHTTP_OPTION_SECURITY_KEY_BITNESS
:
804 if (!buffer
|| *buflen
< sizeof(DWORD
))
806 *buflen
= sizeof(DWORD
);
807 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
811 *(DWORD
*)buffer
= request
->netconn
? netconn_get_cipher_strength( request
->netconn
) : 0;
812 *buflen
= sizeof(DWORD
);
815 case WINHTTP_OPTION_CONNECTION_INFO
:
817 WINHTTP_CONNECTION_INFO
*info
= buffer
;
818 struct sockaddr local
;
819 socklen_t len
= sizeof(local
);
820 const struct sockaddr
*remote
= (const struct sockaddr
*)&request
->connect
->sockaddr
;
822 if (!buffer
|| *buflen
< sizeof(*info
))
824 *buflen
= sizeof(*info
);
825 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
828 if (!request
->netconn
)
830 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_STATE
);
833 if (getsockname( request
->netconn
->socket
, &local
, &len
)) return FALSE
;
834 if (!convert_sockaddr( &local
, &info
->LocalAddress
)) return FALSE
;
835 if (!convert_sockaddr( remote
, &info
->RemoteAddress
)) return FALSE
;
836 info
->cbSize
= sizeof(*info
);
839 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
840 *(DWORD
*)buffer
= request
->resolve_timeout
;
841 *buflen
= sizeof(DWORD
);
843 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
844 *(DWORD
*)buffer
= request
->connect_timeout
;
845 *buflen
= sizeof(DWORD
);
847 case WINHTTP_OPTION_SEND_TIMEOUT
:
848 *(DWORD
*)buffer
= request
->send_timeout
;
849 *buflen
= sizeof(DWORD
);
851 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
852 *(DWORD
*)buffer
= request
->recv_timeout
;
853 *buflen
= sizeof(DWORD
);
856 case WINHTTP_OPTION_USERNAME
:
857 str_to_buffer( buffer
, request
->connect
->username
, buflen
);
860 case WINHTTP_OPTION_PASSWORD
:
861 str_to_buffer( buffer
, request
->connect
->password
, buflen
);
864 case WINHTTP_OPTION_PROXY_USERNAME
:
865 str_to_buffer( buffer
, request
->connect
->session
->proxy_username
, buflen
);
868 case WINHTTP_OPTION_PROXY_PASSWORD
:
869 str_to_buffer( buffer
, request
->connect
->session
->proxy_password
, buflen
);
873 FIXME("unimplemented option %u\n", option
);
874 set_last_error( ERROR_INVALID_PARAMETER
);
879 static WCHAR
*buffer_to_str( WCHAR
*buffer
, DWORD buflen
)
882 if ((ret
= heap_alloc( (buflen
+ 1) * sizeof(WCHAR
))))
884 memcpy( ret
, buffer
, buflen
* sizeof(WCHAR
) );
888 set_last_error( ERROR_OUTOFMEMORY
);
892 static BOOL
request_set_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, DWORD buflen
)
894 request_t
*request
= (request_t
*)hdr
;
898 case WINHTTP_OPTION_PROXY
:
900 WINHTTP_PROXY_INFO
*pi
= buffer
;
902 FIXME("%u %s %s\n", pi
->dwAccessType
, debugstr_w(pi
->lpszProxy
), debugstr_w(pi
->lpszProxyBypass
));
905 case WINHTTP_OPTION_DISABLE_FEATURE
:
909 if (buflen
!= sizeof(DWORD
))
911 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
915 disable
= *(DWORD
*)buffer
;
916 TRACE("0x%x\n", disable
);
917 hdr
->disable_flags
|= disable
;
920 case WINHTTP_OPTION_AUTOLOGON_POLICY
:
924 if (buflen
!= sizeof(DWORD
))
926 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
930 policy
= *(DWORD
*)buffer
;
931 TRACE("0x%x\n", policy
);
932 hdr
->logon_policy
= policy
;
935 case WINHTTP_OPTION_REDIRECT_POLICY
:
939 if (buflen
!= sizeof(DWORD
))
941 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
945 policy
= *(DWORD
*)buffer
;
946 TRACE("0x%x\n", policy
);
947 hdr
->redirect_policy
= policy
;
950 case WINHTTP_OPTION_SECURITY_FLAGS
:
954 if (buflen
< sizeof(DWORD
))
956 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
959 flags
= *(DWORD
*)buffer
;
960 TRACE("0x%x\n", flags
);
961 if (!(flags
& (SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|
962 SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
|
963 SECURITY_FLAG_IGNORE_UNKNOWN_CA
|
964 SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE
)))
966 set_last_error( ERROR_INVALID_PARAMETER
);
969 request
->security_flags
= flags
;
972 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
973 request
->resolve_timeout
= *(DWORD
*)buffer
;
975 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
976 request
->connect_timeout
= *(DWORD
*)buffer
;
978 case WINHTTP_OPTION_SEND_TIMEOUT
:
979 request
->send_timeout
= *(DWORD
*)buffer
;
981 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
982 request
->recv_timeout
= *(DWORD
*)buffer
;
985 case WINHTTP_OPTION_USERNAME
:
987 connect_t
*connect
= request
->connect
;
989 heap_free( connect
->username
);
990 if (!(connect
->username
= buffer_to_str( buffer
, buflen
))) return FALSE
;
993 case WINHTTP_OPTION_PASSWORD
:
995 connect_t
*connect
= request
->connect
;
997 heap_free( connect
->password
);
998 if (!(connect
->password
= buffer_to_str( buffer
, buflen
))) return FALSE
;
1001 case WINHTTP_OPTION_PROXY_USERNAME
:
1003 session_t
*session
= request
->connect
->session
;
1005 heap_free( session
->proxy_username
);
1006 if (!(session
->proxy_username
= buffer_to_str( buffer
, buflen
))) return FALSE
;
1009 case WINHTTP_OPTION_PROXY_PASSWORD
:
1011 session_t
*session
= request
->connect
->session
;
1013 heap_free( session
->proxy_password
);
1014 if (!(session
->proxy_password
= buffer_to_str( buffer
, buflen
))) return FALSE
;
1017 case WINHTTP_OPTION_CLIENT_CERT_CONTEXT
:
1018 if (!(hdr
->flags
& WINHTTP_FLAG_SECURE
))
1020 SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_STATE
);
1023 FIXME("WINHTTP_OPTION_CLIENT_CERT_CONTEXT\n");
1026 FIXME("unimplemented option %u\n", option
);
1027 set_last_error( ERROR_INVALID_PARAMETER
);
1032 static const object_vtbl_t request_vtbl
=
1035 request_query_option
,
1039 static BOOL
store_accept_types( request_t
*request
, const WCHAR
**accept_types
)
1041 const WCHAR
**types
= accept_types
;
1044 if (!types
) return TRUE
;
1047 request
->num_accept_types
++;
1050 if (!request
->num_accept_types
) return TRUE
;
1051 if (!(request
->accept_types
= heap_alloc( request
->num_accept_types
* sizeof(WCHAR
*))))
1053 request
->num_accept_types
= 0;
1056 types
= accept_types
;
1057 for (i
= 0; i
< request
->num_accept_types
; i
++)
1059 if (!(request
->accept_types
[i
] = strdupW( *types
)))
1061 for ( ; i
> 0; --i
) heap_free( request
->accept_types
[i
- 1] );
1062 heap_free( request
->accept_types
);
1063 request
->accept_types
= NULL
;
1064 request
->num_accept_types
= 0;
1072 /***********************************************************************
1073 * WinHttpOpenRequest (winhttp.@)
1075 HINTERNET WINAPI
WinHttpOpenRequest( HINTERNET hconnect
, LPCWSTR verb
, LPCWSTR object
, LPCWSTR version
,
1076 LPCWSTR referrer
, LPCWSTR
*types
, DWORD flags
)
1080 HINTERNET hrequest
= NULL
;
1082 TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect
, debugstr_w(verb
), debugstr_w(object
),
1083 debugstr_w(version
), debugstr_w(referrer
), types
, flags
);
1085 if(types
&& TRACE_ON(winhttp
)) {
1088 TRACE("accept types:\n");
1089 for(iter
= types
; *iter
; iter
++)
1090 TRACE(" %s\n", debugstr_w(*iter
));
1093 if (!(connect
= (connect_t
*)grab_object( hconnect
)))
1095 set_last_error( ERROR_INVALID_HANDLE
);
1098 if (connect
->hdr
.type
!= WINHTTP_HANDLE_TYPE_CONNECT
)
1100 release_object( &connect
->hdr
);
1101 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1104 if (!(request
= heap_alloc_zero( sizeof(request_t
) )))
1106 release_object( &connect
->hdr
);
1109 request
->hdr
.type
= WINHTTP_HANDLE_TYPE_REQUEST
;
1110 request
->hdr
.vtbl
= &request_vtbl
;
1111 request
->hdr
.refs
= 1;
1112 request
->hdr
.flags
= flags
;
1113 request
->hdr
.callback
= connect
->hdr
.callback
;
1114 request
->hdr
.notify_mask
= connect
->hdr
.notify_mask
;
1115 request
->hdr
.context
= connect
->hdr
.context
;
1116 request
->hdr
.redirect_policy
= connect
->hdr
.redirect_policy
;
1117 list_init( &request
->hdr
.children
);
1118 list_init( &request
->task_queue
);
1120 addref_object( &connect
->hdr
);
1121 request
->connect
= connect
;
1122 list_add_head( &connect
->hdr
.children
, &request
->hdr
.entry
);
1124 request
->resolve_timeout
= connect
->session
->resolve_timeout
;
1125 request
->connect_timeout
= connect
->session
->connect_timeout
;
1126 request
->send_timeout
= connect
->session
->send_timeout
;
1127 request
->recv_timeout
= connect
->session
->recv_timeout
;
1129 if (!verb
|| !verb
[0]) verb
= getW
;
1130 if (!(request
->verb
= strdupW( verb
))) goto end
;
1137 len
= strlenW( object
) + 1;
1138 if (object
[0] != '/') len
++;
1139 if (!(p
= path
= heap_alloc( len
* sizeof(WCHAR
) ))) goto end
;
1141 if (object
[0] != '/') *p
++ = '/';
1142 strcpyW( p
, object
);
1143 request
->path
= path
;
1145 else if (!(request
->path
= strdupW( slashW
))) goto end
;
1147 if (!version
|| !version
[0]) version
= http1_1
;
1148 if (!(request
->version
= strdupW( version
))) goto end
;
1149 if (!(store_accept_types( request
, types
))) goto end
;
1151 if (!(hrequest
= alloc_handle( &request
->hdr
))) goto end
;
1152 request
->hdr
.handle
= hrequest
;
1154 send_callback( &request
->hdr
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
, &hrequest
, sizeof(hrequest
) );
1157 release_object( &request
->hdr
);
1158 release_object( &connect
->hdr
);
1159 TRACE("returning %p\n", hrequest
);
1160 if (hrequest
) set_last_error( ERROR_SUCCESS
);
1164 /***********************************************************************
1165 * WinHttpCloseHandle (winhttp.@)
1167 BOOL WINAPI
WinHttpCloseHandle( HINTERNET handle
)
1169 object_header_t
*hdr
;
1171 TRACE("%p\n", handle
);
1173 if (!(hdr
= grab_object( handle
)))
1175 set_last_error( ERROR_INVALID_HANDLE
);
1178 release_object( hdr
);
1179 free_handle( handle
);
1180 set_last_error( ERROR_SUCCESS
);
1184 static BOOL
query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
1190 set_last_error( ERROR_INVALID_PARAMETER
);
1196 case WINHTTP_OPTION_CONTEXT_VALUE
:
1198 if (!buffer
|| *buflen
< sizeof(DWORD_PTR
))
1200 *buflen
= sizeof(DWORD_PTR
);
1201 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
1205 *(DWORD_PTR
*)buffer
= hdr
->context
;
1206 *buflen
= sizeof(DWORD_PTR
);
1210 if (hdr
->vtbl
->query_option
) ret
= hdr
->vtbl
->query_option( hdr
, option
, buffer
, buflen
);
1213 FIXME("unimplemented option %u\n", option
);
1214 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1222 /***********************************************************************
1223 * WinHttpQueryOption (winhttp.@)
1225 BOOL WINAPI
WinHttpQueryOption( HINTERNET handle
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
1228 object_header_t
*hdr
;
1230 TRACE("%p, %u, %p, %p\n", handle
, option
, buffer
, buflen
);
1232 if (!(hdr
= grab_object( handle
)))
1234 set_last_error( ERROR_INVALID_HANDLE
);
1238 ret
= query_option( hdr
, option
, buffer
, buflen
);
1240 release_object( hdr
);
1241 if (ret
) set_last_error( ERROR_SUCCESS
);
1245 static BOOL
set_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, DWORD buflen
)
1249 if (!buffer
&& buflen
)
1251 set_last_error( ERROR_INVALID_PARAMETER
);
1257 case WINHTTP_OPTION_CONTEXT_VALUE
:
1259 if (buflen
!= sizeof(DWORD_PTR
))
1261 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
1265 hdr
->context
= *(DWORD_PTR
*)buffer
;
1269 if (hdr
->vtbl
->set_option
) ret
= hdr
->vtbl
->set_option( hdr
, option
, buffer
, buflen
);
1272 FIXME("unimplemented option %u\n", option
);
1273 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1281 /***********************************************************************
1282 * WinHttpSetOption (winhttp.@)
1284 BOOL WINAPI
WinHttpSetOption( HINTERNET handle
, DWORD option
, LPVOID buffer
, DWORD buflen
)
1287 object_header_t
*hdr
;
1289 TRACE("%p, %u, %p, %u\n", handle
, option
, buffer
, buflen
);
1291 if (!(hdr
= grab_object( handle
)))
1293 set_last_error( ERROR_INVALID_HANDLE
);
1297 ret
= set_option( hdr
, option
, buffer
, buflen
);
1299 release_object( hdr
);
1300 if (ret
) set_last_error( ERROR_SUCCESS
);
1304 static char *get_computer_name( COMPUTER_NAME_FORMAT format
)
1309 GetComputerNameExA( format
, NULL
, &size
);
1310 if (GetLastError() != ERROR_MORE_DATA
) return NULL
;
1311 if (!(ret
= heap_alloc( size
))) return NULL
;
1312 if (!GetComputerNameExA( format
, ret
, &size
))
1320 static BOOL
is_domain_suffix( const char *domain
, const char *suffix
)
1322 int len_domain
= strlen( domain
), len_suffix
= strlen( suffix
);
1324 if (len_suffix
> len_domain
) return FALSE
;
1325 if (!strcasecmp( domain
+ len_domain
- len_suffix
, suffix
)) return TRUE
;
1329 static int reverse_lookup( const struct addrinfo
*ai
, char *hostname
, size_t len
)
1332 #ifdef HAVE_GETNAMEINFO
1333 ret
= getnameinfo( ai
->ai_addr
, ai
->ai_addrlen
, hostname
, len
, NULL
, 0, 0 );
1338 static WCHAR
*build_wpad_url( const char *hostname
, const struct addrinfo
*ai
)
1340 static const WCHAR httpW
[] = {'h','t','t','p',':','/','/',0};
1341 static const WCHAR wpadW
[] = {'/','w','p','a','d','.','d','a','t',0};
1342 char name
[NI_MAXHOST
];
1346 while (ai
&& ai
->ai_family
!= AF_INET
&& ai
->ai_family
!= AF_INET6
) ai
= ai
->ai_next
;
1347 if (!ai
) return NULL
;
1349 if (!reverse_lookup( ai
, name
, sizeof(name
) )) hostname
= name
;
1351 len
= strlenW( httpW
) + strlen( hostname
) + strlenW( wpadW
);
1352 if (!(ret
= p
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) return NULL
;
1353 strcpyW( p
, httpW
);
1354 p
+= strlenW( httpW
);
1355 while (*hostname
) { *p
++ = *hostname
++; }
1356 strcpyW( p
, wpadW
);
1360 static BOOL
get_system_proxy_autoconfig_url( char *buf
, DWORD buflen
)
1362 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
1363 CFDictionaryRef settings
= CFNetworkCopySystemProxySettings();
1367 if (!settings
) return FALSE
;
1369 if (!(ref
= CFDictionaryGetValue( settings
, kCFNetworkProxiesProxyAutoConfigURLString
)))
1371 CFRelease( settings
);
1374 if (CFStringGetCString( ref
, buf
, buflen
, kCFStringEncodingASCII
))
1376 TRACE( "returning %s\n", debugstr_a(buf
) );
1379 CFRelease( settings
);
1382 static BOOL first
= TRUE
;
1385 FIXME( "no support on this platform\n" );
1389 TRACE( "no support on this platform\n" );
1394 #define INTERNET_MAX_URL_LENGTH 2084
1396 /***********************************************************************
1397 * WinHttpDetectAutoProxyConfigUrl (winhttp.@)
1399 BOOL WINAPI
WinHttpDetectAutoProxyConfigUrl( DWORD flags
, LPWSTR
*url
)
1402 char system_url
[INTERNET_MAX_URL_LENGTH
+ 1];
1404 TRACE("0x%08x, %p\n", flags
, url
);
1408 set_last_error( ERROR_INVALID_PARAMETER
);
1411 if (get_system_proxy_autoconfig_url( system_url
, sizeof(system_url
) ))
1415 if (!(urlW
= strdupAW( system_url
))) return FALSE
;
1417 set_last_error( ERROR_SUCCESS
);
1420 if (flags
& WINHTTP_AUTO_DETECT_TYPE_DHCP
)
1422 static int fixme_shown
;
1423 if (!fixme_shown
++) FIXME("discovery via DHCP not supported\n");
1425 if (flags
& WINHTTP_AUTO_DETECT_TYPE_DNS_A
)
1427 #ifdef HAVE_GETADDRINFO
1428 char *fqdn
, *domain
, *p
;
1430 if (!(fqdn
= get_computer_name( ComputerNamePhysicalDnsFullyQualified
))) return FALSE
;
1431 if (!(domain
= get_computer_name( ComputerNamePhysicalDnsDomain
)))
1437 while ((p
= strchr( p
, '.' )) && is_domain_suffix( p
+ 1, domain
))
1439 struct addrinfo
*ai
;
1443 if (!(name
= heap_alloc( sizeof("wpad") + strlen(p
) )))
1446 heap_free( domain
);
1449 strcpy( name
, "wpad" );
1451 res
= getaddrinfo( name
, NULL
, NULL
, &ai
);
1454 *url
= build_wpad_url( name
, ai
);
1458 TRACE("returning %s\n", debugstr_w(*url
));
1467 heap_free( domain
);
1470 FIXME("getaddrinfo not found at build time\n");
1475 set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED
);
1478 else set_last_error( ERROR_SUCCESS
);
1482 static const WCHAR Connections
[] = {
1483 'S','o','f','t','w','a','r','e','\\',
1484 'M','i','c','r','o','s','o','f','t','\\',
1485 'W','i','n','d','o','w','s','\\',
1486 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1487 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
1488 'C','o','n','n','e','c','t','i','o','n','s',0 };
1489 static const WCHAR WinHttpSettings
[] = {
1490 'W','i','n','H','t','t','p','S','e','t','t','i','n','g','s',0 };
1491 static const DWORD WINHTTP_SETTINGS_MAGIC
= 0x18;
1492 static const DWORD WININET_SETTINGS_MAGIC
= 0x46;
1493 static const DWORD PROXY_TYPE_DIRECT
= 1;
1494 static const DWORD PROXY_TYPE_PROXY
= 2;
1495 static const DWORD PROXY_USE_PAC_SCRIPT
= 4;
1496 static const DWORD PROXY_AUTODETECT_SETTINGS
= 8;
1498 struct connection_settings_header
1501 DWORD unknown
; /* always zero? */
1502 DWORD flags
; /* one or more of PROXY_* */
1505 static inline void copy_char_to_wchar_sz(const BYTE
*src
, DWORD len
, WCHAR
*dst
)
1509 for (begin
= src
; src
- begin
< len
; src
++, dst
++)
1514 /***********************************************************************
1515 * WinHttpGetDefaultProxyConfiguration (winhttp.@)
1517 BOOL WINAPI
WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO
*info
)
1521 BOOL got_from_reg
= FALSE
, direct
= TRUE
;
1524 TRACE("%p\n", info
);
1526 l
= RegOpenKeyExW( HKEY_LOCAL_MACHINE
, Connections
, 0, KEY_READ
, &key
);
1529 DWORD type
, size
= 0;
1531 l
= RegQueryValueExW( key
, WinHttpSettings
, NULL
, &type
, NULL
, &size
);
1532 if (!l
&& type
== REG_BINARY
&&
1533 size
>= sizeof(struct connection_settings_header
) + 2 * sizeof(DWORD
))
1535 BYTE
*buf
= heap_alloc( size
);
1539 struct connection_settings_header
*hdr
=
1540 (struct connection_settings_header
*)buf
;
1541 DWORD
*len
= (DWORD
*)(hdr
+ 1);
1543 l
= RegQueryValueExW( key
, WinHttpSettings
, NULL
, NULL
, buf
,
1545 if (!l
&& hdr
->magic
== WINHTTP_SETTINGS_MAGIC
&&
1548 if (hdr
->flags
& PROXY_TYPE_PROXY
)
1551 LPWSTR proxy
= NULL
;
1552 LPWSTR proxy_bypass
= NULL
;
1554 /* Sanity-check length of proxy string */
1555 if ((BYTE
*)len
- buf
+ *len
<= size
)
1558 proxy
= GlobalAlloc( 0, (*len
+ 1) * sizeof(WCHAR
) );
1560 copy_char_to_wchar_sz( (BYTE
*)(len
+ 1), *len
, proxy
);
1561 len
= (DWORD
*)((BYTE
*)(len
+ 1) + *len
);
1565 /* Sanity-check length of proxy bypass string */
1566 if ((BYTE
*)len
- buf
+ *len
<= size
)
1568 proxy_bypass
= GlobalAlloc( 0, (*len
+ 1) * sizeof(WCHAR
) );
1570 copy_char_to_wchar_sz( (BYTE
*)(len
+ 1), *len
, proxy_bypass
);
1575 GlobalFree( proxy
);
1579 info
->lpszProxy
= proxy
;
1580 info
->lpszProxyBypass
= proxy_bypass
;
1583 got_from_reg
= TRUE
;
1585 info
->dwAccessType
=
1586 WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1587 TRACE("http proxy (from registry) = %s, bypass = %s\n",
1588 debugstr_w(info
->lpszProxy
),
1589 debugstr_w(info
->lpszProxyBypass
));
1598 if (!got_from_reg
&& (envproxy
= getenv( "http_proxy" )))
1600 char *colon
, *http_proxy
;
1602 if ((colon
= strchr( envproxy
, ':' )))
1604 if (*(colon
+ 1) == '/' && *(colon
+ 2) == '/')
1606 static const char http
[] = "http://";
1608 /* It's a scheme, check that it's http */
1609 if (!strncmp( envproxy
, http
, strlen( http
) ))
1610 http_proxy
= envproxy
+ strlen( http
);
1613 WARN("unsupported scheme in $http_proxy: %s\n", envproxy
);
1618 http_proxy
= envproxy
;
1621 http_proxy
= envproxy
;
1627 len
= MultiByteToWideChar( CP_UNIXCP
, 0, http_proxy
, -1, NULL
, 0 );
1628 if ((http_proxyW
= GlobalAlloc( 0, len
* sizeof(WCHAR
))))
1630 MultiByteToWideChar( CP_UNIXCP
, 0, http_proxy
, -1, http_proxyW
, len
);
1632 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1633 info
->lpszProxy
= http_proxyW
;
1634 info
->lpszProxyBypass
= NULL
;
1635 TRACE("http proxy (from environment) = %s\n",
1636 debugstr_w(info
->lpszProxy
));
1642 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NO_PROXY
;
1643 info
->lpszProxy
= NULL
;
1644 info
->lpszProxyBypass
= NULL
;
1646 set_last_error( ERROR_SUCCESS
);
1650 /***********************************************************************
1651 * WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
1653 BOOL WINAPI
WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG
*config
)
1655 static const WCHAR settingsW
[] =
1656 {'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};
1658 struct connection_settings_header
*hdr
= NULL
;
1659 DWORD type
, offset
, len
, size
= 0;
1662 TRACE("%p\n", config
);
1666 set_last_error( ERROR_INVALID_PARAMETER
);
1669 memset( config
, 0, sizeof(*config
) );
1670 config
->fAutoDetect
= TRUE
;
1672 if (RegOpenKeyExW( HKEY_CURRENT_USER
, Connections
, 0, KEY_READ
, &hkey
) ||
1673 RegQueryValueExW( hkey
, settingsW
, NULL
, &type
, NULL
, &size
) ||
1674 type
!= REG_BINARY
|| size
< sizeof(struct connection_settings_header
))
1679 if (!(hdr
= heap_alloc( size
))) goto done
;
1680 if (RegQueryValueExW( hkey
, settingsW
, NULL
, &type
, (BYTE
*)hdr
, &size
) ||
1681 hdr
->magic
!= WININET_SETTINGS_MAGIC
)
1687 config
->fAutoDetect
= (hdr
->flags
& PROXY_AUTODETECT_SETTINGS
) != 0;
1688 offset
= sizeof(*hdr
);
1689 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1690 len
= *(DWORD
*)((char *)hdr
+ offset
);
1691 offset
+= sizeof(DWORD
);
1692 if (len
&& hdr
->flags
& PROXY_TYPE_PROXY
)
1694 if (!(config
->lpszProxy
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1695 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszProxy
);
1698 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1699 len
= *(DWORD
*)((char *)hdr
+ offset
);
1700 offset
+= sizeof(DWORD
);
1701 if (len
&& (hdr
->flags
& PROXY_TYPE_PROXY
))
1703 if (!(config
->lpszProxyBypass
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1704 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszProxyBypass
);
1707 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1708 len
= *(DWORD
*)((char *)hdr
+ offset
);
1709 offset
+= sizeof(DWORD
);
1710 if (len
&& (hdr
->flags
& PROXY_USE_PAC_SCRIPT
))
1712 if (!(config
->lpszAutoConfigUrl
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1713 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszAutoConfigUrl
);
1718 RegCloseKey( hkey
);
1722 GlobalFree( config
->lpszAutoConfigUrl
);
1723 config
->lpszAutoConfigUrl
= NULL
;
1724 GlobalFree( config
->lpszProxy
);
1725 config
->lpszProxy
= NULL
;
1726 GlobalFree( config
->lpszProxyBypass
);
1727 config
->lpszProxyBypass
= NULL
;
1729 else set_last_error( ERROR_SUCCESS
);
1733 static BOOL
parse_script_result( const char *result
, WINHTTP_PROXY_INFO
*info
)
1739 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NO_PROXY
;
1740 info
->lpszProxy
= NULL
;
1741 info
->lpszProxyBypass
= NULL
;
1743 TRACE("%s\n", debugstr_a( result
));
1746 while (*p
== ' ') p
++;
1748 if (len
>= 5 && !strncasecmp( p
, "PROXY", sizeof("PROXY") - 1 ))
1751 while (*p
== ' ') p
++;
1752 if (!*p
|| *p
== ';') return TRUE
;
1753 if (!(info
->lpszProxy
= q
= strdupAW( p
))) return FALSE
;
1754 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1757 if (*q
== ' ' || *q
== ';')
1767 static char *download_script( const WCHAR
*url
, DWORD
*out_size
)
1769 static const WCHAR typeW
[] = {'*','/','*',0};
1770 static const WCHAR
*acceptW
[] = {typeW
, NULL
};
1771 HINTERNET ses
, con
= NULL
, req
= NULL
;
1774 DWORD status
, size
= sizeof(status
), offset
, to_read
, bytes_read
, flags
= 0;
1775 char *tmp
, *buffer
= NULL
;
1779 memset( &uc
, 0, sizeof(uc
) );
1780 uc
.dwStructSize
= sizeof(uc
);
1781 uc
.dwHostNameLength
= -1;
1782 uc
.dwUrlPathLength
= -1;
1783 if (!WinHttpCrackUrl( url
, 0, 0, &uc
)) return NULL
;
1784 if (!(hostname
= heap_alloc( (uc
.dwHostNameLength
+ 1) * sizeof(WCHAR
) ))) return NULL
;
1785 memcpy( hostname
, uc
.lpszHostName
, uc
.dwHostNameLength
* sizeof(WCHAR
) );
1786 hostname
[uc
.dwHostNameLength
] = 0;
1788 if (!(ses
= WinHttpOpen( NULL
, WINHTTP_ACCESS_TYPE_NO_PROXY
, NULL
, NULL
, 0 ))) goto done
;
1789 if (!(con
= WinHttpConnect( ses
, hostname
, uc
.nPort
, 0 ))) goto done
;
1790 if (uc
.nScheme
== INTERNET_SCHEME_HTTPS
) flags
|= WINHTTP_FLAG_SECURE
;
1791 if (!(req
= WinHttpOpenRequest( con
, NULL
, uc
.lpszUrlPath
, NULL
, NULL
, acceptW
, flags
))) goto done
;
1792 if (!WinHttpSendRequest( req
, NULL
, 0, NULL
, 0, 0, 0 )) goto done
;
1794 if (!(WinHttpReceiveResponse( req
, 0 ))) goto done
;
1795 if (!WinHttpQueryHeaders( req
, WINHTTP_QUERY_STATUS_CODE
|WINHTTP_QUERY_FLAG_NUMBER
, NULL
, &status
,
1796 &size
, NULL
) || status
!= HTTP_STATUS_OK
) goto done
;
1799 if (!(buffer
= heap_alloc( size
))) goto done
;
1804 if (!WinHttpReadData( req
, buffer
+ offset
, to_read
, &bytes_read
)) goto done
;
1805 if (!bytes_read
) break;
1806 to_read
-= bytes_read
;
1807 offset
+= bytes_read
;
1808 *out_size
+= bytes_read
;
1813 if (!(tmp
= heap_realloc( buffer
, size
))) goto done
;
1819 WinHttpCloseHandle( req
);
1820 WinHttpCloseHandle( con
);
1821 WinHttpCloseHandle( ses
);
1822 heap_free( hostname
);
1823 if (!buffer
) set_last_error( ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT
);
1827 struct AUTO_PROXY_SCRIPT_BUFFER
1830 LPSTR lpszScriptBuffer
;
1831 DWORD dwScriptBufferSize
;
1834 BOOL WINAPI
InternetDeInitializeAutoProxyDll(LPSTR
, DWORD
);
1835 BOOL WINAPI
InternetGetProxyInfo(LPCSTR
, DWORD
, LPSTR
, DWORD
, LPSTR
*, LPDWORD
);
1836 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD
, LPSTR
, LPSTR
, void *, struct AUTO_PROXY_SCRIPT_BUFFER
*);
1838 static BOOL
run_script( char *script
, DWORD size
, const WCHAR
*url
, WINHTTP_PROXY_INFO
*info
)
1841 char *result
, *urlA
;
1843 struct AUTO_PROXY_SCRIPT_BUFFER buffer
;
1846 buffer
.dwStructSize
= sizeof(buffer
);
1847 buffer
.lpszScriptBuffer
= script
;
1848 buffer
.dwScriptBufferSize
= size
;
1850 if (!(urlA
= strdupWA( url
))) return FALSE
;
1851 if (!(ret
= InternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buffer
)))
1857 memset( &uc
, 0, sizeof(uc
) );
1858 uc
.dwStructSize
= sizeof(uc
);
1859 uc
.dwHostNameLength
= -1;
1861 if (WinHttpCrackUrl( url
, 0, 0, &uc
))
1863 char *hostnameA
= strdupWA_sized( uc
.lpszHostName
, uc
.dwHostNameLength
);
1865 if ((ret
= InternetGetProxyInfo( urlA
, strlen(urlA
),
1866 hostnameA
, strlen(hostnameA
), &result
, &len_result
)))
1868 ret
= parse_script_result( result
, info
);
1869 heap_free( result
);
1872 heap_free( hostnameA
);
1875 return InternetDeInitializeAutoProxyDll( NULL
, 0 );
1878 /***********************************************************************
1879 * WinHttpGetProxyForUrl (winhttp.@)
1881 BOOL WINAPI
WinHttpGetProxyForUrl( HINTERNET hsession
, LPCWSTR url
, WINHTTP_AUTOPROXY_OPTIONS
*options
,
1882 WINHTTP_PROXY_INFO
*info
)
1884 WCHAR
*detected_pac_url
= NULL
;
1885 const WCHAR
*pac_url
;
1891 TRACE("%p, %s, %p, %p\n", hsession
, debugstr_w(url
), options
, info
);
1893 if (!(session
= (session_t
*)grab_object( hsession
)))
1895 set_last_error( ERROR_INVALID_HANDLE
);
1898 if (session
->hdr
.type
!= WINHTTP_HANDLE_TYPE_SESSION
)
1900 release_object( &session
->hdr
);
1901 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1904 if (!url
|| !options
|| !info
||
1905 !(options
->dwFlags
& (WINHTTP_AUTOPROXY_AUTO_DETECT
|WINHTTP_AUTOPROXY_CONFIG_URL
)) ||
1906 ((options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
) && !options
->dwAutoDetectFlags
) ||
1907 ((options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
) &&
1908 (options
->dwFlags
& WINHTTP_AUTOPROXY_CONFIG_URL
)))
1910 release_object( &session
->hdr
);
1911 set_last_error( ERROR_INVALID_PARAMETER
);
1914 if (options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
&&
1915 !WinHttpDetectAutoProxyConfigUrl( options
->dwAutoDetectFlags
, &detected_pac_url
))
1918 if (options
->dwFlags
& WINHTTP_AUTOPROXY_CONFIG_URL
) pac_url
= options
->lpszAutoConfigUrl
;
1919 else pac_url
= detected_pac_url
;
1921 if ((script
= download_script( pac_url
, &size
)))
1923 ret
= run_script( script
, size
, url
, info
);
1924 heap_free( script
);
1928 GlobalFree( detected_pac_url
);
1929 release_object( &session
->hdr
);
1930 if (ret
) set_last_error( ERROR_SUCCESS
);
1934 /***********************************************************************
1935 * WinHttpSetDefaultProxyConfiguration (winhttp.@)
1937 BOOL WINAPI
WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO
*info
)
1944 TRACE("%p\n", info
);
1948 set_last_error( ERROR_INVALID_PARAMETER
);
1951 switch (info
->dwAccessType
)
1953 case WINHTTP_ACCESS_TYPE_NO_PROXY
:
1955 case WINHTTP_ACCESS_TYPE_NAMED_PROXY
:
1956 if (!info
->lpszProxy
)
1958 set_last_error( ERROR_INVALID_PARAMETER
);
1961 /* Only ASCII characters are allowed */
1962 for (src
= info
->lpszProxy
; *src
; src
++)
1965 set_last_error( ERROR_INVALID_PARAMETER
);
1968 if (info
->lpszProxyBypass
)
1970 for (src
= info
->lpszProxyBypass
; *src
; src
++)
1973 set_last_error( ERROR_INVALID_PARAMETER
);
1979 set_last_error( ERROR_INVALID_PARAMETER
);
1983 l
= RegCreateKeyExW( HKEY_LOCAL_MACHINE
, Connections
, 0, NULL
, 0,
1984 KEY_WRITE
, NULL
, &key
, NULL
);
1987 DWORD size
= sizeof(struct connection_settings_header
) + 2 * sizeof(DWORD
);
1990 if (info
->dwAccessType
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
1992 size
+= strlenW( info
->lpszProxy
);
1993 if (info
->lpszProxyBypass
)
1994 size
+= strlenW( info
->lpszProxyBypass
);
1996 buf
= heap_alloc( size
);
1999 struct connection_settings_header
*hdr
=
2000 (struct connection_settings_header
*)buf
;
2001 DWORD
*len
= (DWORD
*)(hdr
+ 1);
2003 hdr
->magic
= WINHTTP_SETTINGS_MAGIC
;
2005 if (info
->dwAccessType
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
2009 hdr
->flags
= PROXY_TYPE_PROXY
;
2010 *len
++ = strlenW( info
->lpszProxy
);
2011 for (dst
= (BYTE
*)len
, src
= info
->lpszProxy
; *src
;
2015 if (info
->lpszProxyBypass
)
2017 *len
++ = strlenW( info
->lpszProxyBypass
);
2018 for (dst
= (BYTE
*)len
, src
= info
->lpszProxyBypass
; *src
;
2027 hdr
->flags
= PROXY_TYPE_DIRECT
;
2031 l
= RegSetValueExW( key
, WinHttpSettings
, 0, REG_BINARY
, buf
, size
);
2038 if (ret
) set_last_error( ERROR_SUCCESS
);
2042 /***********************************************************************
2043 * WinHttpSetStatusCallback (winhttp.@)
2045 WINHTTP_STATUS_CALLBACK WINAPI
WinHttpSetStatusCallback( HINTERNET handle
, WINHTTP_STATUS_CALLBACK callback
,
2046 DWORD flags
, DWORD_PTR reserved
)
2048 object_header_t
*hdr
;
2049 WINHTTP_STATUS_CALLBACK ret
;
2051 TRACE("%p, %p, 0x%08x, 0x%lx\n", handle
, callback
, flags
, reserved
);
2053 if (!(hdr
= grab_object( handle
)))
2055 set_last_error( ERROR_INVALID_HANDLE
);
2056 return WINHTTP_INVALID_STATUS_CALLBACK
;
2058 ret
= hdr
->callback
;
2059 hdr
->callback
= callback
;
2060 hdr
->notify_mask
= flags
;
2062 release_object( hdr
);
2063 set_last_error( ERROR_SUCCESS
);
2067 /***********************************************************************
2068 * WinHttpSetTimeouts (winhttp.@)
2070 BOOL WINAPI
WinHttpSetTimeouts( HINTERNET handle
, int resolve
, int connect
, int send
, int receive
)
2073 object_header_t
*hdr
;
2077 TRACE("%p, %d, %d, %d, %d\n", handle
, resolve
, connect
, send
, receive
);
2079 if (resolve
< -1 || connect
< -1 || send
< -1 || receive
< -1)
2081 set_last_error( ERROR_INVALID_PARAMETER
);
2085 if (!(hdr
= grab_object( handle
)))
2087 set_last_error( ERROR_INVALID_HANDLE
);
2093 case WINHTTP_HANDLE_TYPE_REQUEST
:
2094 request
= (request_t
*)hdr
;
2095 request
->connect_timeout
= connect
;
2097 if (resolve
< 0) resolve
= 0;
2098 request
->resolve_timeout
= resolve
;
2100 if (send
< 0) send
= 0;
2101 request
->send_timeout
= send
;
2103 if (receive
< 0) receive
= 0;
2104 request
->recv_timeout
= receive
;
2106 if (request
->netconn
)
2108 if (netconn_set_timeout( request
->netconn
, TRUE
, send
)) ret
= FALSE
;
2109 if (netconn_set_timeout( request
->netconn
, FALSE
, receive
)) ret
= FALSE
;
2113 case WINHTTP_HANDLE_TYPE_SESSION
:
2114 session
= (session_t
*)hdr
;
2115 session
->connect_timeout
= connect
;
2117 if (resolve
< 0) resolve
= 0;
2118 session
->resolve_timeout
= resolve
;
2120 if (send
< 0) send
= 0;
2121 session
->send_timeout
= send
;
2123 if (receive
< 0) receive
= 0;
2124 session
->recv_timeout
= receive
;
2128 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
2131 release_object( hdr
);
2132 if (ret
) set_last_error( ERROR_SUCCESS
);
2136 static const WCHAR wkday
[7][4] =
2137 {{'S','u','n', 0}, {'M','o','n', 0}, {'T','u','e', 0}, {'W','e','d', 0},
2138 {'T','h','u', 0}, {'F','r','i', 0}, {'S','a','t', 0}};
2139 static const WCHAR month
[12][4] =
2140 {{'J','a','n', 0}, {'F','e','b', 0}, {'M','a','r', 0}, {'A','p','r', 0},
2141 {'M','a','y', 0}, {'J','u','n', 0}, {'J','u','l', 0}, {'A','u','g', 0},
2142 {'S','e','p', 0}, {'O','c','t', 0}, {'N','o','v', 0}, {'D','e','c', 0}};
2144 /***********************************************************************
2145 * WinHttpTimeFromSystemTime (WININET.@)
2147 BOOL WINAPI
WinHttpTimeFromSystemTime( const SYSTEMTIME
*time
, LPWSTR string
)
2149 static const WCHAR format
[] =
2150 {'%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2151 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0};
2153 TRACE("%p, %p\n", time
, string
);
2155 if (!time
|| !string
)
2157 set_last_error( ERROR_INVALID_PARAMETER
);
2161 sprintfW( string
, format
,
2162 wkday
[time
->wDayOfWeek
],
2164 month
[time
->wMonth
- 1],
2170 set_last_error( ERROR_SUCCESS
);
2174 /***********************************************************************
2175 * WinHttpTimeToSystemTime (WININET.@)
2177 BOOL WINAPI
WinHttpTimeToSystemTime( LPCWSTR string
, SYSTEMTIME
*time
)
2180 const WCHAR
*s
= string
;
2183 TRACE("%s, %p\n", debugstr_w(string
), time
);
2185 if (!string
|| !time
)
2187 set_last_error( ERROR_INVALID_PARAMETER
);
2191 /* Windows does this too */
2192 GetSystemTime( time
);
2194 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2195 * a SYSTEMTIME structure.
2198 set_last_error( ERROR_SUCCESS
);
2200 while (*s
&& !isalphaW( *s
)) s
++;
2201 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2202 time
->wDayOfWeek
= 7;
2204 for (i
= 0; i
< 7; i
++)
2206 if (toupperW( wkday
[i
][0] ) == toupperW( s
[0] ) &&
2207 toupperW( wkday
[i
][1] ) == toupperW( s
[1] ) &&
2208 toupperW( wkday
[i
][2] ) == toupperW( s
[2] ) )
2210 time
->wDayOfWeek
= i
;
2215 if (time
->wDayOfWeek
> 6) return TRUE
;
2216 while (*s
&& !isdigitW( *s
)) s
++;
2217 time
->wDay
= strtolW( s
, &end
, 10 );
2220 while (*s
&& !isalphaW( *s
)) s
++;
2221 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2224 for (i
= 0; i
< 12; i
++)
2226 if (toupperW( month
[i
][0]) == toupperW( s
[0] ) &&
2227 toupperW( month
[i
][1]) == toupperW( s
[1] ) &&
2228 toupperW( month
[i
][2]) == toupperW( s
[2] ) )
2230 time
->wMonth
= i
+ 1;
2234 if (time
->wMonth
== 0) return TRUE
;
2236 while (*s
&& !isdigitW( *s
)) s
++;
2237 if (*s
== '\0') return TRUE
;
2238 time
->wYear
= strtolW( s
, &end
, 10 );
2241 while (*s
&& !isdigitW( *s
)) s
++;
2242 if (*s
== '\0') return TRUE
;
2243 time
->wHour
= strtolW( s
, &end
, 10 );
2246 while (*s
&& !isdigitW( *s
)) s
++;
2247 if (*s
== '\0') return TRUE
;
2248 time
->wMinute
= strtolW( s
, &end
, 10 );
2251 while (*s
&& !isdigitW( *s
)) s
++;
2252 if (*s
== '\0') return TRUE
;
2253 time
->wSecond
= strtolW( s
, &end
, 10 );
2255 time
->wMilliseconds
= 0;