• 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

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

26
%% API
27
-export([init/2, add_channel/3, get_channel/2,
28
         get_channels/1, del_channel/2, del_channels/1]).
29
-export([sql_schemas/0]).
30

31
-include("logger.hrl").
32
-include("ejabberd_sql_pt.hrl").
33

34
%%%===================================================================
35
%%% API
36
%%%===================================================================
37
init(Host, _Opts) ->
38
    ejabberd_sql_schema:update_schema(Host, ?MODULE, sql_schemas()),
4✔
39
    ok.
4✔
40

41
sql_schemas() ->
42
    [#sql_schema{
4✔
43
        version = 1,
44
        tables =
45
            [#sql_table{
46
                name = <<"mix_pam">>,
47
                columns =
48
                    [#sql_column{name = <<"username">>, type = text},
49
                     #sql_column{name = <<"server_host">>, type = text},
50
                     #sql_column{name = <<"channel">>, type = text},
51
                     #sql_column{name = <<"service">>, type = text},
52
                     #sql_column{name = <<"id">>, type = text},
53
                     #sql_column{name = <<"created_at">>, type = timestamp,
54
                                 default = true}],
55
                indices = [#sql_index{
56
                              columns = [<<"username">>, <<"server_host">>,
57
                                         <<"channel">>, <<"service">>],
58
                              unique = true}]}]}].
59

60
add_channel(User, Channel, ID) ->
61
    {LUser, LServer, _} = jid:tolower(User),
×
62
    {Chan, Service, _} = jid:tolower(Channel),
×
63
    case ?SQL_UPSERT(LServer, "mix_pam",
×
64
                     ["!channel=%(Chan)s",
65
                      "!service=%(Service)s",
66
                      "!username=%(LUser)s",
67
                      "!server_host=%(LServer)s",
68
                      "id=%(ID)s"]) of
69
        ok -> ok;
×
70
        _Err -> {error, db_failure}
×
71
    end.
72

73
get_channel(User, Channel) ->
74
    {LUser, LServer, _} = jid:tolower(User),
×
75
    {Chan, Service, _} = jid:tolower(Channel),
×
76
    case ejabberd_sql:sql_query(
×
77
           LServer,
78
           ?SQL("select @(id)s from mix_pam where "
×
79
                "channel=%(Chan)s and service=%(Service)s "
80
                "and username=%(LUser)s and %(LServer)H")) of
81
        {selected, [{ID}]} -> {ok, ID};
×
82
        {selected, []} -> {error, notfound};
×
83
        _Err -> {error, db_failure}
×
84
    end.
85

86
get_channels(User) ->
87
    {LUser, LServer, _} = jid:tolower(User),
1,832✔
88
    SQL = ?SQL("select @(channel)s, @(service)s, @(id)s from mix_pam "
1,832✔
89
               "where username=%(LUser)s and %(LServer)H"),
90
    case ejabberd_sql:sql_query(LServer, SQL) of
1,832✔
91
        {selected, Ret} ->
92
            {ok, lists:filtermap(
1,832✔
93
                   fun({Chan, Service, ID}) ->
94
                           case jid:make(Chan, Service) of
×
95
                               error ->
96
                                   report_corrupted(SQL),
×
97
                                   false;
×
98
                               JID ->
99
                                   {true, {JID, ID}}
×
100
                           end
101
                   end, Ret)};
102
        _Err ->
103
            {error, db_failure}
×
104
    end.
105

106
del_channel(User, Channel) ->
107
    {LUser, LServer, _} = jid:tolower(User),
×
108
    {Chan, Service, _} = jid:tolower(Channel),
×
109
    case ejabberd_sql:sql_query(
×
110
           LServer,
111
           ?SQL("delete from mix_pam where "
×
112
                "channel=%(Chan)s and service=%(Service)s "
113
                "and username=%(LUser)s and %(LServer)H")) of
114
        {updated, _} -> ok;
×
115
        _Err -> {error, db_failure}
×
116
    end.
117

118
del_channels(User) ->
119
    {LUser, LServer, _} = jid:tolower(User),
8✔
120
    case ejabberd_sql:sql_query(
8✔
121
           LServer,
122
           ?SQL("delete from mix_pam where "
8✔
123
                "username=%(LUser)s and %(LServer)H")) of
124
        {updated, _} -> ok;
8✔
125
        _Err -> {error, db_failure}
×
126
    end.
127

128
%%%===================================================================
129
%%% Internal functions
130
%%%===================================================================
131
-spec report_corrupted(#sql_query{}) -> ok.
132
report_corrupted(SQL) ->
133
    ?ERROR_MSG("Corrupted values returned by SQL request: ~ts",
×
134
               [SQL#sql_query.hash]).
×
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