pidgin: 91984369: jabber: Store the "own JabberBuddy" in t...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Sun Aug 2 01:41:17 EDT 2009


-----------------------------------------------------------------
Revision: 91984369c58b66ea4f0f1727060b9a09242b9bfd
Ancestor: e2dae1bf841b14d3908cb5cd922645f697a66c6b
Author: darkrain42 at pidgin.im
Date: 2009-08-01T22:12:30
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/91984369c58b66ea4f0f1727060b9a09242b9bfd

Modified files:
        libpurple/protocols/jabber/buddy.c
        libpurple/protocols/jabber/buddy.h
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/jabber.h
        libpurple/protocols/jabber/roster.c

ChangeLog: 

jabber: Store the "own JabberBuddy" in the JabberStream* struct.

This simplifies the roster code a little (don't need to recalculate our
own JID for string comparisons) and fixes a few FIXMEs in buddy.c.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	cea44f1f631bf38134388d49be6b5c0af910fd35
+++ libpurple/protocols/jabber/buddy.c	441a09259d0655f7f7cf90bc52d06bebeb4d88ea
@@ -1765,9 +1765,7 @@ static GList *jabber_buddy_menu(PurpleBu
 	if(!jb)
 		return m;
 
-	/* XXX: fix the NOT ME below */
-
-	if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) {
+	if (js->protocol_version == JABBER_PROTO_0_9 && jb != js->user_jb) {
 		if(jb->invisible & JABBER_INVIS_BUDDY) {
 			act = purple_menu_action_new(_("Un-hide From"),
 			                           PURPLE_CALLBACK(jabber_buddy_make_visible),
@@ -1780,7 +1778,7 @@ static GList *jabber_buddy_menu(PurpleBu
 		m = g_list_append(m, act);
 	}
 
-	if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) {
+	if(jb->subscription & JABBER_SUB_FROM && jb != js->user_jb) {
 		act = purple_menu_action_new(_("Cancel Presence Notification"),
 		                           PURPLE_CALLBACK(jabber_buddy_cancel_presence_notification),
 		                           NULL, NULL);
@@ -1793,7 +1791,7 @@ static GList *jabber_buddy_menu(PurpleBu
 		                           NULL, NULL);
 		m = g_list_append(m, act);
 
-	} else /* if(NOT ME) */{
+	} else if (jb != js->user_jb) {
 
 		/* shouldn't this just happen automatically when the buddy is
 		   removed? */
============================================================
--- libpurple/protocols/jabber/buddy.h	3e2e28c9c14a8971437406222ad4d57bd3a0c1e8
+++ libpurple/protocols/jabber/buddy.h	1021779cce68a10adbe3e8383641d666ccea85e8
@@ -33,10 +33,12 @@ typedef enum {
 	JABBER_BUDDY_STATE_DND
 } JabberBuddyState;
 
+typedef struct _JabberBuddy JabberBuddy;
+
 #include "jabber.h"
 #include "caps.h"
 
-typedef struct _JabberBuddy {
+struct _JabberBuddy {
 	GList *resources;
 	char *error_msg;
 	enum {
@@ -52,7 +54,7 @@ typedef struct _JabberBuddy {
 		JABBER_SUB_BOTH    = (JABBER_SUB_TO | JABBER_SUB_FROM),
 		JABBER_SUB_REMOVE  = 1 << 4
 	} subscription;
-} JabberBuddy;
+};
 
 typedef struct _JabberAdHocCommands {
 	char *jid;
============================================================
--- libpurple/protocols/jabber/jabber.c	ee8c9879f144270c9d8b94d8b5393d596024e756
+++ libpurple/protocols/jabber/jabber.c	58157b1ffa0ffef712be594d0e37b512d40b760c
@@ -132,7 +132,6 @@ static void jabber_bind_result_cb(Jabber
 		xmlnode *jid;
 		char *full_jid;
 		if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) {
-			JabberBuddy *my_jb;
 			jabber_id_free(js->user);
 
 			js->user = jabber_id_new(full_jid);
@@ -144,9 +143,8 @@ static void jabber_bind_result_cb(Jabber
 				return;
 			}
 
-			my_jb = jabber_buddy_find(js, full_jid, TRUE);
-			if (my_jb)
-				my_jb->subscription |= JABBER_SUB_BOTH;
+			js->user_jb = jabber_buddy_find(js, full_jid, TRUE);
+			js->user_jb->subscription |= JABBER_SUB_BOTH;
 
 			purple_connection_set_display_name(js->gc, full_jid);
 
@@ -781,7 +779,6 @@ jabber_stream_new(PurpleAccount *account
 {
 	PurpleConnection *gc = purple_account_get_connection(account);
 	JabberStream *js;
-	JabberBuddy *my_jb;
 	PurplePresence *presence;
 	gchar *user;
 	gchar *slash;
@@ -816,9 +813,9 @@ jabber_stream_new(PurpleAccount *account
 	js->buddies = g_hash_table_new_full(g_str_hash, g_str_equal,
 			g_free, (GDestroyNotify)jabber_buddy_free);
 
-	my_jb = jabber_buddy_find(js, user, TRUE);
+	js->user_jb = jabber_buddy_find(js, user, TRUE);
 	g_free(user);
-	if (!my_jb) {
+	if (!js->user_jb) {
 		/* This basically *can't* fail, but for good measure... */
 		purple_connection_error_reason(gc,
 			PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
@@ -827,7 +824,7 @@ jabber_stream_new(PurpleAccount *account
 		g_return_val_if_reached(NULL);
 	}
 
-	my_jb->subscription |= JABBER_SUB_BOTH;
+	js->user_jb->subscription |= JABBER_SUB_BOTH;
 
 	js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
 			g_free, g_free);
============================================================
--- libpurple/protocols/jabber/jabber.h	4ea229fd0bbd4dc8dff94acd22a861ac853261ec
+++ libpurple/protocols/jabber/jabber.h	3e299edba21a48ae05cc7f5f811e1d998c32cc73
@@ -164,6 +164,8 @@ struct _JabberStream
 	time_t old_idle;
 
 	JabberID *user;
+	JabberBuddy *user_jb;
+
 	PurpleConnection *gc;
 	PurpleSslConnection *gsc;
 
============================================================
--- libpurple/protocols/jabber/roster.c	b3f625f5ea45285c4250bebe38a6bbee2ac1bbee
+++ libpurple/protocols/jabber/roster.c	41182aae5b3c92673140f06301ba3a63ff6ff1fe
@@ -66,7 +66,7 @@ static void add_purple_buddy_to_groups(J
 }
 
 static void add_purple_buddy_to_groups(JabberStream *js, const char *jid,
-		const char *alias, GSList *groups, const char *own_jid)
+		const char *alias, GSList *groups)
 {
 	GSList *buddies, *l;
 	GSList *pool = NULL;
@@ -162,12 +162,6 @@ static void add_purple_buddy_to_groups(J
 		purple_blist_add_buddy(b, NULL, g, NULL);
 		purple_blist_alias_buddy(b, alias);
 
-		/* If we just learned about ourself, then fake our status,
-		 * because we won't be receiving a normal presence message
-		 * about ourself. */
-		if(!strcmp(purple_buddy_get_name(b), own_jid))
-			jabber_presence_fake_to_self(js, NULL);
-
 		g_free(groups->data);
 		groups = g_slist_delete_link(groups, groups);
 	}
@@ -187,7 +181,6 @@ void jabber_roster_parse(JabberStream *j
                          JabberIqType type, const char *id, xmlnode *query)
 {
 	xmlnode *item, *group;
-	gchar *own_jid;
 
 	if (!jabber_is_own_account(js, from)) {
 		purple_debug_warning("jabber", "Received bogon roster push from %s\n",
@@ -197,8 +190,6 @@ void jabber_roster_parse(JabberStream *j
 
 	js->currently_parsing_roster_push = TRUE;
 
-	own_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
-
 	for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item))
 	{
 		const char *jid, *name, *subscription, *ask;
@@ -216,11 +207,7 @@ void jabber_roster_parse(JabberStream *j
 			continue;
 
 		if(subscription) {
-			gboolean me = FALSE;
-
-			me = g_str_equal(own_jid, jabber_normalize(js->gc->account, jid));
-
-			if(me)
+			if (jb == js->user_jb)
 				jb->subscription = JABBER_SUB_BOTH;
 			else if(!strcmp(subscription, "none"))
 				jb->subscription = JABBER_SUB_NONE;
@@ -260,11 +247,12 @@ void jabber_roster_parse(JabberStream *j
 				groups = g_slist_prepend(groups, group_name);
 			}
 
-			add_purple_buddy_to_groups(js, jid, name, groups, own_jid);
+			add_purple_buddy_to_groups(js, jid, name, groups);
+			if (jb == js->user_jb)
+				jabber_presence_fake_to_self(js, NULL);
 		}
 	}
 
-	g_free(own_jid);
 	js->currently_parsing_roster_push = FALSE;
 
 	/* if we're just now parsing the roster for the first time,
@@ -348,7 +336,6 @@ void jabber_roster_add_buddy(PurpleConne
 	char *who;
 	JabberBuddy *jb;
 	JabberBuddyResource *jbr;
-	char *own_jid;
 	const char *name;
 
 	/* If we haven't received the roster yet, ignore any adds */
@@ -366,8 +353,7 @@ void jabber_roster_add_buddy(PurpleConne
 
 	jabber_roster_update(js, who, NULL);
 
-	own_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
-	if (g_str_equal(who, own_jid)) {
+	if (jb == js->user_jb) {
 		jabber_presence_fake_to_self(js, NULL);
 	} else if(!jb || !(jb->subscription & JABBER_SUB_TO)) {
 		jabber_presence_subscription_set(js, who, "subscribe");
@@ -377,7 +363,6 @@ void jabber_roster_add_buddy(PurpleConne
 				"priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL);
 	}
 
-	g_free(own_jid);
 	g_free(who);
 }
 


More information about the Commits mailing list