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.
This commit is contained in:
Sonny Scroggin 2014-03-18 11:34:21 -05:00
parent 9a30d2d022
commit 73e6b7ed22
1 changed files with 19 additions and 0 deletions

View File

@ -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">>};