26
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-28 17:38:54 +01:00

handle Example 90 of XEP-0060 (EJAB-909), and make use of nodeAttr

SVN Revision: 2069
This commit is contained in:
Christophe Romain 2009-05-08 01:28:17 +00:00
parent 38413dc236
commit 8dc1bb0659
2 changed files with 20 additions and 15 deletions

View File

@ -6,6 +6,9 @@
nodes with presence access model; Do not allow unsubscribed user to nodes with presence access model; Do not allow unsubscribed user to
subscribe node with presence access model. subscribe node with presence access model.
* src/mod_pubsub/mod_pubsub.erl: Handle Example 90 of XEP-0060
(EJAB-909)
2009-05-08 Mickael Remond <mremond@process-one.net> 2009-05-08 Mickael Remond <mremond@process-one.net>
* src/ejabberd_app.erl: Better support for profiling. * src/ejabberd_app.erl: Better support for profiling.

View File

@ -1428,7 +1428,7 @@ create_node(Host, ServerHost, [], Owner, Type, Access, Configuration) ->
{result, []} -> {result, []} ->
{result, {result,
[#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = [?XMLATTR('node', node_to_string(NewNode))]}]}]}; [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(NewNode)}]}]};
Error -> Error Error -> Error
end; end;
false -> false ->
@ -1477,7 +1477,7 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) ->
end end
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 = [?XMLATTR('node', node_to_string(Node))]}]}], [#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]}],
case transaction(CreateNode, transaction) of case transaction(CreateNode, transaction) of
{result, {Result, broadcast}} -> {result, {Result, broadcast}} ->
%%Lang = "en", %% TODO: fix %%Lang = "en", %% TODO: fix
@ -1752,7 +1752,9 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload) ->
end end
end, end,
ejabberd_hooks:run(pubsub_publish_item, ServerHost, [ServerHost, Node, Publisher, service_jid(Host), ItemId, Payload]), ejabberd_hooks:run(pubsub_publish_item, ServerHost, [ServerHost, Node, Publisher, service_jid(Host), ItemId, Payload]),
Reply = [], %% TODO EJAB-909 Reply = [#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'publish', attrs = nodeAttr(Node), children =
[#xmlel{ns = ?NS_PUBSUB, name = 'item', attrs = itemAttr(ItemId)}]}]}],
case transaction(Host, Node, Action, sync_dirty) of case transaction(Host, Node, Action, sync_dirty) of
{result, {TNode, {Result, broadcast, Removed}}} -> {result, {TNode, {Result, broadcast, Removed}}} ->
NodeId = TNode#pubsub_node.id, NodeId = TNode#pubsub_node.id,
@ -1970,7 +1972,7 @@ get_items(Host, Node, From, SubId, SMaxItems, ItemIDs) ->
%% Generate the XML response (Item list), limiting the %% Generate the XML response (Item list), limiting the
%% 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 = [?XMLATTR('node', node_to_string(Node))], children = [#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
itemsEls(lists:sublist(SendItems, MaxItems))}]}]}; itemsEls(lists:sublist(SendItems, MaxItems))}]}]};
Error -> Error ->
Error Error
@ -2014,7 +2016,7 @@ send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
[] []
end, end,
Stanza = event_stanza( Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [?XMLATTR('node', node_to_string(Node))], children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children =
itemsEls(ToSend)}]), itemsEls(ToSend)}]),
ejabberd_router ! {route, service_jid(Host), exmpp_jid:make_jid(LU, LS, LR), Stanza}. ejabberd_router ! {route, service_jid(Host), exmpp_jid:make_jid(LU, LS, LR), Stanza}.
@ -2082,7 +2084,7 @@ get_affiliations(Host, Node, JID) ->
?XMLATTR('affiliation', affiliation_to_string(Affiliation))]}] ?XMLATTR('affiliation', affiliation_to_string(Affiliation))]}]
end, Affiliations), end, Affiliations),
{result, [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'pubsub', children = {result, [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'affiliations', attrs = [?XMLATTR('node', node_to_string(Node))], children = [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'affiliations', attrs = nodeAttr(Node), children =
Entities}]}]}; Entities}]}]};
Error -> Error ->
Error Error
@ -2253,7 +2255,7 @@ get_subscriptions(Host, Node, JID) ->
?XMLATTR('subid', SubId)]}] ?XMLATTR('subid', SubId)]}]
end, Subscriptions), end, Subscriptions),
{result, [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'pubsub', children = {result, [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'subscriptions', attrs = [?XMLATTR('node', node_to_string(Node))], children = [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'subscriptions', attrs = nodeAttr(Node), children =
Entities}]}]}; Entities}]}]};
Error -> Error ->
Error Error
@ -2434,7 +2436,7 @@ broadcast_publish_item(Host, Node, NodeId, Type, Options, Removed, ItemId, _From
false -> [] false -> []
end, end,
Stanza = event_stanza( Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [?XMLATTR('node', node_to_string(Node))], children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children =
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'item', attrs = itemAttr(ItemId), children = Content}]}]), [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'item', attrs = itemAttr(ItemId), children = Content}]}]),
broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, Stanza), broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, Stanza),
case Removed of case Removed of
@ -2444,7 +2446,7 @@ broadcast_publish_item(Host, Node, NodeId, Type, Options, Removed, ItemId, _From
case get_option(Options, notify_retract) of case get_option(Options, notify_retract) of
true -> true ->
RetractStanza = event_stanza( RetractStanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [?XMLATTR('node', node_to_string(Node))], children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children =
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'retract', attrs = itemAttr(RId)} || RId <- Removed]}]), [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'retract', attrs = itemAttr(RId)} || RId <- Removed]}]),
broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, RetractStanza); broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, RetractStanza);
_ -> _ ->
@ -2469,7 +2471,7 @@ broadcast_retract_items(Host, Node, NodeId, Type, Options, ItemIds, ForceNotify)
{result, false}; {result, false};
{result, Subs} -> {result, Subs} ->
Stanza = event_stanza( Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [?XMLATTR('node', node_to_string(Node))], children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children =
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'retract', attrs = itemAttr(ItemId)} || ItemId <- ItemIds]}]), [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'retract', attrs = itemAttr(ItemId)} || ItemId <- ItemIds]}]),
broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, Stanza), broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, Stanza),
{result, true}; {result, true};
@ -2489,7 +2491,7 @@ broadcast_purge_node(Host, Node, NodeId, Type, Options) ->
{result, false}; {result, false};
{result, Subs} -> {result, Subs} ->
Stanza = event_stanza( Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'purge', attrs = [?XMLATTR('node', node_to_string(Node))]}]), [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'purge', attrs = nodeAttr(Node)}]),
broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, Stanza), broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, Stanza),
{result, true}; {result, true};
_ -> _ ->
@ -2508,7 +2510,7 @@ broadcast_removed_node(Host, Node, NodeId, Type, Options, Subs) ->
{result, false}; {result, false};
_ -> _ ->
Stanza = event_stanza( Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'delete', attrs = [?XMLATTR('node', node_to_string(Node))]}]), [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'delete', attrs = nodeAttr(Node)}]),
broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, Stanza), broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, Stanza),
{result, true} {result, true}
end; end;
@ -2532,7 +2534,7 @@ broadcast_config_notification(Host, Node, NodeId, Type, Options, Lang) ->
[] []
end, end,
Stanza = event_stanza( Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = [?XMLATTR('node', node_to_string(Node))], children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children =
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'item', attrs = [?XMLATTR('id', <<"configuration">>)], children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'item', attrs = [?XMLATTR('id', <<"configuration">>)], children =
Content}]}]), Content}]}]),
broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, Stanza), broadcast_stanza(Host, Node, NodeId, Type, Options, Subs, Stanza),
@ -2667,7 +2669,7 @@ get_configure(Host, ServerHost, Node, From, Lang) ->
{result, {result,
[#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'pubsub', children = [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'configure', attrs = [#xmlel{ns = ?NS_PUBSUB_OWNER, name = 'configure', attrs =
[?XMLATTR('node', node_to_string(Node))], children = nodeAttr(Node), children =
[#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs = [#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs =
[?XMLATTR('type', <<"form">>)], children = [?XMLATTR('type', <<"form">>)], children =
get_configure_xfields(Type, Options, Lang, Groups) get_configure_xfields(Type, Options, Lang, Groups)
@ -3094,7 +3096,7 @@ uniqid() ->
lists:flatten(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])). lists:flatten(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])).
% node attributes % node attributes
nodeAttr(Node) -> %% TODO: to be used nodeAttr(Node) ->
[?XMLATTR('node', node_to_string(Node))]. [?XMLATTR('node', node_to_string(Node))].
% item attributes % item attributes