[telepathy-gabble/master] store fallback proxies in a separated list so we can list them after the one discovered on the connection

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Apr 3 08:41:37 PDT 2009


---
 src/bytestream-factory.c |   48 +++++++++++++++++++++++++++++++++------------
 src/bytestream-factory.h |    2 +-
 src/bytestream-socks5.c  |   12 +++++-----
 3 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/src/bytestream-factory.c b/src/bytestream-factory.c
index 5094bdb..d839041 100644
--- a/src/bytestream-factory.c
+++ b/src/bytestream-factory.c
@@ -159,6 +159,8 @@ struct _GabbleBytestreamFactoryPrivate
 
   /* List of GabbleSocks5Proxy discovered on the connection */
   GSList *socks5_proxies;
+  /* List of GabbleSocks5Proxy found using the fallback-socks5-proxy param */
+  GSList *socks5_fallback_proxies;
 
   gboolean dispose_has_run;
 };
@@ -209,12 +211,13 @@ socks5_proxy_query_reply_cb (GabbleConnection *conn,
                              GObject *obj,
                              gpointer user_data)
 {
-  GabbleBytestreamFactory *self = GABBLE_BYTESTREAM_FACTORY (user_data);
+  GabbleBytestreamFactory *self = GABBLE_BYTESTREAM_FACTORY (obj);
   GabbleBytestreamFactoryPrivate *priv = GABBLE_BYTESTREAM_FACTORY_GET_PRIVATE (
       self);
   LmMessageNode *query, *streamhost;
   const gchar *jid, *host, *port;
   GabbleSocks5Proxy *proxy;
+  gboolean fallback = (gboolean) user_data;
 
   if (lm_message_get_sub_type (reply_msg) != LM_MESSAGE_SUB_TYPE_RESULT)
     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
@@ -235,17 +238,27 @@ socks5_proxy_query_reply_cb (GabbleConnection *conn,
   if (jid == NULL || host == NULL || port == NULL)
     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 
-  DEBUG ("Found SOCKS5 proxy: %s %s:%s", jid, host, port);
-
   proxy = gabble_socks5_proxy_new (jid, host, port);
-  priv->socks5_proxies = g_slist_prepend (priv->socks5_proxies, proxy);
+
+  if (fallback)
+    {
+      DEBUG ("Add fallback SOCKS5 proxy: %s %s:%s", jid, host, port);
+      priv->socks5_fallback_proxies = g_slist_prepend (priv->socks5_proxies,
+          proxy);
+    }
+  else
+    {
+      DEBUG ("Discovered SOCKS5 proxy: %s %s:%s", jid, host, port);
+      priv->socks5_proxies = g_slist_prepend (priv->socks5_proxies, proxy);
+    }
 
   return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 }
 
 static void
 send_proxy_query (GabbleBytestreamFactory *self,
-                  const gchar *jid)
+                  const gchar *jid,
+                  gboolean fallback)
 {
   GabbleBytestreamFactoryPrivate *priv = GABBLE_BYTESTREAM_FACTORY_GET_PRIVATE (
       self);
@@ -260,7 +273,7 @@ send_proxy_query (GabbleBytestreamFactory *self,
       ')', NULL);
 
   _gabble_connection_send_with_reply (priv->conn, query,
-      socks5_proxy_query_reply_cb, G_OBJECT (self), self, NULL);
+      socks5_proxy_query_reply_cb, G_OBJECT (self), (gpointer) fallback, NULL);
 
   lm_message_unref (query);
 }
@@ -274,7 +287,7 @@ disco_item_found_cb (GabbleDisco *disco,
       tp_strdiff (item->type, "bytestreams"))
     return;
 
-  send_proxy_query (self, item->jid);
+  send_proxy_query (self, item->jid, FALSE);
 }
 
 static void
@@ -296,7 +309,7 @@ conn_status_changed_cb (GabbleConnection *conn,
       if (jid == NULL)
         return;
 
-      send_proxy_query (self, jid);
+      send_proxy_query (self, jid, TRUE);
       g_free (jid);
     }
 }
@@ -352,7 +365,7 @@ gabble_bytestream_factory_dispose (GObject *object)
   GabbleBytestreamFactory *self = GABBLE_BYTESTREAM_FACTORY (object);
   GabbleBytestreamFactoryPrivate *priv =
     GABBLE_BYTESTREAM_FACTORY_GET_PRIVATE (self);
-  GSList *l;
+  GSList *proxies, *l;
 
   if (priv->dispose_has_run)
     return;
