changeset 13905:4e44ecb866bd

[gaim-migrate @ 16394] msn_session_sync_users() iterates over the buddy list, following the ->next pointers of the groups, contacts, and buddies. msn_show_sync_issue(), if called, removed the buddy for which it was called, in preparation for the buddy either being added to the server list or confirmed-to-be-removed. This could lead to the buddy pointer being released and ->next therefore being junk. The buddy is now not removed until the user responds to the action dialog presented via msn_show_sync_issue(). I'm unclear why gtkgaim got away with this exercise in memory stomping but Adium/libgaim crashed every time, but it's safer in any case. I also changed some foo->bar to gaim_foo_get_bar(). committer: Tailor Script <tailor@pidgin.im>
author Evan Schoenberg <evan.s@dreskin.net>
date Sun, 02 Jul 2006 09:37:25 +0000
parents 863feae7fefa
children b986b6e2441b
files src/protocols/msn/dialog.c src/protocols/msn/session.c
diffstat 2 files changed, 28 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/dialog.c	Sat Jul 01 23:21:12 2006 +0000
+++ b/src/protocols/msn/dialog.c	Sun Jul 02 09:37:25 2006 +0000
@@ -34,9 +34,31 @@
 
 } MsnAddRemData;
 
+/* Remove the buddy referenced by the MsnAddRemData before the serverside list is changed.
+ * If the buddy will be added, he'll be added back; if he will be removed, he won't be. */
+static void
+msn_complete_sync_issue(MsnAddRemData *data)
+{
+	GaimBuddy *buddy;
+	GaimGroup *group = NULL;
+
+	if (data->group != NULL)
+		group = gaim_find_group(data->group);
+	
+	if (group != NULL)
+		buddy = gaim_find_buddy_in_group(gaim_connection_get_account(data->gc), data->who, group);
+	else
+		buddy = gaim_find_buddy(gaim_connection_get_account(data->gc), data->who);
+	
+	if (buddy != NULL)
+		gaim_blist_remove_buddy(buddy);
+}
+
 static void
 msn_add_cb(MsnAddRemData *data)
 {
+	msn_complete_sync_issue(data);
+
 	if (g_list_find(gaim_connections_get_all(), data->gc) != NULL)
 	{
 		MsnSession *session = data->gc->proto_data;
@@ -55,6 +77,8 @@
 static void
 msn_rem_cb(MsnAddRemData *data)
 {
+	msn_complete_sync_issue(data);
+
 	if (g_list_find(gaim_connections_get_all(), data->gc) != NULL)
 	{
 		MsnSession *session = data->gc->proto_data;
@@ -78,8 +102,6 @@
 	GaimAccount *account;
 	MsnAddRemData *data;
 	char *msg, *reason;
-	GaimBuddy *buddy;
-	GaimGroup *group = NULL;
 
 	account = session->account;
 	gc = gaim_account_get_connection(account);
@@ -114,17 +136,6 @@
 						_("Yes"), G_CALLBACK(msn_add_cb),
 						_("No"), G_CALLBACK(msn_rem_cb));
 
-	if (group_name != NULL)
-		group = gaim_find_group(group_name);
-
-	if (group != NULL)
-		buddy = gaim_find_buddy_in_group(account, passport, group);
-	else
-		buddy = gaim_find_buddy(account, passport);
-
-	if (buddy != NULL)
-		gaim_blist_remove_buddy(buddy);
-
 	g_free(reason);
 	g_free(msg);
 }
--- a/src/protocols/msn/session.c	Sat Jul 01 23:21:12 2006 +0000
+++ b/src/protocols/msn/session.c	Sun Jul 02 09:37:25 2006 +0000
@@ -231,7 +231,7 @@
 	 * being logged in. This no longer happens, so we manually iterate
 	 * over the whole buddy list to identify sync issues. */
 
-	for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) {
+	for (gnode = gaim_blist_get_root(); gnode; gnode = gnode->next) {
 		GaimGroup *group = (GaimGroup *)gnode;
 		const char *group_name = group->name;
 		if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
@@ -244,11 +244,11 @@
 				if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
 					continue;
 				b = (GaimBuddy *)bnode;
-				if(b->account == gc->account) {
+				if(gaim_buddy_get_account(b) == gaim_connection_get_account(gc)) {
 					MsnUser *remote_user;
 					gboolean found = FALSE;
 
-					remote_user = msn_userlist_find_user(session->userlist, b->name);
+					remote_user = msn_userlist_find_user(session->userlist, gaim_buddy_get_name(b));
 
 					if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP))
 					{
@@ -273,7 +273,7 @@
 					{
 						/* The user was not on the server list or not in that group
 						 * on the server list */
-						msn_show_sync_issue(session, b->name, group_name);
+						msn_show_sync_issue(session, gaim_buddy_get_name(b), group_name);
 					}
 				}
 			}