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

processone / ejabberd / 1227

02 Dec 2025 11:38AM UTC coverage: 33.6% (+0.06%) from 33.536%
1227

push

github

prefiks
Add db serialization to mod_muc_sql

0 of 38 new or added lines in 1 file covered. (0.0%)

10614 existing lines in 161 files now uncovered.

15526 of 46208 relevant lines covered (33.6%)

1072.13 hits per line

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

40.26
/src/node_pep_sql.erl
1
%%%----------------------------------------------------------------------
2
%%% File    : node_pep_sql.erl
3
%%% Author  : Christophe Romain <christophe.romain@process-one.net>
4
%%% Purpose : Standard PubSub PEP plugin with ODBC backend
5
%%% Created :  1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net>
6
%%%
7
%%%
8
%%% ejabberd, Copyright (C) 2002-2025   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_sql).
30
-behaviour(gen_pubsub_node).
31
-author('christophe.romain@process-one.net').
32

33

34
-include("pubsub.hrl").
35
-include("ejabberd_sql_pt.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_item/2, set_item/1, get_item_name/3, node_to_path/1,
49
    path_to_node/1, depends/3,
50
    get_entity_subscriptions_for_send_last/2, get_last_items/3,
51
    get_only_item/2]).
52

53
depends(_Host, _ServerHost, _Opts) ->
UNCOV
54
    [{mod_caps, hard}].
6✔
55

56
init(Host, ServerHost, Opts) ->
UNCOV
57
    node_flat_sql:init(Host, ServerHost, Opts),
6✔
UNCOV
58
    ok.
6✔
59

60
terminate(Host, ServerHost) ->
UNCOV
61
    node_flat_sql:terminate(Host, ServerHost),
6✔
UNCOV
62
    ok.
6✔
63

64
options() ->
UNCOV
65
    [{sql, true}, {rsm, true} | node_pep:options()].
144✔
66

67
features() ->
UNCOV
68
    [<<"rsm">> | node_pep:features()].
4,194✔
69

70
create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access) ->
UNCOV
71
    node_pep:create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access).
12✔
72

73
create_node(Nidx, Owner) ->
UNCOV
74
    node_flat_sql:create_node(Nidx, Owner),
12✔
UNCOV
75
    {result, {default, broadcast}}.
12✔
76

77
delete_node(Nodes) ->
UNCOV
78
    node_flat_sql:delete_node(Nodes).
12✔
79

80
subscribe_node(Nidx, Sender, Subscriber, AccessModel,
81
            SendLast, PresenceSubscription, RosterGroup, Options) ->
82
    node_flat_sql:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
×
83
        PresenceSubscription, RosterGroup, Options).
84

85

86
unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
87
    case node_flat_sql:unsubscribe_node(Nidx, Sender, Subscriber, SubId) of
×
88
        {error, Error} -> {error, Error};
×
89
        {result, _} -> {result, default}
×
90
    end.
91

92
publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload, PubOpts) ->
UNCOV
93
    node_flat_sql:publish_item(Nidx, Publisher, Model, MaxItems, ItemId,
18✔
94
        Payload, PubOpts).
95

96
remove_extra_items(Nidx, MaxItems) ->
97
    node_flat_sql:remove_extra_items(Nidx, MaxItems).
×
98

99
remove_extra_items(Nidx, MaxItems, ItemIds) ->
100
    node_flat_sql:remove_extra_items(Nidx, MaxItems, ItemIds).
×
101

102
remove_expired_items(Nidx, Seconds) ->
103
    node_flat_sql:remove_expired_items(Nidx, Seconds).
×
104

105
delete_item(Nidx, Publisher, PublishModel, ItemId) ->
106
    node_flat_sql:delete_item(Nidx, Publisher, PublishModel, ItemId).
×
107

108
purge_node(Nidx, Owner) ->
109
    node_flat_sql:purge_node(Nidx, Owner).
×
110

111
get_entity_affiliations(_Host, Owner) ->
UNCOV
112
    OwnerKey = jid:tolower(jid:remove_resource(Owner)),
1,356✔
UNCOV
113
    node_flat_sql:get_entity_affiliations(OwnerKey, Owner).
1,356✔
114

115
get_node_affiliations(Nidx) ->
UNCOV
116
    node_flat_sql:get_node_affiliations(Nidx).
6✔
117

118
get_affiliation(Nidx, Owner) ->
UNCOV
119
    node_flat_sql:get_affiliation(Nidx, Owner).
12✔
120

121
set_affiliation(Nidx, Owner, Affiliation) ->
122
    node_flat_sql:set_affiliation(Nidx, Owner, Affiliation).
×
123

124
get_entity_subscriptions(_Host, Owner) ->
UNCOV
125
    SubKey = jid:tolower(Owner),
582✔
UNCOV
126
    GenKey = jid:remove_resource(SubKey),
582✔
UNCOV
127
    HLike = <<"%@", (node_flat_sql:encode_host_like(element(2, SubKey)))/binary>>,
582✔
UNCOV
128
    GJ = node_flat_sql:encode_jid(GenKey),
582✔
UNCOV
129
    Query = case SubKey of
582✔
130
              GenKey ->
UNCOV
131
                GJLike = <<(node_flat_sql:encode_jid_like(GenKey))/binary, "/%">>,
408✔
UNCOV
132
                ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
408✔
133
                     "from pubsub_state i, pubsub_node n "
134
                     "where i.nodeid = n.nodeid and "
135
                     "(jid=%(GJ)s or jid like %(GJLike)s %ESCAPE) and host like %(HLike)s %ESCAPE");
136
              _ ->
