25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Fix ejabberd_router:is_my_route/1

This commit is contained in:
Evgeniy Khramtsov 2017-04-14 20:34:00 +03:00
parent 5f1f126613
commit d110cbb6e2
2 changed files with 19 additions and 4 deletions

View File

@ -268,7 +268,7 @@ is_my_route(Domain) ->
error ->
erlang:error({invalid_domain, Domain});
LDomain ->
lists:member(LDomain, get_all_routes())
find_routes(LDomain) /= []
end.
-spec is_my_host(binary()) -> boolean().

View File

@ -38,6 +38,7 @@
-record(state, {}).
-define(ROUTES_KEY, <<"ejabberd:routes">>).
-define(DOMAINS_KEY, <<"ejabberd:domains">>).
%%%===================================================================
%%% API
@ -61,7 +62,12 @@ register_route(Domain, ServerHost, LocalHint, _, Pid) ->
case ejabberd_redis:multi(
fun() ->
ejabberd_redis:hset(DomKey, PidKey, T),
ejabberd_redis:sadd(?ROUTES_KEY, [Domain])
ejabberd_redis:sadd(?DOMAINS_KEY, [Domain]),
if Domain /= ServerHost ->
ejabberd_redis:sadd(?ROUTES_KEY, [Domain]);
true ->
ok
end
end) of
{ok, _} ->
ok;
@ -80,7 +86,8 @@ unregister_route(Domain, _, Pid) ->
{ok, _} = ejabberd_redis:multi(
fun() ->
ejabberd_redis:del([DomKey]),
ejabberd_redis:srem(?ROUTES_KEY, [Domain])
ejabberd_redis:srem(?ROUTES_KEY, [Domain]),
ejabberd_redis:srem(?DOMAINS_KEY, [Domain])
end),
ok;
true ->
@ -110,6 +117,14 @@ get_all_routes() ->
{error, db_failure}
end.
get_all_domains() ->
case ejabberd_redis:smembers(?DOMAINS_KEY) of
{ok, Domains} ->
{ok, Domains};
_ ->
{error, db_failure}
end.
%%%===================================================================
%%% gen_server callbacks
%%%===================================================================
@ -147,7 +162,7 @@ clean_table() ->
end, find_routes()).
find_routes() ->
case get_all_routes() of
case get_all_domains() of
{ok, Domains} ->
lists:flatmap(
fun(Domain) ->