./ct_report/coverage/mongoose_local_delivery.COVER.html

1 %%%-------------------------------------------------------------------
2 %%% @doc
3 %%% Completes delivery to local recipient or a component; called by
4 %%% main routing chain if it finds a handler to direct the message to.
5 %%% @end
6 %%%-------------------------------------------------------------------
7 -module(mongoose_local_delivery).
8 -author('bartlomiej.gorny@erlang-solutions.com').
9
10 -include("jlib.hrl").
11
12 %% API
13 -export([do_route/5]).
14
15 -spec do_route(jid:jid(),
16 jid:jid(),
17 mongoose_acc:t(),
18 exml:element(),
19 mongoose_packet_handler:t()) ->
20 mongoose_acc:t().
21 do_route(OrigFrom, OrigTo, OrigAcc, OrigPacket, Handler) ->
22 % strip acc from all sender-related values, from now on we are interested in the recipient
23 49816 LDstDomain = OrigTo#jid.lserver,
24 49816 case mongoose_domain_api:get_host_type(LDstDomain) of
25 {error, not_found} ->
26 %% This can happen e.g. for external components
27 %% No handlers can be registered for filter_local_packet in this case
28 22 Acc = mongoose_acc:strip(#{lserver => LDstDomain,
29 from_jid => OrigFrom,
30 to_jid => OrigTo,
31 element => OrigPacket}, OrigAcc),
32 22 Acc1 = mongoose_packet_handler:process(Handler, Acc, OrigFrom, OrigTo, OrigPacket),
33 22 restore_acc_fields(OrigAcc, Acc1);
34 {ok, HostType} ->
35 49794 Acc0 = mongoose_acc:strip(#{lserver => LDstDomain,
36 host_type => HostType,
37 from_jid => OrigFrom,
38 to_jid => OrigTo,
39 element => OrigPacket}, OrigAcc),
40 49794 case mongoose_hooks:filter_local_packet({OrigFrom, OrigTo, Acc0, OrigPacket}) of
41 {From, To, Acc, Packet} ->
42 49782 Acc1 = mongoose_acc:update_stanza(#{from_jid => From,
43 to_jid => To,
44 element => Packet}, Acc),
45 49782 Acc2 = mongoose_packet_handler:process(Handler, Acc1, From, To, Packet),
46 49779 restore_acc_fields(OrigAcc, Acc2);
47 drop ->
48 11 mongoose_hooks:xmpp_stanza_dropped(Acc0, OrigFrom,
49 OrigTo, OrigPacket),
50 11 Acc0
51 end
52 end.
53
54 restore_acc_fields(OrigAcc, Acc) ->
55 49801 HostType = mongoose_acc:host_type(OrigAcc),
56 49801 LServer = mongoose_acc:lserver(OrigAcc),
57 49801 Acc#{host_type := HostType, lserver := LServer}.
Line Hits Source