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