summaryrefslogtreecommitdiff
path: root/src/gen_mod.erl
diff options
context:
space:
mode:
authorPaweł Chmielowski <pchmielowski@process-one.net>2016-11-04 12:57:57 +0100
committerPaweł Chmielowski <pchmielowski@process-one.net>2016-11-04 12:58:08 +0100
commit62db0309421b9152361aa946c6b9319b8274edd4 (patch)
tree2db77224c290d02909a95c897ec2842b3b03e1f5 /src/gen_mod.erl
parentAppend ; to privacy_list_data exporting lines (thanks to Marcio Luciano Donada) (diff)
Merge mod_opt_type from db sub-modules to main module mod_opt_type
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 c4306577..aaf452ae 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
_ ->