diff options
Diffstat (limited to 'src/gen_mod.erl')
-rw-r--r-- | src/gen_mod.erl | 72 |
1 files changed, 60 insertions, 12 deletions
diff --git a/src/gen_mod.erl b/src/gen_mod.erl index c45642d47..26e662dc6 100644 --- a/src/gen_mod.erl +++ b/src/gen_mod.erl @@ -35,7 +35,8 @@ 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/1, default_db/1, v_db/1, opt_type/1]). + 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]). %%-export([behaviour_info/1]). @@ -47,7 +48,7 @@ opts = [] :: opts() | '_' | '$2'}). -type opts() :: [{atom(), any()}]. --type db_type() :: odbc | mnesia | riak. +-type db_type() :: sql | mnesia | riak. -callback start(binary(), opts()) -> any(). -callback stop(binary()) -> any(). @@ -64,23 +65,38 @@ start() -> {keypos, #ejabberd_module.module_host}]), ok. +-spec start_modules() -> any(). + +%% Start all the modules in all the hosts +start_modules() -> + lists:foreach( + fun(Host) -> + start_modules(Host) + end, ?MYHOSTS). + +get_modules_options(Host) -> + ejabberd_config:get_option( + {modules, Host}, + fun(Mods) -> + lists:map( + fun({M, A}) when is_atom(M), is_list(A) -> + {M, A} + end, Mods) + end, []). + -spec start_modules(binary()) -> any(). start_modules(Host) -> - Modules = ejabberd_config:get_option( - {modules, Host}, - fun(L) when is_list(L) -> L end, []), + Modules = get_modules_options(Host), lists:foreach( - fun({Module, Opts}) -> - start_module(Host, Module, Opts) - end, Modules). + fun({Module, Opts}) -> + start_module(Host, Module, Opts) + end, Modules). -spec start_module(binary(), atom()) -> any(). start_module(Host, Module) -> - Modules = ejabberd_config:get_option( - {modules, Host}, - fun(L) when is_list(L) -> L end, []), + Modules = get_modules_options(Host), case lists:keyfind(Module, 1, Modules) of {_, Opts} -> start_module(Host, Module, Opts); @@ -121,6 +137,23 @@ is_app_running(AppName) -> lists:keymember(AppName, 1, application:which_applications(Timeout)). +-spec stop_modules() -> any(). + +stop_modules() -> + lists:foreach( + fun(Host) -> + stop_modules(Host) + end, ?MYHOSTS). + +-spec stop_modules(binary()) -> any(). + +stop_modules(Host) -> + Modules = get_modules_options(Host), + lists:foreach( + fun({Module, _Args}) -> + gen_mod:stop_module_keep_config(Host, Module) + end, Modules). + -spec stop_module(binary(), atom()) -> error | {aborted, any()} | {atomic, any()}. stop_module(Host, Module) -> @@ -264,7 +297,8 @@ validate_opts(Module, Opts) -> -spec v_db(db_type() | internal) -> db_type(). -v_db(odbc) -> odbc; +v_db(odbc) -> sql; +v_db(sql) -> sql; v_db(internal) -> mnesia; v_db(mnesia) -> mnesia; v_db(riak) -> riak. @@ -286,6 +320,20 @@ db_type(Host, Opts) when is_list(Opts) -> default_db(Host) -> ejabberd_config:get_option({default_db, Host}, fun v_db/1, mnesia). +-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(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). + -spec loaded_modules(binary()) -> [atom()]. loaded_modules(Host) -> |