1 |
|
%% Just a proxy interface module between the main mod_roster module and |
2 |
|
%% the backend modules (i.e. mod_roster_rdbms, mod_roster_mnesia...). |
3 |
|
-module(mod_roster_backend). |
4 |
|
-export([init/2, |
5 |
|
transaction/2, |
6 |
|
read_roster_version/3, |
7 |
|
write_roster_version/5, |
8 |
|
get_roster/3, |
9 |
|
get_roster_entry/6, |
10 |
|
get_subscription_lists/3, |
11 |
|
roster_subscribe_t/2, |
12 |
|
update_roster_t/2, |
13 |
|
del_roster_t/4, |
14 |
|
remove_user_t/3, |
15 |
|
remove_domain_t/2]). |
16 |
|
|
17 |
|
-define(MAIN_MODULE, mod_roster). |
18 |
|
|
19 |
|
%% ---------------------------------------------------------------------- |
20 |
|
%% Callbacks |
21 |
|
%% (exactly the same as specs in this module) |
22 |
|
|
23 |
|
-callback init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. |
24 |
|
|
25 |
|
-callback transaction(mongooseim:host_type(), fun(() -> any())) -> |
26 |
|
{aborted, any()} | {atomic, any()} | {error, any()}. |
27 |
|
|
28 |
|
-callback read_roster_version(mongooseim:host_type(), jid:luser(), jid:lserver()) -> |
29 |
|
binary() | error. |
30 |
|
|
31 |
|
-callback write_roster_version(mongooseim:host_type(), jid:luser(), jid:lserver(), |
32 |
|
mod_roster:transaction_state(), mod_roster:version()) -> ok. |
33 |
|
|
34 |
|
-callback get_roster(mongooseim:host_type(), jid:luser(), jid:lserver()) -> [mod_roster:roster()]. |
35 |
|
|
36 |
|
-callback get_roster_entry(mongooseim:host_type(), jid:luser(), jid:lserver(), mod_roster:contact(), |
37 |
|
mod_roster:transaction_state(), mod_roster:entry_format()) -> |
38 |
|
mod_roster:roster() | does_not_exist | error. |
39 |
|
|
40 |
|
-callback get_subscription_lists(mongoose_acc:t(), jid:luser(), jid:lserver()) -> [mod_roster:roster()]. |
41 |
|
|
42 |
|
-callback roster_subscribe_t(mongooseim:host_type(), mod_roster:roster()) -> ok. |
43 |
|
|
44 |
|
-callback update_roster_t(mongooseim:host_type(), mod_roster:roster()) -> ok. |
45 |
|
|
46 |
|
-callback del_roster_t(mongooseim:host_type(), jid:luser(), jid:lserver(), mod_roster:contact()) -> ok. |
47 |
|
|
48 |
|
-callback remove_user_t(mongooseim:host_type(), jid:luser(), jid:lserver()) -> ok. |
49 |
|
|
50 |
|
-callback remove_domain_t(mongooseim:host_type(), jid:lserver()) -> ok. |
51 |
|
|
52 |
|
-optional_callbacks([remove_domain_t/2]). |
53 |
|
|
54 |
|
-spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. |
55 |
|
init(HostType, Opts) -> |
56 |
165 |
TrackedFuns = [read_roster_version, |
57 |
|
write_roster_version, |
58 |
|
get_roster, |
59 |
|
get_roster_entry, |
60 |
|
get_subscription_lists, |
61 |
|
roster_subscribe_t, |
62 |
|
update_roster_t, |
63 |
|
del_roster_t], |
64 |
165 |
mongoose_backend:init(HostType, ?MAIN_MODULE, TrackedFuns, Opts), |
65 |
165 |
Args = [HostType, Opts], |
66 |
165 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
67 |
|
|
68 |
|
-spec transaction(mongooseim:host_type(), fun(() -> any())) -> |
69 |
|
{aborted, any()} | {atomic, any()} | {error, any()}. |
70 |
|
transaction(HostType, F) -> |
71 |
6674 |
Args = [HostType, F], |
72 |
6674 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
73 |
|
|
74 |
|
|
75 |
|
-spec read_roster_version(mongooseim:host_type(), jid:luser(), jid:lserver()) -> |
76 |
|
binary() | error. |
77 |
|
read_roster_version(HostType, LUser, LServer) -> |
78 |
5 |
Args = [HostType, LUser, LServer], |
79 |
5 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
80 |
|
|
81 |
|
-spec write_roster_version(mongooseim:host_type(), jid:luser(), jid:lserver(), |
82 |
|
mod_roster:transaction_state(), mod_roster:version()) -> ok. |
83 |
|
write_roster_version(HostType, LUser, LServer, TransactionState, Ver) -> |
84 |
3 |
Args = [HostType, LUser, LServer, TransactionState, Ver], |
85 |
3 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
86 |
|
|
87 |
|
-spec get_roster(mongooseim:host_type(), jid:luser(), jid:lserver()) -> [mod_roster:roster()]. |
88 |
|
get_roster(HostType, LUser, LServer) -> |
89 |
5845 |
Args = [HostType, LUser, LServer], |
90 |
5845 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
91 |
|
|
92 |
|
-spec get_roster_entry(mongooseim:host_type(), jid:luser(), jid:lserver(), mod_roster:contact(), |
93 |
|
mod_roster:transaction_state(), mod_roster:entry_format()) -> |
94 |
|
mod_roster:roster() | does_not_exist | error. |
95 |
|
get_roster_entry(HostType, LUser, LServer, LJid, TransactionState, Format) -> |
96 |
1319 |
Args = [HostType, LUser, LServer, LJid, TransactionState, Format], |
97 |
1319 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
98 |
|
|
99 |
|
-spec get_subscription_lists(mongoose_acc:t(), jid:luser(), jid:lserver()) -> [mod_roster:roster()]. |
100 |
|
get_subscription_lists(Acc, LUser, LServer) -> |
101 |
5388 |
Args = [Acc, LUser, LServer], |
102 |
5388 |
mongoose_backend:call_tracked(mongoose_acc:host_type(Acc), ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
103 |
|
|
104 |
|
-spec roster_subscribe_t(mongooseim:host_type(), mod_roster:roster()) -> ok. |
105 |
|
roster_subscribe_t(HostType, Roster) -> |
106 |
872 |
Args = [HostType, Roster], |
107 |
872 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
108 |
|
|
109 |
|
-spec update_roster_t(mongooseim:host_type(), mod_roster:roster()) -> ok. |
110 |
|
update_roster_t(HostType, Roster) -> |
111 |
149 |
Args = [HostType, Roster], |
112 |
149 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
113 |
|
|
114 |
|
-spec del_roster_t(mongooseim:host_type(), jid:luser(), jid:lserver(), mod_roster:contact()) -> ok. |
115 |
|
del_roster_t(HostType, LUser, LServer, LJid) -> |
116 |
30 |
Args = [HostType, LUser, LServer, LJid], |
117 |
30 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
118 |
|
|
119 |
|
-spec remove_user_t(mongooseim:host_type(), jid:luser(), jid:lserver()) -> ok. |
120 |
|
remove_user_t(HostType, LUser, LServer) -> |
121 |
5579 |
Args = [HostType, LUser, LServer], |
122 |
5579 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
123 |
|
|
124 |
|
-spec remove_domain_t(mongooseim:host_type(), jid:lserver()) -> ok. |
125 |
|
remove_domain_t(HostType, LServer) -> |
126 |
18 |
Args = [HostType, LServer], |
127 |
18 |
case mongoose_backend:is_exported(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, 2) of |
128 |
|
true -> |
129 |
18 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args); |
130 |
|
false -> |
131 |
:-( |
ok |
132 |
|
end. |