Mercurial > pidgin.yaz
comparison libpurple/protocols/myspace/message.c @ 19248:d34e49d8fac7
Implement msim_msg_dictionary_parse() based on msim_parse_body(). This allows
msim_msg_get_dictionary() to work on incoming messages.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Sun, 19 Aug 2007 05:04:13 +0000 |
parents | 692b128fe74a |
children | cfbd89a98431 |
comparison
equal
deleted
inserted
replaced
19247:44b9e41bde2a | 19248:d34e49d8fac7 |
---|---|
995 * | 995 * |
996 * @param body_str The text of the dictionary to parse. Often the | 996 * @param body_str The text of the dictionary to parse. Often the |
997 * value for the 'body' field. | 997 * value for the 'body' field. |
998 * | 998 * |
999 * @return Hash table of the keys and values. Must g_hash_table_destroy() when done. | 999 * @return Hash table of the keys and values. Must g_hash_table_destroy() when done. |
1000 * | |
1001 * XXX TODO: This is deprecated in favor of msim_msg_dictionary_parse(); remove it. | |
1000 */ | 1002 */ |
1001 GHashTable * | 1003 GHashTable * |
1002 msim_parse_body(const gchar *body_str) | 1004 msim_parse_body(const gchar *body_str) |
1003 { | 1005 { |
1004 GHashTable *table; | 1006 GHashTable *table; |
1174 elem->type, name ? name : "(NULL)"); | 1176 elem->type, name ? name : "(NULL)"); |
1175 return NULL; | 1177 return NULL; |
1176 } | 1178 } |
1177 } | 1179 } |
1178 | 1180 |
1179 /** Parse a \034-deliminated and =-separated string into a dictionary. TODO */ | 1181 /** |
1182 * Parse a \x1c-separated "dictionary" of key=value pairs into a hash table. | |
1183 * | |
1184 * @param raw The text of the dictionary to parse. Often the | |
1185 * value for the 'body' field. | |
1186 * | |
1187 * @return A new MsimMessage *. Must msim_msg_free() when done. | |
1188 */ | |
1180 MsimMessage * | 1189 MsimMessage * |
1181 msim_msg_dictionary_parse(gchar *raw) | 1190 msim_msg_dictionary_parse(gchar *raw) |
1182 { | 1191 { |
1183 /* TODO - get code from msim_parse_body, but parse into MsimMessage */ | 1192 MsimMessage *dict; |
1184 return NULL; | 1193 gchar *item; |
1194 gchar **items; | |
1195 gchar **elements; | |
1196 guint i; | |
1197 | |
1198 g_return_val_if_fail(raw != NULL, NULL); | |
1199 | |
1200 dict = msim_msg_new(NULL); | |
1201 | |
1202 for (items = g_strsplit(raw, "\x1c", 0), i = 0; | |
1203 (item = items[i]); | |
1204 i++) { | |
1205 gchar *key, *value; | |
1206 | |
1207 elements = g_strsplit(item, "=", 2); | |
1208 | |
1209 key = elements[0]; | |
1210 if (!key) { | |
1211 purple_debug_info("msim", "msim_msg_parse_dictionary(%s): null key\n", | |
1212 raw); | |
1213 g_strfreev(elements); | |
1214 break; | |
1215 } | |
1216 | |
1217 value = elements[1]; | |
1218 if (!value) { | |
1219 purple_debug_info("msim", "msim_msg_parse_dictionary(%s): null value\n", | |
1220 raw); | |
1221 g_strfreev(elements); | |
1222 break; | |
1223 } | |
1224 | |
1225 #ifdef MSIM_DEBUG_PARSE | |
1226 purple_debug_info("msim_msg_parse_dictionary","-- %s: %s\n", key ? key : "(NULL)", | |
1227 value ? value : "(NULL)"); | |
1228 #endif | |
1229 /* TODO: free key; right now it is treated as static */ | |
1230 dict = msim_msg_append(dict, g_strdup(key), MSIM_TYPE_RAW, g_strdup(value)); | |
1231 | |
1232 g_strfreev(elements); | |
1233 } | |
1234 | |
1235 g_strfreev(items); | |
1236 | |
1237 return dict; | |
1185 } | 1238 } |
1186 | 1239 |
1187 /** Return an element as a new dictionary. Caller frees with msim_msg_free(). */ | 1240 /** Return an element as a new dictionary. Caller frees with msim_msg_free(). */ |
1188 MsimMessage * | 1241 MsimMessage * |
1189 msim_msg_get_dictionary(MsimMessage *msg, const gchar *name) | 1242 msim_msg_get_dictionary(MsimMessage *msg, const gchar *name) |