diff --git a/lib/config/aexpression.cpp b/lib/config/aexpression.cpp index 68cdc49b6..3e9e53f99 100644 --- a/lib/config/aexpression.cpp +++ b/lib/config/aexpression.cpp @@ -299,14 +299,16 @@ Value AExpression::OpDict(const AExpression *expr, const Dictionary::Ptr& locals Value AExpression::OpSet(const AExpression *expr, const Dictionary::Ptr& locals) { + Value index = expr->EvaluateOperand1(locals); Value right = expr->EvaluateOperand2(locals); - locals->Set(expr->m_Operand1, right); + locals->Set(index, right); return right; } Value AExpression::OpSetPlus(const AExpression *expr, const Dictionary::Ptr& locals) { - Value left = locals->Get(expr->m_Operand1); + Value index = expr->EvaluateOperand1(locals); + Value left = locals->Get(index); AExpression::Ptr exp_right = expr->m_Operand2; Dictionary::Ptr xlocals = locals; @@ -326,13 +328,14 @@ Value AExpression::OpSetPlus(const AExpression *expr, const Dictionary::Ptr& loc dict->Remove("__parent"); } - locals->Set(expr->m_Operand1, result); + locals->Set(index, result); return result; } Value AExpression::OpSetMinus(const AExpression *expr, const Dictionary::Ptr& locals) { - Value left = locals->Get(expr->m_Operand1); + Value index = expr->EvaluateOperand1(locals); + Value left = locals->Get(index); AExpression::Ptr exp_right = expr->m_Operand2; Dictionary::Ptr xlocals = locals; @@ -352,13 +355,14 @@ Value AExpression::OpSetMinus(const AExpression *expr, const Dictionary::Ptr& lo dict->Remove("__parent"); } - locals->Set(expr->m_Operand1, result); + locals->Set(index, result); return result; } Value AExpression::OpSetMultiply(const AExpression *expr, const Dictionary::Ptr& locals) { - Value left = locals->Get(expr->m_Operand1); + Value index = expr->EvaluateOperand1(locals); + Value left = locals->Get(index); AExpression::Ptr exp_right = expr->m_Operand2; Dictionary::Ptr xlocals = locals; @@ -378,13 +382,14 @@ Value AExpression::OpSetMultiply(const AExpression *expr, const Dictionary::Ptr& dict->Remove("__parent"); } - locals->Set(expr->m_Operand1, result); + locals->Set(index, result); return result; } Value AExpression::OpSetDivide(const AExpression *expr, const Dictionary::Ptr& locals) { - Value left = locals->Get(expr->m_Operand1); + Value index = expr->EvaluateOperand1(locals); + Value left = locals->Get(index); AExpression::Ptr exp_right = expr->m_Operand2; Dictionary::Ptr xlocals = locals; @@ -404,7 +409,7 @@ Value AExpression::OpSetDivide(const AExpression *expr, const Dictionary::Ptr& l dict->Remove("__parent"); } - locals->Set(expr->m_Operand1, result); + locals->Set(index, result); return result; } diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index afd41f0e6..0d093e76f 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -524,36 +524,43 @@ lterm_items_inner: /* empty */ lterm: identifier lbinary_op rterm { - AExpression::Ptr aexpr = static_cast(*$3); - $$ = new Value(make_shared($2, $1, aexpr, DebugInfoRange(@1, @3))); + AExpression::Ptr aindex = make_shared(&AExpression::OpLiteral, $1, @1); free($1); + + AExpression::Ptr aexpr = static_cast(*$3); + $$ = new Value(make_shared($2, aindex, aexpr, DebugInfoRange(@1, @3))); delete $3; } - | identifier '[' T_STRING ']' lbinary_op rterm + | identifier '[' rterm ']' lbinary_op rterm { - AExpression::Ptr subexpr = make_shared($5, $3, static_cast(*$6), DebugInfoRange(@1, @6)); - free($3); + AExpression::Ptr subexpr = make_shared($5, static_cast(*$3), static_cast(*$6), DebugInfoRange(@1, @6)); + delete $3; delete $6; Array::Ptr subexprl = make_shared(); subexprl->Add(subexpr); - AExpression::Ptr expr = make_shared(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @6)); - $$ = new Value(make_shared(&AExpression::OpSetPlus, $1, expr, DebugInfoRange(@1, @6))); + AExpression::Ptr aindex = make_shared(&AExpression::OpLiteral, $1, @1); free($1); + + AExpression::Ptr expr = make_shared(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @6)); + $$ = new Value(make_shared(&AExpression::OpSetPlus, aindex, expr, DebugInfoRange(@1, @6))); } | identifier '.' T_IDENTIFIER lbinary_op rterm { - AExpression::Ptr subexpr = make_shared($4, $3, static_cast(*$5), DebugInfoRange(@1, @5)); + AExpression::Ptr aindex = make_shared(&AExpression::OpLiteral, $1, @1); + AExpression::Ptr subexpr = make_shared($4, aindex, static_cast(*$5), DebugInfoRange(@1, @5)); free($3); delete $5; Array::Ptr subexprl = make_shared(); subexprl->Add(subexpr); - AExpression::Ptr expr = make_shared(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @5)); - $$ = new Value(make_shared(&AExpression::OpSetPlus, $1, expr, DebugInfoRange(@1, @5))); + AExpression::Ptr aindexl = make_shared(&AExpression::OpLiteral, $1, @1); free($1); + + AExpression::Ptr expr = make_shared(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @5)); + $$ = new Value(make_shared(&AExpression::OpSetPlus, aindexl, expr, DebugInfoRange(@1, @5))); } | T_IMPORT rterm { diff --git a/lib/config/configitembuilder.cpp b/lib/config/configitembuilder.cpp index dc4f20b7f..4a6a8d6dd 100644 --- a/lib/config/configitembuilder.cpp +++ b/lib/config/configitembuilder.cpp @@ -88,7 +88,12 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void) Array::Ptr exprs = make_shared(); Array::Ptr templateArray = make_shared(); templateArray->Add(m_Name); - exprs->Add(make_shared(&AExpression::OpSetPlus, "templates", make_shared(&AExpression::OpLiteral, templateArray, m_DebugInfo), m_DebugInfo)); + + exprs->Add(make_shared(&AExpression::OpSetPlus, + make_shared(&AExpression::OpLiteral, "templates", m_DebugInfo), + make_shared(&AExpression::OpLiteral, templateArray, m_DebugInfo), + m_DebugInfo)); + exprs->Add(make_shared(&AExpression::OpDict, m_Expressions, true, m_DebugInfo)); AExpression::Ptr exprl = make_shared(&AExpression::OpDict, exprs, true, m_DebugInfo); diff --git a/lib/icinga/dependency-apply.cpp b/lib/icinga/dependency-apply.cpp index 24d614206..a99b10a24 100644 --- a/lib/icinga/dependency-apply.cpp +++ b/lib/icinga/dependency-apply.cpp @@ -67,8 +67,15 @@ void Dependency::EvaluateApplyRules(const std::vector& rules) builder->SetName(name); builder->SetScope(rule.GetScope()); - builder->AddExpression(make_shared(&AExpression::OpSet, "child_host", make_shared(&AExpression::OpLiteral, service->GetHost()->GetName(), di), di)); - builder->AddExpression(make_shared(&AExpression::OpSet, "child_service", make_shared(&AExpression::OpLiteral, service->GetShortName(), di), di)); + builder->AddExpression(make_shared(&AExpression::OpSet, + make_shared(&AExpression::OpLiteral, "child_host", di), + make_shared(&AExpression::OpLiteral, service->GetHost()->GetName(), + di), di)); + + builder->AddExpression(make_shared(&AExpression::OpSet, + make_shared(&AExpression::OpLiteral, "child_service", di), + make_shared(&AExpression::OpLiteral, service->GetShortName(), di), di)); + builder->AddExpression(rule.GetExpression()); ConfigItem::Ptr serviceItem = builder->Compile(); diff --git a/lib/icinga/notification-apply.cpp b/lib/icinga/notification-apply.cpp index 48e6bdd22..557f6e124 100644 --- a/lib/icinga/notification-apply.cpp +++ b/lib/icinga/notification-apply.cpp @@ -67,8 +67,16 @@ void Notification::EvaluateApplyRules(const std::vector& rules) builder->SetName(name); builder->SetScope(rule.GetScope()); - builder->AddExpression(make_shared(&AExpression::OpSet, "host", make_shared(&AExpression::OpLiteral, service->GetHost()->GetName(), di), di)); - builder->AddExpression(make_shared(&AExpression::OpSet, "service", make_shared(&AExpression::OpLiteral, service->GetShortName(), di), di)); + builder->AddExpression(make_shared(&AExpression::OpSet, + make_shared(&AExpression::OpLiteral, "host", di), + make_shared(&AExpression::OpLiteral, service->GetHost()->GetName(), di), + di)); + + builder->AddExpression(make_shared(&AExpression::OpSet, + make_shared(&AExpression::OpLiteral, "service", di), + make_shared(&AExpression::OpLiteral, service->GetShortName(), di), + di)); + builder->AddExpression(rule.GetExpression()); ConfigItem::Ptr serviceItem = builder->Compile(); diff --git a/lib/icinga/scheduleddowntime-apply.cpp b/lib/icinga/scheduleddowntime-apply.cpp index 3ade63bf0..ff1ffb127 100644 --- a/lib/icinga/scheduleddowntime-apply.cpp +++ b/lib/icinga/scheduleddowntime-apply.cpp @@ -67,8 +67,16 @@ void ScheduledDowntime::EvaluateApplyRules(const std::vector& rules) builder->SetName(name); builder->SetScope(rule.GetScope()); - builder->AddExpression(make_shared(&AExpression::OpSet, "host", make_shared(&AExpression::OpLiteral, service->GetHost()->GetName(), di), di)); - builder->AddExpression(make_shared(&AExpression::OpSet, "service", make_shared(&AExpression::OpLiteral, service->GetShortName(), di), di)); + builder->AddExpression(make_shared(&AExpression::OpSet, + make_shared(&AExpression::OpLiteral, "host", di), + make_shared(&AExpression::OpLiteral, service->GetHost()->GetName(), di), + di)); + + builder->AddExpression(make_shared(&AExpression::OpSet, + make_shared(&AExpression::OpLiteral, "service", di), + make_shared(&AExpression::OpLiteral, service->GetShortName(), di), + di)); + builder->AddExpression(rule.GetExpression()); ConfigItem::Ptr serviceItem = builder->Compile(); diff --git a/lib/icinga/service-apply.cpp b/lib/icinga/service-apply.cpp index 89044285c..6433237e8 100644 --- a/lib/icinga/service-apply.cpp +++ b/lib/icinga/service-apply.cpp @@ -66,8 +66,16 @@ void Service::EvaluateApplyRules(const std::vector& rules) builder->SetName(name); builder->SetScope(rule.GetScope()); - builder->AddExpression(make_shared(&AExpression::OpSet, "host", make_shared(&AExpression::OpLiteral, host->GetName(), di), di)); - builder->AddExpression(make_shared(&AExpression::OpSet, "short_name", make_shared(&AExpression::OpLiteral, rule.GetName(), di), di)); + builder->AddExpression(make_shared(&AExpression::OpSet, + make_shared(&AExpression::OpLiteral, "host", di), + make_shared(&AExpression::OpLiteral, host->GetName(), di), + di)); + + builder->AddExpression(make_shared(&AExpression::OpSet, + make_shared(&AExpression::OpLiteral, "short_name", di), + make_shared(&AExpression::OpLiteral, rule.GetName(), di), + di)); + builder->AddExpression(rule.GetExpression()); ConfigItem::Ptr serviceItem = builder->Compile();