]> granicus.if.org Git - ejabberd/commitdiff
Fix set-subscriptions to work with multi-subscribe (EJAB-977)
authorChristophe Romain <christophe.romain@process-one.net>
Fri, 17 Jul 2009 09:29:11 +0000 (09:29 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Fri, 17 Jul 2009 09:29:11 +0000 (09:29 +0000)
SVN Revision: 2364

13 files changed:
src/mod_pubsub/gen_pubsub_node.erl
src/mod_pubsub/mod_pubsub.erl
src/mod_pubsub/node.template
src/mod_pubsub/node_buddy.erl
src/mod_pubsub/node_club.erl
src/mod_pubsub/node_dag.erl
src/mod_pubsub/node_dispatch.erl
src/mod_pubsub/node_flat.erl
src/mod_pubsub/node_hometree.erl
src/mod_pubsub/node_mb.erl
src/mod_pubsub/node_pep.erl
src/mod_pubsub/node_private.erl
src/mod_pubsub/node_public.erl

index ba0d7386a2d185c69665a45a33fbfc80f1a899f3..dbf7e25d59699d12cfefe2035910bc8bf178fab4 100644 (file)
@@ -58,7 +58,7 @@ behaviour_info(callbacks) ->
      {get_node_subscriptions, 1},
      {get_entity_subscriptions, 2},
      {get_subscriptions, 2},
-     {set_subscriptions, 3},
+     {set_subscriptions, 4},
      {get_states, 1},
      {get_state, 2},
      {set_state, 1},
index 6ddfc945d3551e2214794ae86c9c4f2560cbc26c..a1ec03e62163ff8bf98a0e18bec2d4207f265800 100644 (file)
@@ -2522,12 +2522,13 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
                                          xml:get_attr_s("jid", Attrs)),
                                  Subscription = string_to_subscription(
                                                   xml:get_attr_s("subscription", Attrs)),
+                                  SubId = xml:get_attr_s("subid", Attrs),
                                  if
                                      (JID == error) or
                                      (Subscription == false) ->
                                          error;
                                      true ->
-                                         [{jlib:jid_tolower(JID), Subscription} | Acc]
+                                         [{jlib:jid_tolower(JID), Subscription, SubId} | Acc]
                                  end
                          end
                  end
@@ -2539,10 +2540,10 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
            Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}) ->
                             case lists:member(Owner, Owners) of
                                 true ->
-                                    lists:foreach(fun({JID, Subscription}) ->
-                                                          node_call(Type, set_subscriptions, [NodeId, JID, Subscription])
-                                                  end, Entities),
-                                    {result, []};
+                                     lists:foreach(fun({JID, Subscription, SubId}) ->
+                                                           node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId])
+                                                   end, Entities),
+                                     {result, []};
                                 _ ->
                                     {error, ?ERR_FORBIDDEN}
                             end
@@ -2553,7 +2554,6 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
            end
     end.
 
-
 %% @spec (OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, SubscriberResource}, AllowedGroups)
 %%    -> {PresenceSubscription, RosterGroup}
 get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, AllowedGroups) ->
index 534c182262eb22b976ebd6e92caa247788fb7920..08f2e08ed100b913929c8e9c77b5f9b44e6ed605 100644 (file)
@@ -57,7 +57,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -157,8 +157,8 @@ get_node_subscriptions(NodeId) ->
 get_subscriptions(NodeId, Owner) ->
     node_hometree:get_subscriptions(NodeId, Owner).
 
-set_subscriptions(NodeId, Owner, Subscriptions) ->
-    node_hometree:set_subscriptions(NodeId, Owner, Subscriptions).
+set_subscriptions(NodeId, Owner, Subscription, SubId) ->
+    node_hometree:set_subscriptions(NodeId, Owner, Subscription, SubId).
 
 get_states(NodeId) ->
     node_hometree:get_states(NodeId).
index 2e8dd024955daaae47b0c37f19d15cfaf863b1a9..b3aea6f4a9c3e6cd1a20e54f9c917f2fec0424c0 100644 (file)
@@ -58,7 +58,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -159,8 +159,8 @@ get_node_subscriptions(NodeId) ->
 get_subscriptions(NodeId, Owner) ->
     node_hometree:get_subscriptions(NodeId, Owner).
 
