25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

ejabberd_c2s: Don't close session on stream resume

Don't let ejabberd_c2s close the session and unset presence if a
'c2s_terminated' callback stops hook execution, as is done in
mod_stream_mgmt:c2s_terminated/2 on resumption.

Fixes #1680.
This commit is contained in:
Holger Weiss 2017-04-19 01:20:28 +02:00
parent 7c9415356d
commit b8a7720986

View File

@ -258,7 +258,8 @@ reject_unauthenticated_packet(State, _Pkt) ->
process_closed(State, Reason) -> process_closed(State, Reason) ->
stop(State#{stop_reason => Reason}). stop(State#{stop_reason => Reason}).
process_terminated(#{sockmod := SockMod, socket := Socket, jid := JID} = State, process_terminated(#{sid := SID, sockmod := SockMod, socket := Socket,
jid := JID, user := U, server := S, resource := R} = State,
Reason) -> Reason) ->
Status = format_reason(State, Reason), Status = format_reason(State, Reason),
?INFO_MSG("(~s) Closing c2s session for ~s: ~s", ?INFO_MSG("(~s) Closing c2s session for ~s: ~s",
@ -269,8 +270,11 @@ process_terminated(#{sockmod := SockMod, socket := Socket, jid := JID} = State,
status = xmpp:mk_text(Status), status = xmpp:mk_text(Status),
from = JID, from = JID,
to = jid:remove_resource(JID)}, to = jid:remove_resource(JID)},
ejabberd_sm:close_session_unset_presence(SID, U, S, R,
Status),
broadcast_presence_unavailable(State, Pres); broadcast_presence_unavailable(State, Pres);
false -> false ->
ejabberd_sm:close_session(SID, U, S, R),
State State
end, end,
bounce_message_queue(), bounce_message_queue(),
@ -560,17 +564,6 @@ handle_cast(Msg, #{lserver := LServer} = State) ->
handle_info(Info, #{lserver := LServer} = State) -> handle_info(Info, #{lserver := LServer} = State) ->
ejabberd_hooks:run_fold(c2s_handle_info, LServer, State, [Info]). ejabberd_hooks:run_fold(c2s_handle_info, LServer, State, [Info]).
terminate(Reason, #{sid := SID,
user := U, server := S, resource := R,
lserver := LServer} = State) ->
case maps:is_key(pres_last, State) of
true ->
Status = format_reason(State, Reason),
ejabberd_sm:close_session_unset_presence(SID, U, S, R, Status);
false ->
ejabberd_sm:close_session(SID, U, S, R)
end,
ejabberd_hooks:run_fold(c2s_terminated, LServer, State, [Reason]);
terminate(Reason, #{lserver := LServer} = State) -> terminate(Reason, #{lserver := LServer} = State) ->
ejabberd_hooks:run_fold(c2s_terminated, LServer, State, [Reason]). ejabberd_hooks:run_fold(c2s_terminated, LServer, State, [Reason]).