@@ -388,14 +401,19 @@ gabble_bytestream_factory_dispose (GObject *object)
   g_hash_table_destroy (priv->multiple_bytestreams);
   priv->multiple_bytestreams = NULL;
 
-  for (l = priv->socks5_proxies; l != NULL; l = g_slist_next (l))
+  proxies = g_slist_concat (priv->socks5_proxies,
+      priv->socks5_fallback_proxies);
+
+  for (l = proxies; l != NULL; l = g_slist_next (l))
     {
       GabbleSocks5Proxy *proxy = (GabbleSocks5Proxy *) l->data;
 
       gabble_socks5_proxy_free (proxy);
     }
-  g_slist_free (priv->socks5_proxies);
+  g_slist_free (proxies);
+
   priv->socks5_proxies = NULL;
+  priv->socks5_fallback_proxies = NULL;
 
   if (G_OBJECT_CLASS (gabble_bytestream_factory_parent_class)->dispose)
     G_OBJECT_CLASS (gabble_bytestream_factory_parent_class)->dispose (object);
@@ -1907,11 +1925,15 @@ gabble_bytestream_factory_make_multi_accept_iq (const gchar *full_jid,
   return msg;
 }
 
-const GSList *
+GSList *
 gabble_bytestream_factory_get_socks5_proxies (GabbleBytestreamFactory *self)
 {
   GabbleBytestreamFactoryPrivate *priv = GABBLE_BYTESTREAM_FACTORY_GET_PRIVATE (
       self);
 
-  return priv->socks5_proxies;
+  /* TODO: randomize priv->socks5_fallback_proxies once we can have more than
+   * one proxy in it */
+
+  return g_slist_concat (g_slist_copy (priv->socks5_proxies),
+      g_slist_copy (priv->socks5_fallback_proxies));
 }
diff --git a/src/bytestream-factory.h b/src/bytestream-factory.h
index 532a067..dcc58fc 100644
--- a/src/bytestream-factory.h
+++ b/src/bytestream-factory.h
@@ -106,7 +106,7 @@ gboolean gabble_bytestream_factory_negotiate_stream (
 
 gchar *gabble_bytestream_factory_generate_stream_id (void);
 
-const GSList *gabble_bytestream_factory_get_socks5_proxies (
+GSList *gabble_bytestream_factory_get_socks5_proxies (
     GabbleBytestreamFactory *self);
 
 G_END_DECLS
diff --git a/src/bytestream-socks5.c b/src/bytestream-socks5.c
index e7ae4f5..2f2f7a2 100644
--- a/src/bytestream-socks5.c
+++ b/src/bytestream-socks5.c
@@ -1515,14 +1515,13 @@ initiator_connected_to_proxy (GabbleBytestreamSocks5 *self)
 {
   GabbleBytestreamSocks5Private *priv = GABBLE_BYTESTREAM_SOCKS5_GET_PRIVATE (
       self);
-  const GSList *proxies;
-  GSList *l;
+  GSList *proxies, *l;
   GabbleSocks5Proxy *proxy = NULL;
   GibberTCPTransport *transport;
 
   proxies = gabble_bytestream_factory_get_socks5_proxies (
       priv->conn->bytestream_factory);
-  for (l = (GSList *) proxies; l != NULL; l = g_slist_next (l))
+  for (l = proxies; l != NULL; l = g_slist_next (l))
      {
        proxy = (GabbleSocks5Proxy *) l->data;
 
@@ -1531,6 +1530,7 @@ initiator_connected_to_proxy (GabbleBytestreamSocks5 *self)
 
        proxy = NULL;
      }
+  g_slist_free (proxies);
 
   if (proxy == NULL)
     {
@@ -1853,13 +1853,12 @@ gabble_bytestream_socks5_initiate (GabbleBytestreamIface *iface)
 
   if (!priv->muc_contact)
     {
-      const GSList *proxies;
-      GSList *l;
+      GSList *proxies, *l;
 
       proxies = gabble_bytestream_factory_get_socks5_proxies (
           priv->conn->bytestream_factory);
 
-      for (l = (GSList *) proxies; l != NULL; l = g_slist_next (l))
+      for (l = proxies; l != NULL; l = g_slist_next (l))
         {
           LmMessageNode *node;
           GabbleSocks5Proxy *proxy = (GabbleSocks5Proxy *) l->data;
@@ -1873,6 +1872,7 @@ gabble_bytestream_socks5_initiate (GabbleBytestreamIface *iface)
               "port", proxy->port,
               NULL);
         }
+      g_slist_free (proxies);
     }
   else
     {
-- 
1.5.6.5




More information about the telepathy-commits mailing list