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