changeset 24400:9e0458c98b4c

This was originally a patch from Brian Geppert that corrected the 'silently truncates messages at 800 characters' bug in yahoo. I changed the patch to reflect the reality I saw, which is that the maximum message length is 946 bytes, but only 800 characters. It's possible to fall between 800 and 946 bytes but not exceed 800 characters by using multibyte characters.
author John Bailey <rekkanoryo@rekkanoryo.org>
date Thu, 13 Nov 2008 08:39:44 +0000
parents 9bdaf273c0ff
children f18f37a62971
files COPYRIGHT ChangeLog libpurple/protocols/yahoo/yahoo.c libpurple/protocols/yahoo/yahoo.h
diffstat 4 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/COPYRIGHT	Thu Nov 13 08:26:12 2008 +0000
+++ b/COPYRIGHT	Thu Nov 13 08:39:44 2008 +0000
@@ -145,6 +145,7 @@
 Evgueni V. Gavrilov
 Ignacy Gawedzki
 Georgi Georgiev
+Brian Geppert
 Thomas Gibson-Robinson
 Ike Gingerich
 Gustavo Giráldez
--- a/ChangeLog	Thu Nov 13 08:26:12 2008 +0000
+++ b/ChangeLog	Thu Nov 13 08:39:44 2008 +0000
@@ -7,6 +7,7 @@
 	  "Microsoft Internet Authority" certificates.  People that use
 	  --with-system-ssl-certs and GnuTLS need to include these in the
 	  system certs directory.
+	* Corrected maximum message lengths for Yahoo!
 
 	Pidgin:
 	* On GTK+ 2.14 and higher, we're using the gtk-tooltip-delay setting
--- a/libpurple/protocols/yahoo/yahoo.c	Thu Nov 13 08:26:12 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Thu Nov 13 08:39:44 2008 +0000
@@ -3619,8 +3619,26 @@
 	PurpleWhiteboard *wb;
 	int ret = 1;
 	YahooFriend *f = NULL;
+	gsize lenb = 0;
+	glong lenc = 0;
 
 	msg2 = yahoo_string_encode(gc, msg, &utf8);
+	
+	if(msg2) {
+		lenb = strlen(msg2);
+		lenc = g_utf8_strlen(msg2, -1);
+
+		if(lenb > YAHOO_MAX_MESSAGE_LENGTH_BYTES || lenc > YAHOO_MAX_MESSAGE_LENGTH_CHARS) {
+			purple_debug_info("yahoo", "Message too big.  Length is %" G_GSIZE_FORMAT
+					" bytes, %ld characters.  Max is %d bytes, %d chars."
+					"  Message is '%s'.\n", lenb, lenc, YAHOO_MAX_MESSAGE_LENGTH_BYTES,
+					YAHOO_MAX_MESSAGE_LENGTH_CHARS, msg2);
+			yahoo_packet_free(pkt);
+			g_free(msg);
+			g_free(msg2);
+			return -E2BIG;
+		}
+	}
 
 	yahoo_packet_hash(pkt, "ss", 1, purple_connection_get_display_name(gc), 5, who);
 	if ((f = yahoo_friend_find(gc, who)) && f->protocol)
--- a/libpurple/protocols/yahoo/yahoo.h	Thu Nov 13 08:26:12 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.h	Thu Nov 13 08:39:44 2008 +0000
@@ -182,6 +182,21 @@
 
 #define YAHOO_MAX_STATUS_MESSAGE_LENGTH (255)
 
+/*
+ * Current Maximum Length for Instant Messages
+ *
+ * This was found by experiment.
+ *
+ * The YMSG protocol allows a message of up to 948 bytes, but the official client
+ * limits to 800 characters.  According to experiments I conducted, it seems that
+ * the discrepancy is to allow some leeway for messages with mixed single- and
+ * multi-byte characters, as I was able to send messages of 840 and 932 bytes
+ * by using some multibyte characters (some random Chinese or Japanese characters,
+ * to be precise). - rekkanoryo
+ */
+#define YAHOO_MAX_MESSAGE_LENGTH_BYTES 948
+#define YAHOO_MAX_MESSAGE_LENGTH_CHARS 800
+
 /* sometimes i wish prpls could #include things from other prpls. then i could just
  * use the routines from libfaim and not have to admit to knowing how they work. */
 #define yahoo_put16(buf, data) ( \