[libgovirt] Add more XML parsing helper functions
- From: Christophe Fergeau <teuf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgovirt] Add more XML parsing helper functions
- Date: Mon, 2 Sep 2013 15:45:11 +0000 (UTC)
commit e44ff13544912685f7adf61ed0616f22558b38a3
Author: Christophe Fergeau <cfergeau redhat com>
Date: Tue Aug 20 21:17:50 2013 +0200
Add more XML parsing helper functions
They will be useful when parsing XML documents
govirt/ovirt-utils.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++
govirt/ovirt-utils.h | 6 ++++
2 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/govirt/ovirt-utils.c b/govirt/ovirt-utils.c
index d3f4d6d..567357f 100644
--- a/govirt/ovirt-utils.c
+++ b/govirt/ovirt-utils.c
@@ -43,3 +43,81 @@ ovirt_rest_xml_node_from_call(RestProxyCall *call)
return node;
}
+G_GNUC_INTERNAL const char *
+ovirt_rest_xml_node_get_content(RestXmlNode *node, ...)
+{
+ va_list args;
+
+ g_return_val_if_fail(node != NULL, NULL);
+
+ va_start(args, node);
+
+ while (TRUE) {
+ const char *node_name;
+ node_name = va_arg(args, const char *);
+ 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;
+ }
+ }
+
+ va_end(args);
+
+ g_warn_if_fail(node != NULL);
+
+ return node->content;
+}
+
+
+/* These 2 functions come from
+ * libvirt-glib/libvirt-gconfig/libvirt-gconfig-helpers.c
+ * Copyright (C) 2010, 2011 Red Hat, Inc.
+ * LGPLv2.1+ licensed */
+G_GNUC_INTERNAL const char *
+ovirt_utils_genum_get_nick (GType enum_type, gint value)
+{
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+
+ g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
+
+ enum_class = g_type_class_ref(enum_type);
+ enum_value = g_enum_get_value(enum_class, value);
+ g_type_class_unref(enum_class);
+
+ if (enum_value != NULL)
+ return enum_value->value_nick;
+
+ g_return_val_if_reached(NULL);
+}
+
+G_GNUC_INTERNAL int
+ovirt_utils_genum_get_value (GType enum_type, const char *nick,
+ gint default_value)
+{
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+
+ g_return_val_if_fail(G_TYPE_IS_ENUM(enum_type), default_value);
+ g_return_val_if_fail(nick != NULL, default_value);
+
+ enum_class = g_type_class_ref(enum_type);
+ enum_value = g_enum_get_value_by_nick(enum_class, nick);
+ g_type_class_unref(enum_class);
+
+ if (enum_value != NULL)
+ return enum_value->value;
+
+ g_return_val_if_reached(default_value);
+}
+
+G_GNUC_INTERNAL gboolean
+ovirt_utils_boolean_from_string(const char *value)
+{
+ g_return_val_if_fail(value != NULL, FALSE);
+
+ return (g_strcmp0(value, "true") == 0);
+}
diff --git a/govirt/ovirt-utils.h b/govirt/ovirt-utils.h
index 472bb8a..68e440d 100644
--- a/govirt/ovirt-utils.h
+++ b/govirt/ovirt-utils.h
@@ -28,6 +28,12 @@
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_utils_genum_get_nick (GType enum_type, gint value);
+int ovirt_utils_genum_get_value (GType enum_type, const char *nick,
+ gint default_value);
+gboolean ovirt_utils_boolean_from_string(const char *value);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]