From 7c2183ee323dc062b0dde6bac4cd9c5afa4ab369 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 26 Sep 2012 12:25:10 +0200 Subject: input stmt: add core engine plumbing --- runtime/rsconf.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'runtime/rsconf.c') diff --git a/runtime/rsconf.c b/runtime/rsconf.c index 67a13893..170e0bb1 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -99,6 +99,18 @@ static uchar template_SysklogdFileFormat[] = "\"%TIMESTAMP% %HOSTNAME% %syslogta static uchar template_StdJSONFmt[] = "\"{\\\"message\\\":\\\"%msg:::json%\\\",\\\"fromhost\\\":\\\"%HOSTNAME:::json%\\\",\\\"facility\\\":\\\"%syslogfacility-text%\\\",\\\"priority\\\":\\\"%syslogpriority-text%\\\",\\\"timereported\\\":\\\"%timereported:::date-rfc3339%\\\",\\\"timegenerated\\\":\\\"%timegenerated:::date-rfc3339%\\\"}\""; /* end templates */ +/* tables for interfacing with the v6 config system (as far as we need to) */ +static struct cnfparamdescr inppdescr[] = { + { "name", eCmdHdlrGetWord, 0 }, + { "type", eCmdHdlrString, CNFPARAM_REQUIRED } +}; +static struct cnfparamblk inppblk = + { CNFPARAMBLK_VERSION, + sizeof(inppdescr)/sizeof(struct cnfparamdescr), + inppdescr + }; + +/* forward-definitions */ void cnfDoCfsysline(char *ln); /* Standard-Constructor @@ -373,6 +385,49 @@ finalize_it: return estr; } + +/* Process input() objects */ +rsRetVal +inputProcessCnf(struct cnfobj *o) +{ + struct cnfparamvals *pvals; + modInfo_t *pMod; + uchar *cnfModName = NULL; + void *pModData; + action_t *pAction; + int typeIdx; + DEFiRet; + + pvals = nvlstGetParams(o->nvlst, &inppblk, NULL); + if(pvals == NULL) { + ABORT_FINALIZE(RS_RET_ERR); + } + DBGPRINTF("input param blk after inputProcessCnf:\n"); + cnfparamsPrint(&inppblk, pvals); + typeIdx = cnfparamGetIdx(&inppblk, "type"); + if(pvals[typeIdx].bUsed == 0) { + errmsg.LogError(0, RS_RET_CONF_RQRD_PARAM_MISSING, "input type missing"); + ABORT_FINALIZE(RS_RET_CONF_RQRD_PARAM_MISSING); // TODO: move this into rainerscript handlers + } + cnfModName = (uchar*)es_str2cstr(pvals[typeIdx].val.d.estr, NULL); + if((pMod = module.FindWithCnfName(loadConf, cnfModName, eMOD_IN)) == NULL) { + errmsg.LogError(0, RS_RET_MOD_UNKNOWN, "input module name '%s' is unknown", cnfModName); + ABORT_FINALIZE(RS_RET_MOD_UNKNOWN); + } + if(pMod->mod.im.newInpInst == NULL) { + errmsg.LogError(0, RS_RET_MOD_NO_INPUT_STMT, + "input module '%s' does not support input() statement", cnfModName); + ABORT_FINALIZE(RS_RET_MOD_NO_INPUT_STMT); + } +dbgprintf("DDDD: ready to roll...\n"); + CHKiRet(pMod->mod.im.newInpInst(o->nvlst)); +dbgprintf("DDDD: done calling module entry point\n"); +finalize_it: + free(cnfModName); + cnfparamvalsDestruct(pvals, &inppblk); + RETiRet; +} + /*------------------------------ interface to flex/bison parser ------------------------------*/ extern int yylineno; @@ -416,6 +471,9 @@ void cnfDoObj(struct cnfobj *o) case CNFOBJ_ACTION: actionProcessCnf(o); break; + case CNFOBJ_INPUT: + inputProcessCnf(o); + break; case CNFOBJ_TPL: tplProcessCnf(o); break; -- cgit v1.2.3 From 62eee485a7b1ec6034e22d2cd60a0c13abb0ad54 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 26 Sep 2012 15:21:53 +0200 Subject: cleanup --- runtime/rsconf.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'runtime/rsconf.c') diff --git a/runtime/rsconf.c b/runtime/rsconf.c index 170e0bb1..9d5bb135 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -101,7 +101,6 @@ static uchar template_StdJSONFmt[] = "\"{\\\"message\\\":\\\"%msg:::json%\\\",\\ /* tables for interfacing with the v6 config system (as far as we need to) */ static struct cnfparamdescr inppdescr[] = { - { "name", eCmdHdlrGetWord, 0 }, { "type", eCmdHdlrString, CNFPARAM_REQUIRED } }; static struct cnfparamblk inppblk = @@ -393,8 +392,6 @@ inputProcessCnf(struct cnfobj *o) struct cnfparamvals *pvals; modInfo_t *pMod; uchar *cnfModName = NULL; - void *pModData; - action_t *pAction; int typeIdx; DEFiRet; -- cgit v1.2.3 From f22cb74085d29bcc8b02ca45b118b60a0c043aca Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 26 Sep 2012 16:08:02 +0200 Subject: cleanup --- runtime/rsconf.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'runtime/rsconf.c') diff --git a/runtime/rsconf.c b/runtime/rsconf.c index 9d5bb135..e7ff0899 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -416,9 +416,7 @@ inputProcessCnf(struct cnfobj *o) "input module '%s' does not support input() statement", cnfModName); ABORT_FINALIZE(RS_RET_MOD_NO_INPUT_STMT); } -dbgprintf("DDDD: ready to roll...\n"); CHKiRet(pMod->mod.im.newInpInst(o->nvlst)); -dbgprintf("DDDD: done calling module entry point\n"); finalize_it: free(cnfModName); cnfparamvalsDestruct(pvals, &inppblk); -- cgit v1.2.3 From 77b4efaeecf53678a3de579d73567e61c3b4785b Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 27 Sep 2012 14:22:23 +0200 Subject: Do not load module if it had errorneous parameters --- runtime/rsconf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'runtime/rsconf.c') diff --git a/runtime/rsconf.c b/runtime/rsconf.c index e7ff0899..118e9c11 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -1083,10 +1083,13 @@ setModDir(void __attribute__((unused)) *pVal, uchar* pszNewVal) static rsRetVal regBuildInModule(rsRetVal (*modInit)(), uchar *name, void *pModHdlr) { + cfgmodules_etry_t *pNew; + cfgmodules_etry_t *pLast; modInfo_t *pMod; DEFiRet; CHKiRet(module.doModInit(modInit, name, pModHdlr, &pMod)); - addModToCnfList(pMod); + readyModForCnf(pMod, &pNew, &pLast); + addModToCnfList(pNew, pLast); finalize_it: RETiRet; } -- cgit v1.2.3