Blame SOURCES/0017-channel-add-spice_channel_get_error.patch

dfc2f2
From ba6fe1ef7076e4e6ec6c945aeca63f1092011281 Mon Sep 17 00:00:00 2001
dfc2f2
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
dfc2f2
Date: Mon, 3 Feb 2014 15:47:11 +0100
dfc2f2
Subject: [PATCH] channel: add spice_channel_get_error()
dfc2f2
dfc2f2
Add a function to retrieve the last GError from a channel, this may be
dfc2f2
useful to provide additional error details to the client.
dfc2f2
dfc2f2
Conflicts:
dfc2f2
	gtk/spice-session.c
dfc2f2
---
dfc2f2
 doc/reference/spice-gtk-sections.txt |  1 +
dfc2f2
 gtk/map-file                         |  1 +
dfc2f2
 gtk/spice-channel-priv.h             |  1 +
dfc2f2
 gtk/spice-channel.c                  | 30 +++++++++++++++++++++++++++---
dfc2f2
 gtk/spice-channel.h                  |  2 ++
dfc2f2
 gtk/spice-glib-sym-file              |  1 +
dfc2f2
 gtk/spice-session-priv.h             |  2 +-
dfc2f2
 gtk/spice-session.c                  |  6 +++---
dfc2f2
 gtk/spicy.c                          |  6 ++++++
dfc2f2
 9 files changed, 43 insertions(+), 7 deletions(-)
dfc2f2
dfc2f2
diff --git a/doc/reference/spice-gtk-sections.txt b/doc/reference/spice-gtk-sections.txt
dfc2f2
index 8d61aa9..1aebe58 100644
dfc2f2
--- a/doc/reference/spice-gtk-sections.txt
dfc2f2
+++ b/doc/reference/spice-gtk-sections.txt
dfc2f2
@@ -102,6 +102,7 @@ spice_channel_string_to_type
dfc2f2
 spice_channel_set_capability
dfc2f2
 spice_channel_flush_async
dfc2f2
 spice_channel_flush_finish
dfc2f2
+spice_channel_get_error
dfc2f2
 <SUBSECTION Standard>
dfc2f2
 SPICE_TYPE_CHANNEL_EVENT
dfc2f2
 spice_channel_event_get_type
dfc2f2
diff --git a/gtk/map-file b/gtk/map-file
dfc2f2
index 368b44f..399fa62 100644
dfc2f2
--- a/gtk/map-file
dfc2f2
+++ b/gtk/map-file
dfc2f2
@@ -7,6 +7,7 @@ spice_channel_connect;
dfc2f2
 spice_channel_destroy;
dfc2f2
 spice_channel_disconnect;
dfc2f2
 spice_channel_event_get_type;
dfc2f2
+spice_channel_get_error;
dfc2f2
 spice_channel_get_type;
dfc2f2
 spice_channel_new;
dfc2f2
 spice_channel_open_fd;
dfc2f2
diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
dfc2f2
index 0816061..fef58bf 100644
dfc2f2
--- a/gtk/spice-channel-priv.h
dfc2f2
+++ b/gtk/spice-channel-priv.h
dfc2f2
@@ -134,6 +134,7 @@ struct _SpiceChannelPrivate {
dfc2f2
     GSList                      *flushing;
dfc2f2
 
dfc2f2
     gboolean                    disable_channel_msg;
dfc2f2
+    GError                      *error;
dfc2f2
 };
dfc2f2
 
dfc2f2
 SpiceMsgIn *spice_msg_in_new(SpiceChannel *channel);
dfc2f2
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
dfc2f2
index 9a2b5b4..1a92669 100644
dfc2f2
--- a/gtk/spice-channel.c
dfc2f2
+++ b/gtk/spice-channel.c
dfc2f2
@@ -154,6 +154,8 @@ static void spice_channel_dispose(GObject *gobject)
dfc2f2
          c->session = NULL;
dfc2f2
     }
dfc2f2
 
dfc2f2
+    g_clear_error(&c->error);
dfc2f2
+
dfc2f2
     /* Chain up to the parent class */
dfc2f2
     if (G_OBJECT_CLASS(spice_channel_parent_class)->dispose)
dfc2f2
         G_OBJECT_CLASS(spice_channel_parent_class)->dispose(gobject);
