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

Merge pull request #493 from weiss/rfc-6121-routing

Update ejabberd_sm's routing rules as per RFC 6121
This commit is contained in:
Evgeny Khramtsov 2015-04-01 11:41:05 +03:00
commit 305b281c15
4 changed files with 35 additions and 91 deletions

View File

@ -1694,23 +1694,12 @@ handle_info({route, From, To,
jlib:replace_from_to_attrs(jlib:jid_to_string(From),
jlib:jid_to_string(To), NewAttrs),
FixedPacket = #xmlel{name = Name, attrs = Attrs2, children = Els},
FinalState =
case ejabberd_hooks:run_fold(c2s_filter_packet_in,
NewState#state.server, FixedPacket,
[NewState#state.jid, From, To])
of
drop ->
NewState;
FinalPacket = #xmlel{} ->
SentState = send_packet(NewState, FinalPacket),
ejabberd_hooks:run(user_receive_packet,
SentState#state.server,
[SentState#state.jid, From, To,
FinalPacket]),
SentState
end,
SentStateData = send_packet(NewState, FixedPacket),
ejabberd_hooks:run(user_receive_packet,
SentStateData#state.server,
[SentStateData#state.jid, From, To, FixedPacket]),
ejabberd_hooks:run(c2s_loop_debug, [{route, From, To, Packet}]),
fsm_next_state(StateName, FinalState);
fsm_next_state(StateName, SentStateData);
true ->
ejabberd_hooks:run(c2s_loop_debug, [{route, From, To, Packet}]),
fsm_next_state(StateName, NewState)

View File

@ -516,7 +516,18 @@ do_route(From, To, #xmlel{} = Packet) ->
PResources);
true -> ok
end;
<<"message">> -> route_message(From, To, Packet);
<<"message">> ->
case xml:get_attr_s(<<"type">>, Attrs) of
<<"chat">> -> route_message(From, To, Packet, chat);
<<"headline">> -> route_message(From, To, Packet, headline);
<<"error">> -> ok;
<<"groupchat">> ->
Err = jlib:make_error_reply(Packet,
?ERR_SERVICE_UNAVAILABLE),
ejabberd_router:route(To, From, Err);
_ ->
route_message(From, To, Packet, normal)
end;
<<"iq">> -> process_iq(From, To, Packet);
_ -> ok
end;
@ -525,7 +536,15 @@ do_route(From, To, #xmlel{} = Packet) ->
case Mod:get_sessions(LUser, LServer, LResource) of
[] ->
case Name of
<<"message">> -> route_message(From, To, Packet);
<<"message">> ->
case xml:get_attr_s(<<"type">>, Attrs) of
<<"chat">> -> route_message(From, To, Packet, chat);
<<"error">> -> ok;
_ ->
Err = jlib:make_error_reply(Packet,
?ERR_SERVICE_UNAVAILABLE),
ejabberd_router:route(To, From, Err)
end;
<<"iq">> ->
case xml:get_attr_s(<<"type">>, Attrs) of
<<"error">> -> ok;
@ -568,14 +587,15 @@ is_privacy_allow(From, To, Packet, PrivacyList) ->
[User, Server, PrivacyList, {From, To, Packet},
in]).
route_message(From, To, Packet) ->
route_message(From, To, Packet, Type) ->
LUser = To#jid.luser,
LServer = To#jid.lserver,
PrioRes = get_user_present_resources(LUser, LServer),
case catch lists:max(PrioRes) of
{Priority, _R}
when is_integer(Priority), Priority >= 0 ->
lists:foreach(fun ({P, R}) when P == Priority ->
lists:foreach(fun ({P, R}) when P == Priority;
(P >= 0) and (Type == headline) ->
LResource = jlib:resourceprep(R),
Mod = get_sm_backend(),
case Mod:get_sessions(LUser, LServer,
@ -593,11 +613,10 @@ route_message(From, To, Packet) ->
end,
PrioRes);
_ ->
case xml:get_tag_attr_s(<<"type">>, Packet) of
<<"error">> -> ok;
<<"groupchat">> ->
bounce_offline_message(From, To, Packet);
<<"headline">> ->
case Type of
error -> ok;
headline -> ok;
groupchat ->
bounce_offline_message(From, To, Packet);
_ ->
case ejabberd_auth:is_user_exists(LUser, LServer) of

View File

@ -74,8 +74,7 @@
on_user_offline/3, remove_user/2,
disco_local_identity/5, disco_local_features/5,
disco_local_items/5, disco_sm_identity/5,
disco_sm_features/5, disco_sm_items/5,
drop_pep_error/4]).
disco_sm_features/5, disco_sm_items/5]).
%% exported iq handlers
-export([iq_sm/3]).
@ -345,8 +344,6 @@ init([ServerHost, Opts]) ->
?MODULE, disco_sm_features, 75),
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE,
disco_sm_items, 75),
ejabberd_hooks:add(c2s_filter_packet_in, ServerHost, ?MODULE,
drop_pep_error, 75),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost,
?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost,
@ -1331,33 +1328,6 @@ unsubscribe_user(Entity, Owner) ->
plugins(Host))
end).
%% -------
%% packet receive hook handling function
%%
drop_pep_error(#xmlel{name = <<"message">>, attrs = Attrs} = Packet, _JID, From,
#jid{lresource = <<"">>} = To) ->
case xml:get_attr_s(<<"type">>, Attrs) of
<<"error">> ->
case xml:get_subtag(Packet, <<"event">>) of
#xmlel{attrs = EventAttrs} ->
case xml:get_attr_s(<<"xmlns">>, EventAttrs) of
?NS_PUBSUB_EVENT ->
?DEBUG("Dropping PEP error message from ~s to ~s",
[jlib:jid_to_string(From),
jlib:jid_to_string(To)]),
drop;
_ ->
Packet
end;
false ->
Packet
end;
_ ->
Packet
end;
drop_pep_error(Acc, _JID, _From, _To) -> Acc.
%% -------
%% user remove hook handling function
%%
@ -1498,8 +1468,6 @@ terminate(_Reason,
?MODULE, disco_sm_features, 75),
ejabberd_hooks:delete(disco_sm_items, ServerHost,
?MODULE, disco_sm_items, 75),
ejabberd_hooks:delete(c2s_filter_packet_in, ServerHost,
?MODULE, drop_pep_error, 75),
gen_iq_handler:remove_iq_handler(ejabberd_sm,
ServerHost, ?NS_PUBSUB),
gen_iq_handler:remove_iq_handler(ejabberd_sm,

View File

@ -74,8 +74,7 @@
on_user_offline/3, remove_user/2,
disco_local_identity/5, disco_local_features/5,
disco_local_items/5, disco_sm_identity/5,
disco_sm_features/5, disco_sm_items/5,
drop_pep_error/4]).
disco_sm_features/5, disco_sm_items/5]).
%% exported iq handlers
-export([iq_sm/3]).
@ -345,8 +344,6 @@ init([ServerHost, Opts]) ->
?MODULE, disco_sm_features, 75),
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE,
disco_sm_items, 75),
ejabberd_hooks:add(c2s_filter_packet_in, ServerHost, ?MODULE,
drop_pep_error, 75),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost,
?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost,
@ -941,33 +938,6 @@ unsubscribe_user(Entity, Owner) ->
plugins(Host))
end).
%% -------
%% packet receive hook handling function
%%
drop_pep_error(#xmlel{name = <<"message">>, attrs = Attrs} = Packet, _JID, From,
#jid{lresource = <<"">>} = To) ->
case xml:get_attr_s(<<"type">>, Attrs) of
<<"error">> ->
case xml:get_subtag(Packet, <<"event">>) of
#xmlel{attrs = EventAttrs} ->
case xml:get_attr_s(<<"xmlns">>, EventAttrs) of
?NS_PUBSUB_EVENT ->
?DEBUG("Dropping PEP error message from ~s to ~s",
[jlib:jid_to_string(From),
jlib:jid_to_string(To)]),
drop;
_ ->
Packet
end;
false ->
Packet
end;
_ ->
Packet
end;
drop_pep_error(Acc, _JID, _From, _To) -> Acc.
%% -------
%% user remove hook handling function
%%
@ -1108,8 +1078,6 @@ terminate(_Reason,
?MODULE, disco_sm_features, 75),
ejabberd_hooks:delete(disco_sm_items, ServerHost,
?MODULE, disco_sm_items, 75),
ejabberd_hooks:delete(c2s_filter_packet_in, ServerHost,
?MODULE, drop_pep_error, 75),
gen_iq_handler:remove_iq_handler(ejabberd_sm,
ServerHost, ?NS_PUBSUB),
gen_iq_handler:remove_iq_handler(ejabberd_sm,