• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

processone / ejabberd / 838

14 Nov 2024 12:58PM UTC coverage: 32.911% (-0.009%) from 32.92%
838

push

github

badlop
Runtime: Test Dialyzer in Rebars jobs (#4281)

The CI workflow uses ubuntu-24.04 and setup-beam action,
so it can test only Erlang/OTP 24 and higher.

To ensure Dialyzer is also ran with older Erlang versions,
let's add Dialyzer testing to the Runtime workflow,
which uses the erlang container, and that allows
to run Erlang/OTP 20 in ubuntu-24.04.

14586 of 44320 relevant lines covered (32.91%)

619.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.53
/src/node_pep.erl
1
%%%----------------------------------------------------------------------
2
%%% File    : node_pep.erl
3
%%% Author  : Christophe Romain <christophe.romain@process-one.net>
4
%%% Purpose : Standard PubSub PEP plugin
5
%%% Created :  1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net>
6
%%%
7
%%%
8
%%% ejabberd, Copyright (C) 2002-2024   ProcessOne
9
%%%
10
%%% This program is free software; you can redistribute it and/or
11
%%% modify it under the terms of the GNU General Public License as
12
%%% published by the Free Software Foundation; either version 2 of the
13
%%% License, or (at your option) any later version.
14
%%%
15
%%% This program is distributed in the hope that it will be useful,
16
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
17
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
%%% General Public License for more details.
19
%%%
20
%%% You should have received a copy of the GNU General Public License along
21
%%% with this program; if not, write to the Free Software Foundation, Inc.,
22
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
%%%
24
%%%----------------------------------------------------------------------
25

26
%%% @doc The module <strong>{@module}</strong> is the pep PubSub plugin.
27
%%% <p>PubSub plugin nodes are using the {@link gen_pubsub_node} behaviour.</p>
28

29
-module(node_pep).
30
-behaviour(gen_pubsub_node).
31
-author('christophe.romain@process-one.net').
32

33
-protocol({xep, 384, '0.8.3', '21.12', "complete", ""}).
34

35
-include("pubsub.hrl").
36

37
-export([init/3, terminate/2, options/0, features/0,
38
    create_node_permission/6, create_node/2, delete_node/1,
39
    purge_node/2, subscribe_node/8, unsubscribe_node/4,
40
    publish_item/7, delete_item/4,
41
    remove_extra_items/2, remove_extra_items/3, remove_expired_items/2,
42
    get_entity_affiliations/2, get_node_affiliations/1,
43
    get_affiliation/2, set_affiliation/3,
44
    get_entity_subscriptions/2, get_node_subscriptions/1,
45
    get_subscriptions/2, set_subscriptions/4,
46
    get_pending_nodes/2, get_states/1, get_state/2,
47
    set_state/1, get_items/7, get_items/3, get_item/7,
48
    get_last_items/3, get_only_item/2,
49
    get_item/2, set_item/1, get_item_name/3, node_to_path/1,
50
    path_to_node/1, depends/3]).
51

52
depends(_Host, _ServerHost, _Opts) ->
53
    [{mod_caps, hard}].
4✔
54

55
init(Host, ServerHost, Opts) ->
56
    node_flat:init(Host, ServerHost, Opts),
2✔
57
    ok.
2✔
58

59
terminate(Host, ServerHost) ->
60
    node_flat:terminate(Host, ServerHost),
2✔
61
    ok.
2✔
62

63
options() ->
64
    [{deliver_payloads, true},
76✔
65
        {notify_config, false},
66
        {notify_delete, false},
67
        {notify_retract, false},
68
        {purge_offline, false},
69
        {persist_items, true},
70
        {max_items, 1},
71
        {subscribe, true},
72
        {access_model, presence},
73
        {roster_groups_allowed, []},
74
        {publish_model, publishers},
75
        {notification_type, headline},
76
        {max_payload_size, ?MAX_PAYLOAD_SIZE},
77
        {send_last_published_item, on_sub_and_presence},
78
        {deliver_notifications, true},
79
        {presence_based_delivery, true},
80
        {itemreply, none}].
81

82
features() ->
83
    [<<"create-nodes">>,
3,469✔
84
        <<"auto-create">>,
85
        <<"auto-subscribe">>,
86
        <<"config-node">>,
87
        <<"config-node-max">>,
88
        <<"delete-nodes">>,
89
        <<"delete-items">>,
90
        <<"filtered-notifications">>,
91
        <<"item-ids">>,
92
        <<"modify-affiliations">>,
93
        <<"multi-items">>,
94
        <<"outcast-affiliation">>,
95
        <<"persistent-items">>,
96
        <<"publish">>,
97
        <<"publish-options">>,
98
        <<"purge-nodes">>,
99
        <<"retract-items">>,
100
        <<"retrieve-affiliations">>,
101
        <<"retrieve-items">>,
102
        <<"retrieve-subscriptions">>,
103
        <<"subscribe">>].
104

105
create_node_permission(Host, ServerHost, _Node, _ParentNode, Owner, Access) ->
106
    LOwner = jid:tolower(Owner),
10✔
107
    {User, Server, _Resource} = LOwner,
10✔
108
    Allowed = case LOwner of
10✔
109
        {<<"">>, Host, <<"">>} ->
110
            true; % pubsub service always allowed
×
111
        _ ->
112
            case acl:match_rule(ServerHost, Access, LOwner) of
10✔
113
                allow ->
114
                    case Host of
10✔
115
                        {User, Server, _} -> true;
10✔
116
                        _ -> false
×
117
                    end;
118
                _ ->
119
                    false
×
120
            end
121
    end,
122
    {result, Allowed}.
10✔
123

124
create_node(Nidx, Owner) ->
125
    node_flat:create_node(Nidx, Owner).
4✔
126

127
delete_node(Nodes) ->
128
    node_flat:delete_node(Nodes).
4✔
129

130
subscribe_node(Nidx, Sender, Subscriber, AccessModel,
131
            SendLast, PresenceSubscription, RosterGroup, Options) ->
132
    node_flat:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
×
133
        PresenceSubscription, RosterGroup, Options).
