2009-08-25 19:14:30 +02:00
|
|
|
%%% ====================================================================
|
|
|
|
%%% ``The contents of this file are subject to the Erlang Public License,
|
|
|
|
%%% Version 1.1, (the "License"); you may not use this file except in
|
|
|
|
%%% compliance with the License. You should have received a copy of the
|
|
|
|
%%% Erlang Public License along with this software. If not, it can be
|
|
|
|
%%% retrieved via the world wide web at http://www.erlang.org/.
|
|
|
|
%%%
|
|
|
|
%%% Software distributed under the License is distributed on an "AS IS"
|
|
|
|
%%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
%%% the License for the specific language governing rights and limitations
|
|
|
|
%%% under the License.
|
|
|
|
%%%
|
|
|
|
%%% @author Brian Cully <bjc@kublai.com>
|
|
|
|
%%% @version {@vsn}, {@date} {@time}
|
|
|
|
%%% @end
|
|
|
|
%%% ====================================================================
|
|
|
|
|
|
|
|
-module(nodetree_dag).
|
|
|
|
-author('bjc@kublai.com').
|
|
|
|
|
|
|
|
%% API
|
|
|
|
-export([init/3,
|
|
|
|
terminate/2,
|
|
|
|
options/0,
|
|
|
|
set_node/1,
|
|
|
|
get_node/3,
|
|
|
|
get_node/2,
|
|
|
|
get_node/1,
|
|
|
|
get_nodes/2,
|
|
|
|
get_nodes/1,
|
|
|
|
get_parentnodes/3,
|
|
|
|
get_parentnodes_tree/3,
|
|
|
|
get_subnodes/3,
|
|
|
|
get_subnodes_tree/3,
|
2009-10-21 00:09:43 +02:00
|
|
|
create_node/6,
|
2009-08-25 19:14:30 +02:00
|
|
|
delete_node/2]).
|
|
|
|
|
|
|
|
-include_lib("stdlib/include/qlc.hrl").
|
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
|
|
|
-include("pubsub.hrl").
|
|
|
|
|
|
|
|
-behaviour(gen_pubsub_nodetree).
|
|
|
|
|
|
|
|
-define(DEFAULT_NODETYPE, leaf).
|
|
|
|
-define(DEFAULT_PARENTS, []).
|
|
|
|
-define(DEFAULT_CHILDREN, []).
|
|
|
|
|
|
|
|
-compile(export_all).
|
|
|
|
|
|
|
|
%%====================================================================
|
|
|
|
%% API
|
|
|
|
%%====================================================================
|
2010-10-04 17:41:59 +02:00
|
|
|
-spec(init/3 ::
|
|
|
|
(
|
|
|
|
Host :: string(),
|
|
|
|
ServerHost :: string(),
|
|
|
|
Opts :: [{Key::atom(), Value::term()}])
|
|
|
|
-> 'ok'
|
|
|
|
).
|
|
|
|
|
2009-08-25 19:14:30 +02:00
|
|
|
init(Host, ServerHost, Opts) ->
|
2009-10-21 00:09:43 +02:00
|
|
|
nodetree_tree:init(Host, ServerHost, Opts).
|
2009-08-25 19:14:30 +02:00
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
|
|
|
|
-spec(terminate/2 ::
|
|
|
|
(
|
|
|
|
Host :: string(),
|
|
|
|
ServerHost :: string())
|
|
|
|
-> 'ok'
|
|
|
|
).
|
|
|
|
|
2009-08-25 19:14:30 +02:00
|
|
|
terminate(Host, ServerHost) ->
|
|
|
|
nodetree_tree:terminate(Host, ServerHost).
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
|
|
|
|
-spec(create_node/6 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub(),
|
|
|
|
NodeId :: nodeId(),
|
|
|
|
Type :: nodeType(),
|
|
|
|
JID :: jidEntity(),
|
|
|
|
Options :: [nodeOption()],
|
|
|
|
ParentNodeIds :: [] | [nodeId()])
|
|
|
|
-> {'ok', NodeIdx::nodeIdx()} | {'error', _}
|
|
|
|
).
|
|
|
|
|
|
|
|
create_node(Host, NodeId, Type, #jid{node = U, domain = S} = _JID, Options, ParentNodeIds) ->
|
|
|
|
case find_node(Host, NodeId) of
|
2009-08-25 19:14:30 +02:00
|
|
|
false ->
|
2010-10-04 17:41:59 +02:00
|
|
|
NodeIdx = pubsub_index:new(node),
|
|
|
|
Node = #pubsub_node{id = {Host, NodeId},
|
|
|
|
idx = NodeIdx,
|
2009-08-25 19:14:30 +02:00
|
|
|
type = Type,
|
2010-10-04 17:41:59 +02:00
|
|
|
parents = ParentNodeIds,
|
|
|
|
owners = [_Owner = {U,S,undefined}],
|
2009-08-25 19:14:30 +02:00
|
|
|
options = Options},
|
2010-10-04 17:41:59 +02:00
|
|
|
case set_node(Node) of
|
|
|
|
ok -> {ok, NodeIdx};
|
2009-08-25 19:14:30 +02:00
|
|
|
Other -> Other
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
{error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'conflict')}
|
|
|
|
end.
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
|
|
|
|
-spec(set_node/1 ::
|
|
|
|
(
|
|
|
|
Node :: pubsubNode())
|
|
|
|
-> 'ok' | {'error', _}
|
|
|
|
).
|
|
|
|
|
|
|
|
set_node(#pubsub_node{id = {Host, _},
|
2009-08-25 19:14:30 +02:00
|
|
|
owners = Owners,
|
|
|
|
options = Options} = Node) ->
|
2010-10-04 17:41:59 +02:00
|
|
|
ParentNodeIds = find_opt('collection', ?DEFAULT_PARENTS, Options),
|
|
|
|
case validate_parentage(Host, Owners, ParentNodeIds) of
|
2009-08-25 19:14:30 +02:00
|
|
|
true ->
|
|
|
|
%% Update parents whenever the config changes.
|
2010-10-04 17:41:59 +02:00
|
|
|
mnesia:write(Node#pubsub_node{parents = ParentNodeIds});
|
2009-08-25 19:14:30 +02:00
|
|
|
Other ->
|
|
|
|
Other
|
|
|
|
end.
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
|
|
|
|
-spec(delete_node/2 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub(),
|
|
|
|
NodeId :: nodeId())
|
|
|
|
-> [pubsubNode()] | {'error', _}
|
|
|
|
).
|
|
|
|
|
|
|
|
delete_node(Host, NodeId) ->
|
|
|
|
case find_node(Host, NodeId) of
|
2009-08-25 19:14:30 +02:00
|
|
|
false ->
|
|
|
|
{error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'item-not-found')};
|
2010-10-04 17:41:59 +02:00
|
|
|
ParentNode ->
|
2009-08-25 19:14:30 +02:00
|
|
|
%% Find all of N's children, update their configs to
|
|
|
|
%% remove N from the collection setting.
|
2010-10-04 17:41:59 +02:00
|
|
|
lists:foreach(fun (#pubsub_node{options = Options} = Node) ->
|
|
|
|
NewOptions = remove_config_parent(NodeId, Options),
|
|
|
|
Parents = find_opt('collection', ?DEFAULT_PARENTS, NewOptions),
|
2009-08-25 19:14:30 +02:00
|
|
|
ok = mnesia:write(pubsub_node,
|
2010-10-04 17:41:59 +02:00
|
|
|
Node#pubsub_node{
|
2009-08-25 19:14:30 +02:00
|
|
|
parents = Parents,
|
2010-10-04 17:41:59 +02:00
|
|
|
options = NewOptions},
|
2009-08-25 19:14:30 +02:00
|
|
|
write)
|
2010-10-04 17:41:59 +02:00
|
|
|
end, get_subnodes(Host, NodeId)),
|
2009-08-25 19:14:30 +02:00
|
|
|
|
|
|
|
%% Remove and return the requested node.
|
2010-10-04 17:41:59 +02:00
|
|
|
pubsub_index:free(node, ParentNode#pubsub_node.idx),
|
|
|
|
mnesia:delete_object(pubsub_node, ParentNode, write),
|
|
|
|
[ParentNode]
|
2009-08-25 19:14:30 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
-spec(options/0 :: () -> Options::[Option::nodeOption()]).
|
|
|
|
%Options::[{'virtual_tree', 'false'}])
|
|
|
|
|
|
|
|
options() -> nodetree_tree:options().
|
|
|
|
|
2009-08-25 19:14:30 +02:00
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
-spec(get_node/3 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub(),
|
|
|
|
NodeId :: nodeId(),
|
|
|
|
JID :: jidEntity())
|
|
|
|
-> pubsubNode() | {'error', _}
|
|
|
|
).
|
|
|
|
|
|
|
|
get_node(Host, NodeId, _JID) ->
|
|
|
|
get_node(Host, NodeId).
|
|
|
|
|
|
|
|
|
|
|
|
-spec(get_node/2 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub(),
|
|
|
|
NodeId :: nodeId())
|
|
|
|
-> pubsubNode() | {'error', _}
|
|
|
|
).
|
|
|
|
|
|
|
|
get_node(Host, NodeId) ->
|
|
|
|
case find_node(Host, NodeId) of
|
2009-08-25 19:14:30 +02:00
|
|
|
false -> {error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'item-not-found')};
|
2010-10-04 17:41:59 +02:00
|
|
|
Node -> Node
|
2009-08-25 19:14:30 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
-spec(get_node/1 ::
|
|
|
|
(
|
|
|
|
NodeIdx :: nodeIdx())
|
|
|
|
-> pubsubNode() | {'error', 'item-not-found'}
|
|
|
|
).
|
|
|
|
|
|
|
|
get_node(NodeIdx) ->
|
|
|
|
nodetree_tree:get_node(NodeIdx).
|
|
|
|
|
|
|
|
|
|
|
|
-spec(get_nodes/2 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub(),
|
|
|
|
JID :: jidEntity())
|
|
|
|
-> Nodes :: [] | [Node::pubsubNode()]
|
|
|
|
).
|
|
|
|
|
|
|
|
get_nodes(Host, JID) ->
|
|
|
|
nodetree_tree:get_nodes(Host, JID).
|
|
|
|
|
|
|
|
|
|
|
|
-spec(get_nodes/1 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub())
|
|
|
|
-> Nodes :: [] | [Node::pubsubNode()]
|
|
|
|
).
|
|
|
|
|
|
|
|
get_nodes(Host) ->
|
|
|
|
nodetree_tree:get_nodes(Host).
|
2009-08-25 19:14:30 +02:00
|
|
|
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
-spec(get_parentnodes/3 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub(),
|
|
|
|
NodeId :: nodeId(),
|
|
|
|
JID :: jidEntity())
|
|
|
|
-> ParentNodes :: [] | [ParentNode::pubsubNode()]
|
|
|
|
).
|
|
|
|
|
|
|
|
get_parentnodes(Host, NodeId, _JID) ->
|
|
|
|
case find_node(Host, NodeId) of
|
2009-08-25 19:14:30 +02:00
|
|
|
false -> {error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'item-not-found')};
|
2010-10-04 17:41:59 +02:00
|
|
|
#pubsub_node{parents = ParentNodeIds} ->
|
|
|
|
Q = qlc:q([Node || #pubsub_node{id = {NHost, NNodeId}} = Node
|
|
|
|
<- mnesia:table(pubsub_node),
|
|
|
|
ParentNodeId <- ParentNodeIds,
|
2009-08-25 19:14:30 +02:00
|
|
|
Host == NHost,
|
2010-10-04 17:41:59 +02:00
|
|
|
ParentNodeId == NNodeId]),
|
2009-08-25 19:14:30 +02:00
|
|
|
qlc:e(Q)
|
|
|
|
end.
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
|
|
|
|
-spec(get_parentnodes_tree/3 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub(),
|
|
|
|
NodeId :: nodeId(),
|
|
|
|
JID :: jidEntity())
|
|
|
|
-> [] | [{Depth::integer(), Nodes :: [] | [Node::pubsubNode()]}]
|
|
|
|
).
|
|
|
|
|
|
|
|
get_parentnodes_tree(Host, NodeId, _JID) ->
|
2010-09-10 19:45:28 +02:00
|
|
|
Pred = fun (Name, #pubsub_node{id = {_, NodeName}}) -> Name == NodeName end,
|
2009-08-25 19:14:30 +02:00
|
|
|
Tr = fun (#pubsub_node{parents = Parents}) -> Parents end,
|
2010-10-04 17:41:59 +02:00
|
|
|
traversal_helper(Pred, Tr, Host, [NodeId]).
|
2009-08-25 19:14:30 +02:00
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
|
|
|
|
-spec(get_subnodes/3 ::
|
|
|
|
(
|
|
|
|
ParentNodeHost :: hostPubsub(),
|
|
|
|
ParentNodeId :: nodeId(),
|
|
|
|
JID :: jidEntity())
|
|
|
|
-> [] | [Node::pubsubNode()] | {'error', _}
|
|
|
|
).
|
|
|
|
|
|
|
|
get_subnodes(Host, Node, _JID) ->
|
2010-09-10 19:45:28 +02:00
|
|
|
get_subnodes(Host, Node).
|
2009-08-25 19:14:30 +02:00
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
|
|
|
|
-spec(get_subnodes/2 ::
|
|
|
|
(
|
|
|
|
ParentNodeHost :: hostPubsub(),
|
|
|
|
ParentNodeId :: nodeId())
|
|
|
|
-> [] | [Node::pubsubNode()] | {'error', _}
|
|
|
|
).
|
|
|
|
|
|
|
|
get_subnodes(ParentNodeHost, <<>>) ->
|
|
|
|
get_subnodes_helper(ParentNodeHost, <<>>);
|
|
|
|
get_subnodes(ParentNodeHost, ParentNodeId) ->
|
|
|
|
case find_node(ParentNodeHost, ParentNodeId) of
|
2009-08-25 19:14:30 +02:00
|
|
|
false -> {error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'item-not-found')};
|
2010-10-04 17:41:59 +02:00
|
|
|
_ -> get_subnodes_helper(ParentNodeHost, ParentNodeId)
|
2009-08-25 19:14:30 +02:00
|
|
|
end.
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
|
|
|
|
-spec(get_subnodes_helper/2 ::
|
|
|
|
(
|
|
|
|
ParentNodeHost :: hostPubsub(),
|
|
|
|
ParentNodeId :: nodeId())
|
|
|
|
-> SubNodes :: [] | [Node::pubsubNode()]
|
|
|
|
).
|
|
|
|
|
|
|
|
get_subnodes_helper(ParentNodeHost, ParentNodeId) ->
|
|
|
|
Q = qlc:q([Node || #pubsub_node{id = {Host, _},
|
|
|
|
parents = ParentNodeIds} = Node <- mnesia:table(pubsub_node),
|
|
|
|
ParentNodeHost == Host,
|
|
|
|
lists:member(ParentNodeId, ParentNodeIds)]),
|
2009-10-27 15:30:00 +01:00
|
|
|
qlc:e(Q).
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
|
|
|
|
-spec(get_subnodes_tree/3 ::
|
|
|
|
(
|
|
|
|
ParentNodeHost :: hostPubsub(),
|
|
|
|
ParentNodeId :: nodeId(),
|
|
|
|
JID :: jidEntity())
|
|
|
|
-> [] | [{Depth::integer(), Nodes :: [] | [Node::pubsubNode()]}]
|
|
|
|
).
|
|
|
|
|
|
|
|
get_subnodes_tree(Host, ParentNodeId, JID) ->
|
|
|
|
Pred = fun(NodeId, #pubsub_node{parents = ParentNodeIds}) ->
|
|
|
|
lists:member(NodeId, ParentNodeIds)
|
2009-08-25 19:14:30 +02:00
|
|
|
end,
|
2010-10-04 17:41:59 +02:00
|
|
|
Tr = fun (#pubsub_node{id = {_, NodeId}}) -> [NodeId] end,
|
|
|
|
traversal_helper(Pred, Tr, 1, Host, [ParentNodeId],
|
|
|
|
[{0, [get_node(Host, ParentNodeId, JID)]}]).
|
2009-08-25 19:14:30 +02:00
|
|
|
|
|
|
|
%%====================================================================
|
|
|
|
%% Internal functions
|
|
|
|
%%====================================================================
|
|
|
|
oid(Key, Name) -> {Key, Name}.
|
|
|
|
|
|
|
|
%% Key = jlib:jid() | host()
|
2010-09-10 19:45:28 +02:00
|
|
|
%% Node = string()
|
2010-10-04 17:41:59 +02:00
|
|
|
-spec(find_node/2 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub(),
|
|
|
|
NodeId :: nodeId())
|
|
|
|
-> pubsubNode() | 'false'
|
|
|
|
).
|
|
|
|
|
|
|
|
find_node(Host, NodeId) ->
|
|
|
|
case mnesia:read({pubsub_node, {Host, NodeId}}) of
|
2009-08-25 19:14:30 +02:00
|
|
|
[] -> false;
|
|
|
|
[Node] -> Node
|
|
|
|
end.
|
|
|
|
|
|
|
|
%% Key = jlib:jid() | host()
|
|
|
|
%% Default = term()
|
|
|
|
%% Options = [{Key = atom(), Value = term()}]
|
2010-10-04 17:41:59 +02:00
|
|
|
-spec(find_opt/3 ::
|
|
|
|
(
|
|
|
|
Key :: atom(),
|
|
|
|
Default :: term(),
|
|
|
|
Options :: [Option::nodeOption()])
|
|
|
|
-> Value::term()
|
|
|
|
).
|
|
|
|
|
2009-08-25 19:14:30 +02:00
|
|
|
find_opt(Key, Default, Options) ->
|
|
|
|
case lists:keysearch(Key, 1, Options) of
|
2010-10-04 17:41:59 +02:00
|
|
|
{value, {Key, Value}} -> Value;
|
2009-08-25 19:14:30 +02:00
|
|
|
_ -> Default
|
|
|
|
end.
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
|
|
|
|
-spec(traversal_helper/4 ::
|
|
|
|
(
|
|
|
|
Pred :: fun(),
|
|
|
|
Tr :: fun(),
|
|
|
|
ParentNodeHost :: hostPubsub(),
|
|
|
|
ParentNodeIds :: [] | [ParentNodeId::nodeId()])
|
|
|
|
-> [] | [{Depth::integer(), Nodes :: [] | [Node::pubsubNode()]}]
|
|
|
|
).
|
|
|
|
|
|
|
|
traversal_helper(Pred, Tr, ParentNodeHost, ParentNodeIds) ->
|
|
|
|
traversal_helper(Pred, Tr, 0, ParentNodeHost, ParentNodeIds, []).
|
|
|
|
|
|
|
|
|
|
|
|
-spec(traversal_helper/6 ::
|
|
|
|
(
|
|
|
|
Pred :: fun(),
|
|
|
|
Tr :: fun(),
|
|
|
|
Depth :: integer(),
|
|
|
|
ParentNodeHost :: hostPubsub(),
|
|
|
|
ParentNodeIds :: [] | [ParentNodeId::nodeId()],
|
|
|
|
Acc :: [] | [{Depth::integer(), Nodes :: [] | [Node::pubsubNode()]}])
|
|
|
|
-> [] | [{Depth::integer(), Nodes :: [] | [Node::pubsubNode()]}]
|
|
|
|
).
|
2009-08-25 19:14:30 +02:00
|
|
|
|
|
|
|
traversal_helper(_Pred, _Tr, _Depth, _Host, [], Acc) ->
|
|
|
|
Acc;
|
2010-10-04 17:41:59 +02:00
|
|
|
traversal_helper(Pred, Tr, Depth, ParentNodeHost, ParentNodeIds, Acc) ->
|
|
|
|
Q = qlc:q([Node || #pubsub_node{id = {Host, _}} = Node <- mnesia:table(pubsub_node),
|
|
|
|
ParentNodeId <- ParentNodeIds,
|
|
|
|
ParentNodeHost == Host,
|
|
|
|
Pred(ParentNodeId, Node)]),
|
2009-08-25 19:14:30 +02:00
|
|
|
Nodes = qlc:e(Q),
|
2010-10-04 17:41:59 +02:00
|
|
|
Ids = lists:flatmap(Tr, Nodes),
|
|
|
|
traversal_helper(Pred, Tr, Depth + 1, ParentNodeHost, Ids, [{Depth, Nodes} | Acc]).
|
2009-08-25 19:14:30 +02:00
|
|
|
|
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
-spec(remove_config_parent/2 ::
|
|
|
|
(
|
|
|
|
NodeId :: nodeId(),
|
|
|
|
Options :: [Option::nodeOption()])
|
|
|
|
-> [Option::nodeOption()]
|
|
|
|
).
|
2009-08-25 19:14:30 +02:00
|
|
|
|
2010-10-04 17:41:59 +02:00
|
|
|
remove_config_parent(NodeId, Options) ->
|
|
|
|
remove_config_parent(NodeId, Options, []).
|
|
|
|
|
|
|
|
|
|
|
|
-spec(remove_config_parent/3 ::
|
|
|
|
(
|
|
|
|
NodeId :: nodeId(),
|
|
|
|
Options :: [] | [Option::nodeOption()],
|
|
|
|
Acc :: [Option::nodeOption()])
|
|
|
|
-> [Option::nodeOption()]
|
|
|
|
).
|
|
|
|
|
|
|
|
remove_config_parent(_NodeId, [], Acc) ->
|
|
|
|
lists:reverse(Acc);
|
|
|
|
remove_config_parent(NodeId, [{'collection', ParentNodeIds} | Options], Acc) ->
|
|
|
|
remove_config_parent(NodeId, Options,
|
|
|
|
[{'collection', lists:delete(NodeId, ParentNodeIds)} | Acc]);
|
|
|
|
remove_config_parent(NodeId, [Option | Options], Acc) ->
|
|
|
|
remove_config_parent(NodeId, Options, [Option | Acc]).
|
|
|
|
|
|
|
|
|
|
|
|
-spec(validate_parentage/3 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub(),
|
|
|
|
Owners :: [Owner::bareUsr()],
|
|
|
|
ParentNodeIds :: [] | [ParentNodeId::nodeId()] | [ParentNodeId :: nodeId() | []])
|
|
|
|
-> 'true' | {'error', _}
|
|
|
|
).
|
|
|
|
|
|
|
|
validate_parentage(_Host, _Owners, []) ->
|
2009-08-25 19:14:30 +02:00
|
|
|
true;
|
2010-10-04 17:41:59 +02:00
|
|
|
validate_parentage(Host, Owners, [[] | ParentNodeIds]) ->
|
|
|
|
validate_parentage(Host, Owners, ParentNodeIds);
|
|
|
|
validate_parentage(Host, Owners, [<<>> | ParentNodeIds]) ->
|
|
|
|
validate_parentage(Host, Owners, ParentNodeIds);
|
|
|
|
validate_parentage(Host, Owners, [ParentNodeId | ParentNodeIds]) ->
|
|
|
|
case find_node(Host, ParentNodeId) of
|
2009-08-25 19:14:30 +02:00
|
|
|
false -> {error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'item_not_found')};
|
2010-10-04 17:41:59 +02:00
|
|
|
#pubsub_node{owners = ParentNodeOwners, options = Options} ->
|
|
|
|
NodeType = find_opt('node_type', ?DEFAULT_NODETYPE, Options),
|
|
|
|
MutualOwners = [Owner || Owner <- Owners, ParentNodeOwner <- ParentNodeOwners,
|
|
|
|
Owner == ParentNodeOwner],
|
2009-08-25 19:14:30 +02:00
|
|
|
case {MutualOwners, NodeType} of
|
|
|
|
{[], _} -> {error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'forbidden')};
|
2010-10-04 17:41:59 +02:00
|
|
|
{_, 'collection'} -> validate_parentage(Host, Owners, ParentNodeIds);
|
2009-08-25 19:14:30 +02:00
|
|
|
{_, _} -> {error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'not-allowed')}
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
%% @spec (Host) -> jid()
|
|
|
|
%% Host = host()
|
|
|
|
%% @doc <p>Generate pubsub service JID.</p>
|
2010-10-04 17:41:59 +02:00
|
|
|
-spec(service_jid/1 ::
|
|
|
|
(
|
|
|
|
Host :: hostPubsub())
|
|
|
|
-> ServiceJID :: jidContact() | jidComponent() %% should only return jidContact()
|
|
|
|
).
|
|
|
|
|
2009-08-25 19:14:30 +02:00
|
|
|
service_jid(Host) ->
|
|
|
|
case Host of
|
|
|
|
{U,S,_} -> exmpp_jid:make(U, S);
|
|
|
|
_ -> exmpp_jid:make(Host)
|
|
|
|
end.
|