2 * Copyright 2008 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
21 #include "wine/debug.h"
36 #include "winhttp_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(winhttp
);
40 #define DEFAULT_RESOLVE_TIMEOUT 0
41 #define DEFAULT_CONNECT_TIMEOUT 20000
42 #define DEFAULT_SEND_TIMEOUT 30000
43 #define DEFAULT_RECEIVE_TIMEOUT 30000
45 static const WCHAR global_funcsW
[] = {'g','l','o','b','a','l','_','f','u','n','c','s',0};
46 static const WCHAR dns_resolveW
[] = {'d','n','s','_','r','e','s','o','l','v','e',0};
48 void set_last_error( DWORD error
)
51 SetLastError( error
);
54 DWORD
get_last_error( void )
57 return GetLastError();
60 void send_callback( object_header_t
*hdr
, DWORD status
, LPVOID info
, DWORD buflen
)
62 TRACE("%p, 0x%08x, %p, %u\n", hdr
, status
, info
, buflen
);
64 if (hdr
->callback
&& (hdr
->notify_mask
& status
)) hdr
->callback( hdr
->handle
, hdr
->context
, status
, info
, buflen
);
67 /***********************************************************************
68 * WinHttpCheckPlatform (winhttp.@)
70 BOOL WINAPI
WinHttpCheckPlatform( void )
76 /***********************************************************************
77 * session_destroy (internal)
79 static void session_destroy( object_header_t
*hdr
)
81 session_t
*session
= (session_t
*)hdr
;
82 struct list
*item
, *next
;
85 TRACE("%p\n", session
);
87 LIST_FOR_EACH_SAFE( item
, next
, &session
->cookie_cache
)
89 domain
= LIST_ENTRY( item
, domain_t
, entry
);
90 delete_domain( domain
);
92 heap_free( session
->agent
);
93 heap_free( session
->proxy_server
);
94 heap_free( session
->proxy_bypass
);
95 heap_free( session
->proxy_username
);
96 heap_free( session
->proxy_password
);
103 static BOOL
session_query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
105 session_t
*session
= (session_t
*)hdr
;
109 case WINHTTP_OPTION_REDIRECT_POLICY
:
111 if (!buffer
|| *buflen
< sizeof(DWORD
))
113 *buflen
= sizeof(DWORD
);
114 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
118 *(DWORD
*)buffer
= hdr
->redirect_policy
;
119 *buflen
= sizeof(DWORD
);
122 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
123 *(DWORD
*)buffer
= session
->resolve_timeout
;
124 *buflen
= sizeof(DWORD
);
126 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
127 *(DWORD
*)buffer
= session
->connect_timeout
;
128 *buflen
= sizeof(DWORD
);
130 case WINHTTP_OPTION_SEND_TIMEOUT
:
131 *(DWORD
*)buffer
= session
->send_timeout
;
132 *buflen
= sizeof(DWORD
);
134 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
135 *(DWORD
*)buffer
= session
->recv_timeout
;
136 *buflen
= sizeof(DWORD
);
139 FIXME("unimplemented option %u\n", option
);
140 set_last_error( ERROR_INVALID_PARAMETER
);
145 static BOOL
session_set_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, DWORD buflen
)
147 session_t
*session
= (session_t
*)hdr
;
151 case WINHTTP_OPTION_PROXY
:
153 WINHTTP_PROXY_INFO
*pi
= buffer
;
155 FIXME("%u %s %s\n", pi
->dwAccessType
, debugstr_w(pi
->lpszProxy
), debugstr_w(pi
->lpszProxyBypass
));
158 case WINHTTP_OPTION_REDIRECT_POLICY
:
162 if (buflen
!= sizeof(policy
))
164 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
168 policy
= *(DWORD
*)buffer
;
169 TRACE("0x%x\n", policy
);
170 hdr
->redirect_policy
= policy
;
173 case WINHTTP_OPTION_DISABLE_FEATURE
:
174 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
176 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
177 session
->resolve_timeout
= *(DWORD
*)buffer
;
179 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
180 session
->connect_timeout
= *(DWORD
*)buffer
;
182 case WINHTTP_OPTION_SEND_TIMEOUT
:
183 session
->send_timeout
= *(DWORD
*)buffer
;
185 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
186 session
->recv_timeout
= *(DWORD
*)buffer
;
189 FIXME("unimplemented option %u\n", option
);
190 set_last_error( ERROR_INVALID_PARAMETER
);
195 static const object_vtbl_t session_vtbl
=
198 session_query_option
,
202 /***********************************************************************
203 * WinHttpOpen (winhttp.@)
205 HINTERNET WINAPI
WinHttpOpen( LPCWSTR agent
, DWORD access
, LPCWSTR proxy
, LPCWSTR bypass
, DWORD flags
)
208 HINTERNET handle
= NULL
;
211 int error
= WSAStartup(MAKEWORD(2, 2), &wsaData
);
212 if (error
) ERR("WSAStartup failed: %d\n", error
);
215 TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent
), access
, debugstr_w(proxy
), debugstr_w(bypass
), flags
);
217 if (!(session
= heap_alloc_zero( sizeof(session_t
) ))) return NULL
;
219 session
->hdr
.type
= WINHTTP_HANDLE_TYPE_SESSION
;
220 session
->hdr
.vtbl
= &session_vtbl
;
221 session
->hdr
.flags
= flags
;
222 session
->hdr
.refs
= 1;
223 session
->hdr
.redirect_policy
= WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP
;
224 list_init( &session
->hdr
.children
);
225 session
->resolve_timeout
= DEFAULT_RESOLVE_TIMEOUT
;
226 session
->connect_timeout
= DEFAULT_CONNECT_TIMEOUT
;
227 session
->send_timeout
= DEFAULT_SEND_TIMEOUT
;
228 session
->recv_timeout
= DEFAULT_RECEIVE_TIMEOUT
;
229 list_init( &session
->cookie_cache
);
231 if (agent
&& !(session
->agent
= strdupW( agent
))) goto end
;
232 if (access
== WINHTTP_ACCESS_TYPE_DEFAULT_PROXY
)
234 WINHTTP_PROXY_INFO info
;
236 WinHttpGetDefaultProxyConfiguration( &info
);
237 session
->access
= info
.dwAccessType
;
238 if (info
.lpszProxy
&& !(session
->proxy_server
= strdupW( info
.lpszProxy
)))
240 GlobalFree( (LPWSTR
)info
.lpszProxy
);
241 GlobalFree( (LPWSTR
)info
.lpszProxyBypass
);
244 if (info
.lpszProxyBypass
&& !(session
->proxy_bypass
= strdupW( info
.lpszProxyBypass
)))
246 GlobalFree( (LPWSTR
)info
.lpszProxy
);
247 GlobalFree( (LPWSTR
)info
.lpszProxyBypass
);
251 else if (access
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
253 session
->access
= access
;
254 if (proxy
&& !(session
->proxy_server
= strdupW( proxy
))) goto end
;
255 if (bypass
&& !(session
->proxy_bypass
= strdupW( bypass
))) goto end
;
258 if (!(handle
= alloc_handle( &session
->hdr
))) goto end
;
259 session
->hdr
.handle
= handle
;
262 release_object( &session
->hdr
);
263 TRACE("returning %p\n", handle
);
267 /***********************************************************************
268 * connect_destroy (internal)
270 static void connect_destroy( object_header_t
*hdr
)
272 connect_t
*connect
= (connect_t
*)hdr
;
274 TRACE("%p\n", connect
);
276 release_object( &connect
->session
->hdr
);
278 heap_free( connect
->hostname
);
279 heap_free( connect
->servername
);
280 heap_free( connect
->username
);
281 heap_free( connect
->password
);
282 heap_free( connect
);
285 static BOOL
connect_query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
287 connect_t
*connect
= (connect_t
*)hdr
;
291 case WINHTTP_OPTION_PARENT_HANDLE
:
293 if (!buffer
|| *buflen
< sizeof(HINTERNET
))
295 *buflen
= sizeof(HINTERNET
);
296 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
300 *(HINTERNET
*)buffer
= ((object_header_t
*)connect
->session
)->handle
;
301 *buflen
= sizeof(HINTERNET
);
304 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
305 *(DWORD
*)buffer
= connect
->session
->resolve_timeout
;
306 *buflen
= sizeof(DWORD
);
308 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
309 *(DWORD
*)buffer
= connect
->session
->connect_timeout
;
310 *buflen
= sizeof(DWORD
);
312 case WINHTTP_OPTION_SEND_TIMEOUT
:
313 *(DWORD
*)buffer
= connect
->session
->send_timeout
;
314 *buflen
= sizeof(DWORD
);
316 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
317 *(DWORD
*)buffer
= connect
->session
->recv_timeout
;
318 *buflen
= sizeof(DWORD
);
321 FIXME("unimplemented option %u\n", option
);
322 set_last_error( ERROR_INVALID_PARAMETER
);
327 static const object_vtbl_t connect_vtbl
=
330 connect_query_option
,
334 static BOOL
domain_matches(LPCWSTR server
, LPCWSTR domain
)
336 static const WCHAR localW
[] = { '<','l','o','c','a','l','>',0 };
339 if (!strcmpiW( domain
, localW
) && !strchrW( server
, '.' ))
341 else if (*domain
== '*')
343 if (domain
[1] == '.')
347 /* For a hostname to match a wildcard, the last domain must match
348 * the wildcard exactly. E.g. if the wildcard is *.a.b, and the
349 * hostname is www.foo.a.b, it matches, but a.b does not.
351 dot
= strchrW( server
, '.' );
354 int len
= strlenW( dot
+ 1 );
356 if (len
> strlenW( domain
+ 2 ))
360 /* The server's domain is longer than the wildcard, so it
361 * could be a subdomain. Compare the last portion of the
364 ptr
= dot
+ len
+ 1 - strlenW( domain
+ 2 );
365 if (!strcmpiW( ptr
, domain
+ 2 ))
367 /* This is only a match if the preceding character is
368 * a '.', i.e. that it is a matching domain. E.g.
369 * if domain is '*.b.c' and server is 'www.ab.c' they
372 ret
= *(ptr
- 1) == '.';
376 ret
= !strcmpiW( dot
+ 1, domain
+ 2 );
381 ret
= !strcmpiW( server
, domain
);
385 /* Matches INTERNET_MAX_HOST_NAME_LENGTH in wininet.h, also RFC 1035 */
386 #define MAX_HOST_NAME_LENGTH 256
388 static BOOL
should_bypass_proxy(session_t
*session
, LPCWSTR server
)
393 if (!session
->proxy_bypass
) return FALSE
;
394 ptr
= session
->proxy_bypass
;
398 ptr
= strchrW( ptr
, ';' );
400 ptr
= strchrW( tmp
, ' ' );
403 if (ptr
- tmp
< MAX_HOST_NAME_LENGTH
)
405 WCHAR domain
[MAX_HOST_NAME_LENGTH
];
407 memcpy( domain
, tmp
, (ptr
- tmp
) * sizeof(WCHAR
) );
408 domain
[ptr
- tmp
] = 0;
409 ret
= domain_matches( server
, domain
);
414 ret
= domain_matches( server
, tmp
);
415 } while (ptr
&& !ret
);
419 BOOL
set_server_for_hostname( connect_t
*connect
, LPCWSTR server
, INTERNET_PORT port
)
421 session_t
*session
= connect
->session
;
424 if (session
->proxy_server
&& !should_bypass_proxy(session
, server
))
428 if ((colon
= strchrW( session
->proxy_server
, ':' )))
430 if (!connect
->servername
|| strncmpiW( connect
->servername
,
431 session
->proxy_server
, colon
- session
->proxy_server
- 1 ))
433 heap_free( connect
->servername
);
434 connect
->resolved
= FALSE
;
435 if (!(connect
->servername
= heap_alloc(
436 (colon
- session
->proxy_server
+ 1) * sizeof(WCHAR
) )))
441 memcpy( connect
->servername
, session
->proxy_server
,
442 (colon
- session
->proxy_server
) * sizeof(WCHAR
) );
443 connect
->servername
[colon
- session
->proxy_server
] = 0;
445 connect
->serverport
= atoiW( colon
+ 1 );
447 connect
->serverport
= INTERNET_DEFAULT_PORT
;
452 if (!connect
->servername
|| strcmpiW( connect
->servername
,
453 session
->proxy_server
))
455 heap_free( connect
->servername
);
456 connect
->resolved
= FALSE
;
457 if (!(connect
->servername
= strdupW( session
->proxy_server
)))
462 connect
->serverport
= INTERNET_DEFAULT_PORT
;
468 heap_free( connect
->servername
);
469 connect
->resolved
= FALSE
;
470 if (!(connect
->servername
= strdupW( server
)))
475 connect
->serverport
= port
;
481 /***********************************************************************
482 * WinHttpConnect (winhttp.@)
484 HINTERNET WINAPI
WinHttpConnect( HINTERNET hsession
, LPCWSTR server
, INTERNET_PORT port
, DWORD reserved
)
488 HINTERNET hconnect
= NULL
;
490 TRACE("%p, %s, %u, %x\n", hsession
, debugstr_w(server
), port
, reserved
);
494 set_last_error( ERROR_INVALID_PARAMETER
);
497 if (!(session
= (session_t
*)grab_object( hsession
)))
499 set_last_error( ERROR_INVALID_HANDLE
);
502 if (session
->hdr
.type
!= WINHTTP_HANDLE_TYPE_SESSION
)
504 release_object( &session
->hdr
);
505 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
508 if (!(connect
= heap_alloc_zero( sizeof(connect_t
) )))
510 release_object( &session
->hdr
);
513 connect
->hdr
.type
= WINHTTP_HANDLE_TYPE_CONNECT
;
514 connect
->hdr
.vtbl
= &connect_vtbl
;
515 connect
->hdr
.refs
= 1;
516 connect
->hdr
.flags
= session
->hdr
.flags
;
517 connect
->hdr
.callback
= session
->hdr
.callback
;
518 connect
->hdr
.notify_mask
= session
->hdr
.notify_mask
;
519 connect
->hdr
.context
= session
->hdr
.context
;
520 list_init( &connect
->hdr
.children
);
522 addref_object( &session
->hdr
);
523 connect
->session
= session
;
524 list_add_head( &session
->hdr
.children
, &connect
->hdr
.entry
);
526 if (!(connect
->hostname
= strdupW( server
))) goto end
;
527 connect
->hostport
= port
;
528 if (!set_server_for_hostname( connect
, server
, port
)) goto end
;
530 if (!(hconnect
= alloc_handle( &connect
->hdr
))) goto end
;
531 connect
->hdr
.handle
= hconnect
;
533 send_callback( &session
->hdr
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
, &hconnect
, sizeof(hconnect
) );
536 release_object( &connect
->hdr
);
537 release_object( &session
->hdr
);
538 TRACE("returning %p\n", hconnect
);
542 /***********************************************************************
543 * request_destroy (internal)
545 static void request_destroy( object_header_t
*hdr
)
547 request_t
*request
= (request_t
*)hdr
;
550 TRACE("%p\n", request
);
552 release_object( &request
->connect
->hdr
);
554 heap_free( request
->verb
);
555 heap_free( request
->path
);
556 heap_free( request
->version
);
557 heap_free( request
->raw_headers
);
558 heap_free( request
->status_text
);
559 for (i
= 0; i
< request
->num_headers
; i
++)
561 heap_free( request
->headers
[i
].field
);
562 heap_free( request
->headers
[i
].value
);
564 heap_free( request
->headers
);
565 for (i
= 0; i
< request
->num_accept_types
; i
++) heap_free( request
->accept_types
[i
] );
566 heap_free( request
->accept_types
);
567 heap_free( request
);
570 static void str_to_buffer( WCHAR
*buffer
, const WCHAR
*str
, LPDWORD buflen
)
573 if (str
) len
= strlenW( str
);
574 if (buffer
&& *buflen
> len
)
576 if (str
) memcpy( buffer
, str
, len
* sizeof(WCHAR
) );
579 *buflen
= len
* sizeof(WCHAR
);
582 static WCHAR
*blob_to_str( DWORD encoding
, CERT_NAME_BLOB
*blob
)
585 DWORD size
, format
= CERT_SIMPLE_NAME_STR
| CERT_NAME_STR_CRLF_FLAG
;
587 size
= CertNameToStrW( encoding
, blob
, format
, NULL
, 0 );
588 if ((ret
= LocalAlloc( 0, size
* sizeof(WCHAR
) )))
589 CertNameToStrW( encoding
, blob
, format
, ret
, size
);
594 static BOOL
request_query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
596 request_t
*request
= (request_t
*)hdr
;
600 case WINHTTP_OPTION_SECURITY_FLAGS
:
605 if (!buffer
|| *buflen
< sizeof(flags
))
607 *buflen
= sizeof(flags
);
608 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
613 if (hdr
->flags
& WINHTTP_FLAG_SECURE
) flags
|= SECURITY_FLAG_SECURE
;
614 flags
|= request
->netconn
.security_flags
;
615 bits
= netconn_get_cipher_strength( &request
->netconn
);
617 flags
|= SECURITY_FLAG_STRENGTH_STRONG
;
619 flags
|= SECURITY_FLAG_STRENGTH_MEDIUM
;
621 flags
|= SECURITY_FLAG_STRENGTH_WEAK
;
622 *(DWORD
*)buffer
= flags
;
623 *buflen
= sizeof(flags
);
626 case WINHTTP_OPTION_SERVER_CERT_CONTEXT
:
628 const CERT_CONTEXT
*cert
;
630 if (!buffer
|| *buflen
< sizeof(cert
))
632 *buflen
= sizeof(cert
);
633 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
637 if (!(cert
= netconn_get_certificate( &request
->netconn
))) return FALSE
;
638 *(CERT_CONTEXT
**)buffer
= (CERT_CONTEXT
*)cert
;
639 *buflen
= sizeof(cert
);
642 case WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT
:
644 const CERT_CONTEXT
*cert
;
645 const CRYPT_OID_INFO
*oidInfo
;
646 WINHTTP_CERTIFICATE_INFO
*ci
= buffer
;
648 FIXME("partial stub\n");
650 if (!buffer
|| *buflen
< sizeof(*ci
))
652 *buflen
= sizeof(*ci
);
653 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
656 if (!(cert
= netconn_get_certificate( &request
->netconn
))) return FALSE
;
658 ci
->ftExpiry
= cert
->pCertInfo
->NotAfter
;
659 ci
->ftStart
= cert
->pCertInfo
->NotBefore
;
660 ci
->lpszSubjectInfo
= blob_to_str( cert
->dwCertEncodingType
, &cert
->pCertInfo
->Subject
);
661 ci
->lpszIssuerInfo
= blob_to_str( cert
->dwCertEncodingType
, &cert
->pCertInfo
->Issuer
);
662 ci
->lpszProtocolName
= NULL
;
663 oidInfo
= CryptFindOIDInfo( CRYPT_OID_INFO_OID_KEY
,
664 cert
->pCertInfo
->SignatureAlgorithm
.pszObjId
,
667 ci
->lpszSignatureAlgName
= (LPWSTR
)oidInfo
->pwszName
;
669 ci
->lpszSignatureAlgName
= NULL
;
670 ci
->lpszEncryptionAlgName
= NULL
;
671 ci
->dwKeySize
= netconn_get_cipher_strength( &request
->netconn
);
673 CertFreeCertificateContext( cert
);
674 *buflen
= sizeof(*ci
);
677 case WINHTTP_OPTION_SECURITY_KEY_BITNESS
:
679 if (!buffer
|| *buflen
< sizeof(DWORD
))
681 *buflen
= sizeof(DWORD
);
682 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
686 *(DWORD
*)buffer
= netconn_get_cipher_strength( &request
->netconn
);
687 *buflen
= sizeof(DWORD
);
690 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
691 *(DWORD
*)buffer
= request
->resolve_timeout
;
692 *buflen
= sizeof(DWORD
);
694 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
695 *(DWORD
*)buffer
= request
->connect_timeout
;
696 *buflen
= sizeof(DWORD
);
698 case WINHTTP_OPTION_SEND_TIMEOUT
:
699 *(DWORD
*)buffer
= request
->send_timeout
;
700 *buflen
= sizeof(DWORD
);
702 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
703 *(DWORD
*)buffer
= request
->recv_timeout
;
704 *buflen
= sizeof(DWORD
);
707 case WINHTTP_OPTION_USERNAME
:
708 str_to_buffer( buffer
, request
->connect
->username
, buflen
);
711 case WINHTTP_OPTION_PASSWORD
:
712 str_to_buffer( buffer
, request
->connect
->password
, buflen
);
715 case WINHTTP_OPTION_PROXY_USERNAME
:
716 str_to_buffer( buffer
, request
->connect
->session
->proxy_username
, buflen
);
719 case WINHTTP_OPTION_PROXY_PASSWORD
:
720 str_to_buffer( buffer
, request
->connect
->session
->proxy_password
, buflen
);
724 FIXME("unimplemented option %u\n", option
);
725 set_last_error( ERROR_INVALID_PARAMETER
);
730 static WCHAR
*buffer_to_str( WCHAR
*buffer
, DWORD buflen
)
733 if ((ret
= heap_alloc( (buflen
+ 1) * sizeof(WCHAR
))))
735 memcpy( ret
, buffer
, buflen
* sizeof(WCHAR
) );
739 set_last_error( ERROR_OUTOFMEMORY
);
743 static BOOL
request_set_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, DWORD buflen
)
745 request_t
*request
= (request_t
*)hdr
;
749 case WINHTTP_OPTION_PROXY
:
751 WINHTTP_PROXY_INFO
*pi
= buffer
;
753 FIXME("%u %s %s\n", pi
->dwAccessType
, debugstr_w(pi
->lpszProxy
), debugstr_w(pi
->lpszProxyBypass
));
756 case WINHTTP_OPTION_DISABLE_FEATURE
:
760 if (buflen
!= sizeof(DWORD
))
762 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
766 disable
= *(DWORD
*)buffer
;
767 TRACE("0x%x\n", disable
);
768 hdr
->disable_flags
|= disable
;
771 case WINHTTP_OPTION_AUTOLOGON_POLICY
:
775 if (buflen
!= sizeof(DWORD
))
777 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
781 policy
= *(DWORD
*)buffer
;
782 TRACE("0x%x\n", policy
);
783 hdr
->logon_policy
= policy
;
786 case WINHTTP_OPTION_REDIRECT_POLICY
:
790 if (buflen
!= sizeof(DWORD
))
792 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
796 policy
= *(DWORD
*)buffer
;
797 TRACE("0x%x\n", policy
);
798 hdr
->redirect_policy
= policy
;
801 case WINHTTP_OPTION_SECURITY_FLAGS
:
805 if (buflen
< sizeof(DWORD
))
807 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
810 flags
= *(DWORD
*)buffer
;
811 TRACE("0x%x\n", flags
);
812 if (!(flags
& (SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|
813 SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
|
814 SECURITY_FLAG_IGNORE_UNKNOWN_CA
|
815 SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE
)))
817 set_last_error( ERROR_INVALID_PARAMETER
);
820 request
->netconn
.security_flags
= flags
;
823 case WINHTTP_OPTION_RESOLVE_TIMEOUT
:
824 request
->resolve_timeout
= *(DWORD
*)buffer
;
826 case WINHTTP_OPTION_CONNECT_TIMEOUT
:
827 request
->connect_timeout
= *(DWORD
*)buffer
;
829 case WINHTTP_OPTION_SEND_TIMEOUT
:
830 request
->send_timeout
= *(DWORD
*)buffer
;
832 case WINHTTP_OPTION_RECEIVE_TIMEOUT
:
833 request
->recv_timeout
= *(DWORD
*)buffer
;
836 case WINHTTP_OPTION_USERNAME
:
838 connect_t
*connect
= request
->connect
;
840 heap_free( connect
->username
);
841 if (!(connect
->username
= buffer_to_str( buffer
, buflen
))) return FALSE
;
844 case WINHTTP_OPTION_PASSWORD
:
846 connect_t
*connect
= request
->connect
;
848 heap_free( connect
->password
);
849 if (!(connect
->password
= buffer_to_str( buffer
, buflen
))) return FALSE
;
852 case WINHTTP_OPTION_PROXY_USERNAME
:
854 session_t
*session
= request
->connect
->session
;
856 heap_free( session
->proxy_username
);
857 if (!(session
->proxy_username
= buffer_to_str( buffer
, buflen
))) return FALSE
;
860 case WINHTTP_OPTION_PROXY_PASSWORD
:
862 session_t
*session
= request
->connect
->session
;
864 heap_free( session
->proxy_password
);
865 if (!(session
->proxy_password
= buffer_to_str( buffer
, buflen
))) return FALSE
;
869 FIXME("unimplemented option %u\n", option
);
870 set_last_error( ERROR_INVALID_PARAMETER
);
875 static const object_vtbl_t request_vtbl
=
878 request_query_option
,
882 static BOOL
store_accept_types( request_t
*request
, const WCHAR
**accept_types
)
884 const WCHAR
**types
= accept_types
;
887 if (!types
) return TRUE
;
890 request
->num_accept_types
++;
893 if (!request
->num_accept_types
) return TRUE
;
894 if (!(request
->accept_types
= heap_alloc( request
->num_accept_types
* sizeof(WCHAR
*))))
896 request
->num_accept_types
= 0;
899 types
= accept_types
;
900 for (i
= 0; i
< request
->num_accept_types
; i
++)
902 if (!(request
->accept_types
[i
] = strdupW( *types
)))
904 for (; i
>= 0; i
--) heap_free( request
->accept_types
[i
] );
905 heap_free( request
->accept_types
);
906 request
->accept_types
= NULL
;
907 request
->num_accept_types
= 0;
915 /***********************************************************************
916 * WinHttpOpenRequest (winhttp.@)
918 HINTERNET WINAPI
WinHttpOpenRequest( HINTERNET hconnect
, LPCWSTR verb
, LPCWSTR object
, LPCWSTR version
,
919 LPCWSTR referrer
, LPCWSTR
*types
, DWORD flags
)
923 HINTERNET hrequest
= NULL
;
925 TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect
, debugstr_w(verb
), debugstr_w(object
),
926 debugstr_w(version
), debugstr_w(referrer
), types
, flags
);
928 if(types
&& TRACE_ON(winhttp
)) {
931 TRACE("accept types:\n");
932 for(iter
= types
; *iter
; iter
++)
933 TRACE(" %s\n", debugstr_w(*iter
));
936 if (!(connect
= (connect_t
*)grab_object( hconnect
)))
938 set_last_error( ERROR_INVALID_HANDLE
);
941 if (connect
->hdr
.type
!= WINHTTP_HANDLE_TYPE_CONNECT
)
943 release_object( &connect
->hdr
);
944 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
947 if (!(request
= heap_alloc_zero( sizeof(request_t
) )))
949 release_object( &connect
->hdr
);
952 request
->hdr
.type
= WINHTTP_HANDLE_TYPE_REQUEST
;
953 request
->hdr
.vtbl
= &request_vtbl
;
954 request
->hdr
.refs
= 1;
955 request
->hdr
.flags
= flags
;
956 request
->hdr
.callback
= connect
->hdr
.callback
;
957 request
->hdr
.notify_mask
= connect
->hdr
.notify_mask
;
958 request
->hdr
.context
= connect
->hdr
.context
;
959 list_init( &request
->hdr
.children
);
961 addref_object( &connect
->hdr
);
962 request
->connect
= connect
;
963 list_add_head( &connect
->hdr
.children
, &request
->hdr
.entry
);
965 if (!netconn_init( &request
->netconn
, request
->hdr
.flags
& WINHTTP_FLAG_SECURE
)) goto end
;
966 request
->resolve_timeout
= connect
->session
->resolve_timeout
;
967 request
->connect_timeout
= connect
->session
->connect_timeout
;
968 request
->send_timeout
= connect
->session
->send_timeout
;
969 request
->recv_timeout
= connect
->session
->recv_timeout
;
971 if (!verb
|| !verb
[0]) verb
= getW
;
972 if (!(request
->verb
= strdupW( verb
))) goto end
;
979 len
= strlenW( object
) + 1;
980 if (object
[0] != '/') len
++;
981 if (!(p
= path
= heap_alloc( len
* sizeof(WCHAR
) ))) goto end
;
983 if (object
[0] != '/') *p
++ = '/';
984 strcpyW( p
, object
);
985 request
->path
= path
;
987 else if (!(request
->path
= strdupW( slashW
))) goto end
;
989 if (!version
|| !version
[0]) version
= http1_1
;
990 if (!(request
->version
= strdupW( version
))) goto end
;
991 if (!(store_accept_types( request
, types
))) goto end
;
993 if (!(hrequest
= alloc_handle( &request
->hdr
))) goto end
;
994 request
->hdr
.handle
= hrequest
;
996 send_callback( &request
->hdr
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
, &hrequest
, sizeof(hrequest
) );
999 release_object( &request
->hdr
);
1000 release_object( &connect
->hdr
);
1001 TRACE("returning %p\n", hrequest
);
1005 /***********************************************************************
1006 * WinHttpCloseHandle (winhttp.@)
1008 BOOL WINAPI
WinHttpCloseHandle( HINTERNET handle
)
1010 object_header_t
*hdr
;
1012 TRACE("%p\n", handle
);
1014 if (!(hdr
= grab_object( handle
)))
1016 set_last_error( ERROR_INVALID_HANDLE
);
1019 release_object( hdr
);
1020 free_handle( handle
);
1024 static BOOL
query_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
1030 set_last_error( ERROR_INVALID_PARAMETER
);
1036 case WINHTTP_OPTION_CONTEXT_VALUE
:
1038 if (!buffer
|| *buflen
< sizeof(DWORD_PTR
))
1040 *buflen
= sizeof(DWORD_PTR
);
1041 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
1045 *(DWORD_PTR
*)buffer
= hdr
->context
;
1046 *buflen
= sizeof(DWORD_PTR
);
1050 if (hdr
->vtbl
->query_option
) ret
= hdr
->vtbl
->query_option( hdr
, option
, buffer
, buflen
);
1053 FIXME("unimplemented option %u\n", option
);
1054 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1062 /***********************************************************************
1063 * WinHttpQueryOption (winhttp.@)
1065 BOOL WINAPI
WinHttpQueryOption( HINTERNET handle
, DWORD option
, LPVOID buffer
, LPDWORD buflen
)
1068 object_header_t
*hdr
;
1070 TRACE("%p, %u, %p, %p\n", handle
, option
, buffer
, buflen
);
1072 if (!(hdr
= grab_object( handle
)))
1074 set_last_error( ERROR_INVALID_HANDLE
);
1078 ret
= query_option( hdr
, option
, buffer
, buflen
);
1080 release_object( hdr
);
1084 static BOOL
set_option( object_header_t
*hdr
, DWORD option
, LPVOID buffer
, DWORD buflen
)
1090 set_last_error( ERROR_INVALID_PARAMETER
);
1096 case WINHTTP_OPTION_CONTEXT_VALUE
:
1098 if (buflen
!= sizeof(DWORD_PTR
))
1100 set_last_error( ERROR_INSUFFICIENT_BUFFER
);
1104 hdr
->context
= *(DWORD_PTR
*)buffer
;
1108 if (hdr
->vtbl
->set_option
) ret
= hdr
->vtbl
->set_option( hdr
, option
, buffer
, buflen
);
1111 FIXME("unimplemented option %u\n", option
);
1112 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
1120 /***********************************************************************
1121 * WinHttpSetOption (winhttp.@)
1123 BOOL WINAPI
WinHttpSetOption( HINTERNET handle
, DWORD option
, LPVOID buffer
, DWORD buflen
)
1126 object_header_t
*hdr
;
1128 TRACE("%p, %u, %p, %u\n", handle
, option
, buffer
, buflen
);
1130 if (!(hdr
= grab_object( handle
)))
1132 set_last_error( ERROR_INVALID_HANDLE
);
1136 ret
= set_option( hdr
, option
, buffer
, buflen
);
1138 release_object( hdr
);
1142 static char *get_computer_name( COMPUTER_NAME_FORMAT format
)
1147 GetComputerNameExA( format
, NULL
, &size
);
1148 if (GetLastError() != ERROR_MORE_DATA
) return NULL
;
1149 if (!(ret
= heap_alloc( size
))) return NULL
;
1150 if (!GetComputerNameExA( format
, ret
, &size
))
1158 static BOOL
is_domain_suffix( const char *domain
, const char *suffix
)
1160 int len_domain
= strlen( domain
), len_suffix
= strlen( suffix
);
1162 if (len_suffix
> len_domain
) return FALSE
;
1163 if (!strcasecmp( domain
+ len_domain
- len_suffix
, suffix
)) return TRUE
;
1167 static void printf_addr( const WCHAR
*fmt
, WCHAR
*buf
, struct sockaddr_in
*addr
)
1170 (unsigned int)(ntohl( addr
->sin_addr
.s_addr
) >> 24 & 0xff),
1171 (unsigned int)(ntohl( addr
->sin_addr
.s_addr
) >> 16 & 0xff),
1172 (unsigned int)(ntohl( addr
->sin_addr
.s_addr
) >> 8 & 0xff),
1173 (unsigned int)(ntohl( addr
->sin_addr
.s_addr
) & 0xff) );
1176 static WCHAR
*build_wpad_url( const struct addrinfo
*ai
)
1178 static const WCHAR fmtW
[] =
1179 {'h','t','t','p',':','/','/','%','u','.','%','u','.','%','u','.','%','u',
1180 '/','w','p','a','d','.','d','a','t',0};
1183 while (ai
&& ai
->ai_family
!= AF_INET
) ai
= ai
->ai_next
;
1184 if (!ai
) return NULL
;
1186 if (!(ret
= GlobalAlloc( 0, sizeof(fmtW
) + 12 * sizeof(WCHAR
) ))) return NULL
;
1187 printf_addr( fmtW
, ret
, (struct sockaddr_in
*)ai
->ai_addr
);
1191 /***********************************************************************
1192 * WinHttpDetectAutoProxyConfigUrl (winhttp.@)
1194 BOOL WINAPI
WinHttpDetectAutoProxyConfigUrl( DWORD flags
, LPWSTR
*url
)
1198 TRACE("0x%08x, %p\n", flags
, url
);
1202 set_last_error( ERROR_INVALID_PARAMETER
);
1205 if (flags
& WINHTTP_AUTO_DETECT_TYPE_DHCP
) FIXME("discovery via DHCP not supported\n");
1206 if (flags
& WINHTTP_AUTO_DETECT_TYPE_DNS_A
)
1208 #ifdef HAVE_GETADDRINFO
1209 char *fqdn
, *domain
, *p
;
1211 if (!(fqdn
= get_computer_name( ComputerNamePhysicalDnsFullyQualified
))) return FALSE
;
1212 if (!(domain
= get_computer_name( ComputerNamePhysicalDnsDomain
)))
1218 while ((p
= strchr( p
, '.' )) && is_domain_suffix( p
+ 1, domain
))
1220 struct addrinfo
*ai
;
1224 if (!(name
= heap_alloc( sizeof("wpad") + strlen(p
) )))
1227 heap_free( domain
);
1230 strcpy( name
, "wpad" );
1232 res
= getaddrinfo( name
, NULL
, NULL
, &ai
);
1236 *url
= build_wpad_url( ai
);
1240 TRACE("returning %s\n", debugstr_w(*url
));
1247 heap_free( domain
);
1250 FIXME("getaddrinfo not found at build time\n");
1253 if (!ret
) set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED
);
1257 static const WCHAR Connections
[] = {
1258 'S','o','f','t','w','a','r','e','\\',
1259 'M','i','c','r','o','s','o','f','t','\\',
1260 'W','i','n','d','o','w','s','\\',
1261 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1262 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
1263 'C','o','n','n','e','c','t','i','o','n','s',0 };
1264 static const WCHAR WinHttpSettings
[] = {
1265 'W','i','n','H','t','t','p','S','e','t','t','i','n','g','s',0 };
1266 static const DWORD WINHTTP_SETTINGS_MAGIC
= 0x18;
1267 static const DWORD WININET_SETTINGS_MAGIC
= 0x46;
1268 static const DWORD PROXY_TYPE_DIRECT
= 1;
1269 static const DWORD PROXY_TYPE_PROXY
= 2;
1270 static const DWORD PROXY_USE_PAC_SCRIPT
= 4;
1271 static const DWORD PROXY_AUTODETECT_SETTINGS
= 8;
1273 struct connection_settings_header
1276 DWORD unknown
; /* always zero? */
1277 DWORD flags
; /* one or more of PROXY_* */
1280 static inline void copy_char_to_wchar_sz(const BYTE
*src
, DWORD len
, WCHAR
*dst
)
1284 for (begin
= src
; src
- begin
< len
; src
++, dst
++)
1289 /***********************************************************************
1290 * WinHttpGetDefaultProxyConfiguration (winhttp.@)
1292 BOOL WINAPI
WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO
*info
)
1296 BOOL got_from_reg
= FALSE
, direct
= TRUE
;
1299 TRACE("%p\n", info
);
1301 l
= RegOpenKeyExW( HKEY_LOCAL_MACHINE
, Connections
, 0, KEY_READ
, &key
);
1304 DWORD type
, size
= 0;
1306 l
= RegQueryValueExW( key
, WinHttpSettings
, NULL
, &type
, NULL
, &size
);
1307 if (!l
&& type
== REG_BINARY
&&
1308 size
>= sizeof(struct connection_settings_header
) + 2 * sizeof(DWORD
))
1310 BYTE
*buf
= heap_alloc( size
);
1314 struct connection_settings_header
*hdr
=
1315 (struct connection_settings_header
*)buf
;
1316 DWORD
*len
= (DWORD
*)(hdr
+ 1);
1318 l
= RegQueryValueExW( key
, WinHttpSettings
, NULL
, NULL
, buf
,
1320 if (!l
&& hdr
->magic
== WINHTTP_SETTINGS_MAGIC
&&
1323 if (hdr
->flags
& PROXY_TYPE_PROXY
)
1326 LPWSTR proxy
= NULL
;
1327 LPWSTR proxy_bypass
= NULL
;
1329 /* Sanity-check length of proxy string */
1330 if ((BYTE
*)len
- buf
+ *len
<= size
)
1333 proxy
= GlobalAlloc( 0, (*len
+ 1) * sizeof(WCHAR
) );
1335 copy_char_to_wchar_sz( (BYTE
*)(len
+ 1), *len
, proxy
);
1336 len
= (DWORD
*)((BYTE
*)(len
+ 1) + *len
);
1340 /* Sanity-check length of proxy bypass string */
1341 if ((BYTE
*)len
- buf
+ *len
<= size
)
1343 proxy_bypass
= GlobalAlloc( 0, (*len
+ 1) * sizeof(WCHAR
) );
1345 copy_char_to_wchar_sz( (BYTE
*)(len
+ 1), *len
, proxy_bypass
);
1350 GlobalFree( proxy
);
1354 info
->lpszProxy
= proxy
;
1355 info
->lpszProxyBypass
= proxy_bypass
;
1358 got_from_reg
= TRUE
;
1360 info
->dwAccessType
=
1361 WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1362 TRACE("http proxy (from registry) = %s, bypass = %s\n",
1363 debugstr_w(info
->lpszProxy
),
1364 debugstr_w(info
->lpszProxyBypass
));
1373 if (!got_from_reg
&& (envproxy
= getenv( "http_proxy" )))
1375 char *colon
, *http_proxy
;
1377 if ((colon
= strchr( envproxy
, ':' )))
1379 if (*(colon
+ 1) == '/' && *(colon
+ 2) == '/')
1381 static const char http
[] = "http://";
1383 /* It's a scheme, check that it's http */
1384 if (!strncmp( envproxy
, http
, strlen( http
) ))
1385 http_proxy
= envproxy
+ strlen( http
);
1388 WARN("unsupported scheme in $http_proxy: %s\n", envproxy
);
1393 http_proxy
= envproxy
;
1396 http_proxy
= envproxy
;
1402 len
= MultiByteToWideChar( CP_UNIXCP
, 0, http_proxy
, -1, NULL
, 0 );
1403 if ((http_proxyW
= GlobalAlloc( 0, len
* sizeof(WCHAR
))))
1405 MultiByteToWideChar( CP_UNIXCP
, 0, http_proxy
, -1, http_proxyW
, len
);
1407 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1408 info
->lpszProxy
= http_proxyW
;
1409 info
->lpszProxyBypass
= NULL
;
1410 TRACE("http proxy (from environment) = %s\n",
1411 debugstr_w(info
->lpszProxy
));
1417 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NO_PROXY
;
1418 info
->lpszProxy
= NULL
;
1419 info
->lpszProxyBypass
= NULL
;
1424 /***********************************************************************
1425 * WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
1427 BOOL WINAPI
WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG
*config
)
1429 static const WCHAR settingsW
[] =
1430 {'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};
1432 struct connection_settings_header
*hdr
= NULL
;
1433 DWORD type
, offset
, len
, size
= 0;
1436 TRACE("%p\n", config
);
1440 set_last_error( ERROR_INVALID_PARAMETER
);
1443 memset( config
, 0, sizeof(*config
) );
1444 config
->fAutoDetect
= TRUE
;
1446 if (RegOpenKeyExW( HKEY_CURRENT_USER
, Connections
, 0, KEY_READ
, &hkey
) ||
1447 RegQueryValueExW( hkey
, settingsW
, NULL
, &type
, NULL
, &size
) ||
1448 type
!= REG_BINARY
|| size
< sizeof(struct connection_settings_header
))
1453 if (!(hdr
= heap_alloc( size
))) goto done
;
1454 if (RegQueryValueExW( hkey
, settingsW
, NULL
, &type
, (BYTE
*)hdr
, &size
) ||
1455 hdr
->magic
!= WININET_SETTINGS_MAGIC
)
1461 config
->fAutoDetect
= (hdr
->flags
& PROXY_AUTODETECT_SETTINGS
) != 0;
1462 offset
= sizeof(*hdr
);
1463 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1464 len
= *(DWORD
*)((char *)hdr
+ offset
);
1465 offset
+= sizeof(DWORD
);
1466 if (len
&& hdr
->flags
& PROXY_TYPE_PROXY
)
1468 if (!(config
->lpszProxy
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1469 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszProxy
);
1472 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1473 len
= *(DWORD
*)((char *)hdr
+ offset
);
1474 offset
+= sizeof(DWORD
);
1475 if (len
&& (hdr
->flags
& PROXY_TYPE_PROXY
))
1477 if (!(config
->lpszProxyBypass
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1478 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszProxyBypass
);
1481 if (offset
+ sizeof(DWORD
) > size
) goto done
;
1482 len
= *(DWORD
*)((char *)hdr
+ offset
);
1483 offset
+= sizeof(DWORD
);
1484 if (len
&& (hdr
->flags
& PROXY_USE_PAC_SCRIPT
))
1486 if (!(config
->lpszAutoConfigUrl
= GlobalAlloc( 0, (len
+ 1) * sizeof(WCHAR
) ))) goto done
;
1487 copy_char_to_wchar_sz( (const BYTE
*)hdr
+ offset
, len
, config
->lpszAutoConfigUrl
);
1492 RegCloseKey( hkey
);
1496 heap_free( config
->lpszAutoConfigUrl
);
1497 config
->lpszAutoConfigUrl
= NULL
;
1498 heap_free( config
->lpszProxy
);
1499 config
->lpszProxy
= NULL
;
1500 heap_free( config
->lpszProxyBypass
);
1501 config
->lpszProxyBypass
= NULL
;
1506 static HRESULT WINAPI
dispex_QueryInterface(
1507 IDispatchEx
*iface
, REFIID riid
, void **ppv
)
1511 if (IsEqualGUID( riid
, &IID_IUnknown
) ||
1512 IsEqualGUID( riid
, &IID_IDispatch
) ||
1513 IsEqualGUID( riid
, &IID_IDispatchEx
))
1516 return E_NOINTERFACE
;
1521 static ULONG WINAPI
dispex_AddRef(
1522 IDispatchEx
*iface
)
1527 static ULONG WINAPI
dispex_Release(
1528 IDispatchEx
*iface
)
1533 static HRESULT WINAPI
dispex_GetTypeInfoCount(
1534 IDispatchEx
*iface
, UINT
*info
)
1539 static HRESULT WINAPI
dispex_GetTypeInfo(
1540 IDispatchEx
*iface
, UINT info
, LCID lcid
, ITypeInfo
**type_info
)
1545 static HRESULT WINAPI
dispex_GetIDsOfNames(
1546 IDispatchEx
*iface
, REFIID riid
, LPOLESTR
*names
, UINT count
, LCID lcid
, DISPID
*id
)
1551 static HRESULT WINAPI
dispex_Invoke(
1552 IDispatchEx
*iface
, DISPID member
, REFIID riid
, LCID lcid
, WORD flags
,
1553 DISPPARAMS
*params
, VARIANT
*result
, EXCEPINFO
*excep
, UINT
*err
)
1558 static HRESULT WINAPI
dispex_DeleteMemberByName(
1559 IDispatchEx
*iface
, BSTR name
, DWORD flags
)
1564 static HRESULT WINAPI
dispex_DeleteMemberByDispID(
1565 IDispatchEx
*iface
, DISPID id
)
1570 static HRESULT WINAPI
dispex_GetMemberProperties(
1571 IDispatchEx
*iface
, DISPID id
, DWORD flags_fetch
, DWORD
*flags
)
1576 static HRESULT WINAPI
dispex_GetMemberName(
1577 IDispatchEx
*iface
, DISPID id
, BSTR
*name
)
1582 static HRESULT WINAPI
dispex_GetNextDispID(
1583 IDispatchEx
*iface
, DWORD flags
, DISPID id
, DISPID
*next
)
1588 static HRESULT WINAPI
dispex_GetNameSpaceParent(
1589 IDispatchEx
*iface
, IUnknown
**unk
)
1594 #define DISPID_GLOBAL_DNSRESOLVE 0x1000
1596 static HRESULT WINAPI
dispex_GetDispID(
1597 IDispatchEx
*iface
, BSTR name
, DWORD flags
, DISPID
*id
)
1599 if (!strcmpW( name
, dns_resolveW
))
1601 *id
= DISPID_GLOBAL_DNSRESOLVE
;
1604 return DISP_E_UNKNOWNNAME
;
1607 static HRESULT
dns_resolve( const WCHAR
*hostname
, VARIANT
*result
)
1609 #ifdef HAVE_GETADDRINFO
1610 static const WCHAR fmtW
[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1612 struct addrinfo
*ai
, *elem
;
1617 hostnameA
= strdupWA( hostname
);
1619 hostnameA
= get_computer_name( ComputerNamePhysicalDnsFullyQualified
);
1621 if (!hostnameA
) return E_OUTOFMEMORY
;
1622 res
= getaddrinfo( hostnameA
, NULL
, NULL
, &ai
);
1623 heap_free( hostnameA
);
1624 if (res
) return S_FALSE
;
1627 while (elem
&& elem
->ai_family
!= AF_INET
) elem
= elem
->ai_next
;
1633 printf_addr( fmtW
, addr
, (struct sockaddr_in
*)elem
->ai_addr
);
1635 V_VT( result
) = VT_BSTR
;
1636 V_BSTR( result
) = SysAllocString( addr
);
1639 FIXME("getaddrinfo not found at build time\n");
1644 static HRESULT WINAPI
dispex_InvokeEx(
1645 IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
1646 VARIANT
*result
, EXCEPINFO
*exep
, IServiceProvider
*caller
)
1648 if (id
== DISPID_GLOBAL_DNSRESOLVE
)
1650 if (params
->cArgs
!= 1) return DISP_E_BADPARAMCOUNT
;
1651 if (V_VT(¶ms
->rgvarg
[0]) != VT_BSTR
) return DISP_E_BADVARTYPE
;
1652 return dns_resolve( V_BSTR(¶ms
->rgvarg
[0]), result
);
1654 return DISP_E_MEMBERNOTFOUND
;
1657 static const IDispatchExVtbl dispex_vtbl
=
1659 dispex_QueryInterface
,
1662 dispex_GetTypeInfoCount
,
1664 dispex_GetIDsOfNames
,
1668 dispex_DeleteMemberByName
,
1669 dispex_DeleteMemberByDispID
,
1670 dispex_GetMemberProperties
,
1671 dispex_GetMemberName
,
1672 dispex_GetNextDispID
,
1673 dispex_GetNameSpaceParent
1676 static IDispatchEx global_dispex
= { &dispex_vtbl
};
1678 static HRESULT WINAPI
site_QueryInterface(
1679 IActiveScriptSite
*iface
, REFIID riid
, void **ppv
)
1683 if (IsEqualGUID( &IID_IUnknown
, riid
))
1685 else if (IsEqualGUID( &IID_IActiveScriptSite
, riid
))
1688 return E_NOINTERFACE
;
1690 IUnknown_AddRef( (IUnknown
*)*ppv
);
1694 static ULONG WINAPI
site_AddRef(
1695 IActiveScriptSite
*iface
)
1700 static ULONG WINAPI
site_Release(
1701 IActiveScriptSite
*iface
)
1706 static HRESULT WINAPI
site_GetLCID(
1707 IActiveScriptSite
*iface
, LCID
*lcid
)
1712 static HRESULT WINAPI
site_GetItemInfo(
1713 IActiveScriptSite
*iface
, LPCOLESTR name
, DWORD mask
,
1714 IUnknown
**item
, ITypeInfo
**type_info
)
1716 if (!strcmpW( name
, global_funcsW
) && mask
== SCRIPTINFO_IUNKNOWN
)
1718 *item
= (IUnknown
*)&global_dispex
;
1724 static HRESULT WINAPI
site_GetDocVersionString(
1725 IActiveScriptSite
*iface
, BSTR
*version
)
1730 static HRESULT WINAPI
site_OnScriptTerminate(
1731 IActiveScriptSite
*iface
, const VARIANT
*result
, const EXCEPINFO
*info
)
1736 static HRESULT WINAPI
site_OnStateChange(
1737 IActiveScriptSite
*iface
, SCRIPTSTATE state
)
1742 static HRESULT WINAPI
site_OnScriptError(
1743 IActiveScriptSite
*iface
, IActiveScriptError
*error
)
1748 static HRESULT WINAPI
site_OnEnterScript(
1749 IActiveScriptSite
*iface
)
1754 static HRESULT WINAPI
site_OnLeaveScript(
1755 IActiveScriptSite
*iface
)
1760 static const IActiveScriptSiteVtbl site_vtbl
=
1762 site_QueryInterface
,
1767 site_GetDocVersionString
,
1768 site_OnScriptTerminate
,
1775 static IActiveScriptSite script_site
= { &site_vtbl
};
1777 static BOOL
parse_script_result( VARIANT result
, WINHTTP_PROXY_INFO
*info
)
1779 static const WCHAR proxyW
[] = {'P','R','O','X','Y'};
1784 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NO_PROXY
;
1785 info
->lpszProxy
= NULL
;
1786 info
->lpszProxyBypass
= NULL
;
1788 if (V_VT( &result
) != VT_BSTR
) return TRUE
;
1789 TRACE("%s\n", debugstr_w( V_BSTR( &result
) ));
1791 p
= V_BSTR( &result
);
1792 while (*p
== ' ') p
++;
1794 if (len
>= 5 && !memicmpW( p
, proxyW
, sizeof(proxyW
)/sizeof(WCHAR
) ))
1797 while (*p
== ' ') p
++;
1798 if (!*p
|| *p
== ';') return TRUE
;
1799 if (!(info
->lpszProxy
= q
= strdupW( p
))) return FALSE
;
1800 info
->dwAccessType
= WINHTTP_ACCESS_TYPE_NAMED_PROXY
;
1803 if (*q
== ' ' || *q
== ';')
1813 static BSTR
include_pac_utils( BSTR script
)
1815 static const WCHAR pacjsW
[] = {'p','a','c','.','j','s',0};
1816 HMODULE hmod
= GetModuleHandleA( "winhttp.dll" );
1823 if (!(rsrc
= FindResourceW( hmod
, pacjsW
, (LPCWSTR
)40 ))) return NULL
;
1824 size
= SizeofResource( hmod
, rsrc
);
1825 data
= LoadResource( hmod
, rsrc
);
1827 len
= MultiByteToWideChar( CP_ACP
, 0, data
, size
, NULL
, 0 );
1828 if (!(ret
= SysAllocStringLen( NULL
, len
+ SysStringLen( script
) + 1 ))) return NULL
;
1829 MultiByteToWideChar( CP_ACP
, 0, data
, size
, ret
, len
);
1831 strcatW( ret
, script
);
1835 static BOOL
run_script( const BSTR script
, const WCHAR
*url
, WINHTTP_PROXY_INFO
*info
)
1837 static const WCHAR jscriptW
[] = {'J','S','c','r','i','p','t',0};
1838 static const WCHAR findproxyW
[] = {'F','i','n','d','P','r','o','x','y','F','o','r','U','R','L',0};
1839 IActiveScriptParse
*parser
= NULL
;
1840 IActiveScript
*engine
= NULL
;
1841 IDispatch
*dispatch
= NULL
;
1845 BSTR func
= NULL
, hostname
= NULL
, full_script
= NULL
;
1847 VARIANT args
[2], result
;
1851 memset( &uc
, 0, sizeof(uc
) );
1852 uc
.dwStructSize
= sizeof(uc
);
1853 if (!WinHttpCrackUrl( url
, 0, 0, &uc
)) return FALSE
;
1854 if (!(hostname
= SysAllocStringLen( NULL
, uc
.dwHostNameLength
+ 1 ))) return FALSE
;
1855 memcpy( hostname
, uc
.lpszHostName
, uc
.dwHostNameLength
* sizeof(WCHAR
) );
1856 hostname
[uc
.dwHostNameLength
] = 0;
1858 init
= CoInitialize( NULL
);
1859 hr
= CLSIDFromProgID( jscriptW
, &clsid
);
1860 if (hr
!= S_OK
) goto done
;
1862 hr
= CoCreateInstance( &clsid
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1863 &IID_IActiveScript
, (void **)&engine
);
1864 if (hr
!= S_OK
) goto done
;
1866 hr
= IActiveScript_QueryInterface( engine
, &IID_IActiveScriptParse
, (void **)&parser
);
1867 if (hr
!= S_OK
) goto done
;
1869 hr
= IActiveScriptParse64_InitNew( parser
);
1870 if (hr
!= S_OK
) goto done
;
1872 hr
= IActiveScript_SetScriptSite( engine
, &script_site
);
1873 if (hr
!= S_OK
) goto done
;
1875 hr
= IActiveScript_AddNamedItem( engine
, global_funcsW
, SCRIPTITEM_GLOBALMEMBERS
);
1876 if (hr
!= S_OK
) goto done
;
1878 if (!(full_script
= include_pac_utils( script
))) goto done
;
1880 hr
= IActiveScriptParse64_ParseScriptText( parser
, full_script
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1881 if (hr
!= S_OK
) goto done
;
1883 hr
= IActiveScript_SetScriptState( engine
, SCRIPTSTATE_STARTED
);
1884 if (hr
!= S_OK
) goto done
;
1886 hr
= IActiveScript_GetScriptDispatch( engine
, NULL
, &dispatch
);
1887 if (hr
!= S_OK
) goto done
;
1889 if (!(func
= SysAllocString( findproxyW
))) goto done
;
1890 hr
= IDispatch_GetIDsOfNames( dispatch
, &IID_NULL
, &func
, 1, LOCALE_SYSTEM_DEFAULT
, &dispid
);
1891 if (hr
!= S_OK
) goto done
;
1893 V_VT( &args
[0] ) = VT_BSTR
;
1894 V_BSTR( &args
[0] ) = hostname
;
1895 V_VT( &args
[1] ) = VT_BSTR
;
1896 V_BSTR( &args
[1] ) = SysAllocString( url
);
1898 params
.rgvarg
= args
;
1899 params
.rgdispidNamedArgs
= NULL
;
1901 params
.cNamedArgs
= 0;
1902 hr
= IDispatch_Invoke( dispatch
, dispid
, &IID_NULL
, LOCALE_SYSTEM_DEFAULT
, DISPATCH_METHOD
,
1903 ¶ms
, &result
, NULL
, NULL
);
1904 VariantClear( &args
[1] );
1907 WARN("script failed 0x%08x\n", hr
);
1910 ret
= parse_script_result( result
, info
);
1913 SysFreeString( full_script
);
1914 SysFreeString( hostname
);
1915 SysFreeString( func
);
1916 if (dispatch
) IDispatch_Release( dispatch
);
1917 if (parser
) IUnknown_Release( parser
);
1918 if (engine
) IActiveScript_Release( engine
);
1919 if (SUCCEEDED( init
)) CoUninitialize();
1920 if (!ret
) set_last_error( ERROR_WINHTTP_BAD_AUTO_PROXY_SCRIPT
);
1924 static BSTR
download_script( const WCHAR
*url
)
1926 static const WCHAR typeW
[] = {'*','/','*',0};
1927 static const WCHAR
*acceptW
[] = {typeW
, NULL
};
1928 HINTERNET ses
, con
= NULL
, req
= NULL
;
1931 DWORD size
= 4096, offset
, to_read
, bytes_read
, flags
= 0;
1932 char *tmp
, *buffer
= NULL
;
1936 memset( &uc
, 0, sizeof(uc
) );
1937 uc
.dwStructSize
= sizeof(uc
);
1938 if (!WinHttpCrackUrl( url
, 0, 0, &uc
)) return NULL
;
1939 if (!(hostname
= heap_alloc( (uc
.dwHostNameLength
+ 1) * sizeof(WCHAR
) ))) return NULL
;
1940 memcpy( hostname
, uc
.lpszHostName
, uc
.dwHostNameLength
* sizeof(WCHAR
) );
1941 hostname
[uc
.dwHostNameLength
] = 0;
1943 if (!(ses
= WinHttpOpen( NULL
, WINHTTP_ACCESS_TYPE_NO_PROXY
, NULL
, NULL
, 0 ))) goto done
;
1944 if (!(con
= WinHttpConnect( ses
, hostname
, uc
.nPort
, 0 ))) goto done
;
1945 if (uc
.nScheme
== INTERNET_SCHEME_HTTPS
) flags
|= WINHTTP_FLAG_SECURE
;
1946 if (!(req
= WinHttpOpenRequest( con
, NULL
, uc
.lpszUrlPath
, NULL
, NULL
, acceptW
, flags
))) goto done
;
1947 if (!WinHttpSendRequest( req
, NULL
, 0, NULL
, 0, 0, 0 )) goto done
;
1948 if (!(WinHttpReceiveResponse( req
, 0 ))) goto done
;
1950 if (!(buffer
= heap_alloc( size
))) goto done
;
1955 if (!WinHttpReadData( req
, buffer
+ offset
, to_read
, &bytes_read
)) goto done
;
1956 if (!bytes_read
) break;
1957 to_read
-= bytes_read
;
1958 offset
+= bytes_read
;
1963 if (!(tmp
= heap_realloc( buffer
, size
))) goto done
;
1967 len
= MultiByteToWideChar( CP_ACP
, 0, buffer
, offset
, NULL
, 0 );
1968 if (!(script
= SysAllocStringLen( NULL
, len
))) goto done
;
1969 MultiByteToWideChar( CP_ACP
, 0, buffer
, offset
, script
, len
);
1973 WinHttpCloseHandle( req
);
1974 WinHttpCloseHandle( con
);
1975 WinHttpCloseHandle( ses
);
1976 heap_free( buffer
);
1977 heap_free( hostname
);
1978 if (!script
) set_last_error( ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT
);
1982 /***********************************************************************
1983 * WinHttpGetProxyForUrl (winhttp.@)
1985 BOOL WINAPI
WinHttpGetProxyForUrl( HINTERNET hsession
, LPCWSTR url
, WINHTTP_AUTOPROXY_OPTIONS
*options
,
1986 WINHTTP_PROXY_INFO
*info
)
1988 WCHAR
*detected_pac_url
= NULL
;
1989 const WCHAR
*pac_url
;
1994 TRACE("%p, %s, %p, %p\n", hsession
, debugstr_w(url
), options
, info
);
1996 if (!(session
= (session_t
*)grab_object( hsession
)))
1998 set_last_error( ERROR_INVALID_HANDLE
);
2001 if (session
->hdr
.type
!= WINHTTP_HANDLE_TYPE_SESSION
)
2003 release_object( &session
->hdr
);
2004 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
2007 if (!url
|| !options
|| !info
||
2008 !(options
->dwFlags
& (WINHTTP_AUTOPROXY_AUTO_DETECT
|WINHTTP_AUTOPROXY_CONFIG_URL
)) ||
2009 ((options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
) && !options
->dwAutoDetectFlags
) ||
2010 ((options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
) &&
2011 (options
->dwFlags
& WINHTTP_AUTOPROXY_CONFIG_URL
)))
2013 release_object( &session
->hdr
);
2014 set_last_error( ERROR_INVALID_PARAMETER
);
2017 if (options
->dwFlags
& WINHTTP_AUTOPROXY_AUTO_DETECT
&&
2018 !WinHttpDetectAutoProxyConfigUrl( options
->dwAutoDetectFlags
, &detected_pac_url
))
2020 set_last_error( ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR
);
2023 if (options
->dwFlags
& WINHTTP_AUTOPROXY_CONFIG_URL
) pac_url
= options
->lpszAutoConfigUrl
;
2024 else pac_url
= detected_pac_url
;
2026 if (!(script
= download_script( pac_url
))) goto done
;
2027 ret
= run_script( script
, url
, info
);
2028 SysFreeString( script
);
2031 GlobalFree( detected_pac_url
);
2032 release_object( &session
->hdr
);
2036 /***********************************************************************
2037 * WinHttpSetDefaultProxyConfiguration (winhttp.@)
2039 BOOL WINAPI
WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO
*info
)
2046 TRACE("%p\n", info
);
2050 set_last_error( ERROR_INVALID_PARAMETER
);
2053 switch (info
->dwAccessType
)
2055 case WINHTTP_ACCESS_TYPE_NO_PROXY
:
2057 case WINHTTP_ACCESS_TYPE_NAMED_PROXY
:
2058 if (!info
->lpszProxy
)
2060 set_last_error( ERROR_INVALID_PARAMETER
);
2063 /* Only ASCII characters are allowed */
2064 for (src
= info
->lpszProxy
; *src
; src
++)
2067 set_last_error( ERROR_INVALID_PARAMETER
);
2070 if (info
->lpszProxyBypass
)
2072 for (src
= info
->lpszProxyBypass
; *src
; src
++)
2075 set_last_error( ERROR_INVALID_PARAMETER
);
2081 set_last_error( ERROR_INVALID_PARAMETER
);
2085 l
= RegCreateKeyExW( HKEY_LOCAL_MACHINE
, Connections
, 0, NULL
, 0,
2086 KEY_WRITE
, NULL
, &key
, NULL
);
2089 DWORD size
= sizeof(struct connection_settings_header
) + 2 * sizeof(DWORD
);
2092 if (info
->dwAccessType
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
2094 size
+= strlenW( info
->lpszProxy
);
2095 if (info
->lpszProxyBypass
)
2096 size
+= strlenW( info
->lpszProxyBypass
);
2098 buf
= heap_alloc( size
);
2101 struct connection_settings_header
*hdr
=
2102 (struct connection_settings_header
*)buf
;
2103 DWORD
*len
= (DWORD
*)(hdr
+ 1);
2105 hdr
->magic
= WINHTTP_SETTINGS_MAGIC
;
2107 if (info
->dwAccessType
== WINHTTP_ACCESS_TYPE_NAMED_PROXY
)
2111 hdr
->flags
= PROXY_TYPE_PROXY
;
2112 *len
++ = strlenW( info
->lpszProxy
);
2113 for (dst
= (BYTE
*)len
, src
= info
->lpszProxy
; *src
;
2117 if (info
->lpszProxyBypass
)
2119 *len
++ = strlenW( info
->lpszProxyBypass
);
2120 for (dst
= (BYTE
*)len
, src
= info
->lpszProxyBypass
; *src
;
2129 hdr
->flags
= PROXY_TYPE_DIRECT
;
2133 l
= RegSetValueExW( key
, WinHttpSettings
, 0, REG_BINARY
, buf
, size
);
2143 /***********************************************************************
2144 * WinHttpSetStatusCallback (winhttp.@)
2146 WINHTTP_STATUS_CALLBACK WINAPI
WinHttpSetStatusCallback( HINTERNET handle
, WINHTTP_STATUS_CALLBACK callback
,
2147 DWORD flags
, DWORD_PTR reserved
)
2149 object_header_t
*hdr
;
2150 WINHTTP_STATUS_CALLBACK ret
;
2152 TRACE("%p, %p, 0x%08x, 0x%lx\n", handle
, callback
, flags
, reserved
);
2154 if (!(hdr
= grab_object( handle
)))
2156 set_last_error( ERROR_INVALID_HANDLE
);
2157 return WINHTTP_INVALID_STATUS_CALLBACK
;
2159 ret
= hdr
->callback
;
2160 hdr
->callback
= callback
;
2161 hdr
->notify_mask
= flags
;
2163 release_object( hdr
);
2167 /***********************************************************************
2168 * WinHttpSetTimeouts (winhttp.@)
2170 BOOL WINAPI
WinHttpSetTimeouts( HINTERNET handle
, int resolve
, int connect
, int send
, int receive
)
2173 object_header_t
*hdr
;
2177 TRACE("%p, %d, %d, %d, %d\n", handle
, resolve
, connect
, send
, receive
);
2179 if (resolve
< -1 || connect
< -1 || send
< -1 || receive
< -1)
2181 set_last_error( ERROR_INVALID_PARAMETER
);
2185 if (!(hdr
= grab_object( handle
)))
2187 set_last_error( ERROR_INVALID_HANDLE
);
2193 case WINHTTP_HANDLE_TYPE_REQUEST
:
2194 request
= (request_t
*)hdr
;
2195 request
->connect_timeout
= connect
;
2197 if (resolve
< 0) resolve
= 0;
2198 request
->resolve_timeout
= resolve
;
2200 if (send
< 0) send
= 0;
2201 request
->send_timeout
= send
;
2203 if (receive
< 0) receive
= 0;
2204 request
->recv_timeout
= receive
;
2206 if (netconn_connected( &request
->netconn
))
2208 if (netconn_set_timeout( &request
->netconn
, TRUE
, send
)) ret
= FALSE
;
2209 if (netconn_set_timeout( &request
->netconn
, FALSE
, receive
)) ret
= FALSE
;
2212 release_object( &request
->hdr
);
2215 case WINHTTP_HANDLE_TYPE_SESSION
:
2216 session
= (session_t
*)hdr
;
2217 session
->connect_timeout
= connect
;
2219 if (resolve
< 0) resolve
= 0;
2220 session
->resolve_timeout
= resolve
;
2222 if (send
< 0) send
= 0;
2223 session
->send_timeout
= send
;
2225 if (receive
< 0) receive
= 0;
2226 session
->recv_timeout
= receive
;
2230 release_object( hdr
);
2231 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
2237 static const WCHAR wkday
[7][4] =
2238 {{'S','u','n', 0}, {'M','o','n', 0}, {'T','u','e', 0}, {'W','e','d', 0},
2239 {'T','h','u', 0}, {'F','r','i', 0}, {'S','a','t', 0}};
2240 static const WCHAR month
[12][4] =
2241 {{'J','a','n', 0}, {'F','e','b', 0}, {'M','a','r', 0}, {'A','p','r', 0},
2242 {'M','a','y', 0}, {'J','u','n', 0}, {'J','u','l', 0}, {'A','u','g', 0},
2243 {'S','e','p', 0}, {'O','c','t', 0}, {'N','o','v', 0}, {'D','e','c', 0}};
2245 /***********************************************************************
2246 * WinHttpTimeFromSystemTime (WININET.@)
2248 BOOL WINAPI
WinHttpTimeFromSystemTime( const SYSTEMTIME
*time
, LPWSTR string
)
2250 static const WCHAR format
[] =
2251 {'%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2252 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0};
2254 TRACE("%p, %p\n", time
, string
);
2256 if (!time
|| !string
) return FALSE
;
2258 sprintfW( string
, format
,
2259 wkday
[time
->wDayOfWeek
],
2261 month
[time
->wMonth
- 1],
2270 /***********************************************************************
2271 * WinHttpTimeToSystemTime (WININET.@)
2273 BOOL WINAPI
WinHttpTimeToSystemTime( LPCWSTR string
, SYSTEMTIME
*time
)
2276 const WCHAR
*s
= string
;
2279 TRACE("%s, %p\n", debugstr_w(string
), time
);
2281 if (!string
|| !time
) return FALSE
;
2283 /* Windows does this too */
2284 GetSystemTime( time
);
2286 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2287 * a SYSTEMTIME structure.
2290 while (*s
&& !isalphaW( *s
)) s
++;
2291 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2292 time
->wDayOfWeek
= 7;
2294 for (i
= 0; i
< 7; i
++)
2296 if (toupperW( wkday
[i
][0] ) == toupperW( s
[0] ) &&
2297 toupperW( wkday
[i
][1] ) == toupperW( s
[1] ) &&
2298 toupperW( wkday
[i
][2] ) == toupperW( s
[2] ) )
2300 time
->wDayOfWeek
= i
;
2305 if (time
->wDayOfWeek
> 6) return TRUE
;
2306 while (*s
&& !isdigitW( *s
)) s
++;
2307 time
->wDay
= strtolW( s
, &end
, 10 );
2310 while (*s
&& !isalphaW( *s
)) s
++;
2311 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2314 for (i
= 0; i
< 12; i
++)
2316 if (toupperW( month
[i
][0]) == toupperW( s
[0] ) &&
2317 toupperW( month
[i
][1]) == toupperW( s
[1] ) &&
2318 toupperW( month
[i
][2]) == toupperW( s
[2] ) )
2320 time
->wMonth
= i
+ 1;
2324 if (time
->wMonth
== 0) return TRUE
;
2326 while (*s
&& !isdigitW( *s
)) s
++;
2327 if (*s
== '\0') return TRUE
;
2328 time
->wYear
= strtolW( s
, &end
, 10 );
2331 while (*s
&& !isdigitW( *s
)) s
++;
2332 if (*s
== '\0') return TRUE
;
2333 time
->wHour
= strtolW( s
, &end
, 10 );
2336 while (*s
&& !isdigitW( *s
)) s
++;
2337 if (*s
== '\0') return TRUE
;
2338 time
->wMinute
= strtolW( s
, &end
, 10 );
2341 while (*s
&& !isdigitW( *s
)) s
++;
2342 if (*s
== '\0') return TRUE
;
2343 time
->wSecond
= strtolW( s
, &end
, 10 );
2345 time
->wMilliseconds
= 0;