mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Don't send ping if resource is gone
This commit is contained in:
parent
f61f5beb5b
commit
f4959c8b28
@ -138,29 +138,37 @@ handle_info({iq_reply, timeout, JID}, State) ->
|
||||
ejabberd_hooks:run(user_ping_timeout, State#state.host,
|
||||
[JID]),
|
||||
Timers = case State#state.timeout_action of
|
||||
kill ->
|
||||
#jid{user = User, server = Server,
|
||||
resource = Resource} =
|
||||
JID,
|
||||
case ejabberd_sm:get_session_pid(User, Server, Resource)
|
||||
of
|
||||
Pid when is_pid(Pid) -> ejabberd_c2s:close(Pid, ping_timeout);
|
||||
_ -> ok
|
||||
end,
|
||||
del_timer(JID, State#state.timers);
|
||||
_ ->
|
||||
State#state.timers
|
||||
end,
|
||||
kill ->
|
||||
#jid{user = User, server = Server,
|
||||
resource = Resource} =
|
||||
JID,
|
||||
case ejabberd_sm:get_session_pid(User, Server, Resource) of
|
||||
Pid when is_pid(Pid) ->
|
||||
ejabberd_c2s:close(Pid, ping_timeout);
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
del_timer(JID, State#state.timers);
|
||||
_ ->
|
||||
State#state.timers
|
||||
end,
|
||||
{noreply, State#state{timers = Timers}};
|
||||
handle_info({timeout, _TRef, {ping, JID}}, State) ->
|
||||
Host = State#state.host,
|
||||
From = jid:make(Host),
|
||||
IQ = #iq{from = From, to = JID, type = get, sub_els = [#ping{}]},
|
||||
ejabberd_router:route_iq(IQ, JID,
|
||||
gen_mod:get_module_proc(Host, ?MODULE),
|
||||
State#state.ping_ack_timeout),
|
||||
Timers = add_timer(JID, State#state.ping_interval,
|
||||
State#state.timers),
|
||||
Timers = case ejabberd_sm:get_session_pid(JID#jid.luser,
|
||||
JID#jid.lserver,
|
||||
JID#jid.lresource) of
|
||||
none ->
|
||||
del_timer(JID, State#state.timers);
|
||||
_ ->
|
||||
Host = State#state.host,
|
||||
From = jid:make(Host),
|
||||
IQ = #iq{from = From, to = JID, type = get, sub_els = [#ping{}]},
|
||||
ejabberd_router:route_iq(IQ, JID,
|
||||
gen_mod:get_module_proc(Host, ?MODULE),
|
||||
State#state.ping_ack_timeout),
|
||||
add_timer(JID, State#state.ping_interval,
|
||||
State#state.timers)
|
||||
end,
|
||||
{noreply, State#state{timers = Timers}};
|
||||
handle_info(Info, State) ->
|
||||
?WARNING_MSG("Unexpected info: ~p", [Info]),
|
||||
@ -243,10 +251,10 @@ unregister_iq_handlers(Host) ->
|
||||
add_timer(JID, Interval, Timers) ->
|
||||
LJID = jid:tolower(JID),
|
||||
NewTimers = case maps:find(LJID, Timers) of
|
||||
{ok, OldTRef} ->
|
||||
misc:cancel_timer(OldTRef),
|
||||
maps:remove(LJID, Timers);
|
||||
_ -> Timers
|
||||
{ok, OldTRef} ->
|
||||
misc:cancel_timer(OldTRef),
|
||||
maps:remove(LJID, Timers);
|
||||
_ -> Timers
|
||||
end,
|
||||
TRef = erlang:start_timer(Interval, self(), {ping, JID}),
|
||||
maps:put(LJID, TRef, NewTimers).
|
||||
@ -255,10 +263,10 @@ add_timer(JID, Interval, Timers) ->
|
||||
del_timer(JID, Timers) ->
|
||||
LJID = jid:tolower(JID),
|
||||
case maps:find(LJID, Timers) of
|
||||
{ok, TRef} ->
|
||||
misc:cancel_timer(TRef),
|
||||
maps:remove(LJID, Timers);
|
||||
_ -> Timers
|
||||
{ok, TRef} ->
|
||||
misc:cancel_timer(TRef),
|
||||
maps:remove(LJID, Timers);
|
||||
_ -> Timers
|
||||
end.
|
||||
|
||||
depends(_Host, _Opts) ->
|
||||
|
Loading…
Reference in New Issue
Block a user