-set_subscriptions(NodeId, Owner, Subscriptions) ->
-    node_hometree:set_subscriptions(NodeId, Owner, Subscriptions).
+set_subscriptions(NodeId, Owner, Subscription, SubId) ->
+    node_hometree:set_subscriptions(NodeId, Owner, Subscription, SubId).
 
 get_states(NodeId) ->
     node_hometree:get_states(NodeId).
index 91ff520c62b21e0a7c32b37864e16d18d87c3dc5..e3c16c630be117eb4df08cab344827b2ca8ef62e 100644 (file)
@@ -58,7 +58,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -158,8 +158,8 @@ get_node_subscriptions(NodeId) ->
 get_subscriptions(NodeId, Owner) ->
     node_hometree:get_subscriptions(NodeId, Owner).
 
-set_subscriptions(NodeId, Owner, Subscription) ->
-    node_hometree:set_subscriptions(NodeId, Owner, Subscription).
+set_subscriptions(NodeId, Owner, Subscription, SubId) ->
+    node_hometree:set_subscriptions(NodeId, Owner, Subscription, SubId).
 
 get_states(NodeId) ->
     node_hometree:get_states(NodeId).
index a276f08f0a702c3d30c4e86be920701a5117ba39..2ffb70df2e0e900c5c080dc1ac382980dfcb9e7f 100644 (file)
@@ -42,7 +42,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -136,8 +136,8 @@ get_node_subscriptions(NodeID) ->
 get_subscriptions(NodeID, Owner) ->
     node_hometree:get_subscriptions(NodeID, Owner).
 
-set_subscriptions(NodeID, Owner, Subscriptions) ->
-    node_hometree:set_subscriptions(NodeID, Owner, Subscriptions).
+set_subscriptions(NodeID, Owner, Subscription, SubID) ->
+    node_hometree:set_subscriptions(NodeID, Owner, Subscription, SubID).
 
 get_states(NodeID) ->
     node_hometree:get_states(NodeID).
index f67ab81fa8dbf914a90d7a990937333d14c95b17..698d2559acf43f469c87caf34056677b061c9a85 100644 (file)
@@ -56,7 +56,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -162,8 +162,8 @@ get_node_subscriptions(NodeId) ->
 get_subscriptions(_NodeId, _Owner) ->
     {result, []}.
 
-set_subscriptions(NodeId, Owner, Subscription) ->
-    node_hometree:set_subscriptions(NodeId, Owner, Subscription).
+set_subscriptions(NodeId, Owner, Subscription, SubId) ->
+    node_hometree:set_subscriptions(NodeId, Owner, Subscription, SubId).
 
 get_states(NodeId) ->
     node_hometree:get_states(NodeId).
index a4fbb3b6761086fbd38b1e068cf53ce50c4eff6b..4a89abdc6577418043ed50be160e7c082943361d 100644 (file)
@@ -49,7 +49,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -145,8 +145,8 @@ get_node_subscriptions(NodeId) ->
 get_subscriptions(NodeId, Owner) ->
     node_hometree:get_subscriptions(NodeId, Owner).
 
-set_subscriptions(NodeId, Owner, Subscription) ->
-    node_hometree:set_subscriptions(NodeId, Owner, Subscription).
+set_subscriptions(NodeId, Owner, Subscription, SubId) ->
+    node_hometree:set_subscriptions(NodeId, Owner, Subscription, SubId).
 
 get_states(NodeId) ->
     node_hometree:get_states(NodeId).
