diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2011-07-03 17:09:09 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2011-07-03 17:09:09 +0200 |
commit | 65076e28dfed0765e51c69be81a7842331aae1d2 (patch) | |
tree | 29cb6d966d7c17c6a6739dc9481fda415322523a | |
parent | 1cdab4d2b548a0db54b5a2c5404f3f78e012113e (diff) | |
download | rsyslog-65076e28dfed0765e51c69be81a7842331aae1d2.tar.gz rsyslog-65076e28dfed0765e51c69be81a7842331aae1d2.tar.xz rsyslog-65076e28dfed0765e51c69be81a7842331aae1d2.zip |
milestone: grammar for basic if/then construct (no expr)
-rw-r--r-- | grammar/mini.samp | 32 | ||||
-rw-r--r-- | grammar/rscript.l | 13 | ||||
-rw-r--r-- | grammar/rscript.y | 35 |
3 files changed, 65 insertions, 15 deletions
diff --git a/grammar/mini.samp b/grammar/mini.samp new file mode 100644 index 00000000..54efacec --- /dev/null +++ b/grammar/mini.samp @@ -0,0 +1,32 @@ +#global (dnscache="yes" arg1="1 2" arg2 = "1 2" arg3 ="1=2\"3") +action(type="omuser" target="all") +global (dnscache="no" b="2") +$FileOwner root +*.* * +$action somelog 1 +& /var/log/somelog +$action log2 1 +$action log2 2 +$action log2 3 +& action(type="fwd" target="10.1.1.2") +& /var/log/log2 + +if 1 then /var/log/log3 +/* sample bwlow is v7 +if 1 then { /var/log/log3 + if 2 then /var/log/log4 + *.* /var/log/log4b +} +*/ +*.* { /var/log/log5 + /var/log/log6 + $port 514 + @@fwd + rger + } +if 1/*pri("*.*")*/ then { + action(type="omfile" taget="/var/log/log5") + action(type="omfile" taget="/var/log/log6") + action(type="omfwd" taget="10.0.0.1" port="514") + action(type="omwusr" taget="rger") +} diff --git a/grammar/rscript.l b/grammar/rscript.l index 750a3e81..d6dab45b 100644 --- a/grammar/rscript.l +++ b/grammar/rscript.l @@ -43,8 +43,8 @@ static int preCommentState; %% /* keywords */ -"if" { printf("IF\n"); BEGIN EXPR; } -<EXPR>"then" { printf("THEN\n"); BEGIN INITIAL; } +"if" { BEGIN EXPR; return IF; } +<EXPR>"then" { BEGIN INITIAL; return THEN; } <EXPR>"or" { printf("OR\n"); } <EXPR>"and" { printf("AND\n"); } <EXPR>"not" { printf("NOT\n"); } @@ -63,12 +63,14 @@ static int preCommentState; <EXPR>"startswith_i" { printf("STARTSWITH_I\n"); } <EXPR>-?0[0-7]+ { printf("NUMBER (oct) %s\n", yytext); } <EXPR>-?0x[0-7a-f] { printf("NUMBER (hex) %s\n", yytext); } -<EXPR>-?([1-9][0-9]*|0) { printf("NUMBER (dec) %s\n", yytext); } +<EXPR>-?([1-9][0-9]*|0) { printf("NUMBER (dec) %s\n", yytext); return NUMBER; } <EXPR>\$[$!]{0,1}[a-z][a-z0-9\-_\.]* { printf("VARNAME: '%s'\n", yytext); } <EXPR>\'([^'\\]|\\['])*\' { printf("EXPR string: -%s-\n", yytext); } <EXPR>[ \t\n] <EXPR>. { printf("invalid char in expr: %s\n", yytext); } "&" { return '&'; } +"{" { return '{'; } +"}" { return '}'; } "ruleset" { printf("RULESET\n"); } "global"[ \n\t]*"(" { yylval.objType = CNFOBJ_GLOBAL; @@ -86,8 +88,8 @@ static int preCommentState; "*" | \/[^*][^\n]* | -[\|\.\-:][^\n]+ { printf("toke legacy_action '%s'\n", yytext);yylval.s = strdup(yytext); return LEGACY_ACTION; } -[a-z0-9_\-\+]+ { printf("name: '%s'\n", yytext); } +[\|\.\-\@:~][^\n]+ | +[a-z0-9_\-\+]+ { yylval.s = strdup(yytext); return LEGACY_ACTION; } <INOBJ>")" { BEGIN INITIAL; return ENDOBJ; } <INOBJ>[a-z][a-z0-9_\.]* { yylval.estr = es_newStrFromCStr(yytext, yyleng); return NAME; } @@ -106,7 +108,6 @@ static int preCommentState; /* CFSYSLINE is valid in all modes */ \$[a-z]+.*$ { yylval.s = strdup(yytext); return CFSYSLINE; } -<INOBJ>\$[a-z]+.*$ { yylval.s = strdup(yytext); return CFSYSLINE; } \#.*\n /* skip comments in input */ [\n\t ] /* drop whitespace */ diff --git a/grammar/rscript.y b/grammar/rscript.y index 15348e4d..7e9365c5 100644 --- a/grammar/rscript.y +++ b/grammar/rscript.y @@ -24,14 +24,18 @@ %token <s> LEGACY_ACTION %token <s> PRIFILT %token <s> PROPFILT +%token IF +%token THEN +%token NUMBER %type <nvlst> nv nvlst %type <obj> obj %type <actlst> actlst %type <actlst> act +%type <s> cfsysline +%type <actlst> block - -%expect 2 +%expect 3 /* two shift/reduce conflicts are created by the CFSYSLINE construct, which we * unfortunately can not avoid. The problem is that CFSYSLINE can occur both in * global context as well as within an action. It's not permitted somewhere else, @@ -47,17 +51,17 @@ conf: /* empty (to end recursion) */ | cfsysline conf | rule conf -obj: BEGINOBJ nvlst ENDOBJ { $$ = cnfobjNew($1, $2); +obj: BEGINOBJ nvlst ENDOBJ { $$ = cnfobjNew($1, $2); cnfobjPrint($$); cnfobjDestruct($$); } -obj: BEGIN_ACTION nvlst ENDOBJ { struct cnfobj *t = cnfobjNew(CNFOBJ_ACTION, $2); + | BEGIN_ACTION nvlst ENDOBJ { struct cnfobj *t = cnfobjNew(CNFOBJ_ACTION, $2); cnfobjPrint(t); cnfobjDestruct(t); printf("XXXX: this is an new-style action!\n"); } -cfsysline: CFSYSLINE { printf("XXXX: processing CFSYSLINE: %s\n", $1); - } +cfsysline: CFSYSLINE { printf("XXXX: processing CFSYSLINE: %s\n", $1); } + nvlst: { $$ = NULL; } | nvlst nv { $2->next = $1; $$ = $2; } nv: NAME '=' VALUE { $$ = nvlstNew($1, $3); } @@ -66,12 +70,25 @@ rule: PRIFILT actlst { printf("PRIFILT: %s\n", $1); free($1); $2 = cnfactlstReverse($2); cnfactlstPrint($2); } | PROPFILT actlst + | scriptfilt + +scriptfilt: IF NUMBER THEN actlst { printf("if filter detected\n"); } + +/* note: we can do some limited block-structuring with the v6 engine. In that case, + * we must not support additonal filters inside the blocks, so they must consist of + * "act", only. We can implement that via the "&" actlist logic. + */ +block: actlst + | block actlst + /* v7: | actlst + v7: | block rule */ -actlst: act { printf("action (end actlst)\n");$$=$1; } - | actlst '&' act { printf("in actionlist \n"); +actlst: act { printf("action (end actlst)\n");$$=$1; } + | actlst '&' act { printf("in actionlist \n"); $3->next = $1; $$ = $3; } - | actlst CFSYSLINE { printf("in actionlist/CFSYSLINE: %s\n", $2); + | actlst cfsysline { printf("in actionlist/CFSYSLINE: %s\n", $2); $$ = cnfactlstAddSysline($1, $2); } + | '{' block '}' { $$ = $2; } act: BEGIN_ACTION nvlst ENDOBJ { $$ = cnfactlstNew(CNFACT_V2, $2, NULL); } | LEGACY_ACTION { printf("legacy action: '%s'\n", $1); |