[libvirt] [gconfig v2 0/6] Add support for changing listen address

From: Visarion Alexandru <viorel.visarion@gmail.com> libvirt-domain-graphics-listen defines an abstract class used to represent one listen node. libvirt-domain-graphics-liste-address defines a class that represents a listen node of type 'address', for the graphics device. We have to first remove the 'listen' attribute of the graphics device before adding child 'listen' nodes, to avoid inconsistencies check. I added a test for the new API which uses a SPICE graphics (I noticed that generally APIs aren't tested on both SPICE and VNC) Visarion Alexandru (6): libvirt-gconfig: Include GIO dependency Introduce libvirt-domain-graphics-listen Introduce libvirt-gconfig-domain-graphics-listen-address config: Add vnc listen getter/setter config: Add spice listen getter/setter tests: Add test for GVirConfigDomainGraphicsListenAddress configure.ac | 2 + libvirt-gconfig-1.0.pc.in | 2 +- libvirt-gconfig/Makefile.am | 10 +- ...ibvirt-gconfig-domain-graphics-listen-address.c | 128 +++++++++++++++++++++ ...ibvirt-gconfig-domain-graphics-listen-address.h | 78 +++++++++++++ .../libvirt-gconfig-domain-graphics-listen.c | 49 ++++++++ .../libvirt-gconfig-domain-graphics-listen.h | 65 +++++++++++ .../libvirt-gconfig-domain-graphics-spice.c | 84 ++++++++++++++ .../libvirt-gconfig-domain-graphics-spice.h | 4 + .../libvirt-gconfig-domain-graphics-vnc.c | 84 ++++++++++++++ .../libvirt-gconfig-domain-graphics-vnc.h | 4 + libvirt-gconfig/libvirt-gconfig.h | 2 + libvirt-gconfig/libvirt-gconfig.sym | 12 ++ tests/test-gconfig.c | 36 ++++++ .../xml/gconfig-domain-device-graphics-listen.xml | 7 ++ vapi/Makefile.am | 1 + 16 files changed, 565 insertions(+), 3 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.h create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h create mode 100644 tests/xml/gconfig-domain-device-graphics-listen.xml -- 2.7.4

From: Visarion Alexandru <viorel.visarion@gmail.com> We will need a GInetAddress for setting a graphics device's listen address, so let's include GIO2 in libvirt-gconfig. --- configure.ac | 2 ++ libvirt-gconfig-1.0.pc.in | 2 +- libvirt-gconfig/Makefile.am | 6 ++++-- vapi/Makefile.am | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 8edde74..647a5ec 100644 --- a/configure.ac +++ b/configure.ac @@ -112,6 +112,8 @@ PKG_CHECK_MODULES(GLIB2, glib-2.0 >= $GLIB2_TEST_REQUIRED, PKG_CHECK_MODULES(GTHREAD2, gthread-2.0 >= $GLIB2_REQUIRED) PKG_CHECK_MODULES(GOBJECT2, gobject-2.0 >= $GLIB2_REQUIRED) PKG_CHECK_MODULES(GIO2, gio-2.0 >= $GLIB2_REQUIRED) +AC_SUBST(GIO2_CFLAGS) +AC_SUBST(GIO2_LIBS) PKG_CHECK_MODULES(LIBXML2, libxml-2.0 >= $LIBXML2_REQUIRED) AM_CONDITIONAL([ENABLE_TESTS], [test "$enable_tests" = "yes"]) diff --git a/libvirt-gconfig-1.0.pc.in b/libvirt-gconfig-1.0.pc.in index a8cb5ac..c0212f8 100644 --- a/libvirt-gconfig-1.0.pc.in +++ b/libvirt-gconfig-1.0.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: libvirt-gconfig Version: @VERSION@ Description: libvirt GConfig library -Requires: gobject-2.0 libxml-2.0 +Requires: gobject-2.0 libxml-2.0 gio-2.0 Libs: -L${libdir} -lvirt-gconfig-1.0 Cflags: -I${includedir}/libvirt-gconfig-1.0 diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 0400343..1a9a97a 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -209,10 +209,12 @@ libvirt_gconfig_1_0_la_CFLAGS = \ -I$(top_builddir) \ $(GOBJECT2_CFLAGS) \ $(LIBXML2_CFLAGS) \ + $(GIO2_CFLAGS) \ $(WARN_CFLAGS) libvirt_gconfig_1_0_la_LIBADD = \ $(GOBJECT2_LIBS) \ $(LIBXML2_LIBS) \ + $(GIO2_LIBS) \ $(CYGWIN_EXTRA_LIBADD) libvirt_gconfig_1_0_la_DEPENDENCIES = \ libvirt-gconfig.sym @@ -253,8 +255,8 @@ INTROSPECTION_GIRS = if HAVE_INTROSPECTION LibvirtGConfig-1.0.gir: libvirt-gconfig-1.0.la -LibvirtGConfig_1_0_gir_INCLUDES = GObject-2.0 -LibvirtGConfig_1_0_gir_PACKAGES = gobject-2.0 +LibvirtGConfig_1_0_gir_INCLUDES = GObject-2.0 Gio-2.0 +LibvirtGConfig_1_0_gir_PACKAGES = gobject-2.0 gio-2.0 LibvirtGConfig_1_0_gir_EXPORT_PACKAGES = libvirt-gconfig-1.0 LibvirtGConfig_1_0_gir_LIBS = libvirt-gconfig-1.0.la LibvirtGConfig_1_0_gir_FILES = \ diff --git a/vapi/Makefile.am b/vapi/Makefile.am index 568de4f..dc98bd1 100644 --- a/vapi/Makefile.am +++ b/vapi/Makefile.am @@ -33,6 +33,7 @@ libvirt-gconfig-1.0.vapi: $(top_builddir)/libvirt-gconfig/LibvirtGConfig-1.0.gir $(AM_V_GEN)$(VAPIGEN) \ --vapidir=$(builddir) \ --pkg gobject-2.0 \ + --pkg gio-2.0 \ --library libvirt-gconfig-1.0 \ $< -- 2.7.4

Hey, On Wed, Aug 17, 2016 at 06:58:46PM +0300, Visarion Alexandru wrote:
From: Visarion Alexandru <viorel.visarion@gmail.com>
We will need a GInetAddress for setting a graphics device's listen address, so let's include GIO2 in libvirt-gconfig. --- configure.ac | 2 ++ libvirt-gconfig-1.0.pc.in | 2 +- libvirt-gconfig/Makefile.am | 6 ++++-- vapi/Makefile.am | 1 + 4 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac index 8edde74..647a5ec 100644 --- a/configure.ac +++ b/configure.ac @@ -112,6 +112,8 @@ PKG_CHECK_MODULES(GLIB2, glib-2.0 >= $GLIB2_TEST_REQUIRED, PKG_CHECK_MODULES(GTHREAD2, gthread-2.0 >= $GLIB2_REQUIRED) PKG_CHECK_MODULES(GOBJECT2, gobject-2.0 >= $GLIB2_REQUIRED) PKG_CHECK_MODULES(GIO2, gio-2.0 >= $GLIB2_REQUIRED) +AC_SUBST(GIO2_CFLAGS) +AC_SUBST(GIO2_LIBS)
This is not needed, PKG_CHECK_MODULES() already does it for you (I've fixed it locally, so no need to resend a patch). Acked-by: Christophe Fergeau <cfergeau@redhat.com> Christophe

From: Visarion Alexandru <viorel.visarion@gmail.com> Abstract class which represents a listen child node of the graphics device. --- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-graphics-listen.c | 49 ++++++++++++++++ .../libvirt-gconfig-domain-graphics-listen.h | 65 ++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 1 + 5 files changed, 118 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 1a9a97a..09739c5 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -46,6 +46,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-filesys.h \ libvirt-gconfig-domain-graphics.h \ libvirt-gconfig-domain-graphics-desktop.h \ + libvirt-gconfig-domain-graphics-listen.h\ libvirt-gconfig-domain-graphics-rdp.h \ libvirt-gconfig-domain-graphics-sdl.h \ libvirt-gconfig-domain-graphics-spice.h \ @@ -139,6 +140,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-filesys.c \ libvirt-gconfig-domain-graphics.c \ libvirt-gconfig-domain-graphics-desktop.c \ + libvirt-gconfig-domain-graphics-listen.c\ libvirt-gconfig-domain-graphics-rdp.c \ libvirt-gconfig-domain-graphics-sdl.c \ libvirt-gconfig-domain-graphics-spice.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.c new file mode 100644 index 0000000..095abe7 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.c @@ -0,0 +1,49 @@ +/* + * libvirt-gconfig-domain-graphics-listen.c: libvirt domain graphics listen base class + * + * Copyright (C) 2016 Red Hat, Inc. + * Copyright (C) 2016 Visarion Alexandru <viorel.visarion@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Visarion Alexandru <viorel.visarion@gmail.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN, GVirConfigDomainGraphicsListenPrivate)) + +struct _GVirConfigDomainGraphicsListenPrivate +{ + gboolean unused; +}; + +G_DEFINE_ABSTRACT_TYPE(GVirConfigDomainGraphicsListen, gvir_config_domain_graphics_listen, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_domain_graphics_listen_class_init(GVirConfigDomainGraphicsListenClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainGraphicsListenPrivate)); +} + + +static void gvir_config_domain_graphics_listen_init(GVirConfigDomainGraphicsListen *listen) +{ + listen->priv = GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_GET_PRIVATE(listen); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h new file mode 100644 index 0000000..6f93d27 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h @@ -0,0 +1,65 @@ +/* + * libvirt-gconfig-domain-graphics-listen.h: libvirt domain graphics listen base class + * + * Copyright (C) 2016 Red Hat, Inc. + * Copyright (C) 2016 Visarion Alexandru <viorel.visarion@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Visarion Alexandru <viorel.visarion@gmail.com> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_LISTEN_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_LISTEN_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN (gvir_config_domain_graphics_listen_get_type ()) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN, GVirConfigDomainGraphicsListen)) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN, GVirConfigDomainGraphicsListenClass)) +#define GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN)) +#define GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN)) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN, GVirConfigDomainGraphicsListenClass)) + +typedef struct _GVirConfigDomainGraphicsListen GVirConfigDomainGraphicsListen; +typedef struct _GVirConfigDomainGraphicsListenPrivate GVirConfigDomainGraphicsListenPrivate; +typedef struct _GVirConfigDomainGraphicsListenClass GVirConfigDomainGraphicsListenClass; + +struct _GVirConfigDomainGraphicsListen +{ + GVirConfigObject parent; + + GVirConfigDomainGraphicsListenPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainGraphicsListenClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_domain_graphics_listen_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_LISTEN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 6462154..496986e 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -63,6 +63,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-filesys.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 4ef4bf7..32d2c7b 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -741,6 +741,7 @@ global: gvir_config_domain_address_pci_get_multifunction; gvir_config_domain_address_pci_get_slot; + gvir_config_domain_graphics_listen_get_type; gvir_config_domain_graphics_spice_set_gl; gvir_config_domain_hostdev_get_boot_order; -- 2.7.4

Acked-by: Christophe Fergeau <cfergeau@redhat.com> On Wed, Aug 17, 2016 at 06:58:47PM +0300, Visarion Alexandru wrote:
From: Visarion Alexandru <viorel.visarion@gmail.com>
Abstract class which represents a listen child node of the graphics device. --- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-graphics-listen.c | 49 ++++++++++++++++ .../libvirt-gconfig-domain-graphics-listen.h | 65 ++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 1 + 5 files changed, 118 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 1a9a97a..09739c5 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -46,6 +46,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-filesys.h \ libvirt-gconfig-domain-graphics.h \ libvirt-gconfig-domain-graphics-desktop.h \ + libvirt-gconfig-domain-graphics-listen.h\ libvirt-gconfig-domain-graphics-rdp.h \ libvirt-gconfig-domain-graphics-sdl.h \ libvirt-gconfig-domain-graphics-spice.h \ @@ -139,6 +140,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-filesys.c \ libvirt-gconfig-domain-graphics.c \ libvirt-gconfig-domain-graphics-desktop.c \ + libvirt-gconfig-domain-graphics-listen.c\ libvirt-gconfig-domain-graphics-rdp.c \ libvirt-gconfig-domain-graphics-sdl.c \ libvirt-gconfig-domain-graphics-spice.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.c new file mode 100644 index 0000000..095abe7 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.c @@ -0,0 +1,49 @@ +/* + * libvirt-gconfig-domain-graphics-listen.c: libvirt domain graphics listen base class + * + * Copyright (C) 2016 Red Hat, Inc. + * Copyright (C) 2016 Visarion Alexandru <viorel.visarion@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Visarion Alexandru <viorel.visarion@gmail.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN, GVirConfigDomainGraphicsListenPrivate)) + +struct _GVirConfigDomainGraphicsListenPrivate +{ + gboolean unused; +}; + +G_DEFINE_ABSTRACT_TYPE(GVirConfigDomainGraphicsListen, gvir_config_domain_graphics_listen, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_domain_graphics_listen_class_init(GVirConfigDomainGraphicsListenClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainGraphicsListenPrivate)); +} + + +static void gvir_config_domain_graphics_listen_init(GVirConfigDomainGraphicsListen *listen) +{ + listen->priv = GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_GET_PRIVATE(listen); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h new file mode 100644 index 0000000..6f93d27 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h @@ -0,0 +1,65 @@ +/* + * libvirt-gconfig-domain-graphics-listen.h: libvirt domain graphics listen base class + * + * Copyright (C) 2016 Red Hat, Inc. + * Copyright (C) 2016 Visarion Alexandru <viorel.visarion@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Visarion Alexandru <viorel.visarion@gmail.com> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_LISTEN_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_LISTEN_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN (gvir_config_domain_graphics_listen_get_type ()) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN, GVirConfigDomainGraphicsListen)) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN, GVirConfigDomainGraphicsListenClass)) +#define GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN)) +#define GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN)) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN, GVirConfigDomainGraphicsListenClass)) + +typedef struct _GVirConfigDomainGraphicsListen GVirConfigDomainGraphicsListen; +typedef struct _GVirConfigDomainGraphicsListenPrivate GVirConfigDomainGraphicsListenPrivate; +typedef struct _GVirConfigDomainGraphicsListenClass GVirConfigDomainGraphicsListenClass; + +struct _GVirConfigDomainGraphicsListen +{ + GVirConfigObject parent; + + GVirConfigDomainGraphicsListenPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainGraphicsListenClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_domain_graphics_listen_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_LISTEN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 6462154..496986e 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -63,6 +63,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-filesys.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 4ef4bf7..32d2c7b 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -741,6 +741,7 @@ global: gvir_config_domain_address_pci_get_multifunction; gvir_config_domain_address_pci_get_slot;
+ gvir_config_domain_graphics_listen_get_type; gvir_config_domain_graphics_spice_set_gl;
gvir_config_domain_hostdev_get_boot_order; -- 2.7.4
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

From: Visarion Alexandru <viorel.visarion@gmail.com> This is needed to be able to change the address a graphics device is listening for. --- libvirt-gconfig/Makefile.am | 2 + ...ibvirt-gconfig-domain-graphics-listen-address.c | 128 +++++++++++++++++++++ ...ibvirt-gconfig-domain-graphics-listen-address.h | 78 +++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 7 ++ 5 files changed, 216 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 09739c5..5e66c4a 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -47,6 +47,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics.h \ libvirt-gconfig-domain-graphics-desktop.h \ libvirt-gconfig-domain-graphics-listen.h\ + libvirt-gconfig-domain-graphics-listen-address.h\ libvirt-gconfig-domain-graphics-rdp.h \ libvirt-gconfig-domain-graphics-sdl.h \ libvirt-gconfig-domain-graphics-spice.h \ @@ -141,6 +142,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics.c \ libvirt-gconfig-domain-graphics-desktop.c \ libvirt-gconfig-domain-graphics-listen.c\ + libvirt-gconfig-domain-graphics-listen-address.c\ libvirt-gconfig-domain-graphics-rdp.c \ libvirt-gconfig-domain-graphics-sdl.c \ libvirt-gconfig-domain-graphics-spice.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.c new file mode 100644 index 0000000..74815a8 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.c @@ -0,0 +1,128 @@ +/* + * libvirt-gconfig-domain-graphics-listen-address.c: libvirt domain graphics listen address configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * Copyright (C) 2016 Visarion Alexandru <viorel.visarion@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Visarion Alexandru <viorel.visarion@gmail.com> + */ + +#include <config.h> + +#include <gio/gio.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_ADDRESS_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS, GVirConfigDomainGraphicsListenAddressPrivate)) + +struct _GVirConfigDomainGraphicsListenAddressPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainGraphicsListenAddress, gvir_config_domain_graphics_listen_address, GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN); + + +static void gvir_config_domain_graphics_listen_address_class_init(GVirConfigDomainGraphicsListenAddressClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainGraphicsListenAddressPrivate)); +} + + +static void gvir_config_domain_graphics_listen_address_init(GVirConfigDomainGraphicsListenAddress *address) +{ + address->priv = GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_ADDRESS_GET_PRIVATE(address); +} + + +GVirConfigDomainGraphicsListenAddress *gvir_config_domain_graphics_listen_address_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS, "listen", NULL); + gvir_config_object_set_attribute(object, + "type", "address", + NULL); + + return GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_ADDRESS(object); +} + + +GVirConfigDomainGraphicsListenAddress *gvir_config_domain_graphics_listen_address_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS, + "listen", NULL, xml, error); + if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "address") != 0) { + g_object_unref(G_OBJECT(object)); + g_return_val_if_reached(NULL); + } + return GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_ADDRESS(object); +} + +void gvir_config_domain_graphics_listen_address_set_address(GVirConfigDomainGraphicsListenAddress *listen, + const gchar *address) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_ADDRESS(listen)); + + gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(listen), + "address", address, + NULL); +} + +const gchar * +gvir_config_domain_graphics_listen_address_get_address(GVirConfigDomainGraphicsListenAddress *listen) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_ADDRESS(listen), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(listen), + NULL, + "address"); +} + +void gvir_config_domain_graphics_listen_address_set_inet_address(GVirConfigDomainGraphicsListenAddress *listen, + GInetAddress *address) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_ADDRESS(listen)); + + gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(listen), + "address", g_inet_address_to_string (address), + NULL); +} + +/** + * gvir_config_domain_graphics_listen_address_get_inet_address: + * + * Returns the #GInetAddress associated with the #GVirConfigDomainGraphicsListenAddress. + * + * Returns: (transfer full): a #GInetAddress. + * + */ +GInetAddress * +gvir_config_domain_graphics_listen_address_get_inet_address(GVirConfigDomainGraphicsListenAddress *listen) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_ADDRESS(listen), NULL); + + const gchar *address = gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(listen), + NULL, + "address"); + return g_inet_address_new_from_string(address); +} \ No newline at end of file diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.h b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.h new file mode 100644 index 0000000..1178b9f --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.h @@ -0,0 +1,78 @@ +/* + * libvirt-gconfig-domain-graphics-listen-address.h: libvirt domain graphics listen address configuration + * + * Copyright (C) 2016 Red Hat, Inc. + * Copyright (C) 2016 Visarion Alexandru <viorel.visarion@gmail.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Author: Visarion Alexandru <viorel.visarion@gmail.com> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_LISTEN_ADDRESS_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_LISTEN_ADDRESS_H__ + +#include <gio/gio.h> + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS (gvir_config_domain_graphics_listen_address_get_type ()) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_ADDRESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS, GVirConfigDomainGraphicsListenAddress)) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_ADDRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS, GVirConfigDomainGraphicsListenAddressClass)) +#define GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_ADDRESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS)) +#define GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_ADDRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS)) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_LISTEN_ADDRESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS, GVirConfigDomainGraphicsListenAddressClass)) + +typedef struct _GVirConfigDomainGraphicsListenAddress GVirConfigDomainGraphicsListenAddress; +typedef struct _GVirConfigDomainGraphicsListenAddressPrivate GVirConfigDomainGraphicsListenAddressPrivate; +typedef struct _GVirConfigDomainGraphicsListenAddressClass GVirConfigDomainGraphicsListenAddressClass; + +struct _GVirConfigDomainGraphicsListenAddress +{ + GVirConfigDomainGraphicsListen parent; + + GVirConfigDomainGraphicsListenAddressPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainGraphicsListenAddressClass +{ + GVirConfigDomainGraphicsListenClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_domain_graphics_listen_address_get_type(void); + +GVirConfigDomainGraphicsListenAddress *gvir_config_domain_graphics_listen_address_new(void); +GVirConfigDomainGraphicsListenAddress *gvir_config_domain_graphics_listen_address_new_from_xml(const gchar *xml, + GError **error); + +void gvir_config_domain_graphics_listen_address_set_address(GVirConfigDomainGraphicsListenAddress *listen, + const gchar *address); +const gchar *gvir_config_domain_graphics_listen_address_get_address(GVirConfigDomainGraphicsListenAddress *listen); + +void gvir_config_domain_graphics_listen_address_set_inet_address(GVirConfigDomainGraphicsListenAddress *listen, + GInetAddress *address); +GInetAddress *gvir_config_domain_graphics_listen_address_get_inet_address(GVirConfigDomainGraphicsListenAddress *listen); +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_LISTEN_ADDRESS_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 496986e..6132bc1 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -64,6 +64,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-graphics.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-listen.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-rdp.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-sdl.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 32d2c7b..364d8ff 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -741,6 +741,13 @@ global: gvir_config_domain_address_pci_get_multifunction; gvir_config_domain_address_pci_get_slot; + gvir_config_domain_graphics_listen_address_get_address; + gvir_config_domain_graphics_listen_address_get_inet_address; + gvir_config_domain_graphics_listen_address_get_type; + gvir_config_domain_graphics_listen_address_new; + gvir_config_domain_graphics_listen_address_new_from_xml; + gvir_config_domain_graphics_listen_address_set_address; + gvir_config_domain_graphics_listen_address_set_inet_address; gvir_config_domain_graphics_listen_get_type; gvir_config_domain_graphics_spice_set_gl; -- 2.7.4

On Wed, Aug 17, 2016 at 06:58:48PM +0300, Visarion Alexandru wrote:
From: Visarion Alexandru <viorel.visarion@gmail.com>
This is needed to be able to change the address a graphics device is listening for. --- libvirt-gconfig/Makefile.am | 2 + ...ibvirt-gconfig-domain-graphics-listen-address.c | 128 +++++++++++++++++++++ ...ibvirt-gconfig-domain-graphics-listen-address.h | 78 +++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 7 ++ 5 files changed, 216 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 09739c5..5e66c4a 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -47,6 +47,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-graphics.h \ libvirt-gconfig-domain-graphics-desktop.h \ libvirt-gconfig-domain-graphics-listen.h\ + libvirt-gconfig-domain-graphics-listen-address.h\ libvirt-gconfig-domain-graphics-rdp.h \ libvirt-gconfig-domain-graphics-sdl.h \ libvirt-gconfig-domain-graphics-spice.h \ @@ -141,6 +142,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-graphics.c \ libvirt-gconfig-domain-graphics-desktop.c \ libvirt-gconfig-domain-graphics-listen.c\ + libvirt-gconfig-domain-graphics-listen-address.c\ libvirt-gconfig-domain-graphics-rdp.c \ libvirt-gconfig-domain-graphics-sdl.c \ libvirt-gconfig-domain-graphics-spice.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.c new file mode 100644 index 0000000..74815a8 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-listen-address.c + +void gvir_config_domain_graphics_listen_address_set_address(GVirConfigDomainGraphicsListenAddress *listen, + const gchar *address) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_ADDRESS(listen)); + + gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(listen), + "address", address, + NULL); +} + +const gchar * +gvir_config_domain_graphics_listen_address_get_address(GVirConfigDomainGraphicsListenAddress *listen) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_ADDRESS(listen), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(listen), + NULL, + "address"); +} + +void gvir_config_domain_graphics_listen_address_set_inet_address(GVirConfigDomainGraphicsListenAddress *listen, + GInetAddress *address) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN_ADDRESS(listen)); + + gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(listen), + "address", g_inet_address_to_string (address), + NULL);
You need to g_free() the string returned by g_inet_address_new_from_string() after using it or you will have a memory leak. Fixed locally too, so no need to resend. Acked-by: Christophe Fergeau <cfergeau@redhat.com> Christophe

