aboutsummaryrefslogtreecommitdiff
path: root/src/mod_http_api.erl
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2019-06-18 11:09:35 +0200
committerBadlop <badlop@process-one.net>2019-06-19 09:30:53 +0200
commitfb77e2e8c0a63e5ac3a3888dfbde92f1057c3089 (patch)
tree8e26287da0e79e429921fdfcec531a69f3b07b43 /src/mod_http_api.erl
parentFix support for nonexistent or empty access_commands in ejabberd_xmlrpc (diff)
Add support for backwards compatibility in command argument names (#2908)
Diffstat (limited to 'src/mod_http_api.erl')
-rw-r--r--src/mod_http_api.erl17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/mod_http_api.erl b/src/mod_http_api.erl
index 4e2ecdcdd..28228f3e5 100644
--- a/src/mod_http_api.erl
+++ b/src/mod_http_api.erl
@@ -304,8 +304,8 @@ handle(Call, Auth, Args, Version) when is_atom(Call), is_list(Args) ->
end.
handle2(Call, Auth, Args, Version) when is_atom(Call), is_list(Args) ->
- {ArgsF, _ResultF} = ejabberd_commands:get_command_format(Call, Auth, Version),
- ArgsFormatted = format_args(Call, Args, ArgsF),
+ {ArgsF, ArgsR, _ResultF} = ejabberd_commands:get_command_format(Call, Auth, Version),
+ ArgsFormatted = format_args(Call, rename_old_args(Args, ArgsR), ArgsF),
case ejabberd_commands:execute_command2(Call, ArgsFormatted, Auth, Version) of
{error, Error} ->
throw(Error);
@@ -313,6 +313,17 @@ handle2(Call, Auth, Args, Version) when is_atom(Call), is_list(Args) ->
format_command_result(Call, Auth, Res, Version)
end.
+rename_old_args(Args, []) ->
+ Args;
+rename_old_args(Args, [{OldName, NewName} | ArgsR]) ->
+ Args2 = case lists:keytake(OldName, 1, Args) of
+ {value, {OldName, Value}, ArgsTail} ->
+ [{NewName, Value} | ArgsTail];
+ false ->
+ Args
+ end,
+ rename_old_args(Args2, ArgsR).
+
get_elem_delete(Call, A, L, F) ->
case proplists:get_all_values(A, L) of
[Value] -> {Value, proplists:delete(A, L)};
@@ -422,7 +433,7 @@ process_unicode_codepoints(Str) ->
%% ----------------
format_command_result(Cmd, Auth, Result, Version) ->
- {_, ResultFormat} = ejabberd_commands:get_command_format(Cmd, Auth, Version),
+ {_, _, ResultFormat} = ejabberd_commands:get_command_format(Cmd, Auth, Version),
case {ResultFormat, Result} of
{{_, rescode}, V} when V == true; V == ok ->
{200, 0};