Mercurial > pidgin.yaz
changeset 28514:02c62c9ad822
merge of '72c558ad4f7ad4f6c3ef1347e9d202cebdfaed83'
and 'eb7f43240a9076b19941ad012cb5b9046f5cd0ce'
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Mon, 31 Aug 2009 20:07:36 +0000 |
parents | 7f447db0e03b (diff) 86e6df9a0c80 (current diff) |
children | 087ad09cd4f5 |
files | |
diffstat | 1 files changed, 31 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/data.c Mon Aug 31 16:12:03 2009 +0000 +++ b/libpurple/protocols/jabber/data.c Mon Aug 31 20:07:36 2009 +0000 @@ -56,31 +56,42 @@ JabberData * jabber_data_create_from_xml(xmlnode *tag) { - JabberData *data = g_new0(JabberData, 1); - gsize size; - gpointer raw_data = NULL; + JabberData *data; + gchar *raw_data = NULL; + const gchar *cid, *type; + + /* check if this is a "data" tag */ + if (strcmp(tag->name, "data") != 0) { + purple_debug_error("jabber", "Invalid data element\n"); + return NULL; + } + + cid = xmlnode_get_attrib(tag, "cid"); + type = xmlnode_get_attrib(tag, "type"); - if (data == NULL) { - purple_debug_error("jabber", "Could not allocate data object\n"); + if (!cid || !type) { + purple_debug_error("jabber", "cid or type missing\n"); + return NULL; + } + + raw_data = xmlnode_get_data(tag); + if (raw_data == NULL || *raw_data == '\0') { + g_free(raw_data); + return NULL; + } + + data = g_new0(JabberData, 1); + data->data = purple_base64_decode(raw_data, &data->size); + g_free(raw_data); + + if (data->data == NULL) { + purple_debug_error("jabber", "Malformed base64 data\n"); g_free(data); return NULL; } - /* check if this is a "data" tag */ - if (strcmp(tag->name, "data") != 0) { - purple_debug_error("jabber", "Invalid data element"); - g_free(data); - return NULL; - } - - data->cid = g_strdup(xmlnode_get_attrib(tag, "cid")); - data->type = g_strdup(xmlnode_get_attrib(tag, "type")); - - raw_data = xmlnode_get_data(tag); - data->data = purple_base64_decode(raw_data, &size); - data->size = size; - - g_free(raw_data); + data->cid = g_strdup(cid); + data->type = g_strdup(type); return data; }