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

processone / ejabberd / 1173

28 Oct 2025 11:02AM UTC coverage: 33.768% (-0.02%) from 33.79%
1173

push

github

badlop
CHANGELOG.md: Update to 25.10

15513 of 45940 relevant lines covered (33.77%)

1078.01 hits per line

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

68.18
/src/mod_caps_sql.erl
1
%%%-------------------------------------------------------------------
2
%%% File    : mod_caps_sql.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-2025   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_caps_sql).
26

27
-behaviour(mod_caps).
28

29

30
%% API
31
-export([init/2, caps_read/2, caps_write/3, export/1, import/3]).
32
-export([sql_schemas/0]).
33

34
-include("mod_caps.hrl").
35
-include("ejabberd_sql_pt.hrl").
36
-include("logger.hrl").
37

38
%%%===================================================================
39
%%% API
40
%%%===================================================================
41
init(Host, _Opts) ->
42
    ejabberd_sql_schema:update_schema(Host, ?MODULE, sql_schemas()),
6✔
43
    ok.
6✔
44

45
sql_schemas() ->
46
    [#sql_schema{
6✔
47
        version = 1,
48
        tables =
49
            [#sql_table{
50
                name = <<"caps_features">>,
51
                columns =
52
                    [#sql_column{name = <<"node">>, type = text},
53
                     #sql_column{name = <<"subnode">>, type = text},
54
                     #sql_column{name = <<"feature">>, type = text},
55
                     #sql_column{name = <<"created_at">>, type = timestamp,
56
                                 default = true}],
57
                indices = [#sql_index{
58
                              columns = [<<"node">>, <<"subnode">>]}]}]}].
59

60
caps_read(LServer, {Node, SubNode}) ->
61
    case ejabberd_sql:sql_query(
12✔
62
           LServer,
63
           ?SQL("select @(feature)s from caps_features where"
20✔
64
                " node=%(Node)s and subnode=%(SubNode)s")) of
65
        {selected, [{H}|_] = Fs} ->
66
            case catch binary_to_integer(H) of
6✔
67
                Int when is_integer(Int), Int>=0 ->
68
                    {ok, Int};
×
69
                _ ->
70
                    {ok, [F || {F} <- Fs]}
6✔
71
            end;
72
        _ ->
73
            error
6✔
74
    end.
75

76
caps_write(LServer, NodePair, Features) ->
77
    case ejabberd_sql:sql_transaction(
6✔
78
           LServer,
79
           sql_write_features_t(NodePair, Features)) of
80
        {atomic, _} ->
81
            ok;
6✔
82
        {aborted, _Reason} ->
83
            {error, db_failure}
×
84
    end.
85

86
export(_Server) ->
87
    [{caps_features,
×
88
      fun(_Host, #caps_features{node_pair = NodePair,
89
                                features = Features}) ->
90
              sql_write_features_t(NodePair, Features);
×
91
         (_Host, _R) ->
92
              []
×
93
      end}].
94

95
import(_, _, _) ->
96
    ok.
×
97

98
%%%===================================================================
99
%%% Internal functions
100
%%%===================================================================
101
sql_write_features_t({Node, SubNode}, Features) ->
102
    NewFeatures = if is_integer(Features) ->
6✔
103
                          [integer_to_binary(Features)];
×
104
                     true ->
105
                          Features
6✔
106
                  end,
107
    [?SQL("delete from caps_features where node=%(Node)s"
6✔
108
          " and subnode=%(SubNode)s;") |
109
     [?SQL("insert into caps_features(node, subnode, feature)"
6✔
110
           " values (%(Node)s, %(SubNode)s, %(F)s);") || F <- NewFeatures]].
6✔
111

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