]> granicus.if.org Git - icinga2/blob - lib/remote/zone.cpp
Make sure we don't include zones.d directories for zones which were removed
[icinga2] / lib / remote / zone.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #include "remote/zone.hpp"
21 #include "remote/apiclient.hpp"
22 #include "base/objectlock.hpp"
23 #include <boost/foreach.hpp>
24
25 using namespace icinga;
26
27 REGISTER_TYPE(Zone);
28
29 Zone::Ptr Zone::GetParent(void) const
30 {
31         return Zone::GetByName(GetParentRaw());
32 }
33
34 std::set<Endpoint::Ptr> Zone::GetEndpoints(void) const
35 {
36         std::set<Endpoint::Ptr> result;
37
38         Array::Ptr endpoints = GetEndpointsRaw();
39
40         if (endpoints) {
41                 ObjectLock olock(endpoints);
42
43                 BOOST_FOREACH(const String& name, endpoints) {
44                         Endpoint::Ptr endpoint = Endpoint::GetByName(name);
45
46                         if (!endpoint)
47                                 continue;
48
49                         result.insert(endpoint);
50                 }
51         }
52
53         return result;
54 }
55
56 bool Zone::CanAccessObject(const DynamicObject::Ptr& object)
57 {
58         Zone::Ptr object_zone;
59
60         if (dynamic_pointer_cast<Zone>(object))
61                 object_zone = static_pointer_cast<Zone>(object);
62         else
63                 object_zone = Zone::GetByName(object->GetZone());
64
65         if (!object_zone)
66                 object_zone = Zone::GetLocalZone();
67
68         return object_zone->IsChildOf(this);
69 }
70
71 bool Zone::IsChildOf(const Zone::Ptr& zone)
72 {
73         Zone::Ptr azone = this;
74
75         while (azone) {
76                 if (azone == zone)
77                         return true;
78
79                 azone = azone->GetParent();
80         }
81
82         return false;
83 }
84
85 bool Zone::IsGlobal(void) const
86 {
87         return GetGlobal();
88 }
89
90 Zone::Ptr Zone::GetLocalZone(void)
91 {
92         Endpoint::Ptr local = Endpoint::GetLocalEndpoint();
93
94         if (!local)
95                 return Zone::Ptr();
96
97         return local->GetZone();
98 }