2003-10-24 21:21:07 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_last.erl
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2010-04-14 01:00:14 +02:00
|
|
|
%%% Purpose : jabber:iq:last support (XEP-0012)
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Created : 24 Oct 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2018-01-05 21:18:58 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2018 ProcessOne
|
2007-12-24 13:58:05 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2014-02-22 11:27:40 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-24 13:58:05 +01:00
|
|
|
%%%
|
2003-10-24 21:21:07 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_last).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-12-24 13:58:05 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-10-24 21:21:07 +02:00
|
|
|
|
2015-05-21 17:02:36 +02:00
|
|
|
-protocol({xep, 12, '2.0'}).
|
|
|
|
|
2003-10-24 21:21:07 +02:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
-export([start/2, stop/1, reload/3, process_local_iq/1, export/1,
|
2016-11-22 14:48:01 +01:00
|
|
|
process_sm_iq/1, on_presence_update/4, import_info/0,
|
2016-11-22 16:12:19 +01:00
|
|
|
import/5, import_start/2, store_last_info/4, get_last_info/2,
|
2018-01-23 08:54:52 +01:00
|
|
|
remove_user/2, mod_opt_type/1, mod_options/1,
|
2017-04-28 12:23:32 +02:00
|
|
|
register_user/2, depends/2, privacy_check_packet/4]).
|
2003-10-24 21:21:07 +02:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-include("xmpp.hrl").
|
2003-10-24 21:21:07 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-include("mod_privacy.hrl").
|
2016-04-13 08:59:39 +02:00
|
|
|
-include("mod_last.hrl").
|
2003-10-24 21:21:07 +02:00
|
|
|
|
2017-05-18 12:21:17 +02:00
|
|
|
-define(LAST_CACHE, last_activity_cache).
|
|
|
|
|
2016-04-13 08:59:39 +02:00
|
|
|
-callback init(binary(), gen_mod:opts()) -> any().
|
|
|
|
-callback import(binary(), #last_activity{}) -> ok | pass.
|
|
|
|
-callback get_last(binary(), binary()) ->
|
2017-05-18 12:21:17 +02:00
|
|
|
{ok, {non_neg_integer(), binary()}} | error | {error, any()}.
|
|
|
|
-callback store_last_info(binary(), binary(), non_neg_integer(), binary()) -> ok | {error, any()}.
|
2017-02-18 07:36:27 +01:00
|
|
|
-callback remove_user(binary(), binary()) -> any().
|
2017-05-18 12:21:17 +02:00
|
|
|
-callback use_cache(binary()) -> boolean().
|
|
|
|
-callback cache_nodes(binary()) -> [node()].
|
|
|
|
|
|
|
|
-optional_callbacks([use_cache/1, cache_nodes/1]).
|
2003-10-24 21:21:07 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
start(Host, Opts) ->
|
2016-04-13 08:59:39 +02:00
|
|
|
Mod = gen_mod:db_mod(Host, Opts, ?MODULE),
|
|
|
|
Mod:init(Host, Opts),
|
2017-05-18 12:21:17 +02:00
|
|
|
init_cache(Mod, Host, Opts),
|
2013-03-14 10:33:02 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
|
2018-02-11 10:54:15 +01:00
|
|
|
?NS_LAST, ?MODULE, process_local_iq),
|
2013-03-14 10:33:02 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
|
2018-02-11 10:54:15 +01:00
|
|
|
?NS_LAST, ?MODULE, process_sm_iq),
|
2016-12-11 13:03:37 +01:00
|
|
|
ejabberd_hooks:add(privacy_check_packet, Host, ?MODULE,
|
|
|
|
privacy_check_packet, 30),
|
2016-06-08 13:02:02 +02:00
|
|
|
ejabberd_hooks:add(register_user, Host, ?MODULE,
|
|
|
|
register_user, 50),
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:add(remove_user, Host, ?MODULE,
|
|
|
|
remove_user, 50),
|
|
|
|
ejabberd_hooks:add(unset_presence_hook, Host, ?MODULE,
|
|
|
|
on_presence_update, 50).
|
2003-10-24 21:21:07 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
stop(Host) ->
|
2016-06-08 13:02:02 +02:00
|
|
|
ejabberd_hooks:delete(register_user, Host, ?MODULE,
|
|
|
|
register_user, 50),
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:delete(remove_user, Host, ?MODULE,
|
|
|
|
remove_user, 50),
|
2005-06-20 05:18:13 +02:00
|
|
|
ejabberd_hooks:delete(unset_presence_hook, Host,
|
2004-12-19 21:47:35 +01:00
|
|
|
?MODULE, on_presence_update, 50),
|
2017-02-14 08:25:08 +01:00
|
|
|
ejabberd_hooks:delete(privacy_check_packet, Host, ?MODULE,
|
|
|
|
privacy_check_packet, 30),
|
2013-03-14 10:33:02 +01:00
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
|
|
|
|
?NS_LAST),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host,
|
|
|
|
?NS_LAST).
|
2003-10-24 21:21:07 +02:00
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
reload(Host, NewOpts, OldOpts) ->
|
|
|
|
NewMod = gen_mod:db_mod(Host, NewOpts, ?MODULE),
|
|
|
|
OldMod = gen_mod:db_mod(Host, OldOpts, ?MODULE),
|
|
|
|
if NewMod /= OldMod ->
|
|
|
|
NewMod:init(Host, NewOpts);
|
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end,
|
2018-02-11 10:54:15 +01:00
|
|
|
init_cache(NewMod, Host, NewOpts).
|
2017-02-22 17:46:47 +01:00
|
|
|
|
2008-12-23 02:34:52 +01:00
|
|
|
%%%
|
|
|
|
%%% Uptime of ejabberd node
|
|
|
|
%%%
|
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec process_local_iq(iq()) -> iq().
|
|
|
|
process_local_iq(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_local_iq(#iq{type = get} = IQ) ->
|
|
|
|
xmpp:make_iq_result(IQ, #last{seconds = get_node_uptime()}).
|
2003-10-24 21:21:07 +02:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec get_node_uptime() -> non_neg_integer().
|
2008-12-23 02:34:52 +01:00
|
|
|
%% @doc Get the uptime of the ejabberd node, expressed in seconds.
|
|
|
|
%% When ejabberd is starting, ejabberd_config:start/0 stores the datetime.
|
|
|
|
get_node_uptime() ->
|
2017-04-29 10:39:40 +02:00
|
|
|
case ejabberd_config:get_option(node_start) of
|
2013-03-14 10:33:02 +01:00
|
|
|
undefined ->
|
|
|
|
trunc(element(1, erlang:statistics(wall_clock)) / 1000);
|
2013-08-12 14:25:05 +02:00
|
|
|
Now ->
|
2015-12-07 16:08:57 +01:00
|
|
|
p1_time_compat:system_time(seconds) - Now
|
2008-12-23 02:34:52 +01:00
|
|
|
end.
|
|
|
|
|
|
|
|
%%%
|
|
|
|
%%% Serve queries about user last online
|
|
|
|
%%%
|
2003-10-24 21:21:07 +02:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec process_sm_iq(iq()) -> iq().
|
|
|
|
process_sm_iq(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_sm_iq(#iq{from = From, to = To, lang = Lang} = IQ) ->
|
|
|
|
User = To#jid.luser,
|
|
|
|
Server = To#jid.lserver,
|
2018-01-26 13:02:06 +01:00
|
|
|
{Subscription, _Ask, _Groups} =
|
2016-07-18 14:01:32 +02:00
|
|
|
ejabberd_hooks:run_fold(roster_get_jid_info, Server,
|
2018-01-26 13:02:06 +01:00
|
|
|
{none, none, []}, [User, Server, From]),
|
2016-07-18 14:01:32 +02:00
|
|
|
if (Subscription == both) or (Subscription == from) or
|
|
|
|
(From#jid.luser == To#jid.luser) and
|
|
|
|
(From#jid.lserver == To#jid.lserver) ->
|
2017-01-09 15:02:17 +01:00
|
|
|
Pres = xmpp:set_from_to(#presence{}, To, From),
|
2016-07-18 14:01:32 +02:00
|
|
|
case ejabberd_hooks:run_fold(privacy_check_packet,
|
|
|
|
Server, allow,
|
2017-01-09 15:02:17 +01:00
|
|
|
[To, Pres, out]) of
|
2016-07-18 14:01:32 +02:00
|
|
|
allow -> get_last_iq(IQ, User, Server);
|
|
|
|
deny -> xmpp:make_error(IQ, xmpp:err_forbidden())
|
|
|
|
end;
|
|
|
|
true ->
|
|
|
|
Txt = <<"Not subscribed">>,
|
2016-07-25 12:50:30 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_subscription_required(Txt, Lang))
|
2003-10-24 21:21:07 +02:00
|
|
|
end.
|
|
|
|
|
2016-12-11 13:03:37 +01:00
|
|
|
privacy_check_packet(allow, C2SState,
|
|
|
|
#iq{from = From, to = To, type = T} = IQ, in)
|
|
|
|
when T == get; T == set ->
|
|
|
|
case xmpp:has_subtag(IQ, #last{}) of
|
|
|
|
true ->
|
2017-05-17 13:47:35 +02:00
|
|
|
#jid{luser = LUser, lserver = LServer} = To,
|
2018-02-17 18:06:50 +01:00
|
|
|
{Sub, _, _} = ejabberd_hooks:run_fold(
|
|
|
|
roster_get_jid_info, LServer,
|
|
|
|
{none, none, []}, [LUser, LServer, From]),
|
2016-12-11 13:03:37 +01:00
|
|
|
if Sub == from; Sub == both ->
|
|
|
|
Pres = #presence{from = To, to = From},
|
|
|
|
case ejabberd_hooks:run_fold(
|
|
|
|
privacy_check_packet, allow,
|
|
|
|
[C2SState, Pres, out]) of
|
|
|
|
allow ->
|
|
|
|
allow;
|
|
|
|
deny ->
|
|
|
|
{stop, deny}
|
|
|
|
end;
|
|
|
|
true ->
|
|
|
|
{stop, deny}
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
allow
|
|
|
|
end;
|
|
|
|
privacy_check_packet(Acc, _, _, _) ->
|
|
|
|
Acc.
|
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec get_last(binary(), binary()) -> {ok, non_neg_integer(), binary()} |
|
|
|
|
not_found | {error, any()}.
|
2010-11-05 18:32:25 +01:00
|
|
|
get_last(LUser, LServer) ->
|
2016-04-13 08:59:39 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2017-05-18 12:21:17 +02:00
|
|
|
Res = case use_cache(Mod, LServer) of
|
|
|
|
true ->
|
|
|
|
ets_cache:lookup(
|
|
|
|
?LAST_CACHE, {LUser, LServer},
|
|
|
|
fun() -> Mod:get_last(LUser, LServer) end);
|
|
|
|
false ->
|
2018-03-20 22:18:43 +01:00
|
|
|
Mod:get_last(LUser, LServer);
|
|
|
|
undefined ->
|
|
|
|
error
|
2017-05-18 12:21:17 +02:00
|
|
|
end,
|
|
|
|
case Res of
|
|
|
|
{ok, {TimeStamp, Status}} -> {ok, TimeStamp, Status};
|
|
|
|
error -> not_found;
|
|
|
|
Err -> Err
|
|
|
|
end.
|
2010-11-05 18:32:25 +01:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec get_last_iq(iq(), binary(), binary()) -> iq().
|
|
|
|
get_last_iq(#iq{lang = Lang} = IQ, LUser, LServer) ->
|
2010-11-05 18:38:42 +01:00
|
|
|
case ejabberd_sm:get_user_resources(LUser, LServer) of
|
2013-03-14 10:33:02 +01:00
|
|
|
[] ->
|
|
|
|
case get_last(LUser, LServer) of
|
|
|
|
{error, _Reason} ->
|
2016-03-31 10:00:29 +02:00
|
|
|
Txt = <<"Database failure">>,
|
2016-07-18 14:01:32 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang));
|
2013-03-14 10:33:02 +01:00
|
|
|
not_found ->
|
2016-03-31 10:00:29 +02:00
|
|
|
Txt = <<"No info about last activity found">>,
|
2016-07-18 14:01:32 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang));
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, TimeStamp, Status} ->
|
2015-12-07 16:08:57 +01:00
|
|
|
TimeStamp2 = p1_time_compat:system_time(seconds),
|
2013-03-14 10:33:02 +01:00
|
|
|
Sec = TimeStamp2 - TimeStamp,
|
2016-07-18 14:01:32 +02:00
|
|
|
xmpp:make_iq_result(IQ, #last{seconds = Sec, status = Status})
|
2013-03-14 10:33:02 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2016-07-18 14:01:32 +02:00
|
|
|
xmpp:make_iq_result(IQ, #last{seconds = 0})
|
2003-10-24 21:21:07 +02:00
|
|
|
end.
|
|
|
|
|
2017-02-18 07:36:27 +01:00
|
|
|
-spec register_user(binary(), binary()) -> any().
|
2016-06-08 13:02:02 +02:00
|
|
|
register_user(User, Server) ->
|
|
|
|
on_presence_update(
|
|
|
|
User,
|
|
|
|
Server,
|
|
|
|
<<"RegisterResource">>,
|
|
|
|
<<"Registered but didn't login">>).
|
|
|
|
|
2017-02-18 07:36:27 +01:00
|
|
|
-spec on_presence_update(binary(), binary(), binary(), binary()) -> any().
|
2005-04-17 20:08:34 +02:00
|
|
|
on_presence_update(User, Server, _Resource, Status) ->
|
2015-12-07 16:08:57 +01:00
|
|
|
TimeStamp = p1_time_compat:system_time(seconds),
|
2005-05-23 21:47:57 +02:00
|
|
|
store_last_info(User, Server, TimeStamp, Status).
|
|
|
|
|
2017-02-18 07:36:27 +01:00
|
|
|
-spec store_last_info(binary(), binary(), non_neg_integer(), binary()) -> any().
|
2005-05-23 21:47:57 +02:00
|
|
|
store_last_info(User, Server, TimeStamp, Status) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LUser = jid:nodeprep(User),
|
|
|
|
LServer = jid:nameprep(Server),
|
2016-04-13 08:59:39 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2017-05-18 12:21:17 +02:00
|
|
|
case use_cache(Mod, LServer) of
|
|
|
|
true ->
|
|
|
|
ets_cache:update(
|
|
|
|
?LAST_CACHE, {LUser, LServer}, {ok, {TimeStamp, Status}},
|
|
|
|
fun() ->
|
|
|
|
Mod:store_last_info(LUser, LServer, TimeStamp, Status)
|
|
|
|
end, cache_nodes(Mod, LServer));
|
|
|
|
false ->
|
|
|
|
Mod:store_last_info(LUser, LServer, TimeStamp, Status)
|
|
|
|
end.
|
2008-12-23 02:34:52 +01:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec get_last_info(binary(), binary()) -> {ok, non_neg_integer(), binary()} |
|
|
|
|
not_found.
|
2007-11-27 19:54:06 +01:00
|
|
|
get_last_info(LUser, LServer) ->
|
2010-11-05 18:32:25 +01:00
|
|
|
case get_last(LUser, LServer) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{error, _Reason} -> not_found;
|
|
|
|
Res -> Res
|
2007-11-27 19:54:06 +01:00
|
|
|
end.
|
2003-10-24 21:21:07 +02:00
|
|
|
|
2016-08-12 12:17:42 +02:00
|
|
|
-spec remove_user(binary(), binary()) -> any().
|
2005-04-17 20:08:34 +02:00
|
|
|
remove_user(User, Server) ->
|
2015-11-24 16:44:13 +01:00
|
|
|
LUser = jid:nodeprep(User),
|
|
|
|
LServer = jid:nameprep(Server),
|
2016-04-13 08:59:39 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2017-05-18 12:21:17 +02:00
|
|
|
Mod:remove_user(LUser, LServer),
|
|
|
|
ets_cache:delete(?LAST_CACHE, {LUser, LServer}, cache_nodes(Mod, LServer)).
|
|
|
|
|
|
|
|
-spec init_cache(module(), binary(), gen_mod:opts()) -> ok.
|
|
|
|
init_cache(Mod, Host, Opts) ->
|
|
|
|
case use_cache(Mod, Host) of
|
|
|
|
true ->
|
2018-01-23 08:54:52 +01:00
|
|
|
CacheOpts = cache_opts(Opts),
|
2017-05-18 12:21:17 +02:00
|
|
|
ets_cache:new(?LAST_CACHE, CacheOpts);
|
|
|
|
false ->
|
|
|
|
ets_cache:delete(?LAST_CACHE)
|
|
|
|
end.
|
|
|
|
|
2018-01-23 08:54:52 +01:00
|
|
|
-spec cache_opts(gen_mod:opts()) -> [proplists:property()].
|
|
|
|
cache_opts(Opts) ->
|
|
|
|
MaxSize = gen_mod:get_opt(cache_size, Opts),
|
|
|
|
CacheMissed = gen_mod:get_opt(cache_missed, Opts),
|
|
|
|
LifeTime = case gen_mod:get_opt(cache_life_time, Opts) of
|
2017-05-18 12:21:17 +02:00
|
|
|
infinity -> infinity;
|
|
|
|
I -> timer:seconds(I)
|
|
|
|
end,
|
|
|
|
[{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}].
|
|
|
|
|
|
|
|
-spec use_cache(module(), binary()) -> boolean().
|
|
|
|
use_cache(Mod, Host) ->
|
|
|
|
case erlang:function_exported(Mod, use_cache, 1) of
|
|
|
|
true -> Mod:use_cache(Host);
|
2018-01-23 08:54:52 +01:00
|
|
|
false -> gen_mod:get_module_opt(Host, ?MODULE, use_cache)
|
2017-05-18 12:21:17 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
-spec cache_nodes(module(), binary()) -> [node()].
|
|
|
|
cache_nodes(Mod, Host) ->
|
|
|
|
case erlang:function_exported(Mod, cache_nodes, 1) of
|
|
|
|
true -> Mod:cache_nodes(Host);
|
|
|
|
false -> ejabberd_cluster:get_nodes()
|
|
|
|
end.
|
2014-07-14 05:49:02 +02:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import_info() ->
|
|
|
|
[{<<"last">>, 3}].
|
2013-07-21 12:24:36 +02:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import_start(LServer, DBType) ->
|
|
|
|
Mod = gen_mod:db_mod(DBType, ?MODULE),
|
|
|
|
Mod:init(LServer, []).
|
|
|
|
|
|
|
|
import(LServer, {sql, _}, DBType, <<"last">>, [LUser, TimeStamp, State]) ->
|
|
|
|
TS = case TimeStamp of
|
|
|
|
<<"">> -> 0;
|
2016-11-23 08:41:26 +01:00
|
|
|
_ -> binary_to_integer(TimeStamp)
|
2016-11-22 14:48:01 +01:00
|
|
|
end,
|
|
|
|
LA = #last_activity{us = {LUser, LServer},
|
|
|
|
timestamp = TS,
|
|
|
|
status = State},
|
2016-04-13 08:59:39 +02:00
|
|
|
Mod = gen_mod:db_mod(DBType, ?MODULE),
|
|
|
|
Mod:import(LServer, LA).
|
2013-08-12 14:25:05 +02:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
export(LServer) ->
|
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:export(LServer).
|
|
|
|
|
2016-07-06 13:58:48 +02:00
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[].
|
|
|
|
|
2016-04-27 16:10:50 +02:00
|
|
|
mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
|
2017-05-18 12:21:17 +02:00
|
|
|
mod_opt_type(O) when O == cache_life_time; O == cache_size ->
|
|
|
|
fun (I) when is_integer(I), I > 0 -> I;
|
|
|
|
(infinity) -> infinity
|
|
|
|
end;
|
|
|
|
mod_opt_type(O) when O == use_cache; O == cache_missed ->
|
2018-01-23 08:54:52 +01:00
|
|
|
fun (B) when is_boolean(B) -> B end.
|
|
|
|
|
|
|
|
mod_options(Host) ->
|
2018-02-11 10:54:15 +01:00
|
|
|
[{db_type, ejabberd_config:default_db(Host, ?MODULE)},
|
2018-01-23 08:54:52 +01:00
|
|
|
{use_cache, ejabberd_config:use_cache(Host)},
|
|
|
|
{cache_size, ejabberd_config:cache_size(Host)},
|
|
|
|
{cache_missed, ejabberd_config:cache_missed(Host)},
|
|
|
|
{cache_life_time, ejabberd_config:cache_life_time(Host)}].
|