./ct_report/coverage/node_pep.COVER.html

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/.
7 %%%
8 %%%
9 %%% Software distributed under the License is distributed on an "AS IS"
10 %%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11 %%% the License for the specific language governing rights and limitations
12 %%% under the License.
13 %%%
14 %%%
15 %%% The Initial Developer of the Original Code is ProcessOne.
16 %%% Portions created by ProcessOne are Copyright 2006-2015, ProcessOne
17 %%% All Rights Reserved.''
18 %%% This software is copyright 2006-2015, ProcessOne.
19 %%%
20 %%% @copyright 2006-2015 ProcessOne
21 %%% @author Christophe Romain <christophe.romain@process-one.net>
22 %%% [http://www.process-one.net/]
23 %%% @end
24 %%% ====================================================================
25
26 -module(node_pep).
27 -behaviour(gen_pubsub_node).
28 -author('christophe.romain@process-one.net').
29
30 -include("mongoose.hrl").
31 -include("pubsub.hrl").
32 -include("jlib.hrl").
33
34 %%% @doc The module <strong>{@module}</strong> is the pep PubSub plugin.
35 %%% <p>PubSub plugin nodes are using the {@link gen_pubsub_node} behaviour.</p>
36
37 -export([based_on/0, init/3, terminate/2, options/0, features/0,
38 create_node_permission/6, delete_node/1,
39 unsubscribe_node/4, node_to_path/1,
40 get_entity_affiliations/2, get_entity_affiliations/3,
41 get_entity_subscriptions/2, get_entity_subscriptions/4,
42 should_delete_when_owner_removed/0
43 ]).
44
45 -ignore_xref([get_entity_affiliations/3, get_entity_subscriptions/4]).
46
47
:-(
based_on() -> node_flat.
48
49 init(Host, ServerHost, Opts) ->
50
:-(
node_flat:init(Host, ServerHost, Opts),
51
:-(
complain_if_modcaps_disabled(ServerHost),
52
:-(
ok.
53
54 terminate(Host, ServerHost) ->
55
:-(
node_flat:terminate(Host, ServerHost),
56
:-(
ok.
57
58 options() ->
59
:-(
[{deliver_payloads, true},
60 {notify_config, false},
61 {notify_delete, false},
62 {notify_retract, false},
63 {purge_offline, false},
64 {persist_items, true},
65 {max_items, 1},
66 {subscribe, true},
67 {access_model, presence},
68 {roster_groups_allowed, []},
69 {publish_model, publishers},
70 {notification_type, headline},
71 {max_payload_size, ?MAX_PAYLOAD_SIZE},
72 {send_last_published_item, on_sub_and_presence},
73 {deliver_notifications, true},
74 {presence_based_delivery, true}].
75
76 features() ->
77
:-(
[<<"create-nodes">>,
78 <<"auto-create">>,
79 <<"auto-subscribe">>,
80 <<"delete-nodes">>,
81 <<"delete-items">>,
82 <<"filtered-notifications">>,
83 <<"modify-affiliations">>,
84 <<"outcast-affiliation">>,
85 <<"persistent-items">>,
86 <<"publish">>,
87 <<"publish-options">>,
88 <<"purge-nodes">>,
89 <<"retract-items">>,
90 <<"retrieve-affiliations">>,
91 <<"retrieve-items">>,
92 <<"retrieve-subscriptions">>,
93 <<"subscribe">>].
94
95 create_node_permission(Host, _ServerHost, _Node, _ParentNode,
96 #jid{ luser = <<>>, lserver = Host, lresource = <<>> }, _Access) ->
97
:-(
{result, true}; % pubsub service always allowed
98 create_node_permission(Host, ServerHost, _Node, _ParentNode,
99 #jid{ luser = User, lserver = Server } = Owner, Access) ->
100
:-(
{ok, HostType} = mongoose_domain_api:get_domain_host_type(ServerHost),
101
:-(
case acl:match_rule(HostType, ServerHost, Access, Owner) of
102 allow ->
103
:-(
case Host of
104
:-(
{User, Server, _} -> {result, true};
105
:-(
_ -> {result, false}
106 end;
107 _ ->
108
:-(
{result, false}
109 end.
110
111 delete_node(Nodes) ->
112
:-(
{result, {_, _, Result}} = node_flat:delete_node(Nodes),
113
:-(
{result, {[], Result}}.
114
115 unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
116
:-(
case node_flat:unsubscribe_node(Nidx, Sender, Subscriber, SubId) of
117
:-(
{error, Error} -> {error, Error};
118
:-(
{result, _} -> {result, []}
119 end.
120
121 get_entity_affiliations(Host, #jid{ lserver = D } = Owner) ->
122
:-(
get_entity_affiliations(Host, D, jid:to_lower(Owner));
123 get_entity_affiliations(Host, {_, D, _} = Owner) ->
124
:-(
get_entity_affiliations(Host, D, Owner).
125
126 get_entity_affiliations(Host, D, Owner) ->
127
:-(
{ok, States} = mod_pubsub_db_backend:get_states_by_bare(Owner),
128
:-(
NodeTree = mod_pubsub:tree(Host),
129
:-(
Reply = lists:foldl(fun (#pubsub_state{stateid = {_, N}, affiliation = A}, Acc) ->
130
:-(
case gen_pubsub_nodetree:get_node(NodeTree, N) of
131
:-(
#pubsub_node{nodeid = {{_, D, _}, _}} = Node -> [{Node, A} | Acc];
132
:-(
_ -> Acc
133 end
134 end,
135 [], States),
136
:-(
{result, Reply}.
137
138 get_entity_subscriptions(Host, #jid{ lserver = D, lresource = R } = Owner) ->
139
:-(
get_entity_subscriptions(Host, D, R, Owner);
140 get_entity_subscriptions(Host, {_, D, R} = Owner) ->
141
:-(
get_entity_subscriptions(Host, D, R, Owner).
142
143 get_entity_subscriptions(Host, D, R, Owner) ->
144
:-(
LOwner = jid:to_lower(Owner),
145
:-(
States = case R of
146 <<>> ->
147
:-(
{ok, States0} = mod_pubsub_db_backend:get_states_by_lus(LOwner),
148
:-(
States0;
149 _ ->
150
:-(
{ok, States0} = mod_pubsub_db_backend:get_states_by_bare_and_full(LOwner),
151
:-(
States0
152 end,
153
:-(
NodeTree = mod_pubsub:tree(Host),
154
:-(
Reply = lists:foldl(fun (#pubsub_state{stateid = {J, N}, subscriptions = Ss}, Acc) ->
155
:-(
case gen_pubsub_nodetree:get_node(NodeTree, N) of
156 #pubsub_node{nodeid = {{_, D, _}, _}} = Node ->
157
:-(
accumulate_entity_subscriptions(J, Node, Ss, Acc);
158 _ ->
159
:-(
Acc
160 end
161 end,
162 [], States),
163
:-(
{result, Reply}.
164
165 accumulate_entity_subscriptions(J, Node, Ss, Acc) ->
166
:-(
lists:foldl(fun({subscribed, SubId}, Acc2) ->
167
:-(
[{Node, subscribed, SubId, J} | Acc2];
168 ({pending, _SubId}, Acc2) ->
169
:-(
[{Node, pending, J} | Acc2];
170 (S, Acc2) ->
171
:-(
[{Node, S, J} | Acc2]
172 end, Acc, Ss).
173
174
175 node_to_path(Node) ->
176
:-(
node_flat:node_to_path(Node).
177
178
:-(
should_delete_when_owner_removed() -> true.
179
180 %%%
181 %%% Internal
182 %%%
183
184 %% @doc Check mod_caps is enabled, otherwise show warning.
185 %% The PEP plugin for mod_pubsub requires mod_caps to be enabled in the host.
186 %% Check that the mod_caps module is enabled in that Jabber Host
187 %% If not, log a warning message.
188 complain_if_modcaps_disabled(ServerHost) ->
189
:-(
?WARNING_MSG_IF(
190
:-(
not gen_mod:is_loaded(ServerHost, mod_caps),
191 "The PEP plugin is enabled in mod_pubsub "
192 "of host ~p. This plugin requires mod_caps "
193 "to be enabled, but it isn't.",
194
:-(
[ServerHost]).
Line Hits Source