wined3d: Add AMD NT6x drivers.
[wine.git] / dlls / winhttp / session.c
blobe0c1c2fed9f64d3ec16b2e8cc9fcc2669ada3aea
1 /*
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 #include "config.h"
20 #include "wine/port.h"
21 #include "wine/debug.h"
23 #include <stdarg.h>
24 #include <stdlib.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winhttp.h"
29 #include "wincrypt.h"
30 #include "winreg.h"
32 #include "winhttp_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
36 #define DEFAULT_RESOLVE_TIMEOUT 0
37 #define DEFAULT_CONNECT_TIMEOUT 20000
38 #define DEFAULT_SEND_TIMEOUT 30000
39 #define DEFAULT_RECEIVE_TIMEOUT 30000
41 void set_last_error( DWORD error )
43 /* FIXME */
44 SetLastError( error );
47 DWORD get_last_error( void )
49 /* FIXME */
50 return GetLastError();
53 void send_callback( object_header_t *hdr, DWORD status, LPVOID info, DWORD buflen )
55 TRACE("%p, 0x%08x, %p, %u\n", hdr, status, info, buflen);
57 if (hdr->callback && (hdr->notify_mask & status)) hdr->callback( hdr->handle, hdr->context, status, info, buflen );
60 /***********************************************************************
61 * WinHttpCheckPlatform (winhttp.@)
63 BOOL WINAPI WinHttpCheckPlatform( void )
65 TRACE("\n");
66 return TRUE;
69 /***********************************************************************
70 * session_destroy (internal)
72 static void session_destroy( object_header_t *hdr )
74 session_t *session = (session_t *)hdr;
75 struct list *item, *next;
76 domain_t *domain;
78 TRACE("%p\n", session);
80 LIST_FOR_EACH_SAFE( item, next, &session->cookie_cache )
82 domain = LIST_ENTRY( item, domain_t, entry );
83 delete_domain( domain );
85 heap_free( session->agent );
86 heap_free( session->proxy_server );
87 heap_free( session->proxy_bypass );
88 heap_free( session->proxy_username );
89 heap_free( session->proxy_password );
90 heap_free( session );
93 static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
95 session_t *session = (session_t *)hdr;
97 switch (option)
99 case WINHTTP_OPTION_REDIRECT_POLICY:
101 if (!buffer || *buflen < sizeof(DWORD))
103 *buflen = sizeof(DWORD);
104 set_last_error( ERROR_INSUFFICIENT_BUFFER );
105 return FALSE;
108 *(DWORD *)buffer = hdr->redirect_policy;
109 *buflen = sizeof(DWORD);
110 return TRUE;
112 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
113 *(DWORD *)buffer = session->resolve_timeout;
114 *buflen = sizeof(DWORD);
115 return TRUE;
116 case WINHTTP_OPTION_CONNECT_TIMEOUT:
117 *(DWORD *)buffer = session->connect_timeout;
118 *buflen = sizeof(DWORD);
119 return TRUE;
120 case WINHTTP_OPTION_SEND_TIMEOUT:
121 *(DWORD *)buffer = session->send_timeout;
122 *buflen = sizeof(DWORD);
123 return TRUE;
124 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
125 *(DWORD *)buffer = session->recv_timeout;
126 *buflen = sizeof(DWORD);
127 return TRUE;
128 default:
129 FIXME("unimplemented option %u\n", option);
130 set_last_error( ERROR_INVALID_PARAMETER );
131 return FALSE;
135 static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
137 session_t *session = (session_t *)hdr;
139 switch (option)
141 case WINHTTP_OPTION_PROXY:
143 WINHTTP_PROXY_INFO *pi = buffer;
145 FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
146 return TRUE;
148 case WINHTTP_OPTION_REDIRECT_POLICY:
150 DWORD policy;
152 if (buflen != sizeof(policy))
154 set_last_error( ERROR_INSUFFICIENT_BUFFER );
155 return FALSE;
158 policy = *(DWORD *)buffer;
159 TRACE("0x%x\n", policy);
160 hdr->redirect_policy = policy;
161 return TRUE;
163 case WINHTTP_OPTION_DISABLE_FEATURE:
164 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
165 return FALSE;
166 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
167 session->resolve_timeout = *(DWORD *)buffer;
168 return TRUE;
169 case WINHTTP_OPTION_CONNECT_TIMEOUT:
170 session->connect_timeout = *(DWORD *)buffer;
171 return TRUE;
172 case WINHTTP_OPTION_SEND_TIMEOUT:
173 session->send_timeout = *(DWORD *)buffer;
174 return TRUE;
175 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
176 session->recv_timeout = *(DWORD *)buffer;
177 return TRUE;
178 default:
179 FIXME("unimplemented option %u\n", option);
180 set_last_error( ERROR_INVALID_PARAMETER );
181 return FALSE;
185 static const object_vtbl_t session_vtbl =
187 session_destroy,
188 session_query_option,
189 session_set_option
192 /***********************************************************************
193 * WinHttpOpen (winhttp.@)
195 HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags )
197 session_t *session;
198 HINTERNET handle = NULL;
200 TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent), access, debugstr_w(proxy), debugstr_w(bypass), flags);
202 if (!(session = heap_alloc_zero( sizeof(session_t) ))) return NULL;
204 session->hdr.type = WINHTTP_HANDLE_TYPE_SESSION;
205 session->hdr.vtbl = &session_vtbl;
206 session->hdr.flags = flags;
207 session->hdr.refs = 1;
208 session->hdr.redirect_policy = WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP;
209 session->resolve_timeout = DEFAULT_RESOLVE_TIMEOUT;
210 session->connect_timeout = DEFAULT_CONNECT_TIMEOUT;
211 session->send_timeout = DEFAULT_SEND_TIMEOUT;
212 session->recv_timeout = DEFAULT_RECEIVE_TIMEOUT;
213 list_init( &session->cookie_cache );
215 if (agent && !(session->agent = strdupW( agent ))) goto end;
216 if (access == WINHTTP_ACCESS_TYPE_DEFAULT_PROXY)
218 WINHTTP_PROXY_INFO info;
220 WinHttpGetDefaultProxyConfiguration( &info );
221 session->access = info.dwAccessType;
222 if (info.lpszProxy && !(session->proxy_server = strdupW( info.lpszProxy )))
224 GlobalFree( (LPWSTR)info.lpszProxy );
225 GlobalFree( (LPWSTR)info.lpszProxyBypass );
226 goto end;
228 if (info.lpszProxyBypass && !(session->proxy_bypass = strdupW( info.lpszProxyBypass )))
230 GlobalFree( (LPWSTR)info.lpszProxy );
231 GlobalFree( (LPWSTR)info.lpszProxyBypass );
232 goto end;
235 else if (access == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
237 session->access = access;
238 if (proxy && !(session->proxy_server = strdupW( proxy ))) goto end;
239 if (bypass && !(session->proxy_bypass = strdupW( bypass ))) goto end;
242 if (!(handle = alloc_handle( &session->hdr ))) goto end;
243 session->hdr.handle = handle;
245 end:
246 release_object( &session->hdr );
247 TRACE("returning %p\n", handle);
248 return handle;
251 /***********************************************************************
252 * connect_destroy (internal)
254 static void connect_destroy( object_header_t *hdr )
256 connect_t *connect = (connect_t *)hdr;
258 TRACE("%p\n", connect);
260 release_object( &connect->session->hdr );
262 heap_free( connect->hostname );
263 heap_free( connect->servername );
264 heap_free( connect->username );
265 heap_free( connect->password );
266 heap_free( connect );
269 static BOOL connect_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
271 connect_t *connect = (connect_t *)hdr;
273 switch (option)
275 case WINHTTP_OPTION_PARENT_HANDLE:
277 if (!buffer || *buflen < sizeof(HINTERNET))
279 *buflen = sizeof(HINTERNET);
280 set_last_error( ERROR_INSUFFICIENT_BUFFER );
281 return FALSE;
284 *(HINTERNET *)buffer = ((object_header_t *)connect->session)->handle;
285 *buflen = sizeof(HINTERNET);
286 return TRUE;
288 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
289 *(DWORD *)buffer = connect->session->resolve_timeout;
290 *buflen = sizeof(DWORD);
291 return TRUE;
292 case WINHTTP_OPTION_CONNECT_TIMEOUT:
293 *(DWORD *)buffer = connect->session->connect_timeout;
294 *buflen = sizeof(DWORD);
295 return TRUE;
296 case WINHTTP_OPTION_SEND_TIMEOUT:
297 *(DWORD *)buffer = connect->session->send_timeout;
298 *buflen = sizeof(DWORD);
299 return TRUE;
300 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
301 *(DWORD *)buffer = connect->session->recv_timeout;
302 *buflen = sizeof(DWORD);
303 return TRUE;
304 default:
305 FIXME("unimplemented option %u\n", option);
306 set_last_error( ERROR_INVALID_PARAMETER );
307 return FALSE;
311 static const object_vtbl_t connect_vtbl =
313 connect_destroy,
314 connect_query_option,
315 NULL
318 static BOOL domain_matches(LPCWSTR server, LPCWSTR domain)
320 static const WCHAR localW[] = { '<','l','o','c','a','l','>',0 };
321 BOOL ret = FALSE;
323 if (!strcmpiW( domain, localW ) && !strchrW( server, '.' ))
324 ret = TRUE;
325 else if (*domain == '*')
327 if (domain[1] == '.')
329 LPCWSTR dot;
331 /* For a hostname to match a wildcard, the last domain must match
332 * the wildcard exactly. E.g. if the wildcard is *.a.b, and the
333 * hostname is www.foo.a.b, it matches, but a.b does not.
335 dot = strchrW( server, '.' );
336 if (dot)
338 int len = strlenW( dot + 1 );
340 if (len > strlenW( domain + 2 ))
342 LPCWSTR ptr;
344 /* The server's domain is longer than the wildcard, so it
345 * could be a subdomain. Compare the last portion of the
346 * server's domain.
348 ptr = dot + len + 1 - strlenW( domain + 2 );
349 if (!strcmpiW( ptr, domain + 2 ))
351 /* This is only a match if the preceding character is
352 * a '.', i.e. that it is a matching domain. E.g.
353 * if domain is '*.b.c' and server is 'www.ab.c' they
354 * do not match.
356 ret = *(ptr - 1) == '.';
359 else
360 ret = !strcmpiW( dot + 1, domain + 2 );
364 else
365 ret = !strcmpiW( server, domain );
366 return ret;
369 /* Matches INTERNET_MAX_HOST_NAME_LENGTH in wininet.h, also RFC 1035 */
370 #define MAX_HOST_NAME_LENGTH 256
372 static BOOL should_bypass_proxy(session_t *session, LPCWSTR server)
374 LPCWSTR ptr;
375 BOOL ret = FALSE;
377 if (!session->proxy_bypass) return FALSE;
378 ptr = session->proxy_bypass;
379 do {
380 LPCWSTR tmp = ptr;
382 ptr = strchrW( ptr, ';' );
383 if (!ptr)
384 ptr = strchrW( tmp, ' ' );
385 if (ptr)
387 if (ptr - tmp < MAX_HOST_NAME_LENGTH)
389 WCHAR domain[MAX_HOST_NAME_LENGTH];
391 memcpy( domain, tmp, (ptr - tmp) * sizeof(WCHAR) );
392 domain[ptr - tmp] = 0;
393 ret = domain_matches( server, domain );
395 ptr += 1;
397 else if (*tmp)
398 ret = domain_matches( server, tmp );
399 } while (ptr && !ret);
400 return ret;
403 BOOL set_server_for_hostname( connect_t *connect, LPCWSTR server, INTERNET_PORT port )
405 session_t *session = connect->session;
406 BOOL ret = TRUE;
408 if (session->proxy_server && !should_bypass_proxy(session, server))
410 LPCWSTR colon;
412 if ((colon = strchrW( session->proxy_server, ':' )))
414 if (!connect->servername || strncmpiW( connect->servername,
415 session->proxy_server, colon - session->proxy_server - 1 ))
417 heap_free( connect->servername );
418 if (!(connect->servername = heap_alloc(
419 (colon - session->proxy_server + 1) * sizeof(WCHAR) )))
421 ret = FALSE;
422 goto end;
424 memcpy( connect->servername, session->proxy_server,
425 (colon - session->proxy_server) * sizeof(WCHAR) );
426 connect->servername[colon - session->proxy_server] = 0;
427 if (*(colon + 1))
428 connect->serverport = atoiW( colon + 1 );
429 else
430 connect->serverport = INTERNET_DEFAULT_PORT;
433 else
435 if (!connect->servername || strcmpiW( connect->servername,
436 session->proxy_server ))
438 heap_free( connect->servername );
439 if (!(connect->servername = strdupW( session->proxy_server )))
441 ret = FALSE;
442 goto end;
444 connect->serverport = INTERNET_DEFAULT_PORT;
448 else if (server)
450 heap_free( connect->servername );
451 if (!(connect->servername = strdupW( server )))
453 ret = FALSE;
454 goto end;
456 connect->serverport = port;
458 end:
459 return ret;
462 /***********************************************************************
463 * WinHttpConnect (winhttp.@)
465 HINTERNET WINAPI WinHttpConnect( HINTERNET hsession, LPCWSTR server, INTERNET_PORT port, DWORD reserved )
467 connect_t *connect;
468 session_t *session;
469 HINTERNET hconnect = NULL;
471 TRACE("%p, %s, %u, %x\n", hsession, debugstr_w(server), port, reserved);
473 if (!server)
475 set_last_error( ERROR_INVALID_PARAMETER );
476 return NULL;
478 if (!(session = (session_t *)grab_object( hsession )))
480 set_last_error( ERROR_INVALID_HANDLE );
481 return NULL;
483 if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
485 release_object( &session->hdr );
486 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
487 return NULL;
489 if (!(connect = heap_alloc_zero( sizeof(connect_t) )))
491 release_object( &session->hdr );
492 return NULL;
494 connect->hdr.type = WINHTTP_HANDLE_TYPE_CONNECT;
495 connect->hdr.vtbl = &connect_vtbl;
496 connect->hdr.refs = 1;
497 connect->hdr.flags = session->hdr.flags;
498 connect->hdr.callback = session->hdr.callback;
499 connect->hdr.notify_mask = session->hdr.notify_mask;
500 connect->hdr.context = session->hdr.context;
502 addref_object( &session->hdr );
503 connect->session = session;
504 list_add_head( &session->hdr.children, &connect->hdr.entry );
506 if (!(connect->hostname = strdupW( server ))) goto end;
507 connect->hostport = port;
509 if (!set_server_for_hostname( connect, server, port ))
510 goto end;
512 if (!(hconnect = alloc_handle( &connect->hdr ))) goto end;
513 connect->hdr.handle = hconnect;
515 send_callback( &session->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hconnect, sizeof(hconnect) );
517 end:
518 release_object( &connect->hdr );
520 TRACE("returning %p\n", hconnect);
521 return hconnect;
524 /***********************************************************************
525 * request_destroy (internal)
527 static void request_destroy( object_header_t *hdr )
529 request_t *request = (request_t *)hdr;
530 DWORD i;
532 TRACE("%p\n", request);
534 release_object( &request->connect->hdr );
536 heap_free( request->verb );
537 heap_free( request->path );
538 heap_free( request->version );
539 heap_free( request->raw_headers );
540 heap_free( request->status_text );
541 for (i = 0; i < request->num_headers; i++)
543 heap_free( request->headers[i].field );
544 heap_free( request->headers[i].value );
546 heap_free( request->headers );
547 heap_free( request );
550 static void str_to_buffer( WCHAR *buffer, const WCHAR *str, LPDWORD buflen )
552 int len = 0;
553 if (str) len = strlenW( str );
554 if (buffer && *buflen > len)
556 memcpy( buffer, str, len * sizeof(WCHAR) );
557 buffer[len] = 0;
559 *buflen = len * sizeof(WCHAR);
562 static WCHAR *blob_to_str( DWORD encoding, CERT_NAME_BLOB *blob )
564 WCHAR *ret;
565 DWORD size, format = CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG;
567 size = CertNameToStrW( encoding, blob, format, NULL, 0 );
568 if ((ret = LocalAlloc( 0, size * sizeof(WCHAR) )))
569 CertNameToStrW( encoding, blob, format, ret, size );
571 return ret;
574 static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
576 request_t *request = (request_t *)hdr;
578 switch (option)
580 case WINHTTP_OPTION_SECURITY_FLAGS:
582 DWORD flags;
584 if (!buffer || *buflen < sizeof(flags))
586 *buflen = sizeof(flags);
587 set_last_error( ERROR_INSUFFICIENT_BUFFER );
588 return FALSE;
591 flags = 0;
592 if (hdr->flags & WINHTTP_FLAG_SECURE) flags |= SECURITY_FLAG_SECURE;
593 *(DWORD *)buffer = flags;
594 *buflen = sizeof(flags);
595 return TRUE;
597 case WINHTTP_OPTION_SERVER_CERT_CONTEXT:
599 const CERT_CONTEXT *cert;
601 if (!buffer || *buflen < sizeof(cert))
603 *buflen = sizeof(cert);
604 set_last_error( ERROR_INSUFFICIENT_BUFFER );
605 return FALSE;
608 if (!(cert = netconn_get_certificate( &request->netconn ))) return FALSE;
609 *(CERT_CONTEXT **)buffer = (CERT_CONTEXT *)cert;
610 *buflen = sizeof(cert);
611 return TRUE;
613 case WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT:
615 const CERT_CONTEXT *cert;
616 WINHTTP_CERTIFICATE_INFO *ci = buffer;
618 FIXME("partial stub\n");
620 if (!buffer || *buflen < sizeof(*ci))
622 *buflen = sizeof(*ci);
623 set_last_error( ERROR_INSUFFICIENT_BUFFER );
624 return FALSE;
626 if (!(cert = netconn_get_certificate( &request->netconn ))) return FALSE;
628 ci->ftExpiry = cert->pCertInfo->NotAfter;
629 ci->ftStart = cert->pCertInfo->NotBefore;
630 ci->lpszSubjectInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Subject );
631 ci->lpszIssuerInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Issuer );
632 ci->lpszProtocolName = NULL;
633 ci->lpszSignatureAlgName = NULL;
634 ci->lpszEncryptionAlgName = NULL;
635 ci->dwKeySize = 128;
637 CertFreeCertificateContext( cert );
638 *buflen = sizeof(*ci);
639 return TRUE;
641 case WINHTTP_OPTION_SECURITY_KEY_BITNESS:
643 if (!buffer || *buflen < sizeof(DWORD))
645 *buflen = sizeof(DWORD);
646 set_last_error( ERROR_INSUFFICIENT_BUFFER );
647 return FALSE;
650 *(DWORD *)buffer = 128; /* FIXME */
651 *buflen = sizeof(DWORD);
652 return TRUE;
654 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
655 *(DWORD *)buffer = request->resolve_timeout;
656 *buflen = sizeof(DWORD);
657 return TRUE;
658 case WINHTTP_OPTION_CONNECT_TIMEOUT:
659 *(DWORD *)buffer = request->connect_timeout;
660 *buflen = sizeof(DWORD);
661 return TRUE;
662 case WINHTTP_OPTION_SEND_TIMEOUT:
663 *(DWORD *)buffer = request->send_timeout;
664 *buflen = sizeof(DWORD);
665 return TRUE;
666 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
667 *(DWORD *)buffer = request->recv_timeout;
668 *buflen = sizeof(DWORD);
669 return TRUE;
671 case WINHTTP_OPTION_USERNAME:
672 str_to_buffer( buffer, request->connect->username, buflen );
673 return TRUE;
675 case WINHTTP_OPTION_PASSWORD:
676 str_to_buffer( buffer, request->connect->password, buflen );
677 return TRUE;
679 case WINHTTP_OPTION_PROXY_USERNAME:
680 str_to_buffer( buffer, request->connect->session->proxy_username, buflen );
681 return TRUE;
683 case WINHTTP_OPTION_PROXY_PASSWORD:
684 str_to_buffer( buffer, request->connect->session->proxy_password, buflen );
685 return TRUE;
687 default:
688 FIXME("unimplemented option %u\n", option);
689 set_last_error( ERROR_INVALID_PARAMETER );
690 return FALSE;
694 static WCHAR *buffer_to_str( WCHAR *buffer, DWORD buflen )
696 WCHAR *ret;
697 if ((ret = heap_alloc( (buflen + 1) * sizeof(WCHAR))))
699 memcpy( ret, buffer, buflen * sizeof(WCHAR) );
700 ret[buflen] = 0;
701 return ret;
703 set_last_error( ERROR_OUTOFMEMORY );
704 return NULL;
707 static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
709 request_t *request = (request_t *)hdr;
711 switch (option)
713 case WINHTTP_OPTION_PROXY:
715 WINHTTP_PROXY_INFO *pi = buffer;
717 FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
718 return TRUE;
720 case WINHTTP_OPTION_DISABLE_FEATURE:
722 DWORD disable;
724 if (buflen != sizeof(DWORD))
726 set_last_error( ERROR_INSUFFICIENT_BUFFER );
727 return FALSE;
730 disable = *(DWORD *)buffer;
731 TRACE("0x%x\n", disable);
732 hdr->disable_flags |= disable;
733 return TRUE;
735 case WINHTTP_OPTION_AUTOLOGON_POLICY:
737 DWORD policy;
739 if (buflen != sizeof(DWORD))
741 set_last_error( ERROR_INSUFFICIENT_BUFFER );
742 return FALSE;
745 policy = *(DWORD *)buffer;
746 TRACE("0x%x\n", policy);
747 hdr->logon_policy = policy;
748 return TRUE;
750 case WINHTTP_OPTION_REDIRECT_POLICY:
752 DWORD policy;
754 if (buflen != sizeof(DWORD))
756 set_last_error( ERROR_INSUFFICIENT_BUFFER );
757 return FALSE;
760 policy = *(DWORD *)buffer;
761 TRACE("0x%x\n", policy);
762 hdr->redirect_policy = policy;
763 return TRUE;
765 case WINHTTP_OPTION_SECURITY_FLAGS:
767 DWORD flags;
769 if (buflen < sizeof(DWORD))
771 set_last_error( ERROR_INSUFFICIENT_BUFFER );
772 return FALSE;
774 flags = *(DWORD *)buffer;
775 TRACE("0x%x\n", flags);
776 if (!(flags & (SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
777 SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
778 SECURITY_FLAG_IGNORE_UNKNOWN_CA |
779 SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE)))
781 set_last_error( ERROR_INVALID_PARAMETER );
782 return FALSE;
784 request->netconn.security_flags = flags;
785 return TRUE;
787 case WINHTTP_OPTION_RESOLVE_TIMEOUT:
788 request->resolve_timeout = *(DWORD *)buffer;
789 return TRUE;
790 case WINHTTP_OPTION_CONNECT_TIMEOUT:
791 request->connect_timeout = *(DWORD *)buffer;
792 return TRUE;
793 case WINHTTP_OPTION_SEND_TIMEOUT:
794 request->send_timeout = *(DWORD *)buffer;
795 return TRUE;
796 case WINHTTP_OPTION_RECEIVE_TIMEOUT:
797 request->recv_timeout = *(DWORD *)buffer;
798 return TRUE;
800 case WINHTTP_OPTION_USERNAME:
802 connect_t *connect = request->connect;
804 heap_free( connect->username );
805 if (!(connect->username = buffer_to_str( buffer, buflen ))) return FALSE;
806 return TRUE;
808 case WINHTTP_OPTION_PASSWORD:
810 connect_t *connect = request->connect;
812 heap_free( connect->password );
813 if (!(connect->password = buffer_to_str( buffer, buflen ))) return FALSE;
814 return TRUE;
816 case WINHTTP_OPTION_PROXY_USERNAME:
818 session_t *session = request->connect->session;
820 heap_free( session->proxy_username );
821 if (!(session->proxy_username = buffer_to_str( buffer, buflen ))) return FALSE;
822 return TRUE;
824 case WINHTTP_OPTION_PROXY_PASSWORD:
826 session_t *session = request->connect->session;
828 heap_free( session->proxy_password );
829 if (!(session->proxy_password = buffer_to_str( buffer, buflen ))) return FALSE;
830 return TRUE;
832 default:
833 FIXME("unimplemented option %u\n", option);
834 set_last_error( ERROR_INVALID_PARAMETER );
835 return TRUE;
839 static const object_vtbl_t request_vtbl =
841 request_destroy,
842 request_query_option,
843 request_set_option
846 /***********************************************************************
847 * WinHttpOpenRequest (winhttp.@)
849 HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR object, LPCWSTR version,
850 LPCWSTR referrer, LPCWSTR *types, DWORD flags )
852 request_t *request;
853 connect_t *connect;
854 HINTERNET hrequest = NULL;
856 TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect, debugstr_w(verb), debugstr_w(object),
857 debugstr_w(version), debugstr_w(referrer), types, flags);
859 if (!(connect = (connect_t *)grab_object( hconnect )))
861 set_last_error( ERROR_INVALID_HANDLE );
862 return NULL;
864 if (connect->hdr.type != WINHTTP_HANDLE_TYPE_CONNECT)
866 release_object( &connect->hdr );
867 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
868 return NULL;
870 if (!(request = heap_alloc_zero( sizeof(request_t) )))
872 release_object( &connect->hdr );
873 return NULL;
875 request->hdr.type = WINHTTP_HANDLE_TYPE_REQUEST;
876 request->hdr.vtbl = &request_vtbl;
877 request->hdr.refs = 1;
878 request->hdr.flags = flags;
879 request->hdr.callback = connect->hdr.callback;
880 request->hdr.notify_mask = connect->hdr.notify_mask;
881 request->hdr.context = connect->hdr.context;
883 addref_object( &connect->hdr );
884 request->connect = connect;
885 list_add_head( &connect->hdr.children, &request->hdr.entry );
887 if (!netconn_init( &request->netconn, request->hdr.flags & WINHTTP_FLAG_SECURE )) goto end;
888 request->resolve_timeout = connect->session->resolve_timeout;
889 request->connect_timeout = connect->session->connect_timeout;
890 request->send_timeout = connect->session->send_timeout;
891 request->recv_timeout = connect->session->recv_timeout;
893 if (!verb || !verb[0]) verb = getW;
894 if (!(request->verb = strdupW( verb ))) goto end;
896 if (object)
898 WCHAR *path, *p;
899 unsigned int len;
901 len = strlenW( object ) + 1;
902 if (object[0] != '/') len++;
903 if (!(p = path = heap_alloc( len * sizeof(WCHAR) ))) goto end;
905 if (object[0] != '/') *p++ = '/';
906 strcpyW( p, object );
907 request->path = path;
909 else if (!(request->path = strdupW( slashW ))) goto end;
911 if (!version || !version[0]) version = http1_1;
912 if (!(request->version = strdupW( version ))) goto end;
914 if (!(hrequest = alloc_handle( &request->hdr ))) goto end;
915 request->hdr.handle = hrequest;
917 send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hrequest, sizeof(hrequest) );
919 end:
920 release_object( &request->hdr );
922 TRACE("returning %p\n", hrequest);
923 return hrequest;
926 /***********************************************************************
927 * WinHttpCloseHandle (winhttp.@)
929 BOOL WINAPI WinHttpCloseHandle( HINTERNET handle )
931 object_header_t *hdr;
933 TRACE("%p\n", handle);
935 if (!(hdr = grab_object( handle )))
937 set_last_error( ERROR_INVALID_HANDLE );
938 return FALSE;
940 release_object( hdr );
941 free_handle( handle );
942 return TRUE;
945 static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
947 BOOL ret = FALSE;
949 if (!buflen)
951 set_last_error( ERROR_INVALID_PARAMETER );
952 return FALSE;
955 switch (option)
957 case WINHTTP_OPTION_CONTEXT_VALUE:
959 if (!buffer || *buflen < sizeof(DWORD_PTR))
961 *buflen = sizeof(DWORD_PTR);
962 set_last_error( ERROR_INSUFFICIENT_BUFFER );
963 return FALSE;
966 *(DWORD_PTR *)buffer = hdr->context;
967 *buflen = sizeof(DWORD_PTR);
968 return TRUE;
970 default:
971 if (hdr->vtbl->query_option) ret = hdr->vtbl->query_option( hdr, option, buffer, buflen );
972 else
974 FIXME("unimplemented option %u\n", option);
975 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
976 return FALSE;
978 break;
980 return ret;
983 /***********************************************************************
984 * WinHttpQueryOption (winhttp.@)
986 BOOL WINAPI WinHttpQueryOption( HINTERNET handle, DWORD option, LPVOID buffer, LPDWORD buflen )
988 BOOL ret = FALSE;
989 object_header_t *hdr;
991 TRACE("%p, %u, %p, %p\n", handle, option, buffer, buflen);
993 if (!(hdr = grab_object( handle )))
995 set_last_error( ERROR_INVALID_HANDLE );
996 return FALSE;
999 ret = query_option( hdr, option, buffer, buflen );
1001 release_object( hdr );
1002 return ret;
1005 static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
1007 BOOL ret = TRUE;
1009 if (!buffer)
1011 set_last_error( ERROR_INVALID_PARAMETER );
1012 return FALSE;
1015 switch (option)
1017 case WINHTTP_OPTION_CONTEXT_VALUE:
1019 if (buflen != sizeof(DWORD_PTR))
1021 set_last_error( ERROR_INSUFFICIENT_BUFFER );
1022 return FALSE;
1025 hdr->context = *(DWORD_PTR *)buffer;
1026 return TRUE;
1028 default:
1029 if (hdr->vtbl->set_option) ret = hdr->vtbl->set_option( hdr, option, buffer, buflen );
1030 else
1032 FIXME("unimplemented option %u\n", option);
1033 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1034 return FALSE;
1036 break;
1038 return ret;
1041 /***********************************************************************
1042 * WinHttpSetOption (winhttp.@)
1044 BOOL WINAPI WinHttpSetOption( HINTERNET handle, DWORD option, LPVOID buffer, DWORD buflen )
1046 BOOL ret = FALSE;
1047 object_header_t *hdr;
1049 TRACE("%p, %u, %p, %u\n", handle, option, buffer, buflen);
1051 if (!(hdr = grab_object( handle )))
1053 set_last_error( ERROR_INVALID_HANDLE );
1054 return FALSE;
1057 ret = set_option( hdr, option, buffer, buflen );
1059 release_object( hdr );
1060 return ret;
1063 /***********************************************************************
1064 * WinHttpDetectAutoProxyConfigUrl (winhttp.@)
1066 BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url )
1068 FIXME("0x%08x, %p\n", flags, url);
1070 set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED );
1071 return FALSE;
1074 static const WCHAR Connections[] = {
1075 'S','o','f','t','w','a','r','e','\\',
1076 'M','i','c','r','o','s','o','f','t','\\',
1077 'W','i','n','d','o','w','s','\\',
1078 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1079 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
1080 'C','o','n','n','e','c','t','i','o','n','s',0 };
1081 static const WCHAR WinHttpSettings[] = {
1082 'W','i','n','H','t','t','p','S','e','t','t','i','n','g','s',0 };
1083 static const DWORD WINHTTPSETTINGS_MAGIC = 0x18;
1084 static const DWORD WINHTTP_PROXY_TYPE_DIRECT = 1;
1085 static const DWORD WINHTTP_PROXY_TYPE_PROXY = 2;
1087 struct winhttp_settings_header
1089 DWORD magic;
1090 DWORD unknown; /* always zero? */
1091 DWORD flags; /* one of WINHTTP_PROXY_TYPE_* */
1094 static inline void copy_char_to_wchar_sz(const BYTE *src, DWORD len, WCHAR *dst)
1096 const BYTE *begin;
1098 for (begin = src; src - begin < len; src++, dst++)
1099 *dst = *src;
1100 *dst = 0;
1103 /***********************************************************************
1104 * WinHttpGetDefaultProxyConfiguration (winhttp.@)
1106 BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
1108 LONG l;
1109 HKEY key;
1110 BOOL got_from_reg = FALSE, direct = TRUE;
1111 char *envproxy;
1113 TRACE("%p\n", info);
1115 l = RegOpenKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, KEY_READ, &key );
1116 if (!l)
1118 DWORD type, size = 0;
1120 l = RegQueryValueExW( key, WinHttpSettings, NULL, &type, NULL, &size );
1121 if (!l && type == REG_BINARY &&
1122 size >= sizeof(struct winhttp_settings_header) + 2 * sizeof(DWORD))
1124 BYTE *buf = heap_alloc( size );
1126 if (buf)
1128 struct winhttp_settings_header *hdr =
1129 (struct winhttp_settings_header *)buf;
1130 DWORD *len = (DWORD *)(hdr + 1);
1132 l = RegQueryValueExW( key, WinHttpSettings, NULL, NULL, buf,
1133 &size );
1134 if (!l && hdr->magic == WINHTTPSETTINGS_MAGIC &&
1135 hdr->unknown == 0)
1137 if (hdr->flags & WINHTTP_PROXY_TYPE_PROXY)
1139 BOOL sane = FALSE;
1140 LPWSTR proxy = NULL;
1141 LPWSTR proxy_bypass = NULL;
1143 /* Sanity-check length of proxy string */
1144 if ((BYTE *)len - buf + *len <= size)
1146 sane = TRUE;
1147 proxy = GlobalAlloc( 0, (*len + 1) * sizeof(WCHAR) );
1148 if (proxy)
1149 copy_char_to_wchar_sz( (BYTE *)(len + 1), *len, proxy );
1150 len = (DWORD *)((BYTE *)(len + 1) + *len);
1152 if (sane)
1154 /* Sanity-check length of proxy bypass string */
1155 if ((BYTE *)len - buf + *len <= size)
1157 proxy_bypass = GlobalAlloc( 0, (*len + 1) * sizeof(WCHAR) );
1158 if (proxy_bypass)
1159 copy_char_to_wchar_sz( (BYTE *)(len + 1), *len, proxy_bypass );
1161 else
1163 sane = FALSE;
1164 GlobalFree( proxy );
1165 proxy = NULL;
1168 info->lpszProxy = proxy;
1169 info->lpszProxyBypass = proxy_bypass;
1170 if (sane)
1172 got_from_reg = TRUE;
1173 direct = FALSE;
1174 info->dwAccessType =
1175 WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1176 TRACE("http proxy (from registry) = %s, bypass = %s\n",
1177 debugstr_w(info->lpszProxy),
1178 debugstr_w(info->lpszProxyBypass));
1182 heap_free( buf );
1185 RegCloseKey( key );
1187 if (!got_from_reg && (envproxy = getenv( "http_proxy" )))
1189 char *colon, *http_proxy;
1191 if ((colon = strchr( envproxy, ':' )))
1193 if (*(colon + 1) == '/' && *(colon + 2) == '/')
1195 static const char http[] = "http://";
1197 /* It's a scheme, check that it's http */
1198 if (!strncmp( envproxy, http, strlen( http ) ))
1199 http_proxy = envproxy + strlen( http );
1200 else
1202 WARN("unsupported scheme in $http_proxy: %s\n", envproxy);
1203 http_proxy = NULL;
1206 else
1207 http_proxy = envproxy;
1209 else
1210 http_proxy = envproxy;
1211 if (http_proxy)
1213 WCHAR *http_proxyW;
1214 int len;
1216 len = MultiByteToWideChar( CP_UNIXCP, 0, http_proxy, -1, NULL, 0 );
1217 if ((http_proxyW = GlobalAlloc( 0, len * sizeof(WCHAR))))
1219 MultiByteToWideChar( CP_UNIXCP, 0, http_proxy, -1, http_proxyW, len );
1220 direct = FALSE;
1221 info->dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1222 info->lpszProxy = http_proxyW;
1223 info->lpszProxyBypass = NULL;
1224 TRACE("http proxy (from environment) = %s\n",
1225 debugstr_w(info->lpszProxy));
1229 if (direct)
1231 info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
1232 info->lpszProxy = NULL;
1233 info->lpszProxyBypass = NULL;
1235 return TRUE;
1238 /***********************************************************************
1239 * WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
1241 BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *config )
1243 TRACE("%p\n", config);
1245 if (!config)
1247 set_last_error( ERROR_INVALID_PARAMETER );
1248 return FALSE;
1251 /* FIXME: read from HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings */
1253 FIXME("returning no proxy used\n");
1254 config->fAutoDetect = FALSE;
1255 config->lpszAutoConfigUrl = NULL;
1256 config->lpszProxy = NULL;
1257 config->lpszProxyBypass = NULL;
1259 return TRUE;
1262 /***********************************************************************
1263 * WinHttpGetProxyForUrl (winhttp.@)
1265 BOOL WINAPI WinHttpGetProxyForUrl( HINTERNET hsession, LPCWSTR url, WINHTTP_AUTOPROXY_OPTIONS *options,
1266 WINHTTP_PROXY_INFO *info )
1268 FIXME("%p, %s, %p, %p\n", hsession, debugstr_w(url), options, info);
1270 set_last_error( ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR );
1271 return FALSE;
1274 /***********************************************************************
1275 * WinHttpSetDefaultProxyConfiguration (winhttp.@)
1277 BOOL WINAPI WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
1279 LONG l;
1280 HKEY key;
1281 BOOL ret = FALSE;
1282 const WCHAR *src;
1284 TRACE("%p\n", info);
1286 if (!info)
1288 set_last_error( ERROR_INVALID_PARAMETER );
1289 return FALSE;
1291 switch (info->dwAccessType)
1293 case WINHTTP_ACCESS_TYPE_NO_PROXY:
1294 break;
1295 case WINHTTP_ACCESS_TYPE_NAMED_PROXY:
1296 if (!info->lpszProxy)
1298 set_last_error( ERROR_INVALID_PARAMETER );
1299 return FALSE;
1301 /* Only ASCII characters are allowed */
1302 for (src = info->lpszProxy; *src; src++)
1303 if (*src > 0x7f)
1305 set_last_error( ERROR_INVALID_PARAMETER );
1306 return FALSE;
1308 if (info->lpszProxyBypass)
1310 for (src = info->lpszProxyBypass; *src; src++)
1311 if (*src > 0x7f)
1313 set_last_error( ERROR_INVALID_PARAMETER );
1314 return FALSE;
1317 break;
1318 default:
1319 set_last_error( ERROR_INVALID_PARAMETER );
1320 return FALSE;
1323 l = RegCreateKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, NULL, 0,
1324 KEY_WRITE, NULL, &key, NULL );
1325 if (!l)
1327 DWORD size = sizeof(struct winhttp_settings_header) + 2 * sizeof(DWORD);
1328 BYTE *buf;
1330 if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
1332 size += strlenW( info->lpszProxy );
1333 if (info->lpszProxyBypass)
1334 size += strlenW( info->lpszProxyBypass );
1336 buf = heap_alloc( size );
1337 if (buf)
1339 struct winhttp_settings_header *hdr =
1340 (struct winhttp_settings_header *)buf;
1341 DWORD *len = (DWORD *)(hdr + 1);
1343 hdr->magic = WINHTTPSETTINGS_MAGIC;
1344 hdr->unknown = 0;
1345 if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
1347 BYTE *dst;
1349 hdr->flags = WINHTTP_PROXY_TYPE_PROXY;
1350 *len++ = strlenW( info->lpszProxy );
1351 for (dst = (BYTE *)len, src = info->lpszProxy; *src;
1352 src++, dst++)
1353 *dst = *src;
1354 len = (DWORD *)dst;
1355 if (info->lpszProxyBypass)
1357 *len++ = strlenW( info->lpszProxyBypass );
1358 for (dst = (BYTE *)len, src = info->lpszProxyBypass; *src;
1359 src++, dst++)
1360 *dst = *src;
1362 else
1363 *len++ = 0;
1365 else
1367 hdr->flags = WINHTTP_PROXY_TYPE_DIRECT;
1368 *len++ = 0;
1369 *len++ = 0;
1371 l = RegSetValueExW( key, WinHttpSettings, 0, REG_BINARY, buf, size );
1372 if (!l)
1373 ret = TRUE;
1374 heap_free( buf );
1376 RegCloseKey( key );
1378 return ret;
1381 /***********************************************************************
1382 * WinHttpSetStatusCallback (winhttp.@)
1384 WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback( HINTERNET handle, WINHTTP_STATUS_CALLBACK callback,
1385 DWORD flags, DWORD_PTR reserved )
1387 object_header_t *hdr;
1388 WINHTTP_STATUS_CALLBACK ret;
1390 TRACE("%p, %p, 0x%08x, 0x%lx\n", handle, callback, flags, reserved);
1392 if (!(hdr = grab_object( handle )))
1394 set_last_error( ERROR_INVALID_HANDLE );
1395 return WINHTTP_INVALID_STATUS_CALLBACK;
1397 ret = hdr->callback;
1398 hdr->callback = callback;
1399 hdr->notify_mask = flags;
1401 release_object( hdr );
1402 return ret;
1405 /***********************************************************************
1406 * WinHttpSetTimeouts (winhttp.@)
1408 BOOL WINAPI WinHttpSetTimeouts( HINTERNET handle, int resolve, int connect, int send, int receive )
1410 BOOL ret = TRUE;
1411 object_header_t *hdr;
1412 request_t *request;
1413 session_t *session;
1415 TRACE("%p, %d, %d, %d, %d\n", handle, resolve, connect, send, receive);
1417 if (resolve < -1 || connect < -1 || send < -1 || receive < -1)
1419 set_last_error( ERROR_INVALID_PARAMETER );
1420 return FALSE;
1423 if (!(hdr = grab_object( handle )))
1425 set_last_error( ERROR_INVALID_HANDLE );
1426 return FALSE;
1429 switch(hdr->type)
1431 case WINHTTP_HANDLE_TYPE_REQUEST:
1432 request = (request_t *)hdr;
1433 request->connect_timeout = connect;
1435 if (resolve < 0) resolve = 0;
1436 request->resolve_timeout = resolve;
1438 if (send < 0) send = 0;
1439 request->send_timeout = send;
1441 if (receive < 0) receive = 0;
1442 request->recv_timeout = receive;
1444 if (netconn_connected( &request->netconn ))
1446 if (netconn_set_timeout( &request->netconn, TRUE, send )) ret = FALSE;
1447 if (netconn_set_timeout( &request->netconn, FALSE, receive )) ret = FALSE;
1450 release_object( &request->hdr );
1451 break;
1453 case WINHTTP_HANDLE_TYPE_SESSION:
1454 session = (session_t *)hdr;
1455 session->connect_timeout = connect;
1457 if (resolve < 0) resolve = 0;
1458 session->resolve_timeout = resolve;
1460 if (send < 0) send = 0;
1461 session->send_timeout = send;
1463 if (receive < 0) receive = 0;
1464 session->recv_timeout = receive;
1465 break;
1467 default:
1468 release_object( hdr );
1469 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
1470 return FALSE;
1472 return ret;
1475 static const WCHAR wkday[7][4] =
1476 {{'S','u','n', 0}, {'M','o','n', 0}, {'T','u','e', 0}, {'W','e','d', 0},
1477 {'T','h','u', 0}, {'F','r','i', 0}, {'S','a','t', 0}};
1478 static const WCHAR month[12][4] =
1479 {{'J','a','n', 0}, {'F','e','b', 0}, {'M','a','r', 0}, {'A','p','r', 0},
1480 {'M','a','y', 0}, {'J','u','n', 0}, {'J','u','l', 0}, {'A','u','g', 0},
1481 {'S','e','p', 0}, {'O','c','t', 0}, {'N','o','v', 0}, {'D','e','c', 0}};
1483 /***********************************************************************
1484 * WinHttpTimeFromSystemTime (WININET.@)
1486 BOOL WINAPI WinHttpTimeFromSystemTime( const SYSTEMTIME *time, LPWSTR string )
1488 static const WCHAR format[] =
1489 {'%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
1490 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0};
1492 TRACE("%p, %p\n", time, string);
1494 if (!time || !string) return FALSE;
1496 sprintfW( string, format,
1497 wkday[time->wDayOfWeek],
1498 time->wDay,
1499 month[time->wMonth - 1],
1500 time->wYear,
1501 time->wHour,
1502 time->wMinute,
1503 time->wSecond );
1505 return TRUE;
1508 /***********************************************************************
1509 * WinHttpTimeToSystemTime (WININET.@)
1511 BOOL WINAPI WinHttpTimeToSystemTime( LPCWSTR string, SYSTEMTIME *time )
1513 unsigned int i;
1514 const WCHAR *s = string;
1515 WCHAR *end;
1517 TRACE("%s, %p\n", debugstr_w(string), time);
1519 if (!string || !time) return FALSE;
1521 /* Windows does this too */
1522 GetSystemTime( time );
1524 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
1525 * a SYSTEMTIME structure.
1528 while (*s && !isalphaW( *s )) s++;
1529 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
1530 time->wDayOfWeek = 7;
1532 for (i = 0; i < 7; i++)
1534 if (toupperW( wkday[i][0] ) == toupperW( s[0] ) &&
1535 toupperW( wkday[i][1] ) == toupperW( s[1] ) &&
1536 toupperW( wkday[i][2] ) == toupperW( s[2] ) )
1538 time->wDayOfWeek = i;
1539 break;
1543 if (time->wDayOfWeek > 6) return TRUE;
1544 while (*s && !isdigitW( *s )) s++;
1545 time->wDay = strtolW( s, &end, 10 );
1546 s = end;
1548 while (*s && !isalphaW( *s )) s++;
1549 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
1550 time->wMonth = 0;
1552 for (i = 0; i < 12; i++)
1554 if (toupperW( month[i][0]) == toupperW( s[0] ) &&
1555 toupperW( month[i][1]) == toupperW( s[1] ) &&
1556 toupperW( month[i][2]) == toupperW( s[2] ) )
1558 time->wMonth = i + 1;
1559 break;
1562 if (time->wMonth == 0) return TRUE;
1564 while (*s && !isdigitW( *s )) s++;
1565 if (*s == '\0') return TRUE;
1566 time->wYear = strtolW( s, &end, 10 );
1567 s = end;
1569 while (*s && !isdigitW( *s )) s++;
1570 if (*s == '\0') return TRUE;
1571 time->wHour = strtolW( s, &end, 10 );
1572 s = end;
1574 while (*s && !isdigitW( *s )) s++;
1575 if (*s == '\0') return TRUE;
1576 time->wMinute = strtolW( s, &end, 10 );
1577 s = end;
1579 while (*s && !isdigitW( *s )) s++;
1580 if (*s == '\0') return TRUE;
1581 time->wSecond = strtolW( s, &end, 10 );
1582 s = end;
1584 time->wMilliseconds = 0;
1585 return TRUE;