changeset 19431:3b7539c7402e

Now that MsimMessageElement's are more accessible outside message.c, change msim_msg_get_list() to return a GList of MsimMessageElements instead of strings. This just makes sense, because it gives myspace.c full access to the msim_msg_get_*_from_element() data conversion routines that give you an integer, unescaped string, etc. This fixes half of #2637, in that status messages now are unescaped (http://example.com/ used to show up as http://1/1example.com/1, but no more.)
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 26 Aug 2007 02:50:38 +0000
parents 0104035fd510
children 210f792efd7c
files libpurple/protocols/myspace/message.c libpurple/protocols/myspace/myspace.c
diffstat 2 files changed, 27 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c	Sun Aug 26 01:35:10 2007 +0000
+++ b/libpurple/protocols/myspace/message.c	Sun Aug 26 02:50:38 2007 +0000
@@ -250,13 +250,21 @@
 	return new_list;
 }
 
-/** Free a GList * of gchar * strings. */
+/** Free a GList * of MsimMessageElement *'s. */
 void
 msim_msg_list_free(GList *l)
 {
 
 	for (; l != NULL; l = g_list_next(l)) {
-		g_free((gchar *)(l->data));
+		MsimMessageElement *elem;
+
+		elem = (MsimMessageElement *)l->data;
+
+		/* Note that name is almost never dynamically allocated elsewhere;
+		 * it is usually a static string, but not in lists. So cast it. */
+		g_free((gchar *)elem->name);
+		g_free(elem->data);
+		g_free(elem);
 	}
 	g_list_free(l);
 }
@@ -275,7 +283,19 @@
 	/* TODO: escape/unescape /3 <-> | within list elements */
 	
 	for (i = 0; array[i] != NULL; ++i) {
-		list = g_list_append(list, g_strdup(array[i]));
+		MsimMessageElement *elem;
+
+		/* Freed in msim_msg_list_free() */
+		elem = g_new0(MsimMessageElement, 1);
+
+		/* Give the element a name for debugging purposes.
+		 * Not supposed to be looked up by this name; instead,
+		 * lookup the elements by indexing the array. */
+		elem->name = g_strdup_printf("(list item #%d)", i);
+		elem->type = MSIM_TYPE_RAW;
+		elem->data = g_strdup(array[i]);
+
+		list = g_list_append(list, elem);
 	}
 
 	g_strfreev(array);
--- a/libpurple/protocols/myspace/myspace.c	Sun Aug 26 01:35:10 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Sun Aug 26 02:50:38 2007 +0000
@@ -2991,9 +2991,9 @@
 	 */
 	list = msim_msg_get_list(msg, "msg");
 
-	status_code = atoi(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE));
+	status_code = msim_msg_get_integer_from_element(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE));
 	purple_debug_info("msim", "msim_status: %s's status code = %d\n", username, status_code);
-	status_headline = g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE);
+	status_headline = msim_msg_get_string_from_element(g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE));
 
 	blist = purple_get_blist();
 
@@ -3017,7 +3017,8 @@
 		purple_debug_info("msim", "msim_status: found buddy %s\n", username);
 	}
 
-	user->headline = g_strdup(status_headline);
+	/* don't copy; let the MsimUser own the headline, memory-wise */
+	user->headline = status_headline;
   
 	/* Set user status */
 	switch (status_code) {