From d110cbb6e28e9aa906881293d30ba22255848985 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Fri, 14 Apr 2017 20:34:00 +0300 Subject: [PATCH] Fix ejabberd_router:is_my_route/1 --- src/ejabberd_router.erl | 2 +- src/ejabberd_router_redis.erl | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/ejabberd_router.erl b/src/ejabberd_router.erl index 30654a03b..5951cbeca 100644 --- a/src/ejabberd_router.erl +++ b/src/ejabberd_router.erl @@ -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(). diff --git a/src/ejabberd_router_redis.erl b/src/ejabberd_router_redis.erl index 2b02a7595..03581a863 100644 --- a/src/ejabberd_router_redis.erl +++ b/src/ejabberd_router_redis.erl @@ -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) -> -- 2.40.0