./ct_report/coverage/mod_muc_light_db_backend.COVER.html

1 %%%----------------------------------------------------------------------
2 %%% File : mod_muc_light_db.erl
3 %%% Author : Piotr Nosek <piotr.nosek@erlang-solutions.com>
4 %%% Purpose : MUC light DB behaviour
5 %%% Created : 6 Oct 2015 by Piotr Nosek <piotr.nosek@erlang-solutions.com>
6 %%%----------------------------------------------------------------------
7
8 -module(mod_muc_light_db_backend).
9 -author('piotr.nosek@erlang-solutions.com').
10
11 -define(MAIN_MODULE, mod_muc_light_db).
12
13 -include("mod_muc_light.hrl").
14
15 -type modify_aff_users_return() :: {ok, OldAffUsers :: aff_users(),
16 NewAffUsers :: aff_users(),
17 AffUsersChanged :: aff_users(),
18 PrevVersion :: binary()}
19 | {error, any()}.
20
21 -type remove_user_return() :: [{RoomUS :: jid:simple_bare_jid(),
22 modify_aff_users_return()}].
23
24 -export_type([modify_aff_users_return/0,
25 remove_user_return/0]).
26
27 %% API
28 -export([start/2]).
29 -export([stop/1]).
30 -export([create_room/5]).
31 -export([destroy_room/2]).
32 -export([room_exists/2]).
33 -export([get_user_rooms/3]).
34 -export([get_user_rooms_count/2]).
35 -export([remove_user/3]).
36 -export([remove_domain/3]).
37 -export([get_config/2]).
38 -export([set_config/4]).
39 -export([get_blocking/3]).
40 -export([get_blocking/4]).
41 -export([set_blocking/4]).
42 -export([get_aff_users/2]).
43 -export([modify_aff_users/5]).
44 -export([get_info/2]).
45
46 %% For tests
47 -export([force_clear/1]).
48
49 %%====================================================================
50 %% Behaviour callbacks
51 %%====================================================================
52
53 %% ------------------------ Backend start/stop ------------------------
54 -callback start(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
55
56 -callback stop(mongooseim:host_type()) -> ok.
57
58 %% ------------------------ General room management ------------------------
59 -callback create_room(HostType :: mongooseim:host_type(),
60 RoomUS :: jid:simple_bare_jid(),
61 Config :: mod_muc_light_room_config:kv(),
62 AffUsers :: aff_users(),
63 Version :: binary()) ->
64 {ok, FinalRoomUS :: jid:simple_bare_jid()} | {error, exists}.
65
66 -callback destroy_room(HostType :: mongooseim:host_type(),
67 RoomUS :: jid:simple_bare_jid()) ->
68 ok | {error, not_exists}.
69
70 -callback room_exists(HostType :: mongooseim:host_type(),
71 RoomUS :: jid:simple_bare_jid()) ->
72 boolean().
73
74 -callback get_user_rooms(HostType :: mongooseim:host_type(),
75 UserUS :: jid:simple_bare_jid(),
76 MUCServer :: jid:lserver() | undefined) ->
77 [RoomUS :: jid:simple_bare_jid()].
78
79 -callback get_user_rooms_count(HostType :: mongooseim:host_type(),
80 UserUS :: jid:simple_bare_jid()) ->
81 non_neg_integer().
82
83 -callback remove_user(HostType :: mongooseim:host_type(),
84 UserUS :: jid:simple_bare_jid(),
85 Version :: binary()) ->
86 remove_user_return() | {error, term()}.
87
88 -callback remove_domain(mongooseim:host_type(), jid:lserver(), jid:lserver()) ->
89 ok.
90
91 %% ------------------------ Configuration manipulation ------------------------
92 -callback get_config(HostType :: mongooseim:host_type(),
93 RoomUS :: jid:simple_bare_jid()) ->
94 {ok, mod_muc_light_room_config:kv(), Version :: binary()} | {error, not_exists}.
95
96 -callback set_config(HostType :: mongooseim:host_type(),
97 RoomUS :: jid:simple_bare_jid(),
98 Config :: mod_muc_light_room_config:kv(),
99 Version :: binary()) ->
100 {ok, PrevVersion :: binary()} | {error, not_exists}.
101
102 %% ------------------------ Blocking manipulation ------------------------
103 -callback get_blocking(HostType :: mongooseim:host_type(),
104 UserUS :: jid:simple_bare_jid(),
105 MUCServer :: jid:lserver()) ->
106 [blocking_item()].
107
108 -callback get_blocking(HostType :: mongooseim:host_type(),
109 UserUS :: jid:simple_bare_jid(),
110 MUCServer :: jid:lserver(),
111 WhatWhos :: [{blocking_what(), blocking_who()}]) ->
112 blocking_action().
113
114 -callback set_blocking(HostType :: mongooseim:host_type(),
115 UserUS :: jid:simple_bare_jid(),
116 MUCServer :: jid:lserver(),
117 BlockingItems :: [blocking_item()]) ->
118 ok.
119
120 %% ------------------------ Affiliations manipulation ------------------------
121 -callback get_aff_users(HostType :: mongooseim:host_type(),
122 RoomUS :: jid:simple_bare_jid()) ->
123 {ok, aff_users(), Version :: binary()} | {error, not_exists}.
124
125 -callback modify_aff_users(HostType :: mongooseim:host_type(),
126 RoomUS :: jid:simple_bare_jid(),
127 AffUsersChanges :: aff_users(),
128 ExternalCheck :: external_check_fun(),
129 Version :: binary()) ->
130 modify_aff_users_return().
131
132 %% ------------------------ Getting room configuration ------------------------
133 -callback get_info(HostType :: mongooseim:host_type(),
134 RoomUS :: jid:simple_bare_jid()) ->
135 {ok, mod_muc_light_room_config:kv(), aff_users(), Version :: binary()}
136 | {error, not_exists}.
137
138 %% ------------------------ API for tests ------------------------
139 -callback force_clear() -> ok.
140
141 %%====================================================================
142 %% API
143 %%====================================================================
144
145 -spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
146 start(HostType, Opts) ->
147 87 TrackedFuns = [create_room, destroy_room,
148 room_exists, get_user_rooms,
149 remove_user, remove_domain,
150 get_config, set_config,
151 get_blocking, set_blocking,
152 get_aff_users, modify_aff_users],
153 87 mongoose_backend:init(HostType, ?MAIN_MODULE, TrackedFuns, Opts),
154 87 Args = [HostType, Opts],
155 87 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
156
157 -spec stop(mongooseim:host_type()) -> ok.
158 stop(HostType) ->
159 87 Args = [HostType],
160 87 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
161
162 -spec create_room(HostType :: mongooseim:host_type(),
163 RoomUS :: jid:simple_bare_jid(),
164 Config :: mod_muc_light_room_config:kv(),
165 AffUsers :: aff_users(),
166 Version :: binary()) ->
167 {ok, FinalRoomUS :: jid:simple_bare_jid()} | {error, exists}.
168 create_room(HostType, RoomUS, Config, AffUsers, Version) ->
169 429 Args = [HostType, RoomUS, Config, AffUsers, Version],
170 429 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
171
172 -spec destroy_room(HostType :: mongooseim:host_type(),
173 RoomUS :: jid:simple_bare_jid()) ->
174 ok | {error, not_exists}.
175 destroy_room(HostType, RoomUS) ->
176 190 Args = [HostType, RoomUS],
177 190 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
178
179 -spec room_exists(HostType :: mongooseim:host_type(),
180 RoomUS :: jid:simple_bare_jid()) -> boolean().
181 room_exists(HostType, RoomUS) ->
182 631 Args = [HostType, RoomUS],
183 631 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
184
185 -spec get_user_rooms(HostType :: mongooseim:host_type(),
186 UserUS :: jid:simple_bare_jid(),
187 MUCServer :: jid:lserver() | undefined) ->
188 [RoomUS :: jid:simple_bare_jid()].
189 get_user_rooms(HostType, UserUS, MUCServer) ->
190 44 Args = [HostType, UserUS, MUCServer],
191 44 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
192
193 -spec get_user_rooms_count(HostType :: mongooseim:host_type(),
194 UserUS :: jid:simple_bare_jid()) ->
195 non_neg_integer().
196 get_user_rooms_count(HostType, UserUS) ->
197 3 Args = [HostType, UserUS],
198 3 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
199
200 -spec remove_user(HostType :: mongooseim:host_type(),
201 UserUS :: jid:simple_bare_jid(),
202 Version :: binary()) ->
203 remove_user_return() | {error, term()}.
204 remove_user(HostType, UserUS, Version) ->
205 971 Args = [HostType, UserUS, Version],
206 971 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
207
208 -spec remove_domain(mongooseim:host_type(), jid:lserver(), jid:lserver()) ->
209 ok.
210 remove_domain(HostType, RoomS, LServer) ->
211 5 Args = [HostType, RoomS, LServer],
212 5 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
213
214 -spec get_config(HostType :: mongooseim:host_type(),
215 RoomUS :: jid:simple_bare_jid()) ->
216 {ok, mod_muc_light_room_config:kv(), Version :: binary()} | {error, not_exists}.
217 get_config(HostType, RoomUS) ->
218 48 Args = [HostType, RoomUS],
219 48 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
220
221 -spec set_config(HostType :: mongooseim:host_type(),
222 RoomUS :: jid:simple_bare_jid(),
223 Config :: mod_muc_light_room_config:kv(),
224 Version :: binary()) -> {ok, PrevVersion :: binary()} | {error, not_exists}.
225 set_config(HostType, RoomUS, ConfigChanges, Version) ->
226 29 Args = [HostType, RoomUS, ConfigChanges, Version],
227 29 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
228
229 -spec get_blocking(HostType :: mongooseim:host_type(),
230 UserUS :: jid:simple_bare_jid(), MUCServer :: jid:lserver()) ->
231 [blocking_item()].
232 get_blocking(HostType, RoomUS, MUCServer) ->
233 24 Args = [HostType, RoomUS, MUCServer],
234 24 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
235
236 -spec get_blocking(HostType :: mongooseim:host_type(),
237 UserUS :: jid:simple_bare_jid(),
238 MUCServer :: jid:lserver(),
239 WhatWhos :: [{blocking_what(), blocking_who()}]) ->
240 blocking_action().
241 get_blocking(HostType, RoomUS, MUCServer, WhatWhos) ->
242 286 Args = [HostType, RoomUS, MUCServer, WhatWhos],
243 286 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
244
245 -spec set_blocking(HostType :: mongooseim:host_type(),
246 UserUS :: jid:simple_bare_jid(),
247 MUCServer :: jid:lserver(),
248 BlockingItems :: [blocking_item()]) -> ok.
249 set_blocking(HostType, UserUS, MUCServer, BlockingItems) ->
250 21 Args = [HostType, UserUS, MUCServer, BlockingItems],
251 21 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
252
253 -spec get_aff_users(HostType :: mongooseim:host_type(),
254 RoomUS :: jid:simple_bare_jid()) ->
255 {ok, aff_users(), Version :: binary()} | {error, not_exists}.
256 get_aff_users(HostType, RoomUS) ->
257 832 Args = [HostType, RoomUS],
258 832 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
259
260 -spec modify_aff_users(HostType :: mongooseim:host_type(),
261 RoomUS :: jid:simple_bare_jid(),
262 AffUsersChanges :: aff_users(),
263 ExternalCheck :: external_check_fun(),
264 Version :: binary()) ->
265 modify_aff_users_return().
266 modify_aff_users(HostType, RoomUS, AffUsersChanges, ExternalCheck, Version) ->
267 154 Args = [HostType, RoomUS, AffUsersChanges, ExternalCheck, Version],
268 154 mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
269
270 -spec get_info(HostType :: mongooseim:host_type(),
271 RoomUS :: jid:simple_bare_jid()) ->
272 {ok, mod_muc_light_room_config:kv(), aff_users(), Version :: binary()}
273 | {error, not_exists}.
274 get_info(HostType, RoomUS) ->
275 53 Args = [HostType, RoomUS],
276 53 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
277
278 -spec force_clear(HostType :: mongooseim:host_type()) -> ok.
279 force_clear(HostType) ->
280 108 mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, []).
Line Hits Source