mirror of
https://github.com/processone/ejabberd.git
synced 2025-01-03 18:02:28 +01:00
implemented timeout_action: none | kill. default is none
SVN Revision: 2402
This commit is contained in:
parent
458b28eeff
commit
548be039b3
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
%% External exports
|
%% External exports
|
||||||
-export([start/2,
|
-export([start/2,
|
||||||
|
stop/1,
|
||||||
start_link/2,
|
start_link/2,
|
||||||
send_text/2,
|
send_text/2,
|
||||||
send_element/2,
|
send_element/2,
|
||||||
@ -151,6 +152,9 @@ socket_type() ->
|
|||||||
get_presence(FsmRef) ->
|
get_presence(FsmRef) ->
|
||||||
gen_fsm:sync_send_all_state_event(FsmRef, {get_presence}, 1000).
|
gen_fsm:sync_send_all_state_event(FsmRef, {get_presence}, 1000).
|
||||||
|
|
||||||
|
stop(FsmRef) ->
|
||||||
|
gen_fsm:send_event(FsmRef, closed).
|
||||||
|
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% Callback functions from gen_fsm
|
%%% Callback functions from gen_fsm
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
-record(state, {host = "",
|
-record(state, {host = "",
|
||||||
send_pings = ?DEFAULT_SEND_PINGS,
|
send_pings = ?DEFAULT_SEND_PINGS,
|
||||||
ping_interval = ?DEFAULT_PING_INTERVAL,
|
ping_interval = ?DEFAULT_PING_INTERVAL,
|
||||||
|
timeout_action = none,
|
||||||
timers = ?DICT:new()}).
|
timers = ?DICT:new()}).
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
@ -95,6 +96,7 @@ stop(Host) ->
|
|||||||
init([Host, Opts]) ->
|
init([Host, Opts]) ->
|
||||||
SendPings = gen_mod:get_opt(send_pings, Opts, ?DEFAULT_SEND_PINGS),
|
SendPings = gen_mod:get_opt(send_pings, Opts, ?DEFAULT_SEND_PINGS),
|
||||||
PingInterval = gen_mod:get_opt(ping_interval, Opts, ?DEFAULT_PING_INTERVAL),
|
PingInterval = gen_mod:get_opt(ping_interval, Opts, ?DEFAULT_PING_INTERVAL),
|
||||||
|
TimeoutAction = gen_mod:get_opt(timeout_action, Opts, none),
|
||||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||||
mod_disco:register_feature(Host, ?NS_PING),
|
mod_disco:register_feature(Host, ?NS_PING),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PING,
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PING,
|
||||||
@ -115,6 +117,7 @@ init([Host, Opts]) ->
|
|||||||
{ok, #state{host = Host,
|
{ok, #state{host = Host,
|
||||||
send_pings = SendPings,
|
send_pings = SendPings,
|
||||||
ping_interval = PingInterval,
|
ping_interval = PingInterval,
|
||||||
|
timeout_action = TimeoutAction,
|
||||||
timers = ?DICT:new()}}.
|
timers = ?DICT:new()}}.
|
||||||
|
|
||||||
terminate(_Reason, #state{host = Host}) ->
|
terminate(_Reason, #state{host = Host}) ->
|
||||||
@ -142,6 +145,18 @@ handle_cast({stop_ping, JID}, State) ->
|
|||||||
handle_cast({iq_pong, JID, timeout}, State) ->
|
handle_cast({iq_pong, JID, timeout}, State) ->
|
||||||
Timers = del_timer(JID, State#state.timers),
|
Timers = del_timer(JID, State#state.timers),
|
||||||
ejabberd_hooks:run(user_ping_timeout, State#state.host, [JID]),
|
ejabberd_hooks:run(user_ping_timeout, State#state.host, [JID]),
|
||||||
|
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:stop(Pid);
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
{noreply, State#state{timers = Timers}};
|
{noreply, State#state{timers = Timers}};
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
Loading…
Reference in New Issue
Block a user