[Spice-commits] 2 commits - gtk/spice-proxy.c gtk/spice-proxy.h gtk/spice-session.c gtk/spice-session-priv.h

Marc-André Lureau elmarco at kemper.freedesktop.org
Tue Jan 29 05:38:13 PST 2013


 gtk/spice-proxy.c        |   13 ++++++++
 gtk/spice-proxy.h        |    1 
 gtk/spice-session-priv.h |    2 +
 gtk/spice-session.c      |   76 +++++++++++++++++++++++++++++++++++------------
 4 files changed, 73 insertions(+), 19 deletions(-)

New commits:
commit 5ad2fa098be217a19844a504236053ad107372e1
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Mon Jan 28 21:12:10 2013 +0100

    Add SpiceSession:proxy
    
    Add a session property to set proxy setting, since it is racy to rely
    on setenv(). Also doing so would override system environment, which
    will modify other session too sharing the same process.

diff --git a/gtk/spice-proxy.c b/gtk/spice-proxy.c
index 97c3a6b..581f030 100644
--- a/gtk/spice-proxy.c
+++ b/gtk/spice-proxy.c
@@ -234,3 +234,16 @@ static void spice_proxy_class_init(SpiceProxyClass *klass)
                                                        G_PARAM_STATIC_STRINGS |
                                                        G_PARAM_READWRITE));
 }
+
+gchar* spice_proxy_to_string(SpiceProxy* self)
+{
+    SpiceProxyPrivate *p;
+
+    g_return_val_if_fail(SPICE_IS_PROXY(self), NULL);
+    p = self->priv;
+
+    if (p->protocol == NULL || p->hostname == NULL)
+        return NULL;
+
+    return g_strdup_printf("%s://%s:%u", p->protocol, p->hostname, p->port);
+}
diff --git a/gtk/spice-proxy.h b/gtk/spice-proxy.h
index c780931..1e7b6d7 100644
--- a/gtk/spice-proxy.h
+++ b/gtk/spice-proxy.h
@@ -53,6 +53,7 @@ const gchar* spice_proxy_get_hostname(SpiceProxy* self);
 void spice_proxy_set_hostname(SpiceProxy* self, const gchar* value);
 guint spice_proxy_get_port(SpiceProxy* self);
 void spice_proxy_set_port(SpiceProxy* self, guint port);
+gchar *spice_proxy_to_string(SpiceProxy* self);
 
 G_END_DECLS
 
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index 5beb6a1..299bebc 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -106,6 +106,7 @@ enum {
     PROP_UUID,
     PROP_NAME,
     PROP_CA,
+    PROP_PROXY
 };
 
 /* signals */
@@ -118,24 +119,29 @@ enum {
 static guint signals[SPICE_SESSION_LAST_SIGNAL];
 
 
-static SpiceProxy* get_proxy(void)
+static void update_proxy(SpiceSession *self, const gchar *str)
 {
+    SpiceSessionPrivate *s = self->priv;
+    SpiceProxy *proxy = NULL;
     GError *error = NULL;
-    SpiceProxy *proxy;
 
-    const gchar *proxy_env = g_getenv("SPICE_PROXY");
-    if (proxy_env == NULL || strlen(proxy_env) == 0)
-        return NULL;
+    if (str == NULL)
+        str = g_getenv("SPICE_PROXY");
+    if (str == NULL || *str == 0)
+        return;
 
     proxy = spice_proxy_new();
-    if (!spice_proxy_parse(proxy, proxy_env, &error))
+    if (!spice_proxy_parse(proxy, str, &error))
         g_clear_object(&proxy);
     if (error) {
         g_warning ("%s", error->message);
         g_clear_error (&error);
     }
 
-    return proxy;
+    if (proxy != NULL) {
+        g_clear_object(&s->proxy);
+        s->proxy = proxy;
+    }
 }
 
 static void spice_session_init(SpiceSession *session)
@@ -167,7 +173,7 @@ static void spice_session_init(SpiceSession *session)
     cache_init(&s->images, "image");
     cache_init(&s->palettes, "palette");
     s->glz_window = glz_decoder_window_new();
-    s->proxy = get_proxy();
+    update_proxy(session, NULL);
 }
 
 static void
@@ -513,6 +519,9 @@ static void spice_session_get_property(GObject    *gobject,
     case PROP_UUID:
         g_value_set_pointer(value, s->uuid);
 	break;
+    case PROP_PROXY:
+        g_value_take_string(value, spice_proxy_to_string(s->proxy));
+	break;
     default:
 	G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
 	break;
@@ -628,6 +637,9 @@ static void spice_session_set_property(GObject      *gobject,
         g_clear_pointer(&s->ca, g_byte_array_unref);
         s->ca = g_value_dup_boxed(value);
         break;
+    case PROP_PROXY:
+        update_proxy(session, g_value_get_string(value));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
         break;
@@ -1119,6 +1131,23 @@ static void spice_session_class_init(SpiceSessionClass *klass)
                               G_PARAM_READABLE |
                               G_PARAM_STATIC_STRINGS));
 
