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
36 #include "wine/debug.h"
37 #include "winhttp_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(winhttp
);
41 #define DEFAULT_RESOLVE_TIMEOUT 0
42 #define DEFAULT_CONNECT_TIMEOUT 20000
43 #define DEFAULT_SEND_TIMEOUT 30000
44 #define DEFAULT_RECEIVE_TIMEOUT 30000
45 #define DEFAULT_RECEIVE_RESPONSE_TIMEOUT ~0u
47 void send_callback( struct object_header
*hdr
, DWORD status
, void *info
, DWORD buflen
)
49 if (hdr
->callback
&& (hdr
->notify_mask
& status
))
51 TRACE("%p, 0x%08x, %p, %u\n", hdr
, status
, info
, buflen
);
52 hdr
->callback( hdr
->handle
, hdr
->context
, status
, info
, buflen
);
53 TRACE("returning from 0x%08x callback\n", status
);
57 /***********************************************************************
58 * WinHttpCheckPlatform (winhttp.@)
60 BOOL WINAPI
WinHttpCheckPlatform( void )
66 /***********************************************************************
67 * session_destroy (internal)
69 static void session_destroy( struct object_header
*hdr
)
71 struct session
*session
= (struct session
*)hdr
;
73 TRACE("%p\n", session
);
75 if (session
->unload_event
) SetEvent( session
->unload_event
);
76 destroy_cookies( session
);
78 session
->cs
.DebugInfo
->Spare
[0] = 0;
79 DeleteCriticalSection( &session
->cs
);
80 heap_free( session
->agent
);
81 heap_free( session
->proxy_server
);
82 heap_free( session
->proxy_bypass
);
83 heap_free( session
->proxy_username
);
84 heap_free( session
->proxy_password
);
88 static BOOL
session_query_option( struct object_header
*hdr
, DWORD option
, void *buffer
, DWORD
*buflen
)
90 struct session
*session
= (struct session
*)hdr
;
94 case WINHTTP_OPTION_REDIRECT_POLICY
:
96 if (!buffer
|| *buflen
< sizeof(DWORD
))
98 *buflen
= sizeof(DWORD
);
99 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
103 *(DWORD
*)buffer
= hdr
->redirect_policy
;
104 *buflen
= sizeof(DWORD
);
107 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
108 *(DWORD
*)buffer
= session
->resolve_timeout
;
109 *buflen
= sizeof(DWORD
);
112 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
113 *(DWORD
*)buffer
= session
->connect_timeout
;
114 *buflen
= sizeof(DWORD
);
117 case WINHTTP_OPTION_SEND_TIMEOUT
:
118 *(DWORD
*)buffer
= session
->send_timeout
;
119 *buflen
= sizeof(DWORD
);
122 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
123 *(DWORD
*)buffer
= session
->receive_timeout
;
124 *buflen
= sizeof(DWORD
);
127 case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT
:
128 *(DWORD
*)buffer
= session
->receive_response_timeout
;
129 *buflen
= sizeof(DWORD
);
133 FIXME("unimplemented option %u\n", option
);
134 SetLastError( ERROR_INVALID_PARAMETER
);
139 static BOOL
session_set_option( struct object_header
*hdr
, DWORD option
, void *buffer
, DWORD buflen
)
141 struct session
*session
= (struct session
*)hdr
;
145 case WINHTTP_OPTION_PROXY
:
147 WINHTTP_PROXY_INFO
*pi
= buffer
;
149 FIXME("%u %s %s\n", pi
->dwAccessType
, debugstr_w(pi
->lpszProxy
), debugstr_w(pi
->lpszProxyBypass
));
152 case WINHTTP_OPTION_REDIRECT_POLICY
:
156 if (buflen
!= sizeof(policy
))
158 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
162 policy
= *(DWORD
*)buffer
;
163 TRACE("0x%x\n", policy
);
164 hdr
->redirect_policy
= policy
;
167 case WINHTTP_OPTION_SECURE_PROTOCOLS
:
169 if (buflen
!= sizeof(session
->secure_protocols
))
171 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
174 EnterCriticalSection( &session
->cs
);
175 session
->secure_protocols
= *(DWORD
*)buffer
;
176 LeaveCriticalSection( &session
->cs
);
177 TRACE("0x%x\n", session
->secure_protocols
);
180 case WINHTTP_OPTION_DISABLE_FEATURE
:
181 SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
184 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
185 session
->resolve_timeout
= *(DWORD
*)buffer
;
188 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
189 session
->connect_timeout
= *(DWORD
*)buffer
;
192 case WINHTTP_OPTION_SEND_TIMEOUT
:
193 session
->send_timeout
= *(DWORD
*)buffer
;
196 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
197 session
->receive_timeout
= *(DWORD
*)buffer
;
200 case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT
:
201 session
->receive_response_timeout
= *(DWORD
*)buffer
;
204 case WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH
:
205 session
->passport_flags
= *(DWORD
*)buffer
;
208 case WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT
:
209 TRACE("WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT: %p\n", *(HANDLE
*)buffer
);
210 session
->unload_event
= *(HANDLE
*)buffer
;
213 case WINHTTP_OPTION_MAX_CONNS_PER_SERVER
:
214 FIXME("WINHTTP_OPTION_MAX_CONNS_PER_SERVER: %d\n", *(DWORD
*)buffer
);
217 case WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER
:
218 FIXME("WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER: %d\n", *(DWORD
*)buffer
);
222 FIXME("unimplemented option %u\n", option
);
223 SetLastError( ERROR_WINHTTP_INVALID_OPTION
);
228 static const struct object_vtbl session_vtbl
=
231 session_query_option
,
235 /***********************************************************************
236 * WinHttpOpen (winhttp.@)
238 HINTERNET WINAPI
WinHttpOpen( LPCWSTR agent
, DWORD access
, LPCWSTR proxy
, LPCWSTR bypass
, DWORD flags
)
240 struct session
*session
;
241 HINTERNET handle
= NULL
;
243 TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent
), access
, debugstr_w(proxy
), debugstr_w(bypass
), flags
);
245 if (!(session
= heap_alloc_zero( sizeof(struct session
) ))) return NULL
;
247 session
->hdr
.type
= WINHTTP_HANDLE_TYPE_SESSION
;
248 session
->hdr
.vtbl
= &session_vtbl
;
249 session
->hdr
.flags
= flags
;
250 session
->hdr
.refs
= 1;
251 session
->hdr
.redirect_policy
= WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP
;
252 list_init( &session
->hdr
.children
);
253 session
->resolve_timeout
= DEFAULT_RESOLVE_TIMEOUT
;
254 session
->connect_timeout
= DEFAULT_CONNECT_TIMEOUT
;
255 session
->send_timeout
= DEFAULT_SEND_TIMEOUT
;
256 session
->receive_timeout
= DEFAULT_RECEIVE_TIMEOUT
;
257 session
->receive_response_timeout
= DEFAULT_RECEIVE_RESPONSE_TIMEOUT
;
258 list_init( &session
->cookie_cache
);
259 InitializeCriticalSection( &session
->cs
);
260 session
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": session.cs");
262 if (agent
&& !(session
->agent
= strdupW( agent
))) goto end
;
263 if (access
== WINHTTP_ACCESS_TYPE_DEFAULT_PROXY
)
265 WINHTTP_PROXY_INFO info
;
267 WinHttpGetDefaultProxyConfiguration( &info
);
268 session
->access
= info
.dwAccessType
;
269 if (info
.lpszProxy
&& !(session
->proxy_server
= strdupW( info
.lpszProxy
)))
271 GlobalFree( info
.lpszProxy
);
272 GlobalFree( info
.lpszProxyBypass
);
275 if (info
.lpszProxyBypass
&& !(session
->proxy_bypass
= strdupW( info
.lpszProxyBypass
)))
277 GlobalFree( info
.lpszProxy
);
278 GlobalFree( info
.lpszProxyBypass
);
282 else if (access
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
284 session
->access
= access
;
285 if (proxy
&& !(session
->proxy_server
= strdupW( proxy
))) goto end
;
286 if (bypass
&& !(session
->proxy_bypass
= strdupW( bypass
))) goto end
;
289 if (!(handle
= alloc_handle( &session
->hdr
))) goto end
;
290 session
->hdr
.handle
= handle
;
293 release_object( &session
->hdr
);
294 TRACE("returning %p\n", handle
);
295 if (handle
) SetLastError( ERROR_SUCCESS
);
299 /***********************************************************************
300 * connect_destroy (internal)
302 static void connect_destroy( struct object_header
*hdr
)
304 struct connect
*connect
= (struct connect
*)hdr
;
306 TRACE("%p\n", connect
);
308 release_object( &connect
->session
->hdr
);
310 heap_free( connect
->hostname
);
311 heap_free( connect
->servername
);
312 heap_free( connect
->username
);
313 heap_free( connect
->password
);
314 heap_free( connect
);
317 static BOOL
connect_query_option( struct object_header
*hdr
, DWORD option
, void *buffer
, DWORD
*buflen
)
319 struct connect
*connect
= (struct connect
*)hdr
;
323 case WINHTTP_OPTION_PARENT_HANDLE
:
325 if (!buffer
|| *buflen
< sizeof(HINTERNET
))
327 *buflen
= sizeof(HINTERNET
);
328 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
332 *(HINTERNET
*)buffer
= ((struct object_header
*)connect
->session
)->handle
;
333 *buflen
= sizeof(HINTERNET
);
336 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
337 *(DWORD
*)buffer
= connect
->session
->resolve_timeout
;
338 *buflen
= sizeof(DWORD
);
341 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
342 *(DWORD
*)buffer
= connect
->session
->connect_timeout
;
343 *buflen
= sizeof(DWORD
);
346 case WINHTTP_OPTION_SEND_TIMEOUT
:
347 *(DWORD
*)buffer
= connect
->session
->send_timeout
;
348 *buflen
= sizeof(DWORD
);
351 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
352 *(DWORD
*)buffer
= connect
->session
->receive_timeout
;
353 *buflen
= sizeof(DWORD
);
356 case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT
:
357 *(DWORD
*)buffer
= connect
->session
->receive_response_timeout
;
358 *buflen
= sizeof(DWORD
);
362 FIXME("unimplemented option %u\n", option
);
363 SetLastError( ERROR_INVALID_PARAMETER
);
368 static const struct object_vtbl connect_vtbl
=
371 connect_query_option
,
375 static BOOL
domain_matches(LPCWSTR server
, LPCWSTR domain
)
379 if (!wcsicmp( domain
, L
"<local>" ) && !wcschr( server
, '.' ))
381 else if (*domain
== '*')
383 if (domain
[1] == '.')
387 /* For a hostname to match a wildcard, the last domain must match
388 * the wildcard exactly. E.g. if the wildcard is *.a.b, and the
389 * hostname is www.foo.a.b, it matches, but a.b does not.
391 dot
= wcschr( server
, '.' );
394 int len
= lstrlenW( dot
+ 1 );
396 if (len
> lstrlenW( domain
+ 2 ))
400 /* The server's domain is longer than the wildcard, so it
401 * could be a subdomain. Compare the last portion of the
404 ptr
= dot
+ len
+ 1 - lstrlenW( domain
+ 2 );
405 if (!wcsicmp( ptr
, domain
+ 2 ))
407 /* This is only a match if the preceding character is
408 * a '.', i.e. that it is a matching domain. E.g.
409 * if domain is '*.b.c' and server is 'www.ab.c' they
412 ret
= *(ptr
- 1) == '.';
416 ret
= !wcsicmp( dot
+ 1, domain
+ 2 );
421 ret
= !wcsicmp( server
, domain
);
425 /* Matches INTERNET_MAX_HOST_NAME_LENGTH in wininet.h, also RFC 1035 */
426 #define MAX_HOST_NAME_LENGTH 256
428 static BOOL
should_bypass_proxy(struct session
*session
, LPCWSTR server
)
433 if (!session
->proxy_bypass
) return FALSE
;
434 ptr
= session
->proxy_bypass
;
438 ptr
= wcschr( ptr
, ';' );
440 ptr
= wcschr( tmp
, ' ' );
443 if (ptr
- tmp
< MAX_HOST_NAME_LENGTH
)
445 WCHAR domain
[MAX_HOST_NAME_LENGTH
];
447 memcpy( domain
, tmp
, (ptr
- tmp
) * sizeof(WCHAR
) );
448 domain
[ptr
- tmp
] = 0;
449 ret
= domain_matches( server
, domain
);
454 ret
= domain_matches( server
, tmp
);
455 } while (ptr
&& !ret
);
459 BOOL
set_server_for_hostname( struct connect
*connect
, const WCHAR
*server
, INTERNET_PORT port
)
461 struct session
*session
= connect
->session
;
464 if (session
->proxy_server
&& !should_bypass_proxy(session
, server
))
468 if ((colon
= wcschr( session
->proxy_server
, ':' )))
470 if (!connect
->servername
|| wcsnicmp( connect
->servername
,
471 session
->proxy_server
, colon
- session
->proxy_server
- 1 ))
473 heap_free( connect
->servername
);
474 connect
->resolved
= FALSE
;
475 if (!(connect
->servername
= heap_alloc(
476 (colon
- session
->proxy_server
+ 1) * sizeof(WCHAR
) )))
481 memcpy( connect
->servername
, session
->proxy_server
,
482 (colon
- session
->proxy_server
) * sizeof(WCHAR
) );
483 connect
->servername
[colon
- session
->proxy_server
] = 0;
485 connect
->serverport
= wcstol( colon
+ 1, NULL
, 10 );
487 connect
->serverport
= INTERNET_DEFAULT_PORT
;
492 if (!connect
->servername
|| wcsicmp( connect
->servername
,
493 session
->proxy_server
))
495 heap_free( connect
->servername
);
496 connect
->resolved
= FALSE
;
497 if (!(connect
->servername
= strdupW( session
->proxy_server
)))
502 connect
->serverport
= INTERNET_DEFAULT_PORT
;
508 heap_free( connect
->servername
);
509 connect
->resolved
= FALSE
;
510 if (!(connect
->servername
= strdupW( server
)))
515 connect
->serverport
= port
;
521 /***********************************************************************
522 * WinHttpConnect (winhttp.@)
524 HINTERNET WINAPI
WinHttpConnect( HINTERNET hsession
, LPCWSTR server
, INTERNET_PORT port
, DWORD reserved
)
526 struct connect
*connect
;
527 struct session
*session
;
528 HINTERNET hconnect
= NULL
;
530 TRACE("%p, %s, %u, %x\n", hsession
, debugstr_w(server
), port
, reserved
);
534 SetLastError( ERROR_INVALID_PARAMETER
);
537 if (!(session
= (struct session
*)grab_object( hsession
)))
539 SetLastError( ERROR_INVALID_HANDLE
);
542 if (session
->hdr
.type
!= WINHTTP_HANDLE_TYPE_SESSION
)
544 release_object( &session
->hdr
);
545 SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
548 if (!(connect
= heap_alloc_zero( sizeof(struct connect
) )))
550 release_object( &session
->hdr
);
553 connect
->hdr
.type
= WINHTTP_HANDLE_TYPE_CONNECT
;
554 connect
->hdr
.vtbl
= &connect_vtbl
;
555 connect
->hdr
.refs
= 1;
556 connect
->hdr
.flags
= session
->hdr
.flags
;
557 connect
->hdr
.callback
= session
->hdr
.callback
;
558 connect
->hdr
.notify_mask
= session
->hdr
.notify_mask
;
559 connect
->hdr
.context
= session
->hdr
.context
;
560 connect
->hdr
.redirect_policy
= session
->hdr
.redirect_policy
;
561 list_init( &connect
->hdr
.children
);
563 addref_object( &session
->hdr
);
564 connect
->session
= session
;
565 list_add_head( &session
->hdr
.children
, &connect
->hdr
.entry
);
567 if (!(connect
->hostname
= strdupW( server
))) goto end
;
568 connect
->hostport
= port
;
569 if (!set_server_for_hostname( connect
, server
, port
)) goto end
;
571 if (!(hconnect
= alloc_handle( &connect
->hdr
))) goto end
;
572 connect
->hdr
.handle
= hconnect
;
574 send_callback( &session
->hdr
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
, &hconnect
, sizeof(hconnect
) );
577 release_object( &connect
->hdr
);
578 release_object( &session
->hdr
);
579 TRACE("returning %p\n", hconnect
);
580 if (hconnect
) SetLastError( ERROR_SUCCESS
);
584 /***********************************************************************
585 * request_destroy (internal)
587 static void request_destroy( struct object_header
*hdr
)
589 struct request
*request
= (struct request
*)hdr
;
592 TRACE("%p\n", request
);
594 if (request
->task_proc_running
)
596 /* Signal to the task proc to quit. It will call this again when it does. */
597 request
->task_proc_running
= FALSE
;
598 SetEvent( request
->task_cancel
);
601 release_object( &request
->connect
->hdr
);
603 if (request
->cred_handle_initialized
) FreeCredentialsHandle( &request
->cred_handle
);
604 CertFreeCertificateContext( request
->server_cert
);
605 CertFreeCertificateContext( request
->client_cert
);
607 destroy_authinfo( request
->authinfo
);
608 destroy_authinfo( request
->proxy_authinfo
);
610 heap_free( request
->verb
);
611 heap_free( request
->path
);
612 heap_free( request
->version
);
613 heap_free( request
->raw_headers
);
614 heap_free( request
->status_text
);
615 for (i
= 0; i
< request
->num_headers
; i
++)
617 heap_free( request
->headers
[i
].field
);
618 heap_free( request
->headers
[i
].value
);
620 heap_free( request
->headers
);
621 for (i
= 0; i
< TARGET_MAX
; i
++)
623 for (j
= 0; j
< SCHEME_MAX
; j
++)
625 heap_free( request
->creds
[i
][j
].username
);
626 heap_free( request
->creds
[i
][j
].password
);
629 heap_free( request
);
632 static void str_to_buffer( WCHAR
*buffer
, const WCHAR
*str
, LPDWORD buflen
)
635 if (str
) len
= lstrlenW( str
);
636 if (buffer
&& *buflen
> len
)
638 if (str
) memcpy( buffer
, str
, len
* sizeof(WCHAR
) );
641 *buflen
= len
* sizeof(WCHAR
);
644 static WCHAR
*blob_to_str( DWORD encoding
, CERT_NAME_BLOB
*blob
)
647 DWORD size
, format
= CERT_SIMPLE_NAME_STR
| CERT_NAME_STR_CRLF_FLAG
;
649 size
= CertNameToStrW( encoding
, blob
, format
, NULL
, 0 );
650 if ((ret
= LocalAlloc( 0, size
* sizeof(WCHAR
) )))
651 CertNameToStrW( encoding
, blob
, format
, ret
, size
);
656 static BOOL
copy_sockaddr( const struct sockaddr
*addr
, SOCKADDR_STORAGE
*addr_storage
)
658 switch (addr
->sa_family
)
662 struct sockaddr_in
*addr_in
= (struct sockaddr_in
*)addr_storage
;
664 memcpy( addr_in
, addr
, sizeof(*addr_in
) );
665 memset( addr_in
+ 1, 0, sizeof(*addr_storage
) - sizeof(*addr_in
) );
670 struct sockaddr_in6
*addr_in6
= (struct sockaddr_in6
*)addr_storage
;
672 memcpy( addr_in6
, addr
, sizeof(*addr_in6
) );
673 memset( addr_in6
+ 1, 0, sizeof(*addr_storage
) - sizeof(*addr_in6
) );
677 ERR("unhandled family %u\n", addr
->sa_family
);
682 static BOOL
request_query_option( struct object_header
*hdr
, DWORD option
, void *buffer
, DWORD
*buflen
)
684 struct request
*request
= (struct request
*)hdr
;
688 case WINHTTP_OPTION_SECURITY_FLAGS
:
693 if (!buffer
|| *buflen
< sizeof(flags
))
695 *buflen
= sizeof(flags
);
696 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
700 flags
= request
->security_flags
;
701 if (request
->netconn
)
703 bits
= netconn_get_cipher_strength( request
->netconn
);
705 flags
|= SECURITY_FLAG_STRENGTH_STRONG
;
707 flags
|= SECURITY_FLAG_STRENGTH_MEDIUM
;
709 flags
|= SECURITY_FLAG_STRENGTH_WEAK
;
711 *(DWORD
*)buffer
= flags
;
712 *buflen
= sizeof(flags
);
715 case WINHTTP_OPTION_SERVER_CERT_CONTEXT
:
717 const CERT_CONTEXT
*cert
;
719 if (!buffer
|| *buflen
< sizeof(cert
))
721 *buflen
= sizeof(cert
);
722 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
726 if (!(cert
= CertDuplicateCertificateContext( request
->server_cert
))) return FALSE
;
727 *(CERT_CONTEXT
**)buffer
= (CERT_CONTEXT
*)cert
;
728 *buflen
= sizeof(cert
);
731 case WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT
:
733 const CERT_CONTEXT
*cert
= request
->server_cert
;
734 const CRYPT_OID_INFO
*oidInfo
;
735 WINHTTP_CERTIFICATE_INFO
*ci
= buffer
;
737 FIXME("partial stub\n");
739 if (!buffer
|| *buflen
< sizeof(*ci
))
741 *buflen
= sizeof(*ci
);
742 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
745 if (!cert
) return FALSE
;
747 ci
->ftExpiry
= cert
->pCertInfo
->NotAfter
;
748 ci
->ftStart
= cert
->pCertInfo
->NotBefore
;
749 ci
->lpszSubjectInfo
= blob_to_str( cert
->dwCertEncodingType
, &cert
->pCertInfo
->Subject
);
750 ci
->lpszIssuerInfo
= blob_to_str( cert
->dwCertEncodingType
, &cert
->pCertInfo
->Issuer
);
751 ci
->lpszProtocolName
= NULL
;
752 oidInfo
= CryptFindOIDInfo( CRYPT_OID_INFO_OID_KEY
, cert
->pCertInfo
->SignatureAlgorithm
.pszObjId
, 0 );
754 ci
->lpszSignatureAlgName
= (LPWSTR
)oidInfo
->pwszName
;
756 ci
->lpszSignatureAlgName
= NULL
;
757 ci
->lpszEncryptionAlgName
= NULL
;
758 ci
->dwKeySize
= request
->netconn
? netconn_get_cipher_strength( request
->netconn
) : 0;
760 *buflen
= sizeof(*ci
);
763 case WINHTTP_OPTION_SECURITY_KEY_BITNESS
:
765 if (!buffer
|| *buflen
< sizeof(DWORD
))
767 *buflen
= sizeof(DWORD
);
768 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
772 *(DWORD
*)buffer
= request
->netconn
? netconn_get_cipher_strength( request
->netconn
) : 0;
773 *buflen
= sizeof(DWORD
);
776 case WINHTTP_OPTION_CONNECTION_INFO
:
778 WINHTTP_CONNECTION_INFO
*info
= buffer
;
779 struct sockaddr local
;
780 socklen_t len
= sizeof(local
);
781 const struct sockaddr
*remote
= (const struct sockaddr
*)&request
->connect
->sockaddr
;
783 if (!buffer
|| *buflen
< sizeof(*info
))
785 *buflen
= sizeof(*info
);
786 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
789 if (!request
->netconn
)
791 SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_STATE
);
794 if (getsockname( request
->netconn
->socket
, &local
, &len
)) return FALSE
;
795 if (!copy_sockaddr( &local
, &info
->LocalAddress
)) return FALSE
;
796 if (!copy_sockaddr( remote
, &info
->RemoteAddress
)) return FALSE
;
797 info
->cbSize
= sizeof(*info
);
800 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
801 *(DWORD
*)buffer
= request
->resolve_timeout
;
802 *buflen
= sizeof(DWORD
);
805 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
806 *(DWORD
*)buffer
= request
->connect_timeout
;
807 *buflen
= sizeof(DWORD
);
810 case WINHTTP_OPTION_SEND_TIMEOUT
:
811 *(DWORD
*)buffer
= request
->send_timeout
;
812 *buflen
= sizeof(DWORD
);
815 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
816 *(DWORD
*)buffer
= request
->receive_timeout
;
817 *buflen
= sizeof(DWORD
);
820 case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT
:
821 *(DWORD
*)buffer
= request
->receive_response_timeout
;
822 *buflen
= sizeof(DWORD
);
825 case WINHTTP_OPTION_USERNAME
:
826 str_to_buffer( buffer
, request
->connect
->username
, buflen
);
829 case WINHTTP_OPTION_PASSWORD
:
830 str_to_buffer( buffer
, request
->connect
->password
, buflen
);
833 case WINHTTP_OPTION_PROXY_USERNAME
:
834 str_to_buffer( buffer
, request
->connect
->session
->proxy_username
, buflen
);
837 case WINHTTP_OPTION_PROXY_PASSWORD
:
838 str_to_buffer( buffer
, request
->connect
->session
->proxy_password
, buflen
);
842 FIXME("unimplemented option %u\n", option
);
843 SetLastError( ERROR_INVALID_PARAMETER
);
848 static WCHAR
*buffer_to_str( WCHAR
*buffer
, DWORD buflen
)
851 if ((ret
= heap_alloc( (buflen
+ 1) * sizeof(WCHAR
))))
853 memcpy( ret
, buffer
, buflen
* sizeof(WCHAR
) );
857 SetLastError( ERROR_OUTOFMEMORY
);
861 static BOOL
request_set_option( struct object_header
*hdr
, DWORD option
, void *buffer
, DWORD buflen
)
863 struct request
*request
= (struct request
*)hdr
;
867 case WINHTTP_OPTION_PROXY
:
869 WINHTTP_PROXY_INFO
*pi
= buffer
;
871 FIXME("%u %s %s\n", pi
->dwAccessType
, debugstr_w(pi
->lpszProxy
), debugstr_w(pi
->lpszProxyBypass
));
874 case WINHTTP_OPTION_DISABLE_FEATURE
:
878 if (buflen
!= sizeof(DWORD
))
880 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
884 disable
= *(DWORD
*)buffer
;
885 TRACE("0x%x\n", disable
);
886 hdr
->disable_flags
|= disable
;
889 case WINHTTP_OPTION_AUTOLOGON_POLICY
:
893 if (buflen
!= sizeof(DWORD
))
895 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
899 policy
= *(DWORD
*)buffer
;
900 TRACE("0x%x\n", policy
);
901 hdr
->logon_policy
= policy
;
904 case WINHTTP_OPTION_REDIRECT_POLICY
:
908 if (buflen
!= sizeof(DWORD
))
910 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
914 policy
= *(DWORD
*)buffer
;
915 TRACE("0x%x\n", policy
);
916 hdr
->redirect_policy
= policy
;
919 case WINHTTP_OPTION_SECURITY_FLAGS
:
922 static const DWORD accepted
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|
923 SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
|
924 SECURITY_FLAG_IGNORE_UNKNOWN_CA
|
925 SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE
;
927 if (buflen
< sizeof(DWORD
))
929 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
932 flags
= *(DWORD
*)buffer
;
933 TRACE("0x%x\n", flags
);
934 if (flags
&& (flags
& ~accepted
))
936 SetLastError( ERROR_INVALID_PARAMETER
);
939 request
->security_flags
= flags
;
942 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
943 request
->resolve_timeout
= *(DWORD
*)buffer
;
946 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
947 request
->connect_timeout
= *(DWORD
*)buffer
;
950 case WINHTTP_OPTION_SEND_TIMEOUT
:
951 request
->send_timeout
= *(DWORD
*)buffer
;
954 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
955 request
->receive_timeout
= *(DWORD
*)buffer
;
958 case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT
:
959 request
->receive_response_timeout
= *(DWORD
*)buffer
;
962 case WINHTTP_OPTION_USERNAME
:
964 struct connect
*connect
= request
->connect
;
966 heap_free( connect
->username
);
967 if (!(connect
->username
= buffer_to_str( buffer
, buflen
))) return FALSE
;
970 case WINHTTP_OPTION_PASSWORD
:
972 struct connect
*connect
= request
->connect
;
974 heap_free( connect
->password
);
975 if (!(connect
->password
= buffer_to_str( buffer
, buflen
))) return FALSE
;
978 case WINHTTP_OPTION_PROXY_USERNAME
:
980 struct session
*session
= request
->connect
->session
;
982 heap_free( session
->proxy_username
);
983 if (!(session
->proxy_username
= buffer_to_str( buffer
, buflen
))) return FALSE
;
986 case WINHTTP_OPTION_PROXY_PASSWORD
:
988 struct session
*session
= request
->connect
->session
;
990 heap_free( session
->proxy_password
);
991 if (!(session
->proxy_password
= buffer_to_str( buffer
, buflen
))) return FALSE
;
994 case WINHTTP_OPTION_CLIENT_CERT_CONTEXT
:
996 const CERT_CONTEXT
*cert
;
998 if (!(hdr
->flags
& WINHTTP_FLAG_SECURE
))
1000 SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_STATE
);
1005 CertFreeCertificateContext( request
->client_cert
);
1006 request
->client_cert
= NULL
;
1008 else if (buflen
>= sizeof(cert
))
1010 if (!(cert
= CertDuplicateCertificateContext( buffer
))) return FALSE
;
1011 CertFreeCertificateContext( request
->client_cert
);
1012 request
->client_cert
= cert
;
1016 SetLastError( ERROR_INVALID_PARAMETER
);
1020 if (request
->cred_handle_initialized
)
1022 FreeCredentialsHandle( &request
->cred_handle
);
1023 request
->cred_handle_initialized
= FALSE
;
1028 case WINHTTP_OPTION_ENABLE_FEATURE
:
1029 if(buflen
== sizeof( DWORD
) && *(DWORD
*)buffer
== WINHTTP_ENABLE_SSL_REVOCATION
)
1031 request
->check_revocation
= TRUE
;
1032 SetLastError( NO_ERROR
);
1037 SetLastError( ERROR_INVALID_PARAMETER
);
1041 case WINHTTP_OPTION_CONNECT_RETRIES
:
1042 FIXME("WINHTTP_OPTION_CONNECT_RETRIES\n");
1046 FIXME("unimplemented option %u\n", option
);
1047 SetLastError( ERROR_WINHTTP_INVALID_OPTION
);
1052 static const struct object_vtbl request_vtbl
=
1055 request_query_option
,
1059 static BOOL
add_accept_types_header( struct request
*request
, const WCHAR
**types
)
1061 static const DWORD flags
= WINHTTP_ADDREQ_FLAG_ADD
| WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
;
1063 if (!types
) return TRUE
;
1066 if (!process_header( request
, L
"Accept", *types
, flags
, TRUE
)) return FALSE
;
1072 static WCHAR
*get_request_path( const WCHAR
*object
)
1074 int len
= object
? lstrlenW(object
) : 0;
1077 if (!object
|| object
[0] != '/') len
++;
1078 if (!(p
= ret
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) ))) return NULL
;
1079 if (!object
|| object
[0] != '/') *p
++ = '/';
1080 if (object
) lstrcpyW( p
, object
);
1085 /***********************************************************************
1086 * WinHttpOpenRequest (winhttp.@)
1088 HINTERNET WINAPI
WinHttpOpenRequest( HINTERNET hconnect
, LPCWSTR verb
, LPCWSTR object
, LPCWSTR version
,
1089 LPCWSTR referrer
, LPCWSTR
*types
, DWORD flags
)
1091 struct request
*request
;
1092 struct connect
*connect
;
1093 HINTERNET hrequest
= NULL
;
1095 TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect
, debugstr_w(verb
), debugstr_w(object
),
1096 debugstr_w(version
), debugstr_w(referrer
), types
, flags
);
1098 if (types
&& TRACE_ON(winhttp
))
1101 TRACE("accept types:\n");
1102 for (iter
= types
; *iter
; iter
++) TRACE(" %s\n", debugstr_w(*iter
));
1105 if (!(connect
= (struct connect
*)grab_object( hconnect
)))
1107 SetLastError( ERROR_INVALID_HANDLE
);
1110 if (connect
->hdr
.type
!= WINHTTP_HANDLE_TYPE_CONNECT
)
1112 release_object( &connect
->hdr
);
1113 SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1116 if (!(request
= heap_alloc_zero( sizeof(struct request
) )))
1118 release_object( &connect
->hdr
);
1121 request
->hdr
.type
= WINHTTP_HANDLE_TYPE_REQUEST
;
1122 request
->hdr
.vtbl
= &request_vtbl
;
1123 request
->hdr
.refs
= 1;
1124 request
->hdr
.flags
= flags
;
1125 request
->hdr
.callback
= connect
->hdr
.callback
;
1126 request
->hdr
.notify_mask
= connect
->hdr
.notify_mask
;
1127 request
->hdr
.context
= connect
->hdr
.context
;
1128 request
->hdr
.redirect_policy
= connect
->hdr
.redirect_policy
;
1129 list_init( &request
->hdr
.children
);
1130 list_init( &request
->task_queue
);
1132 addref_object( &connect
->hdr
);
1133 request
->connect
= connect
;
1134 list_add_head( &connect
->hdr
.children
, &request
->hdr
.entry
);
1136 request
->resolve_timeout
= connect
->session
->resolve_timeout
;
1137 request
->connect_timeout
= connect
->session
->connect_timeout
;
1138 request
->send_timeout
= connect
->session
->send_timeout
;
1139 request
->receive_timeout
= connect
->session
->receive_timeout
;
1140 request
->receive_response_timeout
= connect
->session
->receive_response_timeout
;
1142 if (!verb
|| !verb
[0]) verb
= L
"GET";
1143 if (!(request
->verb
= strdupW( verb
))) goto end
;
1144 if (!(request
->path
= get_request_path( object
))) goto end
;
1146 if (!version
|| !version
[0]) version
= L
"HTTP/1.1";
1147 if (!(request
->version
= strdupW( version
))) goto end
;
1148 if (!(add_accept_types_header( request
, types
))) goto end
;
1150 if (!(hrequest
= alloc_handle( &request
->hdr
))) goto end
;
1151 request
->hdr
.handle
= hrequest
;
1153 send_callback( &request
->hdr
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
, &hrequest
, sizeof(hrequest
) );
1156 release_object( &request
->hdr
);
1157 release_object( &connect
->hdr
);
1158 TRACE("returning %p\n", hrequest
);
1159 if (hrequest
) SetLastError( ERROR_SUCCESS
);
1163 /***********************************************************************
1164 * WinHttpCloseHandle (winhttp.@)
1166 BOOL WINAPI
WinHttpCloseHandle( HINTERNET handle
)
1168 struct object_header
*hdr
;
1170 TRACE("%p\n", handle
);
1172 if (!(hdr
= grab_object( handle
)))
1174 SetLastError( ERROR_INVALID_HANDLE
);
1177 release_object( hdr
);
1178 free_handle( handle
);
1179 SetLastError( ERROR_SUCCESS
);
1183 static BOOL
query_option( struct object_header
*hdr
, DWORD option
, void *buffer
, DWORD
*buflen
)
1189 SetLastError( ERROR_INVALID_PARAMETER
);
1195 case WINHTTP_OPTION_CONTEXT_VALUE
:
1197 if (!buffer
|| *buflen
< sizeof(DWORD_PTR
))
1199 *buflen
= sizeof(DWORD_PTR
);
1200 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1204 *(DWORD_PTR
*)buffer
= hdr
->context
;
1205 *buflen
= sizeof(DWORD_PTR
);
1209 if (hdr
->vtbl
->query_option
) ret
= hdr
->vtbl
->query_option( hdr
, option
, buffer
, buflen
);
1212 FIXME("unimplemented option %u\n", option
);
1213 SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1221 /***********************************************************************
1222 * WinHttpQueryOption (winhttp.@)
1224 BOOL WINAPI
WinHttpQueryOption( HINTERNET handle
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
1227 struct object_header
*hdr
;
1229 TRACE("%p, %u, %p, %p\n", handle
, option
, buffer
, buflen
);
1231 if (!(hdr
= grab_object( handle
)))
1233 SetLastError( ERROR_INVALID_HANDLE
);
1237 ret
= query_option( hdr
, option
, buffer
, buflen
);
1239 release_object( hdr
);
1240 if (ret
) SetLastError( ERROR_SUCCESS
);
1244 static BOOL
set_option( struct object_header
*hdr
, DWORD option
, void *buffer
, DWORD buflen
)
1248 if (!buffer
&& buflen
)
1250 SetLastError( ERROR_INVALID_PARAMETER
);
1256 case WINHTTP_OPTION_CONTEXT_VALUE
:
1258 if (buflen
!= sizeof(DWORD_PTR
))
1260 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1264 hdr
->context
= *(DWORD_PTR
*)buffer
;
1268 if (hdr
->vtbl
->set_option
) ret
= hdr
->vtbl
->set_option( hdr
, option
, buffer
, buflen
);
1271 FIXME("unimplemented option %u\n", option
);
1272 SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1280 /***********************************************************************
1281 * WinHttpSetOption (winhttp.@)
1283 BOOL WINAPI
WinHttpSetOption( HINTERNET handle
, DWORD option
, LPVOID buffer
, DWORD buflen
)
1286 struct object_header
*hdr
;
1288 TRACE("%p, %u, %p, %u\n", handle
, option
, buffer
, buflen
);
1290 if (!(hdr
= grab_object( handle
)))
1292 SetLastError( ERROR_INVALID_HANDLE
);
1296 ret
= set_option( hdr
, option
, buffer
, buflen
);
1298 release_object( hdr
);
1299 if (ret
) SetLastError( ERROR_SUCCESS
);
1303 static IP_ADAPTER_ADDRESSES
*get_adapters(void)
1305 ULONG err
, size
= 1024, flags
= GAA_FLAG_SKIP_ANYCAST
| GAA_FLAG_SKIP_MULTICAST
|
1306 GAA_FLAG_SKIP_DNS_SERVER
| GAA_FLAG_SKIP_FRIENDLY_NAME
;
1307 IP_ADAPTER_ADDRESSES
*tmp
, *ret
;
1309 if (!(ret
= heap_alloc( size
))) return NULL
;
1310 err
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, ret
, &size
);
1311 while (err
== ERROR_BUFFER_OVERFLOW
)
1313 if (!(tmp
= heap_realloc( ret
, size
))) break;
1315 err
= GetAdaptersAddresses( AF_UNSPEC
, flags
, NULL
, ret
, &size
);
1317 if (err
== ERROR_SUCCESS
) return ret
;
1322 static WCHAR
*detect_autoproxyconfig_url_dhcp(void)
1324 IP_ADAPTER_ADDRESSES
*adapters
, *ptr
;
1325 DHCPCAPI_PARAMS_ARRAY send_params
, recv_params
;
1326 DHCPCAPI_PARAMS param
;
1327 WCHAR name
[MAX_ADAPTER_NAME_LENGTH
+ 1], *ret
= NULL
;
1329 BYTE
*tmp
, *buf
= NULL
;
1331 if (!(adapters
= get_adapters())) return NULL
;
1333 memset( &send_params
, 0, sizeof(send_params
) );
1334 memset( ¶m
, 0, sizeof(param
) );
1335 param
.OptionId
= OPTION_MSFT_IE_PROXY
;
1336 recv_params
.nParams
= 1;
1337 recv_params
.Params
= ¶m
;
1339 for (ptr
= adapters
; ptr
; ptr
= ptr
->Next
)
1341 MultiByteToWideChar( CP_ACP
, 0, ptr
->AdapterName
, -1, name
, ARRAY_SIZE(name
) );
1342 TRACE( "adapter '%s' type %u dhcpv4 enabled %d\n", wine_dbgstr_w(name
), ptr
->IfType
, ptr
->Dhcpv4Enabled
);
1344 if (ptr
->IfType
== IF_TYPE_SOFTWARE_LOOPBACK
) continue;
1345 /* FIXME: also skip adapters where DHCP is disabled */
1348 if (!(buf
= heap_alloc( size
))) goto done
;
1349 err
= DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS
, NULL
, name
, NULL
, send_params
, recv_params
,
1351 while (err
== ERROR_MORE_DATA
)
1353 if (!(tmp
= heap_realloc( buf
, size
))) goto done
;
1355 err
= DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS
, NULL
, name
, NULL
, send_params
, recv_params
,
1358 if (err
== ERROR_SUCCESS
&& param
.nBytesData
)
1360 int len
= MultiByteToWideChar( CP_ACP
, 0, (const char *)param
.Data
, param
.nBytesData
, NULL
, 0 );
1361 if ((ret
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
1363 MultiByteToWideChar( CP_ACP
, 0, (const char *)param
.Data
, param
.nBytesData
, ret
, len
);
1366 TRACE("returning %s\n", debugstr_w(ret
));
1373 heap_free( adapters
);
1377 static char *get_computer_name( COMPUTER_NAME_FORMAT format
)
1382 GetComputerNameExA( format
, NULL
, &size
);
1383 if (GetLastError() != ERROR_MORE_DATA
) return NULL
;
1384 if (!(ret
= heap_alloc( size
))) return NULL
;
1385 if (!GetComputerNameExA( format
, ret
, &size
))
1393 static BOOL
is_domain_suffix( const char *domain
, const char *suffix
)
1395 int len_domain
= strlen( domain
), len_suffix
= strlen( suffix
);
1397 if (len_suffix
> len_domain
) return FALSE
;
1398 if (!stricmp( domain
+ len_domain
- len_suffix
, suffix
)) return TRUE
;
1402 static int reverse_lookup( const struct addrinfo
*ai
, char *hostname
, size_t len
)
1404 return getnameinfo( ai
->ai_addr
, ai
->ai_addrlen
, hostname
, len
, NULL
, 0, 0 );
1407 static WCHAR
*build_wpad_url( const char *hostname
, const struct addrinfo
*ai
)
1409 char name
[NI_MAXHOST
];
1413 while (ai
&& ai
->ai_family
!= AF_INET
&& ai
->ai_family
!= AF_INET6
) ai
= ai
->ai_next
;
1414 if (!ai
) return NULL
;
1416 if (!reverse_lookup( ai
, name
, sizeof(name
) )) hostname
= name
;
1418 len
= lstrlenW( L
"http://" ) + strlen( hostname
) + lstrlenW( L
"/wpad.dat" );
1419 if (!(ret
= p
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) return NULL
;
1420 lstrcpyW( p
, L
"http://" );
1421 p
+= lstrlenW( L
"http://" );
1422 while (*hostname
) { *p
++ = *hostname
++; }
1423 lstrcpyW( p
, L
"/wpad.dat" );
1427 static WCHAR
*detect_autoproxyconfig_url_dns(void)
1429 char *fqdn
, *domain
, *p
;
1432 if (!(fqdn
= get_computer_name( ComputerNamePhysicalDnsFullyQualified
))) return NULL
;
1433 if (!(domain
= get_computer_name( ComputerNamePhysicalDnsDomain
)))
1439 while ((p
= strchr( p
, '.' )) && is_domain_suffix( p
+ 1, domain
))
1442 struct addrinfo
*ai
;
1445 if (!(name
= heap_alloc( sizeof("wpad") + strlen(p
) )))
1448 heap_free( domain
);
1451 strcpy( name
, "wpad" );
1453 res
= getaddrinfo( name
, NULL
, NULL
, &ai
);
1456 ret
= build_wpad_url( name
, ai
);
1460 TRACE("returning %s\n", debugstr_w(ret
));
1468 heap_free( domain
);
1473 /***********************************************************************
1474 * WinHttpDetectAutoProxyConfigUrl (winhttp.@)
1476 BOOL WINAPI
WinHttpDetectAutoProxyConfigUrl( DWORD flags
, LPWSTR
*url
)
1478 TRACE("0x%08x, %p\n", flags
, url
);
1482 SetLastError( ERROR_INVALID_PARAMETER
);
1486 if (flags
& WINHTTP_AUTO_DETECT_TYPE_DHCP
)
1488 *url
= detect_autoproxyconfig_url_dhcp();
1490 if (flags
& WINHTTP_AUTO_DETECT_TYPE_DNS_A
)
1492 if (!*url
) *url
= detect_autoproxyconfig_url_dns();
1496 SetLastError( ERROR_WINHTTP_AUTODETECTION_FAILED
);
1499 SetLastError( ERROR_SUCCESS
);
1503 static const WCHAR path_connections
[] =
1504 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections";
1506 static const DWORD WINHTTP_SETTINGS_MAGIC
= 0x18;
1507 static const DWORD WININET_SETTINGS_MAGIC
= 0x46;
1508 static const DWORD PROXY_TYPE_DIRECT
= 1;
1509 static const DWORD PROXY_TYPE_PROXY
= 2;
1510 static const DWORD PROXY_USE_PAC_SCRIPT
= 4;
1511 static const DWORD PROXY_AUTODETECT_SETTINGS
= 8;
1513 struct connection_settings_header
1516 DWORD unknown
; /* always zero? */
1517 DWORD flags
; /* one or more of PROXY_* */
1520 static inline void copy_char_to_wchar_sz(const BYTE
*src
, DWORD len
, WCHAR
*dst
)
1524 for (begin
= src
; src
- begin
< len
; src
++, dst
++)
1529 /***********************************************************************
1530 * WinHttpGetDefaultProxyConfiguration (winhttp.@)
1532 BOOL WINAPI
WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO
*info
)
1536 BOOL got_from_reg
= FALSE
, direct
= TRUE
;
1539 TRACE("%p\n", info
);
1541 l
= RegOpenKeyExW( HKEY_LOCAL_MACHINE
, path_connections
, 0, KEY_READ
, &key
);
1544 DWORD type
, size
= 0;
1546 l
= RegQueryValueExW( key
, L
"WinHttpSettings", NULL
, &type
, NULL
, &size
);
1547 if (!l
&& type
== REG_BINARY
&&
1548 size
>= sizeof(struct connection_settings_header
) + 2 * sizeof(DWORD
))
1550 BYTE
*buf
= heap_alloc( size
);
1554 struct connection_settings_header
*hdr
=
1555 (struct connection_settings_header
*)buf
;
1556 DWORD
*len
= (DWORD
*)(hdr
+ 1);
1558 l
= RegQueryValueExW( key
, L
"WinHttpSettings", NULL
, NULL
, buf
,
1560 if (!l
&& hdr
->magic
== WINHTTP_SETTINGS_MAGIC
&&
1563 if (hdr
->flags
& PROXY_TYPE_PROXY
)
1566 LPWSTR proxy
= NULL
;
1567 LPWSTR proxy_bypass
= NULL
;
1569 /* Sanity-check length of proxy string */
1570 if ((BYTE
*)len
- buf
+ *len
<= size
)
1573 proxy
= GlobalAlloc( 0, (*len
+ 1) * sizeof(WCHAR
) );
1575 copy_char_to_wchar_sz( (BYTE
*)(len
+ 1), *len
, proxy
);
1576 len
= (DWORD
*)((BYTE
*)(len
+ 1) + *len
);
1580 /* Sanity-check length of proxy bypass string */
1581 if ((BYTE
*)len
- buf
+ *len
<= size
)
1583 proxy_bypass
= GlobalAlloc( 0, (*len
+ 1) * sizeof(WCHAR
) );
1585 copy_char_to_wchar_sz( (BYTE
*)(len
+ 1), *len
, proxy_bypass
);
1590 GlobalFree( proxy
);
1594 info
->lpszProxy
= proxy
;
1595 info
->lpszProxyBypass
= proxy_bypass
;
1598 got_from_reg
= TRUE
;
1600 info
->dwAccessType
=
1601 WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1602 TRACE("http proxy (from registry) = %s, bypass = %s\n",
1603 debugstr_w(info
->lpszProxy
),
1604 debugstr_w(info
->lpszProxyBypass
));
1613 if (!got_from_reg
&& (envproxy
= _wgetenv( L
"http_proxy" )))
1615 WCHAR
*colon
, *http_proxy
= NULL
;
1617 if (!(colon
= wcschr( envproxy
, ':' ))) http_proxy
= envproxy
;
1620 if (*(colon
+ 1) == '/' && *(colon
+ 2) == '/')
1622 /* It's a scheme, check that it's http */
1623 if (!wcsncmp( envproxy
, L
"http://", 7 )) http_proxy
= envproxy
+ 7;
1624 else WARN("unsupported scheme in $http_proxy: %s\n", debugstr_w(envproxy
));
1626 else http_proxy
= envproxy
;
1629 if (http_proxy
&& http_proxy
[0])
1632 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1633 info
->lpszProxy
= GlobalAlloc( 0, (lstrlenW(http_proxy
) + 1) * sizeof(WCHAR
) );
1634 wcscpy( info
->lpszProxy
, http_proxy
);
1635 info
->lpszProxyBypass
= NULL
;
1636 TRACE("http proxy (from environment) = %s\n", debugstr_w(info
->lpszProxy
));
1641 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NO_PROXY
;
1642 info
->lpszProxy
= NULL
;
1643 info
->lpszProxyBypass
= NULL
;
1645 SetLastError( ERROR_SUCCESS
);
1649 /***********************************************************************
1650 * WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
1652 BOOL WINAPI
WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG
*config
)
1655 struct connection_settings_header
*hdr
= NULL
;
1656 DWORD type
, offset
, len
, size
= 0;
1659 TRACE("%p\n", config
);
1663 SetLastError( ERROR_INVALID_PARAMETER
);
1666 memset( config
, 0, sizeof(*config
) );
1667 config
->fAutoDetect
= TRUE
;
1669 if (RegOpenKeyExW( HKEY_CURRENT_USER
, path_connections
, 0, KEY_READ
, &hkey
) ||
1670 RegQueryValueExW( hkey
, L
"DefaultConnectionSettings", NULL
, &type
, NULL
, &size
) ||
1671 type
!= REG_BINARY
|| size
< sizeof(struct connection_settings_header
))
1676 if (!(hdr
= heap_alloc( size
))) goto done
;
1677 if (RegQueryValueExW( hkey
, L
"DefaultConnectionSettings", NULL
, &type
, (BYTE
*)hdr
, &size
) ||
1678 hdr
->magic
!= WININET_SETTINGS_MAGIC
)
1684 config
->fAutoDetect
= (hdr
->flags
& PROXY_AUTODETECT_SETTINGS
) != 0;
1685 offset
= sizeof(*hdr
);
1686 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1687 len
= *(DWORD
*)((char *)hdr
+ offset
);
1688 offset
+= sizeof(DWORD
);
1689 if (len
&& hdr
->flags
& PROXY_TYPE_PROXY
)
1691 if (!(config
->lpszProxy
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1692 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszProxy
);
1695 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1696 len
= *(DWORD
*)((char *)hdr
+ offset
);
1697 offset
+= sizeof(DWORD
);
1698 if (len
&& (hdr
->flags
& PROXY_TYPE_PROXY
))
1700 if (!(config
->lpszProxyBypass
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1701 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszProxyBypass
);
1704 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1705 len
= *(DWORD
*)((char *)hdr
+ offset
);
1706 offset
+= sizeof(DWORD
);
1707 if (len
&& (hdr
->flags
& PROXY_USE_PAC_SCRIPT
))
1709 if (!(config
->lpszAutoConfigUrl
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1710 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszAutoConfigUrl
);
1715 RegCloseKey( hkey
);
1719 GlobalFree( config
->lpszAutoConfigUrl
);
1720 config
->lpszAutoConfigUrl
= NULL
;
1721 GlobalFree( config
->lpszProxy
);
1722 config
->lpszProxy
= NULL
;
1723 GlobalFree( config
->lpszProxyBypass
);
1724 config
->lpszProxyBypass
= NULL
;
1726 else SetLastError( ERROR_SUCCESS
);
1730 static BOOL
parse_script_result( const char *result
, WINHTTP_PROXY_INFO
*info
)
1736 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NO_PROXY
;
1737 info
->lpszProxy
= NULL
;
1738 info
->lpszProxyBypass
= NULL
;
1740 TRACE("%s\n", debugstr_a( result
));
1743 while (*p
== ' ') p
++;
1745 if (len
>= 5 && !_strnicmp( p
, "PROXY", sizeof("PROXY") - 1 ))
1748 while (*p
== ' ') p
++;
1749 if (!*p
|| *p
== ';') return TRUE
;
1750 if (!(info
->lpszProxy
= q
= strdupAW( p
))) return FALSE
;
1751 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1754 if (*q
== ' ' || *q
== ';')
1764 static char *download_script( const WCHAR
*url
, DWORD
*out_size
)
1766 static const WCHAR
*acceptW
[] = {L
"*/*", NULL
};
1767 HINTERNET ses
, con
= NULL
, req
= NULL
;
1770 DWORD status
, size
= sizeof(status
), offset
, to_read
, bytes_read
, flags
= 0;
1771 char *tmp
, *buffer
= NULL
;
1775 memset( &uc
, 0, sizeof(uc
) );
1776 uc
.dwStructSize
= sizeof(uc
);
1777 uc
.dwHostNameLength
= -1;
1778 uc
.dwUrlPathLength
= -1;
1779 if (!WinHttpCrackUrl( url
, 0, 0, &uc
)) return NULL
;
1780 if (!(hostname
= heap_alloc( (uc
.dwHostNameLength
+ 1) * sizeof(WCHAR
) ))) return NULL
;
1781 memcpy( hostname
, uc
.lpszHostName
, uc
.dwHostNameLength
* sizeof(WCHAR
) );
1782 hostname
[uc
.dwHostNameLength
] = 0;
1784 if (!(ses
= WinHttpOpen( NULL
, WINHTTP_ACCESS_TYPE_NO_PROXY
, NULL
, NULL
, 0 ))) goto done
;
1785 if (!(con
= WinHttpConnect( ses
, hostname
, uc
.nPort
, 0 ))) goto done
;
1786 if (uc
.nScheme
== INTERNET_SCHEME_HTTPS
) flags
|= WINHTTP_FLAG_SECURE
;
1787 if (!(req
= WinHttpOpenRequest( con
, NULL
, uc
.lpszUrlPath
, NULL
, NULL
, acceptW
, flags
))) goto done
;
1788 if (!WinHttpSendRequest( req
, NULL
, 0, NULL
, 0, 0, 0 )) goto done
;
1790 if (!(WinHttpReceiveResponse( req
, 0 ))) goto done
;
1791 if (!WinHttpQueryHeaders( req
, WINHTTP_QUERY_STATUS_CODE
|WINHTTP_QUERY_FLAG_NUMBER
, NULL
, &status
,
1792 &size
, NULL
) || status
!= HTTP_STATUS_OK
) goto done
;
1795 if (!(buffer
= heap_alloc( size
))) goto done
;
1800 if (!WinHttpReadData( req
, buffer
+ offset
, to_read
, &bytes_read
)) goto done
;
1801 if (!bytes_read
) break;
1802 to_read
-= bytes_read
;
1803 offset
+= bytes_read
;
1804 *out_size
+= bytes_read
;
1809 if (!(tmp
= heap_realloc( buffer
, size
))) goto done
;
1815 WinHttpCloseHandle( req
);
1816 WinHttpCloseHandle( con
);
1817 WinHttpCloseHandle( ses
);
1818 heap_free( hostname
);
1819 if (!buffer
) SetLastError( ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT
);
1823 struct AUTO_PROXY_SCRIPT_BUFFER
1826 LPSTR lpszScriptBuffer
;
1827 DWORD dwScriptBufferSize
;
1830 BOOL WINAPI
InternetDeInitializeAutoProxyDll(LPSTR
, DWORD
);
1831 BOOL WINAPI
InternetGetProxyInfo(LPCSTR
, DWORD
, LPSTR
, DWORD
, LPSTR
*, LPDWORD
);
1832 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD
, LPSTR
, LPSTR
, void *, struct AUTO_PROXY_SCRIPT_BUFFER
*);
1834 static BOOL
run_script( char *script
, DWORD size
, const WCHAR
*url
, WINHTTP_PROXY_INFO
*info
)
1837 char *result
, *urlA
;
1839 struct AUTO_PROXY_SCRIPT_BUFFER buffer
;
1842 buffer
.dwStructSize
= sizeof(buffer
);
1843 buffer
.lpszScriptBuffer
= script
;
1844 buffer
.dwScriptBufferSize
= size
;
1846 if (!(urlA
= strdupWA( url
))) return FALSE
;
1847 if (!(ret
= InternetInitializeAutoProxyDll( 0, NULL
, NULL
, NULL
, &buffer
)))
1853 memset( &uc
, 0, sizeof(uc
) );
1854 uc
.dwStructSize
= sizeof(uc
);
1855 uc
.dwHostNameLength
= -1;
1857 if (WinHttpCrackUrl( url
, 0, 0, &uc
))
1859 char *hostnameA
= strdupWA_sized( uc
.lpszHostName
, uc
.dwHostNameLength
);
1861 if ((ret
= InternetGetProxyInfo( urlA
, strlen(urlA
),
1862 hostnameA
, strlen(hostnameA
), &result
, &len_result
)))
1864 ret
= parse_script_result( result
, info
);
1865 heap_free( result
);
1868 heap_free( hostnameA
);
1871 return InternetDeInitializeAutoProxyDll( NULL
, 0 );
1874 /***********************************************************************
1875 * WinHttpGetProxyForUrl (winhttp.@)
1877 BOOL WINAPI
WinHttpGetProxyForUrl( HINTERNET hsession
, LPCWSTR url
, WINHTTP_AUTOPROXY_OPTIONS
*options
,
1878 WINHTTP_PROXY_INFO
*info
)
1880 WCHAR
*detected_pac_url
= NULL
;
1881 const WCHAR
*pac_url
;
1882 struct session
*session
;
1887 TRACE("%p, %s, %p, %p\n", hsession
, debugstr_w(url
), options
, info
);
1889 if (!(session
= (struct session
*)grab_object( hsession
)))
1891 SetLastError( ERROR_INVALID_HANDLE
);
1894 if (session
->hdr
.type
!= WINHTTP_HANDLE_TYPE_SESSION
)
1896 release_object( &session
->hdr
);
1897 SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1900 if (!url
|| !options
|| !info
||
1901 !(options
->dwFlags
& (WINHTTP_AUTOPROXY_AUTO_DETECT
|WINHTTP_AUTOPROXY_CONFIG_URL
)) ||
1902 ((options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
) && !options
->dwAutoDetectFlags
) ||
1903 ((options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
) &&
1904 (options
->dwFlags
& WINHTTP_AUTOPROXY_CONFIG_URL
)))
1906 release_object( &session
->hdr
);
1907 SetLastError( ERROR_INVALID_PARAMETER
);
1910 if (options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
&&
1911 !WinHttpDetectAutoProxyConfigUrl( options
->dwAutoDetectFlags
, &detected_pac_url
))
1914 if (options
->dwFlags
& WINHTTP_AUTOPROXY_CONFIG_URL
) pac_url
= options
->lpszAutoConfigUrl
;
1915 else pac_url
= detected_pac_url
;
1917 if ((script
= download_script( pac_url
, &size
)))
1919 ret
= run_script( script
, size
, url
, info
);
1920 heap_free( script
);
1924 GlobalFree( detected_pac_url
);
1925 release_object( &session
->hdr
);
1926 if (ret
) SetLastError( ERROR_SUCCESS
);
1930 /***********************************************************************
1931 * WinHttpSetDefaultProxyConfiguration (winhttp.@)
1933 BOOL WINAPI
WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO
*info
)
1940 TRACE("%p\n", info
);
1944 SetLastError( ERROR_INVALID_PARAMETER
);
1947 switch (info
->dwAccessType
)
1949 case WINHTTP_ACCESS_TYPE_NO_PROXY
:
1951 case WINHTTP_ACCESS_TYPE_NAMED_PROXY
:
1952 if (!info
->lpszProxy
)
1954 SetLastError( ERROR_INVALID_PARAMETER
);
1957 /* Only ASCII characters are allowed */
1958 for (src
= info
->lpszProxy
; *src
; src
++)
1961 SetLastError( ERROR_INVALID_PARAMETER
);
1964 if (info
->lpszProxyBypass
)
1966 for (src
= info
->lpszProxyBypass
; *src
; src
++)
1969 SetLastError( ERROR_INVALID_PARAMETER
);
1975 SetLastError( ERROR_INVALID_PARAMETER
);
1979 l
= RegCreateKeyExW( HKEY_LOCAL_MACHINE
, path_connections
, 0, NULL
, 0,
1980 KEY_WRITE
, NULL
, &key
, NULL
);
1983 DWORD size
= sizeof(struct connection_settings_header
) + 2 * sizeof(DWORD
);
1986 if (info
->dwAccessType
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
1988 size
+= lstrlenW( info
->lpszProxy
);
1989 if (info
->lpszProxyBypass
)
1990 size
+= lstrlenW( info
->lpszProxyBypass
);
1992 buf
= heap_alloc( size
);
1995 struct connection_settings_header
*hdr
=
1996 (struct connection_settings_header
*)buf
;
1997 DWORD
*len
= (DWORD
*)(hdr
+ 1);
1999 hdr
->magic
= WINHTTP_SETTINGS_MAGIC
;
2001 if (info
->dwAccessType
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
2005 hdr
->flags
= PROXY_TYPE_PROXY
;
2006 *len
++ = lstrlenW( info
->lpszProxy
);
2007 for (dst
= (BYTE
*)len
, src
= info
->lpszProxy
; *src
;
2011 if (info
->lpszProxyBypass
)
2013 *len
++ = lstrlenW( info
->lpszProxyBypass
);
2014 for (dst
= (BYTE
*)len
, src
= info
->lpszProxyBypass
; *src
;
2023 hdr
->flags
= PROXY_TYPE_DIRECT
;
2027 l
= RegSetValueExW( key
, L
"WinHttpSettings", 0, REG_BINARY
, buf
, size
);
2034 if (ret
) SetLastError( ERROR_SUCCESS
);
2038 /***********************************************************************
2039 * WinHttpSetStatusCallback (winhttp.@)
2041 WINHTTP_STATUS_CALLBACK WINAPI
WinHttpSetStatusCallback( HINTERNET handle
, WINHTTP_STATUS_CALLBACK callback
,
2042 DWORD flags
, DWORD_PTR reserved
)
2044 struct object_header
*hdr
;
2045 WINHTTP_STATUS_CALLBACK ret
;
2047 TRACE("%p, %p, 0x%08x, 0x%lx\n", handle
, callback
, flags
, reserved
);
2049 if (!(hdr
= grab_object( handle
)))
2051 SetLastError( ERROR_INVALID_HANDLE
);
2052 return WINHTTP_INVALID_STATUS_CALLBACK
;
2054 ret
= hdr
->callback
;
2055 hdr
->callback
= callback
;
2056 hdr
->notify_mask
= flags
;
2058 release_object( hdr
);
2059 SetLastError( ERROR_SUCCESS
);
2063 /***********************************************************************
2064 * WinHttpSetTimeouts (winhttp.@)
2066 BOOL WINAPI
WinHttpSetTimeouts( HINTERNET handle
, int resolve
, int connect
, int send
, int receive
)
2069 struct object_header
*hdr
;
2071 TRACE("%p, %d, %d, %d, %d\n", handle
, resolve
, connect
, send
, receive
);
2073 if (resolve
< -1 || connect
< -1 || send
< -1 || receive
< -1)
2075 SetLastError( ERROR_INVALID_PARAMETER
);
2079 if (!(hdr
= grab_object( handle
)))
2081 SetLastError( ERROR_INVALID_HANDLE
);
2087 case WINHTTP_HANDLE_TYPE_REQUEST
:
2089 struct request
*request
= (struct request
*)hdr
;
2090 request
->connect_timeout
= connect
;
2092 if (resolve
< 0) resolve
= 0;
2093 request
->resolve_timeout
= resolve
;
2095 if (send
< 0) send
= 0;
2096 request
->send_timeout
= send
;
2098 if (receive
< 0) receive
= 0;
2099 request
->receive_timeout
= receive
;
2101 if (request
->netconn
)
2103 if (netconn_set_timeout( request
->netconn
, TRUE
, send
)) ret
= FALSE
;
2104 if (netconn_set_timeout( request
->netconn
, FALSE
, receive
)) ret
= FALSE
;
2108 case WINHTTP_HANDLE_TYPE_SESSION
:
2110 struct session
*session
= (struct session
*)hdr
;
2111 session
->connect_timeout
= connect
;
2113 if (resolve
< 0) resolve
= 0;
2114 session
->resolve_timeout
= resolve
;
2116 if (send
< 0) send
= 0;
2117 session
->send_timeout
= send
;
2119 if (receive
< 0) receive
= 0;
2120 session
->receive_timeout
= receive
;
2124 SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
2127 release_object( hdr
);
2128 if (ret
) SetLastError( ERROR_SUCCESS
);
2132 static const WCHAR wkday
[7][4] =
2133 {L
"Sun", L
"Mon", L
"Tue", L
"Wed", L
"Thu", L
"Fri", L
"Sat"};
2134 static const WCHAR month
[12][4] =
2135 {L
"Jan", L
"Feb", L
"Mar", L
"Apr", L
"May", L
"Jun", L
"Jul", L
"Aug", L
"Sep", L
"Oct", L
"Nov", L
"Dec"};
2137 /***********************************************************************
2138 * WinHttpTimeFromSystemTime (WININET.@)
2140 BOOL WINAPI
WinHttpTimeFromSystemTime( const SYSTEMTIME
*time
, LPWSTR string
)
2142 TRACE("%p, %p\n", time
, string
);
2144 if (!time
|| !string
)
2146 SetLastError( ERROR_INVALID_PARAMETER
);
2150 swprintf( string
, WINHTTP_TIME_FORMAT_BUFSIZE
/ sizeof(WCHAR
),
2151 L
"%s, %02d %s %4d %02d:%02d:%02d GMT",
2152 wkday
[time
->wDayOfWeek
],
2154 month
[time
->wMonth
- 1],
2160 SetLastError( ERROR_SUCCESS
);
2164 /***********************************************************************
2165 * WinHttpTimeToSystemTime (WININET.@)
2167 BOOL WINAPI
WinHttpTimeToSystemTime( LPCWSTR string
, SYSTEMTIME
*time
)
2170 const WCHAR
*s
= string
;
2173 TRACE("%s, %p\n", debugstr_w(string
), time
);
2175 if (!string
|| !time
)
2177 SetLastError( ERROR_INVALID_PARAMETER
);
2181 /* Windows does this too */
2182 GetSystemTime( time
);
2184 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2185 * a SYSTEMTIME structure.
2188 SetLastError( ERROR_SUCCESS
);
2190 while (*s
&& !iswalpha( *s
)) s
++;
2191 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2192 time
->wDayOfWeek
= 7;
2194 for (i
= 0; i
< 7; i
++)
2196 if (towupper( wkday
[i
][0] ) == towupper( s
[0] ) &&
2197 towupper( wkday
[i
][1] ) == towupper( s
[1] ) &&
2198 towupper( wkday
[i
][2] ) == towupper( s
[2] ) )
2200 time
->wDayOfWeek
= i
;
2205 if (time
->wDayOfWeek
> 6) return TRUE
;
2206 while (*s
&& !iswdigit( *s
)) s
++;
2207 time
->wDay
= wcstol( s
, &end
, 10 );
2210 while (*s
&& !iswalpha( *s
)) s
++;
2211 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2214 for (i
= 0; i
< 12; i
++)
2216 if (towupper( month
[i
][0]) == towupper( s
[0] ) &&
2217 towupper( month
[i
][1]) == towupper( s
[1] ) &&
2218 towupper( month
[i
][2]) == towupper( s
[2] ) )
2220 time
->wMonth
= i
+ 1;
2224 if (time
->wMonth
== 0) return TRUE
;
2226 while (*s
&& !iswdigit( *s
)) s
++;
2227 if (*s
== '\0') return TRUE
;
2228 time
->wYear
= wcstol( s
, &end
, 10 );
2231 while (*s
&& !iswdigit( *s
)) s
++;
2232 if (*s
== '\0') return TRUE
;
2233 time
->wHour
= wcstol( s
, &end
, 10 );
2236 while (*s
&& !iswdigit( *s
)) s
++;
2237 if (*s
== '\0') return TRUE
;
2238 time
->wMinute
= wcstol( s
, &end
, 10 );
2241 while (*s
&& !iswdigit( *s
)) s
++;
2242 if (*s
== '\0') return TRUE
;
2243 time
->wSecond
= wcstol( s
, &end
, 10 );
2245 time
->wMilliseconds
= 0;