diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/rsconf.c | 3 | ||||
-rw-r--r-- | runtime/rsyslog.h | 1 | ||||
-rw-r--r-- | runtime/ruleset.c | 57 | ||||
-rw-r--r-- | runtime/ruleset.h | 1 |
4 files changed, 59 insertions, 3 deletions
diff --git a/runtime/rsconf.c b/runtime/rsconf.c index 982013e9..97680795 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -412,6 +412,9 @@ void cnfDoObj(struct cnfobj *o) case CNFOBJ_TPL: tplProcessCnf(o); break; + case CNFOBJ_RULESET: + rulesetProcessCnf(o); + break; case CNFOBJ_PROPERTY: case CNFOBJ_CONSTANT: /* these types are processed at a later stage */ diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index 336ab5bf..ad5e54b4 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -390,6 +390,7 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth RS_RET_BSD_BLOCKS_UNSUPPORTED = -2304, /**< BSD-style config blocks are no longer supported */ RS_RET_JNAME_NOTFOUND = -2305, /**< JSON name not found (does not exist) */ RS_RET_INVLD_SETOP = -2305, /**< invalid variable set operation, incompatible type */ + RS_RET_RULESET_EXISTS = -2306,/**< ruleset already exists */ /* RainerScript error messages (range 1000.. 1999) */ RS_RET_SYSVAR_NOT_FOUND = 1001, /**< system variable could not be found (maybe misspelled) */ diff --git a/runtime/ruleset.c b/runtime/ruleset.c index 2af44bc4..896df5c6 100644 --- a/runtime/ruleset.c +++ b/runtime/ruleset.c @@ -29,7 +29,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "config.h" #include <stdlib.h> #include <assert.h> @@ -56,6 +55,16 @@ DEFobjStaticHelpers DEFobjCurrIf(errmsg) DEFobjCurrIf(parser) +/* tables for interfacing with the v6 config system (as far as we need to) */ +static struct cnfparamdescr rspdescr[] = { + { "name", eCmdHdlrString, CNFPARAM_REQUIRED } +}; +static struct cnfparamblk rspblk = + { CNFPARAMBLK_VERSION, + sizeof(rspdescr)/sizeof(struct cnfparamdescr), + rspdescr + }; + /* forward definitions */ static rsRetVal processBatch(batch_t *pBatch); static rsRetVal scriptExec(struct cnfstmt *root, batch_t *pBatch, sbool *active); @@ -564,6 +573,7 @@ GetParserList(rsconf_t *conf, msg_t *pMsg) static void addScript(ruleset_t *pThis, struct cnfstmt *script) { +dbgprintf("DDDD: add script %p, ruleset %p\n", script, pThis); if(pThis->last == NULL) pThis->root = pThis->last = script; else { @@ -574,7 +584,7 @@ addScript(ruleset_t *pThis, struct cnfstmt *script) /* set name for ruleset */ -static rsRetVal setName(ruleset_t *pThis, uchar *pszName) +static rsRetVal rulesetSetName(ruleset_t *pThis, uchar *pszName) { DEFiRet; free(pThis->pszName); @@ -890,6 +900,47 @@ rulesetAddParser(void __attribute__((unused)) *pVal, uchar *pName) } +/* Process ruleset() objects */ +rsRetVal +rulesetProcessCnf(struct cnfobj *o) +{ + struct cnfparamvals *pvals; + rsRetVal localRet; + uchar *rsName = NULL; + int nameIdx; + ruleset_t *pRuleset; + DEFiRet; + + pvals = nvlstGetParams(o->nvlst, &rspblk, NULL); + if(pvals == NULL) { + ABORT_FINALIZE(RS_RET_CONFIG_ERROR); + } + DBGPRINTF("ruleset param blk after rulesetProcessCnf:\n"); + cnfparamsPrint(&rspblk, pvals); + nameIdx = cnfparamGetIdx(&rspblk, "name"); + rsName = (uchar*)es_str2cstr(pvals[nameIdx].val.d.estr, NULL); + localRet = rulesetGetRuleset(loadConf, &pRuleset, rsName); + if(localRet == RS_RET_OK) { + errmsg.LogError(0, RS_RET_RULESET_EXISTS, + "error: ruleset '%s' specified more than once", + rsName); + cnfstmtDestruct(o->script); + ABORT_FINALIZE(RS_RET_RULESET_EXISTS); + } else if(localRet != RS_RET_NOT_FOUND) { + ABORT_FINALIZE(localRet); + } + CHKiRet(rulesetConstruct(&pRuleset)); + CHKiRet(rulesetSetName(pRuleset, rsName)); + CHKiRet(rulesetConstructFinalize(loadConf, pRuleset)); + addScript(pRuleset, o->script); + +finalize_it: + free(rsName); + cnfparamvalsDestruct(pvals, &rspblk); + RETiRet; +} + + /* queryInterface function * rgerhards, 2008-02-21 */ @@ -913,7 +964,7 @@ CODESTARTobjQueryInterface(ruleset) pIf->DestructAllActions = destructAllActions; pIf->AddScript = addScript; pIf->ProcessBatch = processBatch; - pIf->SetName = setName; + pIf->SetName = rulesetSetName; pIf->DebugPrintAll = debugPrintAll; pIf->GetCurrent = GetCurrent; pIf->GetRuleset = rulesetGetRuleset; diff --git a/runtime/ruleset.h b/runtime/ruleset.h index 1f8f948f..93a2f06e 100644 --- a/runtime/ruleset.h +++ b/runtime/ruleset.h @@ -95,4 +95,5 @@ rulesetGetName(ruleset_t *pRuleset) */ rsRetVal rulesetGetRuleset(rsconf_t *conf, ruleset_t **ppRuleset, uchar *pszName); rsRetVal rulesetOptimizeAll(rsconf_t *conf); +rsRetVal rulesetProcessCnf(struct cnfobj *o); #endif /* #ifndef INCLUDED_RULESET_H */ |