./ct_report/coverage/mod_muc_backend.COVER.html

1 -module(mod_muc_backend).
2 -export([init/2,
3 store_room/4,
4 restore_room/3,
5 forget_room/3,
6 get_rooms/2,
7 can_use_nick/4,
8 get_nick/3,
9 set_nick/4,
10 unset_nick/3,
11 remove_domain/3
12 ]).
13
14 -ignore_xref([remove_domain/3]).
15
16 -define(MAIN_MODULE, mod_muc).
17
18 -include("mod_muc.hrl").
19
20 %% Host of MUC service
21 -type muc_host() :: jid:server().
22
23 %% User's JID. Can be on another domain accessible over FED.
24 %% Only bare part (user@host) is important.
25 -type client_jid() :: jid:jid().
26
27 -type room_opts() :: [{OptionName :: atom(), OptionValue :: term()}].
28
29
30 %% Called when MUC service starts or restarts for each domain
31 -callback init(mongooseim:host_type(), ModuleOpts :: gen_mod:module_opts()) -> ok.
32
33 -callback store_room(mongooseim:host_type(), muc_host(), mod_muc:room(), room_opts()) ->
34 ok | {error, term()}.
35
36 -callback restore_room(mongooseim:host_type(), muc_host(), mod_muc:room()) ->
37 {ok, room_opts()} | {error, room_not_found} | {error, term()}.
38
39 -callback forget_room(mongooseim:host_type(), muc_host(), mod_muc:room()) ->
40 ok | {error, term()}.
41
42 -callback get_rooms(mongooseim:host_type(), muc_host()) ->
43 {ok, [#muc_room{}]} | {error, term()}.
44
45 -callback can_use_nick(mongooseim:host_type(), muc_host(),
46 client_jid(), mod_muc:nick()) -> boolean().
47
48 %% Get nick associated with jid client_jid() across muc_host() domain
49 -callback get_nick(mongooseim:host_type(), muc_host(), client_jid()) ->
50 {ok, mod_muc:nick()} | {error, not_registered} | {error, term()}.
51
52 %% Register nick
53 -callback set_nick(mongooseim:host_type(), muc_host(), client_jid(), mod_muc:nick()) ->
54 ok | {error, conflict} | {error, term()}.
55
56 %% Unregister nick
57 %% Unregistered nicks can be used by someone else
58 -callback unset_nick(mongooseim:host_type(), muc_host(), client_jid()) ->
59 ok | {error, term()}.
60
61 -callback remove_domain(mongooseim:host_type(), muc_host(), jid:lserver()) -> ok.
62
63 -optional_callbacks([remove_domain/3]).
64
65 %% Called when MUC service starts or restarts for each domain
66 -spec init(mongooseim:host_type(), Opts :: gen_mod:module_opts()) -> ok.
67 init(HostType, Opts) ->
68 29 TrackedFuns = [store_room, restore_room, forget_room, get_rooms,
69 can_use_nick, get_nick, set_nick, unset_nick],
70 29 mongoose_backend:init(HostType, ?MAIN_MODULE, TrackedFuns, Opts),
71 29 Args = [HostType, Opts],
72 29 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
73
74 -spec store_room(mongooseim:host_type(), muc_host(), mod_muc:room(), room_opts()) ->
75 ok | {error, term()}.
76 store_room(HostType, MucHost, Room, RoomOpts) ->
77 311 Args = [HostType, MucHost, Room, RoomOpts],
78 311 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
79
80 -spec restore_room(mongooseim:host_type(), muc_host(), mod_muc:room()) ->
81 {ok, room_opts()} | {error, room_not_found} | {error, term()}.
82 restore_room(HostType, MucHost, Room) ->
83 77 Args = [HostType, MucHost, Room],
84 77 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
85
86 -spec forget_room(mongooseim:host_type(), muc_host(), mod_muc:room()) ->
87 ok | {error, term()}.
88 forget_room(HostType, MucHost, Room) ->
89 256 Args = [HostType, MucHost, Room],
90 256 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
91
92 -spec get_rooms(mongooseim:host_type(), muc_host()) ->
93 {ok, [#muc_room{}]} | {error, term()}.
94 get_rooms(HostType, MucHost) ->
95 62 Args = [HostType, MucHost],
96 62 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
97
98 -spec can_use_nick(mongooseim:host_type(), muc_host(), client_jid(), mod_muc:nick()) ->
99 boolean().
100 can_use_nick(HostType, MucHost, ClientJID, Nick) ->
101 703 Args = [HostType, MucHost, ClientJID, Nick],
102 703 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
103
104 %% Get nick associated with jid client_jid() across muc_host() domain
105 -spec get_nick(mongooseim:host_type(), muc_host(), client_jid()) ->
106 {ok, mod_muc:nick()} | {error, not_registered} | {error, term()}.
107 get_nick(HostType, MucHost, ClientJID) ->
108 11 Args = [HostType, MucHost, ClientJID],
109 11 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
110
111 %% Register nick
112 -spec set_nick(mongooseim:host_type(), muc_host(), client_jid(), mod_muc:nick()) ->
113 ok | {error, conflict} | {error, term()}.
114 set_nick(HostType, MucHost, ClientJID, Nick) ->
115 8 Args = [HostType, MucHost, ClientJID, Nick],
116 8 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
117
118 %% Unregister nick
119 %% Unregistered nicks can be used by someone else
120 -spec unset_nick(mongooseim:host_type(), muc_host(), client_jid()) ->
121 ok | {error, term()}.
122 unset_nick(HostType, MucHost, ClientJID) ->
123 3 Args = [HostType, MucHost, ClientJID],
124 3 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
125
126 -spec remove_domain(mongooseim:host_type(), muc_host(), jid:lserver()) -> ok.
127 remove_domain(HostType, MUCHost, Domain) ->
128 1 case mongoose_backend:is_exported(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY) of
129 true ->
130 1 Args = [HostType, MUCHost, Domain],
131 1 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args);
132 false ->
133
:-(
ok
134 end.
Line Hits Source