summaryrefslogtreecommitdiff
path: root/src/ejabberd_ctl.erl
diff options
context:
space:
mode:
authorEvgeny Khramtsov <ekhramtsov@process-one.net>2019-06-14 12:33:26 +0300
committerEvgeny Khramtsov <ekhramtsov@process-one.net>2019-06-14 12:33:26 +0300
commita02cff0e780bb735531594c4ece81e8628f79782 (patch)
tree6fe7d8219d14f58183be1741fcea262c216db447 /src/ejabberd_ctl.erl
parentReturn jid_malformed error when sending presence without nick to conference (diff)
Use new configuration validator
Diffstat (limited to 'src/ejabberd_ctl.erl')
-rw-r--r--src/ejabberd_ctl.erl89
1 files changed, 35 insertions, 54 deletions
diff --git a/src/ejabberd_ctl.erl b/src/ejabberd_ctl.erl
index f4a898c1..e1c29400 100644
--- a/src/ejabberd_ctl.erl
+++ b/src/ejabberd_ctl.erl
@@ -45,13 +45,11 @@
-module(ejabberd_ctl).
--behaviour(ejabberd_config).
-behaviour(gen_server).
-author('alexey@process-one.net').
-export([start/0, start_link/0, process/1, process2/2,
- register_commands/3, unregister_commands/3,
- opt_type/1]).
+ register_commands/3, unregister_commands/3]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
@@ -177,7 +175,7 @@ process(["status"], _Version) ->
"or other files in that directory.~n", [EjabberdLogPath]),
?STATUS_ERROR;
true ->
- print("ejabberd ~s is running in that node~n", [ejabberd_config:get_version()]),
+ print("ejabberd ~s is running in that node~n", [ejabberd_option:version()]),
?STATUS_SUCCESS
end;
@@ -248,8 +246,7 @@ process(["--version", Arg | Args], _) ->
process(Args, Version);
process(Args, Version) ->
- AccessCommands = get_accesscommands(),
- {String, Code} = process2(Args, AccessCommands, Version),
+ {String, Code} = process2(Args, [], Version),
case String of
[] -> ok;
_ ->
@@ -291,9 +288,6 @@ process2(Args, AccessCommands, Auth, Version) ->
{"Erroneous result: " ++ io_lib:format("~p", [Other]), ?STATUS_ERROR}
end.
-get_accesscommands() ->
- ejabberd_config:get_option(ejabberdctl_access_commands, []).
-
%%-----------------------------
%% Command calling
%%-----------------------------
@@ -322,8 +316,8 @@ try_run_ctp(Args, Auth, AccessCommands, Version) ->
%% @spec (Args::[string()], Auth, AccessCommands) -> string() | integer() | {string(), integer()}
try_call_command(Args, Auth, AccessCommands, Version) ->
try call_command(Args, Auth, AccessCommands, Version) of
- {error, wrong_command_arguments} ->
- {"Error: wrong arguments", ?STATUS_ERROR};
+ {Reason, wrong_command_arguments} ->
+ {Reason, ?STATUS_ERROR};
Res ->
Res
catch
@@ -346,32 +340,28 @@ call_command([CmdString | Args], Auth, _AccessCommands, Version) ->
CmdStringU = ejabberd_regexp:greplace(
list_to_binary(CmdString), <<"-">>, <<"_">>),
Command = list_to_atom(binary_to_list(CmdStringU)),
- case ejabberd_commands:get_command_format(Command, Auth, Version) of
- {error, command_unknown} ->
- throw({error, unknown_command});
- {ArgsFormat, ResultFormat} ->
- case (catch format_args(Args, ArgsFormat)) of
- ArgsFormatted when is_list(ArgsFormatted) ->
- CI = case Auth of
- {U, S, _, _} -> #{usr => {U, S, <<"">>}, caller_host => S};
- _ -> #{}
- end,
- CI2 = CI#{caller_module => ?MODULE},
- Result = ejabberd_commands:execute_command2(Command,
- ArgsFormatted,
- CI2,
- Version),
- format_result(Result, ResultFormat);
- {'EXIT', {function_clause,[{lists,zip,[A1, A2], _} | _]}} ->
- {NumCompa, TextCompa} =
- case {length(A1), length(A2)} of
- {L1, L2} when L1 < L2 -> {L2-L1, "less argument"};
- {L1, L2} when L1 > L2 -> {L1-L2, "more argument"}
- end,
- {io_lib:format("Error: the command ~p requires ~p ~s.",
- [CmdString, NumCompa, TextCompa]),
- wrong_command_arguments}
- end
+ {ArgsFormat, ResultFormat} = ejabberd_commands:get_command_format(Command, Auth, Version),
+ case (catch format_args(Args, ArgsFormat)) of
+ ArgsFormatted when is_list(ArgsFormatted) ->
+ CI = case Auth of
+ {U, S, _, _} -> #{usr => {U, S, <<"">>}, caller_host => S};
+ _ -> #{}
+ end,
+ CI2 = CI#{caller_module => ?MODULE},
+ Result = ejabberd_commands:execute_command2(Command,
+ ArgsFormatted,
+ CI2,
+ Version),
+ format_result(Result, ResultFormat);
+ {'EXIT', {function_clause,[{lists,zip,[A1, A2], _} | _]}} ->
+ {NumCompa, TextCompa} =
+ case {length(A1), length(A2)} of
+ {L1, L2} when L1 < L2 -> {L2-L1, "less argument"};
+ {L1, L2} when L1 > L2 -> {L1-L2, "more argument"}
+ end,
+ {io_lib:format("Error: the command ~p requires ~p ~s.",
+ [CmdString, NumCompa, TextCompa]),
+ wrong_command_arguments}
end.
@@ -735,11 +725,12 @@ print_usage_help(MaxC, ShCode) ->
"Those commands can be identified because the description starts with: *"],
ArgsDef = [],
C = #ejabberd_commands{
- desc = "Show help of ejabberd commands",
- longdesc = lists:flatten(LongDesc),
- args = ArgsDef,
- result = {help, string}},
- print_usage_command("help", C, MaxC, ShCode).
+ name = help,
+ desc = "Show help of ejabberd commands",
+ longdesc = lists:flatten(LongDesc),
+ args = ArgsDef,
+ result = {help, string}},
+ print_usage_command2("help", C, MaxC, ShCode).
%%-----------------------------
@@ -792,12 +783,8 @@ filter_commands_regexp(All, Glob) ->
%% @spec (Cmd::string(), MaxC::integer(), ShCode::boolean()) -> ok
print_usage_command(Cmd, MaxC, ShCode, Version) ->
Name = list_to_atom(Cmd),
- case ejabberd_commands:get_command_definition(Name, Version) of
- command_not_found ->
- io:format("Error: command ~p not known.~n", [Cmd]);
- C ->
- print_usage_command2(Cmd, C, MaxC, ShCode)
- end.
+ C = ejabberd_commands:get_command_definition(Name, Version),
+ print_usage_command2(Cmd, C, MaxC, ShCode).
print_usage_command2(Cmd, C, MaxC, ShCode) ->
#ejabberd_commands{
@@ -881,9 +868,3 @@ print(Format, Args) ->
%% Struct(Integer res) create_account(Struct(String user, String server, String password))
%%format_usage_xmlrpc(ArgsDef, ResultDef) ->
%% ["aaaa bbb ccc"].
-
-
--spec opt_type(atom()) -> fun((any()) -> any()) | [atom()].
-opt_type(ejabberdctl_access_commands) ->
- fun (V) when is_list(V) -> V end;
-opt_type(_) -> [ejabberdctl_access_commands].