pidgin: 884bb785: jabber: Don't send custom smileys larger...

malu at pidgin.im malu at pidgin.im
Wed Feb 3 16:15:41 EST 2010


-----------------------------------------------------------------
Revision: 884bb785d674029cb52e46cb82a86241df13bf46
Ancestor: 8a52232908b9b170d0de8f3291482e1db49bd838
Author: malu at pidgin.im
Date: 2010-02-03T21:11:25
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/884bb785d674029cb52e46cb82a86241df13bf46

Modified files:
        ChangeLog libpurple/protocols/jabber/data.h
        libpurple/protocols/jabber/message.c

ChangeLog: 

jabber: Don't send custom smileys larger than the recommended maximum BoB size
Closes #8356

-------------- next part --------------
============================================================
--- ChangeLog	5f4d8a04f67b88e8f2cd192109e6501957fca3cb
+++ ChangeLog	6a1b6c6527a93a19e0d3e2f7045910584268b45c
@@ -33,6 +33,9 @@ version 2.6.6 (??/??/20??):
 	  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)
============================================================
--- libpurple/protocols/jabber/data.h	dcfa89336e98350268f3cc37b891b08db6ff9303
+++ libpurple/protocols/jabber/data.h	cb00d566b725ad66aa578f242509865f2ea01f8f
@@ -26,6 +26,8 @@
 
 #include <glib.h>
 
+#define JABBER_DATA_MAX_SIZE 8192
+
 typedef struct {
 	char *cid;
 	char *type;
============================================================
--- libpurple/protocols/jabber/message.c	0fbb879ce26e625a4965568890ed93c2ce689c73
+++ libpurple/protocols/jabber/message.c	6d343217b6bb0743d556cf3d8fe5609635aa7cae
@@ -862,6 +862,7 @@ jabber_message_xhtml_find_smileys(const 
 
 	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 @@ jabber_message_smileyfy_xhtml(JabberMess
 		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;
 		}


More information about the Commits mailing list