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

fix: subscribe, unsubscribe, last published item (thanks karim)

This commit is contained in:
Christophe Romain 2010-03-05 13:50:51 +01:00
parent c8c7169465
commit 236423d058
4 changed files with 72 additions and 65 deletions

View File

@ -976,6 +976,8 @@ do_route(ServerHost, Access, Plugins, Host, From, To, Packet) ->
lang = Lang, payload = SubEl} -> lang = Lang, payload = SubEl} ->
Res = Res =
case iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) of case iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) of
{result, []} ->
exmpp_iq:result(Packet);
{result, IQRes} -> {result, IQRes} ->
exmpp_iq:result(Packet, IQRes); exmpp_iq:result(Packet, IQRes);
{error, Error} -> {error, Error} ->
@ -1922,7 +1924,6 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
_:_ -> _:_ ->
{undefined, undefined, undefined} {undefined, undefined, undefined}
end, end,
SubId = uniqid(),
Action = fun(#pubsub_node{options = Options, owners = [Owner|_], type = Type, id = NodeId}) -> Action = fun(#pubsub_node{options = Options, owners = [Owner|_], type = Type, id = NodeId}) ->
Features = features(Type), Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features), SubscribeFeature = lists:member("subscribe", Features),
@ -1972,13 +1973,13 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
%% TODO, this is subscription-notification, should depends on node features %% TODO, this is subscription-notification, should depends on node features
SubAttrs = case Subscription of SubAttrs = case Subscription of
{subscribed, SubId} -> {subscribed, SubId} ->
[{"subscription", subscription_to_string(subscribed)}, [?XMLATTR("subscription", subscription_to_string(subscribed)),
{"subid", SubId}]; ?XMLATTR("subid", SubId)];
Other -> Other ->
[{"subscription", subscription_to_string(Other)}] [?XMLATTR("subscription", subscription_to_string(Other))]
end, end,
Fields = Fields =
[ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)) | SubAttrs], [ ?XMLATTR('jid', JID) | SubAttrs],
#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'subscription', attrs = Fields}]} [#xmlel{ns = ?NS_PUBSUB, name = 'subscription', attrs = Fields}]}
end, end,
@ -2390,7 +2391,8 @@ send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
end, end,
Stanza = case ToSend of Stanza = case ToSend of
[LastItem] -> [LastItem] ->
{ModifNow, ModifLjid} = LastItem#pubsub_item.modification, {ModifNow, {U, S, R}} = LastItem#pubsub_item.modification,
ModifLjid = exmpp_jid:make(U, S, R),
event_stanza_with_delay( event_stanza_with_delay(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children =
itemsEls(ToSend)}], ModifNow, ModifLjid); itemsEls(ToSend)}], ModifNow, ModifLjid);

View File

@ -137,6 +137,7 @@
nodetree = ?STDTREE, nodetree = ?STDTREE,
plugins = [?STDNODE]}). plugins = [?STDNODE]}).
%%==================================================================== %%====================================================================
%% API %% API
%%==================================================================== %%====================================================================
@ -540,6 +541,8 @@ presence_probe(Peer, JID, Pid) ->
presence(Host, {presence, User, Server, [Resource], JID}) presence(Host, {presence, User, Server, [Resource], JID})
end end
end. end.
presence(ServerHost, Presence) when is_binary(ServerHost) ->
presence(binary_to_list(ServerHost), Presence);
presence(ServerHost, Presence) -> presence(ServerHost, Presence) ->
SendLoop = case whereis(gen_mod:get_module_proc(ServerHost, ?LOOPNAME)) of SendLoop = case whereis(gen_mod:get_module_proc(ServerHost, ?LOOPNAME)) of
undefined -> undefined ->
@ -779,6 +782,8 @@ do_route(ServerHost, Access, Plugins, Host, From, To, Packet) ->
lang = Lang, payload = SubEl} -> lang = Lang, payload = SubEl} ->
Res = Res =
case iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) of case iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) of
{result, []} ->
exmpp_iq:result(Packet);
{result, IQRes} -> {result, IQRes} ->
exmpp_iq:result(Packet, IQRes); exmpp_iq:result(Packet, IQRes);
{error, Error} -> {error, Error} ->
@ -1731,7 +1736,6 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
_:_ -> _:_ ->
{undefined, undefined, undefined} {undefined, undefined, undefined}
end, end,
SubId = uniqid(),
Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) -> Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) ->
Features = features(Type), Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features), SubscribeFeature = lists:member("subscribe", Features),
@ -1785,13 +1789,13 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
%% TODO, this is subscription-notification, should depends on node features %% TODO, this is subscription-notification, should depends on node features
SubAttrs = case Subscription of SubAttrs = case Subscription of
{subscribed, SubId} -> {subscribed, SubId} ->
[{"subscription", subscription_to_string(subscribed)}, [?XMLATTR("subscription", subscription_to_string(subscribed)),
{"subid", SubId}]; ?XMLATTR("subid", SubId)];
Other -> Other ->
[{"subscription", subscription_to_string(Other)}] [?XMLATTR("subscription", subscription_to_string(Other))]
end, end,
Fields = Fields =
[ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)) | SubAttrs], [ ?XMLATTR('jid', JID) | SubAttrs],
#xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'subscription', attrs = Fields}]} [#xmlel{ns = ?NS_PUBSUB, name = 'subscription', attrs = Fields}]}
end, end,
@ -2215,7 +2219,8 @@ send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
end, end,
Stanza = case ToSend of Stanza = case ToSend of
[LastItem] -> [LastItem] ->
{ModifNow, ModifLjid} = LastItem#pubsub_item.modification, {ModifNow, {U, S, R}} = LastItem#pubsub_item.modification,
ModifLjid = exmpp_jid:make(U, S, R),
event_stanza_with_delay( event_stanza_with_delay(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children = [#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node), children =
itemsEls(ToSend)}], ModifNow, ModifLjid); itemsEls(ToSend)}], ModifNow, ModifLjid);

