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