24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-02 21:17:12 +02:00

fix create_node and subscribe_node glitches from last merge

SVN Revision: 2496
This commit is contained in:
Christophe Romain 2009-08-17 20:25:31 +00:00
parent 45b12ec886
commit f2bd9e01b0
7 changed files with 44 additions and 33 deletions

View File

@ -264,8 +264,8 @@ terminate_plugins(Host, ServerHost, Plugins, TreePlugin) ->
ok. ok.
init_nodes(Host, ServerHost) -> init_nodes(Host, ServerHost) ->
%create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree"), create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree"),
%create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree"), create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree"),
ok. ok.
update_node_database(Host, ServerHost) -> update_node_database(Host, ServerHost) ->

View File

@ -263,8 +263,8 @@ terminate_plugins(Host, ServerHost, Plugins, TreePlugin) ->
ok. ok.
init_nodes(Host, ServerHost) -> init_nodes(Host, ServerHost) ->
%create_node(Host, ServerHost, ["home"], 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"), create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree_odbc"),
ok. ok.
update_node_database(Host, ServerHost) -> update_node_database(Host, ServerHost) ->

View File

@ -321,8 +321,8 @@ subscribe_node(NodeId, Sender, Subscriber, AccessModel,
%% % Requesting entity is anonymous %% % Requesting entity is anonymous
%% {error, ?ERR_FORBIDDEN}; %% {error, ?ERR_FORBIDDEN};
true -> true ->
case pubsub_subscription:subscribe_node(Subscriber, NodeId, Options) of case pubsub_subscription:add_subscription(Subscriber, NodeId, Options) of
{result, SubId} -> SubId when is_list(SubId) ->
NewSub = case AccessModel of NewSub = case AccessModel of
authorize -> pending; authorize -> pending;
_ -> subscribed _ -> subscribed
@ -409,7 +409,7 @@ delete_subscription(SubKey, NodeID, {Subscription, SubId}, SubState) ->
Affiliation = SubState#pubsub_state.affiliation, Affiliation = SubState#pubsub_state.affiliation,
AllSubs = SubState#pubsub_state.subscriptions, AllSubs = SubState#pubsub_state.subscriptions,
NewSubs = AllSubs -- [{Subscription, SubId}], NewSubs = AllSubs -- [{Subscription, SubId}],
pubsub_subscription:unsubscribe_node(SubKey, NodeID, SubId), pubsub_subscription:delete_subscription(SubKey, NodeID, SubId),
case {Affiliation, NewSubs} of case {Affiliation, NewSubs} of
{none, []} -> {none, []} ->
% Just a regular subscriber, and this is final item, so % 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]). replace_subscription({Sub, SubId}, T, [{Sub, SubID} | Acc]).
unsub_with_subid(NodeId, SubId, SubState) -> unsub_with_subid(NodeId, SubId, SubState) ->
pubsub_subscription:unsubscribe_node(SubState#pubsub_state.stateid, pubsub_subscription:delete_subscription(SubState#pubsub_state.stateid,
NodeId, SubId), NodeId, SubId),
NewSubs = lists:filter(fun ({_, SID}) -> SubId =/= SID end, NewSubs = lists:filter(fun ({_, SID}) -> SubId =/= SID end,
SubState#pubsub_state.subscriptions), SubState#pubsub_state.subscriptions),

View File

@ -161,6 +161,12 @@ get_parentnodes_tree(Host, Node, From) ->
get_subnodes(Host, Node, _From) -> get_subnodes(Host, Node, _From) ->
get_subnodes(Host, Node). get_subnodes(Host, Node).
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, _}, Q = qlc:q([N || #pubsub_node{nodeid = {NHost, _},
parents = Parents} = N <- mnesia:table(pubsub_node), parents = Parents} = N <- mnesia:table(pubsub_node),
Host == NHost, Host == NHost,
@ -176,10 +182,10 @@ get_subnodes_tree(Host, Node, _From) ->
%% From = mod_pubsub:jid() %% From = mod_pubsub:jid()
get_subnodes_tree(Host, Node) -> get_subnodes_tree(Host, Node) ->
mnesia:foldl(fun(#pubsub_node{nodeid = {H, N}} = R, Acc) -> mnesia:foldl(fun(#pubsub_node{nodeid = {H, N}} = R, Acc) ->
case lists:prefix(Node, N) and (H == Host) of case lists:prefix(Node, N) and (H == Host) of
true -> [R | Acc]; true -> [R | Acc];
_ -> Acc false -> Acc
end end
end, [], pubsub_node). end, [], pubsub_node).
%% @spec (Host, Node, Type, Owner, Options) -> ok | {error, Reason} %% @spec (Host, Node, Type, Owner, Options) -> ok | {error, Reason}
@ -190,7 +196,7 @@ get_subnodes_tree(Host, Node) ->
%% Options = list() %% Options = list()
create_node(Host, Node, Type, Owner, Options) -> create_node(Host, Node, Type, Owner, Options) ->
BJID = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), 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} = {ParentNode, ParentExists} =
case Host of case Host of
@ -199,14 +205,14 @@ create_node(Host, Node, Type, Owner, Options) ->
%% PEP does not uses hierarchy %% PEP does not uses hierarchy
{[], true}; {[], true};
_ -> _ ->
Parent = lists:sublist(Node, length(Node) - 1), case lists:sublist(Node, length(Node) - 1) of
case Parent of
[] -> [] ->
{[], true}; {[], true};
_ -> Parent ->
case mnesia:read({pubsub_node, {Host, Parent}}) of case catch mnesia:read({pubsub_node, {Host, Parent}}) of
[] -> {Parent, false}; [#pubsub_node{owners = [{[], Host, []}]}] -> {Parent, true};
_ -> {Parent, lists:member(BJID, Parent#pubsub_node.owners)} [#pubsub_node{owners = Owners}] -> {Parent, lists:member(BJID, Owners)};
_ -> {Parent, false}
end end
end end
end, end,

View File

@ -220,13 +220,15 @@ create_node(Host, Node, Type, _Owner, Options) ->
%% PEP does not uses hierarchy %% PEP does not uses hierarchy
{[], true}; {[], true};
_ -> _ ->
Parent = lists:sublist(Node, length(Node) - 1), case lists:sublist(Node, length(Node) - 1) of
ParentE = (Parent == []) orelse [] ->
{[], true};
Parent ->
case nodeid(Host, Parent) of case nodeid(Host, Parent) of
{result, _} -> true; {result, _} -> {Parent, true};
_ -> false _ -> {Parent, false}
end, end
{Parent, ParentE} end
end, end,
case ParentExists of case ParentExists of
true -> true ->

View File

@ -32,6 +32,12 @@
get_options_xform/2, get_options_xform/2,
parse_options_xform/1]). 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_lib("stdlib/include/qlc.hrl").
-include("pubsub.hrl"). -include("pubsub.hrl").

View File

@ -22,7 +22,7 @@
%%% ==================================================================== %%% ====================================================================
-module(pubsub_subscription_odbc). -module(pubsub_subscription_odbc).
-author("bjc@kublai.com"). -author("pablo.polvorin@process-one.net").
%% API %% API
-export([init/0, -export([init/0,
@ -33,8 +33,6 @@
get_options_xform/2, get_options_xform/2,
parse_options_xform/1]). parse_options_xform/1]).
-include_lib("stdlib/include/qlc.hrl").
-include("pubsub.hrl"). -include("pubsub.hrl").
-include("jlib.hrl"). -include("jlib.hrl").
@ -90,10 +88,9 @@ init() ->
subscribe_node(_JID, _NodeID, Options) -> subscribe_node(_JID, _NodeID, Options) ->
SubId = make_subid(), SubId = make_subid(),
ok = pubsub_db_odbc:add_subscription(#pubsub_subscription{subid = SubId, ok = ?DB_MOD:add_subscription(#pubsub_subscription{subid = SubId, options = Options}),
options = Options}),
{result, SubId}. {result, SubId}.
unsubscribe_node(_JID, _NodeID, SubID) -> unsubscribe_node(_JID, _NodeID, SubID) ->
{ok, Sub} = ?DB_MOD:read_subscription(SubID), {ok, Sub} = ?DB_MOD:read_subscription(SubID),
@ -105,7 +102,7 @@ get_subscription(_JID, _NodeID, SubID) ->
{ok, Sub} -> {result, Sub}; {ok, Sub} -> {result, Sub};
notfound -> {error, notfound} notfound -> {error, notfound}
end. end.
set_subscription(_JID, _NodeID, SubID, Options) -> set_subscription(_JID, _NodeID, SubID, Options) ->
case ?DB_MOD:read_subscription(SubID) of case ?DB_MOD:read_subscription(SubID) of
@ -115,7 +112,7 @@ set_subscription(_JID, _NodeID, SubID, Options) ->
notfound -> notfound ->
{error, notfound} {error, notfound}
end. end.
get_options_xform(Lang, Options) -> get_options_xform(Lang, Options) ->
Keys = [deliver, show_values, subscription_type, subscription_depth], Keys = [deliver, show_values, subscription_type, subscription_depth],