1 |
|
%%% @doc Hooks wrapper providing clear specifications for a hook caller. |
2 |
|
%%% |
3 |
|
%%% Every hook has its own function in this module with specs as accurate as |
4 |
|
%%% possible. This helps to have a static analysis of the hooks callers to |
5 |
|
%%% make sure they pass the expected arguments. |
6 |
|
-module(mongoose_hooks). |
7 |
|
|
8 |
|
-include("jlib.hrl"). |
9 |
|
-include("mod_privacy.hrl"). |
10 |
|
-include("mongoose.hrl"). |
11 |
|
|
12 |
|
-export([adhoc_local_commands/4, |
13 |
|
adhoc_sm_commands/4, |
14 |
|
anonymous_purge_hook/3, |
15 |
|
auth_failed/3, |
16 |
|
does_user_exist/3, |
17 |
|
ejabberd_ctl_process/2, |
18 |
|
failed_to_store_message/1, |
19 |
|
filter_local_packet/1, |
20 |
|
filter_packet/1, |
21 |
|
inbox_unread_count/3, |
22 |
|
get_key/2, |
23 |
|
packet_to_component/3, |
24 |
|
presence_probe_hook/5, |
25 |
|
push_notifications/4, |
26 |
|
register_command/1, |
27 |
|
register_subhost/2, |
28 |
|
register_user/3, |
29 |
|
remove_user/3, |
30 |
|
resend_offline_messages_hook/2, |
31 |
|
rest_user_send_packet/4, |
32 |
|
session_cleanup/5, |
33 |
|
set_vcard/3, |
34 |
|
unacknowledged_message/3, |
35 |
|
unregister_command/1, |
36 |
|
unregister_subhost/1, |
37 |
|
user_available_hook/3, |
38 |
|
user_ping_response/5, |
39 |
|
user_ping_timeout/2, |
40 |
|
user_receive_packet/6, |
41 |
|
user_sent_keep_alive/2, |
42 |
|
user_send_packet/4, |
43 |
|
vcard_set/4, |
44 |
|
xmpp_send_element/3, |
45 |
|
xmpp_stanza_dropped/4]). |
46 |
|
|
47 |
|
-export([c2s_broadcast_recipients/4, |
48 |
|
c2s_filter_packet/4, |
49 |
|
c2s_preprocessing_hook/3, |
50 |
|
c2s_presence_in/4, |
51 |
|
c2s_stream_features/2, |
52 |
|
c2s_unauthenticated_iq/4, |
53 |
|
c2s_update_presence/2, |
54 |
|
check_bl_c2s/1, |
55 |
|
forbidden_session_hook/3, |
56 |
|
session_opening_allowed_for_user/2]). |
57 |
|
|
58 |
|
-export([privacy_check_packet/5, |
59 |
|
privacy_get_user_list/2, |
60 |
|
privacy_iq_get/6, |
61 |
|
privacy_iq_set/5, |
62 |
|
privacy_updated_list/3]). |
63 |
|
|
64 |
|
-export([offline_groupchat_message_hook/4, |
65 |
|
offline_message_hook/4, |
66 |
|
set_presence_hook/3, |
67 |
|
sm_broadcast/5, |
68 |
|
sm_filter_offline_message/4, |
69 |
|
sm_register_connection_hook/4, |
70 |
|
sm_remove_connection_hook/5, |
71 |
|
unset_presence_hook/3, |
72 |
|
xmpp_bounce_message/1]). |
73 |
|
|
74 |
|
-export([roster_get/2, |
75 |
|
roster_get_jid_info/3, |
76 |
|
roster_get_subscription_lists/3, |
77 |
|
roster_get_versioning_feature/1, |
78 |
|
roster_groups/1, |
79 |
|
roster_in_subscription/5, |
80 |
|
roster_out_subscription/4, |
81 |
|
roster_process_item/3, |
82 |
|
roster_push/3, |
83 |
|
roster_set/4]). |
84 |
|
|
85 |
|
-export([is_muc_room_owner/4, |
86 |
|
can_access_identity/3, |
87 |
|
can_access_room/4, |
88 |
|
acc_room_affiliations/2, |
89 |
|
room_new_affiliations/4, |
90 |
|
room_exists/2]). |
91 |
|
|
92 |
|
-export([mam_archive_id/2, |
93 |
|
mam_archive_size/3, |
94 |
|
mam_get_behaviour/4, |
95 |
|
mam_set_prefs/6, |
96 |
|
mam_get_prefs/4, |
97 |
|
mam_remove_archive/3, |
98 |
|
mam_lookup_messages/2, |
99 |
|
mam_archive_message/2, |
100 |
|
mam_flush_messages/2, |
101 |
|
mam_archive_sync/1, |
102 |
|
mam_retraction/3]). |
103 |
|
|
104 |
|
-export([mam_muc_archive_id/2, |
105 |
|
mam_muc_archive_size/3, |
106 |
|
mam_muc_get_behaviour/4, |
107 |
|
mam_muc_set_prefs/6, |
108 |
|
mam_muc_get_prefs/4, |
109 |
|
mam_muc_remove_archive/3, |
110 |
|
mam_muc_lookup_messages/2, |
111 |
|
mam_muc_archive_message/2, |
112 |
|
mam_muc_flush_messages/2, |
113 |
|
mam_muc_archive_sync/1, |
114 |
|
mam_muc_retraction/3]). |
115 |
|
|
116 |
|
-export([get_mam_pm_gdpr_data/2, |
117 |
|
get_mam_muc_gdpr_data/2, |
118 |
|
get_personal_data/2]). |
119 |
|
|
120 |
|
-export([find_s2s_bridge/2, |
121 |
|
s2s_allow_host/2, |
122 |
|
s2s_connect_hook/2, |
123 |
|
s2s_receive_packet/1, |
124 |
|
s2s_stream_features/2, |
125 |
|
s2s_send_packet/4]). |
126 |
|
|
127 |
|
-export([disco_local_identity/1, |
128 |
|
disco_sm_identity/1, |
129 |
|
disco_local_items/1, |
130 |
|
disco_sm_items/1, |
131 |
|
disco_local_features/1, |
132 |
|
disco_sm_features/1, |
133 |
|
disco_muc_features/1, |
134 |
|
disco_info/1]). |
135 |
|
|
136 |
|
-export([amp_check_condition/3, |
137 |
|
amp_determine_strategy/5, |
138 |
|
amp_verify_support/2]). |
139 |
|
|
140 |
|
-export([filter_room_packet/3, |
141 |
|
forget_room/3, |
142 |
|
invitation_sent/6, |
143 |
|
join_room/5, |
144 |
|
leave_room/5, |
145 |
|
room_packet/5, |
146 |
|
update_inbox_for_muc/2]). |
147 |
|
|
148 |
|
-export([caps_recognised/4]). |
149 |
|
|
150 |
|
-export([pubsub_create_node/5, |
151 |
|
pubsub_delete_node/4, |
152 |
|
pubsub_publish_item/6]). |
153 |
|
|
154 |
|
-export([mod_global_distrib_known_recipient/4, |
155 |
|
mod_global_distrib_unknown_recipient/2]). |
156 |
|
|
157 |
|
-export([c2s_remote_hook/5]). |
158 |
|
|
159 |
|
-export([remove_domain/2, |
160 |
|
node_cleanup/1]). |
161 |
|
|
162 |
|
-ignore_xref([node_cleanup/1, remove_domain/2]). |
163 |
|
-ignore_xref([mam_archive_sync/1, mam_muc_archive_sync/1]). |
164 |
|
|
165 |
|
%% Just a map, used by some hooks as a first argument. |
166 |
|
%% Not mongoose_acc:t(). |
167 |
|
-type simple_acc() :: #{}. |
168 |
|
-export_type([simple_acc/0]). |
169 |
|
|
170 |
|
-type filter_packet_acc() :: {From :: jid:jid(), |
171 |
|
To :: jid:jid(), |
172 |
|
Acc :: mongoose_acc:t(), |
173 |
|
Packet :: exml:element()}. |
174 |
|
-export_type([filter_packet_acc/0]). |
175 |
|
|
176 |
|
-spec c2s_remote_hook(HostType, Tag, Args, HandlerState, C2SState) -> Result when |
177 |
|
HostType :: binary(), |
178 |
|
Tag :: atom(), |
179 |
|
Args :: term(), |
180 |
|
HandlerState :: term(), |
181 |
|
C2SState :: ejabberd_c2s:state(), |
182 |
|
Result :: term(). % ok | empty_state | HandlerState |
183 |
|
c2s_remote_hook(HostType, Tag, Args, HandlerState, C2SState) -> |
184 |
88 |
run_hook_for_host_type(c2s_remote_hook, HostType, HandlerState, |
185 |
|
[Tag, Args, C2SState]). |
186 |
|
|
187 |
|
-spec adhoc_local_commands(HostType, From, To, AdhocRequest) -> Result when |
188 |
|
HostType :: mongooseim:host_type(), |
189 |
|
From :: jid:jid(), |
190 |
|
To :: jid:jid(), |
191 |
|
AdhocRequest :: adhoc:request(), |
192 |
|
Result :: mod_adhoc:command_hook_acc(). |
193 |
|
adhoc_local_commands(HostType, From, To, AdhocRequest) -> |
194 |
1 |
run_hook_for_host_type(adhoc_local_commands, HostType, empty, |
195 |
|
[From, To, AdhocRequest]). |
196 |
|
|
197 |
|
-spec adhoc_sm_commands(HostType, From, To, AdhocRequest) -> Result when |
198 |
|
HostType :: mongooseim:host_type(), |
199 |
|
From :: jid:jid(), |
200 |
|
To :: jid:jid(), |
201 |
|
AdhocRequest :: adhoc:request(), |
202 |
|
Result :: mod_adhoc:command_hook_acc(). |
203 |
|
adhoc_sm_commands(HostType, From, To, AdhocRequest) -> |
204 |
:-( |
run_hook_for_host_type(adhoc_sm_commands, HostType, empty, [From, To, AdhocRequest]). |
205 |
|
|
206 |
|
%%% @doc The `anonymous_purge_hook' hook is called when anonymous user's data is removed. |
207 |
|
-spec anonymous_purge_hook(LServer, Acc, LUser) -> Result when |
208 |
|
LServer :: jid:lserver(), |
209 |
|
Acc :: mongoose_acc:t(), |
210 |
|
LUser :: jid:user(), |
211 |
|
Result :: mongose_acc:t(). |
212 |
|
anonymous_purge_hook(LServer, Acc, LUser) -> |
213 |
2 |
HostType = mongoose_acc:host_type(Acc), |
214 |
2 |
run_hook_for_host_type(anonymous_purge_hook, HostType, Acc, [LUser, LServer]). |
215 |
|
|
216 |
|
-spec auth_failed(HostType, Server, Username) -> Result when |
217 |
|
HostType :: binary(), |
218 |
|
Server :: jid:server(), |
219 |
|
Username :: jid:user() | unknown, |
220 |
|
Result :: ok. |
221 |
|
auth_failed(HostType, Server, Username) -> |
222 |
51 |
run_hook_for_host_type(auth_failed, HostType, ok, [Username, Server]). |
223 |
|
|
224 |
|
-spec does_user_exist(HostType, Jid, RequestType) -> Result when |
225 |
|
HostType :: mongooseim:host_type(), |
226 |
|
Jid :: jid:jid(), |
227 |
|
RequestType :: ejabberd_auth:exist_type(), |
228 |
|
Result :: boolean(). |
229 |
|
does_user_exist(HostType, Jid, RequestType) -> |
230 |
412 |
run_hook_for_host_type(does_user_exist, HostType, false, |
231 |
|
[HostType, Jid, RequestType]). |
232 |
|
|
233 |
|
-spec remove_domain(HostType, Domain) -> Result when |
234 |
|
HostType :: binary(), |
235 |
|
Domain :: jid:lserver(), |
236 |
|
Result :: ok. |
237 |
|
remove_domain(HostType, Domain) -> |
238 |
1 |
run_hook_for_host_type(remove_domain, HostType, #{}, [HostType, Domain]). |
239 |
|
|
240 |
|
-spec node_cleanup(Node :: node()) -> Acc :: map(). |
241 |
|
node_cleanup(Node) -> |
242 |
:-( |
Params = #{node => Node}, |
243 |
:-( |
Args = [Node], |
244 |
:-( |
ParamsWithLegacyArgs = ejabberd_hooks:add_args(Params, Args), |
245 |
:-( |
run_global_hook(node_cleanup, #{}, ParamsWithLegacyArgs). |
246 |
|
|
247 |
|
-spec ejabberd_ctl_process(Acc, Args) -> Result when |
248 |
|
Acc :: any(), |
249 |
|
Args :: [string()], |
250 |
|
Result :: any(). |
251 |
|
ejabberd_ctl_process(Acc, Args) -> |
252 |
154 |
run_global_hook(ejabberd_ctl_process, Acc, [Args]). |
253 |
|
|
254 |
|
-spec failed_to_store_message(Acc) -> Result when |
255 |
|
Acc :: mongoose_acc:t(), |
256 |
|
Result :: mongoose_acc:t(). |
257 |
|
failed_to_store_message(Acc) -> |
258 |
12 |
HostType = mongoose_acc:host_type(Acc), |
259 |
12 |
run_hook_for_host_type(failed_to_store_message, HostType, Acc, []). |
260 |
|
|
261 |
|
%%% @doc The `filter_local_packet' hook is called to filter out |
262 |
|
%%% stanzas routed with `mongoose_local_delivery'. |
263 |
|
-spec filter_local_packet(FilterAcc) -> Result when |
264 |
|
FilterAcc :: filter_packet_acc(), |
265 |
|
Result :: drop | filter_packet_acc(). |
266 |
|
filter_local_packet(FilterAcc = {_From, _To, Acc, _Packet}) -> |
267 |
17092 |
HostType = mongoose_acc:host_type(Acc), |
268 |
17092 |
run_hook_for_host_type(filter_local_packet, HostType, FilterAcc, []). |
269 |
|
|
270 |
|
%%% @doc The `filter_packet' hook is called to filter out |
271 |
|
%%% stanzas routed with `mongoose_router_global'. |
272 |
|
-spec filter_packet(Acc) -> Result when |
273 |
|
Acc :: filter_packet_acc(), |
274 |
|
Result :: drop | filter_packet_acc(). |
275 |
|
filter_packet(Acc) -> |
276 |
17601 |
run_global_hook(filter_packet, Acc, []). |
277 |
|
|
278 |
|
%%% @doc The `inbox_unread_count' hook is called to get the number |
279 |
|
%%% of unread messages in the inbox for a user. |
280 |
|
-spec inbox_unread_count(LServer, Acc, User) -> Result when |
281 |
|
LServer :: jid:lserver(), |
282 |
|
Acc :: mongoose_acc:t(), |
283 |
|
User :: jid:jid(), |
284 |
|
Result :: mongoose_acc:t(). |
285 |
|
inbox_unread_count(LServer, Acc, User) -> |
286 |
189 |
run_hook_for_host_type(inbox_unread_count, LServer, Acc, [User]). |
287 |
|
|
288 |
|
%%% @doc The `get_key' hook is called to extract a key from `mod_keystore'. |
289 |
|
-spec get_key(HostType, KeyName) -> Result when |
290 |
|
HostType :: mongooseim:host_type(), |
291 |
|
KeyName :: atom(), |
292 |
|
Result :: mod_keystore:key_list(). |
293 |
|
get_key(HostType, KeyName) -> |
294 |
:-( |
run_hook_for_host_type(get_key, HostType, [], [{KeyName, HostType}]). |
295 |
|
|
296 |
|
-spec packet_to_component(Acc, From, To) -> Result when |
297 |
|
Acc :: mongoose_acc:t(), |
298 |
|
From :: jid:jid(), |
299 |
|
To :: jid:jid(), |
300 |
|
Result :: mongoose_acc:t(). |
301 |
|
packet_to_component(Acc, From, To) -> |
302 |
21 |
run_global_hook(packet_to_component, Acc, [From, To]). |
303 |
|
|
304 |
|
-spec presence_probe_hook(HostType, Acc, From, To, Pid) -> Result when |
305 |
|
HostType :: binary(), |
306 |
|
Acc :: mongoose_acc:t(), |
307 |
|
From :: jid:jid(), |
308 |
|
To :: jid:jid(), |
309 |
|
Pid :: pid(), |
310 |
|
Result :: mongoose_acc:t(). |
311 |
|
presence_probe_hook(HostType, Acc, From, To, Pid) -> |
312 |
2664 |
run_hook_for_host_type(presence_probe_hook, HostType, Acc, [From, To, Pid]). |
313 |
|
|
314 |
|
%%% @doc The `push_notifications' hook is called to push notifications. |
315 |
|
-spec push_notifications(Server, Acc, NotificationForms, Options) -> Result when |
316 |
|
Server :: jid:server(), |
317 |
|
Acc :: ok | mongoose_acc:t(), |
318 |
|
NotificationForms :: [#{atom() => binary()}], |
319 |
|
Options :: #{atom() => binary()}, |
320 |
|
Result :: ok | {error, any()}. |
321 |
|
push_notifications(Server, Acc, NotificationForms, Options) -> |
322 |
77 |
Params = #{server => Server, options => Options, |
323 |
|
notification_forms => NotificationForms}, |
324 |
77 |
Args = [Server, NotificationForms, Options], |
325 |
77 |
ParamsWithLegacyArgs = ejabberd_hooks:add_args(Params, Args), |
326 |
77 |
run_hook_for_host_type(push_notifications, Server, Acc, ParamsWithLegacyArgs). |
327 |
|
|
328 |
|
%%% @doc The `register_command' hook is called when a command |
329 |
|
%%% is registered in `mongoose_commands'. |
330 |
|
-spec register_command(Command) -> Result when |
331 |
|
Command :: mongoose_commands:t(), |
332 |
|
Result :: drop. |
333 |
|
register_command(Command) -> |
334 |
8551 |
run_global_hook(register_command, Command, []). |
335 |
|
|
336 |
|
%%% @doc The `register_subhost' hook is called when a component |
337 |
|
%%% is registered for ejabberd_router. |
338 |
|
-spec register_subhost(LDomain, IsHidden) -> Result when |
339 |
|
LDomain :: binary(), |
340 |
|
IsHidden :: boolean(), |
341 |
|
Result :: any(). |
342 |
|
register_subhost(LDomain, IsHidden) -> |
343 |
189 |
run_global_hook(register_subhost, ok, [LDomain, IsHidden]). |
344 |
|
|
345 |
|
%%% @doc The `register_user' hook is called when a user is successfully |
346 |
|
%%% registered in an authentication backend. |
347 |
|
-spec register_user(HostType, LServer, LUser) -> Result when |
348 |
|
HostType :: binary(), |
349 |
|
LServer :: jid:lserver(), |
350 |
|
LUser :: jid:luser(), |
351 |
|
Result :: any(). |
352 |
|
register_user(HostType, LServer, LUser) -> |
353 |
2315 |
run_hook_for_host_type(register_user, HostType, ok, [LUser, LServer]). |
354 |
|
|
355 |
|
%%% @doc The `remove_user' hook is called when a user is removed. |
356 |
|
-spec remove_user(Acc, LServer, LUser) -> Result when |
357 |
|
Acc :: mongoose_acc:t(), |
358 |
|
LServer :: jid:lserver(), |
359 |
|
LUser :: jid:luser(), |
360 |
|
Result :: mongoose_acc:t(). |
361 |
|
remove_user(Acc, LServer, LUser) -> |
362 |
2318 |
HostType = mongoose_acc:host_type(Acc), |
363 |
2318 |
run_hook_for_host_type(remove_user, HostType, Acc, [LUser, LServer]). |
364 |
|
|
365 |
|
-spec resend_offline_messages_hook(Acc, JID) -> Result when |
366 |
|
Acc :: mongoose_acc:t(), |
367 |
|
JID :: jid:jid(), |
368 |
|
Result :: mongoose_acc:t(). |
369 |
|
resend_offline_messages_hook(Acc, JID) -> |
370 |
2530 |
HostType = mongoose_acc:host_type(Acc), |
371 |
2530 |
run_hook_for_host_type(resend_offline_messages_hook, HostType, Acc, [JID]). |
372 |
|
|
373 |
|
%%% @doc The `rest_user_send_packet' hook is called when a user sends |
374 |
|
%%% a message using the REST API. |
375 |
|
-spec rest_user_send_packet(Acc, From, To, Packet) -> Result when |
376 |
|
Acc :: mongoose_acc:t(), |
377 |
|
From :: jid:jid(), |
378 |
|
To :: jid:jid(), |
379 |
|
Packet :: exml:element(), |
380 |
|
Result :: mongoose_acc:t(). |
381 |
|
rest_user_send_packet(Acc, From, To, Packet) -> |
382 |
2 |
HostType = mongoose_acc:host_type(Acc), |
383 |
2 |
run_hook_for_host_type(rest_user_send_packet, HostType, Acc, [From, To, Packet]). |
384 |
|
|
385 |
|
%%% @doc The `session_cleanup' hook is called when sm backend cleans up a user's session. |
386 |
|
-spec session_cleanup(Server, Acc, User, Resource, SID) -> Result when |
387 |
|
Server :: jid:server(), |
388 |
|
Acc :: mongoose_acc:t(), |
389 |
|
User :: jid:user(), |
390 |
|
Resource :: jid:resource(), |
391 |
|
SID :: ejabberd_sm:sid(), |
392 |
|
Result :: mongoose_acc:t(). |
393 |
|
session_cleanup(Server, Acc, User, Resource, SID) -> |
394 |
:-( |
HostType = mongoose_acc:host_type(Acc), |
395 |
:-( |
run_hook_for_host_type(session_cleanup, HostType, Acc, |
396 |
|
[User, Server, Resource, SID]). |
397 |
|
|
398 |
|
%%% @doc The `set_vcard' hook is called when the caller wants to set the VCard. |
399 |
|
-spec set_vcard(HostType, UserJID, VCard) -> Result when |
400 |
|
HostType :: mongooseim:host_type(), |
401 |
|
UserJID :: jid:jid(), |
402 |
|
VCard :: exml:element(), |
403 |
|
Result :: ok | {error, any()}. |
404 |
|
set_vcard(HostType, UserJID, VCard) -> |
405 |
:-( |
run_hook_for_host_type(set_vcard, HostType, {error, no_handler_defined}, |
406 |
|
[HostType, UserJID, VCard]). |
407 |
|
|
408 |
|
-spec unacknowledged_message(HostType, Acc, JID) -> Result when |
409 |
|
HostType :: binary(), |
410 |
|
Acc :: mongoose_acc:t(), |
411 |
|
JID :: jid:jid(), |
412 |
|
Result :: mongoose_acc:t(). |
413 |
|
unacknowledged_message(HostType, Acc, JID) -> |
414 |
61 |
Params = #{jid => JID}, |
415 |
61 |
Args = [JID], |
416 |
61 |
ParamsWithLegacyArgs = ejabberd_hooks:add_args(Params, Args), |
417 |
61 |
run_hook_for_host_type(unacknowledged_message, HostType, Acc, ParamsWithLegacyArgs). |
418 |
|
|
419 |
|
%%% @doc The `unregister_command' hook is called when a command |
420 |
|
%%% is unregistered from `mongoose_commands'. |
421 |
|
-spec unregister_command(Command) -> Result when |
422 |
|
Command :: mongoose_commands:t(), |
423 |
|
Result :: drop. |
424 |
|
unregister_command(Command) -> |
425 |
8551 |
run_global_hook(unregister_command, Command, []). |
426 |
|
|
427 |
|
%%% @doc The `unregister_subhost' hook is called when a component |
428 |
|
%%% is unregistered from ejabberd_router. |
429 |
|
-spec unregister_subhost(LDomain) -> Result when |
430 |
|
LDomain :: binary(), |
431 |
|
Result :: any(). |
432 |
|
unregister_subhost(LDomain) -> |
433 |
171 |
run_global_hook(unregister_subhost, ok, [LDomain]). |
434 |
|
|
435 |
|
-spec user_available_hook(HostType, Acc, JID) -> Result when |
436 |
|
HostType :: binary(), |
437 |
|
Acc :: mongoose_acc:t(), |
438 |
|
JID :: jid:jid(), |
439 |
|
Result :: mongoose_acc:t(). |
440 |
|
user_available_hook(HostType, Acc, JID) -> |
441 |
2529 |
run_hook_for_host_type(user_available_hook, HostType, Acc, [JID]). |
442 |
|
|
443 |
|
%%% @doc The `user_ping_response' hook is called when a user responds to a ping. |
444 |
|
-spec user_ping_response(HostType, Acc, JID, Response, TDelta) -> Result when |
445 |
|
HostType :: mongooseim:host_type(), |
446 |
|
Acc :: mongoose_acc:t(), |
447 |
|
JID :: jid:jid(), |
448 |
|
Response :: timeout | jlib:iq(), |
449 |
|
TDelta :: non_neg_integer(), |
450 |
|
Result :: mongoose_acc:t(). |
451 |
|
user_ping_response(HostType, Acc, JID, Response, TDelta) -> |
452 |
12 |
Params = #{jid => JID, response => Response, time_delta => TDelta}, |
453 |
12 |
Args = [HostType, JID, Response, TDelta], |
454 |
12 |
ParamsWithLegacyArgs = ejabberd_hooks:add_args(Params, Args), |
455 |
12 |
run_hook_for_host_type(user_ping_response, HostType, Acc, ParamsWithLegacyArgs). |
456 |
|
|
457 |
|
%%% @doc The `user_ping_timeout' hook is called when there is a timeout |
458 |
|
%%% when waiting for a ping response from a user. |
459 |
|
-spec user_ping_timeout(HostType, JID) -> Result when |
460 |
|
HostType :: mongooseim:host_type(), |
461 |
|
JID :: jid:jid(), |
462 |
|
Result :: any(). |
463 |
|
user_ping_timeout(HostType, JID) -> |
464 |
2 |
run_hook_for_host_type(user_ping_timeout, HostType, ok, [JID]). |
465 |
|
|
466 |
|
-spec user_receive_packet(HostType, Acc, JID, From, To, El) -> Result when |
467 |
|
HostType :: binary(), |
468 |
|
Acc :: mongoose_acc:t(), |
469 |
|
JID :: jid:jid(), |
470 |
|
From :: jid:jid(), |
471 |
|
To :: jid:jid(), |
472 |
|
El :: exml:element(), |
473 |
|
Result :: mongoose_acc:t(). |
474 |
|
user_receive_packet(HostType, Acc, JID, From, To, El) -> |
475 |
8528 |
run_hook_for_host_type(user_receive_packet, HostType, Acc, [JID, From, To, El]). |
476 |
|
|
477 |
|
-spec user_sent_keep_alive(HostType, JID) -> Result when |
478 |
|
HostType :: binary(), |
479 |
|
JID :: jid:jid(), |
480 |
|
Result :: any(). |
481 |
|
user_sent_keep_alive(HostType, JID) -> |
482 |
7 |
run_hook_for_host_type(user_sent_keep_alive, HostType, ok, [JID]). |
483 |
|
|
484 |
|
%%% @doc A hook called when a user sends an XMPP stanza. |
485 |
|
%%% The hook's handler is expected to accept four parameters: |
486 |
|
%%% `Acc', `From', `To' and `Packet' |
487 |
|
%%% The arguments and the return value types correspond to the following spec. |
488 |
|
-spec user_send_packet(Acc, From, To, Packet) -> Result when |
489 |
|
Acc :: mongoose_acc:t(), |
490 |
|
From :: jid:jid(), |
491 |
|
To :: jid:jid(), |
492 |
|
Packet :: exml:element(), |
493 |
|
Result :: mongoose_acc:t(). |
494 |
|
user_send_packet(Acc, From, To, Packet) -> |
495 |
6394 |
HostType = mongoose_acc:host_type(Acc), |
496 |
6394 |
run_hook_for_host_type(user_send_packet, HostType, Acc, [From, To, Packet]). |
497 |
|
|
498 |
|
%%% @doc The `vcard_set' hook is called to inform that the vcard |
499 |
|
%%% has been set in mod_vcard backend. |
500 |
|
-spec vcard_set(HostType, Server, LUser, VCard) -> Result when |
501 |
|
HostType :: mongooseim:host_type(), |
502 |
|
Server :: jid:server(), |
503 |
|
LUser :: jid:luser(), |
504 |
|
VCard :: exml:element(), |
505 |
|
Result :: any(). |
506 |
|
vcard_set(HostType, Server, LUser, VCard) -> |
507 |
:-( |
run_hook_for_host_type(vcard_set, HostType, ok, [HostType, LUser, Server, VCard]). |
508 |
|
|
509 |
|
-spec xmpp_send_element(HostType, Acc, El) -> Result when |
510 |
|
HostType :: binary(), |
511 |
|
Acc :: mongoose_acc:t(), |
512 |
|
El :: exml:element(), |
513 |
|
Result :: mongoose_acc:t(). |
514 |
|
xmpp_send_element(HostType, Acc, El) -> |
515 |
23297 |
run_hook_for_host_type(xmpp_send_element, HostType, Acc, [El]). |
516 |
|
|
517 |
|
%%% @doc The `xmpp_stanza_dropped' hook is called to inform that |
518 |
|
%%% an xmpp stanza has been dropped. |
519 |
|
-spec xmpp_stanza_dropped(Acc, From, To, Packet) -> Result when |
520 |
|
Acc :: mongoose_acc:t(), |
521 |
|
From :: jid:jid(), |
522 |
|
To :: jid:jid(), |
523 |
|
Packet :: exml:element(), |
524 |
|
Result :: any(). |
525 |
|
xmpp_stanza_dropped(Acc, From, To, Packet) -> |
526 |
43 |
HostType = mongoose_acc:host_type(Acc), |
527 |
43 |
run_hook_for_host_type(xmpp_stanza_dropped, HostType, Acc, [From, To, Packet]). |
528 |
|
|
529 |
|
%% C2S related hooks |
530 |
|
|
531 |
|
-spec c2s_broadcast_recipients(State, Type, From, Packet) -> Result when |
532 |
|
State :: ejabberd_c2s:state(), |
533 |
|
Type :: {atom(), any()}, |
534 |
|
From :: jid:jid(), |
535 |
|
Packet :: exml:element(), |
536 |
|
Result :: [jid:simple_jid()]. |
537 |
|
c2s_broadcast_recipients(State, Type, From, Packet) -> |
538 |
10 |
HostType = ejabberd_c2s_state:host_type(State), |
539 |
10 |
run_hook_for_host_type(c2s_broadcast_recipients, HostType, [], |
540 |
|
[State, Type, From, Packet]). |
541 |
|
|
542 |
|
-spec c2s_filter_packet(State, Feature, To, Packet) -> Result when |
543 |
|
State :: ejabberd_c2s:state(), |
544 |
|
Feature :: {atom(), binary()}, |
545 |
|
To :: jid:jid(), |
546 |
|
Packet :: exml:element(), |
547 |
|
Result :: boolean(). |
548 |
|
c2s_filter_packet(State, Feature, To, Packet) -> |
549 |
4 |
HostType = ejabberd_c2s_state:host_type(State), |
550 |
4 |
run_hook_for_host_type(c2s_filter_packet, HostType, true, |
551 |
|
[State, Feature, To, Packet]). |
552 |
|
|
553 |
|
-spec c2s_preprocessing_hook(HostType, Acc, State) -> Result when |
554 |
|
HostType :: mongooseim:host_type(), |
555 |
|
Acc :: mongoose_acc:t(), |
556 |
|
State :: ejabberd_c2s:state(), |
557 |
|
Result :: mongoose_acc:t(). |
558 |
|
c2s_preprocessing_hook(HostType, Acc, State) -> |
559 |
6676 |
run_hook_for_host_type(c2s_preprocessing_hook, HostType, Acc, [State]). |
560 |
|
|
561 |
|
-spec c2s_presence_in(State, From, To, Packet) -> Result when |
562 |
|
State :: ejabberd_c2s:state(), |
563 |
|
From :: jid:jid(), |
564 |
|
To :: jid:jid(), |
565 |
|
Packet :: exml:element(), |
566 |
|
Result :: ejabberd_c2s:state(). |
567 |
|
c2s_presence_in(State, From, To, Packet) -> |
568 |
6582 |
HostType = ejabberd_c2s_state:host_type(State), |
569 |
6582 |
run_hook_for_host_type(c2s_presence_in, HostType, State, [From, To, Packet]). |
570 |
|
|
571 |
|
-spec c2s_stream_features(HostType, LServer) -> Result when |
572 |
|
HostType :: mongooseim:host_type(), |
573 |
|
LServer :: jid:lserver(), |
574 |
|
Result :: [exml:element()]. |
575 |
|
c2s_stream_features(HostType, LServer) -> |
576 |
5893 |
run_hook_for_host_type(c2s_stream_features, HostType, [], [HostType, LServer]). |
577 |
|
|
578 |
|
-spec c2s_unauthenticated_iq(HostType, Server, IQ, IP) -> Result when |
579 |
|
HostType :: mongooseim:host_type(), |
580 |
|
Server :: jid:server(), |
581 |
|
IQ :: jlib:iq(), |
582 |
|
IP :: {inet:ip_address(), inet:port_number()} | undefined, |
583 |
|
Result :: exml:element() | empty. |
584 |
|
c2s_unauthenticated_iq(HostType, Server, IQ, IP) -> |
585 |
382 |
run_hook_for_host_type(c2s_unauthenticated_iq, HostType, empty, [HostType, Server, IQ, IP]). |
586 |
|
|
587 |
|
-spec c2s_update_presence(HostType, Acc) -> Result when |
588 |
|
HostType :: mongooseim:host_type(), |
589 |
|
Acc :: mongoose_acc:t(), |
590 |
|
Result :: mongoose_acc:t(). |
591 |
|
c2s_update_presence(HostType, Acc) -> |
592 |
3088 |
run_hook_for_host_type(c2s_update_presence, HostType, Acc, []). |
593 |
|
|
594 |
|
-spec check_bl_c2s(IP) -> Result when |
595 |
|
IP :: inet:ip_address(), |
596 |
|
Result :: boolean(). |
597 |
|
check_bl_c2s(IP) -> |
598 |
4041 |
run_global_hook(check_bl_c2s, false, [IP]). |
599 |
|
|
600 |
|
-spec forbidden_session_hook(HostType, Acc, JID) -> Result when |
601 |
|
HostType :: mongooseim:host_type(), |
602 |
|
Acc :: mongoose_acc:t(), |
603 |
|
JID :: jid:jid(), |
604 |
|
Result :: mongoose_acc:t(). |
605 |
|
forbidden_session_hook(HostType, Acc, JID) -> |
606 |
1 |
run_hook_for_host_type(forbidden_session_hook, HostType, Acc, [JID]). |
607 |
|
|
608 |
|
-spec session_opening_allowed_for_user(HostType, JID) -> Result when |
609 |
|
HostType :: mongooseim:host_type(), |
610 |
|
JID :: jid:jid(), |
611 |
|
Result :: allow | any(). %% anything else than 'allow' is interpreted |
612 |
|
%% as not allowed |
613 |
|
session_opening_allowed_for_user(HostType, JID) -> |
614 |
2704 |
run_hook_for_host_type(session_opening_allowed_for_user, HostType, allow, [JID]). |
615 |
|
|
616 |
|
%% Privacy related hooks |
617 |
|
|
618 |
|
-spec privacy_check_packet(Acc, JID, PrivacyList, |
619 |
|
FromToNameType, Dir) -> Result when |
620 |
|
Acc :: mongoose_acc:t(), JID :: jid:jid(), |
621 |
|
PrivacyList :: mongoose_privacy:userlist(), |
622 |
|
FromToNameType :: {jid:jid(), jid:jid(), binary(), binary()}, |
623 |
|
Dir :: in | out, |
624 |
|
Result :: mongoose_acc:t(). |
625 |
|
privacy_check_packet(Acc, JID, PrivacyList, FromToNameType, Dir) -> |
626 |
21289 |
HostType = mongoose_acc:host_type(Acc), |
627 |
21289 |
AccWithRes = mongoose_acc:set(hook, result, allow, Acc), |
628 |
21289 |
run_hook_for_host_type(privacy_check_packet, HostType, AccWithRes, |
629 |
|
[JID, PrivacyList, FromToNameType, Dir]). |
630 |
|
|
631 |
|
-spec privacy_get_user_list(HostType, JID) -> Result when |
632 |
|
HostType :: binary(), |
633 |
|
JID :: jid:jid(), |
634 |
|
Result :: mongoose_privacy:userlist(). |
635 |
|
privacy_get_user_list(HostType, JID) -> |
636 |
3553 |
run_hook_for_host_type(privacy_get_user_list, HostType, #userlist{}, [HostType, JID]). |
637 |
|
|
638 |
|
-spec privacy_iq_get(HostType, Acc, From, To, IQ, PrivList) -> Result when |
639 |
|
HostType :: binary(), |
640 |
|
Acc :: mongoose_acc:t(), |
641 |
|
From :: jid:jid(), |
642 |
|
To :: jid:jid(), |
643 |
|
IQ :: jlib:iq(), |
644 |
|
PrivList :: mongoose_privacy:userlist(), |
645 |
|
Result :: mongoose_acc:t(). |
646 |
|
privacy_iq_get(HostType, Acc, From, To, IQ, PrivList) -> |
647 |
66 |
run_hook_for_host_type(privacy_iq_get, HostType, Acc, [From, To, IQ, PrivList]). |
648 |
|
|
649 |
|
-spec privacy_iq_set(HostType, Acc, From, To, IQ) -> Result when |
650 |
|
HostType :: binary(), |
651 |
|
Acc :: mongoose_acc:t(), |
652 |
|
From :: jid:jid(), |
653 |
|
To :: jid:jid(), |
654 |
|
IQ :: jlib:iq(), |
655 |
|
Result :: mongoose_acc:t(). |
656 |
|
privacy_iq_set(HostType, Acc, From, To, IQ) -> |
657 |
144 |
run_hook_for_host_type(privacy_iq_set, HostType, Acc, [From, To, IQ]). |
658 |
|
|
659 |
|
-spec privacy_updated_list(HostType, OldList, NewList) -> Result when |
660 |
|
HostType :: binary(), |
661 |
|
OldList :: mongoose_privacy:userlist(), |
662 |
|
NewList :: mongoose_privacy:userlist(), |
663 |
|
Result :: false | mongoose_privacy:userlist(). |
664 |
|
privacy_updated_list(HostType, OldList, NewList) -> |
665 |
53 |
run_hook_for_host_type(privacy_updated_list, HostType, false, [OldList, NewList]). |
666 |
|
|
667 |
|
%% Session management related hooks |
668 |
|
|
669 |
|
-spec offline_groupchat_message_hook(Acc, From, To, Packet) -> Result when |
670 |
|
Acc :: mongoose_acc:t(), |
671 |
|
From :: jid:jid(), |
672 |
|
To :: jid:jid(), |
673 |
|
Packet :: exml:element(), |
674 |
|
Result :: mongoose_acc:t(). |
675 |
|
offline_groupchat_message_hook(Acc, From, To, Packet) -> |
676 |
147 |
HostType = mongoose_acc:host_type(Acc), |
677 |
147 |
run_hook_for_host_type(offline_groupchat_message_hook, HostType, Acc, |
678 |
|
[From, To, Packet]). |
679 |
|
|
680 |
|
-spec offline_message_hook(Acc, From, To, Packet) -> Result when |
681 |
|
Acc :: mongoose_acc:t(), |
682 |
|
From :: jid:jid(), |
683 |
|
To :: jid:jid(), |
684 |
|
Packet :: exml:element(), |
685 |
|
Result :: mongoose_acc:t(). |
686 |
|
offline_message_hook(Acc, From, To, Packet) -> |
687 |
219 |
HostType = mongoose_acc:host_type(Acc), |
688 |
219 |
run_hook_for_host_type(offline_message_hook, HostType, Acc, [From, To, Packet]). |
689 |
|
|
690 |
|
-spec set_presence_hook(Acc, JID, Presence) -> Result when |
691 |
|
Acc :: mongoose_acc:t(), |
692 |
|
JID :: jid:jid(), |
693 |
|
Presence :: any(), |
694 |
|
Result :: mongoose_acc:t(). |
695 |
|
set_presence_hook(Acc, JID, Presence) -> |
696 |
2553 |
#jid{luser = LUser, lserver = LServer, lresource = LResource} = JID, |
697 |
2553 |
HostType = mongoose_acc:host_type(Acc), |
698 |
2553 |
run_hook_for_host_type(set_presence_hook, HostType, Acc, |
699 |
|
[LUser, LServer, LResource, Presence]). |
700 |
|
|
701 |
|
-spec sm_broadcast(Acc, From, To, Broadcast, SessionCount) -> Result when |
702 |
|
Acc :: mongoose_acc:t(), |
703 |
|
From :: jid:jid(), |
704 |
|
To :: jid:jid(), |
705 |
|
Broadcast :: ejabberd_c2s:broadcast(), |
706 |
|
SessionCount :: non_neg_integer(), |
707 |
|
Result :: mongoose_acc:t(). |
708 |
|
sm_broadcast(Acc, From, To, Broadcast, SessionCount) -> |
709 |
728 |
HostType = mongoose_acc:host_type(Acc), |
710 |
728 |
run_hook_for_host_type(sm_broadcast, HostType, Acc, |
711 |
|
[From, To, Broadcast, SessionCount]). |
712 |
|
|
713 |
|
-spec sm_filter_offline_message(HostType, From, To, Packet) -> Result when |
714 |
|
HostType :: binary(), |
715 |
|
From :: jid:jid(), |
716 |
|
To :: jid:jid(), |
717 |
|
Packet :: exml:element(), |
718 |
|
Result :: boolean(). |
719 |
|
sm_filter_offline_message(HostType, From, To, Packet) -> |
720 |
301 |
run_hook_for_host_type(sm_filter_offline_message, HostType, false, |
721 |
|
[From, To, Packet]). |
722 |
|
|
723 |
|
-spec sm_register_connection_hook(HostType, SID, JID, Info) -> Result when |
724 |
|
HostType :: binary(), |
725 |
|
SID :: 'undefined' | ejabberd_sm:sid(), |
726 |
|
JID :: jid:jid(), |
727 |
|
Info :: ejabberd_sm:info(), |
728 |
|
Result :: ok. |
729 |
|
sm_register_connection_hook(HostType, SID, JID, Info) -> |
730 |
2717 |
run_hook_for_host_type(sm_register_connection_hook, HostType, ok, |
731 |
|
[HostType, SID, JID, Info]). |
732 |
|
|
733 |
|
-spec sm_remove_connection_hook(Acc, SID, JID, Info, Reason) -> Result when |
734 |
|
Acc :: mongoose_acc:t(), |
735 |
|
SID :: 'undefined' | ejabberd_sm:sid(), |
736 |
|
JID :: jid:jid(), |
737 |
|
Info :: ejabberd_sm:info(), |
738 |
|
Reason :: ejabberd_sm:close_reason(), |
739 |
|
Result :: mongoose_acc:t(). |
740 |
|
sm_remove_connection_hook(Acc, SID, JID, Info, Reason) -> |
741 |
2714 |
HostType = mongoose_acc:host_type(Acc), |
742 |
2714 |
run_hook_for_host_type(sm_remove_connection_hook, HostType, Acc, |
743 |
|
[SID, JID, Info, Reason]). |
744 |
|
|
745 |
|
-spec unset_presence_hook(Acc, JID, Status) -> Result when |
746 |
|
Acc :: mongoose_acc:t(), |
747 |
|
JID:: jid:jid(), |
748 |
|
Status :: binary(), |
749 |
|
Result :: mongoose_acc:t(). |
750 |
|
unset_presence_hook(Acc, JID, Status) -> |
751 |
2536 |
#jid{luser = LUser, lserver = LServer, lresource = LResource} = JID, |
752 |
2536 |
HostType = mongoose_acc:host_type(Acc), |
753 |
2536 |
run_hook_for_host_type(unset_presence_hook, HostType, Acc, |
754 |
|
[LUser, LServer, LResource, Status]). |
755 |
|
|
756 |
|
-spec xmpp_bounce_message(Acc) -> Result when |
757 |
|
Acc :: mongoose_acc:t(), |
758 |
|
Result :: mongoose_acc:t(). |
759 |
|
xmpp_bounce_message(Acc) -> |
760 |
29 |
HostType = mongoose_acc:host_type(Acc), |
761 |
29 |
run_hook_for_host_type(xmpp_bounce_message, HostType, Acc, []). |
762 |
|
|
763 |
|
%% Roster related hooks |
764 |
|
|
765 |
|
%%% @doc The `roster_get' hook is called to extract a user's roster. |
766 |
|
-spec roster_get(Acc, JID) -> Result when |
767 |
|
Acc :: mongoose_acc:t(), |
768 |
|
JID :: jid:jid(), |
769 |
|
Result :: mongoose_acc:t(). |
770 |
|
roster_get(Acc, JID) -> |
771 |
109 |
HostType = mongoose_acc:host_type(Acc), |
772 |
109 |
run_hook_for_host_type(roster_get, HostType, Acc, [JID]). |
773 |
|
|
774 |
|
%%% @doc The `roster_groups' hook is called to extract roster groups. |
775 |
|
-spec roster_groups(LServer) -> Result when |
776 |
|
LServer :: jid:lserver(), |
777 |
|
Result :: list(). |
778 |
|
roster_groups(LServer) -> |
779 |
7 |
run_hook_for_host_type(roster_groups, LServer, [], [LServer]). |
780 |
|
|
781 |
|
%%% @doc The `roster_get_jid_info' hook is called to determine the |
782 |
|
%%% subscription state between a given pair of users. |
783 |
|
%%% The hook handlers need to expect following arguments: |
784 |
|
%%% * Acc with an initial value of {none, []}, |
785 |
|
%%% * ToJID, a stringprepped roster's owner's jid |
786 |
|
%%% * RemoteBareJID, a bare JID of the other user. |
787 |
|
%%% |
788 |
|
%%% The arguments and the return value types correspond to the following spec. |
789 |
|
-spec roster_get_jid_info(HostType, ToJID, RemoteJID) -> Result when |
790 |
|
HostType :: mongooseim:host_type(), |
791 |
|
ToJID :: jid:jid(), |
792 |
|
RemoteJID :: jid:jid() | jid:simple_jid(), |
793 |
|
Result :: {mod_roster:subscription_state(), [binary()]}. |
794 |
|
roster_get_jid_info(HostType, ToJID, RemBareJID) -> |
795 |
67 |
run_hook_for_host_type(roster_get_jid_info, HostType, {none, []}, |
796 |
|
[HostType, ToJID, RemBareJID]). |
797 |
|
|
798 |
|
%%% @doc The `roster_get_subscription_lists' hook is called to extract |
799 |
|
%%% user's subscription list. |
800 |
|
-spec roster_get_subscription_lists(HostType, Acc, JID) -> Result when |
801 |
|
HostType :: binary(), |
802 |
|
Acc ::mongoose_acc:t(), |
803 |
|
JID :: jid:jid(), |
804 |
|
Result :: mongoose_acc:t(). |
805 |
|
roster_get_subscription_lists(HostType, Acc, JID) -> |
806 |
5233 |
run_hook_for_host_type(roster_get_subscription_lists, HostType, Acc, |
807 |
|
[jid:to_bare(JID)]). |
808 |
|
|
809 |
|
%%% @doc The `roster_get_versioning_feature' hook is |
810 |
|
%%% called to determine if roster versioning is enabled. |
811 |
|
-spec roster_get_versioning_feature(HostType) -> Result when |
812 |
|
HostType :: binary(), |
813 |
|
Result :: [exml:element()]. |
814 |
|
roster_get_versioning_feature(HostType) -> |
815 |
2738 |
run_hook_for_host_type(roster_get_versioning_feature, HostType, [], [HostType]). |
816 |
|
|
817 |
|
%%% @doc The `roster_in_subscription' hook is called to determine |
818 |
|
%%% if a subscription presence is routed to a user. |
819 |
|
-spec roster_in_subscription(Acc, To, From, Type, Reason) -> Result when |
820 |
|
Acc :: mongoose_acc:t(), |
821 |
|
To :: jid:jid(), |
822 |
|
From :: jid:jid(), |
823 |
|
Type :: mod_roster:sub_presence(), |
824 |
|
Reason :: any(), |
825 |
|
Result :: mongoose_acc:t(). |
826 |
|
roster_in_subscription(Acc, To, From, Type, Reason) -> |
827 |
615 |
HostType = mongoose_acc:host_type(Acc), |
828 |
615 |
run_hook_for_host_type(roster_in_subscription, HostType, Acc, |
829 |
|
[jid:to_bare(To), From, Type, Reason]). |
830 |
|
|
831 |
|
%%% @doc The `roster_out_subscription' hook is called |
832 |
|
%%% when a user sends out subscription. |
833 |
|
-spec roster_out_subscription(Acc, From, To, Type) -> Result when |
834 |
|
Acc :: mongoose_acc:t(), |
835 |
|
From :: jid:jid(), |
836 |
|
To :: jid:jid(), |
837 |
|
Type :: mod_roster:sub_presence(), |
838 |
|
Result :: mongoose_acc:t(). |
839 |
|
roster_out_subscription(Acc, From, To, Type) -> |
840 |
146 |
HostType = mongoose_acc:host_type(Acc), |
841 |
146 |
run_hook_for_host_type(roster_out_subscription, HostType, Acc, |
842 |
|
[jid:to_bare(From), To, Type]). |
843 |
|
|
844 |
|
%%% @doc The `roster_process_item' hook is called when a user's roster is set. |
845 |
|
-spec roster_process_item(HostType, LServer, Item) -> Result when |
846 |
|
HostType :: mongooseim:host_type(), |
847 |
|
LServer :: jid:lserver(), |
848 |
|
Item :: mod_roster:roster(), |
849 |
|
Result :: mod_roster:roster(). |
850 |
|
roster_process_item(HostType, LServer, Item) -> |
851 |
101 |
run_hook_for_host_type(roster_process_item, HostType, Item, [LServer]). |
852 |
|
|
853 |
|
%%% @doc The `roster_push' hook is called when a roster item is |
854 |
|
%%% being pushed and roster versioning is not enabled. |
855 |
|
-spec roster_push(HostType, From, Item) -> Result when |
856 |
|
HostType :: mongooseim:host_type(), |
857 |
|
From :: jid:jid(), |
858 |
|
Item :: mod_roster:roster(), |
859 |
|
Result :: any(). |
860 |
|
roster_push(HostType, From, Item) -> |
861 |
342 |
run_hook_for_host_type(roster_push, HostType, ok, [HostType, From, Item]). |
862 |
|
|
863 |
|
%%% @doc The `roster_set' hook is called when a user's roster is set through an IQ. |
864 |
|
-spec roster_set(HostType, From, To, SubEl) -> Result when |
865 |
|
HostType :: mongooseim:host_type(), |
866 |
|
From :: jid:jid(), |
867 |
|
To :: jid:jid(), |
868 |
|
SubEl :: exml:element(), |
869 |
|
Result :: any(). |
870 |
|
roster_set(HostType, From, To, SubEl) -> |
871 |
37 |
run_hook_for_host_type(roster_set, HostType, ok, [From, To, SubEl]). |
872 |
|
|
873 |
|
%% MUC related hooks |
874 |
|
|
875 |
|
%%% @doc The `is_muc_room_owner' hooks is called to determine |
876 |
|
%%% if a given user is a room's owner. |
877 |
|
%%% |
878 |
|
%%% The hook's handler needs to expect the following arguments: |
879 |
|
%%% `Acc', `Room', `User'. |
880 |
|
%%% The arguments and the return value types correspond to the |
881 |
|
%%% following spec. |
882 |
|
-spec is_muc_room_owner(HostType, Acc, Room, User) -> Result when |
883 |
|
HostType :: mongooseim:host_type(), |
884 |
|
Acc :: mongoose_acc:t(), |
885 |
|
Room :: jid:jid(), |
886 |
|
User :: jid:jid(), |
887 |
|
Result :: boolean(). |
888 |
|
is_muc_room_owner(HostType, Acc, Room, User) -> |
889 |
:-( |
run_hook_for_host_type(is_muc_room_owner, HostType, false, [Acc, Room, User]). |
890 |
|
|
891 |
|
%%% @doc The `can_access_identity' hook is called to determine if |
892 |
|
%%% a given user can see the real identity of the people in a room. |
893 |
|
-spec can_access_identity(HostType, Room, User) -> Result when |
894 |
|
HostType :: mongooseim:host_type(), |
895 |
|
Room :: jid:jid(), |
896 |
|
User :: jid:jid(), |
897 |
|
Result :: boolean(). |
898 |
|
can_access_identity(HostType, Room, User) -> |
899 |
:-( |
run_hook_for_host_type(can_access_identity, HostType, false, [HostType, Room, User]). |
900 |
|
|
901 |
|
%%% @doc The `can_access_room' hook is called to determine |
902 |
|
%%% if a given user can access a room. |
903 |
|
-spec can_access_room(HostType, Acc, Room, User) -> Result when |
904 |
|
HostType :: mongooseim:host_type(), |
905 |
|
Acc :: mongoose_acc:t(), |
906 |
|
Room :: jid:jid(), |
907 |
|
User :: jid:jid(), |
908 |
|
Result :: boolean(). |
909 |
|
can_access_room(HostType, Acc, Room, User) -> |
910 |
:-( |
run_hook_for_host_type(can_access_room, HostType, false, [Acc, Room, User]). |
911 |
|
|
912 |
|
-spec acc_room_affiliations(Acc, Room) -> NewAcc when |
913 |
|
Acc :: mongoose_acc:t(), |
914 |
|
Room :: jid:jid(), |
915 |
|
NewAcc :: mongoose_acc:t(). |
916 |
|
acc_room_affiliations(Acc, Room) -> |
917 |
181 |
HostType = mod_muc_light_utils:acc_to_host_type(Acc), |
918 |
181 |
run_hook_for_host_type(acc_room_affiliations, HostType, Acc, [Room]). |
919 |
|
|
920 |
|
-spec room_exists(HostType, Room) -> Result when |
921 |
|
HostType :: mongooseim:host_type(), |
922 |
|
Room :: jid:jid(), |
923 |
|
Result :: boolean(). |
924 |
|
room_exists(HostType, Room) -> |
925 |
171 |
run_hook_for_host_type(room_exists, HostType, false, [HostType, Room]). |
926 |
|
|
927 |
|
-spec room_new_affiliations(Acc, Room, NewAffs, Version) -> NewAcc when |
928 |
|
Acc :: mongoose_acc:t(), |
929 |
|
Room :: jid:jid(), |
930 |
|
NewAffs :: mod_muc_light:aff_users(), |
931 |
|
Version :: binary(), |
932 |
|
NewAcc :: mongoose_acc:t(). |
933 |
|
room_new_affiliations(Acc, Room, NewAffs, Version) -> |
934 |
72 |
HostType = mod_muc_light_utils:acc_to_host_type(Acc), |
935 |
72 |
run_hook_for_host_type(room_new_affiliations, HostType, Acc, [Room, NewAffs, Version]). |
936 |
|
|
937 |
|
%% MAM related hooks |
938 |
|
|
939 |
|
%%% @doc The `mam_archive_id' hook is called to determine |
940 |
|
%%% the integer id of an archive for a particular user or entity. |
941 |
|
%%% |
942 |
|
%%% If a MAM backend doesn't support or doesn't require archive IDs, |
943 |
|
%%% `undefined' may be returned. |
944 |
|
-spec mam_archive_id(HostType, OwnerJID) -> Result when |
945 |
|
HostType :: mongooseim:host_type(), |
946 |
|
OwnerJID :: jid:jid(), |
947 |
|
Result :: undefined | mod_mam:archive_id(). |
948 |
|
mam_archive_id(HostType, OwnerJID) -> |
949 |
:-( |
run_hook_for_host_type(mam_archive_id, HostType, undefined, [HostType, OwnerJID]). |
950 |
|
|
951 |
|
%%% @doc The `mam_archive_size' hook is called to determine the size |
952 |
|
%%% of the archive for a given JID |
953 |
|
-spec mam_archive_size(HostType, ArchiveID, OwnerJID) -> Result when |
954 |
|
HostType :: mongooseim:host_type(), |
955 |
|
ArchiveID :: undefined | mod_mam:archive_id(), |
956 |
|
OwnerJID :: jid:jid(), |
957 |
|
Result :: integer(). |
958 |
|
mam_archive_size(HostType, ArchiveID, OwnerJID) -> |
959 |
:-( |
run_hook_for_host_type(mam_archive_size, HostType, 0, |
960 |
|
[HostType, ArchiveID, OwnerJID]). |
961 |
|
|
962 |
|
%%% @doc The `mam_get_behaviour' hooks is called to determine if a message |
963 |
|
%%% should be archived or not based on a given pair of JIDs. |
964 |
|
-spec mam_get_behaviour(HookServer, ArchiveID, |
965 |
|
OwnerJID, RemoteJID) -> Result when |
966 |
|
HookServer :: jid:lserver(), |
967 |
|
ArchiveID :: undefined | mod_mam:archive_id(), |
968 |
|
OwnerJID :: jid:jid(), |
969 |
|
RemoteJID :: jid:jid(), |
970 |
|
Result :: mod_mam:archive_behaviour(). |
971 |
|
mam_get_behaviour(HookServer, ArchiveID, OwnerJID, RemoteJID) -> |
972 |
:-( |
run_hook_for_host_type(mam_get_behaviour, HookServer, always, |
973 |
|
[HookServer, ArchiveID, OwnerJID, RemoteJID]). |
974 |
|
|
975 |
|
%%% @doc The `mam_set_prefs' hook is called to set a user's archive preferences. |
976 |
|
%%% |
977 |
|
%%% It's possible to set which JIDs are always or never allowed in the archive |
978 |
|
-spec mam_set_prefs(HookServer, ArchiveId, OwnerJID, |
979 |
|
DefaultMode, AlwaysJIDs, NeverJIDs) -> Result when |
980 |
|
HookServer :: jid:lserver(), |
981 |
|
ArchiveId :: undefined | mod_mam:archive_id(), |
982 |
|
OwnerJID :: jid:jid(), |
983 |
|
DefaultMode :: mod_mam:archive_behaviour(), |
984 |
|
AlwaysJIDs :: [jid:literal_jid()], |
985 |
|
NeverJIDs :: [jid:literel_jid()], |
986 |
|
Result :: any(). |
987 |
|
mam_set_prefs(HookServer, ArchiveID, OwnerJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> |
988 |
:-( |
run_hook_for_host_type(mam_set_prefs, HookServer, {error, not_implemented}, |
989 |
|
[HookServer, ArchiveID, OwnerJID, |
990 |
|
DefaultMode, AlwaysJIDs, NeverJIDs]). |
991 |
|
|
992 |
|
%%% @doc The `mam_get_prefs' hook is called to read |
993 |
|
%%% the archive settings for a given user. |
994 |
|
-spec mam_get_prefs(HookServer, DefaultMode, ArchiveID, OwnerJID) -> Result when |
995 |
|
HookServer :: jid:lserver(), |
996 |
|
DefaultMode :: mod_mam:archive_behaviour(), |
997 |
|
ArchiveID :: undefined | mod_mam:archive_id(), |
998 |
|
OwnerJID :: jid:jid(), |
999 |
|
Result :: mod_mam:preference() | {error, Reason :: term()}. |
1000 |
|
mam_get_prefs(HookServer, DefaultMode, ArchiveID, OwnerJID) -> |
1001 |
:-( |
InitialAccValue = {DefaultMode, [], []}, %% mod_mam:preference() type |
1002 |
:-( |
run_hook_for_host_type(mam_get_prefs, HookServer, InitialAccValue, |
1003 |
|
[HookServer, ArchiveID, OwnerJID]). |
1004 |
|
|
1005 |
|
%%% @doc The `mam_remove_archive' hook is called in order to |
1006 |
|
%%% remove the entire archive for a particular user. |
1007 |
|
-spec mam_remove_archive(HookServer, ArchiveID, OwnerJID) -> any() when |
1008 |
|
HookServer :: jid:lserver(), |
1009 |
|
ArchiveID :: undefined | mod_mam:archive_id(), |
1010 |
|
OwnerJID :: jid:jid(). |
1011 |
|
mam_remove_archive(HookServer, ArchiveID, OwnerJID) -> |
1012 |
:-( |
run_hook_for_host_type(mam_remove_archive, HookServer, ok, |
1013 |
|
[HookServer, ArchiveID, OwnerJID]). |
1014 |
|
|
1015 |
|
%%% @doc The `mam_lookup_messages' hook is to retrieve |
1016 |
|
%%% archived messages for given search parameters. |
1017 |
|
-spec mam_lookup_messages(HookServer, Params) -> Result when |
1018 |
|
HookServer :: jid:lserver(), |
1019 |
|
Params :: map(), |
1020 |
|
Result :: {ok, mod_mam:lookup_result()}. |
1021 |
|
mam_lookup_messages(HookServer, Params) -> |
1022 |
:-( |
InitialLookupValue = {0, 0, []}, %% mod_mam:lookup_result() type |
1023 |
:-( |
run_hook_for_host_type(mam_lookup_messages, HookServer, {ok, InitialLookupValue}, |
1024 |
|
[HookServer, Params]). |
1025 |
|
|
1026 |
|
%%% @doc The `mam_archive_message' hook is called in order |
1027 |
|
%%% to store the message in the archive. |
1028 |
|
-spec mam_archive_message(HookServer, Params) -> |
1029 |
|
Result when |
1030 |
|
HookServer :: jid:lserver(), |
1031 |
|
Params :: mod_mam:archive_message_params(), |
1032 |
|
Result :: ok | {error, timeout}. |
1033 |
|
mam_archive_message(HookServer, Params) -> |
1034 |
:-( |
run_hook_for_host_type(mam_archive_message, HookServer, ok, [HookServer, Params]). |
1035 |
|
|
1036 |
|
%%% @doc The `mam_flush_messages' hook is run after the async bulk write |
1037 |
|
%%% happens for messages despite the result of the write. |
1038 |
|
-spec mam_flush_messages(HookServer :: jid:lserver(), |
1039 |
|
MessageCount :: integer()) -> ok. |
1040 |
|
mam_flush_messages(HookServer, MessageCount) -> |
1041 |
:-( |
run_hook_for_host_type(mam_flush_messages, HookServer, ok, |
1042 |
|
[HookServer, MessageCount]). |
1043 |
|
|
1044 |
|
%% @doc Waits until all pending messages are written |
1045 |
|
-spec mam_archive_sync(HostType :: mongooseim:host_type()) -> ok. |
1046 |
|
mam_archive_sync(HostType) -> |
1047 |
:-( |
run_hook_for_host_type(mam_archive_sync, HostType, ok, [HostType]). |
1048 |
|
|
1049 |
|
%% @doc Notifies of a message retraction |
1050 |
|
-spec mam_retraction(mongooseim:host_type(), |
1051 |
|
mod_mam_utils:retraction_info(), |
1052 |
|
mod_mam:archive_message_params()) -> |
1053 |
|
mod_mam_utils:retraction_info(). |
1054 |
|
mam_retraction(HostType, RetractionInfo, Env) -> |
1055 |
:-( |
run_fold(mam_retraction, HostType, RetractionInfo, Env). |
1056 |
|
|
1057 |
|
%% MAM MUC related hooks |
1058 |
|
|
1059 |
|
%%% @doc The `mam_muc_archive_id' hook is called to determine the |
1060 |
|
%%% archive ID for a particular room. |
1061 |
|
%%% The hook handler is expected to accept the following arguments: |
1062 |
|
%%% * Acc with initial value `undefined', |
1063 |
|
%%% * Host as passed in `HooksServer' variable, |
1064 |
|
%%% * OwnerJID, |
1065 |
|
%%% |
1066 |
|
%%% and return an integer value corresponding to the given owner's archive. |
1067 |
|
%%% |
1068 |
|
%%% If a MAM backend doesn't support or doesn't require archive IDs, |
1069 |
|
%%% `undefined' may be returned. |
1070 |
|
-spec mam_muc_archive_id(HookServer, OwnerJID) -> Result when |
1071 |
|
HookServer :: jid:lserver(), |
1072 |
|
OwnerJID :: jid:jid(), |
1073 |
|
Result :: undefined | mod_mam:archive_id(). |
1074 |
|
mam_muc_archive_id(HookServer, OwnerJID) -> |
1075 |
:-( |
run_hook_for_host_type(mam_muc_archive_id, HookServer, undefined, |
1076 |
|
[HookServer, OwnerJID]). |
1077 |
|
|
1078 |
|
%%% @doc The `mam_muc_archive_size' hook is called to determine |
1079 |
|
%%% the archive size for a given room. |
1080 |
|
-spec mam_muc_archive_size(HostType, ArchiveID, RoomJID) -> Result when |
1081 |
|
HostType :: mongooseim:host_type(), |
1082 |
|
ArchiveID :: undefined | mod_mam:archive_id(), |
1083 |
|
RoomJID :: jid:jid(), |
1084 |
|
Result :: integer(). |
1085 |
|
mam_muc_archive_size(HostType, ArchiveID, RoomJID) -> |
1086 |
:-( |
run_hook_for_host_type(mam_muc_archive_size, HostType, 0, |
1087 |
|
[HostType, ArchiveID, RoomJID]). |
1088 |
|
|
1089 |
|
%%% @doc The `mam_muc_get_behaviour' hooks is called to determine if a message should |
1090 |
|
%%% be archived or not based on the given room and user JIDs. |
1091 |
|
-spec mam_muc_get_behaviour(HostType, ArchiveID, |
1092 |
|
RoomJID, RemoteJID) -> Result when |
1093 |
|
HostType :: mongooseim:host_type(), |
1094 |
|
ArchiveID :: undefined | mod_mam:archive_id(), |
1095 |
|
RoomJID :: jid:jid(), |
1096 |
|
RemoteJID :: jid:jid(), |
1097 |
|
Result :: mod_mam:archive_behaviour(). |
1098 |
|
mam_muc_get_behaviour(HostType, ArchiveID, RoomJID, RemoteJID) -> |
1099 |
:-( |
DefaultBehaviour = always, %% mod_mam:archive_behaviour() type |
1100 |
:-( |
run_hook_for_host_type(mam_muc_get_behaviour, HostType, DefaultBehaviour, |
1101 |
|
[HostType, ArchiveID, RoomJID, RemoteJID]). |
1102 |
|
|
1103 |
|
%%% @doc The `mam_muc_set_prefs' hook is called to set a room's archive preferences. |
1104 |
|
%%% |
1105 |
|
%%% It's possible to set which JIDs are always or never allowed in the archive |
1106 |
|
-spec mam_muc_set_prefs(HostType, ArchiveId, RoomJID, |
1107 |
|
DefaultMode, AlwaysJIDs, NeverJIDs) -> Result when |
1108 |
|
HostType :: mongooseim:host_type(), |
1109 |
|
ArchiveId :: undefined | mod_mam:archive_id(), |
1110 |
|
RoomJID :: jid:jid(), |
1111 |
|
DefaultMode :: mod_mam:archive_behaviour(), |
1112 |
|
AlwaysJIDs :: [jid:literal_jid()], |
1113 |
|
NeverJIDs :: [jid:literel_jid()], |
1114 |
|
Result :: any(). |
1115 |
|
mam_muc_set_prefs(HostType, ArchiveID, RoomJID, DefaultMode, AlwaysJIDs, NeverJIDs) -> |
1116 |
:-( |
InitialAcc = {error, not_implemented}, |
1117 |
:-( |
run_hook_for_host_type(mam_muc_set_prefs, HostType, InitialAcc, |
1118 |
|
[HostType, ArchiveID, RoomJID, DefaultMode, |
1119 |
|
AlwaysJIDs, NeverJIDs]). |
1120 |
|
|
1121 |
|
%%% @doc The `mam_muc_get_prefs' hook is called to read |
1122 |
|
%%% the archive settings for a given room. |
1123 |
|
-spec mam_muc_get_prefs(HostType, DefaultMode, ArchiveID, RoomJID) -> Result when |
1124 |
|
HostType :: mongooseim:host_type(), |
1125 |
|
DefaultMode :: mod_mam:archive_behaviour(), |
1126 |
|
ArchiveID :: undefined | mod_mam:archive_id(), |
1127 |
|
RoomJID :: jid:jid(), |
1128 |
|
Result :: mod_mam:preference() | {error, Reason :: term()}. |
1129 |
|
mam_muc_get_prefs(HostType, DefaultMode, ArchiveID, RoomJID) -> |
1130 |
:-( |
InitialAcc = {DefaultMode, [], []}, %% mod_mam:preference() type |
1131 |
:-( |
run_hook_for_host_type(mam_muc_get_prefs, HostType, InitialAcc, |
1132 |
|
[HostType, ArchiveID, RoomJID]). |
1133 |
|
|
1134 |
|
%%% @doc The `mam_muc_remove_archive' hook is called in order to remove the entire |
1135 |
|
%%% archive for a particular user. |
1136 |
|
-spec mam_muc_remove_archive(HostType, ArchiveID, RoomJID) -> any() when |
1137 |
|
HostType :: mongooseim:host_type(), |
1138 |
|
ArchiveID :: undefined | mod_mam:archive_id(), |
1139 |
|
RoomJID :: jid:jid(). |
1140 |
|
mam_muc_remove_archive(HostType, ArchiveID, RoomJID) -> |
1141 |
:-( |
run_hook_for_host_type(mam_muc_remove_archive, HostType, ok, |
1142 |
|
[HostType, ArchiveID, RoomJID]). |
1143 |
|
|
1144 |
|
%%% @doc The `mam_muc_lookup_messages' hook is to retrieve archived |
1145 |
|
%%% MUC messages for any given search parameters. |
1146 |
|
-spec mam_muc_lookup_messages(HostType, Params) -> Result when |
1147 |
|
HostType :: mongooseim:host_type(), |
1148 |
|
Params :: map(), |
1149 |
|
Result :: {ok, mod_mam:lookup_result()}. |
1150 |
|
mam_muc_lookup_messages(HostType, Params) -> |
1151 |
:-( |
InitialLookupValue = {0, 0, []}, %% mod_mam:lookup_result() type |
1152 |
:-( |
run_hook_for_host_type(mam_muc_lookup_messages, HostType, {ok, InitialLookupValue}, |
1153 |
|
[HostType, Params]). |
1154 |
|
|
1155 |
|
%%% @doc The `mam_muc_archive_message' hook is called in order |
1156 |
|
%%% to store the MUC message in the archive. |
1157 |
|
-spec mam_muc_archive_message(HostType, Params) -> Result when |
1158 |
|
HostType :: mongooseim:host_type(), |
1159 |
|
Params :: mod_mam:archive_message_params(), |
1160 |
|
Result :: ok | {error, timeout}. |
1161 |
|
mam_muc_archive_message(HostType, Params) -> |
1162 |
:-( |
run_hook_for_host_type(mam_muc_archive_message, HostType, ok, [HostType, Params]). |
1163 |
|
|
1164 |
|
%%% @doc The `mam_muc_flush_messages' hook is run after the async bulk write |
1165 |
|
%%% happens for MUC messages despite the result of the write. |
1166 |
|
-spec mam_muc_flush_messages(HookServer :: jid:lserver(), |
1167 |
|
MessageCount :: integer()) -> ok. |
1168 |
|
mam_muc_flush_messages(HookServer, MessageCount) -> |
1169 |
:-( |
run_hook_for_host_type(mam_muc_flush_messages, HookServer, ok, |
1170 |
|
[HookServer, MessageCount]). |
1171 |
|
|
1172 |
|
%% @doc Waits until all pending messages are written |
1173 |
|
-spec mam_muc_archive_sync(HostType :: mongooseim:host_type()) -> ok. |
1174 |
|
mam_muc_archive_sync(HostType) -> |
1175 |
:-( |
run_hook_for_host_type(mam_muc_archive_sync, HostType, ok, [HostType]). |
1176 |
|
|
1177 |
|
%% @doc Notifies of a muc message retraction |
1178 |
|
-spec mam_muc_retraction(mongooseim:host_type(), |
1179 |
|
mod_mam_utils:retraction_info(), |
1180 |
|
mod_mam:archive_message_params()) -> |
1181 |
|
mod_mam_utils:retraction_info(). |
1182 |
|
mam_muc_retraction(HostType, RetractionInfo, Env) -> |
1183 |
:-( |
run_fold(mam_muc_retraction, HostType, RetractionInfo, Env). |
1184 |
|
|
1185 |
|
%% GDPR related hooks |
1186 |
|
|
1187 |
|
%%% @doc `get_mam_pm_gdpr_data' hook is called to provide |
1188 |
|
%%% a user's archive for GDPR purposes. |
1189 |
|
-spec get_mam_pm_gdpr_data(HostType, JID) -> Result when |
1190 |
|
HostType :: mongooseim:host_type(), |
1191 |
|
JID :: jid:jid(), |
1192 |
|
Result :: ejabberd_gen_mam_archive:mam_pm_gdpr_data(). |
1193 |
|
get_mam_pm_gdpr_data(HostType, JID) -> |
1194 |
:-( |
run_hook_for_host_type(get_mam_pm_gdpr_data, HostType, [], [HostType, JID]). |
1195 |
|
|
1196 |
|
%%% @doc `get_mam_muc_gdpr_data' hook is called to provide |
1197 |
|
%%% a user's archive for GDPR purposes. |
1198 |
|
-spec get_mam_muc_gdpr_data(HostType, JID) -> Result when |
1199 |
|
HostType :: mongooseim:host_type(), |
1200 |
|
JID :: jid:jid(), |
1201 |
|
Result :: ejabberd_gen_mam_archive:mam_muc_gdpr_data(). |
1202 |
|
get_mam_muc_gdpr_data(HostType, JID) -> |
1203 |
:-( |
run_hook_for_host_type(get_mam_muc_gdpr_data, HostType, [], [HostType, JID]). |
1204 |
|
|
1205 |
|
%%% @doc `get_personal_data' hook is called to retrieve |
1206 |
|
%%% a user's personal data for GDPR purposes. |
1207 |
|
-spec get_personal_data(HostType, JID) -> Result when |
1208 |
|
HostType :: binary(), |
1209 |
|
JID :: jid:jid(), |
1210 |
|
Result :: gdpr:personal_data(). |
1211 |
|
get_personal_data(HostType, JID) -> |
1212 |
33 |
run_hook_for_host_type(get_personal_data, HostType, [], [HostType, JID]). |
1213 |
|
|
1214 |
|
%% S2S related hooks |
1215 |
|
|
1216 |
|
%%% @doc `find_s2s_bridge' hook is called to find a s2s bridge to a foreign protocol |
1217 |
|
%%% when opening a socket to a different XMPP server fails. |
1218 |
|
-spec find_s2s_bridge(Name, Server) -> Result when |
1219 |
|
Name :: any(), |
1220 |
|
Server :: jid:server(), |
1221 |
|
Result :: any(). |
1222 |
|
find_s2s_bridge(Name, Server) -> |
1223 |
6 |
run_global_hook(find_s2s_bridge, undefined, [Name, Server]). |
1224 |
|
|
1225 |
|
%%% @doc `s2s_allow_host' hook is called to check whether a server |
1226 |
|
%%% should be allowed to be connected to. |
1227 |
|
%%% |
1228 |
|
%%% A handler can decide that a server should not be allowed and pass this |
1229 |
|
%%% information to the caller. |
1230 |
|
-spec s2s_allow_host(MyHost, S2SHost) -> Result when |
1231 |
|
MyHost :: jid:server(), |
1232 |
|
S2SHost :: jid:server(), |
1233 |
|
Result :: allow | deny. |
1234 |
|
s2s_allow_host(MyHost, S2SHost) -> |
1235 |
56 |
run_global_hook(s2s_allow_host, allow, [MyHost, S2SHost]). |
1236 |
|
|
1237 |
|
%%% @doc `s2s_connect_hook' hook is called when a s2s connection is established. |
1238 |
|
-spec s2s_connect_hook(Name, Server) -> Result when |
1239 |
|
Name :: any(), |
1240 |
|
Server :: jid:server(), |
1241 |
|
Result :: any(). |
1242 |
|
s2s_connect_hook(Name, Server) -> |
1243 |
24 |
run_global_hook(s2s_connect_hook, ok, [Name, Server]). |
1244 |
|
|
1245 |
|
%%% @doc `s2s_send_packet' hook is called when a message is routed. |
1246 |
|
-spec s2s_send_packet(Acc, From, To, Packet) -> Result when |
1247 |
|
Acc :: mongoose_acc:t(), |
1248 |
|
From :: jid:jid(), |
1249 |
|
To :: jid:jid(), |
1250 |
|
Packet :: exml:element(), |
1251 |
|
Result :: mongoose_acc:t(). |
1252 |
|
s2s_send_packet(Acc, From, To, Packet) -> |
1253 |
91 |
run_global_hook(s2s_send_packet, Acc, [From, To, Packet]). |
1254 |
|
|
1255 |
|
%%% @doc `s2s_stream_features' hook is used to extract |
1256 |
|
%%% the stream management features supported by the server. |
1257 |
|
-spec s2s_stream_features(HostType, LServer) -> Result when |
1258 |
|
HostType :: mongooseim:host_type(), |
1259 |
|
LServer :: jid:lserver(), |
1260 |
|
Result :: [exml:element()]. |
1261 |
|
s2s_stream_features(HostType, LServer) -> |
1262 |
45 |
run_hook_for_host_type(s2s_stream_features, HostType, [], [HostType, LServer]). |
1263 |
|
|
1264 |
|
%%% @doc `s2s_receive_packet' hook is called when |
1265 |
|
%%% an incoming stanza is routed by the server. |
1266 |
|
-spec s2s_receive_packet(Acc) -> Result when |
1267 |
|
Acc :: mongoose_acc:t(), |
1268 |
|
Result :: mongoose_acc:t(). |
1269 |
|
s2s_receive_packet(Acc) -> |
1270 |
71 |
run_global_hook(s2s_receive_packet, Acc, []). |
1271 |
|
|
1272 |
|
%% Discovery related hooks |
1273 |
|
|
1274 |
|
%%% @doc `disco_local_identity' hook is called to get the identity of the server. |
1275 |
|
-spec disco_local_identity(mongoose_disco:identity_acc()) -> |
1276 |
|
mongoose_disco:identity_acc(). |
1277 |
|
disco_local_identity(Acc = #{host_type := HostType}) -> |
1278 |
159 |
run_hook_for_host_type(disco_local_identity, HostType, Acc, []). |
1279 |
|
|
1280 |
|
%%% @doc `disco_sm_identity' hook is called to get the identity of the |
1281 |
|
%%% client when a discovery IQ gets to session management. |
1282 |
|
-spec disco_sm_identity(mongoose_disco:identity_acc()) -> mongoose_disco:identity_acc(). |
1283 |
|
disco_sm_identity(Acc = #{host_type := HostType}) -> |
1284 |
11 |
run_hook_for_host_type(disco_sm_identity, HostType, Acc, []). |
1285 |
|
|
1286 |
|
%%% @doc `disco_local_items' hook is called to extract items associated with the server. |
1287 |
|
-spec disco_local_items(mongoose_disco:item_acc()) -> mongoose_disco:item_acc(). |
1288 |
|
disco_local_items(Acc = #{host_type := HostType}) -> |
1289 |
31 |
run_hook_for_host_type(disco_local_items, HostType, Acc, []). |
1290 |
|
|
1291 |
|
%%% @doc `disco_sm_items' hook is called to get the items associated |
1292 |
|
%%% with the client when a discovery IQ gets to session management. |
1293 |
|
-spec disco_sm_items(mongoose_disco:item_acc()) -> mongoose_disco:item_acc(). |
1294 |
|
disco_sm_items(Acc = #{host_type := HostType}) -> |
1295 |
10 |
run_hook_for_host_type(disco_sm_items, HostType, Acc, []). |
1296 |
|
|
1297 |
|
%%% @doc `disco_local_features' hook is called to extract features |
1298 |
|
%%% offered by the server. |
1299 |
|
-spec disco_local_features(mongoose_disco:feature_acc()) -> mongoose_disco:feature_acc(). |
1300 |
|
disco_local_features(Acc = #{host_type := HostType}) -> |
1301 |
159 |
run_hook_for_host_type(disco_local_features, HostType, Acc, []). |
1302 |
|
|
1303 |
|
%%% @doc `disco_sm_features' hook is called to get the features of the client |
1304 |
|
%%% when a discovery IQ gets to session management. |
1305 |
|
-spec disco_sm_features(mongoose_disco:feature_acc()) -> mongoose_disco:feature_acc(). |
1306 |
|
disco_sm_features(Acc = #{host_type := HostType}) -> |
1307 |
11 |
run_hook_for_host_type(disco_sm_features, HostType, Acc, []). |
1308 |
|
|
1309 |
|
%%% @doc `disco_muc_features' hook is called to get the features |
1310 |
|
%%% supported by the MUC (Light) service. |
1311 |
|
-spec disco_muc_features(mongoose_disco:feature_acc()) -> mongoose_disco:feature_acc(). |
1312 |
|
disco_muc_features(Acc = #{host_type := HostType}) -> |
1313 |
9 |
run_hook_for_host_type(disco_muc_features, HostType, Acc, []). |
1314 |
|
|
1315 |
|
%%% @doc `disco_info' hook is called to extract information about the server. |
1316 |
|
-spec disco_info(mongoose_disco:info_acc()) -> mongoose_disco:info_acc(). |
1317 |
|
disco_info(Acc = #{host_type := HostType}) -> |
1318 |
165 |
run_hook_for_host_type(disco_info, HostType, Acc, []). |
1319 |
|
|
1320 |
|
%% AMP related hooks |
1321 |
|
|
1322 |
|
%%% @doc The `amp_check_condition' hook is called to determine whether |
1323 |
|
%%% the AMP strategy matches the given AMP rule. |
1324 |
|
-spec amp_check_condition(HostType, Strategy, Rule) -> Result when |
1325 |
|
HostType :: mongooseim:host_type(), |
1326 |
|
Strategy :: mod_amp:amp_strategy(), |
1327 |
|
Rule :: mod_amp:amp_rule(), |
1328 |
|
Result :: mod_amp:amp_match_result(). |
1329 |
|
amp_check_condition(HostType, Strategy, Rule) -> |
1330 |
332 |
InitialAcc = no_match, %% mod_amp:amp_match_result() type |
1331 |
332 |
run_hook_for_host_type(amp_check_condition, HostType, InitialAcc, [Strategy, Rule]). |
1332 |
|
|
1333 |
|
%%% @doc The `amp_determine_strategy' hook is called when checking to determine |
1334 |
|
%%% which strategy will be chosen when executing AMP rules. |
1335 |
|
-spec amp_determine_strategy(HostType, From, To, Packet, Event) -> Result when |
1336 |
|
HostType :: mongooseim:host_type(), |
1337 |
|
From :: jid:jid(), |
1338 |
|
To :: jid:jid() | undefined, |
1339 |
|
Packet :: exml:element(), |
1340 |
|
Event :: mod_amp:amp_event(), |
1341 |
|
Result :: mod_amp:amp_strategy(). |
1342 |
|
amp_determine_strategy(HostType, From, To, Packet, Event) -> |
1343 |
326 |
DefaultStrategy = amp_strategy:null_strategy(), |
1344 |
326 |
run_hook_for_host_type(amp_determine_strategy, HostType, DefaultStrategy, |
1345 |
|
[From, To, Packet, Event]). |
1346 |
|
|
1347 |
|
%%% @doc The `amp_verify_support' hook is called when checking |
1348 |
|
%%% whether the host supports given AMP rules. |
1349 |
|
-spec amp_verify_support(HostType, Rules) -> Result when |
1350 |
|
HostType :: mongooseim:host_type(), |
1351 |
|
Rules :: mod_amp:amp_rules(), |
1352 |
|
Result :: [mod_amp:amp_rule_support()]. |
1353 |
|
amp_verify_support(HostType, Rules) -> |
1354 |
175 |
run_hook_for_host_type(amp_verify_support, HostType, [], [Rules]). |
1355 |
|
|
1356 |
|
%% MUC and MUC Light related hooks |
1357 |
|
|
1358 |
|
-spec filter_room_packet(HostType, Packet, EventData) -> Result when |
1359 |
|
HostType :: mongooseim:host_type(), |
1360 |
|
Packet :: exml:element(), |
1361 |
|
EventData :: mod_muc:room_event_data(), |
1362 |
|
Result :: exml:element(). |
1363 |
|
filter_room_packet(HostType, Packet, EventData) -> |
1364 |
233 |
run_hook_for_host_type(filter_room_packet, HostType, Packet, [HostType, EventData]). |
1365 |
|
|
1366 |
|
%%% @doc The `forget_room' hook is called when a room is removed from the database. |
1367 |
|
-spec forget_room(HostType, MucHost, Room) -> Result when |
1368 |
|
HostType :: mongooseim:host_type(), |
1369 |
|
MucHost :: jid:server(), |
1370 |
|
Room :: jid:luser(), |
1371 |
|
Result :: any(). |
1372 |
|
forget_room(HostType, MucHost, Room) -> |
1373 |
233 |
run_hook_for_host_type(forget_room, HostType, #{}, [HostType, MucHost, Room]). |
1374 |
|
|
1375 |
|
-spec invitation_sent(HookServer, Host, RoomJID, From, To, Reason) -> Result when |
1376 |
|
HookServer :: jid:server(), |
1377 |
|
Host :: jid:server(), |
1378 |
|
RoomJID :: jid:jid(), |
1379 |
|
From :: jid:jid(), |
1380 |
|
To :: jid:jid(), |
1381 |
|
Reason :: binary(), |
1382 |
|
Result :: any(). |
1383 |
|
invitation_sent(HookServer, Host, RoomJID, From, To, Reason) -> |
1384 |
11 |
run_hook_for_host_type(invitation_sent, HookServer, ok, |
1385 |
|
[HookServer, Host, RoomJID, From, To, Reason]). |
1386 |
|
|
1387 |
|
%%% @doc The `join_room' hook is called when a user joins a MUC room. |
1388 |
|
-spec join_room(HookServer, Room, Host, JID, MucJID) -> Result when |
1389 |
|
HookServer :: jid:server(), |
1390 |
|
Room :: mod_muc:room(), |
1391 |
|
Host :: jid:server(), |
1392 |
|
JID :: jid:jid(), |
1393 |
|
MucJID :: jid:jid(), |
1394 |
|
Result :: any(). |
1395 |
|
join_room(HookServer, Room, Host, JID, MucJID) -> |
1396 |
185 |
run_hook_for_host_type(join_room, HookServer, ok, |
1397 |
|
[HookServer, Room, Host, JID, MucJID]). |
1398 |
|
|
1399 |
|
%%% @doc The `leave_room' hook is called when a user joins a MUC room. |
1400 |
|
-spec leave_room(HookServer, Room, Host, JID, MucJID) -> Result when |
1401 |
|
HookServer :: jid:server(), |
1402 |
|
Room :: mod_muc:room(), |
1403 |
|
Host :: jid:server(), |
1404 |
|
JID :: jid:jid(), |
1405 |
|
MucJID :: jid:jid(), |
1406 |
|
Result :: any(). |
1407 |
|
leave_room(HookServer, Room, Host, JID, MucJID) -> |
1408 |
162 |
run_hook_for_host_type(leave_room, HookServer, ok, |
1409 |
|
[HookServer, Room, Host, JID, MucJID]). |
1410 |
|
|
1411 |
|
%%% @doc The `room_packet' hook is called when a message is added to room's history. |
1412 |
|
-spec room_packet(Server, FromNick, FromJID, JID, Packet) -> Result when |
1413 |
|
Server :: jid:lserver(), |
1414 |
|
FromNick :: mod_muc:nick(), |
1415 |
|
FromJID :: jid:jid(), |
1416 |
|
JID :: jid:jid(), |
1417 |
|
Packet :: exml:element(), |
1418 |
|
Result :: any(). |
1419 |
|
room_packet(Server, FromNick, FromJID, JID, Packet) -> |
1420 |
21 |
run_hook_for_host_type(room_packet, Server, ok, [FromNick, FromJID, JID, Packet]). |
1421 |
|
|
1422 |
|
-spec update_inbox_for_muc(HostType, Info) -> Result when |
1423 |
|
HostType :: mongooseim:host_type(), |
1424 |
|
Info :: mod_muc_room:update_inbox_for_muc_payload(), |
1425 |
|
Result :: mod_muc_room:update_inbox_for_muc_payload(). |
1426 |
|
update_inbox_for_muc(HostType, Info) -> |
1427 |
21 |
run_hook_for_host_type(update_inbox_for_muc, HostType, Info, []). |
1428 |
|
|
1429 |
|
%% Caps related hooks |
1430 |
|
|
1431 |
|
-spec caps_recognised(Acc, From, Pid, Features) -> Result when |
1432 |
|
Acc :: mongoose_acc:t(), |
1433 |
|
From :: jid:jid(), |
1434 |
|
Pid :: pid(), |
1435 |
|
Features :: unknown | list(), |
1436 |
|
Result :: mongoose_acc:t(). |
1437 |
|
caps_recognised(Acc, From, Pid, Features) -> |
1438 |
6 |
HostType = mongoose_acc:host_type(Acc), |
1439 |
6 |
run_hook_for_host_type(caps_recognised, HostType, Acc, [From, Pid, Features]). |
1440 |
|
|
1441 |
|
%% PubSub related hooks |
1442 |
|
|
1443 |
|
%%% @doc The `pubsub_create_node' hook is called to |
1444 |
|
%%% inform that a pubsub node is created. |
1445 |
|
-spec pubsub_create_node(Server, PubSubHost, NodeId, Nidx, NodeOptions) -> Result when |
1446 |
|
Server :: jid:server(), |
1447 |
|
PubSubHost :: mod_pubsub:host(), |
1448 |
|
NodeId :: mod_pubsub:nodeId(), |
1449 |
|
Nidx :: mod_pubsub:nodeIdx(), |
1450 |
|
NodeOptions :: list(), |
1451 |
|
Result :: any(). |
1452 |
|
pubsub_create_node(Server, PubSubHost, NodeId, Nidx, NodeOptions) -> |
1453 |
205 |
run_hook_for_host_type(pubsub_create_node, Server, ok, |
1454 |
|
[Server, PubSubHost, NodeId, Nidx, NodeOptions]). |
1455 |
|
|
1456 |
|
%%% @doc The `pubsub_delete_node' hook is called to inform |
1457 |
|
%%% that a pubsub node is deleted. |
1458 |
|
-spec pubsub_delete_node(Server, PubSubHost, NodeId, Nidx) -> Result when |
1459 |
|
Server :: jid:server(), |
1460 |
|
PubSubHost :: mod_pubsub:host(), |
1461 |
|
NodeId :: mod_pubsub:nodeId(), |
1462 |
|
Nidx :: mod_pubsub:nodeIdx(), |
1463 |
|
Result :: any(). |
1464 |
|
pubsub_delete_node(Server, PubSubHost, NodeId, Nidx) -> |
1465 |
145 |
run_hook_for_host_type(pubsub_delete_node, Server, ok, |
1466 |
|
[Server, PubSubHost, NodeId, Nidx]). |
1467 |
|
|
1468 |
|
%%% @doc The `pubsub_publish_item' hook is called to inform |
1469 |
|
%%% that a pubsub item is published. |
1470 |
|
-spec pubsub_publish_item(Server, NodeId, Publisher, |
1471 |
|
ServiceJID, ItemId, BrPayload) -> Result when |
1472 |
|
Server :: jid:server(), |
1473 |
|
NodeId :: mod_pubsub:nodeId(), |
1474 |
|
Publisher :: jid:jid(), |
1475 |
|
ServiceJID :: jid:jid(), |
1476 |
|
ItemId :: mod_pubsub:itemId(), |
1477 |
|
BrPayload :: mod_pubsub:payload(), |
1478 |
|
Result :: any(). |
1479 |
|
pubsub_publish_item(Server, NodeId, Publisher, ServiceJID, ItemId, BrPayload) -> |
1480 |
114 |
run_hook_for_host_type(pubsub_publish_item, Server, ok, |
1481 |
|
[Server, NodeId, Publisher, ServiceJID, |
1482 |
|
ItemId, BrPayload]). |
1483 |
|
|
1484 |
|
%% Global distribution related hooks |
1485 |
|
|
1486 |
|
%%% @doc The `mod_global_distrib_known_recipient' hook is called when |
1487 |
|
%%% the recipient is known to `global_distrib'. |
1488 |
|
-spec mod_global_distrib_known_recipient(GlobalHost, From, To, LocalHost) -> Result when |
1489 |
|
GlobalHost :: jid:server(), |
1490 |
|
From :: jid:jid(), |
1491 |
|
To :: jid:jid(), |
1492 |
|
LocalHost :: jid:server(), |
1493 |
|
Result :: any(). |
1494 |
|
mod_global_distrib_known_recipient(GlobalHost, From, To, LocalHost) -> |
1495 |
745 |
run_hook_for_host_type(mod_global_distrib_known_recipient, GlobalHost, ok, |
1496 |
|
[From, To, LocalHost]). |
1497 |
|
|
1498 |
|
%%% @doc The `mod_global_distrib_unknown_recipient' hook is called when |
1499 |
|
%%% the recipient is unknown to `global_distrib'. |
1500 |
|
-spec mod_global_distrib_unknown_recipient(GlobalHost, Info) -> Result when |
1501 |
|
GlobalHost :: jid:server(), |
1502 |
|
Info :: filter_packet_acc(), |
1503 |
|
Result :: any(). |
1504 |
|
mod_global_distrib_unknown_recipient(GlobalHost, Info) -> |
1505 |
56 |
run_hook_for_host_type(mod_global_distrib_unknown_recipient, GlobalHost, Info, []). |
1506 |
|
|
1507 |
|
|
1508 |
|
%%%---------------------------------------------------------------------- |
1509 |
|
%%% Internal functions |
1510 |
|
%%%---------------------------------------------------------------------- |
1511 |
|
run_global_hook(HookName, Acc, Params) when is_map(Params) -> |
1512 |
:-( |
run_fold(HookName, global, Acc, Params); |
1513 |
|
run_global_hook(HookName, Acc, Args) when is_list(Args) -> |
1514 |
39527 |
ParamsWithLegacyArgs = ejabberd_hooks:add_args(#{}, Args), |
1515 |
39527 |
run_fold(HookName, global, Acc, ParamsWithLegacyArgs). |
1516 |
|
|
1517 |
|
run_hook_for_host_type(HookName, undefined, Acc, Args) -> |
1518 |
:-( |
?LOG_ERROR(#{what => undefined_host_type, |
1519 |
|
text => <<"Running hook for an undefined host type">>, |
1520 |
:-( |
hook_name => HookName, hook_acc => Acc, hook_args => Args}), |
1521 |
:-( |
Acc; |
1522 |
|
run_hook_for_host_type(HookName, HostType, Acc, Params) when is_binary(HostType), |
1523 |
|
is_map(Params) -> |
1524 |
150 |
run_fold(HookName, HostType, Acc, Params); |
1525 |
|
run_hook_for_host_type(HookName, HostType, Acc, Args) when is_binary(HostType), |
1526 |
|
is_list(Args) -> |
1527 |
144288 |
ParamsWithLegacyArgs = ejabberd_hooks:add_args(#{}, Args), |
1528 |
144288 |
run_fold(HookName, HostType, Acc, ParamsWithLegacyArgs). |
1529 |
|
|
1530 |
|
run_fold(HookName, HostType, Acc, Params) when is_map(Params) -> |
1531 |
183965 |
{_, RetValue} = gen_hook:run_fold(HookName, HostType, Acc, Params), |
1532 |
183965 |
RetValue. |