This makes it possible to use the other GVirConfigObject helpers with the new child, and hides libxml from one more place in our API. --- libvirt-gconfig/libvirt-gconfig-domain-disk.c | 9 +++- .../libvirt-gconfig-domain-interface-network.c | 7 ++- libvirt-gconfig/libvirt-gconfig-domain-os.c | 46 +++++++++---------- libvirt-gconfig/libvirt-gconfig-domain-video.c | 14 +++--- libvirt-gconfig/libvirt-gconfig-domain.c | 12 +++-- libvirt-gconfig/libvirt-gconfig-object-private.h | 4 +- libvirt-gconfig/libvirt-gconfig-object.c | 14 ++++-- 7 files changed, 57 insertions(+), 49 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c index 0c42384..53a80f3 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c @@ -112,13 +112,13 @@ void gvir_config_domain_disk_set_snapshot_type(GVirConfigDomainDisk *disk, void gvir_config_domain_disk_set_source(GVirConfigDomainDisk *disk, const char *source) { - xmlNodePtr source_node; + GVirConfigObject *source_node; const char *attribute_name; g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk)); source_node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(disk), "source"); - g_return_if_fail(source_node != NULL); + g_return_if_fail(GVIR_IS_CONFIG_OBJECT(source_node)); switch (disk->priv->type) { case GVIR_CONFIG_DOMAIN_DISK_FILE: @@ -136,7 +136,10 @@ void gvir_config_domain_disk_set_source(GVirConfigDomainDisk *disk, default: g_return_if_reached(); } - xmlNewProp(source_node, (xmlChar*)attribute_name, (xmlChar*)source); + gvir_config_object_set_attribute(source_node, + attribute_name, source, + NULL); + g_object_unref(G_OBJECT(source_node)); } void gvir_config_domain_disk_set_driver_name(GVirConfigDomainDisk *disk, diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface-network.c b/libvirt-gconfig/libvirt-gconfig-domain-interface-network.c index 9ccf41a..d9e00fe 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-interface-network.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-interface-network.c @@ -85,12 +85,13 @@ GVirConfigDomainInterfaceNetwork *gvir_config_domain_interface_network_new_from_ void gvir_config_domain_interface_network_set_source(GVirConfigDomainInterfaceNetwork *interface, const char *source) { - xmlNodePtr source_node; + GVirConfigObject *source_node; g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_INTERFACE_NETWORK(interface)); source_node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(interface), "source"); - g_return_if_fail(source_node != NULL); - xmlNewProp(source_node, (xmlChar*)"network", (xmlChar*)source); + g_return_if_fail(GVIR_IS_CONFIG_OBJECT(source_node)); + gvir_config_object_set_attribute(source_node, "network", source, NULL); + g_object_unref(G_OBJECT(source_node)); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-os.c b/libvirt-gconfig/libvirt-gconfig-domain-os.c index f1802ae..9110d6a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-os.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-os.c @@ -79,16 +79,15 @@ GVirConfigDomainOs *gvir_config_domain_os_new_from_xml(const gchar *xml, GError void gvir_config_domain_os_set_os_type(GVirConfigDomainOs *os, GVirConfigDomainOsType type) { - xmlNodePtr node; const char *type_str; g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os)); - node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(os), "type"); - g_return_if_fail(node != NULL); type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_OS_TYPE, type); g_return_if_fail(type_str != NULL); - xmlNodeSetContent(node, (xmlChar*)type_str); + + gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(os), + "type", type_str); } void gvir_config_domain_os_set_loader(GVirConfigDomainOs *os, @@ -101,47 +100,46 @@ void gvir_config_domain_os_set_loader(GVirConfigDomainOs *os, void gvir_config_domain_os_enable_boot_menu(GVirConfigDomainOs *os, gboolean enable) { - xmlNodePtr node; + GVirConfigObject *node; g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os)); node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(os), "bootmenu"); - g_return_if_fail(node != NULL); - if (enable) - xmlNewProp(node, (xmlChar*)"enable", (xmlChar*)"yes"); - else - xmlNewProp(node, (xmlChar*)"enable", (xmlChar*)"no"); + g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node)); + gvir_config_object_set_attribute_with_type(node, "enable", + G_TYPE_BOOLEAN, enable, + NULL); + g_object_unref(G_OBJECT(node)); } void gvir_config_domain_os_bios_enable_serial(GVirConfigDomainOs *os, gboolean enable) { - xmlNodePtr node; + GVirConfigObject *node; g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os)); node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(os), "bios"); - g_return_if_fail(node != NULL); - if (enable) - xmlNewProp(node, (xmlChar*)"useserial", (xmlChar*)"yes"); - else - xmlNewProp(node, (xmlChar*)"useserial", (xmlChar*)"no"); + g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node)); + gvir_config_object_set_attribute_with_type(node, "useserial", + G_TYPE_BOOLEAN, enable, + NULL); + g_object_unref(G_OBJECT(node)); } void gvir_config_domain_os_set_smbios_mode(GVirConfigDomainOs *os, - GVirConfigDomainOsSmBiosMode mode) + GVirConfigDomainOsSmBiosMode mode) { - xmlNodePtr node; - const char *mode_str; + GVirConfigObject *node; g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os)); node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(os), "smbios"); - g_return_if_fail(node != NULL); - mode_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_OS_SM_BIOS_MODE, - mode); - if (mode_str != NULL) - xmlNewProp(node, (xmlChar*)"mode", (xmlChar*)mode_str); + g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node)); + gvir_config_object_set_attribute_with_type(node, "mode", + GVIR_TYPE_CONFIG_DOMAIN_OS_SM_BIOS_MODE, + mode, NULL); + g_object_unref(G_OBJECT(node)); } /** diff --git a/libvirt-gconfig/libvirt-gconfig-domain-video.c b/libvirt-gconfig/libvirt-gconfig-domain-video.c index 8c6c9fb..7276e02 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-video.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-video.c @@ -81,17 +81,17 @@ GVirConfigDomainVideo *gvir_config_domain_video_new_from_xml(const gchar *xml, void gvir_config_domain_video_set_model(GVirConfigDomainVideo *video, GVirConfigDomainVideoModel model) { - xmlNodePtr node; - const char *model_str; + GVirConfigObject *node; g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_VIDEO(video)); node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(video), "model"); - g_return_if_fail(node != NULL); - model_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_VIDEO_MODEL, - model); - g_return_if_fail(model_str != NULL); - xmlNewProp(node, (xmlChar*)"type", (xmlChar*)model_str); + g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node)); + gvir_config_object_set_attribute_with_type(node, "type", + GVIR_TYPE_CONFIG_DOMAIN_VIDEO_MODEL, + model, + NULL); + g_object_unref(G_OBJECT(node)); } void gvir_config_domain_video_set_vram(GVirConfigDomainVideo *video, diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index d9cb2e9..84b7401 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -249,17 +249,19 @@ GStrv gvir_config_domain_get_features(GVirConfigDomain *domain) void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features) { - xmlNodePtr features_node; + GVirConfigObject *features_node; GStrv it; features_node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(domain), "features"); + g_return_if_fail(GVIR_IS_CONFIG_OBJECT(features_node)); for (it = features; *it != NULL; it++) { - xmlNodePtr node; - - node = xmlNewDocNode(features_node->doc, NULL, (xmlChar *)*it, NULL); - xmlAddChild(features_node, node); + GVirConfigObject *feature; + feature = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(features_node), + *it); + g_object_unref(G_OBJECT(feature)); } + g_object_unref(G_OBJECT(features_node)); g_object_notify(G_OBJECT(domain), "features"); } diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h index 8f9b943..f196be6 100644 --- a/libvirt-gconfig/libvirt-gconfig-object-private.h +++ b/libvirt-gconfig/libvirt-gconfig-object-private.h @@ -37,8 +37,8 @@ void gvir_config_object_set_node_content_uint64(GVirConfigObject *object, guint64 value); GVirConfigObject *gvir_config_object_add_child(GVirConfigObject *object, const char *child_name); -xmlNodePtr gvir_config_object_replace_child(GVirConfigObject *object, - const char *child_name); +GVirConfigObject *gvir_config_object_replace_child(GVirConfigObject *object, + const char *child_name); 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 70d0608..72203be 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -368,7 +368,7 @@ gvir_config_object_add_child(GVirConfigObject *object, NULL)); } -G_GNUC_INTERNAL xmlNodePtr +G_GNUC_INTERNAL GVirConfigObject * gvir_config_object_replace_child(GVirConfigObject *object, const char *child_name) { @@ -380,7 +380,10 @@ gvir_config_object_replace_child(GVirConfigObject *object, new_node = xmlNewDocNode(NULL, NULL, (xmlChar *)child_name, NULL); gvir_config_object_set_child_internal(object, new_node, TRUE); - return new_node; + return GVIR_CONFIG_OBJECT(g_object_new(GVIR_TYPE_CONFIG_OBJECT, + "doc", object->priv->doc, + "node", new_node, + NULL)); } G_GNUC_INTERNAL void @@ -388,8 +391,8 @@ gvir_config_object_set_node_content(GVirConfigObject *object, const char *node_name, const char *value) { - xmlNodePtr node; xmlChar *encoded_data; + GVirConfigObject *node; g_return_if_fail(GVIR_IS_CONFIG_OBJECT(object)); g_return_if_fail(node_name != NULL); @@ -397,10 +400,11 @@ gvir_config_object_set_node_content(GVirConfigObject *object, node = gvir_config_object_replace_child(object, node_name); g_return_if_fail(node != NULL); - encoded_data = xmlEncodeEntitiesReentrant(node->doc, + encoded_data = xmlEncodeEntitiesReentrant(node->priv->node->doc, (xmlChar *)value); - xmlNodeSetContent(node, encoded_data); + xmlNodeSetContent(node->priv->node, encoded_data); xmlFree(encoded_data); + g_object_unref(G_OBJECT(node)); } G_GNUC_INTERNAL void -- 1.7.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list