Mercurial > pidgin
changeset 29612:8f442c566ff2
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@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.
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Thu, 18 Mar 2010 21:19:44 +0000 |
parents | ffc1f997cb91 |
children | 79c6f28e44ec |
files | libpurple/protocols/jabber/ibb.c libpurple/protocols/jabber/ibb.h libpurple/protocols/jabber/si.c |
diffstat | 3 files changed, 21 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/ibb.c Wed Mar 17 20:42:48 2010 +0000 +++ b/libpurple/protocols/jabber/ibb.c Thu Mar 18 21:19:44 2010 +0000 @@ -157,6 +157,12 @@ } } +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 @@ 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 @@ 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");
--- a/libpurple/protocols/jabber/ibb.h Wed Mar 17 20:42:48 2010 +0000 +++ b/libpurple/protocols/jabber/ibb.h Thu Mar 18 21:19:44 2010 +0000 @@ -107,6 +107,10 @@ 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 */
--- a/libpurple/protocols/jabber/si.c Wed Mar 17 20:42:48 2010 +0000 +++ b/libpurple/protocols/jabber/si.c Thu Mar 18 21:19:44 2010 +0000 @@ -1075,6 +1075,9 @@ 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 @@ { 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 @@ 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);