From: Visarion Alexandru <viorel.visarion@gmail.com> 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

On Wed, Aug 17, 2016 at 06:58:49PM +0300, Visarion Alexandru wrote:
From: Visarion Alexandru <viorel.visarion@gmail.com>
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)
Patch is good overall, but the naming needs improving, these <listen> nodes are not devices. I'm not exactly sure how to name the API though. _set_listen_nodes() is the only thing which comes to mind, and I don't think it's great. Another options would be just _set_listens(), but that's odd too. Any better suggestion? Apart from this naming issue (which has to be fixed before pushing), Acked-by: Christophe Fergeau <cfergeau@redhat.com> Christophe

Hi! Sorry for the delay, I had some exams. _set_listen_list () is the only other name that comes into my mind. I also think _set_listens () is a bit odd, but _set_listen_nodes () doesn't sound that odd to me (maybe a bit too technical). I think you should choose the name from those 3, because you have more experience, and I'll update and upload the remaining two patches right away. All the best, Alex On Fri, Sep 2, 2016 at 5:17 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Wed, Aug 17, 2016 at 06:58:49PM +0300, Visarion Alexandru wrote:
From: Visarion Alexandru <viorel.visarion@gmail.com>
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)
Patch is good overall, but the naming needs improving, these <listen> nodes are not devices. I'm not exactly sure how to name the API though. _set_listen_nodes() is the only thing which comes to mind, and I don't think it's great. Another options would be just _set_listens(), but that's odd too. Any better suggestion?
Apart from this naming issue (which has to be fixed before pushing),
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
Christophe
-- Visarion-Mingopol Alexandru-Viorel Telefon : 0729614060 Best Bucuresti

