diff options
-rw-r--r-- | grammar/Makefile.am | 4 | ||||
-rw-r--r-- | grammar/grammar.y | 24 | ||||
-rw-r--r-- | grammar/lexer.l | 23 | ||||
-rw-r--r-- | grammar/parserif.h | 2 | ||||
-rw-r--r-- | grammar/rainerscript.c (renamed from grammar/utils.c) | 40 | ||||
-rw-r--r-- | grammar/rainerscript.h (renamed from grammar/utils.h) | 2 | ||||
-rw-r--r-- | grammar/testdriver.c | 2 | ||||
-rw-r--r-- | runtime/conf.c | 10 | ||||
-rw-r--r-- | runtime/conf.h | 3 | ||||
-rw-r--r-- | runtime/rsconf.c | 20 | ||||
-rw-r--r-- | runtime/rule.c | 8 | ||||
-rw-r--r-- | runtime/rule.h | 6 |
12 files changed, 116 insertions, 28 deletions
diff --git a/grammar/Makefile.am b/grammar/Makefile.am index b482c99e..2b149abe 100644 --- a/grammar/Makefile.am +++ b/grammar/Makefile.am @@ -7,8 +7,8 @@ bin_PROGRAMS = testdriver # TODO: make this conditional libgrammar_la_SOURCES = \ grammar.y \ lexer.l \ - utils.c \ - utils.h \ + rainerscript.c \ + rainerscript.h \ grammar.h testdriver_SOURCES = testdriver.c libgrammar.la diff --git a/grammar/grammar.y b/grammar/grammar.y index 428011c5..b8790411 100644 --- a/grammar/grammar.y +++ b/grammar/grammar.y @@ -9,14 +9,30 @@ * cases. So while we hope that cfsysline support can be dropped some time in * the future, we will probably keep these useful constructs. * - * Copyright (C) 2011 by Rainer Gerhards and Adiscon GmbH - * Released under the GNU GPL v3. For details see LICENSE file. + * Copyright 2011 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of the rsyslog runtime library. + * + * The rsyslog runtime library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The rsyslog runtime library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution. */ - %{ #include <stdio.h> #include <libestr.h> -#include "utils.h" +#include "rainerscript.h" #include "parserif.h" #define YYDEBUG 1 extern int yylineno; diff --git a/grammar/lexer.l b/grammar/lexer.l index ba432b2e..d761003a 100644 --- a/grammar/lexer.l +++ b/grammar/lexer.l @@ -9,8 +9,25 @@ * cases. So while we hope that cfsysline support can be dropped some time in * the future, we will probably keep these useful constructs. * - * Copyright (C) 2011 by Rainer Gerhards and Adiscon GmbH - * Released under the GNU GPL v3. For details see LICENSE file. + * Copyright 2011 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of the rsyslog runtime library. + * + * The rsyslog runtime library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The rsyslog runtime library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution. */ %option noyywrap nodefault case-insensitive yylineno @@ -46,7 +63,7 @@ #include <stdlib.h> #include <strings.h> #include <libestr.h> -#include "utils.h" +#include "rainerscript.h" #include "grammar.h" static int preCommentState; /* save for lex state before a comment */ diff --git a/grammar/parserif.h b/grammar/parserif.h index 0a6434d3..a04abb0c 100644 --- a/grammar/parserif.h +++ b/grammar/parserif.h @@ -1,6 +1,6 @@ #ifndef PARSERIF_H_DEFINED #define PARSERIF_H_DEFINED -#include "utils.h" +#include "rainerscript.h" int cnfSetLexFile(char*); int yyparse(); int yydebug; diff --git a/grammar/utils.c b/grammar/rainerscript.c index f49af9b0..801a52b2 100644 --- a/grammar/utils.c +++ b/grammar/rainerscript.c @@ -1,9 +1,35 @@ +/* rainerscript.c - routines to support RainerScript config language + * + * Module begun 2011-07-01 by Rainer Gerhards + * + * Copyright 2011 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of the rsyslog runtime library. + * + * The rsyslog runtime library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The rsyslog runtime library 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution. + */ + +#include "config.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <libestr.h> -#include "utils.h" +#include "rainerscript.h" #include "parserif.h" #include "grammar.h" @@ -388,6 +414,18 @@ cnfexprEval(struct cnfexpr *expr, struct exprret *ret) } } +/* Evaluate an expression as a bool. This is added because expressions are + * mostly used inside filters, and so this function is quite common and + * important. + */ +int +cnfexprEvalBool(struct cnfexpr *expr) +{ + struct exprret ret; + cnfexprEval(expr, &ret); + return exprret2Number(&ret); +} + inline static void doIndent(int indent) { diff --git a/grammar/utils.h b/grammar/rainerscript.h index e75105da..bab7e602 100644 --- a/grammar/utils.h +++ b/grammar/rainerscript.h @@ -1,5 +1,6 @@ #ifndef INC_UTILS_H #define INC_UTILS_H +#include <stdio.h> #include <libestr.h> enum cnfobjType { @@ -161,6 +162,7 @@ struct cnfactlst* cnfactlstReverse(struct cnfactlst *actlst); struct cnfexpr* cnfexprNew(unsigned nodetype, struct cnfexpr *l, struct cnfexpr *r); void cnfexprPrint(struct cnfexpr *expr, int indent); void cnfexprEval(struct cnfexpr *expr, struct exprret *ret); +int cnfexprEvalBool(struct cnfexpr *expr); struct cnfnumval* cnfnumvalNew(long long val); struct cnfstringval* cnfstringvalNew(es_str_t *estr); struct cnfrule * cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst); diff --git a/grammar/testdriver.c b/grammar/testdriver.c index 43f3bd3f..52d2d0c7 100644 --- a/grammar/testdriver.c +++ b/grammar/testdriver.c @@ -26,7 +26,7 @@ #include <stdlib.h> #include <stdarg.h> #include <libestr.h> -#include "utils.h" +#include "rainerscript.h" #include "parserif.h" extern int yylineno; diff --git a/runtime/conf.c b/runtime/conf.c index 5eb1aae2..51cf39e1 100644 --- a/runtime/conf.c +++ b/runtime/conf.c @@ -104,9 +104,9 @@ int bConfStrictScoping = 0; /* force strict scoping during config processing? */ * be run in a single thread anyways. So there can be no race conditions. * rgerhards 2005-10-18 */ -static EHostnameCmpMode eDfltHostnameCmpMode = HN_NO_COMP; -static cstr_t *pDfltHostnameCmp = NULL; -static cstr_t *pDfltProgNameCmp = NULL; +EHostnameCmpMode eDfltHostnameCmpMode = HN_NO_COMP; +cstr_t *pDfltHostnameCmp = NULL; +cstr_t *pDfltProgNameCmp = NULL; /* process a directory and include all of its files into @@ -763,6 +763,7 @@ rsRetVal cflineProcessTradPRIFilter(uchar **pline, register rule_t *pRule) } +#if 0 /* Helper to cfline(). This function processes an "if" type of filter, * what essentially means it parses an expression. As usual, * It processes the line up to the beginning of the action part. @@ -830,6 +831,7 @@ finalize_it: RETiRet; } +#endif /* Helper to cfline(). This function takes the filter part of a property @@ -1061,12 +1063,14 @@ static rsRetVal cflineDoFilter(uchar **pp, rule_t *f) case ':': CHKiRet(cflineProcessPropFilter(pp, f)); break; +#if 0 case 'i': /* "if" filter? */ if(*(*pp+1) && (*(*pp+1) == 'f') && isspace(*(*pp+2))) { CHKiRet(cflineProcessIfFilter(pp, f)); break; } /*FALLTHROUGH*/ +#endif default: CHKiRet(cflineProcessTradPRIFilter(pp, f)); break; diff --git a/runtime/conf.h b/runtime/conf.h index 28ccdde1..aa57c8fc 100644 --- a/runtime/conf.h +++ b/runtime/conf.h @@ -72,5 +72,8 @@ rsRetVal cflineProcessHostSelector(uchar **pline); rsRetVal cflineProcessTradPRIFilter(uchar **pline, rule_t *pRule); rsRetVal cflineProcessPropFilter(uchar **pline, rule_t *f); rsRetVal cflineDoAction(rsconf_t *conf, uchar **p, action_t **ppAction); +extern EHostnameCmpMode eDfltHostnameCmpMode; +extern cstr_t *pDfltHostnameCmp; +extern cstr_t *pDfltProgNameCmp; #endif /* #ifndef INCLUDED_CONF_H */ diff --git a/runtime/rsconf.c b/runtime/rsconf.c index 17332464..cb8eac50 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -255,7 +255,9 @@ parser_errmsg(char *fmt, ...) va_list ap; va_start(ap, fmt); // TODO: create useful code ;) 2011-07-06 - dbgprintf("error on or before line %d: ", yylineno); + errmsg.LogError(0, NO_ERRCODE, "error during parsing on or before line %d", + yylineno); +dbgprintf("error on or before line %d: ", yylineno); vprintf(fmt, ap); printf("\n"); va_end(ap); @@ -284,8 +286,8 @@ void cnfDoRule(struct cnfrule *cnfrule) cnfrulePrint(cnfrule); CHKiRet(rule.Construct(&pRule)); /* create "fresh" selector */ - CHKiRet(rule.SetAssRuleset(pRule, ruleset.GetCurrent(loadConf))); /* create "fresh" selector */ - CHKiRet(rule.ConstructFinalize(pRule)); /* create "fresh" selector */ + CHKiRet(rule.SetAssRuleset(pRule, ruleset.GetCurrent(loadConf))); + CHKiRet(rule.ConstructFinalize(pRule)); switch(cnfrule->filttype) { case CNFFILT_NONE: @@ -300,23 +302,21 @@ void cnfDoRule(struct cnfrule *cnfrule) iRet = cflineProcessPropFilter(&str, pRule); break; case CNFFILT_SCRIPT: - dbgprintf("TODO: script filter implementation missing\n"); - cnfexprPrint(cnfrule->filt.expr, 0); + pRule->f_filter_type = FILTER_EXPR; + pRule->f_filterData.f_expr = cnfrule->filt.expr; break; } /* we now check if there are some global (BSD-style) filter conditions * and, if so, we copy them over. rgerhards, 2005-10-18 */ -#if 0 // TODO: add LATER! if(pDfltProgNameCmp != NULL) { - CHKiRet(rsCStrConstructFromCStr(&(f->pCSProgNameComp), pDfltProgNameCmp)); + CHKiRet(rsCStrConstructFromCStr(&(pRule->pCSProgNameComp), pDfltProgNameCmp)); } if(eDfltHostnameCmpMode != HN_NO_COMP) { - f->eHostnameCmpMode = eDfltHostnameCmpMode; - CHKiRet(rsCStrConstructFromCStr(&(f->pCSHostnameComp), pDfltHostnameCmp)); + pRule->eHostnameCmpMode = eDfltHostnameCmpMode; + CHKiRet(rsCStrConstructFromCStr(&(pRule->pCSHostnameComp), pDfltHostnameCmp)); } -#endif cnfDoActlst(cnfrule->actlst, pRule); diff --git a/runtime/rule.c b/runtime/rule.c index 3dcee877..8976c898 100644 --- a/runtime/rule.c +++ b/runtime/rule.c @@ -40,6 +40,7 @@ #include "var.h" #include "srUtils.h" #include "batch.h" +#include "parserif.h" #include "unicode-helper.h" /* static data */ @@ -186,14 +187,17 @@ shouldProcessThisMessage(rule_t *pRule, msg_t *pMsg, sbool *bProcessMsg) else bRet = 1; } else if(pRule->f_filter_type == FILTER_EXPR) { +#if 0 CHKiRet(vm.Construct(&pVM)); CHKiRet(vm.ConstructFinalize(pVM)); CHKiRet(vm.SetMsg(pVM, pMsg)); CHKiRet(vm.ExecProg(pVM, pRule->f_filterData.f_expr->pVmprg)); CHKiRet(vm.PopBoolFromStack(pVM, &pResult)); - dbgprintf("result of rainerscript filter evaluation: %lld\n", pResult->val.num); /* VM is destructed on function exit */ bRet = (pResult->val.num) ? 1 : 0; +#endif + bRet = cnfexprEvalBool(pRule->f_filterData.expr); + dbgprintf("result of rainerscript filter evaluation: %d\n", bRet); } else { assert(pRule->f_filter_type == FILTER_PROP); /* assert() just in case... */ pszPropVal = MsgGetProp(pMsg, NULL, pRule->f_filterData.prop.propID, @@ -356,9 +360,11 @@ CODESTARTobjDestruct(rule) rsCStrRegexDestruct(&pThis->f_filterData.prop.regex_cache); if(pThis->f_filterData.prop.propName != NULL) es_deleteStr(pThis->f_filterData.prop.propName); +#if 0 } else if(pThis->f_filter_type == FILTER_EXPR) { if(pThis->f_filterData.f_expr != NULL) expr.Destruct(&pThis->f_filterData.f_expr); +#endif } llDestroy(&pThis->llActList); diff --git a/runtime/rule.h b/runtime/rule.h index 3b34e11a..f346c764 100644 --- a/runtime/rule.h +++ b/runtime/rule.h @@ -2,7 +2,7 @@ * * This implements rules within rsyslog. * - * Copyright 2009 Rainer Gerhards and Adiscon GmbH. + * Copyright 2009-2011 Rainer Gerhards and Adiscon GmbH. * * This file is part of the rsyslog runtime library. * @@ -28,7 +28,8 @@ #include "libestr.h" #include "linkedlist.h" #include "regexp.h" -#include "expr.h" +#include "expr.h" // TODO: remove #if 0 +#include "rainerscript.h" /* the rule object */ struct rule_s { @@ -52,6 +53,7 @@ struct rule_s { propid_t propID; /* ID of the requested property */ es_str_t *propName; /* name of property for CEE-based filters */ } prop; + struct cnfexpr *expr; /* expression object */ expr_t *f_expr; /* expression object */ } f_filterData; |