Module: check_mk
Branch: master
Commit: 5707eb8b31389903c763ea6182ef41250d676e47
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5707eb8b313899…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Jul 6 10:08:20 2016 +0200
Fetched Livestatus from upstream.
---
livestatus/src/Column.cc | 7 +++++++
livestatus/src/Column.h | 6 ++----
livestatus/src/CustomVarsFilter.cc | 14 ++++++--------
livestatus/src/Filter.cc | 18 ++++++++++++++----
livestatus/src/Filter.h | 30 ++++++++----------------------
livestatus/src/Query.cc | 17 +++++++----------
livestatus/src/StringFilter.cc | 14 ++++++--------
7 files changed, 50 insertions(+), 56 deletions(-)
diff --git a/livestatus/src/Column.cc b/livestatus/src/Column.cc
index d68be5e..18925a2 100644
--- a/livestatus/src/Column.cc
+++ b/livestatus/src/Column.cc
@@ -23,8 +23,10 @@
// Boston, MA 02110-1301 USA.
#include "Column.h"
+#include <stdexcept>
#include <utility>
+using std::runtime_error;
using std::string;
Column::Column(string name, string description, int indirect_offset,
@@ -62,3 +64,8 @@ void *Column::shiftPointer(void *data) const {
return data;
}
+
+Filter *Column::createFilter(Query * /*unused*/, RelationalOperator /*unused*/,
+ const std::string & /*unused*/) {
+ throw runtime_error("filtering on column " + _name + " not
supported");
+}
diff --git a/livestatus/src/Column.h b/livestatus/src/Column.h
index ab9a0c7..9819db7 100644
--- a/livestatus/src/Column.h
+++ b/livestatus/src/Column.h
@@ -55,10 +55,8 @@ public:
virtual bool mustDelete() {
return false; // true for dynamic Columns to be deleted after Query
}
- virtual Filter *createFilter(Query * /*unused*/, RelationalOperator,
- const std::string &) {
- return nullptr;
- }
+ virtual Filter *createFilter(Query *, RelationalOperator,
+ const std::string &);
};
#endif // Column_h
diff --git a/livestatus/src/CustomVarsFilter.cc b/livestatus/src/CustomVarsFilter.cc
index ebe8251..1ec8328 100644
--- a/livestatus/src/CustomVarsFilter.cc
+++ b/livestatus/src/CustomVarsFilter.cc
@@ -26,11 +26,12 @@
#include <ctype.h>
#include <string.h>
#include <ostream>
+#include <stdexcept>
#include "Column.h"
#include "CustomVarsColumn.h"
#include "Logger.h"
-#include "OutputBuffer.h"
+using std::runtime_error;
using std::string;
CustomVarsFilter::CustomVarsFilter(Query *query, CustomVarsColumn *column,
@@ -66,9 +67,8 @@ CustomVarsFilter::CustomVarsFilter(Query *query, CustomVarsColumn
*column,
case RelationalOperator::doesnt_match_icase:
if (strchr(search_space, '{') != nullptr ||
strchr(search_space, '}') != nullptr) {
- setError(OutputBuffer::ResponseCode::invalid_header,
- "disallowed regular expression '" + string(value)
+
- "': must not contain { or }");
+ throw runtime_error("disallowed regular expression '" +
value +
+ "': must not contain { or }");
} else {
_regex = new regex_t();
bool ignore_case =
@@ -77,11 +77,9 @@ CustomVarsFilter::CustomVarsFilter(Query *query, CustomVarsColumn
*column,
if (regcomp(_regex, search_space,
REG_EXTENDED | REG_NOSUB |
(ignore_case ? REG_ICASE : 0)) != 0) {
- setError(
- OutputBuffer::ResponseCode::invalid_header,
- "invalid regular expression '" + string(value) +
"'");
delete _regex;
- _regex = nullptr;
+ throw runtime_error("invalid regular expression '" +
value +
+ "'");
}
}
break;
diff --git a/livestatus/src/Filter.cc b/livestatus/src/Filter.cc
index d46542f..349489c 100644
--- a/livestatus/src/Filter.cc
+++ b/livestatus/src/Filter.cc
@@ -24,8 +24,18 @@
#include "Filter.h"
-void Filter::setError(OutputBuffer::ResponseCode code,
- const std::string &message) {
- _error_message = message;
- _error_code = code;
+Filter::Filter(Query *query) : _query(query) {}
+
+Filter::~Filter() = default;
+
+void *Filter::indexFilter(const std::string & /* column_name */) {
+ return nullptr;
+}
+
+void Filter::findIntLimits(const std::string & /* column_name */,
+ int * /* lower */, int * /* upper */) {}
+
+bool Filter::optimizeBitmask(const std::string & /* column_name */,
+ uint32_t * /* mask */) {
+ return false;
}
diff --git a/livestatus/src/Filter.h b/livestatus/src/Filter.h
index f70c73d..53a6abc 100644
--- a/livestatus/src/Filter.h
+++ b/livestatus/src/Filter.h
@@ -28,38 +28,24 @@
#include "config.h" // IWYU pragma: keep
#include <stdint.h>
#include <string>
-#include "OutputBuffer.h"
class FilterVisitor;
class Query;
class Filter {
public:
- explicit Filter(Query *query)
- : _query(query), _error_code(OutputBuffer::ResponseCode::ok) {}
- virtual ~Filter() {}
+ explicit Filter(Query *query);
+ virtual ~Filter();
virtual void accept(FilterVisitor &) = 0;
- std::string errorMessage() const { return _error_message; }
- OutputBuffer::ResponseCode errorCode() const { return _error_code; }
- bool hasError() const { return _error_message != ""; }
Query *query() const { return _query; }
virtual bool accepts(void *data) = 0;
- virtual void *indexFilter(const std::string & /* column_name */) {
- return nullptr;
- }
- virtual void findIntLimits(const std::string & /* column_name */,
- int * /* lower */, int * /* upper */) {}
- virtual bool optimizeBitmask(const std::string & /* column_name */,
- uint32_t * /* mask */) {
- return false;
- }
-
-protected:
- void setError(OutputBuffer::ResponseCode code, const std::string &message);
+ virtual void *indexFilter(const std::string &column_name);
+ virtual void findIntLimits(const std::string &column_name, int *lower,
+ int *upper);
+ virtual bool optimizeBitmask(const std::string &column_name,
+ uint32_t *mask);
private:
- Query *_query;
- OutputBuffer::ResponseCode _error_code;
- std::string _error_message;
+ Query *const _query;
};
#endif // Filter_h
diff --git a/livestatus/src/Query.cc b/livestatus/src/Query.cc
index 7d583b1..705c213 100644
--- a/livestatus/src/Query.cc
+++ b/livestatus/src/Query.cc
@@ -30,6 +30,7 @@
#include <string.h>
#include <memory>
#include <ostream>
+#include <stdexcept>
#include <utility>
#include <vector>
#include "Aggregator.h"
@@ -55,6 +56,7 @@ extern unsigned long g_max_response_size;
extern int g_data_encoding;
using std::list;
+using std::runtime_error;
using std::string;
using std::to_string;
using std::unordered_set;
@@ -263,19 +265,14 @@ void Query::setError(OutputBuffer::ResponseCode code, const string
&message) {
Filter *Query::createFilter(Column *column, RelationalOperator relOp,
const string &value) {
- Filter *filter = column->createFilter(this, relOp, value);
- if (filter == nullptr) {
+ try {
+ return column->createFilter(this, relOp, value);
+ } catch (const runtime_error &e) {
setError(OutputBuffer::ResponseCode::invalid_header,
- "cannot create filter on table " +
string(_table->name()));
+ "error creating filter on table" + string(_table->name())
+
+ ": " + e.what());
return nullptr;
}
- if (filter->hasError()) {
- setError(filter->errorCode(),
- "error in Filter header: " + filter->errorMessage());
- delete filter;
- return nullptr;
- }
- return filter;
}
void Query::parseAndOrLine(char *line, LogicalOperator andor,
diff --git a/livestatus/src/StringFilter.cc b/livestatus/src/StringFilter.cc
index a938aaf..db4cfb2 100644
--- a/livestatus/src/StringFilter.cc
+++ b/livestatus/src/StringFilter.cc
@@ -24,10 +24,11 @@
#include "StringFilter.h"
#include <string.h>
-#include "OutputBuffer.h"
+#include <stdexcept>
#include "StringColumn.h"
#include "opids.h"
+using std::runtime_error;
using std::string;
StringFilter::StringFilter(Query *query, StringColumn *column,
@@ -44,9 +45,8 @@ StringFilter::StringFilter(Query *query, StringColumn *column,
case RelationalOperator::doesnt_match_icase:
if (strchr(value.c_str(), '{') != nullptr ||
strchr(value.c_str(), '}') != nullptr) {
- setError(OutputBuffer::ResponseCode::invalid_header,
- "disallowed regular expression '" + string(value)
+
- "': must not contain { or }");
+ throw runtime_error("disallowed regular expression '" +
value +
+ "': must not contain { or }");
} else {
_regex = new regex_t();
bool ignore_case =
@@ -55,11 +55,9 @@ StringFilter::StringFilter(Query *query, StringColumn *column,
if (regcomp(_regex, value.c_str(),
REG_EXTENDED | REG_NOSUB |
(ignore_case ? REG_ICASE : 0)) != 0) {
- setError(
- OutputBuffer::ResponseCode::invalid_header,
- "invalid regular expression '" + string(value) +
"'");
delete _regex;
- _regex = nullptr;
+ throw runtime_error("invalid regular expression '" +
value +
+ "'");
}
}
break;