1
0
Fork 0
mirror of https://github.com/processone/ejabberd synced 2025-10-03 09:49:18 +02:00

mod_antispam: Move some definitions to a header file

This commit is contained in:
Badlop 2025-06-21 18:27:38 +02:00
parent b55b6f3d26
commit bddcf0624e
5 changed files with 37 additions and 18 deletions

26
include/mod_antispam.hrl Normal file
View file

@ -0,0 +1,26 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2025 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License along
%%% with this program; if not, write to the Free Software Foundation, Inc.,
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
%%%
%%%----------------------------------------------------------------------
-define(MODULE_ANTISPAM, mod_antispam).
-type url() :: binary().
-type filename() :: binary() | none | false.
-type jid_set() :: sets:set(ljid()).
-type url_set() :: sets:set(url()).

View file

@ -63,15 +63,11 @@
-include("ejabberd_commands.hrl"). -include("ejabberd_commands.hrl").
-include("logger.hrl"). -include("logger.hrl").
-include("mod_antispam.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-type url() :: binary().
-type filename() :: binary() | none | false.
-type jid_set() :: sets:set(ljid()).
-type url_set() :: sets:set(url()).
-record(state, -record(state,
{host = <<>> :: binary(), {host = <<>> :: binary(),
dump_fd = undefined :: file:io_device() | undefined, dump_fd = undefined :: file:io_device() | undefined,

View file

@ -38,14 +38,11 @@
-export([dump_spam_stanza/1, reopen_log/0]). -export([dump_spam_stanza/1, reopen_log/0]).
-include("logger.hrl"). -include("logger.hrl").
-include("mod_antispam.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-type filename() :: binary() | none | false.
-define(MODULE_PARENT, mod_antispam).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%%| Exported %%| Exported
@ -157,7 +154,7 @@ write_stanza_dump(Fd, XML) ->
%%| Auxiliary %%| Auxiliary
get_path_option(Host) -> get_path_option(Host) ->
Opts = gen_mod:get_module_opts(Host, ?MODULE_PARENT), Opts = gen_mod:get_module_opts(Host, ?MODULE_ANTISPAM),
get_path_option(Host, Opts). get_path_option(Host, Opts).
get_path_option(Host, Opts) -> get_path_option(Host, Opts) ->
@ -178,11 +175,11 @@ get_path_option(Host, Opts) ->
-spec get_proc_name(binary()) -> atom(). -spec get_proc_name(binary()) -> atom().
get_proc_name(Host) -> get_proc_name(Host) ->
gen_mod:get_module_proc(Host, ?MODULE_PARENT). gen_mod:get_module_proc(Host, ?MODULE_ANTISPAM).
-spec get_spam_filter_hosts() -> [binary()]. -spec get_spam_filter_hosts() -> [binary()].
get_spam_filter_hosts() -> get_spam_filter_hosts() ->
[H || H <- ejabberd_option:hosts(), gen_mod:is_loaded(H, ?MODULE_PARENT)]. [H || H <- ejabberd_option:hosts(), gen_mod:is_loaded(H, ?MODULE_ANTISPAM)].
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------

View file

@ -38,13 +38,12 @@
-include("logger.hrl"). -include("logger.hrl").
-include("translate.hrl"). -include("translate.hrl").
-include("mod_antispam.hrl").
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-type url() :: binary().
-type s2s_in_state() :: ejabberd_s2s_in:state(). -type s2s_in_state() :: ejabberd_s2s_in:state().
-define(MODULE_PARENT, mod_antispam).
-define(HTTPC_TIMEOUT, timer:seconds(3)). -define(HTTPC_TIMEOUT, timer:seconds(3)).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -128,9 +127,9 @@ s2s_in_handle_info(State, _) ->
-spec needs_checking(jid(), jid()) -> boolean(). -spec needs_checking(jid(), jid()) -> boolean().
needs_checking(#jid{lserver = FromHost} = From, #jid{lserver = LServer} = To) -> needs_checking(#jid{lserver = FromHost} = From, #jid{lserver = LServer} = To) ->
case gen_mod:is_loaded(LServer, ?MODULE_PARENT) of case gen_mod:is_loaded(LServer, ?MODULE_ANTISPAM) of
true -> true ->
Access = gen_mod:get_module_opt(LServer, ?MODULE_PARENT, access_spam), Access = gen_mod:get_module_opt(LServer, ?MODULE_ANTISPAM, access_spam),
case acl:match_rule(LServer, Access, To) of case acl:match_rule(LServer, Access, To) of
allow -> allow ->
?DEBUG("Spam not filtered for ~s", [jid:encode(To)]), ?DEBUG("Spam not filtered for ~s", [jid:encode(To)]),
@ -144,7 +143,7 @@ needs_checking(#jid{lserver = FromHost} = From, #jid{lserver = LServer} = To) ->
To) % likely a gateway To) % likely a gateway
end; end;
false -> false ->
?DEBUG("~s not loaded for ~s", [?MODULE_PARENT, LServer]), ?DEBUG("~s not loaded for ~s", [?MODULE_ANTISPAM, LServer]),
false false
end. end.
@ -292,7 +291,7 @@ reject(_) ->
-spec get_proc_name(binary()) -> atom(). -spec get_proc_name(binary()) -> atom().
get_proc_name(Host) -> get_proc_name(Host) ->
gen_mod:get_module_proc(Host, ?MODULE_PARENT). gen_mod:get_module_proc(Host, ?MODULE_ANTISPAM).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------

View file

@ -27,6 +27,7 @@
-include_lib("xmpp/include/xmpp.hrl"). -include_lib("xmpp/include/xmpp.hrl").
-include("logger.hrl"). -include("logger.hrl").
-include("mod_antispam.hrl").
-define(SERVICE_MODULE, mod_antispam). -define(SERVICE_MODULE, mod_antispam).
-define(SERVICE_JID_PREFIX, "rtbl-"). -define(SERVICE_JID_PREFIX, "rtbl-").