summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-09-28 11:06:16 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2012-09-28 11:06:16 +0200
commit38cdf1abaddea47aa5e9d11d97fade6a2455b632 (patch)
tree7676ef3216c6f322a47c5a0840a44c3ab0fc3029
parentb0764541ab2f2d0448ca79564479bb5865a02ecf (diff)
downloadrsyslog-38cdf1abaddea47aa5e9d11d97fade6a2455b632.tar.gz
rsyslog-38cdf1abaddea47aa5e9d11d97fade6a2455b632.tar.xz
rsyslog-38cdf1abaddea47aa5e9d11d97fade6a2455b632.zip
Implement RainerScript ruleset() statement
-rw-r--r--ChangeLog1
-rw-r--r--grammar/grammar.y5
-rw-r--r--grammar/lexer.l9
-rw-r--r--grammar/parserif.h1
-rw-r--r--grammar/rainerscript.c2
-rw-r--r--grammar/rainerscript.h5
-rw-r--r--runtime/rsconf.c3
-rw-r--r--runtime/rsyslog.h1
-rw-r--r--runtime/ruleset.c57
-rw-r--r--runtime/ruleset.h1
10 files changed, 77 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 9da699af..f19f9abc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
---------------------------------------------------------------------------
Version 7.1.5 [devel] 2012-09-25
+- implemented RainerScript ruleset() statement
- implemented RainerScript prifield() function
- implemented RainerScript field() function
- added new module imkmsg to process structured kernel log
diff --git a/grammar/grammar.y b/grammar/grammar.y
index ce749807..fcb9119b 100644
--- a/grammar/grammar.y
+++ b/grammar/grammar.y
@@ -64,6 +64,7 @@ extern int yyerror(char*);
%token BEGIN_PROPERTY
%token BEGIN_CONSTANT
%token BEGIN_TPL
+%token BEGIN_RULESET
%token STOP
%token SET
%token UNSET
@@ -135,6 +136,10 @@ obj: BEGINOBJ nvlst ENDOBJ { $$ = cnfobjNew($1, $2); }
{ $$ = cnfobjNew(CNFOBJ_TPL, $2);
$$->subobjs = $5;
}
+ | BEGIN_RULESET nvlst ENDOBJ '{' stmt '}'
+ { $$ = cnfobjNew(CNFOBJ_RULESET, $2);
+ $$->script = $5;
+ }
propconst: { $$ = NULL; }
| propconst property { $$ = objlstAdd($1, $2); }
| propconst constant { $$ = objlstAdd($1, $2); }
diff --git a/grammar/lexer.l b/grammar/lexer.l
index 38703f25..0fc333e4 100644
--- a/grammar/lexer.l
+++ b/grammar/lexer.l
@@ -142,14 +142,13 @@ int fileno(FILE *stream);
"&" { return '&'; }
"{" { return '{'; }
"}" { return '}'; }
-"ruleset" { dbgprintf("RULESET\n"); }
- /* line number support because the "preprocessor" combines lines and so needs
- * to tell us the real source line.
- */
"stop" { return STOP; }
"else" { return ELSE; }
"set" { BEGIN EXPR; return SET; }
"unset" { BEGIN EXPR; return UNSET; }
+ /* line number support because the "preprocessor" combines lines and so needs
+ * to tell us the real source line.
+ */
"preprocfilelinenumber(" { BEGIN LINENO; }
<LINENO>[0-9]+ { yylineno = atoi(yytext) - 1; }
<LINENO>")" { BEGIN INITIAL; }
@@ -165,6 +164,8 @@ int fileno(FILE *stream);
BEGIN INOBJ; return BEGINOBJ; }
"template"[ \n\t]*"(" { yylval.objType = CNFOBJ_TPL;
BEGIN INOBJ; return BEGIN_TPL; }
+"ruleset"[ \n\t]*"(" { yylval.objType = CNFOBJ_RULESET;
+ BEGIN INOBJ; return BEGIN_RULESET; }
"property"[ \n\t]*"(" { yylval.objType = CNFOBJ_PROPERTY;
BEGIN INOBJ; return BEGIN_PROPERTY; }
"constant"[ \n\t]*"(" { yylval.objType = CNFOBJ_CONSTANT;
diff --git a/grammar/parserif.h b/grammar/parserif.h
index aa271ec4..dbafe067 100644
--- a/grammar/parserif.h
+++ b/grammar/parserif.h
@@ -16,6 +16,7 @@ extern int yylineno;
*/
void cnfDoObj(struct cnfobj *o);
void cnfDoScript(struct cnfstmt *script);
+void cnfDoRuleset(struct cnfstmt *script);
void cnfDoCfsysline(char *ln);
void cnfDoBSDTag(char *ln);
void cnfDoBSDHost(char *ln);
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
index 1a14b212..4e484804 100644
--- a/grammar/rainerscript.c
+++ b/grammar/rainerscript.c
@@ -732,7 +732,6 @@ nvlstGetParams(struct nvlst *lst, struct cnfparamblk *params,
vals = NULL;
}
-dbgprintf("DDDD: vals %p\n", vals);
return vals;
}
@@ -777,6 +776,7 @@ cnfobjNew(enum cnfobjType objType, struct nvlst *lst)
o->objType = objType;
o->nvlst = lst;
o->subobjs = NULL;
+ o->script = NULL;
}
return o;
diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h
index 902ff4c5..6bd1660a 100644
--- a/grammar/rainerscript.h
+++ b/grammar/rainerscript.h
@@ -20,6 +20,7 @@ extern int Debug; /* 1 if in debug mode, 0 otherwise -- to be enhanced */
enum cnfobjType {
CNFOBJ_ACTION,
+ CNFOBJ_RULESET,
CNFOBJ_GLOBAL,
CNFOBJ_INPUT,
CNFOBJ_MODULE,
@@ -36,6 +37,9 @@ cnfobjType2str(enum cnfobjType ot)
case CNFOBJ_ACTION:
return "action";
break;
+ case CNFOBJ_RULESET:
+ return "ruleset";
+ break;
case CNFOBJ_GLOBAL:
return "global";
break;
@@ -81,6 +85,7 @@ struct cnfobj {
enum cnfobjType objType;
struct nvlst *nvlst;
struct objlst *subobjs;
+ struct cnfstmt *script;
};
struct objlst {
diff --git a/runtime/rsconf.c b/runtime/rsconf.c
index 982013e9..97680795 100644
--- a/runtime/rsconf.c
+++ b/runtime/rsconf.c
@@ -412,6 +412,9 @@ void cnfDoObj(struct cnfobj *o)
case CNFOBJ_TPL:
tplProcessCnf(o);
break;
+ case CNFOBJ_RULESET:
+ rulesetProcessCnf(o);
+ break;
case CNFOBJ_PROPERTY:
case CNFOBJ_CONSTANT:
/* these types are processed at a later stage */
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index 336ab5bf..ad5e54b4 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -390,6 +390,7 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
RS_RET_BSD_BLOCKS_UNSUPPORTED = -2304, /**< BSD-style config blocks are no longer supported */
RS_RET_JNAME_NOTFOUND = -2305, /**< JSON name not found (does not exist) */
RS_RET_INVLD_SETOP = -2305, /**< invalid variable set operation, incompatible type */
+ RS_RET_RULESET_EXISTS = -2306,/**< ruleset already exists */
/* RainerScript error messages (range 1000.. 1999) */
RS_RET_SYSVAR_NOT_FOUND = 1001, /**< system variable could not be found (maybe misspelled) */
diff --git a/runtime/ruleset.c b/runtime/ruleset.c
index 2af44bc4..896df5c6 100644
--- a/runtime/ruleset.c
+++ b/runtime/ruleset.c
@@ -29,7 +29,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#include "config.h"
#include <stdlib.h>
#include <assert.h>
@@ -56,6 +55,16 @@ DEFobjStaticHelpers
DEFobjCurrIf(errmsg)
DEFobjCurrIf(parser)
+/* tables for interfacing with the v6 config system (as far as we need to) */
+static struct cnfparamdescr rspdescr[] = {
+ { "name", eCmdHdlrString, CNFPARAM_REQUIRED }
+};
+static struct cnfparamblk rspblk =
+ { CNFPARAMBLK_VERSION,
+ sizeof(rspdescr)/sizeof(struct cnfparamdescr),
+ rspdescr
+ };
+
/* forward definitions */
static rsRetVal processBatch(batch_t *pBatch);
static rsRetVal scriptExec(struct cnfstmt *root, batch_t *pBatch, sbool *active);
@@ -564,6 +573,7 @@ GetParserList(rsconf_t *conf, msg_t *pMsg)
static void
addScript(ruleset_t *pThis, struct cnfstmt *script)
{
+dbgprintf("DDDD: add script %p, ruleset %p\n", script, pThis);
if(pThis->last == NULL)
pThis->root = pThis->last = script;
else {
@@ -574,7 +584,7 @@ addScript(ruleset_t *pThis, struct cnfstmt *script)
/* set name for ruleset */
-static rsRetVal setName(ruleset_t *pThis, uchar *pszName)
+static rsRetVal rulesetSetName(ruleset_t *pThis, uchar *pszName)
{
DEFiRet;
free(pThis->pszName);
@@ -890,6 +900,47 @@ rulesetAddParser(void __attribute__((unused)) *pVal, uchar *pName)
}
+/* Process ruleset() objects */
+rsRetVal
+rulesetProcessCnf(struct cnfobj *o)
+{
+ struct cnfparamvals *pvals;
+ rsRetVal localRet;
+ uchar *rsName = NULL;
+ int nameIdx;
+ ruleset_t *pRuleset;
+ DEFiRet;
+
+ pvals = nvlstGetParams(o->nvlst, &rspblk, NULL);
+ if(pvals == NULL) {
+ ABORT_FINALIZE(RS_RET_CONFIG_ERROR);
+ }
+ DBGPRINTF("ruleset param blk after rulesetProcessCnf:\n");
+ cnfparamsPrint(&rspblk, pvals);
+ nameIdx = cnfparamGetIdx(&rspblk, "name");
+ rsName = (uchar*)es_str2cstr(pvals[nameIdx].val.d.estr, NULL);
+ localRet = rulesetGetRuleset(loadConf, &pRuleset, rsName);
+ if(localRet == RS_RET_OK) {
+ errmsg.LogError(0, RS_RET_RULESET_EXISTS,
+ "error: ruleset '%s' specified more than once",
+ rsName);
+ cnfstmtDestruct(o->script);
+ ABORT_FINALIZE(RS_RET_RULESET_EXISTS);
+ } else if(localRet != RS_RET_NOT_FOUND) {
+ ABORT_FINALIZE(localRet);
+ }
+ CHKiRet(rulesetConstruct(&pRuleset));
+ CHKiRet(rulesetSetName(pRuleset, rsName));
+ CHKiRet(rulesetConstructFinalize(loadConf, pRuleset));
+ addScript(pRuleset, o->script);
+
+finalize_it:
+ free(rsName);
+ cnfparamvalsDestruct(pvals, &rspblk);
+ RETiRet;
+}
+
+
/* queryInterface function
* rgerhards, 2008-02-21
*/
@@ -913,7 +964,7 @@ CODESTARTobjQueryInterface(ruleset)
pIf->DestructAllActions = destructAllActions;
pIf->AddScript = addScript;
pIf->ProcessBatch = processBatch;
- pIf->SetName = setName;
+ pIf->SetName = rulesetSetName;
pIf->DebugPrintAll = debugPrintAll;
pIf->GetCurrent = GetCurrent;
pIf->GetRuleset = rulesetGetRuleset;
diff --git a/runtime/ruleset.h b/runtime/ruleset.h
index 1f8f948f..93a2f06e 100644
--- a/runtime/ruleset.h
+++ b/runtime/ruleset.h
@@ -95,4 +95,5 @@ rulesetGetName(ruleset_t *pRuleset)
*/
rsRetVal rulesetGetRuleset(rsconf_t *conf, ruleset_t **ppRuleset, uchar *pszName);
rsRetVal rulesetOptimizeAll(rsconf_t *conf);
+rsRetVal rulesetProcessCnf(struct cnfobj *o);
#endif /* #ifndef INCLUDED_RULESET_H */