[Spice-commits] 6 commits - configure.ac gtk/channel-main.c gtk/channel-smartcard.c gtk/smartcard-manager.c gtk/spice-channel.c gtk/spice-session.c

Marc-André Lureau elmarco at kemper.freedesktop.org
Wed Feb 27 09:45:14 PST 2013


 configure.ac            |    2 +-
 gtk/channel-main.c      |    7 ++++---
 gtk/channel-smartcard.c |    9 ++-------
 gtk/smartcard-manager.c |   34 +++++++++++++++++++++-------------
 gtk/spice-channel.c     |    1 +
 gtk/spice-session.c     |   16 ++++++++++++----
 6 files changed, 41 insertions(+), 28 deletions(-)

New commits:
commit 736a2298b0c281e5f7bd19e5f0e833707675032a
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Tue Feb 26 01:10:59 2013 +0100

    smartcard: do not register monitor before smartcard init
    
    Never call vevent_get_next_vevent() before calling vcard_emul_init()
    
    Some mutexes are initialized in vevent_queue_init(), during emul_init()

diff --git a/gtk/smartcard-manager.c b/gtk/smartcard-manager.c
index dbb121f..51f228a 100644
--- a/gtk/smartcard-manager.c
+++ b/gtk/smartcard-manager.c
@@ -94,8 +94,6 @@ static guint signals[SPICE_SMARTCARD_MANAGER_LAST_SIGNAL];
 
 #ifdef USE_SMARTCARD
 typedef gboolean (*SmartcardSourceFunc)(VEvent *event, gpointer user_data);
-static guint smartcard_monitor_add(SmartcardSourceFunc callback,
-                                   gpointer user_data);
 static gboolean smartcard_monitor_dispatch(VEvent *event, gpointer user_data);
 #endif
 
@@ -107,10 +105,6 @@ static void spice_smartcard_manager_init(SpiceSmartcardManager *smartcard_manage
 
     priv = SPICE_SMARTCARD_MANAGER_GET_PRIVATE(smartcard_manager);
     smartcard_manager->priv = priv;
-#ifdef USE_SMARTCARD
-    priv->monitor_id = smartcard_monitor_add(smartcard_monitor_dispatch,
-                                             smartcard_manager);
-#endif
 }
 
 static void spice_smartcard_manager_dispose(GObject *gobject)
@@ -394,6 +388,18 @@ static guint smartcard_monitor_add(SmartcardSourceFunc callback,
     return id;
 }
 
