2016-04-13 16:37:52 +02:00
|
|
|
%%%-------------------------------------------------------------------
|
2016-12-27 10:44:07 +01:00
|
|
|
%%% File : mod_vcard_riak.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
|
|
|
%%%
|
|
|
|
%%%
|
2017-01-02 21:41:53 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2017 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_riak).
|
|
|
|
|
|
|
|
-behaviour(mod_vcard).
|
|
|
|
|
|
|
|
%% API
|
|
|
|
-export([init/2, 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, stop/1]).
|
|
|
|
-export([is_search_supported/1]).
|
2016-04-13 16:37:52 +02:00
|
|
|
|
2016-07-26 10:29:17 +02:00
|
|
|
-include("xmpp.hrl").
|
2016-04-13 16:37:52 +02:00
|
|
|
-include("mod_vcard.hrl").
|
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% API
|
|
|
|
%%%===================================================================
|
|
|
|
init(_Host, _Opts) ->
|
|
|
|
ok.
|
|
|
|
|
2016-07-29 16:39:13 +02:00
|
|
|
stop(_Host) ->
|
|
|
|
ok.
|
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
is_search_supported(_LServer) ->
|
|
|
|
false.
|
|
|
|
|
2016-04-13 16:37:52 +02:00
|
|
|
get_vcard(LUser, LServer) ->
|
|
|
|
case ejabberd_riak:get(vcard, vcard_schema(), {LUser, LServer}) of
|
|
|
|
{ok, R} ->
|
2017-05-17 16:13:34 +02:00
|
|
|
{ok, [R#vcard.vcard]};
|
2016-04-13 16:37:52 +02:00
|
|
|
{error, notfound} ->
|
2017-05-17 16:13:34 +02:00
|
|
|
{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}) ->
|
|
|
|
US = {LUser, LServer},
|
|
|
|
{atomic,
|
|
|
|
ejabberd_riak:put(#vcard{us = US, vcard = VCARD},
|
|
|
|
vcard_schema(),
|
|
|
|
[{'2i', [{<<"user">>, User},
|
|
|
|
{<<"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}]}])}.
|
|
|
|
|
|
|
|
search(_LServer, _Data, _AllowReturnAll, _MaxMatch) ->
|
|
|
|
[].
|
|
|
|
|
2016-07-29 16:39:13 +02:00
|
|
|
search_fields(_LServer) ->
|
|
|
|
[].
|
|
|
|
|
|
|
|
search_reported(_LServer) ->
|
|
|
|
[].
|
|
|
|
|
2016-04-13 16:37:52 +02:00
|
|
|
remove_user(LUser, LServer) ->
|
|
|
|
{atomic, ejabberd_riak:delete(vcard, {LUser, LServer})}.
|
|
|
|
|
2016-11-22 14:48:01 +01:00
|
|
|
import(LServer, <<"vcard">>, [LUser, XML, _TimeStamp]) ->
|
|
|
|
El = fxml_stream:parse_element(XML),
|
|
|
|
VCard = #vcard{us = {LUser, LServer}, vcard = El},
|
2016-04-13 16:37:52 +02:00
|
|
|
#vcard_search{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} =
|
|
|
|
mod_vcard:make_vcard_search(LUser, LUser, LServer, El),
|
|
|
|
ejabberd_riak:put(VCard, vcard_schema(),
|
|
|
|
[{'2i', [{<<"user">>, LUser},
|
|
|
|
{<<"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}]}]);
|
2016-11-22 14:48:01 +01:00
|
|
|
import(_LServer, <<"vcard_search">>, _) ->
|
2016-04-13 16:37:52 +02:00
|
|
|
ok.
|
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% Internal functions
|
|
|
|
%%%===================================================================
|
|
|
|
vcard_schema() ->
|
|
|
|
{record_info(fields, vcard), #vcard{}}.
|