UNCOV
137
                SJ = node_flat_sql:encode_jid(SubKey),
174✔
UNCOV
138
                ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
174✔
139
                     "from pubsub_state i, pubsub_node n "
140
                     "where i.nodeid = n.nodeid and "
141
                     "jid in (%(SJ)s,%(GJ)s) and host like %(HLike)s %ESCAPE")
142
            end,
UNCOV
143
    {result,
582✔
144
     case ejabberd_sql:sql_query_t(Query) of
145
         {selected, RItems} ->
UNCOV
146
             lists:foldl(
582✔
147
               fun({H, N, T, I, J, S}, Acc) ->
148
                       O = node_flat_sql:decode_jid(H),
×
149
                       Node = nodetree_tree_sql:raw_to_node(O, {N, <<"">>, T, I}),
×
150
                       Jid = node_flat_sql:decode_jid(J),
×
151
                       lists:foldl(
×
152
                         fun({Sub, SubId}, Acc2) ->
153
                             [{Node, Sub, SubId, Jid} | Acc2]
×
154
                         end, Acc, node_flat_sql:decode_subscriptions(S))
155
               end, [], RItems);
156
         _ ->
157
             []
×
158
     end}.
159

160
get_entity_subscriptions_for_send_last(_Host, Owner) ->
161
    SubKey = jid:tolower(Owner),
×
162
    GenKey = jid:remove_resource(SubKey),
×
163
    HLike = <<"%@", (node_flat_sql:encode_host_like(element(2, SubKey)))/binary>>,
×
164
    GJ = node_flat_sql:encode_jid(GenKey),
×
165
    Query = case SubKey of
×
166
              GenKey ->
167
                GJLike = <<(node_flat_sql:encode_jid_like(GenKey))/binary, "/%">>,
×
168
                ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
×
169
                     "from pubsub_state i, pubsub_node n, pubsub_node_option o "
170
                     "where i.nodeid = n.nodeid and n.nodeid = o.nodeid and "
171
                     "name='send_last_published_item' and val='on_sub_and_presence' and "
172
                     "(jid=%(GJ)s or jid like %(GJLike)s %ESCAPE) and host like %(HLike)s %ESCAPE");
173
              _ ->
174
                SJ = node_flat_sql:encode_jid(SubKey),
×
175
                ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
×
176
                     "from pubsub_state i, pubsub_node n, pubsub_node_option o "
177
                     "where i.nodeid = n.nodeid and n.nodeid = o.nodeid and "
178
                     "name='send_last_published_item' and val='on_sub_and_presence' and "
179
                     "jid in (%(SJ)s,%(GJ)s) and host like %(HLike)s %ESCAPE")
180
            end,
181
    {result,
×
182
     case ejabberd_sql:sql_query_t(Query) of
183
         {selected, RItems} ->
184
             lists:foldl(
×
185
               fun ({H, N, T, I, J, S}, Acc) ->
186
                       O = node_flat_sql:decode_jid(H),
×
187
                       Node = nodetree_tree_sql:raw_to_node(O, {N, <<"">>, T, I}),
×
188
                       Jid = node_flat_sql:decode_jid(J),
×
189
                       lists:foldl(
×
190
                         fun ({Sub, SubId}, Acc2) ->
191
                             [{Node, Sub, SubId, Jid}| Acc2]
×
192
                         end, Acc, node_flat_sql:decode_subscriptions(S))
193
               end, [], RItems);
194
         _ ->
195
             []
×
196
     end}.
197

198
get_node_subscriptions(Nidx) ->
UNCOV
199
    node_flat_sql:get_node_subscriptions(Nidx).
42✔
200

201
get_subscriptions(Nidx, Owner) ->
202
    node_flat_sql:get_subscriptions(Nidx, Owner).
×
203

204
set_subscriptions(Nidx, Owner, Subscription, SubId) ->
205
    node_flat_sql:set_subscriptions(Nidx, Owner, Subscription, SubId).
×
206

207
get_pending_nodes(Host, Owner) ->
208
    node_flat_sql:get_pending_nodes(Host, Owner).
×
209

210
get_states(Nidx) ->
211
    node_flat_sql:get_states(Nidx).
×
212

213
get_state(Nidx, JID) ->
214
    node_flat_sql:get_state(Nidx, JID).
×
215

216
set_state(State) ->
217
    node_flat_sql:set_state(State).
×
218

219
get_items(Nidx, From, RSM) ->
UNCOV
220
    node_flat_sql:get_items(Nidx, From, RSM).
30✔
221

222
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
UNCOV
223
    node_flat_sql:get_items(Nidx, JID, AccessModel,
6✔
224
        PresenceSubscription, RosterGroup, SubId, RSM).
225

226
get_last_items(Nidx, JID, Count) ->
227
    node_flat_sql:get_last_items(Nidx, JID, Count).
×
228

229
get_only_item(Nidx, JID) ->
230
    node_flat_sql:get_only_item(Nidx, JID).
×
231

232
get_item(Nidx, ItemId) ->
233
    node_flat_sql:get_item(Nidx, ItemId).
×
234

235
get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
236
    node_flat_sql:get_item(Nidx, ItemId, JID, AccessModel,
×
237
        PresenceSubscription, RosterGroup, SubId).
238

239
set_item(Item) ->
240
    node_flat_sql:set_item(Item).
×
241

242
get_item_name(Host, Node, Id) ->
243
    node_flat_sql:get_item_name(Host, Node, Id).
×
244

245
node_to_path(Node) ->
UNCOV
246
    node_flat_sql:node_to_path(Node).
12✔
247

248
path_to_node(Path) ->
249
    node_flat_sql: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

© 2025 Coveralls, Inc