summaryrefslogtreecommitdiffstats
path: root/cfsysline.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-02-14 15:43:50 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-02-14 15:43:50 +0000
commit52b6b6f2211718101e43de05e5292f555e8198a8 (patch)
treee84f9d0fe3cc2c436d944357812712e6961ef296 /cfsysline.c
parentd6b22dd69ea85d024eaaac93e2a6521669f1ccc0 (diff)
downloadrsyslog-52b6b6f2211718101e43de05e5292f555e8198a8.tar.gz
rsyslog-52b6b6f2211718101e43de05e5292f555e8198a8.tar.xz
rsyslog-52b6b6f2211718101e43de05e5292f555e8198a8.zip
- added new facility and severity syntaxes to cfsysline handler
- implemented $InputFileFacility config directive - implemented $InputFileSeverity config directive
Diffstat (limited to 'cfsysline.c')
-rw-r--r--cfsysline.c124
1 files changed, 105 insertions, 19 deletions
diff --git a/cfsysline.c b/cfsysline.c
index 0cc6c134..7249188e 100644
--- a/cfsysline.c
+++ b/cfsysline.c
@@ -438,7 +438,40 @@ finalize_it:
}
-/* Parse and a word config line option. A word is a consequitive
+/* parse a whitespace-delimited word from the provided string. This is a
+ * helper function for a number of syntaxes. The parsed value is returned
+ * in ppStrB (which must be provided by caller).
+ * rgerhards, 2008-02-14
+ */
+static rsRetVal
+getWord(uchar **pp, rsCStrObj **ppStrB)
+{
+ DEFiRet;
+ uchar *p;
+
+ ASSERT(pp != NULL);
+ ASSERT(*pp != NULL);
+ ASSERT(*ppStrB != NULL);
+
+ if((*ppStrB = rsCStrConstruct()) == NULL)
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+
+ /* parse out the word */
+ p = *pp;
+
+ while(*p && !isspace((int) *p)) {
+ CHKiRet(rsCStrAppendChar(*ppStrB, *p++));
+ }
+ CHKiRet(rsCStrFinish(*ppStrB));
+
+ *pp = p;
+
+finalize_it:
+ RETiRet;
+}
+
+
+/* Parse and a word config line option. A word is a consequtive
* sequence of non-whitespace characters. pVal must be
* a pointer to a string which is to receive the option
* value. The returned string must be freed by the caller.
@@ -455,23 +488,12 @@ static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void
{
DEFiRet;
rsCStrObj *pStrB;
- uchar *p;
uchar *pNewVal;
- assert(pp != NULL);
- assert(*pp != NULL);
-
- if((pStrB = rsCStrConstruct()) == NULL)
- return RS_RET_OUT_OF_MEMORY;
-
- /* parse out the word */
- p = *pp;
-
- while(*p && !isspace((int) *p)) {
- CHKiRet(rsCStrAppendChar(pStrB, *p++));
- }
- CHKiRet(rsCStrFinish(pStrB));
+ ASSERT(pp != NULL);
+ ASSERT(*pp != NULL);
+ CHKiRet(getWord(pp, &pStrB));
CHKiRet(rsCStrConvSzStrAndDestruct(pStrB, &pNewVal, 0));
pStrB = NULL;
@@ -486,7 +508,6 @@ static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void
CHKiRet(pSetHdlr(pVal, pNewVal));
}
- *pp = p;
skipWhiteSpace(pp); /* skip over any whitespace */
finalize_it:
@@ -499,6 +520,66 @@ finalize_it:
}
+/* parse a syslog name from the string. This is the generic code that is
+ * called by the facility/severity functions. Note that we do not check the
+ * validity of numerical values, something that should probably change over
+ * time (TODO). -- rgerhards, 2008-02-14
+ */
+static rsRetVal
+doSyslogName(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal, syslogName_t *pNameTable)
+{
+ DEFiRet;
+ rsCStrObj *pStrB;
+ int iNewVal;
+
+ ASSERT(pp != NULL);
+ ASSERT(*pp != NULL);
+
+ CHKiRet(getWord(pp, &pStrB)); /* get word */
+ iNewVal = decodeSyslogName(rsCStrGetSzStr(pStrB), pNameTable);
+
+ if(pSetHdlr == NULL) {
+ /* we should set value directly to var */
+ *((int*)pVal) = iNewVal; /* set new one */
+ } else {
+ /* we set value via a set function */
+ CHKiRet(pSetHdlr(pVal, iNewVal));
+ }
+
+ skipWhiteSpace(pp); /* skip over any whitespace */
+
+finalize_it:
+ if(pStrB != NULL)
+ rsCStrDestruct(pStrB);
+
+ RETiRet;
+}
+
+
+/* Implements the facility syntax.
+ * rgerhards, 2008-02-14
+ */
+static rsRetVal
+doFacility(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal)
+{
+ DEFiRet;
+ iRet = doSyslogName(pp, pSetHdlr, pVal, syslogFacNames);
+ RETiRet;
+}
+
+
+/* Implements the severity syntax.
+ * rgerhards, 2008-02-14
+ */
+static rsRetVal
+doSeverity(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal)
+{
+ DEFiRet;
+ iRet = doSyslogName(pp, pSetHdlr, pVal, syslogPriNames);
+ RETiRet;
+}
+
+
/* --------------- END functions for handling canned syntaxes --------------- */
/* destructor for cslCmdHdlr
@@ -507,7 +588,7 @@ finalize_it:
*/
static rsRetVal cslchDestruct(void *pThis)
{
- assert(pThis != NULL);
+ ASSERT(pThis != NULL);
free(pThis);
return RS_RET_OK;
@@ -607,6 +688,12 @@ static rsRetVal cslchCallHdlr(cslCmdHdlr_t *pThis, uchar **ppConfLine)
case eCmdHdlrGetChar:
pHdlr = doGetChar;
break;
+ case eCmdHdlrFacility:
+ pHdlr = doFacility;
+ break;
+ case eCmdHdlrSeverity:
+ pHdlr = doSeverity;
+ break;
case eCmdHdlrGetWord:
pHdlr = doGetWord;
break;
@@ -892,6 +979,5 @@ void dbgPrintCfSysLineHandlers(void)
ENDfunc
}
-/*
- * vi:set ai:
+/* vim:set ai:
*/