These functions now take an additional argument corresponding to a namespace href. It's optional and can be NULL when namespaces should be ignored. The 'child_name' argument can now be NULL in order to remove all nodes belonging to a given namespace. --- libvirt-gconfig/libvirt-gconfig-domain-disk.c | 2 +- libvirt-gconfig/libvirt-gconfig-domain-filesys.c | 2 +- libvirt-gconfig/libvirt-gconfig-object-private.h | 7 ++- libvirt-gconfig/libvirt-gconfig-object.c | 50 ++++++++++++++++------ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c index fb4e2b4..b2861e4 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c @@ -301,5 +301,5 @@ gvir_config_domain_disk_set_readonly(GVirConfigDomainDisk *disk, GVirConfigObject *node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(disk), "readonly"); g_object_unref(node); } else - gvir_config_object_delete_child(GVIR_CONFIG_OBJECT(disk), "readonly"); + gvir_config_object_delete_child(GVIR_CONFIG_OBJECT(disk), "readonly", NULL); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-filesys.c b/libvirt-gconfig/libvirt-gconfig-domain-filesys.c index 3eb96f6..904a7a3 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-filesys.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-filesys.c @@ -156,6 +156,6 @@ void gvir_config_domain_filesys_set_readonly(GVirConfigDomainFilesys *filesys, GVirConfigObject *node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(filesys), "readonly"); g_object_unref(node); } else { - gvir_config_object_delete_child(GVIR_CONFIG_OBJECT(filesys), "readonly"); + gvir_config_object_delete_child(GVIR_CONFIG_OBJECT(filesys), "readonly", NULL); } } diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h index 781e1a3..afd28f0 100644 --- a/libvirt-gconfig/libvirt-gconfig-object-private.h +++ b/libvirt-gconfig/libvirt-gconfig-object-private.h @@ -71,8 +71,11 @@ void gvir_config_object_replace_child_with_attribute(GVirConfigObject *object, const char *attr_name, const char *attr_value); void gvir_config_object_delete_child(GVirConfigObject *object, - const char *child_name); -void gvir_config_object_delete_children(GVirConfigObject *object, const char *child_name); + const char *child_name, + const char *ns_href); +void gvir_config_object_delete_children(GVirConfigObject *object, + const char *child_name, + const char *ns_href); void gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child); diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index 7e3cb88..9d99faf 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -465,16 +465,29 @@ gvir_config_object_replace_child_with_attribute(GVirConfigObject *object, g_object_unref(G_OBJECT(child)); } -static gboolean maybe_unlink_node(xmlNodePtr node, const char *name) +struct NodeMatch { + const char *name; + const char *ns; +}; + +static gboolean maybe_unlink_node(xmlNodePtr node, void *opaque) { - if (g_strcmp0((char *)node->name, name) == 0) { + gboolean unlink = TRUE; + struct NodeMatch *match = (struct NodeMatch *)opaque; + + if (match->ns != NULL) { + unlink = unlink && (g_strcmp0(match->ns, (char *)node->ns->href) == 0); + } + + if (match->name != NULL) { + unlink = unlink && (g_strcmp0(match->name, (char *)node->name) == 0); + } + if (unlink) { xmlUnlinkNode(node); xmlFreeNode(node); - - return TRUE; } - return FALSE; + return unlink; } static gboolean remove_oneshot(xmlNodePtr node, gpointer opaque) @@ -484,13 +497,16 @@ static gboolean remove_oneshot(xmlNodePtr node, gpointer opaque) G_GNUC_INTERNAL void gvir_config_object_delete_child(GVirConfigObject *object, - const char *child_name) + const char *child_name, + const char *ns_href) { + struct NodeMatch match; + g_return_if_fail(GVIR_CONFIG_IS_OBJECT(object)); - g_return_if_fail(child_name != NULL); - gvir_config_object_foreach_child(object, NULL, remove_oneshot, - (gpointer)child_name); + match.name = child_name; + match.ns = ns_href; + gvir_config_object_foreach_child(object, NULL, remove_oneshot, &match); } static gboolean remove_always(xmlNodePtr node, gpointer opaque) @@ -501,13 +517,18 @@ static gboolean remove_always(xmlNodePtr node, gpointer opaque) } G_GNUC_INTERNAL void -gvir_config_object_delete_children(GVirConfigObject *object, const char *child_name) +gvir_config_object_delete_children(GVirConfigObject *object, + const char *child_name, + const char *ns_href) { + struct NodeMatch match; + g_return_if_fail(GVIR_CONFIG_IS_OBJECT(object)); - g_return_if_fail(child_name != NULL); - gvir_config_object_foreach_child(object, NULL, remove_always, - (gpointer)child_name); + match.name = child_name; + match.ns = ns_href; + + gvir_config_object_foreach_child(object, NULL, remove_always, &match); } G_GNUC_INTERNAL void @@ -814,7 +835,8 @@ gvir_config_object_attach(GVirConfigObject *parent, GVirConfigObject *child, gbo if (replace) { gvir_config_object_delete_children(parent, - (char *)child->priv->node->name); + (char *)child->priv->node->name, + NULL); } xmlUnlinkNode(child->priv->node); xmlAddChild(parent->priv->node, child->priv->node); -- 1.7.7.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list