1 |
|
%%% @doc A proxy interface module between the main mod_global_distrib_mapping module |
2 |
|
%%% and the backend modules. |
3 |
|
%%% There is only one backend implementation (redis), so the backend module is global. |
4 |
|
-module(mod_global_distrib_mapping_backend). |
5 |
|
|
6 |
|
-export([start/1, |
7 |
|
stop/0, |
8 |
|
put_session/1, |
9 |
|
get_session/1, |
10 |
|
delete_session/1, |
11 |
|
put_domain/2, |
12 |
|
get_domain/1, |
13 |
|
delete_domain/1, |
14 |
|
get_domains/0, |
15 |
|
get_public_domains/0, |
16 |
|
get_endpoints/1, |
17 |
|
get_hosts/0]). |
18 |
|
|
19 |
|
-define(MAIN_MODULE, mod_global_distrib_mapping). |
20 |
|
|
21 |
|
-type endpoint() :: mod_global_distrib_utils:endpoint(). |
22 |
|
|
23 |
|
%% Callbacks |
24 |
|
|
25 |
|
-callback start(gen_mod:module_opts()) -> any(). |
26 |
|
-callback stop() -> any(). |
27 |
|
|
28 |
|
%% Mapping from a JID to the local host |
29 |
|
-callback put_session(jid:literal_jid()) -> ok. |
30 |
|
-callback get_session(jid:literal_jid()) -> {ok, jid:lserver()} | error. |
31 |
|
-callback delete_session(jid:literal_jid()) -> ok. |
32 |
|
|
33 |
|
%% Mapping from a domain to the local host |
34 |
|
-callback put_domain(jid:lserver(), IsHidden :: boolean()) -> ok. |
35 |
|
-callback get_domain(jid:lserver()) -> {ok, jid:lserver()} | error. |
36 |
|
-callback delete_domain(jid:lserver()) -> ok. |
37 |
|
|
38 |
|
-callback get_domains() -> [jid:lserver()]. |
39 |
|
-callback get_public_domains() -> [jid:lserver()]. |
40 |
|
-callback get_endpoints(jid:lserver()) -> [endpoint()]. |
41 |
|
-callback get_hosts() -> [jid:lserver()]. |
42 |
|
|
43 |
|
%% API Functions |
44 |
|
|
45 |
|
-spec start(gen_mod:module_opts()) -> any(). |
46 |
|
start(Opts) -> |
47 |
21 |
mongoose_backend:init(global, ?MAIN_MODULE, [], Opts), |
48 |
21 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, [Opts]). |
49 |
|
|
50 |
|
-spec stop() -> any(). |
51 |
|
stop() -> |
52 |
21 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, []). |
53 |
|
|
54 |
|
-spec put_session(jid:literal_jid()) -> ok. |
55 |
|
put_session(JID) -> |
56 |
142 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, [JID]). |
57 |
|
|
58 |
|
-spec get_session(jid:literal_jid()) -> {ok, jid:lserver()} | error. |
59 |
|
get_session(JID) -> |
60 |
76 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, [JID]). |
61 |
|
|
62 |
|
-spec delete_session(jid:literal_jid()) -> ok. |
63 |
|
delete_session(JID) -> |
64 |
146 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, [JID]). |
65 |
|
|
66 |
|
-spec put_domain(jid:lserver(), boolean()) -> ok. |
67 |
|
put_domain(Domain, IsHidden) -> |
68 |
10 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, [Domain, IsHidden]). |
69 |
|
|
70 |
|
-spec get_domain(jid:lserver()) -> {ok, jid:lserver()} | error. |
71 |
|
get_domain(Domain) -> |
72 |
17 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, [Domain]). |
73 |
|
|
74 |
|
-spec delete_domain(jid:lserver()) -> ok. |
75 |
|
delete_domain(Domain) -> |
76 |
12 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, [Domain]). |
77 |
|
|
78 |
|
-spec get_domains() -> [jid:lserver()]. |
79 |
|
get_domains() -> |
80 |
3 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, []). |
81 |
|
|
82 |
|
-spec get_public_domains() -> [jid:lserver()]. |
83 |
|
get_public_domains() -> |
84 |
3 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, []). |
85 |
|
|
86 |
|
-spec get_endpoints(jid:lserver()) -> [endpoint()]. |
87 |
|
get_endpoints(Domain) -> |
88 |
99 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, [Domain]). |
89 |
|
|
90 |
|
-spec get_hosts() -> [jid:lserver()]. |
91 |
|
get_hosts() -> |
92 |
590 |
mongoose_backend:call(global, ?MAIN_MODULE, ?FUNCTION_NAME, []). |