26
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

Merge branch 'mod_ping_no_kill' of https://github.com/fdie/ejabberd into 3

This commit is contained in:
Badlop 2019-02-01 16:21:58 +01:00
commit 8baced0d8b
2 changed files with 26 additions and 21 deletions

View File

@ -173,4 +173,8 @@ calc_checksum(Data) ->
callback(undefined, IQRes, Fun) -> callback(undefined, IQRes, Fun) ->
Fun(IQRes); Fun(IQRes);
callback(Proc, IQRes, Ctx) -> callback(Proc, IQRes, Ctx) ->
Proc ! {iq_reply, IQRes, Ctx}. try
Proc ! {iq_reply, IQRes, Ctx}
catch _:badarg ->
ok
end.

View File

@ -122,10 +122,19 @@ handle_cast({start_ping, JID}, State) ->
handle_cast({stop_ping, JID}, State) -> handle_cast({stop_ping, JID}, State) ->
Timers = del_timer(JID, State#state.timers), Timers = del_timer(JID, State#state.timers),
{noreply, State#state{timers = Timers}}; {noreply, State#state{timers = Timers}};
handle_cast({iq_reply, timeout, JID}, State) -> handle_cast(Msg, State) ->
?WARNING_MSG("unexpected cast: ~p", [Msg]),
{noreply, State}.
handle_info({iq_reply, #iq{type = error}, JID}, State) ->
handle_info({iq_reply, timeout, JID}, State);
handle_info({iq_reply, #iq{}, _JID}, State) ->
{noreply, State};
handle_info({iq_reply, timeout, JID}, State) ->
Timers = del_timer(JID, State#state.timers),
ejabberd_hooks:run(user_ping_timeout, State#state.host, ejabberd_hooks:run(user_ping_timeout, State#state.host,
[JID]), [JID]),
Timers = case State#state.timeout_action of case State#state.timeout_action of
kill -> kill ->
#jid{user = User, server = Server, #jid{user = User, server = Server,
resource = Resource} = resource = Resource} =
@ -134,18 +143,10 @@ handle_cast({iq_reply, timeout, JID}, State) ->
of of
Pid when is_pid(Pid) -> ejabberd_c2s:close(Pid, ping_timeout); Pid when is_pid(Pid) -> ejabberd_c2s:close(Pid, ping_timeout);
_ -> ok _ -> ok
end, end;
del_timer(JID, State#state.timers); _ -> ok
_ ->
State#state.timers
end, end,
{noreply, State#state{timers = Timers}}; {noreply, State#state{timers = Timers}};
handle_cast({iq_reply, #iq{}, _JID}, State) ->
{noreply, State};
handle_cast(Msg, State) ->
?WARNING_MSG("unexpected cast: ~p", [Msg]),
{noreply, State}.
handle_info({timeout, _TRef, {ping, JID}}, State) -> handle_info({timeout, _TRef, {ping, JID}}, State) ->
Host = State#state.host, Host = State#state.host,
From = jid:remove_resource(JID), From = jid:remove_resource(JID),