]> granicus.if.org Git - ejabberd/commitdiff
Use user_receive_packet hook in mod_block_strangers
authorAlexey Shchepin <alexey@process-one.net>
Mon, 16 Jan 2017 15:40:30 +0000 (18:40 +0300)
committerAlexey Shchepin <alexey@process-one.net>
Mon, 16 Jan 2017 15:40:30 +0000 (18:40 +0300)
src/ejabberd_c2s.erl
src/mod_block_strangers.erl

index 113be09109d32b9a9cc98c9434b0f4387c34ad10..ecd6321d4d1a00025aba4b2d2b748c8b699383b7 100644 (file)
@@ -546,7 +546,7 @@ process_iq_in(State, #iq{} = IQ) ->
 
 -spec process_message_in(state(), message()) -> {boolean(), state()}.
 process_message_in(State, #message{type = T} = Msg) ->
-    case filter_incoming_message(State, Msg) of
+    case privacy_check_packet(State, Msg, in) of
        allow ->
            {true, State};
        deny when T == groupchat; T == headline ->
@@ -561,24 +561,6 @@ process_message_in(State, #message{type = T} = Msg) ->
            {false, State}
     end.
 
-filter_incoming_message(State, Msg) ->
-    case privacy_check_packet(State, Msg, in) of
-        allow ->
-            #{lserver := LServer} = State,
-            case ejabberd_hooks:run_fold(
-                   c2s_filter_incoming_packet,
-                   LServer,
-                   allow,
-                   [State, Msg]) of
-                allow ->
-                    allow;
-                deny ->
-                    deny
-            end;
-        deny ->
-            deny
-    end.
-
 -spec process_presence_in(state(), presence()) -> {boolean(), state()}.
 process_presence_in(#{lserver := LServer, pres_a := PresA} = State0,
                    #presence{from = From, to = To, type = T} = Pres) ->
index bc329ea0b55bb85609496f1b7c6bc43d6a35df20..34a40d03626a660afb429b295e9adff0e1f34976 100644 (file)
@@ -32,7 +32,7 @@
 -export([start/2, stop/1,
          depends/2, mod_opt_type/1]).
 
--export([filter_packet/3]).
+-export([filter_packet/1]).
 
 -include("xmpp.hrl").
 -include("ejabberd.hrl").
 -define(SETS, gb_sets).
 
 start(Host, _Opts) ->
-    ejabberd_hooks:add(c2s_filter_incoming_packet, Host,
-                       ?MODULE, filter_packet, 50),
+    ejabberd_hooks:add(user_receive_packet, Host,
+                       ?MODULE, filter_packet, 25),
     ok.
 
 stop(Host) ->
-    ejabberd_hooks:delete(c2s_filter_incoming_packet, Host,
-                          ?MODULE, filter_packet, 50),
+    ejabberd_hooks:delete(user_receive_packet, Host,
+                          ?MODULE, filter_packet, 25),
     ok.
 
-filter_packet(deny = Acc, _State, _Msg) ->
-    Acc;
-filter_packet(Acc, State, Msg) ->
+filter_packet({#message{} = Msg, State} = Acc) ->
     From = xmpp:get_from(Msg),
     LFrom = jid:tolower(From),
     LBFrom = jid:remove_resource(LFrom),
@@ -83,12 +81,13 @@ filter_packet(Acc, State, Msg) ->
             end,
             if
                 Drop ->
-                    deny;
+                    {drop, State};
                 true ->
                     Acc
             end
-    end.
-
+    end;
+filter_packet(Acc) ->
+    Acc.
 
 sets_bare_member({U, S, <<"">>} = LBJID, Set) ->
     case ?SETS:next(?SETS:iterator_from(LBJID, Set)) of