From 179e8934cf153a3811f5654f592d82b1f76ca7b4 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Wed, 5 Apr 2017 21:03:13 +0200 Subject: [PATCH] ejabberd_sm: Fix routing of headline messages As per RFC 6121, silently drop headline messages sent to the bare JID of an offline user or to the full JID of an unavailable resource. --- src/ejabberd_sm.erl | 9 ++++++--- test/offline_tests.erl | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index 659961d10..343775021 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -177,7 +177,8 @@ check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) -> -spec bounce_offline_message({bounce, message()} | any()) -> any(). -bounce_offline_message({bounce, Packet} = Acc) -> +bounce_offline_message({bounce, #message{type = T} = Packet} = Acc) + when T == chat; T == groupchat; T == normal -> Lang = xmpp:get_lang(Packet), Txt = <<"User session not found">>, Err = xmpp:err_service_unavailable(Txt, Lang), @@ -572,9 +573,11 @@ do_route(Packet) -> case online(Mod:get_sessions(LUser, LServer, LResource)) of [] -> case Packet of - #message{type = T} when T == chat; T == normal; - T == headline -> + #message{type = T} when T == chat; T == normal -> route_message(Packet); + #message{type = T} when T == headline -> + ?DEBUG("dropping headline to unavailable resource:~n~s", + [xmpp:pp(Packet)]); #presence{} -> ?DEBUG("dropping presence to unavailable resource:~n~s", [xmpp:pp(Packet)]); diff --git a/test/offline_tests.erl b/test/offline_tests.erl index 1d2803db0..df9b346ca 100644 --- a/test/offline_tests.erl +++ b/test/offline_tests.erl @@ -197,7 +197,9 @@ send_all_master(Config) -> Acc + 1 end, 0, Deliver), lists:foreach( - fun(Msg) -> + fun(#message{type = headline} = Msg) -> + send(Config, Msg#message{to = BarePeer}); + (Msg) -> #message{type = error} = Err = send_recv(Config, Msg#message{to = BarePeer}), #stanza_error{reason = 'service-unavailable'} = xmpp:get_error(Err)