25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

VCard are now stored as #xmlel. Mnesia tables are converted during

startup.

SVN Revision: 1553
This commit is contained in:
Jean-Sébastien Pédron 2008-08-27 12:39:49 +00:00
parent 02e6bf8759
commit 414948d822
2 changed files with 31 additions and 15 deletions

View File

@ -5,6 +5,9 @@
* src/mod_caps.erl: handle_cast({disco_response, ...}, ...) now * src/mod_caps.erl: handle_cast({disco_response, ...}, ...) now
receives an #iq record: update the code to handle this. receives an #iq record: update the code to handle this.
* src/mod_vcard.erl: VCard are now stored as #xmlel. Mnesia tables are
converted during startup.
2008-08-26 Jean-Sébastien Pédron <js.pedron@meetic-corp.com> 2008-08-26 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/jlib.erl: short_jid/1 and short_bare_jid/1 now produce a short * src/jlib.erl: short_jid/1 and short_bare_jid/1 now produce a short

View File

@ -142,10 +142,10 @@ get_sm_features(Acc, _From, _To, Node, _Lang) ->
case Acc of case Acc of
{result, Features} -> {result, Features} ->
% XXX OLD FORMAT: NS as string. % XXX OLD FORMAT: NS as string.
{result, [atom_to_list(?NS_VCARD) | Features]}; {result, [?NS_VCARD_s | Features]};
empty -> empty ->
% XXX OLD FORMAT: NS as string. % XXX OLD FORMAT: NS as string.
{result, [atom_to_list(?NS_VCARD)]} {result, [?NS_VCARD_s]}
end; end;
_ -> _ ->
Acc Acc
@ -177,14 +177,7 @@ process_sm_iq(_From, To, #iq{type = get} = IQ_Rec) ->
[VCard | _] = case mnesia:transaction(F) of [VCard | _] = case mnesia:transaction(F) of
{atomic, Rs} -> {atomic, Rs} ->
lists:map(fun(R) -> lists:map(fun(R) ->
case R#vcard.vcard of R#vcard.vcard
#xmlel{} = E ->
E;
#xmlelement{} = E ->
% XXX OLD FORMAT: Base contains old elements.
io:format("VCARD: Old element in base: ~p~n", [E]),
exmpp_xml:xmlelement_to_xmlel(E, [?NS_VCARD], [])
end
end, Rs); end, Rs);
{aborted, _Reason} -> {aborted, _Reason} ->
[] []
@ -249,10 +242,7 @@ set_vcard(User, LServer, VCARD) ->
US = {LUser, LServer}, US = {LUser, LServer},
F = fun() -> F = fun() ->
% XXX OLD FORMAT: We keep persistent data in the old format mnesia:write(#vcard{us = US, vcard = VCARD}),
% for now.
VCARDOld = exmpp_xml:xmlel_to_xmlelement(VCARD, [?NS_VCARD], []),
mnesia:write(#vcard{us = US, vcard = VCARDOld}),
mnesia:write( mnesia:write(
#vcard_search{us = US, #vcard_search{us = US,
user = {User, LServer}, user = {User, LServer},
@ -673,7 +663,7 @@ update_vcard_table() ->
Fields = record_info(fields, vcard), Fields = record_info(fields, vcard),
case mnesia:table_info(vcard, attributes) of case mnesia:table_info(vcard, attributes) of
Fields -> Fields ->
ok; convert_to_exmpp();
[user, vcard] -> [user, vcard] ->
?INFO_MSG("Converting vcard table from " ?INFO_MSG("Converting vcard table from "
"{user, vcard} format", []), "{user, vcard} format", []),
@ -712,6 +702,29 @@ update_vcard_table() ->
end. end.
convert_to_exmpp() ->
Fun = fun() ->
case mnesia:first(vcard) of
'$end_of_table' ->
none;
Key ->
case mnesia:read({vcard, Key}) of
[#vcard{vcard = #xmlel{}}] ->
none;
[#vcard{vcard = #xmlelement{}}] ->
mnesia:foldl(fun convert_to_exmpp2/2,
done, vcard, write)
end
end
end,
mnesia:transaction(Fun).
convert_to_exmpp2(#vcard{vcard = ElOld} = VCard, Acc) ->
El0 = exmpp_xml:xmlelement_to_xmlel(ElOld, [?NS_VCARD], []),
El = exmpp_xml:remove_whitespaces_deeply(El0),
mnesia:write(VCard#vcard{vcard = El}),
Acc.
update_vcard_search_table() -> update_vcard_search_table() ->
Fields = record_info(fields, vcard_search), Fields = record_info(fields, vcard_search),
case mnesia:table_info(vcard_search, attributes) of case mnesia:table_info(vcard_search, attributes) of