Skip to content

Commit

Permalink
Merge branch 'master' into module-opts-map-private
Browse files Browse the repository at this point in the history
  • Loading branch information
JanuszJakubiec authored and Janusz Jakubiec committed Feb 18, 2022
2 parents dca6612 + c431f16 commit 246a677
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
7 changes: 5 additions & 2 deletions big_tests/tests/mod_version_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
-include_lib("eunit/include/eunit.hrl").
-include_lib("escalus/include/escalus_xmlns.hrl").
-include_lib("exml/include/exml.hrl").

-import(config_parser_helper, [default_mod_config/1, mod_config/2]).
%%--------------------------------------------------------------------
%% Suite configuration
%%--------------------------------------------------------------------
Expand All @@ -31,10 +33,11 @@ end_per_suite(Config) ->
escalus:end_per_suite(Config).

init_per_group(soft_version, Config) ->
dynamic_modules:start(domain_helper:host_type(), mod_version, []),
dynamic_modules:start(domain_helper:host_type(), mod_version, default_mod_config(mod_version)),
Config;
init_per_group(soft_version_with_os, Config) ->
dynamic_modules:start(domain_helper:host_type(), mod_version, [{os_info, true}]),
ModuleConfig = mod_config(mod_version, #{os_info => true}),
dynamic_modules:start(domain_helper:host_type(), mod_version, ModuleConfig),
Config.

end_per_group(_Group, Config) ->
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/mod_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This module provides the functionality specified in [XEP-0092: Software Version]

### `modules.mod_version.iqdisc.type`
* **Syntax:** string, one of `"one_queue"`, `"no_queue"`, `"queues"`, `"parallel"`
* **Default:** `"one_queue"`
* **Default:** `"no_queue"`

Strategy to handle incoming stanzas. For details, please refer to
[IQ processing policies](../configuration/Modules.md#iq-processing-policies).
Expand Down
10 changes: 6 additions & 4 deletions src/mod_version.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
-xep([{xep, 92}, {version, "1.1"}]).

-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> any().
start(HostType, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, no_queue),
start(HostType, #{iqdisc := IQDisc}) ->
gen_iq_handler:add_iq_handler_for_domain(HostType, ?NS_VERSION, ejabberd_local,
fun ?MODULE:process_iq/5, #{}, IQDisc).

Expand All @@ -35,7 +34,10 @@ config_spec() ->
#section{
items = #{<<"iqdisc">> => mongoose_config_spec:iqdisc(),
<<"os_info">> => #option{type = boolean}
}
},
defaults = #{<<"iqdisc">> => no_queue,
<<"os_info">> => false},
format_items = map
}.

-spec process_iq(mongoose_acc:t(), jid:jid(), jid:jid(), jlib:iq(), any()) ->
Expand All @@ -58,7 +60,7 @@ process_iq(Acc, _From, _To, #iq{type = get} = IQ, _Extra) ->

-spec add_os_info(mongooseim:host_type()) -> [exml:element()] | [].
add_os_info(HostType) ->
case gen_mod:get_module_opt(HostType, ?MODULE, os_info, false) of
case gen_mod:get_module_opt(HostType, ?MODULE, os_info) of
true ->
[#xmlel{name = <<"os">>, attrs = [],
children = [#xmlcdata{content = os_info()}]}];
Expand Down
6 changes: 4 additions & 2 deletions test/common/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ all_modules() ->
{max_items_node, 1000},
{pep_mapping, [{<<"urn:xmpp:microblog:0">>, <<"mb">>}]},
{plugins, [<<"flat">>, <<"pep">>]}],
mod_version => [{os_info, true}],
mod_version => mod_config(mod_version, #{os_info => true}),
mod_auth_token => #{backend => rdbms,
validity_period => #{access => #{unit => minutes, value => 13},
refresh => #{unit => days, value => 13}},
Expand Down Expand Up @@ -834,4 +834,6 @@ default_mod_config(mod_inbox) ->
reset_markers => [<<"displayed">>],
iqdisc => no_queue};
default_mod_config(mod_private) ->
#{iqdisc => one_queue, backend => rdbms}.
#{iqdisc => one_queue, backend => rdbms};
default_mod_config(mod_version) ->
#{iqdisc => no_queue, os_info => false}.
8 changes: 5 additions & 3 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3034,10 +3034,12 @@ mod_vcard_ldap_search_reported(_Config) ->
?errh(T(RequiredOpts#{<<"vcard_field">> := -1})).

mod_version(_Config) ->
check_module_defaults(mod_version),
check_iqdisc_map(mod_version),
P = [modules, mod_version],
T = fun(Opts) -> #{<<"modules">> => #{<<"mod_version">> => Opts}} end,
?cfgh(modopts(mod_version, [{os_info, false}]), T(#{<<"os_info">> => false})),
?errh(T(#{<<"os_info">> => 1})),
check_iqdisc(mod_version).
?cfgh(P ++ [os_info], true, T(#{<<"os_info">> => true})),
?errh(T(#{<<"os_info">> => 1})).

modules_without_config(_Config) ->
?cfgh(modopts(mod_amp, []), #{<<"modules">> => #{<<"mod_amp">> => #{}}}),
Expand Down

0 comments on commit 246a677

Please sign in to comment.