From 3190c0ed6c4ab3fa51c2f2138068d2be35495233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Mon, 13 Oct 2008 09:39:58 +0000 Subject: [PATCH] Convert to exmpp. PR: EJABP-1 SVN Revision: 1649 --- ChangeLog | 2 +- src/ejd2odbc.erl | 39 ++++++++++++++++++--------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4aae94ef..e9de2947d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,7 +6,7 @@ * src/gen_iq_handler.erl: Remove the deprecated list of converted modules. - * src/jd2ejd.erl: Convert to exmpp. + * src/ejd2odbc.erl, src/jd2ejd.erl: Convert to exmpp. 2008-10-10 Jean-Sébastien Pédron diff --git a/src/ejd2odbc.erl b/src/ejd2odbc.erl index c1399f987..86b42679a 100644 --- a/src/ejd2odbc.erl +++ b/src/ejd2odbc.erl @@ -36,8 +36,9 @@ export_vcard_search/2, export_private_storage/2]). +-include_lib("exmpp/include/exmpp.hrl"). + -include("ejabberd.hrl"). --include("jlib.hrl"). -include("mod_roster.hrl"). -record(offline_msg, {us, timestamp, expire, from, to, packet}). @@ -88,10 +89,10 @@ export_passwd(Server, Output) -> export_roster(Server, Output) -> export_common( 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 -> 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), ItemGroups = groups_to_string(R), ["delete from rosterusers " @@ -123,19 +124,15 @@ export_offline(Server, Output) -> packet = Packet}) when LServer == Host -> Username = ejabberd_odbc:escape(LUser), - {xmlelement, Name, Attrs, Els} = Packet, - Attrs2 = jlib:replace_from_to_attrs( - jlib:jid_to_string(From), - jlib:jid_to_string(To), - Attrs), - NewPacket = {xmlelement, Name, Attrs2, - Els ++ - [jlib:timestamp_to_xml( - calendar:now_to_universal_time(TimeStamp))]}, + Packet0 = exmpp_stanza:set_jids(Packet, + exmpp_jid:jid_to_list(From), + exmpp_jid:jid_to_list(To)), + Packet1 = exmpp_xml:append_child(Packet0, + jlib:timestamp_to_xml( + calendar:now_to_universal_time(TimeStamp))), XML = ejabberd_odbc:escape( - lists:flatten( - xml:element_to_string(NewPacket))), + exmpp_xml:document_to_list(Packet1)), ["insert into spool(username, xml) " "values ('", Username, "', '", XML, @@ -169,7 +166,7 @@ export_vcard(Server, Output) -> when LServer == Host -> Username = ejabberd_odbc:escape(LUser), SVCARD = ejabberd_odbc:escape( - lists:flatten(xml:element_to_string(VCARD))), + exmpp_xml:document_to_list(VCARD)), ["delete from vcard where username='", Username, "';" "insert into vcard(username, vcard) " "values ('", Username, "', '", SVCARD, "');"]; @@ -253,7 +250,7 @@ export_private_storage(Server, Output) -> Username = ejabberd_odbc:escape(LUser), LXMLNS = ejabberd_odbc:escape(XMLNS), 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); (_Host, _R) -> [] @@ -274,7 +271,7 @@ export_common(Server, Table, Output, ConvertFun) -> mnesia:transaction( fun() -> mnesia:read_lock_table(Table), - LServer = jlib:nameprep(Server), + LServer = exmpp_stringprep:nameprep(Server), {_N, SQLs} = mnesia:foldl( fun(R, {N, SQLs} = Acc) -> @@ -310,13 +307,13 @@ output(LServer, IO, SQL) -> file:write(IO, [SQL, $;, $\n]) end. -record_to_string(#roster{usj = {User, _Server, JID}, +record_to_string(#roster{usj = {User, _Server, {N, D, R} = _JID}, name = Name, subscription = Subscription, ask = Ask, askmessage = AskMessage}) -> 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), SSubscription = case Subscription of both -> "B"; @@ -349,10 +346,10 @@ record_to_string(#roster{usj = {User, _Server, JID}, "'", SAskMessage, "'," "'N', '', 'item')"]. -groups_to_string(#roster{usj = {User, _Server, JID}, +groups_to_string(#roster{usj = {User, _Server, {N, D, R} = _JID}, groups = Groups}) -> 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, "'," "'", SJID, "',"