Blame SOURCES/0011-utils-Retrieve-node-attributes-in-ovirt_resource_par.patch

4dfa2a
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2bd53e
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
2bd53e
Date: Thu, 18 May 2017 17:53:33 -0300
2bd53e
Subject: [PATCH] utils: Retrieve node attributes in ovirt_resource_parse_xml()
2bd53e
2bd53e
This commit adds a new field to the OvirtXmlElement struct, which is
2bd53e
used to retrieve an attribute from the xml node. It is optional, meaning
2bd53e
that, if not informed, the function will still retrieve the node
2bd53e
contents instead.
2bd53e
2bd53e
We also introduce ovirt_rest_xml_node_get_attr_from_path() function,
2bd53e
to retrieve the given attribute value from the path below the node, much
2bd53e
similar to ovirt_rest_xml_node_get_content_from_path().
2bd53e
2bd53e
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2bd53e
---
2bd53e
 govirt/ovirt-utils.c | 15 ++++++++++++++-
2bd53e
 govirt/ovirt-utils.h |  1 +
2bd53e
 2 files changed, 15 insertions(+), 1 deletion(-)
2bd53e
2bd53e
diff --git a/govirt/ovirt-utils.c b/govirt/ovirt-utils.c
2bd53e
index c0541e9..b9b7c15 100644
2bd53e
--- a/govirt/ovirt-utils.c
2bd53e
+++ b/govirt/ovirt-utils.c
2bd53e
@@ -84,6 +84,16 @@ ovirt_rest_xml_node_get_content_from_path(RestXmlNode *node, const char *path)
2bd53e
     return node->content;
2bd53e
 }
2bd53e
 
2bd53e
+static const char *
2bd53e
+ovirt_rest_xml_node_get_attr_from_path(RestXmlNode *node, const char *path, const char *attr)
2bd53e
+{
2bd53e
+    node = ovirt_rest_xml_node_find(node, path);
2bd53e
+    if (node == NULL)
2bd53e
+        return NULL;
2bd53e
+
2bd53e
+    return rest_xml_node_get_attr(node, attr);
2bd53e
+}
2bd53e
+
2bd53e
 static gboolean
2bd53e
 _set_property_value_from_type(GValue *value,
2bd53e
                               GType type,
2bd53e
@@ -141,7 +151,10 @@ ovirt_rest_xml_node_parse(RestXmlNode *node,
2bd53e
         const char *value_str;
2bd53e
         GValue value = { 0, };
2bd53e
 
2bd53e
-        value_str = ovirt_rest_xml_node_get_content_from_path(node, elements->xml_path);
2bd53e
+        if (elements->xml_attr != NULL)
2bd53e
+            value_str = ovirt_rest_xml_node_get_attr_from_path(node, elements->xml_path, elements->xml_attr);
2bd53e
+        else
2bd53e
+            value_str = ovirt_rest_xml_node_get_content_from_path(node, elements->xml_path);
2bd53e
 
2bd53e
         g_value_init(&value, elements->type);
2bd53e
         if (_set_property_value_from_type(&value, elements->type, value_str, node))
2bd53e
diff --git a/govirt/ovirt-utils.h b/govirt/ovirt-utils.h
2bd53e
index e786311..545847a 100644
2bd53e
--- a/govirt/ovirt-utils.h
2bd53e
+++ b/govirt/ovirt-utils.h
2bd53e
@@ -33,6 +33,7 @@ struct _OvirtXmlElement
2bd53e
     const char *prop_name;
2bd53e
     GType type;
2bd53e
     const char *xml_path;
2bd53e
+    const char *xml_attr; /* if NULL, retrieve node content instead of attribute */
2bd53e
 };
2bd53e
 
2bd53e
 RestXmlNode *ovirt_rest_xml_node_from_call(RestProxyCall *call);