pidgin: dcd01209: jabber_id_new() needs to be case-folding...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Sun May 17 17:51:17 EDT 2009


-----------------------------------------------------------------
Revision: dcd01209d8af5268ac18d8f55577aadc4b1c1179
Ancestor: 36e85b01808a3c6e32116cb8b71b10e31b0da072
Author: darkrain42 at pidgin.im
Date: 2009-05-17T21:45:21
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/dcd01209d8af5268ac18d8f55577aadc4b1c1179

Modified files:
        libpurple/protocols/jabber/jutil.c

ChangeLog: 

jabber_id_new() needs to be case-folding the node and domain.

A user appearing on the roster as Node at domain.org needs to be treated as
matching the user on the local buddy list node at domain.org. Technically,
this is strdown, not case-folding.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jutil.c	6acada4142410f97e4e9887ac31e1ce6d4e575f7
+++ libpurple/protocols/jabber/jutil.c	409fce0ef0ea2655a392592cf6f0803eaa58dc51
@@ -105,6 +105,8 @@ jabber_id_new(const char *str)
 {
 	char *at;
 	char *slash;
+	char *node = NULL;
+	char *domain;
 	JabberID *jid;
 
 	if(!str || !g_utf8_validate(str, -1, NULL))
@@ -116,23 +118,32 @@ jabber_id_new(const char *str)
 	slash = g_utf8_strchr(str, -1, '/');
 
 	if(at) {
-		jid->node = g_utf8_normalize(str, at-str, G_NORMALIZE_NFKC);
+		node = g_utf8_normalize(str, at-str, G_NORMALIZE_NFKC);
 		if(slash) {
-			jid->domain = g_utf8_normalize(at+1, slash-(at+1), G_NORMALIZE_NFKC);
+			domain = g_utf8_normalize(at+1, slash-(at+1), G_NORMALIZE_NFKC);
 			jid->resource = g_utf8_normalize(slash+1, -1, G_NORMALIZE_NFKC);
 		} else {
-			jid->domain = g_utf8_normalize(at+1, -1, G_NORMALIZE_NFKC);
+			domain = g_utf8_normalize(at+1, -1, G_NORMALIZE_NFKC);
 		}
 	} else {
 		if(slash) {
-			jid->domain = g_utf8_normalize(str, slash-str, G_NORMALIZE_NFKC);
+			domain = g_utf8_normalize(str, slash-str, G_NORMALIZE_NFKC);
 			jid->resource = g_utf8_normalize(slash+1, -1, G_NORMALIZE_NFKC);
 		} else {
-			jid->domain = g_utf8_normalize(str, -1, G_NORMALIZE_NFKC);
+			domain = g_utf8_normalize(str, -1, G_NORMALIZE_NFKC);
 		}
 	}
 
+	if (node) {
+		jid->node = g_utf8_strdown(node, -1);
+		g_free(node);
+	}
 
+	if (domain) {
+		jid->domain = g_utf8_strdown(domain, -1);
+		g_free(domain);
+	}
+
 	if(!jabber_nodeprep_validate(jid->node) ||
 			!jabber_nameprep_validate(jid->domain) ||
 			!jabber_resourceprep_validate(jid->resource)) {
@@ -193,28 +204,21 @@ const char *jabber_normalize(const Purpl
 	JabberStream *js = gc ? gc->proto_data : NULL;
 	static char buf[3072]; /* maximum legal length of a jabber jid */
 	JabberID *jid;
-	char *node, *domain;
 
 	jid = jabber_id_new(in);
 
 	if(!jid)
 		return NULL;
 
-	node = jid->node ? g_utf8_strdown(jid->node, -1) : NULL;
-	domain = g_utf8_strdown(jid->domain, -1);
-
-
-	if(js && node && jid->resource &&
-			jabber_chat_find(js, node, domain))
-		g_snprintf(buf, sizeof(buf), "%s@%s/%s", node, domain,
+	if(js && jid->node && jid->resource &&
+			jabber_chat_find(js, jid->node, jid->domain))
+		g_snprintf(buf, sizeof(buf), "%s@%s/%s", jid->node, jid->domain,
 				jid->resource);
 	else
-		g_snprintf(buf, sizeof(buf), "%s%s%s", node ? node : "",
-				node ? "@" : "", domain);
+		g_snprintf(buf, sizeof(buf), "%s%s%s", jid->node ? jid->node : "",
+				jid->node ? "@" : "", jid->domain);
 
 	jabber_id_free(jid);
-	g_free(node);
-	g_free(domain);
 
 	return buf;
 }


More information about the Commits mailing list