From 8621a8f0066cd053c209d228c0ff7bddd2039bbc Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Tue, 9 Jul 2013 18:11:27 +0200 Subject: [PATCH] fix invalid response on get_options when no options set (EJAB-1648) --- src/mod_pubsub.erl | 35 +++++++++++++++++++++-------------- src/mod_pubsub_odbc.erl | 35 +++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl index bfb971f8c..ba9870d9d 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -3682,26 +3682,33 @@ get_options_helper(JID, Lang, Node, NodeID, SubID, Type) -> {error, extended_error(?ERR_NOT_ACCEPTABLE, <<"subid-required">>)}; {_, _} -> - read_sub(Subscriber, Node, NodeID, SubID, Lang) + ValidSubId = lists:member(SubID, SubIDs), + if ValidSubId -> + read_sub(Subscriber, Node, NodeID, SubID, Lang); + true -> + {error, + extended_error(?ERR_NOT_ACCEPTABLE, <<"invalid-subid">>)} + end end. read_sub(Subscriber, Node, NodeID, SubID, Lang) -> - case pubsub_subscription:get_subscription(Subscriber, NodeID, SubID) of + Children = case pubsub_subscription:get_subscription(Subscriber, NodeID, SubID) of {error, notfound} -> - {error, extended_error(?ERR_NOT_ACCEPTABLE, <<"invalid-subid">>)}; + []; {result, #pubsub_subscription{options = Options}} -> {result, XdataEl} = pubsub_subscription:get_options_xform(Lang, Options), - OptionsEl = #xmlel{name = <<"options">>, - attrs = - [{<<"jid">>, jlib:jid_to_string(Subscriber)}, - {<<"subid">>, SubID} - | nodeAttr(Node)], - children = [XdataEl]}, - PubsubEl = #xmlel{name = <<"pubsub">>, - attrs = [{<<"xmlns">>, ?NS_PUBSUB}], - children = [OptionsEl]}, - {result, PubsubEl} - end. + [XdataEl] + end, + OptionsEl = #xmlel{name = <<"options">>, + attrs = + [{<<"jid">>, jlib:jid_to_string(Subscriber)}, + {<<"subid">>, SubID} + | nodeAttr(Node)], + children = Children}, + PubsubEl = #xmlel{name = <<"pubsub">>, + attrs = [{<<"xmlns">>, ?NS_PUBSUB}], + children = [OptionsEl]}, + {result, PubsubEl}. set_options(Host, Node, JID, SubID, Configuration) -> Action = fun (#pubsub_node{type = Type, id = NodeID}) -> diff --git a/src/mod_pubsub_odbc.erl b/src/mod_pubsub_odbc.erl index 5602b6ef9..6932a8fd6 100644 --- a/src/mod_pubsub_odbc.erl +++ b/src/mod_pubsub_odbc.erl @@ -3301,26 +3301,33 @@ get_options_helper(JID, Lang, Node, NodeID, SubID, Type) -> {error, extended_error(?ERR_NOT_ACCEPTABLE, <<"subid-required">>)}; {_, _} -> - read_sub(Subscriber, Node, NodeID, SubID, Lang) + ValidSubId = lists:member(SubID, SubIDs), + if ValidSubId -> + read_sub(Subscriber, Node, NodeID, SubID, Lang); + true -> + {error, + extended_error(?ERR_NOT_ACCEPTABLE, <<"invalid-subid">>)} + end end. read_sub(Subscriber, Node, NodeID, SubID, Lang) -> - case pubsub_subscription_odbc:get_subscription(Subscriber, NodeID, SubID) of + Children = case pubsub_subscription_odbc:get_subscription(Subscriber, NodeID, SubID) of {error, notfound} -> - {error, extended_error(?ERR_NOT_ACCEPTABLE, <<"invalid-subid">>)}; + []; {result, #pubsub_subscription{options = Options}} -> {result, XdataEl} = pubsub_subscription_odbc:get_options_xform(Lang, Options), - OptionsEl = #xmlel{name = <<"options">>, - attrs = - [{<<"jid">>, jlib:jid_to_string(Subscriber)}, - {<<"subid">>, SubID} - | nodeAttr(Node)], - children = [XdataEl]}, - PubsubEl = #xmlel{name = <<"pubsub">>, - attrs = [{<<"xmlns">>, ?NS_PUBSUB}], - children = [OptionsEl]}, - {result, PubsubEl} - end. + [XdataEl] + end, + OptionsEl = #xmlel{name = <<"options">>, + attrs = + [{<<"jid">>, jlib:jid_to_string(Subscriber)}, + {<<"subid">>, SubID} + | nodeAttr(Node)], + children = Children}, + PubsubEl = #xmlel{name = <<"pubsub">>, + attrs = [{<<"xmlns">>, ?NS_PUBSUB}], + children = [OptionsEl]}, + {result, PubsubEl}. set_options(Host, Node, JID, SubID, Configuration) -> Action = fun (#pubsub_node{type = Type, id = NodeID}) ->