It's similar to gvir_config_object_replace_child except that if the current node already has a child with the correct name, it returns the existing child instead of replacing it. -- v2: instead of adding an argument to gvir_config_object_new_child, split the function in 2 separate ones, gvir_config_object_add_child and gvir_config_object_replace_child. use g_return_if_fail to test function args for sanity --- libvirt-gconfig/libvirt-gconfig-object-private.h | 2 ++ libvirt-gconfig/libvirt-gconfig-object.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h index a14a792..0cedaef 100644 --- a/libvirt-gconfig/libvirt-gconfig-object-private.h +++ b/libvirt-gconfig/libvirt-gconfig-object-private.h @@ -35,6 +35,8 @@ void gvir_config_object_set_node_content(GVirConfigObject *object, void gvir_config_object_set_node_content_uint64(GVirConfigObject *object, const char *node_name, guint64 value); +xmlNodePtr gvir_config_object_add_child(GVirConfigObject *object, + const char *child_name); xmlNodePtr gvir_config_object_replace_child(GVirConfigObject *object, const char *child_name); void gvir_config_object_set_child(GVirConfigObject *object, diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index ac10e88..142d714 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -333,6 +333,26 @@ gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child) } G_GNUC_INTERNAL xmlNodePtr +gvir_config_object_add_child(GVirConfigObject *object, + const char *child_name) +{ + xmlNodePtr new_node; + xmlNodePtr old_node; + + g_return_val_if_fail(GVIR_IS_CONFIG_OBJECT(object), NULL); + + new_node = xmlNewDocNode(NULL, NULL, (xmlChar *)child_name, NULL); + old_node = gvir_config_object_set_child_internal(object, new_node, + FALSE); + if (old_node != NULL) { + xmlFreeNode(new_node); + return old_node; + } + + return new_node; +} + +G_GNUC_INTERNAL xmlNodePtr gvir_config_object_replace_child(GVirConfigObject *object, const char *child_name) { -- 1.7.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list