[telepathy-gabble/master] change fallback-socks5-proxy to fallback-socks5-proxies

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Wed Mar 25 04:56:45 PDT 2009


By using an 'as' we can define more than one fallback proxy
---
 src/bytestream-factory.c                    |   17 ++++++++----
 src/connection-manager.c                    |   24 +++++++++---------
 src/connection.c                            |   24 +++++++++---------
 tests/twisted/test-fallback-socks5-proxy.py |   35 +++++++++++++++++----------
 4 files changed, 57 insertions(+), 43 deletions(-)

diff --git a/src/bytestream-factory.c b/src/bytestream-factory.c
index b6f5f38..9fb33ee 100644
--- a/src/bytestream-factory.c
+++ b/src/bytestream-factory.c
@@ -159,7 +159,7 @@ struct _GabbleBytestreamFactoryPrivate
 
   /* List of GabbleSocks5Proxy discovered on the connection */
   GSList *socks5_proxies;
-  /* List of GabbleSocks5Proxy found using the fallback-socks5-proxy param */
+  /* List of GabbleSocks5Proxy found using the fallback-socks5-proxies param */
   GSList *socks5_fallback_proxies;
 
   gboolean dispose_has_run;
@@ -304,14 +304,19 @@ conn_status_changed_cb (GabbleConnection *conn,
   if (status == TP_CONNECTION_STATUS_CONNECTED)
     {
       /* Send SOCKS5 query to fallback SOCKS5 proxy if any */
-      gchar *jid;
+      GStrv jids;
+      guint i;
 
-      g_object_get (priv->conn, "fallback-socks5-proxy", &jid, NULL);
-      if (jid == NULL)
+      g_object_get (priv->conn, "fallback-socks5-proxies", &jids, NULL);
+      if (jids == NULL)
         return;
 
-      send_proxy_query (self, jid, TRUE);
-      g_free (jid);
+      for (i = 0; jids[i] != NULL; i++)
+        {
+          send_proxy_query (self, jids[i], TRUE);
+        }
+
+      g_strfreev (jids);
     }
 }
 
