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 * src/gen_iq_handler.erl: Remove the deprecated list of converted
modules. modules.
* 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>
* src/ejabberd_c2s.erl (is_auth_packet/1): Fix a bug where * src/ejabberd_c2s.erl (is_auth_packet/1): Fix a bug where

View File

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