From: Visarion Alexandru <viorel.visarion@xxxxxxxxx> Learn to get/set the listen devices that vnc is using. When setting the listen devices, first remove the 'listen' attribute to avoid inconsistencies checks between the 'listen' attribute and the 'address' attribute of the 'listen' node. --- .../libvirt-gconfig-domain-graphics-vnc.c | 84 ++++++++++++++++++++++ .../libvirt-gconfig-domain-graphics-vnc.h | 4 ++ libvirt-gconfig/libvirt-gconfig.sym | 2 + 3 files changed, 90 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c index fc26bb9..46f3a4b 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.c @@ -120,6 +120,90 @@ void gvir_config_domain_graphics_vnc_set_port(GVirConfigDomainGraphicsVnc *graph NULL); } +/** + * gvir_config_domain_graphics_vnc_set_listen_devices: + * @graphics: a #GVirConfigDomainGraphicsVnc + * @listens: (in) (element-type LibvirtGConfig.DomainGraphicsListen): + * + * This method is used to set the various listen nodes a #GVirConfigDomainGraphicsVnc + * device can handle. +*/ +void gvir_config_domain_graphics_vnc_set_listen_devices(GVirConfigDomainGraphicsVnc *graphics, + GList *listens) +{ + GList *it; + + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_VNC(graphics)); + + gvir_config_object_remove_attribute (GVIR_CONFIG_OBJECT(graphics), + "listen"); + gvir_config_object_delete_children (GVIR_CONFIG_OBJECT (graphics), + "listen", NULL); + + for (it = listens; it != NULL; it = it->next) { + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN(it->data)); + + gvir_config_object_attach_add(GVIR_CONFIG_OBJECT(graphics), + GVIR_CONFIG_OBJECT(it->data)); + } +} + +struct ListenData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *listen_devices; +}; + +static gboolean add_listen(xmlNodePtr node, gpointer opaque) +{ + struct ListenData* data = (struct ListenData*)opaque; + GVirConfigObject *object; + + if (g_strcmp0((const gchar *)node->name, "listen") != 0) + return TRUE; + + object = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS, + data->doc, + data->schema, + node); + if (object != NULL) + data->listen_devices = g_list_append(data->listen_devices, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_domain_graphics_vnc_get_listen_devices: + * + * Gets all the listen not of #GVirConfigDomainGraphicsVnc + * + * Returns: (element-type LibvirtGConfig.DomainGraphicsListen) (transfer full): + * a newly allocated #GList of #GVirConfigDomainGraphicsListen. + */ +GList * +gvir_config_domain_graphics_vnc_get_listen_devices(GVirConfigDomainGraphicsVnc *graphics) +{ + struct ListenData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_VNC(graphics), NULL); + + g_object_get(G_OBJECT(graphics), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(graphics)); + data.listen_devices = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(graphics), + NULL, + add_listen, + &data); + g_clear_object(&data.doc); + + return data.listen_devices; +} + void gvir_config_domain_graphics_vnc_set_password(GVirConfigDomainGraphicsVnc *graphics, const char *password) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.h b/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.h index fe78621..8d92952 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.h @@ -73,6 +73,10 @@ int gvir_config_domain_graphics_vnc_get_port(GVirConfigDomainGraphicsVnc *graphi void gvir_config_domain_graphics_vnc_set_port(GVirConfigDomainGraphicsVnc *graphics, int port); +void gvir_config_domain_graphics_vnc_set_listen_devices(GVirConfigDomainGraphicsVnc *graphics, + GList *listens); +GList *gvir_config_domain_graphics_vnc_get_listen_devices(GVirConfigDomainGraphicsVnc *graphics); + void gvir_config_domain_graphics_vnc_set_password(GVirConfigDomainGraphicsVnc *graphics, const char *password); diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 364d8ff..e30ad04 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -750,6 +750,8 @@ global: gvir_config_domain_graphics_listen_address_set_inet_address; gvir_config_domain_graphics_listen_get_type; gvir_config_domain_graphics_spice_set_gl; + gvir_config_domain_graphics_vnc_get_listen_devices; + gvir_config_domain_graphics_vnc_set_listen_devices; gvir_config_domain_hostdev_get_boot_order; gvir_config_domain_hostdev_get_readonly; -- 2.7.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list