dfc2f2
@@ -317,7 +319,9 @@ static void spice_channel_class_init(SpiceChannelClass *klass)
dfc2f2
      * @event: a #SpiceChannelEvent
dfc2f2
      *
dfc2f2
      * The #SpiceChannel::channel-event signal is emitted when the
dfc2f2
-     * state of the connection change.
dfc2f2
+     * state of the connection is changed. In case of errors,
dfc2f2
+     * spice_channel_get_error() may provide additional informations
dfc2f2
+     * on the source of the error.
dfc2f2
      **/
dfc2f2
     signals[SPICE_CHANNEL_EVENT] =
dfc2f2
         g_signal_new("channel-event",
dfc2f2
@@ -2206,6 +2210,25 @@ static int spice_channel_load_ca(SpiceChannel *channel)
dfc2f2
     return count;
dfc2f2
 }
dfc2f2
 
dfc2f2
+/**
dfc2f2
+ * spice_channel_get_error:
dfc2f2
+ * @channel:
dfc2f2
+ *
dfc2f2
+ * Retrieves the #GError currently set on channel, if the #SpiceChannel
dfc2f2
+ * is in error state and can provide additional error details.
dfc2f2
+ *
dfc2f2
+ * Returns: the pointer to the error, or %NULL
dfc2f2
+ * Since: 0.24
dfc2f2
+ **/
dfc2f2
+const GError* spice_channel_get_error(SpiceChannel *self)
dfc2f2
+{
dfc2f2
+    SpiceChannelPrivate *c;
dfc2f2
+
dfc2f2
+    g_return_val_if_fail(SPICE_IS_CHANNEL(self), NULL);
dfc2f2
+    c = self->priv;
dfc2f2
+
dfc2f2
+    return c->error;
dfc2f2
+}
dfc2f2
 
dfc2f2
 /* coroutine context */
dfc2f2
 static void *spice_channel_coroutine(void *data)
dfc2f2
@@ -2241,15 +2264,16 @@ static void *spice_channel_coroutine(void *data)
dfc2f2
     }
dfc2f2
 
dfc2f2
 reconnect:
dfc2f2
-    c->conn = spice_session_channel_open_host(c->session, channel, &c->tls);
dfc2f2
+    c->conn = spice_session_channel_open_host(c->session, channel, &c->tls, &c->error);
dfc2f2
     if (c->conn == NULL) {
dfc2f2
-        if (!c->tls) {
dfc2f2
+        if (!c->error && !c->tls) {
dfc2f2
             CHANNEL_DEBUG(channel, "trying with TLS port");
dfc2f2
             c->tls = true; /* FIXME: does that really work with provided fd */
dfc2f2
             goto reconnect;
dfc2f2
         } else {
dfc2f2
             CHANNEL_DEBUG(channel, "Connect error");
dfc2f2
             emit_main_context(channel, SPICE_CHANNEL_EVENT, SPICE_CHANNEL_ERROR_CONNECT);
dfc2f2
+            g_clear_error(&c->error);
dfc2f2
             goto cleanup;
dfc2f2
         }
dfc2f2
     }
dfc2f2
diff --git a/gtk/spice-channel.h b/gtk/spice-channel.h
dfc2f2
index 705dddf..1c303b4 100644
dfc2f2
--- a/gtk/spice-channel.h
dfc2f2
+++ b/gtk/spice-channel.h
dfc2f2
@@ -123,6 +123,8 @@ void spice_channel_set_capability(SpiceChannel *channel, guint32 cap);
dfc2f2
 const gchar* spice_channel_type_to_string(gint type);
dfc2f2
 gint spice_channel_string_to_type(const gchar *str);
dfc2f2
 
dfc2f2
+const GError* spice_channel_get_error(SpiceChannel *channel);
dfc2f2
+
dfc2f2
 G_END_DECLS
dfc2f2
 
dfc2f2
 #endif /* __SPICE_CLIENT_CHANNEL_H__ */
dfc2f2
diff --git a/gtk/spice-glib-sym-file b/gtk/spice-glib-sym-file
dfc2f2
index 4fc8643..d48ef7f 100644
dfc2f2
--- a/gtk/spice-glib-sym-file
dfc2f2
+++ b/gtk/spice-glib-sym-file
dfc2f2
@@ -7,6 +7,7 @@ spice_channel_disconnect
dfc2f2
 spice_channel_event_get_type
dfc2f2
 spice_channel_flush_async
dfc2f2
 spice_channel_flush_finish
dfc2f2
+spice_channel_get_error
dfc2f2
 spice_channel_get_type
dfc2f2
 spice_channel_new
dfc2f2
 spice_channel_open_fd
dfc2f2
diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
dfc2f2
index 55fee47..d127f16 100644
dfc2f2
--- a/gtk/spice-session-priv.h
dfc2f2
+++ b/gtk/spice-session-priv.h
dfc2f2
@@ -117,7 +117,7 @@ int spice_session_get_connection_id(SpiceSession *session);
dfc2f2
 gboolean spice_session_get_client_provided_socket(SpiceSession *session);
dfc2f2
 
dfc2f2
 GSocketConnection* spice_session_channel_open_host(SpiceSession *session, SpiceChannel *channel,
dfc2f2
-                                                   gboolean *use_tls);
dfc2f2
+                                                   gboolean *use_tls, GError **error);
dfc2f2
 void spice_session_channel_new(SpiceSession *session, SpiceChannel *channel);
