1 |
|
-module(mod_vcard_backend). |
2 |
|
|
3 |
|
-define(MAIN_MODULE, mod_vcard). |
4 |
|
|
5 |
|
-export([init/2]). |
6 |
|
-export([remove_user/3]). |
7 |
|
-export([get_vcard/3]). |
8 |
|
-export([set_vcard/5]). |
9 |
|
-export([search/3]). |
10 |
|
-export([search_fields/2]). |
11 |
|
-export([search_reported_fields/3]). |
12 |
|
-export([remove_domain/2]). |
13 |
|
-export([tear_down/1]). |
14 |
|
|
15 |
|
%%-------------------------------------------------------------------- |
16 |
|
%% callbacks |
17 |
|
%%-------------------------------------------------------------------- |
18 |
|
-callback init(HostType, Opts) -> ok when |
19 |
|
HostType :: mongooseim:host_type(), |
20 |
|
Opts :: gen_mod:module_opts(). |
21 |
|
|
22 |
|
-callback remove_user(HostType, LUser, LServer) -> any() when |
23 |
|
HostType :: mongooseim:host_type(), |
24 |
|
LUser :: jid:luser(), |
25 |
|
LServer :: jid:lserver(). |
26 |
|
|
27 |
|
-callback remove_domain(HostType, Domain) -> ok when |
28 |
|
HostType :: mongooseim:host_type(), |
29 |
|
Domain :: jid:lserver(). |
30 |
|
|
31 |
|
-callback set_vcard(HostType, LUser, LServer, VCard, VCardSearch) -> |
32 |
|
ok | {error, Reason :: term()} when |
33 |
|
HostType :: mongooseim:host_type(), |
34 |
|
LUser :: jid:luser(), |
35 |
|
LServer :: jid:lserver(), |
36 |
|
VCard :: term(), |
37 |
|
VCardSearch :: term(). |
38 |
|
|
39 |
|
-callback get_vcard(HostType, LUser, LServer) -> |
40 |
|
{ok, Vcard :: term()} | {error, Reason :: term()} when |
41 |
|
HostType :: mongooseim:host_type(), |
42 |
|
LUser :: jid:luser(), |
43 |
|
LServer :: jid:lserver(). |
44 |
|
|
45 |
|
-callback search(HostType, LServer, Data) -> |
46 |
|
Res :: term() when |
47 |
|
HostType :: mongooseim:host_type(), |
48 |
|
LServer :: jid:lserver(), |
49 |
|
Data :: term(). |
50 |
|
|
51 |
|
-callback search_fields(HostType, LServer) -> |
52 |
|
Res :: list() when |
53 |
|
HostType :: mongooseim:host_type(), |
54 |
|
LServer :: jid:lserver(). |
55 |
|
|
56 |
|
-callback search_reported_fields(HostType, LServer, Lang) -> |
57 |
|
Res :: term() when |
58 |
|
HostType :: mongooseim:host_type(), |
59 |
|
LServer :: jid:lserver(), |
60 |
|
Lang :: binary(). |
61 |
|
|
62 |
|
-callback tear_down(HostType) -> ok when |
63 |
|
HostType :: mongooseim:host_type(). |
64 |
|
|
65 |
|
-optional_callbacks([tear_down/1, remove_domain/2]). |
66 |
|
|
67 |
|
|
68 |
|
%%-------------------------------------------------------------------- |
69 |
|
%% specs |
70 |
|
%%-------------------------------------------------------------------- |
71 |
|
-spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. |
72 |
|
init(HostType, Opts) -> |
73 |
224 |
TrackedFuns = [set_vcard, get_vcard, search], |
74 |
224 |
mongoose_backend:init(HostType, ?MAIN_MODULE, TrackedFuns, Opts), |
75 |
224 |
Args = [HostType, Opts], |
76 |
224 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
77 |
|
|
78 |
|
-spec remove_user(mongooseim:host_type(), jid:luser(), jid:lserver()) -> any(). |
79 |
|
remove_user(HostType, LUser, LServer) -> |
80 |
6134 |
Args = [HostType, LUser, LServer], |
81 |
6134 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
82 |
|
|
83 |
|
-spec set_vcard(mongooseim:host_type(), jid:luser(), jid:lserver(), VCard, VCardSearch) -> |
84 |
|
ok | {error, Reason :: term()} when |
85 |
|
VCard :: term(), |
86 |
|
VCardSearch :: term(). |
87 |
|
set_vcard(HostType, LUser, LServer, VCard, VCardSearch) -> |
88 |
35 |
Args = [HostType, LUser, LServer, VCard, VCardSearch], |
89 |
35 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
90 |
|
|
91 |
|
-spec get_vcard(mongooseim:host_type(), jid:luser(), jid:lserver()) -> |
92 |
|
{ok, Vcard :: term()} | {error, Reason :: term()}. |
93 |
|
get_vcard(HostType, LUser, LServer) -> |
94 |
130 |
Args = [HostType, LUser, LServer], |
95 |
130 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
96 |
|
|
97 |
|
-spec search(mongooseim:host_type(), jid:lserver(), Data) -> |
98 |
|
Res :: [[mongoose_data_forms:field()]] when |
99 |
|
Data :: term(). |
100 |
|
search(HostType, LServer, Data) -> |
101 |
21 |
Args = [HostType, LServer, Data], |
102 |
21 |
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
103 |
|
|
104 |
|
-spec search_fields(mongooseim:host_type(), jid:lserver()) -> list(). |
105 |
|
search_fields(HostType, LServer) -> |
106 |
2 |
Args = [HostType, LServer], |
107 |
2 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
108 |
|
|
109 |
|
-spec search_reported_fields(mongooseim:host_type(), jid:lserver(), Lang) -> |
110 |
|
Res :: [mongoose_data_forms:field()] when |
111 |
|
Lang :: binary(). |
112 |
|
search_reported_fields(HostType, LServer, Lang) -> |
113 |
21 |
Args = [HostType, LServer, Lang], |
114 |
21 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
115 |
|
|
116 |
|
-spec remove_domain(mongooseim:host_type(), jid:lserver()) -> ok. |
117 |
|
remove_domain(HostType, LServer) -> |
118 |
18 |
case mongoose_backend:is_exported(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, 2) of |
119 |
|
true -> |
120 |
18 |
Args = [HostType, LServer], |
121 |
18 |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args); |
122 |
|
false -> |
123 |
:-( |
ok |
124 |
|
end. |
125 |
|
|
126 |
|
-spec tear_down(mongooseim:host_type()) -> ok. |
127 |
|
tear_down(HostType) -> |
128 |
224 |
case mongoose_backend:is_exported(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, 1) of |
129 |
|
true -> |
130 |
:-( |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, [HostType]); |
131 |
|
false -> |
132 |
224 |
ok |
133 |
|
end. |