]> granicus.if.org Git - ejabberd/commitdiff
port commit from r2527 to odbc plugin
authorChristophe Romain <christophe.romain@process-one.net>
Thu, 27 Aug 2009 08:17:44 +0000 (08:17 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Thu, 27 Aug 2009 08:17:44 +0000 (08:17 +0000)
SVN Revision: 2543

src/mod_pubsub/node_hometree.erl
src/mod_pubsub/node_hometree_odbc.erl

index cb7373677cf8d44460e5e04cf35c8c5407587947..5bb9be056e27883669e7ae7c166b84c37a9c1223 100644 (file)
@@ -702,7 +702,7 @@ set_subscriptions(NodeId, Owner, Subscription, SubId) ->
     case {SubId, SubState#pubsub_state.subscriptions} of
        {_, []} ->
            case Subscription of
-               none -> ok;
+               none -> {error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "not-subscribed")};
                _ -> new_subscription(NodeId, Owner, Subscription, SubState)
            end;
        {"", [{_, SID}]} ->
index d4ffeca92934839389dc0fa2c7944ec7e1d20687..a9a815f573d53fd5136d0b2f6300d0dde604eb3e 100644 (file)
@@ -740,7 +740,10 @@ set_subscriptions(NodeId, Owner, Subscription, SubId) ->
     SubState = get_state_without_itemids(NodeId, SubKey),
     case {SubId, SubState#pubsub_state.subscriptions} of
        {_, []} ->
-           {error, ?ERR_ITEM_NOT_FOUND};
+           case Subscription of
+               none -> {error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "not-subscribed")};
+               _ -> new_subscription(NodeId, Owner, Subscription, SubState)
+           end;
        {"", [{_, SID}]} ->
            case Subscription of
                none -> unsub_with_subid(NodeId, SID, SubState);
@@ -765,6 +768,16 @@ replace_subscription(_, [], Acc) ->
 replace_subscription({Sub, SubId}, [{_, SubID} | T], Acc) ->
     replace_subscription({Sub, SubId}, T, [{Sub, SubID} | Acc]).
 
+new_subscription(NodeId, Owner, Subscription, SubState) ->
+    case pubsub_subscription_odbc:subscribe_node(Owner, NodeId, []) of
+       {result, SubId} ->
+           Subscriptions = SubState#pubsub_state.subscriptions,
+           set_state(SubState#pubsub_state{subscriptions = [{Subscription, SubId} | Subscriptions]}),
+           {Subscription, SubId};
+       _ ->
+           {error, ?ERR_INTERNAL_SERVER_ERROR}
+    end.
+
 unsub_with_subid(NodeId, SubId, SubState) ->
     pubsub_subscription_odbc:unsubscribe_node(SubState#pubsub_state.stateid,
                                         NodeId, SubId),