diff --git a/Makefile.am b/Makefile.am index ccd79df5d..7c42f478c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,6 +7,8 @@ SUBDIRS = \ compat \ third-party \ base \ + dyn \ + dyntest \ jsonrpc \ icinga \ components \ diff --git a/components/configfile/Makefile.am b/components/configfile/Makefile.am index 931ae6790..f1d6783ff 100644 --- a/components/configfile/Makefile.am +++ b/components/configfile/Makefile.am @@ -3,9 +3,17 @@ pkglib_LTLIBRARIES = \ configfile.la +BUILD_SOURCES = icinga_parser.h + +AM_YFLAGS = -d + configfile_la_SOURCES = \ + configcontext.cpp \ + configcontext.h \ configfilecomponent.cpp \ configfilecomponent.h \ + icinga_lexer.ll \ + icinga_parser.yy \ i2-configfile.h configfile_la_CPPFLAGS = \ diff --git a/components/configfile/configcontext.cpp b/components/configfile/configcontext.cpp new file mode 100644 index 000000000..1abfa20a1 --- /dev/null +++ b/components/configfile/configcontext.cpp @@ -0,0 +1,16 @@ +#include +#include "configcontext.h" + +using namespace std; + +ConfigContext::ConfigContext(istream *input) +{ + Input = input; + InitializeScanner(); +} + +ConfigContext::~ConfigContext(void) +{ + DestroyScanner(); +} + diff --git a/components/configfile/configcontext.h b/components/configfile/configcontext.h new file mode 100644 index 000000000..4d4ada0b2 --- /dev/null +++ b/components/configfile/configcontext.h @@ -0,0 +1,20 @@ +#ifndef CONFIGCONTEXT_H +#define CONFIGCONTEXT_H + +class ConfigContext +{ +public: + ConfigContext(std::istream *input = &std::cin); + virtual ~ConfigContext(void); + + std::istream *Input; + void *Scanner; + +private: + void InitializeScanner(void); + void DestroyScanner(void); +}; + +int icingaparse(ConfigContext *context); + +#endif /* CONFIGCONTEXT_H */ diff --git a/components/configfile/icinga_lexer.ll b/components/configfile/icinga_lexer.ll new file mode 100644 index 000000000..e15183bfb --- /dev/null +++ b/components/configfile/icinga_lexer.ll @@ -0,0 +1,64 @@ +%{ +#include +#include "configcontext.h" +#include "icinga.tab.h" + +#define YY_EXTRA_TYPE ConfigContext * +#define YY_USER_ACTION yylloc->first_line = yylineno; + +#define YY_INPUT(buf, result, max_size) \ +do { \ + yyextra->Input->read(buf, max_size); \ + result = yyextra->Input->gcount(); \ +} while (0) +%} + +%option reentrant noyywrap yylineno +%option prefix="icinga" +%option bison-bridge bison-locations + +%x IN_C_COMMENT + +%% +abstract return T_ABSTRACT; +local return T_LOCAL; +object return T_OBJECT; +include return T_INCLUDE; +inherits return T_INHERITS; +[a-zA-Z][a-zA-Z0-9]* return T_IDENTIFIER; +\"[^\"]+\" { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING; } +[0-9]+ { yylval->num = atoi(yytext); return T_NUMBER; } +\{ return T_OPEN_BRACE; +\} return T_CLOSE_BRACE; +\[ return T_OPEN_BRACKET; +\] return T_CLOSE_BRACKET; +, return T_COMMA; += return T_EQUAL; + +{ +"/*" BEGIN(IN_C_COMMENT); +} + +{ +"*/" BEGIN(INITIAL); +[^*]+ /* ignore comment */ +"*" /* ignore star */ +} + +\/\/[^\n]+ /* ignore C++-style comments */ +#[^\n]+ /* ignore shell-style comments */ +[ \t\n]+ /* ignore whitespace */ +%% + + +void ConfigContext::InitializeScanner(void) +{ + yylex_init(&Scanner); + yyset_extra(this, Scanner); +} + +void ConfigContext::DestroyScanner(void) +{ + yylex_destroy(Scanner); +} + diff --git a/components/configfile/icinga_parser.yy b/components/configfile/icinga_parser.yy new file mode 100644 index 000000000..fc6adb1a6 --- /dev/null +++ b/components/configfile/icinga_parser.yy @@ -0,0 +1,105 @@ +%pure-parser +%name-prefix="icinga" + +%locations +%defines +%error-verbose + +%parse-param { ConfigContext *context } +%lex-param { void *scanner } + +%union { + char *text; + int num; +} + +%token T_STRING +%token T_NUMBER +%token T_IDENTIFIER +%token T_OPEN_BRACE +%token T_CLOSE_BRACE +%token T_OPEN_BRACKET +%token T_CLOSE_BRACKET +%token T_EQUAL +%token T_COMMA +%token T_ABSTRACT +%token T_LOCAL +%token T_OBJECT +%token T_INCLUDE +%token T_INHERITS + +%{ +#include +#include "configcontext.h" + +int icingalex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner); + +void icingaerror(YYLTYPE *locp, ConfigContext *context, const char *err) +{ + std::cout << locp->first_line << ":" << locp->first_column + << "-" + << locp->last_line << ":" << locp->last_column + << ": " << err << std::endl; +} + +#define scanner context->Scanner + +%} + +%% +statements: /* empty */ + | statements statement + ; + +statement: object | include + ; + +include: T_INCLUDE T_STRING + ; + +object: attributes_list object_declaration + | object_declaration + ; + +object_declaration: T_OBJECT T_IDENTIFIER T_STRING inherits_specifier dictionary + ; + +attributes_list: attributes_list attribute + | attribute + ; + +attribute: T_ABSTRACT + | T_LOCAL + ; + +inherits_list: T_STRING + | inherits_list T_COMMA T_STRING + ; + +inherits_specifier: /* empty */ + | T_INHERITS inherits_list + ; + +dictionary: T_OPEN_BRACE nvpairs T_CLOSE_BRACE + ; + +nvpairs: /* empty */ + | nvpair + | nvpairs T_COMMA nvpair + ; + +nvpair: T_IDENTIFIER T_EQUAL value + ; + +value: T_STRING | T_NUMBER | array | dictionary + ; + +array: T_OPEN_BRACKET arrayitems T_CLOSE_BRACKET + ; + +arrayitems: + /* empty */ + | value + | arrayitems T_COMMA value + ; +%% diff --git a/configure.ac b/configure.ac index eeab8d6d2..5577e5f1c 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,8 @@ DX_PS_FEATURE(OFF) DX_INIT_DOXYGEN([icinga], [Doxyfile], [doc]) AC_PROG_INSTALL +AM_PROG_LEX +AC_PROG_YACC AC_PROG_LIBTOOL AX_CXX_COMPILE_STDCXX_0X AX_CXX_GCC_ABI_DEMANGLE @@ -71,6 +73,8 @@ components/configfile/Makefile components/configrpc/Makefile components/demo/Makefile components/discovery/Makefile +dyn/Makefile +dyntest/Makefile icinga/Makefile icinga-app/Makefile jsonrpc/Makefile diff --git a/dyn/Makefile.am b/dyn/Makefile.am new file mode 100644 index 000000000..2d8136059 --- /dev/null +++ b/dyn/Makefile.am @@ -0,0 +1,28 @@ +## Process this file with automake to produce Makefile.in + + +pkglib_LTLIBRARIES = \ + libdyn.la + +libdyn_la_SOURCES = \ + i2-dyn.h \ + dynamicobject.cpp \ + dynamicobject.h \ + objectset.cpp \ + objectset.h \ + objectmap.cpp \ + objectmap.h + +libdyn_la_CPPFLAGS = \ + -DI2_DYN_BUILD \ + $(BOOST_CPPFLAGS) \ + -I${top_srcdir}/base + +libdyn_la_LDFLAGS = \ + $(BOOST_LDFLAGS) \ + -no-undefined \ + @RELEASE_INFO@ \ + @VERSION_INFO@ + +libdyn_la_LIBADD = \ + ${top_builddir}/base/libbase.la diff --git a/dyntest/Makefile.am b/dyntest/Makefile.am new file mode 100644 index 000000000..8dcdc755c --- /dev/null +++ b/dyntest/Makefile.am @@ -0,0 +1,22 @@ +## Process this file with automake to produce Makefile.in + + +bin_PROGRAMS = \ + dyntest + +dyntest_SOURCES = \ + dyntest.cpp + +dyntest_CPPFLAGS = \ + -DI2_DYNTEST_BUILD \ + $(BOOST_CPPFLAGS) \ + -I${top_srcdir}/base \ + -I${top_srcdir}/dyn \ + -I${top_srcdir} + +dyntest_LDFLAGS = \ + $(BOOST_LDFLAGS) + +dyntest_LDADD = \ + ${top_builddir}/base/libbase.la \ + ${top_builddir}/dyn/libdyn.la