2003-01-24 21:18:33 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : gen_mod.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2013-03-14 10:33:02 +01:00
|
|
|
%%% Purpose :
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 24 Jan 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2016-01-13 12:29:14 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2016 ProcessOne
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2015-08-05 09:52:54 +02:00
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
2003-01-24 21:18:33 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(gen_mod).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
-behaviour(ejabberd_config).
|
|
|
|
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-01-24 21:18:33 +01:00
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
-export([start/0, start_module/2, start_module/3,
|
|
|
|
stop_module/2, stop_module_keep_config/2, get_opt/3,
|
2016-04-27 16:10:50 +02:00
|
|
|
get_opt/4, get_opt_host/3, db_type/2, db_type/3,
|
2015-06-01 14:38:27 +02:00
|
|
|
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,
|
2016-03-29 15:25:24 +02:00
|
|
|
start_modules/0, start_modules/1, stop_modules/0, stop_modules/1,
|
2016-04-27 16:10:50 +02:00
|
|
|
opt_type/1, db_mod/2, db_mod/3]).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
|
|
|
%%-export([behaviour_info/1]).
|
2003-01-24 21:18:33 +01:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2003-01-24 21:18:33 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-record(ejabberd_module,
|
|
|
|
{module_host = {undefined, <<"">>} :: {atom(), binary()},
|
|
|
|
opts = [] :: opts() | '_' | '$2'}).
|
|
|
|
|
|
|
|
-type opts() :: [{atom(), any()}].
|
2016-04-20 11:27:32 +02:00
|
|
|
-type db_type() :: sql | mnesia | riak.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
|
|
|
-callback start(binary(), opts()) -> any().
|
|
|
|
-callback stop(binary()) -> any().
|
2016-05-01 22:09:40 +02:00
|
|
|
-callback mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()].
|
2003-01-24 21:18:33 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-export_type([opts/0]).
|
2015-06-01 14:38:27 +02:00
|
|
|
-export_type([db_type/0]).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
|
|
|
%%behaviour_info(callbacks) -> [{start, 2}, {stop, 1}];
|
|
|
|
%%behaviour_info(_Other) -> undefined.
|
2003-01-24 21:18:33 +01:00
|
|
|
|
2003-01-28 20:45:13 +01:00
|
|
|
start() ->
|
2013-03-14 10:33:02 +01:00
|
|
|
ets:new(ejabberd_modules,
|
|
|
|
[named_table, public,
|
|
|
|
{keypos, #ejabberd_module.module_host}]),
|
2003-01-28 20:45:13 +01:00
|
|
|
ok.
|
|
|
|
|
2016-03-29 15:25:24 +02:00
|
|
|
-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, []).
|
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
-spec start_modules(binary()) -> any().
|
|
|
|
|
|
|
|
start_modules(Host) ->
|
2016-03-29 15:25:24 +02:00
|
|
|
Modules = get_modules_options(Host),
|
2015-06-01 14:38:27 +02:00
|
|
|
lists:foreach(
|
2016-03-29 15:25:24 +02:00
|
|
|
fun({Module, Opts}) ->
|
|
|
|
start_module(Host, Module, Opts)
|
|
|
|
end, Modules).
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2014-07-08 18:57:43 +02:00
|
|
|
-spec start_module(binary(), atom()) -> any().
|
|
|
|
|
|
|
|
start_module(Host, Module) ->
|
2016-03-29 15:25:24 +02:00
|
|
|
Modules = get_modules_options(Host),
|
2014-07-08 18:57:43 +02:00
|
|
|
case lists:keyfind(Module, 1, Modules) of
|
|
|
|
{_, Opts} ->
|
|
|
|
start_module(Host, Module, Opts);
|
|
|
|
false ->
|
|
|
|
{error, not_found_in_config}
|
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec start_module(binary(), atom(), opts()) -> any().
|
2003-01-24 21:18:33 +01:00
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
start_module(Host, Module, Opts0) ->
|
|
|
|
Opts = validate_opts(Module, Opts0),
|
2008-11-26 16:10:38 +01:00
|
|
|
ets:insert(ejabberd_modules,
|
|
|
|
#ejabberd_module{module_host = {Module, Host},
|
|
|
|
opts = Opts}),
|
2013-03-14 10:33:02 +01:00
|
|
|
try Module:start(Host, Opts) catch
|
|
|
|
Class:Reason ->
|
|
|
|
ets:delete(ejabberd_modules, {Module, Host}),
|
|
|
|
ErrorText =
|
|
|
|
io_lib:format("Problem starting the module ~p for host "
|
|
|
|
"~p ~n options: ~p~n ~p: ~p~n~p",
|
|
|
|
[Module, Host, Opts, Class, Reason,
|
|
|
|
erlang:get_stacktrace()]),
|
|
|
|
?CRITICAL_MSG(ErrorText, []),
|
|
|
|
case is_app_running(ejabberd) of
|
|
|
|
true ->
|
|
|
|
erlang:raise(Class, Reason, erlang:get_stacktrace());
|
|
|
|
false ->
|
|
|
|
?CRITICAL_MSG("ejabberd initialization was aborted "
|
|
|
|
"because a module start failed.",
|
|
|
|
[]),
|
|
|
|
timer:sleep(3000),
|
|
|
|
erlang:halt(string:substr(lists:flatten(ErrorText), 1, 199))
|
|
|
|
end
|
2003-01-24 21:18:33 +01:00
|
|
|
end.
|
|
|
|
|
2011-05-16 22:33:08 +02:00
|
|
|
is_app_running(AppName) ->
|
|
|
|
Timeout = 15000,
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:keymember(AppName, 1,
|
|
|
|
application:which_applications(Timeout)).
|
|
|
|
|
2016-03-29 15:25:24 +02:00
|
|
|
-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).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec stop_module(binary(), atom()) -> error | {aborted, any()} | {atomic, any()}.
|
2011-05-16 22:33:08 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
stop_module(Host, Module) ->
|
2008-07-30 20:11:14 +02:00
|
|
|
case stop_module_keep_config(Host, Module) of
|
2013-03-14 10:33:02 +01:00
|
|
|
error -> error;
|
2013-08-12 14:25:05 +02:00
|
|
|
ok -> ok
|
2008-07-30 20:11:14 +02:00
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec stop_module_keep_config(binary(), atom()) -> error | ok.
|
|
|
|
|
2008-07-30 20:11:14 +02:00
|
|
|
stop_module_keep_config(Host, Module) ->
|
2005-06-20 05:18:13 +02:00
|
|
|
case catch Module:stop(Host) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{'EXIT', Reason} -> ?ERROR_MSG("~p", [Reason]), error;
|
|
|
|
{wait, ProcList} when is_list(ProcList) ->
|
|
|
|
lists:foreach(fun wait_for_process/1, ProcList),
|
|
|
|
ets:delete(ejabberd_modules, {Module, Host}),
|
|
|
|
ok;
|
|
|
|
{wait, Process} ->
|
|
|
|
wait_for_process(Process),
|
|
|
|
ets:delete(ejabberd_modules, {Module, Host}),
|
|
|
|
ok;
|
|
|
|
_ -> ets:delete(ejabberd_modules, {Module, Host}), ok
|
2003-01-28 20:45:13 +01:00
|
|
|
end.
|
2003-01-24 21:18:33 +01:00
|
|
|
|
2005-05-23 02:30:29 +02:00
|
|
|
wait_for_process(Process) ->
|
|
|
|
MonitorReference = erlang:monitor(process, Process),
|
|
|
|
wait_for_stop(Process, MonitorReference).
|
|
|
|
|
|
|
|
wait_for_stop(Process, MonitorReference) ->
|
|
|
|
receive
|
2013-03-14 10:33:02 +01:00
|
|
|
{'DOWN', MonitorReference, _Type, _Object, _Info} -> ok
|
|
|
|
after 5000 ->
|
|
|
|
catch exit(whereis(Process), kill),
|
|
|
|
wait_for_stop1(MonitorReference)
|
2005-05-23 02:30:29 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
wait_for_stop1(MonitorReference) ->
|
|
|
|
receive
|
2013-03-14 10:33:02 +01:00
|
|
|
{'DOWN', MonitorReference, _Type, _Object, _Info} -> ok
|
|
|
|
after 5000 -> ok
|
2005-05-23 02:30:29 +02:00
|
|
|
end.
|
2003-01-24 21:18:33 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-type check_fun() :: fun((any()) -> any()) | {module(), atom()}.
|
|
|
|
|
2015-05-31 15:14:57 +02:00
|
|
|
-spec get_opt(atom() | {atom(), binary()|global}, opts(), check_fun()) -> any().
|
2003-01-24 21:18:33 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
get_opt(Opt, Opts, F) ->
|
|
|
|
get_opt(Opt, Opts, F, undefined).
|
|
|
|
|
2015-05-31 15:14:57 +02:00
|
|
|
-spec get_opt(atom() | {atom(), binary()|global}, opts(), check_fun(), any()) -> any().
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2015-05-31 15:14:57 +02:00
|
|
|
get_opt({Opt, Host}, Opts, F, Default) ->
|
|
|
|
case lists:keysearch(Opt, 1, Opts) of
|
|
|
|
false ->
|
|
|
|
ejabberd_config:get_option({Opt, Host}, F, Default);
|
|
|
|
{value, {_, Val}} ->
|
|
|
|
ejabberd_config:prepare_opt_val(Opt, Val, F, Default)
|
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
get_opt(Opt, Opts, F, Default) ->
|
2003-01-24 21:18:33 +01:00
|
|
|
case lists:keysearch(Opt, 1, Opts) of
|
2013-03-14 10:33:02 +01:00
|
|
|
false ->
|
|
|
|
Default;
|
|
|
|
{value, {_, Val}} ->
|
|
|
|
ejabberd_config:prepare_opt_val(Opt, Val, F, Default)
|
2003-01-24 21:18:33 +01:00
|
|
|
end.
|
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
-spec get_module_opt(global | binary(), atom(), atom(), check_fun()) -> any().
|
|
|
|
|
|
|
|
get_module_opt(Host, Module, Opt, F) ->
|
|
|
|
get_module_opt(Host, Module, Opt, F, undefined).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec get_module_opt(global | binary(), atom(), atom(), check_fun(), any()) -> any().
|
|
|
|
|
|
|
|
get_module_opt(global, Module, Opt, F, Default) ->
|
|
|
|
Hosts = (?MYHOSTS),
|
|
|
|
[Value | Values] = lists:map(fun (Host) ->
|
|
|
|
get_module_opt(Host, Module, Opt,
|
|
|
|
F, Default)
|
|
|
|
end,
|
|
|
|
Hosts),
|
|
|
|
Same_all = lists:all(fun (Other_value) ->
|
|
|
|
Other_value == Value
|
|
|
|
end,
|
|
|
|
Values),
|
|
|
|
case Same_all of
|
|
|
|
true -> Value;
|
|
|
|
false -> Default
|
|
|
|
end;
|
|
|
|
get_module_opt(Host, Module, Opt, F, Default) ->
|
2005-06-20 05:18:13 +02:00
|
|
|
OptsList = ets:lookup(ejabberd_modules, {Module, Host}),
|
2004-07-11 22:51:54 +02:00
|
|
|
case OptsList of
|
2013-03-14 10:33:02 +01:00
|
|
|
[] -> Default;
|
|
|
|
[#ejabberd_module{opts = Opts} | _] ->
|
|
|
|
get_opt(Opt, Opts, F, Default)
|
2004-07-11 22:51:54 +02:00
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec get_module_opt_host(global | binary(), atom(), binary()) -> binary().
|
|
|
|
|
2007-09-11 13:20:36 +02:00
|
|
|
get_module_opt_host(Host, Module, Default) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Val = get_module_opt(Host, Module, host,
|
|
|
|
fun iolist_to_binary/1,
|
|
|
|
Default),
|
|
|
|
ejabberd_regexp:greplace(Val, <<"@HOST@">>, Host).
|
|
|
|
|
|
|
|
-spec get_opt_host(binary(), opts(), binary()) -> binary().
|
2007-09-11 13:20:36 +02:00
|
|
|
|
2007-08-25 19:24:00 +02:00
|
|
|
get_opt_host(Host, Opts, Default) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Val = get_opt(host, Opts, fun iolist_to_binary/1, Default),
|
|
|
|
ejabberd_regexp:greplace(Val, <<"@HOST@">>, Host).
|
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
validate_opts(Module, Opts) ->
|
2016-06-21 12:25:29 +02:00
|
|
|
lists:filtermap(
|
2015-06-01 14:38:27 +02:00
|
|
|
fun({Opt, Val}) ->
|
|
|
|
case catch Module:mod_opt_type(Opt) of
|
|
|
|
VFun when is_function(VFun) ->
|
2016-06-21 12:25:29 +02:00
|
|
|
try VFun(Val) of
|
|
|
|
_ ->
|
|
|
|
true
|
|
|
|
catch {replace_with, NewVal} ->
|
|
|
|
{true, {Opt, NewVal}};
|
|
|
|
{invalid_syntax, Error} ->
|
|
|
|
?ERROR_MSG("ignoring invalid value '~p' for "
|
|
|
|
"option '~s' of module '~s': ~s",
|
|
|
|
[Val, Opt, Module, Error]),
|
|
|
|
false;
|
|
|
|
_:_ ->
|
2015-06-01 14:38:27 +02:00
|
|
|
?ERROR_MSG("ignoring invalid value '~p' for "
|
|
|
|
"option '~s' of module '~s'",
|
|
|
|
[Val, Opt, Module]),
|
2016-06-21 12:25:29 +02:00
|
|
|
false
|
2015-06-01 14:38:27 +02:00
|
|
|
end;
|
|
|
|
L when is_list(L) ->
|
|
|
|
SOpts = str:join([[$', atom_to_list(A), $'] || A <- L], <<", ">>),
|
2015-06-03 15:21:07 +02:00
|
|
|
?ERROR_MSG("unknown option '~s' for module '~s' will be"
|
|
|
|
" likely ignored, available options are: ~s",
|
|
|
|
[Opt, Module, SOpts]),
|
|
|
|
true;
|
2015-06-01 14:38:27 +02:00
|
|
|
{'EXIT', {undef, _}} ->
|
|
|
|
?WARNING_MSG("module '~s' doesn't export mod_opt_type/1",
|
|
|
|
[Module]),
|
|
|
|
true
|
|
|
|
end;
|
|
|
|
(Junk) ->
|
|
|
|
?ERROR_MSG("failed to understand option ~p for module '~s'",
|
|
|
|
[Junk, Module]),
|
|
|
|
false
|
|
|
|
end, Opts).
|
|
|
|
|
2016-04-27 16:10:50 +02:00
|
|
|
-spec db_type(binary() | global, module()) -> db_type();
|
|
|
|
(opts(), module()) -> db_type().
|
2012-04-27 11:52:05 +02:00
|
|
|
|
2016-04-27 16:10:50 +02:00
|
|
|
db_type(Opts, Module) when is_list(Opts) ->
|
|
|
|
db_type(global, Opts, Module);
|
2015-03-30 11:15:29 +02:00
|
|
|
db_type(Host, Module) when is_atom(Module) ->
|
2016-05-01 22:06:15 +02:00
|
|
|
case catch Module:mod_opt_type(db_type) of
|
2016-04-27 16:10:50 +02:00
|
|
|
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.
|
2015-03-30 11:15:29 +02:00
|
|
|
|
2016-04-27 16:10:50 +02:00
|
|
|
-spec db_type(binary(), opts(), module()) -> db_type().
|
|
|
|
|
|
|
|
db_type(Host, Opts, Module) ->
|
2016-05-01 22:06:15 +02:00
|
|
|
case catch Module:mod_opt_type(db_type) of
|
2016-04-27 16:10:50 +02:00
|
|
|
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.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2016-04-13 08:56:10 +02:00
|
|
|
-spec db_mod(binary() | global | db_type(), module()) -> module().
|
|
|
|
|
2016-04-27 16:10:50 +02:00
|
|
|
db_mod(Type, Module) when is_atom(Type) ->
|
|
|
|
list_to_atom(atom_to_list(Module) ++ "_" ++ atom_to_list(Type));
|
2016-04-13 08:56:10 +02:00
|
|
|
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) ->
|
2016-04-27 16:10:50 +02:00
|
|
|
db_mod(db_type(Host, Opts, Module), Module).
|
2016-04-13 08:56:10 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec loaded_modules(binary()) -> [atom()].
|
2012-04-27 11:52:05 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
loaded_modules(Host) ->
|
2003-01-28 20:45:13 +01:00
|
|
|
ets:select(ejabberd_modules,
|
2005-06-20 05:18:13 +02:00
|
|
|
[{#ejabberd_module{_ = '_', module_host = {'$1', Host}},
|
2013-03-14 10:33:02 +01:00
|
|
|
[], ['$1']}]).
|
|
|
|
|
|
|
|
-spec loaded_modules_with_opts(binary()) -> [{atom(), opts()}].
|
2005-05-23 02:30:29 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
loaded_modules_with_opts(Host) ->
|
2005-05-23 02:30:29 +02:00
|
|
|
ets:select(ejabberd_modules,
|
2005-06-20 05:18:13 +02:00
|
|
|
[{#ejabberd_module{_ = '_', module_host = {'$1', Host},
|
|
|
|
opts = '$2'},
|
2013-03-14 10:33:02 +01:00
|
|
|
[], [{{'$1', '$2'}}]}]).
|
2004-07-11 22:51:54 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec get_hosts(opts(), binary()) -> [binary()].
|
2007-11-27 23:30:51 +01:00
|
|
|
|
2005-04-17 20:08:34 +02:00
|
|
|
get_hosts(Opts, Prefix) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case get_opt(hosts, Opts,
|
|
|
|
fun(Hs) -> [iolist_to_binary(H) || H <- Hs] end) of
|
|
|
|
undefined ->
|
|
|
|
case get_opt(host, Opts,
|
|
|
|
fun iolist_to_binary/1) of
|
|
|
|
undefined ->
|
|
|
|
[<<Prefix/binary, Host/binary>> || Host <- ?MYHOSTS];
|
|
|
|
Host ->
|
|
|
|
[Host]
|
|
|
|
end;
|
|
|
|
Hosts ->
|
|
|
|
Hosts
|
2005-04-17 20:08:34 +02:00
|
|
|
end.
|
2005-06-20 05:18:13 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec get_module_proc(binary(), {frontend, atom()} | atom()) -> atom().
|
|
|
|
|
2008-10-24 19:26:11 +02:00
|
|
|
get_module_proc(Host, {frontend, Base}) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
get_module_proc(<<"frontend_", Host/binary>>, Base);
|
2005-06-20 05:18:13 +02:00
|
|
|
get_module_proc(Host, Base) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
binary_to_atom(
|
|
|
|
<<(erlang:atom_to_binary(Base, latin1))/binary, "_", Host/binary>>,
|
|
|
|
latin1).
|
|
|
|
|
|
|
|
-spec is_loaded(binary(), atom()) -> boolean().
|
2005-06-20 05:18:13 +02:00
|
|
|
|
2006-01-19 03:17:31 +01:00
|
|
|
is_loaded(Host, Module) ->
|
|
|
|
ets:member(ejabberd_modules, {Module, Host}).
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2016-04-27 16:10:50 +02:00
|
|
|
opt_type(default_db) -> fun(T) when is_atom(T) -> T end;
|
2015-06-01 14:38:27 +02:00
|
|
|
opt_type(modules) -> fun (L) when is_list(L) -> L end;
|
|
|
|
opt_type(_) -> [default_db, modules].
|