Hey, On Mon, Sep 12, 2016 at 01:10:28AM +0300, Visarion-Mingopol Alexandru-Viorel wrote:
Hi! Sorry for the delay, I had some exams.
_set_listen_list () is the only other name that comes into my mind.
I also think _set_listens () is a bit odd, but _set_listen_nodes () doesn't sound that odd to me (maybe a bit too technical).
I don't think we really expose anything called 'node' in libvirt-gconfig API. We don't say we are using it to add nodes to VM or things like that. So this does not sound like a very good name to have in the API. Lately, I'd favour _set_listen(s) unless someone has a strong objection/a better name.
I think you should choose the name from those 3, because you have more experience, and I'll update and upload the remaining two patches right away.
I have already did the update/rebasing work in https://gitlab.com/teuf/libvirt-glib/commits/graphics , so no updates should be needed :) I've added on top of your series patches Fidencio sent a while ago. Need to send that to the ML next ;) Christophe

From: Visarion Alexandru <viorel.visarion@gmail.com> Learn to get/set the listen devices that spice graphics is using. When setting the listen devices, first remove the 'listen' attribute to avoid the inconsistencies checks between the 'listen' attribute and the 'address' attribute of the 'listen' node. --- .../libvirt-gconfig-domain-graphics-spice.c | 84 ++++++++++++++++++++++ .../libvirt-gconfig-domain-graphics-spice.h | 4 ++ libvirt-gconfig/libvirt-gconfig.sym | 2 + 3 files changed, 90 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c index 079ea27..133eb1f 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c @@ -157,6 +157,90 @@ void gvir_config_domain_graphics_spice_set_image_compression compression); } +/** + * gvir_config_domain_graphics_spice_set_listen_devices: + * @graphics: a #GVirConfigDomainGraphicsSpice + * @listens: (in) (element-type LibvirtGConfig.DomainGraphicsListen): listens + * + * This method is used to set the various listen nodes a #GVirConfigDomainGraphicsSpice + * device can handle. +*/ +void gvir_config_domain_graphics_spice_set_listen_devices(GVirConfigDomainGraphicsSpice *graphics, + GList *listens) +{ + GList *it; + + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_SPICE(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_spice_get_listen_devices: + * + * Gets all the listen not of #GVirConfigDomainGraphicsSpice + * + * Returns: (element-type LibvirtGConfig.DomainGraphicsListen) (transfer full): + * a newly allocated #GList of #GVirConfigDomainGraphicsListen. + */ +GList * +gvir_config_domain_graphics_spice_get_listen_devices(GVirConfigDomainGraphicsSpice *graphics) +{ + struct ListenData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_SPICE(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_spice_set_gl(GVirConfigDomainGraphicsSpice *graphics, gboolean gl) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h index 25c132e..faf3c7a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h @@ -95,6 +95,10 @@ gvir_config_domain_graphics_spice_get_image_compression void gvir_config_domain_graphics_spice_set_gl(GVirConfigDomainGraphicsSpice *graphics, gboolean gl); +void gvir_config_domain_graphics_spice_set_listen_devices(GVirConfigDomainGraphicsSpice *graphics, + GList *listens); +GList *gvir_config_domain_graphics_spice_get_listen_devices(GVirConfigDomainGraphicsSpice *graphics); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_SPICE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index e30ad04..e4f50de 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -749,7 +749,9 @@ global: gvir_config_domain_graphics_listen_address_set_address; gvir_config_domain_graphics_listen_address_set_inet_address; gvir_config_domain_graphics_listen_get_type; + gvir_config_domain_graphics_spice_get_listen_devices; gvir_config_domain_graphics_spice_set_gl; + gvir_config_domain_graphics_spice_set_listen_devices; gvir_config_domain_graphics_vnc_get_listen_devices; gvir_config_domain_graphics_vnc_set_listen_devices; -- 2.7.4

On Wed, Aug 17, 2016 at 06:58:50PM +0300, Visarion Alexandru wrote:
From: Visarion Alexandru <viorel.visarion@gmail.com>
Learn to get/set the listen devices that spice graphics is using.
When setting the listen devices, first remove the 'listen' attribute to avoid the inconsistencies checks between the 'listen' attribute and the 'address' attribute of the 'listen' node. --- .../libvirt-gconfig-domain-graphics-spice.c | 84 ++++++++++++++++++++++ .../libvirt-gconfig-domain-graphics-spice.h | 4 ++ libvirt-gconfig/libvirt-gconfig.sym | 2 + 3 files changed, 90 insertions(+)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c index 079ea27..133eb1f 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c @@ -157,6 +157,90 @@ void gvir_config_domain_graphics_spice_set_image_compression compression); }
+/** + * gvir_config_domain_graphics_spice_set_listen_devices: + * @graphics: a #GVirConfigDomainGraphicsSpice + * @listens: (in) (element-type LibvirtGConfig.DomainGraphicsListen): listens + * + * This method is used to set the various listen nodes a #GVirConfigDomainGraphicsSpice + * device can handle. +*/ +void gvir_config_domain_graphics_spice_set_listen_devices(GVirConfigDomainGraphicsSpice *graphics, + GList *listens)
Same comment as in the previous patch regarding the naming. Christophe

