summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-11-03 12:39:48 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2009-11-03 12:39:48 +0100
commit6f511cecfae3592f271627ebcb41e6a8c4f831e9 (patch)
treefbc67531528d42ba50c66e1d9129792bad5a3cc5 /runtime
parent7d78b3bdfd357dd921797ce983eb96532c56a7f6 (diff)
downloadrsyslog-6f511cecfae3592f271627ebcb41e6a8c4f831e9.tar.gz
rsyslog-6f511cecfae3592f271627ebcb41e6a8c4f831e9.tar.xz
rsyslog-6f511cecfae3592f271627ebcb41e6a8c4f831e9.zip
more cleanup and working towards a parser module calling interface
I cleaned up a lot of config variable access along the way. This version compiles and runs, but does not yet offer any enhanced functionality. pmrfc5424 is just a dummy that is not yet being used.
Diffstat (limited to 'runtime')
-rw-r--r--runtime/glbl.c4
-rw-r--r--runtime/glbl.h4
-rw-r--r--runtime/module-template.h30
-rw-r--r--runtime/modules.c6
-rw-r--r--runtime/modules.h12
-rw-r--r--runtime/parser.c84
-rw-r--r--runtime/parser.h18
-rw-r--r--runtime/rsyslog.c3
-rw-r--r--runtime/rsyslog.h11
9 files changed, 151 insertions, 21 deletions
diff --git a/runtime/glbl.c b/runtime/glbl.c
index f27b8e73..71c2ed0d 100644
--- a/runtime/glbl.c
+++ b/runtime/glbl.c
@@ -56,6 +56,7 @@ DEFobjCurrIf(prop)
*/
static uchar *pszWorkDir = NULL;
static int bOptimizeUniProc = 1; /* enable uniprocessor optimizations */
+static int bParseHOSTNAMEandTAG = 1; /* parser modification (based on startup params!) */
static int bPreserveFQDN = 0; /* should FQDNs always be preserved? */
static int iMaxLine = 2048; /* maximum length of a syslog message */
static int iDefPFFamily = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */
@@ -94,6 +95,7 @@ static dataType Get##nameFunc(void) \
return(nameVar); \
}
+SIMP_PROP(ParseHOSTNAMEandTAG, bParseHOSTNAMEandTAG, int)
SIMP_PROP(OptimizeUniProc, bOptimizeUniProc, int)
SIMP_PROP(PreserveFQDN, bPreserveFQDN, int)
SIMP_PROP(MaxLine, iMaxLine, int)
@@ -183,6 +185,7 @@ finalize_it:
RETiRet;
}
+
/* return our local hostname as a string property
*/
static prop_t*
@@ -266,6 +269,7 @@ CODESTARTobjQueryInterface(glbl)
pIf->Set##name = Set##name;
SIMP_PROP(MaxLine);
SIMP_PROP(OptimizeUniProc);
+ SIMP_PROP(ParseHOSTNAMEandTAG);
SIMP_PROP(PreserveFQDN);
SIMP_PROP(DefPFFamily);
SIMP_PROP(DropMalPTRMsgs);
diff --git a/runtime/glbl.h b/runtime/glbl.h
index 0d0c8210..7506f16b 100644
--- a/runtime/glbl.h
+++ b/runtime/glbl.h
@@ -64,9 +64,11 @@ BEGINinterface(glbl) /* name must also be changed in ENDinterface macro! */
/* added v4, 2009-07-20 */
int (*GetGlobalInputTermState)(void);
void (*SetGlobalInputTermination)(void);
+ /* added v5, 2009-11-03 */
+ SIMP_PROP(ParseHOSTNAMEandTAG, int)
#undef SIMP_PROP
ENDinterface(glbl)
-#define glblCURR_IF_VERSION 4 /* increment whenever you change the interface structure! */
+#define glblCURR_IF_VERSION 5 /* increment whenever you change the interface structure! */
/* version 2 had PreserveFQDN added - rgerhards, 2008-12-08 */
/* the remaining prototypes */
diff --git a/runtime/module-template.h b/runtime/module-template.h
index d49da2c9..b136b6a3 100644
--- a/runtime/module-template.h
+++ b/runtime/module-template.h
@@ -46,6 +46,9 @@
DEFobjCurrIf(obj)
#define DEF_LMOD_STATIC_DATA \
DEF_MOD_STATIC_DATA
+#define DEF_PMOD_STATIC_DATA \
+ DEFobjCurrIf(obj) \
+ DEF_MOD_STATIC_DATA
/* Macro to define the module type. Each module can only have a single type. If
@@ -65,6 +68,7 @@ static rsRetVal modGetType(eModType_t *modType) \
#define MODULE_TYPE_INPUT MODULE_TYPE(eMOD_IN)
#define MODULE_TYPE_OUTPUT MODULE_TYPE(eMOD_OUT)
+#define MODULE_TYPE_PARSER MODULE_TYPE(eMOD_PARSER)
#define MODULE_TYPE_LIB \
DEF_LMOD_STATIC_DATA \
MODULE_TYPE(eMOD_LIB)
@@ -400,6 +404,16 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())\
#define CODEqueryEtryPt_STD_LIB_QUERIES \
CODEqueryEtryPt_STD_MOD_QUERIES
+/* the following definition is the standard block for queryEtryPt for PARSER
+ * modules. This can be used if no specific handling (e.g. to cover version
+ * differences) is needed.
+ */
+#define CODEqueryEtryPt_STD_PMOD_QUERIES \
+ CODEqueryEtryPt_STD_MOD_QUERIES \
+ else if(!strcmp((char*) name, "parse")) {\
+ *pEtryPoint = parse;\
+ }
+
/* modInit()
* This has an extra parameter, which is the specific name of the modInit
* function. That is needed for built-in modules, which must have unique
@@ -590,5 +604,21 @@ static rsRetVal doHUP(instanceData __attribute__((unused)) *pData)\
}
+
+/* parse() - main entry point of parser modules
+ */
+#define BEGINparse \
+static rsRetVal parse(msg_t *pMsg)\
+{\
+ DEFiRet;
+
+#define CODESTARTparse \
+ assert(pMsg != NULL);
+
+#define ENDparse \
+ RETiRet;\
+}
+
+
/* vim:set ai:
*/
diff --git a/runtime/modules.c b/runtime/modules.c
index bdb15e7f..5321c5e8 100644
--- a/runtime/modules.c
+++ b/runtime/modules.c
@@ -475,6 +475,9 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)(), modInfo_
break;
case eMOD_LIB:
break;
+ case eMOD_PARSER:
+ CHKiRet((*pNew->modQueryEtryPt)((uchar*)"parse", &pNew->mod.pm.parse));
+ break;
}
pNew->pszName = (uchar*) strdup((char*)name); /* we do not care if strdup() fails, we can accept that */
@@ -521,6 +524,9 @@ static void modPrintList(void)
case eMOD_LIB:
dbgprintf("library");
break;
+ case eMOD_PARSER:
+ dbgprintf("parser");
+ break;
}
dbgprintf(" module.\n");
dbgprintf("Entry points:\n");
diff --git a/runtime/modules.h b/runtime/modules.h
index 71e3199c..e92760b8 100644
--- a/runtime/modules.h
+++ b/runtime/modules.h
@@ -51,9 +51,10 @@
#define CURR_MOD_IF_VERSION 5
typedef enum eModType_ {
- eMOD_IN, /* input module */
- eMOD_OUT, /* output module */
- eMOD_LIB /* library module - this module provides one or many interfaces */
+ eMOD_IN = 0, /* input module */
+ eMOD_OUT = 1, /* output module */
+ eMOD_LIB = 2, /* library module */
+ eMOD_PARSER = 3 /* parser module */
} eModType_t;
@@ -117,7 +118,10 @@ typedef struct modInfo_s {
rsRetVal (*parseSelectorAct)(uchar**, void**,omodStringRequest_t**);
} om;
struct { /* data for library modules */
- } fm;
+ } lm;
+ struct { /* data for parser modules */
+ rsRetVal (*parse)(msg_t*);
+ } pm;
} mod;
void *pModHdlr; /* handler to the dynamic library holding the module */
# ifdef DEBUG
diff --git a/runtime/parser.c b/runtime/parser.c
index 89e59f87..e2ad69e4 100644
--- a/runtime/parser.c
+++ b/runtime/parser.c
@@ -39,8 +39,10 @@
#include "obj.h"
#include "datetime.h"
#include "errmsg.h"
+#include "parser.h"
#include "unicode-helper.h"
#include "dirty.h"
+#include "cfsysline.h"
/* some defines */
#define DEFUPRI (LOG_USER|LOG_NOTICE)
@@ -52,23 +54,22 @@ DEFobjCurrIf(errmsg)
DEFobjCurrIf(datetime)
/* static data */
+static int bParseHOSTNAMEandTAG; /* cache for the equally-named global param - performance enhancement */
+/* config data */
+static uchar cCCEscapeChar = '#';/* character to be used to start an escape sequence for control chars */
+static int bEscapeCCOnRcv = 1; /* escape control characters on reception: 0 - no, 1 - yes */
+static int bDropTrailingLF = 1; /* drop trailing LF's on reception? */
-/* this is a dummy class init
+/* we need to provide standard constructors and destructors, even though
+ * we only have static methods. The framework requires that.
*/
-rsRetVal parserClassInit(void)
-{
- DEFiRet;
+BEGINobjConstruct(parser) /* be sure to specify the object type also in END macro! */
+ENDobjConstruct(parser)
- /* request objects we use */
- CHKiRet(objGetObjInterface(&obj)); /* this provides the root pointer for all other queries */
- CHKiRet(objUse(glbl, CORE_COMPONENT));
- CHKiRet(objUse(errmsg, CORE_COMPONENT));
- CHKiRet(objUse(datetime, CORE_COMPONENT));
-// TODO: free components! see action.c
-finalize_it:
- RETiRet;
-}
+BEGINobjDestruct(parser) /* be sure to specify the object type also in END and CODESTART macros! */
+CODESTARTobjDestruct(parser)
+ENDobjDestruct(parser)
/***************************RFC 5425 PARSER ******************************************************/
@@ -643,7 +644,8 @@ finalize_it:
* extended to support configured parsers.
* rgerhards, 2008-10-09
*/
-rsRetVal parseMsg(msg_t *pMsg)
+static rsRetVal
+ParseMsg(msg_t *pMsg)
{
DEFiRet;
uchar *msg;
@@ -709,3 +711,57 @@ rsRetVal parseMsg(msg_t *pMsg)
finalize_it:
RETiRet;
}
+
+
+/* queryInterface function-- rgerhards, 2009-11-03
+ */
+BEGINobjQueryInterface(parser)
+CODESTARTobjQueryInterface(parser)
+ if(pIf->ifVersion != parserCURR_IF_VERSION) { /* check for current version, increment on each change */
+ ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
+ }
+
+ /* ok, we have the right interface, so let's fill it
+ * Please note that we may also do some backwards-compatibility
+ * work here (if we can support an older interface version - that,
+ * of course, also affects the "if" above).
+ */
+ pIf->ParseMsg = ParseMsg;
+finalize_it:
+ENDobjQueryInterface(parser)
+
+
+
+/* Reset config variables to default values.
+ * rgerhards, 2007-07-17
+ */
+static rsRetVal
+resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
+{
+ cCCEscapeChar = '#';
+ bEscapeCCOnRcv = 1; /* default is to escape control characters */
+ bDropTrailingLF = 1; /* default is to drop trailing LF's on reception */
+
+ return RS_RET_OK;
+}
+
+
+/* Initialize the parser class. Must be called as the very first method
+ * before anything else is called inside this class.
+ * rgerhards, 2009-11-02
+ */
+//BEGINObjClassInit(parser, 1, OBJ_IS_CORE_MODULE) /* class, version */
+BEGINAbstractObjClassInit(parser, 1, OBJ_IS_CORE_MODULE) /* class, version */
+ /* request objects we use */
+ CHKiRet(objUse(glbl, CORE_COMPONENT));
+ CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ CHKiRet(objUse(datetime, CORE_COMPONENT));
+
+ bParseHOSTNAMEandTAG = glbl.GetParseHOSTNAMEandTAG(); /* cache value, is set only during rsyslogd option processing */
+
+ CHKiRet(regCfSysLineHdlr((uchar *)"controlcharacterescapeprefix", 0, eCmdHdlrGetChar, NULL, &cCCEscapeChar, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"droptrailinglfonreception", 0, eCmdHdlrBinary, NULL, &bDropTrailingLF, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"escapecontrolcharactersonreceive", 0, eCmdHdlrBinary, NULL, &bEscapeCCOnRcv, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, NULL));
+ENDObjClassInit(parser)
+
diff --git a/runtime/parser.h b/runtime/parser.h
index cec9c083..d5d9243d 100644
--- a/runtime/parser.h
+++ b/runtime/parser.h
@@ -24,7 +24,21 @@
#ifndef INCLUDED_PARSE_H
#define INCLUDED_PARSE_H
-extern rsRetVal parserClassInit(void);
-extern rsRetVal parseMsg(msg_t*);
+/* the parser object, a dummy because we have only static methods */
+typedef struct parser_s {
+ BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
+} parser_t;
+
+/* interfaces */
+BEGINinterface(parser) /* name must also be changed in ENDinterface macro! */
+ INTERFACEObjDebugPrint(var);
+ rsRetVal (*ParseMsg)(msg_t *pMsg);
+ENDinterface(parser)
+#define parserCURR_IF_VERSION 1 /* increment whenever you change the interface above! */
+
+
+/* prototypes */
+PROTOTYPEObj(parser);
+
#endif /* #ifndef INCLUDED_PARSE_H */
diff --git a/runtime/rsyslog.c b/runtime/rsyslog.c
index 443d0f41..8c44d16a 100644
--- a/runtime/rsyslog.c
+++ b/runtime/rsyslog.c
@@ -80,6 +80,7 @@
#include "prop.h"
#include "rule.h"
#include "ruleset.h"
+#include "parser.h"
/* forward definitions */
static rsRetVal dfltErrLogger(int, uchar *errMsg);
@@ -183,6 +184,8 @@ rsrtInit(char **ppErrObj, obj_if_t *pObjIF)
CHKiRet(qqueueClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "conf";
CHKiRet(confClassInit(NULL));
+ if(ppErrObj != NULL) *ppErrObj = "parser";
+ CHKiRet(parserClassInit(NULL));
/* dummy "classes" */
if(ppErrObj != NULL) *ppErrObj = "str";
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index f059a970..ef323c7d 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -40,6 +40,17 @@
#define CONF_TAG_BUFSIZE 32
#define CONF_HOSTNAME_BUFSIZE 32
#define CONF_PROP_BUFSIZE 16 /* should be close to sizeof(ptr) or lighly above it */
+#define CONF_MIN_SIZE_FOR_COMPRESS 60 /* config param: minimum message size to try compression. The smaller
+ * the message, the less likely is any compression gain. We check for
+ * gain before we submit the message. But to do so we still need to
+ * do the (costly) compress() call. The following setting sets a size
+ * for which no call to compress() is done at all. This may result in
+ * a few more bytes being transmited but better overall performance.
+ * Note: I have not yet checked the minimum UDP packet size. It might be
+ * that we do not save anything by compressing very small messages, because
+ * UDP might need to pad ;)
+ * rgerhards, 2006-11-30
+ */
/* ############################################################# *