ejabberd_c2s: Let stop/1 close XEP-0198 sessions
authorHolger Weiss <holger@zedat.fu-berlin.de>
Sat, 17 Oct 2015 21:15:31 +0000 (23:15 +0200)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Sat, 17 Oct 2015 21:15:31 +0000 (23:15 +0200)
The stop/1 function now terminates stream management sessions
immediately, just as it does for other sessions.  The new
ejabberd_c2s:close/1 function can be used to close the socket without
terminating the stream management session, like stop/1 did before.

src/ejabberd_c2s.erl
src/mod_ping.erl

index f48f44add7117910ee4e5d6a47b72b931cb1a426..69b4652384596df96ee54f7992b553d0a047cc5d 100644 (file)
@@ -43,6 +43,7 @@
 -export([start/2,
         stop/1,
         start_link/2,
+        close/1,
         send_text/2,
         send_element/2,
         socket_type/0,
@@ -251,7 +252,9 @@ send_filtered(FsmRef, Feature, From, To, Packet) ->
 broadcast(FsmRef, Type, From, Packet) ->
     FsmRef ! {broadcast, Type, From, Packet}.
 
-stop(FsmRef) -> (?GEN_FSM):send_event(FsmRef, closed).
+stop(FsmRef) -> (?GEN_FSM):send_event(FsmRef, stop).
+
+close(FsmRef) -> (?GEN_FSM):send_event(FsmRef, closed).
 
 %%%----------------------------------------------------------------------
 %%% Callback functions from gen_fsm
@@ -552,6 +555,8 @@ wait_for_stream({xmlstreamerror, _}, StateData) ->
     send_trailer(StateData),
     {stop, normal, StateData};
 wait_for_stream(closed, StateData) ->
+    {stop, normal, StateData};
+wait_for_stream(stop, StateData) ->
     {stop, normal, StateData}.
 
 wait_for_auth({xmlstreamelement, #xmlel{name = Name} = El}, StateData)
@@ -707,6 +712,8 @@ wait_for_auth({xmlstreamerror, _}, StateData) ->
     send_trailer(StateData),
     {stop, normal, StateData};
 wait_for_auth(closed, StateData) ->
+    {stop, normal, StateData};
+wait_for_auth(stop, StateData) ->
     {stop, normal, StateData}.
 
 wait_for_feature_request({xmlstreamelement, #xmlel{name = Name} = El},
@@ -869,6 +876,8 @@ wait_for_feature_request({xmlstreamerror, _},
     send_trailer(StateData),
     {stop, normal, StateData};
 wait_for_feature_request(closed, StateData) ->
+    {stop, normal, StateData};
+wait_for_feature_request(stop, StateData) ->
     {stop, normal, StateData}.
 
 wait_for_sasl_response({xmlstreamelement, #xmlel{name = Name} = El}, StateData)
@@ -980,6 +989,8 @@ wait_for_sasl_response({xmlstreamerror, _},
     send_trailer(StateData),
     {stop, normal, StateData};
 wait_for_sasl_response(closed, StateData) ->
+    {stop, normal, StateData};
+wait_for_sasl_response(stop, StateData) ->
     {stop, normal, StateData}.
 
 resource_conflict_action(U, S, R) ->
@@ -1086,6 +1097,8 @@ wait_for_bind({xmlstreamerror, _}, StateData) ->
     send_trailer(StateData),
     {stop, normal, StateData};
 wait_for_bind(closed, StateData) ->
+    {stop, normal, StateData};
+wait_for_bind(stop, StateData) ->
     {stop, normal, StateData}.
 
 wait_for_session({xmlstreamelement, #xmlel{name = Name} = El}, StateData)
@@ -1154,6 +1167,8 @@ wait_for_session({xmlstreamerror, _}, StateData) ->
     send_trailer(StateData),
     {stop, normal, StateData};
 wait_for_session(closed, StateData) ->
+    {stop, normal, StateData};
+wait_for_session(stop, StateData) ->
     {stop, normal, StateData}.
 
 session_established({xmlstreamelement, #xmlel{name = Name} = El}, StateData)
@@ -1205,6 +1220,8 @@ session_established(closed, #state{mgmt_state = active} = StateData) ->
     catch (StateData#state.sockmod):close(StateData#state.socket),
     fsm_next_state(wait_for_resume, StateData);
 session_established(closed, StateData) ->
+    {stop, normal, StateData};
+session_established(stop, StateData) ->
     {stop, normal, StateData}.
 
 %% Process packets sent by user (coming from user on c2s XMPP connection)
index 7d030685cd027bf17b6bd429843f3a900ce35485..b4e1041d55219220240823b14377074eff55be3a 100644 (file)
@@ -169,7 +169,7 @@ handle_cast({iq_pong, JID, timeout}, State) ->
              JID,
          case ejabberd_sm:get_session_pid(User, Server, Resource)
              of
-           Pid when is_pid(Pid) -> ejabberd_c2s:stop(Pid);
+           Pid when is_pid(Pid) -> ejabberd_c2s:close(Pid);
            _ -> ok
          end;
       _ -> ok