summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-11-04 14:21:08 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2009-11-04 14:21:08 +0100
commitb6a92e2f23895cadf9f0ea2de64021912bd2eeb0 (patch)
tree734177c4783d946ea28af05dfd75b60ae6d6d2c9 /runtime
parentef661fe13c0ab5018afedb1cb5b8cffab05ad7c4 (diff)
downloadrsyslog-b6a92e2f23895cadf9f0ea2de64021912bd2eeb0.tar.gz
rsyslog-b6a92e2f23895cadf9f0ea2de64021912bd2eeb0.tar.xz
rsyslog-b6a92e2f23895cadf9f0ea2de64021912bd2eeb0.zip
added $RulesetParser config directive
The implementation is now almost done and works, including doc. I now need to verify shutdown, guess there are some resource leaks left...
Diffstat (limited to 'runtime')
-rw-r--r--runtime/parser.c8
-rw-r--r--runtime/ruleset.c48
2 files changed, 51 insertions, 5 deletions
diff --git a/runtime/parser.c b/runtime/parser.c
index e87068fc..0689657f 100644
--- a/runtime/parser.c
+++ b/runtime/parser.c
@@ -450,9 +450,10 @@ ParseMsg(msg_t *pMsg)
* loger possible.
*/
pParserList = ruleset.GetParserList(pMsg);
- if(pParserList == NULL)
+ if(pParserList == NULL) {
pParserList = pDfltParsLst;
- DBGPRINTF("Using parser list %p%s.\n", pParserList,
+ }
+ DBGPRINTF("parse using parser list %p%s.\n", pParserList,
(pParserList == pDfltParsLst) ? " (the default list)" : "");
bIsSanitized = FALSE;
@@ -467,7 +468,8 @@ ParseMsg(msg_t *pMsg)
}
bIsSanitized = TRUE;
}
- localRet = pParserList->pParser->pModule->mod.pm.parse(pMsg);
+ localRet = pParser->pModule->mod.pm.parse(pMsg);
+ dbgprintf("Parser '%s' returned %d\n", pParser->pName, localRet);
if(localRet != RS_RET_COULD_NOT_PARSE)
break;
pParserList = pParserList->pNext;
diff --git a/runtime/ruleset.c b/runtime/ruleset.c
index 5e1bfced..bfcb520f 100644
--- a/runtime/ruleset.c
+++ b/runtime/ruleset.c
@@ -45,6 +45,7 @@
#include "ruleset.h"
#include "rule.h"
#include "errmsg.h"
+#include "parser.h"
#include "unicode-helper.h"
#include "dirty.h" /* for main ruleset queue creation */
@@ -52,10 +53,11 @@
DEFobjStaticHelpers
DEFobjCurrIf(errmsg)
DEFobjCurrIf(rule)
+DEFobjCurrIf(parser)
linkedList_t llRulesets; /* this is NOT a pointer - no typo here ;) */
ruleset_t *pCurrRuleset = NULL; /* currently "active" ruleset */
-ruleset_t *pDfltRuleset = NULL; /* currentl default ruleset, e.g. for binding to actions which have no other */
+ruleset_t *pDfltRuleset = NULL; /* current default ruleset, e.g. for binding to actions which have no other */
/* ---------- linked-list key handling functions ---------- */
@@ -174,7 +176,7 @@ dbgprintf("ruleset.ProcessMsg() returns %d\n", iRet);
static parserList_t*
GetParserList(msg_t *pMsg)
{
- return (pMsg->pRuleset == NULL) ? NULL : pMsg->pRuleset->pParserLst;
+ return (pMsg->pRuleset == NULL) ? pDfltRuleset->pParserLst : pMsg->pRuleset->pParserLst;
}
@@ -448,6 +450,46 @@ finalize_it:
}
+/* Add a ruleset specific parser to the ruleset. Note that adding the first
+ * parser automatically disables the default parsers. If they are needed as well,
+ * the must be added via explicit config directives.
+ * Note: this is the only spot in the code that requires the parser object. In order
+ * to solve some class init bootstrap sequence problems, we get the object handle here
+ * instead of during module initialization. Note that objUse() is capable of being
+ * called multiple times.
+ * rgerhards, 2009-11-04
+ */
+static rsRetVal
+rulesetAddParser(void __attribute__((unused)) *pVal, uchar *pName)
+{
+ parser_t *pParser;
+ DEFiRet;
+
+ assert(pCurrRuleset != NULL);
+
+ CHKiRet(objUse(parser, CORE_COMPONENT));
+ iRet = parser.FindParser(&pParser, pName);
+ if(iRet == RS_RET_PARSER_NOT_FOUND) {
+ errmsg.LogError(0, RS_RET_PARSER_NOT_FOUND, "error: parser '%s' unknown at this time "
+ "(maybe defined too late in rsyslog.conf?)", pName);
+ ABORT_FINALIZE(RS_RET_NO_CURR_RULESET);
+ } else if(iRet != RS_RET_OK) {
+ errmsg.LogError(0, iRet, "error trying to find parser '%s'\n", pName);
+ FINALIZE;
+ }
+
+ CHKiRet(parser.AddParserToList(&pCurrRuleset->pParserLst, pParser));
+
+ dbgprintf("added parser '%s' to ruleset '%s'\n", pName, pCurrRuleset->pszName);
+RUNLOG_VAR("%p", pCurrRuleset->pParserLst);
+
+finalize_it:
+ d_free(pName); /* no longer needed */
+
+ RETiRet;
+}
+
+
/* queryInterface function
* rgerhards, 2008-02-21
*/
@@ -490,6 +532,7 @@ BEGINObjClassExit(ruleset, OBJ_IS_CORE_MODULE) /* class, version */
llDestroy(&llRulesets);
objRelease(errmsg, CORE_COMPONENT);
objRelease(rule, CORE_COMPONENT);
+ objRelease(parser, CORE_COMPONENT);
ENDObjClassExit(ruleset)
@@ -510,6 +553,7 @@ BEGINObjClassInit(ruleset, 1, OBJ_IS_CORE_MODULE) /* class, version */
CHKiRet(llInit(&llRulesets, rulesetDestructForLinkedList, keyDestruct, strcasecmp));
/* config file handlers */
+ CHKiRet(regCfSysLineHdlr((uchar *)"rulesetparser", 0, eCmdHdlrGetWord, rulesetAddParser, NULL, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"rulesetcreatemainqueue", 0, eCmdHdlrBinary, rulesetCreateQueue, NULL, NULL));
ENDObjClassInit(ruleset)