./ct_report/coverage/mod_offline_stub.COVER.html

1 %%%----------------------------------------------------------------------
2 %%% File : mod_offline_stub.erl
3 %%% Author : Radek Szymczyszyn
4 %%% <radoslaw.szymczyszyn@erlang-solutions.com>
5 %%% Purpose : Silence <service-unavailable/> when not using mod_offline
6 %%% but using mod_mam for message persistence.
7 %%%
8 %%% RFC 6121 requires a <service-unavailable/> stanza error
9 %%% to be sent to a user messaging an unavailable recipient
10 %%% if the message is not stored for delayed delivery
11 %%% (i.e. as an "offline message").
12 %%% If the recipient exists (i.e. auth module returns `true`
13 %%% from `does_user_exist`) mod_mam stores the message,
14 %%% but <service-unavailable/> is still returned,
15 %%% what is not compliant with the RFC.
16 %%%
17 %%% This module prevents returning <service-unavailable/>.
18 %%% See : RFC 6121 8.5.2.2.1
19 %%% License : GNU GPLv2 or (at your option) any later version
20 %%%
21 %%% MongooseIM, Copyright (C) 2014 Erlang Solutions
22 %%%----------------------------------------------------------------------
23
24 -module(mod_offline_stub).
25 -author('mongoose-im@erlang-solutions.com').
26 -behaviour(gen_mod).
27 -behaviour(mongoose_module_metrics).
28
29 %% gen_mod callbacks
30 -export([start/2,
31 stop/1,
32 supported_features/0]).
33
34 %% Hook handlers
35 -export([stop_hook_processing/4]).
36
37 -ignore_xref([stop_hook_processing/4]).
38
39 -spec start(any(), any()) -> 'ok'.
40 start(HostType, _Opts) ->
41 3 [ejabberd_hooks:add(Hook, HostType, M, F, Prio)
42 3 || {Hook, M, F, Prio} <- handlers()],
43 3 ok.
44
45 -spec stop(any()) -> 'ok'.
46 stop(HostType) ->
47 3 [ejabberd_hooks:delete(Hook, HostType, M, F, Prio)
48 3 || {Hook, M, F, Prio} <- handlers()],
49 3 ok.
50
51 3 supported_features() -> [dynamic_domains].
52
53 %% Don't repeat yourself.
54 handlers() ->
55 6 [{offline_message_hook, ?MODULE, stop_hook_processing, 75}].
56
57 -spec stop_hook_processing(map(), any(), any(), any()) -> {stop, map()}.
58 stop_hook_processing(Acc, _From, _To, _Packet) ->
59 25 {stop, Acc}.
Line Hits Source