From a5c461793d8867a572e8598494468e40bd0a2479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20D=C5=82ugosz?= Date: Thu, 1 Dec 2022 14:01:53 +0100 Subject: [PATCH] Refactored hook handlers in ejabberd_ctl --- src/ejabberd_app.erl | 1 - src/ejabberd_ctl.erl | 39 +++------------------------------------ src/gen_hook.erl | 6 +++++- 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/src/ejabberd_app.erl b/src/ejabberd_app.erl index dfea351e799..244c0ea8fb9 100644 --- a/src/ejabberd_app.erl +++ b/src/ejabberd_app.erl @@ -49,7 +49,6 @@ start(normal, _Args) -> mongoose_graphql:init(), translate:start(), ejabberd_node_id:start(), - ejabberd_ctl:init(), ejabberd_commands:init(), mongoose_graphql_commands:start(), mongoose_config:start(), diff --git a/src/ejabberd_ctl.erl b/src/ejabberd_ctl.erl index 20b1bce73f7..7f41858eeff 100644 --- a/src/ejabberd_ctl.erl +++ b/src/ejabberd_ctl.erl @@ -47,16 +47,14 @@ -author('alexey@process-one.net'). -export([start/0, - init/0, process/1, - process2/2, - register_commands/3, - unregister_commands/3]). + process2/2]). --ignore_xref([process/1, process2/2, register_commands/3, start/0, unregister_commands/3]). +-ignore_xref([process/1, process2/2, start/0]). -include("ejabberd_ctl.hrl"). -include("ejabberd_commands.hrl"). +-include("mongoose_logger.hrl"). -type format() :: integer | string | binary | {list, format()}. -type format_type() :: binary() | string() | char(). @@ -105,37 +103,6 @@ start() -> halt(?STATUS_USAGE) end. - --spec init() -> atom() | ets:tid(). -init() -> - ets:new(ejabberd_ctl_cmds, [named_table, set, public]), - ets:new(ejabberd_ctl_host_cmds, [named_table, set, public]). - - -%%----------------------------- -%% mongooseimctl Command managment -%%----------------------------- - --spec register_commands(CmdDescs :: [tuple()] | tuple(), - Module :: atom(), - Function :: atom()) -> 'ok'. -register_commands(CmdDescs, Module, Function) -> - ets:insert(ejabberd_ctl_cmds, CmdDescs), - ejabberd_hooks:add(ejabberd_ctl_process, global, Module, Function, 50), - ok. - - --spec unregister_commands(CmdDescs :: [any()], - Module :: atom(), - Function :: atom()) -> 'ok'. -unregister_commands(CmdDescs, Module, Function) -> - lists:foreach(fun(CmdDesc) -> - ets:delete_object(ejabberd_ctl_cmds, CmdDesc) - end, CmdDescs), - ejabberd_hooks:delete(ejabberd_ctl_process, global, Module, Function, 50), - ok. - - %%----------------------------- %% Process %%----------------------------- diff --git a/src/gen_hook.erl b/src/gen_hook.erl index fedb7ba1d4e..9e113376d48 100644 --- a/src/gen_hook.erl +++ b/src/gen_hook.erl @@ -55,7 +55,11 @@ -type hook_list() :: [hook_tuple()]. --export_type([hook_fn/0, hook_list/0, hook_fn_ret/0, hook_fn_ret/1]). +-export_type([hook_fn/0, + hook_list/0, + hook_fn_ret/0, + hook_fn_ret/1, + extra/0]). -record(hook_handler, {prio :: pos_integer(), hook_fn :: hook_fn(),