ia64/xen-unstable

changeset 14535:931c4b77ea7d

Implement parsing of datetimes.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Fri Mar 23 13:26:08 2007 +0000 (2007-03-23)
parents fbe72d878196
children 678b8838d361
files tools/libxen/src/xen_common.c
line diff
     1.1 --- a/tools/libxen/src/xen_common.c	Fri Mar 23 11:52:09 2007 +0000
     1.2 +++ b/tools/libxen/src/xen_common.c	Fri Mar 23 13:26:08 2007 +0000
     1.3 @@ -16,12 +16,14 @@
     1.4   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
     1.5   */
     1.6  
     1.7 +#define _XOPEN_SOURCE
     1.8  #include <assert.h>
     1.9  #include <stdarg.h>
    1.10  #include <stddef.h>
    1.11  #include <stdio.h>
    1.12  #include <stdlib.h>
    1.13  #include <string.h>
    1.14 +#include <time.h>
    1.15  
    1.16  #include <libxml/parser.h>
    1.17  #include <libxml/tree.h>
    1.18 @@ -493,16 +495,18 @@ static void destring(xen_session *s, xml
    1.19  
    1.20  
    1.21  /**
    1.22 - * result_type : STRING => value : char **, the char * is yours.
    1.23 - * result_type : ENUM   => value : int *
    1.24 - * result_type : INT    => value : int64_t *
    1.25 - * result_type : FLOAT  => value : double *
    1.26 - * result_type : BOOL   => value : bool *
    1.27 - * result_type : SET    => value : arbitrary_set **, the set is yours.
    1.28 - * result_type : MAP    => value : arbitrary_map **, the map is yours.
    1.29 - * result_type : OPT    => value : arbitrary_record_opt **,
    1.30 - *                                 the record is yours, the handle is filled.
    1.31 - * result_type : STRUCT => value : void **, the void * is yours.
    1.32 + * result_type : STRING   => value : char **, the char * is yours.
    1.33 + * result_type : ENUM     => value : int *
    1.34 + * result_type : INT      => value : int64_t *
    1.35 + * result_type : FLOAT    => value : double *
    1.36 + * result_type : BOOL     => value : bool *
    1.37 + * result_type : DATETIME => value : time_t *
    1.38 + * result_type : SET      => value : arbitrary_set **, the set is yours.
    1.39 + * result_type : MAP      => value : arbitrary_map **, the map is yours.
    1.40 + * result_type : OPT      => value : arbitrary_record_opt **,
    1.41 + *                                   the record is yours, the handle is
    1.42 + *                                   filled.
    1.43 + * result_type : STRUCT   => value : void **, the void * is yours.
    1.44   */
    1.45  static void parse_into(xen_session *s, xmlNode *value_node,
    1.46                         const abstract_type *result_type, void *value,
    1.47 @@ -625,6 +629,25 @@ static void parse_into(xen_session *s, x
    1.48      }
    1.49      break;
    1.50  
    1.51 +    case DATETIME:
    1.52 +    {
    1.53 +        xmlChar *string = string_from_value(value_node, "dateTime.iso8601");
    1.54 +        if (string == NULL)
    1.55 +        {
    1.56 +            server_error(
    1.57 +                s, "Expected an DateTime from the server but didn't get one");
    1.58 +        }
    1.59 +        else
    1.60 +        {
    1.61 +            struct tm tm;
    1.62 +            memset(&tm, 0, sizeof(tm));
    1.63 +            strptime((char *)string, "%Y%m%dT%H:%M:%S", &tm);
    1.64 +            ((time_t *)value)[slot] = (time_t)mktime(&tm);
    1.65 +            free(string);
    1.66 +        }
    1.67 +    }
    1.68 +    break;
    1.69 +
    1.70      case SET:
    1.71      {
    1.72          if (!is_container_node(value_node, "value") ||