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

o Use the new functions from jlib.

o  Remove the compatibility code. It's becoming confusing to handle every
case every where. Also, in JIDs (normal and short), the atom "undefined'
is expected, not the empty string anymore!

SVN Revision: 1546
This commit is contained in:
Jean-Sébastien Pédron 2008-08-26 13:38:49 +00:00
parent 80fcd2eb56
commit 9f0d79da9a
8 changed files with 99 additions and 262 deletions

View File

@ -4,9 +4,18 @@
JID from the user-provided JID parts. To obtain a short JID from the JID from the user-provided JID parts. To obtain a short JID from the
STRINGPREP'd parts, use the new short_prepd_jid/1 and STRINGPREP'd parts, use the new short_prepd_jid/1 and
short_prepd_bare_jid/1 functions. Remove commented-out code and use short_prepd_bare_jid/1 functions. Remove commented-out code and use
proper variable names. proper variable names. Those functions use the atom 'undefined' and
NOT the empty string anymore!
* src/acl.erl: Use the new short_prepd_jid/1 function from jlib. * src/acl.erl, src/ejabberd_router.erl: Use the new functions from
jlib.
* src/ejabberd_router.erl, src/ejabberd_local.erl,
src/ejabberd_sm.erl, src/ejabberd_s2s.erl, src/ejabberd_s2s_in.erl,
src/ejabberd_s2s_out.erl, src/ejabberd_c2s.erl: Remove the
compatibility code. It's becoming confusing to handle every case every
where. Also, in JIDs (normal and short), the atom "undefined' is
expected, not the empty string anymore!
2008-08-14 Jean-Sébastien Pédron <js.pedron@meetic-corp.com> 2008-08-14 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>

View File

