mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
parent
9a142eb807
commit
b932afb0cd
@ -279,7 +279,11 @@ update_table() ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
host_up(Host) ->
|
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,
|
ejabberd_hooks:add(local_send_to_resource_hook, Host,
|
||||||
?MODULE, bounce_resource_packet, 100).
|
?MODULE, bounce_resource_packet, 100).
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
route_error/2,
|
route_error/2,
|
||||||
register_route/2,
|
register_route/2,
|
||||||
register_route/3,
|
register_route/3,
|
||||||
|
register_route/4,
|
||||||
register_routes/1,
|
register_routes/1,
|
||||||
host_of_route/1,
|
host_of_route/1,
|
||||||
process_iq/1,
|
process_iq/1,
|
||||||
@ -65,7 +66,7 @@
|
|||||||
|
|
||||||
-callback init() -> any().
|
-callback init() -> any().
|
||||||
-callback register_route(binary(), binary(), local_hint(),
|
-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 unregister_route(binary(), undefined | pos_integer()) -> ok | {error, term()}.
|
||||||
-callback find_routes(binary()) -> [#route{}].
|
-callback find_routes(binary()) -> [#route{}].
|
||||||
-callback host_of_route(binary()) -> {ok, binary()} | error.
|
-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.
|
-spec register_route(binary(), binary(), local_hint() | undefined) -> ok.
|
||||||
register_route(Domain, ServerHost, LocalHint) ->
|
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
|
case {jid:nameprep(Domain), jid:nameprep(ServerHost)} of
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
erlang:error({invalid_domain, Domain});
|
erlang:error({invalid_domain, Domain});
|
||||||
@ -149,7 +154,7 @@ register_route(Domain, ServerHost, LocalHint) ->
|
|||||||
{LDomain, LServerHost} ->
|
{LDomain, LServerHost} ->
|
||||||
Mod = get_backend(),
|
Mod = get_backend(),
|
||||||
case Mod:register_route(LDomain, LServerHost, LocalHint,
|
case Mod:register_route(LDomain, LServerHost, LocalHint,
|
||||||
get_component_number(LDomain)) of
|
get_component_number(LDomain), Pid) of
|
||||||
ok ->
|
ok ->
|
||||||
?DEBUG("Route registered: ~s", [LDomain]);
|
?DEBUG("Route registered: ~s", [LDomain]);
|
||||||
{error, Err} ->
|
{error, Err} ->
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
|
||||||
%% API
|
%% 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]).
|
host_of_route/1, is_my_route/1, is_my_host/1, get_all_routes/0]).
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_cast/2, handle_call/3, handle_info/2,
|
-export([init/1, handle_cast/2, handle_call/3, handle_info/2,
|
||||||
@ -53,16 +53,15 @@ init() ->
|
|||||||
start_link() ->
|
start_link() ->
|
||||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||||
|
|
||||||
register_route(Domain, ServerHost, LocalHint, undefined) ->
|
register_route(Domain, ServerHost, LocalHint, undefined, Pid) ->
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
mnesia:write(#route{domain = Domain,
|
mnesia:write(#route{domain = Domain,
|
||||||
pid = self(),
|
pid = Pid,
|
||||||
server_host = ServerHost,
|
server_host = ServerHost,
|
||||||
local_hint = LocalHint})
|
local_hint = LocalHint})
|
||||||
end,
|
end,
|
||||||
transaction(F);
|
transaction(F);
|
||||||
register_route(Domain, ServerHost, _LocalHint, N) ->
|
register_route(Domain, ServerHost, _LocalHint, N, Pid) ->
|
||||||
Pid = self(),
|
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
case mnesia:wread({route, Domain}) of
|
case mnesia:wread({route, Domain}) of
|
||||||
[] ->
|
[] ->
|
||||||
|
Loading…
Reference in New Issue
Block a user