./ct_report/coverage/mongoose_router.COVER.html

1 -module(mongoose_router).
2
3 -define(TABLE, ?MODULE).
4
5 -export([start/0, routing_modules_list/0, default_routing_modules/0]).
6
7 -export([get_all_domains/0, lookup_route/1, is_registered_route/1,
8 register_route/2, unregister_route/1]).
9
10 -spec get_all_domains() -> [jid:lserver()].
11 get_all_domains() ->
12 43 ets:select(?TABLE, [{{'$1', '_'}, [], ['$1']}]).
13
14 -spec lookup_route(jid:lserver()) -> no_route | mongoose_packet_handler:t().
15 lookup_route(LDomain) ->
16 50115 case ets:lookup(?TABLE, LDomain) of
17 359 [] -> no_route;
18 [{_, Handler}] ->
19 49756 Handler
20 end.
21
22 -spec register_route(jid:server(), mongoose_packet_handler:t()) -> any().
23 register_route(Domain, Handler) ->
24 198 case jid:nameprep(Domain) of
25 error ->
26
:-(
{error, invalid_domain, Domain};
27 LDomain ->
28 198 ets:insert(?TABLE, {LDomain, Handler})
29 end.
30
31 -spec unregister_route(jid:server()) -> any().
32 unregister_route(Domain) ->
33 173 case jid:nameprep(Domain) of
34 error ->
35
:-(
{error, invalid_domain, Domain};
36 LDomain ->
37 173 ets:delete(?TABLE, LDomain)
38 end.
39
40 -spec is_registered_route(jid:lserver()) -> boolean().
41 is_registered_route(LDomain) ->
42 27 ets:member(?TABLE, LDomain).
43
44 %% start/stop
45 start() ->
46 104 ets:new(?TABLE, [named_table, public, set, {read_concurrency, true}]),
47 104 mongoose_metrics:ensure_metric(global, routingErrors, spiral).
48
49 default_routing_modules() ->
50 104 List = [mongoose_router_global,
51 mongoose_router_localdomain,
52 mongoose_router_external_localnode,
53 mongoose_router_external,
54 mongoose_router_dynamic_domains,
55 ejabberd_s2s],
56 104 xmpp_router:expand_routing_modules(List).
57
58 routing_modules_list() ->
59 50288 mongoose_config:get_opt(routing_modules).
Line Hits Source