fix delete item to allow owner being able to remove all publisher items, and also fix EJAB-1036
SVN Revision: 2589
This commit is contained in:
parent
d678a21f21
commit
31c6d6194f
|
@ -657,6 +657,7 @@ disco_sm_items(Acc, From, To, [], _Lang) ->
|
||||||
disco_sm_items(Acc, From, To, Node, _Lang) ->
|
disco_sm_items(Acc, From, To, Node, _Lang) ->
|
||||||
Host = To#jid.lserver,
|
Host = To#jid.lserver,
|
||||||
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
|
% TODO call get_items/6 instead for access control (EJAB-1033)
|
||||||
case node_call(Type, get_items, [NodeId, From]) of
|
case node_call(Type, get_items, [NodeId, From]) of
|
||||||
{result, []} ->
|
{result, []} ->
|
||||||
none;
|
none;
|
||||||
|
@ -1092,6 +1093,7 @@ iq_disco_items(Host, Item, From) ->
|
||||||
%% TODO That is, remove name attribute (or node?, please check for 2.1)
|
%% TODO That is, remove name attribute (or node?, please check for 2.1)
|
||||||
Action =
|
Action =
|
||||||
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
|
% TODO call get_items/6 instead for access control (EJAB-1033)
|
||||||
NodeItems = case node_call(Type, get_items, [NodeId, From]) of
|
NodeItems = case node_call(Type, get_items, [NodeId, From]) of
|
||||||
{result, I} -> I;
|
{result, I} -> I;
|
||||||
_ -> []
|
_ -> []
|
||||||
|
|
|
@ -481,6 +481,7 @@ disco_sm_items(Acc, From, To, [], _Lang) ->
|
||||||
disco_sm_items(Acc, From, To, Node, _Lang) ->
|
disco_sm_items(Acc, From, To, Node, _Lang) ->
|
||||||
Host = To#jid.lserver,
|
Host = To#jid.lserver,
|
||||||
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
|
% TODO call get_items/6 instead for access control (EJAB-1033)
|
||||||
case node_call(Type, get_items, [NodeId, From]) of
|
case node_call(Type, get_items, [NodeId, From]) of
|
||||||
{result, []} ->
|
{result, []} ->
|
||||||
none;
|
none;
|
||||||
|
@ -919,6 +920,7 @@ iq_disco_items(Host, Item, From, RSM) ->
|
||||||
%% TODO That is, remove name attribute (or node?, please check for 2.1)
|
%% TODO That is, remove name attribute (or node?, please check for 2.1)
|
||||||
Action =
|
Action =
|
||||||
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
|
%% TODO call get_items/6 instead for access control (EJAB-1033)
|
||||||
{NodeItems, RsmOut} = case node_call(Type, get_items, [NodeId, From, RSM]) of
|
{NodeItems, RsmOut} = case node_call(Type, get_items, [NodeId, From, RSM]) of
|
||||||
{result, I} -> I;
|
{result, I} -> I;
|
||||||
_ -> {[], none}
|
_ -> {[], none}
|
||||||
|
|
|
@ -557,12 +557,30 @@ delete_item(NodeId, Publisher, PublishModel, ItemId) ->
|
||||||
case lists:member(ItemId, Items) of
|
case lists:member(ItemId, Items) of
|
||||||
true ->
|
true ->
|
||||||
del_item(NodeId, ItemId),
|
del_item(NodeId, ItemId),
|
||||||
NewItems = lists:delete(ItemId, Items),
|
set_state(GenState#pubsub_state{items = lists:delete(ItemId, Items)}),
|
||||||
set_state(GenState#pubsub_state{items = NewItems}),
|
|
||||||
{result, {default, broadcast}};
|
{result, {default, broadcast}};
|
||||||
false ->
|
false ->
|
||||||
%% Non-existent node or item
|
case Affiliation of
|
||||||
{error, ?ERR_ITEM_NOT_FOUND}
|
owner ->
|
||||||
|
%% Owner can delete other publishers items as well
|
||||||
|
{result, States} = get_states(NodeId),
|
||||||
|
lists:foldl(
|
||||||
|
fun(#pubsub_state{items = PI, affiliation = publisher} = S, Res) ->
|
||||||
|
case lists:member(ItemId, PI) of
|
||||||
|
true ->
|
||||||
|
del_item(NodeId, ItemId),
|
||||||
|
set_state(S#pubsub_state{items = lists:delete(ItemId, PI)}),
|
||||||
|
{result, {default, broadcast}};
|
||||||
|
false ->
|
||||||
|
Res
|
||||||
|
end;
|
||||||
|
(_, Res) ->
|
||||||
|
Res
|
||||||
|
end, {error, ?ERR_ITEM_NOT_FOUND}, States);
|
||||||
|
_ ->
|
||||||
|
%% Non-existent node or item
|
||||||
|
{error, ?ERR_ITEM_NOT_FOUND}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -576,9 +594,15 @@ purge_node(NodeId, Owner) ->
|
||||||
GenKey = jlib:jid_remove_resource(SubKey),
|
GenKey = jlib:jid_remove_resource(SubKey),
|
||||||
GenState = get_state(NodeId, GenKey),
|
GenState = get_state(NodeId, GenKey),
|
||||||
case GenState of
|
case GenState of
|
||||||
#pubsub_state{items = Items, affiliation = owner} ->
|
#pubsub_state{affiliation = owner} ->
|
||||||
del_items(NodeId, Items),
|
{result, States} = get_states(NodeId),
|
||||||
set_state(GenState#pubsub_state{items = []}),
|
lists:foreach(
|
||||||
|
fun(#pubsub_state{items = []}) ->
|
||||||
|
ok;
|
||||||
|
(#pubsub_state{items = Items} = S) ->
|
||||||
|
del_items(NodeId, Items),
|
||||||
|
set_state(S#pubsub_state{items = []})
|
||||||
|
end, States),
|
||||||
{result, {default, broadcast}};
|
{result, {default, broadcast}};
|
||||||
_ ->
|
_ ->
|
||||||
%% Entity is not owner
|
%% Entity is not owner
|
||||||
|
|
|
@ -558,9 +558,12 @@ purge_node(NodeId, Owner) ->
|
||||||
GenKey = jlib:jid_remove_resource(SubKey),
|
GenKey = jlib:jid_remove_resource(SubKey),
|
||||||
GenState = get_state(NodeId, GenKey),
|
GenState = get_state(NodeId, GenKey),
|
||||||
case GenState of
|
case GenState of
|
||||||
#pubsub_state{items = Items, affiliation = owner} ->
|
#pubsub_state{affiliation = owner} ->
|
||||||
del_items(NodeId, Items),
|
{result, States} = get_states(NodeId),
|
||||||
%% set new item list use useless
|
lists:foreach(
|
||||||
|
fun(#pubsub_state{items = []}) -> ok;
|
||||||
|
(#pubsub_state{items = Items}) -> del_items(NodeId, Items)
|
||||||
|
end, States),
|
||||||
{result, {default, broadcast}};
|
{result, {default, broadcast}};
|
||||||
_ ->
|
_ ->
|
||||||
%% Entity is not owner
|
%% Entity is not owner
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
--- mod_pubsub.erl 2009-09-01 15:02:18.000000000 +0200
|
--- mod_pubsub.erl 2009-09-09 21:00:22.000000000 +0200
|
||||||
+++ mod_pubsub_odbc.erl 2009-09-01 15:14:29.000000000 +0200
|
+++ mod_pubsub_odbc.erl 2009-09-09 23:14:58.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)
|
||||||
|
@ -252,7 +252,7 @@
|
||||||
true ->
|
true ->
|
||||||
% resource not concerned about that subscription
|
% resource not concerned about that subscription
|
||||||
ok
|
ok
|
||||||
@@ -796,10 +620,10 @@
|
@@ -797,10 +621,10 @@
|
||||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]),
|
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]),
|
||||||
lists:foreach(fun
|
lists:foreach(fun
|
||||||
({Node, subscribed, _, JID}) ->
|
({Node, subscribed, _, JID}) ->
|
||||||
|
@ -265,7 +265,7 @@
|
||||||
true ->
|
true ->
|
||||||
node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]);
|
node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]);
|
||||||
false ->
|
false ->
|
||||||
@@ -913,7 +737,8 @@
|
@@ -914,7 +738,8 @@
|
||||||
sub_el = SubEl} = IQ ->
|
sub_el = SubEl} = IQ ->
|
||||||
{xmlelement, _, QAttrs, _} = SubEl,
|
{xmlelement, _, QAttrs, _} = SubEl,
|
||||||
Node = xml:get_attr_s("node", QAttrs),
|
Node = xml:get_attr_s("node", QAttrs),
|
||||||
|
@ -275,7 +275,7 @@
|
||||||
{result, IQRes} ->
|
{result, IQRes} ->
|
||||||
jlib:iq_to_xml(
|
jlib:iq_to_xml(
|
||||||
IQ#iq{type = result,
|
IQ#iq{type = result,
|
||||||
@@ -1018,7 +843,7 @@
|
@@ -1019,7 +844,7 @@
|
||||||
[] ->
|
[] ->
|
||||||
["leaf"]; %% No sub-nodes: it's a leaf node
|
["leaf"]; %% No sub-nodes: it's a leaf node
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -284,7 +284,7 @@
|
||||||
{result, []} -> ["collection"];
|
{result, []} -> ["collection"];
|
||||||
{result, _} -> ["leaf", "collection"];
|
{result, _} -> ["leaf", "collection"];
|
||||||
_ -> []
|
_ -> []
|
||||||
@@ -1034,8 +859,9 @@
|
@@ -1035,8 +860,9 @@
|
||||||
[];
|
[];
|
||||||
true ->
|
true ->
|
||||||
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
|
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
|
||||||
|
@ -296,7 +296,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)
|
||||||
@@ -1063,14 +889,15 @@
|
@@ -1064,14 +890,15 @@
|
||||||
{xmlelement, "feature", [{"var", ?NS_DISCO_ITEMS}], []},
|
{xmlelement, "feature", [{"var", ?NS_DISCO_ITEMS}], []},
|
||||||
{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []},
|
{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []},
|
||||||
{xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++
|
{xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++
|
||||||
|
@ -315,7 +315,7 @@
|
||||||
{result, lists:map(
|
{result, lists:map(
|
||||||
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
|
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
|
||||||
SN = node_to_string(SubNode),
|
SN = node_to_string(SubNode),
|
||||||
@@ -1080,7 +907,7 @@
|
@@ -1081,7 +908,7 @@
|
||||||
{"node", SN},
|
{"node", SN},
|
||||||
{"name", RN}], []}
|
{"name", RN}], []}
|
||||||
end, tree_action(Host, get_subnodes, [Host, [], From]))};
|
end, tree_action(Host, get_subnodes, [Host, [], From]))};
|
||||||
|
@ -324,11 +324,13 @@
|
||||||
case string:tokens(Item, "!") of
|
case string:tokens(Item, "!") of
|
||||||
[_SNode, _ItemID] ->
|
[_SNode, _ItemID] ->
|
||||||
{result, []};
|
{result, []};
|
||||||
@@ -1092,9 +919,9 @@
|
@@ -1093,10 +920,10 @@
|
||||||
%% TODO That is, remove name attribute (or node?, please check for 2.1)
|
%% TODO That is, remove name attribute (or node?, please check for 2.1)
|
||||||
Action =
|
Action =
|
||||||
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
|
- % TODO call get_items/6 instead for access control (EJAB-1033)
|
||||||
- NodeItems = case node_call(Type, get_items, [NodeId, From]) of
|
- NodeItems = case node_call(Type, get_items, [NodeId, From]) of
|
||||||
|
+ %% TODO call get_items/6 instead for access control (EJAB-1033)
|
||||||
+ {NodeItems, RsmOut} = case node_call(Type, get_items, [NodeId, From, RSM]) of
|
+ {NodeItems, RsmOut} = case node_call(Type, get_items, [NodeId, From, RSM]) of
|
||||||
{result, I} -> I;
|
{result, I} -> I;
|
||||||
- _ -> []
|
- _ -> []
|
||||||
|
@ -336,7 +338,7 @@
|
||||||
end,
|
end,
|
||||||
Nodes = lists:map(
|
Nodes = lists:map(
|
||||||
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
|
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
|
||||||
@@ -1110,7 +937,7 @@
|
@@ -1112,7 +939,7 @@
|
||||||
{xmlelement, "item", [{"jid", Host}, {"node", SN},
|
{xmlelement, "item", [{"jid", Host}, {"node", SN},
|
||||||
{"name", Name}], []}
|
{"name", Name}], []}
|
||||||
end, NodeItems),
|
end, NodeItems),
|
||||||
|
@ -345,7 +347,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};
|
||||||
@@ -1242,7 +1069,8 @@
|
@@ -1244,7 +1071,8 @@
|
||||||
(_, Acc) ->
|
(_, Acc) ->
|
||||||
Acc
|
Acc
|
||||||
end, [], xml:remove_cdata(Els)),
|
end, [], xml:remove_cdata(Els)),
|
||||||
|
@ -355,7 +357,7 @@
|
||||||
{get, "subscriptions"} ->
|
{get, "subscriptions"} ->
|
||||||
get_subscriptions(Host, Node, From, Plugins);
|
get_subscriptions(Host, Node, From, Plugins);
|
||||||
{get, "affiliations"} ->
|
{get, "affiliations"} ->
|
||||||
@@ -1265,7 +1093,9 @@
|
@@ -1267,7 +1095,9 @@
|
||||||
|
|
||||||
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
||||||
{xmlelement, _, _, SubEls} = SubEl,
|
{xmlelement, _, _, SubEls} = SubEl,
|
||||||
|
@ -366,7 +368,7 @@
|
||||||
case Action of
|
case Action of
|
||||||
[{xmlelement, Name, Attrs, Els}] ->
|
[{xmlelement, Name, Attrs, Els}] ->
|
||||||
Node = case Host of
|
Node = case Host of
|
||||||
@@ -1391,7 +1221,8 @@
|
@@ -1393,7 +1223,8 @@
|
||||||
_ -> []
|
_ -> []
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -376,7 +378,7 @@
|
||||||
sync_dirty) of
|
sync_dirty) of
|
||||||
{result, Res} -> Res;
|
{result, Res} -> Res;
|
||||||
Err -> Err
|
Err -> Err
|
||||||
@@ -1431,7 +1262,7 @@
|
@@ -1433,7 +1264,7 @@
|
||||||
|
|
||||||
%%% authorization handling
|
%%% authorization handling
|
||||||
|
|
||||||
|
@ -385,7 +387,7 @@
|
||||||
Lang = "en", %% TODO fix
|
Lang = "en", %% TODO fix
|
||||||
Stanza = {xmlelement, "message",
|
Stanza = {xmlelement, "message",
|
||||||
[],
|
[],
|
||||||
@@ -1460,7 +1291,7 @@
|
@@ -1462,7 +1293,7 @@
|
||||||
[{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]},
|
[{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]},
|
||||||
lists:foreach(fun(Owner) ->
|
lists:foreach(fun(Owner) ->
|
||||||
ejabberd_router ! {route, service_jid(Host), jlib:make_jid(Owner), Stanza}
|
ejabberd_router ! {route, service_jid(Host), jlib:make_jid(Owner), Stanza}
|
||||||
|
@ -394,7 +396,7 @@
|
||||||
|
|
||||||
find_authorization_response(Packet) ->
|
find_authorization_response(Packet) ->
|
||||||
{xmlelement, _Name, _Attrs, Els} = Packet,
|
{xmlelement, _Name, _Attrs, Els} = Packet,
|
||||||
@@ -1527,8 +1358,8 @@
|
@@ -1529,8 +1360,8 @@
|
||||||
"true" -> true;
|
"true" -> true;
|
||||||
_ -> false
|
_ -> false
|
||||||
end,
|
end,
|
||||||
|
@ -405,7 +407,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 ->
|
||||||
@@ -1714,7 +1545,7 @@
|
@@ -1716,7 +1547,7 @@
|
||||||
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||||
[{xmlelement, "create", nodeAttr(Node),
|
[{xmlelement, "create", nodeAttr(Node),
|
||||||
[]}]}],
|
[]}]}],
|
||||||
|
@ -414,7 +416,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)),
|
||||||
@@ -1822,12 +1653,12 @@
|
@@ -1824,12 +1655,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) ->
|
||||||
|
@ -429,7 +431,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),
|
||||||
@@ -1846,9 +1677,13 @@
|
@@ -1848,9 +1679,13 @@
|
||||||
{"", "", ""} ->
|
{"", "", ""} ->
|
||||||
{false, false};
|
{false, false};
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -446,7 +448,7 @@
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
if
|
if
|
||||||
@@ -2171,7 +2006,7 @@
|
@@ -2173,7 +2008,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.
|
||||||
|
@ -455,7 +457,7 @@
|
||||||
MaxItems =
|
MaxItems =
|
||||||
if
|
if
|
||||||
SMaxItems == "" -> ?MAXITEMS;
|
SMaxItems == "" -> ?MAXITEMS;
|
||||||
@@ -2210,11 +2045,11 @@
|
@@ -2212,11 +2047,11 @@
|
||||||
node_call(Type, get_items,
|
node_call(Type, get_items,
|
||||||
[NodeId, From,
|
[NodeId, From,
|
||||||
AccessModel, PresenceSubscription, RosterGroup,
|
AccessModel, PresenceSubscription, RosterGroup,
|
||||||
|
@ -469,7 +471,7 @@
|
||||||
SendItems = case ItemIDs of
|
SendItems = case ItemIDs of
|
||||||
[] ->
|
[] ->
|
||||||
Items;
|
Items;
|
||||||
@@ -2227,7 +2062,8 @@
|
@@ -2229,7 +2064,8 @@
|
||||||
%% number of items sent to MaxItems:
|
%% number of items sent to MaxItems:
|
||||||
{result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
{result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||||
[{xmlelement, "items", nodeAttr(Node),
|
[{xmlelement, "items", nodeAttr(Node),
|
||||||
|
@ -479,7 +481,7 @@
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end
|
end
|
||||||
@@ -2259,15 +2095,22 @@
|
@@ -2261,15 +2097,22 @@
|
||||||
%% @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) ->
|
||||||
|
@ -508,7 +510,7 @@
|
||||||
send_items(Host, Node, NodeId, Type, LJID, Number) ->
|
send_items(Host, Node, NodeId, Type, 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, []} ->
|
||||||
@@ -2385,29 +2228,12 @@
|
@@ -2387,29 +2230,12 @@
|
||||||
error ->
|
error ->
|
||||||
{error, ?ERR_BAD_REQUEST};
|
{error, ?ERR_BAD_REQUEST};
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -541,7 +543,7 @@
|
||||||
end, Entities),
|
end, Entities),
|
||||||
{result, []};
|
{result, []};
|
||||||
_ ->
|
_ ->
|
||||||
@@ -2460,11 +2286,11 @@
|
@@ -2462,11 +2288,11 @@
|
||||||
end.
|
end.
|
||||||
|
|
||||||
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
|
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
|
||||||
|
@ -555,7 +557,7 @@
|
||||||
OptionsEl = {xmlelement, "options", [{"node", node_to_string(Node)},
|
OptionsEl = {xmlelement, "options", [{"node", node_to_string(Node)},
|
||||||
{"jid", jlib:jid_to_string(Subscriber)},
|
{"jid", jlib:jid_to_string(Subscriber)},
|
||||||
{"subid", SubID}],
|
{"subid", SubID}],
|
||||||
@@ -2495,7 +2321,7 @@
|
@@ -2497,7 +2323,7 @@
|
||||||
error -> {"", "", ""};
|
error -> {"", "", ""};
|
||||||
J -> jlib:jid_tolower(J)
|
J -> jlib:jid_tolower(J)
|
||||||
end,
|
end,
|
||||||
|
@ -564,7 +566,7 @@
|
||||||
{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) ->
|
||||||
@@ -2515,7 +2341,7 @@
|
@@ -2517,7 +2343,7 @@
|
||||||
end.
|
end.
|
||||||
|
|
||||||
write_sub(Subscriber, NodeID, SubID, Options) ->
|
write_sub(Subscriber, NodeID, SubID, Options) ->
|
||||||
|
@ -573,7 +575,7 @@
|
||||||
{error, notfound} ->
|
{error, notfound} ->
|
||||||
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
||||||
{result, _} ->
|
{result, _} ->
|
||||||
@@ -2683,8 +2509,8 @@
|
@@ -2685,8 +2511,8 @@
|
||||||
{"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
|
{"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
|
||||||
ejabberd_router ! {route, service_jid(Host), jlib:make_jid(JID), Stanza}
|
ejabberd_router ! {route, service_jid(Host), jlib:make_jid(JID), Stanza}
|
||||||
end,
|
end,
|
||||||
|
@ -584,7 +586,7 @@
|
||||||
true ->
|
true ->
|
||||||
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
||||||
|
|
||||||
@@ -2966,7 +2792,7 @@
|
@@ -2968,7 +2794,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,
|
||||||
|
@ -593,7 +595,7 @@
|
||||||
{result, CollSubs} -> CollSubs;
|
{result, CollSubs} -> CollSubs;
|
||||||
_ -> []
|
_ -> []
|
||||||
end.
|
end.
|
||||||
@@ -2980,9 +2806,9 @@
|
@@ -2982,9 +2808,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) ->
|
||||||
|
@ -605,7 +607,7 @@
|
||||||
_ -> Acc
|
_ -> Acc
|
||||||
end;
|
end;
|
||||||
(_, Acc) ->
|
(_, Acc) ->
|
||||||
@@ -3176,6 +3002,30 @@
|
@@ -3178,6 +3004,30 @@
|
||||||
Result
|
Result
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -636,7 +638,7 @@
|
||||||
%% @spec (Host, Options) -> MaxItems
|
%% @spec (Host, Options) -> MaxItems
|
||||||
%% Host = host()
|
%% Host = host()
|
||||||
%% Options = [Option]
|
%% Options = [Option]
|
||||||
@@ -3549,7 +3399,13 @@
|
@@ -3551,7 +3401,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,
|
||||||
|
@ -651,7 +653,7 @@
|
||||||
|
|
||||||
%% @doc <p>node plugin call.</p>
|
%% @doc <p>node plugin call.</p>
|
||||||
node_call(Type, Function, Args) ->
|
node_call(Type, Function, Args) ->
|
||||||
@@ -3569,13 +3425,13 @@
|
@@ -3571,13 +3427,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]),
|
||||||
|
@ -667,7 +669,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
|
||||||
@@ -3588,8 +3444,14 @@
|
@@ -3590,8 +3446,14 @@
|
||||||
end
|
end
|
||||||
end, Trans).
|
end, Trans).
|
||||||
|
|
||||||
|
@ -684,7 +686,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};
|
||||||
@@ -3597,6 +3459,15 @@
|
@@ -3599,6 +3461,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, ?ERR_INTERNAL_SERVER_ERROR};
|
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||||
|
@ -700,7 +702,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, ?ERR_INTERNAL_SERVER_ERROR};
|
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||||
@@ -3605,6 +3476,17 @@
|
@@ -3607,6 +3478,17 @@
|
||||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ subscribe_node(JID, NodeID, Options) ->
|
||||||
case catch mnesia:sync_dirty(fun add_subscription/3,
|
case catch mnesia:sync_dirty(fun add_subscription/3,
|
||||||
[JID, NodeID, Options]) of
|
[JID, NodeID, Options]) of
|
||||||
{'EXIT', {aborted, Error}} -> Error;
|
{'EXIT', {aborted, Error}} -> Error;
|
||||||
|
{error, Error} -> {error, Error};
|
||||||
Result -> {result, Result}
|
Result -> {result, Result}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -102,6 +103,7 @@ unsubscribe_node(JID, NodeID, SubID) ->
|
||||||
case catch mnesia:sync_dirty(fun delete_subscription/3,
|
case catch mnesia:sync_dirty(fun delete_subscription/3,
|
||||||
[JID, NodeID, SubID]) of
|
[JID, NodeID, SubID]) of
|
||||||
{'EXIT', {aborted, Error}} -> Error;
|
{'EXIT', {aborted, Error}} -> Error;
|
||||||
|
{error, Error} -> {error, Error};
|
||||||
Result -> {result, Result}
|
Result -> {result, Result}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -109,6 +111,7 @@ get_subscription(JID, NodeID, SubID) ->
|
||||||
case catch mnesia:sync_dirty(fun read_subscription/3,
|
case catch mnesia:sync_dirty(fun read_subscription/3,
|
||||||
[JID, NodeID, SubID]) of
|
[JID, NodeID, SubID]) of
|
||||||
{'EXIT', {aborted, Error}} -> Error;
|
{'EXIT', {aborted, Error}} -> Error;
|
||||||
|
{error, Error} -> {error, Error};
|
||||||
Result -> {result, Result}
|
Result -> {result, Result}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -116,6 +119,7 @@ set_subscription(JID, NodeID, SubID, Options) ->
|
||||||
case catch mnesia:sync_dirty(fun write_subscription/4,
|
case catch mnesia:sync_dirty(fun write_subscription/4,
|
||||||
[JID, NodeID, SubID, Options]) of
|
[JID, NodeID, SubID, Options]) of
|
||||||
{'EXIT', {aborted, Error}} -> Error;
|
{'EXIT', {aborted, Error}} -> Error;
|
||||||
|
{error, Error} -> {error, Error};
|
||||||
Result -> {result, Result}
|
Result -> {result, Result}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -160,26 +164,23 @@ create_table() ->
|
||||||
|
|
||||||
add_subscription(_JID, _NodeID, Options) ->
|
add_subscription(_JID, _NodeID, Options) ->
|
||||||
SubID = make_subid(),
|
SubID = make_subid(),
|
||||||
Record = #pubsub_subscription{subid = SubID, options = Options},
|
mnesia:write(#pubsub_subscription{subid = SubID, options = Options}),
|
||||||
mnesia:write(Record),
|
|
||||||
SubID.
|
SubID.
|
||||||
|
|
||||||
delete_subscription(JID, NodeID, SubID) ->
|
delete_subscription(_JID, _NodeID, SubID) ->
|
||||||
Sub = read_subscription(JID, NodeID, SubID),
|
mnesia:delete({pubsub_subscription, SubID}).
|
||||||
mnesia:delete({pubsub_subscription, SubID}),
|
|
||||||
Sub.
|
|
||||||
|
|
||||||
read_subscription(_JID, _NodeID, SubID) ->
|
read_subscription(_JID, _NodeID, SubID) ->
|
||||||
Q = qlc:q([Sub || Sub <- mnesia:table(pubsub_subscription),
|
case mnesia:read({pubsub_subscription, SubID}) of
|
||||||
Sub#pubsub_subscription.subid == SubID]),
|
[Sub] -> Sub;
|
||||||
case qlc:e(Q) of
|
_ -> {error, notfound}
|
||||||
[Sub] -> Sub;
|
|
||||||
[] -> mnesia:abort({error, notfound})
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
write_subscription(JID, NodeID, SubID, Options) ->
|
write_subscription(JID, NodeID, SubID, Options) ->
|
||||||
Sub = read_subscription(JID, NodeID, SubID),
|
case read_subscription(JID, NodeID, SubID) of
|
||||||
mnesia:write(Sub#pubsub_subscription{options = Options}).
|
{error, notfound} -> {error, notfound};
|
||||||
|
Sub -> mnesia:write(Sub#pubsub_subscription{options = Options})
|
||||||
|
end.
|
||||||
|
|
||||||
make_subid() ->
|
make_subid() ->
|
||||||
{T1, T2, T3} = now(),
|
{T1, T2, T3} = now(),
|
||||||
|
|
Loading…
Reference in New Issue