25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

improve get_entity_* to work regardless of nodetree (EJAB-937)

SVN Revision: 2104
This commit is contained in:
Christophe Romain 2009-05-26 21:50:13 +00:00
parent 43a3fef7bb
commit aa210166c4
6 changed files with 53 additions and 30 deletions

View File

@ -44,6 +44,7 @@ behaviour_info(callbacks) ->
{set_node, 1},
{get_node, 3},
{get_node, 2},
{get_node, 1},
{get_nodes, 2},
{get_nodes, 1},
{get_subnodes, 3},

View File

@ -167,12 +167,12 @@ init([ServerHost, Opts]) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
ServerHostB = list_to_binary(ServerHost),
pubsub_index:init(Host, ServerHost, Opts),
ets:new(gen_mod:get_module_proc(Host, pubsub_state), [set, named_table]),
ets:new(gen_mod:get_module_proc(ServerHost, pubsub_state), [set, named_table]),
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
mod_disco:register_feature(ServerHost, ?NS_PUBSUB_s),
ets:new(gen_mod:get_module_proc(Host, pubsub_state), [set, named_table]),
ets:insert(gen_mod:get_module_proc(Host, pubsub_state), {nodetree, NodeTree}),
ets:insert(gen_mod:get_module_proc(Host, pubsub_state), {plugins, Plugins}),
ets:new(gen_mod:get_module_proc(ServerHost, pubsub_state), [set, named_table]),
ets:insert(gen_mod:get_module_proc(ServerHost, pubsub_state), {nodetree, NodeTree}),
ets:insert(gen_mod:get_module_proc(ServerHost, pubsub_state), {plugins, Plugins}),
ets:insert(gen_mod:get_module_proc(ServerHost, pubsub_state), {pep_mapping, PepMapping}),
@ -3018,6 +3018,7 @@ tree_call(Host, Function, Args) ->
end,
catch apply(Module, Function, Args).
tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end,
catch mnesia:sync_dirty(Fun).
@ -3037,7 +3038,8 @@ node_call(Type, Function, Args) ->
Result -> {result, Result} %% any other return value is forced as result
end.
node_action(_Host, Type, Function, Args) ->
node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
transaction(fun() ->
node_call(Type, Function, Args)
end, sync_dirty).

View File

