1 // +------------------------------------------------------------------+
2 // | ____ _ _ __ __ _ __ |
3 // | / ___| |__ ___ ___| | __ | \/ | |/ / |
4 // | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
5 // | | |___| | | | __/ (__| < | | | | . \ |
6 // | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
7 // | |
8 // | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
9 // +------------------------------------------------------------------+
10 //
11 // This file is part of Check_MK.
12 // The official homepage is at http://mathias-kettner.de/check_mk.
13 //
14 // check_mk is free software; you can redistribute it and/or modify it
15 // under the terms of the GNU General Public License as published by
16 // the Free Software Foundation in version 2. check_mk is distributed
17 // in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
18 // out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19 // PARTICULAR PURPOSE. See the GNU General Public License for more de-
20 // ails. You should have received a copy of the GNU General Public
21 // License along with GNU Make; see the file COPYING. If not, write
22 // to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 // Boston, MA 02110-1301 USA.
24
25 #include "HostgroupsColumn.h"
26 #include "Query.h"
27
getData(void * data)28 objectlist *HostgroupsColumn::getData(void *data) {
29 if (data != nullptr) {
30 data = shiftPointer(data);
31 if (data != nullptr) {
32 return *reinterpret_cast<objectlist **>(
33 reinterpret_cast<char *>(data) + _offset);
34 }
35 }
36 return nullptr;
37 }
38
output(void * data,Query * query)39 void HostgroupsColumn::output(void *data, Query *query) {
40 query->outputBeginList();
41 objectlist *list = getData(data);
42 if (list != nullptr) {
43 bool first = true;
44 while (list != nullptr) {
45 hostgroup *sg = reinterpret_cast<hostgroup *>(list->object_ptr);
46 if (!first) {
47 query->outputListSeparator();
48 } else {
49 first = false;
50 }
51 query->outputString(sg->group_name);
52 list = list->next;
53 }
54 }
55 query->outputEndList();
56 }
57
getNagiosObject(char * name)58 void *HostgroupsColumn::getNagiosObject(char *name) {
59 return find_hostgroup(name);
60 }
61
isNagiosMember(void * data,void * nagobject)62 bool HostgroupsColumn::isNagiosMember(void *data, void *nagobject) {
63 if ((nagobject == nullptr) || (data == nullptr)) {
64 return false;
65 }
66
67 // data is already shifted (_indirect_offset is taken into account)
68 // But _offset needs still to be accounted for
69 objectlist *list = *reinterpret_cast<objectlist **>(
70 reinterpret_cast<char *>(data) + _offset);
71
72 while (list != nullptr) {
73 if (list->object_ptr == nagobject) {
74 return true;
75 }
76 list = list->next;
77 }
78 return false;
79 }
80
isEmpty(void * data)81 bool HostgroupsColumn::isEmpty(void *data) {
82 objectlist *list = *reinterpret_cast<objectlist **>(
83 reinterpret_cast<char *>(data) + _offset);
84 return list == nullptr;
85 }
86