2003-01-02 22:01:12 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_vcard.erl
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2012-04-27 11:52:05 +02:00
|
|
|
%%% Purpose : Vcard management
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Created : 2 Jan 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2023-01-09 17:09:06 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2023 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-01-02 22:01:12 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_vcard).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-12-24 13:58:05 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-01-02 22:01:12 +01:00
|
|
|
|
2015-05-21 17:02:36 +02:00
|
|
|
-protocol({xep, 54, '1.2'}).
|
|
|
|
-protocol({xep, 55, '1.3'}).
|
2022-11-04 11:34:45 +01:00
|
|
|
-protocol({xep, 153, '1.1'}).
|
2015-05-21 17:02:36 +02:00
|
|
|
|
2017-02-14 08:25:08 +01:00
|
|
|
-behaviour(gen_server).
|
2003-01-24 21:18:33 +01:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2020-01-08 10:24:51 +01:00
|
|
|
-export([start/2, stop/1, get_sm_features/5, mod_options/1, mod_doc/0,
|
2016-07-18 14:01:32 +02:00
|
|
|
process_local_iq/1, process_sm_iq/1, string2lower/1,
|
2016-11-22 14:48:01 +01:00
|
|
|
remove_user/2, export/1, import_info/0, import/5, import_start/2,
|
|
|
|
depends/2, process_search/1, process_vcard/1, get_vcard/2,
|
2016-07-18 14:01:32 +02:00
|
|
|
disco_items/5, disco_features/5, disco_identity/5,
|
2017-09-17 09:26:48 +02:00
|
|
|
vcard_iq_set/1, mod_opt_type/1, set_vcard/3, make_vcard_search/4]).
|
2017-02-14 10:39:26 +01:00
|
|
|
-export([init/1, handle_call/3, handle_cast/2,
|
2017-02-14 08:25:08 +01:00
|
|
|
handle_info/2, terminate/2, code_change/3]).
|
2019-07-06 11:30:57 +02:00
|
|
|
-export([route/1]).
|
2003-01-02 22:01:12 +01:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2020-09-03 13:45:57 +02:00
|
|
|
-include_lib("xmpp/include/xmpp.hrl").
|
2016-04-13 16:37:52 +02:00
|
|
|
-include("mod_vcard.hrl").
|
2018-01-08 09:29:17 +01:00
|
|
|
-include("translate.hrl").
|
2019-07-06 11:30:57 +02:00
|
|
|
-include("ejabberd_stacktrace.hrl").
|
2003-01-02 22:01:12 +01:00
|
|
|
|
2017-05-17 16:13:34 +02:00
|
|
|
-define(VCARD_CACHE, vcard_cache).
|
2003-10-28 21:26:43 +01:00
|
|
|
|
2016-04-13 16:37:52 +02:00
|
|
|
-callback init(binary(), gen_mod:opts()) -> any().
|
2016-07-29 16:39:13 +02:00
|
|
|
-callback stop(binary()) -> any().
|
2016-11-22 14:48:01 +01:00
|
|
|
-callback import(binary(), binary(), [binary()]) -> ok.
|
2017-05-17 16:13:34 +02:00
|
|
|
-callback get_vcard(binary(), binary()) -> {ok, [xmlel()]} | error.
|
2016-04-13 16:37:52 +02:00
|
|
|
-callback set_vcard(binary(), binary(),
|
|
|
|
xmlel(), #vcard_search{}) -> {atomic, any()}.
|
2016-07-29 16:39:13 +02:00
|
|
|
-callback search_fields(binary()) -> [{binary(), binary()}].
|
|
|
|
-callback search_reported(binary()) -> [{binary(), binary()}].
|
2016-04-13 16:37:52 +02:00
|
|
|
-callback search(binary(), [{binary(), [binary()]}], boolean(),
|
2016-07-29 16:39:13 +02:00
|
|
|
infinity | pos_integer()) -> [{binary(), binary()}].
|
2016-04-13 16:37:52 +02:00
|
|
|
-callback remove_user(binary(), binary()) -> {atomic, any()}.
|
2016-11-22 14:48:01 +01:00
|
|
|
-callback is_search_supported(binary()) -> boolean().
|
2017-05-17 16:13:34 +02:00
|
|
|
-callback use_cache(binary()) -> boolean().
|
|
|
|
-callback cache_nodes(binary()) -> [node()].
|
|
|
|
|
|
|
|
-optional_callbacks([use_cache/1, cache_nodes/1]).
|
2016-04-13 16:37:52 +02:00
|
|
|
|
2017-08-08 16:46:26 +02:00
|
|
|
-record(state, {hosts :: [binary()], server_host :: binary()}).
|
2017-02-14 08:25:08 +01:00
|
|
|
|
|
|
|
%%====================================================================
|
|
|
|
%% gen_mod callbacks
|
|
|
|
%%====================================================================
|
2005-06-20 05:18:13 +02:00
|
|
|
start(Host, Opts) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:start_child(?MODULE, Host, Opts).
|
2017-02-14 08:25:08 +01:00
|
|
|
|
|
|
|
stop(Host) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:stop_child(?MODULE, Host).
|
2017-02-14 08:25:08 +01:00
|
|
|
|
|
|
|
%%====================================================================
|
|
|
|
%% gen_server callbacks
|
|
|
|
%%====================================================================
|
2019-08-04 20:46:18 +02:00
|
|
|
init([Host|_]) ->
|
2017-02-14 08:25:08 +01:00
|
|
|
process_flag(trap_exit, true),
|
2019-08-04 20:46:18 +02:00
|
|
|
Opts = gen_mod:get_module_opts(Host, ?MODULE),
|
2019-06-14 11:33:26 +02:00
|
|
|
Mod = gen_mod:db_mod(Opts, ?MODULE),
|
2016-04-13 16:37:52 +02:00
|
|
|
Mod:init(Host, Opts),
|
2017-05-17 16:13:34 +02:00
|
|
|
init_cache(Mod, Host, Opts),
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:add(remove_user, Host, ?MODULE,
|
|
|
|
remove_user, 50),
|
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
|
2018-02-11 10:54:15 +01:00
|
|
|
?NS_VCARD, ?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_VCARD, ?MODULE, process_sm_iq),
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
|
|
|
|
get_sm_features, 50),
|
2017-09-17 09:26:48 +02:00
|
|
|
ejabberd_hooks:add(vcard_iq_set, Host, ?MODULE, vcard_iq_set, 50),
|
2019-06-14 11:33:26 +02:00
|
|
|
MyHosts = gen_mod:get_opt_hosts(Opts),
|
|
|
|
Search = mod_vcard_opt:search(Opts),
|
2016-07-18 14:01:32 +02:00
|
|
|
if Search ->
|
2017-08-08 16:46:26 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(MyHost) ->
|
|
|
|
ejabberd_hooks:add(
|
|
|
|
disco_local_items, MyHost, ?MODULE, disco_items, 100),
|
|
|
|
ejabberd_hooks:add(
|
|
|
|
disco_local_features, MyHost, ?MODULE, disco_features, 100),
|
|
|
|
ejabberd_hooks:add(
|
|
|
|
disco_local_identity, MyHost, ?MODULE, disco_identity, 100),
|
|
|
|
gen_iq_handler:add_iq_handler(
|
2018-02-11 10:54:15 +01:00
|
|
|
ejabberd_local, MyHost, ?NS_SEARCH, ?MODULE, process_search),
|
2017-08-08 16:46:26 +02:00
|
|
|
gen_iq_handler:add_iq_handler(
|
2018-02-11 10:54:15 +01:00
|
|
|
ejabberd_local, MyHost, ?NS_VCARD, ?MODULE, process_vcard),
|
2017-08-08 16:46:26 +02:00
|
|
|
gen_iq_handler:add_iq_handler(
|
|
|
|
ejabberd_local, MyHost, ?NS_DISCO_ITEMS, mod_disco,
|
2018-02-11 10:54:15 +01:00
|
|
|
process_local_iq_items),
|
2017-08-08 16:46:26 +02:00
|
|
|
gen_iq_handler:add_iq_handler(
|
|
|
|
ejabberd_local, MyHost, ?NS_DISCO_INFO, mod_disco,
|
2018-02-11 10:54:15 +01:00
|
|
|
process_local_iq_info),
|
2017-08-08 16:46:26 +02:00
|
|
|
case Mod:is_search_supported(Host) of
|
|
|
|
false ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?WARNING_MSG("vCard search functionality is "
|
2019-09-23 14:17:20 +02:00
|
|
|
"not implemented for ~ts backend",
|
2019-06-14 11:33:26 +02:00
|
|
|
[mod_vcard_opt:db_type(Opts)]);
|
2017-08-08 16:46:26 +02:00
|
|
|
true ->
|
2019-07-06 11:30:57 +02:00
|
|
|
ejabberd_router:register_route(
|
|
|
|
MyHost, Host, {apply, ?MODULE, route})
|
2017-08-08 16:46:26 +02:00
|
|
|
end
|
|
|
|
end, MyHosts);
|
2016-07-18 14:01:32 +02:00
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end,
|
2017-08-08 16:46:26 +02:00
|
|
|
{ok, #state{hosts = MyHosts, server_host = Host}}.
|
2003-01-02 22:01:12 +01:00
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
handle_call(Call, From, State) ->
|
|
|
|
?WARNING_MSG("Unexpected call from ~p: ~p", [From, Call]),
|
2017-02-14 08:25:08 +01:00
|
|
|
{noreply, State}.
|
|
|
|
|
|
|
|
handle_cast(Cast, State) ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?WARNING_MSG("Unexpected cast: ~p", [Cast]),
|
2017-02-14 08:25:08 +01:00
|
|
|
{noreply, State}.
|
|
|
|
|
2017-02-16 09:00:26 +01:00
|
|
|
handle_info({route, Packet}, State) ->
|
2019-07-06 11:30:57 +02:00
|
|
|
try route(Packet)
|
|
|
|
catch ?EX_RULE(Class, Reason, St) ->
|
|
|
|
StackTrace = ?EX_STACK(St),
|
2019-09-23 14:17:20 +02:00
|
|
|
?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts",
|
2019-07-06 11:30:57 +02:00
|
|
|
[xmpp:pp(Packet),
|
|
|
|
misc:format_exception(2, Class, Reason, StackTrace)])
|
2017-02-14 08:25:08 +01:00
|
|
|
end,
|
|
|
|
{noreply, State};
|
|
|
|
handle_info(Info, State) ->
|
2019-06-24 19:32:34 +02:00
|
|
|
?WARNING_MSG("Unexpected info: ~p", [Info]),
|
2017-02-14 08:25:08 +01:00
|
|
|
{noreply, State}.
|
|
|
|
|
2017-08-08 16:46:26 +02:00
|
|
|
terminate(_Reason, #state{hosts = MyHosts, server_host = Host}) ->
|
2017-02-14 08:25:08 +01:00
|
|
|
ejabberd_hooks:delete(remove_user, Host, ?MODULE, remove_user, 50),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_VCARD),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_VCARD),
|
|
|
|
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, get_sm_features, 50),
|
2017-09-17 09:26:48 +02:00
|
|
|
ejabberd_hooks:delete(vcard_iq_set, Host, ?MODULE, vcard_iq_set, 50),
|
2016-09-13 11:30:05 +02:00
|
|
|
Mod = gen_mod:db_mod(Host, ?MODULE),
|
2016-07-29 16:39:13 +02:00
|
|
|
Mod:stop(Host),
|
2017-08-08 16:46:26 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(MyHost) ->
|
|
|
|
ejabberd_router:unregister_route(MyHost),
|
|
|
|
ejabberd_hooks:delete(disco_local_items, MyHost, ?MODULE, disco_items, 100),
|
|
|
|
ejabberd_hooks:delete(disco_local_features, MyHost, ?MODULE, disco_features, 100),
|
|
|
|
ejabberd_hooks:delete(disco_local_identity, MyHost, ?MODULE, disco_identity, 100),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, MyHost, ?NS_SEARCH),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, MyHost, ?NS_VCARD),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, MyHost, ?NS_DISCO_ITEMS),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, MyHost, ?NS_DISCO_INFO)
|
|
|
|
end, MyHosts).
|
2017-02-14 08:25:08 +01:00
|
|
|
|
|
|
|
code_change(_OldVsn, State, _Extra) ->
|
|
|
|
{ok, State}.
|
2003-01-02 22:01:12 +01:00
|
|
|
|
2019-07-06 11:30:57 +02:00
|
|
|
-spec route(stanza()) -> ok.
|
|
|
|
route(#iq{} = IQ) ->
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:process_iq(IQ);
|
2019-07-06 11:30:57 +02:00
|
|
|
route(_) ->
|
2016-07-18 14:01:32 +02:00
|
|
|
ok.
|
|
|
|
|
2016-09-08 16:08:48 +02:00
|
|
|
-spec get_sm_features({error, stanza_error()} | empty | {result, [binary()]},
|
2016-08-05 07:41:08 +02:00
|
|
|
jid(), jid(), binary(), binary()) ->
|
2016-09-08 16:08:48 +02:00
|
|
|
{error, stanza_error()} | empty | {result, [binary()]}.
|
2013-03-14 10:33:02 +01:00
|
|
|
get_sm_features({error, _Error} = Acc, _From, _To,
|
|
|
|
_Node, _Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
Acc;
|
|
|
|
get_sm_features(Acc, _From, _To, Node, _Lang) ->
|
|
|
|
case Node of
|
2016-08-05 07:41:08 +02:00
|
|
|
<<"">> ->
|
2013-03-14 10:33:02 +01:00
|
|
|
case Acc of
|
|
|
|
{result, Features} ->
|
2018-06-13 13:55:06 +02:00
|
|
|
{result, [?NS_VCARD | Features]};
|
|
|
|
empty -> {result, [?NS_VCARD]}
|
2013-03-14 10:33:02 +01:00
|
|
|
end;
|
|
|
|
_ -> Acc
|
2003-01-02 22:01:12 +01:00
|
|
|
end.
|
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec process_local_iq(iq()) -> iq().
|
|
|
|
process_local_iq(#iq{type = set, lang = Lang} = IQ) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
|
2016-07-18 14:01:32 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
2019-08-02 12:55:48 +02:00
|
|
|
process_local_iq(#iq{type = get, to = To, lang = Lang} = IQ) ->
|
|
|
|
ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
|
|
|
|
VCard = case mod_vcard_opt:vcard(ServerHost) of
|
|
|
|
undefined ->
|
|
|
|
#vcard_temp{fn = <<"ejabberd">>,
|
|
|
|
url = ejabberd_config:get_uri(),
|
2021-01-11 20:18:28 +01:00
|
|
|
desc = misc:get_descr(Lang, ?T("Erlang XMPP Server")),
|
2019-08-02 12:55:48 +02:00
|
|
|
bday = <<"2002-11-16">>};
|
|
|
|
V ->
|
|
|
|
V
|
|
|
|
end,
|
|
|
|
xmpp:make_iq_result(IQ, VCard).
|
2016-07-18 14:01:32 +02:00
|
|
|
|
|
|
|
-spec process_sm_iq(iq()) -> iq().
|
2017-09-17 09:26:48 +02:00
|
|
|
process_sm_iq(#iq{type = set, lang = Lang, from = From} = IQ) ->
|
|
|
|
#jid{lserver = LServer} = From,
|
2019-06-14 11:33:26 +02:00
|
|
|
case lists:member(LServer, ejabberd_option:hosts()) of
|
2016-07-18 14:01:32 +02:00
|
|
|
true ->
|
2017-09-17 09:26:48 +02:00
|
|
|
case ejabberd_hooks:run_fold(vcard_iq_set, LServer, IQ, []) of
|
|
|
|
drop -> ignore;
|
|
|
|
#stanza_error{} = Err -> xmpp:make_error(IQ, Err);
|
|
|
|
_ -> xmpp:make_iq_result(IQ)
|
|
|
|
end;
|
2016-07-18 14:01:32 +02:00
|
|
|
false ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("The query is only allowed from local users"),
|
2016-07-18 14:01:32 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang))
|
|
|
|
end;
|
|
|
|
process_sm_iq(#iq{type = get, from = From, to = To, lang = Lang} = IQ) ->
|
|
|
|
#jid{luser = LUser, lserver = LServer} = To,
|
|
|
|
case get_vcard(LUser, LServer) of
|
|
|
|
error ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Database failure"),
|
2016-07-18 14:01:32 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang));
|
|
|
|
[] ->
|
|
|
|
xmpp:make_iq_result(IQ, #vcard_temp{});
|
|
|
|
Els ->
|
|
|
|
IQ#iq{type = result, to = From, from = To, sub_els = Els}
|
2012-04-27 11:52:05 +02:00
|
|
|
end.
|
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec process_vcard(iq()) -> iq().
|
|
|
|
process_vcard(#iq{type = set, lang = Lang} = IQ) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
|
2016-07-18 14:01:32 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_vcard(#iq{type = get, lang = Lang} = IQ) ->
|
|
|
|
xmpp:make_iq_result(
|
|
|
|
IQ, #vcard_temp{fn = <<"ejabberd/mod_vcard">>,
|
2018-06-14 13:00:47 +02:00
|
|
|
url = ejabberd_config:get_uri(),
|
2018-06-20 11:50:36 +02:00
|
|
|
desc = misc:get_descr(Lang, ?T("ejabberd vCard module"))}).
|
2016-07-18 14:01:32 +02:00
|
|
|
|
|
|
|
-spec process_search(iq()) -> iq().
|
|
|
|
process_search(#iq{type = get, to = To, lang = Lang} = IQ) ->
|
2016-07-29 16:39:13 +02:00
|
|
|
ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
|
|
|
|
xmpp:make_iq_result(IQ, mk_search_form(To, ServerHost, Lang));
|
2016-07-18 14:01:32 +02:00
|
|
|
process_search(#iq{type = set, to = To, lang = Lang,
|
|
|
|
sub_els = [#search{xdata = #xdata{type = submit,
|
|
|
|
fields = Fs}}]} = IQ) ->
|
|
|
|
ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
|
|
|
|
ResultXData = search_result(Lang, To, ServerHost, Fs),
|
|
|
|
xmpp:make_iq_result(IQ, #search{xdata = ResultXData});
|
|
|
|
process_search(#iq{type = set, lang = Lang} = IQ) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Incorrect data form"),
|
2016-07-18 14:01:32 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang)).
|
|
|
|
|
2016-09-08 16:08:48 +02:00
|
|
|
-spec disco_items({error, stanza_error()} | {result, [disco_item()]} | empty,
|
2016-08-05 07:41:08 +02:00
|
|
|
jid(), jid(), binary(), binary()) ->
|
2016-09-08 16:08:48 +02:00
|
|
|
{error, stanza_error()} | {result, [disco_item()]}.
|
2016-08-05 07:41:08 +02:00
|
|
|
disco_items(empty, _From, _To, <<"">>, _Lang) ->
|
2016-07-18 14:01:32 +02:00
|
|
|
{result, []};
|
|
|
|
disco_items(empty, _From, _To, _Node, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
{error, xmpp:err_item_not_found(?T("No services available"), Lang)};
|
2016-07-18 14:01:32 +02:00
|
|
|
disco_items(Acc, _From, _To, _Node, _Lang) ->
|
|
|
|
Acc.
|
|
|
|
|
2016-09-08 16:08:48 +02:00
|
|
|
-spec disco_features({error, stanza_error()} | {result, [binary()]} | empty,
|
2016-08-05 07:41:08 +02:00
|
|
|
jid(), jid(), binary(), binary()) ->
|
2016-09-08 16:08:48 +02:00
|
|
|
{error, stanza_error()} | {result, [binary()]}.
|
2016-07-18 14:01:32 +02:00
|
|
|
disco_features({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
|
|
|
|
Acc;
|
2016-08-05 07:41:08 +02:00
|
|
|
disco_features(Acc, _From, _To, <<"">>, _Lang) ->
|
2016-07-18 14:01:32 +02:00
|
|
|
Features = case Acc of
|
|
|
|
{result, Fs} -> Fs;
|
|
|
|
empty -> []
|
|
|
|
end,
|
|
|
|
{result, [?NS_DISCO_INFO, ?NS_DISCO_ITEMS,
|
|
|
|
?NS_VCARD, ?NS_SEARCH | Features]};
|
|
|
|
disco_features(empty, _From, _To, _Node, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No features available"),
|
2016-07-18 14:01:32 +02:00
|
|
|
{error, xmpp:err_item_not_found(Txt, Lang)};
|
|
|
|
disco_features(Acc, _From, _To, _Node, _Lang) ->
|
|
|
|
Acc.
|
|
|
|
|
2016-08-05 07:41:08 +02:00
|
|
|
-spec disco_identity([identity()], jid(), jid(),
|
|
|
|
binary(), binary()) -> [identity()].
|
2018-01-08 09:29:17 +01:00
|
|
|
disco_identity(Acc, _From, To, <<"">>, Lang) ->
|
|
|
|
Host = ejabberd_router:host_of_route(To#jid.lserver),
|
2019-06-14 11:33:26 +02:00
|
|
|
Name = mod_vcard_opt:name(Host),
|
2016-07-18 14:01:32 +02:00
|
|
|
[#identity{category = <<"directory">>,
|
|
|
|
type = <<"user">>,
|
2018-01-08 09:29:17 +01:00
|
|
|
name = translate:translate(Lang, Name)}|Acc];
|
2016-07-18 14:01:32 +02:00
|
|
|
disco_identity(Acc, _From, _To, _Node, _Lang) ->
|
|
|
|
Acc.
|
|
|
|
|
|
|
|
-spec get_vcard(binary(), binary()) -> [xmlel()] | error.
|
2012-04-27 11:52:05 +02:00
|
|
|
get_vcard(LUser, LServer) ->
|
2016-04-13 16:37:52 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2017-05-17 16:13:34 +02:00
|
|
|
Result = case use_cache(Mod, LServer) of
|
|
|
|
true ->
|
|
|
|
ets_cache:lookup(
|
|
|
|
?VCARD_CACHE, {LUser, LServer},
|
|
|
|
fun() -> Mod:get_vcard(LUser, LServer) end);
|
|
|
|
false ->
|
|
|
|
Mod:get_vcard(LUser, LServer)
|
|
|
|
end,
|
|
|
|
case Result of
|
|
|
|
{ok, Els} -> Els;
|
|
|
|
error -> error
|
|
|
|
end.
|
2003-01-02 22:01:12 +01:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec make_vcard_search(binary(), binary(), binary(), xmlel()) -> #vcard_search{}.
|
2016-04-13 16:37:52 +02:00
|
|
|
make_vcard_search(User, LUser, LServer, VCARD) ->
|
2016-02-03 19:03:17 +01:00
|
|
|
FN = fxml:get_path_s(VCARD, [{elem, <<"FN">>}, cdata]),
|
|
|
|
Family = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"N">>}, {elem, <<"FAMILY">>}, cdata]),
|
2016-02-03 19:03:17 +01:00
|
|
|
Given = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"N">>}, {elem, <<"GIVEN">>}, cdata]),
|
2016-02-03 19:03:17 +01:00
|
|
|
Middle = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"N">>}, {elem, <<"MIDDLE">>}, cdata]),
|
2016-02-03 19:03:17 +01:00
|
|
|
Nickname = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"NICKNAME">>}, cdata]),
|
2016-02-03 19:03:17 +01:00
|
|
|
BDay = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"BDAY">>}, cdata]),
|
2016-02-03 19:03:17 +01:00
|
|
|
CTRY = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"ADR">>}, {elem, <<"CTRY">>}, cdata]),
|
2016-02-03 19:03:17 +01:00
|
|
|
Locality = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"ADR">>}, {elem, <<"LOCALITY">>},
|
|
|
|
cdata]),
|
2016-02-03 19:03:17 +01:00
|
|
|
EMail1 = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"EMAIL">>}, {elem, <<"USERID">>}, cdata]),
|
2016-02-03 19:03:17 +01:00
|
|
|
EMail2 = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"EMAIL">>}, cdata]),
|
2016-02-03 19:03:17 +01:00
|
|
|
OrgName = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"ORG">>}, {elem, <<"ORGNAME">>}, cdata]),
|
2016-02-03 19:03:17 +01:00
|
|
|
OrgUnit = fxml:get_path_s(VCARD,
|
2013-03-14 10:33:02 +01:00
|
|
|
[{elem, <<"ORG">>}, {elem, <<"ORGUNIT">>}, cdata]),
|
2004-03-08 21:20:15 +01:00
|
|
|
EMail = case EMail1 of
|
2013-03-14 10:33:02 +01:00
|
|
|
<<"">> -> EMail2;
|
|
|
|
_ -> EMail1
|
2004-03-08 21:20:15 +01:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
LFN = string2lower(FN),
|
|
|
|
LFamily = string2lower(Family),
|
|
|
|
LGiven = string2lower(Given),
|
|
|
|
LMiddle = string2lower(Middle),
|
2012-02-14 13:18:18 +01:00
|
|
|
LNickname = string2lower(Nickname),
|
2013-03-14 10:33:02 +01:00
|
|
|
LBDay = string2lower(BDay),
|
|
|
|
LCTRY = string2lower(CTRY),
|
2012-02-14 13:18:18 +01:00
|
|
|
LLocality = string2lower(Locality),
|
2013-03-14 10:33:02 +01:00
|
|
|
LEMail = string2lower(EMail),
|
|
|
|
LOrgName = string2lower(OrgName),
|
|
|
|
LOrgUnit = string2lower(OrgUnit),
|
2016-04-13 16:37:52 +02:00
|
|
|
US = {LUser, LServer},
|
|
|
|
#vcard_search{us = US,
|
|
|
|
user = {User, LServer},
|
|
|
|
luser = LUser, fn = FN,
|
|
|
|
lfn = LFN,
|
|
|
|
family = Family,
|
|
|
|
lfamily = LFamily,
|
|
|
|
given = Given,
|
|
|
|
lgiven = LGiven,
|
|
|
|
middle = Middle,
|
|
|
|
lmiddle = LMiddle,
|
|
|
|
nickname = Nickname,
|
|
|
|
lnickname = LNickname,
|
|
|
|
bday = BDay,
|
|
|
|
lbday = LBDay,
|
|
|
|
ctry = CTRY,
|
|
|
|
lctry = LCTRY,
|
|
|
|
locality = Locality,
|
|
|
|
llocality = LLocality,
|
|
|
|
email = EMail,
|
|
|
|
lemail = LEMail,
|
|
|
|
orgname = OrgName,
|
|
|
|
lorgname = LOrgName,
|
|
|
|
orgunit = OrgUnit,
|
|
|
|
lorgunit = LOrgUnit}.
|
|
|
|
|
2017-09-17 09:26:48 +02:00
|
|
|
-spec vcard_iq_set(iq()) -> iq() | {stop, stanza_error()}.
|
|
|
|
vcard_iq_set(#iq{from = From, lang = Lang, sub_els = [VCard]} = IQ) ->
|
|
|
|
#jid{user = User, lserver = LServer} = From,
|
|
|
|
case set_vcard(User, LServer, VCard) of
|
|
|
|
{error, badarg} ->
|
|
|
|
%% Should not be here?
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Nodeprep has failed"),
|
2017-09-17 09:26:48 +02:00
|
|
|
{stop, xmpp:err_internal_server_error(Txt, Lang)};
|
|
|
|
ok ->
|
|
|
|
IQ
|
|
|
|
end;
|
|
|
|
vcard_iq_set(Acc) ->
|
|
|
|
Acc.
|
|
|
|
|
2021-02-15 13:12:52 +01:00
|
|
|
-spec set_vcard(binary(), binary(), xmlel() | vcard_temp()) -> {error, badarg|binary()} | ok.
|
2016-04-13 16:37:52 +02:00
|
|
|
set_vcard(User, LServer, VCARD) ->
|
|
|
|
case jid:nodeprep(User) of
|
|
|
|
error ->
|
|
|
|
{error, badarg};
|
|
|
|
LUser ->
|
2017-09-17 09:26:48 +02:00
|
|
|
VCardEl = xmpp:encode(VCARD),
|
|
|
|
VCardSearch = make_vcard_search(User, LUser, LServer, VCardEl),
|
2016-04-13 16:37:52 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2021-02-15 13:12:52 +01:00
|
|
|
case Mod:set_vcard(LUser, LServer, VCardEl, VCardSearch) of
|
|
|
|
{atomic, ok} ->
|
|
|
|
ets_cache:delete(?VCARD_CACHE, {LUser, LServer},
|
2017-05-17 16:13:34 +02:00
|
|
|
cache_nodes(Mod, LServer)),
|
2021-02-15 13:12:52 +01:00
|
|
|
ok;
|
|
|
|
{atomic, Error} ->
|
|
|
|
{error, Error}
|
|
|
|
end
|
2003-10-20 20:23:30 +02:00
|
|
|
end.
|
2003-01-02 22:01:12 +01:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec string2lower(binary()) -> binary().
|
2012-02-14 13:18:18 +01:00
|
|
|
string2lower(String) ->
|
2021-04-29 14:21:37 +02:00
|
|
|
case stringprep:tolower_nofilter(String) of
|
2013-03-14 10:33:02 +01:00
|
|
|
Lower when is_binary(Lower) -> Lower;
|
2021-04-29 14:21:37 +02:00
|
|
|
error -> String
|
2012-02-14 13:18:18 +01:00
|
|
|
end.
|
|
|
|
|
2016-08-05 07:41:08 +02:00
|
|
|
-spec mk_tfield(binary(), binary(), binary()) -> xdata_field().
|
2016-07-18 14:01:32 +02:00
|
|
|
mk_tfield(Label, Var, Lang) ->
|
|
|
|
#xdata_field{type = 'text-single',
|
|
|
|
label = translate:translate(Lang, Label),
|
|
|
|
var = Var}.
|
|
|
|
|
|
|
|
-spec mk_field(binary(), binary()) -> xdata_field().
|
|
|
|
mk_field(Var, Val) ->
|
|
|
|
#xdata_field{var = Var, values = [Val]}.
|
|
|
|
|
2016-08-05 07:41:08 +02:00
|
|
|
-spec mk_search_form(jid(), binary(), binary()) -> search().
|
2016-07-29 16:39:13 +02:00
|
|
|
mk_search_form(JID, ServerHost, Lang) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Title = <<(translate:translate(Lang, ?T("Search users in ")))/binary,
|
2017-02-26 08:07:12 +01:00
|
|
|
(jid:encode(JID))/binary>>,
|
2016-07-29 16:39:13 +02:00
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
SearchFields = Mod:search_fields(ServerHost),
|
|
|
|
Fs = [mk_tfield(Label, Var, Lang) || {Label, Var} <- SearchFields],
|
2016-07-18 14:01:32 +02:00
|
|
|
X = #xdata{type = form,
|
|
|
|
title = Title,
|
2019-05-17 15:24:18 +02:00
|
|
|
instructions = [make_instructions(Mod, Lang)],
|
2016-07-18 14:01:32 +02:00
|
|
|
fields = Fs},
|
|
|
|
#search{instructions =
|
|
|
|
translate:translate(
|
2019-06-22 16:08:45 +02:00
|
|
|
Lang, ?T("You need an x:data capable client to search")),
|
2016-07-18 14:01:32 +02:00
|
|
|
xdata = X}.
|
|
|
|
|
2019-07-10 09:31:51 +02:00
|
|
|
-spec make_instructions(module(), binary()) -> binary().
|
2019-05-17 15:24:18 +02:00
|
|
|
make_instructions(Mod, Lang) ->
|
|
|
|
Fill = translate:translate(
|
|
|
|
Lang,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Fill in the form to search for any matching "
|
2021-01-11 20:18:28 +01:00
|
|
|
"XMPP User")),
|
2019-05-17 15:24:18 +02:00
|
|
|
Add = translate:translate(
|
|
|
|
Lang,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T(" (Add * to the end of field to match substring)")),
|
2019-05-17 15:24:18 +02:00
|
|
|
case Mod of
|
|
|
|
mod_vcard_mnesia -> Fill;
|
|
|
|
_ -> str:concat(Fill, Add)
|
|
|
|
end.
|
|
|
|
|
2016-08-05 07:41:08 +02:00
|
|
|
-spec search_result(binary(), jid(), binary(), [xdata_field()]) -> xdata().
|
2016-07-18 14:01:32 +02:00
|
|
|
search_result(Lang, JID, ServerHost, XFields) ->
|
2016-07-29 16:39:13 +02:00
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
Reported = [mk_tfield(Label, Var, Lang) ||
|
|
|
|
{Label, Var} <- Mod:search_reported(ServerHost)],
|
2016-07-18 14:01:32 +02:00
|
|
|
#xdata{type = result,
|
|
|
|
title = <<(translate:translate(Lang,
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Search Results for ")))/binary,
|
2017-02-26 08:07:12 +01:00
|
|
|
(jid:encode(JID))/binary>>,
|
2016-07-29 16:39:13 +02:00
|
|
|
reported = Reported,
|
|
|
|
items = lists:map(fun (Item) -> item_to_field(Item) end,
|
2016-07-18 14:01:32 +02:00
|
|
|
search(ServerHost, XFields))}.
|
|
|
|
|
2016-07-29 16:39:13 +02:00
|
|
|
-spec item_to_field([{binary(), binary()}]) -> [xdata_field()].
|
|
|
|
item_to_field(Items) ->
|
|
|
|
[mk_field(Var, Value) || {Var, Value} <- Items].
|
2016-07-18 14:01:32 +02:00
|
|
|
|
|
|
|
-spec search(binary(), [xdata_field()]) -> [binary()].
|
|
|
|
search(LServer, XFields) ->
|
|
|
|
Data = [{Var, Vals} || #xdata_field{var = Var, values = Vals} <- XFields],
|
2016-04-13 16:37:52 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2019-06-14 11:33:26 +02:00
|
|
|
AllowReturnAll = mod_vcard_opt:allow_return_all(LServer),
|
|
|
|
MaxMatch = mod_vcard_opt:matches(LServer),
|
2016-04-13 16:37:52 +02:00
|
|
|
Mod:search(LServer, Data, AllowReturnAll, MaxMatch).
|
2005-04-17 20:08:34 +02:00
|
|
|
|
2003-01-09 20:59:16 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2017-05-17 16:13:34 +02:00
|
|
|
-spec remove_user(binary(), binary()) -> ok.
|
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 16:37:52 +02:00
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
2017-05-17 16:13:34 +02:00
|
|
|
Mod:remove_user(LUser, LServer),
|
|
|
|
ets_cache:delete(?VCARD_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 ->
|
|
|
|
CacheOpts = cache_opts(Host, Opts),
|
|
|
|
ets_cache:new(?VCARD_CACHE, CacheOpts);
|
|
|
|
false ->
|
|
|
|
ets_cache:delete(?VCARD_CACHE)
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec cache_opts(binary(), gen_mod:opts()) -> [proplists:property()].
|
2018-01-23 08:54:52 +01:00
|
|
|
cache_opts(_Host, Opts) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
MaxSize = mod_vcard_opt:cache_size(Opts),
|
|
|
|
CacheMissed = mod_vcard_opt:cache_missed(Opts),
|
2019-06-15 11:53:16 +02:00
|
|
|
LifeTime = mod_vcard_opt:cache_life_time(Opts),
|
2017-05-17 16:13:34 +02:00
|
|
|
[{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);
|
2019-06-14 11:33:26 +02:00
|
|
|
false -> mod_vcard_opt:use_cache(Host)
|
2017-05-17 16:13:34 +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.
|
2005-04-17 20:08:34 +02:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import_info() ->
|
|
|
|
[{<<"vcard">>, 3}, {<<"vcard_search">>, 24}].
|
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, []).
|
2013-07-21 12:24:36 +02:00
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import(LServer, {sql, _}, DBType, Tab, L) ->
|
2016-04-13 16:37:52 +02:00
|
|
|
Mod = gen_mod:db_mod(DBType, ?MODULE),
|
2016-11-22 14:48:01 +01:00
|
|
|
Mod:import(LServer, Tab, L).
|
|
|
|
|
|
|
|
export(LServer) ->
|
|
|
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
|
|
|
Mod:export(LServer).
|
2015-06-01 14:38:27 +02:00
|
|
|
|
2016-07-06 13:58:48 +02:00
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[].
|
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(allow_return_all) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:bool();
|
|
|
|
mod_opt_type(name) ->
|
|
|
|
econf:binary();
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(matches) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:pos_int(infinity);
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(search) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:bool();
|
|
|
|
mod_opt_type(host) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:host();
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(hosts) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:hosts();
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(db_type) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:db_type(?MODULE);
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(use_cache) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:bool();
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(cache_size) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:pos_int(infinity);
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(cache_missed) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:bool();
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(cache_life_time) ->
|
2019-08-02 12:55:48 +02:00
|
|
|
econf:timeout(second, infinity);
|
|
|
|
mod_opt_type(vcard) ->
|
|
|
|
econf:vcard_temp().
|
2018-01-23 08:54:52 +01:00
|
|
|
|
|
|
|
mod_options(Host) ->
|
|
|
|
[{allow_return_all, false},
|
2019-06-14 11:33:26 +02:00
|
|
|
{host, <<"vjud.", Host/binary>>},
|
2018-01-23 08:54:52 +01:00
|
|
|
{hosts, []},
|
|
|
|
{matches, 30},
|
|
|
|
{search, false},
|
|
|
|
{name, ?T("vCard User Search")},
|
2019-08-02 12:55:48 +02:00
|
|
|
{vcard, undefined},
|
2018-01-23 08:54:52 +01:00
|
|
|
{db_type, ejabberd_config:default_db(Host, ?MODULE)},
|
2019-06-14 11:33:26 +02:00
|
|
|
{use_cache, ejabberd_option:use_cache(Host)},
|
|
|
|
{cache_size, ejabberd_option:cache_size(Host)},
|
|
|
|
{cache_missed, ejabberd_option:cache_missed(Host)},
|
|
|
|
{cache_life_time, ejabberd_option:cache_life_time(Host)}].
|
2020-01-08 10:24:51 +01:00
|
|
|
|
|
|
|
mod_doc() ->
|
|
|
|
#{desc =>
|
|
|
|
?T("This module allows end users to store and retrieve "
|
|
|
|
"their vCard, and to retrieve other users vCards, "
|
|
|
|
"as defined in https://xmpp.org/extensions/xep-0054.html"
|
|
|
|
"[XEP-0054: vcard-temp]. The module also implements an "
|
|
|
|
"uncomplicated Jabber User Directory based on the vCards "
|
|
|
|
"of these users. Moreover, it enables the server to send "
|
|
|
|
"its vCard when queried."),
|
|
|
|
opts =>
|
|
|
|
[{allow_return_all,
|
|
|
|
#{value => "true | false",
|
|
|
|
desc =>
|
|
|
|
?T("This option enables you to specify if search "
|
|
|
|
"operations with empty input fields should return "
|
|
|
|
"all users who added some information to their vCard. "
|
|
|
|
"The default value is 'false'.")}},
|
|
|
|
{host,
|
|
|
|
#{desc => ?T("Deprecated. Use 'hosts' instead.")}},
|
|
|
|
{hosts,
|
|
|
|
#{value => ?T("[Host, ...]"),
|
|
|
|
desc =>
|
|
|
|
?T("This option defines the Jabber IDs of the service. "
|
|
|
|
"If the 'hosts' option is not specified, the only Jabber ID will "
|
|
|
|
"be the hostname of the virtual host with the prefix \"vjud.\". "
|
|
|
|
"The keyword '@HOST@' is replaced with the real virtual host name.")}},
|
|
|
|
{name,
|
|
|
|
#{value => ?T("Name"),
|
|
|
|
desc =>
|
|
|
|
?T("The value of the service name. This name is only visible in some "
|
|
|
|
"clients that support https://xmpp.org/extensions/xep-0030.html"
|
|
|
|
"[XEP-0030: Service Discovery]. The default is 'vCard User Search'.")}},
|
|
|
|
{matches,
|
|
|
|
#{value => "pos_integer() | infinity",
|
|
|
|
desc =>
|
|
|
|
?T("With this option, the number of reported search results "
|
|
|
|
"can be limited. If the option's value is set to 'infinity', "
|
|
|
|
"all search results are reported. The default value is '30'.")}},
|
|
|
|
{search,
|
|
|
|
#{value => "true | false",
|
|
|
|
desc =>
|
|
|
|
?T("This option specifies whether the search functionality "
|
|
|
|
"is enabled or not. If disabled, the options 'hosts', 'name' "
|
|
|
|
"and 'vcard' will be ignored and the Jabber User Directory "
|
|
|
|
"service will not appear in the Service Discovery item list. "
|
|
|
|
"The default value is 'false'.")}},
|
|
|
|
{db_type,
|
|
|
|
#{value => "mnesia | sql | ldap",
|
|
|
|
desc =>
|
2021-08-21 18:31:21 +02:00
|
|
|
?T("Same as top-level _`default_db`_ option, but applied to this module only.")}},
|
2020-01-08 10:24:51 +01:00
|
|
|
{use_cache,
|
|
|
|
#{value => "true | false",
|
|
|
|
desc =>
|
2021-08-21 18:31:21 +02:00
|
|
|
?T("Same as top-level _`use_cache`_ option, but applied to this module only.")}},
|
2020-01-08 10:24:51 +01:00
|
|
|
{cache_size,
|
|
|
|
#{value => "pos_integer() | infinity",
|
|
|
|
desc =>
|
2021-08-21 18:31:21 +02:00
|
|
|
?T("Same as top-level _`cache_size`_ option, but applied to this module only.")}},
|
2020-01-08 10:24:51 +01:00
|
|
|
{cache_missed,
|
|
|
|
#{value => "true | false",
|
|
|
|
desc =>
|
2021-08-21 18:31:21 +02:00
|
|
|
?T("Same as top-level _`cache_missed`_ option, but applied to this module only.")}},
|
2020-01-08 10:24:51 +01:00
|
|
|
{cache_life_time,
|
|
|
|
#{value => "timeout()",
|
|
|
|
desc =>
|
2021-08-21 18:31:21 +02:00
|
|
|
?T("Same as top-level _`cache_life_time`_ option, but applied to this module only.")}},
|
2020-01-08 10:24:51 +01:00
|
|
|
{vcard,
|
|
|
|
#{value => ?T("vCard"),
|
|
|
|
desc =>
|
|
|
|
?T("A custom vCard of the server that will be displayed "
|
|
|
|
"by some XMPP clients in Service Discovery. The value of "
|
|
|
|
"'vCard' is a YAML map constructed from an XML representation "
|
|
|
|
"of vCard. Since the representation has no attributes, "
|
|
|
|
"the mapping is straightforward."),
|
|
|
|
example =>
|
|
|
|
[{?T("For example, the following XML representation of vCard:"),
|
|
|
|
["<vCard xmlns='vcard-temp'>",
|
|
|
|
" <FN>Conferences</FN>",
|
|
|
|
" <ADR>",
|
|
|
|
" <WORK/>",
|
|
|
|
" <STREET>Elm Street</STREET>",
|
|
|
|
" </ADR>",
|
|
|
|
"</vCard>"]},
|
|
|
|
{?T("will be translated to:"),
|
|
|
|
["vcard:",
|
|
|
|
" fn: Conferences",
|
|
|
|
" adr:",
|
|
|
|
" -",
|
|
|
|
" work: true",
|
|
|
|
" street: Elm Street"]}]}}]}.
|