]> granicus.if.org Git - ejabberd/commitdiff
fix create_node and subscribe_node glitches from last merge
authorChristophe Romain <christophe.romain@process-one.net>
Mon, 17 Aug 2009 20:25:31 +0000 (20:25 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Mon, 17 Aug 2009 20:25:31 +0000 (20:25 +0000)
SVN Revision: 2496

src/mod_pubsub/mod_pubsub.erl
src/mod_pubsub/mod_pubsub_odbc.erl
src/mod_pubsub/node_hometree.erl
src/mod_pubsub/nodetree_tree.erl
src/mod_pubsub/nodetree_tree_odbc.erl
src/mod_pubsub/pubsub_subscription.erl
src/mod_pubsub/pubsub_subscription_odbc.erl

index 2f606d4df9ec5a75ae4dc6a37e231b47d881cb2b..fe0149decc3b759de1c2ab7cca00c0cbb901b439 100644 (file)
@@ -264,8 +264,8 @@ terminate_plugins(Host, ServerHost, Plugins, TreePlugin) ->
     ok.
 
 init_nodes(Host, ServerHost) ->
-    %create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree"),
-    %create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree"),
+    create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree"),
+    create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree"),
     ok.
 
 update_node_database(Host, ServerHost) ->
index bab0e3734f14a7ee8473f3c4bb83f06b54e03609..d6a95ae06ff9fdc22b3785b1547f31f2ad61900a 100644 (file)
@@ -263,8 +263,8 @@ terminate_plugins(Host, ServerHost, Plugins, TreePlugin) ->
     ok.
 
 init_nodes(Host, ServerHost) ->
-    %create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree_odbc"),
-    %create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree_odbc"),
+    create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree_odbc"),
+    create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree_odbc"),
     ok.
 
 update_node_database(Host, ServerHost) ->
index 011ea428a7efc5e31c887b6564e92a0c589c3701..6484fbe0aa68acfd064bb11a357a40d812e1e563 100644 (file)
@@ -321,8 +321,8 @@ subscribe_node(NodeId, Sender, Subscriber, AccessModel,
        %%      % Requesting entity is anonymous
        %%      {error, ?ERR_FORBIDDEN};
        true ->
-           case pubsub_subscription:subscribe_node(Subscriber, NodeId, Options) of
-               {result, SubId} ->
+           case pubsub_subscription:add_subscription(Subscriber, NodeId, Options) of
+               SubId when is_list(SubId) ->
                    NewSub = case AccessModel of
                                 authorize -> pending;
                                 _ -> subscribed
@@ -409,7 +409,7 @@ delete_subscription(SubKey, NodeID, {Subscription, SubId}, SubState) ->
     Affiliation = SubState#pubsub_state.affiliation,
     AllSubs = SubState#pubsub_state.subscriptions,
     NewSubs = AllSubs -- [{Subscription, SubId}],
-    pubsub_subscription:unsubscribe_node(SubKey, NodeID, SubId),
+    pubsub_subscription:delete_subscription(SubKey, NodeID, SubId),
     case {Affiliation, NewSubs} of
        {none, []} ->
            % Just a regular subscriber, and this is final item, so
@@ -727,7 +727,7 @@ replace_subscription({Sub, SubId}, [{_, SubID} | T], Acc) ->
     replace_subscription({Sub, SubId}, T, [{Sub, SubID} | Acc]).
 
 unsub_with_subid(NodeId, SubId, SubState) ->
-    pubsub_subscription:unsubscribe_node(SubState#pubsub_state.stateid,
+    pubsub_subscription:delete_subscription(SubState#pubsub_state.stateid,
                                         NodeId, SubId),
     NewSubs = lists:filter(fun ({_, SID}) -> SubId =/= SID end,
                           SubState#pubsub_state.subscriptions),
index 39724db46424ed155a9a78cb7531dc2ed32883b0..99b4b88911607592471340ddc6c59c1bdcd8c4da 100644 (file)
@@ -161,6 +161,12 @@ get_parentnodes_tree(Host, Node, From) ->
 get_subnodes(Host, Node, _From) ->
     get_subnodes(Host, Node).
 get_subnodes(Host, Node) ->
+%    mnesia:foldl(fun(#pubsub_node{nodeid = {H, _}, parents = Parents} = N, Acc) ->
+%                      case lists:member(Node, Parents) and (Host == H) of
+%                          true -> [N | Acc];
+%                          false -> Acc
+%                      end
+%               end, [], pubsub_node).
     Q = qlc:q([N || #pubsub_node{nodeid = {NHost, _},
                                 parents = Parents} = N <- mnesia:table(pubsub_node),
                       Host == NHost,
@@ -176,10 +182,10 @@ get_subnodes_tree(Host, Node, _From) ->
 %%     From = mod_pubsub:jid()
 get_subnodes_tree(Host, Node) ->
     mnesia:foldl(fun(#pubsub_node{nodeid = {H, N}} = R, Acc) ->
-                        case lists:prefix(Node, N) and (H == Host) of
-                            true -> [R | Acc];
-                            _ -> Acc
-                        end
+                       case lists:prefix(Node, N) and (H == Host) of
+                           true -> [R | Acc];
+                           false -> Acc
+                       end
                 end, [], pubsub_node).
 
 %% @spec (Host, Node, Type, Owner, Options) -> ok | {error, Reason}
@@ -190,7 +196,7 @@ get_subnodes_tree(Host, Node) ->
 %%     Options = list()
 create_node(Host, Node, Type, Owner, Options) ->
     BJID = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
-    case mnesia:read({pubsub_node, {Host, Node}}) of
+    case catch mnesia:read({pubsub_node, {Host, Node}}) of
        [] ->
            {ParentNode, ParentExists} =
                case Host of
@@ -199,14 +205,14 @@ create_node(Host, Node, Type, Owner, Options) ->
                        %% PEP does not uses hierarchy
                        {[], true};
                    _ ->
-                       Parent = lists:sublist(Node, length(Node) - 1),
-                       case Parent of
+                       case lists:sublist(Node, length(Node) - 1) of
                        [] -> 
                            {[], true};
-                       _ ->
-                           case mnesia:read({pubsub_node, {Host, Parent}}) of
-                               [] -> {Parent, false};
-                               _ -> {Parent, lists:member(BJID, Parent#pubsub_node.owners)}
+                       Parent ->
+                           case catch mnesia:read({pubsub_node, {Host, Parent}}) of
+                               [#pubsub_node{owners = [{[], Host, []}]}] -> {Parent, true};
+                               [#pubsub_node{owners = Owners}] -> {Parent, lists:member(BJID, Owners)};
+                               _ -> {Parent, false}
                            end
                        end
                end,
index 95f9b34ef3d3ff621f2c404cfab446d60e0026c9..6468913d18c2bb667624a7dec1bba08ca6f7ec13 100644 (file)
@@ -220,13 +220,15 @@ create_node(Host, Node, Type, _Owner, Options) ->
                    %% PEP does not uses hierarchy
                    {[], true};
                _ ->
-                   Parent = lists:sublist(Node, length(Node) - 1),
-                   ParentE = (Parent == []) orelse 
+                   case lists:sublist(Node, length(Node) - 1) of
+                   [] ->
+                       {[], true};
+                   Parent ->
                        case nodeid(Host, Parent) of
-                           {result, _} -> true;
-                           _ -> false
-                       end,
-                   {Parent, ParentE}
+                           {result, _} -> {Parent, true};
+                           _ -> {Parent, false}
+                       end
+                   end
                end,
            case ParentExists of
                true -> 
index 754a9d8f850aa34f0e0d58da8d1b348483a910c2..5f3038d35d38f651e9bb4fe3dce37c15bf7e89f6 100644 (file)
         get_options_xform/2,
         parse_options_xform/1]).
 
+% Internal function also exported for use in transactional bloc from pubsub plugins
+-export([add_subscription/3,
+        delete_subscription/3,
+        read_subscription/3,
+        write_subscription/4]).
+
 -include_lib("stdlib/include/qlc.hrl").
 
 -include("pubsub.hrl").
index 56ddf6d4bf95c58bd52d648e466036ffc2d31718..98e62abaa6274c679311501ce7c21b56236065fc 100644 (file)
@@ -22,7 +22,7 @@
 %%% ====================================================================
 
 -module(pubsub_subscription_odbc).
--author("bjc@kublai.com").
+-author("pablo.polvorin@process-one.net").
 
 %% API
 -export([init/0,
@@ -33,8 +33,6 @@
         get_options_xform/2,
         parse_options_xform/1]).
 
--include_lib("stdlib/include/qlc.hrl").
-
 -include("pubsub.hrl").
 -include("jlib.hrl").
 
@@ -90,10 +88,9 @@ init() ->
 
 subscribe_node(_JID, _NodeID, Options) ->
     SubId = make_subid(),
-    ok =  pubsub_db_odbc:add_subscription(#pubsub_subscription{subid = SubId,
-                                                             options = Options}),
+    ok = ?DB_MOD:add_subscription(#pubsub_subscription{subid = SubId, options = Options}),
     {result, SubId}.
-       
+
 
 unsubscribe_node(_JID, _NodeID, SubID) ->
     {ok, Sub} = ?DB_MOD:read_subscription(SubID),
@@ -105,7 +102,7 @@ get_subscription(_JID, _NodeID, SubID) ->
        {ok, Sub} -> {result, Sub};
        notfound -> {error, notfound}
     end.
-       
+
 
 set_subscription(_JID, _NodeID, SubID, Options) ->
     case ?DB_MOD:read_subscription(SubID) of
@@ -115,7 +112,7 @@ set_subscription(_JID, _NodeID, SubID, Options) ->
        notfound -> 
             {error, notfound}
     end.
-       
+
 
 get_options_xform(Lang, Options) ->
     Keys = [deliver, show_values, subscription_type, subscription_depth],