diff libpurple/protocols/msn/msn.c @ 31166:2a5dbea6ab6b

Use a linked list to store MsnUserEndpoints instead of a hash table. This is per-buddy on MSN, and I expect most buddies to only have one or two endpoints (only be signed in from one or two locations), so I expect this to use less memory and not much less efficient.
author Mark Doliner <mark@kingant.net>
date Fri, 23 Apr 2010 00:24:07 +0000
parents e167de25e795
children f8ec889c5bce
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c	Thu Apr 22 21:06:41 2010 +0000
+++ b/libpurple/protocols/msn/msn.c	Fri Apr 23 00:24:07 2010 +0000
@@ -416,21 +416,6 @@
 }
 
 static void
-create_endpoint_fields(gpointer key, gpointer value, gpointer user_data)
-{
-	const char *id = key;
-	MsnUserEndpoint *ep = value;
-	MsnLocationData *data = user_data;
-	PurpleRequestField *field;
-
-	if (g_str_equal(id, data->session->guid))
-		return;
-
-	field = purple_request_field_bool_new(id, ep->name, FALSE);
-	purple_request_field_group_add_field(data->group, field);
-}
-
-static void
 msn_show_locations(PurplePluginAction *action)
 {
 	PurpleConnection *pc;
@@ -439,6 +424,7 @@
 	PurpleRequestFields *fields;
 	PurpleRequestFieldGroup *group;
 	PurpleRequestField *field;
+	GSList *l;
 	MsnLocationData *data;
 
 	pc = (PurpleConnection *)action->context;
@@ -462,12 +448,22 @@
 	purple_request_fields_add_group(fields, group);
 	field = purple_request_field_label_new("others-label", _("You can sign out from other locations here"));
 	purple_request_field_group_add_field(group, field);
-	
+
+	for (l = session->user->endpoints; l; l = l->next) {
+		MsnUserEndpoint *ep = l->data;
+
+		if (g_str_equal(ep->id, session->guid))
+			/* Don't add myself to the list */
+			continue;
+
+		field = purple_request_field_bool_new(ep->id, ep->name, FALSE);
+		purple_request_field_group_add_field(group, field);
+	}
+
 	data = g_new0(MsnLocationData, 1);
 	data->account = account;
 	data->session = session;
 	data->group = group;
-	g_hash_table_foreach(session->user->endpoints, create_endpoint_fields, data);
 
 	purple_request_fields(pc, NULL, NULL, NULL,
 	                      fields,