pidgin: 03dc4939: jabber: Adjust amount of data to send in...

malu at pidgin.im malu at pidgin.im
Thu Mar 18 17:25:37 EDT 2010


-----------------------------------------------------------------
Revision: 03dc4939efd70cfe4da6cda40c143a6f6913e1af
Ancestor: 6fbd38d2c19152635e0bd90f861c4c7e5315c4bb
Author: malu at pidgin.im
Date: 2010-03-18T21:19:44
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/03dc4939efd70cfe4da6cda40c143a6f6913e1af

Modified files:
        libpurple/protocols/jabber/ibb.c
        libpurple/protocols/jabber/ibb.h
        libpurple/protocols/jabber/si.c

ChangeLog: 

jabber: Adjust amount of data to send in IBB packets so that at most block-size
bytes of BASE64-encoded data is sent, based on discussion on the standars at j.o
list. Keep accepting receiving packets containing up to block-size bytes of
decoded data to stay compatible with previous version, and other clients who
made that assuption.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/ibb.c	e34ce2522b378bdde90d1cd86ece8268253b17e6
+++ libpurple/protocols/jabber/ibb.c	f6b5e1df23bafdbb210d1a2b3f59a5434dd18496
@@ -157,6 +157,12 @@ jabber_ibb_session_set_block_size(Jabber
 	}
 }
 
+gsize
+jabber_ibb_session_get_max_data_size(const JabberIBBSession *sess)
+{
+	return (gsize) floor((sess->block_size - 2) * (float) 3 / 4);
+}
+
 gpointer
 jabber_ibb_session_get_user_data(JabberIBBSession *sess)
 {
@@ -321,7 +327,7 @@ jabber_ibb_session_send_data(JabberIBBSe
 	if (state != JABBER_IBB_SESSION_OPENED) {
 		purple_debug_error("jabber",
 			"trying to send data on a non-open IBB session\n");
-	} else if (size > jabber_ibb_session_get_block_size(sess)) {
+	} else if (size > jabber_ibb_session_get_max_data_size(sess)) {
 		purple_debug_error("jabber",
 			"trying to send a too large packet in the IBB session\n");
 	} else {
@@ -416,6 +422,10 @@ jabber_ibb_parse(JabberStream *js, const
 						purple_debug_info("jabber",
 							"got %" G_GSIZE_FORMAT " bytes of data on IBB stream\n",
 							size);
+						/* we accept other clients to send up to block-size
+						 of _unencoded_ data, since there's been some confusions
+						 regarding the interpretation of this attribute
+						 (including previous versions of libpurple) */
 						if (size > jabber_ibb_session_get_block_size(sess)) {
 							purple_debug_error("jabber",
 								"IBB: received a too large packet\n");
============================================================
--- libpurple/protocols/jabber/ibb.h	c5afef20541df6cfcdd2a30691ae582416f00cef
+++ libpurple/protocols/jabber/ibb.h	0d642a447c408bdd4fe7c4fffb41ab8944477f9b
@@ -107,6 +107,10 @@ void jabber_ibb_session_set_block_size(J
 gsize jabber_ibb_session_get_block_size(const JabberIBBSession *sess);
 void jabber_ibb_session_set_block_size(JabberIBBSession *sess, gsize size);
 
+/* get maximum size data block to send (in bytes) 
+ (before encoded to BASE64) */ 
+gsize jabber_ibb_session_get_max_data_size(const JabberIBBSession *sess);
+
 gpointer jabber_ibb_session_get_user_data(JabberIBBSession *sess);
 
 /* handle incoming packet */
============================================================
--- libpurple/protocols/jabber/si.c	26051599c6ee83fb299b0e65c669656bcb74aa26
+++ libpurple/protocols/jabber/si.c	7b9f4f692e35d3b14c4e3c6183dee94a753b3e14
@@ -1075,6 +1075,9 @@ jabber_si_xfer_ibb_open_cb(JabberStream 
 				jabber_si_xfer_ibb_error_cb);
 
 			jsx->ibb_session = sess;
+			/* we handle up to block-size bytes of decoded data, to handle
+			 clients interpreting the block-size attribute as that
+			 (see also remark in ibb.c) */
 			jsx->ibb_buffer =
 				purple_circ_buffer_new(jabber_ibb_session_get_block_size(sess));
 
@@ -1103,8 +1106,8 @@ jabber_si_xfer_ibb_write(const guchar *b
 {
 	JabberSIXfer *jsx = (JabberSIXfer *) xfer->data;
 	JabberIBBSession *sess = jsx->ibb_session;
-	gsize packet_size = len < jabber_ibb_session_get_block_size(sess) ?
-		len : jabber_ibb_session_get_block_size(sess);
+	gsize packet_size = len < jabber_ibb_session_get_max_data_size(sess) ?
+		len : jabber_ibb_session_get_max_data_size(sess);
 
 	jabber_ibb_session_send_data(sess, buffer, packet_size);
 
@@ -1170,7 +1173,7 @@ jabber_si_xfer_ibb_send_init(JabberStrea
 		purple_xfer_set_write_fnc(xfer, jabber_si_xfer_ibb_write);
 
 		jsx->ibb_buffer =
-			purple_circ_buffer_new(jabber_ibb_session_get_block_size(jsx->ibb_session));
+			purple_circ_buffer_new(jabber_ibb_session_get_max_data_size(jsx->ibb_session));
 
 		/* open the IBB session */
 		jabber_ibb_session_open(jsx->ibb_session);


More information about the Commits mailing list