changeset 26774:867e231bffbc

A little bit better (free memory and support receiving the nick in subscriptions) and Changelog.
author Paul Aurich <paul@darkrain42.org>
date Sat, 02 May 2009 04:39:38 +0000
parents e816444c1a01
children f0874c392052
files ChangeLog libpurple/protocols/jabber/presence.c
diffstat 2 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat May 02 04:14:09 2009 +0000
+++ b/ChangeLog	Sat May 02 04:39:38 2009 +0000
@@ -33,6 +33,8 @@
 	* Support showing and reporting idle times in the buddy list. (XEP-0256)
 	* Support most recent version of User Avatar. (XEP-0084 v1.1)
 	* Updated Entity Capabilities support. (Tobias Markmann)
+	* Support receiving user nicknames in presence packets and subscriptions.
+	  (XEP-0172)
 
 	IRC:
 	* Correctly handle WHOIS for users who are joined to a large number of
--- a/libpurple/protocols/jabber/presence.c	Sat May 02 04:14:09 2009 +0000
+++ b/libpurple/protocols/jabber/presence.c	Sat May 02 04:39:38 2009 +0000
@@ -441,7 +441,7 @@
 	char *avatar_hash = NULL;
 	xmlnode *caps = NULL;
 	int idle = 0;
-	const gchar *nick = NULL;
+	gchar *nickname = NULL;
 
 	if(!(jb = jabber_buddy_find(js, from, TRUE)))
 		return;
@@ -464,6 +464,11 @@
 		gboolean onlist = FALSE;
 		PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(js->gc), from);
 		JabberBuddy *jb = NULL;
+		xmlnode *nick;
+
+		nick = xmlnode_get_child_with_namespace(packet, "nick", "http://jabber.org/protocol/nick");
+		if (nick)
+			nickname = xmlnode_get_data(nick);
 
 		if (buddy) {
 			jb = jabber_buddy_find(js, from, TRUE);
@@ -475,8 +480,9 @@
 		jap->who = g_strdup(from);
 		jap->js = js;
 
-		purple_account_request_authorization(purple_connection_get_account(js->gc), from, NULL, NULL, NULL, onlist,
+		purple_account_request_authorization(purple_connection_get_account(js->gc), from, NULL, nickname, NULL, onlist,
 				authorize_add_cb, deny_add_cb, jap);
+		g_free(nickname);
 		jabber_id_free(jid);
 		return;
 	} else if(type && !strcmp(type, "subscribed")) {
@@ -528,7 +534,7 @@
 		} else if(!strcmp(y->name, "c") && !strcmp(xmlns, "http://jabber.org/protocol/caps")) {
 			caps = y; /* store for later, when creating buddy resource */
 		} else if (g_str_equal(y->name, "nick") && g_str_equal(xmlns, "http://jabber.org/protocol/nick")) {
-			nick = xmlnode_get_data(y);
+			nickname = xmlnode_get_data(y);
 		} else if(!strcmp(y->name, "x")) {
 			if(!strcmp(xmlns, "jabber:x:delay")) {
 				/* XXX: compare the time.  jabber:x:delay can happen on presence packets that aren't really and truly delayed */
@@ -629,6 +635,7 @@
 			jabber_id_free(jid);
 			g_free(status);
 			g_free(avatar_hash);
+			g_free(nickname);
 			return;
 		}
 
@@ -645,6 +652,7 @@
 				jabber_id_free(jid);
 				g_free(status);
 				g_free(avatar_hash);
+				g_free(nickname);
 				return;
 			}
 
@@ -731,6 +739,7 @@
 				jabber_id_free(jid);
 				g_free(avatar_hash);
 				g_free(buddy_name);
+				g_free(nickname);
 				g_free(status);
 				return;
 			} else {
@@ -787,8 +796,8 @@
 			jabber_google_presence_incoming(js, buddy_name, found_jbr);
 			purple_prpl_got_user_status(js->gc->account, buddy_name, jabber_buddy_state_get_status_id(found_jbr->state), "priority", found_jbr->priority, "message", found_jbr->status, NULL);
 			purple_prpl_got_user_idle(js->gc->account, buddy_name, found_jbr->idle, found_jbr->idle);
-			if (nick)
-				serv_got_alias(js->gc, buddy_name, nick);
+			if (nickname)
+				serv_got_alias(js->gc, buddy_name, nickname);
 		} else {
 			purple_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL);
 		}
@@ -815,6 +824,7 @@
 		}
 	}
 
+	g_free(nickname);
 	g_free(status);
 	jabber_id_free(jid);
 	g_free(avatar_hash);