ia64/xen-unstable

changeset 13272:bb8ae710d829

Treat <value> tags with no type tag inside as if they were strings (as required
by the XML-RPC spec).

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Fri Jan 05 12:30:32 2007 +0000 (2007-01-05)
parents 36e00d04278d
children 269a08123d87
files tools/libxen/src/xen_common.c
line diff
     1.1 --- a/tools/libxen/src/xen_common.c	Fri Jan 05 12:29:26 2007 +0000
     1.2 +++ b/tools/libxen/src/xen_common.c	Fri Jan 05 12:30:32 2007 +0000
     1.3 @@ -373,11 +373,18 @@ static void server_error_2(xen_session *
     1.4  }
     1.5  
     1.6  
     1.7 +static bool is_node(xmlNode *n, char *type)
     1.8 +{
     1.9 +    return
    1.10 +        n->type == XML_ELEMENT_NODE &&
    1.11 +        0 == strcmp((char *)n->name, type);
    1.12 +}
    1.13 +
    1.14 +
    1.15  static bool is_container_node(xmlNode *n, char *type)
    1.16  {
    1.17      return
    1.18 -        n->type == XML_ELEMENT_NODE &&
    1.19 -        0 == strcmp((char *)n->name, type) &&
    1.20 +        is_node(n, type) &&
    1.21          n->children != NULL &&
    1.22          n->children == n->last &&
    1.23          n->children->type == XML_ELEMENT_NODE;
    1.24 @@ -390,13 +397,30 @@ static bool is_container_node(xmlNode *n
    1.25   */
    1.26  static xmlChar *string_from_value(xmlNode *n, char *type)
    1.27  {
    1.28 -    return
    1.29 -        is_container_node(n, "value") &&
    1.30 -        0 == strcmp((char *)n->children->name, type) ?
    1.31 -          (n->children->children == NULL ?
    1.32 -             xmlStrdup(BAD_CAST("")) :
    1.33 -             xmlNodeGetContent(n->children->children)) :
    1.34 -          NULL;
    1.35 +    /*
    1.36 +      <value><type>XYZ</type></value> is normal, but the XML-RPC spec also
    1.37 +      allows <value>XYZ</value> where XYZ is to be interpreted as a string.
    1.38 +    */
    1.39 +
    1.40 +    if (is_container_node(n, "value") &&
    1.41 +        0 == strcmp((char *)n->children->name, type))
    1.42 +    {
    1.43 +        return
    1.44 +            n->children->children == NULL ?
    1.45 +                xmlStrdup(BAD_CAST("")) :
    1.46 +                xmlNodeGetContent(n->children->children);
    1.47 +    }
    1.48 +    else if (0 == strcmp(type, "string") && is_node(n, "value"))
    1.49 +    {
    1.50 +        return
    1.51 +            n->children == NULL ?
    1.52 +                xmlStrdup(BAD_CAST("")) :
    1.53 +                xmlNodeGetContent(n->children);
    1.54 +    }
    1.55 +    else
    1.56 +    {
    1.57 +        return NULL;
    1.58 +    }
    1.59  }
    1.60  
    1.61