134

135
unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
136
    case node_flat:unsubscribe_node(Nidx, Sender, Subscriber, SubId) of
×
137
        {error, Error} -> {error, Error};
×
138
        {result, _} -> {result, default}
×
139
    end.
140

141
publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload, PubOpts) ->
142
    node_flat:publish_item(Nidx, Publisher, Model, MaxItems, ItemId,
6✔
143
        Payload, PubOpts).
144

145
remove_extra_items(Nidx, MaxItems) ->
146
    node_flat:remove_extra_items(Nidx, MaxItems).
×
147

148
remove_extra_items(Nidx, MaxItems, ItemIds) ->
149
    node_flat:remove_extra_items(Nidx, MaxItems, ItemIds).
×
150

151
remove_expired_items(Nidx, Seconds) ->
152
    node_flat:remove_expired_items(Nidx, Seconds).
×
153

154
delete_item(Nidx, Publisher, PublishModel, ItemId) ->
155
    node_flat:delete_item(Nidx, Publisher, PublishModel, ItemId).
×
156

157
purge_node(Nidx, Owner) ->
158
    node_flat:purge_node(Nidx, Owner).
×
159

160
get_entity_affiliations(Host, Owner) ->
161
    {_, D, _} = SubKey = jid:tolower(Owner),
452✔
162
    SubKey = jid:tolower(Owner),
452✔
163
    GenKey = jid:remove_resource(SubKey),
