From e1e75b28520f532216eb6ee2ee445e2a407234eb Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 5 Sep 2011 16:53:04 +0200 Subject: [PATCH] Fix support to negotiate zlib compression after starttls --- src/ejabberd_zlib.erl | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/ejabberd_zlib.erl b/src/ejabberd_zlib.erl index b67784f67..684e81f67 100644 --- a/src/ejabberd_zlib.erl +++ b/src/ejabberd_zlib.erl @@ -40,6 +40,12 @@ -define(DEFLATE, 1). -define(INFLATE, 2). +%% Copied from exmpp/src/core/exmpp_compress.erl +-record(compress_socket, {socket, + packet_mode = binary, + port + }). + start() -> exmpp_compress:start(). @@ -65,7 +71,20 @@ recv(Socket, Length) -> recv(ZlibSock, _Length, Timeout) -> exmpp_compress:recv(ZlibSock, Timeout). -recv_data(ZlibSock, Packet) -> +recv_data(#compress_socket{socket = {SockMod, Socket}} = ZlibSock, Packet) -> + case SockMod of + gen_tcp -> + recv_data2(ZlibSock, Packet); + _ -> + case SockMod:recv_data(Socket, Packet) of + {ok, Packet2} -> + recv_data2(ZlibSock, Packet2); + Error -> + Error + end + end. + +recv_data2(ZlibSock, Packet) -> exmpp_compress:recv_data(ZlibSock, Packet). send(ZlibSock, Packet) -> @@ -75,12 +94,6 @@ send(ZlibSock, Packet) -> setopts(ZlibSock, Opts) -> exmpp_compress:setopts(ZlibSock, Opts). -%% Copied from exmpp/src/core/exmpp_compress.erl --record(compress_socket, {socket, - packet_mode = binary, - port - }). - get_sockmod(#compress_socket{socket = {SockMod, _Port}}) -> SockMod.