[virt-tools-list] [PATCH] spice: add unix-path in .vv file support

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Fri Dec 21 11:27:59 UTC 2018


From: Marc-André Lureau <marcandre.lureau at redhat.com>

This will allow to connect to a Spice server using a unix socket path,
for example:

[virt-viewer]
type=spice
unix-path=/var/run/user/1000/qemu/test/spice.sock

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 man/remote-viewer.pod           |  8 +++++++-
 src/virt-viewer-file.c          | 21 +++++++++++++++++++++
 src/virt-viewer-file.h          |  2 ++
 src/virt-viewer-session-spice.c | 33 ++++++++++++++++++++-------------
 4 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/man/remote-viewer.pod b/man/remote-viewer.pod
index 4296fcc..2e596ce 100644
--- a/man/remote-viewer.pod
+++ b/man/remote-viewer.pod
@@ -161,7 +161,13 @@ fails.
 
 The session type, either "spice", "vnc" or "ovirt".
 
-=item C<host> (string, mandatory)
+=item C<unix-path> (string)
+
+The server to connect to, using a Unix socket path. (supported with spice, since 8.0)
+
+This option is incompatible with C<host>, C<port> and C<tls-port>.
+
+=item C<host> (string)
 
 The server host to connect to.
 
diff --git a/src/virt-viewer-file.c b/src/virt-viewer-file.c
index 1b0c310..d88f4f8 100644
--- a/src/virt-viewer-file.c
+++ b/src/virt-viewer-file.c
@@ -43,6 +43,7 @@
  * - newer-version-url: string specifying an URL to display when the minimum
  *   version check fails
  * - type: string, mandatory, values: "spice" (later "vnc" etc..)
+ * - unix-path: string
  * - host: string
  * - port: int
  * - tls-port: int
@@ -104,6 +105,7 @@ G_DEFINE_TYPE(VirtViewerFile, virt_viewer_file, G_TYPE_OBJECT);
 enum  {
     PROP_DUMMY_PROPERTY,
     PROP_TYPE,
+    PROP_UNIX_PATH,
     PROP_HOST,
     PROP_PORT,
     PROP_TLS_PORT,
@@ -326,6 +328,19 @@ virt_viewer_file_set_host(VirtViewerFile* self, const gchar* value)
     g_object_notify(G_OBJECT(self), "host");
 }
 
+gchar*
+virt_viewer_file_get_unix_path(VirtViewerFile* self)
+{
+    return virt_viewer_file_get_string(self, MAIN_GROUP, "unix-path");
+}
+
+void
+virt_viewer_file_set_unix_path(VirtViewerFile* self, const gchar* value)
+{
+    virt_viewer_file_set_string(self, MAIN_GROUP, "unix-path", value);
+    g_object_notify(G_OBJECT(self), "unix-path");
+}
+
 gchar*
 virt_viewer_file_get_file_type(VirtViewerFile* self)
 {
@@ -939,6 +954,9 @@ virt_viewer_file_set_property(GObject* object, guint property_id,
     case PROP_TYPE:
         virt_viewer_file_set_type(self, g_value_get_string(value));
         break;
+    case PROP_UNIX_PATH:
+        virt_viewer_file_set_unix_path(self, g_value_get_string(value));
+        break;
     case PROP_HOST:
         virt_viewer_file_set_host(self, g_value_get_string(value));
         break;
@@ -1054,6 +1072,9 @@ virt_viewer_file_get_property(GObject* object, guint property_id,
     case PROP_TYPE:
         g_value_take_string(value, virt_viewer_file_get_file_type(self));
         break;
+    case PROP_UNIX_PATH:
+        g_value_take_string(value, virt_viewer_file_get_unix_path(self));
+        break;
     case PROP_HOST:
         g_value_take_string(value, virt_viewer_file_get_host(self));
         break;
diff --git a/src/virt-viewer-file.h b/src/virt-viewer-file.h
index 15c61d0..108bcbf 100644
--- a/src/virt-viewer-file.h
+++ b/src/virt-viewer-file.h
@@ -54,6 +54,8 @@ VirtViewerFile* virt_viewer_file_new_from_buffer(const gchar* buf, gsize len,
                                                  GError** error);
 gboolean virt_viewer_file_is_set(VirtViewerFile* self, const gchar* key);
 
+gchar* virt_viewer_file_get_unix_path(VirtViewerFile* self);
+void virt_viewer_file_set_unix_path(VirtViewerFile* self, const gchar* value);
 gchar* virt_viewer_file_get_ca(VirtViewerFile* self);
 void virt_viewer_file_set_ca(VirtViewerFile* self, const gchar* value);
 gchar* virt_viewer_file_get_host(VirtViewerFile* self);
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index 8bb3bf9..c0c8d6c 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -511,21 +511,28 @@ fill_session(VirtViewerFile *file, SpiceSession *session)
     g_return_if_fail(VIRT_VIEWER_IS_FILE(file));
     g_return_if_fail(SPICE_IS_SESSION(session));
 
-    if (virt_viewer_file_is_set(file, "host")) {
-        gchar *val = virt_viewer_file_get_host(file);
-        g_object_set(G_OBJECT(session), "host", val, NULL);
+    if (virt_viewer_file_is_set(file, "unix-path")) {
+        gchar *val = virt_viewer_file_get_unix_path(file);
+        g_object_set(G_OBJECT(session), "unix-path", val, NULL);
         g_free(val);
-    }
+    } else {
+        if (virt_viewer_file_is_set(file, "host")) {
+            gchar *val = virt_viewer_file_get_host(file);
+            g_object_set(G_OBJECT(session), "host", val, NULL);
+            g_free(val);
+        }
 
-    if (virt_viewer_file_is_set(file, "port")) {
-        gchar *port = g_strdup_printf("%d", virt_viewer_file_get_port(file));
-        g_object_set(G_OBJECT(session), "port", port, NULL);
-        g_free(port);
-    }
-    if (virt_viewer_file_is_set(file, "tls-port")) {
-        gchar *tls_port = g_strdup_printf("%d", virt_viewer_file_get_tls_port(file));
-        g_object_set(G_OBJECT(session), "tls-port", tls_port, NULL);
-        g_free(tls_port);
+        if (virt_viewer_file_is_set(file, "port")) {
+            gchar *port = g_strdup_printf("%d", virt_viewer_file_get_port(file));
+            g_object_set(G_OBJECT(session), "port", port, NULL);
+            g_free(port);
+        }
+
+        if (virt_viewer_file_is_set(file, "tls-port")) {
+            gchar *tls_port = g_strdup_printf("%d", virt_viewer_file_get_tls_port(file));
+            g_object_set(G_OBJECT(session), "tls-port", tls_port, NULL);
+            g_free(tls_port);
+        }
     }
 
     if (virt_viewer_file_is_set(file, "username")) {
-- 
2.20.1.2.gb21ebb671b




More information about the virt-tools-list mailing list