This will be helpful to implement GVirConfig getters.
---
libvirt-gconfig/libvirt-gconfig-helpers-private.h | 5 ++
libvirt-gconfig/libvirt-gconfig-helpers.c | 53 ++++++++++++++++++--
2 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-helpers-private.h
b/libvirt-gconfig/libvirt-gconfig-helpers-private.h
index 4c4a539..de18f50 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-helpers-private.h
@@ -50,7 +50,12 @@ xmlChar * gvir_config_xml_get_child_element_content (xmlNode *node,
const char *child_name);
char *gvir_config_xml_get_child_element_content_glib (xmlNode *node,
const char *child_name);
+xmlChar *gvir_config_xml_get_attribute_content(xmlNodePtr node,
+ const char *attr_name);
+char *gvir_config_xml_get_attribute_content_glib(xmlNodePtr node,
+ const char *attr_name);
const char *gvir_config_genum_get_nick (GType enum_type, gint value);
+int gvir_config_genum_get_value (GType enum_type, const char *nick, gint default_value);
G_END_DECLS
#endif /* __LIBVIRT_GCONFIG_HELPERS_PRIVATE_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig-helpers.c
b/libvirt-gconfig/libvirt-gconfig-helpers.c
index c1c23da..a8001ae 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers.c
+++ b/libvirt-gconfig/libvirt-gconfig-helpers.c
@@ -210,22 +210,43 @@ gvir_config_xml_get_child_element_content (xmlNode *node,
return xmlNodeGetContent (child_node);
}
+static char *libxml_to_glib(xmlChar *str)
+{
+ char *g_str;
+
+ if (str == NULL)
+ return NULL;
+ g_str = g_strdup((char *)str);
+ xmlFree(str);
+
+ return g_str;
+}
+
char *
gvir_config_xml_get_child_element_content_glib (xmlNode *node,
const char *child_name)
{
xmlChar *content;
- char *copy;
content = gvir_config_xml_get_child_element_content (node, child_name);
- if (!content)
- return NULL;
- copy = g_strdup ((char *) content);
+ return libxml_to_glib(content);
+}
+
+G_GNUC_INTERNAL xmlChar *
+gvir_config_xml_get_attribute_content(xmlNodePtr node, const char *attr_name)
+{
+ return xmlGetProp(node, (const xmlChar*)attr_name);
+}
+
+G_GNUC_INTERNAL char *
+gvir_config_xml_get_attribute_content_glib(xmlNodePtr node, const char *attr_name)
+{
+ xmlChar *attr;
- xmlFree (content);
+ attr = gvir_config_xml_get_attribute_content(node, attr_name);
- return copy;
+ return libxml_to_glib(attr);
}
const char *gvir_config_genum_get_nick (GType enum_type, gint value)
@@ -244,3 +265,23 @@ const char *gvir_config_genum_get_nick (GType enum_type, gint value)
g_return_val_if_reached(NULL);
}
+
+G_GNUC_INTERNAL int
+gvir_config_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);
+}
--
1.7.7.5