Module: check_mk
Branch: master
Commit: 97ad2295209dee3d00a279be7e25dd239684c5fa
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=97ad2295209deeā¦
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Aug 9 13:16:34 2017 +0200
Made MonitoringCore and related classes more const-correct.
Change-Id: I76bd58040b5ec0ba17060dc0748a6cc700ff3c0a
---
livestatus/src/MonitoringCore.h | 16 ++++++++-------
livestatus/src/auth.cc | 21 ++++++++++++--------
livestatus/src/auth.h | 2 +-
livestatus/src/module.cc | 43 ++++++++++++++++++++++++-----------------
4 files changed, 48 insertions(+), 34 deletions(-)
diff --git a/livestatus/src/MonitoringCore.h b/livestatus/src/MonitoringCore.h
index 964ee88..10c3e0e 100644
--- a/livestatus/src/MonitoringCore.h
+++ b/livestatus/src/MonitoringCore.h
@@ -66,9 +66,9 @@ public:
virtual Host *getHostByDesignation(const std::string &designation) = 0;
virtual ContactGroup *find_contactgroup(const std::string &name) = 0;
- virtual bool host_has_contact(Host *host, Contact *contact) = 0;
- virtual bool is_contact_member_of_contactgroup(ContactGroup *group,
- Contact *contact) = 0;
+ virtual bool host_has_contact(const Host *host, const Contact *contact) = 0;
+ virtual bool is_contact_member_of_contactgroup(const ContactGroup *group,
+ const Contact *contact) = 0;
virtual std::chrono::system_clock::time_point last_logfile_rotation() = 0;
virtual uint32_t maxLinesPerLogFile() const = 0;
@@ -76,11 +76,13 @@ public:
virtual Command find_command(std::string name) const = 0;
virtual std::vector<Command> commands() const = 0;
- virtual std::vector<DowntimeData> downtimes_for_host(Host *) const = 0;
+ virtual std::vector<DowntimeData> downtimes_for_host(
+ const Host *) const = 0;
virtual std::vector<DowntimeData> downtimes_for_service(
- Service *) const = 0;
- virtual std::vector<CommentData> comments_for_host(Host *) const = 0;
- virtual std::vector<CommentData> comments_for_service(Service *) const = 0;
+ const Service *) const = 0;
+ virtual std::vector<CommentData> comments_for_host(const Host *) const = 0;
+ virtual std::vector<CommentData> comments_for_service(
+ const Service *) const = 0;
virtual bool mkeventdEnabled() = 0;
diff --git a/livestatus/src/auth.cc b/livestatus/src/auth.cc
index 075223d..22a6410 100644
--- a/livestatus/src/auth.cc
+++ b/livestatus/src/auth.cc
@@ -28,21 +28,26 @@
contact *unknown_auth_user() { return reinterpret_cast<contact *>(0xdeadbeaf); }
namespace {
-bool host_has_contact(host *hst, contact *ctc) {
- return is_contact_for_host(hst, ctc) != 0 ||
- is_escalated_contact_for_host(hst, ctc) != 0;
+bool host_has_contact(const host *hst, const contact *ctc) {
+ // Older Nagios headers are not const-correct... :-P
+ return is_contact_for_host(const_cast<host *>(hst),
+ const_cast<contact *>(ctc)) != 0 ||
+ is_escalated_contact_for_host(const_cast<host *>(hst),
+ const_cast<contact *>(ctc)) != 0;
}
-bool service_has_contact(MonitoringCore *mc, host *hst, service *svc,
- contact *ctc) {
- return is_contact_for_service(svc, ctc) != 0 ||
- is_escalated_contact_for_service(svc, ctc) != 0 ||
+bool service_has_contact(MonitoringCore *mc, const host *hst, service *svc,
+ const contact *ctc) {
+ // Older Nagios headers are not const-correct... :-P
+ return is_contact_for_service(svc, const_cast<contact *>(ctc)) != 0 ||
+ is_escalated_contact_for_service(svc, const_cast<contact *>(ctc)) !=
+ 0 ||
(mc->serviceAuthorization() == AuthorizationKind::loose &&
host_has_contact(hst, ctc));
}
} // namespace
-bool is_authorized_for(MonitoringCore *mc, contact *ctc, host *hst,
+bool is_authorized_for(MonitoringCore *mc, const contact *ctc, const host *hst,
service *svc) {
return ctc != unknown_auth_user() &&
(svc == nullptr ? host_has_contact(hst, ctc)
diff --git a/livestatus/src/auth.h b/livestatus/src/auth.h
index 834a49d..15a25f3 100644
--- a/livestatus/src/auth.h
+++ b/livestatus/src/auth.h
@@ -42,7 +42,7 @@ inline contact *unknown_auth_user() {
#else
contact *unknown_auth_user();
class MonitoringCore;
-bool is_authorized_for(MonitoringCore *mc, contact *ctc, host *hst,
+bool is_authorized_for(MonitoringCore *mc, const contact *ctc, const host *hst,
service *svc);
#endif
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 2aea007..1f8bbab 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -587,7 +587,7 @@ public:
: fromImpl(it->second);
}
- bool host_has_contact(Host *host, Contact *contact) override {
+ bool host_has_contact(const Host *host, const Contact *contact) override {
return is_authorized_for(this, toImpl(contact), toImpl(host), nullptr);
}
@@ -596,10 +596,12 @@ public:
return fromImpl(::find_contactgroup(const_cast<char *>(name.c_str())));
}
- bool is_contact_member_of_contactgroup(ContactGroup *group,
- Contact *contact) override {
- return ::is_contact_member_of_contactgroup(toImpl(group),
- toImpl(contact)) != 0;
+ bool is_contact_member_of_contactgroup(const ContactGroup *group,
+ const Contact *contact) override {
+ // Older Nagios headers are not const-correct... :-P
+ return ::is_contact_member_of_contactgroup(
+ const_cast<contactgroup *>(toImpl(group)),
+ const_cast<::contact *>(toImpl(contact))) != 0;
}
system_clock::time_point last_logfile_rotation() override {
@@ -630,20 +632,21 @@ public:
return commands;
}
- vector<DowntimeData> downtimes_for_host(Host *host) const override {
+ vector<DowntimeData> downtimes_for_host(const Host *host) const override {
return downtimes_for_object(toImpl(host), nullptr);
}
vector<DowntimeData> downtimes_for_service(
- Service *service) const override {
+ const Service *service) const override {
return downtimes_for_object(toImpl(service)->host_ptr, toImpl(service));
}
- vector<CommentData> comments_for_host(Host *host) const override {
+ vector<CommentData> comments_for_host(const Host *host) const override {
return comments_for_object(toImpl(host), nullptr);
}
- vector<CommentData> comments_for_service(Service *service) const override {
+ vector<CommentData> comments_for_service(
+ const Service *service) const override {
return comments_for_object(toImpl(service)->host_ptr, toImpl(service));
}
@@ -687,26 +690,29 @@ public:
private:
void *implInternal() const override { return fl_store; }
- static contact *toImpl(Contact *c) {
- return reinterpret_cast<contact *>(c);
+ static const contact *toImpl(const Contact *c) {
+ return reinterpret_cast<const contact *>(c);
}
- static contactgroup *toImpl(ContactGroup *g) {
- return reinterpret_cast<contactgroup *>(g);
+ static const contactgroup *toImpl(const ContactGroup *g) {
+ return reinterpret_cast<const contactgroup *>(g);
}
static ContactGroup *fromImpl(contactgroup *g) {
return reinterpret_cast<ContactGroup *>(g);
}
- static host *toImpl(Host *h) { return reinterpret_cast<host *>(h); }
+ static const host *toImpl(const Host *h) {
+ return reinterpret_cast<const host *>(h);
+ }
static Host *fromImpl(host *h) { return reinterpret_cast<Host *>(h); }
- static service *toImpl(Service *h) {
- return reinterpret_cast<service *>(h);
+ static const service *toImpl(const Service *h) {
+ return reinterpret_cast<const service *>(h);
}
- vector<DowntimeData> downtimes_for_object(::host *h, ::service *s) const {
+ vector<DowntimeData> downtimes_for_object(const ::host *h,
+ const ::service *s) const {
vector<DowntimeData> result;
for (const auto &entry : fl_store->_downtimes) {
auto *dt = static_cast<Downtime *>(entry.second.get());
@@ -717,7 +723,8 @@ private:
return result;
}
- vector<CommentData> comments_for_object(::host *h, ::service *s) const {
+ vector<CommentData> comments_for_object(const ::host *h,
+ const ::service *s) const {
vector<CommentData> result;
for (const auto &entry : fl_store->_comments) {
auto *co = static_cast<Comment *>(entry.second.get());