]> granicus.if.org Git - ejabberd/commitdiff
implemented timeout_action: none | kill. default is none
authorEvgeniy Khramtsov <xramtsov@gmail.com>
Thu, 30 Jul 2009 10:25:54 +0000 (10:25 +0000)
committerEvgeniy Khramtsov <xramtsov@gmail.com>
Thu, 30 Jul 2009 10:25:54 +0000 (10:25 +0000)
SVN Revision: 2402

src/ejabberd_c2s.erl
src/mod_ping.erl

index b0c7b7df77d44186fcc0656a6bd6136063331976..4d41beb2d6685947c39b94f08ab9e91e560ca811 100644 (file)
@@ -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
 %%%----------------------------------------------------------------------
index 353644b14d74a5afc9d0338febf7edb3295b703e..0f5e8ff8d3cf3f8201f137c992aa2858529be6c3 100644 (file)
@@ -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}.