+static void
+spice_smartcard_manager_update_monitor(void)
+{
+    SpiceSmartcardManager *self = spice_smartcard_manager_get();
+    SpiceSmartcardManagerPrivate *priv = self->priv;
+
+    if (priv->monitor_id != 0)
+        return;
+
+    priv->monitor_id = smartcard_monitor_add(smartcard_monitor_dispatch, self);
+}
+
 #define SPICE_SOFTWARE_READER_NAME "Spice Software Smartcard"
 
 /**
@@ -524,6 +530,8 @@ gboolean spice_smartcard_manager_init_finish(SpiceSession *session,
     if (g_simple_async_result_propagate_error(simple, err))
         return FALSE;
 
+    spice_smartcard_manager_update_monitor();
+
     return TRUE;
 }
 
commit 5b9351666c97610d45133f019eaff9c5140efc47
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Tue Feb 26 01:14:36 2013 +0100

    smartcard: trivial cleanup

diff --git a/configure.ac b/configure.ac
index f02552f..ae83f9d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -327,7 +327,7 @@ AC_CHECK_LIB(z, deflate, Z_LIBS='-lz', AC_MSG_ERROR([zlib not found]))
 AC_SUBST(Z_LIBS)
 
 AC_ARG_ENABLE([smartcard],
-  AS_HELP_STRING([--enable-smartcard=@<:@yes/no@:>@],
+  AS_HELP_STRING([--enable-smartcard=@<:@auto/yes/no@:>@],
                  [Enable smartcard support @<:@default=auto@:>@]),
   [],
   [enable_smartcard="auto"])
diff --git a/gtk/channel-smartcard.c b/gtk/channel-smartcard.c
index cbddc1c..21b8343 100644
--- a/gtk/channel-smartcard.c
+++ b/gtk/channel-smartcard.c
@@ -482,15 +482,10 @@ static void spice_smartcard_channel_up_cb(GObject *source_object,
 
 static void spice_smartcard_channel_up(SpiceChannel *channel)
 {
-    SpiceSession *session;
-    GCancellable *cancellable = g_cancellable_new();
-
-    g_object_get(channel, "spice-session", &session, NULL);
-    spice_smartcard_manager_init_async(session,
-                                       cancellable,
+    spice_smartcard_manager_init_async(spice_channel_get_session(channel),
+                                       g_cancellable_new(),
                                        spice_smartcard_channel_up_cb,
                                        channel);
-    g_object_unref(session);
 }
 
 static void handle_smartcard_msg(SpiceChannel *channel, SpiceMsgIn *in)
diff --git a/gtk/smartcard-manager.c b/gtk/smartcard-manager.c
index ab3229f..dbb121f 100644
--- a/gtk/smartcard-manager.c
+++ b/gtk/smartcard-manager.c
@@ -512,17 +512,17 @@ gboolean spice_smartcard_manager_init_finish(SpiceSession *session,
                                              GAsyncResult *result,
                                              GError **err)
 {
+    GSimpleAsyncResult *simple;
+
     g_return_val_if_fail(SPICE_IS_SESSION(session), FALSE);
-    g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
+    g_return_val_if_fail(G_IS_SIMPLE_ASYNC_RESULT(result), FALSE);
 
     SPICE_DEBUG("smartcard_manager_finish");
 
-    if (G_IS_SIMPLE_ASYNC_RESULT(result)) {
-        GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(result);
-        g_warn_if_fail(g_simple_async_result_get_source_tag(simple) == spice_smartcard_manager_init);
-        if (g_simple_async_result_propagate_error(simple, err))
-            return FALSE;
-    }
+    simple = G_SIMPLE_ASYNC_RESULT(result);
+    g_return_val_if_fail(g_simple_async_result_get_source_tag(simple) == spice_smartcard_manager_init, FALSE);
+    if (g_simple_async_result_propagate_error(simple, err))
+        return FALSE;
 
     return TRUE;
 }
commit 0502f09d16733c4e0d30e5d3882fceead0a68d73
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Wed Feb 20 17:58:23 2013 +0100

    session: warn on invalid port value

diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index ccc9367..0f33ba7 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -1745,15 +1745,23 @@ GSocket* spice_session_channel_open_host(SpiceSession *session, SpiceChannel *ch
 {
     SpiceSessionPrivate *s = SPICE_SESSION_GET_PRIVATE(session);
     spice_open_host open_host = { 0, };
-
-    if ((use_tls && !s->tls_port) || (!use_tls && !s->port))
-        return NULL;
+    gchar *port, *endptr;
 
     // FIXME: make open_host() cancellable
     open_host.from = coroutine_self();
     open_host.session = session;
     open_host.channel = channel;
-    open_host.port = atoi(use_tls ? s->tls_port : s->port);
+    port = use_tls ? s->tls_port : s->port;
+    if (port == NULL)
+        return NULL;
+
+    open_host.port = strtol(port, &endptr, 10);
+    if (*port == '\0' || *endptr != '\0' ||
+        open_host.port <= 0 || open_host.port > G_MAXUINT16) {
+        g_warning("Invalid port value %s", port);
+        return NULL;
+    }
+
     open_host.client = g_socket_client_new();
 
     guint id = g_idle_add(open_host_idle_cb, &open_host);
commit 28fe77944bc6c4944de2ff5e9b05129e12944d08
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Wed Feb 20 17:31:12 2013 +0100

    channel: swap tls status during seamless migration
    
    In some cases, source and destinations may have different channel
    encryption. We need to swap tls state too during seamless migration.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=855870

diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index 2c559b7..ce19634 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -2684,6 +2684,7 @@ void spice_channel_swap(SpiceChannel *channel, SpiceChannel *swap, gboolean swap
     SWAP(ctx);
     SWAP(ssl);
     SWAP(sslverify);
+    SWAP(tls);
     SWAP(use_mini_header);
     if (swap_msgs) {
         SWAP(xmit_queue);
commit a2e377f464da2c8b5ecf9355faeb30d621fde20e
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Tue Feb 19 16:33:01 2013 +0100

    main: use stable comparison function for monitors
    
    If monitors are equal, compare them by their addresses, to get the
    effect of a stable sort.

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index fe57684..f86e81d 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -973,8 +973,9 @@ static int monitors_cmp(const void *p1, const void *p2, gpointer user_data)
     const VDAgentMonConfig *m2 = p2;
     double d1 = sqrt(m1->x * m1->x + m1->y * m1->y);
     double d2 = sqrt(m2->x * m2->x + m2->y * m2->y);
+    int diff = d1 - d2;
 
-    return d1 - d2;
+    return diff == 0 ? (char*)p1 - (char*)p2 : diff;
 }
 
 static void monitors_align(VDAgentMonConfig *monitors, int nmonitors)
commit 67c558c0d596d51b45a2383ec17759df408f381d
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Tue Feb 19 16:14:27 2013 +0100

    main: use glib sort
    
    Use glib sort for monitors. This allows to share the same
    implementation and behaviour on various platforms.

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index 40d27cc..fe57684 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -967,7 +967,7 @@ static void agent_msg_queue_many(SpiceMainChannel *channel, int type, const void
     g_warn_if_fail(out == NULL);
 }
 
-static int monitors_cmp(const void *p1, const void *p2)
+static int monitors_cmp(const void *p1, const void *p2, gpointer user_data)
 {
     const VDAgentMonConfig *m1 = p1;
     const VDAgentMonConfig *m2 = p2;
@@ -988,7 +988,7 @@ static void monitors_align(VDAgentMonConfig *monitors, int nmonitors)
 
     /* sort by distance from origin */
     sorted_monitors = g_memdup(monitors, nmonitors * sizeof(VDAgentMonConfig));
-    qsort(sorted_monitors, nmonitors, sizeof(VDAgentMonConfig), monitors_cmp);
+    g_qsort_with_data(sorted_monitors, nmonitors, sizeof(VDAgentMonConfig), monitors_cmp, NULL);
 
     /* super-KISS ltr alignment, feel free to improve */
     for (i = 0; i < nmonitors; i++) {


More information about the Spice-commits mailing list