[telepathy-gabble/telepathy-gabble-0.8] add gabble_encode_jid() and replace ad-hoc string concatentation with calls to it

Dafydd Harries dafydd.harries at collabora.co.uk
Wed Aug 26 09:48:36 PDT 2009


---
 src/connection.c |   10 ++++------
 src/util.c       |   26 ++++++++++++++++++++++++--
 src/util.h       |    2 ++
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index a76f1d4..95d084f 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -545,10 +545,8 @@ gabble_connection_get_unique_name (TpBaseConnection *self)
 {
   GabbleConnectionPrivate *priv = GABBLE_CONNECTION (self)->priv;
 
-  return g_strdup_printf ("%s@%s/%s",
-                          priv->username,
-                          priv->stream_server,
-                          priv->resource);
+  return gabble_encode_jid (
+      priv->username, priv->stream_server, priv->resource);
 }
 
 /* must be in the same order as GabbleListHandle in connection.h */
@@ -1341,7 +1339,7 @@ _gabble_connection_connect (TpBaseConnection *base,
   g_assert (priv->resource != NULL);
   g_assert (lm_connection_is_open (conn->lmconn) == FALSE);
 
-  jid = g_strdup_printf ("%s@%s", priv->username, priv->stream_server);
+  jid = gabble_encode_jid (priv->username, priv->stream_server, NULL);
   lm_connection_set_jid (conn->lmconn, jid);
   g_free (jid);
 
@@ -2899,7 +2897,7 @@ _gabble_connection_get_canonical_room_name (GabbleConnection *conn,
   if (server == NULL)
     return NULL;
 
-  return g_strdup_printf ("%s@%s", name, server);
+  return gabble_encode_jid (name, server, NULL);
 }
 
 
diff --git a/src/util.c b/src/util.c
index fdfd764..20803f8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -636,6 +636,28 @@ gabble_remove_resource (const gchar *jid)
 }
 
 gchar *
+gabble_encode_jid (
+    const gchar *node,
+    const gchar *domain,
+    const gchar *resource)
+{
+  gchar *tmp, *ret;
+
+  if (node != NULL && resource != NULL)
+    tmp = g_strdup_printf ("%s@%s/%s", node, domain, resource);
+  else if (node != NULL)
+    tmp = g_strdup_printf ("%s@%s", node, domain);
+  else if (resource != NULL)
+    tmp = g_strdup_printf ("%s/%s", domain, resource);
+  else
+    tmp = g_strdup (domain);
+
+  ret = g_utf8_normalize (tmp, -1, G_NORMALIZE_NFKC);
+  g_free (tmp);
+  return ret;
+}
+
+gchar *
 gabble_normalize_contact (TpHandleRepoIface *repo,
                           const gchar *jid,
                           gpointer context,
@@ -661,7 +683,7 @@ gabble_normalize_contact (TpHandleRepoIface *repo,
 
   if (mode != GABBLE_JID_GLOBAL && resource != NULL)
     {
-      ret = g_strdup_printf ("%s@%s/%s", username, server, resource);
+      ret = gabble_encode_jid (username, server, resource);
 
       if (mode == GABBLE_JID_ROOM_MEMBER
           || (repo != NULL
@@ -682,7 +704,7 @@ gabble_normalize_contact (TpHandleRepoIface *repo,
    * says it is, or because the context isn't sure and we haven't seen it in
    * use as a room member
    */
-  ret = g_strdup_printf ("%s@%s", username, server);
+  ret = gabble_encode_jid (username, server, NULL);
 
 OUT:
   g_free (username);
diff --git a/src/util.h b/src/util.h
index 1cf1ddf..fe1b5b6 100644
--- a/src/util.h
+++ b/src/util.h
@@ -63,6 +63,8 @@ G_GNUC_NULL_TERMINATED LmMessage * lm_message_build_with_sub_type (
 
 G_GNUC_WARN_UNUSED_RESULT
 gboolean gabble_decode_jid (const gchar *jid, gchar **a, gchar **b, gchar **c);
+gchar *gabble_encode_jid (const gchar *node, const gchar *domain,
+    const gchar *resource);
 
 gchar *gabble_remove_resource (const gchar *jid);
 gchar *gabble_normalize_contact (TpHandleRepoIface *repo, const gchar *jid,
-- 
1.5.6.5




More information about the telepathy-commits mailing list