summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-12 15:31:08 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-12 15:31:08 +0200
commitca0ddc30a3edce02a440904a01f0b866c0f82b5a (patch)
treef751d9d677ce901841874e05650f7ea236a90976 /runtime
parent21dafea3ee98d16a8fe93d0d5228939dc259aea7 (diff)
downloadrsyslog-ca0ddc30a3edce02a440904a01f0b866c0f82b5a.tar.gz
rsyslog-ca0ddc30a3edce02a440904a01f0b866c0f82b5a.tar.xz
rsyslog-ca0ddc30a3edce02a440904a01f0b866c0f82b5a.zip
completed multi-ruleset core support
... as well as added multi-ruleset support for imtcp
Diffstat (limited to 'runtime')
-rw-r--r--runtime/cfsysline.c6
-rw-r--r--runtime/conf.c2
-rw-r--r--runtime/msg.c13
-rw-r--r--runtime/msg.h2
-rw-r--r--runtime/obj.c4
-rw-r--r--runtime/rsyslog.c20
-rw-r--r--runtime/ruleset.c84
-rw-r--r--runtime/ruleset.h6
8 files changed, 116 insertions, 21 deletions
diff --git a/runtime/cfsysline.c b/runtime/cfsysline.c
index e1e4a6a4..c39e54f6 100644
--- a/runtime/cfsysline.c
+++ b/runtime/cfsysline.c
@@ -814,7 +814,7 @@ rsRetVal regCfSysLineHdlr(uchar *pCmdName, int bChainingPermitted, ecslCmdHdrlTy
CHKiRet(cslcConstruct(&pThis, bChainingPermitted));
CHKiRet_Hdlr(cslcAddHdlr(pThis, eType, pHdlr, pData, pOwnerCookie)) {
cslcDestruct(pThis);
- goto finalize_it;
+ FINALIZE;
}
/* important: add to list, AFTER everything else is OK. Else
* we mess up things in the error case.
@@ -825,7 +825,7 @@ rsRetVal regCfSysLineHdlr(uchar *pCmdName, int bChainingPermitted, ecslCmdHdrlTy
}
CHKiRet_Hdlr(llAppend(&llCmdList, pMyCmdName, (void*) pThis)) {
cslcDestruct(pThis);
- goto finalize_it;
+ FINALIZE;
}
} else {
/* command already exists, are we allowed to chain? */
@@ -834,7 +834,7 @@ rsRetVal regCfSysLineHdlr(uchar *pCmdName, int bChainingPermitted, ecslCmdHdrlTy
}
CHKiRet_Hdlr(cslcAddHdlr(pThis, eType, pHdlr, pData, pOwnerCookie)) {
cslcDestruct(pThis);
- goto finalize_it;
+ FINALIZE;
}
}
diff --git a/runtime/conf.c b/runtime/conf.c
index 81b6c081..dbc54fd4 100644
--- a/runtime/conf.c
+++ b/runtime/conf.c
@@ -1152,7 +1152,7 @@ cflineClassic(uchar *p, rule_t **ppRule)
CHKiRet(ruleset.AddRule(rule.GetAssRuleset(*ppRule), ppRule));
}
CHKiRet(rule.Construct(ppRule)); /* create "fresh" selector */
- CHKiRet(rule.SetAssRuleset(*ppRule, pCurrRuleset)); /* create "fresh" selector */
+ CHKiRet(rule.SetAssRuleset(*ppRule, ruleset.GetCurrent())); /* create "fresh" selector */
CHKiRet(rule.ConstructFinalize(*ppRule)); /* create "fresh" selector */
CHKiRet(cflineDoFilter(&p, *ppRule)); /* pull filters */
}
diff --git a/runtime/msg.c b/runtime/msg.c
index dbc3c779..10f283aa 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -46,6 +46,7 @@
#include "regexp.h"
#include "atomic.h"
#include "unicode-helper.h"
+#include "ruleset.h"
/* static data */
DEFobjStaticHelpers
@@ -1166,13 +1167,21 @@ void MsgAssignTAG(msg_t *pMsg, uchar *pBuf)
}
+/* rgerhards 2009-06-12: set associated ruleset
+ */
+void MsgSetRuleset(msg_t *pMsg, ruleset_t *pRuleset)
+{
+ assert(pMsg != NULL);
+ pMsg->pRuleset = pRuleset;
+}
+
+
/* rgerhards 2004-11-16: set TAG in msg object
*/
void MsgSetTAG(msg_t *pMsg, char* pszTAG)
{
assert(pMsg != NULL);
- if(pMsg->pszTAG != NULL)
- free(pMsg->pszTAG);
+ free(pMsg->pszTAG);
pMsg->iLenTAG = strlen(pszTAG);
if((pMsg->pszTAG = malloc(pMsg->iLenTAG + 1)) != NULL)
memcpy(pMsg->pszTAG, pszTAG, pMsg->iLenTAG + 1);
diff --git a/runtime/msg.h b/runtime/msg.h
index a14f6b15..b42f641f 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -120,6 +120,7 @@ short bDoLock; /* use the mutex? */
char *pszTIMESTAMP_PgSQL;/* TIMESTAMP as PgSQL formatted string (always 21 characters) */
char *pszTIMESTAMP_SecFrac;/* TIMESTAMP fractional seconds (always 6 characters) */
int msgFlags; /* flags associated with this message */
+ ruleset_t *pRuleset; /* ruleset to be used for processing this message */
};
@@ -167,6 +168,7 @@ char *getPROCID(msg_t *pM);
rsRetVal MsgSetMSGID(msg_t *pMsg, char* pszMSGID);
void MsgAssignTAG(msg_t *pMsg, uchar *pBuf);
void MsgSetTAG(msg_t *pMsg, char* pszTAG);
+void MsgSetRuleset(msg_t *pMsg, ruleset_t*);
rsRetVal MsgSetFlowControlType(msg_t *pMsg, flowControl_t eFlowCtl);
char *getTAG(msg_t *pM);
int getHOSTNAMELen(msg_t *pM);
diff --git a/runtime/obj.c b/runtime/obj.c
index 8b9c9c83..f38b1d7f 100644
--- a/runtime/obj.c
+++ b/runtime/obj.c
@@ -1279,8 +1279,8 @@ objClassExit(void)
/* TODO: implement the class exits! */
#if 0
- cfsyslineInit(pModInfo);
- varClassInit(pModInfo);
+ cfsyslineExit(pModInfo);
+ varClassExit(pModInfo);
#endif
errmsgClassExit();
moduleClassExit();
diff --git a/runtime/rsyslog.c b/runtime/rsyslog.c
index 3496bb0d..6f732f0e 100644
--- a/runtime/rsyslog.c
+++ b/runtime/rsyslog.c
@@ -152,12 +152,10 @@ rsrtInit(char **ppErrObj, obj_if_t *pObjIF)
CHKiRet(datetimeClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "msg";
CHKiRet(msgClassInit(NULL));
- if(ppErrObj != NULL) *ppErrObj = "wti";
- CHKiRet(wtiClassInit(NULL));
- if(ppErrObj != NULL) *ppErrObj = "wtp";
- CHKiRet(wtpClassInit(NULL));
- if(ppErrObj != NULL) *ppErrObj = "queue";
- CHKiRet(qqueueClassInit(NULL));
+ if(ppErrObj != NULL) *ppErrObj = "ctok_token";
+ CHKiRet(ctok_tokenClassInit(NULL));
+ if(ppErrObj != NULL) *ppErrObj = "ctok";
+ CHKiRet(ctokClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "vmstk";
CHKiRet(vmstkClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "sysvar";
@@ -168,16 +166,18 @@ rsrtInit(char **ppErrObj, obj_if_t *pObjIF)
CHKiRet(vmopClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "vmprg";
CHKiRet(vmprgClassInit(NULL));
- if(ppErrObj != NULL) *ppErrObj = "ctok_token";
- CHKiRet(ctok_tokenClassInit(NULL));
- if(ppErrObj != NULL) *ppErrObj = "ctok";
- CHKiRet(ctokClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "expr";
CHKiRet(exprClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "rule";
CHKiRet(ruleClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "ruleset";
CHKiRet(rulesetClassInit(NULL));
+ if(ppErrObj != NULL) *ppErrObj = "wti";
+ CHKiRet(wtiClassInit(NULL));
+ if(ppErrObj != NULL) *ppErrObj = "wtp";
+ CHKiRet(wtpClassInit(NULL));
+ if(ppErrObj != NULL) *ppErrObj = "queue";
+ CHKiRet(qqueueClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "conf";
CHKiRet(confClassInit(NULL));
diff --git a/runtime/ruleset.c b/runtime/ruleset.c
index f9edde8b..93d40e24 100644
--- a/runtime/ruleset.c
+++ b/runtime/ruleset.c
@@ -40,6 +40,7 @@
#include "rsyslog.h"
#include "obj.h"
+#include "msg.h"
#include "ruleset.h"
#include "rule.h"
#include "errmsg.h"
@@ -53,6 +54,8 @@ DEFobjCurrIf(errmsg)
DEFobjCurrIf(rule)
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 */
/* ---------- linked-list key handling functions ---------- */
@@ -147,12 +150,15 @@ DEFFUNC_llExecFunc(processMsgDoRules)
* rgerhards, 2005-10-13
*/
static rsRetVal
-processMsg(ruleset_t *pThis, msg_t *pMsg)
+processMsg(msg_t *pMsg)
{
+ ruleset_t *pThis;
DEFiRet;
- ISOBJ_TYPE_assert(pThis, ruleset);
assert(pMsg != NULL);
+ pThis = (pMsg->pRuleset == NULL) ? pDfltRuleset : pMsg->pRuleset;
+ ISOBJ_TYPE_assert(pThis, ruleset);
+
CHKiRet(llExecFunc(&pThis->llRules, processMsgDoRules, pMsg));
finalize_it:
@@ -200,6 +206,69 @@ finalize_it:
}
+/* get current ruleset
+ * We use a non-standard calling interface, as nothing can go wrong and it
+ * is really much more natural to return the pointer directly.
+ */
+static ruleset_t*
+GetCurrent(void)
+{
+ return pCurrRuleset;
+}
+
+
+/* Find the ruleset with the given name and return a pointer to its object.
+ */
+static rsRetVal
+GetRuleset(ruleset_t **ppRuleset, uchar *pszName)
+{
+ DEFiRet;
+ assert(ppRuleset != NULL);
+ assert(pszName != NULL);
+
+ CHKiRet(llFind(&llRulesets, pszName, (void*) ppRuleset));
+
+finalize_it:
+ RETiRet;
+}
+
+
+/* Set a new default rule set. If the default can not be found, no change happens.
+ */
+static rsRetVal
+SetDefaultRuleset(uchar *pszName)
+{
+ ruleset_t *pRuleset;
+ DEFiRet;
+ assert(pszName != NULL);
+
+ CHKiRet(GetRuleset(&pRuleset, pszName));
+ pDfltRuleset = pRuleset;
+ dbgprintf("default rule set changed to %p: '%s'\n", pRuleset, pszName);
+
+finalize_it:
+ RETiRet;
+}
+
+
+/* Set a new current rule set. If the ruleset can not be found, no change happens.
+ */
+static rsRetVal
+SetCurrRuleset(uchar *pszName)
+{
+ ruleset_t *pRuleset;
+ DEFiRet;
+ assert(pszName != NULL);
+
+ CHKiRet(GetRuleset(&pRuleset, pszName));
+ pCurrRuleset = pRuleset;
+ dbgprintf("current rule set changed to %p: '%s'\n", pRuleset, pszName);
+
+finalize_it:
+ RETiRet;
+}
+
+
/* destructor we need to destruct rules inside our linked list contents.
*/
static rsRetVal
@@ -237,6 +306,13 @@ rulesetConstructFinalize(ruleset_t *pThis)
CHKmalloc(keyName = ustrdup(pThis->pszName));
CHKiRet(llAppend(&llRulesets, keyName, pThis));
+ /* this now also is the new current ruleset */
+ pCurrRuleset = pThis;
+
+ /* and also the default, if so far none has been set */
+ if(pDfltRuleset == NULL)
+ pDfltRuleset = pThis;
+
finalize_it:
RETiRet;
}
@@ -336,6 +412,10 @@ CODESTARTobjQueryInterface(ruleset)
pIf->ProcessMsg = processMsg;
pIf->SetName = setName;
pIf->DebugPrintAll = debugPrintAll;
+ pIf->GetCurrent = GetCurrent;
+ pIf->GetRuleset = GetRuleset;
+ pIf->SetDefaultRuleset = SetDefaultRuleset;
+ pIf->SetCurrRuleset = SetCurrRuleset;
finalize_it:
ENDobjQueryInterface(ruleset)
diff --git a/runtime/ruleset.h b/runtime/ruleset.h
index b609e6b3..32571687 100644
--- a/runtime/ruleset.h
+++ b/runtime/ruleset.h
@@ -44,8 +44,12 @@ BEGINinterface(ruleset) /* name must also be changed in ENDinterface macro! */
rsRetVal (*IterateAllActions)(rsRetVal (*pFunc)(void*, void*), void* pParam);
rsRetVal (*DestructAllActions)(void);
rsRetVal (*AddRule)(ruleset_t *pThis, rule_t **ppRule);
- rsRetVal (*ProcessMsg)(ruleset_t *pThis, msg_t *pMsg);
rsRetVal (*SetName)(ruleset_t *pThis, uchar *pszName);
+ rsRetVal (*ProcessMsg)(msg_t *pMsg);
+ rsRetVal (*GetRuleset)(ruleset_t **ppThis, uchar*);
+ rsRetVal (*SetDefaultRuleset)(uchar*);
+ rsRetVal (*SetCurrRuleset)(uchar*);
+ ruleset_t* (*GetCurrent)(void);
ENDinterface(ruleset)
#define rulesetCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */