Skip to content

Commit

Permalink
Refactored hook handlers in ejabberd_ctl
Browse files Browse the repository at this point in the history
  • Loading branch information
pawlooss1 committed Dec 2, 2022
1 parent b28a1cf commit a5c4617
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 38 deletions.
1 change: 0 additions & 1 deletion src/ejabberd_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
39 changes: 3 additions & 36 deletions src/ejabberd_ctl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@
-author('[email protected]').

-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().
Expand Down Expand Up @@ -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
%%-----------------------------
Expand Down
6 changes: 5 additions & 1 deletion src/gen_hook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit a5c4617

Please sign in to comment.