aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <xramtsov@gmail.com>2009-07-30 10:25:54 +0000
committerEvgeniy Khramtsov <xramtsov@gmail.com>2009-07-30 10:25:54 +0000
commit548be039b3f865c1b601364997d00292a096d52f (patch)
tree23d523f54fd1f4e24a6dcfaf1ebba9470317831a
parentXMPP Ping support (thanks to Brian Cully) (diff)
implemented timeout_action: none | kill. default is none
SVN Revision: 2402
-rw-r--r--src/ejabberd_c2s.erl4
-rw-r--r--src/mod_ping.erl15
2 files changed, 19 insertions, 0 deletions
diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl
index b0c7b7df7..4d41beb2d 100644
--- a/src/ejabberd_c2s.erl
+++ b/src/ejabberd_c2s.erl
@@ -32,6 +32,7 @@
%% External exports
-export([start/2,
+ stop/1,
start_link/2,
send_text/2,
send_element/2,
@@ -151,6 +152,9 @@ socket_type() ->
get_presence(FsmRef) ->
gen_fsm:sync_send_all_state_event(FsmRef, {get_presence}, 1000).
+stop(FsmRef) ->
+ gen_fsm:send_event(FsmRef, closed).
+
%%%----------------------------------------------------------------------
%%% Callback functions from gen_fsm
%%%----------------------------------------------------------------------
diff --git a/src/mod_ping.erl b/src/mod_ping.erl
index 353644b14..0f5e8ff8d 100644
--- a/src/mod_ping.erl
+++ b/src/mod_ping.erl
@@ -58,6 +58,7 @@
-record(state, {host = "",
send_pings = ?DEFAULT_SEND_PINGS,
ping_interval = ?DEFAULT_PING_INTERVAL,
+ timeout_action = none,
timers = ?DICT:new()}).
%%====================================================================
@@ -95,6 +96,7 @@ stop(Host) ->
init([Host, Opts]) ->
SendPings = gen_mod:get_opt(send_pings, Opts, ?DEFAULT_SEND_PINGS),
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),
mod_disco:register_feature(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,
send_pings = SendPings,
ping_interval = PingInterval,
+ timeout_action = TimeoutAction,
timers = ?DICT:new()}}.
terminate(_Reason, #state{host = Host}) ->
@@ -142,6 +145,18 @@ handle_cast({stop_ping, JID}, State) ->
handle_cast({iq_pong, JID, timeout}, State) ->
Timers = del_timer(JID, State#state.timers),
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}};
handle_cast(_Msg, State) ->
{noreply, State}.