From: Visarion Alexandru <viorel.visarion@gmail.com> --- tests/test-gconfig.c | 36 ++++++++++++++++++++++ .../xml/gconfig-domain-device-graphics-listen.xml | 7 +++++ 2 files changed, 43 insertions(+) create mode 100644 tests/xml/gconfig-domain-device-graphics-listen.xml diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index a26bb5f..28565e3 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -481,6 +481,40 @@ static void test_domain_device_graphics(void) g_object_unref(G_OBJECT(domain)); } +static void test_domain_device_graphics_listen(void) +{ + GVirConfigDomain *domain; + GVirConfigDomainGraphicsSpice *graphics = NULL; + + domain = gvir_config_domain_new(); + GList *listen_list = NULL; + + graphics = gvir_config_domain_graphics_spice_new(); + + /* listen address node */ + GVirConfigDomainGraphicsListenAddress *address_listen = gvir_config_domain_graphics_listen_address_new(); + GInetAddress *inet_address = g_inet_address_new_from_string("0.0.0.0"); + + gvir_config_domain_graphics_listen_address_set_inet_address(address_listen, inet_address); + GInetAddress *ret_inet_address = gvir_config_domain_graphics_listen_address_get_inet_address(address_listen); + g_assert_cmpstr(g_inet_address_to_string(inet_address), ==, g_inet_address_to_string(ret_inet_address)); + + gvir_config_domain_graphics_listen_address_set_address(address_listen, "127.0.0.1"); + const gchar *ret_address = gvir_config_domain_graphics_listen_address_get_address(address_listen); + g_assert_cmpstr("127.0.0.1", ==, ret_address); + + /* test listen setter */ + listen_list = g_list_append(listen_list, address_listen); + gvir_config_domain_graphics_spice_set_listen_devices(graphics, listen_list); + g_object_unref(G_OBJECT(address_listen)); + + gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(graphics)); + g_object_unref(G_OBJECT(graphics)); + + check_xml(domain, "gconfig-domain-device-graphics-listen.xml"); + + g_object_unref(G_OBJECT(domain)); +} static void test_domain_device_video(void) { @@ -782,6 +816,8 @@ int main(int argc, char **argv) test_domain_device_usb_redir); g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev", test_domain_device_pci_hostdev); + g_test_add_func("/libvirt-gconfig/domain-device-graphics-listen", + test_domain_device_graphics_listen); return g_test_run(); } diff --git a/tests/xml/gconfig-domain-device-graphics-listen.xml b/tests/xml/gconfig-domain-device-graphics-listen.xml new file mode 100644 index 0000000..27200c4 --- /dev/null +++ b/tests/xml/gconfig-domain-device-graphics-listen.xml @@ -0,0 +1,7 @@ +<domain> + <devices> + <graphics type="spice"> + <listen type="address" address="127.0.0.1"/> + </graphics> + </devices> +</domain> -- 2.7.4