dfc2f2
 void spice_session_channel_destroy(SpiceSession *session, SpiceChannel *channel);
dfc2f2
 void spice_session_channel_migrate(SpiceSession *session, SpiceChannel *channel);
dfc2f2
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
dfc2f2
index b4675d8..4032ebe 100644
dfc2f2
--- a/gtk/spice-session.c
dfc2f2
+++ b/gtk/spice-session.c
dfc2f2
@@ -1806,7 +1806,7 @@ static gboolean connect_timeout(gpointer data)
dfc2f2
 /* coroutine context */
dfc2f2
 G_GNUC_INTERNAL
dfc2f2
 GSocketConnection* spice_session_channel_open_host(SpiceSession *session, SpiceChannel *channel,
dfc2f2
-                                                   gboolean *use_tls)
dfc2f2
+                                                   gboolean *use_tls, GError **error)
dfc2f2
 {
dfc2f2
     SpiceSessionPrivate *s = session->priv;
dfc2f2
     SpiceChannelPrivate *c = channel->priv;
dfc2f2
@@ -1855,8 +1855,8 @@ GSocketConnection* spice_session_channel_open_host(SpiceSession *session, SpiceC
dfc2f2
 #endif
dfc2f2
 
dfc2f2
     if (open_host.error != NULL) {
dfc2f2
-        g_warning("%s", open_host.error->message);
dfc2f2
-        g_clear_error(&open_host.error);
dfc2f2
+        SPICE_DEBUG("open host: %s", open_host.error->message);
dfc2f2
+        g_propagate_error(error, open_host.error);
dfc2f2
     } else if (open_host.connection != NULL) {
dfc2f2
         GSocket *socket;
dfc2f2
         socket = g_socket_connection_get_socket(open_host.connection);
dfc2f2
diff --git a/gtk/spicy.c b/gtk/spicy.c
dfc2f2
index 916d5d0..0da0bb8 100644
dfc2f2
--- a/gtk/spicy.c
dfc2f2
+++ b/gtk/spicy.c
dfc2f2
@@ -1208,6 +1208,7 @@ static void recent_add(SpiceSession *session)
dfc2f2
 static void main_channel_event(SpiceChannel *channel, SpiceChannelEvent event,
dfc2f2
                                gpointer data)
dfc2f2
 {
dfc2f2
+    const GError *error = NULL;
dfc2f2
     spice_connection *conn = data;
dfc2f2
     char password[64];
dfc2f2
     int rc;
dfc2f2
@@ -1231,7 +1232,12 @@ static void main_channel_event(SpiceChannel *channel, SpiceChannelEvent event,
dfc2f2
     case SPICE_CHANNEL_ERROR_TLS:
dfc2f2
     case SPICE_CHANNEL_ERROR_LINK:
dfc2f2
     case SPICE_CHANNEL_ERROR_CONNECT:
dfc2f2
+        error = spice_channel_get_error(channel);
dfc2f2
         g_message("main channel: failed to connect");
dfc2f2
+        if (error) {
dfc2f2
+            g_message("channel error: %s", error->message);
dfc2f2
+        }
dfc2f2
+
dfc2f2
         rc = connect_dialog(conn->session);
dfc2f2
         if (rc == 0) {
dfc2f2
             connection_connect(conn);
dfc2f2
-- 
dfc2f2
1.9.3
dfc2f2