Update mod_rest to 16.12, but can send only messages, not iq or presence (#196)

This commit is contained in:
Badlop 2017-02-23 18:21:17 +01:00
parent 3dc4494ee1
commit fc901d9dea
1 changed files with 14 additions and 15 deletions

View File

@ -35,9 +35,9 @@
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("logger.hrl"). -include("logger.hrl").
-include("jlib.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
-include("ejabberd_ctl.hrl"). -include("ejabberd_ctl.hrl").
-include("xmpp.hrl").
start(_Host, _Opts) -> start(_Host, _Opts) ->
?DEBUG("Starting: ~p ~p", [_Host, _Opts]), ?DEBUG("Starting: ~p ~p", [_Host, _Opts]),
@ -69,15 +69,12 @@ process(Path, Request) ->
maybe_post_request(<<$<,_/binary>> = Data, Host, ClientIp) -> maybe_post_request(<<$<,_/binary>> = Data, Host, ClientIp) ->
try try
Stanza = {xmlel, _, _, _} = fxml_stream:parse_element(Data), Stanza = {xmlel, _, _, _} = fxml_stream:parse_element(Data),
From = jlib:string_to_jid(fxml:get_tag_attr_s(<<"from">>, Stanza)), Pkt = xmpp:decode(Stanza),
To = jlib:string_to_jid(fxml:get_tag_attr_s(<<"to">>, Stanza)), allowed = check_stanza(Pkt, Host),
allowed = check_stanza(Stanza, From, To, Host), ?INFO_MSG("Got valid request with IP ~p:~n~p",
?INFO_MSG("Got valid request from ~s~nwith IP ~p~nto ~s:~n~p", [ClientIp,
[jlib:jid_to_string(From), Pkt]),
ClientIp, post_request(Pkt)
jlib:jid_to_string(To),
Stanza]),
post_request(Stanza, From, To)
catch catch
error:{badmatch, _} = Error -> error:{badmatch, _} = Error ->
?DEBUG("Error when processing REST request: ~nData: ~p~nError: ~p", [Data, Error]), ?DEBUG("Error when processing REST request: ~nData: ~p~nError: ~p", [Data, Error]),
@ -122,10 +119,11 @@ get_option_access(Host) ->
try_get_option(Host, access_commands, []). try_get_option(Host, access_commands, []).
%% This function crashes if the stanza does not satisfy configured restrictions %% This function crashes if the stanza does not satisfy configured restrictions
check_stanza(Stanza, _From, To, Host) -> check_stanza(Pkt, Host) ->
To = Pkt#message.to,
check_member_option(Host, jlib:jid_to_string(To), allowed_destinations), check_member_option(Host, jlib:jid_to_string(To), allowed_destinations),
{xmlel, StanzaType, _Attrs, _Kids} = Stanza, %%+++ {xmlel, StanzaType, _Attrs, _Kids} = Stanza,
check_member_option(Host, StanzaType, allowed_stanza_types), %%+++ check_member_option(Host, StanzaType, allowed_stanza_types),
allowed. allowed.
check_member_option(Host, ClientIp, allowed_ips) -> check_member_option(Host, ClientIp, allowed_ips) ->
@ -146,8 +144,9 @@ ip_matches(ClientIp, AllowedValues) ->
end, end,
AllowedValues). AllowedValues).
post_request(Stanza, From, To) -> post_request(Pkt) ->
case ejabberd_router:route(From, To, Stanza) of mod_mam:user_send_packet(Pkt, #{jid => Pkt#message.from}, Pkt#message.from, Pkt#message.to),
case ejabberd_router:route(Pkt#message.from, Pkt#message.to, Pkt) of
ok -> {200, [], <<"Ok">>}; ok -> {200, [], <<"Ok">>};
_ -> {500, [], <<"Error">>} _ -> {500, [], <<"Error">>}
end. end.