1 |
|
-module(mod_privacy_backend). |
2 |
|
|
3 |
|
-define(MAIN_MODULE, mod_privacy). |
4 |
|
|
5 |
|
-export([init/2, |
6 |
|
get_default_list/3, |
7 |
|
get_list_names/3, |
8 |
|
get_privacy_list/4, |
9 |
|
set_default_list/4, |
10 |
|
forget_default_list/3, |
11 |
|
remove_privacy_list/4, |
12 |
|
replace_privacy_list/5, |
13 |
|
remove_user/3, |
14 |
|
remove_domain/2]). |
15 |
|
|
16 |
|
%% ------------------------------------------------------------------ |
17 |
|
%% Backend callbacks |
18 |
|
%% ------------------------------------------------------------------ |
19 |
|
|
20 |
|
-callback init(HostType, Opts) -> ok when |
21 |
|
HostType :: mongooseim:host_type(), |
22 |
|
Opts :: gen_mod:module_opts(). |
23 |
|
|
24 |
|
-callback remove_user(HostType, LUser, LServer) -> any() when |
25 |
|
HostType :: mongooseim:host_type(), |
26 |
|
LUser :: jid:luser(), |
27 |
|
LServer :: jid:lserver(). |
28 |
|
|
29 |
|
-callback remove_domain(HostType, LServer) -> any() when |
30 |
|
HostType :: mongooseim:host_type(), |
31 |
|
LServer :: jid:lserver(). |
32 |
|
|
33 |
|
-callback get_list_names(HostType, LUser, LServer) -> |
34 |
|
{ok, {Default, Names}} | {error, Reason} when |
35 |
|
HostType :: mongooseim:host_type(), |
36 |
|
LUser :: jid:luser(), |
37 |
|
LServer :: jid:lserver(), |
38 |
|
Default :: mod_privacy:list_name(), |
39 |
|
Names :: [mod_privacy:list_name()], |
40 |
|
Reason :: not_found | term(). |
41 |
|
|
42 |
|
-callback get_privacy_list(HostType, LUser, LServer, Name) -> |
43 |
|
{ok, Items} | {error, Reason} when |
44 |
|
HostType :: mongooseim:host_type(), |
45 |
|
LUser :: jid:luser(), |
46 |
|
LServer :: jid:lserver(), |
47 |
|
Name :: mod_privacy:list_name(), |
48 |
|
Items :: [mod_privacy:list_item()], |
49 |
|
Reason :: not_found | term(). |
50 |
|
|
51 |
|
-callback set_default_list(HostType, LUser, LServer, Name) -> |
52 |
|
ok | {error, Reason} when |
53 |
|
HostType :: mongooseim:host_type(), |
54 |
|
LUser :: jid:luser(), |
55 |
|
LServer :: jid:lserver(), |
56 |
|
Name :: mod_privacy:list_name(), |
57 |
|
Reason :: not_found | term(). |
58 |
|
|
59 |
|
-callback forget_default_list(HostType, LUser, LServer) -> |
60 |
|
ok | {error, Reason} when |
61 |
|
HostType :: mongooseim:host_type(), |
62 |
|
LUser :: jid:luser(), |
63 |
|
LServer :: jid:lserver(), |
64 |
|
Reason :: not_found | term(). |
65 |
|
|
66 |
|
-callback remove_privacy_list(HostType, LUser, LServer, Name) -> |
67 |
|
ok | {error, Reason} when |
68 |
|
HostType :: mongooseim:host_type(), |
69 |
|
LUser :: jid:luser(), |
70 |
|
LServer :: jid:lserver(), |
71 |
|
Name :: mod_privacy:list_name(), |
72 |
|
Reason :: conflict | term(). |
73 |
|
|
74 |
|
-callback replace_privacy_list(HostType, LUser, LServer, Name, Items) -> |
75 |
|
ok | {error, Reason} when |
76 |
|
HostType :: mongooseim:host_type(), |
77 |
|
LUser :: jid:luser(), |
78 |
|
LServer :: jid:lserver(), |
79 |
|
Name :: mod_privacy:list_name(), |
80 |
|
Items :: [mod_privacy:list_item()], |
81 |
|
Reason :: conflict | term(). |
82 |
|
|
83 |
|
-callback get_default_list(HostType, LUser, LServer) -> |
84 |
|
{ok, {Default, Items}} | {error, Reason} when |
85 |
|
HostType :: mongooseim:host_type(), |
86 |
|
LUser :: jid:luser(), |
87 |
|
LServer :: jid:lserver(), |
88 |
|
Default :: mod_privacy:list_name(), |
89 |
|
Items :: [mod_privacy:list_item()], |
90 |
|
Reason :: not_found | term(). |
91 |
|
|
92 |
|
%% ------------------------------------------------------------------ |
93 |
|
%% Backend implementation |
94 |
|
%% ------------------------------------------------------------------ |
95 |
|
|
96 |
|
-spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. |
97 |
|
init(HostType, Opts) -> |
98 |
5 |
TrackedFuns = [get_privacy_list, get_list_names, set_default_list, forget_default_list, |
99 |
|
remove_privacy_list, replace_privacy_list, get_default_list], |
100 |
5 |
mongoose_backend:init(HostType, ?MAIN_MODULE, TrackedFuns, Opts), |
101 |
5 |
Args = [HostType, Opts], |
102 |
5 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
103 |
|
|
104 |
|
-spec remove_user(mongooseim:host_type(), jid:luser(), jid:lserver()) -> any(). |
105 |
|
remove_user(HostType, LUser, LServer) -> |
106 |
114 |
Args = [HostType, LUser, LServer], |
107 |
114 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
108 |
|
|
109 |
|
-spec remove_domain(mongooseim:host_type(), jid:lserver()) -> any(). |
110 |
|
remove_domain(HostType, LServer) -> |
111 |
:-( |
Args = [HostType, LServer], |
112 |
:-( |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
113 |
|
|
114 |
|
-spec get_list_names(mongooseim:host_type(), jid:luser(), jid:lserver()) -> |
115 |
|
{ok, {Default, Names}} | {error, Reason} when |
116 |
|
Default :: mod_privacy:list_name(), |
117 |
|
Names :: [mod_privacy:list_name()], |
118 |
|
Reason :: not_found | term(). |
119 |
|
get_list_names(HostType, LUser, LServer) -> |
120 |
3 |
Args = [HostType, LUser, LServer], |
121 |
3 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
122 |
|
|
123 |
|
-spec get_privacy_list(mongooseim:host_type(), jid:luser(), jid:lserver(), Name) -> |
124 |
|
{ok, Items} | {error, Reason} when |
125 |
|
Name :: mod_privacy:list_name(), |
126 |
|
Items :: [mod_privacy:list_item()], |
127 |
|
Reason :: not_found | term(). |
128 |
|
get_privacy_list(HostType, LUser, LServer, Name) -> |
129 |
129 |
Args = [HostType, LUser, LServer, Name], |
130 |
129 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
131 |
|
|
132 |
|
-spec set_default_list(mongooseim:host_type(), jid:luser(), jid:lserver(), Name) -> |
133 |
|
ok | {error, Reason} when |
134 |
|
Name :: mod_privacy:list_name(), |
135 |
|
Reason :: not_found | term(). |
136 |
|
set_default_list(HostType, LUser, LServer, Name) -> |
137 |
42 |
Args = [HostType, LUser, LServer, Name], |
138 |
42 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
139 |
|
|
140 |
|
-spec forget_default_list(mongooseim:host_type(), jid:luser(), jid:lserver()) -> |
141 |
|
ok | {error, Reason} when |
142 |
|
Reason :: not_found | term(). |
143 |
|
forget_default_list(HostType, LUser, LServer) -> |
144 |
1 |
Args = [HostType, LUser, LServer], |
145 |
1 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
146 |
|
|
147 |
|
-spec remove_privacy_list(mongooseim:host_type(), jid:luser(), jid:lserver(), Name) -> |
148 |
|
ok | {error, Reason} when |
149 |
|
Name :: mod_privacy:list_name(), |
150 |
|
Reason :: conflict | term(). |
151 |
|
remove_privacy_list(HostType, LUser, LServer, Name) -> |
152 |
1 |
Args = [HostType, LUser, LServer, Name], |
153 |
1 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
154 |
|
|
155 |
|
-spec replace_privacy_list(mongooseim:host_type(), jid:luser(), jid:lserver(), Name, Items) -> |
156 |
|
ok | {error, Reason} when |
157 |
|
Name :: mod_privacy:list_name(), |
158 |
|
Items :: [mod_privacy:list_item()], |
159 |
|
Reason :: conflict | term(). |
160 |
|
replace_privacy_list(HostType, LUser, LServer, Name, List) -> |
161 |
77 |
Args = [HostType, LUser, LServer, Name, List], |
162 |
77 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
163 |
|
|
164 |
|
-spec get_default_list(mongooseim:host_type(), jid:luser(), jid:lserver()) -> |
165 |
|
{ok, {Default, Items}} | {error, Reason} when |
166 |
|
Default :: mod_privacy:list_name(), |
167 |
|
Items :: [mod_privacy:list_item()], |
168 |
|
Reason :: not_found | term(). |
169 |
|
get_default_list(HostType, LUser, LServer) -> |
170 |
2523 |
Args = [HostType, LUser, LServer], |
171 |
2523 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |