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 |
|
|
27 |
|
-module(node_hometree). |
28 |
|
-behaviour(gen_pubsub_node). |
29 |
|
-author('christophe.romain@process-one.net'). |
30 |
|
|
31 |
|
-include("pubsub.hrl"). |
32 |
|
-include("jlib.hrl"). |
33 |
|
|
34 |
|
-export([based_on/0, init/3, terminate/2, options/0, features/0, |
35 |
|
create_node_permission/6, node_to_path/1, |
36 |
|
path_to_node/1]). |
37 |
|
|
38 |
969 |
based_on() -> node_flat. |
39 |
|
|
40 |
|
init(Host, ServerHost, Opts) -> |
41 |
1 |
node_flat:init(Host, ServerHost, Opts), |
42 |
1 |
Owner = mod_pubsub:service_jid(Host), |
43 |
1 |
mod_pubsub:create_node(Host, ServerHost, <<"/home">>, Owner, <<"hometree">>), |
44 |
1 |
mod_pubsub:create_node(Host, ServerHost, <<"/home/", ServerHost/binary>>, |
45 |
|
Owner, <<"hometree">>), |
46 |
1 |
ok. |
47 |
|
|
48 |
|
terminate(Host, ServerHost) -> |
49 |
1 |
node_flat:terminate(Host, ServerHost). |
50 |
|
|
51 |
|
options() -> |
52 |
91 |
node_flat:options(). |
53 |
|
|
54 |
|
features() -> |
55 |
413 |
node_flat:features(). |
56 |
|
|
57 |
|
%% @doc Checks if the current user has the permission to create the requested node |
58 |
|
%% <p>In hometree node, the permission is decided by the place in the |
59 |
|
%% hierarchy where the user is creating the node. The access parameter is also |
60 |
|
%% checked. This parameter depends on the value of the |
61 |
|
%% <tt>access_createnode</tt> ACL value in ejabberd config file.</p> |
62 |
|
%% <p>This function also check that node can be created as a children of its |
63 |
|
%% parent node</p> |
64 |
|
create_node_permission(Host, _ServerHost, _Node, _ParentNode, |
65 |
|
#jid{ luser = <<>>, lserver = Host, lresource = <<>> }, _Access) -> |
66 |
:-( |
{result, true}; % pubsub service always allowed |
67 |
|
create_node_permission(_Host, ServerHost, Node, _ParentNode, |
68 |
|
#jid{ luser = LUser, lserver = LServer } = Owner, Access) -> |
69 |
7 |
{ok, HostType} = mongoose_domain_api:get_domain_host_type(ServerHost), |
70 |
7 |
case acl:match_rule(HostType, ServerHost, Access, Owner) of |
71 |
|
allow -> |
72 |
7 |
case node_to_path(Node) of |
73 |
7 |
[<<"home">>, LServer, LUser | _] -> {result, true}; |
74 |
:-( |
_ -> {result, false} |
75 |
|
end; |
76 |
:-( |
_ -> {result, false} |
77 |
|
end. |
78 |
|
|
79 |
|
%% @doc <p>Return the path of the node.</p> |
80 |
|
node_to_path(Node) -> |
81 |
105 |
mongoose_bin:tokens(Node, <<"/">>). |
82 |
|
|
83 |
:-( |
path_to_node([]) -> <<>>; |
84 |
11 |
path_to_node(Path) -> mongoose_bin:join([<<"">> | Path], <<"/">>). |