mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Add a way to get all ejabberd_commands, not only those that was registered
This is part of (TECH-1828).
This commit is contained in:
parent
fc2d5da112
commit
bdeb4a7e32
@ -51,7 +51,8 @@
|
|||||||
install_fallback_mnesia/1,
|
install_fallback_mnesia/1,
|
||||||
dump_to_textfile/1, dump_to_textfile/2,
|
dump_to_textfile/1, dump_to_textfile/2,
|
||||||
mnesia_change_nodename/4,
|
mnesia_change_nodename/4,
|
||||||
restore/1 % Still used by some modules
|
restore/1, % Still used by some modules
|
||||||
|
get_commands_spec/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
@ -59,16 +60,16 @@
|
|||||||
-include("ejabberd_commands.hrl").
|
-include("ejabberd_commands.hrl").
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ejabberd_commands:register_commands(commands()).
|
ejabberd_commands:register_commands(get_commands_spec()).
|
||||||
|
|
||||||
stop() ->
|
stop() ->
|
||||||
ejabberd_commands:unregister_commands(commands()).
|
ejabberd_commands:unregister_commands(get_commands_spec()).
|
||||||
|
|
||||||
%%%
|
%%%
|
||||||
%%% ejabberd commands
|
%%% ejabberd commands
|
||||||
%%%
|
%%%
|
||||||
|
|
||||||
commands() ->
|
get_commands_spec() ->
|
||||||
[
|
[
|
||||||
%% The commands status, stop and restart are implemented also in ejabberd_ctl
|
%% The commands status, stop and restart are implemented also in ejabberd_ctl
|
||||||
%% They are defined here so that other interfaces can use them too
|
%% They are defined here so that other interfaces can use them too
|
||||||
|
@ -219,7 +219,8 @@
|
|||||||
unregister_commands/1,
|
unregister_commands/1,
|
||||||
execute_command/2,
|
execute_command/2,
|
||||||
execute_command/4,
|
execute_command/4,
|
||||||
opt_type/1
|
opt_type/1,
|
||||||
|
get_commands_spec/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-include("ejabberd_commands.hrl").
|
-include("ejabberd_commands.hrl").
|
||||||
@ -228,10 +229,8 @@
|
|||||||
|
|
||||||
-define(POLICY_ACCESS, '$policy').
|
-define(POLICY_ACCESS, '$policy').
|
||||||
|
|
||||||
init() ->
|
get_commands_spec() ->
|
||||||
ets:new(ejabberd_commands, [named_table, set, public,
|
[
|
||||||
{keypos, #ejabberd_commands.name}]),
|
|
||||||
register_commands([
|
|
||||||
#ejabberd_commands{name = gen_html_doc_for_commands, tags = [documentation],
|
#ejabberd_commands{name = gen_html_doc_for_commands, tags = [documentation],
|
||||||
desc = "Generates html documentation for ejabberd_commands",
|
desc = "Generates html documentation for ejabberd_commands",
|
||||||
module = ejabberd_commands_doc, function = generate_html_output,
|
module = ejabberd_commands_doc, function = generate_html_output,
|
||||||
@ -259,7 +258,11 @@ init() ->
|
|||||||
"that will have example invocation include in markdown document"],
|
"that will have example invocation include in markdown document"],
|
||||||
result_desc = "0 if command failed, 1 when succedded",
|
result_desc = "0 if command failed, 1 when succedded",
|
||||||
args_example = ["/home/me/docs/api.html", "mod_admin", "java,json"],
|
args_example = ["/home/me/docs/api.html", "mod_admin", "java,json"],
|
||||||
result_example = ok}]).
|
result_example = ok}].
|
||||||
|
init() ->
|
||||||
|
ets:new(ejabberd_commands, [named_table, set, public,
|
||||||
|
{keypos, #ejabberd_commands.name}]),
|
||||||
|
register_commands(get_commands_spec()).
|
||||||
|
|
||||||
-spec register_commands([ejabberd_commands()]) -> ok.
|
-spec register_commands([ejabberd_commands()]) -> ok.
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
%%% Created : 20 May 2008 by Badlop <badlop@process-one.net>
|
%%% Created : 20 May 2008 by Badlop <badlop@process-one.net>
|
||||||
%%%
|
%%%
|
||||||
%%%
|
%%%
|
||||||
%%% ejabberd, Copyright (C) 2002-2016 ProcessOne
|
%%% ejabberd, Copyright (C) 2002-2015 ProcessOne
|
||||||
%%%
|
%%%
|
||||||
%%% This program is free software; you can redistribute it and/or
|
%%% This program is free software; you can redistribute it and/or
|
||||||
%%% modify it under the terms of the GNU General Public License as
|
%%% modify it under the terms of the GNU General Public License as
|
||||||
@ -373,10 +373,27 @@ gen_doc(#ejabberd_commands{name=Name, tags=_Tags, desc=Desc, longdesc=LongDesc,
|
|||||||
?TAG(h2, <<"Examples:">>),
|
?TAG(h2, <<"Examples:">>),
|
||||||
gen_calls(Cmd, HTMLOutput, Langs)].
|
gen_calls(Cmd, HTMLOutput, Langs)].
|
||||||
|
|
||||||
|
find_commands_definitions() ->
|
||||||
|
case code:lib_dir(ejabberd, ebin) of
|
||||||
|
{error, _} ->
|
||||||
|
lists:map(fun({N, _, _}) ->
|
||||||
|
ejabberd_commands:get_command_definition(N)
|
||||||
|
end, ejabberd_commands:list_commands());
|
||||||
|
Path ->
|
||||||
|
lists:flatmap(fun(P) ->
|
||||||
|
Mod = list_to_atom(filename:rootname(P)),
|
||||||
|
code:ensure_loaded(Mod),
|
||||||
|
case erlang:function_exported(Mod, get_commands_spec, 0) of
|
||||||
|
true ->
|
||||||
|
apply(Mod, get_commands_spec, []);
|
||||||
|
_ ->
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end, filelib:wildcard("*.beam", Path))
|
||||||
|
end.
|
||||||
|
|
||||||
generate_html_output(File, RegExp, Languages) ->
|
generate_html_output(File, RegExp, Languages) ->
|
||||||
Cmds = lists:map(fun({N, _, _}) ->
|
Cmds = find_commands_definitions(),
|
||||||
ejabberd_commands:get_command_definition(N)
|
|
||||||
end, ejabberd_commands:list_commands()),
|
|
||||||
{ok, RE} = re:compile(RegExp),
|
{ok, RE} = re:compile(RegExp),
|
||||||
Cmds2 = lists:filter(fun(#ejabberd_commands{name=Name, module=Module}) ->
|
Cmds2 = lists:filter(fun(#ejabberd_commands{name=Name, module=Module}) ->
|
||||||
re:run(atom_to_list(Name), RE, [{capture, none}]) == match orelse
|
re:run(atom_to_list(Name), RE, [{capture, none}]) == match orelse
|
||||||
@ -393,9 +410,7 @@ generate_html_output(File, RegExp, Languages) ->
|
|||||||
ok.
|
ok.
|
||||||
|
|
||||||
generate_md_output(File, RegExp, Languages) ->
|
generate_md_output(File, RegExp, Languages) ->
|
||||||
Cmds = lists:map(fun({N, _, _}) ->
|
Cmds = find_commands_definitions(),
|
||||||
ejabberd_commands:get_command_definition(N)
|
|
||||||
end, ejabberd_commands:list_commands()),
|
|
||||||
{ok, RE} = re:compile(RegExp),
|
{ok, RE} = re:compile(RegExp),
|
||||||
Cmds2 = lists:filter(fun(#ejabberd_commands{name=Name, module=Module}) ->
|
Cmds2 = lists:filter(fun(#ejabberd_commands{name=Name, module=Module}) ->
|
||||||
re:run(atom_to_list(Name), RE, [{capture, none}]) == match orelse
|
re:run(atom_to_list(Name), RE, [{capture, none}]) == match orelse
|
||||||
|
@ -42,7 +42,8 @@
|
|||||||
clean_temporarily_blocked_table/0,
|
clean_temporarily_blocked_table/0,
|
||||||
list_temporarily_blocked_hosts/0,
|
list_temporarily_blocked_hosts/0,
|
||||||
external_host_overloaded/1, is_temporarly_blocked/1,
|
external_host_overloaded/1, is_temporarly_blocked/1,
|
||||||
check_peer_certificate/3]).
|
check_peer_certificate/3,
|
||||||
|
get_commands_spec/0]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2,
|
-export([init/1, handle_call/3, handle_cast/2,
|
||||||
@ -239,7 +240,7 @@ init([]) ->
|
|||||||
{attributes, record_info(fields, s2s)}]),
|
{attributes, record_info(fields, s2s)}]),
|
||||||
mnesia:add_table_copy(s2s, node(), ram_copies),
|
mnesia:add_table_copy(s2s, node(), ram_copies),
|
||||||
mnesia:subscribe(system),
|
mnesia:subscribe(system),
|
||||||
ejabberd_commands:register_commands(commands()),
|
ejabberd_commands:register_commands(get_commands_spec()),
|
||||||
mnesia:create_table(temporarily_blocked,
|
mnesia:create_table(temporarily_blocked,
|
||||||
[{ram_copies, [node()]},
|
[{ram_copies, [node()]},
|
||||||
{attributes, record_info(fields, temporarily_blocked)}]),
|
{attributes, record_info(fields, temporarily_blocked)}]),
|
||||||
@ -265,7 +266,7 @@ handle_info({route, From, To, Packet}, State) ->
|
|||||||
handle_info(_Info, State) -> {noreply, State}.
|
handle_info(_Info, State) -> {noreply, State}.
|
||||||
|
|
||||||
terminate(_Reason, _State) ->
|
terminate(_Reason, _State) ->
|
||||||
ejabberd_commands:unregister_commands(commands()),
|
ejabberd_commands:unregister_commands(get_commands_spec()),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
code_change(_OldVsn, State, _Extra) ->
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
@ -469,7 +470,7 @@ send_element(Pid, El) ->
|
|||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% ejabberd commands
|
%%% ejabberd commands
|
||||||
|
|
||||||
commands() ->
|
get_commands_spec() ->
|
||||||
[#ejabberd_commands{name = incoming_s2s_number,
|
[#ejabberd_commands{name = incoming_s2s_number,
|
||||||
tags = [stats, s2s],
|
tags = [stats, s2s],
|
||||||
desc =
|
desc =
|
||||||
|
@ -63,7 +63,8 @@
|
|||||||
get_user_ip/3,
|
get_user_ip/3,
|
||||||
get_max_user_sessions/2,
|
get_max_user_sessions/2,
|
||||||
get_all_pids/0,
|
get_all_pids/0,
|
||||||
is_existing_resource/3
|
is_existing_resource/3,
|
||||||
|
get_commands_spec/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([init/1, handle_call/3, handle_cast/2,
|
-export([init/1, handle_call/3, handle_cast/2,
|
||||||
@ -323,7 +324,7 @@ init([]) ->
|
|||||||
ejabberd_hooks:add(remove_user, Host,
|
ejabberd_hooks:add(remove_user, Host,
|
||||||
ejabberd_sm, disconnect_removed_user, 100)
|
ejabberd_sm, disconnect_removed_user, 100)
|
||||||
end, ?MYHOSTS),
|
end, ?MYHOSTS),
|
||||||
ejabberd_commands:register_commands(commands()),
|
ejabberd_commands:register_commands(get_commands_spec()),
|
||||||
{ok, #state{}}.
|
{ok, #state{}}.
|
||||||
|
|
||||||
handle_call(_Request, _From, State) ->
|
handle_call(_Request, _From, State) ->
|
||||||
@ -361,7 +362,7 @@ handle_info({unregister_iq_handler, Host, XMLNS},
|
|||||||
handle_info(_Info, State) -> {noreply, State}.
|
handle_info(_Info, State) -> {noreply, State}.
|
||||||
|
|
||||||
terminate(_Reason, _State) ->
|
terminate(_Reason, _State) ->
|
||||||
ejabberd_commands:unregister_commands(commands()),
|
ejabberd_commands:unregister_commands(get_commands_spec()),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
||||||
@ -723,7 +724,7 @@ get_sm_backend() ->
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
%%% ejabberd commands
|
%%% ejabberd commands
|
||||||
|
|
||||||
commands() ->
|
get_commands_spec() ->
|
||||||
[#ejabberd_commands{name = connected_users,
|
[#ejabberd_commands{name = connected_users,
|
||||||
tags = [session],
|
tags = [session],
|
||||||
desc = "List all established sessions",
|
desc = "List all established sessions",
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
installed_command/0, installed/0, installed/1,
|
installed_command/0, installed/0, installed/1,
|
||||||
install/1, uninstall/1, upgrade/0, upgrade/1,
|
install/1, uninstall/1, upgrade/0, upgrade/1,
|
||||||
add_sources/2, del_sources/1, modules_dir/0,
|
add_sources/2, del_sources/1, modules_dir/0,
|
||||||
config_dir/0, opt_type/1]).
|
config_dir/0, opt_type/1, get_commands_spec/0]).
|
||||||
|
|
||||||
-include("ejabberd_commands.hrl").
|
-include("ejabberd_commands.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
@ -46,12 +46,12 @@ start() ->
|
|||||||
[code:add_patha(module_ebin_dir(Module))
|
[code:add_patha(module_ebin_dir(Module))
|
||||||
|| {Module, _} <- installed()],
|
|| {Module, _} <- installed()],
|
||||||
application:start(inets),
|
application:start(inets),
|
||||||
ejabberd_commands:register_commands(commands()).
|
ejabberd_commands:register_commands(get_commands_spec()).
|
||||||
|
|
||||||
stop() ->
|
stop() ->
|
||||||
ejabberd_commands:unregister_commands(commands()).
|
ejabberd_commands:unregister_commands(get_commands_spec()).
|
||||||
|
|
||||||
commands() ->
|
get_commands_spec() ->
|
||||||
[#ejabberd_commands{name = modules_update_specs,
|
[#ejabberd_commands{name = modules_update_specs,
|
||||||
tags = [admin,modules],
|
tags = [admin,modules],
|
||||||
desc = "",
|
desc = "",
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
srg_delete/2, srg_list/1, srg_get_info/2,
|
srg_delete/2, srg_list/1, srg_get_info/2,
|
||||||
srg_get_members/2, srg_user_add/4, srg_user_del/4,
|
srg_get_members/2, srg_user_add/4, srg_user_del/4,
|
||||||
send_message/5, send_stanza/3, send_stanza_c2s/4, privacy_set/3,
|
send_message/5, send_stanza/3, send_stanza_c2s/4, privacy_set/3,
|
||||||
stats/1, stats/2, mod_opt_type/1]).
|
stats/1, stats/2, mod_opt_type/1, get_commands_spec/0]).
|
||||||
|
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
@ -61,17 +61,17 @@
|
|||||||
%%%
|
%%%
|
||||||
|
|
||||||
start(_Host, _Opts) ->
|
start(_Host, _Opts) ->
|
||||||
ejabberd_commands:register_commands(commands()).
|
ejabberd_commands:register_commands(get_commands_spec()).
|
||||||
|
|
||||||
stop(_Host) ->
|
stop(_Host) ->
|
||||||
ejabberd_commands:unregister_commands(commands()).
|
ejabberd_commands:unregister_commands(get_commands_spec()).
|
||||||
|
|
||||||
|
|
||||||
%%%
|
%%%
|
||||||
%%% Register commands
|
%%% Register commands
|
||||||
%%%
|
%%%
|
||||||
|
|
||||||
commands() ->
|
get_commands_spec() ->
|
||||||
Vcard1FieldsString = "Some vcard field names in get/set_vcard are:\n"
|
Vcard1FieldsString = "Some vcard field names in get/set_vcard are:\n"
|
||||||
" FN - Full Name\n"
|
" FN - Full Name\n"
|
||||||
" NICKNAME - Nickname\n"
|
" NICKNAME - Nickname\n"
|
||||||
|
@ -36,7 +36,8 @@
|
|||||||
-export([user_send_packet/4, user_receive_packet/5,
|
-export([user_send_packet/4, user_receive_packet/5,
|
||||||
process_iq_v0_2/3, process_iq_v0_3/3, disco_sm_features/5,
|
process_iq_v0_2/3, process_iq_v0_3/3, disco_sm_features/5,
|
||||||
remove_user/2, remove_user/3, mod_opt_type/1, muc_process_iq/4,
|
remove_user/2, remove_user/3, mod_opt_type/1, muc_process_iq/4,
|
||||||
muc_filter_message/5, message_is_archived/5, delete_old_messages/2]).
|
muc_filter_message/5, message_is_archived/5, delete_old_messages/2,
|
||||||
|
get_commands_spec/0]).
|
||||||
|
|
||||||
-include_lib("stdlib/include/ms_transform.hrl").
|
-include_lib("stdlib/include/ms_transform.hrl").
|
||||||
-include("jlib.hrl").
|
-include("jlib.hrl").
|
||||||
@ -116,7 +117,7 @@ start(Host, Opts) ->
|
|||||||
ejabberd_hooks:add(message_is_archived, Host, ?MODULE,
|
ejabberd_hooks:add(message_is_archived, Host, ?MODULE,
|
||||||
message_is_archived, 50)
|
message_is_archived, 50)
|
||||||
end,
|
end,
|
||||||
ejabberd_commands:register_commands(commands()),
|
ejabberd_commands:register_commands(get_commands_spec()),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
init_db(mnesia, _Host) ->
|
init_db(mnesia, _Host) ->
|
||||||
@ -172,7 +173,7 @@ stop(Host) ->
|
|||||||
ejabberd_hooks:delete(message_is_archived, Host, ?MODULE,
|
ejabberd_hooks:delete(message_is_archived, Host, ?MODULE,
|
||||||
message_is_archived, 50)
|
message_is_archived, 50)
|
||||||
end,
|
end,
|
||||||
ejabberd_commands:unregister_commands(commands()),
|
ejabberd_commands:unregister_commands(get_commands_spec()),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
@ -1364,7 +1365,7 @@ update(LServer, Table, Fields, Vals, Where) ->
|
|||||||
join([], _Sep) -> [];
|
join([], _Sep) -> [];
|
||||||
join([H | T], Sep) -> [H, [[Sep, X] || X <- T]].
|
join([H | T], Sep) -> [H, [[Sep, X] || X <- T]].
|
||||||
|
|
||||||
commands() ->
|
get_commands_spec() ->
|
||||||
[#ejabberd_commands{name = delete_old_mam_messages, tags = [purge],
|
[#ejabberd_commands{name = delete_old_mam_messages, tags = [purge],
|
||||||
desc = "Delete MAM messages older than DAYS",
|
desc = "Delete MAM messages older than DAYS",
|
||||||
longdesc = "Valid message TYPEs: "
|
longdesc = "Valid message TYPEs: "
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
change_room_option/4, get_room_options/2,
|
change_room_option/4, get_room_options/2,
|
||||||
set_room_affiliation/4, get_room_affiliations/2,
|
set_room_affiliation/4, get_room_affiliations/2,
|
||||||
web_menu_main/2, web_page_main/2, web_menu_host/3,
|
web_menu_main/2, web_page_main/2, web_menu_host/3,
|
||||||
web_page_host/3, mod_opt_type/1]).
|
web_page_host/3, mod_opt_type/1, get_commands_spec/0]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
@ -36,14 +36,14 @@
|
|||||||
%%----------------------------
|
%%----------------------------
|
||||||
|
|
||||||
start(Host, _Opts) ->
|
start(Host, _Opts) ->
|
||||||
ejabberd_commands:register_commands(commands()),
|
ejabberd_commands:register_commands(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),
|
||||||
ejabberd_hooks:add(webadmin_page_host, Host, ?MODULE, web_page_host, 50).
|
ejabberd_hooks:add(webadmin_page_host, Host, ?MODULE, web_page_host, 50).
|
||||||
|
|
||||||
stop(Host) ->
|
stop(Host) ->
|
||||||
ejabberd_commands:unregister_commands(commands()),
|
ejabberd_commands:unregister_commands(get_commands_spec()),
|
||||||
ejabberd_hooks:delete(webadmin_menu_main, ?MODULE, web_menu_main, 50),
|
ejabberd_hooks:delete(webadmin_menu_main, ?MODULE, web_menu_main, 50),
|
||||||
ejabberd_hooks:delete(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50),
|
ejabberd_hooks:delete(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50),
|
||||||
ejabberd_hooks:delete(webadmin_page_main, ?MODULE, web_page_main, 50),
|
ejabberd_hooks:delete(webadmin_page_main, ?MODULE, web_page_main, 50),
|
||||||
@ -53,7 +53,7 @@ stop(Host) ->
|
|||||||
%%% Register commands
|
%%% Register commands
|
||||||
%%%
|
%%%
|
||||||
|
|
||||||
commands() ->
|
get_commands_spec() ->
|
||||||
[
|
[
|
||||||
#ejabberd_commands{name = muc_online_rooms, tags = [muc],
|
#ejabberd_commands{name = muc_online_rooms, tags = [muc],
|
||||||
desc = "List existing rooms ('global' to get all vhosts)",
|
desc = "List existing rooms ('global' to get all vhosts)",
|
||||||
|
Loading…
Reference in New Issue
Block a user