From 7d5ab3d890ba952ec662c85debf93dac84d2f2e3 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 2 Jul 2012 10:29:32 +0200 Subject: [PATCH] Implemented support for the 'include' config directive. --- components/configfile/configfilecomponent.cpp | 5 - dyn/config_parser.cc | 575 ++++++++++-------- dyn/config_parser.h | 20 +- dyn/config_parser.yy | 10 +- dyn/configcompiler.cpp | 28 +- dyn/configcompiler.h | 12 +- dyn/configvm.cpp | 2 + 7 files changed, 366 insertions(+), 286 deletions(-) diff --git a/components/configfile/configfilecomponent.cpp b/components/configfile/configfilecomponent.cpp index ac6e92a57..e094f0b65 100644 --- a/components/configfile/configfilecomponent.cpp +++ b/components/configfile/configfilecomponent.cpp @@ -37,12 +37,7 @@ void ConfigFileComponent::Start(void) if (!GetConfig()->GetProperty("configFilename", &filename)) throw logic_error("Missing 'configFilename' property"); - Application::Log(LogInformation, "configfile", "Compiling config file: " + filename); - vector configItems = ConfigCompiler::CompileFile(filename); - - Application::Log(LogInformation, "configfile", "Executing config items..."); - ConfigVM::ExecuteItems(configItems); } diff --git a/dyn/config_parser.cc b/dyn/config_parser.cc index f8498050d..1019743a2 100644 --- a/dyn/config_parser.cc +++ b/dyn/config_parser.cc @@ -1,10 +1,8 @@ +/* A Bison parser, made by GNU Bison 2.5. */ -/* A Bison parser, made by GNU Bison 2.4.1. */ - -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -46,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.1" +#define YYBISON_VERSION "2.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -68,8 +66,8 @@ /* Copy the first part of user declarations. */ -/* Line 189 of yacc.c */ -#line 73 "config_parser.cc" +/* Line 268 of yacc.c */ +#line 71 "config_parser.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -91,7 +89,7 @@ /* "%code requires" blocks. */ -/* Line 209 of yacc.c */ +/* Line 288 of yacc.c */ #line 1 "config_parser.yy" /****************************************************************************** @@ -122,8 +120,8 @@ using namespace icinga; -/* Line 209 of yacc.c */ -#line 127 "config_parser.cc" +/* Line 288 of yacc.c */ +#line 125 "config_parser.cc" /* Tokens. */ #ifndef YYTOKENTYPE @@ -172,7 +170,7 @@ using namespace icinga; typedef union YYSTYPE { -/* Line 214 of yacc.c */ +/* Line 293 of yacc.c */ #line 38 "config_parser.yy" char *text; @@ -182,8 +180,8 @@ typedef union YYSTYPE -/* Line 214 of yacc.c */ -#line 187 "config_parser.cc" +/* Line 293 of yacc.c */ +#line 185 "config_parser.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -206,7 +204,7 @@ typedef struct YYLTYPE /* Copy the second part of user declarations. */ -/* Line 264 of yacc.c */ +/* Line 343 of yacc.c */ #line 67 "config_parser.yy" @@ -227,7 +225,6 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err) int yyparse(ConfigCompiler *context); static stack m_ExpressionLists; -static vector m_Objects; static ConfigItem::Ptr m_Object; static bool m_Abstract; static bool m_Temporary; @@ -236,18 +233,15 @@ static Dictionary::Ptr m_Array; void ConfigCompiler::Compile(void) { - m_Objects.clear(); yyparse(this); - SetResult(m_Objects); - m_Objects.clear(); } #define scanner (context->GetScanner()) -/* Line 264 of yacc.c */ -#line 251 "config_parser.cc" +/* Line 343 of yacc.c */ +#line 245 "config_parser.cc" #ifdef short # undef short @@ -297,7 +291,7 @@ typedef short int yytype_int16; #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if YYENABLE_NLS +# if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) @@ -350,11 +344,11 @@ YYID (yyi) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -377,24 +371,24 @@ YYID (yyi) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif @@ -425,23 +419,7 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of @@ -461,6 +439,26 @@ union yyalloc #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ #define YYFINAL 2 /* YYLAST -- Last index in YYTABLE. */ @@ -547,11 +545,11 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 106, 106, 107, 110, 110, 113, 117, 122, 117, - 155, 156, 159, 163, 167, 173, 174, 177, 184, 185, - 189, 188, 200, 201, 203, 204, 205, 208, 216, 230, - 239, 240, 241, 242, 243, 249, 254, 258, 264, 265, - 266, 273, 272, 284, 290, 291, 293, 295, 296 + 0, 102, 102, 103, 106, 106, 109, 115, 120, 115, + 153, 154, 157, 161, 165, 171, 172, 175, 182, 183, + 187, 186, 198, 199, 201, 202, 203, 206, 214, 228, + 237, 238, 239, 240, 241, 247, 252, 256, 262, 263, + 264, 271, 270, 282, 288, 289, 291, 293, 294 }; #endif @@ -604,8 +602,8 @@ static const yytype_uint8 yyr2[] = 1, 0, 4, 1, 1, 2, 0, 1, 3 }; -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { @@ -650,8 +648,7 @@ static const yytype_int8 yypgoto[] = /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ + number is the opposite. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { @@ -662,6 +659,12 @@ static const yytype_uint8 yytable[] = 51, 59, 24, 61, 52, 62, 0, 27, 60 }; +#define yypact_value_is_default(yystate) \ + ((yystate) == (-46)) + +#define yytable_value_is_error(yytable_value) \ + YYID (0) + static const yytype_int8 yycheck[] = { 3, 4, 5, 7, 8, 9, 10, 11, 53, 0, @@ -696,9 +699,18 @@ static const yytype_uint8 yystos[] = /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ #define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif #define YYRECOVERING() (!!yyerrstatus) @@ -708,7 +720,6 @@ do \ { \ yychar = (Token); \ yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK (1); \ goto yybackup; \ } \ @@ -755,7 +766,7 @@ while (YYID (0)) we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT -# if YYLTYPE_IS_TRIVIAL +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL # define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ @@ -964,7 +975,6 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE @@ -1067,115 +1077,142 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) { - int yyn = yypact[yystate]; + YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = 0; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - - if (yysize_overflow) - return YYSIZE_MAXIMUM; - - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (0, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; } #endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | @@ -1212,6 +1249,7 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, context) } } + /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM #if defined __STDC__ || defined __cplusplus @@ -1228,12 +1266,9 @@ int yyparse (); #endif /* ! YYPARSE_PARAM */ - - - -/*-------------------------. -| yyparse or yypush_parse. | -`-------------------------*/ +/*----------. +| yyparse. | +`----------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ @@ -1297,7 +1332,7 @@ YYLTYPE yylloc; YYLTYPE *yylsp; /* The locations where the error started and ended. */ - YYLTYPE yyerror_range[2]; + YYLTYPE yyerror_range[3]; YYSIZE_T yystacksize; @@ -1344,7 +1379,7 @@ YYLTYPE yylloc; yyvsp = yyvs; yylsp = yyls; -#if YYLTYPE_IS_TRIVIAL +#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL /* Initialize the default location before parsing starts. */ yylloc.first_line = yylloc.last_line = 1; yylloc.first_column = yylloc.last_column = 1; @@ -1446,7 +1481,7 @@ yybackup: /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ @@ -1477,8 +1512,8 @@ yybackup: yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -1532,10 +1567,19 @@ yyreduce: YY_REDUCE_PRINT (yyn); switch (yyn) { - case 7: + case 6: -/* Line 1455 of yacc.c */ -#line 117 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 110 "config_parser.yy" + { + context->HandleInclude((yyvsp[(2) - (2)].text)); + } + break; + + case 7: + +/* Line 1806 of yacc.c */ +#line 115 "config_parser.yy" { m_Abstract = false; m_Local = false; @@ -1544,8 +1588,8 @@ yyreduce: case 8: -/* Line 1455 of yacc.c */ -#line 122 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 120 "config_parser.yy" { m_Object = boost::make_shared((yyvsp[(4) - (5)].text), (yyvsp[(5) - (5)].text), yylloc); free((yyvsp[(4) - (5)].text)); @@ -1555,8 +1599,8 @@ yyreduce: case 9: -/* Line 1455 of yacc.c */ -#line 128 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 126 "config_parser.yy" { Object::Ptr exprl_object = *(yyvsp[(8) - (8)].variant); delete (yyvsp[(8) - (8)].variant); @@ -1579,15 +1623,15 @@ yyreduce: m_Object->SetExpressionList(exprl); - m_Objects.push_back(m_Object); + context->AddObject(m_Object); m_Object.reset(); } break; case 12: -/* Line 1455 of yacc.c */ -#line 160 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 158 "config_parser.yy" { m_Abstract = true; } @@ -1595,8 +1639,8 @@ yyreduce: case 13: -/* Line 1455 of yacc.c */ -#line 164 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 162 "config_parser.yy" { m_Temporary = true; } @@ -1604,8 +1648,8 @@ yyreduce: case 14: -/* Line 1455 of yacc.c */ -#line 168 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 166 "config_parser.yy" { m_Local = true; } @@ -1613,8 +1657,8 @@ yyreduce: case 17: -/* Line 1455 of yacc.c */ -#line 178 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 176 "config_parser.yy" { m_Object->AddParent((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text)); @@ -1623,8 +1667,8 @@ yyreduce: case 20: -/* Line 1455 of yacc.c */ -#line 189 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 187 "config_parser.yy" { m_ExpressionLists.push(boost::make_shared()); } @@ -1632,8 +1676,8 @@ yyreduce: case 21: -/* Line 1455 of yacc.c */ -#line 194 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 192 "config_parser.yy" { (yyval.variant) = new Variant(m_ExpressionLists.top()); m_ExpressionLists.pop(); @@ -1642,8 +1686,8 @@ yyreduce: case 27: -/* Line 1455 of yacc.c */ -#line 209 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 207 "config_parser.yy" { Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc); free((yyvsp[(1) - (3)].text)); @@ -1655,8 +1699,8 @@ yyreduce: case 28: -/* Line 1455 of yacc.c */ -#line 217 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 215 "config_parser.yy" { Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc); free((yyvsp[(3) - (6)].text)); @@ -1674,8 +1718,8 @@ yyreduce: case 29: -/* Line 1455 of yacc.c */ -#line 231 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 229 "config_parser.yy" { Expression expr((yyvsp[(1) - (1)].text), OperatorSet, (yyvsp[(1) - (1)].text), yylloc); free((yyvsp[(1) - (1)].text)); @@ -1686,8 +1730,8 @@ yyreduce: case 34: -/* Line 1455 of yacc.c */ -#line 244 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 242 "config_parser.yy" { (yyval.op) = (yyvsp[(1) - (1)].op); } @@ -1695,8 +1739,8 @@ yyreduce: case 35: -/* Line 1455 of yacc.c */ -#line 250 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 248 "config_parser.yy" { (yyval.variant) = new Variant((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text)); @@ -1705,8 +1749,8 @@ yyreduce: case 36: -/* Line 1455 of yacc.c */ -#line 255 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 253 "config_parser.yy" { (yyval.variant) = new Variant((yyvsp[(1) - (1)].num)); } @@ -1714,8 +1758,8 @@ yyreduce: case 37: -/* Line 1455 of yacc.c */ -#line 259 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 257 "config_parser.yy" { (yyval.variant) = new Variant(); } @@ -1723,8 +1767,8 @@ yyreduce: case 40: -/* Line 1455 of yacc.c */ -#line 267 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 265 "config_parser.yy" { (yyval.variant) = (yyvsp[(1) - (1)].variant); } @@ -1732,8 +1776,8 @@ yyreduce: case 41: -/* Line 1455 of yacc.c */ -#line 273 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 271 "config_parser.yy" { m_Array = boost::make_shared(); } @@ -1741,8 +1785,8 @@ yyreduce: case 42: -/* Line 1455 of yacc.c */ -#line 278 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 276 "config_parser.yy" { (yyval.variant) = new Variant(m_Array); m_Array.reset(); @@ -1751,8 +1795,8 @@ yyreduce: case 43: -/* Line 1455 of yacc.c */ -#line 285 "config_parser.yy" +/* Line 1806 of yacc.c */ +#line 283 "config_parser.yy" { m_Array->AddUnnamedProperty(*(yyvsp[(1) - (1)].variant)); delete (yyvsp[(1) - (1)].variant); @@ -1761,10 +1805,21 @@ yyreduce: -/* Line 1455 of yacc.c */ -#line 1766 "config_parser.cc" +/* Line 1806 of yacc.c */ +#line 1810 "config_parser.cc" default: break; } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -1793,6 +1848,10 @@ yyreduce: | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { @@ -1800,41 +1859,40 @@ yyerrlab: #if ! YYERROR_VERBOSE yyerror (&yylloc, context, YY_("syntax error")); #else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (&yylloc, context, yymsg); - } - else - { - yyerror (&yylloc, context, YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (&yylloc, context, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } +# undef YYSYNTAX_ERROR #endif } - yyerror_range[0] = yylloc; + yyerror_range[1] = yylloc; if (yyerrstatus == 3) { @@ -1871,7 +1929,7 @@ yyerrorlab: if (/*CONSTCOND*/ 0) goto yyerrorlab; - yyerror_range[0] = yylsp[1-yylen]; + yyerror_range[1] = yylsp[1-yylen]; /* Do not reclaim the symbols of the rule which action triggered this YYERROR. */ YYPOPSTACK (yylen); @@ -1890,7 +1948,7 @@ yyerrlab1: for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) + if (!yypact_value_is_default (yyn)) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) @@ -1905,7 +1963,7 @@ yyerrlab1: if (yyssp == yyss) YYABORT; - yyerror_range[0] = *yylsp; + yyerror_range[1] = *yylsp; yydestruct ("Error: popping", yystos[yystate], yyvsp, yylsp, context); YYPOPSTACK (1); @@ -1915,10 +1973,10 @@ yyerrlab1: *++yyvsp = yylval; - yyerror_range[1] = yylloc; + yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of the lookahead. YYLOC is available though. */ - YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); + YYLLOC_DEFAULT (yyloc, yyerror_range, 2); *++yylsp = yyloc; /* Shift the error token. */ @@ -1954,8 +2012,13 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, context); + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc, context); + } /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -1980,7 +2043,7 @@ yyreturn: -/* Line 1675 of yacc.c */ -#line 298 "config_parser.yy" +/* Line 2067 of yacc.c */ +#line 296 "config_parser.yy" diff --git a/dyn/config_parser.h b/dyn/config_parser.h index ec90fecf1..4ac314b8c 100644 --- a/dyn/config_parser.h +++ b/dyn/config_parser.h @@ -1,10 +1,8 @@ +/* A Bison parser, made by GNU Bison 2.5. */ -/* A Bison parser, made by GNU Bison 2.4.1. */ - -/* Skeleton interface for Bison's Yacc-like parsers in C +/* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,7 +32,7 @@ /* "%code requires" blocks. */ -/* Line 1676 of yacc.c */ +/* Line 2068 of yacc.c */ #line 1 "config_parser.yy" /****************************************************************************** @@ -65,8 +63,8 @@ using namespace icinga; -/* Line 1676 of yacc.c */ -#line 70 "config_parser.h" +/* Line 2068 of yacc.c */ +#line 68 "config_parser.h" /* Tokens. */ #ifndef YYTOKENTYPE @@ -115,7 +113,7 @@ using namespace icinga; typedef union YYSTYPE { -/* Line 1676 of yacc.c */ +/* Line 2068 of yacc.c */ #line 38 "config_parser.yy" char *text; @@ -125,8 +123,8 @@ typedef union YYSTYPE -/* Line 1676 of yacc.c */ -#line 130 "config_parser.h" +/* Line 2068 of yacc.c */ +#line 128 "config_parser.h" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/dyn/config_parser.yy b/dyn/config_parser.yy index 1246184de..7fa634e81 100644 --- a/dyn/config_parser.yy +++ b/dyn/config_parser.yy @@ -83,7 +83,6 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err) int yyparse(ConfigCompiler *context); static stack m_ExpressionLists; -static vector m_Objects; static ConfigItem::Ptr m_Object; static bool m_Abstract; static bool m_Temporary; @@ -92,10 +91,7 @@ static Dictionary::Ptr m_Array; void ConfigCompiler::Compile(void) { - m_Objects.clear(); yyparse(this); - SetResult(m_Objects); - m_Objects.clear(); } #define scanner (context->GetScanner()) @@ -111,7 +107,9 @@ statement: object | include ; include: T_INCLUDE T_STRING - ; + { + context->HandleInclude($2); + } object: { @@ -147,7 +145,7 @@ inherits_specifier expressionlist m_Object->SetExpressionList(exprl); - m_Objects.push_back(m_Object); + context->AddObject(m_Object); m_Object.reset(); } ; diff --git a/dyn/configcompiler.cpp b/dyn/configcompiler.cpp index d27eb21be..ca572cb6c 100644 --- a/dyn/configcompiler.cpp +++ b/dyn/configcompiler.cpp @@ -23,8 +23,9 @@ using std::ifstream; using namespace icinga; -ConfigCompiler::ConfigCompiler(istream *input) +ConfigCompiler::ConfigCompiler(istream *input, HandleIncludeFunc includeHandler) { + m_HandleInclude = includeHandler; m_Input = input; InitializeScanner(); } @@ -45,16 +46,17 @@ void *ConfigCompiler::GetScanner(void) const return m_Scanner; } -void ConfigCompiler::SetResult(vector result) -{ - m_Result = result; -} - vector ConfigCompiler::GetResult(void) const { return m_Result; } +void ConfigCompiler::HandleInclude(const string& include) +{ + vector items = m_HandleInclude(include); + std::copy(items.begin(), items.end(), back_inserter(m_Result)); +} + vector ConfigCompiler::CompileStream(istream *stream) { ConfigCompiler ctx(stream); @@ -67,6 +69,9 @@ vector ConfigCompiler::CompileFile(const string& filename) ifstream stream; stream.exceptions(ifstream::badbit); stream.open(filename.c_str(), ifstream::in); + + Application::Log(LogInformation, "dyn", "Compiling config file: " + filename); + return CompileStream(&stream); } @@ -75,3 +80,14 @@ vector ConfigCompiler::CompileText(const string& text) stringstream stream(text); return CompileStream(&stream); } + +vector ConfigCompiler::HandleFileInclude(const string& include) +{ + /* TODO: implement wildcard includes */ + return CompileFile(include); +} + +void ConfigCompiler::AddObject(const ConfigItem::Ptr& object) +{ + m_Result.push_back(object); +} diff --git a/dyn/configcompiler.h b/dyn/configcompiler.h index 1ef3a5fd4..77ce90eec 100644 --- a/dyn/configcompiler.h +++ b/dyn/configcompiler.h @@ -26,7 +26,10 @@ namespace icinga class I2_DYN_API ConfigCompiler { public: - ConfigCompiler(istream *input = &cin); + typedef function (const string& include)> HandleIncludeFunc; + + ConfigCompiler(istream *input = &cin, + HandleIncludeFunc includeHandler = &ConfigCompiler::HandleFileInclude); virtual ~ConfigCompiler(void); void Compile(void); @@ -35,13 +38,18 @@ public: static vector CompileFile(const string& filename); static vector CompileText(const string& text); - void SetResult(vector result); + static vector HandleFileInclude(const string& include); + vector GetResult(void) const; + /* internally used methods */ + void HandleInclude(const string& include); + void AddObject(const ConfigItem::Ptr& object); size_t ReadInput(char *buffer, size_t max_bytes); void *GetScanner(void) const; private: + HandleIncludeFunc m_HandleInclude; istream *m_Input; void *m_Scanner; vector m_Result; diff --git a/dyn/configvm.cpp b/dyn/configvm.cpp index ec0ac2dd1..9a274f862 100644 --- a/dyn/configvm.cpp +++ b/dyn/configvm.cpp @@ -25,6 +25,8 @@ void ConfigVM::ExecuteItems(const vector& items) { vector::const_iterator it; + Application::Log(LogInformation, "dyn", "Executing config items..."); + for (it = items.begin(); it != items.end(); it++) { ConfigItem::Ptr obj = *it; obj->Commit();