On Fri, Oct 07, 2011 at 11:41:04AM +0200, Christophe Fergeau wrote:
It's used to set the content of a node in a GVirConfigObject to
a given value, and will replace any existing node with the same
value.
---
libvirt-gconfig/libvirt-gconfig-domain.c | 22 ++--------------------
libvirt-gconfig/libvirt-gconfig-object.c | 30 ++++++++++++++++++++++++++++++
libvirt-gconfig/libvirt-gconfig-object.h | 3 +++
3 files changed, 35 insertions(+), 20 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c
b/libvirt-gconfig/libvirt-gconfig-domain.c
index 66ea7cb..039e551 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -146,25 +146,7 @@ char *gvir_config_domain_get_name(GVirConfigDomain *domain)
void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name)
{
- xmlNodePtr parent_node;
- xmlNodePtr old_node;
- xmlNodePtr new_node;
- xmlChar *encoded_name;
-
- parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(domain));
- encoded_name = xmlEncodeEntitiesReentrant(parent_node->doc,
- (xmlChar *)name);
- new_node = xmlNewDocNode(parent_node->doc, NULL,
- (xmlChar *)"name", encoded_name);
- xmlFree(encoded_name);
-
- old_node = gvir_config_xml_get_element(parent_node, "name", NULL);
- if (old_node) {
- old_node = xmlReplaceNode(old_node, new_node);
- xmlFreeNode(old_node);
- } else {
- xmlAddChild(parent_node, new_node);
- }
-
+ gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(domain),
+ "name", name);
g_object_notify(G_OBJECT(domain), "name");
}
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c
b/libvirt-gconfig/libvirt-gconfig-object.c
index 8855ff8..679c3f9 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -292,3 +292,33 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object,
return gvir_config_xml_get_child_element_content_glib(node, node_name);
}
+
+/* FIXME: if there are multiple nodes with the same name, this function
+ * won't behave as expected. Should we get rid of the duplicated node names
+ * here?
+ */
+void gvir_config_object_set_node_content(GVirConfigObject *object,
+ const char *node_name,
+ const char *value)
+{
+ xmlNodePtr parent_node;
+ xmlNodePtr old_node;
+ xmlNodePtr new_node;
+ xmlChar *encoded_name;
+
+ parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object));
+ encoded_name = xmlEncodeEntitiesReentrant(parent_node->doc,
+ (xmlChar *)value);
+ new_node = xmlNewDocNode(parent_node->doc, NULL,
+ (xmlChar *)node_name, encoded_name);
+ xmlFree(encoded_name);
+
+ old_node = gvir_config_xml_get_element(parent_node, node_name, NULL);
+ if (old_node) {
+ old_node = xmlReplaceNode(old_node, new_node);
+ xmlFreeNode(old_node);
+ } else {
+ xmlAddChild(parent_node, new_node);
+ }
+}
+
diff --git a/libvirt-gconfig/libvirt-gconfig-object.h
b/libvirt-gconfig/libvirt-gconfig-object.h
index 1a82490..ab99279 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.h
+++ b/libvirt-gconfig/libvirt-gconfig-object.h
@@ -68,6 +68,9 @@ const gchar *gvir_config_object_get_schema(GVirConfigObject *config);
xmlNodePtr gvir_config_object_get_xml_node(GVirConfigObject *config);
char *gvir_config_object_get_node_content(GVirConfigObject *object,
const char *node_name);
+void gvir_config_object_set_node_content(GVirConfigObject *object,
+ const char *node_name,
+ const char *value);
/* FIXME: move to a libvirt-gconfig-helpers.h file? */
xmlNodePtr gvir_config_object_parse(const char *xml, const char *root_node, GError
**err);
ACK
This addresses my comment from an earlier patch :-)
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|