25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Store who defines a command, specially when defined by ejabberd modules

This commit is contained in:
Badlop 2021-07-29 23:13:17 +02:00
parent 2050cdffb4
commit ccb4328d06
9 changed files with 13 additions and 8 deletions

View File

@ -59,6 +59,7 @@
policy = restricted :: open | restricted | admin | user, policy = restricted :: open | restricted | admin | user,
%% access is: [accessRuleName] or [{Module, AccessOption, DefaultAccessRuleName}] %% access is: [accessRuleName] or [{Module, AccessOption, DefaultAccessRuleName}]
access = [] :: [{atom(),atom(),atom()}|atom()], access = [] :: [{atom(),atom(),atom()}|atom()],
definer = unknown :: atom(),
result = {res, rescode} :: rterm() | '_' | '$2', result = {res, rescode} :: rterm() | '_' | '$2',
args_rename = [] :: [{atom(),atom()}], args_rename = [] :: [{atom(),atom()}],
args_desc = none :: none | [string()] | '_', args_desc = none :: none | [string()] | '_',

View File

@ -41,6 +41,7 @@
get_tags_commands/0, get_tags_commands/0,
get_tags_commands/1, get_tags_commands/1,
register_commands/1, register_commands/1,
register_commands/2,
unregister_commands/1, unregister_commands/1,
get_commands_spec/0, get_commands_spec/0,
get_commands_definition/0, get_commands_definition/0,
@ -129,10 +130,13 @@ code_change(_OldVsn, State, _Extra) ->
-spec register_commands([ejabberd_commands()]) -> ok. -spec register_commands([ejabberd_commands()]) -> ok.
register_commands(Commands) -> register_commands(Commands) ->
register_commands(unknown, Commands).
register_commands(Definer, Commands) ->
lists:foreach( lists:foreach(
fun(Command) -> fun(Command) ->
%% XXX check if command exists %% XXX check if command exists
mnesia:dirty_write(Command) mnesia:dirty_write(Command#ejabberd_commands{definer = Definer})
%% ?DEBUG("This command is already defined:~n~p", [Command]) %% ?DEBUG("This command is already defined:~n~p", [Command])
end, end,
Commands), Commands),

View File

@ -92,7 +92,7 @@
%%% %%%
start(_Host, _Opts) -> start(_Host, _Opts) ->
ejabberd_commands:register_commands(get_commands_spec()). ejabberd_commands:register_commands(?MODULE, get_commands_spec()).
stop(Host) -> stop(Host) ->
case gen_mod:is_loaded_elsewhere(Host, ?MODULE) of case gen_mod:is_loaded_elsewhere(Host, ?MODULE) of

View File

@ -46,7 +46,7 @@
%%% %%%
start(_Host, _Opts) -> start(_Host, _Opts) ->
ejabberd_commands:register_commands(get_commands_spec()). ejabberd_commands:register_commands(?MODULE, get_commands_spec()).
stop(_Host) -> stop(_Host) ->
ejabberd_commands:unregister_commands(get_commands_spec()). ejabberd_commands:unregister_commands(get_commands_spec()).

View File

@ -107,7 +107,7 @@ c2s_stream_started(#{ip := {Addr, _}} = State, _) ->
start(Host, Opts) -> start(Host, Opts) ->
catch ets:new(failed_auth, [named_table, public, catch ets:new(failed_auth, [named_table, public,
{heir, erlang:group_leader(), none}]), {heir, erlang:group_leader(), none}]),
ejabberd_commands:register_commands(get_commands_spec()), ejabberd_commands:register_commands(?MODULE, get_commands_spec()),
gen_mod:start_child(?MODULE, Host, Opts). gen_mod:start_child(?MODULE, Host, Opts).
stop(Host) -> stop(Host) ->

View File

@ -148,7 +148,7 @@ start(Host, Opts) ->
ejabberd_hooks:add(check_create_room, Host, ?MODULE, ejabberd_hooks:add(check_create_room, Host, ?MODULE,
check_create_room, 50) check_create_room, 50)
end, end,
ejabberd_commands:register_commands(get_commands_spec()), ejabberd_commands:register_commands(?MODULE, get_commands_spec()),
ok; ok;
Err -> Err ->
Err Err

View File

@ -57,7 +57,7 @@
%%---------------------------- %%----------------------------
start(Host, _Opts) -> start(Host, _Opts) ->
ejabberd_commands:register_commands(get_commands_spec()), ejabberd_commands:register_commands(?MODULE, get_commands_spec()),
ejabberd_hooks:add(webadmin_menu_main, ?MODULE, web_menu_main, 50), ejabberd_hooks:add(webadmin_menu_main, ?MODULE, web_menu_main, 50),
ejabberd_hooks:add(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50), ejabberd_hooks:add(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50),
ejabberd_hooks:add(webadmin_page_main, ?MODULE, web_page_main, 50), ejabberd_hooks:add(webadmin_page_main, ?MODULE, web_page_main, 50),

View File

@ -66,7 +66,7 @@ start(Host, Opts) ->
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, get_sm_features, 50), ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, get_sm_features, 50),
ejabberd_hooks:add(pubsub_publish_item, Host, ?MODULE, pubsub_publish_item, 50), ejabberd_hooks:add(pubsub_publish_item, Host, ?MODULE, pubsub_publish_item, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PRIVATE, ?MODULE, process_sm_iq), gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PRIVATE, ?MODULE, process_sm_iq),
ejabberd_commands:register_commands(get_commands_spec()). ejabberd_commands:register_commands(?MODULE, get_commands_spec()).
stop(Host) -> stop(Host) ->
ejabberd_hooks:delete(remove_user, Host, ?MODULE, remove_user, 50), ejabberd_hooks:delete(remove_user, Host, ?MODULE, remove_user, 50),

View File

@ -98,7 +98,7 @@ start(Host, Opts) ->
init_cache(Mod, Host, Opts), init_cache(Mod, Host, Opts),
register_iq_handlers(Host), register_iq_handlers(Host),
register_hooks(Host), register_hooks(Host),
ejabberd_commands:register_commands(get_commands_spec()). ejabberd_commands:register_commands(?MODULE, get_commands_spec()).
-spec stop(binary()) -> ok. -spec stop(binary()) -> ok.
stop(Host) -> stop(Host) ->