mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Allow auth and pubsub plugin to use Elixir module
This commit is contained in:
parent
5f0a84a331
commit
675cc3e0ea
@ -37,7 +37,7 @@
|
||||
-protocol({xep, 270, '1.0'}).
|
||||
|
||||
-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").
|
||||
|
||||
@ -148,3 +148,20 @@ get_module_file(App, Mod) ->
|
||||
Dir ->
|
||||
filename:join([Dir, BaseName ++ ".beam"])
|
||||
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>>.
|
||||
|
@ -735,8 +735,8 @@ auth_modules(Server) ->
|
||||
LServer = jid:nameprep(Server),
|
||||
Default = ejabberd_config:default_db(LServer, ?MODULE),
|
||||
Methods = ejabberd_config:get_option({auth_method, LServer}, [Default]),
|
||||
[misc:binary_to_atom(<<"ejabberd_auth_",
|
||||
(misc:atom_to_binary(M))/binary>>)
|
||||
[ejabberd:module_name([<<"ejabberd">>, <<"auth">>,
|
||||
misc:atom_to_binary(M)])
|
||||
|| M <- Methods].
|
||||
|
||||
-spec match_passwords(password(), password(),
|
||||
|
@ -3380,11 +3380,11 @@ tree(Host) ->
|
||||
tree(_Host, <<"virtual">>) ->
|
||||
nodetree_virtual; % special case, virtual does not use any backend
|
||||
tree(Host, Name) ->
|
||||
submodule(Host, <<"nodetree_", Name/binary>>).
|
||||
submodule(Host, <<"nodetree">>, Name).
|
||||
|
||||
-spec plugin(host(), binary()) -> atom().
|
||||
plugin(Host, Name) ->
|
||||
submodule(Host, <<"node_", Name/binary>>).
|
||||
submodule(Host, <<"node">>, Name).
|
||||
|
||||
-spec plugins(host()) -> [binary()].
|
||||
plugins(Host) ->
|
||||
@ -3396,14 +3396,13 @@ plugins(Host) ->
|
||||
|
||||
-spec subscription_plugin(host()) -> atom().
|
||||
subscription_plugin(Host) ->
|
||||
submodule(Host, <<"pubsub_subscription">>).
|
||||
submodule(Host, <<"pubsub">>, <<"subscription">>).
|
||||
|
||||
-spec submodule(host(), binary()) -> atom().
|
||||
submodule(Host, Name) ->
|
||||
-spec submodule(host(), binary(), binary()) -> atom().
|
||||
submodule(Host, Type, Name) ->
|
||||
case gen_mod:db_type(serverhost(Host), ?MODULE) of
|
||||
mnesia -> misc:binary_to_atom(Name);
|
||||
Type -> misc:binary_to_atom(<<Name/binary, "_",
|
||||
(misc:atom_to_binary(Type))/binary>>)
|
||||
mnesia -> ejabberd:module_name([<<"pubsub">>, Type, Name]);
|
||||
Db -> ejabberd:module_name([<<"pubsub">>, Type, Name, Db])
|
||||
end.
|
||||
|
||||
-spec config(binary(), any()) -> any().
|
||||
|
Loading…
Reference in New Issue
Block a user