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

Fix pubsub virtual nodetree plugin

This commit is contained in:
Christophe Romain 2015-12-17 10:16:17 +01:00
parent 6957e892dd
commit bb5a8a42c3

View File

@ -59,15 +59,12 @@ get_node(Host, Node, _From) ->
get_node(Host, Node). get_node(Host, Node).
get_node(Host, Node) -> get_node(Host, Node) ->
get_node(nodeidx(Host, Node)). Nidx = nodeidx(Host, Node),
node_record(Host, Node, Nidx).
get_node(Nidx) -> get_node(Nidx) ->
{Host, Node} = nodeid(Nidx), {Host, Node} = nodeid(Nidx),
[Type|_] = mod_pubsub:plugins(Host), node_record(Host, Node, Nidx).
Module = mod_pubsub:plugin(Host, Type),
#pubsub_node{nodeid = Node, id = Nidx, type = Type,
owners = [{<<"">>, Host, <<"">>}],
options = Module:options()}.
get_nodes(Host, _From) -> get_nodes(Host, _From) ->
get_nodes(Host). get_nodes(Host).
@ -79,10 +76,7 @@ get_parentnodes(_Host, _Node, _From) ->
[]. [].
get_parentnodes_tree(Host, Node, From) -> get_parentnodes_tree(Host, Node, From) ->
case get_node(Host, Node, From) of [{0, [get_node(Host, Node, From)]}].
Node when is_record(Node, pubsub_node) -> [{0, [Node]}];
_Error -> []
end.
get_subnodes(Host, Node, _From) -> get_subnodes(Host, Node, _From) ->
get_subnodes(Host, Node). get_subnodes(Host, Node).
@ -97,12 +91,35 @@ get_subnodes_tree(_Host, _Node) ->
[]. [].
create_node(Host, Node, _Type, _Owner, _Options, _Parents) -> create_node(Host, Node, _Type, _Owner, _Options, _Parents) ->
{error, {virtual, {Host, Node}}}. {error, {virtual, nodeidx(Host, Node)}}.
delete_node(Host, Node) -> delete_node(Host, Node) ->
[get_node(Host, Node)]. [get_node(Host, Node)].
%% internal helper %% internal helper
nodeidx(Host, Node) -> term_to_binary({Host, Node}). node_record({U,S,R}, Node, Nidx) ->
nodeid(Nidx) -> binary_to_term(Nidx). Host = mod_pubsub:host(S),
Type = <<"pep">>,
Module = mod_pubsub:plugin(Host, Type),
#pubsub_node{nodeid = {{U,S,R},Node}, id = Nidx, type = Type,
owners = [{U,S,R}],
options = Module:options()};
node_record(Host, Node, Nidx) ->
[Type|_] = mod_pubsub:plugins(Host),
Module = mod_pubsub:plugin(Host, Type),
#pubsub_node{nodeid = {Host, Node}, id = Nidx, type = Type,
owners = [{<<"">>, Host, <<"">>}],
options = Module:options()}.
nodeidx({U,S,R}, Node) ->
JID = jid:to_string(jid:make(U,S,R)),
<<JID/binary, ":", Node/binary>>;
nodeidx(Host, Node) ->
<<Host/binary, ":", Node/binary>>.
nodeid(Nidx) ->
[Head, Node] = binary:split(Nidx, <<":">>),
case jid:from_string(Head) of
{jid,<<>>,Host,<<>>,_,_,_} -> {Host, Node};
{jid,U,S,R,_,_,_} -> {{U,S,R}, Node}
end.