Skip to content

Commit 945f34e

Browse files
committed
Merge remote-tracking branch 'processone/pr/360'
* processone/pr/360: mod_spam_filter: domains node can not be `none` mod_spam_filter: cancel existing timer on reload or terminate
2 parents 7d867fe + 3b0feb8 commit 945f34e

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

mod_spam_filter/src/mod_spam_filter.erl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ mod_opt_type(rtbl_host) ->
160160
econf:enum([none]),
161161
econf:host());
162162
mod_opt_type(rtbl_domains_node) ->
163-
econf:either(
164-
none,
165-
econf:binary()).
163+
econf:non_empty(econf:binary()).
166164

167165
-spec mod_options(binary()) -> [{atom(), any()}].
168166
mod_options(_Host) ->
@@ -295,7 +293,9 @@ handle_cast({dump, XML}, #state{dump_fd = Fd} = State) ->
295293
handle_cast({reload, NewOpts, OldOpts},
296294
#state{host = Host,
297295
rtbl_host = OldRTBLHost,
298-
rtbl_domains_node = OldRTBLDomainsNode} = State) ->
296+
rtbl_domains_node = OldRTBLDomainsNode,
297+
rtbl_retry_timer = RTBLRetryTimer} = State) ->
298+
misc:cancel_timer(RTBLRetryTimer),
299299
State1 = case {gen_mod:get_opt(spam_dump_file, OldOpts),
300300
gen_mod:get_opt(spam_dump_file, NewOpts)} of
301301
{OldDumpFile, NewDumpFile} when NewDumpFile /= OldDumpFile ->
@@ -375,8 +375,13 @@ handle_info(Info, State) ->
375375
{noreply, State}.
376376

377377
-spec terminate(normal | shutdown | {shutdown, term()} | term(), state()) -> ok.
378-
terminate(Reason, #state{host = Host, rtbl_host = RTBLHost, rtbl_domains_node = RTBLDomainsNode} = State) ->
378+
terminate(Reason,
379+
#state{host = Host,
380+
rtbl_host = RTBLHost,
381+
rtbl_domains_node = RTBLDomainsNode,
382+
rtbl_retry_timer = RTBLRetryTimer} = State) ->
379383
?DEBUG("Stopping spam filter process for ~s: ~p", [Host, Reason]),
384+
misc:cancel_timer(RTBLRetryTimer),
380385
DumpFile = gen_mod:get_module_opt(Host, ?MODULE, spam_dump_file),
381386
DumpFile1 = expand_host(DumpFile, Host),
382387
close_dump_file(DumpFile1, State),
@@ -679,7 +684,7 @@ read_files(Files) ->
679684
-spec line_parser(Type :: atom()) -> fun((binary()) -> binary()).
680685
line_parser(jid) -> fun parse_jid/1;
681686
line_parser(url) -> fun parse_url/1;
682-
line_parser(_) -> fun trim/1.
687+
line_parser(_) -> fun trim/1.
683688

684689
-spec read_file(filename(), fun((binary()) -> ljid() | url()))
685690
-> jid_set() | url_set().
@@ -934,7 +939,7 @@ get_commands_spec() ->
934939
args = [{host, binary}, {domain, binary}],
935940
result = {res, restuple}}
936941
].
937-
942+
938943
for_all_hosts(F, A) ->
939944
try lists:map(
940945
fun(Host) ->
@@ -968,13 +973,13 @@ reload_spam_filter_files(Host) ->
968973
LServer = jid:nameprep(Host),
969974
Files = #{domains => gen_mod:get_module_opt(LServer, ?MODULE, spam_domains_file),
970975
jid => gen_mod:get_module_opt(LServer, ?MODULE, spam_jids_file),
971-
url => gen_mod:get_module_opt(LServer, ?MODULE, spam_urls_file)},
976+
url => gen_mod:get_module_opt(LServer, ?MODULE, spam_urls_file)},
972977
case try_call_by_host(Host, {reload_files, Files}) of
973978
{spam_filter, ok} ->
974979
ok;
975980
{spam_filter, {error, Txt}} ->
976981
{error, binary_to_list(Txt)};
977-
{error, _R} = Error ->
982+
{error, _R} = Error ->
978983
Error
979984
end.
980985

@@ -1031,7 +1036,7 @@ expire_spam_filter_cache(Host, Age) ->
10311036
Error
10321037
end.
10331038

1034-
-spec add_to_spam_filter_cache(binary(), binary()) -> [{binary(), integer()}] | {error, string()}.
1039+
-spec add_to_spam_filter_cache(binary(), binary()) -> [{binary(), integer()}] | {error, string()}.
10351040
add_to_spam_filter_cache(<<"global">>, JID) ->
10361041
for_all_hosts(fun add_to_spam_filter_cache/2, [JID]);
10371042
add_to_spam_filter_cache(Host, EncJID) ->

mod_spam_filter/src/mod_spam_filter_rtbl.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ parse_blocked_domains(#iq{to = #jid{lserver = LServer}, type = result} = IQ) ->
5656

5757
-spec parse_pubsub_event(stanza()) -> #{binary() => any()}.
5858
parse_pubsub_event(#message{to = #jid{lserver = LServer}} = Msg) ->
59-
RTBLDomainsNode = gen_mod:get_module_opt(LServer, ?SERVICE_MODULE, rtbl_domains_node),
59+
RTBLDomainsNode = gen_mod:get_module_opt(LServer, ?SERVICE_MODULE, rtbl_domains_node),
6060
case xmpp:get_subtag(Msg, #ps_event{}) of
6161
#ps_event{items = #ps_items{node = RTBLDomainsNode, retract = ID}} when ID /= undefined ->
6262
?DEBUG("Got item to retract:~n~p", [ID]),

0 commit comments

Comments
 (0)