[Telepathy-commits] [telepathy-gabble/master] Add a hook for the regression tests to change the HTTP port

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Mar 3 10:26:16 PST 2009


The regression tests can't listen on port 80 (we don't want to run them
as root), so they need a way to feed in a port number.
---
 src/jingle-factory.c       |   28 +++++++++++++++++++++++++++-
 src/jingle-factory.h       |    2 ++
 tests/twisted/main-debug.c |    2 ++
 3 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/src/jingle-factory.c b/src/jingle-factory.c
index 8bed056..93c8387 100644
--- a/src/jingle-factory.c
+++ b/src/jingle-factory.c
@@ -76,6 +76,7 @@ struct _GabbleJingleFactoryPrivate
   gchar *relay_token;
   gboolean get_stun_from_jingle;
   gchar *relay_server;
+  guint16 relay_http_port;
   guint16 relay_udp;
   guint16 relay_tcp;
   guint16 relay_ssltcp;
@@ -98,6 +99,14 @@ static void connection_status_changed_cb (GabbleConnection *conn,
 
 #define RELAY_HTTP_TIMEOUT 5
 
+static gboolean test_mode = FALSE;
+
+void
+gabble_jingle_factory_set_test_mode (void)
+{
+  test_mode = TRUE;
+}
+
 static void
 gabble_jingle_factory_init (GabbleJingleFactory *obj)
 {
@@ -120,6 +129,7 @@ gabble_jingle_factory_init (GabbleJingleFactory *obj)
   priv->conn = NULL;
   priv->dispose_has_run = FALSE;
   priv->resolver = gibber_resolver_get_resolver ();
+  priv->relay_http_port = 80;
 }
 
 typedef struct {
@@ -330,6 +340,21 @@ jingle_info_cb (LmMessageHandler *handler,
               fac->priv->relay_server = g_strdup (server);
             }
 
+          if (test_mode)
+            {
+              /* this is not part of the real protocol, but we can't listen on
+               * port 80 in an unprivileged regression test */
+              port = lm_message_node_get_attribute (subnode,
+                  "gabble-test-http-port");
+
+              if (port != NULL)
+                {
+                  DEBUG ("jingle info: diverting 'Google' HTTP requests to "
+                      "port %s", port);
+                  fac->priv->relay_http_port = atoi (port);
+                }
+            }
+
           /* FIXME: these are not really actually used anywhere at
            * the moment, because we get the same info when creating
            * relay session. */
@@ -983,7 +1008,8 @@ gabble_jingle_factory_create_google_relay_session (
       g_object_set (priv->soup, "timeout", RELAY_HTTP_TIMEOUT, NULL);
     }
 
-  url = g_strdup_printf ("http://%s/create_session", fac->priv->relay_server);
+  url = g_strdup_printf ("http://%s:%d/create_session",
+      fac->priv->relay_server, fac->priv->relay_http_port);
   msg = soup_message_new ("GET", url);
 
   DEBUG ("Trying to create a new relay session on %s", url);
diff --git a/src/jingle-factory.h b/src/jingle-factory.h
index ca40e69..fecd44d 100644
--- a/src/jingle-factory.h
+++ b/src/jingle-factory.h
@@ -154,6 +154,8 @@ const gchar *gabble_jingle_factory_get_google_relay_token (
 gboolean gabble_jingle_factory_get_stun_server (GabbleJingleFactory *self,
     gchar **stun_server, guint *stun_port);
 
+void gabble_jingle_factory_set_test_mode (void);
+
 G_END_DECLS;
 
 #endif /* __JINGLE_FACTORY_H__ */
diff --git a/tests/twisted/main-debug.c b/tests/twisted/main-debug.c
index a9cf2ca..1df6019 100644
--- a/tests/twisted/main-debug.c
+++ b/tests/twisted/main-debug.c
@@ -19,6 +19,7 @@
 
 #include "gabble.h"
 #include "connection.h"
+#include "jingle-factory.h"
 
 #include <lib/gibber/gibber-resolver.h>
 
@@ -33,6 +34,7 @@ main (int argc,
 
   g_type_init ();
   gibber_resolver_set_resolver (GABBLE_TYPE_RESOLVER_FAKE);
+  gabble_jingle_factory_set_test_mode ();
 
   return gabble_main (argc, argv);
 }
-- 
1.5.6.5




More information about the telepathy-commits mailing list