comparison 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
comparison
equal deleted inserted replaced
19430:0104035fd510 19431:3b7539c7402e
248 } 248 }
249 249
250 return new_list; 250 return new_list;
251 } 251 }
252 252
253 /** Free a GList * of gchar * strings. */ 253 /** Free a GList * of MsimMessageElement *'s. */
254 void 254 void
255 msim_msg_list_free(GList *l) 255 msim_msg_list_free(GList *l)
256 { 256 {
257 257
258 for (; l != NULL; l = g_list_next(l)) { 258 for (; l != NULL; l = g_list_next(l)) {
259 g_free((gchar *)(l->data)); 259 MsimMessageElement *elem;
260
261 elem = (MsimMessageElement *)l->data;
262
263 /* Note that name is almost never dynamically allocated elsewhere;
264 * it is usually a static string, but not in lists. So cast it. */
265 g_free((gchar *)elem->name);
266 g_free(elem->data);
267 g_free(elem);
260 } 268 }
261 g_list_free(l); 269 g_list_free(l);
262 } 270 }
263 271
264 /** Parse a |-separated string into a new GList. Free with msim_msg_list_free(). */ 272 /** Parse a |-separated string into a new GList. Free with msim_msg_list_free(). */
273 list = NULL; 281 list = NULL;
274 282
275 /* TODO: escape/unescape /3 <-> | within list elements */ 283 /* TODO: escape/unescape /3 <-> | within list elements */
276 284
277 for (i = 0; array[i] != NULL; ++i) { 285 for (i = 0; array[i] != NULL; ++i) {
278 list = g_list_append(list, g_strdup(array[i])); 286 MsimMessageElement *elem;
287
288 /* Freed in msim_msg_list_free() */
289 elem = g_new0(MsimMessageElement, 1);
290
291 /* Give the element a name for debugging purposes.
292 * Not supposed to be looked up by this name; instead,
293 * lookup the elements by indexing the array. */
294 elem->name = g_strdup_printf("(list item #%d)", i);
295 elem->type = MSIM_TYPE_RAW;
296 elem->data = g_strdup(array[i]);
297
298 list = g_list_append(list, elem);
279 } 299 }
280 300
281 g_strfreev(array); 301 g_strfreev(array);
282 302
283 return list; 303 return list;