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).
route_error/2,
register_route/2,
register_route/3,
+ register_route/4,
register_routes/1,
host_of_route/1,
process_iq/1,
-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.
-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});
{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} ->
-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,
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
[] ->