[checkmk-commits] Fetched livestatus from downstream.

Sven Panne sp at mathias-kettner.de
Tue Dec 27 14:30:32 CET 2016


Module: check_mk
Branch: master
Commit: bc9fdb5ed69654a8a3ca209ddc4c7f3b61460105
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bc9fdb5ed69654a8a3ca209ddc4c7f3b61460105

Author: Sven Panne <sp at mathias-kettner.de>
Date:   Tue Dec 27 14:30:24 2016 +0100

Fetched livestatus from downstream.

Change-Id: I9471628400b78bdcd52142945878f8805e618978

---

 livestatus/src/CustomVarsColumn.cc       | 28 +++++++++++++++-------------
 livestatus/src/CustomVarsColumn.h        |  4 ++--
 livestatus/src/CustomVarsDictColumn.cc   | 11 +++++------
 livestatus/src/CustomVarsNamesColumn.cc  | 16 ++++++----------
 livestatus/src/CustomVarsValuesColumn.cc | 11 +++++------
 livestatus/src/HostFileColumn.cc         |  2 +-
 livestatus/src/LogwatchListColumn.cc     |  2 +-
 livestatus/src/TableStateHistory.cc      |  4 ++--
 8 files changed, 37 insertions(+), 41 deletions(-)

diff --git a/livestatus/src/CustomVarsColumn.cc b/livestatus/src/CustomVarsColumn.cc
index 95adefd..34ee280 100644
--- a/livestatus/src/CustomVarsColumn.cc
+++ b/livestatus/src/CustomVarsColumn.cc
@@ -23,8 +23,11 @@
 // Boston, MA 02110-1301 USA.
 
 #include "CustomVarsColumn.h"
+#include <utility>
+#include "nagios.h"
 
 using std::string;
+using std::unordered_map;
 
 CustomVarsColumn::CustomVarsColumn(string name, string description, int offset,
                                    int indirect_offset, int extra_offset)
