• 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

55.0
/src/mod_last_sql.erl
1
%%%-------------------------------------------------------------------
2
%%% File    : mod_last_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_last_sql).
26

27
-behaviour(mod_last).
28

29

30
%% API
31
-export([init/2, get_last/2, store_last_info/4, remove_user/2,
32
         import/2, export/1]).
33

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

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

45
schemas() ->
46
    [#sql_schema{
3✔
47
        version = 1,
48
        tables =
49
            [#sql_table{
50
                name = <<"last">>,
51
                columns =
52
                    [#sql_column{name = <<"username">>, type = text},
53
                     #sql_column{name = <<"server_host">>, type = text},
54
                     #sql_column{name = <<"seconds">>, type = text},
55
                     #sql_column{name = <<"state">>, type = text}],
56
                indices = [#sql_index{
57
                              columns = [<<"server_host">>, <<"username">>],
58
                              unique = true}]}]}].
59

60
get_last(LUser, LServer) ->
61
    case ejabberd_sql:sql_query(
3✔
62
           LServer,
63
           ?SQL("select @(seconds)d, @(state)s from last"
3✔
64
                " where username=%(LUser)s and %(LServer)H")) of
65
        {selected, []} ->
66
            error;
3✔
67
        {selected, [{TimeStamp, Status}]} ->
68
            {ok, {TimeStamp, Status}};
×
69
        _Reason ->
70
            {error, db_failure}
×
71
    end.
72

73
store_last_info(LUser, LServer, TimeStamp, Status) ->
74
    TS = integer_to_binary(TimeStamp),
75✔
75
    case ?SQL_UPSERT(LServer, "last",
75✔
76
                     ["!username=%(LUser)s",
77
                      "!server_host=%(LServer)s",
78
                      "seconds=%(TS)s",
79
                      "state=%(Status)s"]) of
80
        ok ->
81
            ok;
75✔
82
        _Err ->
83
            {error, db_failure}
×
84
    end.
85

86
remove_user(LUser, LServer) ->
87
    ejabberd_sql:sql_query(
6✔
88
      LServer,
89
      ?SQL("delete from last where username=%(LUser)s and %(LServer)H")).
6✔
90

91
export(_Server) ->
92
    [{last_activity,
×
93
      fun(Host, #last_activity{us = {LUser, LServer},
94
                               timestamp = TimeStamp, status = Status})
95
            when LServer == Host ->
96
              TS = integer_to_binary(TimeStamp),
×
97
              [?SQL("delete from last where username=%(LUser)s and %(LServer)H;"),
×
98
               ?SQL_INSERT("last",
×
99
                           ["username=%(LUser)s",
100
                            "server_host=%(LServer)s",
101
                            "seconds=%(TS)s",
102
                            "state=%(Status)s"])];
103
         (_Host, _R) ->
104
              []
×
105
      end}].
106

107
import(_LServer, _LA) ->
108
    pass.
×
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