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

Convert to exmpp.

PR:		EJABP-1

SVN Revision: 1649
This commit is contained in:
Jean-Sébastien Pédron 2008-10-13 09:39:58 +00:00
parent 461a5eb315
commit 3190c0ed6c
2 changed files with 19 additions and 22 deletions

View File

@ -6,7 +6,7 @@
* src/gen_iq_handler.erl: Remove the deprecated list of converted * src/gen_iq_handler.erl: Remove the deprecated list of converted
modules. modules.
* src/jd2ejd.erl: Convert to exmpp. * src/ejd2odbc.erl, src/jd2ejd.erl: Convert to exmpp.
2008-10-10 Jean-Sébastien Pédron <js.pedron@meetic-corp.com> 2008-10-10 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>

View File

@ -36,8 +36,9 @@
export_vcard_search/2, export_vcard_search/2,
export_private_storage/2]). export_private_storage/2]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl").
-include("mod_roster.hrl"). -include("mod_roster.hrl").
-record(offline_msg, {us, timestamp, expire, from, to, packet}). -record(offline_msg, {us, timestamp, expire, from, to, packet}).
@ -88,10 +89,10 @@ export_passwd(Server, Output) ->
export_roster(Server, Output) -> export_roster(Server, Output) ->
export_common( export_common(
Server, roster, Output, Server, roster, Output,
fun(Host, #roster{usj = {LUser, LServer, LJID}} = R) fun(Host, #roster{usj = {LUser, LServer, {N, D, Res} = _LJID}} = R)
when LServer == Host -> when LServer == Host ->
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(LUser),
SJID = ejabberd_odbc:escape(jlib:jid_to_string(LJID)), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(N, D, Res)),
ItemVals = record_to_string(R), ItemVals = record_to_string(R),
ItemGroups = groups_to_string(R), ItemGroups = groups_to_string(R),
["delete from rosterusers " ["delete from rosterusers "
@ -123,19 +124,15 @@ export_offline(Server, Output) ->
packet = Packet}) packet = Packet})
when LServer == Host -> when LServer == Host ->
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(LUser),
{xmlelement, Name, Attrs, Els} = Packet, Packet0 = exmpp_stanza:set_jids(Packet,
Attrs2 = jlib:replace_from_to_attrs( exmpp_jid:jid_to_list(From),
jlib:jid_to_string(From), exmpp_jid:jid_to_list(To)),
jlib:jid_to_string(To), Packet1 = exmpp_xml:append_child(Packet0,
Attrs), jlib:timestamp_to_xml(
NewPacket = {xmlelement, Name, Attrs2, calendar:now_to_universal_time(TimeStamp))),
Els ++
[jlib:timestamp_to_xml(
calendar:now_to_universal_time(TimeStamp))]},
XML = XML =
ejabberd_odbc:escape( ejabberd_odbc:escape(
lists:flatten( exmpp_xml:document_to_list(Packet1)),
xml:element_to_string(NewPacket))),
["insert into spool(username, xml) " ["insert into spool(username, xml) "
"values ('", Username, "', '", "values ('", Username, "', '",
XML, XML,
@ -169,7 +166,7 @@ export_vcard(Server, Output) ->
when LServer == Host -> when LServer == Host ->
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(LUser),
SVCARD = ejabberd_odbc:escape( SVCARD = ejabberd_odbc:escape(
lists:flatten(xml:element_to_string(VCARD))), exmpp_xml:document_to_list(VCARD)),
["delete from vcard where username='", Username, "';" ["delete from vcard where username='", Username, "';"
"insert into vcard(username, vcard) " "insert into vcard(username, vcard) "
"values ('", Username, "', '", SVCARD, "');"]; "values ('", Username, "', '", SVCARD, "');"];
@ -253,7 +250,7 @@ export_private_storage(Server, Output) ->
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(LUser),
LXMLNS = ejabberd_odbc:escape(XMLNS), LXMLNS = ejabberd_odbc:escape(XMLNS),
SData = ejabberd_odbc:escape( SData = ejabberd_odbc:escape(
lists:flatten(xml:element_to_string(Data))), exmpp_xml:document_to_list(Data)),
odbc_queries:set_private_data_sql(Username, LXMLNS, SData); odbc_queries:set_private_data_sql(Username, LXMLNS, SData);
(_Host, _R) -> (_Host, _R) ->
[] []
@ -274,7 +271,7 @@ export_common(Server, Table, Output, ConvertFun) ->
mnesia:transaction( mnesia:transaction(
fun() -> fun() ->
mnesia:read_lock_table(Table), mnesia:read_lock_table(Table),
LServer = jlib:nameprep(Server), LServer = exmpp_stringprep:nameprep(Server),
{_N, SQLs} = {_N, SQLs} =
mnesia:foldl( mnesia:foldl(
fun(R, {N, SQLs} = Acc) -> fun(R, {N, SQLs} = Acc) ->
@ -310,13 +307,13 @@ output(LServer, IO, SQL) ->
file:write(IO, [SQL, $;, $\n]) file:write(IO, [SQL, $;, $\n])
end. end.
record_to_string(#roster{usj = {User, _Server, JID}, record_to_string(#roster{usj = {User, _Server, {N, D, R} = _JID},
name = Name, name = Name,
subscription = Subscription, subscription = Subscription,
ask = Ask, ask = Ask,
askmessage = AskMessage}) -> askmessage = AskMessage}) ->
Username = ejabberd_odbc:escape(User), Username = ejabberd_odbc:escape(User),
SJID = ejabberd_odbc:escape(jlib:jid_to_string(JID)), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(N, D, R)),
Nick = ejabberd_odbc:escape(Name), Nick = ejabberd_odbc:escape(Name),
SSubscription = case Subscription of SSubscription = case Subscription of
both -> "B"; both -> "B";
@ -349,10 +346,10 @@ record_to_string(#roster{usj = {User, _Server, JID},
"'", SAskMessage, "'," "'", SAskMessage, "',"
"'N', '', 'item')"]. "'N', '', 'item')"].
groups_to_string(#roster{usj = {User, _Server, JID}, groups_to_string(#roster{usj = {User, _Server, {N, D, R} = _JID},
groups = Groups}) -> groups = Groups}) ->
Username = ejabberd_odbc:escape(User), Username = ejabberd_odbc:escape(User),
SJID = ejabberd_odbc:escape(jlib:jid_to_string(JID)), SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(N, D, R)),
[["(" [["("
"'", Username, "'," "'", Username, "',"
"'", SJID, "'," "'", SJID, "',"