changeset 27076:1fcd09c34fee

Use purple_find_buddies() instead of iterating the buddy list.
author Paul Aurich <paul@darkrain42.org>
date Mon, 01 Jun 2009 04:02:10 +0000
parents 5ff1d66e6aef
children 1dcf9c7311f1
files libpurple/protocols/gg/buddylist.c libpurple/protocols/irc/msgs.c libpurple/protocols/msn/session.c libpurple/protocols/msn/userlist.c libpurple/protocols/msnp9/session.c libpurple/protocols/oscar/oscar.c libpurple/protocols/silc/buddy.c libpurple/protocols/silc/ops.c libpurple/protocols/simple/simple.c libpurple/protocols/zephyr/zephyr.c
diffstat 10 files changed, 158 insertions(+), 366 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/gg/buddylist.c	Mon Jun 01 03:34:02 2009 +0000
+++ b/libpurple/protocols/gg/buddylist.c	Mon Jun 01 04:02:10 2009 +0000
@@ -40,57 +40,33 @@
 {
 	GGPInfo *info = gc->proto_data;
 	PurpleAccount *account = purple_connection_get_account(gc);
-
-	PurpleBlistNode *gnode, *cnode, *bnode;
-	PurpleBuddy *buddy;
-	uin_t *userlist = NULL;
-	gchar *types = NULL;
-	int size = 0, ret = 0;
+	GSList *buddies;
+	uin_t *userlist;
+	gchar *types;
+	int i = 0, ret = 0;
+	int size;
 
-	for (gnode = purple_blist_get_root();
-	     gnode != NULL;
-	     gnode = purple_blist_node_get_sibling_next(gnode))
-	{
-		if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-
-		for (cnode = purple_blist_node_get_first_child(gnode);
-		     cnode != NULL;
-		     cnode = purple_blist_node_get_sibling_next(cnode))
-		{
-			if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
+	buddies = purple_find_buddies(account, NULL);
 
-			for (bnode = purple_blist_node_get_first_child(cnode);
-			     bnode != NULL;
-			     bnode = purple_blist_node_get_sibling_next(bnode))
-			{
-				const gchar *name = NULL;
-
-				if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-
-				buddy = (PurpleBuddy *)bnode;
+	size = g_slist_length(buddies);
+	userlist = g_new(uin_t, size);
+	types    = g_new(gchar, size);
 
-				if (purple_buddy_get_account(buddy) != account)
-					continue;
-
-				name = purple_buddy_get_name(buddy);
+	for (buddies = purple_find_buddies(account, NULL); buddies;
+			buddies = g_slist_delete_link(buddies, buddies), ++i)
+	{
+		PurpleBuddy *buddy = buddies->data;
+		const gchar *name = purple_buddy_get_name(buddy);
 
-				size++;
-				userlist = (uin_t *) g_renew(uin_t, userlist, size);
-				types    = (gchar *) g_renew(gchar, types, size);
-				userlist[size - 1] = ggp_str_to_uin(name);
-				types[size - 1]    = GG_USER_NORMAL;
-				purple_debug_info("gg", "ggp_buddylist_send: adding %d\n",
-						userlist[size - 1]);
-			}
-		}
+		userlist[i] = ggp_str_to_uin(name);
+		types[i]    = GG_USER_NORMAL;
+		purple_debug_info("gg", "ggp_buddylist_send: adding %d\n",
+		                  userlist[i]);
 	}
 
 	ret = gg_notify_ex(info->session, userlist, types, size);
 	purple_debug_info("gg", "send: ret=%d; size=%d\n", ret, size);
-	
+
 	if (userlist) {
 		g_free(userlist);
 		g_free(types);
@@ -181,53 +157,25 @@
 /* char *ggp_buddylist_dump(PurpleAccount *account) {{{ */
 char *ggp_buddylist_dump(PurpleAccount *account)
 {
-	PurpleBlistNode *gnode, *cnode, *bnode;
-	PurpleGroup *group;
-	PurpleBuddy *buddy;
+	GSList *buddies;
 	GString *buddylist = g_string_sized_new(1024);
 	char *ptr;
 
-	for (gnode = purple_blist_get_root();
-	     gnode != NULL;
-	     gnode = purple_blist_node_get_sibling_next(gnode))
-	{
-		if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-
-		group = (PurpleGroup *)gnode;
-
-		for (cnode = purple_blist_node_get_first_child(gnode);
-		     cnode != NULL;
-		     cnode = purple_blist_node_get_sibling_next(cnode))
-		{
-			if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
+	for (buddies = purple_find_buddies(account, NULL); buddies;
+			buddies = g_slist_delete_link(buddies, buddies)) {
+		PurpleBuddy *buddy = buddies->data;
+		PurpleGroup *group = purple_buddy_get_group(buddy);
+		const char *bname = purple_buddy_get_name(buddy);
+		const char *gname = purple_group_get_name(group);
+		const char *alias = purple_buddy_get_alias(buddy);
 
-			for (bnode = purple_blist_node_get_first_child(cnode);
-			     bnode != NULL;
-			     bnode = purple_blist_node_get_sibling_next(bnode))
-			{
-				const gchar *name, *alias, *gname;
-
-				if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-
-				buddy = (PurpleBuddy *)bnode;
-				if (purple_buddy_get_account(buddy) != account)
-					continue;
+		if (alias == NULL)
+			alias = bname;
 
-				name = purple_buddy_get_name(buddy);
-				alias = purple_buddy_get_alias(buddy);
-				if(alias == NULL)
-					alias = name;
-				gname = purple_group_get_name(group);
-
-				g_string_append_printf(buddylist,
-						"%s;%s;%s;%s;%s;%s;%s;%s%s\r\n",
-						alias, alias, alias, alias,
-						"", gname, name, "", "");
-			}
-		}
+		g_string_append_printf(buddylist,
+				"%s;%s;%s;%s;%s;%s;%s;%s%s\r\n",
+				alias, alias, alias, alias,
+				"", gname, bname, "", "");
 	}
 
 	ptr = charset_convert(buddylist->str, "UTF-8", "CP1250");
--- a/libpurple/protocols/irc/msgs.c	Mon Jun 01 03:34:02 2009 +0000
+++ b/libpurple/protocols/irc/msgs.c	Mon Jun 01 04:02:10 2009 +0000
@@ -78,7 +78,7 @@
 {
 	PurpleConnection *gc;
 	PurpleStatus *status;
-	PurpleBlistNode *gnode, *cnode, *bnode;
+	GSList *buddies;
 	PurpleAccount *account;
 
 	if ((gc = purple_account_get_connection(irc->account)) == NULL
@@ -97,33 +97,13 @@
 	}
 
 	/* this used to be in the core, but it's not now */
-	for (gnode = purple_blist_get_root();
-	     gnode;
-	     gnode = purple_blist_node_get_sibling_next(gnode))
+	for (buddies = purple_find_buddies(account, NULL); buddies;
+			buddies = g_slist_delete_link(buddies, buddies))
 	{
-		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-		for(cnode = purple_blist_node_get_first_child(gnode);
-		    cnode;
-		    cnode = purple_blist_node_get_sibling_next(cnode))
-		{
-			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
-			for(bnode = purple_blist_node_get_first_child(cnode);
-			    bnode;
-			    bnode = purple_blist_node_get_sibling_next(bnode))
-			{
-				PurpleBuddy *b;
-				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-				b = (PurpleBuddy *)bnode;
-				if(purple_buddy_get_account(b) == account) {
-					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);
-				}
-			}
-		}
+		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);
 	}
 
 	irc_blist_timeout(irc);
--- a/libpurple/protocols/msn/session.c	Mon Jun 01 03:34:02 2009 +0000
+++ b/libpurple/protocols/msn/session.c	Mon Jun 01 04:02:10 2009 +0000
@@ -261,9 +261,9 @@
 static void
 msn_session_sync_users(MsnSession *session)
 {
-	PurpleBlistNode *gnode, *cnode, *bnode;
 	PurpleConnection *gc = purple_account_get_connection(session->account);
 	GList *to_remove = NULL;
+	GSList *buddies;
 
 	g_return_if_fail(gc != NULL);
 
@@ -271,60 +271,36 @@
 	 * being logged in. This no longer happens, so we manually iterate
 	 * over the whole buddy list to identify sync issues.
 	 */
-	for (gnode = purple_blist_get_root(); gnode;
-			gnode = purple_blist_node_get_sibling_next(gnode)) {
-		PurpleGroup *group = (PurpleGroup *)gnode;
-		const char *group_name;
-		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-		group_name = purple_group_get_name(group);
-		for(cnode = purple_blist_node_get_first_child(gnode);
-				cnode;
-				cnode = purple_blist_node_get_sibling_next(cnode)) {
-			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
-			for(bnode = purple_blist_node_get_first_child(cnode);
-					bnode;
-					bnode = purple_blist_node_get_sibling_next(bnode)) {
-				PurpleBuddy *b;
-				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-				b = (PurpleBuddy *)bnode;
-				if(purple_buddy_get_account(b) == purple_connection_get_account(gc)) {
-					MsnUser *remote_user;
-					gboolean found = FALSE;
-
-					remote_user = msn_userlist_find_user(session->userlist, purple_buddy_get_name(b));
+	for (buddies = purple_find_buddies(session->account, NULL); buddies;
+			buddies = g_slist_delete_link(buddies, buddies)) {
+		PurpleBuddy *buddy = buddies->data;
+		const gchar *buddy_name = purple_buddy_get_name(buddy);
+		const gchar *group_name = purple_group_get_name(purple_buddy_get_group(buddy));
+		MsnUser *remote_user;
+		gboolean found = FALSE;
 
-					if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP))
-					{
-						GList *l;
-
-						for (l = remote_user->group_ids; l != NULL; l = l->next)
-						{
-							const char *name = msn_userlist_find_group_name(remote_user->userlist, l->data);
-							if (name && !g_ascii_strcasecmp(group_name, name))
-							{
-								found = TRUE;
-								break;
-							}
-						}
-					}
+		remote_user = msn_userlist_find_user(session->userlist, buddy_name);
+		if (remote_user && remote_user->list_op & MSN_LIST_FL_OP) {
+			GList *l;
+			for (l = remote_user->group_ids; l; l = l->next) {
+				const char *name = msn_userlist_find_group_name(remote_user->userlist, l->data);
+				if (name && !g_ascii_strcasecmp(group_name, name)) {
+					found = TRUE;
+					break;
+				}
+			}
 
-					/* We don't care if they're in a different group, as long as they're on the
-					 * list somewhere. If we check for the group, we cause pain, agony and
-					 * suffering for people who decide to re-arrange their buddy list elsewhere.
-					 */
-					if (!found)
-					{
-						if ((remote_user == NULL) || !(remote_user->list_op & MSN_LIST_FL_OP)) {
-							/* The user is not on the server list */
-							msn_show_sync_issue(session, purple_buddy_get_name(b), group_name);
-						} else {
-							/* The user is not in that group on the server list */
-							to_remove = g_list_prepend(to_remove, b);
-						}
-					}
+			/* We don't care if they're in a different group, as long as they're on the
+			 * list somewhere. If we check for the group, we cause pain, agony and
+			 * suffering for people who decide to re-arrange their buddy list elsewhere.
+			 */
+			if (!found) {
+				if ((remote_user == NULL) || !(remote_user->list_op & MSN_LIST_FL_OP)) {
+					/* The user is not on the server list */
+					msn_show_sync_issue(session, buddy_name, group_name);
+				} else {
+					/* The user is not in that group on the server list */
+					to_remove = g_list_prepend(to_remove, buddy);
 				}
 			}
 		}
--- a/libpurple/protocols/msn/userlist.c	Mon Jun 01 03:34:02 2009 +0000
+++ b/libpurple/protocols/msn/userlist.c	Mon Jun 01 04:02:10 2009 +0000
@@ -783,7 +783,6 @@
 void
 msn_userlist_load(MsnSession *session)
 {
-	PurpleBlistNode *gnode, *cnode, *bnode;
 	PurpleAccount *account = session->account;
 	PurpleConnection *gc = purple_account_get_connection(account);
 	GSList *l;
@@ -791,34 +790,14 @@
 
 	g_return_if_fail(gc != NULL);
 
-	for (gnode = purple_blist_get_root(); gnode;
-			gnode = purple_blist_node_get_sibling_next(gnode))
-	{
-		if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-		for (cnode = purple_blist_node_get_first_child(gnode);
-				cnode;
-				cnode = purple_blist_node_get_sibling_next(cnode))
-		{
-			if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
-			for (bnode = purple_blist_node_get_first_child(cnode);
-					bnode;
-					bnode = purple_blist_node_get_sibling_next(bnode))
-			{
-				PurpleBuddy *b;
-				if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-				b = (PurpleBuddy *)bnode;
-				if (purple_buddy_get_account(b) == account)
-				{
-					user = msn_userlist_find_add_user(session->userlist,
-						purple_buddy_get_name(b), NULL);
-					purple_buddy_set_protocol_data(b, user);
-					msn_user_set_op(user, MSN_LIST_FL_OP);
-				}
-			}
-		}
+	for (l = purple_find_buddies(account, NULL); l != NULL;
+			l = g_slist_delete_link(l, l)) {
+		PurpleBuddy *buddy = l->data;
+
+		user = msn_userlist_find_add_user(session->userlist,
+			purple_buddy_get_name(buddy), NULL);
+		purple_buddy_set_protocol_data(buddy, user);
+		msn_user_set_op(user, MSN_LIST_FL_OP);
 	}
 	for (l = session->account->permit; l != NULL; l = l->next)
 	{
--- a/libpurple/protocols/msnp9/session.c	Mon Jun 01 03:34:02 2009 +0000
+++ b/libpurple/protocols/msnp9/session.c	Mon Jun 01 04:02:10 2009 +0000
@@ -221,68 +221,51 @@
 static void
 msn_session_sync_users(MsnSession *session)
 {
-	PurpleBlistNode *gnode, *cnode, *bnode;
 	PurpleConnection *gc = purple_account_get_connection(session->account);
 	GList *to_remove = NULL;
+	GSList *buddies;
 
 	g_return_if_fail(gc != NULL);
 
 	/* The core used to use msn_add_buddy to add all buddies before
 	 * being logged in. This no longer happens, so we manually iterate
 	 * over the whole buddy list to identify sync issues. */
+	for (buddies = purple_find_buddies(session->account, NULL); buddies;
+			buddies = g_slist_delete_link(buddies, buddies)) {
+		PurpleBuddy *buddy = buddies->data;
+		const char *buddy_name = purple_buddy_get_name(buddy);
+		const char *group_name = purple_group_get_name(purple_buddy_get_group(buddy));
+		MsnUser *remote_user;
+		gboolean found = FALSE;
 
-	for (gnode = purple_blist_get_root(); gnode; gnode = gnode->next) {
-		PurpleGroup *group = (PurpleGroup *)gnode;
-		const char *group_name = group->name;
-		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-		for(cnode = gnode->child; cnode; cnode = cnode->next) {
-			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
-			for(bnode = cnode->child; bnode; bnode = bnode->next) {
-				PurpleBuddy *b;
-				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-				b = (PurpleBuddy *)bnode;
-				if(purple_buddy_get_account(b) == purple_connection_get_account(gc)) {
-					MsnUser *remote_user;
-					gboolean found = FALSE;
+		remote_user = msn_userlist_find_user(session->userlist, buddy_name);
 
-					remote_user = msn_userlist_find_user(session->userlist, purple_buddy_get_name(b));
+		if (remote_user && remote_user->list_op & MSN_LIST_FL_OP) {
+			int group_id;
+			GList *l;
 
-					if ((remote_user != NULL) && (remote_user->list_op & MSN_LIST_FL_OP))
-					{
-						int group_id;
-						GList *l;
+			group_id = msn_userlist_find_group_id(remote_user->userlist,
+					group_name);
 
-						group_id = msn_userlist_find_group_id(remote_user->userlist,
-								group_name);
-
-						for (l = remote_user->group_ids; l != NULL; l = l->next)
-						{
-							if (group_id == GPOINTER_TO_INT(l->data))
-							{
-								found = TRUE;
-								break;
-							}
-						}
-
-					}
+			for (l = remote_user->group_ids; l; l = l->next) {
+				if (group_id == GPOINTER_TO_INT(l->data)) {
+					found = TRUE;
+					break;
+				}
+			}
 
-					/* We don't care if they're in a different group, as long as they're on the
-					 * list somewhere. If we check for the group, we cause pain, agony and
-					 * suffering for people who decide to re-arrange their buddy list elsewhere.
-					 */
-					if (!found)
-					{
-						if ((remote_user == NULL) || !(remote_user->list_op & MSN_LIST_FL_OP)) {
-							/* The user is not on the server list */
-							msn_show_sync_issue(session, purple_buddy_get_name(b), group_name);
-						} else {
-							/* The user is not in that group on the server list */
-							to_remove = g_list_prepend(to_remove, b);
-						}
-					}
+			/* We don't care if they're in a different group, as long as they're on the
+			 * list somewhere. If we check for the group, we cause pain, agony and
+			 * suffering for people who decide to re-arrange their buddy list elsewhere.
+			 */
+			if (!found)
+			{
+				if ((remote_user == NULL) || !(remote_user->list_op & MSN_LIST_FL_OP)) {
+					/* The user is not on the server list */
+					msn_show_sync_issue(session, buddy_name, group_name);
+				} else {
+					/* The user is not in that group on the server list */
+					to_remove = g_list_prepend(to_remove, buddy);
 				}
 			}
 		}
--- a/libpurple/protocols/oscar/oscar.c	Mon Jun 01 03:34:02 2009 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Mon Jun 01 04:02:10 2009 +0000
@@ -6541,47 +6541,35 @@
 {
 	PurpleConnection *gc = (PurpleConnection *) action->context;
 	OscarData *od = purple_connection_get_protocol_data(gc);
-	gchar *nombre, *text, *tmp;
-	PurpleBlistNode *gnode, *cnode, *bnode;
+	gchar *text, *tmp;
+	GSList *buddies;
 	PurpleAccount *account;
 	int num=0;
 
 	text = g_strdup("");
 	account = purple_connection_get_account(gc);
 
-	for (gnode = purple_blist_get_root(); gnode;
-			gnode = purple_blist_node_get_sibling_next(gnode)) {
-		PurpleGroup *group = (PurpleGroup *)gnode;
-		const char *gname;
-		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-		gname = purple_group_get_name(group);
-		for (cnode = purple_blist_node_get_first_child(gnode);
-				cnode;
-				cnode = purple_blist_node_get_sibling_next(cnode)) {
-			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
-			for (bnode = purple_blist_node_get_first_child(cnode);
-					bnode;
-					bnode = purple_blist_node_get_sibling_next(bnode)) {
-				PurpleBuddy *buddy = (PurpleBuddy *)bnode;
-				const char *bname;
-				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-				bname = purple_buddy_get_name(buddy);
-				if (purple_buddy_get_account(buddy) == account && aim_ssi_waitingforauth(od->ssi.local, gname, bname)) {
-					if (purple_buddy_get_alias_only(buddy))
-						nombre = g_strdup_printf(" %s (%s)", bname, purple_buddy_get_alias_only(buddy));
-					else
-						nombre = g_strdup_printf(" %s", bname);
-					tmp = g_strdup_printf("%s%s<br>", text, nombre);
-					g_free(text);
-					text = tmp;
-					g_free(nombre);
-					num++;
-				}
-			}
+	buddies = purple_find_buddies(account, NULL);
+	while (buddies) {
+		PurpleBuddy *buddy;
+		const gchar *bname, *gname;
+
+		buddy = buddies->data;
+		bname = purple_buddy_get_name(buddy);
+		gname = purple_group_get_name(purple_buddy_get_group(buddy));
+		if (aim_ssi_waitingforauth(od->ssi.local, gname, bname)) {
+			const gchar *alias = purple_buddy_get_alias_only(buddy);
+			if (alias)
+				tmp = g_strdup_printf("%s %s (%s)<br>", text, bname, alias);
+			else
+				tmp = g_strdup_printf("%s %s<br>", text, bname);
+			g_free(text);
+			text = tmp;
+
+			num++;
 		}
+
+		buddies = g_slist_delete_link(buddies, buddies);
 	}
 
 	if (!num) {
--- a/libpurple/protocols/silc/buddy.c	Mon Jun 01 03:34:02 2009 +0000
+++ b/libpurple/protocols/silc/buddy.c	Mon Jun 01 04:02:10 2009 +0000
@@ -1407,35 +1407,16 @@
 
 void silcpurple_send_buddylist(PurpleConnection *gc)
 {
-	PurpleBlistNode *gnode, *cnode, *bnode;
-	PurpleBuddy *buddy;
+	GSList *buddies;
 	PurpleAccount *account;
 
 	account = purple_connection_get_account(gc);
 
-	for (gnode = purple_blist_get_root();
-			gnode != NULL;
-			gnode = purple_blist_node_get_sibling_next(gnode))
+	for (buddies = purple_find_buddies(account, NULL); buddies;
+			buddies = g_slist_delete_link(buddies, buddies))
 	{
-		if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-		for (cnode = purple_blist_node_get_first_child(gnode);
-				cnode != NULL;
-				cnode = purple_blist_node_get_sibling_next(cnode))
-		{
-			if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
-			for (bnode = purple_blist_node_get_first_child(cnode);
-					bnode != NULL;
-					bnode = purple_blist_node_get_sibling_next(bnode))
-			{
-				if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-				buddy = (PurpleBuddy *)bnode;
-				if (purple_buddy_get_account(buddy) == account)
-					silcpurple_add_buddy_i(gc, buddy, TRUE);
-			}
-		}
+		PurpleBuddy *buddy = buddies->data;
+		silcpurple_add_buddy_i(gc, buddy, TRUE);
 	}
 }
 
--- a/libpurple/protocols/silc/ops.c	Mon Jun 01 03:34:02 2009 +0000
+++ b/libpurple/protocols/silc/ops.c	Mon Jun 01 04:02:10 2009 +0000
@@ -839,7 +839,7 @@
 
 			b = NULL;
 			if (public_key) {
-				PurpleBlistNode *gnode, *cnode, *bnode;
+				GSList *buddies;
 				const char *f;
 
 				pk = silc_pkcs_public_key_encode(public_key, &pk_len);
@@ -857,29 +857,13 @@
 				silc_free(pk);
 
 				/* Find buddy by associated public key */
-				for (gnode = purple_blist_get_root(); gnode;
-				     gnode = purple_blist_node_get_sibling_next(gnode)) {
-					if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-						continue;
-					for (cnode = purple_blist_node_get_first_child(gnode);
-							cnode;
-							cnode = purple_blist_node_get_sibling_next(cnode)) {
-						if( !PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-							continue;
-						for (bnode = purple_blist_node_get_first_child(cnode);
-								bnode;
-								bnode = purple_blist_node_get_sibling_next(bnode)) {
-							if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-								continue;
-							b = (PurpleBuddy *)bnode;
-							if (purple_buddy_get_account(b) != account)
-								continue;
-							f = purple_blist_node_get_string(bnode, "public-key");
-							if (f && !strcmp(f, buf))
-								goto cont;
-							b = NULL;
-						}
-					}
+				for (buddies = purple_find_buddies(account, NULL); buddies;
+						buddies = g_slist_delete_link(buddies, buddies)) {
+					b = buddies->data;
+					f = purple_blist_node_get_string(PURPLE_BLIST_NODE(b), "public-key");
+					if (purple_strequal(f, buf))
+						goto cont;
+					b = NULL;
 				}
 			}
 		cont:
--- a/libpurple/protocols/simple/simple.c	Mon Jun 01 03:34:02 2009 +0000
+++ b/libpurple/protocols/simple/simple.c	Mon Jun 01 04:02:10 2009 +0000
@@ -213,27 +213,18 @@
 }
 
 static void simple_get_buddies(PurpleConnection *gc) {
-	PurpleBlistNode *gnode, *cnode, *bnode;
+	GSList *buddies;
 	PurpleAccount *account;
 
 	purple_debug_info("simple", "simple_get_buddies\n");
 
 	account = purple_connection_get_account(gc);
-	for(gnode = purple_blist_get_root(); gnode;
-			gnode = purple_blist_node_get_sibling_next(gnode)) {
-		if(!PURPLE_BLIST_NODE_IS_GROUP(gnode)) continue;
-		for(cnode = purple_blist_node_get_first_child(gnode);
-				cnode;
-				cnode = purple_blist_node_get_sibling_next(cnode)) {
-			if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) continue;
-			for(bnode = purple_blist_node_get_first_child(cnode);
-					bnode;
-					bnode = purple_blist_node_get_sibling_next(bnode)) {
-				if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) continue;
-				if(purple_buddy_get_account((PurpleBuddy*)bnode) == account)
-					simple_add_buddy(gc, (PurpleBuddy*)bnode, (PurpleGroup *)gnode);
-			}
-		}
+	buddies = purple_find_buddies(account, NULL);
+	while (buddies) {
+		PurpleBuddy *buddy = buddies->data;
+		simple_add_buddy(gc, buddy, purple_buddy_get_group(buddy));
+
+		buddies = g_slist_delete_link(buddies, buddies);
 	}
 }
 
--- a/libpurple/protocols/zephyr/zephyr.c	Mon Jun 01 03:34:02 2009 +0000
+++ b/libpurple/protocols/zephyr/zephyr.c	Mon Jun 01 04:02:10 2009 +0000
@@ -1926,8 +1926,7 @@
 
 static void write_anyone(PurpleConnection *gc)
 {
-	PurpleBlistNode *gnode, *cnode, *bnode;
-	PurpleBuddy *b;
+	GSList *buddies;
 	char *fname;
 	FILE *fd;
 	PurpleAccount *account;
@@ -1940,29 +1939,12 @@
 	}
 
 	account = purple_connection_get_account(gc);
-	for (gnode = purple_blist_get_root();
-			gnode;
-			gnode = purple_blist_node_get_sibling_next(gnode)) {
-		if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-		for (cnode = purple_blist_node_get_first_child(gnode);
-				cnode;
-				cnode = purple_blist_node_get_sibling_next(cnode)) {
-			if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
-			for (bnode = purple_blist_node_get_first_child(cnode);
-					bnode;
-					bnode = purple_blist_node_get_sibling_next(bnode)) {
-				if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-				b = (PurpleBuddy *) bnode;
-				if (purple_buddy_get_account(b) == account) {
-					gchar *stripped_user = zephyr_strip_local_realm(zephyr, purple_buddy_get_name(b));
-					fprintf(fd, "%s\n", stripped_user);
-					g_free(stripped_user);
-				}
-			}
-		}
+	for (buddies = purple_find_buddies(account, NULL); buddies;
+			buddies = g_slist_delete_link(buddies, buddies)) {
+		PurpleBuddy *b = buddies->data;
+		gchar *stripped_user = zephyr_strip_local_realm(zephyr, purple_buddy_get_name(b));
+		fprintf(fd, "%s\n", stripped_user);
+		g_free(stripped_user);
 	}
 
 	fclose(fd);