summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-06-01 18:51:55 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2010-06-01 18:51:55 +0200
commit527bfcea5c9ca5c8414620a022f097d4e53af784 (patch)
treef4bcee98f1f1f1d372a914a247dad86b5b36ad6e
parent59227a861821b2e0e37357c0695f6b3d9f11dd9d (diff)
downloadrsyslog-527bfcea5c9ca5c8414620a022f097d4e53af784.tar.gz
rsyslog-527bfcea5c9ca5c8414620a022f097d4e53af784.tar.xz
rsyslog-527bfcea5c9ca5c8414620a022f097d4e53af784.zip
first implementation of strgen interface
and a first built-in strgen module. Some tweaks and more default strgens are needed, but the code doesn't look too bad ;)
-rw-r--r--runtime/Makefile.am2
-rw-r--r--runtime/module-template.h43
-rw-r--r--runtime/modules.c36
-rw-r--r--runtime/modules.h6
-rw-r--r--runtime/rsyslog.c3
-rw-r--r--runtime/rsyslog.h2
-rw-r--r--runtime/strgen.c293
-rw-r--r--runtime/strgen.h60
-rw-r--r--template.c70
-rw-r--r--template.h2
-rw-r--r--tools/Makefile.am2
-rw-r--r--tools/smtradfile.c154
-rw-r--r--tools/smtradfile.h31
-rw-r--r--tools/syslogd.c4
14 files changed, 644 insertions, 64 deletions
diff --git a/runtime/Makefile.am b/runtime/Makefile.am
index 9047c83d..f7db3e35 100644
--- a/runtime/Makefile.am
+++ b/runtime/Makefile.am
@@ -21,6 +21,8 @@ librsyslog_la_SOURCES = \
conf.h \
parser.h \
parser.c \
+ strgen.h \
+ strgen.c \
msg.c \
msg.h \
linkedlist.c \
diff --git a/runtime/module-template.h b/runtime/module-template.h
index 18aad650..d05ec23c 100644
--- a/runtime/module-template.h
+++ b/runtime/module-template.h
@@ -49,6 +49,9 @@
#define DEF_PMOD_STATIC_DATA \
DEFobjCurrIf(obj) \
DEF_MOD_STATIC_DATA
+#define DEF_SMOD_STATIC_DATA \
+ DEFobjCurrIf(obj) \
+ DEF_MOD_STATIC_DATA
/* Macro to define the module type. Each module can only have a single type. If
@@ -69,6 +72,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_STRGEN MODULE_TYPE(eMOD_STRGEN)
#define MODULE_TYPE_LIB \
DEF_LMOD_STATIC_DATA \
MODULE_TYPE(eMOD_LIB)
@@ -416,6 +420,18 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())\
*pEtryPoint = GetParserName;\
}
+/* the following definition is the standard block for queryEtryPt for Strgen
+ * modules. This can be used if no specific handling (e.g. to cover version
+ * differences) is needed.
+ */
+#define CODEqueryEtryPt_STD_SMOD_QUERIES \
+ CODEqueryEtryPt_STD_MOD_QUERIES \
+ else if(!strcmp((char*) name, "strgen")) {\
+ *pEtryPoint = strgen;\
+ } else if(!strcmp((char*) name, "GetName")) {\
+ *pEtryPoint = GetStrgenName;\
+ }
+
/* 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
@@ -621,6 +637,21 @@ static rsRetVal parse(msg_t *pMsg)\
}
+/* strgen() - main entry point of parser modules
+ */
+#define BEGINstrgen \
+static rsRetVal strgen(msg_t *pMsg, uchar **ppBuf, size_t *pLenBuf) \
+{\
+ DEFiRet;
+
+#define CODESTARTstrgen \
+ assert(pMsg != NULL);
+
+#define ENDstrgen \
+ RETiRet;\
+}
+
+
/* function to specify the parser name. This is done via a single command which
* receives a ANSI string as parameter.
*/
@@ -632,5 +663,17 @@ static rsRetVal GetParserName(uchar **ppSz)\
}
+
+/* function to specify the strgen name. This is done via a single command which
+ * receives a ANSI string as parameter.
+ */
+#define STRGEN_NAME(x) \
+static rsRetVal GetStrgenName(uchar **ppSz)\
+{\
+ *ppSz = UCHAR_CONSTANT(x);\
+ return RS_RET_OK;\
+}
+
+
/* vim:set ai:
*/
diff --git a/runtime/modules.c b/runtime/modules.c
index 1af94abc..d7362753 100644
--- a/runtime/modules.c
+++ b/runtime/modules.c
@@ -58,11 +58,13 @@
#include "modules.h"
#include "errmsg.h"
#include "parser.h"
+#include "strgen.h"
/* static data */
DEFobjStaticHelpers
DEFobjCurrIf(errmsg)
DEFobjCurrIf(parser)
+DEFobjCurrIf(strgen)
/* we must ensure that only one thread at one time tries to load or unload
* modules, otherwise we may see race conditions. This first came up with
@@ -406,9 +408,10 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)(), modInfo_
{
rsRetVal localRet;
modInfo_t *pNew = NULL;
- uchar *pParserName;
+ uchar *pName;
parser_t *pParser; /* used for parser modules */
- rsRetVal (*GetParserName)(uchar**);
+ strgen_t *pStrgen; /* used for strgen modules */
+ rsRetVal (*GetName)(uchar**);
rsRetVal (*modGetType)(eModType_t *pType);
DEFiRet;
@@ -487,8 +490,8 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)(), modInfo_
CHKiRet(objUse(parser, CORE_COMPONENT));
/* here, we create a new parser object */
CHKiRet((*pNew->modQueryEtryPt)((uchar*)"parse", &pNew->mod.pm.parse));
- CHKiRet((*pNew->modQueryEtryPt)((uchar*)"GetParserName", &GetParserName));
- CHKiRet(GetParserName(&pParserName));
+ CHKiRet((*pNew->modQueryEtryPt)((uchar*)"GetParserName", &GetName));
+ CHKiRet(GetName(&pName));
CHKiRet(parser.Construct(&pParser));
/* check some features */
@@ -501,10 +504,26 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)(), modInfo_
CHKiRet(parser.SetDoPRIParsing(pParser, TRUE));
}
- CHKiRet(parser.SetName(pParser, pParserName));
+ CHKiRet(parser.SetName(pParser, pName));
CHKiRet(parser.SetModPtr(pParser, pNew));
CHKiRet(parser.ConstructFinalize(pParser));
break;
+ case eMOD_STRGEN:
+ /* first, we need to obtain the strgen object. We could not do that during
+ * init as that would have caused class bootstrap issues which are not
+ * absolutely necessary. Note that we can call objUse() multiple times, it
+ * handles that.
+ */
+ CHKiRet(objUse(strgen, CORE_COMPONENT));
+ /* here, we create a new parser object */
+ CHKiRet((*pNew->modQueryEtryPt)((uchar*)"strgen", &pNew->mod.sm.strgen));
+ CHKiRet((*pNew->modQueryEtryPt)((uchar*)"GetName", &GetName));
+ CHKiRet(GetName(&pName));
+ CHKiRet(strgen.Construct(&pStrgen));
+ CHKiRet(strgen.SetName(pStrgen, pName));
+ CHKiRet(strgen.SetModPtr(pStrgen, pNew));
+ CHKiRet(strgen.ConstructFinalize(pStrgen));
+ break;
}
pNew->pszName = (uchar*) strdup((char*)name); /* we do not care if strdup() fails, we can accept that */
@@ -554,6 +573,9 @@ static void modPrintList(void)
case eMOD_PARSER:
dbgprintf("parser");
break;
+ case eMOD_STRGEN:
+ dbgprintf("strgen");
+ break;
}
dbgprintf(" module.\n");
dbgprintf("Entry points:\n");
@@ -586,6 +608,10 @@ static void modPrintList(void)
dbgprintf("Parser Module Entry Points\n");
dbgprintf("\tparse: 0x%lx\n", (unsigned long) pMod->mod.pm.parse);
break;
+ case eMOD_STRGEN:
+ dbgprintf("Strgen Module Entry Points\n");
+ dbgprintf("\tstrgen: 0x%lx\n", (unsigned long) pMod->mod.sm.strgen);
+ break;
}
dbgprintf("\n");
pMod = GetNxt(pMod); /* done, go next */
diff --git a/runtime/modules.h b/runtime/modules.h
index 62f86ded..4ba6411e 100644
--- a/runtime/modules.h
+++ b/runtime/modules.h
@@ -54,7 +54,8 @@ typedef enum eModType_ {
eMOD_IN = 0, /* input module */
eMOD_OUT = 1, /* output module */
eMOD_LIB = 2, /* library module */
- eMOD_PARSER = 3 /* parser module */
+ eMOD_PARSER = 3,/* parser module */
+ eMOD_STRGEN = 4 /* strgen module */
} eModType_t;
@@ -122,6 +123,9 @@ struct modInfo_s {
struct { /* data for parser modules */
rsRetVal (*parse)(msg_t*);
} pm;
+ struct { /* data for strgen modules */
+ rsRetVal (*strgen)(msg_t*, uchar* pBuf);
+ } sm;
} mod;
void *pModHdlr; /* handler to the dynamic library holding the module */
# ifdef DEBUG
diff --git a/runtime/rsyslog.c b/runtime/rsyslog.c
index c321484d..a9794840 100644
--- a/runtime/rsyslog.c
+++ b/runtime/rsyslog.c
@@ -81,6 +81,7 @@
#include "rule.h"
#include "ruleset.h"
#include "parser.h"
+#include "strgen.h"
#include "atomic.h"
/* forward definitions */
@@ -185,6 +186,8 @@ rsrtInit(char **ppErrObj, obj_if_t *pObjIF)
CHKiRet(confClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "parser";
CHKiRet(parserClassInit(NULL));
+ if(ppErrObj != NULL) *ppErrObj = "strgen";
+ CHKiRet(strgenClassInit(NULL));
/* dummy "classes" */
if(ppErrObj != NULL) *ppErrObj = "str";
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index 0b4fbfed..0e5b1ad4 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -133,6 +133,8 @@ typedef struct wtp_s wtp_t;
typedef struct modInfo_s modInfo_t;
typedef struct parser_s parser_t;
typedef struct parserList_s parserList_t;
+typedef struct strgen_s strgen_t;
+typedef struct strgenList_s strgenList_t;
typedef rsRetVal (*prsf_t)(struct vmstk_s*, int); /* pointer to a RainerScript function */
typedef uint64 qDeqID; /* queue Dequeue order ID. 32 bits is considered dangerously few */
diff --git a/runtime/strgen.c b/runtime/strgen.c
new file mode 100644
index 00000000..b8270be9
--- /dev/null
+++ b/runtime/strgen.c
@@ -0,0 +1,293 @@
+/* strgen.c
+ * Module to handle string generators. These are C modules that receive
+ * the message object and return a custom-built string. The primary purpose
+ * for their existance is performance -- they do the same as template strings, but
+ * potentially faster (if well implmented).
+ *
+ * Module begun 2010-06-01 by Rainer Gerhards
+ *
+ * Copyright 2010 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of the rsyslog runtime library.
+ *
+ * The rsyslog runtime library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The rsyslog runtime library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
+ */
+#include "config.h"
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "rsyslog.h"
+#include "msg.h"
+#include "obj.h"
+#include "errmsg.h"
+#include "strgen.h"
+#include "ruleset.h"
+#include "unicode-helper.h"
+#include "cfsysline.h"
+
+/* definitions for objects we access */
+DEFobjStaticHelpers
+DEFobjCurrIf(glbl)
+DEFobjCurrIf(errmsg)
+DEFobjCurrIf(ruleset)
+
+/* static data */
+
+/* config data */
+
+/* This is the list of all strgens known to us.
+ * This is also used to unload all modules on shutdown.
+ */
+strgenList_t *pStrgenLstRoot = NULL;
+
+
+/* intialize (but NOT allocate) a strgen list. Primarily meant as a hook
+ * which can be used to extend the list in the future. So far, just sets
+ * it to NULL.
+ */
+static rsRetVal
+InitStrgenList(strgenList_t **pListRoot)
+{
+ *pListRoot = NULL;
+ return RS_RET_OK;
+}
+
+
+/* destruct a strgen list. The list elements are destroyed, but the strgen objects
+ * themselves are not modified. (That is done at a late stage during rsyslogd
+ * shutdown and need not be considered here.)
+ */
+static rsRetVal
+DestructStrgenList(strgenList_t **ppListRoot)
+{
+ strgenList_t *pStrgenLst;
+ strgenList_t *pStrgenLstDel;
+
+ pStrgenLst = *ppListRoot;
+ while(pStrgenLst != NULL) {
+ pStrgenLstDel = pStrgenLst;
+ pStrgenLst = pStrgenLst->pNext;
+ free(pStrgenLstDel);
+ }
+ *ppListRoot = NULL;
+ return RS_RET_OK;
+}
+
+
+/* Add a strgen to the list. We use a VERY simple and ineffcient algorithm,
+ * but it is employed only for a few milliseconds during config processing. So
+ * I prefer to keep it very simple and with simple data structures. Unfortunately,
+ * we need to preserve the order, but I don't like to add a tail pointer as that
+ * would require a container object. So I do the extra work to skip to the tail
+ * when adding elements...
+ */
+static rsRetVal
+AddStrgenToList(strgenList_t **ppListRoot, strgen_t *pStrgen)
+{
+ strgenList_t *pThis;
+ strgenList_t *pTail;
+ DEFiRet;
+
+ CHKmalloc(pThis = MALLOC(sizeof(strgenList_t)));
+ pThis->pStrgen = pStrgen;
+ pThis->pNext = NULL;
+
+ if(*ppListRoot == NULL) {
+ pThis->pNext = *ppListRoot;
+ *ppListRoot = pThis;
+ } else {
+ /* find tail first */
+ for(pTail = *ppListRoot ; pTail->pNext != NULL ; pTail = pTail->pNext)
+ /* just search, do nothing else */;
+ /* add at tail */
+ pTail->pNext = pThis;
+ }
+
+finalize_it:
+ RETiRet;
+}
+
+
+/* find a strgen based on the provided name */
+static rsRetVal
+FindStrgen(strgen_t **ppStrgen, uchar *pName)
+{
+ strgenList_t *pThis;
+ DEFiRet;
+
+ for(pThis = pStrgenLstRoot ; pThis != NULL ; pThis = pThis->pNext) {
+ if(ustrcmp(pThis->pStrgen->pName, pName) == 0) {
+ *ppStrgen = pThis->pStrgen;
+ FINALIZE; /* found it, iRet still eq. OK! */
+ }
+ }
+
+ iRet = RS_RET_PARSER_NOT_FOUND;
+
+finalize_it:
+ RETiRet;
+}
+
+
+/* --- END helper functions for strgen list handling --- */
+
+
+BEGINobjConstruct(strgen) /* be sure to specify the object type also in END macro! */
+ENDobjConstruct(strgen)
+
+/* ConstructionFinalizer. The most important chore is to add the strgen object
+ * to our global list of available strgens.
+ * rgerhards, 2009-11-03
+ */
+rsRetVal strgenConstructFinalize(strgen_t *pThis)
+{
+ DEFiRet;
+
+ ISOBJ_TYPE_assert(pThis, strgen);
+ CHKiRet(AddStrgenToList(&pStrgenLstRoot, pThis));
+ DBGPRINTF("Strgen '%s' added to list of available strgens.\n", pThis->pName);
+
+finalize_it:
+ RETiRet;
+}
+
+BEGINobjDestruct(strgen) /* be sure to specify the object type also in END and CODESTART macros! */
+CODESTARTobjDestruct(strgen)
+ dbgprintf("destructing strgen '%s'\n", pThis->pName);
+ free(pThis->pName);
+ENDobjDestruct(strgen)
+
+/* set the strgen name - string is copied over, call can continue to use it,
+ * but must free it if desired.
+ */
+static rsRetVal
+SetName(strgen_t *pThis, uchar *name)
+{
+ DEFiRet;
+
+ ISOBJ_TYPE_assert(pThis, strgen);
+ assert(name != NULL);
+
+ if(pThis->pName != NULL) {
+ free(pThis->pName);
+ pThis->pName = NULL;
+ }
+
+ CHKmalloc(pThis->pName = ustrdup(name));
+
+finalize_it:
+ RETiRet;
+}
+
+
+/* set a pointer to "our" module. Note that no module
+ * pointer must already be set.
+ */
+static rsRetVal
+SetModPtr(strgen_t *pThis, modInfo_t *pMod)
+{
+ ISOBJ_TYPE_assert(pThis, strgen);
+ assert(pMod != NULL);
+ assert(pThis->pModule == NULL);
+ pThis->pModule = pMod;
+ return RS_RET_OK;
+}
+
+
+/* queryInterface function-- rgerhards, 2009-11-03
+ */
+BEGINobjQueryInterface(strgen)
+CODESTARTobjQueryInterface(strgen)
+ if(pIf->ifVersion != strgenCURR_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->Construct = strgenConstruct;
+ pIf->ConstructFinalize = strgenConstructFinalize;
+ pIf->Destruct = strgenDestruct;
+ pIf->SetName = SetName;
+ pIf->SetModPtr = SetModPtr;
+ pIf->InitStrgenList = InitStrgenList;
+ pIf->DestructStrgenList = DestructStrgenList;
+ pIf->AddStrgenToList = AddStrgenToList;
+ pIf->FindStrgen = FindStrgen;
+finalize_it:
+ENDobjQueryInterface(strgen)
+
+
+
+/* Reset config variables to default values.
+ * rgerhards, 2007-07-17
+ */
+static rsRetVal
+resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
+{
+ return RS_RET_OK;
+}
+
+/* This destroys the master strgenlist and all of its strgen entries. MUST only be
+ * done when the module is shut down. Strgen modules are NOT unloaded, rsyslog
+ * does that at a later stage for all dynamically loaded modules.
+ */
+static void
+destroyMasterStrgenList(void)
+{
+ strgenList_t *pStrgenLst;
+ strgenList_t *pStrgenLstDel;
+
+ pStrgenLst = pStrgenLstRoot;
+ while(pStrgenLst != NULL) {
+ strgenDestruct(&pStrgenLst->pStrgen);
+ pStrgenLstDel = pStrgenLst;
+ pStrgenLst = pStrgenLst->pNext;
+ free(pStrgenLstDel);
+ }
+}
+
+/* Exit our class.
+ * rgerhards, 2009-11-04
+ */
+BEGINObjClassExit(strgen, OBJ_IS_CORE_MODULE) /* class, version */
+ destroyMasterStrgenList();
+ objRelease(glbl, CORE_COMPONENT);
+ objRelease(errmsg, CORE_COMPONENT);
+ objRelease(ruleset, CORE_COMPONENT);
+ENDObjClassExit(strgen)
+
+
+/* Initialize the strgen class. Must be called as the very first method
+ * before anything else is called inside this class.
+ * rgerhards, 2009-11-02
+ */
+BEGINObjClassInit(strgen, 1, OBJ_IS_CORE_MODULE) /* class, version */
+ /* request objects we use */
+ CHKiRet(objUse(glbl, CORE_COMPONENT));
+ CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ CHKiRet(objUse(ruleset, CORE_COMPONENT));
+
+ //CHKiRet(regCfSysLineHdlr((uchar *)"escapecontrolcharactertab", 0, eCmdHdlrBinary, NULL, &bEscapeTab, NULL));
+ //CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, NULL));
+
+ InitStrgenList(&pStrgenLstRoot);
+ENDObjClassInit(strgen)
+
diff --git a/runtime/strgen.h b/runtime/strgen.h
new file mode 100644
index 00000000..3819dccd
--- /dev/null
+++ b/runtime/strgen.h
@@ -0,0 +1,60 @@
+/* header for strgen.c
+ *
+ * Copyright 2010 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of the rsyslog runtime library.
+ *
+ * The rsyslog runtime library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The rsyslog runtime library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
+ */
+#ifndef INCLUDED_STRGEN_H
+#define INCLUDED_STRGEN_H
+
+
+/* we create a small helper object, a list of strgens, that we can use to
+ * build a chain of them whereever this is needed.
+ */
+struct strgenList_s {
+ strgen_t *pStrgen;
+ strgenList_t *pNext;
+};
+
+
+/* the strgen object, a dummy because we have only static methods */
+struct strgen_s {
+ BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
+ uchar *pName; /* name of this strgen */
+ modInfo_t *pModule; /* pointer to strgen's module */
+};
+
+/* interfaces */
+BEGINinterface(strgen) /* name must also be changed in ENDinterface macro! */
+ rsRetVal (*Construct)(strgen_t **ppThis);
+ rsRetVal (*ConstructFinalize)(strgen_t *pThis);
+ rsRetVal (*Destruct)(strgen_t **ppThis);
+ rsRetVal (*SetName)(strgen_t *pThis, uchar *name);
+ rsRetVal (*SetModPtr)(strgen_t *pThis, modInfo_t *pMod);
+ rsRetVal (*FindStrgen)(strgen_t **ppThis, uchar*name);
+ rsRetVal (*InitStrgenList)(strgenList_t **pListRoot);
+ rsRetVal (*DestructStrgenList)(strgenList_t **pListRoot);
+ rsRetVal (*AddStrgenToList)(strgenList_t **pListRoot, strgen_t *pStrgen);
+ENDinterface(strgen)
+#define strgenCURR_IF_VERSION 1 /* increment whenever you change the interface above! */
+
+
+/* prototypes */
+PROTOTYPEObj(strgen);
+
+#endif /* #ifndef INCLUDED_STRGEN_H */
diff --git a/template.c b/template.c
index 81776c62..16a5fb52 100644
--- a/template.c
+++ b/template.c
@@ -36,12 +36,14 @@
#include "dirty.h"
#include "obj.h"
#include "errmsg.h"
+#include "strgen.h"
#include "unicode-helper.h"
/* static data */
DEFobjCurrIf(obj)
DEFobjCurrIf(errmsg)
DEFobjCurrIf(regexp)
+DEFobjCurrIf(strgen)
static int bFirstRegexpErrmsg = 1; /**< did we already do a "can't load regexp" error message? */
static struct template *tplRoot = NULL; /* the root of the template list */
@@ -52,7 +54,8 @@ static struct template *tplLastStatic = NULL; /* last static element of the temp
/* helper to tplToString, extends buffer */
#define ALLOC_INC 128
-static inline rsRetVal ExtendBuf(uchar **pBuf, size_t *pLenBuf, size_t iMinSize)
+rsRetVal
+ExtendBuf(uchar **pBuf, size_t *pLenBuf, size_t iMinSize)
{
uchar *pNewBuf;
size_t iNewSize;
@@ -78,7 +81,6 @@ finalize_it:
* offers big performance improvements.
* rewritten 2009-06-19 rgerhards
*/
-extern char *getTimeReported(msg_t *pM, enum tplFormatTypes eFmt);
rsRetVal tplToString(struct template *pTpl, msg_t *pMsg, uchar **ppBuf, size_t *pLenBuf)
{
DEFiRet;
@@ -93,59 +95,8 @@ rsRetVal tplToString(struct template *pTpl, msg_t *pMsg, uchar **ppBuf, size_t *
assert(ppBuf != NULL);
assert(pLenBuf != NULL);
- if(pTpl->tplMod != NULL) {
- dbgprintf("XXX: template module, NULL operation, *ppBuf = %p\n", *ppBuf);
- iBuf = 0;
- dbgprintf("TIMESTAMP\n");
- /* TIMESTAMP + ' ' */
- dbgprintf("getTimeReported\n");
- pVal = (uchar*) getTimeReported(pMsg, tplFmtDefault);
- dbgprintf("obtain iLenVal ptr %p\n", pVal);
- iLenVal = ustrlen(pVal);
- dbgprintf("TIMESTAMP pVal='%p', iLenVal=%d\n", pVal, iLenVal);
- if(iBuf + iLenVal + 1 >= *pLenBuf) /* we reserve one char for the final \0! */
- CHKiRet(ExtendBuf(ppBuf, pLenBuf, iBuf + iLenVal + 1));
- memcpy(*ppBuf + iBuf, pVal, iLenVal);
- iBuf += iLenVal;
- *(*ppBuf + iBuf++) = ' ';
-
- dbgprintf("HOSTNAME\n");
- /* HOSTNAME + ' ' */
- pVal = (uchar*) getHOSTNAME(pMsg);
- iLenVal = getHOSTNAMELen(pMsg);
- if(iBuf + iLenVal + 1 >= *pLenBuf) /* we reserve one char for the ' '! */
- CHKiRet(ExtendBuf(ppBuf, pLenBuf, iBuf + iLenVal + 1));
- memcpy(*ppBuf + iBuf, pVal, iLenVal);
- iBuf += iLenVal;
- *(*ppBuf + iBuf++) = ' ';
-
- dbgprintf("TAG\n");
- /* syslogtag */
- /* max size for TAG assumed 200 * TODO: check! */
- if(iBuf + 200 >= *pLenBuf)
- CHKiRet(ExtendBuf(ppBuf, pLenBuf, iBuf + 200));
- getTAG(pMsg, &pVal, &iLenVal);
- memcpy(*ppBuf + iBuf, pVal, iLenVal);
- iBuf += iLenVal;
-
- dbgprintf("MSG\n");
- /* MSG, plus leading space if necessary */
- pVal = getMSG(pMsg);
- iLenVal = getMSGLen(pMsg);
- if(iBuf + iLenVal + 1 >= *pLenBuf) /* we reserve one char for the leading SP*/
- CHKiRet(ExtendBuf(ppBuf, pLenBuf, iBuf + iLenVal + 1));
- if(pVal[0] != ' ')
- *(*ppBuf + iBuf++) = ' ';
- memcpy(*ppBuf + iBuf, pVal, iLenVal);
- iBuf += iLenVal;
-
- dbgprintf("Trailer\n");
- /* end sequence */
- iLenVal = 2;
- if(iBuf + iLenVal >= *pLenBuf) /* we reserve one char for the final \0! */
- CHKiRet(ExtendBuf(ppBuf, pLenBuf, iBuf + iLenVal + 1));
- *(*ppBuf + iBuf++) = '\n';
- *(*ppBuf + iBuf) = '\0';
+ if(pTpl->pStrgen != NULL) {
+ CHKiRet(pTpl->pStrgen(pMsg, ppBuf, pLenBuf));
FINALIZE;
}
@@ -897,6 +848,7 @@ tplAddTplMod(struct template *pTpl, uchar** ppRestOfConfLine)
{
uchar *pSrc, *pDst;
uchar szMod[2048];
+ strgen_t *pStrgen;
DEFiRet;
pSrc = *ppRestOfConfLine;
@@ -906,8 +858,11 @@ tplAddTplMod(struct template *pTpl, uchar** ppRestOfConfLine)
}
*pDst = '\0';
*ppRestOfConfLine = pSrc;
- pTpl->tplMod = ustrdup(szMod);
- dbgprintf("template bound to template module '%s'\n", szMod);
+ CHKiRet(strgen.FindStrgen(&pStrgen, szMod));
+ pTpl->pStrgen = pStrgen->pModule->mod.sm.strgen;
+ dbgprintf("template bound to strgen '%s'\n", szMod);
+
+finalize_it:
RETiRet;
}
@@ -1286,6 +1241,7 @@ rsRetVal templateInit()
DEFiRet;
CHKiRet(objGetObjInterface(&obj));
CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ CHKiRet(objUse(strgen, CORE_COMPONENT));
finalize_it:
RETiRet;
diff --git a/template.h b/template.h
index 9c438159..2a933e8c 100644
--- a/template.h
+++ b/template.h
@@ -32,7 +32,7 @@ struct template {
struct template *pNext;
char *pszName;
int iLenName;
- uchar *tplMod; /* name of template module to use * TODO: replace by ptr to entry point! */
+ rsRetVal (*pStrgen)(msg_t*, uchar**, size_t *); /* name of strgen to use (bound if non-NULL!) */
int tpenElements; /* number of elements in templateEntry list */
struct templateEntry *pEntryRoot;
struct templateEntry *pEntryLast;
diff --git a/tools/Makefile.am b/tools/Makefile.am
index f0a8df5f..d56c46c6 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -21,6 +21,8 @@ rsyslogd_SOURCES = \
pmrfc5424.h \
pmrfc3164.c \
pmrfc3164.h \
+ smtradfile.c \
+ smtradfile.h \
iminternal.c \
iminternal.h \
pidfile.c \
diff --git a/tools/smtradfile.c b/tools/smtradfile.c
new file mode 100644
index 00000000..dcbc1d47
--- /dev/null
+++ b/tools/smtradfile.c
@@ -0,0 +1,154 @@
+/* smtradfile.c
+ * This is a strgen module for the traditional file format.
+ *
+ * NOTE: read comments in module-template.h to understand how this file
+ * works!
+ *
+ * File begun on 2010-06-01 by RGerhards
+ *
+ * Copyright 2010 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of rsyslog.
+ *
+ * Rsyslog is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Rsyslog is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ */
+#include "config.h"
+#include "rsyslog.h"
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+#include "syslogd.h"
+#include "conf.h"
+#include "syslogd-types.h"
+#include "template.h"
+#include "msg.h"
+#include "module-template.h"
+#include "glbl.h"
+#include "errmsg.h"
+#include "parser.h"
+#include "datetime.h"
+#include "unicode-helper.h"
+
+MODULE_TYPE_STRGEN
+STRGEN_NAME("RSYSLOG_TraditionalFileFormat")
+
+/* internal structures
+ */
+DEF_SMOD_STATIC_DATA
+DEFobjCurrIf(errmsg)
+DEFobjCurrIf(glbl)
+DEFobjCurrIf(parser)
+DEFobjCurrIf(datetime)
+
+
+/* config data */
+
+
+#warning TODO: ExtendBuf via object interface!
+extern rsRetVal ExtendBuf(uchar **pBuf, size_t *pLenBuf, size_t iMinSize);
+extern char *getTimeReported(msg_t *pM, enum tplFormatTypes eFmt);
+
+BEGINstrgen
+ int iBuf;
+ uchar *pVal;
+ size_t iLenVal;
+CODESTARTstrgen
+ dbgprintf("XXX: strgen module, *ppBuf = %p\n", *ppBuf);
+ iBuf = 0;
+ dbgprintf("TIMESTAMP\n");
+ /* TIMESTAMP + ' ' */
+ dbgprintf("getTimeReported\n");
+ pVal = (uchar*) getTimeReported(pMsg, tplFmtDefault);
+ dbgprintf("obtain iLenVal ptr %p\n", pVal);
+ iLenVal = ustrlen(pVal);
+ dbgprintf("TIMESTAMP pVal='%p', iLenVal=%d\n", pVal, iLenVal);
+ if(iBuf + iLenVal + 1 >= *pLenBuf) /* we reserve one char for the final \0! */
+ CHKiRet(ExtendBuf(ppBuf, pLenBuf, iBuf + iLenVal + 1));
+ memcpy(*ppBuf + iBuf, pVal, iLenVal);
+ iBuf += iLenVal;
+ *(*ppBuf + iBuf++) = ' ';
+
+ dbgprintf("HOSTNAME\n");
+ /* HOSTNAME + ' ' */
+ pVal = (uchar*) getHOSTNAME(pMsg);
+ iLenVal = getHOSTNAMELen(pMsg);
+ if(iBuf + iLenVal + 1 >= *pLenBuf) /* we reserve one char for the ' '! */
+ CHKiRet(ExtendBuf(ppBuf, pLenBuf, iBuf + iLenVal + 1));
+ memcpy(*ppBuf + iBuf, pVal, iLenVal);
+ iBuf += iLenVal;
+ *(*ppBuf + iBuf++) = ' ';
+
+ dbgprintf("TAG\n");
+ /* syslogtag */
+ /* max size for TAG assumed 200 * TODO: check! */
+ if(iBuf + 200 >= *pLenBuf)
+ CHKiRet(ExtendBuf(ppBuf, pLenBuf, iBuf + 200));
+ getTAG(pMsg, &pVal, &iLenVal);
+ memcpy(*ppBuf + iBuf, pVal, iLenVal);
+ iBuf += iLenVal;
+
+ dbgprintf("MSG\n");
+ /* MSG, plus leading space if necessary */
+ pVal = getMSG(pMsg);
+ iLenVal = getMSGLen(pMsg);
+ if(iBuf + iLenVal + 1 >= *pLenBuf) /* we reserve one char for the leading SP*/
+ CHKiRet(ExtendBuf(ppBuf, pLenBuf, iBuf + iLenVal + 1));
+ if(pVal[0] != ' ')
+ *(*ppBuf + iBuf++) = ' ';
+ memcpy(*ppBuf + iBuf, pVal, iLenVal);
+ iBuf += iLenVal;
+
+ dbgprintf("Trailer\n");
+ /* end sequence */
+ iLenVal = 2;
+ if(iBuf + iLenVal >= *pLenBuf) /* we reserve one char for the final \0! */
+ CHKiRet(ExtendBuf(ppBuf, pLenBuf, iBuf + iLenVal + 1));
+ *(*ppBuf + iBuf++) = '\n';
+ *(*ppBuf + iBuf) = '\0';
+
+finalize_it:
+ENDstrgen
+
+
+BEGINmodExit
+CODESTARTmodExit
+ /* release what we no longer need */
+ objRelease(errmsg, CORE_COMPONENT);
+ objRelease(glbl, CORE_COMPONENT);
+ objRelease(parser, CORE_COMPONENT);
+ objRelease(datetime, CORE_COMPONENT);
+ENDmodExit
+
+
+BEGINqueryEtryPt
+CODESTARTqueryEtryPt
+CODEqueryEtryPt_STD_SMOD_QUERIES
+ENDqueryEtryPt
+
+
+BEGINmodInit(smtradfile)
+CODESTARTmodInit
+ *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
+CODEmodInit_QueryRegCFSLineHdlr
+ CHKiRet(objUse(glbl, CORE_COMPONENT));
+ CHKiRet(objUse(errmsg, CORE_COMPONENT));
+ CHKiRet(objUse(parser, CORE_COMPONENT));
+ CHKiRet(objUse(datetime, CORE_COMPONENT));
+
+ dbgprintf("traditional file format strgen init called, compiled with version %s\n", VERSION);
+ dbgprintf("GetStrgenName addr %p\n", GetStrgenName);
+ENDmodInit
diff --git a/tools/smtradfile.h b/tools/smtradfile.h
new file mode 100644
index 00000000..afc737ed
--- /dev/null
+++ b/tools/smtradfile.h
@@ -0,0 +1,31 @@
+/* smtradfile.h
+ * These are the definitions for the traditional file format stringen module.
+ *
+ * File begun on 2010-06-01 by RGerhards
+ *
+ * Copyright 2010 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of rsyslog.
+ *
+ * Rsyslog is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Rsyslog is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ */
+#ifndef SMTRADFILE_H_INCLUDED
+#define SMTRADFILE_H_INCLUDED 1
+
+/* prototypes */
+rsRetVal modInitsmtradfile(int iIFVersRequested __attribute__((unused)), int *ipIFVersProvided, rsRetVal (**pQueryEtryPt)(), rsRetVal (*pHostQueryEtryPt)(uchar*, rsRetVal (**)()), modInfo_t*);
+
+#endif /* #ifndef SMTRADFILE_H_INCLUDED */
diff --git a/tools/syslogd.c b/tools/syslogd.c
index d5df8b91..49f7ed52 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -116,6 +116,7 @@
#include "omdiscard.h"
#include "pmrfc5424.h"
#include "pmrfc3164.h"
+#include "smtradfile.h"
#include "threads.h"
#include "wti.h"
#include "queue.h"
@@ -2000,6 +2001,9 @@ static rsRetVal loadBuildInModules(void)
CHKiRet(parser.AddDfltParser(UCHAR_CONSTANT("rsyslog.rfc5424")));
CHKiRet(parser.AddDfltParser(UCHAR_CONSTANT("rsyslog.rfc3164")));
+ /* load build-in strgen modules */
+ CHKiRet(module.doModInit(modInitsmtradfile, UCHAR_CONSTANT("builtin-smtradfile"), NULL));
+
/* ok, initialization of the command handler probably does not 100% belong right in
* this space here. However, with the current design, this is actually quite a good
* place to put it. We might decide to shuffle it around later, but for the time