• 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

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-2023   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

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

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

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

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

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

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

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

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

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