From 6258cb42fd407b9388de63c746634b4df03e78eb Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sat, 25 Aug 2012 13:30:53 +0200 Subject: milestone: base plumbing for LIST-type templates mostly in place --- grammar/grammar.y | 22 +++++++++++++++------- grammar/rainerscript.c | 39 +++++++++++++++++++++++++++++++++++++++ grammar/rainerscript.h | 18 ++++++++++++++++++ runtime/rsconf.c | 1 + template.c | 44 +++++++++++++++++++++++++++++++++----------- 5 files changed, 106 insertions(+), 18 deletions(-) diff --git a/grammar/grammar.y b/grammar/grammar.y index 35afae30..d91eb3bb 100644 --- a/grammar/grammar.y +++ b/grammar/grammar.y @@ -49,6 +49,7 @@ extern int yyerror(char*); enum cnfobjType objType; struct cnfobj *obj; struct nvlst *nvlst; + struct objlst *objlst; struct cnfactlst *actlst; struct cnfexpr *expr; struct cnfrule *rule; @@ -92,7 +93,8 @@ extern int yyerror(char*); %token CMP_STARTSWITHI %type nv nvlst -%type obj propconst +%type obj property constant +%type propconst %type actlst %type act %type cfsysline @@ -133,13 +135,19 @@ obj: BEGINOBJ nvlst ENDOBJ { $$ = cnfobjNew($1, $2); } | BEGIN_ACTION nvlst ENDOBJ { $$ = cnfobjNew(CNFOBJ_ACTION, $2); } | BEGIN_TPL nvlst ENDOBJ { $$ = cnfobjNew(CNFOBJ_TPL, $2); dbgprintf("processing template() without {}\n"); } | BEGIN_TPL nvlst ENDOBJ '{' propconst '}' - { $$ = cnfobjNew(CNFOBJ_TPL, $2); dbgprintf("processing template() WITH {}\n"); } -/* TODO: NOTE: - propconst is the NEXT step. It is just included as an experiment and needs - to be replaced. -*/ -propconst: BEGIN_PROPERTY nvlst ENDOBJ { $$ = cnfobjNew(CNFOBJ_PROPERTY, $2); + { $$ = cnfobjNew(CNFOBJ_TPL, $2); + $$->subobjs = $5; + dbgprintf("processing template() WITH {}\n"); } +propconst: { $$ = NULL; } + | propconst property { if($1 == NULL) + $$ = objlstNew($2); + else + $1->next = objlstNew($2); } + | propconst constant { /*$2->next = $1; $$ = $2;*/ } +property: BEGIN_PROPERTY nvlst ENDOBJ { $$ = cnfobjNew(CNFOBJ_PROPERTY, $2); dbgprintf("processed property()\n"); } +constant: BEGIN_CONSTANT nvlst ENDOBJ { $$ = cnfobjNew(CNFOBJ_CONSTANT, $2); + dbgprintf("processed constant()\n"); } cfsysline: CFSYSLINE { $$ = $1; } nvlst: { $$ = NULL; } | nvlst nv { $2->next = $1; $$ = $2; } diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 3bfb2e07..1ccac575 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -98,6 +98,44 @@ readConfFile(FILE *fp, es_str_t **str) es_addChar(str, '\0'); } +struct objlst* +objlstNew(struct cnfobj *o) +{ + struct objlst *lst; + + if((lst = malloc(sizeof(struct objlst))) != NULL) { + lst->next = NULL; + lst->obj = o; + } +dbgprintf("AAAA: creating new objlst\n"); +cnfobjPrint(o); + + return lst; +} + +void +objlstDestruct(struct objlst *lst) +{ + struct objlst *toDel; + + while(lst != NULL) { + toDel = lst; + lst = lst->next; + // TODO: delete object + free(toDel); + } +} + +void +objlstPrint(struct objlst *lst) +{ + dbgprintf("objlst %p:\n", lst); + while(lst != NULL) { + cnfobjPrint(lst->obj); + lst = lst->next; + } +} + struct nvlst* nvlstNew(es_str_t *name, es_str_t *value) { @@ -581,6 +619,7 @@ cnfobjNew(enum cnfobjType objType, struct nvlst *lst) nvlstChkDupes(lst); o->objType = objType; o->nvlst = lst; + o->subobjs = NULL; } return o; diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h index 83a253f7..4c625cd8 100644 --- a/grammar/rainerscript.h +++ b/grammar/rainerscript.h @@ -38,6 +38,15 @@ cnfobjType2str(enum cnfobjType ot) case CNFOBJ_MODULE: return "module"; break; + case CNFOBJ_TPL: + return "template"; + break; + case CNFOBJ_PROPERTY: + return "property"; + break; + case CNFOBJ_CONSTANT: + return "constant"; + break; default:return "error: invalid cnfobjType"; } } @@ -63,6 +72,12 @@ struct var { struct cnfobj { enum cnfobjType objType; struct nvlst *nvlst; + struct objlst *subobjs; +}; + +struct objlst { + struct objlst *next; + struct cnfobj *obj; }; struct nvlst { @@ -221,6 +236,9 @@ struct cnfparamvals { /* the values we obtained for param descr. */ int cnfParseBuffer(char *buf, unsigned lenBuf); void readConfFile(FILE *fp, es_str_t **str); +struct objlst* objlstNew(struct cnfobj *obj); +void objlstDestruct(struct objlst *lst); +void objlstPrint(struct objlst *lst); struct nvlst* nvlstNew(es_str_t *name, es_str_t *value); void nvlstDestruct(struct nvlst *lst); void nvlstPrint(struct nvlst *lst); diff --git a/runtime/rsconf.c b/runtime/rsconf.c index cbc09c11..9c6bf00e 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -404,6 +404,7 @@ int bChkUnuse = 1; // TODO: Delete tplProcessCnf(o); break; case CNFOBJ_PROPERTY: + case CNFOBJ_CONSTANT: //processTemplate(o); bChkUnuse = 0; break; diff --git a/template.c b/template.c index 50db86a3..39f95967 100644 --- a/template.c +++ b/template.c @@ -1146,11 +1146,23 @@ struct template *tplAddLine(rsconf_t *conf, char* pName, uchar** ppRestOfConfLin return(pTpl); } +/* create a template in list mode, is build from sub-objects */ +static rsRetVal +createListTpl(struct template *pTpl, struct cnfobj *o) +{ + struct objlst *lst; + DEFiRet; + dbgprintf("AAAA: create template from subobjs\n"); + objlstPrint(o->subobjs); -// v6 - ASL 2.0! -/* Add a new template via the v6 config system. - */ + for(lst = o->subobjs ; lst != NULL ; lst = lst->next) { + dbgprintf("AAAA: subjobject entry %p\n", lst); + } + RETiRet; +} + +/* Add a new template via the v6 config system. */ rsRetVal tplProcessCnf(struct cnfobj *o) { @@ -1159,8 +1171,8 @@ tplProcessCnf(struct cnfobj *o) int lenName; char *name = NULL; uchar *tplStr = NULL; + uchar *plugin = NULL; uchar *p; - uchar *plugin; enum { T_STRING, T_PLUGIN, T_LIST } tplType; int i; int o_sql=0, o_stdsql=0, o_json=0; /* options */ @@ -1170,7 +1182,6 @@ tplProcessCnf(struct cnfobj *o) pvals = nvlstGetParams(o->nvlst, &pblk, NULL); cnfparamsPrint(&pblk, pvals); - for(i = 0 ; i < pblk.nParams ; ++i) { if(!pvals[i].bUsed) @@ -1185,9 +1196,6 @@ tplProcessCnf(struct cnfobj *o) tplType = T_PLUGIN; } else if(!es_strbufcmp(pvals[i].val.d.estr, (uchar*)"list", sizeof("list")-1)) { tplType = T_LIST; - errmsg.LogError(0, RS_RET_ERR, "template type 'list' is not " - "supported in this rsyslog version"); - ABORT_FINALIZE(RS_RET_ERR); } else { uchar *typeStr = (uchar*) es_str2cstr(pvals[i].val.d.estr, NULL); errmsg.LogError(0, RS_RET_ERR, "invalid template type '%s'", @@ -1228,7 +1236,7 @@ tplProcessCnf(struct cnfobj *o) if(plugin == NULL) { if(tplType == T_PLUGIN) { errmsg.LogError(0, RS_RET_ERR, "template '%s' of type plugin needs " - "plugin parameter - ignored", name); + "plugin parameter", name); ABORT_FINALIZE(RS_RET_ERR); } } else { @@ -1238,6 +1246,19 @@ tplProcessCnf(struct cnfobj *o) } } + if(o->subobjs == NULL) { + if(tplType == T_LIST) { + errmsg.LogError(0, RS_RET_ERR, "template '%s' of type list has " + "has no parameters specified", name); + ABORT_FINALIZE(RS_RET_ERR); + } + } else { + if(tplType != T_LIST) { + errmsg.LogError(0, RS_RET_ERR, "template '%s' is not a list " + "template but has parameters specified - ignored", name); + } + } + numopts = 0; if(o_sql) ++numopts; if(o_stdsql) ++numopts; @@ -1279,6 +1300,9 @@ tplProcessCnf(struct cnfobj *o) pTpl->pszName, localRet); ABORT_FINALIZE(localRet); } + break; + case T_LIST: createListTpl(pTpl, o); + break; } pTpl->optFormatEscape = NO_ESCAPE; @@ -1304,8 +1328,6 @@ finalize_it: RETiRet; } -// END v6 - /* Find a template object based on name. Search * currently is case-senstive (should we change?). -- cgit