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

Convert to exmpp.

PR:		EJABP-1

SVN Revision: 1648
This commit is contained in:
Jean-Sébastien Pédron 2008-10-13 09:39:18 +00:00
parent 01ef834b82
commit 461a5eb315
2 changed files with 62 additions and 55 deletions

View File

@ -6,6 +6,8 @@
* src/gen_iq_handler.erl: Remove the deprecated list of converted
modules.
* src/jd2ejd.erl: Convert to exmpp.
2008-10-10 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/ejabberd_c2s.erl (is_auth_packet/1): Fix a bug where

View File

@ -31,8 +31,9 @@
-export([import_file/1,
import_dir/1]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl").
-include("jlib.hrl").
@ -43,13 +44,14 @@
import_file(File) ->
User = filename:rootname(filename:basename(File)),
Server = filename:basename(filename:dirname(File)),
case (jlib:nodeprep(User) /= error) andalso
(jlib:nameprep(Server) /= error) of
case exmpp_stringprep:is_node(User) andalso
exmpp_stringprep:is_name(Server) of
true ->
case file:read_file(File) of
{ok, Text} ->
case xml_stream:parse_element(Text) of
El when element(1, El) == xmlelement ->
try
[El] = exmpp_xml:parse_document(Text,
[namespace, name_as_atom]),
case catch process_xdb(User, Server, El) of
{'EXIT', Reason} ->
?ERROR_MSG(
@ -58,11 +60,12 @@ import_file(File) ->
{error, Reason};
_ ->
ok
end;
{error, Reason} ->
end
catch
_:Reason1 ->
?ERROR_MSG("Can't parse file \"~s\": ~p~n",
[File, Reason]),
{error, Reason}
[File, Reason1]),
{error, Reason1}
end;
{error, Reason} ->
?ERROR_MSG("Can't read file \"~s\": ~p~n", [File, Reason]),
@ -100,26 +103,23 @@ import_dir(Dir) ->
%%% Internal functions
%%%----------------------------------------------------------------------
process_xdb(User, Server, {xmlelement, Name, _Attrs, Els}) ->
case Name of
"xdb" ->
process_xdb(User, Server, #xmlel{name = "xdb", children = Els}) ->
lists:foreach(
fun(El) ->
xdb_data(User, Server, El)
end, Els);
_ ->
ok
end.
process_xdb(_User, _Server, _El) ->
ok.
xdb_data(_User, _Server, {xmlcdata, _CData}) ->
xdb_data(_User, _Server, #xmlcdata{}) ->
ok;
xdb_data(User, Server, {xmlelement, _Name, Attrs, _Els} = El) ->
From = jlib:make_jid(User, Server, ""),
LServer = jlib:nameprep(Server),
case xml:get_attr_s("xmlns", Attrs) of
?NS_AUTH ->
Password = xml:get_tag_cdata(El),
xdb_data(User, Server, #xmlel{ns = NS} = El) ->
From = exmpp_jid:make_bare_jid(User, Server),
LServer = exmpp_stringprep:nameprep(Server),
case NS of
?NS_LEGACY_AUTH ->
Password = exmpp_xml:get_cdata(El),
ejabberd_auth:set_password(User, Server, Password),
ok;
?NS_ROSTER ->
@ -131,9 +131,9 @@ xdb_data(User, Server, {xmlelement, _Name, Attrs, _Els} = El) ->
catch mod_roster:set_items(User, Server, El)
end,
ok;
?NS_LAST ->
TimeStamp = xml:get_attr_s("last", Attrs),
Status = xml:get_tag_cdata(El),
?NS_LAST_ACTIVITY ->
TimeStamp = exmpp_xml:get_attribute(El, 'last', ""),
Status = exmpp_xml:get_cdata(El),
case lists:member(mod_last_odbc,
gen_mod:loaded_modules(LServer)) of
true ->
@ -156,29 +156,29 @@ xdb_data(User, Server, {xmlelement, _Name, Attrs, _Els} = El) ->
true ->
catch mod_vcard_odbc:process_sm_iq(
From,
jlib:make_jid("", Server, ""),
#iq{type = set, xmlns = ?NS_VCARD, sub_el = El});
exmpp_jid:make_bare_jid(Server),
#iq{kind = request, type = set, ns = ?NS_VCARD, payload = El, iq_ns = ?NS_JABBER_CLIENT});
false ->
catch mod_vcard:process_sm_iq(
From,
jlib:make_jid("", Server, ""),
#iq{type = set, xmlns = ?NS_VCARD, sub_el = El})
exmpp_jid:make_bare_jid(Server),
#iq{kind = request, type = set, ns = ?NS_VCARD, payload = El, iq_ns = ?NS_JABBER_CLIENT})
end,
ok;
"jabber:x:offline" ->
process_offline(Server, From, El),
ok;
XMLNS ->
case xml:get_attr_s("j_private_flag", Attrs) of
case exmpp_xml:get_attribute(El, "j_private_flag", "") of
"1" ->
catch mod_private:process_sm_iq(
From,
jlib:make_jid("", Server, ""),
#iq{type = set, xmlns = ?NS_PRIVATE,
sub_el = {xmlelement, "query", [],
[jlib:remove_attr(
"j_private_flag",
jlib:remove_attr("xdbns", El))]}});
exmpp_jid:make_bare_jid(Server),
#iq{kind = request, type = set, ns = ?NS_PRIVATE,
iq_ns = ?NS_JABBER_CLIENT,
payload = #xmlel{name = 'query', children =
[exmpp_xml:remove_attribute(
exmpp_xml:remove_attribute(El, "xdbns"), "j_private_flag")]}});
_ ->
?DEBUG("jd2ejd: Unknown namespace \"~s\"~n", [XMLNS])
end,
@ -186,15 +186,20 @@ xdb_data(User, Server, {xmlelement, _Name, Attrs, _Els} = El) ->
end.
process_offline(Server, To, {xmlelement, _, _, Els}) ->
LServer = jlib:nameprep(Server),
lists:foreach(fun({xmlelement, _, Attrs, _} = El) ->
FromS = xml:get_attr_s("from", Attrs),
process_offline(Server, To, #xmlel{children = Els}) ->
LServer = exmpp_stringprep:nameprep(Server),
lists:foreach(fun(#xmlel{} = El) ->
FromS = exmpp_stanza:get_sender(El),
From = case FromS of
"" ->
jlib:make_jid("", Server, "");
undefined ->
exmpp_jid:make_bare_jid(Server);
_ ->
jlib:string_to_jid(FromS)
try
exmpp_jid:list_to_jid(FromS)
catch
_ ->
error
end
end,
case From of
error ->