24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-28 22:52:27 +02:00

fix pubsub#title option (EJAB-1190) (thanks karim)

This commit is contained in:
Christophe Romain 2010-03-05 15:45:31 +01:00
parent 7d97830ad7
commit 3c36cd64e3
3 changed files with 72 additions and 54 deletions

View File

@ -1116,11 +1116,15 @@ iq_disco_items(Host, [], From) ->
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
Nodes when is_list(Nodes) -> Nodes when is_list(Nodes) ->
{result, lists:map( {result, lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}, type = Type}) -> fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
{result, Path} = node_call(Type, node_to_path, [SubNode]), Attrs =
[Name | _] = lists:reverse(Path), case get_option(Options, title) of
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), false ->
?XMLATTR('name', Name) | nodeAttr(SubNode)]} [?XMLATTR('jid', Host) | nodeAttr(SubNode)];
Title ->
[?XMLATTR('jid', Host), ?XMLATTR('name', Title) | nodeAttr(SubNode)]
end,
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = Attrs}
end, Nodes)}; end, Nodes)};
Other -> Other ->
Other Other
@ -1151,10 +1155,15 @@ iq_disco_items(Host, Item, From) ->
_ -> [] _ -> []
end, end,
Nodes = lists:map( Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) -> fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
{result, Path} = node_call(Type, node_to_path, [SubNode]), Attrs =
[Name|_] = lists:reverse(Path), case get_option(Options, title) of
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('name', Name) | nodeAttr(SubNode)]} false ->
[?XMLATTR('jid', Host) | nodeAttr(SubNode)];
Title ->
[?XMLATTR('jid', Host), ?XMLATTR('name', Title) | nodeAttr(SubNode)]
end,
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = Attrs}
end, tree_call(Host, get_subnodes, [Host, Node, From])), end, tree_call(Host, get_subnodes, [Host, Node, From])),
Items = lists:map( Items = lists:map(
fun(#pubsub_item{itemid = {RN, _}}) -> fun(#pubsub_item{itemid = {RN, _}}) ->

View File

@ -924,11 +924,15 @@ iq_disco_items(Host, [], From, _RSM) ->
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
Nodes when is_list(Nodes) -> Nodes when is_list(Nodes) ->
{result, lists:map( {result, lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}, type = Type}) -> fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
{result, Path} = node_call(Type, node_to_path, [SubNode]), Attrs =
[Name | _] = lists:reverse(Path), case get_option(Options, title) of
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), false ->
?XMLATTR('name', Name) | nodeAttr(SubNode)]} [?XMLATTR('jid', Host) | nodeAttr(SubNode)];
Title ->
[?XMLATTR('jid', Host), ?XMLATTR('name', Title) | nodeAttr(SubNode)]
end,
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = Attrs}
end, Nodes)}; end, Nodes)};
Other -> Other ->
Other Other
@ -959,10 +963,15 @@ iq_disco_items(Host, Item, From, RSM) ->
_ -> {[], none} _ -> {[], none}
end, end,
Nodes = lists:map( Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) -> fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
{result, Path} = node_call(Type, node_to_path, [SubNode]), Attrs =
[Name|_] = lists:reverse(Path), case get_option(Options, title) of
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('name', Name) | nodeAttr(SubNode)]} false ->
[?XMLATTR('jid', Host) | nodeAttr(SubNode)];
Title ->
[?XMLATTR('jid', Host), ?XMLATTR('name', Title) | nodeAttr(SubNode)]
end,
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = Attrs}
end, tree_call(Host, get_subnodes, [Host, Node, From])), end, tree_call(Host, get_subnodes, [Host, Node, From])),
Items = lists:map( Items = lists:map(
fun(#pubsub_item{itemid = {RN, _}}) -> fun(#pubsub_item{itemid = {RN, _}}) ->

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2010-03-05 15:35:25.000000000 +0100 --- mod_pubsub.erl 2010-03-05 15:44:11.000000000 +0100
+++ mod_pubsub_odbc.erl 2010-03-05 15:37:52.000000000 +0100 +++ mod_pubsub_odbc.erl 2010-03-05 15:45:00.000000000 +0100
@@ -42,7 +42,7 @@ @@ -42,7 +42,7 @@
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see %%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
%%% XEP-0060 section 12.18. %%% XEP-0060 section 12.18.
@ -371,7 +371,7 @@
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
Nodes when is_list(Nodes) -> Nodes when is_list(Nodes) ->
{result, lists:map( {result, lists:map(
@@ -1125,7 +933,7 @@ @@ -1129,7 +937,7 @@
Other -> Other ->
Other Other
end; end;
@ -380,7 +380,7 @@
%% TODO: support localization of this string %% TODO: support localization of this string
CommandItems = [ CommandItems = [
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item',
@@ -1134,10 +942,10 @@ @@ -1138,10 +946,10 @@
?XMLATTR('name', "Get Pending") ?XMLATTR('name', "Get Pending")
]}], ]}],
{result, CommandItems}; {result, CommandItems};
@ -393,7 +393,7 @@
case string:tokens(Item, "!") of case string:tokens(Item, "!") of
[_SNode, _ItemID] -> [_SNode, _ItemID] ->
{result, []}; {result, []};
@@ -1145,10 +953,10 @@ @@ -1149,10 +957,10 @@
Node = string_to_node(SNode), Node = string_to_node(SNode),
Action = Action =
fun(#pubsub_node{type = Type, id = NodeId}) -> fun(#pubsub_node{type = Type, id = NodeId}) ->
@ -406,8 +406,8 @@
+ _ -> {[], none} + _ -> {[], none}
end, end,
Nodes = lists:map( Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) -> fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
@@ -1159,9 +967,10 @@ @@ -1168,9 +976,10 @@
Items = lists:map( Items = lists:map(
fun(#pubsub_item{itemid = {RN, _}}) -> fun(#pubsub_item{itemid = {RN, _}}) ->
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]), {result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
@ -420,7 +420,7 @@
end, end,
case transaction(Host, Node, Action, sync_dirty) of case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> {result, Result}; {result, {_, Result}} -> {result, Result};
@@ -1292,7 +1101,8 @@ @@ -1301,7 +1110,8 @@
(_, Acc) -> (_, Acc) ->
Acc Acc
end, [], exmpp_xml:remove_cdata_from_list(Els)), end, [], exmpp_xml:remove_cdata_from_list(Els)),
@ -430,7 +430,7 @@
{get, 'subscriptions'} -> {get, 'subscriptions'} ->
get_subscriptions(Host, Node, From, Plugins); get_subscriptions(Host, Node, From, Plugins);
{get, 'affiliations'} -> {get, 'affiliations'} ->
@@ -1314,8 +1124,9 @@ @@ -1323,8 +1133,9 @@
end. end.
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) -> iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
@ -442,7 +442,7 @@
case Action of case Action of
[#xmlel{name = Name, attrs = Attrs, children = Els}] -> [#xmlel{name = Name, attrs = Attrs, children = Els}] ->
Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', "")), Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', "")),
@@ -1449,7 +1260,8 @@ @@ -1458,7 +1269,8 @@
_ -> [] _ -> []
end end
end, end,
@ -452,7 +452,7 @@
sync_dirty) of sync_dirty) of
{result, Res} -> Res; {result, Res} -> Res;
Err -> Err Err -> Err
@@ -1493,7 +1305,7 @@ @@ -1502,7 +1314,7 @@
%%% authorization handling %%% authorization handling
@ -461,7 +461,7 @@
Lang = "en", %% TODO fix Lang = "en", %% TODO fix
{U, S, R} = Subscriber, {U, S, R} = Subscriber,
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children = Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
@@ -1523,7 +1335,7 @@ @@ -1532,7 +1344,7 @@
lists:foreach(fun(Owner) -> lists:foreach(fun(Owner) ->
{U, S, R} = Owner, {U, S, R} = Owner,
ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza) ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza)
@ -470,7 +470,7 @@
find_authorization_response(Packet) -> find_authorization_response(Packet) ->
Els = Packet#xmlel.children, Els = Packet#xmlel.children,
@@ -1565,7 +1377,7 @@ @@ -1574,7 +1386,7 @@
end, end,
Stanza = event_stanza( Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'subscription', attrs = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'subscription', attrs =
@ -479,7 +479,7 @@
}]), }]),
ejabberd_router:route(service_jid(Host), JID, Stanza). ejabberd_router:route(service_jid(Host), JID, Stanza).
@@ -1576,14 +1388,14 @@ @@ -1585,14 +1397,14 @@
{{value, {_, [SNode]}}, {value, {_, [SSubscriber]}}, {{value, {_, [SNode]}}, {value, {_, [SSubscriber]}},
{value, {_, [SAllow]}}} -> {value, {_, [SAllow]}}} ->
Node = string_to_node(SNode), Node = string_to_node(SNode),
@ -497,7 +497,7 @@
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]), {result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
if if
not IsApprover -> not IsApprover ->
@@ -1778,7 +1590,7 @@ @@ -1787,7 +1599,7 @@
end, end,
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]}, [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
@ -506,7 +506,7 @@
{result, {Result, broadcast}} -> {result, {Result, broadcast}} ->
%%Lang = "en", %% TODO: fix %%Lang = "en", %% TODO: fix
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), %%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
@@ -1887,7 +1699,7 @@ @@ -1896,7 +1708,7 @@
%%<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) ->
@ -515,7 +515,7 @@
{result, GoodSubOpts} -> GoodSubOpts; {result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid _ -> invalid
end, end,
@@ -1897,7 +1709,7 @@ @@ -1906,7 +1718,7 @@
_:_ -> _:_ ->
{undefined, undefined, undefined} {undefined, undefined, undefined}
end, end,
@ -524,7 +524,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),
@@ -1916,9 +1728,13 @@ @@ -1925,9 +1737,13 @@
{"", "", ""} -> {"", "", ""} ->
{false, false}; {false, false};
_ -> _ ->
@ -541,7 +541,7 @@
end end
end, end,
if if
@@ -2251,7 +2067,7 @@ @@ -2260,7 +2076,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.
@ -550,7 +550,7 @@
MaxItems = MaxItems =
if if
SMaxItems == "" -> get_max_items_node(Host); SMaxItems == "" -> get_max_items_node(Host);
@@ -2290,11 +2106,11 @@ @@ -2299,11 +2115,11 @@
node_call(Type, get_items, node_call(Type, get_items,
[NodeId, From, [NodeId, From,
AccessModel, PresenceSubscription, RosterGroup, AccessModel, PresenceSubscription, RosterGroup,
@ -564,7 +564,7 @@
SendItems = case ItemIDs of SendItems = case ItemIDs of
[] -> [] ->
Items; Items;
@@ -2307,7 +2123,7 @@ @@ -2316,7 +2132,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 =
@ -573,7 +573,7 @@
Error -> Error ->
Error Error
end end
@@ -2339,17 +2155,29 @@ @@ -2348,17 +2164,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) ->
@ -610,7 +610,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, []} ->
@@ -2479,29 +2307,12 @@ @@ -2488,29 +2316,12 @@
error -> error ->
{error, 'bad-request'}; {error, 'bad-request'};
_ -> _ ->
@ -643,7 +643,7 @@
end, Entities), end, Entities),
{result, []}; {result, []};
_ -> _ ->
@@ -2556,11 +2367,11 @@ @@ -2565,11 +2376,11 @@
end. end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) -> read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -657,7 +657,7 @@
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options', OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)), attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
?XMLATTR('Subid', SubID) | nodeAttr(Node)], ?XMLATTR('Subid', SubID) | nodeAttr(Node)],
@@ -2587,7 +2398,7 @@ @@ -2596,7 +2407,7 @@
end. end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) -> set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
@ -666,7 +666,7 @@
{result, GoodSubOpts} -> GoodSubOpts; {result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid _ -> invalid
end, end,
@@ -2617,7 +2428,7 @@ @@ -2626,7 +2437,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) -> write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error('bad-request', "invalid-options")}; {error, extended_error('bad-request', "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) -> write_sub(Subscriber, NodeID, SubID, Options) ->
@ -675,7 +675,7 @@
{error, notfound} -> {error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")}; {error, extended_error('not-acceptable', "invalid-subid")};
{result, _} -> {result, _} ->
@@ -2790,8 +2601,8 @@ @@ -2799,8 +2610,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,
@ -686,7 +686,7 @@
true -> true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3080,7 +2891,7 @@ @@ -3089,7 +2900,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,
@ -695,7 +695,7 @@
{result, CollSubs} -> CollSubs; {result, CollSubs} -> CollSubs;
_ -> [] _ -> []
end. end.
@@ -3094,9 +2905,9 @@ @@ -3103,9 +2914,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) ->
@ -707,7 +707,7 @@
_ -> Acc _ -> Acc
end; end;
(_, Acc) -> (_, Acc) ->
@@ -3104,7 +2915,7 @@ @@ -3113,7 +2924,7 @@
end, [], Subs). end, [], Subs).
% TODO: merge broadcast code that way % TODO: merge broadcast code that way
@ -716,7 +716,7 @@
%broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) -> %broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) ->
% case (get_option(NodeOptions, Feature) or Force) of % case (get_option(NodeOptions, Feature) or Force) of
% true -> % true ->
@@ -3303,6 +3114,30 @@ @@ -3312,6 +3123,30 @@
Result Result
end. end.
@ -747,7 +747,7 @@
%% @spec (Host, Options) -> MaxItems %% @spec (Host, Options) -> MaxItems
%% Host = host() %% Host = host()
%% Options = [Option] %% Options = [Option]
@@ -3698,7 +3533,13 @@ @@ -3707,7 +3542,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,
@ -762,7 +762,7 @@
%% @doc <p>node plugin call.</p> %% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) -> node_call(Type, Function, Args) ->
@@ -3718,13 +3559,13 @@ @@ -3727,13 +3568,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]),
@ -778,7 +778,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
@@ -3737,8 +3578,15 @@ @@ -3746,8 +3587,15 @@
end end
end, Trans). end, Trans).
@ -796,7 +796,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};
@@ -3746,6 +3594,15 @@ @@ -3755,6 +3603,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'};
@ -812,7 +812,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'};
@@ -3754,6 +3611,16 @@ @@ -3763,6 +3620,16 @@
{error, 'internal-server-error'} {error, 'internal-server-error'}
end. end.