Mercurial > pidgin
changeset 28948:8271e42acdcb
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Closes #8356
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Wed, 03 Feb 2010 21:11:25 +0000 |
parents | 81a60d12897f |
children | 3422481df7ba bf0db10b0e3c |
files | ChangeLog libpurple/protocols/jabber/data.h libpurple/protocols/jabber/message.c |
diffstat | 3 files changed, 35 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Feb 03 20:15:19 2010 +0000 +++ b/ChangeLog Wed Feb 03 21:11:25 2010 +0000 @@ -33,6 +33,9 @@ with some clients. * Don't do an SRV lookup for a STUN server associated with the account if one is already set globally in prefs. + * Don't send custom smileys larger than the recommended maximum object size + specified in the BoB XEP. Will prevent getting disconnected because of + sending to large stanzas. Yahoo: * Don't send <span> and </span> tags. (Fartash Faghri)
--- a/libpurple/protocols/jabber/data.h Wed Feb 03 20:15:19 2010 +0000 +++ b/libpurple/protocols/jabber/data.h Wed Feb 03 21:11:25 2010 +0000 @@ -26,6 +26,8 @@ #include <glib.h> +#define JABBER_DATA_MAX_SIZE 8192 + typedef struct { char *cid; char *type;
--- a/libpurple/protocols/jabber/message.c Wed Feb 03 20:15:19 2010 +0000 +++ b/libpurple/protocols/jabber/message.c Wed Feb 03 21:11:25 2010 +0000 @@ -862,6 +862,7 @@ for (; smileys ; smileys = g_list_delete_link(smileys, smileys)) { PurpleSmiley *smiley = (PurpleSmiley *) smileys->data; + const gchar *shortcut = purple_smiley_get_shortcut(smiley); const gssize len = strlen(shortcut); @@ -983,36 +984,46 @@ if (found_smileys) { gchar *smileyfied_xhtml = NULL; const GList *iterator; - + GList *valid_smileys = NULL; + for (iterator = found_smileys; iterator ; iterator = g_list_next(iterator)) { - const PurpleSmiley *smiley = - (PurpleSmiley *) iterator->data; + PurpleSmiley *smiley = (PurpleSmiley *) iterator->data; const gchar *shortcut = purple_smiley_get_shortcut(smiley); const JabberData *data = jabber_data_find_local_by_alt(shortcut); + PurpleStoredImage *image = purple_smiley_get_stored_image(smiley); - /* the object has not been sent before */ - if (!data) { - PurpleStoredImage *image = - purple_smiley_get_stored_image(smiley); - const gchar *ext = purple_imgstore_get_extension(image); - JabberStream *js = jm->js; + if (purple_imgstore_get_size(image) <= JABBER_DATA_MAX_SIZE) { + /* the object has not been sent before */ + if (!data) { + const gchar *ext = purple_imgstore_get_extension(image); + JabberStream *js = jm->js; - JabberData *new_data = - jabber_data_create_from_data(purple_imgstore_get_data(image), - purple_imgstore_get_size(image), - jabber_message_get_mimetype_from_ext(ext), js); - purple_debug_info("jabber", - "cache local smiley alt = %s, cid = %s\n", - shortcut, jabber_data_get_cid(new_data)); - jabber_data_associate_local(new_data, shortcut); - } + JabberData *new_data = + jabber_data_create_from_data(purple_imgstore_get_data(image), + purple_imgstore_get_size(image), + jabber_message_get_mimetype_from_ext(ext), js); + purple_debug_info("jabber", + "cache local smiley alt = %s, cid = %s\n", + shortcut, jabber_data_get_cid(new_data)); + jabber_data_associate_local(new_data, shortcut); + } + valid_smileys = g_list_append(valid_smileys, smiley); + } else { + gchar *msg = + g_strdup_printf(_("Custom smiley with shortcut %s is too large to send."), + purple_smiley_get_shortcut(smiley)); + purple_conversation_write(conv, NULL, msg, + PURPLE_MESSAGE_ERROR, time(NULL)); + g_free(msg); + } } smileyfied_xhtml = - jabber_message_get_smileyfied_xhtml(xhtml, found_smileys); + jabber_message_get_smileyfied_xhtml(xhtml, valid_smileys); g_list_free(found_smileys); + g_list_free(valid_smileys); return smileyfied_xhtml; }