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