index 764b511d4cc174491ab76788985f3bedb5516d27..cdad0699f912264a69208580b1b9a697214a88e2 100644 (file)
@@ -65,7 +65,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -691,23 +691,30 @@ get_subscriptions(NodeId, Owner) ->
     SubState = get_state(NodeId, SubKey),
     {result, SubState#pubsub_state.subscriptions}.
 
-set_subscriptions(NodeId, Owner, Subscriptions) ->
+set_subscriptions(NodeId, Owner, none, SubId) ->
     SubKey = jlib:jid_tolower(Owner),
     SubState = get_state(NodeId, SubKey),
+    case {SubId, SubState#pubsub_state.subscriptions} of
+        {_, []} ->
+            {error, ?ERR_ITEM_NOT_FOUND};
+        {"", [{_, SID}]} ->
+            unsub_with_subid(NodeId, SID, SubState);
+        {"", [_|_]} ->
+            {error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "subid-required")};
+        _ ->
+            unsub_with_subid(NodeId, SubId, SubState)
+    end.
 
-    OSIDs = [SID || {_, SID} <- SubState#pubsub_state.subscriptions],
-    NSIDs = [SID || {_, SID} <- Subscriptions],
-    RSIDs = OSIDs -- NSIDs,
-
-    lists:foreach(fun(SubID) ->
-                         pubsub_subscription:unsubscribe_node(SubKey, NodeId,
-                                                              SubID)
-                 end, RSIDs),
-    case {Subscriptions, SubState#pubsub_state.affiliation} of
+unsub_with_subid(NodeId, SubId, SubState) ->
+    pubsub_subscription:unsubscribe_node(SubState#pubsub_state.stateid,
+                                         NodeId, SubId),
+    NewSubs = lists:filter(fun ({_, SID}) -> SubId =/= SID end,
+                           SubState#pubsub_state.subscriptions),
+    case {NewSubs, SubState#pubsub_state.affiliation} of
        {[], none} ->
-           del_state(NodeId, SubKey);
+           del_state(NodeId, element(1, SubState#pubsub_state.stateid));
        _ ->
-           set_state(SubState#pubsub_state{subscriptions = Subscriptions})
+           set_state(SubState#pubsub_state{subscriptions = NewSubs})
     end.
 
 %% @spec (NodeId) -> [States] | []
index 70ceabbb164ccb164e098856e6a3db565568e4f8..b7ac76238cce8cb9b7489769d47909cdafdca4d3 100644 (file)
@@ -61,7 +61,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -166,8 +166,8 @@ get_node_subscriptions(NodeId) ->
 get_subscriptions(NodeId, Owner) ->
     node_pep:get_subscriptions(NodeId, Owner).
 
-set_subscriptions(NodeId, Owner, Subscription) ->
-    node_pep:set_subscriptions(NodeId, Owner, Subscription).
+set_subscriptions(NodeId, Owner, Subscription, SubId) ->
+    node_pep:set_subscriptions(NodeId, Owner, Subscription, SubId).
 
 get_states(NodeId) ->
     node_pep:get_states(NodeId).
index 8e2e7e0a3fa5eb077e90dd8d70323120a91ac6df..57e30fecbcf6a94e279a5488fc61912ad525853b 100644 (file)
@@ -54,7 +54,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -233,8 +233,8 @@ get_node_subscriptions(NodeId) ->
 get_subscriptions(NodeId, Owner) ->
     node_hometree:get_subscriptions(NodeId, Owner).
 
-set_subscriptions(NodeId, Owner, Subscription) ->
-    node_hometree:set_subscriptions(NodeId, Owner, Subscription).
+set_subscriptions(NodeId, Owner, Subscription, SubId) ->
+    node_hometree:set_subscriptions(NodeId, Owner, Subscription, SubId).
 
 get_states(NodeId) ->
     node_hometree:get_states(NodeId).
index e9c925403223f2f18df4462fe33318800c6ba499..f4d4c8deaacaa304d013254695f391b52838be30 100644 (file)
@@ -58,7 +58,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -162,8 +162,8 @@ get_node_subscriptions(NodeId) ->
 get_subscriptions(NodeId, Owner) ->
     node_hometree:get_subscriptions(NodeId, Owner).
 
-set_subscriptions(NodeId, Owner, Subscription) ->
-    node_hometree:set_subscriptions(NodeId, Owner, Subscription).
+set_subscriptions(NodeId, Owner, Subscription, SubId) ->
+    node_hometree:set_subscriptions(NodeId, Owner, Subscription, SubId).
 
 get_states(NodeId) ->
     node_hometree:get_states(NodeId).
index ae7beff84d974caa83badb2ffc3f06121d6e9ee6..fa806b7120a331bdece1c8dcbfd9de660551256a 100644 (file)
@@ -58,7 +58,7 @@
         get_entity_subscriptions/2,
         get_node_subscriptions/1,
         get_subscriptions/2,
-        set_subscriptions/3,
+        set_subscriptions/4,
         get_states/1,
         get_state/2,
         set_state/1,
@@ -158,8 +158,8 @@ get_node_subscriptions(NodeId) ->
 get_subscriptions(NodeId, Owner) ->
     node_hometree:get_subscriptions(NodeId, Owner).
 
-set_subscriptions(NodeId, Owner, Subscription) ->
-    node_hometree:set_subscriptions(NodeId, Owner, Subscription).
+set_subscriptions(NodeId, Owner, Subscription, SubId) ->
+    node_hometree:set_subscriptions(NodeId, Owner, Subscription, SubId).
 
 get_states(NodeId) ->
     node_hometree:get_states(NodeId).