# HG changeset patch # User Jeffrey Connelly # Date 1187499853 0 # Node ID d34e49d8fac7437c52d56f653f07d6ca04c1d13c # Parent 44b9e41bde2a1d140b5cdfc754d4712c3d4b13d4 Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows msim_msg_get_dictionary() to work on incoming messages. diff -r 44b9e41bde2a -r d34e49d8fac7 libpurple/protocols/myspace/message.c --- a/libpurple/protocols/myspace/message.c Wed Aug 15 15:41:33 2007 +0000 +++ b/libpurple/protocols/myspace/message.c Sun Aug 19 05:04:13 2007 +0000 @@ -997,6 +997,8 @@ * value for the 'body' field. * * @return Hash table of the keys and values. Must g_hash_table_destroy() when done. + * + * XXX TODO: This is deprecated in favor of msim_msg_dictionary_parse(); remove it. */ GHashTable * msim_parse_body(const gchar *body_str) @@ -1176,12 +1178,63 @@ } } -/** Parse a \034-deliminated and =-separated string into a dictionary. TODO */ +/** + * Parse a \x1c-separated "dictionary" of key=value pairs into a hash table. + * + * @param raw The text of the dictionary to parse. Often the + * value for the 'body' field. + * + * @return A new MsimMessage *. Must msim_msg_free() when done. + */ MsimMessage * msim_msg_dictionary_parse(gchar *raw) { - /* TODO - get code from msim_parse_body, but parse into MsimMessage */ - return NULL; + MsimMessage *dict; + gchar *item; + gchar **items; + gchar **elements; + guint i; + + g_return_val_if_fail(raw != NULL, NULL); + + dict = msim_msg_new(NULL); + + for (items = g_strsplit(raw, "\x1c", 0), i = 0; + (item = items[i]); + i++) { + gchar *key, *value; + + elements = g_strsplit(item, "=", 2); + + key = elements[0]; + if (!key) { + purple_debug_info("msim", "msim_msg_parse_dictionary(%s): null key\n", + raw); + g_strfreev(elements); + break; + } + + value = elements[1]; + if (!value) { + purple_debug_info("msim", "msim_msg_parse_dictionary(%s): null value\n", + raw); + g_strfreev(elements); + break; + } + +#ifdef MSIM_DEBUG_PARSE + purple_debug_info("msim_msg_parse_dictionary","-- %s: %s\n", key ? key : "(NULL)", + value ? value : "(NULL)"); +#endif + /* TODO: free key; right now it is treated as static */ + dict = msim_msg_append(dict, g_strdup(key), MSIM_TYPE_RAW, g_strdup(value)); + + g_strfreev(elements); + } + + g_strfreev(items); + + return dict; } /** Return an element as a new dictionary. Caller frees with msim_msg_free(). */