./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, deps/2, disco_local_items/1]).
27
28 -ignore_xref([disco_local_items/1]).
29
30 %%--------------------------------------------------------------------
31 %% API
32 %%--------------------------------------------------------------------
33
34 -spec start(mongooseim:host_type(), gen_mod:module_opts()) -> any().
35 start(HostType, _Opts) ->
36
:-(
ejabberd_hooks:add(hooks(HostType)).
37
38 -spec stop(mongooseim:host_type()) -> any().
39 stop(HostType) ->
40
:-(
ejabberd_hooks:delete(hooks(HostType)).
41
42 -spec deps(mongooseim:host_type(), gen_mod:module_opts()) -> gen_mod_deps:deps().
43 deps(_HostType, Opts) ->
44
:-(
[{mod_global_distrib_utils, Opts, hard}].
45
46 %%--------------------------------------------------------------------
47 %% Hooks implementation
48 %%--------------------------------------------------------------------
49
50 -spec disco_local_items(mongoose_disco:item_acc()) -> mongoose_disco:item_acc().
51 disco_local_items(Acc = #{host_type := HostType, from_jid := From, node := <<>>}) ->
52
:-(
Domains = domains_for_disco(HostType, From),
53
:-(
?LOG_DEBUG(#{what => gd_domains_fetched_for_disco, domains => Domains}),
54
:-(
Items = [#{jid => Domain} || Domain <- Domains],
55
:-(
mongoose_disco:add_items(Items, Acc);
56 disco_local_items(Acc) ->
57
:-(
Acc.
58
59 %%--------------------------------------------------------------------
60 %% Helpers
61 %%--------------------------------------------------------------------
62
63 hooks(HostType) ->
64
:-(
[{disco_local_items, HostType, ?MODULE, disco_local_items, 99}].
65
66 -spec domains_for_disco(mongooseim:host_type(), From :: jid:jid()) -> Domains :: [binary()].
67 domains_for_disco(_HostType, #jid{ luser = <<>> } = _From) ->
68 %% Currently all non-user entities may discover all services
69
:-(
mod_global_distrib_mapping:all_domains();
70 domains_for_disco(HostType, _From) ->
71 %% mod_disco is running because it is the only caller of 'disco_local_items'
72
:-(
case gen_mod:get_module_opt(HostType, mod_disco, users_can_see_hidden_services) of
73 true ->
74
:-(
mod_global_distrib_mapping:all_domains();
75 false ->
76
:-(
mod_global_distrib_mapping:public_domains()
77 end.
Line Hits Source