25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Allow auth and pubsub plugin to use Elixir module

This commit is contained in:
Christophe Romain 2017-10-31 11:04:32 +01:00
parent 5f0a84a331
commit 675cc3e0ea
3 changed files with 27 additions and 11 deletions

View File

@ -37,7 +37,7 @@
-protocol({xep, 270, '1.0'}). -protocol({xep, 270, '1.0'}).
-export([start/0, stop/0, start_app/1, start_app/2, -export([start/0, stop/0, start_app/1, start_app/2,
get_pid_file/0, check_app/1]). get_pid_file/0, check_app/1, module_name/1]).
-include("logger.hrl"). -include("logger.hrl").
@ -148,3 +148,20 @@ get_module_file(App, Mod) ->
Dir -> Dir ->
filename:join([Dir, BaseName ++ ".beam"]) filename:join([Dir, BaseName ++ ".beam"])
end. end.
module_name([Dir, _, <<H,T/binary>> | _] = Mod) when H >= 65, H =< 90 ->
Module = str:join([elixir_name(M) || M<-tl(Mod)], <<>>),
Prefix = case elixir_name(Dir) of
<<"Ejabberd">> -> <<"Elixir.Ejabberd.">>;
Lib -> <<"Elixir.Ejabberd.", Lib/binary, ".">>
end,
misc:binary_to_atom(<<Prefix/binary, Module/binary>>);
module_name([<<"ejabberd">> | _] = Mod) ->
misc:binary_to_atom(str:join(Mod,$_));
module_name(Mod) when is_list(Mod) ->
misc:binary_to_atom(str:join(tl(Mod),$_)).
elixir_name(<<H,T/binary>>) when H >= 65, H =< 90 ->
<<H, T/binary>>;
elixir_name(<<H,T/binary>>) ->
<<(H-32), T/binary>>.

View File

@ -735,8 +735,8 @@ auth_modules(Server) ->
LServer = jid:nameprep(Server), LServer = jid:nameprep(Server),
Default = ejabberd_config:default_db(LServer, ?MODULE), Default = ejabberd_config:default_db(LServer, ?MODULE),
Methods = ejabberd_config:get_option({auth_method, LServer}, [Default]), Methods = ejabberd_config:get_option({auth_method, LServer}, [Default]),
[misc:binary_to_atom(<<"ejabberd_auth_", [ejabberd:module_name([<<"ejabberd">>, <<"auth">>,
(misc:atom_to_binary(M))/binary>>) misc:atom_to_binary(M)])
|| M <- Methods]. || M <- Methods].
-spec match_passwords(password(), password(), -spec match_passwords(password(), password(),

View File

@ -3380,11 +3380,11 @@ tree(Host) ->
tree(_Host, <<"virtual">>) -> tree(_Host, <<"virtual">>) ->
nodetree_virtual; % special case, virtual does not use any backend nodetree_virtual; % special case, virtual does not use any backend
tree(Host, Name) -> tree(Host, Name) ->
submodule(Host, <<"nodetree_", Name/binary>>). submodule(Host, <<"nodetree">>, Name).
-spec plugin(host(), binary()) -> atom(). -spec plugin(host(), binary()) -> atom().
plugin(Host, Name) -> plugin(Host, Name) ->
submodule(Host, <<"node_", Name/binary>>). submodule(Host, <<"node">>, Name).
-spec plugins(host()) -> [binary()]. -spec plugins(host()) -> [binary()].
plugins(Host) -> plugins(Host) ->
@ -3396,14 +3396,13 @@ plugins(Host) ->
-spec subscription_plugin(host()) -> atom(). -spec subscription_plugin(host()) -> atom().
subscription_plugin(Host) -> subscription_plugin(Host) ->
submodule(Host, <<"pubsub_subscription">>). submodule(Host, <<"pubsub">>, <<"subscription">>).
-spec submodule(host(), binary()) -> atom(). -spec submodule(host(), binary(), binary()) -> atom().
submodule(Host, Name) -> submodule(Host, Type, Name) ->
case gen_mod:db_type(serverhost(Host), ?MODULE) of case gen_mod:db_type(serverhost(Host), ?MODULE) of
mnesia -> misc:binary_to_atom(Name); mnesia -> ejabberd:module_name([<<"pubsub">>, Type, Name]);
Type -> misc:binary_to_atom(<<Name/binary, "_", Db -> ejabberd:module_name([<<"pubsub">>, Type, Name, Db])
(misc:atom_to_binary(Type))/binary>>)
end. end.
-spec config(binary(), any()) -> any(). -spec config(binary(), any()) -> any().