On Wed, Aug 17, 2016 at 06:58:51PM +0300, Visarion Alexandru wrote:
From: Visarion Alexandru <viorel.visarion@gmail.com>
--- tests/test-gconfig.c | 36 ++++++++++++++++++++++ .../xml/gconfig-domain-device-graphics-listen.xml | 7 +++++ 2 files changed, 43 insertions(+) create mode 100644 tests/xml/gconfig-domain-device-graphics-listen.xml
diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index a26bb5f..28565e3 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -481,6 +481,40 @@ static void test_domain_device_graphics(void) g_object_unref(G_OBJECT(domain)); }
+static void test_domain_device_graphics_listen(void) +{ + GVirConfigDomain *domain; + GVirConfigDomainGraphicsSpice *graphics = NULL; + + domain = gvir_config_domain_new(); + GList *listen_list = NULL; + + graphics = gvir_config_domain_graphics_spice_new(); + + /* listen address node */ + GVirConfigDomainGraphicsListenAddress *address_listen = gvir_config_domain_graphics_listen_address_new(); + GInetAddress *inet_address = g_inet_address_new_from_string("0.0.0.0");
This needs to be g_object_unref'ed() when no longer needed
+ + gvir_config_domain_graphics_listen_address_set_inet_address(address_listen, inet_address); + GInetAddress *ret_inet_address = gvir_config_domain_graphics_listen_address_get_inet_address(address_listen);
This too needs g_object_unref()
+ g_assert_cmpstr(g_inet_address_to_string(inet_address), ==, g_inet_address_to_string(ret_inet_address));
Better to use g_inet_address_equal() here, as otherwise you need to make sure you free the strings returned by g_inet_address_to_string(). It's better if the test case is leak-free so that it's easier to detect leaks in newly added code. And if people use it as a base for their code, better if the code is not too bad.
+ + gvir_config_domain_graphics_listen_address_set_address(address_listen, "127.0.0.1"); + const gchar *ret_address = gvir_config_domain_graphics_listen_address_get_address(address_listen); + g_assert_cmpstr("127.0.0.1", ==, ret_address); + + /* test listen setter */ + listen_list = g_list_append(listen_list, address_listen);
You are missing a g_list_free() when you no longer need this
+ gvir_config_domain_graphics_spice_set_listen_devices(graphics, listen_list); + g_object_unref(G_OBJECT(address_listen)); + + gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(graphics)); + g_object_unref(G_OBJECT(graphics));
I've fixed all this locally, so no need to resend a fixed version. Christophe
participants (3)
-
Christophe Fergeau
-
Visarion Alexandru
-
Visarion-Mingopol Alexandru-Viorel