diff --git a/docs/icinga2-config.txt b/docs/icinga2-config.txt index 70cdd2288..8873a0620 100644 --- a/docs/icinga2-config.txt +++ b/docs/icinga2-config.txt @@ -312,6 +312,20 @@ Example: NOTE: Wildcard includes are not currently implemented. +Library directive +~~~~~~~~~~~~~~~~~ + +The "#library" directive can be used to manually load additional libraries. +Upon loading these libraries may provide additional classes or methods. + +Example: + +------------------------------------------------------------------------------- +#library "snmphelper" +------------------------------------------------------------------------------- + +NOTE: The "icinga" library is automatically loaded by Icinga. + Configuration Objects --------------------- diff --git a/icinga-app/Makefile.am b/icinga-app/Makefile.am index 813af82a7..9665a9f58 100644 --- a/icinga-app/Makefile.am +++ b/icinga-app/Makefile.am @@ -31,7 +31,7 @@ icinga2_LDADD = \ ${top_builddir}/lib/base/libbase.la \ ${top_builddir}/lib/config/libconfig.la \ ${top_builddir}/lib/remoting/libremoting.la \ - ${top_builddir}/lib/icinga/libicinga.la \ + -dlopen ${top_builddir}/lib/icinga/libicinga.la \ -dlopen ${top_builddir}/components/checker/checker.la \ -dlopen ${top_builddir}/components/replication/replication.la \ -dlopen ${top_builddir}/components/compat/compat.la \ diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 8402df55f..74b8500ec 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -140,6 +140,8 @@ int main(int argc, char **argv) Component::AddSearchDir(Application::GetPkgLibDir()); + Utility::LoadIcingaLibrary("icinga", false); + try { DynamicObject::BeginTx(); diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 23dac5ed9..dcf4b2e2d 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -19,10 +19,6 @@ #include "i2-base.h" -#ifndef _WIN32 -# include -#endif /* _WIN32 */ - using namespace icinga; Application *Application::m_Instance = NULL; diff --git a/lib/base/component.cpp b/lib/base/component.cpp index cf8413e7b..928cca446 100644 --- a/lib/base/component.cpp +++ b/lib/base/component.cpp @@ -18,9 +18,6 @@ ******************************************************************************/ #include "i2-base.h" -#ifndef _WIN32 -# include -#endif /* _WIN32 */ using namespace icinga; @@ -37,27 +34,16 @@ Component::Component(const Dictionary::Ptr& properties) if (!IsLocal()) throw_exception(runtime_error("Component objects must be local.")); - String path; #ifdef _WIN32 - path = GetName() + ".dll"; + HMODULE #else /* _WIN32 */ - path = GetName() + ".la"; + lt_dlhandle #endif /* _WIN32 */ + hModule; - Logger::Write(LogInformation, "base", "Loading component '" + GetName() + "' (using library '" + path + "')"); + Logger::Write(LogInformation, "base", "Loading component '" + GetName() + "'"); -#ifdef _WIN32 - HMODULE hModule = LoadLibrary(path.CStr()); - - if (hModule == NULL) - throw_exception(Win32Exception("LoadLibrary('" + path + "') failed", GetLastError())); -#else /* _WIN32 */ - lt_dlhandle hModule = lt_dlopen(path.CStr()); - - if (hModule == NULL) { - throw_exception(runtime_error("Could not load module '" + path + "': " + lt_dlerror())); - } -#endif /* _WIN32 */ + hModule = Utility::LoadIcingaLibrary(GetName(), true); CreateComponentFunction pCreateComponent; diff --git a/lib/base/unix.h b/lib/base/unix.h index df0b5e2a9..56ca602a5 100644 --- a/lib/base/unix.h +++ b/lib/base/unix.h @@ -37,6 +37,7 @@ #include #include #include +#include typedef int SOCKET; #define INVALID_SOCKET (-1) diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index 1eae0f3a3..83371d161 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -334,3 +334,45 @@ void Utility::Sleep(double timeout) #endif /* _WIN32 */ } +/** + * Loads the specified library and invokes an Icinga-specific init + * function if available. + * + * @param library The name of the library. + * @param module Whether the library is a module (non-module libraries have a + * "lib" prefix on *NIX). + */ +#ifdef _WIN32 +HMODULE +#else /* _WIN32 */ +lt_dlhandle +#endif /* _WIN32 */ +Utility::LoadIcingaLibrary(const String& library, bool module) +{ + String path; +#ifdef _WIN32 + path = library + ".dll"; +#else /* _WIN32 */ + path = (module ? "" : "lib") + library + ".la"; +#endif /* _WIN32 */ + + Logger::Write(LogInformation, "base", "Loading library '" + path + "'"); + +#ifdef _WIN32 + HMODULE hModule = LoadLibrary(path.CStr()); + + if (hModule == NULL) + throw_exception(Win32Exception("LoadLibrary('" + path + "') failed", GetLastError())); +#else /* _WIN32 */ + lt_dlhandle hModule = lt_dlopen(path.CStr()); + + if (hModule == NULL) { + throw_exception(runtime_error("Could not load library '" + path + "': " + lt_dlerror())); + } +#endif /* _WIN32 */ + + // TODO: call InitializeLibrary + + return hModule; +} + diff --git a/lib/base/utility.h b/lib/base/utility.h index 50c97ce3f..9ac16d023 100644 --- a/lib/base/utility.h +++ b/lib/base/utility.h @@ -53,6 +53,14 @@ public: static void Sleep(double timeout); + static +#ifdef _WIN32 + HMODULE +#else /* _WIN32 */ + lt_dlhandle +#endif /* _WIN32 */ + LoadIcingaLibrary(const String& library, bool module); + private: static bool m_SSLInitialized; diff --git a/lib/config/config_lexer.cc b/lib/config/config_lexer.cc index e8b32b898..46f3d18bf 100644 --- a/lib/config/config_lexer.cc +++ b/lib/config/config_lexer.cc @@ -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 25 -#define YY_END_OF_BUFFER 26 +#define YY_NUM_RULES 26 +#define YY_END_OF_BUFFER 27 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -379,16 +379,17 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[78] = +static yyconst flex_int16_t yy_accept[85] = { 0, - 0, 0, 0, 0, 26, 24, 23, 23, 24, 24, - 24, 24, 24, 24, 12, 13, 7, 7, 7, 7, - 7, 7, 20, 21, 23, 0, 8, 0, 16, 14, - 12, 15, 18, 0, 17, 0, 9, 10, 11, 7, - 7, 7, 7, 7, 7, 20, 19, 0, 22, 12, - 7, 7, 7, 7, 7, 0, 7, 7, 7, 6, - 7, 0, 7, 7, 2, 7, 0, 7, 7, 3, - 0, 7, 7, 4, 1, 5, 0 + 0, 0, 0, 0, 27, 25, 24, 24, 25, 25, + 25, 25, 25, 25, 13, 14, 8, 8, 8, 8, + 8, 8, 21, 22, 24, 0, 9, 0, 0, 17, + 15, 13, 16, 19, 0, 18, 0, 10, 11, 12, + 8, 8, 8, 8, 8, 8, 21, 20, 0, 0, + 23, 13, 8, 8, 8, 8, 8, 0, 0, 8, + 8, 8, 7, 8, 0, 0, 8, 8, 2, 8, + 0, 0, 8, 8, 3, 0, 0, 8, 8, 4, + 5, 1, 6, 0 } ; static yyconst flex_int32_t yy_ec[256] = @@ -406,7 +407,7 @@ static yyconst flex_int32_t yy_ec[256] = 18, 13, 13, 19, 20, 21, 13, 22, 23, 24, 25, 13, 13, 26, 27, 28, 29, 13, 13, 13, - 13, 13, 1, 1, 1, 1, 1, 1, 1, 1, + 30, 13, 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, @@ -423,82 +424,84 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[30] = +static yyconst flex_int32_t yy_meta[31] = { 0, 1, 1, 2, 1, 1, 3, 1, 4, 1, 1, 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4 + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 } ; -static yyconst flex_int16_t yy_base[83] = +static yyconst flex_int16_t yy_base[90] = { 0, - 0, 0, 100, 99, 104, 107, 28, 30, 99, 82, - 89, 88, 23, 30, 34, 107, 0, 84, 74, 72, - 67, 80, 0, 84, 35, 89, 107, 68, 107, 107, - 0, 107, 107, 0, 107, 80, 107, 107, 107, 0, - 63, 70, 72, 65, 65, 0, 107, 69, 0, 28, - 56, 65, 68, 59, 62, 57, 52, 49, 50, 0, - 44, 30, 44, 36, 0, 26, 35, 34, 21, 0, - 30, 18, 17, 107, 0, 0, 107, 61, 65, 37, - 69, 73 + 0, 0, 108, 107, 112, 115, 29, 31, 107, 15, + 98, 97, 27, 30, 34, 115, 0, 93, 83, 81, + 76, 89, 0, 93, 44, 98, 115, 77, 80, 115, + 115, 0, 115, 115, 0, 115, 88, 115, 115, 115, + 0, 71, 78, 80, 73, 73, 0, 115, 77, 77, + 0, 33, 63, 72, 75, 66, 69, 64, 59, 58, + 57, 60, 0, 65, 51, 65, 64, 55, 0, 44, + 42, 32, 39, 26, 0, 33, 20, 21, 21, 115, + 115, 0, 0, 115, 61, 65, 37, 69, 73 } ; -static yyconst flex_int16_t yy_def[83] = +static yyconst flex_int16_t yy_def[90] = { 0, - 77, 1, 78, 78, 77, 77, 77, 77, 79, 77, - 77, 77, 77, 77, 77, 77, 80, 80, 80, 80, - 80, 80, 81, 77, 77, 79, 77, 77, 77, 77, - 15, 77, 77, 82, 77, 77, 77, 77, 77, 80, - 80, 80, 80, 80, 80, 81, 77, 77, 82, 77, - 80, 80, 80, 80, 80, 77, 80, 80, 80, 80, - 80, 77, 80, 80, 80, 80, 77, 80, 80, 80, - 77, 80, 80, 77, 80, 80, 0, 77, 77, 77, - 77, 77 + 84, 1, 85, 85, 84, 84, 84, 84, 86, 84, + 84, 84, 84, 84, 84, 84, 87, 87, 87, 87, + 87, 87, 88, 84, 84, 86, 84, 84, 84, 84, + 84, 15, 84, 84, 89, 84, 84, 84, 84, 84, + 87, 87, 87, 87, 87, 87, 88, 84, 84, 84, + 89, 84, 87, 87, 87, 87, 87, 84, 84, 87, + 87, 87, 87, 87, 84, 84, 87, 87, 87, 87, + 84, 84, 87, 87, 87, 84, 84, 87, 87, 84, + 84, 87, 87, 0, 84, 84, 84, 84, 84 } ; -static yyconst flex_int16_t yy_nxt[137] = +static yyconst flex_int16_t yy_nxt[146] = { 0, 6, 7, 8, 9, 10, 11, 12, 13, 6, 14, 15, 16, 17, 18, 17, 17, 17, 17, 17, 19, - 17, 20, 17, 21, 22, 17, 17, 17, 17, 25, - 25, 25, 25, 31, 32, 33, 25, 25, 50, 34, - 40, 35, 36, 76, 31, 75, 37, 74, 73, 72, - 38, 71, 37, 70, 39, 69, 38, 68, 67, 66, - 39, 23, 23, 23, 23, 26, 26, 26, 26, 46, - 46, 65, 46, 49, 64, 49, 49, 63, 62, 61, - 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, - 50, 48, 27, 47, 45, 44, 43, 42, 41, 30, + 17, 20, 17, 21, 22, 17, 17, 17, 17, 17, + 25, 25, 25, 25, 28, 34, 29, 32, 33, 35, + 41, 36, 37, 52, 32, 25, 25, 83, 82, 81, + 80, 38, 38, 79, 78, 39, 39, 77, 76, 40, + 40, 23, 23, 23, 23, 26, 26, 26, 26, 47, + 47, 75, 47, 51, 74, 51, 51, 73, 72, 71, + 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, + 60, 59, 58, 57, 56, 55, 54, 53, 52, 50, - 29, 28, 27, 77, 24, 24, 5, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77 + 49, 27, 48, 46, 45, 44, 43, 42, 31, 30, + 27, 84, 24, 24, 5, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84 } ; -static yyconst flex_int16_t yy_chk[137] = +static yyconst flex_int16_t yy_chk[146] = { 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, 7, - 7, 8, 8, 13, 13, 14, 25, 25, 50, 14, - 80, 14, 15, 73, 15, 72, 50, 71, 69, 68, - 50, 67, 15, 66, 50, 64, 15, 63, 62, 61, - 15, 78, 78, 78, 78, 79, 79, 79, 79, 81, - 81, 59, 81, 82, 58, 82, 82, 57, 56, 55, - 54, 53, 52, 51, 48, 45, 44, 43, 42, 41, - 36, 28, 26, 24, 22, 21, 20, 19, 18, 12, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 7, 7, 8, 8, 10, 14, 10, 13, 13, 14, + 87, 14, 15, 52, 15, 25, 25, 79, 78, 77, + 76, 52, 15, 74, 73, 52, 15, 72, 71, 52, + 15, 85, 85, 85, 85, 86, 86, 86, 86, 88, + 88, 70, 88, 89, 68, 89, 89, 67, 66, 65, + 64, 62, 61, 60, 59, 58, 57, 56, 55, 54, + 53, 50, 49, 46, 45, 44, 43, 42, 37, 29, - 11, 10, 9, 5, 4, 3, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 77, 77 + 28, 26, 24, 22, 21, 20, 19, 18, 12, 11, + 9, 5, 4, 3, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84 } ; /* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[26] = +static yyconst flex_int32_t yy_rule_can_match_eol[27] = { 0, -0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 1, 0, 0, }; +0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 1, 0, 0, }; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. @@ -550,7 +553,7 @@ do { \ } while (0) #define YY_NO_UNISTD_H 1 -#line 554 "config_lexer.cc" +#line 557 "config_lexer.cc" #define INITIAL 0 #define IN_C_COMMENT 1 @@ -799,7 +802,7 @@ YY_DECL #line 49 "config_lexer.ll" -#line 803 "config_lexer.cc" +#line 806 "config_lexer.cc" yylval = yylval_param; @@ -856,13 +859,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 >= 78 ) + if ( yy_current_state >= 85 ) 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 != 77 ); + while ( yy_current_state != 84 ); yy_cp = yyg->yy_last_accepting_cpos; yy_current_state = yyg->yy_last_accepting_state; @@ -917,38 +920,38 @@ return T_INCLUDE; case 5: YY_RULE_SETUP #line 54 "config_lexer.ll" -return T_INHERITS; +return T_LIBRARY; YY_BREAK case 6: YY_RULE_SETUP #line 55 "config_lexer.ll" -return T_NULL; +return T_INHERITS; YY_BREAK case 7: YY_RULE_SETUP #line 56 "config_lexer.ll" -{ yylval->text = strdup(yytext); return T_IDENTIFIER; } +return T_NULL; YY_BREAK case 8: -/* rule 8 can match eol */ YY_RULE_SETUP #line 57 "config_lexer.ll" -{ yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING; } +{ yylval->text = strdup(yytext); return T_IDENTIFIER; } YY_BREAK case 9: +/* rule 9 can match eol */ YY_RULE_SETUP #line 58 "config_lexer.ll" -{ yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; } +{ yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING; } YY_BREAK case 10: YY_RULE_SETUP #line 59 "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 11: YY_RULE_SETUP #line 60 "config_lexer.ll" -{ yylval->num = strtod(yytext, NULL); return T_NUMBER; } +{ yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; } YY_BREAK case 12: YY_RULE_SETUP @@ -958,75 +961,80 @@ YY_RULE_SETUP case 13: YY_RULE_SETUP #line 62 "config_lexer.ll" -{ yylval->op = OperatorSet; return T_EQUAL; } +{ yylval->num = strtod(yytext, NULL); return T_NUMBER; } YY_BREAK case 14: YY_RULE_SETUP #line 63 "config_lexer.ll" -{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; } +{ yylval->op = OperatorSet; return T_EQUAL; } YY_BREAK case 15: YY_RULE_SETUP #line 64 "config_lexer.ll" -{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; } +{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; } YY_BREAK case 16: YY_RULE_SETUP #line 65 "config_lexer.ll" -{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; } +{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; } YY_BREAK case 17: YY_RULE_SETUP #line 66 "config_lexer.ll" +{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 67 "config_lexer.ll" { yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; } YY_BREAK -case 18: +case 19: YY_RULE_SETUP -#line 69 "config_lexer.ll" +#line 70 "config_lexer.ll" BEGIN(IN_C_COMMENT); YY_BREAK -case 19: -YY_RULE_SETUP -#line 73 "config_lexer.ll" -BEGIN(INITIAL); - YY_BREAK case 20: -/* rule 20 can match eol */ YY_RULE_SETUP #line 74 "config_lexer.ll" -/* ignore comment */ +BEGIN(INITIAL); YY_BREAK case 21: +/* rule 21 can match eol */ YY_RULE_SETUP #line 75 "config_lexer.ll" +/* ignore comment */ + YY_BREAK +case 22: +YY_RULE_SETUP +#line 76 "config_lexer.ll" /* ignore star */ YY_BREAK -case 22: -YY_RULE_SETUP -#line 78 "config_lexer.ll" -/* ignore C++-style comments */ - YY_BREAK case 23: -/* rule 23 can match eol */ YY_RULE_SETUP #line 79 "config_lexer.ll" -/* ignore whitespace */ +/* ignore C++-style comments */ YY_BREAK case 24: +/* rule 24 can match eol */ YY_RULE_SETUP -#line 81 "config_lexer.ll" -return yytext[0]; +#line 80 "config_lexer.ll" +/* ignore whitespace */ YY_BREAK case 25: YY_RULE_SETUP #line 82 "config_lexer.ll" +return yytext[0]; + YY_BREAK +case 26: +YY_RULE_SETUP +#line 83 "config_lexer.ll" ECHO; YY_BREAK -#line 1030 "config_lexer.cc" +#line 1038 "config_lexer.cc" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(IN_C_COMMENT): yyterminate(); @@ -1322,7 +1330,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 >= 78 ) + if ( yy_current_state >= 85 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1351,11 +1359,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 >= 78 ) + if ( yy_current_state >= 85 ) 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 == 77); + yy_is_jam = (yy_current_state == 84); return yy_is_jam ? 0 : yy_current_state; } @@ -2214,7 +2222,7 @@ void yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 82 "config_lexer.ll" +#line 83 "config_lexer.ll" diff --git a/lib/config/config_lexer.ll b/lib/config/config_lexer.ll index b0931bba0..468da1994 100644 --- a/lib/config/config_lexer.ll +++ b/lib/config/config_lexer.ll @@ -51,6 +51,7 @@ abstract return T_ABSTRACT; local return T_LOCAL; object return T_OBJECT; #include return T_INCLUDE; +#library return T_LIBRARY; inherits return T_INHERITS; null return T_NULL; [a-zA-Z_][a-zA-Z0-9\-_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; } diff --git a/lib/config/config_parser.cc b/lib/config/config_parser.cc index 508c8052b..e1168e699 100644 --- a/lib/config/config_parser.cc +++ b/lib/config/config_parser.cc @@ -142,7 +142,8 @@ using namespace icinga; T_LOCAL = 268, T_OBJECT = 269, T_INCLUDE = 270, - T_INHERITS = 271 + T_LIBRARY = 271, + T_INHERITS = 272 }; #endif /* Tokens. */ @@ -159,7 +160,8 @@ using namespace icinga; #define T_LOCAL 268 #define T_OBJECT 269 #define T_INCLUDE 270 -#define T_INHERITS 271 +#define T_LIBRARY 271 +#define T_INHERITS 272 @@ -179,7 +181,7 @@ typedef union YYSTYPE /* Line 293 of yacc.c */ -#line 183 "config_parser.cc" +#line 185 "config_parser.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -203,7 +205,7 @@ typedef struct YYLTYPE /* Copy the second part of user declarations. */ /* Line 343 of yacc.c */ -#line 65 "config_parser.yy" +#line 66 "config_parser.yy" int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner); @@ -233,7 +235,7 @@ void ConfigCompiler::Compile(void) /* Line 343 of yacc.c */ -#line 237 "config_parser.cc" +#line 239 "config_parser.cc" #ifdef short # undef short @@ -454,20 +456,20 @@ union yyalloc /* YYFINAL -- State number of the termination state. */ #define YYFINAL 2 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 40 +#define YYLAST 45 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 26 +#define YYNTOKENS 27 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 20 +#define YYNNTS 21 /* YYNRULES -- Number of rules. */ -#define YYNRULES 38 +#define YYNRULES 40 /* YYNRULES -- Number of states. */ -#define YYNSTATES 52 +#define YYNSTATES 55 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 271 +#define YYMAXUTOK 272 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) @@ -479,15 +481,15 @@ static const yytype_uint8 yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 19, 17, 21, 18, 2, 20, 2, 2, + 2, 2, 20, 18, 22, 19, 2, 21, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 24, 2, 25, 2, 2, 2, 2, 2, 2, + 2, 25, 2, 26, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 22, 2, 23, 2, 2, 2, 2, + 2, 2, 2, 23, 2, 24, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -502,7 +504,7 @@ static const yytype_uint8 yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16 + 15, 16, 17 }; #if YYDEBUG @@ -510,34 +512,37 @@ static const yytype_uint8 yytranslate[] = YYRHS. */ static const yytype_uint8 yyprhs[] = { - 0, 0, 3, 4, 7, 9, 11, 14, 15, 16, - 25, 26, 29, 31, 33, 35, 39, 41, 42, 45, - 46, 51, 53, 56, 57, 59, 63, 67, 74, 76, - 78, 80, 82, 84, 86, 88, 90, 92, 94 + 0, 0, 3, 4, 7, 9, 11, 13, 16, 19, + 20, 21, 30, 31, 34, 36, 38, 40, 44, 46, + 47, 50, 51, 56, 58, 61, 62, 64, 68, 72, + 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, + 99 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yytype_int8 yyrhs[] = { - 27, 0, -1, -1, 27, 28, -1, 30, -1, 29, - -1, 15, 3, -1, -1, -1, 31, 33, 14, 6, - 3, 32, 37, 38, -1, -1, 33, 34, -1, 12, - -1, 13, -1, 36, -1, 35, 21, 36, -1, 3, - -1, -1, 16, 35, -1, -1, 22, 39, 40, 23, - -1, 41, -1, 41, 21, -1, -1, 42, -1, 41, - 21, 42, -1, 6, 43, 45, -1, 6, 24, 3, - 25, 43, 45, -1, 3, -1, 7, -1, 8, -1, - 9, -1, 10, -1, 11, -1, 3, -1, 4, -1, - 5, -1, 44, -1, 38, -1 + 28, 0, -1, -1, 28, 29, -1, 32, -1, 30, + -1, 31, -1, 15, 3, -1, 16, 3, -1, -1, + -1, 33, 35, 14, 6, 3, 34, 39, 40, -1, + -1, 35, 36, -1, 12, -1, 13, -1, 38, -1, + 37, 22, 38, -1, 3, -1, -1, 17, 37, -1, + -1, 23, 41, 42, 24, -1, 43, -1, 43, 22, + -1, -1, 44, -1, 43, 22, 44, -1, 6, 45, + 47, -1, 6, 25, 3, 26, 45, 47, -1, 3, + -1, 7, -1, 8, -1, 9, -1, 10, -1, 11, + -1, 3, -1, 4, -1, 5, -1, 46, -1, 40, + -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 94, 94, 95, 98, 98, 101, 107, 112, 107, - 131, 132, 135, 139, 145, 146, 149, 156, 157, 161, - 160, 172, 173, 175, 176, 177, 180, 188, 202, 211, - 212, 213, 214, 215, 221, 226, 230, 236, 237 + 0, 95, 95, 96, 99, 99, 99, 102, 107, 113, + 118, 113, 137, 138, 141, 145, 151, 152, 155, 162, + 163, 167, 166, 178, 179, 181, 182, 183, 186, 194, + 208, 217, 218, 219, 220, 221, 227, 232, 236, 242, + 243 }; #endif @@ -549,12 +554,12 @@ static const char *const yytname[] = "$end", "error", "$undefined", "T_STRING", "T_NUMBER", "T_NULL", "T_IDENTIFIER", "T_EQUAL", "T_PLUS_EQUAL", "T_MINUS_EQUAL", "T_MULTIPLY_EQUAL", "T_DIVIDE_EQUAL", "T_ABSTRACT", "T_LOCAL", - "T_OBJECT", "T_INCLUDE", "T_INHERITS", "'+'", "'-'", "'*'", "'/'", "','", - "'{'", "'}'", "'['", "']'", "$accept", "statements", "statement", - "include", "object", "$@1", "$@2", "attributes", "attribute", - "inherits_list", "inherits_item", "inherits_specifier", "expressionlist", - "$@3", "expressions", "expressions_inner", "expression", "operator", - "simplevalue", "value", 0 + "T_OBJECT", "T_INCLUDE", "T_LIBRARY", "T_INHERITS", "'+'", "'-'", "'*'", + "'/'", "','", "'{'", "'}'", "'['", "']'", "$accept", "statements", + "statement", "include", "library", "object", "$@1", "$@2", "attributes", + "attribute", "inherits_list", "inherits_item", "inherits_specifier", + "expressionlist", "$@3", "expressions", "expressions_inner", + "expression", "operator", "simplevalue", "value", 0 }; #endif @@ -564,27 +569,29 @@ static const char *const yytname[] = static const yytype_uint16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 43, 45, 42, - 47, 44, 123, 125, 91, 93 + 265, 266, 267, 268, 269, 270, 271, 272, 43, 45, + 42, 47, 44, 123, 125, 91, 93 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint8 yyr1[] = { - 0, 26, 27, 27, 28, 28, 29, 31, 32, 30, - 33, 33, 34, 34, 35, 35, 36, 37, 37, 39, - 38, 40, 40, 41, 41, 41, 42, 42, 42, 43, - 43, 43, 43, 43, 44, 44, 44, 45, 45 + 0, 27, 28, 28, 29, 29, 29, 30, 31, 33, + 34, 32, 35, 35, 36, 36, 37, 37, 38, 39, + 39, 41, 40, 42, 42, 43, 43, 43, 44, 44, + 44, 45, 45, 45, 45, 45, 46, 46, 46, 47, + 47 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const yytype_uint8 yyr2[] = { - 0, 2, 0, 2, 1, 1, 2, 0, 0, 8, - 0, 2, 1, 1, 1, 3, 1, 0, 2, 0, - 4, 1, 2, 0, 1, 3, 3, 6, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1 + 0, 2, 0, 2, 1, 1, 1, 2, 2, 0, + 0, 8, 0, 2, 1, 1, 1, 3, 1, 0, + 2, 0, 4, 1, 2, 0, 1, 3, 3, 6, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1 }; /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. @@ -592,39 +599,41 @@ static const yytype_uint8 yyr2[] = means the default is an error. */ static const yytype_uint8 yydefact[] = { - 2, 7, 1, 0, 3, 5, 4, 10, 6, 0, - 12, 13, 0, 11, 0, 8, 17, 0, 0, 16, - 18, 14, 19, 9, 0, 23, 15, 28, 0, 0, - 21, 24, 29, 30, 31, 32, 33, 0, 0, 20, - 22, 0, 34, 35, 36, 38, 37, 26, 25, 0, - 0, 27 + 2, 9, 1, 0, 0, 3, 5, 6, 4, 12, + 7, 8, 0, 14, 15, 0, 13, 0, 10, 19, + 0, 0, 18, 20, 16, 21, 11, 0, 25, 17, + 30, 0, 0, 23, 26, 31, 32, 33, 34, 35, + 0, 0, 22, 24, 0, 36, 37, 38, 40, 39, + 28, 27, 0, 0, 29 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int8 yydefgoto[] = { - -1, 1, 4, 5, 6, 7, 16, 9, 13, 20, - 21, 18, 45, 25, 29, 30, 31, 38, 46, 47 + -1, 1, 5, 6, 7, 8, 9, 19, 12, 16, + 23, 24, 21, 48, 28, 32, 33, 34, 41, 49, + 50 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ -#define YYPACT_NINF -17 +#define YYPACT_NINF -19 static const yytype_int8 yypact[] = { - -17, 8, -17, 13, -17, -17, -17, -17, -17, 12, - -17, -17, 9, -17, 15, -17, 5, 19, 6, -17, - 10, -17, -17, -17, 19, 11, -17, -17, -4, 4, - 14, -17, -17, -17, -17, -17, -17, 26, -3, -17, - 11, 7, -17, -17, -17, -17, -17, -17, -17, 2, - -3, -17 + -19, 8, -19, 12, 15, -19, -19, -19, -19, -19, + -19, -19, 13, -19, -19, 10, -19, 16, -19, 5, + 25, 6, -19, 9, -19, -19, -19, 25, 11, -19, + -19, -4, 14, 17, -19, -19, -19, -19, -19, -19, + 27, -3, -19, 11, 7, -19, -19, -19, -19, -19, + -19, -19, 2, -3, -19 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { - -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, - 16, -17, 18, -17, -17, -17, -10, -16, -17, -13 + -19, -19, -19, -19, -19, -19, -19, -19, -19, -19, + -19, 18, -19, 19, -19, -19, -19, -11, -18, -19, + -17 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If @@ -633,15 +642,15 @@ static const yytype_int8 yypgoto[] = #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { - 42, 43, 44, 32, 33, 34, 35, 36, 2, 32, - 33, 34, 35, 36, 27, 14, 8, 28, 15, 22, - 37, 17, 19, 3, 10, 11, 12, 39, 22, 41, - 48, 24, 49, 50, 0, 40, 23, 51, 0, 0, - 26 + 45, 46, 47, 35, 36, 37, 38, 39, 2, 35, + 36, 37, 38, 39, 30, 10, 17, 31, 11, 18, + 25, 40, 20, 3, 4, 13, 14, 15, 22, 25, + 44, 27, 51, 52, 53, 0, 54, 0, 42, 43, + 26, 0, 0, 0, 0, 29 }; #define yypact_value_is_default(yystate) \ - ((yystate) == (-17)) + ((yystate) == (-19)) #define yytable_value_is_error(yytable_value) \ YYID (0) @@ -649,22 +658,22 @@ static const yytype_uint8 yytable[] = static const yytype_int8 yycheck[] = { 3, 4, 5, 7, 8, 9, 10, 11, 0, 7, - 8, 9, 10, 11, 3, 6, 3, 6, 3, 22, - 24, 16, 3, 15, 12, 13, 14, 23, 22, 3, - 40, 21, 25, 49, -1, 21, 18, 50, -1, -1, - 24 + 8, 9, 10, 11, 3, 3, 6, 6, 3, 3, + 23, 25, 17, 15, 16, 12, 13, 14, 3, 23, + 3, 22, 43, 26, 52, -1, 53, -1, 24, 22, + 21, -1, -1, -1, -1, 27 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { - 0, 27, 0, 15, 28, 29, 30, 31, 3, 33, - 12, 13, 14, 34, 6, 3, 32, 16, 37, 3, - 35, 36, 22, 38, 21, 39, 36, 3, 6, 40, - 41, 42, 7, 8, 9, 10, 11, 24, 43, 23, - 21, 3, 3, 4, 5, 38, 44, 45, 42, 25, - 43, 45 + 0, 28, 0, 15, 16, 29, 30, 31, 32, 33, + 3, 3, 35, 12, 13, 14, 36, 6, 3, 34, + 17, 39, 3, 37, 38, 23, 40, 22, 41, 38, + 3, 6, 42, 43, 44, 7, 8, 9, 10, 11, + 25, 45, 24, 22, 3, 3, 4, 5, 40, 46, + 47, 44, 26, 45, 47 }; #define yyerrok (yyerrstatus = 0) @@ -1547,29 +1556,38 @@ yyreduce: YY_REDUCE_PRINT (yyn); switch (yyn) { - case 6: + case 7: /* Line 1806 of yacc.c */ -#line 102 "config_parser.yy" +#line 103 "config_parser.yy" { context->HandleInclude((yyvsp[(2) - (2)].text)); } break; - case 7: - -/* Line 1806 of yacc.c */ -#line 107 "config_parser.yy" - { - m_Abstract = false; - m_Local = false; - } - break; - case 8: /* Line 1806 of yacc.c */ -#line 112 "config_parser.yy" +#line 108 "config_parser.yy" + { + context->HandleLibrary((yyvsp[(2) - (2)].text)); + } + break; + + case 9: + +/* Line 1806 of yacc.c */ +#line 113 "config_parser.yy" + { + m_Abstract = false; + m_Local = false; + } + break; + + case 10: + +/* Line 1806 of yacc.c */ +#line 118 "config_parser.yy" { m_Item = boost::make_shared(yylloc); m_Item->SetType((yyvsp[(4) - (5)].text)); @@ -1577,10 +1595,10 @@ yyreduce: } break; - case 9: + case 11: /* Line 1806 of yacc.c */ -#line 118 "config_parser.yy" +#line 124 "config_parser.yy" { ExpressionList::Ptr exprl = *(yyvsp[(8) - (8)].variant); delete (yyvsp[(8) - (8)].variant); @@ -1594,57 +1612,57 @@ yyreduce: } break; - case 12: + case 14: /* Line 1806 of yacc.c */ -#line 136 "config_parser.yy" +#line 142 "config_parser.yy" { m_Abstract = true; } break; - case 13: + case 15: /* Line 1806 of yacc.c */ -#line 140 "config_parser.yy" +#line 146 "config_parser.yy" { m_Local = true; } break; - case 16: + case 18: /* Line 1806 of yacc.c */ -#line 150 "config_parser.yy" +#line 156 "config_parser.yy" { m_Item->AddParent((yyvsp[(1) - (1)].text)); free((yyvsp[(1) - (1)].text)); } break; - case 19: + case 21: /* Line 1806 of yacc.c */ -#line 161 "config_parser.yy" +#line 167 "config_parser.yy" { m_ExpressionLists.push(boost::make_shared()); } break; - case 20: + case 22: /* Line 1806 of yacc.c */ -#line 166 "config_parser.yy" +#line 172 "config_parser.yy" { (yyval.variant) = new Value(m_ExpressionLists.top()); m_ExpressionLists.pop(); } break; - case 26: + case 28: /* Line 1806 of yacc.c */ -#line 181 "config_parser.yy" +#line 187 "config_parser.yy" { Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc); free((yyvsp[(1) - (3)].text)); @@ -1654,10 +1672,10 @@ yyreduce: } break; - case 27: + case 29: /* Line 1806 of yacc.c */ -#line 189 "config_parser.yy" +#line 195 "config_parser.yy" { Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc); free((yyvsp[(3) - (6)].text)); @@ -1673,10 +1691,10 @@ yyreduce: } break; - case 28: + case 30: /* Line 1806 of yacc.c */ -#line 203 "config_parser.yy" +#line 209 "config_parser.yy" { Expression expr((yyvsp[(1) - (1)].text), OperatorSet, (yyvsp[(1) - (1)].text), yylloc); free((yyvsp[(1) - (1)].text)); @@ -1685,47 +1703,47 @@ yyreduce: } break; - case 33: - -/* Line 1806 of yacc.c */ -#line 216 "config_parser.yy" - { - (yyval.op) = (yyvsp[(1) - (1)].op); - } - break; - - case 34: + case 35: /* Line 1806 of yacc.c */ #line 222 "config_parser.yy" { - (yyval.variant) = new Value((yyvsp[(1) - (1)].text)); - free((yyvsp[(1) - (1)].text)); - } - break; - - case 35: - -/* Line 1806 of yacc.c */ -#line 227 "config_parser.yy" - { - (yyval.variant) = new Value((yyvsp[(1) - (1)].num)); + (yyval.op) = (yyvsp[(1) - (1)].op); } break; case 36: /* Line 1806 of yacc.c */ -#line 231 "config_parser.yy" +#line 228 "config_parser.yy" { - (yyval.variant) = new Value(); + (yyval.variant) = new Value((yyvsp[(1) - (1)].text)); + free((yyvsp[(1) - (1)].text)); + } + break; + + case 37: + +/* Line 1806 of yacc.c */ +#line 233 "config_parser.yy" + { + (yyval.variant) = new Value((yyvsp[(1) - (1)].num)); } break; case 38: /* Line 1806 of yacc.c */ -#line 238 "config_parser.yy" +#line 237 "config_parser.yy" + { + (yyval.variant) = new Value(); + } + break; + + case 40: + +/* Line 1806 of yacc.c */ +#line 244 "config_parser.yy" { (yyval.variant) = (yyvsp[(1) - (1)].variant); } @@ -1734,7 +1752,7 @@ yyreduce: /* Line 1806 of yacc.c */ -#line 1738 "config_parser.cc" +#line 1756 "config_parser.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1972,6 +1990,6 @@ yyreturn: /* Line 2067 of yacc.c */ -#line 242 "config_parser.yy" +#line 248 "config_parser.yy" diff --git a/lib/config/config_parser.h b/lib/config/config_parser.h index b9bacc4be..13d1f43b2 100644 --- a/lib/config/config_parser.h +++ b/lib/config/config_parser.h @@ -85,7 +85,8 @@ using namespace icinga; T_LOCAL = 268, T_OBJECT = 269, T_INCLUDE = 270, - T_INHERITS = 271 + T_LIBRARY = 271, + T_INHERITS = 272 }; #endif /* Tokens. */ @@ -102,7 +103,8 @@ using namespace icinga; #define T_LOCAL 268 #define T_OBJECT 269 #define T_INCLUDE 270 -#define T_INHERITS 271 +#define T_LIBRARY 271 +#define T_INHERITS 272 @@ -122,7 +124,7 @@ typedef union YYSTYPE /* Line 2068 of yacc.c */ -#line 126 "config_parser.h" +#line 128 "config_parser.h" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 8c4b49548..7962e88e1 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -55,6 +55,7 @@ using namespace icinga; %token T_LOCAL %token T_OBJECT %token T_INCLUDE +%token T_LIBRARY %token T_INHERITS %type simplevalue %type value @@ -95,7 +96,7 @@ statements: /* empty */ | statements statement ; -statement: object | include +statement: object | include | library ; include: T_INCLUDE T_STRING @@ -103,6 +104,11 @@ include: T_INCLUDE T_STRING context->HandleInclude($2); } +library: T_LIBRARY T_STRING + { + context->HandleLibrary($2); + } + object: { m_Abstract = false; diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp index 3e6be26f9..dfd06e987 100644 --- a/lib/config/configcompiler.cpp +++ b/lib/config/configcompiler.cpp @@ -102,6 +102,16 @@ void ConfigCompiler::HandleInclude(const String& include) std::copy(items.begin(), items.end(), back_inserter(m_Result)); } +/** + * Handles the library directive. + * + * @param library The name of the library. + */ +void ConfigCompiler::HandleLibrary(const String& library) +{ + Utility::LoadIcingaLibrary(library, false); +} + /** * Compiles a stream. * diff --git a/lib/config/configcompiler.h b/lib/config/configcompiler.h index d214e446e..94cb2d0b5 100644 --- a/lib/config/configcompiler.h +++ b/lib/config/configcompiler.h @@ -54,6 +54,7 @@ public: /* internally used methods */ void HandleInclude(const String& include); + void HandleLibrary(const String& library); void AddObject(const ConfigItem::Ptr& object); size_t ReadInput(char *buffer, size_t max_bytes); void *GetScanner(void) const;