diff --git a/src/connection-manager.c b/src/connection-manager.c
index 4231ad6..0336c23 100644
--- a/src/connection-manager.c
+++ b/src/connection-manager.c
@@ -80,7 +80,7 @@ struct _GabbleParams {
   guint fallback_stun_port;
   gboolean ignore_ssl_errors;
   gchar *alias;
-  gchar *fallback_socks5_proxy;
+  GStrv fallback_socks5_proxies;
 };
 
 enum {
@@ -103,11 +103,11 @@ enum {
     JABBER_PARAM_FALLBACK_STUN_PORT,
     JABBER_PARAM_IGNORE_SSL_ERRORS,
     JABBER_PARAM_ALIAS,
-    JABBER_PARAM_FALLBACK_SOCKS5_PROXY,
+    JABBER_PARAM_FALLBACK_SOCKS5_PROXIES,
     LAST_JABBER_PARAM
 };
 
-static const TpCMParamSpec jabber_params[] = {
+static TpCMParamSpec jabber_params[] = {
   { "account", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
     TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER, NULL,
     G_STRUCT_OFFSET(GabbleParams, account),
@@ -199,13 +199,10 @@ static const TpCMParamSpec jabber_params[] = {
     /* setting a 0-length alias makes no sense */
     tp_cm_param_filter_string_nonempty, NULL },
 
-  /* FIXME: we should have "fallback-socks5-proxies" but we currently can't
-   * define a boxed G_TYPE_STRV parameter */
-  { "fallback-socks5-proxy", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
+  { "fallback-socks5-proxies", "as", 0,
     0, NULL,
-    G_STRUCT_OFFSET (GabbleParams, fallback_socks5_proxy),
-    /* setting a 0-length proxy makes no sense */
-    tp_cm_param_filter_string_nonempty, NULL },
+    G_STRUCT_OFFSET (GabbleParams, fallback_socks5_proxies),
+    NULL, NULL },
 
   { NULL, NULL, 0, 0, NULL, 0 }
 };
@@ -229,7 +226,7 @@ free_params (void *p)
   g_free (params->fallback_conference_server);
   g_free (params->stun_server);
   g_free (params->alias);
-  g_free (params->fallback_socks5_proxy);
+  g_strfreev (params->fallback_socks5_proxies);
 
   g_slice_free (GabbleParams, params);
 }
@@ -242,9 +239,12 @@ const TpCMProtocolSpec gabble_protocols[] = {
 const TpCMProtocolSpec *
 gabble_connection_manager_get_protocols (void)
 {
+  jabber_params[JABBER_PARAM_FALLBACK_SOCKS5_PROXIES].gtype = G_TYPE_STRV;
+
   return gabble_protocols;
 }
 
+
 #define SET_PROPERTY_IF_PARAM_SET(prop, param, member) \
   if (tp_intset_is_member (params_present, param)) \
     { \
@@ -303,8 +303,8 @@ _gabble_connection_manager_new_connection (TpBaseConnectionManager *self,
                               JABBER_PARAM_IGNORE_SSL_ERRORS,
                               params->ignore_ssl_errors);
   SET_PROPERTY_IF_PARAM_SET ("alias", JABBER_PARAM_ALIAS, params->alias);
-  SET_PROPERTY_IF_PARAM_SET ("fallback-socks5-proxy",
-      JABBER_PARAM_FALLBACK_SOCKS5_PROXY, params->fallback_socks5_proxy);
+  SET_PROPERTY_IF_PARAM_SET ("fallback-socks5-proxies",
+      JABBER_PARAM_FALLBACK_SOCKS5_PROXIES, params->fallback_socks5_proxies);
 
   /* split up account into username, stream-server and resource */
   if (!_gabble_connection_set_properties_from_account (conn, params->account,
diff --git a/src/connection.c b/src/connection.c
index 73c7143..93274e0 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -138,7 +138,7 @@ enum
     PROP_FALLBACK_STUN_PORT,
     PROP_IGNORE_SSL_ERRORS,
     PROP_ALIAS,
-    PROP_FALLBACK_SOCKS5_PROXY,
+    PROP_FALLBACK_SOCKS5_PROXIES,
 
     LAST_PROPERTY
 };
@@ -178,7 +178,7 @@ struct _GabbleConnectionPrivate
 
   gchar *fallback_conference_server;
 
-  gchar *fallback_socks5_proxy;
+  GStrv fallback_socks5_proxies;
 
   /* authentication properties */
   gchar *stream_server;
@@ -385,8 +385,8 @@ gabble_connection_get_property (GObject    *object,
     case PROP_FALLBACK_STUN_PORT:
       g_value_set_uint (value, priv->fallback_stun_port);
       break;
-    case PROP_FALLBACK_SOCKS5_PROXY:
-      g_value_set_string (value, priv->fallback_socks5_proxy);
+    case PROP_FALLBACK_SOCKS5_PROXIES:
+      g_value_set_boxed (value, priv->fallback_socks5_proxies);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -474,8 +474,8 @@ gabble_connection_set_property (GObject      *object,
     case PROP_FALLBACK_STUN_PORT:
       priv->fallback_stun_port = g_value_get_uint (value);
       break;
-    case PROP_FALLBACK_SOCKS5_PROXY:
-      priv->fallback_socks5_proxy = g_value_dup_string (value);
+    case PROP_FALLBACK_SOCKS5_PROXIES:
+      priv->fallback_socks5_proxies = g_value_dup_boxed (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -752,11 +752,11 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class)
           NULL,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
-  g_object_class_install_property (object_class, PROP_FALLBACK_SOCKS5_PROXY,
-      g_param_spec_string (
-          "fallback-socks5-proxy", "fallback SOCKS5 proxy",
-          "Fallback SOCKS5 proxy.",
-          NULL,
+  g_object_class_install_property (object_class, PROP_FALLBACK_SOCKS5_PROXIES,
+      g_param_spec_boxed (
+          "fallback-socks5-proxies", "fallback SOCKS5 proxies",
+          "Fallback SOCKS5 proxies.",
+          G_TYPE_STRV,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   gabble_connection_class->properties_class.interfaces = prop_interfaces;
@@ -866,7 +866,7 @@ gabble_connection_finalize (GObject *object)
   g_free (priv->https_proxy_server);
   g_free (priv->stun_server);
   g_free (priv->fallback_conference_server);
-  g_free (priv->fallback_socks5_proxy);
+  g_strfreev (priv->fallback_socks5_proxies);
 
   g_free (priv->alias);
 
diff --git a/tests/twisted/test-fallback-socks5-proxy.py b/tests/twisted/test-fallback-socks5-proxy.py
index b46daa0..d0900a7 100644
--- a/tests/twisted/test-fallback-socks5-proxy.py
+++ b/tests/twisted/test-fallback-socks5-proxy.py
@@ -12,14 +12,25 @@ from bytestream import create_from_si_offer, BytestreamS5B
 def test(q, bus, conn, stream):
     conn.Connect()
 
-    _, e = q.expect_many(
+    _, e1, e2 = q.expect_many(
         EventPattern('dbus-signal', signal='StatusChanged', args=[0, 1]),
-        EventPattern('stream-iq', to='fallback-proxy.localhost', iq_type='get', query_ns=ns.BYTESTREAMS))
+        EventPattern('stream-iq', to='fallback1-proxy.localhost', iq_type='get', query_ns=ns.BYTESTREAMS),
+        EventPattern('stream-iq', to='fallback2-proxy.localhost', iq_type='get', query_ns=ns.BYTESTREAMS),
+        )
 
-    reply = elem_iq(stream, 'result', id=e.stanza['id'])(
-        elem(ns.BYTESTREAMS, 'query')(
-            elem('streamhost', jid='fallback-proxy.localhost', host='127.0.0.1', port='12345')()))
-    stream.send(reply)
+    proxy_port = {'fallback1-proxy.localhost': '12345', 'fallback2-proxy.localhost': '6789'}
+
+    def send_socks5_reply(iq):
+        jid = iq['to']
+        port = proxy_port[jid]
+
+        reply = elem_iq(stream, 'result', id=iq['id'])(
+            elem(ns.BYTESTREAMS, 'query')(
+                elem('streamhost', jid=jid, host='127.0.0.1', port=port)()))
+        stream.send(reply)
+
+    send_socks5_reply(e1.stanza)
+    send_socks5_reply(e2.stanza)
 
     # Offer a private D-Bus tube just to check if the proxy is present in the
     # SOCKS5 offer
@@ -61,17 +72,15 @@ def test(q, bus, conn, stream):
     found = False
     nodes = xpath.queryForNodes('/iq/query/streamhost', e.stanza)
     for node in nodes:
-        if node['jid'] == 'fallback-proxy.localhost':
-            found = True
+        if node['jid'] in proxy_port:
             assert node['host'] == '127.0.0.1'
-            assert node['port'] == '12345'
-            break
-    assert found
+            assert node['port'] == proxy_port.pop(node['jid'])
+    assert proxy_port == {}
 
     conn.Disconnect()
     q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
     return True
 
 if __name__ == '__main__':
-    exec_test(test, params={'fallback-socks5-proxy': 'fallback-proxy.localhost'})
-
+    exec_test(test, params={'fallback-socks5-proxies':
+        ['fallback1-proxy.localhost', 'fallback2-proxy.localhost']})
-- 
1.5.6.5




More information about the telepathy-commits mailing list