2016-04-13 16:37:52 +02:00
|
|
|
%%%-------------------------------------------------------------------
|
2016-12-27 10:44:07 +01:00
|
|
|
%%% File : mod_vcard_sql.erl
|
|
|
|
%%% Author : Evgeny Khramtsov <ekhramtsov@process-one.net>
|
2016-04-13 16:37:52 +02:00
|
|
|
%%% Created : 13 Apr 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
|
2016-12-27 10:44:07 +01:00
|
|
|
%%%
|
|
|
|
%%%
|
2024-01-22 16:40:01 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2024 ProcessOne
|
2016-12-27 10:44:07 +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.
|
|
|
|
%%%
|
|
|
|
%%% 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.
|
|
|
|
%%%
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
2016-04-13 16:37:52 +02:00
|
|
|
-module(mod_vcard_sql).
|
|
|
|
|
|
|
|
|
|
|
|
-behaviour(mod_vcard).
|
|
|
|
|
|
|
|
%% API
|
2016-07-29 16:39:13 +02:00
|
|
|
-export([init/2, stop/1, get_vcard/2, set_vcard/4, search/4, remove_user/2,
|
2016-11-22 14:48:01 +01:00
|
|
|
search_fields/1, search_reported/1, import/3, export/1]).
|
|
|
|
-export([is_search_supported/1]).
|
2024-01-24 20:49:59 +01:00
|
|
|
-export([sql_schemas/0]).
|
2016-04-13 16:37:52 +02:00
|
|
|
|
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").
|
|
|
|
-include("logger.hrl").
|
|
|
|
-include("ejabberd_sql_pt.hrl").
|
2017-09-24 11:42:35 +02:00
|
|
|
-include("translate.hrl").
|
2016-04-13 16:37:52 +02:00
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% API
|
|
|
|
%%%===================================================================
|
2023-09-28 02:37:36 +02:00
|
|
|
init(Host, _Opts) ->
|
2024-01-24 20:49:59 +01:00
|
|
|
ejabberd_sql_schema:update_schema(Host, ?MODULE, sql_schemas()),
|
2016-04-13 16:37:52 +02:00
|
|
|
ok.
|
|
|
|
|
2024-01-24 20:49:59 +01:00
|
|
|
sql_schemas() ->
|
2023-09-28 02:37:36 +02:00
|
|
|
[#sql_schema{
|
|
|
|
version = 1,
|
|
|
|
tables =
|
|
|
|
[#sql_table{
|
|
|
|
name = <<"vcard">>,
|
|
|
|
columns =
|
|
|
|
[#sql_column{name = <<"username">>, type = text},
|
|
|
|
#sql_column{name = <<"server_host">>, type = text},
|
|
|
|
#sql_column{name = <<"vcard">>, type = {text, big}},
|
|
|
|
#sql_column{name = <<"created_at">>, type = timestamp,
|
|
|
|
default = true}],
|
|
|
|
indices = [#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"username">>],
|
|
|
|
unique = true}]},
|
|
|
|
#sql_table{
|
|
|
|
name = <<"vcard_search">>,
|
|
|
|
columns =
|
|
|
|
[#sql_column{name = <<"username">>, type = text},
|
|
|
|
#sql_column{name = <<"lusername">>, type = text},
|
|
|
|
#sql_column{name = <<"server_host">>, type = text},
|
|
|
|
#sql_column{name = <<"fn">>, type = text},
|
|
|
|
#sql_column{name = <<"lfn">>, type = text},
|
|
|
|
#sql_column{name = <<"family">>, type = text},
|
|
|
|
#sql_column{name = <<"lfamily">>, type = text},
|
|
|
|
#sql_column{name = <<"given">>, type = text},
|
|
|
|
#sql_column{name = <<"lgiven">>, type = text},
|
|
|
|
#sql_column{name = <<"middle">>, type = text},
|
|
|
|
#sql_column{name = <<"lmiddle">>, type = text},
|
|
|
|
#sql_column{name = <<"nickname">>, type = text},
|
|
|
|
#sql_column{name = <<"lnickname">>, type = text},
|
|
|
|
#sql_column{name = <<"bday">>, type = text},
|
|
|
|
#sql_column{name = <<"lbday">>, type = text},
|
|
|
|
#sql_column{name = <<"ctry">>, type = text},
|
|
|
|
#sql_column{name = <<"lctry">>, type = text},
|
|
|
|
#sql_column{name = <<"locality">>, type = text},
|
|
|
|
#sql_column{name = <<"llocality">>, type = text},
|
|
|
|
#sql_column{name = <<"email">>, type = text},
|
|
|
|
#sql_column{name = <<"lemail">>, type = text},
|
|
|
|
#sql_column{name = <<"orgname">>, type = text},
|
|
|
|
#sql_column{name = <<"lorgname">>, type = text},
|
|
|
|
#sql_column{name = <<"orgunit">>, type = text},
|
|
|
|
#sql_column{name = <<"lorgunit">>, type = text}],
|
|
|
|
indices = [#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lusername">>],
|
|
|
|
unique = true},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lfn">>]},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lfamily">>]},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lgiven">>]},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lmiddle">>]},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lnickname">>]},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lbday">>]},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lctry">>]},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"llocality">>]},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lemail">>]},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lorgname">>]},
|
|
|
|
#sql_index{
|
|
|
|
columns = [<<"server_host">>, <<"lorgunit">>]}]}]}].
|
|
|
|
|
2016-07-29 16:39:13 +02:00
|
|
|
stop(_Host) ->
|
|
|
|
ok.
|
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
is_search_supported(_LServer) ->
|
|
|
|
true.
|
|
|
|
|
2016-04-13 16:37:52 +02:00
|
|
|
get_vcard(LUser, LServer) ->
|
2017-05-23 11:25:13 +02:00
|
|
|
case ejabberd_sql:sql_query(
|
|
|
|
LServer,
|
2017-11-02 15:03:30 +01:00
|
|
|
?SQL("select @(vcard)s from vcard"
|
|
|
|
" where username=%(LUser)s and %(LServer)H")) of
|
2016-04-13 16:37:52 +02:00
|
|
|
{selected, [{SVCARD}]} ->
|
|
|
|
case fxml_stream:parse_element(SVCARD) of
|
|
|
|
{error, _Reason} -> error;
|
2017-05-17 16:13:34 +02:00
|
|
|
VCARD -> {ok, [VCARD]}
|
2016-04-13 16:37:52 +02:00
|
|
|
end;
|
2017-05-17 16:13:34 +02:00
|
|
|
{selected, []} -> {ok, []};
|
2016-04-13 16:37:52 +02:00
|
|
|
_ -> error
|
|
|
|
end.
|
|
|
|
|
|
|
|
set_vcard(LUser, LServer, VCARD,
|
|
|
|
#vcard_search{user = {User, _},
|
|
|
|
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}) ->
|
|
|
|
SVCARD = fxml:element_to_binary(VCARD),
|
2017-05-23 11:25:13 +02:00
|
|
|
ejabberd_sql:sql_transaction(
|
|
|
|
LServer,
|
|
|
|
fun() ->
|
|
|
|
?SQL_UPSERT(LServer, "vcard",
|
|
|
|
["!username=%(LUser)s",
|
2017-11-02 15:03:30 +01:00
|
|
|
"!server_host=%(LServer)s",
|
2017-05-23 11:25:13 +02:00
|
|
|
"vcard=%(SVCARD)s"]),
|
|
|
|
?SQL_UPSERT(LServer, "vcard_search",
|
|
|
|
["username=%(User)s",
|
|
|
|
"!lusername=%(LUser)s",
|
2017-11-02 15:03:30 +01:00
|
|
|
"!server_host=%(LServer)s",
|
2017-05-23 11:25:13 +02:00
|
|
|
"fn=%(FN)s",
|
|
|
|
"lfn=%(LFN)s",
|
2019-10-30 07:11:13 +01:00
|
|
|
"family=%(Family)s",
|
2017-05-23 11:25:13 +02:00
|
|
|
"lfamily=%(LFamily)s",
|
|
|
|
"given=%(Given)s",
|
|
|
|
"lgiven=%(LGiven)s",
|
|
|
|
"middle=%(Middle)s",
|
|
|
|
"lmiddle=%(LMiddle)s",
|
|
|
|
"nickname=%(Nickname)s",
|
|
|
|
"lnickname=%(LNickname)s",
|
|
|
|
"bday=%(BDay)s",
|
|
|
|
"lbday=%(LBDay)s",
|
|
|
|
"ctry=%(CTRY)s",
|
|
|
|
"lctry=%(LCTRY)s",
|
|
|
|
"locality=%(Locality)s",
|
|
|
|
"llocality=%(LLocality)s",
|
|
|
|
"email=%(EMail)s",
|
|
|
|
"lemail=%(LEMail)s",
|
|
|
|
"orgname=%(OrgName)s",
|
|
|
|
"lorgname=%(LOrgName)s",
|
|
|
|
"orgunit=%(OrgUnit)s",
|
|
|
|
"lorgunit=%(LOrgUnit)s"])
|
|
|
|
end).
|
2016-04-13 16:37:52 +02:00
|
|
|
|
|
|
|
search(LServer, Data, AllowReturnAll, MaxMatch) ->
|
|
|
|
MatchSpec = make_matchspec(LServer, Data),
|
|
|
|
if (MatchSpec == <<"">>) and not AllowReturnAll -> [];
|
|
|
|
true ->
|
|
|
|
Limit = case MaxMatch of
|
|
|
|
infinity ->
|
|
|
|
<<"">>;
|
|
|
|
Val ->
|
2016-09-24 22:34:28 +02:00
|
|
|
[<<" LIMIT ">>, integer_to_binary(Val)]
|
2016-04-13 16:37:52 +02:00
|
|
|
end,
|
2016-04-20 11:27:32 +02:00
|
|
|
case catch ejabberd_sql:sql_query(
|
2016-04-13 16:37:52 +02:00
|
|
|
LServer,
|
2019-10-30 07:11:13 +01:00
|
|
|
[<<"select username, fn, family, given, "
|
2016-04-13 16:37:52 +02:00
|
|
|
"middle, nickname, bday, ctry, "
|
|
|
|
"locality, email, orgname, orgunit "
|
|
|
|
"from vcard_search ">>,
|
|
|
|
MatchSpec, Limit, <<";">>]) of
|
|
|
|
{selected,
|
|
|
|
[<<"username">>, <<"fn">>, <<"family">>, <<"given">>,
|
|
|
|
<<"middle">>, <<"nickname">>, <<"bday">>, <<"ctry">>,
|
|
|
|
<<"locality">>, <<"email">>, <<"orgname">>,
|
|
|
|
<<"orgunit">>], Rs} when is_list(Rs) ->
|
2016-07-29 16:39:13 +02:00
|
|
|
[row_to_item(LServer, R) || R <- Rs];
|
2016-04-13 16:37:52 +02:00
|
|
|
Error ->
|
|
|
|
?ERROR_MSG("~p", [Error]), []
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
2016-07-29 16:39:13 +02:00
|
|
|
search_fields(_LServer) ->
|
2017-09-24 11:42:35 +02:00
|
|
|
[{?T("User"), <<"user">>},
|
|
|
|
{?T("Full Name"), <<"fn">>},
|
|
|
|
{?T("Name"), <<"first">>},
|
|
|
|
{?T("Middle Name"), <<"middle">>},
|
|
|
|
{?T("Family Name"), <<"last">>},
|
|
|
|
{?T("Nickname"), <<"nick">>},
|
|
|
|
{?T("Birthday"), <<"bday">>},
|
|
|
|
{?T("Country"), <<"ctry">>},
|
|
|
|
{?T("City"), <<"locality">>},
|
|
|
|
{?T("Email"), <<"email">>},
|
|
|
|
{?T("Organization Name"), <<"orgname">>},
|
|
|
|
{?T("Organization Unit"), <<"orgunit">>}].
|
2016-07-29 16:39:13 +02:00
|
|
|
|
|
|
|
search_reported(_LServer) ->
|
2017-09-24 11:42:35 +02:00
|
|
|
[{?T("Jabber ID"), <<"jid">>},
|
|
|
|
{?T("Full Name"), <<"fn">>},
|
|
|
|
{?T("Name"), <<"first">>},
|
|
|
|
{?T("Middle Name"), <<"middle">>},
|
|
|
|
{?T("Family Name"), <<"last">>},
|
|
|
|
{?T("Nickname"), <<"nick">>},
|
|
|
|
{?T("Birthday"), <<"bday">>},
|
|
|
|
{?T("Country"), <<"ctry">>},
|
|
|
|
{?T("City"), <<"locality">>},
|
|
|
|
{?T("Email"), <<"email">>},
|
|
|
|
{?T("Organization Name"), <<"orgname">>},
|
|
|
|
{?T("Organization Unit"), <<"orgunit">>}].
|
2016-07-29 16:39:13 +02:00
|
|
|
|
2016-04-13 16:37:52 +02:00
|
|
|
remove_user(LUser, LServer) ->
|
2016-04-20 11:27:32 +02:00
|
|
|
ejabberd_sql:sql_transaction(
|
2016-04-13 16:37:52 +02:00
|
|
|
LServer,
|
|
|
|
fun() ->
|
2016-04-20 11:27:32 +02:00
|
|
|
ejabberd_sql:sql_query_t(
|
2017-11-02 15:03:30 +01:00
|
|
|
?SQL("delete from vcard"
|
|
|
|
" where username=%(LUser)s and %(LServer)H")),
|
2016-04-20 11:27:32 +02:00
|
|
|
ejabberd_sql:sql_query_t(
|
2017-11-02 15:03:30 +01:00
|
|
|
?SQL("delete from vcard_search"
|
|
|
|
" where lusername=%(LUser)s and %(LServer)H"))
|
2016-04-13 16:37:52 +02:00
|
|
|
end).
|
|
|
|
|
2024-08-21 23:30:00 +02:00
|
|
|
export(_Server) ->
|
2016-04-13 16:37:52 +02:00
|
|
|
[{vcard,
|
|
|
|
fun(Host, #vcard{us = {LUser, LServer}, vcard = VCARD})
|
|
|
|
when LServer == Host ->
|
2016-05-04 20:01:05 +02:00
|
|
|
SVCARD = fxml:element_to_binary(VCARD),
|
2017-11-02 15:03:30 +01:00
|
|
|
[?SQL("delete from vcard"
|
|
|
|
" where username=%(LUser)s and %(LServer)H;"),
|
|
|
|
?SQL_INSERT("vcard",
|
|
|
|
["username=%(LUser)s",
|
|
|
|
"server_host=%(LServer)s",
|
|
|
|
"vcard=%(SVCARD)s"])];
|
2016-04-13 16:37:52 +02:00
|
|
|
(_Host, _R) ->
|
|
|
|
[]
|
|
|
|
end},
|
|
|
|
{vcard_search,
|
|
|
|
fun(Host, #vcard_search{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})
|
|
|
|
when LServer == Host ->
|
2017-11-02 15:03:30 +01:00
|
|
|
[?SQL("delete from vcard_search"
|
|
|
|
" where lusername=%(LUser)s and %(LServer)H;"),
|
|
|
|
?SQL_INSERT("vcard_search",
|
|
|
|
["username=%(User)s",
|
|
|
|
"lusername=%(LUser)s",
|
|
|
|
"server_host=%(LServer)s",
|
|
|
|
"fn=%(FN)s",
|
|
|
|
"lfn=%(LFN)s",
|
2019-10-30 07:11:13 +01:00
|
|
|
"family=%(Family)s",
|
2017-11-02 15:03:30 +01:00
|
|
|
"lfamily=%(LFamily)s",
|
|
|
|
"given=%(Given)s",
|
|
|
|
"lgiven=%(LGiven)s",
|
|
|
|
"middle=%(Middle)s",
|
|
|
|
"lmiddle=%(LMiddle)s",
|
|
|
|
"nickname=%(Nickname)s",
|
|
|
|
"lnickname=%(LNickname)s",
|
|
|
|
"bday=%(BDay)s",
|
|
|
|
"lbday=%(LBDay)s",
|
|
|
|
"ctry=%(CTRY)s",
|
|
|
|
"lctry=%(LCTRY)s",
|
|
|
|
"locality=%(Locality)s",
|
|
|
|
"llocality=%(LLocality)s",
|
|
|
|
"email=%(EMail)s",
|
|
|
|
"lemail=%(LEMail)s",
|
|
|
|
"orgname=%(OrgName)s",
|
|
|
|
"lorgname=%(LOrgName)s",
|
|
|
|
"orgunit=%(OrgUnit)s",
|
|
|
|
"lorgunit=%(LOrgUnit)s"])];
|
2016-04-13 16:37:52 +02:00
|
|
|
(_Host, _R) ->
|
|
|
|
[]
|
|
|
|
end}].
|
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import(_, _, _) ->
|
|
|
|
ok.
|
2016-04-13 16:37:52 +02:00
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% Internal functions
|
|
|
|
%%%===================================================================
|
|
|
|
make_matchspec(LServer, Data) ->
|
|
|
|
filter_fields(Data, <<"">>, LServer).
|
|
|
|
|
2017-11-02 15:03:30 +01:00
|
|
|
filter_fields([], Match, LServer) ->
|
2018-03-15 15:55:05 +01:00
|
|
|
case ejabberd_sql:use_new_schema() of
|
2017-11-02 15:03:30 +01:00
|
|
|
true ->
|
2019-12-16 04:52:06 +01:00
|
|
|
SQLType = ejabberd_option:sql_type(LServer),
|
|
|
|
SServer = ejabberd_sql:to_string_literal(SQLType, LServer),
|
2017-11-02 15:03:30 +01:00
|
|
|
case Match of
|
2019-12-16 04:52:06 +01:00
|
|
|
<<"">> -> [<<"where server_host=">>, SServer];
|
|
|
|
_ -> [<<" where server_host=">>, SServer, <<" and ">>, Match]
|
2017-11-02 15:03:30 +01:00
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
case Match of
|
|
|
|
<<"">> -> <<"">>;
|
|
|
|
_ -> [<<" where ">>, Match]
|
|
|
|
end
|
2016-04-13 16:37:52 +02:00
|
|
|
end;
|
|
|
|
filter_fields([{SVar, [Val]} | Ds], Match, LServer)
|
|
|
|
when is_binary(Val) and (Val /= <<"">>) ->
|
|
|
|
LVal = mod_vcard:string2lower(Val),
|
|
|
|
NewMatch = case SVar of
|
2019-12-16 04:52:06 +01:00
|
|
|
<<"user">> -> make_val(LServer, Match, <<"lusername">>, LVal);
|
|
|
|
<<"fn">> -> make_val(LServer, Match, <<"lfn">>, LVal);
|
|
|
|
<<"last">> -> make_val(LServer, Match, <<"lfamily">>, LVal);
|
|
|
|
<<"first">> -> make_val(LServer, Match, <<"lgiven">>, LVal);
|
|
|
|
<<"middle">> -> make_val(LServer, Match, <<"lmiddle">>, LVal);
|
|
|
|
<<"nick">> -> make_val(LServer, Match, <<"lnickname">>, LVal);
|
|
|
|
<<"bday">> -> make_val(LServer, Match, <<"lbday">>, LVal);
|
|
|
|
<<"ctry">> -> make_val(LServer, Match, <<"lctry">>, LVal);
|
2016-04-13 16:37:52 +02:00
|
|
|
<<"locality">> ->
|
2019-12-16 04:52:06 +01:00
|
|
|
make_val(LServer, Match, <<"llocality">>, LVal);
|
|
|
|
<<"email">> -> make_val(LServer, Match, <<"lemail">>, LVal);
|
|
|
|
<<"orgname">> -> make_val(LServer, Match, <<"lorgname">>, LVal);
|
|
|
|
<<"orgunit">> -> make_val(LServer, Match, <<"lorgunit">>, LVal);
|
2016-04-13 16:37:52 +02:00
|
|
|
_ -> Match
|
|
|
|
end,
|
|
|
|
filter_fields(Ds, NewMatch, LServer);
|
|
|
|
filter_fields([_ | Ds], Match, LServer) ->
|
|
|
|
filter_fields(Ds, Match, LServer).
|
|
|
|
|
2019-12-16 04:52:06 +01:00
|
|
|
make_val(LServer, Match, Field, Val) ->
|
2016-04-13 16:37:52 +02:00
|
|
|
Condition = case str:suffix(<<"*">>, Val) of
|
|
|
|
true ->
|
|
|
|
Val1 = str:substr(Val, 1, byte_size(Val) - 1),
|
2016-05-12 17:32:13 +02:00
|
|
|
SVal = <<(ejabberd_sql:escape(
|
|
|
|
ejabberd_sql:escape_like_arg_circumflex(
|
|
|
|
Val1)))/binary,
|
2016-04-13 16:37:52 +02:00
|
|
|
"%">>,
|
2016-05-12 17:32:13 +02:00
|
|
|
[Field, <<" LIKE '">>, SVal, <<"' ESCAPE '^'">>];
|
2016-04-13 16:37:52 +02:00
|
|
|
_ ->
|
2019-12-16 04:52:06 +01:00
|
|
|
SQLType = ejabberd_option:sql_type(LServer),
|
|
|
|
SVal = ejabberd_sql:to_string_literal(SQLType, Val),
|
|
|
|
[Field, <<" = ">>, SVal]
|
2016-04-13 16:37:52 +02:00
|
|
|
end,
|
|
|
|
case Match of
|
|
|
|
<<"">> -> Condition;
|
|
|
|
_ -> [Match, <<" and ">>, Condition]
|
|
|
|
end.
|
2016-07-29 16:39:13 +02:00
|
|
|
|
|
|
|
row_to_item(LServer, [Username, FN, Family, Given, Middle, Nickname, BDay,
|
|
|
|
CTRY, Locality, EMail, OrgName, OrgUnit]) ->
|
|
|
|
[{<<"jid">>, <<Username/binary, $@, LServer/binary>>},
|
|
|
|
{<<"fn">>, FN},
|
|
|
|
{<<"last">>, Family},
|
|
|
|
{<<"first">>, Given},
|
|
|
|
{<<"middle">>, Middle},
|
|
|
|
{<<"nick">>, Nickname},
|
|
|
|
{<<"bday">>, BDay},
|
|
|
|
{<<"ctry">>, CTRY},
|
|
|
|
{<<"locality">>, Locality},
|
|
|
|
{<<"email">>, EMail},
|
|
|
|
{<<"orgname">>, OrgName},
|
|
|
|
{<<"orgunit">>, OrgUnit}].
|