[telepathy-gabble/master] util.c: gabble_decode_jid use wocky_decode_jid directly

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Sep 11 07:56:21 PDT 2009


---
 src/util.c |  114 +----------------------------------------------------------
 1 files changed, 2 insertions(+), 112 deletions(-)

diff --git a/src/util.c b/src/util.c
index 7b8c592..92f7013 100644
--- a/src/util.c
+++ b/src/util.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <wocky/wocky-utils.h>
 #include <telepathy-glib/handle-repo-dynamic.h>
 
 #ifdef HAVE_UUID
@@ -364,39 +365,6 @@ lm_message_build_with_sub_type (const gchar *to, LmMessageType type,
   return msg;
 }
 
-static gboolean
-validate_jid_node (const gchar *node)
-{
-  /* See RFC 3920 §3.3. */
-  const gchar *c;
-
-  for (c = node; *c; c++)
-    if (strchr ("\"&'/:<>@", *c))
-      /* RFC 3920 §A.5 */
-      return FALSE;
-
-  return TRUE;
-}
-
-static gboolean
-validate_jid_domain (const gchar *domain)
-{
-  /* XXX: This doesn't do proper validation, it just checks the character
-   * range. In theory, we check that the domain is a well-formed IDN or
-   * an IPv4/IPv6 address literal.
-   *
-   * See RFC 3920 §3.2.
-   */
-
-  const gchar *c;
-
-  for (c = domain; *c; c++)
-    if (!g_ascii_isalnum (*c) && !strchr (":-.", *c))
-      return FALSE;
-
-  return TRUE;
-}
-
 /**
  * gabble_decode_jid
  *
@@ -423,85 +391,7 @@ gabble_decode_jid (const gchar *jid,
                    gchar **domain,
                    gchar **resource)
 {
-  char *tmp_jid, *tmp_node, *tmp_domain, *tmp_resource;
-
-  g_assert (jid != NULL);
-
-  if (node != NULL)
-    *node = NULL;
-
-  if (domain != NULL)
-    *domain = NULL;
-
-  if (resource != NULL)
-    *resource = NULL;
-
-  /* Take a local copy so we don't modify the caller's string. */
-  tmp_jid = g_strdup (jid);
-
-  /* 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_domain = '\0';
-      tmp_domain++;
-      tmp_node = tmp_jid;
-    }
-  else
-    {
-      tmp_domain = tmp_jid;
-      tmp_node = NULL;
-    }
-
-  /* Domain must be non-empty and not contain invalid characters. If the node
-   * or the resource exist, they must be non-empty and the node must not
-   * contain invalid characters.
-   */
-  if (*tmp_domain == '\0' ||
-      !validate_jid_domain (tmp_domain) ||
-      (tmp_node != NULL &&
-         (*tmp_node == '\0' || !validate_jid_node (tmp_node))) ||
-      (tmp_resource != NULL && *tmp_resource == '\0'))
-    {
-      g_free (tmp_jid);
-      return FALSE;
-    }
-
-  /* the server must be stored after we find the resource, in case we
-   * truncated a resource from it */
-  if (domain != NULL)
-    *domain = g_utf8_strdown (tmp_domain, -1);
-
-  /* store the username if the user provided a pointer */
-  if (tmp_node != NULL && node != NULL)
-    *node = g_utf8_strdown (tmp_node, -1);
-
-  /* store the resource if the user provided a pointer */
-  if (tmp_resource != NULL && resource != NULL)
-    *resource = g_strdup (tmp_resource);
-
-  /* free our working copy */
-  g_free (tmp_jid);
-  return TRUE;
+  return wocky_decode_jid (jid, node, domain, resource);
 }
 
 /**
-- 
1.5.6.5




More information about the telepathy-commits mailing list