aboutsummaryrefslogtreecommitdiff
path: root/src/ejabberd_ctl.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ejabberd_ctl.erl')
-rw-r--r--src/ejabberd_ctl.erl86
1 files changed, 46 insertions, 40 deletions
diff --git a/src/ejabberd_ctl.erl b/src/ejabberd_ctl.erl
index 9b41b1463..2b4702176 100644
--- a/src/ejabberd_ctl.erl
+++ b/src/ejabberd_ctl.erl
@@ -72,10 +72,10 @@ start() ->
_ ->
case net_kernel:longnames() of
true ->
- SNode ++ "@" ++ inet_db:gethostname() ++
- "." ++ inet_db:res_option(domain);
+ lists:flatten([SNode, "@", inet_db:gethostname(),
+ ".", inet_db:res_option(domain)]);
false ->
- SNode ++ "@" ++ inet_db:gethostname();
+ lists:flatten([SNode, "@", inet_db:gethostname()]);
_ ->
SNode
end
@@ -124,6 +124,8 @@ unregister_commands(CmdDescs, Module, Function) ->
%% Process
%%-----------------------------
+-spec process([string()]) -> non_neg_integer().
+
%% The commands status, stop and restart are defined here to ensure
%% they are usable even if ejabberd is completely stopped.
process(["status"]) ->
@@ -159,7 +161,7 @@ process(["mnesia", "info"]) ->
mnesia:info(),
?STATUS_SUCCESS;
-process(["mnesia", Arg]) when is_list(Arg) ->
+process(["mnesia", Arg]) ->
case catch mnesia:system_info(list_to_atom(Arg)) of
{'EXIT', Error} -> ?PRINT("Error: ~p~n", [Error]);
Return -> ?PRINT("~p~n", [Return])
@@ -190,8 +192,9 @@ process(["help" | Mode]) ->
print_usage_help(MaxC, ShCode),
?STATUS_SUCCESS;
[CmdString | _] ->
- CmdStringU = ejabberd_regexp:greplace(CmdString, "-", "_"),
- print_usage_commands(CmdStringU, MaxC, ShCode),
+ CmdStringU = ejabberd_regexp:greplace(
+ list_to_binary(CmdString), <<"-">>, <<"_">>),
+ print_usage_commands(binary_to_list(CmdStringU), MaxC, ShCode),
?STATUS_SUCCESS
end;
@@ -214,30 +217,27 @@ process2(Args, AccessCommands) ->
process2(Args, Auth, AccessCommands) ->
case try_run_ctp(Args, Auth, AccessCommands) of
{String, wrong_command_arguments}
- when is_list(String) ->
+ when is_list(String) ->
io:format(lists:flatten(["\n" | String]++["\n"])),
[CommandString | _] = Args,
process(["help" | [CommandString]]),
{lists:flatten(String), ?STATUS_ERROR};
{String, Code}
- when is_list(String) and is_integer(Code) ->
+ when is_list(String) and is_integer(Code) ->
{lists:flatten(String), Code};
String
- when is_list(String) ->
+ when is_list(String) ->
{lists:flatten(String), ?STATUS_SUCCESS};
Code
- when is_integer(Code) ->
+ when is_integer(Code) ->
{"", Code};
Other ->
{"Erroneous result: " ++ io_lib:format("~p", [Other]), ?STATUS_ERROR}
end.
get_accesscommands() ->
- case ejabberd_config:get_local_option(ejabberdctl_access_commands) of
- ACs when is_list(ACs) -> ACs;
- _ -> []
- end.
-
+ ejabberd_config:get_local_option(ejabberdctl_access_commands,
+ fun(V) when is_list(V) -> V end, []).
%%-----------------------------
%% Command calling
@@ -281,8 +281,9 @@ try_call_command(Args, Auth, AccessCommands) ->
%% @spec (Args::[string()], Auth, AccessCommands) -> string() | integer() | {string(), integer()} | {error, ErrorType}
call_command([CmdString | Args], Auth, AccessCommands) ->
- CmdStringU = ejabberd_regexp:greplace(CmdString, "-", "_"),
- Command = list_to_atom(CmdStringU),
+ CmdStringU = ejabberd_regexp:greplace(
+ list_to_binary(CmdString), <<"-">>, <<"_">>),
+ Command = list_to_atom(binary_to_list(CmdStringU)),
case ejabberd_commands:get_command_format(Command) of
{error, command_unknown} ->
{error, command_unknown};
@@ -331,10 +332,12 @@ format_args(Args, ArgsFormat) ->
format_arg(Arg, integer) ->
format_arg2(Arg, "~d");
+format_arg(Arg, binary) ->
+ list_to_binary(format_arg(Arg, string));
format_arg("", string) ->
"";
format_arg(Arg, string) ->
- NumChars = integer_to_list(string:len(Arg)),
+ NumChars = integer_to_list(length(Arg)),
Parse = "~" ++ NumChars ++ "c",
format_arg2(Arg, Parse).
@@ -540,24 +543,25 @@ split_desc_segments(MaxL, Words) ->
join(L, Words) ->
join(L, Words, 0, [], []).
-join(_L, [], _LenLastSeg, LastSeg, ResSeg) ->
- ResSeg2 = [lists:reverse(LastSeg) | ResSeg],
- lists:reverse(ResSeg2);
-join(L, [Word | Words], LenLastSeg, LastSeg, ResSeg) ->
- LWord = length(Word),
- case LWord + LenLastSeg < L of
- true ->
- %% This word fits in the last segment
- %% If this word ends with "\n", reset column counter
- case string:str(Word, "\n") of
- 0 ->
- join(L, Words, LenLastSeg+LWord+1, [" ", Word | LastSeg], ResSeg);
- _ ->
- join(L, Words, LWord+1, [" ", Word | LastSeg], ResSeg)
- end;
- false ->
- join(L, Words, LWord, [" ", Word], [lists:reverse(LastSeg) | ResSeg])
- end.
+join(_Len, [], _CurSegLen, CurSeg, AllSegs) ->
+ lists:reverse([CurSeg | AllSegs]);
+join(Len, [Word | Tail], CurSegLen, CurSeg, AllSegs) ->
+ WordLen = length(Word),
+ SegSize = WordLen + CurSegLen + 1,
+ {NewCurSeg, NewAllSegs, NewCurSegLen} =
+ if SegSize < Len ->
+ {[CurSeg, " ", Word], AllSegs, SegSize};
+ true ->
+ {Word, [CurSeg | AllSegs], WordLen}
+ end,
+ NewLen = case string:str(Word, "\n") of
+ 0 ->
+ NewCurSegLen;
+ _ ->
+ 0
+ end,
+ join(Len, Tail, NewLen, NewCurSeg, NewAllSegs).
+
format_command_lines(CALD, MaxCmdLen, MaxC, ShCode, dual)
when MaxC - MaxCmdLen < 40 ->
@@ -568,7 +572,8 @@ format_command_lines(CALD, MaxCmdLen, MaxC, ShCode, dual) ->
lists:map(
fun({Cmd, Args, CmdArgsL, Desc}) ->
DescFmt = prepare_description(MaxCmdLen+4, MaxC, Desc),
- [" ", ?B(Cmd), " ", [[?U(Arg), " "] || Arg <- Args], string:chars($\s, MaxCmdLen - CmdArgsL + 1),
+ [" ", ?B(Cmd), " ", [[?U(Arg), " "] || Arg <- Args],
+ string:chars($\s, MaxCmdLen - CmdArgsL + 1),
DescFmt, "\n"]
end, CALD);
@@ -608,7 +613,8 @@ print_usage_tags(Tag, MaxC, ShCode) ->
end,
CommandsList = lists:map(
fun(NameString) ->
- C = ejabberd_commands:get_command_definition(list_to_atom(NameString)),
+ C = ejabberd_commands:get_command_definition(
+ list_to_atom(NameString)),
#ejabberd_commands{name = Name,
args = Args,
desc = Desc} = C,
@@ -689,10 +695,10 @@ filter_commands(All, SubString) ->
end.
filter_commands_regexp(All, Glob) ->
- RegExp = ejabberd_regexp:sh_to_awk(Glob),
+ RegExp = ejabberd_regexp:sh_to_awk(list_to_binary(Glob)),
lists:filter(
fun(Command) ->
- case ejabberd_regexp:run(Command, RegExp) of
+ case ejabberd_regexp:run(list_to_binary(Command), RegExp) of
match ->
true;
nomatch ->