From 89078e1cfb65dd999e8dc5bbb717faad71f5081a Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 21 Jun 2013 09:07:57 +0200 Subject: [PATCH] Config: Fix nested dictionaries in arrays. --- contrib/gdb/gdbinit | 2 ++ lib/config/config_parser.cc | 37 +++++++++++++++++++++++++++---------- lib/config/config_parser.yy | 17 +++++++++++++++++ lib/icinga/host.cpp | 2 -- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/contrib/gdb/gdbinit b/contrib/gdb/gdbinit index f4fe791c6..b15fb55ba 100644 --- a/contrib/gdb/gdbinit +++ b/contrib/gdb/gdbinit @@ -1,3 +1,5 @@ +set env LD_PRELOAD /lib/x86_64-linux-gnu/libpthread.so.0 + python import sys sys.path.insert(0, '/home/gbeutner/strawberry/contrib/gdb') diff --git a/lib/config/config_parser.cc b/lib/config/config_parser.cc index 4121738c3..1f8dbf7f2 100644 --- a/lib/config/config_parser.cc +++ b/lib/config/config_parser.cc @@ -612,8 +612,8 @@ static const yytype_uint16 yyrline[] = 273, 280, 281, 282, 283, 284, 285, 286, 293, 293, 338, 339, 344, 345, 348, 352, 359, 362, 368, 381, 384, 390, 396, 400, 406, 409, 415, 427, 433, 447, - 448, 449, 450, 451, 457, 463, 467, 473, 476, 482, - 494, 499, 503, 507, 517, 518 + 448, 449, 450, 451, 457, 463, 467, 473, 476, 491, + 511, 516, 520, 524, 534, 535 }; #endif @@ -2136,6 +2136,15 @@ yyreduce: #line 477 "config_parser.yy" { (yyval.array) = new Array(); + + if ((yyvsp[(1) - (1)].variant)->IsObjectType()) { + ExpressionList::Ptr exprl = *(yyvsp[(1) - (1)].variant); + Dictionary::Ptr dict = boost::make_shared(); + exprl->Execute(dict); + delete (yyvsp[(1) - (1)].variant); + (yyvsp[(1) - (1)].variant) = new Value(dict); + } + (yyval.array)->Add(*(yyvsp[(1) - (1)].variant)); delete (yyvsp[(1) - (1)].variant); } @@ -2144,13 +2153,21 @@ yyreduce: case 69: /* Line 1806 of yacc.c */ -#line 483 "config_parser.yy" +#line 492 "config_parser.yy" { if ((yyvsp[(1) - (3)].array)) (yyval.array) = (yyvsp[(1) - (3)].array); else (yyval.array) = new Array(); + if ((yyvsp[(3) - (3)].variant)->IsObjectType()) { + ExpressionList::Ptr exprl = *(yyvsp[(3) - (3)].variant); + Dictionary::Ptr dict = boost::make_shared(); + exprl->Execute(dict); + delete (yyvsp[(3) - (3)].variant); + (yyvsp[(3) - (3)].variant) = new Value(dict); + } + (yyval.array)->Add(*(yyvsp[(3) - (3)].variant)); delete (yyvsp[(3) - (3)].variant); } @@ -2159,7 +2176,7 @@ yyreduce: case 70: /* Line 1806 of yacc.c */ -#line 495 "config_parser.yy" +#line 512 "config_parser.yy" { (yyval.variant) = new Value((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text)); @@ -2169,7 +2186,7 @@ yyreduce: case 71: /* Line 1806 of yacc.c */ -#line 500 "config_parser.yy" +#line 517 "config_parser.yy" { (yyval.variant) = new Value((yyvsp[(1) - (1)].num)); } @@ -2178,7 +2195,7 @@ yyreduce: case 72: /* Line 1806 of yacc.c */ -#line 504 "config_parser.yy" +#line 521 "config_parser.yy" { (yyval.variant) = new Value(); } @@ -2187,7 +2204,7 @@ yyreduce: case 73: /* Line 1806 of yacc.c */ -#line 508 "config_parser.yy" +#line 525 "config_parser.yy" { if ((yyvsp[(1) - (1)].array) == NULL) (yyvsp[(1) - (1)].array) = new Array(); @@ -2200,7 +2217,7 @@ yyreduce: case 75: /* Line 1806 of yacc.c */ -#line 519 "config_parser.yy" +#line 536 "config_parser.yy" { ExpressionList::Ptr exprl = ExpressionList::Ptr((yyvsp[(1) - (1)].exprl)); (yyval.variant) = new Value(exprl); @@ -2210,7 +2227,7 @@ yyreduce: /* Line 1806 of yacc.c */ -#line 2214 "../../../lib/config/config_parser.cc" +#line 2231 "../../../lib/config/config_parser.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2448,6 +2465,6 @@ yyreturn: /* Line 2067 of yacc.c */ -#line 524 "config_parser.yy" +#line 541 "config_parser.yy" diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 5c2c35e2a..201460d03 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -476,6 +476,15 @@ array_items_inner: /* empty */ | value { $$ = new Array(); + + if ($1->IsObjectType()) { + ExpressionList::Ptr exprl = *$1; + Dictionary::Ptr dict = boost::make_shared(); + exprl->Execute(dict); + delete $1; + $1 = new Value(dict); + } + $$->Add(*$1); delete $1; } @@ -486,6 +495,14 @@ array_items_inner: /* empty */ else $$ = new Array(); + if ($3->IsObjectType()) { + ExpressionList::Ptr exprl = *$3; + Dictionary::Ptr dict = boost::make_shared(); + exprl->Execute(dict); + delete $3; + $3 = new Value(dict); + } + $$->Add(*$3); delete $3; } diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index dcdf3f18e..9435187ba 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -420,8 +420,6 @@ Service::Ptr Host::GetServiceByShortName(const Value& name) const Dictionary::Ptr dict = name; String short_name; - ASSERT(dict->IsSealed()); - return Service::GetByNamePair(dict->Get("host"), dict->Get("service")); } else { BOOST_THROW_EXCEPTION(std::invalid_argument("Host/Service name pair is invalid: " + name.Serialize()));