From 9eeb64a7805074ac0cda67f68b690a2b9b0cc282 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 17 Dec 2014 08:54:28 +0100 Subject: [PATCH] Update livestatus and statusdata to properly support booleans fixes #8100 --- lib/base/convert.hpp | 5 +++++ lib/base/value-operators.cpp | 11 ++++++++++- lib/compat/statusdatawriter.cpp | 2 +- lib/db_ido_mysql/idomysqlconnection.cpp | 2 +- lib/db_ido_pgsql/idopgsqlconnection.cpp | 2 +- lib/livestatus/livestatusquery.cpp | 2 ++ 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/base/convert.hpp b/lib/base/convert.hpp index f637ac8f6..a0e027be7 100644 --- a/lib/base/convert.hpp +++ b/lib/base/convert.hpp @@ -59,6 +59,11 @@ public: } } + static inline long ToLong(const Value& val) + { + return val; + } + static inline double ToDouble(const Value& val) { return val; diff --git a/lib/base/value-operators.cpp b/lib/base/value-operators.cpp index 2ef1541c8..51e998eb2 100644 --- a/lib/base/value-operators.cpp +++ b/lib/base/value-operators.cpp @@ -34,6 +34,11 @@ Value::operator double(void) const if (value) return *value; + const bool *fvalue = boost::get(&m_Value); + + if (fvalue) + return *fvalue; + if (IsEmpty()) return 0; @@ -72,7 +77,11 @@ Value::operator String(void) const std::ostream& icinga::operator<<(std::ostream& stream, const Value& value) { - stream << static_cast(value); + if (value.IsBoolean()) + stream << static_cast(value); + else + stream << static_cast(value); + return stream; } diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 57efb57db..484852a8d 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -522,7 +522,7 @@ void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const CustomVarObj if (kv.first.IsEmpty()) continue; - String value; + Value value; if (kv.second.IsObjectType() || kv.second.IsObjectType()) { value = JsonEncode(kv.second); diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index c84dbe912..69461ebce 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -573,7 +573,7 @@ bool IdoMysqlConnection::FieldToEscapedString(const String& key, const Value& va Value fvalue; if (rawvalue.IsBoolean()) - fvalue = rawvalue.ToBool() ? 1 : 0; + fvalue = Convert::ToLong(rawvalue); else fvalue = rawvalue; diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index b29f6c76d..045adfe98 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -567,7 +567,7 @@ bool IdoPgsqlConnection::FieldToEscapedString(const String& key, const Value& va Value fvalue; if (rawvalue.IsBoolean()) - fvalue = rawvalue.ToBool() ? 1 : 0; + fvalue = Convert::ToLong(rawvalue); else fvalue = rawvalue; diff --git a/lib/livestatus/livestatusquery.cpp b/lib/livestatus/livestatusquery.cpp index 60d5ba79c..990161ffa 100644 --- a/lib/livestatus/livestatusquery.cpp +++ b/lib/livestatus/livestatusquery.cpp @@ -446,6 +446,8 @@ void LivestatusQuery::PrintCsvArray(std::ostream& fp, const Array::Ptr& array, i if (value.IsObjectType()) PrintCsvArray(fp, value, level + 1); + else if (value.IsBoolean()) + fp << Convert::ToLong(value); else fp << value; }