Skip to content

Commit

Permalink
Merge pull request #3255 from esl/multitenancy/mod_time
Browse files Browse the repository at this point in the history
Make mod_time multitenancy ready
  • Loading branch information
chrzaszcz authored Sep 10, 2021
2 parents b4b26dc + bb0829b commit ddd3533
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
2 changes: 2 additions & 0 deletions big_tests/dynamic_domains.spec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

{suites, "tests", mod_ping_SUITE}.

{suites, "tests", mod_time_SUITE}.

{suites, "tests", muc_SUITE}.
{skip_groups, "tests", muc_SUITE,
[register_over_s2s],
Expand Down
16 changes: 7 additions & 9 deletions big_tests/tests/mod_time_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ all() ->
[{group, mod_time}].

groups() ->
G = [{mod_time, [], [ask_for_time, time_service_discovery]}],
ct_helper:repeat_all_until_all_ok(G).
[{mod_time, [parallel], [ask_for_time, time_service_discovery]}].

suite() ->
escalus:suite().
Expand All @@ -40,19 +39,18 @@ suite() ->
%%--------------------------------------------------------------------

init_per_suite(Config) ->
dynamic_modules:start(<<"localhost">>, mod_time, []),
dynamic_modules:start(domain_helper:host_type(), mod_time, []),
escalus:init_per_suite(Config).

end_per_suite(Config) ->
dynamic_modules:stop(<<"localhost">>, mod_time),
dynamic_modules:stop(domain_helper:host_type(), mod_time),
escalus:end_per_suite(Config).

init_per_group(mod_time, Config) ->
escalus:create_users(Config, escalus:get_users([alice])).
Config.

end_per_group(mod_time, Config) ->
escalus:delete_users(Config, escalus:get_users([alice])).

Config.

init_per_testcase(CaseName, Config) ->
escalus:init_per_testcase(CaseName, Config).
Expand All @@ -65,7 +63,7 @@ end_per_testcase(CaseName, Config) ->
%%--------------------------------------------------------------------

ask_for_time(Config) ->
escalus:story(Config, [{alice, 1}], fun(Alice) ->
escalus:fresh_story(Config, [{alice, 1}], fun(Alice) ->
Server = escalus_users:get_server(Config, alice),
ID = escalus_stanza:id(),
TimeStanza = time_request_stanza(Server, ID),
Expand All @@ -83,7 +81,7 @@ ask_for_time(Config) ->
%%--------------------------------------------------------------------

time_service_discovery(Config) ->
escalus:story(
escalus:fresh_story(
Config, [{alice, 1}],
fun(Client) ->
ServJID = escalus_client:server(Client),
Expand Down
3 changes: 0 additions & 3 deletions src/mod_last.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@

-include("jlib.hrl").

-include("mod_privacy.hrl").
-include("mod_last.hrl").

%% ------------------------------------------------------------------
%% Backend callbacks

Expand Down
31 changes: 18 additions & 13 deletions src/mod_time.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,42 @@
-behaviour(gen_mod).
-behaviour(mongoose_module_metrics).

-export([start/2, stop/1, config_spec/0, process_local_iq/4]).
-export([start/2]).
-export([stop/1]).
-export([supported_features/0]).
-export([config_spec/0]).
-export([process_local_iq/5]).

-ignore_xref([process_local_iq/4]).
-ignore_xref([process_local_iq/5]).

-include("jlib.hrl").
-include("mongoose.hrl").
-include("mongoose_config_spec.hrl").

-xep([{xep, 202}, {version, "2.0"}]).
-xep([{xep, 82}, {version, "1.1"}]).

start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts,
one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
?NS_TIME, ?MODULE, process_local_iq, IQDisc).
start(HostType, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler_for_domain(HostType, ?NS_TIME, ejabberd_local,
fun ?MODULE:process_local_iq/5, #{}, IQDisc).


stop(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
?NS_TIME).
stop(HostType) ->
gen_iq_handler:remove_iq_handler_for_domain(HostType, ?NS_TIME, ejabberd_local).

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

-spec config_spec() -> mongoose_config_spec:config_section().
config_spec() ->
#section{
items = #{<<"iqdisc">> => mongoose_config_spec:iqdisc()}}.

process_local_iq(_From, _To, Acc, #iq{type = set, sub_el = SubEl} = IQ) ->
process_local_iq(Acc, _From, _To, #iq{type = set, sub_el = SubEl} = IQ, _Extra) ->
{Acc, IQ#iq{type = error, sub_el = [SubEl, mongoose_xmpp_errors:not_allowed()]}};

process_local_iq(_From, _To, Acc, #iq{type = get} = IQ) ->
process_local_iq(Acc, _From, _To, #iq{type = get} = IQ, _Extra) ->
{UTC, TZODiff} = calculate_time(),
R = IQ#iq{type = result,
sub_el =
Expand Down

0 comments on commit ddd3533

Please sign in to comment.