From 553b402d034b14df6b5db8bb131d695a3fad46d8 Mon Sep 17 00:00:00 2001
From: Christophe Romain In the default plugin module, the record is unchanged. Unsubscribe the Subscriber from the Node.
In the default plugin module, the record is unchanged.
publish_item(Host, Node, Publisher, PublishModel, MaxItems, ItemId, Payload) -> - PublisherKey = jlib:jid_tolower(jlib:jid_remove_resource(Publisher)), - State = get_state(Host, Node, PublisherKey), - #pubsub_state{affiliation = Affiliation, - subscription = Subscription} = State, + SubKey = jlib:jid_tolower(Publisher), + GenKey = jlib:jid_remove_resource(SubKey), + GenState = get_state(Host, Node, GenKey), + SubState = case SubKey of + GenKey -> GenState; + _ -> get_state(Host, Node, SubKey) + end, + Affiliation = GenState#pubsub_state.affiliation, + Subscription = SubState#pubsub_state.subscription, if not ((PublishModel == open) or ((PublishModel == publishers) @@ -417,24 +434,24 @@ publish_item(Host, Node, Publisher, PublishModel, MaxItems, ItemId, Payload) -> %% Entity does not have sufficient privileges to publish to node {error, ?ERR_FORBIDDEN}; true -> - PubId = {PublisherKey, now()}, + PubId = {SubKey, now()}, Item = case get_item(Host, Node, ItemId) of {result, OldItem} -> OldItem#pubsub_item{modification = PubId, payload = Payload}; _ -> #pubsub_item{itemid = {ItemId, {Host, Node}}, - creation = PubId, + creation = {GenKey, now()}, modification = PubId, payload = Payload} end, - Items = [ItemId | State#pubsub_state.items--[ItemId]], + Items = [ItemId | GenState#pubsub_state.items--[ItemId]], {result, {NI, OI}} = remove_extra_items( Host, Node, MaxItems, Items), if MaxItems > 0 -> set_item(Item); true -> ok end, - set_state(State#pubsub_state{items = NI}), + set_state(GenState#pubsub_state{items = NI}), {result, {default, broadcast, OI}} end. @@ -475,12 +492,13 @@ remove_extra_items(Host, Node, MaxItems, ItemIds) -> %%Default plugin: The user performing the deletion must be the node owner %% or a publisher.
delete_item(Host, Node, Publisher, ItemId) -> - PublisherKey = jlib:jid_tolower(jlib:jid_remove_resource(Publisher)), - State = get_state(Host, Node, PublisherKey), - #pubsub_state{affiliation = Affiliation, items = Items} = State, + SubKey = jlib:jid_tolower(Publisher), + GenKey = jlib:jid_remove_resource(SubKey), + GenState = get_state(Host, Node, GenKey), + #pubsub_state{affiliation = Affiliation, items = Items} = GenState, Allowed = (Affiliation == publisher) orelse (Affiliation == owner) orelse case get_item(Host, Node, ItemId) of - {result, #pubsub_item{creation = {PublisherKey, _}}} -> true; + {result, #pubsub_item{creation = {GenKey, _}}} -> true; _ -> false end, if @@ -492,7 +510,7 @@ delete_item(Host, Node, Publisher, ItemId) -> {result, _} -> del_item(Host, Node, ItemId), NewItems = lists:delete(ItemId, Items), - set_state(State#pubsub_state{items = NewItems}), + set_state(GenState#pubsub_state{items = NewItems}), {result, {default, broadcast}}; _ -> %% Non-existent node or item @@ -509,8 +527,10 @@ delete_item(Host, Node, Publisher, ItemId) -> %% @docPurge all node items.
%%Default plugin: The user performing the deletion must be the node owner.
purge_node(Host, Node, Owner) -> - OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), - case get_state(Host, Node, OwnerKey) of + SubKey = jlib:jid_tolower(Owner), + GenKey = jlib:jid_remove_resource(SubKey), + GenState = get_state(Host, Node, GenKey), + case GenState of #pubsub_state{items = Items, affiliation = owner} -> del_items(Host, Node, Items), {result, {default, broadcast}}; @@ -530,9 +550,10 @@ purge_node(Host, Node, Owner) -> %% that will be added to the affiliation stored in the main %% pubsub_state table. get_entity_affiliations(Host, Owner) -> - OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), + SubKey = jlib:jid_tolower(Owner), + GenKey = jlib:jid_remove_resource(SubKey), States = mnesia:match_object( - #pubsub_state{stateid = {OwnerKey, {Host, '_'}}, _ = '_'}), + #pubsub_state{stateid = {GenKey, {Host, '_'}}, _ = '_'}), Tr = fun(#pubsub_state{stateid = {_, {_, N}}, affiliation = A}) -> {N, A} end, @@ -547,14 +568,16 @@ get_node_affiliations(Host, Node) -> {result, lists:map(Tr, States)}. get_affiliation(Host, Node, Owner) -> - OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), - State = get_state(Host, Node, OwnerKey), - {result, State#pubsub_state.affiliation}. + SubKey = jlib:jid_tolower(Owner), + GenKey = jlib:jid_remove_resource(SubKey), + GenState = get_state(Host, Node, GenKey), + {result, GenState#pubsub_state.affiliation}. set_affiliation(Host, Node, Owner, Affiliation) -> - OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), - State = get_state(Host, Node, OwnerKey), - set_state(State#pubsub_state{affiliation = Affiliation}), + SubKey = jlib:jid_tolower(Owner), + GenKey = jlib:jid_remove_resource(SubKey), + GenState = get_state(Host, Node, GenKey), + set_state(GenState#pubsub_state{affiliation = Affiliation}), ok. %% @spec (Host, Ownner) -> [{Node,Subscription}] @@ -568,11 +591,16 @@ set_affiliation(Host, Node, Owner, Affiliation) -> %% that will be added to the affiliation stored in the main %% pubsub_state table. get_entity_subscriptions(Host, Owner) -> - OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), - States = mnesia:match_object( - #pubsub_state{stateid = {OwnerKey, {Host, '_'}}, _ = '_'}), - Tr = fun(#pubsub_state{stateid = {_, {_, N}}, subscription = S}) -> - {N, S} + States = case jlib:jid_tolower(Owner) of + {U, D, ""} -> mnesia:match_object( + #pubsub_state{stateid = {{U, D, '_'}, {Host, '_'}}, _ = '_'}); + {U, D, R} -> mnesia:match_object( + #pubsub_state{stateid = {{U, D, ""}, {Host, '_'}}, _ = '_'}) + ++ mnesia:match_object( + #pubsub_state{stateid = {{U, D, R}, {Host, '_'}}, _ = '_'}) + end, + Tr = fun(#pubsub_state{stateid = {J, {_, N}}, subscription = S}) -> + {N, S, J} end, {result, lists:map(Tr, States)}. @@ -585,14 +613,14 @@ get_node_subscriptions(Host, Node) -> {result, lists:map(Tr, States)}. get_subscription(Host, Node, Owner) -> - OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), - State = get_state(Host, Node, OwnerKey), - {result, State#pubsub_state.subscription}. + SubKey = jlib:jid_tolower(Owner), + SubState = get_state(Host, Node, SubKey), + {result, SubState#pubsub_state.subscription}. set_subscription(Host, Node, Owner, Subscription) -> - OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), - State = get_state(Host, Node, OwnerKey), - set_state(State#pubsub_state{subscription = Subscription}), + SubKey = jlib:jid_tolower(Owner), + SubState = get_state(Host, Node, SubKey), + set_state(SubState#pubsub_state{subscription = Subscription}), ok. %% @spec (Host, Node) -> [States] | [] @@ -660,10 +688,10 @@ get_items(Host, Node) -> #pubsub_item{itemid = {'_', {Host, Node}}, _ = '_'}), {result, Items}. get_items(Host, Node, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId) -> - State = get_state(Host, Node, jlib:jid_tolower(jlib:jid_remove_resource(JID))), - #pubsub_state{affiliation = Affiliation, - subscription = Subscription} = State, - Subscribed = not ((Subscription == none) or (Subscription == pending)), + SubKey = jlib:jid_tolower(JID), + GenKey = jlib:jid_remove_resource(SubKey), + GenState = get_state(Host, Node, GenKey), + Affiliation = GenState#pubsub_state.affiliation, if %%SubID == "", ?? -> %% Entity has multiple subscriptions to the node but does not specify a subscription ID @@ -674,9 +702,6 @@ get_items(Host, Node, JID, AccessModel, PresenceSubscription, RosterGroup, _SubI Affiliation == outcast -> %% Requesting entity is blocked {error, ?ERR_FORBIDDEN}; - (AccessModel == open) and (not Subscribed) -> - %% Entity is not subscribed - {error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "not-subscribed")}; (AccessModel == presence) and (not PresenceSubscription) -> %% Entity is not authorized to create a subscription (presence subscription required) {error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "presence-subscription-required")}; @@ -710,10 +735,10 @@ get_item(Host, Node, ItemId) -> {error, ?ERR_ITEM_NOT_FOUND} end. get_item(Host, Node, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId) -> - State = get_state(Host, Node, jlib:jid_tolower(jlib:jid_remove_resource(JID))), - #pubsub_state{affiliation = Affiliation, - subscription = Subscription} = State, - Subscribed = not ((Subscription == none) or (Subscription == pending)), + SubKey = jlib:jid_tolower(JID), + GenKey = jlib:jid_remove_resource(SubKey), + GenState = get_state(Host, Node, GenKey), + Affiliation = GenState#pubsub_state.affiliation, if %%SubID == "", ?? -> %% Entity has multiple subscriptions to the node but does not specify a subscription ID @@ -724,9 +749,6 @@ get_item(Host, Node, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup Affiliation == outcast -> %% Requesting entity is blocked {error, ?ERR_FORBIDDEN}; - (AccessModel == open) and (not Subscribed) -> - %% Entity is not subscribed - {error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "not-subscribed")}; (AccessModel == presence) and (not PresenceSubscription) -> %% Entity is not authorized to create a subscription (presence subscription required) {error, ?ERR_EXTENDED(?ERR_NOT_AUTHORIZED, "presence-subscription-required")};