92 lines
2.5 KiB
Diff
92 lines
2.5 KiB
Diff
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
|
||
|
Date: Fri, 19 May 2017 00:31:46 -0300
|
||
|
Subject: [PATCH] utils: Rename ovirt_rest_xml_node_get_content_va() to
|
||
|
ovirt_rest_xml_node_find()
|
||
|
|
||
|
It is more useful to make this function retrieve a sub node and let the
|
||
|
caller do what it wants with that node, instead of returning the content
|
||
|
directly.
|
||
|
|
||
|
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
|
||
|
---
|
||
|
govirt/ovirt-utils.c | 59 +++++++++++++++++++-------------------------
|
||
|
1 file changed, 26 insertions(+), 33 deletions(-)
|
||
|
|
||
|
diff --git a/govirt/ovirt-utils.c b/govirt/ovirt-utils.c
|
||
|
index 951c693..c0541e9 100644
|
||
|
--- a/govirt/ovirt-utils.c
|
||
|
+++ b/govirt/ovirt-utils.c
|
||
|
@@ -50,45 +50,38 @@ ovirt_rest_xml_node_from_call(RestProxyCall *call)
|
||
|
return node;
|
||
|
}
|
||
|
|
||
|
-static const char *
|
||
|
-ovirt_rest_xml_node_get_content_va(RestXmlNode *node,
|
||
|
- va_list *args,
|
||
|
- GStrv str_array)
|
||
|
-{
|
||
|
- g_return_val_if_fail((args != NULL) || (str_array != NULL), NULL);
|
||
|
-
|
||
|
- while (TRUE) {
|
||
|
- const char *node_name;
|
||
|
-
|
||
|
- if (args != NULL) {
|
||
|
- node_name = va_arg(*args, const char *);
|
||
|
- } else {
|
||
|
- node_name = *str_array;
|
||
|
- str_array++;
|
||
|
- }
|
||
|
- if (node_name == NULL)
|
||
|
- break;
|
||
|
- node = rest_xml_node_find(node, node_name);
|
||
|
- if (node == NULL) {
|
||
|
- g_debug("could not find XML node '%s'", node_name);
|
||
|
- return NULL;
|
||
|
- }
|
||
|
- }
|
||
|
-
|
||
|
- return node->content;
|
||
|
-}
|
||
|
-
|
||
|
-static const char *
|
||
|
-ovirt_rest_xml_node_get_content_from_path(RestXmlNode *node, const char *path)
|
||
|
+static RestXmlNode *
|
||
|
+ovirt_rest_xml_node_find(RestXmlNode *node, const char *path)
|
||
|
{
|
||
|
+ guint i;
|
||
|
GStrv pathv;
|
||
|
- const char *content;
|
||
|
+
|
||
|
+ g_return_val_if_fail((path != NULL), NULL);
|
||
|
|
||
|
pathv = g_strsplit(path, "/", -1);
|
||
|
- content = ovirt_rest_xml_node_get_content_va(node, NULL, pathv);
|
||
|
+
|
||
|
+ for (i = 0; i < g_strv_length(pathv); ++i) {
|
||
|
+ node = rest_xml_node_find(node, pathv[i]);
|
||
|
+ if (node == NULL) {
|
||
|
+ g_debug("could not find XML node '%s'", pathv[i]);
|
||
|
+ break;
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
g_strfreev(pathv);
|
||
|
|
||
|
- return content;
|
||
|
+ return node;
|
||
|
+}
|
||
|
+
|
||
|
+static const char *
|
||
|
+ovirt_rest_xml_node_get_content_from_path(RestXmlNode *node, const char *path)
|
||
|
+{
|
||
|
+ node = ovirt_rest_xml_node_find(node, path);
|
||
|
+
|
||
|
+ if (node == NULL)
|
||
|
+ return NULL;
|
||
|
+
|
||
|
+ return node->content;
|
||
|
}
|
||
|
|
||
|
static gboolean
|