From 71dc682924716de9c2c04db6046d0251a31bbd39 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 18 Aug 2015 16:53:30 +0200 Subject: [PATCH] Implement support for "." in attributes when creating objects refs #9082 --- lib/config/configwriter.cpp | 15 ++++++++++++++- lib/remote/configobjectutility.cpp | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/config/configwriter.cpp b/lib/config/configwriter.cpp index d704208dd..a113ad5ac 100644 --- a/lib/config/configwriter.cpp +++ b/lib/config/configwriter.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include @@ -93,7 +95,18 @@ void ConfigWriter::EmitScope(int indentLevel, const Dictionary::Ptr& val, const BOOST_FOREACH(const Dictionary::Pair& kv, val) { m_FP << "\n"; EmitIndent(indentLevel); - EmitIdentifier(kv.first, true); + + std::vector tokens; + boost::algorithm::split(tokens, kv.first, boost::is_any_of(".")); + + EmitIdentifier(tokens[0], true); + + for (std::vector::size_type i = 1; i < tokens.size(); i++) { + m_FP << "["; + EmitString(tokens[i]); + m_FP << "]"; + } + m_FP << " = "; EmitValue(indentLevel + 1, kv.second); } diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index b4e097fc9..18b865b3c 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -24,6 +24,8 @@ #include "config/configwriter.hpp" #include "base/exception.hpp" #include "base/serializer.hpp" +#include +#include #include using namespace icinga; @@ -77,8 +79,17 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full if (attrs) { ObjectLock olock(attrs); BOOST_FOREACH(const Dictionary::Pair& kv, attrs) { - SetExpression *expr = new SetExpression(MakeIndexer(ScopeThis, kv.first), OpSetLiteral, MakeLiteral(kv.second)); - builder->AddExpression(expr); + std::vector tokens; + boost::algorithm::split(tokens, kv.first, boost::is_any_of(".")); + + Expression *expr = new GetScopeExpression(ScopeThis); + + BOOST_FOREACH(const String& val, tokens) { + expr = new IndexerExpression(expr, MakeLiteral(val)); + } + + SetExpression *aexpr = new SetExpression(expr, OpSetLiteral, MakeLiteral(kv.second)); + builder->AddExpression(aexpr); } } -- 2.50.1