@ -76,7 +76,7 @@
tls_options = [], tls_options = [],
authenticated = false, authenticated = false,
jid, jid,
user = "", server = ?MYNAME, resource = "", user = undefined, server = ?MYNAME, resource = undefined,
sid, sid,
pres_t = ?SETS:new(), pres_t = ?SETS:new(),
pres_f = ?SETS:new(), pres_f = ?SETS:new(),
@ -273,12 +273,10 @@ wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) ->
false -> false ->
[] []
end, end,
% XXX OLD FORMAT: Other_Feats. Other_Feats = ejabberd_hooks:run_fold(
Other_FeatsOld = ejabberd_hooks:run_fold(
c2s_stream_features, c2s_stream_features,
Server, Server,
[], []), [], []),
Other_Feats = [exmpp_xml:xmlelement_to_xmlel(F, [?DEFAULT_NS], ?PREFIXED_NS) || F <- Other_FeatsOld],
send_element(StateData, send_element(StateData,
exmpp_stream:features( exmpp_stream:features(
TLSFeature ++ TLSFeature ++
@ -292,7 +290,7 @@ wait_for_stream({xmlstreamstart, #xmlel{ns = NS} = Opening}, StateData) ->
lang = Lang}); lang = Lang});
_ -> _ ->
case StateData#state.resource of case StateData#state.resource of
"" -> undefined ->
send_element( send_element(
StateData, StateData,
exmpp_stream:features([ exmpp_stream:features([
@ -413,7 +411,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
StateData#state.server, StateData#state.server,
{[], []}, {[], []},
[U, StateData#state.server]), [U, StateData#state.server]),
LJID = jlib:short_bare_jid(JID), LJID = jlib:short_prepd_bare_jid(JID),
Fs1 = [LJID | Fs], Fs1 = [LJID | Fs],
Ts1 = [LJID | Ts], Ts1 = [LJID | Ts],
PrivList = ejabberd_hooks:run_fold( PrivList = ejabberd_hooks:run_fold(
@ -728,7 +726,7 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
StateData#state.server, StateData#state.server,
{[], []}, {[], []},
[U, StateData#state.server]), [U, StateData#state.server]),
LJID = jlib:short_bare_jid(JID), LJID = jlib:short_prepd_bare_jid(JID),
Fs1 = [LJID | Fs], Fs1 = [LJID | Fs],
Ts1 = [LJID | Ts], Ts1 = [LJID | Ts],
PrivList = PrivList =
@ -744,10 +742,8 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
pres_t = ?SETS:from_list(Ts1), pres_t = ?SETS:from_list(Ts1),
privacy_list = PrivList}); privacy_list = PrivList});
_ -> _ ->
% XXX OLD FORMAT: Jid.
JIDOld = jlib:to_old_jid(JID),
ejabberd_hooks:run(forbidden_session_hook, ejabberd_hooks:run(forbidden_session_hook,
StateData#state.server, [JIDOld]), StateData#state.server, [JID]),
?INFO_MSG("(~w) Forbidden session for ~s", ?INFO_MSG("(~w) Forbidden session for ~s",
[StateData#state.socket, [StateData#state.socket,
exmpp_jid:jid_to_list(JID)]), exmpp_jid:jid_to_list(JID)]),
@ -801,22 +797,15 @@ session_established({xmlstreamelement, El}, StateData) ->
end, end,
NewState = case El of NewState = case El of
#xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence'} -> #xmlel{ns = ?NS_JABBER_CLIENT, name = 'presence'} ->
% XXX OLD FORMAT: NewEl. PresenceEl = ejabberd_hooks:run_fold(
PresenceElOld = ejabberd_hooks:run_fold(
c2s_update_presence, c2s_update_presence,
Server, Server,
exmpp_xml:xmlel_to_xmlelement(NewEl, NewEl,
[?DEFAULT_NS], ?PREFIXED_NS),
[User, Server]), [User, Server]),
PresenceEl = exmpp_xml:xmlelement_to_xmlel(PresenceElOld,
[?DEFAULT_NS], ?PREFIXED_NS),
% XXX OLD FORMAT: PresenceElOld, *JID.
FromJIDOld = jlib:to_old_jid(FromJID),
ToJIDOld = jlib:to_old_jid(ToJID),
ejabberd_hooks:run( ejabberd_hooks:run(
user_send_packet, user_send_packet,
Server, Server,
[FromJIDOld, ToJIDOld, PresenceElOld]), [FromJID, ToJID, PresenceEl]),
case ToJID of case ToJID of
#jid{node = User, #jid{node = User,
domain = Server, domain = Server,
@ -830,43 +819,29 @@ session_established({xmlstreamelement, El}, StateData) ->
StateData) StateData)
end; end;
#xmlel{ns = ?NS_JABBER_CLIENT, name = 'iq'} -> #xmlel{ns = ?NS_JABBER_CLIENT, name = 'iq'} ->
% XXX OLD FORMAT: JIDs. case exmpp_iq:xmlel_to_iq(El) of
FromJIDOld = jlib:to_old_jid(FromJID), #iq{kind = request, ns = ?NS_PRIVACY} = IQ_Rec ->
ToJIDOld = jlib:to_old_jid(ToJID),
case exmpp_iq:get_payload(El) of
#xmlel{ns = ?NS_PRIVACY} ->
process_privacy_iq( process_privacy_iq(
FromJID, ToJID, El, StateData); FromJID, ToJID, IQ_Rec, StateData);
_ -> _ ->
% XXX OLD FORMAT: NewElOld.
NewElOld = exmpp_xml:xmlel_to_xmlelement(NewEl,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_hooks:run( ejabberd_hooks:run(
user_send_packet, user_send_packet,
Server, Server,
[FromJIDOld, ToJIDOld, NewElOld]), [FromJID, ToJID, NewEl]),
ejabberd_router:route( ejabberd_router:route(
FromJID, ToJID, NewEl), FromJID, ToJID, NewEl),
StateData StateData
end; end;
#xmlel{ns = ?NS_JABBER_CLIENT, name = 'message'} -> #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message'} ->
% XXX OLD FORMAT: NewElOld, JIDs.
NewElOld = exmpp_xml:xmlel_to_xmlelement(NewEl,
[?DEFAULT_NS], ?PREFIXED_NS),
FromJIDOld = jlib:to_old_jid(FromJID),
ToJIDOld = jlib:to_old_jid(ToJID),
ejabberd_hooks:run(user_send_packet, ejabberd_hooks:run(user_send_packet,
Server, Server,
[FromJIDOld, ToJIDOld, NewElOld]), [FromJID, ToJID, NewEl]),
ejabberd_router:route(FromJID, ToJID, NewEl), ejabberd_router:route(FromJID, ToJID, NewEl),
StateData; StateData;
_ -> _ ->
StateData StateData
end, end,
% XXX OLD FORMAT: El. ejabberd_hooks:run(c2s_loop_debug, [{xmlstreamelement, El}]),
ElOld = exmpp_xml:xmlel_to_xmlelement(El,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_hooks:run(c2s_loop_debug, [{xmlstreamelement, ElOld}]),
fsm_next_state(session_established, NewState) fsm_next_state(session_established, NewState)
catch catch
throw:{stringprep, _, _, _} -> throw:{stringprep, _, _, _} ->
@ -879,10 +854,7 @@ session_established({xmlstreamelement, El}, StateData) ->
Err = exmpp_stanza:reply_with_error(El, 'jid-malformed'), Err = exmpp_stanza:reply_with_error(El, 'jid-malformed'),
send_element(StateData, Err) send_element(StateData, Err)
end, end,
% XXX OLD FORMAT: ElOld1. ejabberd_hooks:run(c2s_loop_debug, [{xmlstreamelement, El}]),
ElOld1 = exmpp_xml:xmlel_to_xmlelement(El,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_hooks:run(c2s_loop_debug, [{xmlstreamelement, ElOld1}]),
fsm_next_state(session_established, StateData); fsm_next_state(session_established, StateData);
throw:Exception -> throw:Exception ->
io:format("SESSION ESTABLISHED: Exception=~p~n", [Exception]), io:format("SESSION ESTABLISHED: Exception=~p~n", [Exception]),
@ -963,9 +935,8 @@ handle_sync_event({get_presence}, _From, StateName, StateData) ->
handle_sync_event(get_subscribed_and_online, _From, StateName, StateData) -> handle_sync_event(get_subscribed_and_online, _From, StateName, StateData) ->
Subscribed = StateData#state.pres_f, Subscribed = StateData#state.pres_f,
Online = StateData#state.pres_available, Online = StateData#state.pres_available,
% XXX OLF FORMAT: short JID with empty string(s).
Pred = fun({U, S, _R} = User, _Caps) -> Pred = fun({U, S, _R} = User, _Caps) ->
?SETS:is_element({U, S, ""}, ?SETS:is_element({U, S, undefined},
Subscribed) orelse Subscribed) orelse
?SETS:is_element(User, Subscribed) ?SETS:is_element(User, Subscribed)
end, end,
@ -994,19 +965,14 @@ handle_info(replaced, _StateName, StateData) ->
send_element(StateData, exmpp_stream:error('conflict')), send_element(StateData, exmpp_stream:error('conflict')),
send_element(StateData, exmpp_stream:closing()), send_element(StateData, exmpp_stream:closing()),
{stop, normal, StateData#state{authenticated = replaced}}; {stop, normal, StateData#state{authenticated = replaced}};
handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) -> handle_info({route, From, To, Packet}, StateName, StateData) ->
%% XXX OLD FORMAT: From, To and Packet are in the old format.
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
[?DEFAULT_NS], ?PREFIXED_NS),
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
{Pass, NewAttrs, NewState} = {Pass, NewAttrs, NewState} =
case Packet of case Packet of
#xmlel{attrs = Attrs} when ?IS_PRESENCE(Packet) -> #xmlel{attrs = Attrs} when ?IS_PRESENCE(Packet) ->
case exmpp_presence:get_type(Packet) of case exmpp_presence:get_type(Packet) of
'probe' -> 'probe' ->
LFrom = jlib:short_jid(From), LFrom = jlib:short_prepd_jid(From),
LBFrom = jlib:short_bare_jid(From), LBFrom = jlib:short_prepd_bare_jid(From),
NewStateData = NewStateData =
case ?SETS:is_element( case ?SETS:is_element(
LFrom, StateData#state.pres_a) orelse LFrom, StateData#state.pres_a) orelse
@ -1038,7 +1004,7 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
process_presence_probe(From, To, NewStateData), process_presence_probe(From, To, NewStateData),
{false, Attrs, NewStateData}; {false, Attrs, NewStateData};
'error' -> 'error' ->
LFrom = jlib:short_jid(From), LFrom = jlib:short_prepd_jid(From),
NewA = remove_element(LFrom, NewA = remove_element(LFrom,
StateData#state.pres_a), StateData#state.pres_a),
{true, Attrs, StateData#state{pres_a = NewA}}; {true, Attrs, StateData#state{pres_a = NewA}};
@ -1055,18 +1021,17 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
'unsubscribed' -> 'unsubscribed' ->
{true, Attrs, StateData}; {true, Attrs, StateData};
_ -> _ ->
% XXX OLD FORMAT: From, To, Packet.
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
[StateData#state.user, [StateData#state.user,
StateData#state.server, StateData#state.server,
StateData#state.privacy_list, StateData#state.privacy_list,
{FromOld, ToOld, PacketOld}, {From, To, Packet},
in]) of in]) of
allow -> allow ->
LFrom = jlib:short_jid(From), LFrom = jlib:short_prepd_jid(From),
LBFrom = jlib:short_bare_jid(From), LBFrom = jlib:short_prepd_bare_jid(From),
%% Note contact availability %% Note contact availability
Els = Packet#xmlel.children, Els = Packet#xmlel.children,
Caps = mod_caps:read_caps(Els), Caps = mod_caps:read_caps(Els),
@ -1144,9 +1109,7 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
case exmpp_iq:get_request(Packet) of case exmpp_iq:get_request(Packet) of
#xmlel{ns = ?NS_VCARD} -> #xmlel{ns = ?NS_VCARD} ->
Host = StateData#state.server, Host = StateData#state.server,
% XXX OLD FORMAT: sm_iqtable contains strings case ets:lookup(sm_iqtable, {?NS_VCARD, Host}) of
% for namespaces.
case ets:lookup(sm_iqtable, {atom_to_list(?NS_VCARD), Host}) of
[{_, Module, Function, Opts}] -> [{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts, gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Packet); From, To, Packet);
@ -1156,14 +1119,13 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
end, end,
{false, Attrs, StateData}; {false, Attrs, StateData};
_ -> _ ->
% XXX OLD FORMAT: From, To and Packet.
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
[StateData#state.user, [StateData#state.user,
StateData#state.server, StateData#state.server,
StateData#state.privacy_list, StateData#state.privacy_list,
{FromOld, ToOld, PacketOld}, {From, To, Packet},
in]) of in]) of
allow -> allow ->
{true, Attrs, StateData}; {true, Attrs, StateData};
@ -1177,14 +1139,13 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
{true, Attrs, StateData} {true, Attrs, StateData}
end; end;
#xmlel{attrs = Attrs} when ?IS_MESSAGE(Packet) -> #xmlel{attrs = Attrs} when ?IS_MESSAGE(Packet) ->
% XXX OLD FORMAT: From, To and Packet.
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
[StateData#state.user, [StateData#state.user,
StateData#state.server, StateData#state.server,
StateData#state.privacy_list, StateData#state.privacy_list,
{FromOld, ToOld, PacketOld}, {From, To, Packet},
in]) of in]) of
allow -> allow ->
{true, Attrs, StateData}; {true, Attrs, StateData};
@ -1203,19 +1164,13 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
Attrs3 = exmpp_stanza:set_recipient_in_attrs(Attrs2, To), Attrs3 = exmpp_stanza:set_recipient_in_attrs(Attrs2, To),
FixedPacket = Packet#xmlel{attrs = Attrs3}, FixedPacket = Packet#xmlel{attrs = Attrs3},
send_element(StateData, FixedPacket), send_element(StateData, FixedPacket),
% XXX OLD FORMAT: JID, From, To, FixedPacket.
JIDOld = jlib:to_old_jid(StateData#state.jid),
FixedPacketOld = exmpp_xml:xmlel_to_xmlelement(FixedPacket,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_hooks:run(user_receive_packet, ejabberd_hooks:run(user_receive_packet,
StateData#state.server, StateData#state.server,
[JIDOld, FromOld, ToOld, FixedPacketOld]), [StateData#state.jid, From, To, FixedPacket]),
% XXX OLD FORMAT: From, To, FixedPacket. ejabberd_hooks:run(c2s_loop_debug, [{route, From, To, Packet}]),
ejabberd_hooks:run(c2s_loop_debug, [{route, FromOld, ToOld, PacketOld}]),
fsm_next_state(StateName, NewState); fsm_next_state(StateName, NewState);
true -> true ->
% XXX OLD FORMAT: From, To, FixedPacket. ejabberd_hooks:run(c2s_loop_debug, [{route, From, To, Packet}]),
ejabberd_hooks:run(c2s_loop_debug, [{route, FromOld, ToOld, PacketOld}]),
fsm_next_state(StateName, NewState) fsm_next_state(StateName, NewState)
end; end;
handle_info({'DOWN', Monitor, _Type, _Object, _Info}, _StateName, StateData) handle_info({'DOWN', Monitor, _Type, _Object, _Info}, _StateName, StateData)
@ -1353,8 +1308,8 @@ get_conn_type(StateData) ->
end. end.
process_presence_probe(From, To, StateData) -> process_presence_probe(From, To, StateData) ->
LFrom = jlib:short_jid(From), LFrom = jlib:short_prepd_jid(From),
LBFrom = jlib:short_bare_jid(From), LBFrom = jlib:short_prepd_bare_jid(From),
case StateData#state.pres_last of case StateData#state.pres_last of
undefined -> undefined ->
ok; ok;
@ -1375,25 +1330,19 @@ process_presence_probe(From, To, StateData) ->
if if
Cond1 -> Cond1 ->
Packet = StateData#state.pres_last, Packet = StateData#state.pres_last,
% XXX OLD FORMAT: From, To, Packet.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
[?DEFAULT_NS], ?PREFIXED_NS),
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
[StateData#state.user, [StateData#state.user,
StateData#state.server, StateData#state.server,
StateData#state.privacy_list, StateData#state.privacy_list,
{ToOld, FromOld, PacketOld}, {To, From, Packet},
out]) of out]) of
deny -> deny ->
ok; ok;
allow -> allow ->
Pid=element(2, StateData#state.sid), Pid=element(2, StateData#state.sid),
% XXX OLD FORMAT: From, To. ejabberd_hooks:run(presence_probe_hook, StateData#state.server, [From, To, Pid]),
ejabberd_hooks:run(presence_probe_hook, StateData#state.server, [FromOld, ToOld, Pid]),
%% Don't route a presence probe to oneself %% Don't route a presence probe to oneself
case From == To of case From == To of
false -> false ->
@ -1491,11 +1440,9 @@ presence_update(From, Packet, StateData) ->
NewState = NewState =
if if
FromUnavail -> FromUnavail ->
% XXX OLD FORMAT: JID.
JIDOld = jlib:to_old_jid(StateData#state.jid),
ejabberd_hooks:run(user_available_hook, ejabberd_hooks:run(user_available_hook,
StateData#state.server, StateData#state.server,
[JIDOld]), [StateData#state.jid]),
if NewPriority >= 0 -> if NewPriority >= 0 ->
resend_offline_messages(StateData), resend_offline_messages(StateData),
resend_subscription_requests(StateData); resend_subscription_requests(StateData);
@ -1525,15 +1472,10 @@ presence_update(From, Packet, StateData) ->
end. end.
presence_track(From, To, Packet, StateData) -> presence_track(From, To, Packet, StateData) ->
LTo = jlib:short_jid(To), LTo = jlib:short_prepd_jid(To),
User = StateData#state.user, User = StateData#state.user,
Server = StateData#state.server, Server = StateData#state.server,
BFrom = exmpp_jid:jid_to_bare_jid(From), BFrom = exmpp_jid:jid_to_bare_jid(From),
% XXX OLD FORMAT: From, To, Packet.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
[?DEFAULT_NS], ?PREFIXED_NS),
case exmpp_presence:get_type(Packet) of case exmpp_presence:get_type(Packet) of
'unavailable' -> 'unavailable' ->
ejabberd_router:route(From, To, Packet), ejabberd_router:route(From, To, Packet),
@ -1548,31 +1490,27 @@ presence_track(From, To, Packet, StateData) ->
StateData#state{pres_i = I, StateData#state{pres_i = I,
pres_a = A}; pres_a = A};
'subscribe' -> 'subscribe' ->
% XXX OLD FORMAT: To.
ejabberd_hooks:run(roster_out_subscription, ejabberd_hooks:run(roster_out_subscription,
Server, Server,
[User, Server, ToOld, subscribe]), [User, Server, To, subscribe]),
ejabberd_router:route(BFrom, To, Packet), ejabberd_router:route(BFrom, To, Packet),
StateData; StateData;
'subscribed' -> 'subscribed' ->
% XXX OLD FORMAT: To.
ejabberd_hooks:run(roster_out_subscription, ejabberd_hooks:run(roster_out_subscription,
Server, Server,
[User, Server, ToOld, subscribed]), [User, Server, To, subscribed]),
ejabberd_router:route(BFrom, To, Packet), ejabberd_router:route(BFrom, To, Packet),
StateData; StateData;
'unsubscribe' -> 'unsubscribe' ->
% XXX OLD FORMAT: To.
ejabberd_hooks:run(roster_out_subscription, ejabberd_hooks:run(roster_out_subscription,
Server, Server,
[User, Server, ToOld, unsubscribe]), [User, Server, To, unsubscribe]),
ejabberd_router:route(BFrom, To, Packet), ejabberd_router:route(BFrom, To, Packet),
StateData; StateData;
'unsubscribed' -> 'unsubscribed' ->
% XXX OLD FORMAT: To.
ejabberd_hooks:run(roster_out_subscription, ejabberd_hooks:run(roster_out_subscription,
Server, Server,
[User, Server, ToOld, unsubscribed]), [User, Server, To, unsubscribed]),
ejabberd_router:route(BFrom, To, Packet), ejabberd_router:route(BFrom, To, Packet),
StateData; StateData;
'error' -> 'error' ->
@ -1582,14 +1520,13 @@ presence_track(From, To, Packet, StateData) ->
ejabberd_router:route(From, To, Packet), ejabberd_router:route(From, To, Packet),
StateData; StateData;
_ -> _ ->
% XXX OLD FORMAT: From, To, Packet.
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
[StateData#state.user, [StateData#state.user,
StateData#state.server, StateData#state.server,
StateData#state.privacy_list, StateData#state.privacy_list,
{FromOld, ToOld, PacketOld}, {From, To, Packet},
out]) of out]) of
deny -> deny ->
ok; ok;
@ -1605,18 +1542,13 @@ presence_track(From, To, Packet, StateData) ->
presence_broadcast(StateData, From, JIDSet, Packet) -> presence_broadcast(StateData, From, JIDSet, Packet) ->
lists:foreach(fun({U, S, R}) -> lists:foreach(fun({U, S, R}) ->
FJID = exmpp_jid:make_jid(U, S, R), FJID = exmpp_jid:make_jid(U, S, R),
% XXX OLD FORMAT: From, FJID, Packet.
FJIDOld = jlib:to_old_jid(FJID),
FromOld = jlib:to_old_jid(From),
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
[?DEFAULT_NS], ?PREFIXED_NS),
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
[StateData#state.user, [StateData#state.user,
StateData#state.server, StateData#state.server,
StateData#state.privacy_list, StateData#state.privacy_list,
{FromOld, FJIDOld, PacketOld}, {From, FJID, Packet},
out]) of out]) of
deny -> deny ->
ok; ok;
@ -1626,24 +1558,18 @@ presence_broadcast(StateData, From, JIDSet, Packet) ->
end, ?SETS:to_list(JIDSet)). end, ?SETS:to_list(JIDSet)).
presence_broadcast_to_trusted(StateData, From, T, A, Packet) -> presence_broadcast_to_trusted(StateData, From, T, A, Packet) ->
% XXX OLD FORMAT: From, Packet.
FromOld = jlib:to_old_jid(From),
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
[?DEFAULT_NS], ?PREFIXED_NS),
lists:foreach( lists:foreach(
fun({U, S, R} = JID) -> fun({U, S, R} = JID) ->
case ?SETS:is_element(JID, T) of case ?SETS:is_element(JID, T) of
true -> true ->
FJID = exmpp_jid:make_jid(U, S, R), FJID = exmpp_jid:make_jid(U, S, R),
% XXX OLD FORMAT: FJID.
FJIDOld = jlib:to_old_jid(FJID),
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
[StateData#state.user, [StateData#state.user,
StateData#state.server, StateData#state.server,
StateData#state.privacy_list, StateData#state.privacy_list,
{FromOld, FJIDOld, PacketOld}, {From, FJID, Packet},
out]) of out]) of
deny -> deny ->
ok; ok;
@ -1675,18 +1601,13 @@ presence_broadcast_first(From, StateData, Packet) ->
As = ?SETS:fold( As = ?SETS:fold(
fun({U, S, R} = JID, A) -> fun({U, S, R} = JID, A) ->
FJID = exmpp_jid:make_jid(U, S, R), FJID = exmpp_jid:make_jid(U, S, R),
% XXX OLD FORMAT: From, FJID, Packet.
FromOld = jlib:to_old_jid(From),
FJIDOld = jlib:to_old_jid(FJID),
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
[?DEFAULT_NS], ?PREFIXED_NS),
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
[StateData#state.user, [StateData#state.user,
StateData#state.server, StateData#state.server,
StateData#state.privacy_list, StateData#state.privacy_list,
{FromOld, FJIDOld, PacketOld}, {From, FJID, Packet},
out]) of out]) of
deny -> deny ->
ok; ok;
@ -1711,7 +1632,7 @@ remove_element(E, Set) ->
roster_change(IJID, ISubscription, StateData) -> roster_change(IJID, ISubscription, StateData) ->
LIJID = jlib:short_jid(IJID), LIJID = jlib:short_prepd_jid(IJID),
IsFrom = (ISubscription == both) or (ISubscription == from), IsFrom = (ISubscription == both) or (ISubscription == from),
IsTo = (ISubscription == both) or (ISubscription == to), IsTo = (ISubscription == both) or (ISubscription == to),
OldIsFrom = ?SETS:is_element(LIJID, StateData#state.pres_f), OldIsFrom = ?SETS:is_element(LIJID, StateData#state.pres_f),
@ -1734,9 +1655,6 @@ roster_change(IJID, ISubscription, StateData) ->
?DEBUG("roster changed for ~p~n", [StateData#state.user]), ?DEBUG("roster changed for ~p~n", [StateData#state.user]),
From = StateData#state.jid, From = StateData#state.jid,
To = IJID, To = IJID,
% XXX OLD FORMAT: From, To.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
Cond1 = (not StateData#state.pres_invis) and IsFrom Cond1 = (not StateData#state.pres_invis) and IsFrom
and (not OldIsFrom), and (not OldIsFrom),
Cond2 = (not IsFrom) and OldIsFrom Cond2 = (not IsFrom) and OldIsFrom
@ -1745,17 +1663,13 @@ roster_change(IJID, ISubscription, StateData) ->
if if
Cond1 -> Cond1 ->
?DEBUG("C1: ~p~n", [LIJID]), ?DEBUG("C1: ~p~n", [LIJID]),
% XXX OLD FORMAT: P.
POld = exmpp_xml:xmlelement_to_xmlel(P,
[?DEFAULT_NS], ?PREFIXED_NS),
% XXX OLD FORMAT: From, To, P.
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
[StateData#state.user, [StateData#state.user,
StateData#state.server, StateData#state.server,
StateData#state.privacy_list, StateData#state.privacy_list,
{FromOld, ToOld, POld}, {From, To, P},
out]) of out]) of
deny -> deny ->
ok; ok;
@ -1770,17 +1684,13 @@ roster_change(IJID, ISubscription, StateData) ->
Cond2 -> Cond2 ->
?DEBUG("C2: ~p~n", [LIJID]), ?DEBUG("C2: ~p~n", [LIJID]),
PU = exmpp_presence:unavailable(), PU = exmpp_presence:unavailable(),
% XXX OLD FORMAT: PU.
PUOld = exmpp_xml:xmlelement_to_xmlel(PU,
[?DEFAULT_NS], ?PREFIXED_NS),
% XXX OLD FORMAT: From, To, PU.
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
[StateData#state.user, [StateData#state.user,
StateData#state.server, StateData#state.server,
StateData#state.privacy_list, StateData#state.privacy_list,
{FromOld, ToOld, PUOld}, {From, To, PU},
out]) of out]) of
deny -> deny ->
ok; ok;
@ -1813,26 +1723,21 @@ update_priority(Priority, Packet, StateData) ->
Info). Info).
process_privacy_iq(From, To, process_privacy_iq(From, To,
El, #iq{type = Type} = IQ_Rec,
StateData) -> StateData) ->
% XXX OLD FORMAT: IQ_Rec is an #iq.
IQ_Rec = jlib:iq_query_info(El),
% XXX OLD FORMAT: JIDs.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
{Res, NewStateData} = {Res, NewStateData} =
case exmpp_iq:get_type(El) of case Type of
get -> get ->
R = ejabberd_hooks:run_fold( R = ejabberd_hooks:run_fold(
privacy_iq_get, StateData#state.server, privacy_iq_get, StateData#state.server,
{error, ?ERR_FEATURE_NOT_IMPLEMENTED}, {error, ?ERR_FEATURE_NOT_IMPLEMENTED},
[FromOld, ToOld, IQ_Rec, StateData#state.privacy_list]), [From, To, IQ_Rec, StateData#state.privacy_list]),
{R, StateData}; {R, StateData};
set -> set ->
case ejabberd_hooks:run_fold( case ejabberd_hooks:run_fold(
privacy_iq_set, StateData#state.server, privacy_iq_set, StateData#state.server,
{error, ?ERR_FEATURE_NOT_IMPLEMENTED}, {error, ?ERR_FEATURE_NOT_IMPLEMENTED},
[FromOld, ToOld, IQ_Rec]) of [From, To, IQ_Rec]) of
{result, R, NewPrivList} -> {result, R, NewPrivList} ->
{{result, R}, {{result, R},
StateData#state{privacy_list = NewPrivList}}; StateData#state{privacy_list = NewPrivList}};
@ -1841,14 +1746,10 @@ process_privacy_iq(From, To,
end, end,
IQRes = IQRes =
case Res of case Res of
{result, ResultOld} -> {result, Result} ->
Result = exmpp_xml:xmlelement_to_xmlel(ResultOld, exmpp_iq:result(IQ_Rec, Result);
[?DEFAULT_NS], ?PREFIXED_NS), {error, Error} ->
exmpp_iq:result(El, Result); exmpp_iq:error(IQ_Rec, Error)
{error, ErrorOld} ->
Error = exmpp_xml:xmlelement_to_xmlel(ErrorOld,
[?DEFAULT_NS], ?PREFIXED_NS),
exmpp_iq:error(El, Error)
end, end,
ejabberd_router:route( ejabberd_router:route(
To, From, IQRes), To, From, IQRes),
@ -1863,18 +1764,16 @@ resend_offline_messages(#state{user = User,
[], [],
[User, Server]) of [User, Server]) of
Rs when list(Rs) -> Rs when list(Rs) ->
% XXX OLD FORMAT: From, To, Packet.
% XXX OLD FORMAT ON DISK!
lists:foreach( lists:foreach(
fun({route, fun({route,
FromOld, ToOld, PacketOld}) -> From, To, Packet}) ->
Pass = case ejabberd_hooks:run_fold( Pass = case ejabberd_hooks:run_fold(
privacy_check_packet, Server, privacy_check_packet, Server,
allow, allow,
[User, [User,
Server, Server,
PrivList, PrivList,
{FromOld, ToOld, PacketOld}, {From, To, Packet},
in]) of in]) of
allow -> allow ->
true; true;
@ -1883,11 +1782,6 @@ resend_offline_messages(#state{user = User,
end, end,
if if
Pass -> Pass ->
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
[?DEFAULT_NS], ?PREFIXED_NS),
Attrs1 = exmpp_stanza:set_sender_in_attrs( Attrs1 = exmpp_stanza:set_sender_in_attrs(
Packet#xmlel.attrs, From), Packet#xmlel.attrs, From),
Attrs2 = exmpp_stanza:set_recipient_in_attrs( Attrs2 = exmpp_stanza:set_recipient_in_attrs(
@ -1907,11 +1801,7 @@ resend_subscription_requests(#state{user = User,
Server, Server,
[], [],
[User, Server]), [User, Server]),
% XXX OLD FORMAT: XMLPacket. lists:foreach(fun(XMLPacket) ->
% XXX OLD FORMAT ON DISK!
lists:foreach(fun(XMLPacketOld) ->
XMLPacket = exmpp_xml:xmlelement_to_xmlel(
XMLPacketOld, [?DEFAULT_NS], ?PREFIXED_NS),
send_element(StateData, send_element(StateData,
XMLPacket) XMLPacket)
end, end,
@ -1920,14 +1810,13 @@ resend_subscription_requests(#state{user = User,
process_unauthenticated_stanza(StateData, El) -> process_unauthenticated_stanza(StateData, El) ->
case exmpp_iq:get_kind(El) of case exmpp_iq:get_kind(El) of
request -> request ->
% XXX OLD FORMAT: IQ_Rec is an #iq. IQ_Rec = exmpp_iq:xmlel_to_iq(El),
IQ_Rec = jlib:iq_query_info(El), Res = ejabberd_hooks:run_fold(c2s_unauthenticated_iq,
ResOld = ejabberd_hooks:run_fold(c2s_unauthenticated_iq,
StateData#state.server, StateData#state.server,
empty, empty,
[StateData#state.server, IQ_Rec, [StateData#state.server, IQ_Rec,
StateData#state.ip]), StateData#state.ip]),
case ResOld of case Res of
empty -> empty ->
% The only reasonable IQ's here are auth and register IQ's % The only reasonable IQ's here are auth and register IQ's
% They contain secrets, so don't include subelements to response % They contain secrets, so don't include subelements to response
@ -1938,8 +1827,6 @@ process_unauthenticated_stanza(StateData, El) ->
Res2 = exmpp_stanza:remove_recipient(Res1), Res2 = exmpp_stanza:remove_recipient(Res1),
send_element(StateData, Res2); send_element(StateData, Res2);
_ -> _ ->
Res = exmpp_xml:xmlelement_to_xmlel(ResOld,
[?DEFAULT_NS], ?PREFIXED_NS),
send_element(StateData, Res) send_element(StateData, Res)
end; end;
_ -> _ ->

View File

@ -321,14 +321,9 @@ do_route(From, To, Packet) ->
"error" -> ok; "error" -> ok;
"result" -> ok; "result" -> ok;
_ -> _ ->
% XXX OLD FORMAT: From, To, Packet.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_hooks:run(local_send_to_resource_hook, ejabberd_hooks:run(local_send_to_resource_hook,
To#jid.ldomain, To#jid.ldomain,
[FromOld, ToOld, PacketOld]) [From, To, Packet])
end end
end. end.

View File

@ -321,19 +321,9 @@ code_change(_OldVsn, State, _Extra) ->
do_route(OrigFrom, OrigTo, OrigPacket) -> do_route(OrigFrom, OrigTo, OrigPacket) ->
?DEBUG("route~n\tfrom ~p~n\tto ~p~n\tpacket ~p~n", ?DEBUG("route~n\tfrom ~p~n\tto ~p~n\tpacket ~p~n",
[OrigFrom, OrigTo, OrigPacket]), [OrigFrom, OrigTo, OrigPacket]),
% XXX OLD FORMAT: OrigFrom, OrigTo, OrigPacket.
OrigFromOld = jlib:to_old_jid(OrigFrom),
OrigToOld = jlib:to_old_jid(OrigTo),
OrigPacketOld = exmpp_xml:xmlel_to_xmlelement(OrigPacket,
[?NS_JABBER_CLIENT], [{?NS_XMPP, ?NS_XMPP_pfx}]),
case ejabberd_hooks:run_fold(filter_packet, case ejabberd_hooks:run_fold(filter_packet,
{OrigFromOld, OrigToOld, OrigPacketOld}, []) of {OrigFrom, OrigTo, OrigPacket}, []) of
{FromOld, ToOld, PacketOld} -> {From, To, Packet} ->
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
[?NS_JABBER_CLIENT], [{?NS_XMPP, ?NS_XMPP_pfx}]),
LDstDomain = To#jid.ldomain, LDstDomain = To#jid.ldomain,
case mnesia:dirty_read(route, LDstDomain) of case mnesia:dirty_read(route, LDstDomain) of
[] -> [] ->
@ -358,12 +348,12 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
{domain_balancing, LDstDomain}) of {domain_balancing, LDstDomain}) of
undefined -> now(); undefined -> now();
random -> now(); random -> now();
source -> jlib:short_jid(From); source -> jlib:short_prepd_jid(From);
destination -> jlib:short_jid(To); destination -> jlib:short_prepd_jid(To);
bare_source -> bare_source ->
jlib:short_bare_jid(From); jlib:short_prepd_bare_jid(From);
bare_destination -> bare_destination ->
jlib:short_bare_jid(To) jlib:short_prepd_bare_jid(To)
end, end,
case get_component_number(LDstDomain) of case get_component_number(LDstDomain) of
undefined -> undefined ->

View File

@ -283,15 +283,10 @@ do_route(From, To, Packet) ->
NewPacket1 = exmpp_stanza:set_sender(Packet, From), NewPacket1 = exmpp_stanza:set_sender(Packet, From),
NewPacket = exmpp_stanza:set_recipient(NewPacket1, To), NewPacket = exmpp_stanza:set_recipient(NewPacket1, To),
#jid{ldomain = MyServer} = From, #jid{ldomain = MyServer} = From,
% XXX OLD FORMAT: From, To, NewPacket.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
NewPacketOld = exmpp_xml:xmlel_to_xmlelement(NewPacket,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_hooks:run( ejabberd_hooks:run(
s2s_send_packet, s2s_send_packet,
MyServer, MyServer,
[FromOld, ToOld, NewPacketOld]), [From, To, NewPacket]),
send_element(Pid, NewPacket), send_element(Pid, NewPacket),
ok; ok;
{aborted, _Reason} -> {aborted, _Reason} ->

View File

@ -386,11 +386,8 @@ stream_established({xmlstreamelement, El}, StateData) ->
_Exception2 -> error _Exception2 -> error
end end
end, end,
% XXX OLD FORMAT: El. % No namespace conversion (:server <-> :client) is done.
% XXX No namespace conversion (:server <-> :client) is done.
% This is handled by C2S and S2S send_element functions. % This is handled by C2S and S2S send_element functions.
ElOld = exmpp_xml:xmlel_to_xmlelement(El,
[?DEFAULT_NS], ?PREFIXED_NS),
if if
(To /= error) and (From /= error) -> (To /= error) and (From /= error) ->
LFrom = From#jid.ldomain, LFrom = From#jid.ldomain,
@ -407,13 +404,10 @@ stream_established({xmlstreamelement, El}, StateData) ->
if ((Name == 'iq') or if ((Name == 'iq') or
(Name == 'message') or (Name == 'message') or
(Name == 'presence')) -> (Name == 'presence')) ->
% XXX OLD FORMAT: From, To.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
ejabberd_hooks:run( ejabberd_hooks:run(
s2s_receive_packet, s2s_receive_packet,
LFrom, LFrom,
[FromOld, ToOld, ElOld]), [From, To, El]),
ejabberd_router:route( ejabberd_router:route(
From, To, El); From, To, El);
true -> true ->
@ -430,13 +424,10 @@ stream_established({xmlstreamelement, El}, StateData) ->
if ((Name == 'iq') or if ((Name == 'iq') or
(Name == 'message') or (Name == 'message') or
(Name == 'presence')) -> (Name == 'presence')) ->
% XXX OLD FORMAT: From, To.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
ejabberd_hooks:run( ejabberd_hooks:run(
s2s_receive_packet, s2s_receive_packet,
LFrom, LFrom,
[FromOld, ToOld, ElOld]), [From, To, El]),
ejabberd_router:route( ejabberd_router:route(
From, To, El); From, To, El);
true -> true ->
@ -449,7 +440,7 @@ stream_established({xmlstreamelement, El}, StateData) ->
true -> true ->
error error
end, end,
ejabberd_hooks:run(s2s_loop_debug, [{xmlstreamelement, ElOld}]), ejabberd_hooks:run(s2s_loop_debug, [{xmlstreamelement, El}]),
{next_state, stream_established, StateData#state{timer = Timer}} {next_state, stream_established, StateData#state{timer = Timer}}
end; end;
@ -656,11 +647,11 @@ get_cert_domains(Cert) ->
case 'XmppAddr':decode( case 'XmppAddr':decode(
'XmppAddr', XmppAddr) of 'XmppAddr', XmppAddr) of
{ok, D} when is_binary(D) -> {ok, D} when is_binary(D) ->
case jlib:string_to_jid( case exmpp_jid:list_to_jid(
binary_to_list(D)) of binary_to_list(D)) of
#jid{lnode = "", #jid{lnode = undefined,
ldomain = LD, ldomain = LD,
lresource = ""} -> lresource = undefined} ->
case idna:domain_utf8_to_ascii(LD) of case idna:domain_utf8_to_ascii(LD) of
false -> false ->
[]; [];

View File

@ -716,10 +716,7 @@ handle_info({send_text, Text}, StateName, StateData) ->
{next_state, StateName, StateData#state{timer = Timer}, {next_state, StateName, StateData#state{timer = Timer},
get_timeout_interval(StateName)}; get_timeout_interval(StateName)};
handle_info({send_element, ElOld}, StateName, StateData) -> handle_info({send_element, El}, StateName, StateData) ->
% XXX OLD FORMAT: El.
El = exmpp_xml:xmlelement_to_xmlel(ElOld,
[?NS_JABBER_CLIENT], ?PREFIXED_NS),
case StateName of case StateName of
stream_established -> stream_established ->
cancel_timer(StateData#state.timer), cancel_timer(StateData#state.timer),
@ -839,10 +836,7 @@ cancel_timer(Timer) ->
bounce_messages(Condition) -> bounce_messages(Condition) ->
receive receive
{send_element, ElOld} -> {send_element, El} ->
% XXX OLD FORMAT: El.
El = exmpp_xml:xmlelement_to_xmlel(ElOld,
[?NS_JABBER_CLIENT], ?PREFIXED_NS),
bounce_element(El, Condition), bounce_element(El, Condition),
bounce_messages(Condition) bounce_messages(Condition)
after 0 -> after 0 ->

View File

@ -107,10 +107,8 @@ open_session(SID, User, Server, Resource, Info) ->
set_session(SID, User, Server, Resource, undefined, Info), set_session(SID, User, Server, Resource, undefined, Info),
check_for_sessions_to_replace(User, Server, Resource), check_for_sessions_to_replace(User, Server, Resource),
JID = exmpp_jid:make_jid(User, Server, Resource), JID = exmpp_jid:make_jid(User, Server, Resource),
% XXX OLD FORMAT: JID.
JIDOld = jlib:to_old_jid(JID),
ejabberd_hooks:run(sm_register_connection_hook, JID#jid.ldomain, ejabberd_hooks:run(sm_register_connection_hook, JID#jid.ldomain,
[SID, JIDOld, Info]). [SID, JID, Info]).
close_session(SID, User, Server, Resource) -> close_session(SID, User, Server, Resource) ->
Info = case mnesia:dirty_read({session, SID}) of Info = case mnesia:dirty_read({session, SID}) of
@ -122,10 +120,8 @@ close_session(SID, User, Server, Resource) ->
end, end,
mnesia:sync_dirty(F), mnesia:sync_dirty(F),
JID = exmpp_jid:make_jid(User, Server, Resource), JID = exmpp_jid:make_jid(User, Server, Resource),
% XXX OLD FORMAT: JID.
JIDOld = jlib:to_old_jid(JID),
ejabberd_hooks:run(sm_remove_connection_hook, JID#jid.ldomain, ejabberd_hooks:run(sm_remove_connection_hook, JID#jid.ldomain,
[SID, JIDOld, Info]). [SID, JID, Info]).
check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) -> check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
case ejabberd_auth:is_user_exists(User, Server) of case ejabberd_auth:is_user_exists(User, Server) of
@ -188,11 +184,8 @@ get_user_info(User, Server, Resource) ->
set_presence(SID, User, Server, Resource, Priority, Presence, Info) -> set_presence(SID, User, Server, Resource, Priority, Presence, Info) ->
set_session(SID, User, Server, Resource, Priority, Info), set_session(SID, User, Server, Resource, Priority, Info),
% XXX OLD FORMAT: Presence.
PresenceOld = exmpp_xml:xmlel_to_xmlelement(Presence,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_hooks:run(set_presence_hook, exmpp_stringprep:nameprep(Server), ejabberd_hooks:run(set_presence_hook, exmpp_stringprep:nameprep(Server),
[User, Server, Resource, PresenceOld]). [User, Server, Resource, Presence]).
unset_presence(SID, User, Server, Resource, Status, Info) -> unset_presence(SID, User, Server, Resource, Status, Info) ->
set_session(SID, User, Server, Resource, undefined, Info), set_session(SID, User, Server, Resource, undefined, Info),
@ -408,9 +401,6 @@ do_route(From, To, Packet) ->
[From, To, Packet, 8]), [From, To, Packet, 8]),
#jid{node = User, domain = Server, #jid{node = User, domain = Server,
lnode = LUser, ldomain = LServer, lresource = LResource} = To, lnode = LUser, ldomain = LServer, lresource = LResource} = To,
% XXX OLD FORMAT: From, To.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
case LResource of case LResource of
undefined -> undefined ->
case Packet of case Packet of
@ -419,36 +409,32 @@ do_route(From, To, Packet) ->
case exmpp_presence:get_type(Packet) of case exmpp_presence:get_type(Packet) of
'subscribe' -> 'subscribe' ->
Reason = exmpp_presence:get_status(Packet), Reason = exmpp_presence:get_status(Packet),
% XXX OLD FORMAT: From.
{ejabberd_hooks:run_fold( {ejabberd_hooks:run_fold(
roster_in_subscription, roster_in_subscription,
LServer, LServer,
false, false,
[User, Server, FromOld, subscribe, Reason]), [User, Server, From, subscribe, Reason]),
true}; true};
'subscribed' -> 'subscribed' ->
% XXX OLD FORMAT: From.
{ejabberd_hooks:run_fold( {ejabberd_hooks:run_fold(
roster_in_subscription, roster_in_subscription,
LServer, LServer,
false, false,
[User, Server, FromOld, subscribed, ""]), [User, Server, From, subscribed, ""]),
true}; true};
'unsubscribe' -> 'unsubscribe' ->
% XXX OLD FORMAT: From.
{ejabberd_hooks:run_fold( {ejabberd_hooks:run_fold(
roster_in_subscription, roster_in_subscription,
LServer, LServer,
false, false,
[User, Server, FromOld, unsubscribe, ""]), [User, Server, From, unsubscribe, ""]),
true}; true};
'unsubscribed' -> 'unsubscribed' ->
% XXX OLD FORMAT: From.
{ejabberd_hooks:run_fold( {ejabberd_hooks:run_fold(
roster_in_subscription, roster_in_subscription,
LServer, LServer,
false, false,
[User, Server, FromOld, unsubscribed, ""]), [User, Server, From, unsubscribed, ""]),
true}; true};
_ -> _ ->
{true, false} {true, false}
@ -504,10 +490,7 @@ do_route(From, To, Packet) ->
Session = lists:max(Ss), Session = lists:max(Ss),
Pid = element(2, Session#session.sid), Pid = element(2, Session#session.sid),
?DEBUG("sending to process ~p~n", [Pid]), ?DEBUG("sending to process ~p~n", [Pid]),
% XXX OLD FORMAT: From, To, Packet. Pid ! {route, From, To, Packet}
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
[?DEFAULT_NS], ?PREFIXED_NS),
Pid ! {route, FromOld, ToOld, PacketOld}
end end
end. end.
@ -515,11 +498,6 @@ route_message(From, To, Packet) ->
LUser = To#jid.lnode, LUser = To#jid.lnode,
LServer = To#jid.ldomain, LServer = To#jid.ldomain,
PrioRes = get_user_present_resources(LUser, LServer), PrioRes = get_user_present_resources(LUser, LServer),
% XXX OLD FORMAT: From, To, Packet.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
[?DEFAULT_NS], ?PREFIXED_NS),
case catch lists:max(PrioRes) of case catch lists:max(PrioRes) of
{Priority, _R} when is_integer(Priority), Priority >= 0 -> {Priority, _R} when is_integer(Priority), Priority >= 0 ->
lists:foreach( lists:foreach(
@ -535,8 +513,7 @@ route_message(From, To, Packet) ->
Session = lists:max(Ss), Session = lists:max(Ss),
Pid = element(2, Session#session.sid), Pid = element(2, Session#session.sid),
?DEBUG("sending to process ~p~n", [Pid]), ?DEBUG("sending to process ~p~n", [Pid]),
% XXX OLD FORMAT: From, To, Packet. Pid ! {route, From, To, Packet}
Pid ! {route, FromOld, ToOld, PacketOld}
end; end;
%% Ignore other priority: %% Ignore other priority:
({_Prio, _Res}) -> ({_Prio, _Res}) ->
@ -554,10 +531,9 @@ route_message(From, To, Packet) ->
_ -> _ ->
case ejabberd_auth:is_user_exists(LUser, LServer) of case ejabberd_auth:is_user_exists(LUser, LServer) of
true -> true ->
% XXX OLD FORMAT: From, To, Packet.
ejabberd_hooks:run(offline_message_hook, ejabberd_hooks:run(offline_message_hook,
LServer, LServer,
[FromOld, ToOld, PacketOld]); [From, To, Packet]);
_ -> _ ->
Err = exmpp_stanza:reply_with_error( Err = exmpp_stanza:reply_with_error(
Packet, 'service-unaivailable'), Packet, 'service-unaivailable'),