From 839b406903e49170fd266e8143249c926f552612 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Tue, 9 Mar 2010 14:03:27 +0900 Subject: [PATCH] don't route PEP error messsages to a client --- src/mod_pubsub/mod_pubsub.erl | 31 +++++++++++++++++++++++------- src/mod_pubsub/mod_pubsub_odbc.erl | 31 +++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index e0b54ded2..b7d45b7e1 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -3769,7 +3769,9 @@ extended_headers(Jids) -> [{xmlelement, "address", [{"type", "replyto"}, {"jid", Jid}], []} || Jid <- Jids]. -feature_check_packet(allow, _User, Server, Pres, {#jid{lserver = LServer}, _To, {xmlelement, "message", _, _} = El}, in) -> +feature_check_packet(allow, _User, Server, Pres, + {#jid{lserver = LServer}, _To, + {xmlelement, "message", MsgAttrs, _} = El}, in) -> Host = host(Server), case LServer of %% If the sender Server equals Host, the message comes from the Pubsub server @@ -3781,12 +3783,27 @@ feature_check_packet(allow, _User, Server, Pres, {#jid{lserver = LServer}, _To, {xmlelement, _, Attrs, _} = EventEl -> case xml:get_attr_s("xmlns", Attrs) of ?NS_PUBSUB_EVENT -> - Feature = xml:get_path_s(EventEl, [{elem, "items"}, {attr, "node"}]), - case is_feature_supported(Pres, Feature) of - true -> - allow; - false -> - deny + case xml:get_attr_s("type", MsgAttrs) of + "error" -> + %% Filter error-repsonse of PEP message + %% to avoid routing it to client + deny; + _ when Pres /= undefined -> + %% Yes, sometimes Pres = undefined, + %% very rare though. + %% Seems like this is a bug: should + %% be fixed in ejabberd_s2s.erl + Feature = xml:get_path_s( + EventEl, [{elem, "items"}, + {attr, "node"}]), + case is_feature_supported(Pres, Feature) of + true -> + allow; + false -> + deny + end; + _ -> + allow end; _ -> allow diff --git a/src/mod_pubsub/mod_pubsub_odbc.erl b/src/mod_pubsub/mod_pubsub_odbc.erl index a6dca0035..cc783913b 100644 --- a/src/mod_pubsub/mod_pubsub_odbc.erl +++ b/src/mod_pubsub/mod_pubsub_odbc.erl @@ -3634,7 +3634,9 @@ extended_headers(Jids) -> [{xmlelement, "address", [{"type", "replyto"}, {"jid", Jid}], []} || Jid <- Jids]. -feature_check_packet(allow, _User, Server, Pres, {#jid{lserver = LServer}, _To, {xmlelement, "message", _, _} = El}, in) -> +feature_check_packet(allow, _User, Server, Pres, + {#jid{lserver = LServer}, _To, + {xmlelement, "message", MsgAttrs, _} = El}, in) -> Host = host(Server), case LServer of %% If the sender Server equals Host, the message comes from the Pubsub server @@ -3646,12 +3648,27 @@ feature_check_packet(allow, _User, Server, Pres, {#jid{lserver = LServer}, _To, {xmlelement, _, Attrs, _} = EventEl -> case xml:get_attr_s("xmlns", Attrs) of ?NS_PUBSUB_EVENT -> - Feature = xml:get_path_s(EventEl, [{elem, "items"}, {attr, "node"}]), - case is_feature_supported(Pres, Feature) of - true -> - allow; - false -> - deny + case xml:get_attr_s("type", MsgAttrs) of + "error" -> + %% Filter error-repsonse of PEP message + %% to avoid routing it to client + deny; + _ when Pres /= undefined -> + %% Yes, sometimes Pres = undefined, + %% very rare though. + %% Seems like this is a bug: should + %% be fixed in ejabberd_s2s.erl + Feature = xml:get_path_s( + EventEl, [{elem, "items"}, + {attr, "node"}]), + case is_feature_supported(Pres, Feature) of + true -> + allow; + false -> + deny + end; + _ -> + allow end; _ -> allow