aboutsummaryrefslogtreecommitdiff
path: root/src/gen_mod.erl
diff options
context:
space:
mode:
authorMickael Remond <mremond@process-one.net>2016-11-09 09:04:58 +0100
committerMickael Remond <mremond@process-one.net>2016-11-09 09:04:58 +0100
commit42bede77a1a36c6bbc1ce3c2728e8c3dd78eb5f2 (patch)
tree677c46157270f24a40200ebb21beb5ba0397d358 /src/gen_mod.erl
parentExpose unregister API command (diff)
parentSupport several groups separated by ; in add_rosteritem command (diff)
Merge branch 'master' of github.com:processone/ejabberd
Diffstat (limited to 'src/gen_mod.erl')
-rw-r--r--src/gen_mod.erl39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/gen_mod.erl b/src/gen_mod.erl
index c4306577c..aaf452aeb 100644
--- a/src/gen_mod.erl
+++ b/src/gen_mod.erl
@@ -308,10 +308,47 @@ get_opt_host(Host, Opts, Default) ->
Val = get_opt(host, Opts, fun iolist_to_binary/1, Default),
ejabberd_regexp:greplace(Val, <<"@HOST@">>, Host).
+
+get_module_mod_opt_type_fun(Module) ->
+ DBSubMods = ejabberd_config:v_dbs_mods(Module),
+ fun(Opt) ->
+ Res = lists:foldl(fun(Mod, {Funs, ArgsList, _} = Acc) ->
+ case catch Mod:mod_opt_type(Opt) of
+ Fun when is_function(Fun) ->
+ {[Fun | Funs], ArgsList, true};
+ L when is_list(L) ->
+ {Funs, L ++ ArgsList, true};
+ _ ->
+ Acc
+ end
+ end, {[], [], false}, [Module | DBSubMods]),
+ case Res of
+ {[], [], false} ->
+ throw({'EXIT', {undef, mod_opt_type}});
+ {[], Args, _} -> Args;
+ {Funs, _, _} ->
+ fun(Val) ->
+ lists:any(fun(F) ->
+ try F(Val) of
+ _ ->
+ true
+ catch {replace_with, _NewVal} = E ->
+ throw(E);
+ {invalid_syntax, _Error} = E2 ->
+ throw(E2);
+ _:_ ->
+ false
+ end
+ end, Funs)
+ end
+ end
+ end.
+
validate_opts(Module, Opts) ->
+ ModOptFun = get_module_mod_opt_type_fun(Module),
lists:filtermap(
fun({Opt, Val}) ->
- case catch Module:mod_opt_type(Opt) of
+ case catch ModOptFun(Opt) of
VFun when is_function(VFun) ->
try VFun(Val) of
_ ->