2015-12-15 16:11:29 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : node_dag.erl
|
|
|
|
%%% Author : Brian Cully <bjc@kublai.com>
|
|
|
|
%%% Purpose : experimental support of XEP-248
|
|
|
|
%%% Created : 15 Jun 2009 by Brian Cully <bjc@kublai.com>
|
2009-06-15 15:45:40 +02:00
|
|
|
%%%
|
2015-04-08 17:12:05 +02:00
|
|
|
%%%
|
2016-01-13 12:29:14 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2016 ProcessOne
|
2009-06-15 15:45:40 +02:00
|
|
|
%%%
|
2015-12-15 16:11:29 +01:00
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
2015-04-08 17:12:05 +02:00
|
|
|
%%%
|
2015-12-15 16:11:29 +01:00
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
|
|
|
%%%
|
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
%%%
|
|
|
|
%%%----------------------------------------------------------------------
|
2009-06-15 15:45:40 +02:00
|
|
|
|
|
|
|
-module(node_dag).
|
2015-04-08 17:12:05 +02:00
|
|
|
-behaviour(gen_pubsub_node).
|
2009-06-15 15:45:40 +02:00
|
|
|
-author('bjc@kublai.com').
|
|
|
|
|
|
|
|
-include("pubsub.hrl").
|
|
|
|
-include("jlib.hrl").
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-export([init/3, terminate/2, options/0, features/0,
|
2015-04-08 17:12:05 +02:00
|
|
|
create_node_permission/6, create_node/2, delete_node/1,
|
|
|
|
purge_node/2, subscribe_node/8, unsubscribe_node/4,
|
|
|
|
publish_item/6, delete_item/4, remove_extra_items/3,
|
|
|
|
get_entity_affiliations/2, get_node_affiliations/1,
|
|
|
|
get_affiliation/2, set_affiliation/3,
|
|
|
|
get_entity_subscriptions/2, get_node_subscriptions/1,
|
|
|
|
get_subscriptions/2, set_subscriptions/4,
|
|
|
|
get_pending_nodes/2, get_states/1, get_state/2,
|
|
|
|
set_state/1, get_items/7, get_items/3, get_item/7,
|
|
|
|
get_item/2, set_item/1, get_item_name/3, node_to_path/1,
|
|
|
|
path_to_node/1]).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
|
|
|
init(Host, ServerHost, Opts) ->
|
|
|
|
node_hometree:init(Host, ServerHost, Opts).
|
|
|
|
|
|
|
|
terminate(Host, ServerHost) ->
|
|
|
|
node_hometree:terminate(Host, ServerHost).
|
|
|
|
|
|
|
|
options() ->
|
|
|
|
[{node_type, leaf} | node_hometree:options()].
|
|
|
|
|
|
|
|
features() ->
|
2013-03-14 10:33:02 +01:00
|
|
|
[<<"multi-collection">> | node_hometree:features()].
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
create_node_permission(_Host, _ServerHost, _Node, _ParentNode, _Owner, _Access) ->
|
2009-06-15 15:45:40 +02:00
|
|
|
{result, true}.
|
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
create_node(Nidx, Owner) ->
|
|
|
|
node_hometree:create_node(Nidx, Owner).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
|
|
|
delete_node(Removed) ->
|
|
|
|
node_hometree:delete_node(Removed).
|
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
subscribe_node(Nidx, Sender, Subscriber, AccessModel,
|
|
|
|
SendLast, PresenceSubscription, RosterGroup, Options) ->
|
|
|
|
node_hometree:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
|
|
|
|
PresenceSubscription, RosterGroup, Options).
|
|
|
|
|
|
|
|
unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
|
|
|
|
node_hometree:unsubscribe_node(Nidx, Sender, Subscriber, SubId).
|
|
|
|
|
|
|
|
publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload) ->
|
|
|
|
case nodetree_dag:get_node(Nidx) of
|
|
|
|
#pubsub_node{options = Options} ->
|
|
|
|
case find_opt(node_type, Options) of
|
|
|
|
collection ->
|
|
|
|
{error,
|
|
|
|
?ERR_EXTENDED((?ERR_NOT_ALLOWED), <<"publish">>)};
|
|
|
|
_ ->
|
|
|
|
node_hometree:publish_item(Nidx, Publisher, Model,
|
|
|
|
MaxItems, ItemId, Payload)
|
|
|
|
end;
|
|
|
|
Err -> Err
|
2009-06-29 23:46:13 +02:00
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
find_opt(_, []) -> false;
|
2009-06-29 23:46:13 +02:00
|
|
|
find_opt(Option, [{Option, Value} | _]) -> Value;
|
2013-03-14 10:33:02 +01:00
|
|
|
find_opt(Option, [_ | T]) -> find_opt(Option, T).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
remove_extra_items(Nidx, MaxItems, ItemIds) ->
|
|
|
|
node_hometree:remove_extra_items(Nidx, MaxItems, ItemIds).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
delete_item(Nidx, Publisher, PublishModel, ItemId) ->
|
|
|
|
node_hometree:delete_item(Nidx, Publisher, PublishModel, ItemId).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
purge_node(Nidx, Owner) ->
|
|
|
|
node_hometree:purge_node(Nidx, Owner).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
|
|
|
get_entity_affiliations(Host, Owner) ->
|
|
|
|
node_hometree:get_entity_affiliations(Host, Owner).
|
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_node_affiliations(Nidx) ->
|
|
|
|
node_hometree:get_node_affiliations(Nidx).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_affiliation(Nidx, Owner) ->
|
|
|
|
node_hometree:get_affiliation(Nidx, Owner).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
set_affiliation(Nidx, Owner, Affiliation) ->
|
|
|
|
node_hometree:set_affiliation(Nidx, Owner, Affiliation).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
|
|
|
get_entity_subscriptions(Host, Owner) ->
|
|
|
|
node_hometree:get_entity_subscriptions(Host, Owner).
|
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_node_subscriptions(Nidx) ->
|
|
|
|
node_hometree:get_node_subscriptions(Nidx).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_subscriptions(Nidx, Owner) ->
|
|
|
|
node_hometree:get_subscriptions(Nidx, Owner).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
set_subscriptions(Nidx, Owner, Subscription, SubId) ->
|
|
|
|
node_hometree:set_subscriptions(Nidx, Owner, Subscription, SubId).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2009-07-20 10:53:56 +02:00
|
|
|
get_pending_nodes(Host, Owner) ->
|
|
|
|
node_hometree:get_pending_nodes(Host, Owner).
|
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_states(Nidx) ->
|
|
|
|
node_hometree:get_states(Nidx).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_state(Nidx, JID) ->
|
|
|
|
node_hometree:get_state(Nidx, JID).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
set_state(State) ->
|
|
|
|
node_hometree:set_state(State).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_items(Nidx, From, RSM) ->
|
|
|
|
node_hometree:get_items(Nidx, From, RSM).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
|
|
|
|
node_hometree:get_items(Nidx, JID, AccessModel,
|
|
|
|
PresenceSubscription, RosterGroup, SubId, RSM).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_item(Nidx, ItemId) ->
|
|
|
|
node_hometree:get_item(Nidx, ItemId).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
|
|
|
|
node_hometree:get_item(Nidx, ItemId, JID, AccessModel,
|
|
|
|
PresenceSubscription, RosterGroup, SubId).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
set_item(Item) ->
|
|
|
|
node_hometree:set_item(Item).
|
2009-06-15 15:45:40 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
get_item_name(Host, Node, Id) ->
|
|
|
|
node_hometree:get_item_name(Host, Node, Id).
|
2009-10-20 17:03:07 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
node_to_path(Node) ->
|
|
|
|
node_hometree:node_to_path(Node).
|
2009-10-20 17:03:07 +02:00
|
|
|
|
2015-04-08 17:12:05 +02:00
|
|
|
path_to_node(Path) ->
|
|
|
|
node_hometree:path_to_node(Path).
|