diff libpurple/protocols/myspace/message.c @ 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 34a1957de14b
children 44b4e8bd759b
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);