diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-09-17 09:34:01 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-09-17 09:34:01 +0200 |
commit | b3eb2f9b81a3cfc2d179aea364501fca4134e480 (patch) | |
tree | 082f9951df5c113d6495c029e00dbb42d441365c /grammar | |
parent | 92564dc5560aff06062a612058865f2a8a8bdff3 (diff) | |
parent | 5ab936a92d636390026d466350464ec4182075ac (diff) | |
download | rsyslog-b3eb2f9b81a3cfc2d179aea364501fca4134e480.tar.gz rsyslog-b3eb2f9b81a3cfc2d179aea364501fca4134e480.tar.xz rsyslog-b3eb2f9b81a3cfc2d179aea364501fca4134e480.zip |
Merge branch 'master-newruleset'
Diffstat (limited to 'grammar')
-rw-r--r-- | grammar/grammar.y | 4 | ||||
-rw-r--r-- | grammar/lexer.l | 6 | ||||
-rw-r--r-- | grammar/rainerscript.c | 38 | ||||
-rw-r--r-- | grammar/rainerscript.h | 11 |
4 files changed, 58 insertions, 1 deletions
diff --git a/grammar/grammar.y b/grammar/grammar.y index f455a21f..074d2abd 100644 --- a/grammar/grammar.y +++ b/grammar/grammar.y @@ -65,6 +65,8 @@ extern int yyerror(char*); %token BEGIN_CONSTANT %token BEGIN_TPL %token STOP +%token SET +%token UNSET %token <s> LEGACY_ACTION %token <s> LEGACY_RULESET %token <s> PRIFILT @@ -153,6 +155,8 @@ stmt: actlst { $$ = $1; } $$->d.s_if.expr = $2; $$->d.s_if.t_then = $4; $$->d.s_if.t_else = $6; } + | SET VAR '=' expr ';' { $$ = cnfstmtNewSet($2, $4); } + | UNSET VAR ';' { $$ = cnfstmtNewUnset($2); } | PRIFILT block { $$ = cnfstmtNewPRIFILT($1, $2); } | PROPFILT block { $$ = cnfstmtNewPROPFILT($1, $2); } block: stmt { $$ = $1; } diff --git a/grammar/lexer.l b/grammar/lexer.l index 869b34fe..657c817f 100644 --- a/grammar/lexer.l +++ b/grammar/lexer.l @@ -96,9 +96,11 @@ int fileno(FILE *stream); /* keywords */ "if" { BEGIN EXPR; return IF; } <EXPR>"then" { BEGIN INITIAL; return THEN; } +<EXPR>";" { BEGIN INITIAL; return ';'; } <EXPR>"or" { return OR; } <EXPR>"and" { return AND; } <EXPR>"not" { return NOT; } +<EXPR>"=" | <EXPR>"," | <EXPR>"*" | <EXPR>"/" | @@ -121,7 +123,7 @@ int fileno(FILE *stream); <EXPR>0[0-7]+ | /* octal number */ <EXPR>0x[0-7a-f] | /* hex number, following rule is dec; strtoll handles all! */ <EXPR>([1-9][0-9]*|0) { yylval.n = strtoll(yytext, NULL, 0); return NUMBER; } -<EXPR>\$[$!]{0,1}[a-z][a-z0-9\-_\.]* { yylval.s = strdup(yytext); return VAR; } +<EXPR>\$[$!]{0,1}[a-z][!a-z0-9\-_\.]* { yylval.s = strdup(yytext); return VAR; } <EXPR>\'([^'\\]|\\['"\\$bntr]|\\x[0-9a-f][0-9a-f]|\\[0-7][0-7][0-7])*\' { yytext[yyleng-1] = '\0'; unescapeStr((uchar*)yytext+1, yyleng-2); @@ -145,6 +147,8 @@ int fileno(FILE *stream); */ "stop" { return STOP; } "else" { return ELSE; } +"set" { BEGIN EXPR; return SET; } +"unset" { BEGIN EXPR; return UNSET; } "preprocfilelinenumber(" { BEGIN LINENO; } <LINENO>[0-9]+ { yylineno = atoi(yytext) - 1; } <LINENO>")" { BEGIN INITIAL; } diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index b0a79458..c7344628 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -1466,6 +1466,16 @@ cnfstmtPrint(struct cnfstmt *root, int indent) } doIndent(indent); dbgprintf("END IF\n"); break; + case S_SET: + doIndent(indent); dbgprintf("SET %s =\n", + stmt->d.s_set.varname); + cnfexprPrint(stmt->d.s_set.expr, indent+1); + doIndent(indent); dbgprintf("END SET\n"); + break; + case S_UNSET: + doIndent(indent); dbgprintf("UNSET %s\n", + stmt->d.s_unset.varname); + break; case S_PRIFILT: doIndent(indent); dbgprintf("PRIFILT '%s'\n", stmt->printable); cnfstmtPrint(stmt->d.s_prifilt.t_then, indent+1); @@ -1569,6 +1579,13 @@ cnfstmtDestruct(struct cnfstmt *root) cnfstmtDestruct(stmt->d.s_if.t_else); } break; + case S_SET: + free(stmt->d.s_set.varname); + cnfexprDestruct(stmt->d.s_set.expr); + break; + case S_UNSET: + free(stmt->d.s_set.varname); + break; case S_PRIFILT: cnfstmtDestruct(stmt->d.s_prifilt.t_then); break; @@ -1594,6 +1611,27 @@ cnfstmtDestruct(struct cnfstmt *root) } struct cnfstmt * +cnfstmtNewSet(char *var, struct cnfexpr *expr) +{ + struct cnfstmt* cnfstmt; + if((cnfstmt = cnfstmtNew(S_SET)) != NULL) { + cnfstmt->d.s_set.varname = (uchar*) var; + cnfstmt->d.s_set.expr = expr; + } + return cnfstmt; +} + +struct cnfstmt * +cnfstmtNewUnset(char *var) +{ + struct cnfstmt* cnfstmt; + if((cnfstmt = cnfstmtNew(S_UNSET)) != NULL) { + cnfstmt->d.s_unset.varname = (uchar*) var; + } + return cnfstmt; +} + +struct cnfstmt * cnfstmtNewPRIFILT(char *prifilt, struct cnfstmt *t_then) { struct cnfstmt* cnfstmt; diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h index 7637ae48..51d96e51 100644 --- a/grammar/rainerscript.h +++ b/grammar/rainerscript.h @@ -116,6 +116,8 @@ struct nvlst { #define S_IF 4003 #define S_ACT 4004 #define S_NOP 4005 /* usually used to disable some statement */ +#define S_SET 4006 +#define S_UNSET 4007 enum cnfFiltType { CNFFILT_NONE, CNFFILT_PRI, CNFFILT_PROP, CNFFILT_SCRIPT }; static inline char* @@ -146,6 +148,13 @@ struct cnfstmt { struct cnfstmt *t_else; } s_if; struct { + uchar *varname; + struct cnfexpr *expr; + } s_set; + struct { + uchar *varname; + } s_unset; + struct { uchar pmask[LOG_NFACILITIES+1]; /* priority mask */ struct cnfstmt *t_then; } s_prifilt; @@ -288,6 +297,8 @@ struct cnfstmt * cnfstmtNewPRIFILT(char *prifilt, struct cnfstmt *t_then); struct cnfstmt * cnfstmtNewPROPFILT(char *propfilt, struct cnfstmt *t_then); struct cnfstmt * cnfstmtNewAct(struct nvlst *lst); struct cnfstmt * cnfstmtNewLegaAct(char *actline); +struct cnfstmt * cnfstmtNewSet(char *var, struct cnfexpr *expr); +struct cnfstmt * cnfstmtNewUnset(char *var); void cnfstmtDestruct(struct cnfstmt *root); char* getFIOPName(unsigned iFIOP); rsRetVal initRainerscript(void); |