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

processone / ejabberd / 603

17 Oct 2023 01:57PM UTC coverage: 32.654% (-0.4%) from 33.021%
603

push

github

badlop
Fixing minor typos in CHANGELOG

13497 of 41333 relevant lines covered (32.65%)

646.75 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-2023   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
-include("pubsub.hrl").
34

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

50
depends(_Host, _ServerHost, _Opts) ->
51
    [{mod_caps, hard}].
2✔
52

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

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

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

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

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

121
create_node(Nidx, Owner) ->
122
    node_flat:create_node(Nidx, Owner).
4✔
123

124
delete_node(Nodes) ->
125
    node_flat:delete_node(Nodes).
4✔
126

127
subscribe_node(Nidx, Sender, Subscriber, AccessModel,
128
            SendLast, PresenceSubscription, RosterGroup, Options) ->
129
    node_flat:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
×
130
        PresenceSubscription, RosterGroup, Options).
131

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

138
publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload, PubOpts) ->
139
    node_flat:publish_item(Nidx, Publisher, Model, MaxItems, ItemId,
6✔
140
        Payload, PubOpts).
141

142
remove_extra_items(Nidx, MaxItems) ->
143
    node_flat:remove_extra_items(Nidx, MaxItems).
×
144

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

148
remove_expired_items(Nidx, Seconds) ->
149
    node_flat:remove_expired_items(Nidx, Seconds).
×
150

151
delete_item(Nidx, Publisher, PublishModel, ItemId) ->
152
    node_flat:delete_item(Nidx, Publisher, PublishModel, ItemId).
×
153

154
purge_node(Nidx, Owner) ->
155
    node_flat:purge_node(Nidx, Owner).
×
156

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

172

173
get_node_affiliations(Nidx) ->
174
    node_flat:get_node_affiliations(Nidx).
×
175

176
get_affiliation(Nidx, Owner) ->
177
    node_flat:get_affiliation(Nidx, Owner).
4✔
178

179
set_affiliation(Nidx, Owner, Affiliation) ->
180
    node_flat:set_affiliation(Nidx, Owner, Affiliation).
×
181

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

213
get_node_subscriptions(Nidx) ->
214
    node_flat:get_node_subscriptions(Nidx).
14✔
215

216
get_subscriptions(Nidx, Owner) ->
217
    node_flat:get_subscriptions(Nidx, Owner).
×
218

219
set_subscriptions(Nidx, Owner, Subscription, SubId) ->
220
    node_flat:set_subscriptions(Nidx, Owner, Subscription, SubId).
×
221

222
get_pending_nodes(Host, Owner) ->
223
    node_flat:get_pending_nodes(Host, Owner).
×
224

225
get_states(Nidx) ->
226
    node_flat:get_states(Nidx).
×
227

228
get_state(Nidx, JID) ->
229
    node_flat:get_state(Nidx, JID).
×
230

231
set_state(State) ->
232
    node_flat:set_state(State).
×
233

234
get_items(Nidx, From, RSM) ->
235
    node_flat:get_items(Nidx, From, RSM).
8✔
236

237
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
238
    node_flat:get_items(Nidx, JID, AccessModel,
2✔
239
        PresenceSubscription, RosterGroup, SubId, RSM).
240

241
get_last_items(Nidx, From, Count) ->
242
    node_flat:get_last_items(Nidx, From, Count).
×
243

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

247
get_item(Nidx, ItemId) ->
248
    node_flat:get_item(Nidx, ItemId).
×
249

250
get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
251
    node_flat:get_item(Nidx, ItemId, JID, AccessModel,
×
252
        PresenceSubscription, RosterGroup, SubId).
253

254
set_item(Item) ->
255
    node_flat:set_item(Item).
×
256

257
get_item_name(Host, Node, Id) ->
258
    node_flat:get_item_name(Host, Node, Id).
×
259

260
node_to_path(Node) ->
261
    node_flat:node_to_path(Node).
14✔
262

263
path_to_node(Path) ->
264
    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