diff src/protocols/jabber/jutil.c @ 7310:dd4b4a187171

[gaim-migrate @ 7894] assorted jabber tweaks committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 21 Oct 2003 17:18:46 +0000
parents 7c12dab8e513
children ab828b8c3f22
line wrap: on
line diff
--- a/src/protocols/jabber/jutil.c	Tue Oct 21 16:34:12 2003 +0000
+++ b/src/protocols/jabber/jutil.c	Tue Oct 21 17:18:46 2003 +0000
@@ -111,13 +111,80 @@
 	}
 }
 
+gboolean jabber_nodeprep_validate(const char *str)
+{
+	const char *c;
+
+	if(!str)
+		return TRUE;
+
+	if(strlen(str) > 1023)
+		return FALSE;
+
+	c = str;
+	while(c && *c) {
+		gunichar ch = g_utf8_get_char(c);
+		if(ch == '\"' || ch == '&' || ch == '\'' || ch == '/' || ch == ':' ||
+				ch == '<' || ch == '>' || ch == '@' || !g_unichar_isgraph(ch)) {
+			return FALSE;
+		}
+		c = g_utf8_next_char(c);
+	}
+
+	return TRUE;
+}
+
+gboolean jabber_nameprep_validate(const char *str)
+{
+	const char *c;
+
+	if(!str)
+		return TRUE;
+
+	if(strlen(str) > 1023)
+		return FALSE;
+
+	c = str;
+	while(c && *c) {
+		gunichar ch = g_utf8_get_char(c);
+		if(!g_unichar_isgraph(ch))
+			return FALSE;
+
+		c = g_utf8_next_char(c);
+	}
+
+
+	return TRUE;
+}
+
+gboolean jabber_resourceprep_validate(const char *str)
+{
+	const char *c;
+
+	if(!str)
+		return TRUE;
+
+	if(strlen(str) > 1023)
+		return FALSE;
+
+	c = str;
+	while(c && *c) {
+		gunichar ch = g_utf8_get_char(c);
+		if(!g_unichar_isgraph(ch))
+			return FALSE;
+
+		c = g_utf8_next_char(c);
+	}
+
+	return TRUE;
+}
+
+
 JabberID*
 jabber_id_new(const char *str)
 {
 	char *at;
 	char *slash;
-	char *c;
-
 	JabberID *jid;
 
 	if(!str || !g_utf8_validate(str, -1, NULL))
@@ -146,48 +213,13 @@
 	}
 
 
-	/* check lengths */
-	if((jid->node && strlen(jid->node) > 1023) ||
-			(jid->domain && strlen(jid->domain) > 1023) ||
-			(jid->resource && strlen(jid->resource) > 1023)) {
+	if(!jabber_nodeprep_validate(jid->node) ||
+			!jabber_nameprep_validate(jid->domain) ||
+			!jabber_resourceprep_validate(jid->resource)) {
 		jabber_id_free(jid);
 		return NULL;
 	}
 
-	/* nodeprep */
-	c = jid->node;
-	while(c && *c) {
-		gunichar ch = g_utf8_get_char(c);
-		if(ch == '\"' || ch == '&' || ch == '\'' || ch == '/' || ch == ':' ||
-				ch == '<' || ch == '>' || ch == '@' || !g_unichar_isgraph(ch)) {
-			jabber_id_free(jid);
-			return NULL;
-		}
-		c = g_utf8_next_char(c);
-	}
-
-	/* nameprep */
-	c = jid->domain;
-	while(c && *c) {
-		gunichar ch = g_utf8_get_char(c);
-		if(!g_unichar_isgraph(ch)) {
-			jabber_id_free(jid);
-			return NULL;
-		}
-		c = g_utf8_next_char(c);
-	}
-
-	/* resourceprep */
-	c = jid->resource;
-	while(c && *c) {
-	gunichar ch = g_utf8_get_char(c);
-		if(!g_unichar_isgraph(ch)) {
-			jabber_id_free(jid);
-			return NULL;
-		}
-		c = g_utf8_next_char(c);
-	}
-
 	return jid;
 }
 
@@ -240,6 +272,10 @@
 	char *tmp;
 
 	tmp = jabber_get_bare_jid(in);
+
+	if(!tmp)
+		return NULL;
+
 	g_snprintf(buf, sizeof(buf), "%s", tmp);
 	g_free(tmp);
 	return buf;