From 0bf6991bf6c155ff43c394c284e23dfe6b0fc53f Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 4 Sep 2012 10:50:07 +0200 Subject: new ruleengine: first code for stmt handling --- grammar/rainerscript.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 33630a76..0d236c1e 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -107,7 +107,6 @@ objlstNew(struct cnfobj *o) lst->next = NULL; lst->obj = o; } -dbgprintf("AAAA: creating new objlst\n"); cnfobjPrint(o); return lst; @@ -1497,6 +1496,48 @@ cnfexprPrint(struct cnfexpr *expr, int indent) break; } } +void +cnfstmtPrint(struct cnfstmt *stmt, int indent) +{ + //dbgprintf("stmt %p, indent %d, type '%c'\n", expr, indent, expr->nodetype); + switch(stmt->nodetype) { + case S_STOP: + doIndent(indent); dbgprintf("STOP\n"); + break; + case S_ACT: + doIndent(indent); dbgprintf("ACTION %p\n", stmt->d.act); + break; + case S_IF: + doIndent(indent); dbgprintf("IF\n"); + cnfexprPrint(stmt->d.cond.expr, indent+1); + doIndent(indent); dbgprintf("THEN\n"); + cnfstmtPrint(stmt->d.cond.t_then, indent+1); + if(stmt->d.cond.t_else != NULL) { + doIndent(indent); dbgprintf("ELSE\n"); + cnfstmtPrint(stmt->d.cond.t_else, indent+1); + } + doIndent(indent); dbgprintf("END IF\n"); + break; + case S_PRIFILT: + doIndent(indent); dbgprintf("PRIFILT\n"); + cnfexprPrint(stmt->d.cond.expr, indent+1); + doIndent(indent); dbgprintf("THEN\n"); + cnfstmtPrint(stmt->d.cond.t_then, indent+1); + doIndent(indent); dbgprintf("END PRIFILT\n"); + break; + case S_PROPFILT: + doIndent(indent); dbgprintf("PROPFILT\n"); + cnfexprPrint(stmt->d.cond.expr, indent+1); + doIndent(indent); dbgprintf("THEN\n"); + cnfstmtPrint(stmt->d.cond.t_then, indent+1); + doIndent(indent); dbgprintf("END PROPFILT\n"); + break; + default: + dbgprintf("error: unknown stmt type %u\n", + (unsigned) stmt->nodetype); + break; + } +} struct cnfnumval* cnfnumvalNew(long long val) @@ -1531,6 +1572,17 @@ cnfvarNew(char *name) return var; } +struct cnfstmt * +cnfstmtNew(unsigned s_type) +{ + struct cnfstmt* cnfstmt; + if((cnfstmt = malloc(sizeof(struct cnfstmt))) != NULL) { + cnfstmt->nodetype = s_type; + cnfstmt->next = NULL; + } + return cnfstmt; +} + struct cnfrule * cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst) { -- cgit v1.2.3 From 493ddeaa770de41ab5a6bb5279eed355c84b12ee Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 4 Sep 2012 11:05:19 +0200 Subject: new ruleengine: add &-operator (legacy action list) --- grammar/rainerscript.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 0d236c1e..d9812fee 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -1519,8 +1519,8 @@ cnfstmtPrint(struct cnfstmt *stmt, int indent) doIndent(indent); dbgprintf("END IF\n"); break; case S_PRIFILT: - doIndent(indent); dbgprintf("PRIFILT\n"); - cnfexprPrint(stmt->d.cond.expr, indent+1); + doIndent(indent); dbgprintf("PRIFILT '%s'\n", stmt->d.cond.printable); + //cnfexprPrint(stmt->d.cond.expr, indent+1); doIndent(indent); dbgprintf("THEN\n"); cnfstmtPrint(stmt->d.cond.t_then, indent+1); doIndent(indent); dbgprintf("END PRIFILT\n"); -- cgit v1.2.3 From 68b9fe72b89ff47efdbed8fea4185bac84279a51 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 4 Sep 2012 12:00:01 +0200 Subject: new ruleengine: script block correctly built --- grammar/rainerscript.c | 102 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 36 deletions(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 2d5bbd9b..b127b906 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -130,6 +130,25 @@ objlstAdd(struct objlst *root, struct cnfobj *o) return root; } +/* add stmt to current script, always return root stmt pointer */ +struct cnfstmt* +scriptAddStmt(struct cnfstmt *root, struct cnfstmt *s) +{ + struct cnfstmt *l; +dbgprintf("RRRR: scriptAddStmt(%p, %p): ", root, s); + + if(root == NULL) { + root = s; +dbgprintf("root set to %p\n", s); + } else { /* find last, linear search ok, as only during config phase */ + for(l = root ; l->next != NULL ; l = l->next) + ; + l->next = s; +dbgprintf("%p->next = %p\n", l, s); + } + return root; +} + void objlstDestruct(struct objlst *lst) { @@ -1498,45 +1517,47 @@ cnfexprPrint(struct cnfexpr *expr, int indent) } } void -cnfstmtPrint(struct cnfstmt *stmt, int indent) +cnfstmtPrint(struct cnfstmt *root, int indent) { + struct cnfstmt *stmt; //dbgprintf("stmt %p, indent %d, type '%c'\n", expr, indent, expr->nodetype); - switch(stmt->nodetype) { - case S_STOP: - doIndent(indent); dbgprintf("STOP\n"); - break; - case S_ACT: - doIndent(indent); dbgprintf("ACTION %p\n", stmt->d.act); - break; - case S_IF: - doIndent(indent); dbgprintf("IF\n"); - cnfexprPrint(stmt->d.cond.expr, indent+1); - doIndent(indent); dbgprintf("THEN\n"); - cnfstmtPrint(stmt->d.cond.t_then, indent+1); - if(stmt->d.cond.t_else != NULL) { - doIndent(indent); dbgprintf("ELSE\n"); - cnfstmtPrint(stmt->d.cond.t_else, indent+1); + for(stmt = root ; stmt != NULL ; stmt = stmt->next) { + switch(stmt->nodetype) { + case S_STOP: + doIndent(indent); dbgprintf("STOP\n"); + break; + case S_ACT: + doIndent(indent); dbgprintf("ACTION %p (%s)\n", stmt->d.act, stmt->printable); + break; + case S_IF: + doIndent(indent); dbgprintf("IF\n"); + cnfexprPrint(stmt->d.cond.expr, indent+1); + doIndent(indent); dbgprintf("THEN\n"); + cnfstmtPrint(stmt->d.cond.t_then, indent+1); + if(stmt->d.cond.t_else != NULL) { + doIndent(indent); dbgprintf("ELSE\n"); + cnfstmtPrint(stmt->d.cond.t_else, indent+1); + } + doIndent(indent); dbgprintf("END IF\n"); + break; + case S_PRIFILT: + doIndent(indent); dbgprintf("PRIFILT '%s'\n", stmt->printable); + //cnfexprPrint(stmt->d.cond.expr, indent+1); + cnfstmtPrint(stmt->d.cond.t_then, indent+1); + doIndent(indent); dbgprintf("END PRIFILT\n"); + break; + case S_PROPFILT: + doIndent(indent); dbgprintf("PROPFILT\n"); + cnfexprPrint(stmt->d.cond.expr, indent+1); + doIndent(indent); dbgprintf("THEN\n"); + cnfstmtPrint(stmt->d.cond.t_then, indent+1); + doIndent(indent); dbgprintf("END PROPFILT\n"); + break; + default: + dbgprintf("error: unknown stmt type %u\n", + (unsigned) stmt->nodetype); + break; } - doIndent(indent); dbgprintf("END IF\n"); - break; - case S_PRIFILT: - doIndent(indent); dbgprintf("PRIFILT '%s'\n", stmt->d.cond.printable); - //cnfexprPrint(stmt->d.cond.expr, indent+1); - doIndent(indent); dbgprintf("THEN\n"); - cnfstmtPrint(stmt->d.cond.t_then, indent+1); - doIndent(indent); dbgprintf("END PRIFILT\n"); - break; - case S_PROPFILT: - doIndent(indent); dbgprintf("PROPFILT\n"); - cnfexprPrint(stmt->d.cond.expr, indent+1); - doIndent(indent); dbgprintf("THEN\n"); - cnfstmtPrint(stmt->d.cond.t_then, indent+1); - doIndent(indent); dbgprintf("END PROPFILT\n"); - break; - default: - dbgprintf("error: unknown stmt type %u\n", - (unsigned) stmt->nodetype); - break; } } @@ -1873,6 +1894,15 @@ cstrPrint(char *text, es_str_t *estr) free(str); } +char * +rmLeadingSpace(char *s) +{ + char *p; + for(p = s ; *p && isspace(*p) ; ++p) + ; + return(p); +} + /* init must be called once before any parsing of the script files start */ rsRetVal initRainerscript(void) -- cgit v1.2.3 From c596f1c1b2b6df18a9209d436a8255d96f437b54 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 4 Sep 2012 14:51:35 +0200 Subject: new ruleengine: PROP and PRI legacy filter structures properly created --- grammar/rainerscript.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 7 deletions(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index b127b906..0e3f30ae 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -37,6 +37,7 @@ #include #include "rsyslog.h" #include "rainerscript.h" +#include "conf.h" #include "parserif.h" #include "grammar.h" #include "queue.h" @@ -47,6 +48,37 @@ DEFobjCurrIf(obj) DEFobjCurrIf(regexp) +static char* +getFIOPName(unsigned iFIOP) +{ + char *pRet; + switch(iFIOP) { + case FIOP_CONTAINS: + pRet = "contains"; + break; + case FIOP_ISEQUAL: + pRet = "isequal"; + break; + case FIOP_STARTSWITH: + pRet = "startswith"; + break; + case FIOP_REGEX: + pRet = "regex"; + break; + case FIOP_EREREGEX: + pRet = "ereregex"; + break; + case FIOP_ISEMPTY: + pRet = "isempty"; + break; + default: + pRet = "NOP"; + break; + } + return pRet; +} + + void readConfFile(FILE *fp, es_str_t **str) { @@ -1531,26 +1563,42 @@ cnfstmtPrint(struct cnfstmt *root, int indent) break; case S_IF: doIndent(indent); dbgprintf("IF\n"); - cnfexprPrint(stmt->d.cond.expr, indent+1); + cnfexprPrint(stmt->d.s_if.expr, indent+1); doIndent(indent); dbgprintf("THEN\n"); - cnfstmtPrint(stmt->d.cond.t_then, indent+1); - if(stmt->d.cond.t_else != NULL) { + cnfstmtPrint(stmt->d.s_if.t_then, indent+1); + if(stmt->d.s_if.t_else != NULL) { doIndent(indent); dbgprintf("ELSE\n"); - cnfstmtPrint(stmt->d.cond.t_else, indent+1); + cnfstmtPrint(stmt->d.s_if.t_else, indent+1); } doIndent(indent); dbgprintf("END IF\n"); break; case S_PRIFILT: doIndent(indent); dbgprintf("PRIFILT '%s'\n", stmt->printable); //cnfexprPrint(stmt->d.cond.expr, indent+1); - cnfstmtPrint(stmt->d.cond.t_then, indent+1); + cnfstmtPrint(stmt->d.s_prifilt.t_then, indent+1); doIndent(indent); dbgprintf("END PRIFILT\n"); break; case S_PROPFILT: doIndent(indent); dbgprintf("PROPFILT\n"); - cnfexprPrint(stmt->d.cond.expr, indent+1); + doIndent(indent); dbgprintf("\tProperty.: '%s'\n", + propIDToName(stmt->d.s_propfilt.propID)); + if(stmt->d.s_propfilt.propName != NULL) { + char *cstr; + cstr = es_str2cstr(stmt->d.s_propfilt.propName, NULL); + doIndent(indent); + dbgprintf("\tCEE-Prop.: '%s'\n", cstr); + free(cstr); + } + doIndent(indent); dbgprintf("\tOperation: "); + if(stmt->d.s_propfilt.isNegated) + dbgprintf("NOT "); + dbgprintf("'%s'\n", getFIOPName(stmt->d.s_propfilt.operation)); + if(stmt->d.s_propfilt.pCSCompValue != NULL) { + doIndent(indent); dbgprintf("\tValue....: '%s'\n", + rsCStrGetSzStrNoNULL(stmt->d.s_propfilt.pCSCompValue)); + } doIndent(indent); dbgprintf("THEN\n"); - cnfstmtPrint(stmt->d.cond.t_then, indent+1); + cnfstmtPrint(stmt->d.s_propfilt.t_then, indent+1); doIndent(indent); dbgprintf("END PROPFILT\n"); break; default: @@ -1605,6 +1653,30 @@ cnfstmtNew(unsigned s_type) return cnfstmt; } +struct cnfstmt * +cnfstmtNewPRIFILT(char *prifilt, struct cnfstmt *t_then) +{ + struct cnfstmt* cnfstmt; + if((cnfstmt = cnfstmtNew(S_PRIFILT)) != NULL) { + cnfstmt->printable = (uchar*)strdup(prifilt); + cnfstmt->d.s_prifilt.t_then = t_then; + DecodePRIFilter((uchar*)prifilt, cnfstmt->d.s_prifilt.pmask); + } + return cnfstmt; +} + +struct cnfstmt * +cnfstmtNewPROPFILT(char *propfilt, struct cnfstmt *t_then) +{ + struct cnfstmt* cnfstmt; + if((cnfstmt = cnfstmtNew(S_PROPFILT)) != NULL) { + cnfstmt->printable = (uchar*)strdup(propfilt); + cnfstmt->d.s_propfilt.t_then = t_then; + DecodePropFilter((uchar*)propfilt, cnfstmt); + } + return cnfstmt; +} + struct cnfrule * cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst) { -- cgit v1.2.3 From 72f9fe88b24428067557a71405ee641a641bf7c4 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 4 Sep 2012 15:18:37 +0200 Subject: new ruleengine: v6+ action object properly constructed --- grammar/rainerscript.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 0e3f30ae..6e3bae68 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -1677,6 +1677,23 @@ cnfstmtNewPROPFILT(char *propfilt, struct cnfstmt *t_then) return cnfstmt; } +struct cnfstmt * +cnfstmtNewAct(struct nvlst *lst) +{ + struct cnfstmt* cnfstmt; + if((cnfstmt = cnfstmtNew(S_ACT)) == NULL) + goto done; + if(actionNewInst(lst, &cnfstmt->d.act) != RS_RET_OK) { + // TODO:RS_RET_WARN? + parser_errmsg("errors occured in file '%s' around line %d", + cnfcurrfn, yylineno); + cnfstmt->nodetype = S_NOP; /* disable action! */ + goto done; + } + cnfstmt->printable = (uchar*)"action()"; +done: return cnfstmt; +} + struct cnfrule * cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst) { -- cgit v1.2.3 From 3dd73d7f7194139a9b8bf1668f6192ead0c801ec Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 4 Sep 2012 15:54:40 +0200 Subject: new ruleengine: legacy action object properly constructed --- grammar/rainerscript.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 6e3bae68..20cf2f6d 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -39,6 +39,7 @@ #include "rainerscript.h" #include "conf.h" #include "parserif.h" +#include "rsconf.h" #include "grammar.h" #include "queue.h" #include "srUtils.h" @@ -1555,6 +1556,9 @@ cnfstmtPrint(struct cnfstmt *root, int indent) //dbgprintf("stmt %p, indent %d, type '%c'\n", expr, indent, expr->nodetype); for(stmt = root ; stmt != NULL ; stmt = stmt->next) { switch(stmt->nodetype) { + case S_NOP: + doIndent(indent); dbgprintf("NOP\n"); + break; case S_STOP: doIndent(indent); dbgprintf("STOP\n"); break; @@ -1694,6 +1698,27 @@ cnfstmtNewAct(struct nvlst *lst) done: return cnfstmt; } +struct cnfstmt * +cnfstmtNewLegaAct(uchar *actline) +{ + struct cnfstmt* cnfstmt; + rsRetVal localRet; + if((cnfstmt = cnfstmtNew(S_ACT)) == NULL) + goto done; + cnfstmt->printable = (uchar*)strdup((char*)actline); + localRet = cflineDoAction(loadConf, &actline, &cnfstmt->d.act); + if(localRet != RS_RET_OK && localRet != RS_RET_OK_WARN) { + parser_errmsg("%s occured in file '%s' around line %d", + (localRet == RS_RET_OK_WARN) ? "warnings" : "errors", + cnfcurrfn, yylineno); + if(localRet != RS_RET_OK_WARN) { + cnfstmt->nodetype = S_NOP; /* disable action! */ + goto done; + } + } +done: return cnfstmt; +} + struct cnfrule * cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst) { -- cgit v1.2.3 From d3e96418f514cd69592be24af6a632a8491820fc Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 6 Sep 2012 10:48:24 +0200 Subject: new ruleengine: implement rainerscript execution engine --- grammar/rainerscript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 20cf2f6d..dc2ef64c 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -49,7 +49,7 @@ DEFobjCurrIf(obj) DEFobjCurrIf(regexp) -static char* +char* getFIOPName(unsigned iFIOP) { char *pRet; -- cgit v1.2.3 From 77ea54a5b98e80738914587bd0f252befeffe4f7 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 6 Sep 2012 17:17:50 +0200 Subject: new ruleengine: restore action iterator functionality --- grammar/rainerscript.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index dc2ef64c..0ebfb44e 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -1699,14 +1699,14 @@ done: return cnfstmt; } struct cnfstmt * -cnfstmtNewLegaAct(uchar *actline) +cnfstmtNewLegaAct(char *actline) { struct cnfstmt* cnfstmt; rsRetVal localRet; if((cnfstmt = cnfstmtNew(S_ACT)) == NULL) goto done; cnfstmt->printable = (uchar*)strdup((char*)actline); - localRet = cflineDoAction(loadConf, &actline, &cnfstmt->d.act); + localRet = cflineDoAction(loadConf, (uchar**)&actline, &cnfstmt->d.act); if(localRet != RS_RET_OK && localRet != RS_RET_OK_WARN) { parser_errmsg("%s occured in file '%s' around line %d", (localRet == RS_RET_OK_WARN) ? "warnings" : "errors", -- cgit v1.2.3 From 8795df908b969f6e226256a3cd25cc976491533b Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 6 Sep 2012 18:23:16 +0200 Subject: new ruleengine: properly freeing stmt tree --- grammar/rainerscript.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 0ebfb44e..d6a51191 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -1635,6 +1635,7 @@ cnfstringvalNew(es_str_t *estr) return strval; } + struct cnfvar* cnfvarNew(char *name) { @@ -1657,12 +1658,57 @@ cnfstmtNew(unsigned s_type) return cnfstmt; } +void +cnfstmtDestruct(struct cnfstmt *root) +{ + struct cnfstmt *stmt, *todel; + for(stmt = root ; stmt != NULL ; ) { + switch(stmt->nodetype) { + case S_NOP: + case S_STOP: + break; + case S_ACT: +dbgprintf("XXXX: destruct action %p\n", stmt->d.act); + actionDestruct(stmt->d.act); + break; + case S_IF: + cnfexprDestruct(stmt->d.s_if.expr); + if(stmt->d.s_if.t_then != NULL) { + cnfstmtDestruct(stmt->d.s_if.t_then); + } + if(stmt->d.s_if.t_else != NULL) { + cnfstmtDestruct(stmt->d.s_if.t_else); + } + break; + case S_PRIFILT: + cnfstmtDestruct(stmt->d.s_prifilt.t_then); + break; + case S_PROPFILT: + if(stmt->d.s_propfilt.propName != NULL) + es_deleteStr(stmt->d.s_propfilt.propName); + if(stmt->d.s_propfilt.regex_cache != NULL) + rsCStrRegexDestruct(&stmt->d.s_propfilt.regex_cache); + if(stmt->d.s_propfilt.pCSCompValue != NULL) + cstrDestruct(&stmt->d.s_propfilt.pCSCompValue); + cnfstmtDestruct(stmt->d.s_propfilt.t_then); + break; + default: + dbgprintf("error: unknown stmt type during destruct %u\n", + (unsigned) stmt->nodetype); + break; + } + todel = stmt; + stmt = stmt->next; + free(todel); + } +} + struct cnfstmt * cnfstmtNewPRIFILT(char *prifilt, struct cnfstmt *t_then) { struct cnfstmt* cnfstmt; if((cnfstmt = cnfstmtNew(S_PRIFILT)) != NULL) { - cnfstmt->printable = (uchar*)strdup(prifilt); + cnfstmt->printable = (uchar*)prifilt; cnfstmt->d.s_prifilt.t_then = t_then; DecodePRIFilter((uchar*)prifilt, cnfstmt->d.s_prifilt.pmask); } @@ -1676,6 +1722,9 @@ cnfstmtNewPROPFILT(char *propfilt, struct cnfstmt *t_then) if((cnfstmt = cnfstmtNew(S_PROPFILT)) != NULL) { cnfstmt->printable = (uchar*)strdup(propfilt); cnfstmt->d.s_propfilt.t_then = t_then; + cnfstmt->d.s_propfilt.propName = NULL; + cnfstmt->d.s_propfilt.regex_cache = NULL; + cnfstmt->d.s_propfilt.pCSCompValue = NULL; DecodePropFilter((uchar*)propfilt, cnfstmt); } return cnfstmt; -- cgit v1.2.3 From 92c030bb767b7f7306a3b8d015b901bb8f1f79b9 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 10 Sep 2012 16:59:20 +0200 Subject: new ruleengine: more cleanup --- grammar/rainerscript.c | 169 +------------------------------------------------ 1 file changed, 1 insertion(+), 168 deletions(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index d6a51191..295e46b6 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -2,7 +2,7 @@ * * Module begun 2011-07-01 by Rainer Gerhards * - * Copyright 2011 Rainer Gerhards and Adiscon GmbH. + * Copyright 2011-2012 Rainer Gerhards and Adiscon GmbH. * * This file is part of the rsyslog runtime library. * @@ -712,116 +712,6 @@ cnfobjPrint(struct cnfobj *o) } -struct cnfactlst* -cnfactlstNew(enum cnfactType actType, struct nvlst *lst, char *actLine) -{ - struct cnfactlst *actlst; - - if((actlst = malloc(sizeof(struct cnfactlst))) != NULL) { - actlst->next = NULL; - actlst->syslines = NULL; - actlst->actType = actType; - actlst->lineno = yylineno; - actlst->cnfFile = strdup(cnfcurrfn); - if(actType == CNFACT_V2) - actlst->data.lst = lst; - else - actlst->data.legActLine = actLine; - } - return actlst; -} - -struct cnfactlst* -cnfactlstAddSysline(struct cnfactlst* actlst, char *line) -{ - struct cnfcfsyslinelst *cflst; - - if((cflst = malloc(sizeof(struct cnfcfsyslinelst))) != NULL) { - cflst->line = line; - if(actlst->syslines == NULL) { - cflst->next = NULL; - } else { - cflst->next = actlst->syslines; - } - actlst->syslines = cflst; - } - return actlst; -} - - -void -cnfactlstDestruct(struct cnfactlst *actlst) -{ - struct cnfactlst *toDel; - - while(actlst != NULL) { - toDel = actlst; - actlst = actlst->next; - free(toDel->cnfFile); - cnfcfsyslinelstDestruct(toDel->syslines); - if(toDel->actType == CNFACT_V2) - nvlstDestruct(toDel->data.lst); - else - free(toDel->data.legActLine); - free(toDel); - } - -} - -static inline struct cnfcfsyslinelst* -cnfcfsyslinelstReverse(struct cnfcfsyslinelst *lst) -{ - struct cnfcfsyslinelst *curr, *prev; - if(lst == NULL) - return NULL; - prev = NULL; - while(lst != NULL) { - curr = lst; - lst = lst->next; - curr->next = prev; - prev = curr; - } - return prev; -} - -struct cnfactlst* -cnfactlstReverse(struct cnfactlst *actlst) -{ - struct cnfactlst *curr, *prev; - - prev = NULL; - while(actlst != NULL) { - curr = actlst; - actlst = actlst->next; - curr->syslines = cnfcfsyslinelstReverse(curr->syslines); - curr->next = prev; - prev = curr; - } - return prev; -} - -void -cnfactlstPrint(struct cnfactlst *actlst) -{ - struct cnfcfsyslinelst *cflst; - - while(actlst != NULL) { - dbgprintf("aclst %p: ", actlst); - if(actlst->actType == CNFACT_V2) { - dbgprintf("V2 action type: "); - nvlstPrint(actlst->data.lst); - } else { - dbgprintf("legacy action line: '%s'\n", - actlst->data.legActLine); - } - for( cflst = actlst->syslines - ; cflst != NULL ; cflst = cflst->next) { - dbgprintf("action:cfsysline: '%s'\n", cflst->line); - } - actlst = actlst->next; - } -} - struct cnfexpr* cnfexprNew(unsigned nodetype, struct cnfexpr *l, struct cnfexpr *r) { @@ -1768,63 +1658,6 @@ cnfstmtNewLegaAct(char *actline) done: return cnfstmt; } -struct cnfrule * -cnfruleNew(enum cnfFiltType filttype, struct cnfactlst *actlst) -{ - struct cnfrule* cnfrule; - if((cnfrule = malloc(sizeof(struct cnfrule))) != NULL) { - cnfrule->nodetype = 'R'; - cnfrule->filttype = filttype; - cnfrule->actlst = cnfactlstReverse(actlst); - } - return cnfrule; -} - -void -cnfrulePrint(struct cnfrule *rule) -{ - dbgprintf("------ start rule %p:\n", rule); - dbgprintf("%s: ", cnfFiltType2str(rule->filttype)); - switch(rule->filttype) { - case CNFFILT_NONE: - break; - case CNFFILT_PRI: - case CNFFILT_PROP: - dbgprintf("%s\n", rule->filt.s); - break; - case CNFFILT_SCRIPT: - dbgprintf("\n"); - cnfexprPrint(rule->filt.expr, 0); - break; - } - cnfactlstPrint(rule->actlst); - dbgprintf("------ end rule %p\n", rule); -} - -/* note: the sysline itself was already freed during processing - * and as such MUST NOT be freed again! - */ -void -cnfcfsyslinelstDestruct(struct cnfcfsyslinelst *cfslst) -{ - struct cnfcfsyslinelst *toDel; - while(cfslst != NULL) { - toDel = cfslst; - cfslst = cfslst->next; - free(toDel); - } -} - -void -cnfruleDestruct(struct cnfrule *rule) -{ - if( rule->filttype == CNFFILT_PRI - || rule->filttype == CNFFILT_PROP) - free(rule->filt.s); - cnfactlstDestruct(rule->actlst); - free(rule); -} - struct cnffparamlst * cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next) { -- cgit v1.2.3 From d3bb43798c95f9d95f9e031387f4aedd814c34ab Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 10 Sep 2012 18:17:34 +0200 Subject: new ruleengine: fix memory leaks & a little cleanup --- grammar/rainerscript.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 295e46b6..30600ea3 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -1468,7 +1468,6 @@ cnfstmtPrint(struct cnfstmt *root, int indent) break; case S_PRIFILT: doIndent(indent); dbgprintf("PRIFILT '%s'\n", stmt->printable); - //cnfexprPrint(stmt->d.cond.expr, indent+1); cnfstmtPrint(stmt->d.s_prifilt.t_then, indent+1); doIndent(indent); dbgprintf("END PRIFILT\n"); break; @@ -1543,6 +1542,7 @@ cnfstmtNew(unsigned s_type) struct cnfstmt* cnfstmt; if((cnfstmt = malloc(sizeof(struct cnfstmt))) != NULL) { cnfstmt->nodetype = s_type; + cnfstmt->printable = NULL; cnfstmt->next = NULL; } return cnfstmt; @@ -1558,7 +1558,6 @@ cnfstmtDestruct(struct cnfstmt *root) case S_STOP: break; case S_ACT: -dbgprintf("XXXX: destruct action %p\n", stmt->d.act); actionDestruct(stmt->d.act); break; case S_IF: @@ -1587,6 +1586,7 @@ dbgprintf("XXXX: destruct action %p\n", stmt->d.act); (unsigned) stmt->nodetype); break; } + free(stmt->printable); todel = stmt; stmt = stmt->next; free(todel); @@ -1610,7 +1610,7 @@ cnfstmtNewPROPFILT(char *propfilt, struct cnfstmt *t_then) { struct cnfstmt* cnfstmt; if((cnfstmt = cnfstmtNew(S_PROPFILT)) != NULL) { - cnfstmt->printable = (uchar*)strdup(propfilt); + cnfstmt->printable = (uchar*)propfilt; cnfstmt->d.s_propfilt.t_then = t_then; cnfstmt->d.s_propfilt.propName = NULL; cnfstmt->d.s_propfilt.regex_cache = NULL; @@ -1633,7 +1633,7 @@ cnfstmtNewAct(struct nvlst *lst) cnfstmt->nodetype = S_NOP; /* disable action! */ goto done; } - cnfstmt->printable = (uchar*)"action()"; + cnfstmt->printable = (uchar*)strdup("action()"); done: return cnfstmt; } -- cgit v1.2.3