25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01: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.
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) ->

View 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) ->

View 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),

View 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,

View 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 ->

View File

@ -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").

View 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],