From 73e6b7ed227fd477aa8ca15cff6fdd21375b861a Mon Sep 17 00:00:00 2001 From: Sonny Scroggin Date: Tue, 18 Mar 2014 11:34:21 -0500 Subject: [PATCH] Add support for using yaml config file. When converting to use the yaml config, the option for `allowed_ips` gets stored as a binary. But needs to be compared against the client ip of the request (which is a tuple). This converts the list of binaries into a list of ip tuples. --- mod_rest/src/mod_rest.erl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mod_rest/src/mod_rest.erl b/mod_rest/src/mod_rest.erl index 24074b2..152ee0b 100644 --- a/mod_rest/src/mod_rest.erl +++ b/mod_rest/src/mod_rest.erl @@ -119,12 +119,31 @@ check_stanza(Stanza, _From, To, Host) -> check_member_option(Host, StanzaType, allowed_stanza_types), allowed. +check_member_option(Host, ClientIp, allowed_ips) -> + true = case try_get_option(Host, allowed_ips, all) of + all -> true; + AllowedValues -> + case lists:all(fun(El) -> is_binary(El) end, AllowedValues) of + true -> + AllowedIps = lists:map(fun(El) -> + binary_to_ip_tuple(El) + end, + AllowedValues), + lists:member(ClientIp, AllowedIps); + false -> + lists:member(ClientIp, AllowedValues) + end + end; check_member_option(Host, Element, Option) -> true = case try_get_option(Host, Option, all) of all -> true; AllowedValues -> lists:member(Element, AllowedValues) end. +binary_to_ip_tuple(IpAddress) when is_binary(IpAddress) -> + {ok, IpTuple} = inet_parse:address(binary_to_list(IpAddress)), + IpTuple. + post_request(Stanza, From, To) -> case ejabberd_router:route(From, To, Stanza) of ok -> {200, [], <<"Ok">>};