24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-09-27 14:30:55 +02:00

fix delete item to allow owner being able to remove all publisher items, and also fix EJAB-1036

SVN Revision: 2591
This commit is contained in:
Christophe Romain 2009-09-09 21:49:23 +00:00
parent 04e86829e3
commit 376741c9a1
6 changed files with 100 additions and 68 deletions

View File

@ -668,6 +668,7 @@ disco_sm_items(Acc, From, To, NodeB, _Lang) ->
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),
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;
@ -1111,6 +1112,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;
_ -> [] _ -> []

View File

@ -494,6 +494,7 @@ disco_sm_items(Acc, From, To, NodeB, _Lang) ->
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),
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;
@ -940,6 +941,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}

View File

@ -556,13 +556,31 @@ 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 ->
case Affiliation of
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, 'item-not-found'}, States);
_ ->
%% Non-existent node or item %% Non-existent node or item
{error, 'item-not-found'} {error, 'item-not-found'}
end end
end
end. end.
%% @spec (NodeId, Owner) -> %% @spec (NodeId, Owner) ->
@ -574,9 +592,15 @@ purge_node(NodeId, Owner) ->
GenKey = jlib:short_prepd_bare_jid(Owner), GenKey = jlib:short_prepd_bare_jid(Owner),
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} ->
{result, States} = get_states(NodeId),
lists:foreach(
fun(#pubsub_state{items = []}) ->
ok;
(#pubsub_state{items = Items} = S) ->
del_items(NodeId, Items), del_items(NodeId, Items),
set_state(GenState#pubsub_state{items = []}), set_state(S#pubsub_state{items = []})
end, States),
{result, {default, broadcast}}; {result, {default, broadcast}};
_ -> _ ->
%% Entity is not owner %% Entity is not owner

View File

@ -562,9 +562,12 @@ purge_node(NodeId, Owner) ->
GenKey = jlib:short_prepd_bare_jid(Owner), GenKey = jlib:short_prepd_bare_jid(Owner),
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

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2009-09-01 15:20:44.000000000 +0200 --- mod_pubsub.erl 2009-09-09 23:42:26.000000000 +0200
+++ mod_pubsub_odbc.erl 2009-09-01 15:22:27.000000000 +0200 +++ mod_pubsub_odbc.erl 2009-09-09 23:42:26.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)
@ -251,7 +251,7 @@
true -> true ->
% resource not concerned about that subscription % resource not concerned about that subscription
ok ok
@@ -809,10 +635,10 @@ @@ -810,10 +636,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}) ->
@ -264,7 +264,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 ->
@@ -930,11 +756,12 @@ @@ -931,11 +757,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,
@ -279,7 +279,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,
@@ -1037,7 +864,7 @@ @@ -1038,7 +865,7 @@
[] -> [] ->
["leaf"]; %% No sub-nodes: it's a leaf node ["leaf"]; %% No sub-nodes: it's a leaf node
_ -> _ ->
@ -288,7 +288,7 @@
{result, []} -> ["collection"]; {result, []} -> ["collection"];
{result, _} -> ["leaf", "collection"]; {result, _} -> ["leaf", "collection"];
_ -> [] _ -> []
@@ -1053,8 +880,9 @@ @@ -1054,8 +881,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)]} |
@ -300,7 +300,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)
@@ -1082,14 +910,15 @@ @@ -1083,14 +911,15 @@
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_DISCO_ITEMS_s)]}, #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_DISCO_ITEMS_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_PUBSUB_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)]}] ++
@ -319,7 +319,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),
@@ -1099,7 +928,7 @@ @@ -1100,7 +929,7 @@
?XMLATTR('node', SN), ?XMLATTR('node', SN),
?XMLATTR('name', RN)]} ?XMLATTR('name', RN)]}
end, tree_action(Host, get_subnodes, [Host, [], From]))}; end, tree_action(Host, get_subnodes, [Host, [], From]))};
@ -328,11 +328,13 @@
case string:tokens(Item, "!") of case string:tokens(Item, "!") of
[_SNode, _ItemID] -> [_SNode, _ItemID] ->
{result, []}; {result, []};
@@ -1111,9 +940,9 @@ @@ -1112,10 +941,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;
- _ -> [] - _ -> []
@ -340,7 +342,7 @@
end, end,
Nodes = lists:map( Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) -> fun(#pubsub_node{nodeid = {_, SubNode}}) ->
@@ -1129,7 +958,7 @@ @@ -1131,7 +960,7 @@
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('node', SN), #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('node', SN),
?XMLATTR('name', Name)]} ?XMLATTR('name', Name)]}
end, NodeItems), end, NodeItems),
@ -349,7 +351,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};
@@ -1268,7 +1097,8 @@ @@ -1270,7 +1099,8 @@
(_, Acc) -> (_, Acc) ->
Acc Acc
end, [], exmpp_xml:remove_cdata_from_list(Els)), end, [], exmpp_xml:remove_cdata_from_list(Els)),
@ -359,7 +361,7 @@
{get, 'subscriptions'} -> {get, 'subscriptions'} ->
get_subscriptions(Host, Node, From, Plugins); get_subscriptions(Host, Node, From, Plugins);
{get, 'affiliations'} -> {get, 'affiliations'} ->
@@ -1290,8 +1120,9 @@ @@ -1292,8 +1122,9 @@
end. end.
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) -> iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
@ -371,7 +373,7 @@
case Action of case Action of
[#xmlel{name = Name, attrs = Attrs, children = Els}] -> [#xmlel{name = Name, attrs = Attrs, children = Els}] ->
Node = case Host of Node = case Host of
@@ -1421,7 +1252,8 @@ @@ -1423,7 +1254,8 @@
_ -> [] _ -> []
end end
end, end,
@ -381,7 +383,7 @@
sync_dirty) of sync_dirty) of
{result, Res} -> Res; {result, Res} -> Res;
Err -> Err Err -> Err
@@ -1466,7 +1298,7 @@ @@ -1468,7 +1300,7 @@
%%% authorization handling %%% authorization handling
@ -390,7 +392,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 =
@@ -1496,7 +1328,7 @@ @@ -1498,7 +1330,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}
@ -399,7 +401,7 @@
find_authorization_response(Packet) -> find_authorization_response(Packet) ->
Els = Packet#xmlel.children, Els = Packet#xmlel.children,
@@ -1559,8 +1391,8 @@ @@ -1561,8 +1393,8 @@
"true" -> true; "true" -> true;
_ -> false _ -> false
end, end,
@ -410,7 +412,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 ->
@@ -1750,7 +1582,7 @@ @@ -1752,7 +1584,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)}]},
@ -419,7 +421,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)),
@@ -1859,7 +1691,7 @@ @@ -1861,7 +1693,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) ->
@ -428,7 +430,7 @@
Subscriber = try Subscriber = try
jlib:short_prepd_jid(exmpp_jid:parse(JID)) jlib:short_prepd_jid(exmpp_jid:parse(JID))
catch catch
@@ -1867,7 +1699,7 @@ @@ -1869,7 +1701,7 @@
{undefined, undefined, undefined} {undefined, undefined, undefined}
end, end,
SubId = uniqid(), SubId = uniqid(),
@ -437,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),
@@ -1886,9 +1718,13 @@ @@ -1888,9 +1720,13 @@
{"", "", ""} -> {"", "", ""} ->
{false, false}; {false, false};
_ -> _ ->
@ -454,7 +456,7 @@
end end
end, end,
if if
@@ -2213,7 +2049,7 @@ @@ -2215,7 +2051,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.
@ -463,7 +465,7 @@
MaxItems = MaxItems =
if if
SMaxItems == "" -> ?MAXITEMS; SMaxItems == "" -> ?MAXITEMS;
@@ -2252,11 +2088,11 @@ @@ -2254,11 +2090,11 @@
node_call(Type, get_items, node_call(Type, get_items,
[NodeId, From, [NodeId, From,
AccessModel, PresenceSubscription, RosterGroup, AccessModel, PresenceSubscription, RosterGroup,
@ -477,7 +479,7 @@
SendItems = case ItemIDs of SendItems = case ItemIDs of
[] -> [] ->
Items; Items;
@@ -2269,7 +2105,7 @@ @@ -2271,7 +2107,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 =
@ -486,7 +488,7 @@
Error -> Error ->
Error Error
end end
@@ -2301,16 +2137,25 @@ @@ -2303,16 +2139,25 @@
%% @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) ->
@ -519,7 +521,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, []} ->
@@ -2431,29 +2276,12 @@ @@ -2433,29 +2278,12 @@
error -> error ->
{error, 'bad-request'}; {error, 'bad-request'};
_ -> _ ->
@ -552,7 +554,7 @@
end, Entities), end, Entities),
{result, []}; {result, []};
_ -> _ ->
@@ -2508,11 +2336,11 @@ @@ -2510,11 +2338,11 @@
end. end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) -> read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -566,7 +568,7 @@
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options', OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
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)),
@@ -2546,7 +2374,7 @@ @@ -2548,7 +2376,7 @@
_ -> _ ->
{"", "", ""} %%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,
@ -575,7 +577,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) ->
@@ -2566,7 +2394,7 @@ @@ -2568,7 +2396,7 @@
end. end.
write_sub(Subscriber, NodeID, SubID, Options) -> write_sub(Subscriber, NodeID, SubID, Options) ->
@ -584,7 +586,7 @@
{error, notfound} -> {error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")}; {error, extended_error('not-acceptable', "invalid-subid")};
{result, _} -> {result, _} ->
@@ -2739,8 +2567,8 @@ @@ -2741,8 +2569,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,
@ -595,7 +597,7 @@
true -> true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3027,7 +2855,7 @@ @@ -3029,7 +2857,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,
@ -604,7 +606,7 @@
{result, CollSubs} -> CollSubs; {result, CollSubs} -> CollSubs;
_ -> [] _ -> []
end. end.
@@ -3041,9 +2869,9 @@ @@ -3043,9 +2871,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) ->
@ -616,7 +618,7 @@
_ -> Acc _ -> Acc
end; end;
(_, Acc) -> (_, Acc) ->
@@ -3238,6 +3066,30 @@ @@ -3240,6 +3068,30 @@
Result Result
end. end.
@ -647,7 +649,7 @@
%% @spec (Host, Options) -> MaxItems %% @spec (Host, Options) -> MaxItems
%% Host = host() %% Host = host()
%% Options = [Option] %% Options = [Option]
@@ -3614,7 +3466,13 @@ @@ -3616,7 +3468,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,
@ -662,7 +664,7 @@
%% @doc <p>node plugin call.</p> %% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) -> node_call(Type, Function, Args) ->
@@ -3634,13 +3492,13 @@ @@ -3636,13 +3494,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]),
@ -678,7 +680,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
@@ -3653,8 +3511,15 @@ @@ -3655,8 +3513,15 @@
end end
end, Trans). end, Trans).
@ -696,7 +698,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};
@@ -3662,6 +3527,15 @@ @@ -3664,6 +3529,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'};
@ -712,7 +714,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'};
@@ -3670,6 +3544,16 @@ @@ -3672,6 +3546,16 @@
{error, 'internal-server-error'} {error, 'internal-server-error'}
end. end.