@@ -33,21 +36,20 @@ CustomVarsColumn::CustomVarsColumn(string name, string description, int offset,
 
 CustomVarsColumn::~CustomVarsColumn() = default;
 
-customvariablesmember *CustomVarsColumn::getCVM(void *row) {
-    void *data = shiftPointer(row);
-    if (data == nullptr) {
-        return nullptr;
+unordered_map<string, string> CustomVarsColumn::getCVM(void *row) const {
+    unordered_map<string, string> result;
+    if (char *data = static_cast<char *>(shiftPointer(row))) {
+        for (customvariablesmember *cvm =
+                 *reinterpret_cast<customvariablesmember **>(data + _offset);
+             cvm != nullptr; cvm = cvm->next) {
+            result.emplace(cvm->variable_name, cvm->variable_value);
+        }
     }
-    return *reinterpret_cast<customvariablesmember **>(
-        reinterpret_cast<char *>(data) + _offset);
+    return result;
 }
 
 string CustomVarsColumn::getVariable(void *row, const string &varname) {
-    for (customvariablesmember *cvm = getCVM(row); cvm != nullptr;
-         cvm = cvm->next) {
-        if (varname.compare(cvm->variable_name) == 0) {
-            return cvm->variable_value;
-        }
-    }
-    return "";
+    auto cvm = getCVM(row);
+    auto it = cvm.find(varname);
+    return it == cvm.end() ? "" : it->second;
 }
diff --git a/livestatus/src/CustomVarsColumn.h b/livestatus/src/CustomVarsColumn.h
index 548ea9f..5a59f0e 100644
--- a/livestatus/src/CustomVarsColumn.h
+++ b/livestatus/src/CustomVarsColumn.h
@@ -27,8 +27,8 @@
 
 #include "config.h"  // IWYU pragma: keep
 #include <string>
+#include <unordered_map>
 #include "Column.h"
-#include "nagios.h"
 
 class CustomVarsColumn : public Column {
 public:
@@ -41,7 +41,7 @@ public:
 protected:
     const int _offset;  // within data structure (differs from host/service)
 
-    customvariablesmember *getCVM(void *row);
+    std::unordered_map<std::string, std::string> getCVM(void *row) const;
 };
 
 #endif  // CustomVarsColumn_h
diff --git a/livestatus/src/CustomVarsDictColumn.cc b/livestatus/src/CustomVarsDictColumn.cc
index e3c255e..5b79e83 100644
--- a/livestatus/src/CustomVarsDictColumn.cc
+++ b/livestatus/src/CustomVarsDictColumn.cc
@@ -23,6 +23,7 @@
 // Boston, MA 02110-1301 USA.
 
 #include "CustomVarsDictColumn.h"
+#include <utility>
 #include "CustomVarsDictFilter.h"
 #include "Filter.h"
 #include "Renderer.h"
@@ -42,9 +43,8 @@ ColumnType CustomVarsDictColumn::type() { return ColumnType::dict; }
 void CustomVarsDictColumn::output(void *row, RowRenderer &r,
                                   contact * /* auth_user */) {
     DictRenderer d(r);
-    for (customvariablesmember *cvm = getCVM(row); cvm != nullptr;
-         cvm = cvm->next) {
-        d.output(cvm->variable_name, cvm->variable_value);
+    for (const auto &it : getCVM(row)) {
+        d.output(it.first, it.second);
     }
 }
 
@@ -54,9 +54,8 @@ unique_ptr<Filter> CustomVarsDictColumn::createFilter(RelationalOperator relOp,
 }
 
 bool CustomVarsDictColumn::contains(void *row, const string &value) {
-    for (customvariablesmember *cvm = getCVM(row); cvm != nullptr;
-         cvm = cvm->next) {
-        if (value.compare(cvm->variable_value) == 0) {
+    for (const auto &it : getCVM(row)) {
+        if (it.second == value) {
             return true;
         }
     }
diff --git a/livestatus/src/CustomVarsNamesColumn.cc b/livestatus/src/CustomVarsNamesColumn.cc
index 768e3ff..bcf6177 100644
--- a/livestatus/src/CustomVarsNamesColumn.cc
+++ b/livestatus/src/CustomVarsNamesColumn.cc
@@ -23,6 +23,8 @@
 // Boston, MA 02110-1301 USA.
 
 #include "CustomVarsNamesColumn.h"
+#include <unordered_map>
+#include <utility>
 #include "CustomVarsListFilter.h"
 #include "Filter.h"
 #include "Renderer.h"
@@ -42,9 +44,8 @@ ColumnType CustomVarsNamesColumn::type() { return ColumnType::list; }
 void CustomVarsNamesColumn::output(void *row, RowRenderer &r,
                                    contact * /* auth_user */) {
     ListRenderer l(r);
-    for (customvariablesmember *cvm = getCVM(row); cvm != nullptr;
-         cvm = cvm->next) {
-        l.output(string(cvm->variable_name));
+    for (const auto &it : getCVM(row)) {
+        l.output(it.first);
     }
 }
 
@@ -54,11 +55,6 @@ unique_ptr<Filter> CustomVarsNamesColumn::createFilter(RelationalOperator relOp,
 }
 
 bool CustomVarsNamesColumn::contains(void *row, const string &value) {
-    for (customvariablesmember *cvm = getCVM(row); cvm != nullptr;
-         cvm = cvm->next) {
-        if (value.compare(cvm->variable_name) == 0) {
-            return true;
-        }
-    }
-    return false;
+    auto cvm = getCVM(row);
+    return cvm.find(value) != cvm.end();
 }
diff --git a/livestatus/src/CustomVarsValuesColumn.cc b/livestatus/src/CustomVarsValuesColumn.cc
index 7488356..67b7955 100644
--- a/livestatus/src/CustomVarsValuesColumn.cc
+++ b/livestatus/src/CustomVarsValuesColumn.cc
@@ -23,6 +23,7 @@
 // Boston, MA 02110-1301 USA.
 
 #include "CustomVarsValuesColumn.h"
+#include <utility>
 #include "CustomVarsListFilter.h"
 #include "Filter.h"
 #include "Renderer.h"
@@ -42,9 +43,8 @@ ColumnType CustomVarsValuesColumn::type() { return ColumnType::list; }
 void CustomVarsValuesColumn::output(void *row, RowRenderer &r,
                                     contact * /* auth_user */) {
     ListRenderer l(r);
-    for (customvariablesmember *cvm = getCVM(row); cvm != nullptr;
-         cvm = cvm->next) {
-        l.output(string(cvm->variable_value));
+    for (const auto &it : getCVM(row)) {
+        l.output(it.second);
     }
 }
 
@@ -54,9 +54,8 @@ unique_ptr<Filter> CustomVarsValuesColumn::createFilter(
 }
 
 bool CustomVarsValuesColumn::contains(void *row, const string &value) {
-    for (customvariablesmember *cvm = getCVM(row); cvm != nullptr;
-         cvm = cvm->next) {
-        if (value.compare(cvm->variable_value) == 0) {
+    for (const auto &it : getCVM(row)) {
+        if (it.second == value) {
             return true;
         }
     }
diff --git a/livestatus/src/HostFileColumn.cc b/livestatus/src/HostFileColumn.cc
index ca7e202..94a38e6 100644
--- a/livestatus/src/HostFileColumn.cc
+++ b/livestatus/src/HostFileColumn.cc
@@ -61,7 +61,7 @@ unique_ptr<vector<char>> HostFileColumn::getBlob(void *data) {
     }
 
 #ifdef CMC
-    string host_name = static_cast<Host *>(data)->_name;
+    string host_name = static_cast<Host *>(data)->name();
 #else
     string host_name = static_cast<host *>(data)->name;
 #endif
diff --git a/livestatus/src/LogwatchListColumn.cc b/livestatus/src/LogwatchListColumn.cc
index ce0b99c..aee5d38 100644
--- a/livestatus/src/LogwatchListColumn.cc
+++ b/livestatus/src/LogwatchListColumn.cc
@@ -42,7 +42,7 @@ void LogwatchListColumn::output(void *row, RowRenderer &r,
 
 #ifdef CMC
     Host *host = static_cast<Host *>(data);
-    string host_name = host->_name;
+    string host_name = host->name();
 #else
     host *hst = static_cast<host *>(data);
     string host_name = hst->name;
diff --git a/livestatus/src/TableStateHistory.cc b/livestatus/src/TableStateHistory.cc
index 135c11e..3b10117 100644
--- a/livestatus/src/TableStateHistory.cc
+++ b/livestatus/src/TableStateHistory.cc
@@ -512,10 +512,10 @@ void TableStateHistory::answerQuery(Query *query) {
                     state->_host = entry->_host;
                     state->_service = entry->_service;
 #ifdef CMC
-                    state->_host_name = entry->_host->_name.c_str();
+                    state->_host_name = entry->_host->name().c_str();
                     state->_service_description =
                         entry->_service != nullptr
-                            ? entry->_service->_name.c_str()
+                            ? entry->_service->name().c_str()
                             : "";
 #else
                     state->_host_name = entry->_host->name;



More information about the checkmk-commits mailing list