diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index 2f606d4df..fe0149dec 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -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) -> diff --git a/src/mod_pubsub/mod_pubsub_odbc.erl b/src/mod_pubsub/mod_pubsub_odbc.erl index bab0e3734..d6a95ae06 100644 --- a/src/mod_pubsub/mod_pubsub_odbc.erl +++ b/src/mod_pubsub/mod_pubsub_odbc.erl @@ -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) -> diff --git a/src/mod_pubsub/node_hometree.erl b/src/mod_pubsub/node_hometree.erl index 011ea428a..6484fbe0a 100644 --- a/src/mod_pubsub/node_hometree.erl +++ b/src/mod_pubsub/node_hometree.erl @@ -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), diff --git a/src/mod_pubsub/nodetree_tree.erl b/src/mod_pubsub/nodetree_tree.erl index 39724db46..99b4b8891 100644 --- a/src/mod_pubsub/nodetree_tree.erl +++ b/src/mod_pubsub/nodetree_tree.erl @@ -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, diff --git a/src/mod_pubsub/nodetree_tree_odbc.erl b/src/mod_pubsub/nodetree_tree_odbc.erl index 95f9b34ef..6468913d1 100644 --- a/src/mod_pubsub/nodetree_tree_odbc.erl +++ b/src/mod_pubsub/nodetree_tree_odbc.erl @@ -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 -> diff --git a/src/mod_pubsub/pubsub_subscription.erl b/src/mod_pubsub/pubsub_subscription.erl index 754a9d8f8..5f3038d35 100644 --- a/src/mod_pubsub/pubsub_subscription.erl +++ b/src/mod_pubsub/pubsub_subscription.erl @@ -32,6 +32,12 @@ 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"). diff --git a/src/mod_pubsub/pubsub_subscription_odbc.erl b/src/mod_pubsub/pubsub_subscription_odbc.erl index 56ddf6d4b..98e62abaa 100644 --- a/src/mod_pubsub/pubsub_subscription_odbc.erl +++ b/src/mod_pubsub/pubsub_subscription_odbc.erl @@ -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],