View File

@ -38,8 +38,6 @@
read_subscription/3, read_subscription/3,
write_subscription/4]). write_subscription/4]).
-include_lib("stdlib/include/qlc.hrl").
-include("pubsub.hrl"). -include("pubsub.hrl").
-include_lib("exmpp/include/exmpp.hrl"). -include_lib("exmpp/include/exmpp.hrl").
@ -94,6 +92,7 @@ init() ->
subscribe_node(JID, NodeID, Options) -> subscribe_node(JID, NodeID, Options) ->
try mnesia:sync_dirty(fun add_subscription/3, try mnesia:sync_dirty(fun add_subscription/3,
[JID, NodeID, Options]) of [JID, NodeID, Options]) of
{error, Error} -> {error, Error};
Result -> {result, Result} Result -> {result, Result}
catch catch
Error -> Error Error -> Error
@ -102,6 +101,7 @@ subscribe_node(JID, NodeID, Options) ->
unsubscribe_node(JID, NodeID, SubID) -> unsubscribe_node(JID, NodeID, SubID) ->
try mnesia:sync_dirty(fun delete_subscription/3, try mnesia:sync_dirty(fun delete_subscription/3,
[JID, NodeID, SubID]) of [JID, NodeID, SubID]) of
{error, Error} -> {error, Error};
Result -> {result, Result} Result -> {result, Result}
catch catch
Error -> Error Error -> Error
@ -110,6 +110,7 @@ unsubscribe_node(JID, NodeID, SubID) ->
get_subscription(JID, NodeID, SubID) -> get_subscription(JID, NodeID, SubID) ->
try mnesia:sync_dirty(fun read_subscription/3, try mnesia:sync_dirty(fun read_subscription/3,
[JID, NodeID, SubID]) of [JID, NodeID, SubID]) of
{error, Error} -> {error, Error};
Result -> {result, Result} Result -> {result, Result}
catch catch
Error -> Error Error -> Error
@ -118,6 +119,7 @@ get_subscription(JID, NodeID, SubID) ->
set_subscription(JID, NodeID, SubID, Options) -> set_subscription(JID, NodeID, SubID, Options) ->
try mnesia:sync_dirty(fun write_subscription/4, try mnesia:sync_dirty(fun write_subscription/4,
[JID, NodeID, SubID, Options]) of [JID, NodeID, SubID, Options]) of
{error, Error} -> {error, Error};
Result -> {result, Result} Result -> {result, Result}
catch catch
Error -> Error Error -> Error
@ -167,26 +169,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]),
case qlc:e(Q) of
[Sub] -> Sub; [Sub] -> Sub;
[] -> mnesia:abort({error, notfound}) _ -> {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(),