[telepathy-gabble/master] Ignore port=5222 if we think we know better.

Will Thompson will.thompson at collabora.co.uk
Fri Jun 19 11:00:34 PDT 2009


Previously, if the UI sets port=5222 then Gabble disabled SRV lookups.
This turns out not to be great, because if the UI sets port=5222 (which
was not the default per Gabble's parameters, it is the spiritual XMPP
default port) then it can't connect to any XMPP server that uses an SRV
record.

While pedantically correct, the previous semantics turn out not to be
very helpful. We could go around fixing every account UI that ever gets
written, but ignoring 5222 if neither the connect server nor old-ssl
were set is more useful behaviour.
---
 src/connection-manager.c |    2 +-
 src/connection.c         |   23 +++++++++++++++--------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/connection-manager.c b/src/connection-manager.c
index cd11d73..5753b27 100644
--- a/src/connection-manager.c
+++ b/src/connection-manager.c
@@ -144,7 +144,7 @@ static TpCMParamSpec jabber_params[] = {
     G_STRUCT_OFFSET(GabbleParams, priority), NULL, NULL },
 
   { "port", DBUS_TYPE_UINT16_AS_STRING, G_TYPE_UINT,
-    0, GUINT_TO_POINTER(0),
+    TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(5222),
     G_STRUCT_OFFSET(GabbleParams, port),
     tp_cm_param_filter_uint_nonzero, NULL },
 
diff --git a/src/connection.c b/src/connection.c
index a3457fe..b2b51a9 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -348,6 +348,7 @@ gabble_connection_init (GabbleConnection *self)
   self->lmconn = lm_connection_new (NULL);
 
   priv->caps_serial = 1;
+  priv->port = 5222;
 }
 
 static void
@@ -664,7 +665,7 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class)
       g_param_spec_uint (
           "port", "Jabber server port",
           "The port used when establishing a connection.",
-          0, G_MAXUINT16, 0,
+          0, G_MAXUINT16, 5222,
           G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_property (object_class, PROP_OLD_SSL,
@@ -1339,8 +1340,16 @@ _gabble_connection_connect (TpBaseConnection *base,
   lm_connection_set_jid (conn->lmconn, jid);
   g_free (jid);
 
-  /* override server and port if either was provided */
-  if (priv->connect_server != NULL || priv->port != 0)
+  /* If the UI explicitly specified a port or a server, pass them to Loudmouth
+   * rather than letting it do an SRV lookup.
+   *
+   * If the port is 5222 (the default) then unless the UI also specified a
+   * server or old-style SSL, we ignore it and do an SRV lookup anyway. This
+   * means that UIs that blindly pass the default back to Gabble work
+   * correctly. If the user really did mean 5222, then when the SRV lookup
+   * fails we fall back to that anyway.
+   */
+  if (priv->port != 5222 || priv->connect_server != NULL || priv->old_ssl)
     {
       gchar *server;
 
@@ -1349,13 +1358,11 @@ _gabble_connection_connect (TpBaseConnection *base,
       else
         server = priv->stream_server;
 
-      DEBUG ("disabling SRV because \"server\" or \"port\" parameter "
-          "specified, will connect to %s", server);
+      DEBUG ("disabling SRV because \"server\" or \"old-ssl\" was specified "
+          "or port was not 5222, will connect to %s", server);
 
       lm_connection_set_server (conn->lmconn, server);
-
-      if (priv->port != 0)
-        lm_connection_set_port (conn->lmconn, priv->port);
+      lm_connection_set_port (conn->lmconn, priv->port);
     }
   else
     {
-- 
1.5.6.5




More information about the telepathy-commits mailing list