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

processone / ejabberd / 1296

19 Jan 2026 11:25AM UTC coverage: 33.562% (+0.09%) from 33.468%
1296

push

github

badlop
mod_conversejs: Cosmetic change: sort paths alphabetically

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

11245 existing lines in 174 files now uncovered.

15580 of 46421 relevant lines covered (33.56%)

1074.56 hits per line

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

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

25
-module(mod_private_mnesia).
26

27
-behaviour(mod_private).
28

29
%% API
30
-export([init/2, set_data/3, get_data/3, get_all_data/2, del_data/2,
31
        del_data/3, get_users_with_data/2, count_users_with_data/2,
32
        use_cache/1, import/3]).
33
-export([need_transform/1, transform/1]).
34

35
-include_lib("xmpp/include/xmpp.hrl").
36
-include("mod_private.hrl").
37
-include("logger.hrl").
38

39
%%%===================================================================
40
%%% API
41
%%%===================================================================
42
init(_Host, _Opts) ->
UNCOV
43
    ejabberd_mnesia:create(?MODULE, private_storage,
2✔
44
                           [{disc_only_copies, [node()]},
45
                            {attributes, record_info(fields, private_storage)}]).
46

47
use_cache(Host) ->
UNCOV
48
    case mnesia:table_info(private_storage, storage_type) of
538✔
49
        disc_only_copies ->
UNCOV
50
            mod_private_opt:use_cache(Host);
538✔
51
        _ ->
52
            false
×
53
    end.
54

55
set_data(LUser, LServer, Data) ->
UNCOV
56
    F = fun () ->
6✔
UNCOV
57
                lists:foreach(
6✔
58
                  fun({XmlNS, Xmlel}) ->
UNCOV
59
                          mnesia:write(
6✔
60
                            #private_storage{
61
                               usns = {LUser, LServer, XmlNS},
62
                               xml = Xmlel})
63
                  end, Data)
64
        end,
UNCOV
65
    transaction(F).
6✔
66

67
get_data(LUser, LServer, XmlNS) ->
UNCOV
68
    case mnesia:dirty_read(private_storage, {LUser, LServer, XmlNS}) of
16✔
69
        [#private_storage{xml = Storage_Xmlel}] ->
UNCOV
70
            {ok, Storage_Xmlel};
4✔
71
        _ ->
UNCOV
72
            error
12✔
73
    end.
74

75
get_all_data(LUser, LServer) ->
UNCOV
76
    case lists:flatten(
4✔
77
           mnesia:dirty_select(private_storage,
78
                               [{#private_storage{usns = {LUser, LServer, '_'},
79
                                                  xml = '$1'},
80
                                 [], ['$1']}])) of
81
        [] ->
UNCOV
82
            error;
2✔
83
        Res ->
UNCOV
84
            {ok, Res}
2✔
85
    end.
86

87
del_data(LUser, LServer) ->
UNCOV
88
    F = fun () ->
4✔
UNCOV
89
                Namespaces = mnesia:select(private_storage,
4✔
90
                                           [{#private_storage{usns =
91
                                                                  {LUser,
92
                                                                   LServer,
93
                                                                   '$1'},
94
                                                              _ = '_'},
95
                                             [], ['$$']}]),
UNCOV
96
                lists:foreach(fun ([Namespace]) ->
4✔
UNCOV
97
                                      mnesia:delete({private_storage,
2✔
98
                                                     {LUser, LServer,
99
                                                      Namespace}})
100
                              end,
101
                              Namespaces)
102
        end,
UNCOV
103
    transaction(F).
4✔
104

105
-spec del_data(binary(), binary(), binary()) -> ok | {error, any()}.
106
del_data(LUser, LServer, NS) ->
107
    F = fun () ->
×
108
                mnesia:delete({private_storage, {LUser, LServer, NS}})
×
109
        end,
110
    transaction(F).
×
111

112
-spec get_users_with_data(binary(), binary()) -> {ok, [binary()]} | {error, any()}.
113
get_users_with_data(LServer, NS) ->
114
        Val = mnesia:dirty_select(private_storage,
×
115
                                   [{#private_storage{usns =
116
                                                          {'$1',
117
                                                           LServer,
118
                                                           NS},
119
                                                      _ = '_'},
120
                                     [], ['$1']}]),
121
        {ok, Val}.
×
122

123
-spec count_users_with_data(binary(), binary()) -> {ok, integer()} | {error, any()}.
124
count_users_with_data(LServer, NS) ->
125
        {ok, Val} = get_users_with_data(LServer, NS),
×
126
        {ok, length(Val)}.
×
127

128
import(LServer, <<"private_storage">>,
129
       [LUser, XMLNS, XML, _TimeStamp]) ->
130
    El = #xmlel{} = fxml_stream:parse_element(XML),
×
131
    PS = #private_storage{usns = {LUser, LServer, XMLNS}, xml = El},
×
132
    mnesia:dirty_write(PS).
×
133

134
need_transform({private_storage, {U, S, NS}, _})
135
  when is_list(U) orelse is_list(S) orelse is_list(NS) ->
136
    ?INFO_MSG("Mnesia table 'private_storage' will be converted to binary", []),
×
137
    true;
×
138
need_transform(_) ->
139
    false.
×
140

141
transform(#private_storage{usns = {U, S, NS}, xml = El} = R) ->
142
    R#private_storage{usns = {iolist_to_binary(U),
×
143
                              iolist_to_binary(S),
144
                              iolist_to_binary(NS)},
145
                      xml = fxml:to_xmlel(El)}.
146

147
%%%===================================================================
148
%%% Internal functions
149
%%%===================================================================
150
transaction(F) ->
UNCOV
151
    case mnesia:transaction(F) of
10✔
152
        {atomic, Res} ->
UNCOV
153
            Res;
10✔
154
        {aborted, Reason} ->
155
            ?ERROR_MSG("Mnesia transaction failed: ~p", [Reason]),
×
156
            {error, db_failure}
×
157
    end.
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