From f0d55c9a3faf9d9796fca560065ddbd433c02e02 Mon Sep 17 00:00:00 2001 From: Pablo Polvorin Date: Sun, 1 Mar 2009 20:18:42 +0000 Subject: [PATCH] Fix bug when clients connect using legacy ssl (ejabberd_receiver:process_data/2 was called before initializing the xmlstream). SVN Revision: 1933 --- ChangeLog | 4 ++++ src/ejabberd_receiver.erl | 38 +++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 73d3abb4f..724a6ead9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ * src/ejabberd_auth_anonymous.erl: Host argument for ejabberd_hooks's functions must be in binary() format. + * src/ejabberd_receiver.erl: Fix bug when clients connect using legacy + ssl (ejabberd_receiver:process_data/2 was called before initializing + the xmlstream). + 2009-02-28 Badlop * src/mod_pubsub/node_default.erl: Fix that non-subscriber could diff --git a/src/ejabberd_receiver.erl b/src/ejabberd_receiver.erl index 95e153554..8d13eb497 100644 --- a/src/ejabberd_receiver.erl +++ b/src/ejabberd_receiver.erl @@ -132,9 +132,8 @@ init([Socket, SockMod, Shaper, MaxStanzaSize]) -> %% {stop, Reason, State} %% Description: Handling call messages %%-------------------------------------------------------------------- -handle_call({starttls, TLSSocket}, _From, - #state{xml_stream_state = XMLStreamState} = State) -> - NewXMLStreamState = do_reset_stream(XMLStreamState), +handle_call({starttls, TLSSocket}, _From, State) -> + NewXMLStreamState = do_reset_stream(State), NewState = State#state{socket = TLSSocket, sock_mod = tls, xml_stream_state = NewXMLStreamState}, @@ -165,17 +164,8 @@ handle_call(reset_stream, _From, {reply, Reply, State#state{xml_stream_state = NewXMLStreamState}, ?HIBERNATE_TIMEOUT}; handle_call({become_controller, C2SPid}, _From, State) -> - Parser = exmpp_xml:start_parser([ - {names_as_atom, true}, - {check_nss, xmpp}, - {check_elems, xmpp}, - {check_attrs, xmpp}, - {max_size, State#state.max_stanza_size} - ]), - XMLStreamState = exmpp_xmlstream:start( - {gen_fsm, C2SPid}, Parser, - [{xmlstreamstart, new}] - ), + close_stream(State#state.xml_stream_state), + XMLStreamState = new_xmlstream(C2SPid, State#state.max_stanza_size), NewState = State#state{c2s_pid = C2SPid, xml_stream_state = XMLStreamState}, activate_socket(NewState), @@ -327,8 +317,22 @@ close_stream(XMLStreamState) -> exmpp_xmlstream:stop(XMLStreamState). -do_reset_stream(undefined) -> - undefined; +do_reset_stream(#state{xml_stream_state = undefined, c2s_pid = C2SPid, max_stanza_size = MaxStanzaSize}) -> + new_xmlstream(C2SPid, MaxStanzaSize); -do_reset_stream(XMLStreamState) -> +do_reset_stream(#state{xml_stream_state = XMLStreamState}) -> exmpp_xmlstream:reset(XMLStreamState). + + +new_xmlstream(C2SPid, MaxStanzaSize) -> + Parser = exmpp_xml:start_parser([ + {names_as_atom, true}, + {check_nss, xmpp}, + {check_elems, xmpp}, + {check_attrs, xmpp}, + {max_size, MaxStanzaSize} + ]), + exmpp_xmlstream:start( + {gen_fsm, C2SPid}, Parser, + [{xmlstreamstart, new}] + ).