changeset 26620:2b7604ede0e4

Change purple_blist_get_buddies to return a list instead of the hash table. Closes #8644.
author Paul Aurich <paul@darkrain42.org>
date Sat, 11 Apr 2009 17:41:10 +0000
parents d7bd1431b989
children d68b338d9eed
files libpurple/blist.c libpurple/blist.h libpurple/protocols/bonjour/jabber.c
diffstat 3 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/blist.c	Sat Apr 11 02:55:46 2009 +0000
+++ b/libpurple/blist.c	Sat Apr 11 17:41:10 2009 +0000
@@ -699,10 +699,23 @@
 	return purplebuddylist ? purplebuddylist->root : NULL;
 }
 
-GHashTable *
+static void
+append_buddy(gpointer key, gpointer value, gpointer user_data)
+{
+	GSList **list = user_data;
+	*list = g_slist_prepend(*list, value);
+}
+
+GSList *
 purple_blist_get_buddies()
 {
-	return purplebuddylist ? purplebuddylist->buddies : NULL;
+	GSList *buddies = NULL;
+
+	if (!purplebuddylist)
+		return NULL;
+
+	g_hash_table_foreach(purplebuddylist->buddies, append_buddy, &buddies);
+	return buddies;
 }
 
 void *
--- a/libpurple/blist.h	Sat Apr 11 02:55:46 2009 +0000
+++ b/libpurple/blist.h	Sat Apr 11 17:41:10 2009 +0000
@@ -260,13 +260,14 @@
 PurpleBlistNode *purple_blist_get_root(void);
 
 /**
- * Returns the hash table of every buddy in the list.
+ * Returns a list of every buddy in the list.
  *
- * @return The hash table of every buddy in the list.
+ * @return A list of every buddy in the list. Caller is responsible for
+ *         freeing the list.
  *
  * @since 2.6.0
  */
-GHashTable *purple_blist_get_buddies(void);
+GSList *purple_blist_get_buddies(void);
 
 /**
  * Returns the UI data for the list.
--- a/libpurple/protocols/bonjour/jabber.c	Sat Apr 11 02:55:46 2009 +0000
+++ b/libpurple/protocols/bonjour/jabber.c	Sat Apr 11 17:41:10 2009 +0000
@@ -237,7 +237,7 @@
 };
 
 static void
-_match_buddies_by_address(gpointer key, gpointer value, gpointer data)
+_match_buddies_by_address(gpointer value, gpointer data)
 {
 	PurpleBuddy *pb = value;
 	PurpleAccount *account = NULL;
@@ -638,6 +638,7 @@
 	char *address_text = NULL;
 	struct _match_buddies_by_address_t *mbba;
 	BonjourJabberConversation *bconv;
+	GSList *buddies;
 
 	/* Check that it is a read condition */
 	if (condition != PURPLE_INPUT_READ)
@@ -658,7 +659,10 @@
 	mbba = g_new0(struct _match_buddies_by_address_t, 1);
 	mbba->address = address_text;
 	mbba->jdata = jdata;
-	g_hash_table_foreach(purple_blist_get_buddies(), _match_buddies_by_address, mbba);
+
+	buddies = purple_blist_get_buddies();
+	g_slist_foreach(buddies, _match_buddies_by_address, mbba);
+	g_slist_free(buddies);
 
 	if (mbba->matched_buddies == NULL) {
 		purple_debug_info("bonjour", "We don't like invisible buddies, this is not a superheros comic\n");
@@ -850,11 +854,15 @@
 bonjour_jabber_conv_match_by_ip(BonjourJabberConversation *bconv) {
 	BonjourJabber *jdata = ((BonjourData*) bconv->account->gc->proto_data)->jabber_data;
 	struct _match_buddies_by_address_t *mbba;
+	GSList *buddies;
 
 	mbba = g_new0(struct _match_buddies_by_address_t, 1);
 	mbba->address = bconv->ip;
 	mbba->jdata = jdata;
-	g_hash_table_foreach(purple_blist_get_buddies(), _match_buddies_by_address, mbba);
+
+	buddies = purple_blist_get_buddies();
+	g_slist_foreach(buddies, _match_buddies_by_address, mbba);
+	g_slist_free(buddies);
 
 	/* If there is exactly one match, use it */
 	if(mbba->matched_buddies != NULL) {