]> granicus.if.org Git - ejabberd/commitdiff
Get rid of direct calls to 'session' Mnesia table
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Wed, 30 May 2018 16:21:56 +0000 (19:21 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Wed, 30 May 2018 16:21:56 +0000 (19:21 +0300)
Fixes #2439

src/ejabberd_sm.erl
src/mod_configure.erl

index e35f31079841908fa34b79d5ccf06c3ab17e9fde..67fa8ca00bab5f79fb13d214aebc8faf0f51c767 100644 (file)
@@ -62,6 +62,7 @@
         connected_users_number/0,
         user_resources/2,
         kick_user/2,
+        kick_user/3,
         get_session_pid/3,
         get_session_sid/3,
         get_session_sids/2,
@@ -978,14 +979,23 @@ user_resources(User, Server) ->
     Resources = get_user_resources(User, Server),
     lists:sort(Resources).
 
+-spec kick_user(binary(), binary()) -> non_neg_integer().
 kick_user(User, Server) ->
     Resources = get_user_resources(User, Server),
-    lists:foreach(
-       fun(Resource) ->
-               PID = get_session_pid(User, Server, Resource),
-               ejabberd_c2s:route(PID, kick)
-       end, Resources),
-    length(Resources).
+    lists:foldl(
+      fun(Resource, Acc) ->
+             case kick_user(User, Server, Resource) of
+                 false -> Acc;
+                 true -> Acc + 1
+             end
+      end, 0, Resources).
+
+-spec kick_user(binary(), binary(), binary()) -> boolean().
+kick_user(User, Server, Resource) ->
+    case get_session_pid(User, Server, Resource) of
+       none -> false;
+       Pid -> ejabberd_c2s:route(Pid, kick)
+    end.
 
 make_sid() ->
     {p1_time_compat:unique_timestamp(), self()}.
index 471e2bcdc6f3eb66ad04af27623d828b73fa9643..74b3cc793603e57af07468cd4df282df1e7f93bc 100644 (file)
@@ -1552,39 +1552,17 @@ set_form(From, Host, ?NS_ADMINL(<<"delete-user">>),
      || {User, Server} <- ASL2],
     {result, undefined};
 set_form(From, Host, ?NS_ADMINL(<<"end-user-session">>),
-        Lang, XData) ->
+        _Lang, XData) ->
     AccountString = get_value(<<"accountjid">>, XData),
     JID = jid:decode(AccountString),
-    LUser = JID#jid.luser,
     LServer = JID#jid.lserver,
     true = LServer == Host orelse
             get_permission_level(From) == global,
-    Xmlelement = xmpp:serr_policy_violation(<<"has been kicked">>, Lang),
     case JID#jid.lresource of
-      <<>> ->
-         SIs = mnesia:dirty_select(session,
-                                   [{#session{usr = {LUser, LServer, '_'},
-                                              sid = '$1',
-                                              info = '$2',
-                                               _ = '_'},
-                                     [], [{{'$1', '$2'}}]}]),
-         Pids = [P || {{_, P}, Info} <- SIs,
-                      not proplists:get_bool(offline, Info)],
-         lists:foreach(fun(Pid) ->
-                               Pid ! {kick, kicked_by_admin, Xmlelement}
-                       end, Pids);
-      R ->
-         [{{_, Pid}, Info}] = mnesia:dirty_select(
-                                session,
-                                [{#session{usr = {LUser, LServer, R},
-                                           sid = '$1',
-                                           info = '$2',
-                                                     _ = '_'},
-                                  [], [{{'$1', '$2'}}]}]),
-         case proplists:get_bool(offline, Info) of
-           true -> ok;
-           false -> Pid ! {kick, kicked_by_admin, Xmlelement}
-         end
+       <<>> ->
+           ejabberd_sm:kick_user(JID#jid.luser, JID#jid.lserver);
+       R ->
+           ejabberd_sm:kick_user(JID#jid.luser, JID#jid.lserver, R)
     end,
     {result, undefined};
 set_form(From, Host,