push ac694015ba9a1d7cf8fc6346c6e51d4c35a62962
[wine/hacks.git] / dlls / winhttp / session.c
blob11c4b4fbf99716b41af3124aa010a93035bfcc1e
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>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winhttp.h"
28 #include "wincrypt.h"
30 #include "winhttp_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
34 void set_last_error( DWORD error )
36 /* FIXME */
37 SetLastError( error );
40 DWORD get_last_error( void )
42 /* FIXME */
43 return GetLastError();
46 void send_callback( object_header_t *hdr, DWORD status, LPVOID info, DWORD buflen )
48 TRACE("%p, 0x%08x, %p, %u\n", hdr, status, info, buflen);
50 if (hdr->callback && (hdr->notify_mask & status)) hdr->callback( hdr->handle, hdr->context, status, info, buflen );
53 /***********************************************************************
54 * WinHttpCheckPlatform (winhttp.@)
56 BOOL WINAPI WinHttpCheckPlatform( void )
58 TRACE("\n");
59 return TRUE;
62 /***********************************************************************
63 * session_destroy (internal)
65 static void session_destroy( object_header_t *hdr )
67 session_t *session = (session_t *)hdr;
68 struct list *item, *next;
69 domain_t *domain;
71 TRACE("%p\n", session);
73 LIST_FOR_EACH_SAFE( item, next, &session->cookie_cache )
75 domain = LIST_ENTRY( item, domain_t, entry );
76 delete_domain( domain );
78 heap_free( session->agent );
79 heap_free( session->proxy_server );
80 heap_free( session->proxy_bypass );
81 heap_free( session->proxy_username );
82 heap_free( session->proxy_password );
83 heap_free( session );
86 static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
88 switch (option)
90 case WINHTTP_OPTION_REDIRECT_POLICY:
92 if (!buffer || *buflen < sizeof(DWORD))
94 *buflen = sizeof(DWORD);
95 set_last_error( ERROR_INSUFFICIENT_BUFFER );
96 return FALSE;
99 *(DWORD *)buffer = hdr->redirect_policy;
100 *buflen = sizeof(DWORD);
101 return TRUE;
103 default:
104 FIXME("unimplemented option %u\n", option);
105 set_last_error( ERROR_INVALID_PARAMETER );
106 return FALSE;
110 static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
112 switch (option)
114 case WINHTTP_OPTION_PROXY:
116 WINHTTP_PROXY_INFO *pi = buffer;
118 FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
119 return TRUE;
121 case WINHTTP_OPTION_REDIRECT_POLICY:
123 DWORD policy;
125 if (buflen != sizeof(policy))
127 set_last_error( ERROR_INSUFFICIENT_BUFFER );
128 return FALSE;
131 policy = *(DWORD *)buffer;
132 TRACE("0x%x\n", policy);
133 hdr->redirect_policy = policy;
134 return TRUE;
136 case WINHTTP_OPTION_DISABLE_FEATURE:
137 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
138 return FALSE;
139 default:
140 FIXME("unimplemented option %u\n", option);
141 set_last_error( ERROR_INVALID_PARAMETER );
142 return FALSE;
146 static const object_vtbl_t session_vtbl =
148 session_destroy,
149 session_query_option,
150 session_set_option
153 /***********************************************************************
154 * WinHttpOpen (winhttp.@)
156 HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags )
158 session_t *session;
159 HINTERNET handle = NULL;
161 TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent), access, debugstr_w(proxy), debugstr_w(bypass), flags);
163 if (!(session = heap_alloc_zero( sizeof(session_t) ))) return NULL;
165 session->hdr.type = WINHTTP_HANDLE_TYPE_SESSION;
166 session->hdr.vtbl = &session_vtbl;
167 session->hdr.flags = flags;
168 session->hdr.refs = 1;
169 session->access = access;
170 session->hdr.redirect_policy = WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP;
171 list_init( &session->cookie_cache );
173 if (agent && !(session->agent = strdupW( agent ))) goto end;
174 if (proxy && !(session->proxy_server = strdupW( proxy ))) goto end;
175 if (bypass && !(session->proxy_bypass = strdupW( bypass ))) goto end;
177 if (!(handle = alloc_handle( &session->hdr ))) goto end;
178 session->hdr.handle = handle;
180 end:
181 release_object( &session->hdr );
182 TRACE("returning %p\n", handle);
183 return handle;
186 /***********************************************************************
187 * connect_destroy (internal)
189 static void connect_destroy( object_header_t *hdr )
191 connect_t *connect = (connect_t *)hdr;
193 TRACE("%p\n", connect);
195 release_object( &connect->session->hdr );
197 heap_free( connect->hostname );
198 heap_free( connect->servername );
199 heap_free( connect->username );
200 heap_free( connect->password );
201 heap_free( connect );
204 static const object_vtbl_t connect_vtbl =
206 connect_destroy,
207 NULL,
208 NULL
211 /***********************************************************************
212 * WinHttpConnect (winhttp.@)
214 HINTERNET WINAPI WinHttpConnect( HINTERNET hsession, LPCWSTR server, INTERNET_PORT port, DWORD reserved )
216 connect_t *connect;
217 session_t *session;
218 HINTERNET hconnect = NULL;
220 TRACE("%p, %s, %u, %x\n", hsession, debugstr_w(server), port, reserved);
222 if (!server)
224 set_last_error( ERROR_INVALID_PARAMETER );
225 return NULL;
227 if (!(session = (session_t *)grab_object( hsession )))
229 set_last_error( ERROR_INVALID_HANDLE );
230 return NULL;
232 if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
234 release_object( &session->hdr );
235 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
236 return NULL;
238 if (!(connect = heap_alloc_zero( sizeof(connect_t) )))
240 release_object( &session->hdr );
241 return NULL;
243 connect->hdr.type = WINHTTP_HANDLE_TYPE_CONNECT;
244 connect->hdr.vtbl = &connect_vtbl;
245 connect->hdr.refs = 1;
246 connect->hdr.flags = session->hdr.flags;
247 connect->hdr.callback = session->hdr.callback;
248 connect->hdr.notify_mask = session->hdr.notify_mask;
249 connect->hdr.context = session->hdr.context;
251 addref_object( &session->hdr );
252 connect->session = session;
253 list_add_head( &session->hdr.children, &connect->hdr.entry );
255 if (server && !(connect->hostname = strdupW( server ))) goto end;
256 connect->hostport = port;
258 if (server && !(connect->servername = strdupW( server ))) goto end;
259 connect->serverport = port;
261 if (!(hconnect = alloc_handle( &connect->hdr ))) goto end;
262 connect->hdr.handle = hconnect;
264 send_callback( &session->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hconnect, sizeof(hconnect) );
266 end:
267 release_object( &connect->hdr );
269 TRACE("returning %p\n", hconnect);
270 return hconnect;
273 /***********************************************************************
274 * request_destroy (internal)
276 static void request_destroy( object_header_t *hdr )
278 request_t *request = (request_t *)hdr;
279 DWORD i;
281 TRACE("%p\n", request);
283 release_object( &request->connect->hdr );
285 heap_free( request->verb );
286 heap_free( request->path );
287 heap_free( request->version );
288 heap_free( request->raw_headers );
289 heap_free( request->status_text );
290 for (i = 0; i < request->num_headers; i++)
292 heap_free( request->headers[i].field );
293 heap_free( request->headers[i].value );
295 heap_free( request->headers );
296 heap_free( request );
299 static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
301 switch (option)
303 case WINHTTP_OPTION_SECURITY_FLAGS:
305 DWORD flags;
307 if (!buffer || *buflen < sizeof(flags))
309 *buflen = sizeof(flags);
310 set_last_error( ERROR_INSUFFICIENT_BUFFER );
311 return FALSE;
314 flags = 0;
315 if (hdr->flags & WINHTTP_FLAG_SECURE) flags |= SECURITY_FLAG_SECURE;
316 *(DWORD *)buffer = flags;
317 *buflen = sizeof(flags);
318 return TRUE;
320 case WINHTTP_OPTION_SERVER_CERT_CONTEXT:
322 const CERT_CONTEXT *cert;
323 request_t *request = (request_t *)hdr;
325 if (!buffer || *buflen < sizeof(cert))
327 *buflen = sizeof(cert);
328 set_last_error( ERROR_INSUFFICIENT_BUFFER );
329 return FALSE;
332 if (!(cert = netconn_get_certificate( &request->netconn ))) return FALSE;
333 *(CERT_CONTEXT **)buffer = (CERT_CONTEXT *)cert;
334 *buflen = sizeof(cert);
335 return TRUE;
337 case WINHTTP_OPTION_SECURITY_KEY_BITNESS:
339 if (!buffer || *buflen < sizeof(DWORD))
341 *buflen = sizeof(DWORD);
342 set_last_error( ERROR_INSUFFICIENT_BUFFER );
343 return FALSE;
346 *(DWORD *)buffer = 128; /* FIXME */
347 *buflen = sizeof(DWORD);
348 return TRUE;
350 default:
351 FIXME("unimplemented option %u\n", option);
352 set_last_error( ERROR_INVALID_PARAMETER );
353 return FALSE;
357 static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
359 switch (option)
361 case WINHTTP_OPTION_PROXY:
363 WINHTTP_PROXY_INFO *pi = buffer;
365 FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
366 return TRUE;
368 case WINHTTP_OPTION_DISABLE_FEATURE:
370 DWORD disable;
372 if (buflen != sizeof(DWORD))
374 set_last_error( ERROR_INSUFFICIENT_BUFFER );
375 return FALSE;
378 disable = *(DWORD *)buffer;
379 TRACE("0x%x\n", disable);
380 hdr->disable_flags |= disable;
381 return TRUE;
383 case WINHTTP_OPTION_AUTOLOGON_POLICY:
385 DWORD policy;
387 if (buflen != sizeof(DWORD))
389 set_last_error( ERROR_INSUFFICIENT_BUFFER );
390 return FALSE;
393 policy = *(DWORD *)buffer;
394 TRACE("0x%x\n", policy);
395 hdr->logon_policy = policy;
396 return TRUE;
398 case WINHTTP_OPTION_REDIRECT_POLICY:
400 DWORD policy;
402 if (buflen != sizeof(DWORD))
404 set_last_error( ERROR_INSUFFICIENT_BUFFER );
405 return FALSE;
408 policy = *(DWORD *)buffer;
409 TRACE("0x%x\n", policy);
410 hdr->redirect_policy = policy;
411 return TRUE;
413 default:
414 FIXME("unimplemented option %u\n", option);
415 set_last_error( ERROR_INVALID_PARAMETER );
416 return TRUE;
420 static const object_vtbl_t request_vtbl =
422 request_destroy,
423 request_query_option,
424 request_set_option
427 /***********************************************************************
428 * WinHttpOpenRequest (winhttp.@)
430 HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR object, LPCWSTR version,
431 LPCWSTR referrer, LPCWSTR *types, DWORD flags )
433 request_t *request;
434 connect_t *connect;
435 HINTERNET hrequest = NULL;
437 TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect, debugstr_w(verb), debugstr_w(object),
438 debugstr_w(version), debugstr_w(referrer), types, flags);
440 if (!(connect = (connect_t *)grab_object( hconnect )))
442 set_last_error( ERROR_INVALID_HANDLE );
443 return NULL;
445 if (connect->hdr.type != WINHTTP_HANDLE_TYPE_CONNECT)
447 release_object( &connect->hdr );
448 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
449 return NULL;
451 if (!(request = heap_alloc_zero( sizeof(request_t) )))
453 release_object( &connect->hdr );
454 return NULL;
456 request->hdr.type = WINHTTP_HANDLE_TYPE_REQUEST;
457 request->hdr.vtbl = &request_vtbl;
458 request->hdr.refs = 1;
459 request->hdr.flags = flags;
460 request->hdr.callback = connect->hdr.callback;
461 request->hdr.notify_mask = connect->hdr.notify_mask;
462 request->hdr.context = connect->hdr.context;
464 addref_object( &connect->hdr );
465 request->connect = connect;
466 list_add_head( &connect->hdr.children, &request->hdr.entry );
468 if (!netconn_init( &request->netconn, request->hdr.flags & WINHTTP_FLAG_SECURE )) goto end;
470 if (!verb || !verb[0]) verb = getW;
471 if (!(request->verb = strdupW( verb ))) goto end;
473 if (object)
475 WCHAR *path, *p;
476 unsigned int len;
478 len = strlenW( object ) + 1;
479 if (object[0] != '/') len++;
480 if (!(p = path = heap_alloc( len * sizeof(WCHAR) ))) goto end;
482 if (object[0] != '/') *p++ = '/';
483 strcpyW( p, object );
484 request->path = path;
486 else if (!(request->path = strdupW( slashW ))) goto end;
488 if (!version || !version[0]) version = http1_1;
489 if (!(request->version = strdupW( version ))) goto end;
491 if (!(hrequest = alloc_handle( &request->hdr ))) goto end;
492 request->hdr.handle = hrequest;
494 send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hrequest, sizeof(hrequest) );
496 end:
497 release_object( &request->hdr );
499 TRACE("returning %p\n", hrequest);
500 return hrequest;
503 /***********************************************************************
504 * WinHttpCloseHandle (winhttp.@)
506 BOOL WINAPI WinHttpCloseHandle( HINTERNET handle )
508 object_header_t *hdr;
510 TRACE("%p\n", handle);
512 if (!(hdr = grab_object( handle )))
514 set_last_error( ERROR_INVALID_HANDLE );
515 return FALSE;
517 release_object( hdr );
518 free_handle( handle );
519 return TRUE;
522 static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
524 BOOL ret = FALSE;
526 if (!buflen)
528 set_last_error( ERROR_INVALID_PARAMETER );
529 return FALSE;
532 switch (option)
534 case WINHTTP_OPTION_CONTEXT_VALUE:
536 if (!buffer || *buflen < sizeof(DWORD_PTR))
538 *buflen = sizeof(DWORD_PTR);
539 set_last_error( ERROR_INSUFFICIENT_BUFFER );
540 return FALSE;
543 *(DWORD_PTR *)buffer = hdr->context;
544 *buflen = sizeof(DWORD_PTR);
545 return TRUE;
547 default:
548 if (hdr->vtbl->query_option) ret = hdr->vtbl->query_option( hdr, option, buffer, buflen );
549 else
551 FIXME("unimplemented option %u\n", option);
552 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
553 return FALSE;
555 break;
557 return ret;
560 /***********************************************************************
561 * WinHttpQueryOption (winhttp.@)
563 BOOL WINAPI WinHttpQueryOption( HINTERNET handle, DWORD option, LPVOID buffer, LPDWORD buflen )
565 BOOL ret = FALSE;
566 object_header_t *hdr;
568 TRACE("%p, %u, %p, %p\n", handle, option, buffer, buflen);
570 if (!(hdr = grab_object( handle )))
572 set_last_error( ERROR_INVALID_HANDLE );
573 return FALSE;
576 ret = query_option( hdr, option, buffer, buflen );
578 release_object( hdr );
579 return ret;
582 static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
584 BOOL ret = TRUE;
586 if (!buffer)
588 set_last_error( ERROR_INVALID_PARAMETER );
589 return FALSE;
592 switch (option)
594 case WINHTTP_OPTION_CONTEXT_VALUE:
596 if (buflen != sizeof(DWORD_PTR))
598 set_last_error( ERROR_INSUFFICIENT_BUFFER );
599 return FALSE;
602 hdr->context = *(DWORD_PTR *)buffer;
603 return TRUE;
605 default:
606 if (hdr->vtbl->set_option) ret = hdr->vtbl->set_option( hdr, option, buffer, buflen );
607 else
609 FIXME("unimplemented option %u\n", option);
610 set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
611 return FALSE;
613 break;
615 return ret;
618 /***********************************************************************
619 * WinHttpSetOption (winhttp.@)
621 BOOL WINAPI WinHttpSetOption( HINTERNET handle, DWORD option, LPVOID buffer, DWORD buflen )
623 BOOL ret = FALSE;
624 object_header_t *hdr;
626 TRACE("%p, %u, %p, %u\n", handle, option, buffer, buflen);
628 if (!(hdr = grab_object( handle )))
630 set_last_error( ERROR_INVALID_HANDLE );
631 return FALSE;
634 ret = set_option( hdr, option, buffer, buflen );
636 release_object( hdr );
637 return ret;
640 /***********************************************************************
641 * WinHttpDetectAutoProxyConfigUrl (winhttp.@)
643 BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url )
645 FIXME("0x%08x, %p\n", flags, url);
647 set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED );
648 return FALSE;
651 /***********************************************************************
652 * WinHttpGetDefaultProxyConfiguration (winhttp.@)
654 BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
656 FIXME("%p\n", info);
658 info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
659 info->lpszProxy = NULL;
660 info->lpszProxyBypass = NULL;
662 return TRUE;
665 /***********************************************************************
666 * WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
668 BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *config )
670 TRACE("%p\n", config);
672 if (!config)
674 set_last_error( ERROR_INVALID_PARAMETER );
675 return FALSE;
678 /* FIXME: read from HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings */
680 FIXME("returning no proxy used\n");
681 config->fAutoDetect = FALSE;
682 config->lpszAutoConfigUrl = NULL;
683 config->lpszProxy = NULL;
684 config->lpszProxyBypass = NULL;
686 return TRUE;
689 /***********************************************************************
690 * WinHttpGetProxyForUrl (winhttp.@)
692 BOOL WINAPI WinHttpGetProxyForUrl( HINTERNET hsession, LPCWSTR url, WINHTTP_AUTOPROXY_OPTIONS *options,
693 WINHTTP_PROXY_INFO *info )
695 FIXME("%p, %s, %p, %p\n", hsession, debugstr_w(url), options, info);
697 set_last_error( ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR );
698 return FALSE;
701 /***********************************************************************
702 * WinHttpSetDefaultProxyConfiguration (winhttp.@)
704 BOOL WINAPI WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
706 FIXME("%p [%u, %s, %s]\n", info, info->dwAccessType, debugstr_w(info->lpszProxy),
707 debugstr_w(info->lpszProxyBypass));
708 return TRUE;
711 /***********************************************************************
712 * WinHttpSetStatusCallback (winhttp.@)
714 WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback( HINTERNET handle, WINHTTP_STATUS_CALLBACK callback,
715 DWORD flags, DWORD_PTR reserved )
717 object_header_t *hdr;
718 WINHTTP_STATUS_CALLBACK ret;
720 TRACE("%p, %p, 0x%08x, 0x%lx\n", handle, callback, flags, reserved);
722 if (!(hdr = grab_object( handle )))
724 set_last_error( ERROR_INVALID_HANDLE );
725 return WINHTTP_INVALID_STATUS_CALLBACK;
727 ret = hdr->callback;
728 hdr->callback = callback;
729 hdr->notify_mask = flags;
731 release_object( hdr );
732 return ret;
735 /***********************************************************************
736 * WinHttpSetTimeouts (winhttp.@)
738 BOOL WINAPI WinHttpSetTimeouts( HINTERNET handle, int resolve, int connect, int send, int receive )
740 FIXME("%p, %d, %d, %d, %d\n", handle, resolve, connect, send, receive);
741 return TRUE;
744 static const WCHAR wkday[7][4] =
745 {{'S','u','n', 0}, {'M','o','n', 0}, {'T','u','e', 0}, {'W','e','d', 0},
746 {'T','h','u', 0}, {'F','r','i', 0}, {'S','a','t', 0}};
747 static const WCHAR month[12][4] =
748 {{'J','a','n', 0}, {'F','e','b', 0}, {'M','a','r', 0}, {'A','p','r', 0},
749 {'M','a','y', 0}, {'J','u','n', 0}, {'J','u','l', 0}, {'A','u','g', 0},
750 {'S','e','p', 0}, {'O','c','t', 0}, {'N','o','v', 0}, {'D','e','c', 0}};
752 /***********************************************************************
753 * WinHttpTimeFromSystemTime (WININET.@)
755 BOOL WINAPI WinHttpTimeFromSystemTime( const SYSTEMTIME *time, LPWSTR string )
757 static const WCHAR format[] =
758 {'%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
759 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0};
761 TRACE("%p, %p\n", time, string);
763 if (!time || !string) return FALSE;
765 sprintfW( string, format,
766 wkday[time->wDayOfWeek],
767 time->wDay,
768 month[time->wMonth - 1],
769 time->wYear,
770 time->wHour,
771 time->wMinute,
772 time->wSecond );
774 return TRUE;
777 /***********************************************************************
778 * WinHttpTimeToSystemTime (WININET.@)
780 BOOL WINAPI WinHttpTimeToSystemTime( LPCWSTR string, SYSTEMTIME *time )
782 unsigned int i;
783 const WCHAR *s = string;
784 WCHAR *end;
786 TRACE("%s, %p\n", debugstr_w(string), time);
788 if (!string || !time) return FALSE;
790 /* Windows does this too */
791 GetSystemTime( time );
793 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
794 * a SYSTEMTIME structure.
797 while (*s && !isalphaW( *s )) s++;
798 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
799 time->wDayOfWeek = 7;
801 for (i = 0; i < 7; i++)
803 if (toupperW( wkday[i][0] ) == toupperW( s[0] ) &&
804 toupperW( wkday[i][1] ) == toupperW( s[1] ) &&
805 toupperW( wkday[i][2] ) == toupperW( s[2] ) )
807 time->wDayOfWeek = i;
808 break;
812 if (time->wDayOfWeek > 6) return TRUE;
813 while (*s && !isdigitW( *s )) s++;
814 time->wDay = strtolW( s, &end, 10 );
815 s = end;
817 while (*s && !isalphaW( *s )) s++;
818 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
819 time->wMonth = 0;
821 for (i = 0; i < 12; i++)
823 if (toupperW( month[i][0]) == toupperW( s[0] ) &&
824 toupperW( month[i][1]) == toupperW( s[1] ) &&
825 toupperW( month[i][2]) == toupperW( s[2] ) )
827 time->wMonth = i + 1;
828 break;
831 if (time->wMonth == 0) return TRUE;
833 while (*s && !isdigitW( *s )) s++;
834 if (*s == '\0') return TRUE;
835 time->wYear = strtolW( s, &end, 10 );
836 s = end;
838 while (*s && !isdigitW( *s )) s++;
839 if (*s == '\0') return TRUE;
840 time->wHour = strtolW( s, &end, 10 );
841 s = end;
843 while (*s && !isdigitW( *s )) s++;
844 if (*s == '\0') return TRUE;
845 time->wMinute = strtolW( s, &end, 10 );
846 s = end;
848 while (*s && !isdigitW( *s )) s++;
849 if (*s == '\0') return TRUE;
850 time->wSecond = strtolW( s, &end, 10 );
851 s = end;
853 time->wMilliseconds = 0;
854 return TRUE;