1 |
|
%% Just a proxy interface module between the main mod_private module and |
2 |
|
%% the backend modules (i.e. mod_private_rdbms, mod_private_mnesia...). |
3 |
|
-module(mod_private_backend). |
4 |
|
-export([init/2, |
5 |
|
multi_set_data/4, |
6 |
|
multi_get_data/4, |
7 |
|
get_all_nss/3, |
8 |
|
remove_user/3, |
9 |
|
remove_domain/2]). |
10 |
|
|
11 |
|
-define(MAIN_MODULE, mod_private). |
12 |
|
|
13 |
|
-type ns() :: binary(). |
14 |
|
-type ns_xml() :: {ns(), exml:element()}. |
15 |
|
|
16 |
|
%% ---------------------------------------------------------------------- |
17 |
|
%% Callbacks |
18 |
|
%% (exactly the same as specs in this module) |
19 |
|
|
20 |
|
-callback init(HostType, Opts) -> ok when |
21 |
|
HostType :: mongooseim:host_type(), |
22 |
|
Opts :: gen_mod:module_opts(). |
23 |
|
|
24 |
|
-callback multi_set_data(HostType, LUser, LServer, NS2XML) -> Result when |
25 |
|
HostType :: mongooseim:host_type(), |
26 |
|
LUser :: jid:luser(), |
27 |
|
LServer :: jid:lserver(), |
28 |
|
NS2XML :: [ns_xml()], |
29 |
|
Reason :: term(), |
30 |
|
Result :: ok | {aborted, Reason} | {error, Reason}. |
31 |
|
|
32 |
|
-callback multi_get_data(HostType, LUser, LServer, NS2Def) -> [XML | Default] when |
33 |
|
HostType :: mongooseim:host_type(), |
34 |
|
LUser :: jid:luser(), |
35 |
|
LServer :: jid:lserver(), |
36 |
|
NS2Def :: [{NS, Default}], |
37 |
|
NS :: ns(), |
38 |
|
Default :: term(), |
39 |
|
XML :: exml:element(). |
40 |
|
|
41 |
|
-callback remove_user(HostType, LUser, LServer) -> any() when |
42 |
|
HostType :: mongooseim:host_type(), |
43 |
|
LUser :: jid:luser(), |
44 |
|
LServer :: jid:lserver(). |
45 |
|
|
46 |
|
-callback remove_domain(HostType, LServer) -> any() when |
47 |
|
HostType :: mongooseim:host_type(), |
48 |
|
LServer :: jid:lserver(). |
49 |
|
|
50 |
|
-callback get_all_nss(HostType, LUser, LServer) -> NSs when |
51 |
|
HostType :: mongooseim:host_type(), |
52 |
|
LUser :: jid:luser(), |
53 |
|
LServer :: jid:lserver(), |
54 |
|
NSs :: [ns()]. |
55 |
|
|
56 |
|
%% ---------------------------------------------------------------------- |
57 |
|
%% API Functions |
58 |
|
|
59 |
|
-spec init(HostType, Opts) -> ok when |
60 |
|
HostType :: mongooseim:host_type(), |
61 |
|
Opts :: gen_mod:module_opts(). |
62 |
|
init(HostType, Opts) -> |
63 |
6 |
TrackedFuns = [multi_get_data, multi_set_data], |
64 |
6 |
mongoose_backend:init(HostType, ?MAIN_MODULE, TrackedFuns, Opts), |
65 |
6 |
Args = [HostType, Opts], |
66 |
6 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
67 |
|
|
68 |
|
-spec multi_set_data(HostType, LUser, LServer, NS2XML) -> Result when |
69 |
|
HostType :: mongooseim:host_type(), |
70 |
|
LUser :: jid:luser(), |
71 |
|
LServer :: jid:lserver(), |
72 |
|
NS2XML :: [ns_xml()], |
73 |
|
Reason :: term(), |
74 |
|
Result :: ok | {aborted, Reason} | {error, Reason}. |
75 |
|
multi_set_data(HostType, LUser, LServer, NS2XML) -> |
76 |
21 |
Args = [HostType, LUser, LServer, NS2XML], |
77 |
21 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
78 |
|
|
79 |
|
-spec multi_get_data(HostType, LUser, LServer, NS2Def) -> [XML | Default] when |
80 |
|
HostType :: mongooseim:host_type(), |
81 |
|
LUser :: jid:luser(), |
82 |
|
LServer :: jid:lserver(), |
83 |
|
NS2Def :: [{NS, Default}], |
84 |
|
NS :: ns(), |
85 |
|
Default :: term(), |
86 |
|
XML :: exml:element(). |
87 |
|
multi_get_data(HostType, LUser, LServer, NS2Def) -> |
88 |
20 |
Args = [HostType, LUser, LServer, NS2Def], |
89 |
20 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
90 |
|
|
91 |
|
-spec remove_user(HostType, LUser, LServer) -> any() when |
92 |
|
HostType :: mongooseim:host_type(), |
93 |
|
LUser :: jid:luser(), |
94 |
|
LServer :: jid:lserver(). |
95 |
|
remove_user(HostType, LUser, LServer) -> |
96 |
38 |
Args = [HostType, LUser, LServer], |
97 |
38 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
98 |
|
|
99 |
|
-spec remove_domain(HostType, LServer) -> any() when |
100 |
|
HostType :: mongooseim:host_type(), |
101 |
|
LServer :: jid:lserver(). |
102 |
|
remove_domain(HostType, LServer) -> |
103 |
:-( |
Args = [HostType, LServer], |
104 |
:-( |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
105 |
|
|
106 |
|
-spec get_all_nss(HostType, LUser, LServer) -> NSs when |
107 |
|
HostType :: mongooseim:host_type(), |
108 |
|
LUser :: jid:luser(), |
109 |
|
LServer :: jid:lserver(), |
110 |
|
NSs :: [ns()]. |
111 |
|
get_all_nss(HostType, LUser, LServer) -> |
112 |
20 |
Args = [HostType, LUser, LServer], |
113 |
20 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |