mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
*** empty log message ***
SVN Revision: 34
This commit is contained in:
parent
e23adaae38
commit
a99c52880e
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
-include_lib("mnemosyne/include/mnemosyne.hrl").
|
-include_lib("mnemosyne/include/mnemosyne.hrl").
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
|
-include("namespaces.hrl").
|
||||||
|
|
||||||
-record(roster, {uj,
|
-record(roster, {uj,
|
||||||
user,
|
user,
|
||||||
@ -40,7 +41,7 @@ init() ->
|
|||||||
mnesia:create_table(roster,[{disc_copies, [node()]},
|
mnesia:create_table(roster,[{disc_copies, [node()]},
|
||||||
{attributes, record_info(fields, roster)}]),
|
{attributes, record_info(fields, roster)}]),
|
||||||
mnesia:add_table_index(roster, user),
|
mnesia:add_table_index(roster, user),
|
||||||
ejabberd_local:register_iq_handler("jabber:iq:roster",
|
ejabberd_local:register_iq_handler(?NS_ROSTER,
|
||||||
?MODULE, process_iq),
|
?MODULE, process_iq),
|
||||||
loop().
|
loop().
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ process_iq_get(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
|
|||||||
{atomic, Items} ->
|
{atomic, Items} ->
|
||||||
XItems = lists:map(fun item_to_xml/1, Items),
|
XItems = lists:map(fun item_to_xml/1, Items),
|
||||||
{iq, ID, result, XMLNS, [{xmlelement, "query",
|
{iq, ID, result, XMLNS, [{xmlelement, "query",
|
||||||
[{"xmlns", "jabber:iq:roster"}],
|
[{"xmlns", ?NS_ROSTER}],
|
||||||
XItems}]};
|
XItems}]};
|
||||||
_ ->
|
_ ->
|
||||||
{iq, ID, error, XMLNS,
|
{iq, ID, error, XMLNS,
|
||||||
@ -244,9 +245,9 @@ push_item(User, From, Item) ->
|
|||||||
|
|
||||||
% TODO: don't push to those who not load roster
|
% TODO: don't push to those who not load roster
|
||||||
push_item(User, Resource, From, Item) ->
|
push_item(User, Resource, From, Item) ->
|
||||||
ResIQ = {iq, "", set, "jabber:iq:roster",
|
ResIQ = {iq, "", set, ?NS_ROSTER,
|
||||||
[{xmlelement, "query",
|
[{xmlelement, "query",
|
||||||
[{"xmlns", "jabber:iq:roster"}],
|
[{"xmlns", ?NS_ROSTER}],
|
||||||
[item_to_xml(Item)]}]},
|
[item_to_xml(Item)]}]},
|
||||||
ejabberd_router ! {route,
|
ejabberd_router ! {route,
|
||||||
From,
|
From,
|
||||||
|
@ -12,15 +12,26 @@
|
|||||||
|
|
||||||
-export([start/0, init/0,
|
-export([start/0, init/0,
|
||||||
process_local_iq/3,
|
process_local_iq/3,
|
||||||
process_sm_iq/3]).
|
process_sm_iq/3,
|
||||||
|
reindex_vcards/0]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("namespaces.hrl").
|
-include("namespaces.hrl").
|
||||||
|
|
||||||
|
|
||||||
-record(vcard_search, {user, fn, family, given, middle, nickname,
|
-record(vcard_search, {user, luser,
|
||||||
bday, ctry="", locality="", email,
|
fn, lfn,
|
||||||
orgname, orgunit}).
|
family, lfamily,
|
||||||
|
given, lgiven,
|
||||||
|
middle, lmiddle,
|
||||||
|
nickname, lnickname,
|
||||||
|
bday, lbday,
|
||||||
|
ctry, lctry,
|
||||||
|
locality, llocality,
|
||||||
|
email, lemail,
|
||||||
|
orgname, lorgname,
|
||||||
|
orgunit, lorgunit
|
||||||
|
}).
|
||||||
-record(vcard, {user, vcard}).
|
-record(vcard, {user, vcard}).
|
||||||
|
|
||||||
|
|
||||||
@ -30,17 +41,17 @@ start() ->
|
|||||||
mnesia:create_table(vcard_search,
|
mnesia:create_table(vcard_search,
|
||||||
[{disc_copies, [node()]},
|
[{disc_copies, [node()]},
|
||||||
{attributes, record_info(fields, vcard_search)}]),
|
{attributes, record_info(fields, vcard_search)}]),
|
||||||
mnesia:add_table_index(vcard_search, fn),
|
mnesia:add_table_index(vcard_search, lfn),
|
||||||
mnesia:add_table_index(vcard_search, family),
|
mnesia:add_table_index(vcard_search, lfamily),
|
||||||
mnesia:add_table_index(vcard_search, given),
|
mnesia:add_table_index(vcard_search, lgiven),
|
||||||
mnesia:add_table_index(vcard_search, middle),
|
mnesia:add_table_index(vcard_search, lmiddle),
|
||||||
mnesia:add_table_index(vcard_search, nickname),
|
mnesia:add_table_index(vcard_search, lnickname),
|
||||||
mnesia:add_table_index(vcard_search, bday),
|
mnesia:add_table_index(vcard_search, lbday),
|
||||||
mnesia:add_table_index(vcard_search, ctry),
|
mnesia:add_table_index(vcard_search, lctry),
|
||||||
mnesia:add_table_index(vcard_search, locality),
|
mnesia:add_table_index(vcard_search, llocality),
|
||||||
mnesia:add_table_index(vcard_search, email),
|
mnesia:add_table_index(vcard_search, lemail),
|
||||||
mnesia:add_table_index(vcard_search, orgname),
|
mnesia:add_table_index(vcard_search, lorgname),
|
||||||
mnesia:add_table_index(vcard_search, orgunit),
|
mnesia:add_table_index(vcard_search, lorgunit),
|
||||||
|
|
||||||
|
|
||||||
ejabberd_local:register_iq_handler(?NS_VCARD,
|
ejabberd_local:register_iq_handler(?NS_VCARD,
|
||||||
@ -71,7 +82,7 @@ process_local_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
|
|||||||
LServer = jlib:tolower(Server),
|
LServer = jlib:tolower(Server),
|
||||||
case ?MYNAME of
|
case ?MYNAME of
|
||||||
LServer ->
|
LServer ->
|
||||||
set_vcard(LUser, SubEl),
|
set_vcard(User, SubEl),
|
||||||
{iq, ID, result, XMLNS, []};
|
{iq, ID, result, XMLNS, []};
|
||||||
_ ->
|
_ ->
|
||||||
{iq, ID, error, XMLNS,
|
{iq, ID, error, XMLNS,
|
||||||
@ -120,8 +131,7 @@ process_sm_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
|
|||||||
{iq, ID, result, XMLNS, Els}
|
{iq, ID, result, XMLNS, Els}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
set_vcard(User, VCARD) ->
|
||||||
set_vcard(LUser, VCARD) ->
|
|
||||||
FN = xml:get_path_s(VCARD, [{elem, "FN"}, cdata]),
|
FN = xml:get_path_s(VCARD, [{elem, "FN"}, cdata]),
|
||||||
Family = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "FAMILY"}, cdata]),
|
Family = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "FAMILY"}, cdata]),
|
||||||
Given = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "GIVEN"}, cdata]),
|
Given = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "GIVEN"}, cdata]),
|
||||||
@ -134,6 +144,7 @@ set_vcard(LUser, VCARD) ->
|
|||||||
OrgName = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGNAME"}, cdata]),
|
OrgName = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGNAME"}, cdata]),
|
||||||
OrgUnit = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGUNIT"}, cdata]),
|
OrgUnit = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGUNIT"}, cdata]),
|
||||||
|
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
LFN = jlib:tolower(FN),
|
LFN = jlib:tolower(FN),
|
||||||
LFamily = jlib:tolower(Family),
|
LFamily = jlib:tolower(Family),
|
||||||
LGiven = jlib:tolower(Given),
|
LGiven = jlib:tolower(Given),
|
||||||
@ -148,18 +159,19 @@ set_vcard(LUser, VCARD) ->
|
|||||||
|
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
mnesia:write(#vcard{user = LUser, vcard = VCARD}),
|
mnesia:write(#vcard{user = LUser, vcard = VCARD}),
|
||||||
mnesia:write(#vcard_search{user = LUser,
|
mnesia:write(
|
||||||
fn = LFN,
|
#vcard_search{user = User, luser = LUser,
|
||||||
family = LFamily,
|
fn = FN, lfn = LFN,
|
||||||
given = LGiven,
|
family = Family, lfamily = LFamily,
|
||||||
middle = LMiddle,
|
given = Given, lgiven = LGiven,
|
||||||
nickname = LNickname,
|
middle = Middle, lmiddle = LMiddle,
|
||||||
bday = LBDay,
|
nickname = Nickname, lnickname = LNickname,
|
||||||
ctry = LCTRY,
|
bday = BDay, lbday = LBDay,
|
||||||
locality = LLocality,
|
ctry = CTRY, lctry = LCTRY,
|
||||||
email = LEMail,
|
locality = Locality, llocality = LLocality,
|
||||||
orgname = LOrgName,
|
email = EMail, lemail = LEMail,
|
||||||
orgunit = LOrgUnit
|
orgname = OrgName, lorgname = LOrgName,
|
||||||
|
orgunit = OrgUnit, lorgunit = LOrgUnit
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
@ -380,20 +392,76 @@ filter_fields([{SVar, [Val]} | Ds], Match)
|
|||||||
when is_list(Val) and (Val /= "") ->
|
when is_list(Val) and (Val /= "") ->
|
||||||
LVal = jlib:tolower(Val),
|
LVal = jlib:tolower(Val),
|
||||||
NewMatch = case SVar of
|
NewMatch = case SVar of
|
||||||
"user" -> Match#vcard_search{user = LVal};
|
"user" -> Match#vcard_search{luser = LVal};
|
||||||
"fn" -> Match#vcard_search{fn = LVal};
|
"fn" -> Match#vcard_search{lfn = LVal};
|
||||||
"family" -> Match#vcard_search{family = LVal};
|
"family" -> Match#vcard_search{lfamily = LVal};
|
||||||
"given" -> Match#vcard_search{given = LVal};
|
"given" -> Match#vcard_search{lgiven = LVal};
|
||||||
"middle" -> Match#vcard_search{middle = LVal};
|
"middle" -> Match#vcard_search{lmiddle = LVal};
|
||||||
"nickname" -> Match#vcard_search{nickname = LVal};
|
"nickname" -> Match#vcard_search{lnickname = LVal};
|
||||||
"bday" -> Match#vcard_search{bday = LVal};
|
"bday" -> Match#vcard_search{lbday = LVal};
|
||||||
"ctry" -> Match#vcard_search{ctry = LVal};
|
"ctry" -> Match#vcard_search{lctry = LVal};
|
||||||
"locality" -> Match#vcard_search{locality = LVal};
|
"locality" -> Match#vcard_search{llocality = LVal};
|
||||||
"email" -> Match#vcard_search{email = LVal};
|
"email" -> Match#vcard_search{lemail = LVal};
|
||||||
"orgname" -> Match#vcard_search{orgname = LVal};
|
"orgname" -> Match#vcard_search{lorgname = LVal};
|
||||||
"orgunit" -> Match#vcard_search{orgunit = LVal};
|
"orgunit" -> Match#vcard_search{lorgunit = LVal};
|
||||||
_ -> Match
|
_ -> Match
|
||||||
end,
|
end,
|
||||||
filter_fields(Ds, NewMatch);
|
filter_fields(Ds, NewMatch);
|
||||||
filter_fields([_ | Ds], Match) ->
|
filter_fields([_ | Ds], Match) ->
|
||||||
filter_fields(Ds, Match).
|
filter_fields(Ds, Match).
|
||||||
|
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
set_vcard_t(R, _) ->
|
||||||
|
User = R#vcard.user,
|
||||||
|
VCARD = R#vcard.vcard,
|
||||||
|
|
||||||
|
FN = xml:get_path_s(VCARD, [{elem, "FN"}, cdata]),
|
||||||
|
Family = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "FAMILY"}, cdata]),
|
||||||
|
Given = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "GIVEN"}, cdata]),
|
||||||
|
Middle = xml:get_path_s(VCARD, [{elem, "N"}, {elem, "MIDDLE"}, cdata]),
|
||||||
|
Nickname = xml:get_path_s(VCARD, [{elem, "NICKNAME"}, cdata]),
|
||||||
|
BDay = xml:get_path_s(VCARD, [{elem, "BDAY"}, cdata]),
|
||||||
|
CTRY = xml:get_path_s(VCARD, [{elem, "ADR"}, {elem, "CTRY"}, cdata]),
|
||||||
|
Locality = xml:get_path_s(VCARD, [{elem, "ADR"}, {elem, "LOCALITY"},cdata]),
|
||||||
|
EMail = xml:get_path_s(VCARD, [{elem, "EMAIL"}, cdata]),
|
||||||
|
OrgName = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGNAME"}, cdata]),
|
||||||
|
OrgUnit = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGUNIT"}, cdata]),
|
||||||
|
|
||||||
|
LUser = jlib:tolower(User),
|
||||||
|
LFN = jlib:tolower(FN),
|
||||||
|
LFamily = jlib:tolower(Family),
|
||||||
|
LGiven = jlib:tolower(Given),
|
||||||
|
LMiddle = jlib:tolower(Middle),
|
||||||
|
LNickname = jlib:tolower(Nickname),
|
||||||
|
LBDay = jlib:tolower(BDay),
|
||||||
|
LCTRY = jlib:tolower(CTRY),
|
||||||
|
LLocality = jlib:tolower(Locality),
|
||||||
|
LEMail = jlib:tolower(EMail),
|
||||||
|
LOrgName = jlib:tolower(OrgName),
|
||||||
|
LOrgUnit = jlib:tolower(OrgUnit),
|
||||||
|
|
||||||
|
mnesia:write(
|
||||||
|
#vcard_search{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
|
||||||
|
}).
|
||||||
|
|
||||||
|
|
||||||
|
reindex_vcards() ->
|
||||||
|
F = fun() ->
|
||||||
|
mnesia:foldl(fun set_vcard_t/2, [], vcard)
|
||||||
|
end,
|
||||||
|
mnesia:transaction(F).
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
-define(NS_DISCO_INFO, "http://jabber.org/protocol/disco#info").
|
-define(NS_DISCO_INFO, "http://jabber.org/protocol/disco#info").
|
||||||
-define(NS_VCARD, "vcard-temp").
|
-define(NS_VCARD, "vcard-temp").
|
||||||
-define(NS_SEARCH, "jabber:iq:search").
|
-define(NS_SEARCH, "jabber:iq:search").
|
||||||
|
-define(NS_ROSTER, "jabber:iq:roster").
|
||||||
-define(NS_XDATA, "jabber:x:data").
|
-define(NS_XDATA, "jabber:x:data").
|
||||||
-define(NS_DELAY, "jabber:x:delay").
|
-define(NS_DELAY, "jabber:x:delay").
|
||||||
-define(NS_EVENT, "jabber:x:event").
|
-define(NS_EVENT, "jabber:x:event").
|
||||||
|
36
src/sha.erl
36
src/sha.erl
@ -10,33 +10,23 @@
|
|||||||
-author('alexey@sevcom.net').
|
-author('alexey@sevcom.net').
|
||||||
-vsn('$Revision$ ').
|
-vsn('$Revision$ ').
|
||||||
|
|
||||||
-export([start/0, init/0, sha/1]).
|
-export([start/0, sha/1]).
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
register(sha, spawn(?MODULE, init, [])).
|
crypto:start().
|
||||||
|
|
||||||
init() ->
|
digit_to_xchar(D) when (D >= 0) and (D < 10) ->
|
||||||
ok = erl_ddll:load_driver(".", sha_erl),
|
D + 48;
|
||||||
Port = open_port({spawn, sha_erl}, [binary]),
|
digit_to_xchar(D) ->
|
||||||
loop(Port).
|
D + 87.
|
||||||
|
|
||||||
loop(Port) ->
|
|
||||||
receive
|
|
||||||
{From, {text, Str}} ->
|
|
||||||
Port ! {self(), {command, Str}},
|
|
||||||
SHA = receive
|
|
||||||
{Port, {data, Bin}} ->
|
|
||||||
binary_to_term(Bin)
|
|
||||||
end,
|
|
||||||
From ! {sha, SHA},
|
|
||||||
loop(Port)
|
|
||||||
end.
|
|
||||||
|
|
||||||
sha(Text) ->
|
sha(Text) ->
|
||||||
sha ! {self(), {text, Text}},
|
Bin = crypto:sha(Text),
|
||||||
receive
|
lists:reverse(ints_to_rxstr(binary_to_list(Bin), [])).
|
||||||
{sha, S} ->
|
|
||||||
S
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
ints_to_rxstr([], Res) ->
|
||||||
|
Res;
|
||||||
|
ints_to_rxstr([N | Ns], Res) ->
|
||||||
|
ints_to_rxstr(Ns, [digit_to_xchar(N rem 16),
|
||||||
|
digit_to_xchar(N div 16) | Res]).
|
||||||
|
|
||||||
|
22
src/xml.erl
22
src/xml.erl
@ -57,15 +57,21 @@ crypt([], R) ->
|
|||||||
R.
|
R.
|
||||||
|
|
||||||
|
|
||||||
remove_cdata(L) ->
|
remove_cdata_p({xmlelement, Name, Attrs, Els}) -> true;
|
||||||
lists:reverse(remove_cdata(L, [])).
|
remove_cdata_p(_) -> false.
|
||||||
|
|
||||||
remove_cdata([{xmlelement, Name, Attrs, Els} | L], R) ->
|
remove_cdata(L) -> [E || E <- L, remove_cdata_p(E)].
|
||||||
remove_cdata(L, [{xmlelement, Name, Attrs, Els} | R]);
|
|
||||||
remove_cdata([{xmlcdata, CData} | L], R) ->
|
|
||||||
remove_cdata(L, R);
|
%remove_cdata(L) ->
|
||||||
remove_cdata([], R) ->
|
% lists:reverse(remove_cdata(L, [])).
|
||||||
R.
|
%
|
||||||
|
%remove_cdata([{xmlelement, Name, Attrs, Els} | L], R) ->
|
||||||
|
% remove_cdata(L, [{xmlelement, Name, Attrs, Els} | R]);
|
||||||
|
%remove_cdata([{xmlcdata, CData} | L], R) ->
|
||||||
|
% remove_cdata(L, R);
|
||||||
|
%remove_cdata([], R) ->
|
||||||
|
% R.
|
||||||
|
|
||||||
get_cdata(L) ->
|
get_cdata(L) ->
|
||||||
get_cdata(L, "").
|
get_cdata(L, "").
|
||||||
|
Loading…
Reference in New Issue
Block a user