[telepathy-gabble/master] gabble_jid_decode(): fix the case where there is a / before an @

Dafydd Harries dafydd.harries at collabora.co.uk
Tue Aug 25 12:19:28 PDT 2009


---
 src/util.c              |   39 +++++++++++++++++++++++----------------
 tests/test-jid-decode.c |    1 +
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/util.c b/src/util.c
index 97c651a..a670aac 100644
--- a/src/util.c
+++ b/src/util.c
@@ -471,33 +471,40 @@ gabble_decode_jid (const gchar *jid,
   if (resource != NULL)
     *resource = NULL;
 
-  /* take a local copy so we don't modify the caller's string */
+  /* Take a local copy so we don't modify the caller's string. */
   tmp_jid = g_strdup (jid);
 
-  /* find an @ in username, truncate username to that length, and point
-   * 'server' to the byte afterwards */
+  /* If there's a slash in tmp_jid, split it in two and take the second part as
+   * the resource.
+   */
+  tmp_resource = strchr (tmp_jid, '/');
+
+  if (tmp_resource)
+    {
+      *tmp_resource = '\0';
+      tmp_resource++;
+    }
+  else
+    {
+      tmp_resource = NULL;
+    }
+
+  /* If there's an at sign in tmp_jid, split it in two and set tmp_node and
+   * tmp_domain appropriately. Otherwise, tmp_node is NULL and the domain is
+   * the whole string.
+   */
   tmp_domain = strchr (tmp_jid, '@');
+
   if (tmp_domain)
     {
-      tmp_node = tmp_jid;
-
       *tmp_domain = '\0';
       tmp_domain++;
+      tmp_node = tmp_jid;
     }
   else
     {
-      tmp_node = NULL;
       tmp_domain = tmp_jid;
-    }
-
-  /* if we have a server, find a / in it, truncate it to that length, and point
-   * 'resource' to the byte afterwards. otherwise, do the same to username to
-   * find any resource there. */
-  tmp_resource = strchr (tmp_domain, '/');
-  if (tmp_resource)
-    {
-      *tmp_resource = '\0';
-      tmp_resource++;
+      tmp_node = NULL;
     }
 
   /* Domain must be non-empty. If the node or the resource exist, they must be
diff --git a/tests/test-jid-decode.c b/tests/test-jid-decode.c
index b72015c..4231029 100644
--- a/tests/test-jid-decode.c
+++ b/tests/test-jid-decode.c
@@ -50,6 +50,7 @@ main (void)
   test_pass ("Foo at Bar/Baz", "foo", "bar", "Baz");
   test_fail ("foo@@");
   test_fail ("foo&bar at baz");
+  test_pass ("foo/bar at baz", NULL, "foo", "bar at baz");
   test_pass ("foo at bar/foo at bar/foo at bar", "foo", "bar", "foo at bar/foo at bar");
 
   return 0;
-- 
1.5.6.5




More information about the telepathy-commits mailing list