From: Gunnar Beutner Date: Tue, 18 Aug 2015 14:53:30 +0000 (+0200) Subject: Implement support for "." in attributes when creating objects X-Git-Tag: v2.4.0~397 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=71dc682924716de9c2c04db6046d0251a31bbd39;p=icinga2 Implement support for "." in attributes when creating objects refs #9082 --- 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); } }