summaryrefslogtreecommitdiff
path: root/src/gen_mod.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gen_mod.erl')
-rw-r--r--src/gen_mod.erl61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/gen_mod.erl b/src/gen_mod.erl
index 26e662dc..f9639719 100644
--- a/src/gen_mod.erl
+++ b/src/gen_mod.erl
@@ -31,12 +31,12 @@
-export([start/0, start_module/2, start_module/3,
stop_module/2, stop_module_keep_config/2, get_opt/3,
- get_opt/4, get_opt_host/3, db_type/1, db_type/2,
+ get_opt/4, get_opt_host/3, db_type/2, db_type/3,
get_module_opt/4, get_module_opt/5, get_module_opt_host/3,
loaded_modules/1, loaded_modules_with_opts/1,
get_hosts/2, get_module_proc/2, is_loaded/2,
start_modules/0, start_modules/1, stop_modules/0, stop_modules/1,
- default_db/1, v_db/1, opt_type/1, db_mod/2, db_mod/3]).
+ opt_type/1, db_mod/2, db_mod/3]).
%%-export([behaviour_info/1]).
@@ -52,6 +52,7 @@
-callback start(binary(), opts()) -> any().
-callback stop(binary()) -> any().
+-callback mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()].
-export_type([opts/0]).
-export_type([db_type/0]).
@@ -295,44 +296,46 @@ validate_opts(Module, Opts) ->
false
end, Opts).
--spec v_db(db_type() | internal) -> db_type().
-
-v_db(odbc) -> sql;
-v_db(sql) -> sql;
-v_db(internal) -> mnesia;
-v_db(mnesia) -> mnesia;
-v_db(riak) -> riak.
-
--spec db_type(opts()) -> db_type().
-
-db_type(Opts) ->
- db_type(global, Opts).
-
--spec db_type(binary() | global, atom() | opts()) -> db_type().
+-spec db_type(binary() | global, module()) -> db_type();
+ (opts(), module()) -> db_type().
+db_type(Opts, Module) when is_list(Opts) ->
+ db_type(global, Opts, Module);
db_type(Host, Module) when is_atom(Module) ->
- get_module_opt(Host, Module, db_type, fun v_db/1, default_db(Host));
-db_type(Host, Opts) when is_list(Opts) ->
- get_opt(db_type, Opts, fun v_db/1, default_db(Host)).
-
--spec default_db(binary() | global) -> db_type().
+ case catch Module:mod_opt_type(db_type) of
+ F when is_function(F) ->
+ case get_module_opt(Host, Module, db_type, F) of
+ undefined -> ejabberd_config:default_db(Host, Module);
+ Type -> Type
+ end;
+ _ ->
+ undefined
+ end.
-default_db(Host) ->
- ejabberd_config:get_option({default_db, Host}, fun v_db/1, mnesia).
+-spec db_type(binary(), opts(), module()) -> db_type().
+
+db_type(Host, Opts, Module) ->
+ case catch Module:mod_opt_type(db_type) of
+ F when is_function(F) ->
+ case get_opt(db_type, Opts, F) of
+ undefined -> ejabberd_config:default_db(Host, Module);
+ Type -> Type
+ end;
+ _ ->
+ undefined
+ end.
-spec db_mod(binary() | global | db_type(), module()) -> module().
-db_mod(odbc, Module) -> list_to_atom(atom_to_list(Module) ++ "_sql");
-db_mod(sql, Module) -> list_to_atom(atom_to_list(Module) ++ "_sql");
-db_mod(mnesia, Module) -> list_to_atom(atom_to_list(Module) ++ "_mnesia");
-db_mod(riak, Module) -> list_to_atom(atom_to_list(Module) ++ "_riak");
+db_mod(Type, Module) when is_atom(Type) ->
+ list_to_atom(atom_to_list(Module) ++ "_" ++ atom_to_list(Type));
db_mod(Host, Module) when is_binary(Host) orelse Host == global ->
db_mod(db_type(Host, Module), Module).
-spec db_mod(binary() | global, opts(), module()) -> module().
db_mod(Host, Opts, Module) when is_list(Opts) ->
- db_mod(db_type(Host, Opts), Module).
+ db_mod(db_type(Host, Opts, Module), Module).
-spec loaded_modules(binary()) -> [atom()].
@@ -380,6 +383,6 @@ get_module_proc(Host, Base) ->
is_loaded(Host, Module) ->
ets:member(ejabberd_modules, {Module, Host}).
-opt_type(default_db) -> fun v_db/1;
+opt_type(default_db) -> fun(T) when is_atom(T) -> T end;
opt_type(modules) -> fun (L) when is_list(L) -> L end;
opt_type(_) -> [default_db, modules].