From a67539075faf2916f186dd82d187079221f5135e Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Thu, 10 Jun 2010 14:25:46 +0200 Subject: [PATCH] prevent pubsub filtering too much packets --- src/mod_pubsub/mod_pubsub.erl | 20 +++++++++++--------- src/mod_pubsub/mod_pubsub_odbc.erl | 24 +++++++++++++----------- src/mod_pubsub/pubsub_odbc.patch | 4 ++-- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index 8cc604676..c9b95a755 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -3981,20 +3981,22 @@ feature_check_packet(allow, _User, Server, Pres, {From, _To, El}, in) -> %% Else, the message comes from PEP _ -> case exmpp_xml:get_element(El, 'event') of - #xmlel{name = 'event', ns = ?NS_PUBSUB_EVENT} = Event -> - Items = exmpp_xml:get_element(Event, ?NS_PUBSUB_EVENT, 'items'), - Feature = exmpp_xml:get_attribute_as_list(Items, "node", ""), - case is_feature_supported(Pres, Feature) of - true -> allow; - false -> deny - end; - _ -> - allow + #xmlel{name = 'event', ns = ?NS_PUBSUB_EVENT} = Event -> + Items = exmpp_xml:get_element(Event, ?NS_PUBSUB_EVENT, 'items'), + Feature = exmpp_xml:get_attribute_as_list(Items, "node", ""), + case is_feature_supported(Pres, Feature) of + true -> allow; + false -> deny + end; + _ -> + allow end end; feature_check_packet(Acc, _User, _Server, _Pres, _Packet, _Direction) -> Acc. +is_feature_supported(_, []) -> + true; is_feature_supported(#xmlel{name = 'presence', children = Els}, Feature) -> case mod_caps:read_caps(Els) of nothing -> false; diff --git a/src/mod_pubsub/mod_pubsub_odbc.erl b/src/mod_pubsub/mod_pubsub_odbc.erl index b2e2f6757..1b2f47745 100644 --- a/src/mod_pubsub/mod_pubsub_odbc.erl +++ b/src/mod_pubsub/mod_pubsub_odbc.erl @@ -3759,8 +3759,8 @@ odbc_conn(Host) -> lists:dropwhile(fun(A) -> A/=$. end, Host) -- ".". %% escape value for database storage -escape({U, H, R})-> - ejabberd_odbc:escape(exmpp_jid:to_list(U, H, R)); +escape({_U, _H, _R}=JID)-> + ejabberd_odbc:escape(exmpp_jid:to_list(JID)); escape(Value)-> ejabberd_odbc:escape(Value). %%%% helpers @@ -3853,20 +3853,22 @@ feature_check_packet(allow, _User, Server, Pres, {From, _To, El}, in) -> %% Else, the message comes from PEP _ -> case exmpp_xml:get_element(El, 'event') of - #xmlel{name = 'event', ns = ?NS_PUBSUB_EVENT} = Event -> - Items = exmpp_xml:get_element(Event, ?NS_PUBSUB_EVENT, 'items'), - Feature = exmpp_xml:get_attribute_as_list(Items, "node", ""), - case is_feature_supported(Pres, Feature) of - true -> allow; - false -> deny - end; - _ -> - allow + #xmlel{name = 'event', ns = ?NS_PUBSUB_EVENT} = Event -> + Items = exmpp_xml:get_element(Event, ?NS_PUBSUB_EVENT, 'items'), + Feature = exmpp_xml:get_attribute_as_list(Items, "node", ""), + case is_feature_supported(Pres, Feature) of + true -> allow; + false -> deny + end; + _ -> + allow end end; feature_check_packet(Acc, _User, _Server, _Pres, _Packet, _Direction) -> Acc. +is_feature_supported(_, []) -> + true; is_feature_supported(#xmlel{name = 'presence', children = Els}, Feature) -> case mod_caps:read_caps(Els) of nothing -> false; diff --git a/src/mod_pubsub/pubsub_odbc.patch b/src/mod_pubsub/pubsub_odbc.patch index 548ab68a1..a7954aada 100644 --- a/src/mod_pubsub/pubsub_odbc.patch +++ b/src/mod_pubsub/pubsub_odbc.patch @@ -1,5 +1,5 @@ ---- mod_pubsub.erl 2010-06-02 16:46:29.000000000 +0200 -+++ mod_pubsub_odbc.erl 2010-06-02 16:46:33.000000000 +0200 +--- mod_pubsub.erl 2010-06-10 14:25:01.000000000 +0200 ++++ mod_pubsub_odbc.erl 2010-06-10 14:25:09.000000000 +0200 @@ -42,7 +42,7 @@ %%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see %%% XEP-0060 section 12.18.