1
%%% ====================================================================
2
%%% ``The contents of this file are subject to the Erlang Public License,
3
%%% Version 1.1, (the "License"); you may not use this file except in
4
%%% compliance with the License. You should have received a copy of the
5
%%% Erlang Public License along with this software. If not, it can be
6
%%% retrieved via the world wide web at http://www.erlang.org/.
8
%%% Software distributed under the License is distributed on an "AS IS"
9
%%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
10
%%% the License for the specific language governing rights and limitations
11
%%% under the License.
13
%%% The Initial Developer of the Original Code is ProcessOne.
14
%%% Portions created by ProcessOne are Copyright 2006-2009, ProcessOne
15
%%% All Rights Reserved.''
16
%%% This software is copyright 2006-2009, ProcessOne.
18
%%% @copyright 2006-2009 ProcessOne
19
%%% @author Christophe Romain <christophe.romain@process-one.net>
20
%%% [http://www.process-one.net/]
21
%%% @version {@vsn}, {@date} {@time}
23
%%% ====================================================================
26
-author('christophe.romain@process-one.net').
28
-include("pubsub.hrl").
31
-behaviour(gen_pubsub_node).
34
-export([init/3, terminate/2,
35
options/0, features/0,
36
create_node_permission/6,
45
get_entity_affiliations/2,
46
get_node_affiliations/1,
49
get_entity_subscriptions/2,
50
get_node_subscriptions/1,
68
init(Host, ServerHost, Opts) ->
69
node_hometree:init(Host, ServerHost, Opts).
71
terminate(Host, ServerHost) ->
72
node_hometree:terminate(Host, ServerHost).
75
[{deliver_payloads, true},
76
{notify_config, false},
77
{notify_delete, false},
78
{notify_retract, true},
79
{persist_items, true},
80
{max_items, ?MAXITEMS},
83
{roster_groups_allowed, []},
84
{publish_model, publishers},
85
{notification_type, headline},
86
{max_payload_size, ?MAX_PAYLOAD_SIZE},
87
{send_last_published_item, on_sub_and_presence},
88
{deliver_notifications, true},
89
{presence_based_delivery, false}].
92
node_hometree:features().
94
%% use same code as node_hometree, but do not limite node to
95
%% the home/localhost/user/... hierarchy
96
%% any node is allowed
97
create_node_permission(Host, ServerHost, _Node, _ParentNode, Owner, Access) ->
98
LOwner = jlib:jid_tolower(Owner),
99
Allowed = case LOwner of
101
true; % pubsub service always allowed
103
acl:match_rule(ServerHost, Access, LOwner) =:= allow
107
create_node(NodeId, Owner) ->
108
node_hometree:create_node(NodeId, Owner).
110
delete_node(Removed) ->
111
node_hometree:delete_node(Removed).
113
subscribe_node(NodeId, Sender, Subscriber, AccessModel, SendLast, PresenceSubscription, RosterGroup, Options) ->
114
node_hometree:subscribe_node(NodeId, Sender, Subscriber, AccessModel, SendLast, PresenceSubscription, RosterGroup, Options).
116
unsubscribe_node(NodeId, Sender, Subscriber, SubID) ->
117
node_hometree:unsubscribe_node(NodeId, Sender, Subscriber, SubID).
119
publish_item(NodeId, Publisher, Model, MaxItems, ItemId, Payload) ->
120
node_hometree:publish_item(NodeId, Publisher, Model, MaxItems, ItemId, Payload).
122
remove_extra_items(NodeId, MaxItems, ItemIds) ->
123
node_hometree:remove_extra_items(NodeId, MaxItems, ItemIds).
125
delete_item(NodeId, Publisher, PublishModel, ItemId) ->
126
node_hometree:delete_item(NodeId, Publisher, PublishModel, ItemId).
128
purge_node(NodeId, Owner) ->
129
node_hometree:purge_node(NodeId, Owner).
131
get_entity_affiliations(Host, Owner) ->
132
node_hometree:get_entity_affiliations(Host, Owner).
134
get_node_affiliations(NodeId) ->
135
node_hometree:get_node_affiliations(NodeId).
137
get_affiliation(NodeId, Owner) ->
138
node_hometree:get_affiliation(NodeId, Owner).
140
set_affiliation(NodeId, Owner, Affiliation) ->
141
node_hometree:set_affiliation(NodeId, Owner, Affiliation).
143
get_entity_subscriptions(Host, Owner) ->
144
node_hometree:get_entity_subscriptions(Host, Owner).
146
get_node_subscriptions(NodeId) ->
147
node_hometree:get_node_subscriptions(NodeId).
149
get_subscriptions(NodeId, Owner) ->
150
node_hometree:get_subscriptions(NodeId, Owner).
152
set_subscriptions(NodeId, Owner, Subscription, SubId) ->
153
node_hometree:set_subscriptions(NodeId, Owner, Subscription, SubId).
155
get_pending_nodes(Host, Owner) ->
156
node_hometree:get_pending_nodes(Host, Owner).
158
get_states(NodeId) ->
159
node_hometree:get_states(NodeId).
161
get_state(NodeId, JID) ->
162
node_hometree:get_state(NodeId, JID).
165
node_hometree:set_state(State).
167
get_items(NodeId, From) ->
168
node_hometree:get_items(NodeId, From).
170
get_items(NodeId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
171
node_hometree:get_items(NodeId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId).
173
get_item(NodeId, ItemId) ->
174
node_hometree:get_item(NodeId, ItemId).
176
get_item(NodeId, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
177
node_hometree:get_item(NodeId, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId).
180
node_hometree:set_item(Item).
182
get_item_name(Host, Node, Id) ->
183
node_hometree:get_item_name(Host, Node, Id).
185
node_to_path(Node) ->
186
[binary_to_list(Node)].
188
path_to_node(Path) ->
191
[Node] -> list_to_binary(Node);
192
% handle old possible entries, used when migrating database content to new format
193
[Node|_] when is_list(Node) -> list_to_binary(string:join([""|Path], "/"));
194
% default case (used by PEP for example)
195
_ -> list_to_binary(Path)