[libgovirt] utils: Add ovirt_rest_xml_node_get_content_from_path



commit daca155abd4142dbe69b08832e9286e683a4e808
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Thu Mar 12 12:59:13 2015 +0100

    utils: Add ovirt_rest_xml_node_get_content_from_path
    
    This will be used in the storage domain parser instead of
    ovirt_rest_xml_node_get_content() as this will allow us
    to parse the /status/state node.

 govirt/ovirt-utils.c |   51 ++++++++++++++++++++++++++++++++++++++++---------
 govirt/ovirt-utils.h |    2 +
 2 files changed, 43 insertions(+), 10 deletions(-)
---
diff --git a/govirt/ovirt-utils.c b/govirt/ovirt-utils.c
index 77a3f8e..0e0134c 100644
--- a/govirt/ovirt-utils.c
+++ b/govirt/ovirt-utils.c
@@ -49,33 +49,64 @@ ovirt_rest_xml_node_from_call(RestProxyCall *call)
     return node;
 }
 
-G_GNUC_INTERNAL const char *
-ovirt_rest_xml_node_get_content(RestXmlNode *node, ...)
+static const char *
+ovirt_rest_xml_node_get_content_va(RestXmlNode *node,
+                                   va_list *args,
+                                   GStrv str_array)
 {
-    va_list args;
-
-    g_return_val_if_fail(node != NULL, NULL);
-
-    va_start(args, node);
+    g_return_val_if_fail((args != NULL) || (str_array != NULL), NULL);
 
     while (TRUE) {
         const char *node_name;
-        node_name = va_arg(args, const char *);
+
+        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);
-            va_end(args);
             return NULL;
         }
     }
 
+    return node->content;
+}
+
+G_GNUC_INTERNAL const char *
+ovirt_rest_xml_node_get_content_from_path(RestXmlNode *node, const char *path)
+{
+    GStrv pathv;
+    const char *content;
+
+    pathv = g_strsplit(path, "/", -1);
+    content = ovirt_rest_xml_node_get_content_va(node, NULL, pathv);
+    g_strfreev(pathv);
+
+    return content;
+}
+
+G_GNUC_INTERNAL const char *
+ovirt_rest_xml_node_get_content(RestXmlNode *node, ...)
+{
+    va_list args;
+    const char *content;
+
+    g_return_val_if_fail(node != NULL, NULL);
+
+    va_start(args, node);
+
+    content = ovirt_rest_xml_node_get_content_va(node, &args, NULL);
+
     va_end(args);
 
     g_warn_if_fail(node != NULL);
 
-    return node->content;
+    return content;
 }
 
 
diff --git a/govirt/ovirt-utils.h b/govirt/ovirt-utils.h
index 0232e26..3f43fc9 100644
--- a/govirt/ovirt-utils.h
+++ b/govirt/ovirt-utils.h
@@ -29,6 +29,8 @@ G_BEGIN_DECLS
 
 RestXmlNode *ovirt_rest_xml_node_from_call(RestProxyCall *call);
 const char *ovirt_rest_xml_node_get_content(RestXmlNode *node, ...);
+const char *ovirt_rest_xml_node_get_content_from_path(RestXmlNode *node,
+                                                      const char *path);
 gboolean ovirt_utils_gerror_from_xml_fault(RestXmlNode *root, GError **error);
 gboolean g_object_set_guint_property_from_xml(GObject *g_object,
                                                    RestXmlNode *node,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]