./ct_report/coverage/mod_global_distrib_disco.COVER.html

1 %%==============================================================================
2 %% Copyright 2017 Erlang Solutions Ltd.
3 %%
4 %% Licensed under the Apache License, Version 2.0 (the "License");
5 %% you may not use this file except in compliance with the License.
6 %% You may obtain a copy of the License at
7 %%
8 %% http://www.apache.org/licenses/LICENSE-2.0
9 %%
10 %% Unless required by applicable law or agreed to in writing, software
11 %% distributed under the License is distributed on an "AS IS" BASIS,
12 %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 %% See the License for the specific language governing permissions and
14 %% limitations under the License.
15 %%==============================================================================
16
17 -module(mod_global_distrib_disco).
18 -author('konrad.zemek@erlang-solutions.com').
19
20 -behaviour(gen_mod).
21 -behaviour(mongoose_module_metrics).
22
23 -include("mongoose.hrl").
24 -include("jlib.hrl").
25
26 -export([start/2, stop/1, hooks/1, deps/2, disco_local_items/3]).
27
28 %%--------------------------------------------------------------------
29 %% API
30 %%--------------------------------------------------------------------
31
32 -spec start(mongooseim:host_type(), gen_mod:module_opts()) -> any().
33 start(_HostType, _Opts) ->
34 21 ok.
35
36 -spec stop(mongooseim:host_type()) -> any().
37 stop(_HostType) ->
38 21 ok.
39
40 -spec deps(mongooseim:host_type(), gen_mod:module_opts()) -> gen_mod_deps:deps().
41 deps(_HostType, Opts) ->
42 106 [{mod_global_distrib_utils, Opts, hard}].
43
44 %%--------------------------------------------------------------------
45 %% Hooks implementation
46 %%--------------------------------------------------------------------
47
48 -spec disco_local_items(Acc, Params, Extra) -> {ok, Acc} when
49 Acc :: mongoose_disco:item_acc(),
50 Params :: map(),
51 Extra :: map().
52 disco_local_items(Acc = #{host_type := HostType, from_jid := From, node := <<>>}, _, _) ->
53 3 Domains = domains_for_disco(HostType, From),
54 3 ?LOG_DEBUG(#{what => gd_domains_fetched_for_disco, domains => Domains}),
55 3 Items = [#{jid => Domain} || Domain <- Domains],
56 3 NewAcc = mongoose_disco:add_items(Items, Acc),
57 3 {ok, NewAcc};
58 disco_local_items(Acc, _, _) ->
59
:-(
{ok, Acc}.
60
61 %%--------------------------------------------------------------------
62 %% Helpers
63 %%--------------------------------------------------------------------
64
65 hooks(HostType) ->
66 42 [{disco_local_items, HostType, fun ?MODULE:disco_local_items/3, #{}, 99}].
67
68 -spec domains_for_disco(mongooseim:host_type(), From :: jid:jid()) -> Domains :: [binary()].
69 domains_for_disco(_HostType, #jid{ luser = <<>> } = _From) ->
70 %% Currently all non-user entities may discover all services
71
:-(
mod_global_distrib_mapping:all_domains();
72 domains_for_disco(HostType, _From) ->
73 %% mod_disco is running because it is the only caller of 'disco_local_items'
74 3 case gen_mod:get_module_opt(HostType, mod_disco, users_can_see_hidden_services) of
75 true ->
76
:-(
mod_global_distrib_mapping:all_domains();
77 false ->
78 3 mod_global_distrib_mapping:public_domains()
79 end.
Line Hits Source