pidgin: 66c2e732: irc: Handle a buddy appearing in multipl...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Thu Aug 6 01:05:31 EDT 2009


-----------------------------------------------------------------
Revision: 66c2e7329145cfc8eb6bb71d6f9cc4684c979812
Ancestor: 40ec1f048551727aa8ebbedc7c5c8752dc517780
Author: darkrain42 at pidgin.im
Date: 2009-08-06T04:59:12
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/66c2e7329145cfc8eb6bb71d6f9cc4684c979812

Modified files:
        ChangeLog libpurple/protocols/irc/irc.c
        libpurple/protocols/irc/irc.h libpurple/protocols/irc/msgs.c

ChangeLog: 

irc: Handle a buddy appearing in multiple groups properly.

Handle multiple PurpleBuddy's corresponding to the same buddy with a reference
count in struct irc_buddy and fix a string corruption that would be caused
by using g_hash_table_insert instead of replace (the wrong string is freed).

-------------- next part --------------
============================================================
--- ChangeLog	728fa886b24f7db60397b7de1c6f9a7b35cbef57
+++ ChangeLog	f24960cb458665064071fae322061c31002cb4a2
@@ -45,6 +45,7 @@ version 2.6.0 (??/??/2009):
 	  the dialog icons, and the Buddy List emblems.
 	* Build properly on Hurd.  (Marc Dequ?nes)
 	* Various memory leaks fixed as reported by Josh Mueller.
+	* Properly handle an IRC buddy appearing in multiple groups.
 
 	AIM and ICQ:
 	* Preliminary support for a new authentication scheme called
============================================================
--- libpurple/protocols/irc/irc.c	a02796a2798a16a8dd2606252755cf3ba56a1a3c
+++ libpurple/protocols/irc/irc.c	5e34ebca540c653ff4c6a1c62fc13d0438c80c72
@@ -569,10 +569,21 @@ static void irc_add_buddy(PurpleConnecti
 static void irc_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
 {
 	struct irc_conn *irc = (struct irc_conn *)gc->proto_data;
-	struct irc_buddy *ib = g_new0(struct irc_buddy, 1);
-	ib->name = g_strdup(purple_buddy_get_name(buddy));
-	g_hash_table_replace(irc->buddies, ib->name, ib);
+	struct irc_buddy *ib;
+	const char *bname = purple_buddy_get_name(buddy);
 
+	ib = g_hash_table_lookup(irc->buddies, bname);
+	if (ib != NULL) {
+		ib->ref++;
+		purple_prpl_got_user_status(irc->account, bname,
+				ib->online ? "available" : "offline", NULL);
+	} else {
+		ib = g_new0(struct irc_buddy, 1);
+		ib->name = g_strdup(bname);
+		ib->ref = 1;
+		g_hash_table_replace(irc->buddies, ib->name, ib);
+	}
+
 	/* if the timer isn't set, this is during signon, so we don't want to flood
 	 * ourself off with ISON's, so we don't, but after that we want to know when
 	 * someone's online asap */
@@ -583,7 +594,12 @@ static void irc_remove_buddy(PurpleConne
 static void irc_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
 {
 	struct irc_conn *irc = (struct irc_conn *)gc->proto_data;
-	g_hash_table_remove(irc->buddies, purple_buddy_get_name(buddy));
+	struct irc_buddy *ib;
+
+	ib = g_hash_table_lookup(irc->buddies, purple_buddy_get_name(buddy));
+	if (ib && --ib->ref == 0) {
+		g_hash_table_remove(irc->buddies, purple_buddy_get_name(buddy));
+	}
 }
 
 static void read_input(struct irc_conn *irc, int len)
============================================================
--- libpurple/protocols/irc/irc.h	3ec9f203e62e5297a814a6840b6f16379471533c
+++ libpurple/protocols/irc/irc.h	b74849f9927175a474cb318bbdde9d2b130b992e
@@ -97,6 +97,7 @@ struct irc_buddy {
 	char *name;
 	gboolean online;
 	gboolean flag;
+	int ref;
 };
 
 typedef int (*IRCCmdCallback) (struct irc_conn *irc, const char *cmd, const char *target, const char **args);
============================================================
--- libpurple/protocols/irc/msgs.c	4805492a1a66fe1d66e07906bad49f34424c1e32
+++ libpurple/protocols/irc/msgs.c	6d17f00388dffe02b6d0699998e5921293fb25cc
@@ -103,7 +103,8 @@ static void irc_connected(struct irc_con
 		PurpleBuddy *b = buddies->data;
 		struct irc_buddy *ib = g_new0(struct irc_buddy, 1);
 		ib->name = g_strdup(purple_buddy_get_name(b));
-		g_hash_table_insert(irc->buddies, ib->name, ib);
+		ib->ref = 1;
+		g_hash_table_replace(irc->buddies, ib->name, ib);
 	}
 
 	irc_blist_timeout(irc);


More information about the Commits mailing list