2013-12-10 12:25:12 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_xmlrpc.erl
|
|
|
|
%%% Author : Badlop <badlop@process-one.net>
|
|
|
|
%%% Purpose : XML-RPC server that frontends ejabberd commands
|
2015-05-29 15:48:43 +02:00
|
|
|
%%% Created : 21 Aug 2007 by Badlop <badlop@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2024-01-22 16:40:01 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2024 ProcessOne
|
2015-05-29 15:48:43 +02:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
|
|
|
%%%
|
2015-08-05 09:52:54 +02:00
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2015-05-29 15:48:43 +02:00
|
|
|
%%%
|
2013-12-10 12:25:12 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
%%% TODO: Remove support for plaintext password
|
|
|
|
|
|
|
|
%%% TODO: commands strings should be strings without ~n
|
|
|
|
|
|
|
|
-module(ejabberd_xmlrpc).
|
2018-09-17 10:21:02 +02:00
|
|
|
-behaviour(ejabberd_listener).
|
2013-12-10 12:25:12 +01:00
|
|
|
|
|
|
|
-author('badlop@process-one.net').
|
|
|
|
|
2019-04-01 15:53:28 +02:00
|
|
|
-export([start/3, start_link/3, handler/2, process/2, accept/1,
|
2019-06-24 16:20:29 +02:00
|
|
|
listen_options/0]).
|
2013-12-10 12:25:12 +01:00
|
|
|
|
|
|
|
-include("logger.hrl").
|
2014-10-03 16:53:55 +02:00
|
|
|
-include("ejabberd_http.hrl").
|
2013-12-10 12:25:12 +01:00
|
|
|
-include("mod_roster.hrl").
|
|
|
|
|
2020-09-03 13:45:57 +02:00
|
|
|
-include_lib("xmpp/include/xmpp.hrl").
|
2013-12-10 12:25:12 +01:00
|
|
|
|
|
|
|
-record(state,
|
2020-05-05 19:20:22 +02:00
|
|
|
{auth = noauth :: noauth | map(),
|
2016-10-14 13:55:50 +02:00
|
|
|
get_auth = true :: boolean(),
|
|
|
|
ip :: inet:ip_address()}).
|
2013-12-10 12:25:12 +01:00
|
|
|
|
|
|
|
%% -----------------------------
|
|
|
|
%% Listener interface
|
|
|
|
%% -----------------------------
|
|
|
|
|
2019-06-24 16:13:34 +02:00
|
|
|
start(SockMod, Socket, Opts) ->
|
|
|
|
Opts1 = [{request_handlers, [{[], ?MODULE}]}|Opts],
|
|
|
|
ejabberd_http:start(SockMod, Socket, Opts1).
|
2014-10-03 16:53:55 +02:00
|
|
|
|
2019-06-24 16:13:34 +02:00
|
|
|
start_link(SockMod, Socket, Opts) ->
|
|
|
|
Opts1 = [{request_handlers, [{[], ?MODULE}]}|Opts],
|
|
|
|
ejabberd_http:start_link(SockMod, Socket, Opts1).
|
2018-09-17 10:21:02 +02:00
|
|
|
|
|
|
|
accept(Pid) ->
|
|
|
|
ejabberd_http:accept(Pid).
|
2014-10-03 16:53:55 +02:00
|
|
|
|
|
|
|
%% -----------------------------
|
|
|
|
%% HTTP interface
|
|
|
|
%% -----------------------------
|
2019-07-16 12:56:41 +02:00
|
|
|
|
2020-05-05 19:20:22 +02:00
|
|
|
process(_, #request{method = 'POST', data = Data, ip = {IP, _}}) ->
|
2015-09-25 14:53:25 +02:00
|
|
|
GetAuth = true,
|
2020-05-05 19:20:22 +02:00
|
|
|
State = #state{get_auth = GetAuth, ip = IP},
|
2016-02-03 19:03:17 +01:00
|
|
|
case fxml_stream:parse_element(Data) of
|
2014-10-04 10:37:31 +02:00
|
|
|
{error, _} ->
|
2014-10-03 16:53:55 +02:00
|
|
|
{400, [],
|
|
|
|
#xmlel{name = <<"h1">>, attrs = [],
|
2014-10-04 10:37:31 +02:00
|
|
|
children = [{xmlcdata, <<"Malformed XML">>}]}};
|
|
|
|
El ->
|
2016-02-03 19:03:17 +01:00
|
|
|
case fxmlrpc:decode(El) of
|
2014-10-04 10:37:31 +02:00
|
|
|
{error, _} = Err ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?ERROR_MSG("XML-RPC request ~ts failed with reason: ~p",
|
2014-10-04 10:37:31 +02:00
|
|
|
[Data, Err]),
|
|
|
|
{400, [],
|
|
|
|
#xmlel{name = <<"h1">>, attrs = [],
|
|
|
|
children = [{xmlcdata, <<"Malformed Request">>}]}};
|
|
|
|
{ok, RPC} ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?DEBUG("Got XML-RPC request: ~p", [RPC]),
|
2014-10-04 10:37:31 +02:00
|
|
|
{false, Result} = handler(State, RPC),
|
2016-02-03 19:03:17 +01:00
|
|
|
XML = fxml:element_to_binary(fxmlrpc:encode(Result)),
|
2014-10-04 10:55:59 +02:00
|
|
|
{200, [{<<"Content-Type">>, <<"text/xml">>}],
|
2014-10-04 10:37:31 +02:00
|
|
|
<<"<?xml version=\"1.0\"?>", XML/binary>>}
|
|
|
|
end
|
2014-10-03 16:53:55 +02:00
|
|
|
end;
|
|
|
|
process(_, _) ->
|
|
|
|
{400, [],
|
|
|
|
#xmlel{name = <<"h1">>, attrs = [],
|
|
|
|
children = [{xmlcdata, <<"400 Bad Request">>}]}}.
|
2013-12-10 12:25:12 +01:00
|
|
|
|
|
|
|
%% -----------------------------
|
|
|
|
%% Access verification
|
|
|
|
%% -----------------------------
|
2019-07-16 12:56:41 +02:00
|
|
|
|
2019-06-14 11:33:26 +02:00
|
|
|
-spec extract_auth([{user | server | token | password, binary()}]) ->
|
|
|
|
map() | {error, not_found | expired | invalid_auth}.
|
2016-10-14 13:55:50 +02:00
|
|
|
extract_auth(AuthList) ->
|
|
|
|
?DEBUG("AUTHLIST ~p", [AuthList]),
|
2015-09-25 14:53:25 +02:00
|
|
|
try get_attrs([user, server, token], AuthList) of
|
2016-10-14 13:55:50 +02:00
|
|
|
[U0, S0, T] ->
|
|
|
|
U = jid:nodeprep(U0),
|
|
|
|
S = jid:nameprep(S0),
|
|
|
|
case ejabberd_oauth:check_token(T) of
|
|
|
|
{ok, {U, S}, Scope} ->
|
|
|
|
#{usr => {U, S, <<"">>}, oauth_scope => Scope, caller_server => S};
|
|
|
|
{false, Reason} ->
|
|
|
|
{error, Reason};
|
|
|
|
_ ->
|
|
|
|
{error, not_found}
|
|
|
|
end
|
2015-09-25 14:53:25 +02:00
|
|
|
catch
|
2017-03-13 16:41:52 +01:00
|
|
|
exit:{attribute_not_found, _, _} ->
|
2015-09-25 14:53:25 +02:00
|
|
|
try get_attrs([user, server, password], AuthList) of
|
2016-10-14 13:55:50 +02:00
|
|
|
[U0, S0, P] ->
|
|
|
|
U = jid:nodeprep(U0),
|
|
|
|
S = jid:nameprep(S0),
|
|
|
|
case ejabberd_auth:check_password(U, <<"">>, S, P) of
|
|
|
|
true ->
|
|
|
|
#{usr => {U, S, <<"">>}, caller_server => S};
|
|
|
|
false ->
|
|
|
|
{error, invalid_auth}
|
|
|
|
end
|
2015-09-25 14:53:25 +02:00
|
|
|
catch
|
2017-03-13 16:41:52 +01:00
|
|
|
exit:{attribute_not_found, Attr, _} ->
|
|
|
|
throw({error, missing_auth_arguments, Attr})
|
2015-09-25 14:53:25 +02:00
|
|
|
end
|
|
|
|
end.
|
2013-12-10 12:25:12 +01:00
|
|
|
|
|
|
|
%% -----------------------------
|
|
|
|
%% Handlers
|
|
|
|
%% -----------------------------
|
|
|
|
|
2016-10-14 13:55:50 +02:00
|
|
|
handler(#state{get_auth = true, auth = noauth, ip = IP} = State,
|
2013-12-10 12:25:12 +01:00
|
|
|
{call, Method,
|
|
|
|
[{struct, AuthList} | Arguments] = AllArgs}) ->
|
2016-10-14 13:55:50 +02:00
|
|
|
try extract_auth(AuthList) of
|
|
|
|
{error, invalid_auth} ->
|
|
|
|
build_fault_response(-118,
|
|
|
|
"Invalid authentication data",
|
|
|
|
[]);
|
|
|
|
{error, not_found} ->
|
|
|
|
build_fault_response(-118,
|
|
|
|
"Invalid oauth token",
|
|
|
|
[]);
|
|
|
|
{error, expired} ->
|
|
|
|
build_fault_response(-118,
|
|
|
|
"Invalid oauth token",
|
|
|
|
[]);
|
2015-09-25 14:53:25 +02:00
|
|
|
Auth ->
|
2016-10-14 13:55:50 +02:00
|
|
|
handler(State#state{get_auth = false, auth = Auth#{ip => IP, caller_module => ?MODULE}},
|
2015-09-25 14:53:25 +02:00
|
|
|
{call, Method, Arguments})
|
2013-12-10 12:25:12 +01:00
|
|
|
catch
|
|
|
|
{error, missing_auth_arguments, _Attr} ->
|
2017-03-13 16:41:52 +01:00
|
|
|
handler(State#state{get_auth = false,
|
|
|
|
auth = #{ip => IP, caller_module => ?MODULE}},
|
2013-12-10 12:25:12 +01:00
|
|
|
{call, Method, AllArgs})
|
|
|
|
end;
|
2019-07-16 12:56:41 +02:00
|
|
|
|
2013-12-10 12:25:12 +01:00
|
|
|
%% .............................
|
|
|
|
%% Debug
|
2019-07-16 12:56:41 +02:00
|
|
|
|
2013-12-10 12:25:12 +01:00
|
|
|
handler(_State, {call, echothis, [A]}) ->
|
|
|
|
{false, {response, [A]}};
|
2019-07-16 12:56:41 +02:00
|
|
|
|
2013-12-10 12:25:12 +01:00
|
|
|
handler(_State,
|
|
|
|
{call, echothisnew, [{struct, [{sentence, A}]}]}) ->
|
|
|
|
{false, {response, [{struct, [{repeated, A}]}]}};
|
2019-07-16 12:56:41 +02:00
|
|
|
|
2013-12-10 12:25:12 +01:00
|
|
|
handler(_State,
|
|
|
|
{call, multhis, [{struct, [{a, A}, {b, B}]}]}) ->
|
|
|
|
{false, {response, [A * B]}};
|
2019-07-16 12:56:41 +02:00
|
|
|
|
2013-12-10 12:25:12 +01:00
|
|
|
handler(_State,
|
|
|
|
{call, multhisnew, [{struct, [{a, A}, {b, B}]}]}) ->
|
|
|
|
{false, {response, [{struct, [{mu, A * B}]}]}};
|
2019-07-16 12:56:41 +02:00
|
|
|
|
2013-12-10 12:25:12 +01:00
|
|
|
%% .............................
|
|
|
|
%% ejabberd commands
|
2019-07-16 12:56:41 +02:00
|
|
|
|
2013-12-10 12:25:12 +01:00
|
|
|
handler(State, {call, Command, []}) ->
|
|
|
|
handler(State, {call, Command, [{struct, []}]});
|
|
|
|
handler(State,
|
2019-06-14 11:33:26 +02:00
|
|
|
{call, Command, [{struct, AttrL}]}) ->
|
2019-06-18 11:09:35 +02:00
|
|
|
{ArgsF, ArgsR, ResultF} = ejabberd_commands:get_command_format(Command, State#state.auth),
|
2020-05-05 19:20:22 +02:00
|
|
|
try_do_command(State#state.auth, Command, AttrL, ArgsF, ArgsR, ResultF);
|
2013-12-10 12:25:12 +01:00
|
|
|
handler(_State, Payload) ->
|
|
|
|
build_fault_response(-112, "Unknown call: ~p",
|
|
|
|
[Payload]).
|
|
|
|
|
|
|
|
%% -----------------------------
|
|
|
|
%% Command
|
|
|
|
%% -----------------------------
|
|
|
|
|
2020-05-05 19:20:22 +02:00
|
|
|
try_do_command(Auth, Command, AttrL, ArgsF, ArgsR, ResultF) ->
|
|
|
|
try do_command(Auth, Command, AttrL, ArgsF, ArgsR, ResultF)
|
2013-12-10 12:25:12 +01:00
|
|
|
of
|
|
|
|
{command_result, ResultFormatted} ->
|
|
|
|
{false, {response, [ResultFormatted]}}
|
|
|
|
catch
|
|
|
|
exit:{duplicated_attribute, ExitAt, ExitAtL} ->
|
|
|
|
build_fault_response(-114,
|
|
|
|
"Attribute '~p' duplicated:~n~p",
|
|
|
|
[ExitAt, ExitAtL]);
|
|
|
|
exit:{attribute_not_found, ExitAt, ExitAtL} ->
|
|
|
|
build_fault_response(-116,
|
|
|
|
"Required attribute '~p' not found:~n~p",
|
|
|
|
[ExitAt, ExitAtL]);
|
|
|
|
exit:{additional_unused_args, ExitAtL} ->
|
|
|
|
build_fault_response(-120,
|
|
|
|
"The call provided additional unused "
|
|
|
|
"arguments:~n~p",
|
|
|
|
[ExitAtL]);
|
2016-06-16 10:24:50 +02:00
|
|
|
exit:{invalid_arg_type, Arg, Type} ->
|
|
|
|
build_fault_response(-122,
|
|
|
|
"Parameter '~p' can't be coerced to type '~p'",
|
|
|
|
[Arg, Type]);
|
2013-12-10 12:25:12 +01:00
|
|
|
Why ->
|
|
|
|
build_fault_response(-118,
|
|
|
|
"A problem '~p' occurred executing the "
|
|
|
|
"command ~p with arguments~n~p",
|
|
|
|
[Why, Command, AttrL])
|
|
|
|
end.
|
|
|
|
|
|
|
|
build_fault_response(Code, ParseString, ParseArgs) ->
|
|
|
|
FaultString = "Error " ++ integer_to_list(Code) ++ "\n"
|
|
|
|
++ lists:flatten(io_lib:format(ParseString, ParseArgs)),
|
|
|
|
?WARNING_MSG(FaultString, []),
|
2015-01-15 17:39:12 +01:00
|
|
|
{false, {response, {fault, Code, list_to_binary(FaultString)}}}.
|
2013-12-10 12:25:12 +01:00
|
|
|
|
2020-05-05 19:20:22 +02:00
|
|
|
do_command(Auth, Command, AttrL, ArgsF, ArgsR,
|
2013-12-10 12:25:12 +01:00
|
|
|
ResultF) ->
|
2019-06-18 11:09:35 +02:00
|
|
|
ArgsFormatted = format_args(rename_old_args(AttrL, ArgsR), ArgsF),
|
2020-05-05 19:20:22 +02:00
|
|
|
Result = ejabberd_commands:execute_command2(Command, ArgsFormatted, Auth),
|
2013-12-10 12:25:12 +01:00
|
|
|
ResultFormatted = format_result(Result, ResultF),
|
2023-11-28 16:16:14 +01:00
|
|
|
{command_result, {struct, [ResultFormatted]}}.
|
2013-12-10 12:25:12 +01:00
|
|
|
|
2019-06-18 11:09:35 +02:00
|
|
|
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).
|
|
|
|
|
2013-12-10 12:25:12 +01:00
|
|
|
%%-----------------------------
|
|
|
|
%% Format arguments
|
|
|
|
%%-----------------------------
|
|
|
|
|
|
|
|
get_attrs(Attribute_names, L) ->
|
|
|
|
[get_attr(A, L) || A <- Attribute_names].
|
|
|
|
|
|
|
|
get_attr(A, L) ->
|
|
|
|
case lists:keysearch(A, 1, L) of
|
|
|
|
{value, {A, Value}} -> Value;
|
|
|
|
false ->
|
|
|
|
exit({attribute_not_found, A, L})
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_elem_delete(A, L) ->
|
|
|
|
case proplists:get_all_values(A, L) of
|
|
|
|
[Value] -> {Value, proplists:delete(A, L)};
|
|
|
|
[_, _ | _] ->
|
|
|
|
exit({duplicated_attribute, A, L});
|
|
|
|
[] ->
|
|
|
|
exit({attribute_not_found, A, L})
|
|
|
|
end.
|
|
|
|
|
|
|
|
format_args(Args, ArgsFormat) ->
|
|
|
|
{ArgsRemaining, R} = lists:foldl(fun ({ArgName,
|
|
|
|
ArgFormat},
|
|
|
|
{Args1, Res}) ->
|
|
|
|
{ArgValue, Args2} =
|
|
|
|
get_elem_delete(ArgName,
|
|
|
|
Args1),
|
|
|
|
Formatted = format_arg(ArgValue,
|
|
|
|
ArgFormat),
|
|
|
|
{Args2, Res ++ [Formatted]}
|
|
|
|
end,
|
|
|
|
{Args, []}, ArgsFormat),
|
|
|
|
case ArgsRemaining of
|
|
|
|
[] -> R;
|
|
|
|
L when is_list(L) -> exit({additional_unused_args, L})
|
|
|
|
end.
|
|
|
|
|
2023-11-28 16:16:14 +01:00
|
|
|
format_arg({array, Elements},
|
|
|
|
{list, {_ElementDefName, ElementDefFormat}})
|
|
|
|
when is_list(Elements) ->
|
|
|
|
lists:map(fun (ElementValue) ->
|
|
|
|
format_arg(ElementValue, ElementDefFormat)
|
|
|
|
end,
|
|
|
|
Elements);
|
|
|
|
|
2013-12-10 12:25:12 +01:00
|
|
|
format_arg({array, Elements},
|
|
|
|
{list, {ElementDefName, ElementDefFormat}})
|
|
|
|
when is_list(Elements) ->
|
|
|
|
lists:map(fun ({struct, [{ElementName, ElementValue}]}) when
|
|
|
|
ElementDefName == ElementName ->
|
|
|
|
format_arg(ElementValue, ElementDefFormat)
|
|
|
|
end,
|
|
|
|
Elements);
|
|
|
|
format_arg({array, [{struct, Elements}]},
|
|
|
|
{list, {ElementDefName, ElementDefFormat}})
|
|
|
|
when is_list(Elements) ->
|
|
|
|
lists:map(fun ({ElementName, ElementValue}) ->
|
|
|
|
true = ElementDefName == ElementName,
|
|
|
|
format_arg(ElementValue, ElementDefFormat)
|
|
|
|
end,
|
|
|
|
Elements);
|
2023-11-28 16:16:14 +01:00
|
|
|
%% Old ejabberd 23.10
|
2013-12-10 12:25:12 +01:00
|
|
|
format_arg({array, [{struct, Elements}]},
|
|
|
|
{tuple, ElementsDef})
|
|
|
|
when is_list(Elements) ->
|
|
|
|
FormattedList = format_args(Elements, ElementsDef),
|
|
|
|
list_to_tuple(FormattedList);
|
2024-02-24 17:40:03 +01:00
|
|
|
%% New ejabberd 24.02
|
2023-11-28 16:16:14 +01:00
|
|
|
format_arg({struct, Elements},
|
|
|
|
{tuple, ElementsDef})
|
|
|
|
when is_list(Elements) ->
|
|
|
|
FormattedList = format_args(Elements, ElementsDef),
|
|
|
|
list_to_tuple(FormattedList);
|
2013-12-10 12:25:12 +01:00
|
|
|
format_arg({array, Elements}, {list, ElementsDef})
|
|
|
|
when is_list(Elements) and is_atom(ElementsDef) ->
|
|
|
|
[format_arg(Element, ElementsDef)
|
|
|
|
|| Element <- Elements];
|
|
|
|
format_arg(Arg, integer) when is_integer(Arg) -> Arg;
|
2015-05-29 15:48:43 +02:00
|
|
|
format_arg(Arg, binary) when is_list(Arg) -> process_unicode_codepoints(Arg);
|
2013-12-10 12:25:12 +01:00
|
|
|
format_arg(Arg, binary) when is_binary(Arg) -> Arg;
|
2014-11-20 11:21:51 +01:00
|
|
|
format_arg(Arg, string) when is_list(Arg) -> Arg;
|
|
|
|
format_arg(Arg, string) when is_binary(Arg) -> binary_to_list(Arg);
|
2015-04-04 13:48:17 +02:00
|
|
|
format_arg(undefined, binary) -> <<>>;
|
|
|
|
format_arg(undefined, string) -> "";
|
2014-04-30 15:59:44 +02:00
|
|
|
format_arg(Arg, Format) ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?ERROR_MSG("Don't know how to format Arg ~p for format ~p", [Arg, Format]),
|
2016-06-16 10:24:50 +02:00
|
|
|
exit({invalid_arg_type, Arg, Format}).
|
2015-05-29 15:48:43 +02:00
|
|
|
|
|
|
|
process_unicode_codepoints(Str) ->
|
|
|
|
iolist_to_binary(lists:map(fun(X) when X > 255 -> unicode:characters_to_binary([X]);
|
|
|
|
(Y) -> Y
|
|
|
|
end, Str)).
|
2013-12-10 12:25:12 +01:00
|
|
|
|
|
|
|
%% -----------------------------
|
|
|
|
%% Result
|
|
|
|
%% -----------------------------
|
|
|
|
|
2023-11-28 16:16:14 +01:00
|
|
|
format_result(Code, {Name, rescode}) ->
|
|
|
|
{Name, make_status(Code)};
|
|
|
|
format_result({_Code, Text}, {_Name, restuple}) ->
|
|
|
|
{text, io_lib:format("~s", [Text])};
|
2019-10-18 11:52:03 +02:00
|
|
|
format_result({error, Error}, _) when is_list(Error) ->
|
|
|
|
throw({error, lists:flatten(Error)});
|
2013-12-10 12:25:12 +01:00
|
|
|
format_result({error, Error}, _) ->
|
|
|
|
throw({error, Error});
|
2019-10-18 11:52:03 +02:00
|
|
|
format_result({error, _Type, _Code, Error}, _) when is_list(Error) ->
|
|
|
|
throw({error, lists:flatten(Error)});
|
2016-10-14 13:55:50 +02:00
|
|
|
format_result({error, _Type, _Code, Error}, _) ->
|
|
|
|
throw({error, Error});
|
2013-12-10 12:25:12 +01:00
|
|
|
format_result(String, string) -> lists:flatten(String);
|
|
|
|
format_result(Atom, {Name, atom}) ->
|
2023-11-28 16:16:14 +01:00
|
|
|
{Name, iolist_to_binary(atom_to_list(Atom))};
|
2013-12-10 12:25:12 +01:00
|
|
|
format_result(Int, {Name, integer}) ->
|
2023-11-28 16:16:14 +01:00
|
|
|
{Name, Int};
|
2016-03-07 17:34:08 +01:00
|
|
|
format_result([A|_]=String, {Name, string}) when is_list(String) and is_integer(A) ->
|
2023-11-28 16:16:14 +01:00
|
|
|
{Name, lists:flatten(String)};
|
2013-12-10 12:25:12 +01:00
|
|
|
format_result(Binary, {Name, string}) when is_binary(Binary) ->
|
2023-11-28 16:16:14 +01:00
|
|
|
{Name, binary_to_list(Binary)};
|
2015-05-15 17:47:10 +02:00
|
|
|
format_result(Atom, {Name, string}) when is_atom(Atom) ->
|
2023-11-28 16:16:14 +01:00
|
|
|
{Name, atom_to_list(Atom)};
|
2015-05-15 17:47:10 +02:00
|
|
|
format_result(Integer, {Name, string}) when is_integer(Integer) ->
|
2023-11-28 16:16:14 +01:00
|
|
|
{Name, integer_to_list(Integer)};
|
2015-05-15 17:47:10 +02:00
|
|
|
format_result(Other, {Name, string}) ->
|
2023-11-28 16:16:14 +01:00
|
|
|
{Name, io_lib:format("~p", [Other])};
|
2014-06-05 16:18:17 +02:00
|
|
|
format_result(String, {Name, binary}) when is_list(String) ->
|
2023-11-28 16:16:14 +01:00
|
|
|
{Name, lists:flatten(String)};
|
2014-06-05 16:18:17 +02:00
|
|
|
format_result(Binary, {Name, binary}) when is_binary(Binary) ->
|
2023-11-28 16:16:14 +01:00
|
|
|
{Name, binary_to_list(Binary)};
|
|
|
|
|
|
|
|
|
|
|
|
format_result(Els, {Name, {list, Def}}) ->
|
|
|
|
FormattedList = [element(2, format_result(El, Def)) || El <- Els],
|
|
|
|
{Name, {array, FormattedList}};
|
|
|
|
|
|
|
|
|
|
|
|
format_result(Tuple,
|
|
|
|
{Name, {tuple, Def}}) ->
|
|
|
|
Els = lists:zip(tuple_to_list(Tuple), Def),
|
|
|
|
FormattedList = [format_result(El, ElDef) || {El, ElDef} <- Els],
|
|
|
|
{Name, {struct, FormattedList}};
|
|
|
|
|
2013-12-10 12:25:12 +01:00
|
|
|
format_result(404, {Name, _}) ->
|
|
|
|
{struct, [{Name, make_status(not_found)}]}.
|
|
|
|
|
|
|
|
make_status(ok) -> 0;
|
|
|
|
make_status(true) -> 0;
|
|
|
|
make_status(false) -> 1;
|
|
|
|
make_status(error) -> 1;
|
|
|
|
make_status(_) -> 1.
|
|
|
|
|
2018-09-18 11:53:36 +02:00
|
|
|
listen_options() ->
|
2020-05-06 13:21:30 +02:00
|
|
|
?WARNING_MSG("It is deprecated defining ejabberd_xmlrpc as a listen module "
|
|
|
|
"in the ejabberd configuration. Support for that configuration"
|
|
|
|
" method may be removed in a future ejabberd release. You are "
|
|
|
|
"encouraged to define ejabberd_xmlrpc inside request_handlers "
|
|
|
|
"option of ejabberd_http listen module. See the ejabberd "
|
2024-03-14 12:38:03 +01:00
|
|
|
"documentation for details: _`/admin/configuration/listen/#ejabberd-xmlrpc|ejabberd_xmlrpc listener`_.", []),
|
2019-06-24 16:20:29 +02:00
|
|
|
[].
|