]> granicus.if.org Git - icinga2/commitdiff
Implement support for "." in attributes when creating objects
authorGunnar Beutner <gunnar@beutner.name>
Tue, 18 Aug 2015 14:53:30 +0000 (16:53 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 18 Aug 2015 14:53:30 +0000 (16:53 +0200)
refs #9082

lib/config/configwriter.cpp
lib/remote/configobjectutility.cpp

index d704208dd32dff1ab67ae485a903e1a29f22f944..a113ad5ac946b6895d706f992816671c77ffb806 100644 (file)
@@ -23,6 +23,8 @@
 #include <boost/foreach.hpp>
 #include <boost/regex.hpp>
 #include <boost/algorithm/string/replace.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/classification.hpp>
 #include <set>
 #include <iterator>
 
@@ -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<String> tokens;
+               boost::algorithm::split(tokens, kv.first, boost::is_any_of("."));
+               
+               EmitIdentifier(tokens[0], true);
+               
+               for (std::vector<String>::size_type i = 1; i < tokens.size(); i++) {
+                       m_FP << "[";
+                       EmitString(tokens[i]);
+                       m_FP << "]";
+               }
+               
                m_FP << " = ";
                EmitValue(indentLevel + 1, kv.second);
        }
index b4e097fc9f0a819f91456c328210b446a63c5911..18b865b3ccfa5e2fddc9bf5aae3694b56e6326f0 100644 (file)
@@ -24,6 +24,8 @@
 #include "config/configwriter.hpp"
 #include "base/exception.hpp"
 #include "base/serializer.hpp"
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/case_conv.hpp>
 
 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<String> 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);
                }
        }