mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Use user_receive_packet hook in mod_block_strangers
This commit is contained in:
parent
5a8dea1591
commit
b080b8f54d
@ -546,7 +546,7 @@ process_iq_in(State, #iq{} = IQ) ->
|
|||||||
|
|
||||||
-spec process_message_in(state(), message()) -> {boolean(), state()}.
|
-spec process_message_in(state(), message()) -> {boolean(), state()}.
|
||||||
process_message_in(State, #message{type = T} = Msg) ->
|
process_message_in(State, #message{type = T} = Msg) ->
|
||||||
case filter_incoming_message(State, Msg) of
|
case privacy_check_packet(State, Msg, in) of
|
||||||
allow ->
|
allow ->
|
||||||
{true, State};
|
{true, State};
|
||||||
deny when T == groupchat; T == headline ->
|
deny when T == groupchat; T == headline ->
|
||||||
@ -561,24 +561,6 @@ process_message_in(State, #message{type = T} = Msg) ->
|
|||||||
{false, State}
|
{false, State}
|
||||||
end.
|
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()}.
|
-spec process_presence_in(state(), presence()) -> {boolean(), state()}.
|
||||||
process_presence_in(#{lserver := LServer, pres_a := PresA} = State0,
|
process_presence_in(#{lserver := LServer, pres_a := PresA} = State0,
|
||||||
#presence{from = From, to = To, type = T} = Pres) ->
|
#presence{from = From, to = To, type = T} = Pres) ->
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
-export([start/2, stop/1,
|
-export([start/2, stop/1,
|
||||||
depends/2, mod_opt_type/1]).
|
depends/2, mod_opt_type/1]).
|
||||||
|
|
||||||
-export([filter_packet/3]).
|
-export([filter_packet/1]).
|
||||||
|
|
||||||
-include("xmpp.hrl").
|
-include("xmpp.hrl").
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
@ -41,18 +41,16 @@
|
|||||||
-define(SETS, gb_sets).
|
-define(SETS, gb_sets).
|
||||||
|
|
||||||
start(Host, _Opts) ->
|
start(Host, _Opts) ->
|
||||||
ejabberd_hooks:add(c2s_filter_incoming_packet, Host,
|
ejabberd_hooks:add(user_receive_packet, Host,
|
||||||
?MODULE, filter_packet, 50),
|
?MODULE, filter_packet, 25),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
stop(Host) ->
|
stop(Host) ->
|
||||||
ejabberd_hooks:delete(c2s_filter_incoming_packet, Host,
|
ejabberd_hooks:delete(user_receive_packet, Host,
|
||||||
?MODULE, filter_packet, 50),
|
?MODULE, filter_packet, 25),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
filter_packet(deny = Acc, _State, _Msg) ->
|
filter_packet({#message{} = Msg, State} = Acc) ->
|
||||||
Acc;
|
|
||||||
filter_packet(Acc, State, Msg) ->
|
|
||||||
From = xmpp:get_from(Msg),
|
From = xmpp:get_from(Msg),
|
||||||
LFrom = jid:tolower(From),
|
LFrom = jid:tolower(From),
|
||||||
LBFrom = jid:remove_resource(LFrom),
|
LBFrom = jid:remove_resource(LFrom),
|
||||||
@ -83,12 +81,13 @@ filter_packet(Acc, State, Msg) ->
|
|||||||
end,
|
end,
|
||||||
if
|
if
|
||||||
Drop ->
|
Drop ->
|
||||||
deny;
|
{drop, State};
|
||||||
true ->
|
true ->
|
||||||
Acc
|
Acc
|
||||||
end
|
end
|
||||||
end.
|
end;
|
||||||
|
filter_packet(Acc) ->
|
||||||
|
Acc.
|
||||||
|
|
||||||
sets_bare_member({U, S, <<"">>} = LBJID, Set) ->
|
sets_bare_member({U, S, <<"">>} = LBJID, Set) ->
|
||||||
case ?SETS:next(?SETS:iterator_from(LBJID, Set)) of
|
case ?SETS:next(?SETS:iterator_from(LBJID, Set)) of
|
||||||
|
Loading…
Reference in New Issue
Block a user