Mercurial > pidgin
changeset 17277:af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Fri, 01 Jun 2007 05:44:50 +0000 |
parents | b9c0a8bb94b9 |
children | 3907a1e63344 |
files | libpurple/protocols/myspace/message.c libpurple/protocols/myspace/message.h |
diffstat | 2 files changed, 49 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c Fri Jun 01 05:28:46 2007 +0000 +++ b/libpurple/protocols/myspace/message.c Fri Jun 01 05:44:50 2007 +0000 @@ -641,16 +641,60 @@ /** Return the data of an element of a given name, as a binary GString. * - * @return GString * of binary data, or NULL. + * @param binary_data A pointer to a new pointer, which will be filled in with the binary data. CALLER MUST g_free(). + * + * @param binary_length A pointer to an integer, which will be set to the binary data length. + * + * @return TRUE if successful, FALSE if not. */ -GString *msim_msg_get_binary(MsimMessage *msg, gchar *name) +gboolean msim_msg_get_binary(MsimMessage *msg, gchar *name, gchar **binary_data, guint *binary_length) { switch (elem->type) { + case MSIM_TYPE_STRING: + /* Currently, incoming messages get stored as MSIM_TYPE_STRING. + * This is fine for integers and strings, since they can easily be + * converted in msim_get_*, as desirable. However, it may not work + * well for binary strings. Consider: + * + * Incoming base64'd elements get tagged as MSIM_TYPE_STRING. + * msim_msg_get_binary() sees MSIM_TYPE_STRING, base64 decodes, returns. + * everything is fine. + * But then, msim_send() is called on the incoming message, which has + * a base64'd MSIM_TYPE_STRING that really is encoded binary. The values + * will be escaped since strings are escaped, and / becomes /2; no good. + * + * TODO: Make incoming messages be tagged with MSIM_TYPE_UNKNOWN, and + * converted appropriately. They can still be "strings", just they won't + * be tagged as MSIM_TYPE_STRING (as MSIM_TYPE_STRING is intended to be used + * by msimprpl code for things like instant messages - stuff that should be + * escaped if needed). DWIM. + */ + *binary_data = (guchar *)purple_base64_decode((gchar *)elem->data, binary_length); + return TRUE; + case MSIM_TYPE_BINARY: - return (GString *)elem->data; + { + GString *gs; + + gs = (GString *)elem->data; + + /* Duplicate data, so caller can g_free() it. */ + *binary_data = g_new0(char, gs->len); + memcpy(*binary_data, gs->data, gs->len); + + *binary_length = gs->len; + + return TRUE; + } + + + /* Rejected because if it isn't already a GString, have to g_new0 it and + * then caller has to ALSO free the GString! + * + * return (GString *)elem->data; */ default: - return NULL; + return FALSE; } }
--- a/libpurple/protocols/myspace/message.h Fri Jun 01 05:28:46 2007 +0000 +++ b/libpurple/protocols/myspace/message.h Fri Jun 01 05:44:50 2007 +0000 @@ -60,6 +60,6 @@ MsimMessageElement *msim_msg_get_element(MsimMessage *msg, gchar *name); gchar *msim_msg_get_string(MsimMessage *msg, gchar *name); guint msim_msg_get_integer(MsimMessage *msg, gchar *name); -GString *msim_msg_get_binary(MsimMessage *msg, gchar *name); +gboolean msim_msg_get_binary(MsimMessage *msg, gchar *name, gchar **binary_data, guint *binary_length); #endif /* _MYSPACE_MESSAGE_H */