diff --git a/src/ejabberd_local.erl b/src/ejabberd_local.erl index 7a9034563..196e50324 100644 --- a/src/ejabberd_local.erl +++ b/src/ejabberd_local.erl @@ -279,7 +279,11 @@ update_table() -> end. host_up(Host) -> - ejabberd_router:register_route(Host, Host, {apply, ?MODULE, route}), + Owner = case whereis(?MODULE) of + undefined -> self(); + Pid -> Pid + end, + ejabberd_router:register_route(Host, Host, {apply, ?MODULE, route}, Owner), ejabberd_hooks:add(local_send_to_resource_hook, Host, ?MODULE, bounce_resource_packet, 100). diff --git a/src/ejabberd_router.erl b/src/ejabberd_router.erl index e54abbefa..596dd52c8 100644 --- a/src/ejabberd_router.erl +++ b/src/ejabberd_router.erl @@ -39,6 +39,7 @@ route_error/2, register_route/2, register_route/3, + register_route/4, register_routes/1, host_of_route/1, process_iq/1, @@ -65,7 +66,7 @@ -callback init() -> any(). -callback register_route(binary(), binary(), local_hint(), - undefined | pos_integer()) -> ok | {error, term()}. + undefined | pos_integer(), pid()) -> ok | {error, term()}. -callback unregister_route(binary(), undefined | pos_integer()) -> ok | {error, term()}. -callback find_routes(binary()) -> [#route{}]. -callback host_of_route(binary()) -> {ok, binary()} | error. @@ -141,6 +142,10 @@ register_route(Domain, ServerHost) -> -spec register_route(binary(), binary(), local_hint() | undefined) -> ok. register_route(Domain, ServerHost, LocalHint) -> + register_route(Domain, ServerHost, LocalHint, self()). + +-spec register_route(binary(), binary(), local_hint() | undefined, pid()) -> ok. +register_route(Domain, ServerHost, LocalHint, Pid) -> case {jid:nameprep(Domain), jid:nameprep(ServerHost)} of {error, _} -> erlang:error({invalid_domain, Domain}); @@ -149,7 +154,7 @@ register_route(Domain, ServerHost, LocalHint) -> {LDomain, LServerHost} -> Mod = get_backend(), case Mod:register_route(LDomain, LServerHost, LocalHint, - get_component_number(LDomain)) of + get_component_number(LDomain), Pid) of ok -> ?DEBUG("Route registered: ~s", [LDomain]); {error, Err} -> diff --git a/src/ejabberd_router_mnesia.erl b/src/ejabberd_router_mnesia.erl index 3ea8a3af1..3600c08dc 100644 --- a/src/ejabberd_router_mnesia.erl +++ b/src/ejabberd_router_mnesia.erl @@ -24,7 +24,7 @@ -behaviour(gen_server). %% API --export([init/0, register_route/4, unregister_route/2, find_routes/1, +-export([init/0, register_route/5, unregister_route/2, find_routes/1, host_of_route/1, is_my_route/1, is_my_host/1, get_all_routes/0]). %% gen_server callbacks -export([init/1, handle_cast/2, handle_call/3, handle_info/2, @@ -53,16 +53,15 @@ init() -> start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). -register_route(Domain, ServerHost, LocalHint, undefined) -> +register_route(Domain, ServerHost, LocalHint, undefined, Pid) -> F = fun () -> mnesia:write(#route{domain = Domain, - pid = self(), + pid = Pid, server_host = ServerHost, local_hint = LocalHint}) end, transaction(F); -register_route(Domain, ServerHost, _LocalHint, N) -> - Pid = self(), +register_route(Domain, ServerHost, _LocalHint, N, Pid) -> F = fun () -> case mnesia:wread({route, Domain}) of [] ->