View File

@ -280,10 +280,10 @@ delete_node(Removed) ->
%% to completly disable persistance.</li></ul> %% to completly disable persistance.</li></ul>
%% </p> %% </p>
%% <p>In the default plugin module, the record is unchanged.</p> %% <p>In the default plugin module, the record is unchanged.</p>
subscribe_node(NodeId, Sender, Subscriber, AccessModel, subscribe_node(NodeId, Sender, {U,S,R} = Subscriber, AccessModel,
SendLast, PresenceSubscription, RosterGroup, Options) -> SendLast, PresenceSubscription, RosterGroup, Options) ->
SubKey = jlib:short_prepd_jid(Subscriber), SubKey = {U, S, R},
GenKey = jlib:short_prepd_bare_jid(SubKey), GenKey = {U, S, undefined},
Authorized = (jlib:short_prepd_bare_jid(Sender) == GenKey), Authorized = (jlib:short_prepd_bare_jid(Sender) == GenKey),
GenState = get_state(NodeId, GenKey), GenState = get_state(NodeId, GenKey),
SubState = case SubKey of SubState = case SubKey of
@ -350,9 +350,9 @@ subscribe_node(NodeId, Sender, Subscriber, AccessModel,
%% SubId = mod_pubsub:subid() %% SubId = mod_pubsub:subid()
%% Reason = mod_pubsub:stanzaError() %% Reason = mod_pubsub:stanzaError()
%% @doc <p>Unsubscribe the <tt>Subscriber</tt> from the <tt>Node</tt>.</p> %% @doc <p>Unsubscribe the <tt>Subscriber</tt> from the <tt>Node</tt>.</p>
unsubscribe_node(NodeId, Sender, Subscriber, SubId) -> unsubscribe_node(NodeId, Sender, {User, Server, Resource} = Subscriber, SubId) ->
SubKey = jlib:short_prepd_jid(Subscriber), SubKey = {User, Server, Resource},
GenKey = jlib:short_prepd_bare_jid(SubKey), GenKey = {User, Server, undefined},
Authorized = (jlib:short_prepd_bare_jid(Sender) == GenKey), Authorized = (jlib:short_prepd_bare_jid(Sender) == GenKey),
GenState = get_state(NodeId, GenKey), GenState = get_state(NodeId, GenKey),
SubState = case SubKey of SubState = case SubKey of

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2010-01-13 11:01:09.000000000 +0100 --- mod_pubsub.erl 2010-03-05 13:25:53.000000000 +0100
+++ mod_pubsub_odbc.erl 2010-01-13 11:01:49.000000000 +0100 +++ mod_pubsub_odbc.erl 2010-03-05 13:28:45.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.
@ -40,7 +40,7 @@
-define(LOOPNAME, ejabberd_mod_pubsub_loop). -define(LOOPNAME, ejabberd_mod_pubsub_loop).
-define(PLUGIN_PREFIX, "node_"). -define(PLUGIN_PREFIX, "node_").
-define(TREE_PREFIX, "nodetree_"). -define(TREE_PREFIX, "nodetree_").
@@ -226,8 +226,6 @@ @@ -221,8 +221,6 @@
ok ok
end, end,
ejabberd_router:register_route(Host), ejabberd_router:register_route(Host),
@ -49,7 +49,7 @@
init_nodes(Host, ServerHost, NodeTree, Plugins), init_nodes(Host, ServerHost, NodeTree, Plugins),
State = #state{host = Host, State = #state{host = Host,
server_host = ServerHost, server_host = ServerHost,
@@ -286,206 +284,15 @@ @@ -281,206 +279,15 @@
init_nodes(Host, ServerHost, _NodeTree, Plugins) -> init_nodes(Host, ServerHost, _NodeTree, Plugins) ->
%% TODO, this call should be done plugin side %% TODO, this call should be done plugin side
@ -260,7 +260,7 @@
send_loop(State) -> send_loop(State) ->
receive receive
@@ -497,17 +304,15 @@ @@ -492,17 +299,15 @@
%% for each node From is subscribed to %% for each node From is subscribed to
%% and if the node is so configured, send the last published item to From %% and if the node is so configured, send the last published item to From
lists:foreach(fun(PType) -> lists:foreach(fun(PType) ->
@ -284,7 +284,7 @@
true -> true ->
% resource not concerned about that subscription % resource not concerned about that subscription
ok ok
@@ -688,8 +493,7 @@ @@ -683,8 +488,7 @@
end; end;
disco_sm_items(Acc, From, To, NodeB, _Lang) -> disco_sm_items(Acc, From, To, NodeB, _Lang) ->
@ -294,7 +294,7 @@
%% TODO, use iq_disco_items(Host, Node, From) %% TODO, use iq_disco_items(Host, Node, From)
Host = exmpp_jid:prep_domain_as_list(To), Host = exmpp_jid:prep_domain_as_list(To),
LJID = jlib:short_prepd_bare_jid(To), LJID = jlib:short_prepd_bare_jid(To),
@@ -723,6 +527,7 @@ @@ -718,6 +522,7 @@
%% ------- %% -------
%% presence hooks handling functions %% presence hooks handling functions
%% %%
@ -302,7 +302,7 @@
presence_probe(Peer, JID, Pid) -> presence_probe(Peer, JID, Pid) ->
case exmpp_jid:full_compare(Peer, JID) of case exmpp_jid:full_compare(Peer, JID) of
true -> %% JID are equals true -> %% JID are equals
@@ -787,10 +592,10 @@ @@ -784,10 +589,10 @@
lists:foreach(fun(PType) -> lists:foreach(fun(PType) ->
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]), {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
lists:foreach(fun lists:foreach(fun
@ -315,7 +315,7 @@
true -> true ->
node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]); node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
false -> false ->
@@ -961,11 +766,12 @@ @@ -958,11 +763,12 @@
end, end,
ejabberd_router:route(To, From, Res); ejabberd_router:route(To, From, Res);
#iq{type = get, ns = ?NS_DISCO_ITEMS, #iq{type = get, ns = ?NS_DISCO_ITEMS,
@ -330,7 +330,7 @@
{result, IQRes} -> {result, IQRes} ->
Result = #xmlel{ns = ?NS_DISCO_ITEMS, Result = #xmlel{ns = ?NS_DISCO_ITEMS,
name = 'query', attrs = QAttrs, name = 'query', attrs = QAttrs,
@@ -1083,7 +889,7 @@ @@ -1082,7 +888,7 @@
[] -> [] ->
["leaf"]; %% No sub-nodes: it's a leaf node ["leaf"]; %% No sub-nodes: it's a leaf node
_ -> _ ->
@ -339,7 +339,7 @@
{result, []} -> ["collection"]; {result, []} -> ["collection"];
{result, _} -> ["leaf", "collection"]; {result, _} -> ["leaf", "collection"];
_ -> [] _ -> []
@@ -1099,8 +905,9 @@ @@ -1098,8 +904,9 @@
[]; [];
true -> true ->
[#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} | [#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} |
@ -351,7 +351,7 @@
end, features(Type))] end, features(Type))]
end, end,
%% TODO: add meta-data info (spec section 5.4) %% TODO: add meta-data info (spec section 5.4)
@@ -1129,8 +936,9 @@ @@ -1128,8 +935,9 @@
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]},
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_ADHOC_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_ADHOC_s)]},
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++ #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++
@ -363,7 +363,7 @@
end, features(Host, Node))}; end, features(Host, Node))};
?NS_ADHOC_b -> ?NS_ADHOC_b ->
command_disco_info(Host, Node, From); command_disco_info(Host, Node, From);
@@ -1140,7 +948,7 @@ @@ -1139,7 +947,7 @@
node_disco_info(Host, Node, From) node_disco_info(Host, Node, From)
end. end.
@ -372,7 +372,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(
@@ -1153,7 +961,7 @@ @@ -1152,7 +960,7 @@
Other -> Other ->
Other Other
end; end;
@ -381,7 +381,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',
@@ -1162,10 +970,10 @@ @@ -1161,10 +969,10 @@
?XMLATTR('name', "Get Pending") ?XMLATTR('name', "Get Pending")
]}], ]}],
{result, CommandItems}; {result, CommandItems};
@ -394,7 +394,7 @@
case string:tokens(Item, "!") of case string:tokens(Item, "!") of
[_SNode, _ItemID] -> [_SNode, _ItemID] ->
{result, []}; {result, []};
@@ -1173,10 +981,10 @@ @@ -1172,10 +980,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}) ->
@ -408,7 +408,7 @@
end, end,
Nodes = lists:map( Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) -> fun(#pubsub_node{nodeid = {_, SubNode}}) ->
@@ -1187,9 +995,10 @@ @@ -1186,9 +994,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]),
@ -421,7 +421,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};
@@ -1320,7 +1129,8 @@ @@ -1319,7 +1128,8 @@
(_, Acc) -> (_, Acc) ->
Acc Acc
end, [], exmpp_xml:remove_cdata_from_list(Els)), end, [], exmpp_xml:remove_cdata_from_list(Els)),
@ -431,7 +431,7 @@
{get, 'subscriptions'} -> {get, 'subscriptions'} ->
get_subscriptions(Host, Node, From, Plugins); get_subscriptions(Host, Node, From, Plugins);
{get, 'affiliations'} -> {get, 'affiliations'} ->
@@ -1342,8 +1152,9 @@ @@ -1341,8 +1151,9 @@
end. end.
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) -> iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
@ -443,7 +443,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', "")),
@@ -1477,7 +1288,8 @@ @@ -1476,7 +1287,8 @@
_ -> [] _ -> []
end end
end, end,
@ -453,7 +453,7 @@
sync_dirty) of sync_dirty) of
{result, Res} -> Res; {result, Res} -> Res;
Err -> Err Err -> Err
@@ -1521,7 +1333,7 @@ @@ -1520,7 +1332,7 @@
%%% authorization handling %%% authorization handling
@ -462,7 +462,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 =
@@ -1551,7 +1363,7 @@ @@ -1550,7 +1362,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)
@ -471,7 +471,7 @@
find_authorization_response(Packet) -> find_authorization_response(Packet) ->
Els = Packet#xmlel.children, Els = Packet#xmlel.children,
@@ -1593,7 +1405,7 @@ @@ -1592,7 +1404,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 =
@ -480,7 +480,7 @@
}]), }]),
ejabberd_router:route(service_jid(Host), JID, Stanza). ejabberd_router:route(service_jid(Host), JID, Stanza).
@@ -1604,14 +1416,14 @@ @@ -1603,14 +1415,14 @@
{{value, {_, [SNode]}}, {value, {_, [SSubscriber]}}, {{value, {_, [SNode]}}, {value, {_, [SSubscriber]}},
{value, {_, [SAllow]}}} -> {value, {_, [SAllow]}}} ->
Node = string_to_node(SNode), Node = string_to_node(SNode),
@ -498,7 +498,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 ->
@@ -1806,7 +1618,7 @@ @@ -1805,7 +1617,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)}]},
@ -507,7 +507,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)),
@@ -1915,7 +1727,7 @@ @@ -1914,7 +1726,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) ->
@ -516,16 +516,16 @@
{result, GoodSubOpts} -> GoodSubOpts; {result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid _ -> invalid
end, end,
@@ -1926,7 +1738,7 @@ @@ -1924,7 +1736,7 @@
_:_ ->
{undefined, undefined, undefined} {undefined, undefined, undefined}
end, end,
SubId = uniqid(),
- Action = fun(#pubsub_node{options = Options, owners = [Owner|_], type = Type, id = NodeId}) -> - Action = fun(#pubsub_node{options = Options, owners = [Owner|_], type = Type, id = NodeId}) ->
+ Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) -> + Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) ->
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),
@@ -1945,9 +1757,13 @@ @@ -1943,9 +1755,13 @@
{"", "", ""} -> {"", "", ""} ->
{false, false}; {false, false};
_ -> _ ->
@ -542,7 +542,7 @@
end end
end, end,
if if
@@ -2280,7 +2096,7 @@ @@ -2278,7 +2094,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.
@ -551,7 +551,7 @@
MaxItems = MaxItems =
if if
SMaxItems == "" -> get_max_items_node(Host); SMaxItems == "" -> get_max_items_node(Host);
@@ -2319,11 +2135,11 @@ @@ -2317,11 +2133,11 @@
node_call(Type, get_items, node_call(Type, get_items,
[NodeId, From, [NodeId, From,
AccessModel, PresenceSubscription, RosterGroup, AccessModel, PresenceSubscription, RosterGroup,
@ -565,7 +565,7 @@
SendItems = case ItemIDs of SendItems = case ItemIDs of
[] -> [] ->
Items; Items;
@@ -2336,7 +2152,7 @@ @@ -2334,7 +2150,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 =
@ -574,7 +574,7 @@
Error -> Error ->
Error Error
end end
@@ -2368,17 +2184,29 @@ @@ -2366,17 +2182,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) ->
@ -611,7 +611,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, []} ->
@@ -2507,29 +2335,12 @@ @@ -2506,29 +2334,12 @@
error -> error ->
{error, 'bad-request'}; {error, 'bad-request'};
_ -> _ ->
@ -644,7 +644,7 @@
end, Entities), end, Entities),
{result, []}; {result, []};
_ -> _ ->
@@ -2584,11 +2395,11 @@ @@ -2583,11 +2394,11 @@
end. end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) -> read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -658,7 +658,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)],
@@ -2615,7 +2426,7 @@ @@ -2614,7 +2425,7 @@
end. end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) -> set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
@ -667,7 +667,7 @@
{result, GoodSubOpts} -> GoodSubOpts; {result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid _ -> invalid
end, end,
@@ -2645,7 +2456,7 @@ @@ -2644,7 +2455,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) ->
@ -676,7 +676,7 @@
{error, notfound} -> {error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")}; {error, extended_error('not-acceptable', "invalid-subid")};
{result, _} -> {result, _} ->
@@ -2818,8 +2629,8 @@ @@ -2817,8 +2628,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,
@ -687,7 +687,7 @@
true -> true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3108,7 +2919,7 @@ @@ -3107,7 +2918,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,
@ -696,7 +696,7 @@
{result, CollSubs} -> CollSubs; {result, CollSubs} -> CollSubs;
_ -> [] _ -> []
end. end.
@@ -3122,9 +2933,9 @@ @@ -3121,9 +2932,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) ->
@ -708,7 +708,7 @@
_ -> Acc _ -> Acc
end; end;
(_, Acc) -> (_, Acc) ->
@@ -3132,7 +2943,7 @@ @@ -3131,7 +2942,7 @@
end, [], Subs). end, [], Subs).
% TODO: merge broadcast code that way % TODO: merge broadcast code that way
@ -717,7 +717,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 ->
@@ -3353,6 +3164,30 @@ @@ -3352,6 +3163,30 @@
Result Result
end. end.
@ -748,7 +748,7 @@
%% @spec (Host, Options) -> MaxItems %% @spec (Host, Options) -> MaxItems
%% Host = host() %% Host = host()
%% Options = [Option] %% Options = [Option]
@@ -3748,7 +3583,13 @@ @@ -3747,7 +3582,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,
@ -763,7 +763,7 @@
%% @doc <p>node plugin call.</p> %% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) -> node_call(Type, Function, Args) ->
@@ -3768,13 +3609,13 @@ @@ -3767,13 +3608,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]),
@ -779,7 +779,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
@@ -3787,8 +3628,15 @@ @@ -3786,8 +3627,15 @@
end end
end, Trans). end, Trans).
@ -797,7 +797,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};
@@ -3796,6 +3644,15 @@ @@ -3795,6 +3643,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'};
@ -813,7 +813,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'};
@@ -3804,6 +3661,16 @@ @@ -3803,6 +3660,16 @@
{error, 'internal-server-error'} {error, 'internal-server-error'}
end. end.