Implement script variables.

This commit is contained in:
Gunnar Beutner 2013-06-25 09:21:25 +02:00
parent a5355e63a3
commit f3d0738e93
8 changed files with 833 additions and 542 deletions

View File

@ -60,6 +60,8 @@ libbase_la_SOURCES = \
scriptinterpreter.h \
scriptlanguage.cpp \
scriptlanguage.h \
scriptvariable.cpp \
scriptvariable.h \
singleton.h \
socket.cpp \
socket.h \

View File

@ -0,0 +1,34 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
* *
* 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 the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "base/scriptvariable.h"
using namespace icinga;
Registry<String> ScriptVariable::m_Registry;
Value ScriptVariable::Get(const String& name)
{
return m_Registry.GetItem(name);
}
void ScriptVariable::Set(const String& name, const Value& value)
{
m_Registry.Register(name, value);
}

47
lib/base/scriptvariable.h Normal file
View File

@ -0,0 +1,47 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
* *
* 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 the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#ifndef SCRIPTVARIABLE_H
#define SCRIPTVARIABLE_H
#include "base/i2-base.h"
#include "base/registry.h"
#include "base/value.h"
namespace icinga
{
/**
* Global registry for script variables.
*
* @ingroup base
*/
class I2_BASE_API ScriptVariable
{
public:
static Value Get(const String& name);
static void Set(const String& name, const Value& value);
private:
static Registry<String> m_Registry;
};
}
#endif /* SCRIPTVARIABLE_H */

View File

