Skip to content

Commit

Permalink
Merge pull request #3260 from esl/support-dynamic-domains-in-mod_csi
Browse files Browse the repository at this point in the history
Support dynamic domains in mod_csi
  • Loading branch information
chrzaszcz authored Sep 10, 2021
2 parents cf75dd9 + 0c6cddd commit 06912df
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
3 changes: 3 additions & 0 deletions big_tests/dynamic_domains.spec
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@

{suites, "tests", vcard_SUITE}.
{suites, "tests", vcard_simple_SUITE}.

{suites, "tests", xep_0352_csi_SUITE}.

{suites, "tests", domain_removal_SUITE}.

{config, ["dynamic_domains.config", "test.config"]}.
Expand Down
11 changes: 5 additions & 6 deletions big_tests/tests/xep_0352_csi_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

-compile([export_all]).

-import(domain_helper, [host_type/0]).

-define(CSI_BUFFER_MAX, 10).

all() ->
[{group, basic}].


groups() ->
G = [{basic, [parallel, shuffle], all_tests()}],
ct_helper:repeat_all_until_all_ok(G).
[{basic, [parallel, shuffle], all_tests()}].

all_tests() ->
[
Expand All @@ -32,13 +33,11 @@ suite() ->
escalus:suite().

init_per_suite(Config) ->
Domain = ct:get_config({hosts, mim, domain}),
dynamic_modules:start(Domain, mod_csi, [{buffer_max, ?CSI_BUFFER_MAX}]),
dynamic_modules:start(host_type(), mod_csi, [{buffer_max, ?CSI_BUFFER_MAX}]),
[{escalus_user_db, {module, escalus_ejabberd}} | escalus:init_per_suite(Config)].

end_per_suite(Config) ->
Domain = ct:get_config({hosts, mim, domain}),
dynamic_modules:stop(Domain, mod_csi),
dynamic_modules:stop(host_type(), mod_csi),
escalus_fresh:clean(),
escalus:end_per_suite(Config).

Expand Down
46 changes: 31 additions & 15 deletions src/mod_csi.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
-behaviour(gen_mod).
-behaviour(mongoose_module_metrics).

-export([start/2]).
-export([stop/1]).
-export([config_spec/0]).
%% gen_mod callbacks
-export([start/2,
stop/1,
config_spec/0,
supported_features/0]).

%% Hook handlers
-export([c2s_stream_features/3]).

-ignore_xref([c2s_stream_features/3]).
Expand All @@ -21,30 +25,42 @@

-export_type([state/0]).

start(Host, _Opts) ->
[ejabberd_hooks:add(Name, Host, Module, Function, Priority) ||
{Name, Module, Function, Priority} <- hooks()],
ensure_metrics(Host),
-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
start(HostType, _Opts) ->
ejabberd_hooks:add(hooks(HostType)),
ensure_metrics(HostType),
ok.

stop(Host) ->
[ejabberd_hooks:delete(Name, Host, Module, Function, Priority) ||
{Name, Module, Function, Priority} <- hooks()],
-spec stop(mongooseim:host_type()) -> ok.
stop(HostType) ->
ejabberd_hooks:delete(hooks(HostType)),
ok.

hooks(HostType) ->
[{c2s_stream_features, HostType, ?MODULE, c2s_stream_features, 60}].

ensure_metrics(HostType) ->
mongoose_metrics:ensure_metric(HostType, [HostType, modCSIInactive], spiral),
mongoose_metrics:ensure_metric(HostType, [HostType, modCSIInactive], spiral).

%%%
%%% config_spec
%%%

-spec config_spec() -> mongoose_config_spec:config_section().
config_spec() ->
#section{
items = #{<<"buffer_max">> => #option{type = int_or_infinity,
validate = non_negative}}
}.

hooks() ->
[{c2s_stream_features, ?MODULE, c2s_stream_features, 60}].
-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

ensure_metrics(Host) ->
mongoose_metrics:ensure_metric(Host, [Host, modCSIInactive], spiral),
mongoose_metrics:ensure_metric(Host, [Host, modCSIInactive], spiral).
%%%
%%% Hook handlers
%%%

-spec c2s_stream_features([exml:element()], mongooseim:host_type(), jid:lserver()) ->
[exml:element()].
Expand Down

0 comments on commit 06912df

Please sign in to comment.