2 * Copyright 2008 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define WIN32_NO_STATUS
21 #define COM_NO_WINDOWS_H
24 //#include "wine/port.h"
25 #include <wine/debug.h>
40 #include "winhttp_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(winhttp
);
44 #define DEFAULT_RESOLVE_TIMEOUT 0
45 #define DEFAULT_CONNECT_TIMEOUT 20000
46 #define DEFAULT_SEND_TIMEOUT 30000
47 #define DEFAULT_RECEIVE_TIMEOUT 30000
49 static const WCHAR global_funcsW
[] = {'g','l','o','b','a','l','_','f','u','n','c','s',0};
50 static const WCHAR dns_resolveW
[] = {'d','n','s','_','r','e','s','o','l','v','e',0};
52 void set_last_error( DWORD error
)
55 SetLastError( error
);
58 DWORD
get_last_error( void )
61 return GetLastError();
64 void send_callback( object_header_t
*hdr
, DWORD status
, LPVOID info
, DWORD buflen
)
66 TRACE("%p, 0x%08x, %p, %u\n", hdr
, status
, info
, buflen
);
68 if (hdr
->callback
&& (hdr
->notify_mask
& status
)) hdr
->callback( hdr
->handle
, hdr
->context
, status
, info
, buflen
);
71 /***********************************************************************
72 * WinHttpCheckPlatform (winhttp.@)
74 BOOL WINAPI
WinHttpCheckPlatform( void )
80 /***********************************************************************
81 * session_destroy (internal)
83 static void session_destroy( object_header_t
*hdr
)
85 session_t
*session
= (session_t
*)hdr
;
86 struct list
*item
, *next
;
89 TRACE("%p\n", session
);
91 LIST_FOR_EACH_SAFE( item
, next
, &session
->cookie_cache
)
93 domain
= LIST_ENTRY( item
, domain_t
, entry
);
94 delete_domain( domain
);
96 heap_free( session
->agent
);
97 heap_free( session
->proxy_server
);
98 heap_free( session
->proxy_bypass
);
99 heap_free( session
->proxy_username
);
100 heap_free( session
->proxy_password
);
101 heap_free( session
);
107 static BOOL
session_query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
109 session_t
*session
= (session_t
*)hdr
;
113 case WINHTTP_OPTION_REDIRECT_POLICY
:
115 if (!buffer
|| *buflen
< sizeof(DWORD
))
117 *buflen
= sizeof(DWORD
);
118 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
122 *(DWORD
*)buffer
= hdr
->redirect_policy
;
123 *buflen
= sizeof(DWORD
);
126 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
127 *(DWORD
*)buffer
= session
->resolve_timeout
;
128 *buflen
= sizeof(DWORD
);
130 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
131 *(DWORD
*)buffer
= session
->connect_timeout
;
132 *buflen
= sizeof(DWORD
);
134 case WINHTTP_OPTION_SEND_TIMEOUT
:
135 *(DWORD
*)buffer
= session
->send_timeout
;
136 *buflen
= sizeof(DWORD
);
138 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
139 *(DWORD
*)buffer
= session
->recv_timeout
;
140 *buflen
= sizeof(DWORD
);
143 FIXME("unimplemented option %u\n", option
);
144 set_last_error( ERROR_INVALID_PARAMETER
);
149 static BOOL
session_set_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, DWORD buflen
)
151 session_t
*session
= (session_t
*)hdr
;
155 case WINHTTP_OPTION_PROXY
:
157 WINHTTP_PROXY_INFO
*pi
= buffer
;
159 FIXME("%u %s %s\n", pi
->dwAccessType
, debugstr_w(pi
->lpszProxy
), debugstr_w(pi
->lpszProxyBypass
));
162 case WINHTTP_OPTION_REDIRECT_POLICY
:
166 if (buflen
!= sizeof(policy
))
168 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
172 policy
= *(DWORD
*)buffer
;
173 TRACE("0x%x\n", policy
);
174 hdr
->redirect_policy
= policy
;
177 case WINHTTP_OPTION_DISABLE_FEATURE
:
178 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
180 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
181 session
->resolve_timeout
= *(DWORD
*)buffer
;
183 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
184 session
->connect_timeout
= *(DWORD
*)buffer
;
186 case WINHTTP_OPTION_SEND_TIMEOUT
:
187 session
->send_timeout
= *(DWORD
*)buffer
;
189 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
190 session
->recv_timeout
= *(DWORD
*)buffer
;
193 FIXME("unimplemented option %u\n", option
);
194 set_last_error( ERROR_INVALID_PARAMETER
);
199 static const object_vtbl_t session_vtbl
=
202 session_query_option
,
206 /***********************************************************************
207 * WinHttpOpen (winhttp.@)
209 HINTERNET WINAPI
WinHttpOpen( LPCWSTR agent
, DWORD access
, LPCWSTR proxy
, LPCWSTR bypass
, DWORD flags
)
212 HINTERNET handle
= NULL
;
215 int error
= WSAStartup(MAKEWORD(2, 2), &wsaData
);
216 if (error
) ERR("WSAStartup failed: %d\n", error
);
219 TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent
), access
, debugstr_w(proxy
), debugstr_w(bypass
), flags
);
221 if (!(session
= heap_alloc_zero( sizeof(session_t
) ))) return NULL
;
223 session
->hdr
.type
= WINHTTP_HANDLE_TYPE_SESSION
;
224 session
->hdr
.vtbl
= &session_vtbl
;
225 session
->hdr
.flags
= flags
;
226 session
->hdr
.refs
= 1;
227 session
->hdr
.redirect_policy
= WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP
;
228 list_init( &session
->hdr
.children
);
229 session
->resolve_timeout
= DEFAULT_RESOLVE_TIMEOUT
;
230 session
->connect_timeout
= DEFAULT_CONNECT_TIMEOUT
;
231 session
->send_timeout
= DEFAULT_SEND_TIMEOUT
;
232 session
->recv_timeout
= DEFAULT_RECEIVE_TIMEOUT
;
233 list_init( &session
->cookie_cache
);
235 if (agent
&& !(session
->agent
= strdupW( agent
))) goto end
;
236 if (access
== WINHTTP_ACCESS_TYPE_DEFAULT_PROXY
)
238 WINHTTP_PROXY_INFO info
;
240 WinHttpGetDefaultProxyConfiguration( &info
);
241 session
->access
= info
.dwAccessType
;
242 if (info
.lpszProxy
&& !(session
->proxy_server
= strdupW( info
.lpszProxy
)))
244 GlobalFree( (LPWSTR
)info
.lpszProxy
);
245 GlobalFree( (LPWSTR
)info
.lpszProxyBypass
);
248 if (info
.lpszProxyBypass
&& !(session
->proxy_bypass
= strdupW( info
.lpszProxyBypass
)))
250 GlobalFree( (LPWSTR
)info
.lpszProxy
);
251 GlobalFree( (LPWSTR
)info
.lpszProxyBypass
);
255 else if (access
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
257 session
->access
= access
;
258 if (proxy
&& !(session
->proxy_server
= strdupW( proxy
))) goto end
;
259 if (bypass
&& !(session
->proxy_bypass
= strdupW( bypass
))) goto end
;
262 if (!(handle
= alloc_handle( &session
->hdr
))) goto end
;
263 session
->hdr
.handle
= handle
;
266 release_object( &session
->hdr
);
267 TRACE("returning %p\n", handle
);
271 /***********************************************************************
272 * connect_destroy (internal)
274 static void connect_destroy( object_header_t
*hdr
)
276 connect_t
*connect
= (connect_t
*)hdr
;
278 TRACE("%p\n", connect
);
280 release_object( &connect
->session
->hdr
);
282 heap_free( connect
->hostname
);
283 heap_free( connect
->servername
);
284 heap_free( connect
->username
);
285 heap_free( connect
->password
);
286 heap_free( connect
);
289 static BOOL
connect_query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
291 connect_t
*connect
= (connect_t
*)hdr
;
295 case WINHTTP_OPTION_PARENT_HANDLE
:
297 if (!buffer
|| *buflen
< sizeof(HINTERNET
))
299 *buflen
= sizeof(HINTERNET
);
300 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
304 *(HINTERNET
*)buffer
= ((object_header_t
*)connect
->session
)->handle
;
305 *buflen
= sizeof(HINTERNET
);
308 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
309 *(DWORD
*)buffer
= connect
->session
->resolve_timeout
;
310 *buflen
= sizeof(DWORD
);
312 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
313 *(DWORD
*)buffer
= connect
->session
->connect_timeout
;
314 *buflen
= sizeof(DWORD
);
316 case WINHTTP_OPTION_SEND_TIMEOUT
:
317 *(DWORD
*)buffer
= connect
->session
->send_timeout
;
318 *buflen
= sizeof(DWORD
);
320 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
321 *(DWORD
*)buffer
= connect
->session
->recv_timeout
;
322 *buflen
= sizeof(DWORD
);
325 FIXME("unimplemented option %u\n", option
);
326 set_last_error( ERROR_INVALID_PARAMETER
);
331 static const object_vtbl_t connect_vtbl
=
334 connect_query_option
,
338 static BOOL
domain_matches(LPCWSTR server
, LPCWSTR domain
)
340 static const WCHAR localW
[] = { '<','l','o','c','a','l','>',0 };
343 if (!strcmpiW( domain
, localW
) && !strchrW( server
, '.' ))
345 else if (*domain
== '*')
347 if (domain
[1] == '.')
351 /* For a hostname to match a wildcard, the last domain must match
352 * the wildcard exactly. E.g. if the wildcard is *.a.b, and the
353 * hostname is www.foo.a.b, it matches, but a.b does not.
355 dot
= strchrW( server
, '.' );
358 int len
= strlenW( dot
+ 1 );
360 if (len
> strlenW( domain
+ 2 ))
364 /* The server's domain is longer than the wildcard, so it
365 * could be a subdomain. Compare the last portion of the
368 ptr
= dot
+ len
+ 1 - strlenW( domain
+ 2 );
369 if (!strcmpiW( ptr
, domain
+ 2 ))
371 /* This is only a match if the preceding character is
372 * a '.', i.e. that it is a matching domain. E.g.
373 * if domain is '*.b.c' and server is 'www.ab.c' they
376 ret
= *(ptr
- 1) == '.';
380 ret
= !strcmpiW( dot
+ 1, domain
+ 2 );
385 ret
= !strcmpiW( server
, domain
);
389 /* Matches INTERNET_MAX_HOST_NAME_LENGTH in wininet.h, also RFC 1035 */
390 #define MAX_HOST_NAME_LENGTH 256
392 static BOOL
should_bypass_proxy(session_t
*session
, LPCWSTR server
)
397 if (!session
->proxy_bypass
) return FALSE
;
398 ptr
= session
->proxy_bypass
;
402 ptr
= strchrW( ptr
, ';' );
404 ptr
= strchrW( tmp
, ' ' );
407 if (ptr
- tmp
< MAX_HOST_NAME_LENGTH
)
409 WCHAR domain
[MAX_HOST_NAME_LENGTH
];
411 memcpy( domain
, tmp
, (ptr
- tmp
) * sizeof(WCHAR
) );
412 domain
[ptr
- tmp
] = 0;
413 ret
= domain_matches( server
, domain
);
418 ret
= domain_matches( server
, tmp
);
419 } while (ptr
&& !ret
);
423 BOOL
set_server_for_hostname( connect_t
*connect
, LPCWSTR server
, INTERNET_PORT port
)
425 session_t
*session
= connect
->session
;
428 if (session
->proxy_server
&& !should_bypass_proxy(session
, server
))
432 if ((colon
= strchrW( session
->proxy_server
, ':' )))
434 if (!connect
->servername
|| strncmpiW( connect
->servername
,
435 session
->proxy_server
, colon
- session
->proxy_server
- 1 ))
437 heap_free( connect
->servername
);
438 connect
->resolved
= FALSE
;
439 if (!(connect
->servername
= heap_alloc(
440 (colon
- session
->proxy_server
+ 1) * sizeof(WCHAR
) )))
445 memcpy( connect
->servername
, session
->proxy_server
,
446 (colon
- session
->proxy_server
) * sizeof(WCHAR
) );
447 connect
->servername
[colon
- session
->proxy_server
] = 0;
449 connect
->serverport
= atoiW( colon
+ 1 );
451 connect
->serverport
= INTERNET_DEFAULT_PORT
;
456 if (!connect
->servername
|| strcmpiW( connect
->servername
,
457 session
->proxy_server
))
459 heap_free( connect
->servername
);
460 connect
->resolved
= FALSE
;
461 if (!(connect
->servername
= strdupW( session
->proxy_server
)))
466 connect
->serverport
= INTERNET_DEFAULT_PORT
;
472 heap_free( connect
->servername
);
473 connect
->resolved
= FALSE
;
474 if (!(connect
->servername
= strdupW( server
)))
479 connect
->serverport
= port
;
485 /***********************************************************************
486 * WinHttpConnect (winhttp.@)
488 HINTERNET WINAPI
WinHttpConnect( HINTERNET hsession
, LPCWSTR server
, INTERNET_PORT port
, DWORD reserved
)
492 HINTERNET hconnect
= NULL
;
494 TRACE("%p, %s, %u, %x\n", hsession
, debugstr_w(server
), port
, reserved
);
498 set_last_error( ERROR_INVALID_PARAMETER
);
501 if (!(session
= (session_t
*)grab_object( hsession
)))
503 set_last_error( ERROR_INVALID_HANDLE
);
506 if (session
->hdr
.type
!= WINHTTP_HANDLE_TYPE_SESSION
)
508 release_object( &session
->hdr
);
509 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
512 if (!(connect
= heap_alloc_zero( sizeof(connect_t
) )))
514 release_object( &session
->hdr
);
517 connect
->hdr
.type
= WINHTTP_HANDLE_TYPE_CONNECT
;
518 connect
->hdr
.vtbl
= &connect_vtbl
;
519 connect
->hdr
.refs
= 1;
520 connect
->hdr
.flags
= session
->hdr
.flags
;
521 connect
->hdr
.callback
= session
->hdr
.callback
;
522 connect
->hdr
.notify_mask
= session
->hdr
.notify_mask
;
523 connect
->hdr
.context
= session
->hdr
.context
;
524 list_init( &connect
->hdr
.children
);
526 addref_object( &session
->hdr
);
527 connect
->session
= session
;
528 list_add_head( &session
->hdr
.children
, &connect
->hdr
.entry
);
530 if (!(connect
->hostname
= strdupW( server
))) goto end
;
531 connect
->hostport
= port
;
532 if (!set_server_for_hostname( connect
, server
, port
)) goto end
;
534 if (!(hconnect
= alloc_handle( &connect
->hdr
))) goto end
;
535 connect
->hdr
.handle
= hconnect
;
537 send_callback( &session
->hdr
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
, &hconnect
, sizeof(hconnect
) );
540 release_object( &connect
->hdr
);
541 release_object( &session
->hdr
);
542 TRACE("returning %p\n", hconnect
);
546 /***********************************************************************
547 * request_destroy (internal)
549 static void request_destroy( object_header_t
*hdr
)
551 request_t
*request
= (request_t
*)hdr
;
554 TRACE("%p\n", request
);
556 release_object( &request
->connect
->hdr
);
558 heap_free( request
->verb
);
559 heap_free( request
->path
);
560 heap_free( request
->version
);
561 heap_free( request
->raw_headers
);
562 heap_free( request
->status_text
);
563 for (i
= 0; i
< request
->num_headers
; i
++)
565 heap_free( request
->headers
[i
].field
);
566 heap_free( request
->headers
[i
].value
);
568 heap_free( request
->headers
);
569 for (i
= 0; i
< request
->num_accept_types
; i
++) heap_free( request
->accept_types
[i
] );
570 heap_free( request
->accept_types
);
571 heap_free( request
);
574 static void str_to_buffer( WCHAR
*buffer
, const WCHAR
*str
, LPDWORD buflen
)
577 if (str
) len
= strlenW( str
);
578 if (buffer
&& *buflen
> len
)
580 if (str
) memcpy( buffer
, str
, len
* sizeof(WCHAR
) );
583 *buflen
= len
* sizeof(WCHAR
);
586 static WCHAR
*blob_to_str( DWORD encoding
, CERT_NAME_BLOB
*blob
)
589 DWORD size
, format
= CERT_SIMPLE_NAME_STR
| CERT_NAME_STR_CRLF_FLAG
;
591 size
= CertNameToStrW( encoding
, blob
, format
, NULL
, 0 );
592 if ((ret
= LocalAlloc( 0, size
* sizeof(WCHAR
) )))
593 CertNameToStrW( encoding
, blob
, format
, ret
, size
);
598 static BOOL
request_query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
600 request_t
*request
= (request_t
*)hdr
;
604 case WINHTTP_OPTION_SECURITY_FLAGS
:
609 if (!buffer
|| *buflen
< sizeof(flags
))
611 *buflen
= sizeof(flags
);
612 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
617 if (hdr
->flags
& WINHTTP_FLAG_SECURE
) flags
|= SECURITY_FLAG_SECURE
;
618 flags
|= request
->netconn
.security_flags
;
619 bits
= netconn_get_cipher_strength( &request
->netconn
);
621 flags
|= SECURITY_FLAG_STRENGTH_STRONG
;
623 flags
|= SECURITY_FLAG_STRENGTH_MEDIUM
;
625 flags
|= SECURITY_FLAG_STRENGTH_WEAK
;
626 *(DWORD
*)buffer
= flags
;
627 *buflen
= sizeof(flags
);
630 case WINHTTP_OPTION_SERVER_CERT_CONTEXT
:
632 const CERT_CONTEXT
*cert
;
634 if (!buffer
|| *buflen
< sizeof(cert
))
636 *buflen
= sizeof(cert
);
637 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
641 if (!(cert
= netconn_get_certificate( &request
->netconn
))) return FALSE
;
642 *(CERT_CONTEXT
**)buffer
= (CERT_CONTEXT
*)cert
;
643 *buflen
= sizeof(cert
);
646 case WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT
:
648 const CERT_CONTEXT
*cert
;
649 const CRYPT_OID_INFO
*oidInfo
;
650 WINHTTP_CERTIFICATE_INFO
*ci
= buffer
;
652 FIXME("partial stub\n");
654 if (!buffer
|| *buflen
< sizeof(*ci
))
656 *buflen
= sizeof(*ci
);
657 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
660 if (!(cert
= netconn_get_certificate( &request
->netconn
))) return FALSE
;
662 ci
->ftExpiry
= cert
->pCertInfo
->NotAfter
;
663 ci
->ftStart
= cert
->pCertInfo
->NotBefore
;
664 ci
->lpszSubjectInfo
= blob_to_str( cert
->dwCertEncodingType
, &cert
->pCertInfo
->Subject
);
665 ci
->lpszIssuerInfo
= blob_to_str( cert
->dwCertEncodingType
, &cert
->pCertInfo
->Issuer
);
666 ci
->lpszProtocolName
= NULL
;
667 oidInfo
= CryptFindOIDInfo( CRYPT_OID_INFO_OID_KEY
,
668 cert
->pCertInfo
->SignatureAlgorithm
.pszObjId
,
671 ci
->lpszSignatureAlgName
= (LPWSTR
)oidInfo
->pwszName
;
673 ci
->lpszSignatureAlgName
= NULL
;
674 ci
->lpszEncryptionAlgName
= NULL
;
675 ci
->dwKeySize
= netconn_get_cipher_strength( &request
->netconn
);
677 CertFreeCertificateContext( cert
);
678 *buflen
= sizeof(*ci
);
681 case WINHTTP_OPTION_SECURITY_KEY_BITNESS
:
683 if (!buffer
|| *buflen
< sizeof(DWORD
))
685 *buflen
= sizeof(DWORD
);
686 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
690 *(DWORD
*)buffer
= netconn_get_cipher_strength( &request
->netconn
);
691 *buflen
= sizeof(DWORD
);
694 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
695 *(DWORD
*)buffer
= request
->resolve_timeout
;
696 *buflen
= sizeof(DWORD
);
698 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
699 *(DWORD
*)buffer
= request
->connect_timeout
;
700 *buflen
= sizeof(DWORD
);
702 case WINHTTP_OPTION_SEND_TIMEOUT
:
703 *(DWORD
*)buffer
= request
->send_timeout
;
704 *buflen
= sizeof(DWORD
);
706 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
707 *(DWORD
*)buffer
= request
->recv_timeout
;
708 *buflen
= sizeof(DWORD
);
711 case WINHTTP_OPTION_USERNAME
:
712 str_to_buffer( buffer
, request
->connect
->username
, buflen
);
715 case WINHTTP_OPTION_PASSWORD
:
716 str_to_buffer( buffer
, request
->connect
->password
, buflen
);
719 case WINHTTP_OPTION_PROXY_USERNAME
:
720 str_to_buffer( buffer
, request
->connect
->session
->proxy_username
, buflen
);
723 case WINHTTP_OPTION_PROXY_PASSWORD
:
724 str_to_buffer( buffer
, request
->connect
->session
->proxy_password
, buflen
);
728 FIXME("unimplemented option %u\n", option
);
729 set_last_error( ERROR_INVALID_PARAMETER
);
734 static WCHAR
*buffer_to_str( WCHAR
*buffer
, DWORD buflen
)
737 if ((ret
= heap_alloc( (buflen
+ 1) * sizeof(WCHAR
))))
739 memcpy( ret
, buffer
, buflen
* sizeof(WCHAR
) );
743 set_last_error( ERROR_OUTOFMEMORY
);
747 static BOOL
request_set_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, DWORD buflen
)
749 request_t
*request
= (request_t
*)hdr
;
753 case WINHTTP_OPTION_PROXY
:
755 WINHTTP_PROXY_INFO
*pi
= buffer
;
757 FIXME("%u %s %s\n", pi
->dwAccessType
, debugstr_w(pi
->lpszProxy
), debugstr_w(pi
->lpszProxyBypass
));
760 case WINHTTP_OPTION_DISABLE_FEATURE
:
764 if (buflen
!= sizeof(DWORD
))
766 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
770 disable
= *(DWORD
*)buffer
;
771 TRACE("0x%x\n", disable
);
772 hdr
->disable_flags
|= disable
;
775 case WINHTTP_OPTION_AUTOLOGON_POLICY
:
779 if (buflen
!= sizeof(DWORD
))
781 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
785 policy
= *(DWORD
*)buffer
;
786 TRACE("0x%x\n", policy
);
787 hdr
->logon_policy
= policy
;
790 case WINHTTP_OPTION_REDIRECT_POLICY
:
794 if (buflen
!= sizeof(DWORD
))
796 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
800 policy
= *(DWORD
*)buffer
;
801 TRACE("0x%x\n", policy
);
802 hdr
->redirect_policy
= policy
;
805 case WINHTTP_OPTION_SECURITY_FLAGS
:
809 if (buflen
< sizeof(DWORD
))
811 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
814 flags
= *(DWORD
*)buffer
;
815 TRACE("0x%x\n", flags
);
816 if (!(flags
& (SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|
817 SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
|
818 SECURITY_FLAG_IGNORE_UNKNOWN_CA
|
819 SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE
)))
821 set_last_error( ERROR_INVALID_PARAMETER
);
824 request
->netconn
.security_flags
= flags
;
827 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
828 request
->resolve_timeout
= *(DWORD
*)buffer
;
830 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
831 request
->connect_timeout
= *(DWORD
*)buffer
;
833 case WINHTTP_OPTION_SEND_TIMEOUT
:
834 request
->send_timeout
= *(DWORD
*)buffer
;
836 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
837 request
->recv_timeout
= *(DWORD
*)buffer
;
840 case WINHTTP_OPTION_USERNAME
:
842 connect_t
*connect
= request
->connect
;
844 heap_free( connect
->username
);
845 if (!(connect
->username
= buffer_to_str( buffer
, buflen
))) return FALSE
;
848 case WINHTTP_OPTION_PASSWORD
:
850 connect_t
*connect
= request
->connect
;
852 heap_free( connect
->password
);
853 if (!(connect
->password
= buffer_to_str( buffer
, buflen
))) return FALSE
;
856 case WINHTTP_OPTION_PROXY_USERNAME
:
858 session_t
*session
= request
->connect
->session
;
860 heap_free( session
->proxy_username
);
861 if (!(session
->proxy_username
= buffer_to_str( buffer
, buflen
))) return FALSE
;
864 case WINHTTP_OPTION_PROXY_PASSWORD
:
866 session_t
*session
= request
->connect
->session
;
868 heap_free( session
->proxy_password
);
869 if (!(session
->proxy_password
= buffer_to_str( buffer
, buflen
))) return FALSE
;
873 FIXME("unimplemented option %u\n", option
);
874 set_last_error( ERROR_INVALID_PARAMETER
);
879 static const object_vtbl_t request_vtbl
=
882 request_query_option
,
886 static BOOL
store_accept_types( request_t
*request
, const WCHAR
**accept_types
)
888 const WCHAR
**types
= accept_types
;
891 if (!types
) return TRUE
;
894 request
->num_accept_types
++;
897 if (!request
->num_accept_types
) return TRUE
;
898 if (!(request
->accept_types
= heap_alloc( request
->num_accept_types
* sizeof(WCHAR
*))))
900 request
->num_accept_types
= 0;
903 types
= accept_types
;
904 for (i
= 0; i
< request
->num_accept_types
; i
++)
906 if (!(request
->accept_types
[i
] = strdupW( *types
)))
908 for (; i
>= 0; i
--) heap_free( request
->accept_types
[i
] );
909 heap_free( request
->accept_types
);
910 request
->accept_types
= NULL
;
911 request
->num_accept_types
= 0;
919 /***********************************************************************
920 * WinHttpOpenRequest (winhttp.@)
922 HINTERNET WINAPI
WinHttpOpenRequest( HINTERNET hconnect
, LPCWSTR verb
, LPCWSTR object
, LPCWSTR version
,
923 LPCWSTR referrer
, LPCWSTR
*types
, DWORD flags
)
927 HINTERNET hrequest
= NULL
;
929 TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect
, debugstr_w(verb
), debugstr_w(object
),
930 debugstr_w(version
), debugstr_w(referrer
), types
, flags
);
932 if(types
&& TRACE_ON(winhttp
)) {
935 TRACE("accept types:\n");
936 for(iter
= types
; *iter
; iter
++)
937 TRACE(" %s\n", debugstr_w(*iter
));
940 if (!(connect
= (connect_t
*)grab_object( hconnect
)))
942 set_last_error( ERROR_INVALID_HANDLE
);
945 if (connect
->hdr
.type
!= WINHTTP_HANDLE_TYPE_CONNECT
)
947 release_object( &connect
->hdr
);
948 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
951 if (!(request
= heap_alloc_zero( sizeof(request_t
) )))
953 release_object( &connect
->hdr
);
956 request
->hdr
.type
= WINHTTP_HANDLE_TYPE_REQUEST
;
957 request
->hdr
.vtbl
= &request_vtbl
;
958 request
->hdr
.refs
= 1;
959 request
->hdr
.flags
= flags
;
960 request
->hdr
.callback
= connect
->hdr
.callback
;
961 request
->hdr
.notify_mask
= connect
->hdr
.notify_mask
;
962 request
->hdr
.context
= connect
->hdr
.context
;
963 list_init( &request
->hdr
.children
);
965 addref_object( &connect
->hdr
);
966 request
->connect
= connect
;
967 list_add_head( &connect
->hdr
.children
, &request
->hdr
.entry
);
969 if (!netconn_init( &request
->netconn
, request
->hdr
.flags
& WINHTTP_FLAG_SECURE
)) goto end
;
970 request
->resolve_timeout
= connect
->session
->resolve_timeout
;
971 request
->connect_timeout
= connect
->session
->connect_timeout
;
972 request
->send_timeout
= connect
->session
->send_timeout
;
973 request
->recv_timeout
= connect
->session
->recv_timeout
;
975 if (!verb
|| !verb
[0]) verb
= getW
;
976 if (!(request
->verb
= strdupW( verb
))) goto end
;
983 len
= strlenW( object
) + 1;
984 if (object
[0] != '/') len
++;
985 if (!(p
= path
= heap_alloc( len
* sizeof(WCHAR
) ))) goto end
;
987 if (object
[0] != '/') *p
++ = '/';
988 strcpyW( p
, object
);
989 request
->path
= path
;
991 else if (!(request
->path
= strdupW( slashW
))) goto end
;
993 if (!version
|| !version
[0]) version
= http1_1
;
994 if (!(request
->version
= strdupW( version
))) goto end
;
995 if (!(store_accept_types( request
, types
))) goto end
;
997 if (!(hrequest
= alloc_handle( &request
->hdr
))) goto end
;
998 request
->hdr
.handle
= hrequest
;
1000 send_callback( &request
->hdr
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
, &hrequest
, sizeof(hrequest
) );
1003 release_object( &request
->hdr
);
1004 release_object( &connect
->hdr
);
1005 TRACE("returning %p\n", hrequest
);
1009 /***********************************************************************
1010 * WinHttpCloseHandle (winhttp.@)
1012 BOOL WINAPI
WinHttpCloseHandle( HINTERNET handle
)
1014 object_header_t
*hdr
;
1016 TRACE("%p\n", handle
);
1018 if (!(hdr
= grab_object( handle
)))
1020 set_last_error( ERROR_INVALID_HANDLE
);
1023 release_object( hdr
);
1024 free_handle( handle
);
1028 static BOOL
query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
1034 set_last_error( ERROR_INVALID_PARAMETER
);
1040 case WINHTTP_OPTION_CONTEXT_VALUE
:
1042 if (!buffer
|| *buflen
< sizeof(DWORD_PTR
))
1044 *buflen
= sizeof(DWORD_PTR
);
1045 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
1049 *(DWORD_PTR
*)buffer
= hdr
->context
;
1050 *buflen
= sizeof(DWORD_PTR
);
1054 if (hdr
->vtbl
->query_option
) ret
= hdr
->vtbl
->query_option( hdr
, option
, buffer
, buflen
);
1057 FIXME("unimplemented option %u\n", option
);
1058 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1066 /***********************************************************************
1067 * WinHttpQueryOption (winhttp.@)
1069 BOOL WINAPI
WinHttpQueryOption( HINTERNET handle
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
1072 object_header_t
*hdr
;
1074 TRACE("%p, %u, %p, %p\n", handle
, option
, buffer
, buflen
);
1076 if (!(hdr
= grab_object( handle
)))
1078 set_last_error( ERROR_INVALID_HANDLE
);
1082 ret
= query_option( hdr
, option
, buffer
, buflen
);
1084 release_object( hdr
);
1088 static BOOL
set_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, DWORD buflen
)
1094 set_last_error( ERROR_INVALID_PARAMETER
);
1100 case WINHTTP_OPTION_CONTEXT_VALUE
:
1102 if (buflen
!= sizeof(DWORD_PTR
))
1104 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
1108 hdr
->context
= *(DWORD_PTR
*)buffer
;
1112 if (hdr
->vtbl
->set_option
) ret
= hdr
->vtbl
->set_option( hdr
, option
, buffer
, buflen
);
1115 FIXME("unimplemented option %u\n", option
);
1116 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1124 /***********************************************************************
1125 * WinHttpSetOption (winhttp.@)
1127 BOOL WINAPI
WinHttpSetOption( HINTERNET handle
, DWORD option
, LPVOID buffer
, DWORD buflen
)
1130 object_header_t
*hdr
;
1132 TRACE("%p, %u, %p, %u\n", handle
, option
, buffer
, buflen
);
1134 if (!(hdr
= grab_object( handle
)))
1136 set_last_error( ERROR_INVALID_HANDLE
);
1140 ret
= set_option( hdr
, option
, buffer
, buflen
);
1142 release_object( hdr
);
1146 static char *get_computer_name( COMPUTER_NAME_FORMAT format
)
1151 GetComputerNameExA( format
, NULL
, &size
);
1152 if (GetLastError() != ERROR_MORE_DATA
) return NULL
;
1153 if (!(ret
= heap_alloc( size
))) return NULL
;
1154 if (!GetComputerNameExA( format
, ret
, &size
))
1162 static BOOL
is_domain_suffix( const char *domain
, const char *suffix
)
1164 int len_domain
= strlen( domain
), len_suffix
= strlen( suffix
);
1166 if (len_suffix
> len_domain
) return FALSE
;
1167 if (!strcasecmp( domain
+ len_domain
- len_suffix
, suffix
)) return TRUE
;
1171 static void printf_addr( const WCHAR
*fmt
, WCHAR
*buf
, struct sockaddr_in
*addr
)
1174 (unsigned int)(ntohl( addr
->sin_addr
.s_addr
) >> 24 & 0xff),
1175 (unsigned int)(ntohl( addr
->sin_addr
.s_addr
) >> 16 & 0xff),
1176 (unsigned int)(ntohl( addr
->sin_addr
.s_addr
) >> 8 & 0xff),
1177 (unsigned int)(ntohl( addr
->sin_addr
.s_addr
) & 0xff) );
1180 static WCHAR
*build_wpad_url( const struct addrinfo
*ai
)
1182 static const WCHAR fmtW
[] =
1183 {'h','t','t','p',':','/','/','%','u','.','%','u','.','%','u','.','%','u',
1184 '/','w','p','a','d','.','d','a','t',0};
1187 while (ai
&& ai
->ai_family
!= AF_INET
) ai
= ai
->ai_next
;
1188 if (!ai
) return NULL
;
1190 if (!(ret
= GlobalAlloc( 0, sizeof(fmtW
) + 12 * sizeof(WCHAR
) ))) return NULL
;
1191 printf_addr( fmtW
, ret
, (struct sockaddr_in
*)ai
->ai_addr
);
1195 /***********************************************************************
1196 * WinHttpDetectAutoProxyConfigUrl (winhttp.@)
1198 BOOL WINAPI
WinHttpDetectAutoProxyConfigUrl( DWORD flags
, LPWSTR
*url
)
1202 TRACE("0x%08x, %p\n", flags
, url
);
1206 set_last_error( ERROR_INVALID_PARAMETER
);
1209 if (flags
& WINHTTP_AUTO_DETECT_TYPE_DHCP
) FIXME("discovery via DHCP not supported\n");
1210 if (flags
& WINHTTP_AUTO_DETECT_TYPE_DNS_A
)
1212 #ifdef HAVE_GETADDRINFO
1213 char *fqdn
, *domain
, *p
;
1215 if (!(fqdn
= get_computer_name( ComputerNamePhysicalDnsFullyQualified
))) return FALSE
;
1216 if (!(domain
= get_computer_name( ComputerNamePhysicalDnsDomain
)))
1222 while ((p
= strchr( p
, '.' )) && is_domain_suffix( p
+ 1, domain
))
1224 struct addrinfo
*ai
;
1228 if (!(name
= heap_alloc( sizeof("wpad") + strlen(p
) )))
1231 heap_free( domain
);
1234 strcpy( name
, "wpad" );
1236 res
= getaddrinfo( name
, NULL
, NULL
, &ai
);
1240 *url
= build_wpad_url( ai
);
1244 TRACE("returning %s\n", debugstr_w(*url
));
1251 heap_free( domain
);
1254 FIXME("getaddrinfo not found at build time\n");
1257 if (!ret
) set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED
);
1261 static const WCHAR Connections
[] = {
1262 'S','o','f','t','w','a','r','e','\\',
1263 'M','i','c','r','o','s','o','f','t','\\',
1264 'W','i','n','d','o','w','s','\\',
1265 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1266 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
1267 'C','o','n','n','e','c','t','i','o','n','s',0 };
1268 static const WCHAR WinHttpSettings
[] = {
1269 'W','i','n','H','t','t','p','S','e','t','t','i','n','g','s',0 };
1270 static const DWORD WINHTTP_SETTINGS_MAGIC
= 0x18;
1271 static const DWORD WININET_SETTINGS_MAGIC
= 0x46;
1272 static const DWORD PROXY_TYPE_DIRECT
= 1;
1273 static const DWORD PROXY_TYPE_PROXY
= 2;
1274 static const DWORD PROXY_USE_PAC_SCRIPT
= 4;
1275 static const DWORD PROXY_AUTODETECT_SETTINGS
= 8;
1277 struct connection_settings_header
1280 DWORD unknown
; /* always zero? */
1281 DWORD flags
; /* one or more of PROXY_* */
1284 static inline void copy_char_to_wchar_sz(const BYTE
*src
, DWORD len
, WCHAR
*dst
)
1288 for (begin
= src
; src
- begin
< len
; src
++, dst
++)
1293 /***********************************************************************
1294 * WinHttpGetDefaultProxyConfiguration (winhttp.@)
1296 BOOL WINAPI
WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO
*info
)
1300 BOOL got_from_reg
= FALSE
, direct
= TRUE
;
1303 TRACE("%p\n", info
);
1305 l
= RegOpenKeyExW( HKEY_LOCAL_MACHINE
, Connections
, 0, KEY_READ
, &key
);
1308 DWORD type
, size
= 0;
1310 l
= RegQueryValueExW( key
, WinHttpSettings
, NULL
, &type
, NULL
, &size
);
1311 if (!l
&& type
== REG_BINARY
&&
1312 size
>= sizeof(struct connection_settings_header
) + 2 * sizeof(DWORD
))
1314 BYTE
*buf
= heap_alloc( size
);
1318 struct connection_settings_header
*hdr
=
1319 (struct connection_settings_header
*)buf
;
1320 DWORD
*len
= (DWORD
*)(hdr
+ 1);
1322 l
= RegQueryValueExW( key
, WinHttpSettings
, NULL
, NULL
, buf
,
1324 if (!l
&& hdr
->magic
== WINHTTP_SETTINGS_MAGIC
&&
1327 if (hdr
->flags
& PROXY_TYPE_PROXY
)
1330 LPWSTR proxy
= NULL
;
1331 LPWSTR proxy_bypass
= NULL
;
1333 /* Sanity-check length of proxy string */
1334 if ((BYTE
*)len
- buf
+ *len
<= size
)
1337 proxy
= GlobalAlloc( 0, (*len
+ 1) * sizeof(WCHAR
) );
1339 copy_char_to_wchar_sz( (BYTE
*)(len
+ 1), *len
, proxy
);
1340 len
= (DWORD
*)((BYTE
*)(len
+ 1) + *len
);
1344 /* Sanity-check length of proxy bypass string */
1345 if ((BYTE
*)len
- buf
+ *len
<= size
)
1347 proxy_bypass
= GlobalAlloc( 0, (*len
+ 1) * sizeof(WCHAR
) );
1349 copy_char_to_wchar_sz( (BYTE
*)(len
+ 1), *len
, proxy_bypass
);
1354 GlobalFree( proxy
);
1358 info
->lpszProxy
= proxy
;
1359 info
->lpszProxyBypass
= proxy_bypass
;
1362 got_from_reg
= TRUE
;
1364 info
->dwAccessType
=
1365 WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1366 TRACE("http proxy (from registry) = %s, bypass = %s\n",
1367 debugstr_w(info
->lpszProxy
),
1368 debugstr_w(info
->lpszProxyBypass
));
1377 if (!got_from_reg
&& (envproxy
= getenv( "http_proxy" )))
1379 char *colon
, *http_proxy
;
1381 if ((colon
= strchr( envproxy
, ':' )))
1383 if (*(colon
+ 1) == '/' && *(colon
+ 2) == '/')
1385 static const char http
[] = "http://";
1387 /* It's a scheme, check that it's http */
1388 if (!strncmp( envproxy
, http
, strlen( http
) ))
1389 http_proxy
= envproxy
+ strlen( http
);
1392 WARN("unsupported scheme in $http_proxy: %s\n", envproxy
);
1397 http_proxy
= envproxy
;
1400 http_proxy
= envproxy
;
1406 len
= MultiByteToWideChar( CP_UNIXCP
, 0, http_proxy
, -1, NULL
, 0 );
1407 if ((http_proxyW
= GlobalAlloc( 0, len
* sizeof(WCHAR
))))
1409 MultiByteToWideChar( CP_UNIXCP
, 0, http_proxy
, -1, http_proxyW
, len
);
1411 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1412 info
->lpszProxy
= http_proxyW
;
1413 info
->lpszProxyBypass
= NULL
;
1414 TRACE("http proxy (from environment) = %s\n",
1415 debugstr_w(info
->lpszProxy
));
1421 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NO_PROXY
;
1422 info
->lpszProxy
= NULL
;
1423 info
->lpszProxyBypass
= NULL
;
1428 /***********************************************************************
1429 * WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
1431 BOOL WINAPI
WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG
*config
)
1433 static const WCHAR settingsW
[] =
1434 {'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};
1436 struct connection_settings_header
*hdr
= NULL
;
1437 DWORD type
, offset
, len
, size
= 0;
1440 TRACE("%p\n", config
);
1444 set_last_error( ERROR_INVALID_PARAMETER
);
1447 memset( config
, 0, sizeof(*config
) );
1448 config
->fAutoDetect
= TRUE
;
1450 if (RegOpenKeyExW( HKEY_CURRENT_USER
, Connections
, 0, KEY_READ
, &hkey
) ||
1451 RegQueryValueExW( hkey
, settingsW
, NULL
, &type
, NULL
, &size
) ||
1452 type
!= REG_BINARY
|| size
< sizeof(struct connection_settings_header
))
1457 if (!(hdr
= heap_alloc( size
))) goto done
;
1458 if (RegQueryValueExW( hkey
, settingsW
, NULL
, &type
, (BYTE
*)hdr
, &size
) ||
1459 hdr
->magic
!= WININET_SETTINGS_MAGIC
)
1465 config
->fAutoDetect
= (hdr
->flags
& PROXY_AUTODETECT_SETTINGS
) != 0;
1466 offset
= sizeof(*hdr
);
1467 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1468 len
= *(DWORD
*)((char *)hdr
+ offset
);
1469 offset
+= sizeof(DWORD
);
1470 if (len
&& hdr
->flags
& PROXY_TYPE_PROXY
)
1472 if (!(config
->lpszProxy
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1473 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszProxy
);
1476 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1477 len
= *(DWORD
*)((char *)hdr
+ offset
);
1478 offset
+= sizeof(DWORD
);
1479 if (len
&& (hdr
->flags
& PROXY_TYPE_PROXY
))
1481 if (!(config
->lpszProxyBypass
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1482 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszProxyBypass
);
1485 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1486 len
= *(DWORD
*)((char *)hdr
+ offset
);
1487 offset
+= sizeof(DWORD
);
1488 if (len
&& (hdr
->flags
& PROXY_USE_PAC_SCRIPT
))
1490 if (!(config
->lpszAutoConfigUrl
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1491 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszAutoConfigUrl
);
1496 RegCloseKey( hkey
);
1500 heap_free( config
->lpszAutoConfigUrl
);
1501 config
->lpszAutoConfigUrl
= NULL
;
1502 heap_free( config
->lpszProxy
);
1503 config
->lpszProxy
= NULL
;
1504 heap_free( config
->lpszProxyBypass
);
1505 config
->lpszProxyBypass
= NULL
;
1510 static HRESULT WINAPI
dispex_QueryInterface(
1511 IDispatchEx
*iface
, REFIID riid
, void **ppv
)
1515 if (IsEqualGUID( riid
, &IID_IUnknown
) ||
1516 IsEqualGUID( riid
, &IID_IDispatch
) ||
1517 IsEqualGUID( riid
, &IID_IDispatchEx
))
1520 return E_NOINTERFACE
;
1525 static ULONG WINAPI
dispex_AddRef(
1526 IDispatchEx
*iface
)
1531 static ULONG WINAPI
dispex_Release(
1532 IDispatchEx
*iface
)
1537 static HRESULT WINAPI
dispex_GetTypeInfoCount(
1538 IDispatchEx
*iface
, UINT
*info
)
1543 static HRESULT WINAPI
dispex_GetTypeInfo(
1544 IDispatchEx
*iface
, UINT info
, LCID lcid
, ITypeInfo
**type_info
)
1549 static HRESULT WINAPI
dispex_GetIDsOfNames(
1550 IDispatchEx
*iface
, REFIID riid
, LPOLESTR
*names
, UINT count
, LCID lcid
, DISPID
*id
)
1555 static HRESULT WINAPI
dispex_Invoke(
1556 IDispatchEx
*iface
, DISPID member
, REFIID riid
, LCID lcid
, WORD flags
,
1557 DISPPARAMS
*params
, VARIANT
*result
, EXCEPINFO
*excep
, UINT
*err
)
1562 static HRESULT WINAPI
dispex_DeleteMemberByName(
1563 IDispatchEx
*iface
, BSTR name
, DWORD flags
)
1568 static HRESULT WINAPI
dispex_DeleteMemberByDispID(
1569 IDispatchEx
*iface
, DISPID id
)
1574 static HRESULT WINAPI
dispex_GetMemberProperties(
1575 IDispatchEx
*iface
, DISPID id
, DWORD flags_fetch
, DWORD
*flags
)
1580 static HRESULT WINAPI
dispex_GetMemberName(
1581 IDispatchEx
*iface
, DISPID id
, BSTR
*name
)
1586 static HRESULT WINAPI
dispex_GetNextDispID(
1587 IDispatchEx
*iface
, DWORD flags
, DISPID id
, DISPID
*next
)
1592 static HRESULT WINAPI
dispex_GetNameSpaceParent(
1593 IDispatchEx
*iface
, IUnknown
**unk
)
1598 #define DISPID_GLOBAL_DNSRESOLVE 0x1000
1600 static HRESULT WINAPI
dispex_GetDispID(
1601 IDispatchEx
*iface
, BSTR name
, DWORD flags
, DISPID
*id
)
1603 if (!strcmpW( name
, dns_resolveW
))
1605 *id
= DISPID_GLOBAL_DNSRESOLVE
;
1608 return DISP_E_UNKNOWNNAME
;
1611 static HRESULT
dns_resolve( const WCHAR
*hostname
, VARIANT
*result
)
1613 #ifdef HAVE_GETADDRINFO
1614 static const WCHAR fmtW
[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1616 struct addrinfo
*ai
, *elem
;
1621 hostnameA
= strdupWA( hostname
);
1623 hostnameA
= get_computer_name( ComputerNamePhysicalDnsFullyQualified
);
1625 if (!hostnameA
) return E_OUTOFMEMORY
;
1626 res
= getaddrinfo( hostnameA
, NULL
, NULL
, &ai
);
1627 heap_free( hostnameA
);
1628 if (res
) return S_FALSE
;
1631 while (elem
&& elem
->ai_family
!= AF_INET
) elem
= elem
->ai_next
;
1637 printf_addr( fmtW
, addr
, (struct sockaddr_in
*)elem
->ai_addr
);
1639 V_VT( result
) = VT_BSTR
;
1640 V_BSTR( result
) = SysAllocString( addr
);
1643 FIXME("getaddrinfo not found at build time\n");
1648 static HRESULT WINAPI
dispex_InvokeEx(
1649 IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
1650 VARIANT
*result
, EXCEPINFO
*exep
, IServiceProvider
*caller
)
1652 if (id
== DISPID_GLOBAL_DNSRESOLVE
)
1654 if (params
->cArgs
!= 1) return DISP_E_BADPARAMCOUNT
;
1655 if (V_VT(¶ms
->rgvarg
[0]) != VT_BSTR
) return DISP_E_BADVARTYPE
;
1656 return dns_resolve( V_BSTR(¶ms
->rgvarg
[0]), result
);
1658 return DISP_E_MEMBERNOTFOUND
;
1661 static const IDispatchExVtbl dispex_vtbl
=
1663 dispex_QueryInterface
,
1666 dispex_GetTypeInfoCount
,
1668 dispex_GetIDsOfNames
,
1672 dispex_DeleteMemberByName
,
1673 dispex_DeleteMemberByDispID
,
1674 dispex_GetMemberProperties
,
1675 dispex_GetMemberName
,
1676 dispex_GetNextDispID
,
1677 dispex_GetNameSpaceParent
1680 static IDispatchEx global_dispex
= { &dispex_vtbl
};
1682 static HRESULT WINAPI
site_QueryInterface(
1683 IActiveScriptSite
*iface
, REFIID riid
, void **ppv
)
1687 if (IsEqualGUID( &IID_IUnknown
, riid
))
1689 else if (IsEqualGUID( &IID_IActiveScriptSite
, riid
))
1692 return E_NOINTERFACE
;
1694 IUnknown_AddRef( (IUnknown
*)*ppv
);
1698 static ULONG WINAPI
site_AddRef(
1699 IActiveScriptSite
*iface
)
1704 static ULONG WINAPI
site_Release(
1705 IActiveScriptSite
*iface
)
1710 static HRESULT WINAPI
site_GetLCID(
1711 IActiveScriptSite
*iface
, LCID
*lcid
)
1716 static HRESULT WINAPI
site_GetItemInfo(
1717 IActiveScriptSite
*iface
, LPCOLESTR name
, DWORD mask
,
1718 IUnknown
**item
, ITypeInfo
**type_info
)
1720 if (!strcmpW( name
, global_funcsW
) && mask
== SCRIPTINFO_IUNKNOWN
)
1722 *item
= (IUnknown
*)&global_dispex
;
1728 static HRESULT WINAPI
site_GetDocVersionString(
1729 IActiveScriptSite
*iface
, BSTR
*version
)
1734 static HRESULT WINAPI
site_OnScriptTerminate(
1735 IActiveScriptSite
*iface
, const VARIANT
*result
, const EXCEPINFO
*info
)
1740 static HRESULT WINAPI
site_OnStateChange(
1741 IActiveScriptSite
*iface
, SCRIPTSTATE state
)
1746 static HRESULT WINAPI
site_OnScriptError(
1747 IActiveScriptSite
*iface
, IActiveScriptError
*error
)
1752 static HRESULT WINAPI
site_OnEnterScript(
1753 IActiveScriptSite
*iface
)
1758 static HRESULT WINAPI
site_OnLeaveScript(
1759 IActiveScriptSite
*iface
)
1764 static const IActiveScriptSiteVtbl site_vtbl
=
1766 site_QueryInterface
,
1771 site_GetDocVersionString
,
1772 site_OnScriptTerminate
,
1779 static IActiveScriptSite script_site
= { &site_vtbl
};
1781 static BOOL
parse_script_result( VARIANT result
, WINHTTP_PROXY_INFO
*info
)
1783 static const WCHAR proxyW
[] = {'P','R','O','X','Y'};
1788 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NO_PROXY
;
1789 info
->lpszProxy
= NULL
;
1790 info
->lpszProxyBypass
= NULL
;
1792 if (V_VT( &result
) != VT_BSTR
) return TRUE
;
1793 TRACE("%s\n", debugstr_w( V_BSTR( &result
) ));
1795 p
= V_BSTR( &result
);
1796 while (*p
== ' ') p
++;
1798 if (len
>= 5 && !memicmpW( p
, proxyW
, sizeof(proxyW
)/sizeof(WCHAR
) ))
1801 while (*p
== ' ') p
++;
1802 if (!*p
|| *p
== ';') return TRUE
;
1803 if (!(info
->lpszProxy
= q
= strdupW( p
))) return FALSE
;
1804 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1807 if (*q
== ' ' || *q
== ';')
1817 static BSTR
include_pac_utils( BSTR script
)
1819 static const WCHAR pacjsW
[] = {'p','a','c','.','j','s',0};
1820 HMODULE hmod
= GetModuleHandleA( "winhttp.dll" );
1827 if (!(rsrc
= FindResourceW( hmod
, pacjsW
, (LPCWSTR
)40 ))) return NULL
;
1828 size
= SizeofResource( hmod
, rsrc
);
1829 data
= LoadResource( hmod
, rsrc
);
1831 len
= MultiByteToWideChar( CP_ACP
, 0, data
, size
, NULL
, 0 );
1832 if (!(ret
= SysAllocStringLen( NULL
, len
+ SysStringLen( script
) + 1 ))) return NULL
;
1833 MultiByteToWideChar( CP_ACP
, 0, data
, size
, ret
, len
);
1835 strcatW( ret
, script
);
1839 static BOOL
run_script( const BSTR script
, const WCHAR
*url
, WINHTTP_PROXY_INFO
*info
)
1841 static const WCHAR jscriptW
[] = {'J','S','c','r','i','p','t',0};
1842 static const WCHAR findproxyW
[] = {'F','i','n','d','P','r','o','x','y','F','o','r','U','R','L',0};
1843 IActiveScriptParse
*parser
= NULL
;
1844 IActiveScript
*engine
= NULL
;
1845 IDispatch
*dispatch
= NULL
;
1849 BSTR func
= NULL
, hostname
= NULL
, full_script
= NULL
;
1851 VARIANT args
[2], result
;
1855 memset( &uc
, 0, sizeof(uc
) );
1856 uc
.dwStructSize
= sizeof(uc
);
1857 if (!WinHttpCrackUrl( url
, 0, 0, &uc
)) return FALSE
;
1858 if (!(hostname
= SysAllocStringLen( NULL
, uc
.dwHostNameLength
+ 1 ))) return FALSE
;
1859 memcpy( hostname
, uc
.lpszHostName
, uc
.dwHostNameLength
* sizeof(WCHAR
) );
1860 hostname
[uc
.dwHostNameLength
] = 0;
1862 init
= CoInitialize( NULL
);
1863 hr
= CLSIDFromProgID( jscriptW
, &clsid
);
1864 if (hr
!= S_OK
) goto done
;
1866 hr
= CoCreateInstance( &clsid
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1867 &IID_IActiveScript
, (void **)&engine
);
1868 if (hr
!= S_OK
) goto done
;
1870 hr
= IActiveScript_QueryInterface( engine
, &IID_IActiveScriptParse
, (void **)&parser
);
1871 if (hr
!= S_OK
) goto done
;
1873 hr
= IActiveScriptParse64_InitNew( parser
);
1874 if (hr
!= S_OK
) goto done
;
1876 hr
= IActiveScript_SetScriptSite( engine
, &script_site
);
1877 if (hr
!= S_OK
) goto done
;
1879 hr
= IActiveScript_AddNamedItem( engine
, global_funcsW
, SCRIPTITEM_GLOBALMEMBERS
);
1880 if (hr
!= S_OK
) goto done
;
1882 if (!(full_script
= include_pac_utils( script
))) goto done
;
1884 hr
= IActiveScriptParse64_ParseScriptText( parser
, full_script
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1885 if (hr
!= S_OK
) goto done
;
1887 hr
= IActiveScript_SetScriptState( engine
, SCRIPTSTATE_STARTED
);
1888 if (hr
!= S_OK
) goto done
;
1890 hr
= IActiveScript_GetScriptDispatch( engine
, NULL
, &dispatch
);
1891 if (hr
!= S_OK
) goto done
;
1893 if (!(func
= SysAllocString( findproxyW
))) goto done
;
1894 hr
= IDispatch_GetIDsOfNames( dispatch
, &IID_NULL
, &func
, 1, LOCALE_SYSTEM_DEFAULT
, &dispid
);
1895 if (hr
!= S_OK
) goto done
;
1897 V_VT( &args
[0] ) = VT_BSTR
;
1898 V_BSTR( &args
[0] ) = hostname
;
1899 V_VT( &args
[1] ) = VT_BSTR
;
1900 V_BSTR( &args
[1] ) = SysAllocString( url
);
1902 params
.rgvarg
= args
;
1903 params
.rgdispidNamedArgs
= NULL
;
1905 params
.cNamedArgs
= 0;
1906 hr
= IDispatch_Invoke( dispatch
, dispid
, &IID_NULL
, LOCALE_SYSTEM_DEFAULT
, DISPATCH_METHOD
,
1907 ¶ms
, &result
, NULL
, NULL
);
1908 VariantClear( &args
[1] );
1911 WARN("script failed 0x%08x\n", hr
);
1914 ret
= parse_script_result( result
, info
);
1917 SysFreeString( full_script
);
1918 SysFreeString( hostname
);
1919 SysFreeString( func
);
1920 if (dispatch
) IDispatch_Release( dispatch
);
1921 if (parser
) IUnknown_Release( parser
);
1922 if (engine
) IActiveScript_Release( engine
);
1923 if (SUCCEEDED( init
)) CoUninitialize();
1924 if (!ret
) set_last_error( ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT
);
1928 static BSTR
download_script( const WCHAR
*url
)
1930 static const WCHAR typeW
[] = {'*','/','*',0};
1931 static const WCHAR
*acceptW
[] = {typeW
, NULL
};
1932 HINTERNET ses
, con
= NULL
, req
= NULL
;
1935 DWORD size
= 4096, offset
, to_read
, bytes_read
, flags
= 0;
1936 char *tmp
, *buffer
= NULL
;
1940 memset( &uc
, 0, sizeof(uc
) );
1941 uc
.dwStructSize
= sizeof(uc
);
1942 if (!WinHttpCrackUrl( url
, 0, 0, &uc
)) return NULL
;
1943 if (!(hostname
= heap_alloc( (uc
.dwHostNameLength
+ 1) * sizeof(WCHAR
) ))) return NULL
;
1944 memcpy( hostname
, uc
.lpszHostName
, uc
.dwHostNameLength
* sizeof(WCHAR
) );
1945 hostname
[uc
.dwHostNameLength
] = 0;
1947 if (!(ses
= WinHttpOpen( NULL
, WINHTTP_ACCESS_TYPE_NO_PROXY
, NULL
, NULL
, 0 ))) goto done
;
1948 if (!(con
= WinHttpConnect( ses
, hostname
, uc
.nPort
, 0 ))) goto done
;
1949 if (uc
.nScheme
== INTERNET_SCHEME_HTTPS
) flags
|= WINHTTP_FLAG_SECURE
;
1950 if (!(req
= WinHttpOpenRequest( con
, NULL
, uc
.lpszUrlPath
, NULL
, NULL
, acceptW
, flags
))) goto done
;
1951 if (!WinHttpSendRequest( req
, NULL
, 0, NULL
, 0, 0, 0 )) goto done
;
1952 if (!(WinHttpReceiveResponse( req
, 0 ))) goto done
;
1954 if (!(buffer
= heap_alloc( size
))) goto done
;
1959 if (!WinHttpReadData( req
, buffer
+ offset
, to_read
, &bytes_read
)) goto done
;
1960 if (!bytes_read
) break;
1961 to_read
-= bytes_read
;
1962 offset
+= bytes_read
;
1967 if (!(tmp
= heap_realloc( buffer
, size
))) goto done
;
1971 len
= MultiByteToWideChar( CP_ACP
, 0, buffer
, offset
, NULL
, 0 );
1972 if (!(script
= SysAllocStringLen( NULL
, len
))) goto done
;
1973 MultiByteToWideChar( CP_ACP
, 0, buffer
, offset
, script
, len
);
1977 WinHttpCloseHandle( req
);
1978 WinHttpCloseHandle( con
);
1979 WinHttpCloseHandle( ses
);
1980 heap_free( buffer
);
1981 heap_free( hostname
);
1982 if (!script
) set_last_error( ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT
);
1986 /***********************************************************************
1987 * WinHttpGetProxyForUrl (winhttp.@)
1989 BOOL WINAPI
WinHttpGetProxyForUrl( HINTERNET hsession
, LPCWSTR url
, WINHTTP_AUTOPROXY_OPTIONS
*options
,
1990 WINHTTP_PROXY_INFO
*info
)
1992 WCHAR
*detected_pac_url
= NULL
;
1993 const WCHAR
*pac_url
;
1998 TRACE("%p, %s, %p, %p\n", hsession
, debugstr_w(url
), options
, info
);
2000 if (!(session
= (session_t
*)grab_object( hsession
)))
2002 set_last_error( ERROR_INVALID_HANDLE
);
2005 if (session
->hdr
.type
!= WINHTTP_HANDLE_TYPE_SESSION
)
2007 release_object( &session
->hdr
);
2008 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
2011 if (!url
|| !options
|| !info
||
2012 !(options
->dwFlags
& (WINHTTP_AUTOPROXY_AUTO_DETECT
|WINHTTP_AUTOPROXY_CONFIG_URL
)) ||
2013 ((options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
) && !options
->dwAutoDetectFlags
) ||
2014 ((options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
) &&
2015 (options
->dwFlags
& WINHTTP_AUTOPROXY_CONFIG_URL
)))
2017 release_object( &session
->hdr
);
2018 set_last_error( ERROR_INVALID_PARAMETER
);
2021 if (options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
&&
2022 !WinHttpDetectAutoProxyConfigUrl( options
->dwAutoDetectFlags
, &detected_pac_url
))
2024 set_last_error( ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR
);
2027 if (options
->dwFlags
& WINHTTP_AUTOPROXY_CONFIG_URL
) pac_url
= options
->lpszAutoConfigUrl
;
2028 else pac_url
= detected_pac_url
;
2030 if (!(script
= download_script( pac_url
))) goto done
;
2031 ret
= run_script( script
, url
, info
);
2032 SysFreeString( script
);
2035 GlobalFree( detected_pac_url
);
2036 release_object( &session
->hdr
);
2040 /***********************************************************************
2041 * WinHttpSetDefaultProxyConfiguration (winhttp.@)
2043 BOOL WINAPI
WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO
*info
)
2050 TRACE("%p\n", info
);
2054 set_last_error( ERROR_INVALID_PARAMETER
);
2057 switch (info
->dwAccessType
)
2059 case WINHTTP_ACCESS_TYPE_NO_PROXY
:
2061 case WINHTTP_ACCESS_TYPE_NAMED_PROXY
:
2062 if (!info
->lpszProxy
)
2064 set_last_error( ERROR_INVALID_PARAMETER
);
2067 /* Only ASCII characters are allowed */
2068 for (src
= info
->lpszProxy
; *src
; src
++)
2071 set_last_error( ERROR_INVALID_PARAMETER
);
2074 if (info
->lpszProxyBypass
)
2076 for (src
= info
->lpszProxyBypass
; *src
; src
++)
2079 set_last_error( ERROR_INVALID_PARAMETER
);
2085 set_last_error( ERROR_INVALID_PARAMETER
);
2089 l
= RegCreateKeyExW( HKEY_LOCAL_MACHINE
, Connections
, 0, NULL
, 0,
2090 KEY_WRITE
, NULL
, &key
, NULL
);
2093 DWORD size
= sizeof(struct connection_settings_header
) + 2 * sizeof(DWORD
);
2096 if (info
->dwAccessType
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
2098 size
+= strlenW( info
->lpszProxy
);
2099 if (info
->lpszProxyBypass
)
2100 size
+= strlenW( info
->lpszProxyBypass
);
2102 buf
= heap_alloc( size
);
2105 struct connection_settings_header
*hdr
=
2106 (struct connection_settings_header
*)buf
;
2107 DWORD
*len
= (DWORD
*)(hdr
+ 1);
2109 hdr
->magic
= WINHTTP_SETTINGS_MAGIC
;
2111 if (info
->dwAccessType
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
2115 hdr
->flags
= PROXY_TYPE_PROXY
;
2116 *len
++ = strlenW( info
->lpszProxy
);
2117 for (dst
= (BYTE
*)len
, src
= info
->lpszProxy
; *src
;
2121 if (info
->lpszProxyBypass
)
2123 *len
++ = strlenW( info
->lpszProxyBypass
);
2124 for (dst
= (BYTE
*)len
, src
= info
->lpszProxyBypass
; *src
;
2133 hdr
->flags
= PROXY_TYPE_DIRECT
;
2137 l
= RegSetValueExW( key
, WinHttpSettings
, 0, REG_BINARY
, buf
, size
);
2147 /***********************************************************************
2148 * WinHttpSetStatusCallback (winhttp.@)
2150 WINHTTP_STATUS_CALLBACK WINAPI
WinHttpSetStatusCallback( HINTERNET handle
, WINHTTP_STATUS_CALLBACK callback
,
2151 DWORD flags
, DWORD_PTR reserved
)
2153 object_header_t
*hdr
;
2154 WINHTTP_STATUS_CALLBACK ret
;
2156 TRACE("%p, %p, 0x%08x, 0x%lx\n", handle
, callback
, flags
, reserved
);
2158 if (!(hdr
= grab_object( handle
)))
2160 set_last_error( ERROR_INVALID_HANDLE
);
2161 return WINHTTP_INVALID_STATUS_CALLBACK
;
2163 ret
= hdr
->callback
;
2164 hdr
->callback
= callback
;
2165 hdr
->notify_mask
= flags
;
2167 release_object( hdr
);
2171 /***********************************************************************
2172 * WinHttpSetTimeouts (winhttp.@)
2174 BOOL WINAPI
WinHttpSetTimeouts( HINTERNET handle
, int resolve
, int connect
, int send
, int receive
)
2177 object_header_t
*hdr
;
2181 TRACE("%p, %d, %d, %d, %d\n", handle
, resolve
, connect
, send
, receive
);
2183 if (resolve
< -1 || connect
< -1 || send
< -1 || receive
< -1)
2185 set_last_error( ERROR_INVALID_PARAMETER
);
2189 if (!(hdr
= grab_object( handle
)))
2191 set_last_error( ERROR_INVALID_HANDLE
);
2197 case WINHTTP_HANDLE_TYPE_REQUEST
:
2198 request
= (request_t
*)hdr
;
2199 request
->connect_timeout
= connect
;
2201 if (resolve
< 0) resolve
= 0;
2202 request
->resolve_timeout
= resolve
;
2204 if (send
< 0) send
= 0;
2205 request
->send_timeout
= send
;
2207 if (receive
< 0) receive
= 0;
2208 request
->recv_timeout
= receive
;
2210 if (netconn_connected( &request
->netconn
))
2212 if (netconn_set_timeout( &request
->netconn
, TRUE
, send
)) ret
= FALSE
;
2213 if (netconn_set_timeout( &request
->netconn
, FALSE
, receive
)) ret
= FALSE
;
2216 release_object( &request
->hdr
);
2219 case WINHTTP_HANDLE_TYPE_SESSION
:
2220 session
= (session_t
*)hdr
;
2221 session
->connect_timeout
= connect
;
2223 if (resolve
< 0) resolve
= 0;
2224 session
->resolve_timeout
= resolve
;
2226 if (send
< 0) send
= 0;
2227 session
->send_timeout
= send
;
2229 if (receive
< 0) receive
= 0;
2230 session
->recv_timeout
= receive
;
2234 release_object( hdr
);
2235 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
2241 static const WCHAR wkday
[7][4] =
2242 {{'S','u','n', 0}, {'M','o','n', 0}, {'T','u','e', 0}, {'W','e','d', 0},
2243 {'T','h','u', 0}, {'F','r','i', 0}, {'S','a','t', 0}};
2244 static const WCHAR month
[12][4] =
2245 {{'J','a','n', 0}, {'F','e','b', 0}, {'M','a','r', 0}, {'A','p','r', 0},
2246 {'M','a','y', 0}, {'J','u','n', 0}, {'J','u','l', 0}, {'A','u','g', 0},
2247 {'S','e','p', 0}, {'O','c','t', 0}, {'N','o','v', 0}, {'D','e','c', 0}};
2249 /***********************************************************************
2250 * WinHttpTimeFromSystemTime (WININET.@)
2252 BOOL WINAPI
WinHttpTimeFromSystemTime( const SYSTEMTIME
*time
, LPWSTR string
)
2254 static const WCHAR format
[] =
2255 {'%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2256 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0};
2258 TRACE("%p, %p\n", time
, string
);
2260 if (!time
|| !string
) return FALSE
;
2262 sprintfW( string
, format
,
2263 wkday
[time
->wDayOfWeek
],
2265 month
[time
->wMonth
- 1],
2274 /***********************************************************************
2275 * WinHttpTimeToSystemTime (WININET.@)
2277 BOOL WINAPI
WinHttpTimeToSystemTime( LPCWSTR string
, SYSTEMTIME
*time
)
2280 const WCHAR
*s
= string
;
2283 TRACE("%s, %p\n", debugstr_w(string
), time
);
2285 if (!string
|| !time
) return FALSE
;
2287 /* Windows does this too */
2288 GetSystemTime( time
);
2290 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2291 * a SYSTEMTIME structure.
2294 while (*s
&& !isalphaW( *s
)) s
++;
2295 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2296 time
->wDayOfWeek
= 7;
2298 for (i
= 0; i
< 7; i
++)
2300 if (toupperW( wkday
[i
][0] ) == toupperW( s
[0] ) &&
2301 toupperW( wkday
[i
][1] ) == toupperW( s
[1] ) &&
2302 toupperW( wkday
[i
][2] ) == toupperW( s
[2] ) )
2304 time
->wDayOfWeek
= i
;
2309 if (time
->wDayOfWeek
> 6) return TRUE
;
2310 while (*s
&& !isdigitW( *s
)) s
++;
2311 time
->wDay
= strtolW( s
, &end
, 10 );
2314 while (*s
&& !isalphaW( *s
)) s
++;
2315 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2318 for (i
= 0; i
< 12; i
++)
2320 if (toupperW( month
[i
][0]) == toupperW( s
[0] ) &&
2321 toupperW( month
[i
][1]) == toupperW( s
[1] ) &&
2322 toupperW( month
[i
][2]) == toupperW( s
[2] ) )
2324 time
->wMonth
= i
+ 1;
2328 if (time
->wMonth
== 0) return TRUE
;
2330 while (*s
&& !isdigitW( *s
)) s
++;
2331 if (*s
== '\0') return TRUE
;
2332 time
->wYear
= strtolW( s
, &end
, 10 );
2335 while (*s
&& !isdigitW( *s
)) s
++;
2336 if (*s
== '\0') return TRUE
;
2337 time
->wHour
= strtolW( s
, &end
, 10 );
2340 while (*s
&& !isdigitW( *s
)) s
++;
2341 if (*s
== '\0') return TRUE
;
2342 time
->wMinute
= strtolW( s
, &end
, 10 );
2345 while (*s
&& !isdigitW( *s
)) s
++;
2346 if (*s
== '\0') return TRUE
;
2347 time
->wSecond
= strtolW( s
, &end
, 10 );
2349 time
->wMilliseconds
= 0;