@ -552,15 +552,14 @@ purge_node(NodeId, Owner) ->
get_entity_affiliations(Host, Owner) ->
GenKey = jlib:short_prepd_bare_jid(Owner),
States = mnesia:match_object(#pubsub_state{stateid = {GenKey, '_'}, _ = '_'}),
NodeTree = case ets:lookup(gen_mod:get_module_proc(Host, pubsub_state), nodetree) of
[{nodetree, N}] -> N;
_ -> nodetree_default
end,
Reply = lists:foldl(fun(#pubsub_state{stateid = {_, N}, affiliation = A}, Acc) ->
case mnesia:index_read(pubsub_node, N, #pubsub_node.id) of
[#pubsub_node{nodeid = {H, _}} = Node] ->
case H of
Host -> [{Node, A}|Acc];
case NodeTree:get_node(N) of
#pubsub_node{nodeid = {Host, _}} = Node -> [{Node, A}|Acc];
_ -> Acc
end;
_ ->
Acc
end
end, [], States),
{result, Reply}.
@ -608,15 +607,14 @@ get_entity_subscriptions(Host, Owner) ->
++ mnesia:match_object(
#pubsub_state{stateid = {SubKey, '_'}, _ = '_'})
end,
NodeTree = case ets:lookup(gen_mod:get_module_proc(Host, pubsub_state), nodetree) of
[{nodetree, N}] -> N;
_ -> nodetree_default
end,
Reply = lists:foldl(fun(#pubsub_state{stateid = {J, N}, subscription = S}, Acc) ->
case mnesia:index_read(pubsub_node, N, #pubsub_node.id) of
[#pubsub_node{nodeid = {H, _}} = Node] ->
case H of
Host -> [{Node, S, J}|Acc];
case NodeTree:get_node(N) of
#pubsub_node{nodeid = {Host, _}} = Node -> [{Node, S, J}|Acc];
_ -> Acc
end;
_ ->
Acc
end
end, [], States),
{result, Reply}.

View File

@ -170,8 +170,21 @@ purge_node(NodeId, Owner) ->
node_default:purge_node(NodeId, Owner).
get_entity_affiliations(_Host, Owner) ->
OwnerKey = jlib:short_prepd_bare_jid(Owner),
node_default:get_entity_affiliations(OwnerKey, Owner).
{_, D, _} = SubKey = jlib:jid_tolower(Owner),
SubKey = jlib:jid_tolower(Owner),
GenKey = jlib:jid_remove_resource(SubKey),
States = mnesia:match_object(#pubsub_state{stateid = {GenKey, '_'}, _ = '_'}),
NodeTree = case ets:lookup(gen_mod:get_module_proc(D, pubsub_state), nodetree) of
[{nodetree, N}] -> N;
_ -> nodetree_default
end,
Reply = lists:foldl(fun(#pubsub_state{stateid = {_, N}, affiliation = A}, Acc) ->
case NodeTree:get_node(N) of
#pubsub_node{nodeid = {{_, D, _}, _}} = Node -> [{Node, A}|Acc];
_ -> Acc
end
end, [], States),
{result, Reply}.
get_node_affiliations(NodeId) ->
node_default:get_node_affiliations(NodeId).
@ -193,15 +206,14 @@ get_entity_subscriptions(_Host, Owner) ->
++ mnesia:match_object(
#pubsub_state{stateid = {SubKey, '_'}, _ = '_'})
end,
NodeTree = case ets:lookup(gen_mod:get_module_proc(D, pubsub_state), nodetree) of
[{nodetree, N}] -> N;
_ -> nodetree_default
end,
Reply = lists:foldl(fun(#pubsub_state{stateid = {J, N}, subscription = S}, Acc) ->
case mnesia:index_read(pubsub_node, N, #pubsub_node.id) of
[#pubsub_node{nodeid = {H, _}} = Node] ->
case H of
{_, D, _} -> [{Node, S, J}|Acc];
case NodeTree:get_node(N) of
#pubsub_node{nodeid = {{_, D, _}, _}} = Node -> [{Node, S, J}|Acc];
_ -> Acc
end;
_ ->
Acc
end
end, [], States),
{result, Reply}.

View File

@ -48,6 +48,7 @@
set_node/1,
get_node/3,
get_node/2,
get_node/1,
get_nodes/2,
get_nodes/1,
get_subnodes/3,
@ -110,6 +111,12 @@ get_node(Host, Node) ->
[] -> {error, 'item-not-found'};
Error -> Error
end.
get_node(NodeId) ->
case catch mnesia:index_read(pubsub_node, NodeId, #pubsub_node.id) of
[Record] when is_record(Record, pubsub_node) -> Record;
[] -> {error, 'item-not-found'};
Error -> Error
end.
%% @spec (Host) -> [pubsubNode()] | {error, Reason}
%% Host = mod_pubsub:host() | mod_pubsub:jid()

View File

@ -45,6 +45,7 @@
set_node/1,
get_node/3,
get_node/2,
get_node/1,
get_nodes/2,
get_nodes/1,
get_subnodes/3,
@ -91,7 +92,9 @@ set_node(_NodeRecord) ->
get_node(Host, Node, _From) ->
get_node(Host, Node).
get_node(Host, Node) ->
#pubsub_node{nodeid = {Host, Node}}.
#pubsub_node{nodeid = {Host, Node}, id = {Host, Node}}.
get_node(NodeId) ->
#pubsub_node{nodeid = NodeId, id = NodeId}.
%% @spec (Host) -> [pubsubNode()]
%% Host = mod_pubsub:host() | mod_pubsub:jid()