summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--grammar/grammar.y48
-rw-r--r--grammar/parserif.h1
-rw-r--r--runtime/rsconf.c8
-rw-r--r--runtime/ruleset.c20
-rw-r--r--runtime/ruleset.h6
5 files changed, 46 insertions, 37 deletions
diff --git a/grammar/grammar.y b/grammar/grammar.y
index 6e1fd913..65a6e8dc 100644
--- a/grammar/grammar.y
+++ b/grammar/grammar.y
@@ -126,8 +126,7 @@ extern int yyerror(char*);
*/
conf: /* empty (to end recursion) */
| conf obj { cnfDoObj($2); }
- | conf stmt { dbgprintf("RRRR: top-level stmt:\n");
- cnfstmtPrint($2, 0); }
+ | conf stmt { cnfDoScript($2); }
| conf BSD_TAG_SELECTOR { cnfDoBSDTag($2); }
| conf BSD_HOST_SELECTOR { cnfDoBSDHost($2); }
obj: BEGINOBJ nvlst ENDOBJ { $$ = cnfobjNew($1, $2); }
@@ -144,56 +143,35 @@ constant: BEGIN_CONSTANT nvlst ENDOBJ { $$ = cnfobjNew(CNFOBJ_CONSTANT, $2); }
nvlst: { $$ = NULL; }
| nvlst nv { $2->next = $1; $$ = $2; }
nv: NAME '=' VALUE { $$ = nvlstNew($1, $3); }
-script: stmt { $$ = $1; dbgprintf("RRRR: root stmt\n"); }
- | script stmt { $$ = scriptAddStmt($1, $2); dbgprintf("RRRR: stmt in list:\n");cnfstmtPrint($2, 0);dbgprintf("\n"); }
-stmt: actlst { $$ = $1; dbgprintf("RRRR: have stmt:actlst %p\n", $1); }
- | STOP { $$ = cnfstmtNew(S_STOP);
- dbgprintf("RRRR: have STOP\n"); }
+script: stmt { $$ = $1; }
+ | script stmt { $$ = scriptAddStmt($1, $2); }
+stmt: actlst { $$ = $1; }
+ | STOP { $$ = cnfstmtNew(S_STOP); }
| IF expr THEN block { $$ = cnfstmtNew(S_IF);
$$->d.cond.expr = $2;
$$->d.cond.t_then = $4;
- $$->d.cond.t_else = NULL;
- dbgprintf("RRRR: have s_if \n"); }
+ $$->d.cond.t_else = NULL; }
| IF expr THEN block ELSE block { $$ = cnfstmtNew(S_IF);
$$->d.cond.expr = $2;
$$->d.cond.t_then = $4;
- $$->d.cond.t_else = $6;
- dbgprintf("RRRR: have s_if \n"); }
+ $$->d.cond.t_else = $6; }
| PRIFILT block { $$ = cnfstmtNew(S_PRIFILT);
$$->printable = $1;
$$->d.cond.expr = $1;
- $$->d.cond.t_then = $2;
- dbgprintf("RRRR: have s_prifilt %p\n", $2);cnfstmtPrint($2, 0);dbgprintf("\n"); }
+ $$->d.cond.t_then = $2; }
| PROPFILT block { $$ = cnfstmtNew(S_PROPFILT);
$$->d.cond.expr = $1;
- $$->d.cond.t_then = $2;
- dbgprintf("RRRR: have s_propfilt\n"); }
-block: stmt { $$ = $1; dbgprintf("RRRR: have block:stmt %p\n", $1); }
- | '{' script '}' { $$ = $2; dbgprintf("RRRR: have block:script\n"); }
-actlst: s_act { $$ = $1; dbgprintf("RRRR: have s_act, %p\n", $1); }
- | actlst '&' s_act { $$ = scriptAddStmt($1, $3); dbgprintf("RRRR: have actlst actlst:s_act\n"); }
+ $$->d.cond.t_then = $2; }
+block: stmt { $$ = $1; }
+ | '{' script '}' { $$ = $2; }
+actlst: s_act { $$ = $1; }
+ | actlst '&' s_act { $$ = scriptAddStmt($1, $3); }
s_act: BEGIN_ACTION nvlst ENDOBJ { $$ = cnfstmtNew(S_ACT);
$$->printable="action()";
dbgprintf("RRRR: action object\n"); }
| LEGACY_ACTION { $$ = cnfstmtNew(S_ACT);
$$->printable = $1;
dbgprintf("RRRR: legacy action\n"); }
-/*
-rule: PRIFILT actlst { $$ = cnfruleNew(CNFFILT_PRI, $2); $$->filt.s = $1; }
- | PROPFILT actlst { $$ = cnfruleNew(CNFFILT_PROP, $2); $$->filt.s = $1; }
- | scriptfilt { $$ = $1; }
-
-scriptfilt: IF expr THEN actlst { $$ = cnfruleNew(CNFFILT_SCRIPT, $4);
- $$->filt.expr = $2; }
-block: actlst { $$ = $1; }
- | block actlst { $2->next = $1; $$ = $2; }
- / * v7: | actlst
- v7: | block rule v7 extensions require new rule engine capabilities! * /
-actlst: act { $$=$1; }
- | actlst '&' act { $3->next = $1; $$ = $3; }
- | actlst cfsysline { $$ = cnfactlstAddSysline($1, $2); }
- | '{' block '}' { $$ = $2; }
-*/
expr: expr AND expr { $$ = cnfexprNew(AND, $1, $3); }
| expr OR expr { $$ = cnfexprNew(OR, $1, $3); }
| NOT expr { $$ = cnfexprNew(NOT, NULL, $2); }
diff --git a/grammar/parserif.h b/grammar/parserif.h
index 597cfe40..3b2a9a7b 100644
--- a/grammar/parserif.h
+++ b/grammar/parserif.h
@@ -15,6 +15,7 @@ extern int yylineno;
* these functions.
*/
void cnfDoObj(struct cnfobj *o);
+void cnfDoScript(struct cnfstmt *script);
void cnfDoRule(struct cnfrule *rule);
void cnfDoCfsysline(char *ln);
void cnfDoBSDTag(char *ln);
diff --git a/runtime/rsconf.c b/runtime/rsconf.c
index 5d2407ec..0f31e515 100644
--- a/runtime/rsconf.c
+++ b/runtime/rsconf.c
@@ -466,6 +466,14 @@ finalize_it:
cnfruleDestruct(cnfrule);
}
+void cnfDoScript(struct cnfstmt *script)
+{
+ // TODO: streamline this, call directly into ruleset from grammar.y
+ // TODO: BSD-Style blocks?
+ dbgprintf("cnf:global:script\n");
+ ruleset.AddScript(ruleset.GetCurrent(loadConf), script);
+}
+
void cnfDoCfsysline(char *ln)
{
DBGPRINTF("cnf:global:cfsysline: %s\n", ln);
diff --git a/runtime/ruleset.c b/runtime/ruleset.c
index 5cb34148..3bcfc4fb 100644
--- a/runtime/ruleset.c
+++ b/runtime/ruleset.c
@@ -11,7 +11,7 @@
*
* Module begun 2009-06-10 by Rainer Gerhards
*
- * Copyright 2009-2011 Rainer Gerhards and Adiscon GmbH.
+ * Copyright 2009-2012 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of the rsyslog runtime library.
*
@@ -248,6 +248,20 @@ GetParserList(rsconf_t *conf, msg_t *pMsg)
}
+/* Add a script block to the current ruleset */
+static void
+addScript(ruleset_t *pThis, struct cnfstmt *script)
+{
+ if(pThis->last == NULL)
+ pThis->root = pThis->last = script;
+ else {
+ pThis->last->next = script;
+ pThis->last = script;
+ }
+dbgprintf("RRRR: ruleset added script, script total now is:\n");
+ cnfstmtPrint(pThis->root, 0);
+}
+
/* Add a new rule to the end of the current rule set. We do a number
* of checks and ignore the rule if it does not pass them.
*/
@@ -378,6 +392,8 @@ doRuleDestruct(void *pData)
*/
BEGINobjConstruct(ruleset) /* be sure to specify the object type also in END macro! */
CHKiRet(llInit(&pThis->llRules, doRuleDestruct, NULL, NULL));
+ pThis->root = NULL;
+ pThis->last = NULL;
finalize_it:
ENDobjConstruct(ruleset)
@@ -423,6 +439,7 @@ CODESTARTobjDestruct(ruleset)
}
llDestroy(&pThis->llRules);
free(pThis->pszName);
+ // TODO: free rainerscript root (not look at last)
ENDobjDestruct(ruleset)
@@ -596,6 +613,7 @@ CODESTARTobjQueryInterface(ruleset)
pIf->IterateAllActions = iterateAllActions;
pIf->DestructAllActions = destructAllActions;
pIf->AddRule = addRule;
+ pIf->AddScript = addScript;
pIf->ProcessBatch = processBatch;
pIf->SetName = setName;
pIf->DebugPrintAll = debugPrintAll;
diff --git a/runtime/ruleset.h b/runtime/ruleset.h
index f4443e18..cc0c7a06 100644
--- a/runtime/ruleset.h
+++ b/runtime/ruleset.h
@@ -32,6 +32,8 @@ struct ruleset_s {
linkedList_t llRules; /* this is NOT a pointer - no typo here ;) */
uchar *pszName; /* name of our ruleset */
qqueue_t *pQueue; /* "main" message queue, if the ruleset has its own (else NULL) */
+ struct cnfstmt *root;
+ struct cnfstmt *last;
parserList_t *pParserLst;/* list of parsers to use for this ruleset */
};
@@ -60,8 +62,10 @@ BEGINinterface(ruleset) /* name must also be changed in ENDinterface macro! */
* removed conf ptr from SetName, AddRule as the flex/bison based
* system uses globals in any case.
*/
+ /* v7, 2012-09-04 */
+ void (*AddScript)(ruleset_t *pThis, struct cnfstmt *script);
ENDinterface(ruleset)
-#define rulesetCURR_IF_VERSION 6 /* increment whenever you change the interface structure! */
+#define rulesetCURR_IF_VERSION 7 /* increment whenever you change the interface structure! */
/* prototypes */