452✔
164
    States = mnesia:match_object(#pubsub_state{stateid = {GenKey, '_'}, _ = '_'}),
452✔
165
    NodeTree = mod_pubsub:tree(Host),
452✔
166
    Reply = lists:foldl(fun (#pubsub_state{stateid = {_, N}, affiliation = A}, Acc) ->
452✔
167
                    case NodeTree:get_node(N) of
18✔
168
                        #pubsub_node{nodeid = {{_, D, _}, _}} = Node -> [{Node, A} | Acc];
4✔
169
                        _ -> Acc
14✔
170
                    end
171
            end,
172
            [], States),
173
    {result, Reply}.
452✔
174

175

176
get_node_affiliations(Nidx) ->
177
    node_flat:get_node_affiliations(Nidx).
×
178

179
get_affiliation(Nidx, Owner) ->
180
    node_flat:get_affiliation(Nidx, Owner).
4✔
181

182
set_affiliation(Nidx, Owner, Affiliation) ->
183
    node_flat:set_affiliation(Nidx, Owner, Affiliation).
×
184

185
get_entity_subscriptions(Host, Owner) ->
186
    {U, D, _} = SubKey = jid:tolower(Owner),
194✔
187
    GenKey = jid:remove_resource(SubKey),
194✔
188
    States = case SubKey of
194✔
189
        GenKey ->
190
            mnesia:match_object(#pubsub_state{stateid = {{U, D, '_'}, '_'}, _ = '_'});
136✔
191
        _ ->
192
            mnesia:match_object(#pubsub_state{stateid = {GenKey, '_'}, _ = '_'})
193
            ++
58✔
194
            mnesia:match_object(#pubsub_state{stateid = {SubKey, '_'}, _ = '_'})
195
    end,
196
    NodeTree = mod_pubsub:tree(Host),
194✔
197
    Reply = lists:foldl(fun (#pubsub_state{stateid = {J, N}, subscriptions = Ss}, Acc) ->
194✔
198
                    case NodeTree:get_node(N) of
34✔
199
                        #pubsub_node{nodeid = {{_, D, _}, _}} = Node ->
200
                            lists:foldl(fun
×
201
                                    ({subscribed, SubId}, Acc2) ->
202
                                        [{Node, subscribed, SubId, J} | Acc2];
×
203
                                    ({pending, _SubId}, Acc2) ->
204
                                        [{Node, pending, J} | Acc2];
×
205
                                    (S, Acc2) ->
206
                                        [{Node, S, J} | Acc2]
×
207
                                end,
208
                                Acc, Ss);
209
                        _ ->
210
                            Acc
34✔
211
                    end
212
            end,
213
            [], States),
214
    {result, Reply}.
194✔
215

216
get_node_subscriptions(Nidx) ->
217
    node_flat:get_node_subscriptions(Nidx).
14✔
218

219
get_subscriptions(Nidx, Owner) ->
220
    node_flat:get_subscriptions(Nidx, Owner).
×
221

222
set_subscriptions(Nidx, Owner, Subscription, SubId) ->
223
    node_flat:set_subscriptions(Nidx, Owner, Subscription, SubId).
×
224

225
get_pending_nodes(Host, Owner) ->
226
    node_flat:get_pending_nodes(Host, Owner).
×
227

228
get_states(Nidx) ->
229
    node_flat:get_states(Nidx).
×
230

231
get_state(Nidx, JID) ->
232
    node_flat:get_state(Nidx, JID).
×
233

234
set_state(State) ->
235
    node_flat:set_state(State).
×
236

237
get_items(Nidx, From, RSM) ->
238
    node_flat:get_items(Nidx, From, RSM).
10✔
239

240
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
241
    node_flat:get_items(Nidx, JID, AccessModel,
2✔
242
        PresenceSubscription, RosterGroup, SubId, RSM).
243

244
get_last_items(Nidx, From, Count) ->
245
    node_flat:get_last_items(Nidx, From, Count).
×
246

247
get_only_item(Nidx, From) ->
248
    node_flat:get_only_item(Nidx, From).
×
249

250
get_item(Nidx, ItemId) ->
251
    node_flat:get_item(Nidx, ItemId).
×
252

253
get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
254
    node_flat:get_item(Nidx, ItemId, JID, AccessModel,
×
255
        PresenceSubscription, RosterGroup, SubId).
256

257
set_item(Item) ->
258
    node_flat:set_item(Item).
×
259

260
get_item_name(Host, Node, Id) ->
261
    node_flat:get_item_name(Host, Node, Id).
×
262

263
node_to_path(Node) ->
264
    node_flat:node_to_path(Node).
14✔
265

266
path_to_node(Path) ->
267
    node_flat:path_to_node(Path).
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc