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

return invalid-options on badly formed subscription options

SVN Revision: 2657
This commit is contained in:
Christophe Romain 2009-10-12 10:23:51 +00:00
parent 2042ab090d
commit c3303ce364
3 changed files with 67 additions and 47 deletions

View File

@ -1867,7 +1867,10 @@ delete_node(Host, Node, Owner) ->
%%<li>The node does not exist.</li> %%<li>The node does not exist.</li>
%%</ul> %%</ul>
subscribe_node(Host, Node, From, JID, Configuration) -> subscribe_node(Host, Node, From, JID, Configuration) ->
{result, SubOpts} = pubsub_subscription:parse_options_xform(Configuration), SubOpts = case pubsub_subscription:parse_options_xform(Configuration) of
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
Subscriber = try Subscriber = try
jlib:short_prepd_jid(exmpp_jid:parse(JID)) jlib:short_prepd_jid(exmpp_jid:parse(JID))
catch catch
@ -1907,8 +1910,11 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
%% Node does not support subscriptions %% Node does not support subscriptions
{error, extended_error('feature-not-implemented', unsupported, "subscribe")}; {error, extended_error('feature-not-implemented', unsupported, "subscribe")};
HasOptions andalso not OptionsFeature -> HasOptions andalso not OptionsFeature ->
%% Node does not support subscription options %% Node does not support subscription options
{error, extended_error('feature-not-implemented', unsupported, "subscription-options")}; {error, extended_error('feature-not-implemented', unsupported, "subscription-options")};
SubOpts == invalid ->
%% Passed invalit options submit form
{error, extended_error('bad-request', "invalid-options")};
true -> true ->
node_call(Type, subscribe_node, node_call(Type, subscribe_node,
[NodeId, From, Subscriber, [NodeId, From, Subscriber,
@ -2557,13 +2563,15 @@ set_options(Host, Node, JID, SubID, Configuration) ->
end. end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) -> set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
SubOpts = case pubsub_subscription:parse_options_xform(Configuration) of
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
Subscriber = try exmpp_jid:parse(JID) of Subscriber = try exmpp_jid:parse(JID) of
J -> jlib:short_jid(J) J -> jlib:short_jid(J)
catch catch
_ -> _ -> {"", "", ""} %%pablo TODO: "" or <<>> ?. short_jid uses exmpp_jid:node/1, etc. that returns binaries
{"", "", ""} %%pablo TODO: "" or <<>> ?. short_jid uses exmpp_jid:node/1, etc. that returns binaries
end, end,
{result, SubOpts} = pubsub_subscription:parse_options_xform(Configuration),
{result, Subs} = node_call(Type, get_subscriptions, {result, Subs} = node_call(Type, get_subscriptions,
[NodeID, Subscriber]), [NodeID, Subscriber]),
SubIDs = lists:foldl(fun({subscribed, SID}, Acc) -> SubIDs = lists:foldl(fun({subscribed, SID}, Acc) ->
@ -2582,6 +2590,8 @@ set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
write_sub(Subscriber, NodeID, SubID, SubOpts) write_sub(Subscriber, NodeID, SubID, SubOpts)
end. end.
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error('bad-request', "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) -> write_sub(Subscriber, NodeID, SubID, Options) ->
case pubsub_subscription:set_subscription(Subscriber, NodeID, SubID, Options) of case pubsub_subscription:set_subscription(Subscriber, NodeID, SubID, Options) of
{error, notfound} -> {error, notfound} ->

View File

@ -1699,7 +1699,10 @@ delete_node(Host, Node, Owner) ->
%%<li>The node does not exist.</li> %%<li>The node does not exist.</li>
%%</ul> %%</ul>
subscribe_node(Host, Node, From, JID, Configuration) -> subscribe_node(Host, Node, From, JID, Configuration) ->
{result, SubOpts} = pubsub_subscription_odbc:parse_options_xform(Configuration), SubOpts = case pubsub_subscription_odbc:parse_options_xform(Configuration) of
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
Subscriber = try Subscriber = try
jlib:short_prepd_jid(exmpp_jid:parse(JID)) jlib:short_prepd_jid(exmpp_jid:parse(JID))
catch catch
@ -1743,8 +1746,11 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
%% Node does not support subscriptions %% Node does not support subscriptions
{error, extended_error('feature-not-implemented', unsupported, "subscribe")}; {error, extended_error('feature-not-implemented', unsupported, "subscribe")};
HasOptions andalso not OptionsFeature -> HasOptions andalso not OptionsFeature ->
%% Node does not support subscription options %% Node does not support subscription options
{error, extended_error('feature-not-implemented', unsupported, "subscription-options")}; {error, extended_error('feature-not-implemented', unsupported, "subscription-options")};
SubOpts == invalid ->
%% Passed invalit options submit form
{error, extended_error('bad-request', "invalid-options")};
true -> true ->
node_call(Type, subscribe_node, node_call(Type, subscribe_node,
[NodeId, From, Subscriber, [NodeId, From, Subscriber,
@ -2388,13 +2394,15 @@ set_options(Host, Node, JID, SubID, Configuration) ->
end. end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) -> set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
SubOpts = case pubsub_subscription_odbc:parse_options_xform(Configuration) of
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
Subscriber = try exmpp_jid:parse(JID) of Subscriber = try exmpp_jid:parse(JID) of
J -> jlib:short_jid(J) J -> jlib:short_jid(J)
catch catch
_ -> _ -> {"", "", ""} %%pablo TODO: "" or <<>> ?. short_jid uses exmpp_jid:node/1, etc. that returns binaries
{"", "", ""} %%pablo TODO: "" or <<>> ?. short_jid uses exmpp_jid:node/1, etc. that returns binaries
end, end,
{result, SubOpts} = pubsub_subscription_odbc:parse_options_xform(Configuration),
{result, Subs} = node_call(Type, get_subscriptions, {result, Subs} = node_call(Type, get_subscriptions,
[NodeID, Subscriber]), [NodeID, Subscriber]),
SubIDs = lists:foldl(fun({subscribed, SID}, Acc) -> SubIDs = lists:foldl(fun({subscribed, SID}, Acc) ->
@ -2413,6 +2421,8 @@ set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
write_sub(Subscriber, NodeID, SubID, SubOpts) write_sub(Subscriber, NodeID, SubID, SubOpts)
end. end.
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error('bad-request', "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) -> write_sub(Subscriber, NodeID, SubID, Options) ->
case pubsub_subscription_odbc:set_subscription(Subscriber, NodeID, SubID, Options) of case pubsub_subscription_odbc:set_subscription(Subscriber, NodeID, SubID, Options) of
{error, notfound} -> {error, notfound} ->

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2009-10-12 11:05:54.000000000 +0200 --- mod_pubsub.erl 2009-10-12 12:21:54.000000000 +0200
+++ mod_pubsub_odbc.erl 2009-10-12 11:06:09.000000000 +0200 +++ mod_pubsub_odbc.erl 2009-10-12 12:23:13.000000000 +0200
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
%%% TODO %%% TODO
%%% plugin: generate Reply (do not use broadcast atom anymore) %%% plugin: generate Reply (do not use broadcast atom anymore)
@ -425,12 +425,12 @@
%%<li>The node does not exist.</li> %%<li>The node does not exist.</li>
%%</ul> %%</ul>
subscribe_node(Host, Node, From, JID, Configuration) -> subscribe_node(Host, Node, From, JID, Configuration) ->
- {result, SubOpts} = pubsub_subscription:parse_options_xform(Configuration), - SubOpts = case pubsub_subscription:parse_options_xform(Configuration) of
+ {result, SubOpts} = pubsub_subscription_odbc:parse_options_xform(Configuration), + SubOpts = case pubsub_subscription_odbc:parse_options_xform(Configuration) of
Subscriber = try {result, GoodSubOpts} -> GoodSubOpts;
jlib:short_prepd_jid(exmpp_jid:parse(JID)) _ -> invalid
catch end,
@@ -1875,7 +1707,7 @@ @@ -1878,7 +1710,7 @@
{undefined, undefined, undefined} {undefined, undefined, undefined}
end, end,
SubId = uniqid(), SubId = uniqid(),
@ -439,7 +439,7 @@
Features = features(Type), Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features), SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features), OptionsFeature = lists:member("subscription-options", Features),
@@ -1894,9 +1726,13 @@ @@ -1897,9 +1729,13 @@
{"", "", ""} -> {"", "", ""} ->
{false, false}; {false, false};
_ -> _ ->
@ -456,7 +456,7 @@
end end
end, end,
if if
@@ -2221,7 +2057,7 @@ @@ -2227,7 +2063,7 @@
%% <p>The permission are not checked in this function.</p> %% <p>The permission are not checked in this function.</p>
%% @todo We probably need to check that the user doing the query has the right %% @todo We probably need to check that the user doing the query has the right
%% to read the items. %% to read the items.
@ -465,7 +465,7 @@
MaxItems = MaxItems =
if if
SMaxItems == "" -> get_max_items_node(Host); SMaxItems == "" -> get_max_items_node(Host);
@@ -2260,11 +2096,11 @@ @@ -2266,11 +2102,11 @@
node_call(Type, get_items, node_call(Type, get_items,
[NodeId, From, [NodeId, From,
AccessModel, PresenceSubscription, RosterGroup, AccessModel, PresenceSubscription, RosterGroup,
@ -479,7 +479,7 @@
SendItems = case ItemIDs of SendItems = case ItemIDs of
[] -> [] ->
Items; Items;
@@ -2277,7 +2113,7 @@ @@ -2283,7 +2119,7 @@
%% number of items sent to MaxItems: %% number of items sent to MaxItems:
{result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = {result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children = [#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
@ -488,7 +488,7 @@
Error -> Error ->
Error Error
end end
@@ -2309,17 +2145,29 @@ @@ -2315,17 +2151,29 @@
%% @doc <p>Resend the items of a node to the user.</p> %% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature %% @todo use cache-last-item feature
send_items(Host, Node, NodeId, Type, LJID, last) -> send_items(Host, Node, NodeId, Type, LJID, last) ->
@ -525,7 +525,7 @@
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) -> send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} -> {result, []} ->
@@ -2448,29 +2296,12 @@ @@ -2454,29 +2302,12 @@
error -> error ->
{error, 'bad-request'}; {error, 'bad-request'};
_ -> _ ->
@ -558,7 +558,7 @@
end, Entities), end, Entities),
{result, []}; {result, []};
_ -> _ ->
@@ -2525,11 +2356,11 @@ @@ -2531,11 +2362,11 @@
end. end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) -> read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -573,24 +573,24 @@
attrs = [?XMLATTR('node', node_to_string(Node)), attrs = [?XMLATTR('node', node_to_string(Node)),
?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)), ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
@@ -2563,7 +2394,7 @@ @@ -2563,7 +2394,7 @@
_ ->
{"", "", ""} %%pablo TODO: "" or <<>> ?. short_jid uses exmpp_jid:node/1, etc. that returns binaries
end,
- {result, SubOpts} = pubsub_subscription:parse_options_xform(Configuration),
+ {result, SubOpts} = pubsub_subscription_odbc:parse_options_xform(Configuration),
{result, Subs} = node_call(Type, get_subscriptions,
[NodeID, Subscriber]),
SubIDs = lists:foldl(fun({subscribed, SID}, Acc) ->
@@ -2583,7 +2414,7 @@
end. end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
- SubOpts = case pubsub_subscription:parse_options_xform(Configuration) of
+ SubOpts = case pubsub_subscription_odbc:parse_options_xform(Configuration) of
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -2593,7 +2424,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error('bad-request', "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) -> write_sub(Subscriber, NodeID, SubID, Options) ->
- case pubsub_subscription:set_subscription(Subscriber, NodeID, SubID, Options) of - case pubsub_subscription:set_subscription(Subscriber, NodeID, SubID, Options) of
+ case pubsub_subscription_odbc:set_subscription(Subscriber, NodeID, SubID, Options) of + case pubsub_subscription_odbc:set_subscription(Subscriber, NodeID, SubID, Options) of
{error, notfound} -> {error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")}; {error, extended_error('not-acceptable', "invalid-subid")};
{result, _} -> {result, _} ->
@@ -2756,8 +2587,8 @@ @@ -2766,8 +2597,8 @@
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]}, ?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
ejabberd_router ! {route, service_jid(Host), JID, Stanza} ejabberd_router ! {route, service_jid(Host), JID, Stanza}
end, end,
@ -601,7 +601,7 @@
true -> true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3053,7 +2884,7 @@ @@ -3063,7 +2894,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]} {Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))} end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end, end,
@ -610,7 +610,7 @@
{result, CollSubs} -> CollSubs; {result, CollSubs} -> CollSubs;
_ -> [] _ -> []
end. end.
@@ -3067,9 +2898,9 @@ @@ -3077,9 +2908,9 @@
get_options_for_subs(NodeID, Subs) -> get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) -> lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
@ -622,7 +622,7 @@
_ -> Acc _ -> Acc
end; end;
(_, Acc) -> (_, Acc) ->
@@ -3268,6 +3099,30 @@ @@ -3278,6 +3109,30 @@
Result Result
end. end.
@ -653,7 +653,7 @@
%% @spec (Host, Options) -> MaxItems %% @spec (Host, Options) -> MaxItems
%% Host = host() %% Host = host()
%% Options = [Option] %% Options = [Option]
@@ -3657,7 +3512,13 @@ @@ -3667,7 +3522,13 @@
tree_action(Host, Function, Args) -> tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]), ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end, Fun = fun() -> tree_call(Host, Function, Args) end,
@ -668,7 +668,7 @@
%% @doc <p>node plugin call.</p> %% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) -> node_call(Type, Function, Args) ->
@@ -3677,13 +3538,13 @@ @@ -3687,13 +3548,13 @@
node_action(Host, Type, Function, Args) -> node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]), ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -684,7 +684,7 @@
case tree_call(Host, get_node, [Host, Node]) of case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) -> N when is_record(N, pubsub_node) ->
case Action(N) of case Action(N) of
@@ -3696,8 +3557,15 @@ @@ -3706,8 +3567,15 @@
end end
end, Trans). end, Trans).
@ -702,7 +702,7 @@
{result, Result} -> {result, Result}; {result, Result} -> {result, Result};
{error, Error} -> {error, Error}; {error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result}; {atomic, {result, Result}} -> {result, Result};
@@ -3705,6 +3573,15 @@ @@ -3715,6 +3583,15 @@
{aborted, Reason} -> {aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, 'internal-server-error'}; {error, 'internal-server-error'};
@ -718,7 +718,7 @@
{'EXIT', Reason} -> {'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]), ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, 'internal-server-error'}; {error, 'internal-server-error'};
@@ -3713,6 +3590,16 @@ @@ -3723,6 +3600,16 @@
{error, 'internal-server-error'} {error, 'internal-server-error'}
end. end.