+    /**
+     * SpiceSession:proxy:
+     *
+     * URI to the proxy server to use when doing network connection.
+     * of the form <![CDATA[ [protocol://]<host>[:port] ]]>
+     *
+     * Since: 0.17
+     **/
+    g_object_class_install_property
+        (gobject_class, PROP_PROXY,
+         g_param_spec_string("proxy",
+                             "Proxy",
+                             "The proxy server",
+                             NULL,
+                             G_PARAM_READWRITE |
+                             G_PARAM_STATIC_STRINGS));
+
     g_type_class_add_private(klass, sizeof(SpiceSessionPrivate));
 }
 
@@ -1698,8 +1727,11 @@ static gboolean open_host_idle_cb(gpointer data)
                                       g_network_address_new(s->host, open_host->port));
 
     SPICE_DEBUG("open host %s:%d", s->host, open_host->port);
-    if (open_host->proxy != NULL)
-        SPICE_DEBUG("(with proxy %p)", open_host->proxy);
+    if (open_host->proxy != NULL) {
+        gchar *str = spice_proxy_to_string(open_host->proxy);
+        SPICE_DEBUG("(with proxy %s)", str);
+        g_free(str);
+    }
 
     return FALSE;
 }
commit 3129d5f2648d39f3e70fd65a964e672733038484
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Wed Jan 23 19:26:11 2013 +0100

    proxy: initialize proxy at session construct time

diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index 804658d..7ee6b6c 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -22,6 +22,7 @@
 #include <gio/gio.h>
 #include "desktop-integration.h"
 #include "spice-session.h"
+#include "spice-proxy.h"
 #include "spice-gtk-session.h"
 #include "spice-channel-cache.h"
 #include "decode.h"
@@ -44,6 +45,7 @@ struct _SpiceSessionPrivate {
     char              *cert_subject;
     guint             verify;
     gboolean          read_only;
+    SpiceProxy        *proxy;
 
     /* whether to enable audio */
     gboolean          audio;
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index 0e405bc..5beb6a1 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -118,6 +118,26 @@ enum {
 static guint signals[SPICE_SESSION_LAST_SIGNAL];
 
 
+static SpiceProxy* get_proxy(void)
+{
+    GError *error = NULL;
+    SpiceProxy *proxy;
+
+    const gchar *proxy_env = g_getenv("SPICE_PROXY");
+    if (proxy_env == NULL || strlen(proxy_env) == 0)
+        return NULL;
+
+    proxy = spice_proxy_new();
+    if (!spice_proxy_parse(proxy, proxy_env, &error))
+        g_clear_object(&proxy);
+    if (error) {
+        g_warning ("%s", error->message);
+        g_clear_error (&error);
+    }
+
+    return proxy;
+}
+
 static void spice_session_init(SpiceSession *session)
 {
     SpiceSessionPrivate *s;
@@ -147,6 +167,7 @@ static void spice_session_init(SpiceSession *session)
     cache_init(&s->images, "image");
     cache_init(&s->palettes, "palette");
     s->glz_window = glz_decoder_window_new();
+    s->proxy = get_proxy();
 }
 
 static void
@@ -179,6 +200,7 @@ spice_session_dispose(GObject *gobject)
     g_clear_object(&s->desktop_integration);
     g_clear_object(&s->gtk_session);
     g_clear_object(&s->usb_manager);
+    g_clear_object(&s->proxy);
 
     /* Chain up to the parent class */
     if (G_OBJECT_CLASS(spice_session_parent_class)->dispose)
@@ -1647,21 +1669,6 @@ static void proxy_lookup_ready(GObject *source_object, GAsyncResult *result,
     open_host_connectable_connect(open_host, G_SOCKET_CONNECTABLE(address));
     g_resolver_free_addresses(addresses);
 }
-
-static SpiceProxy* get_proxy(GError **error)
-{
-    SpiceProxy *proxy;
-
-    const gchar *proxy_env = g_getenv("SPICE_PROXY");
-    if (proxy_env == NULL || strlen(proxy_env) == 0)
-        return NULL;
-
-    proxy = spice_proxy_new();
-    if (!spice_proxy_parse(proxy, proxy_env, error))
-        g_clear_object(&proxy);
-
-    return proxy;
-}
 #endif
 
 /* main context */
@@ -1674,7 +1681,7 @@ static gboolean open_host_idle_cb(gpointer data)
     g_return_val_if_fail(open_host->socket == NULL, FALSE);
 
 #if GLIB_CHECK_VERSION(2,26,0)
-    open_host->proxy = get_proxy(&open_host->error);
+    open_host->proxy = s->proxy;
     if (open_host->error != NULL) {
         coroutine_yieldto(open_host->from, NULL);
         return FALSE;
@@ -1729,7 +1736,6 @@ GSocket* spice_session_channel_open_host(SpiceSession *session, SpiceChannel *ch
     }
 
     g_clear_object(&open_host.client);
-    g_clear_object(&open_host.proxy);
     return open_host.socket;
 }
 


More information about the Spice-commits mailing list