@ -370,8 +370,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 57
#define YY_END_OF_BUFFER 58
#define YY_NUM_RULES 58
#define YY_END_OF_BUFFER 59
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
@ -379,29 +379,29 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int16_t yy_accept[194] =
static yyconst flex_int16_t yy_accept[196] =
{ 0,
0, 0, 0, 0, 0, 0, 0, 0, 58, 56,
21, 21, 1, 56, 44, 56, 56, 56, 50, 56,
51, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 56, 18, 19, 12, 3, 2, 57, 15,
15, 0, 0, 0, 44, 54, 52, 50, 53, 16,
20, 55, 0, 47, 48, 49, 0, 45, 44, 44,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 44, 44, 44, 0, 17, 12, 11, 4,
5, 9, 10, 6, 8, 7, 0, 0, 0, 0,
20, 50, 46, 44, 28, 44, 44, 44, 44, 44,
0, 0, 0, 0, 0, 0, 0, 0, 59, 57,
21, 21, 1, 57, 45, 57, 57, 57, 51, 57,
52, 45, 45, 45, 45, 45, 45, 45, 45, 45,
45, 45, 57, 18, 19, 12, 3, 2, 58, 15,
15, 0, 0, 0, 45, 55, 53, 51, 54, 16,
20, 56, 0, 48, 49, 50, 0, 46, 45, 45,
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
45, 45, 45, 45, 45, 45, 0, 17, 12, 11,
4, 5, 9, 10, 6, 8, 7, 0, 0, 0,
0, 20, 51, 47, 45, 28, 45, 45, 45, 45,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
44, 44, 13, 4, 5, 14, 0, 0, 0, 44,
44, 44, 44, 44, 44, 44, 44, 29, 40, 44,
44, 44, 44, 44, 44, 42, 22, 4, 0, 0,
0, 44, 24, 44, 43, 44, 44, 44, 34, 44,
44, 44, 44, 44, 44, 0, 0, 0, 44, 44,
44, 44, 44, 25, 35, 44, 27, 26, 44, 0,
0, 0, 44, 44, 37, 44, 38, 41, 44, 0,
31, 0, 33, 44, 39, 36, 0, 0, 44, 32,
30, 23, 0
45, 45, 45, 45, 45, 45, 45, 45, 45, 44,
45, 45, 45, 45, 13, 4, 5, 14, 0, 0,
0, 45, 45, 45, 45, 45, 45, 45, 45, 29,
40, 45, 45, 45, 45, 45, 45, 42, 22, 4,
0, 0, 0, 45, 24, 45, 43, 45, 45, 45,
34, 45, 45, 45, 45, 45, 45, 0, 0, 0,
45, 45, 45, 45, 45, 25, 35, 45, 27, 26,
45, 0, 0, 0, 45, 45, 37, 45, 38, 41,
45, 0, 31, 0, 33, 45, 39, 36, 0, 0,
45, 32, 30, 23, 0
} ;
@ -446,162 +446,162 @@ static yyconst flex_int32_t yy_meta[43] =
1, 1
} ;
static yyconst flex_int16_t yy_base[202] =
static yyconst flex_int16_t yy_base[204] =
{ 0,
0, 0, 346, 345, 40, 42, 308, 307, 348, 353,
353, 353, 353, 28, 332, 331, 37, 44, 44, 329,
353, 329, 42, 49, 46, 51, 54, 53, 63, 56,
64, 69, 302, 353, 332, 0, 353, 353, 99, 353,
299, 303, 316, 319, 322, 353, 353, 86, 353, 353,
0, 353, 76, 353, 300, 353, 319, 353, 78, 75,
85, 81, 74, 92, 79, 106, 102, 109, 113, 90,
114, 91, 116, 120, 122, 293, 353, 0, 353, 131,
133, 353, 353, 353, 353, 353, 291, 295, 297, 301,
0, 136, 353, 134, 314, 135, 136, 125, 138, 137,
0, 0, 350, 349, 40, 42, 312, 311, 352, 357,
357, 357, 357, 28, 336, 335, 37, 44, 44, 333,
357, 333, 42, 49, 46, 51, 54, 53, 63, 56,
64, 69, 306, 357, 336, 0, 357, 357, 99, 357,
303, 307, 320, 323, 326, 357, 357, 86, 357, 357,
0, 357, 77, 357, 304, 357, 323, 357, 78, 75,
85, 81, 79, 92, 106, 84, 102, 109, 112, 110,
114, 91, 116, 120, 122, 126, 297, 357, 0, 357,
131, 135, 357, 357, 357, 357, 357, 295, 299, 301,
305, 0, 137, 357, 129, 318, 137, 138, 140, 139,
141, 144, 142, 149, 154, 160, 153, 155, 162, 164,
165, 170, 353, 170, 175, 353, 293, 289, 299, 176,
177, 179, 180, 181, 183, 185, 184, 310, 309, 186,
187, 195, 197, 190, 199, 308, 307, 212, 294, 293,
297, 210, 303, 200, 302, 205, 211, 215, 299, 216,
218, 220, 219, 221, 222, 287, 271, 268, 227, 225,
229, 228, 230, 271, 270, 232, 269, 268, 234, 244,
258, 242, 238, 243, 262, 242, 261, 259, 244, 236,
353, 240, 254, 245, 253, 251, 241, 172, 248, 353,
353, 93, 353, 288, 292, 296, 47, 300, 304, 308,
142, 143, 155, 146, 156, 157, 164, 147, 165, 317,
166, 149, 168, 173, 357, 178, 186, 357, 296, 292,
302, 171, 177, 180, 185, 184, 186, 190, 187, 313,
312, 188, 189, 197, 199, 198, 204, 311, 310, 214,
297, 296, 300, 208, 306, 200, 305, 213, 215, 205,
304, 216, 219, 222, 223, 221, 224, 298, 280, 289,
229, 230, 232, 233, 234, 292, 273, 237, 272, 271,
238, 247, 261, 246, 239, 244, 266, 242, 265, 264,
245, 240, 357, 241, 257, 247, 256, 254, 244, 230,
249, 357, 357, 88, 357, 289, 293, 297, 47, 301,
312
305, 309, 313
} ;
static yyconst flex_int16_t yy_def[202] =
static yyconst flex_int16_t yy_def[204] =
{ 0,
193, 1, 194, 194, 195, 195, 196, 196, 193, 193,
193, 193, 193, 193, 197, 193, 193, 193, 193, 198,
193, 197, 197, 197, 197, 197, 197, 197, 197, 197,
197, 197, 193, 193, 193, 199, 193, 193, 200, 193,
193, 193, 193, 193, 197, 193, 193, 193, 193, 193,
201, 193, 193, 193, 193, 193, 198, 193, 197, 197,
197, 197, 197, 197, 197, 197, 197, 197, 197, 197,
197, 197, 197, 197, 197, 193, 193, 199, 193, 193,
193, 193, 193, 193, 193, 193, 193, 193, 193, 193,
201, 193, 193, 197, 197, 197, 197, 197, 197, 197,
195, 1, 196, 196, 197, 197, 198, 198, 195, 195,
195, 195, 195, 195, 199, 195, 195, 195, 195, 200,
195, 199, 199, 199, 199, 199, 199, 199, 199, 199,
199, 199, 195, 195, 195, 201, 195, 195, 202, 195,
195, 195, 195, 195, 199, 195, 195, 195, 195, 195,
203, 195, 195, 195, 195, 195, 200, 195, 199, 199,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199,
199, 199, 199, 199, 199, 199, 195, 195, 201, 195,
195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
195, 203, 195, 195, 199, 199, 199, 199, 199, 199,
197, 197, 197, 197, 197, 197, 197, 197, 197, 197,
197, 197, 193, 193, 193, 193, 193, 193, 193, 197,
197, 197, 197, 197, 197, 197, 197, 197, 197, 197,
197, 197, 197, 197, 197, 197, 197, 193, 193, 193,
193, 197, 197, 197, 197, 197, 197, 197, 197, 197,
197, 197, 197, 197, 197, 193, 193, 193, 197, 197,
197, 197, 197, 197, 197, 197, 197, 197, 197, 193,
193, 193, 197, 197, 197, 197, 197, 197, 197, 193,
193, 193, 197, 197, 197, 197, 193, 193, 197, 193,
193, 197, 0, 193, 193, 193, 193, 193, 193, 193,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199,
199, 199, 199, 199, 195, 195, 195, 195, 195, 195,
195, 199, 199, 199, 199, 199, 199, 199, 199, 199,
199, 199, 199, 199, 199, 199, 199, 199, 199, 195,
195, 195, 195, 199, 199, 199, 199, 199, 199, 199,
199, 199, 199, 199, 199, 199, 199, 195, 195, 195,
199, 199, 199, 199, 199, 199, 199, 199, 199, 199,
199, 195, 195, 195, 199, 199, 199, 199, 199, 199,
199, 195, 195, 195, 199, 199, 199, 199, 195, 195,
199, 195, 195, 199, 0, 195, 195, 195, 195, 195,
193
195, 195, 195
} ;
static yyconst flex_int16_t yy_nxt[396] =
static yyconst flex_int16_t yy_nxt[400] =
{ 0,
10, 11, 12, 13, 14, 15, 16, 17, 10, 18,
19, 19, 10, 20, 21, 10, 22, 10, 23, 22,
22, 24, 22, 25, 22, 22, 26, 22, 27, 22,
28, 29, 30, 22, 22, 31, 32, 22, 22, 22,
33, 10, 37, 38, 37, 38, 42, 48, 48, 50,
45, 49, 53, 51, 48, 48, 193, 39, 52, 39,
193, 59, 43, 193, 63, 193, 44, 193, 193, 54,
193, 67, 60, 55, 70, 62, 61, 193, 193, 56,
65, 64, 69, 193, 71, 66, 92, 92, 193, 193,
68, 73, 193, 193, 53, 193, 48, 48, 101, 193,
45, 49, 53, 51, 48, 48, 195, 39, 52, 39,
195, 59, 43, 195, 63, 195, 44, 195, 195, 54,
195, 67, 60, 55, 70, 62, 61, 195, 195, 56,
65, 64, 69, 195, 71, 66, 72, 93, 93, 195,
68, 74, 195, 195, 53, 195, 48, 48, 195, 195,
72, 97, 98, 74, 193, 193, 193, 193, 75, 80,
81, 54, 99, 94, 95, 55, 193, 100, 82, 96,
193, 56, 83, 193, 107, 109, 102, 193, 193, 84,
193, 103, 108, 85, 193, 86, 193, 104, 105, 193,
106, 114, 115, 115, 115, 110, 92, 92, 193, 193,
193, 193, 193, 121, 112, 193, 193, 111, 193, 125,
123, 54, 127, 193, 128, 55, 124, 193, 193, 193,
120, 56, 122, 130, 193, 126, 193, 129, 193, 193,
138, 115, 131, 133, 193, 115, 115, 136, 134, 132,
193, 193, 137, 193, 193, 193, 135, 193, 193, 193,
73, 98, 195, 75, 103, 195, 195, 99, 76, 81,
82, 54, 100, 95, 96, 55, 195, 101, 83, 97,
195, 56, 84, 195, 195, 102, 195, 110, 195, 85,
195, 104, 109, 86, 195, 87, 195, 105, 106, 107,
195, 116, 117, 195, 108, 117, 117, 93, 93, 112,
111, 195, 195, 195, 195, 123, 195, 195, 114, 113,
195, 195, 54, 195, 127, 122, 55, 126, 130, 195,
195, 195, 56, 129, 124, 125, 132, 128, 195, 195,
195, 137, 195, 134, 131, 195, 133, 195, 140, 117,
138, 195, 136, 135, 195, 139, 117, 117, 195, 195,
193, 193, 145, 148, 193, 144, 191, 151, 150, 193,
142, 193, 149, 193, 193, 153, 143, 147, 146, 193,
154, 152, 115, 115, 193, 193, 161, 155, 159, 193,
193, 160, 193, 193, 193, 193, 193, 162, 166, 193,
169, 193, 193, 193, 193, 168, 193, 173, 193, 163,
164, 175, 193, 167, 165, 174, 193, 193, 193, 193,
178, 184, 193, 190, 176, 193, 186, 193, 193, 177,
179, 188, 187, 193, 183, 193, 193, 185, 182, 189,
181, 180, 193, 193, 193, 193, 172, 192, 34, 34,
34, 34, 36, 36, 36, 36, 40, 40, 40, 40,
195, 195, 195, 195, 195, 144, 146, 147, 150, 153,
152, 195, 195, 195, 195, 151, 145, 155, 195, 195,
149, 148, 195, 154, 117, 117, 161, 195, 156, 195,
195, 162, 157, 195, 163, 195, 195, 195, 195, 165,
168, 164, 171, 195, 195, 170, 195, 195, 195, 175,
166, 195, 195, 195, 177, 167, 195, 169, 195, 195,
176, 195, 186, 195, 193, 180, 192, 188, 195, 178,
195, 195, 190, 179, 181, 185, 189, 187, 195, 195,
195, 191, 184, 183, 182, 195, 195, 195, 194, 34,
34, 34, 34, 36, 36, 36, 36, 40, 40, 40,
57, 57, 57, 57, 78, 171, 170, 78, 79, 79,
79, 79, 91, 193, 91, 91, 193, 193, 158, 157,
156, 193, 193, 193, 193, 141, 140, 139, 193, 119,
118, 117, 116, 113, 58, 93, 193, 90, 89, 88,
87, 77, 76, 193, 58, 47, 46, 193, 41, 41,
35, 35, 9, 193, 193, 193, 193, 193, 193, 193,
193, 193, 193, 193, 193, 193, 193, 193, 193, 193,
193, 193, 193, 193, 193, 193, 193, 193, 193, 193,
193, 193, 193, 193, 193, 193, 193, 193, 193, 193,
193, 193, 193, 193, 193
40, 57, 57, 57, 57, 79, 195, 174, 79, 80,
80, 80, 80, 92, 173, 92, 92, 172, 195, 195,
195, 160, 159, 158, 195, 195, 195, 195, 143, 142,
141, 195, 195, 121, 120, 119, 118, 115, 58, 94,
195, 91, 90, 89, 88, 78, 77, 195, 58, 47,
46, 195, 41, 41, 35, 35, 9, 195, 195, 195,
195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
195, 195, 195, 195, 195, 195, 195, 195, 195
} ;
static yyconst flex_int16_t yy_chk[396] =
static yyconst flex_int16_t yy_chk[400] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 5, 5, 6, 6, 14, 17, 17, 18,
197, 17, 19, 18, 19, 19, 23, 5, 18, 6,
199, 17, 19, 18, 19, 19, 23, 5, 18, 6,
25, 23, 14, 24, 25, 26, 14, 28, 27, 19,
30, 28, 23, 19, 30, 24, 23, 29, 31, 19,
27, 26, 29, 32, 31, 27, 53, 53, 63, 60,
28, 32, 59, 65, 48, 62, 48, 48, 65, 61,
27, 26, 29, 32, 31, 27, 31, 53, 53, 60,
28, 32, 59, 63, 48, 62, 48, 48, 66, 61,
31, 62, 63, 32, 70, 72, 64, 192, 32, 39,
31, 62, 194, 32, 66, 72, 64, 63, 32, 39,
39, 48, 64, 59, 60, 48, 67, 64, 39, 61,
66, 48, 39, 68, 70, 72, 66, 69, 71, 39,
73, 67, 71, 39, 74, 39, 75, 68, 68, 98,
69, 80, 80, 81, 81, 73, 92, 92, 94, 96,
97, 100, 99, 96, 75, 101, 103, 74, 102, 100,
98, 92, 102, 104, 103, 92, 99, 107, 105, 108,
94, 92, 97, 105, 106, 101, 109, 104, 110, 111,
114, 114, 106, 108, 112, 115, 115, 111, 109, 107,
120, 121, 112, 122, 123, 124, 110, 125, 127, 126,
65, 48, 39, 68, 70, 65, 69, 72, 71, 39,
73, 67, 71, 39, 74, 39, 75, 68, 68, 69,
76, 81, 81, 95, 70, 82, 82, 93, 93, 74,
73, 97, 98, 100, 99, 97, 101, 102, 76, 75,
104, 108, 93, 112, 101, 95, 93, 100, 104, 103,
105, 106, 93, 103, 98, 99, 106, 102, 107, 109,
111, 112, 113, 108, 105, 122, 107, 114, 116, 116,
113, 123, 111, 109, 124, 114, 117, 117, 126, 125,
130, 131, 123, 126, 134, 122, 188, 131, 130, 132,
120, 133, 127, 135, 144, 133, 121, 125, 124, 146,
134, 132, 138, 138, 142, 147, 146, 135, 142, 148,
150, 144, 151, 153, 152, 154, 155, 147, 152, 160,
155, 159, 162, 161, 163, 154, 166, 159, 169, 148,
150, 161, 173, 153, 151, 160, 176, 174, 179, 184,
166, 174, 189, 187, 162, 186, 179, 185, 183, 163,
169, 182, 180, 178, 173, 177, 175, 176, 172, 184,
171, 170, 168, 167, 165, 164, 158, 189, 194, 194,
194, 194, 195, 195, 195, 195, 196, 196, 196, 196,
127, 129, 132, 133, 128, 122, 124, 125, 128, 133,
132, 134, 136, 135, 146, 129, 123, 135, 137, 150,
127, 126, 144, 134, 140, 140, 144, 148, 136, 149,
152, 146, 137, 153, 148, 156, 154, 155, 157, 150,
154, 149, 157, 161, 162, 156, 163, 164, 165, 161,
152, 168, 171, 175, 163, 153, 178, 155, 176, 181,
162, 186, 176, 191, 190, 168, 189, 181, 188, 164,
187, 185, 184, 165, 171, 175, 182, 178, 180, 179,
177, 186, 174, 173, 172, 170, 169, 167, 191, 196,
196, 196, 196, 197, 197, 197, 197, 198, 198, 198,
198, 198, 198, 198, 199, 157, 156, 199, 200, 200,
200, 200, 201, 149, 201, 201, 145, 143, 141, 140,
139, 137, 136, 129, 128, 119, 118, 117, 95, 90,
89, 88, 87, 76, 57, 55, 45, 44, 43, 42,
41, 35, 33, 22, 20, 16, 15, 9, 8, 7,
4, 3, 193, 193, 193, 193, 193, 193, 193, 193,
193, 193, 193, 193, 193, 193, 193, 193, 193, 193,
193, 193, 193, 193, 193, 193, 193, 193, 193, 193,
193, 193, 193, 193, 193, 193, 193, 193, 193, 193,
193, 193, 193, 193, 193
198, 200, 200, 200, 200, 201, 166, 160, 201, 202,
202, 202, 202, 203, 159, 203, 203, 158, 151, 147,
145, 143, 142, 141, 139, 138, 131, 130, 121, 120,
119, 110, 96, 91, 90, 89, 88, 77, 57, 55,
45, 44, 43, 42, 41, 35, 33, 22, 20, 16,
15, 9, 8, 7, 4, 3, 195, 195, 195, 195,
195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
195, 195, 195, 195, 195, 195, 195, 195, 195
} ;
/* Table of booleans, true if rule could match eol. */
static yyconst flex_int32_t yy_rule_can_match_eol[58] =
static yyconst flex_int32_t yy_rule_can_match_eol[59] =
{ 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
/* The intent behind this definition is that it'll catch
* any uses of REJECT which flex missed.
@ -1019,13 +1019,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 194 )
if ( yy_current_state >= 196 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
while ( yy_current_state != 193 );
while ( yy_current_state != 195 );
yy_cp = yyg->yy_last_accepting_cpos;
yy_current_state = yyg->yy_last_accepting_state;
@ -1332,33 +1332,33 @@ YY_RULE_SETUP
case 44:
YY_RULE_SETUP
#line 212 "config_lexer.ll"
{ yylval->text = strdup(yytext); return T_IDENTIFIER; }
return T_SET;
YY_BREAK
case 45:
/* rule 45 can match eol */
YY_RULE_SETUP
#line 213 "config_lexer.ll"
{ yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; }
{ yylval->text = strdup(yytext); return T_IDENTIFIER; }
YY_BREAK
case 46:
/* rule 46 can match eol */
YY_RULE_SETUP
#line 214 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
{ yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; }
YY_BREAK
case 47:
YY_RULE_SETUP
#line 215 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; }
{ yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
YY_BREAK
case 48:
YY_RULE_SETUP
#line 216 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; }
{ yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; }
YY_BREAK
case 49:
YY_RULE_SETUP
#line 217 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL); return T_NUMBER; }
{ yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; }
YY_BREAK
case 50:
YY_RULE_SETUP
@ -1368,40 +1368,45 @@ YY_RULE_SETUP
case 51:
YY_RULE_SETUP
#line 219 "config_lexer.ll"
{ yylval->op = OperatorSet; return T_EQUAL; }
{ yylval->num = strtod(yytext, NULL); return T_NUMBER; }
YY_BREAK
case 52:
YY_RULE_SETUP
#line 220 "config_lexer.ll"
{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
{ yylval->op = OperatorSet; return T_EQUAL; }
YY_BREAK
case 53:
YY_RULE_SETUP
#line 221 "config_lexer.ll"
{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
YY_BREAK
case 54:
YY_RULE_SETUP
#line 222 "config_lexer.ll"
{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }
{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
YY_BREAK
case 55:
YY_RULE_SETUP
#line 223 "config_lexer.ll"
{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }
YY_BREAK
case 56:
YY_RULE_SETUP
#line 224 "config_lexer.ll"
{ yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; }
YY_BREAK
case 56:
YY_RULE_SETUP
#line 226 "config_lexer.ll"
return yytext[0];
YY_BREAK
case 57:
YY_RULE_SETUP
#line 228 "config_lexer.ll"
#line 227 "config_lexer.ll"
return yytext[0];
YY_BREAK
case 58:
YY_RULE_SETUP
#line 229 "config_lexer.ll"
ECHO;
YY_BREAK
#line 1405 "../../../lib/config/config_lexer.cc"
#line 1410 "../../../lib/config/config_lexer.cc"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(C_COMMENT):
case YY_STATE_EOF(STRING):
@ -1699,7 +1704,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 194 )
if ( yy_current_state >= 196 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@ -1728,11 +1733,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 194 )
if ( yy_current_state >= 196 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 193);
yy_is_jam = (yy_current_state == 195);
return yy_is_jam ? 0 : yy_current_state;
}
@ -2591,7 +2596,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables"
#line 228 "config_lexer.ll"
#line 229 "config_lexer.ll"

View File

@ -209,6 +209,7 @@ null return T_NULL;
partial return T_PARTIAL;
true { yylval->num = 1; return T_NUMBER; }
false { yylval->num = 0; return T_NUMBER; }
set return T_SET;
[a-zA-Z_\*][:a-zA-Z0-9\-_\*]* { yylval->text = strdup(yytext); return T_IDENTIFIER; }
\<[^\>]*\> { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; }
-?[0-9]+(\.[0-9]+)?ms { yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }

File diff suppressed because it is too large Load Diff

View File

@ -65,6 +65,7 @@
#include "base/value.h"
#include "base/utility.h"
#include "base/array.h"
#include "base/scriptvariable.h"
#include <sstream>
#include <stack>
#include <boost/smart_ptr/make_shared.hpp>
@ -79,7 +80,7 @@ using namespace icinga;
/* Line 2068 of yacc.c */
#line 83 "../../../lib/config/config_parser.h"
#line 84 "../../../lib/config/config_parser.h"
/* Tokens. */
#ifndef YYTOKENTYPE
@ -97,25 +98,26 @@ using namespace icinga;
T_MINUS_EQUAL = 265,
T_MULTIPLY_EQUAL = 266,
T_DIVIDE_EQUAL = 267,
T_TYPE_DICTIONARY = 268,
T_TYPE_ARRAY = 269,
T_TYPE_NUMBER = 270,
T_TYPE_STRING = 271,
T_TYPE_SCALAR = 272,
T_TYPE_ANY = 273,
T_TYPE_NAME = 274,
T_VALIDATOR = 275,
T_REQUIRE = 276,
T_ATTRIBUTE = 277,
T_TYPE = 278,
T_ABSTRACT = 279,
T_LOCAL = 280,
T_OBJECT = 281,
T_TEMPLATE = 282,
T_INCLUDE = 283,
T_LIBRARY = 284,
T_INHERITS = 285,
T_PARTIAL = 286
T_SET = 268,
T_TYPE_DICTIONARY = 269,
T_TYPE_ARRAY = 270,
T_TYPE_NUMBER = 271,
T_TYPE_STRING = 272,
T_TYPE_SCALAR = 273,
T_TYPE_ANY = 274,
T_TYPE_NAME = 275,
T_VALIDATOR = 276,
T_REQUIRE = 277,
T_ATTRIBUTE = 278,
T_TYPE = 279,
T_ABSTRACT = 280,
T_LOCAL = 281,
T_OBJECT = 282,
T_TEMPLATE = 283,
T_INCLUDE = 284,
T_LIBRARY = 285,
T_INHERITS = 286,
T_PARTIAL = 287
};
#endif
/* Tokens. */
@ -129,25 +131,26 @@ using namespace icinga;
#define T_MINUS_EQUAL 265
#define T_MULTIPLY_EQUAL 266
#define T_DIVIDE_EQUAL 267
#define T_TYPE_DICTIONARY 268
#define T_TYPE_ARRAY 269
#define T_TYPE_NUMBER 270
#define T_TYPE_STRING 271
#define T_TYPE_SCALAR 272
#define T_TYPE_ANY 273
#define T_TYPE_NAME 274
#define T_VALIDATOR 275
#define T_REQUIRE 276
#define T_ATTRIBUTE 277
#define T_TYPE 278
#define T_ABSTRACT 279
#define T_LOCAL 280
#define T_OBJECT 281
#define T_TEMPLATE 282
#define T_INCLUDE 283
#define T_LIBRARY 284
#define T_INHERITS 285
#define T_PARTIAL 286
#define T_SET 268
#define T_TYPE_DICTIONARY 269
#define T_TYPE_ARRAY 270
#define T_TYPE_NUMBER 271
#define T_TYPE_STRING 272
#define T_TYPE_SCALAR 273
#define T_TYPE_ANY 274
#define T_TYPE_NAME 275
#define T_VALIDATOR 276
#define T_REQUIRE 277
#define T_ATTRIBUTE 278
#define T_TYPE 279
#define T_ABSTRACT 280
#define T_LOCAL 281
#define T_OBJECT 282
#define T_TEMPLATE 283
#define T_INCLUDE 284
#define T_LIBRARY 285
#define T_INHERITS 286
#define T_PARTIAL 287
@ -157,7 +160,7 @@ typedef union YYSTYPE
{
/* Line 2068 of yacc.c */
#line 53 "config_parser.yy"
#line 54 "config_parser.yy"
char *text;
double num;
@ -172,7 +175,7 @@ typedef union YYSTYPE
/* Line 2068 of yacc.c */
#line 176 "../../../lib/config/config_parser.h"
#line 179 "../../../lib/config/config_parser.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */

View File

@ -29,6 +29,7 @@
#include "base/value.h"
#include "base/utility.h"
#include "base/array.h"
#include "base/scriptvariable.h"
#include <sstream>
#include <stack>
#include <boost/smart_ptr/make_shared.hpp>
@ -72,6 +73,7 @@ using namespace icinga;
%token <op> T_MINUS_EQUAL "-= (T_MINUS_EQUAL)"
%token <op> T_MULTIPLY_EQUAL "*= (T_MULTIPLY_EQUAL)"
%token <op> T_DIVIDE_EQUAL "/= (T_DIVIDE_EQUAL)"
%token T_SET "set (T_SET)"
%token <type> T_TYPE_DICTIONARY "dictionary (T_TYPE_DICTIONARY)"
%token <type> T_TYPE_ARRAY "array (T_TYPE_ARRAY)"
%token <type> T_TYPE_NUMBER "number (T_TYPE_NUMBER)"
@ -107,8 +109,12 @@ using namespace icinga;
%type <num> partial_specifier
%type <slist> object_inherits_list
%type <slist> object_inherits_specifier
%type <num> constterm
%type <num> constexpression
%left '+' '-'
%left '*' '/'
%left '&'
%left '|'
%{
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
@ -149,7 +155,7 @@ statements: /* empty */
| statements statement
;
statement: object | type | include | library
statement: object | type | include | library | variable
;
include: T_INCLUDE T_STRING
@ -169,6 +175,13 @@ library: T_LIBRARY T_STRING
free($2);
}
variable: T_SET identifier T_EQUAL value
{
ScriptVariable::Set($2, *$4);
free($2);
delete $4;
}
identifier: T_IDENTIFIER
| T_STRING
{
@ -531,11 +544,59 @@ simplevalue: T_STRING
}
;
constterm: '(' constexpression ')'
{
$$ = $2;
}
constexpression: T_NUMBER
{
$$ = $1;
}
| identifier
{
$$ = ScriptVariable::Get($1);
free($1);
}
| constexpression '+' constexpression
{
$$ = $1 + $3;
}
| constexpression '-' constexpression
{
$$ = $1 - $3;
}
| constexpression '*' constexpression
{
$$ = $1 * $3;
}
| constexpression '/' constexpression
{
$$ = $1 / $3;
}
| constexpression '&' constexpression
{
$$ = (long)$1 & (long)$3;
}
| constexpression '|' constexpression
{
$$ = (long)$1 | (long)$3;
}
| '(' constexpression ')'
{
$$ = $2;
}
;
value: simplevalue
| expressionlist
{
ExpressionList::Ptr exprl = ExpressionList::Ptr($1);
$$ = new Value(exprl);
}
| constterm
{
$$ = new Value($1);
}
;
%%