milestone: templates are now in config object

This commit is contained in:
Rainer Gerhards 2011-04-19 09:43:36 +02:00
parent bbe1f2688c
commit f72bde2f70
12 changed files with 244 additions and 46 deletions

View File

@ -1647,7 +1647,7 @@ addAction(action_t **ppAction, modInfo_t *pMod, void *pModData, omodStringReques
/* Ok, we got everything, so it now is time to look up the template
* (Hint: templates MUST be defined before they are used!)
*/
if((pAction->ppTpl[i] = tplFind((char*)pTplName, strlen((char*)pTplName))) == NULL) {
if((pAction->ppTpl[i] = tplFind(ourConf, (char*)pTplName, strlen((char*)pTplName))) == NULL) {
snprintf(errMsg, sizeof(errMsg) / sizeof(char),
" Could not find template '%s' - action disabled\n",
pTplName);

View File

@ -48,6 +48,7 @@
#include "module-template.h"
#include "debug.h"
#include "errmsg.h"
#include "conf.h"
MODULE_TYPE_OUTPUT
MODULE_TYPE_NOKEEP

View File

@ -20,6 +20,8 @@ librsyslog_la_SOURCES = \
unlimited_select.h \
conf.c \
conf.h \
rsconf.c \
rsconf.h \
parser.h \
parser.c \
strgen.h \

View File

@ -325,7 +325,7 @@ doNameLine(uchar **pp, void* pVal)
switch(eDir) {
case DIR_TEMPLATE:
tplAddLine(szName, &p);
tplAddLine(ourConf, szName, &p);
break;
case DIR_OUTCHANNEL:
ochAddLine(szName, &p);

112
runtime/rsconf.c Normal file
View File

@ -0,0 +1,112 @@
/* rsconf.c - the rsyslog configuration system.
*
* Module begun 2011-04-19 by Rainer Gerhards
*
* Copyright 2007, 2008 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 <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "rsyslog.h"
#include "obj.h"
#include "srUtils.h"
#include "rsconf.h"
/* static data */
DEFobjStaticHelpers
/* Standard-Constructor
*/
BEGINobjConstruct(rsconf) /* be sure to specify the object type also in END macro! */
ENDobjConstruct(rsconf)
/* ConstructionFinalizer
* rgerhards, 2008-01-09
*/
rsRetVal rsconfConstructFinalize(rsconf_t __attribute__((unused)) *pThis)
{
DEFiRet;
ISOBJ_TYPE_assert(pThis, rsconf);
RETiRet;
}
/* destructor for the rsconf object */
BEGINobjDestruct(rsconf) /* be sure to specify the object type also in END and CODESTART macros! */
CODESTARTobjDestruct(rsconf)
pThis->templates.root = NULL;
pThis->templates.last = NULL;
pThis->templates.lastStatic = NULL;
ENDobjDestruct(rsconf)
/* DebugPrint support for the rsconf object */
BEGINobjDebugPrint(rsconf) /* be sure to specify the object type also in END and CODESTART macros! */
CODESTARTobjDebugPrint(rsconf)
ENDobjDebugPrint(rsconf)
/* queryInterface function
*/
BEGINobjQueryInterface(rsconf)
CODESTARTobjQueryInterface(rsconf)
if(pIf->ifVersion != rsconfCURR_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 = rsconfConstruct;
pIf->ConstructFinalize = rsconfConstructFinalize;
pIf->Destruct = rsconfDestruct;
pIf->DebugPrint = rsconfDebugPrint;
finalize_it:
ENDobjQueryInterface(rsconf)
/* Initialize the rsconf class. Must be called as the very first method
* before anything else is called inside this class.
*/
BEGINObjClassInit(rsconf, 1, OBJ_IS_CORE_MODULE) /* class, version */
/* request objects we use */
/* now set our own handlers */
OBJSetMethodHandler(objMethod_DEBUGPRINT, rsconfDebugPrint);
OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, rsconfConstructFinalize);
ENDObjClassInit(rsconf)
/* De-initialize the rsconf class.
*/
BEGINObjClassExit(rsconf, OBJ_IS_CORE_MODULE) /* class, version */
ENDObjClassExit(rsconf)
/* vi:set ai:
*/

59
runtime/rsconf.h Normal file
View File

@ -0,0 +1,59 @@
/* The rsconf object. It models a complete rsyslog configuration.
*
* Copyright 2011 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.
*/
#ifndef INCLUDED_RSCONF_H
#define INCLUDED_RSCONF_H
/* --- configuration objects (the plan is to have ALL upper layers in this file) --- */
/* the following structure is a container for all known templates
* inside a specific configuration. -- rgerhards 2011-04-19
*/
struct templates_s {
struct template *root; /* the root of the template list */
struct template *last; /* points to the last element of the template list */
struct template *lastStatic; /* last static element of the template list */
};
/* --- end configuration objects --- */
/* the rsconf object */
struct rsconf_s {
BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
templates_t templates;
};
/* interfaces */
BEGINinterface(rsconf) /* name must also be changed in ENDinterface macro! */
INTERFACEObjDebugPrint(rsconf);
rsRetVal (*Construct)(rsconf_t **ppThis);
rsRetVal (*ConstructFinalize)(rsconf_t __attribute__((unused)) *pThis);
rsRetVal (*Destruct)(rsconf_t **ppThis);
ENDinterface(rsconf)
#define rsconfCURR_IF_VERSION 1 /* increment whenever you change the interface above! */
/* prototypes */
PROTOTYPEObj(rsconf);
#endif /* #ifndef INCLUDED_RSCONF_H */

View File

@ -75,6 +75,7 @@
#include "datetime.h"
#include "queue.h"
#include "conf.h"
#include "rsconf.h"
#include "glbl.h"
#include "errmsg.h"
#include "prop.h"
@ -209,6 +210,8 @@ rsrtInit(char **ppErrObj, obj_if_t *pObjIF)
CHKiRet(parserClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "strgen";
CHKiRet(strgenClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "rsconf";
CHKiRet(rsconfClassInit(NULL));
/* dummy "classes" */
if(ppErrObj != NULL) *ppErrObj = "str";

View File

@ -486,6 +486,11 @@ rsRetVal rsrtSetErrLogger(rsRetVal (*errLogger)(int, uchar*));
*/
#define EMPTY_STRUCT
/* TODO: remove this -- this is only for transition of the config system */
extern rsconf_t *ourConf; /* defined by syslogd.c, a hack for functions that do not
yet receive a copy, so that we can incrementially
compile and change... -- rgerhars, 2011-04-19 */
#endif /* multi-include protection */
/* vim:set ai:
*/

View File

@ -80,6 +80,8 @@ typedef struct strgen_s strgen_t;
typedef struct strgenList_s strgenList_t;
typedef struct statsobj_s statsobj_t;
typedef struct nsd_epworkset_s nsd_epworkset_t;
typedef struct templates_s templates_t;
typedef struct rsconf_s rsconf_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 */

View File

@ -37,6 +37,7 @@
#include "obj.h"
#include "errmsg.h"
#include "strgen.h"
#include "rsconf.h"
#include "unicode-helper.h"
/* static data */
@ -49,10 +50,12 @@ DEFobjCurrIf(regexp)
static int bFirstRegexpErrmsg = 1; /**< did we already do a "can't load regexp" error message? */
#endif
static struct template *tplRoot = NULL; /* the root of the template list */
static struct template *tplLast = NULL; /* points to the last element of the template list */
static struct template *tplLastStatic = NULL; /* last static element of the template list */
#if 0
static struct template *conf->templates.root = NULL; /* the root of the template list */
static struct template *tplLast = NULL;
static struct template *conf->templates.lastStatic = NULL;
#endif
/* helper to tplToString and strgen's, extends buffer */
@ -357,7 +360,8 @@ struct templateEntry* tpeConstruct(struct template *pTpl)
/* Constructs a template list object. Returns pointer to it
* or NULL (if it fails).
*/
struct template* tplConstruct(void)
static struct template*
tplConstruct(rsconf_t *conf)
{
struct template *pTpl;
if((pTpl = calloc(1, sizeof(struct template))) == NULL)
@ -366,12 +370,12 @@ struct template* tplConstruct(void)
/* basic initialisation is done via calloc() - need to
* initialize only values != 0. */
if(tplLast == NULL) {
if(conf->templates.last == NULL) {
/* we are the first element! */
tplRoot = tplLast = pTpl;
conf->templates.root = conf->templates.last = pTpl;
} else {
tplLast->pNext = pTpl;
tplLast = pTpl;
conf->templates.last->pNext = pTpl;
conf->templates.last = pTpl;
}
return(pTpl);
@ -907,7 +911,7 @@ finalize_it:
/* Add a new template line
* returns pointer to new object if it succeeds, NULL otherwise.
*/
struct template *tplAddLine(char* pName, uchar** ppRestOfConfLine)
struct template *tplAddLine(rsconf_t *conf, char* pName, uchar** ppRestOfConfLine)
{
struct template *pTpl;
unsigned char *p;
@ -919,7 +923,7 @@ struct template *tplAddLine(char* pName, uchar** ppRestOfConfLine)
assert(pName != NULL);
assert(ppRestOfConfLine != NULL);
if((pTpl = tplConstruct()) == NULL)
if((pTpl = tplConstruct(conf)) == NULL)
return NULL;
pTpl->iLenName = strlen(pName);
@ -1046,13 +1050,13 @@ struct template *tplAddLine(char* pName, uchar** ppRestOfConfLine)
* NULL otherwise.
* rgerhards 2004-11-17
*/
struct template *tplFind(char *pName, int iLenName)
struct template *tplFind(rsconf_t *conf, char *pName, int iLenName)
{
struct template *pTpl;
assert(pName != NULL);
pTpl = tplRoot;
pTpl = conf->templates.root;
while(pTpl != NULL &&
!(pTpl->iLenName == iLenName &&
!strcmp(pTpl->pszName, pName)
@ -1070,13 +1074,13 @@ struct template *tplFind(char *pName, int iLenName)
* "normal" debugging. Uncomment them, if they are needed.
* rgerhards, 2007-07-05
*/
void tplDeleteAll(void)
void tplDeleteAll(rsconf_t *conf)
{
struct template *pTpl, *pTplDel;
struct templateEntry *pTpe, *pTpeDel;
BEGINfunc
pTpl = tplRoot;
pTpl = conf->templates.root;
while(pTpl != NULL) {
/* dbgprintf("Delete Template: Name='%s'\n ", pTpl->pszName == NULL? "NULL" : pTpl->pszName);*/
pTpe = pTpl->pEntryRoot;
@ -1122,19 +1126,19 @@ void tplDeleteAll(void)
/* Destroy all templates obtained from conf file
* preserving hardcoded ones. This is called from init().
*/
void tplDeleteNew(void)
void tplDeleteNew(rsconf_t *conf)
{
struct template *pTpl, *pTplDel;
struct templateEntry *pTpe, *pTpeDel;
BEGINfunc
if(tplRoot == NULL || tplLastStatic == NULL)
if(conf->templates.root == NULL || conf->templates.lastStatic == NULL)
return;
pTpl = tplLastStatic->pNext;
tplLastStatic->pNext = NULL;
tplLast = tplLastStatic;
pTpl = conf->templates.lastStatic->pNext;
conf->templates.lastStatic->pNext = NULL;
conf->templates.last = conf->templates.lastStatic;
while(pTpl != NULL) {
/* dbgprintf("Delete Template: Name='%s'\n ", pTpl->pszName == NULL? "NULL" : pTpl->pszName);*/
pTpe = pTpl->pEntryRoot;
@ -1177,20 +1181,20 @@ void tplDeleteNew(void)
}
/* Store the pointer to the last hardcoded teplate */
void tplLastStaticInit(struct template *tpl)
void tplLastStaticInit(rsconf_t *conf, struct template *tpl)
{
tplLastStatic = tpl;
conf->templates.lastStatic = tpl;
}
/* Print the template structure. This is more or less a
* debug or test aid, but anyhow I think it's worth it...
*/
void tplPrintList(void)
void tplPrintList(rsconf_t *conf)
{
struct template *pTpl;
struct templateEntry *pTpe;
pTpl = tplRoot;
pTpl = conf->templates.root;
while(pTpl != NULL) {
dbgprintf("Template: Name='%s' ", pTpl->pszName == NULL? "NULL" : pTpl->pszName);
if(pTpl->optFormatForSQL == 1)

View File

@ -117,14 +117,14 @@ ENDinterface(tpl)
PROTOTYPEObj(tpl);
struct template* tplConstruct(void);
struct template *tplAddLine(char* pName, unsigned char** pRestOfConfLine);
struct template *tplFind(char *pName, int iLenName);
//struct template* tplConstruct(void);
struct template *tplAddLine(rsconf_t *conf, char* pName, unsigned char** pRestOfConfLine);
struct template *tplFind(rsconf_t *conf, char *pName, int iLenName);
int tplGetEntryCount(struct template *pTpl);
void tplDeleteAll(void);
void tplDeleteNew(void);
void tplPrintList(void);
void tplLastStaticInit(struct template *tpl);
void tplDeleteAll(rsconf_t *conf);
void tplDeleteNew(rsconf_t *conf);
void tplPrintList(rsconf_t *conf);
void tplLastStaticInit(rsconf_t *conf, struct template *tpl);
rsRetVal ExtendBuf(uchar **pBuf, size_t *pLenBuf, size_t iMinSize);
/* note: if a compiler warning for undefined type tells you to look at this
* code line below, the actual cause is that you currently MUST include template.h

View File

@ -21,7 +21,7 @@
* For further information, please see http://www.rsyslog.com
*
* rsyslog - An Enhanced syslogd Replacement.
* Copyright 2003-2009 Rainer Gerhards and Adiscon GmbH.
* Copyright 2003-2011 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of rsyslog.
*
@ -135,6 +135,7 @@
#include "net.h"
#include "vm.h"
#include "prop.h"
#include "rsconf.h"
#include "sd-daemon.h"
/* definitions for objects we access */
@ -149,6 +150,7 @@ DEFobjCurrIf(rule)
DEFobjCurrIf(ruleset)
DEFobjCurrIf(prop)
DEFobjCurrIf(parser)
DEFobjCurrIf(rsconf)
DEFobjCurrIf(net) /* TODO: make go away! */
@ -198,6 +200,8 @@ static rsRetVal GlobalClassExit(void);
# define _PATH_TTY "/dev/tty"
#endif
rsconf_t *ourConf; /* our config object */
static prop_t *pInternalInputName = NULL; /* there is only one global inputName for all internally-generated messages */
static prop_t *pLocalHostIP = NULL; /* there is only one global IP for all internally-generated messages */
static uchar *ConfFile = (uchar*) _PATH_LOGCONF; /* read-only after startup */
@ -1087,7 +1091,7 @@ die(int sig)
* ourselfs, this makes finding memory leaks a lot
* easier.
*/
tplDeleteAll();
tplDeleteAll(ourConf);
/* de-init some modules */
modExitIminternal();
@ -1438,7 +1442,7 @@ static void dbgPrintInitInfo(void)
ruleset.DebugPrintAll();
DBGPRINTF("\n");
if(bDebugPrintTemplateList)
tplPrintList();
tplPrintList(ourConf);
if(bDebugPrintModuleList)
module.PrintList();
ochPrintList();
@ -2147,29 +2151,32 @@ static rsRetVal mainThread()
DEFiRet;
uchar *pTmp;
/* we need to init the config object first! */
CHKiRet(rsconf.Construct(&ourConf));
/* initialize the build-in templates */
pTmp = template_DebugFormat;
tplAddLine("RSYSLOG_DebugFormat", &pTmp);
tplAddLine(ourConf, "RSYSLOG_DebugFormat", &pTmp);
pTmp = template_SyslogProtocol23Format;
tplAddLine("RSYSLOG_SyslogProtocol23Format", &pTmp);
tplAddLine(ourConf, "RSYSLOG_SyslogProtocol23Format", &pTmp);
pTmp = template_FileFormat; /* new format for files with high-precision stamp */
tplAddLine("RSYSLOG_FileFormat", &pTmp);
tplAddLine(ourConf, "RSYSLOG_FileFormat", &pTmp);
pTmp = template_TraditionalFileFormat;
tplAddLine("RSYSLOG_TraditionalFileFormat", &pTmp);
tplAddLine(ourConf, "RSYSLOG_TraditionalFileFormat", &pTmp);
pTmp = template_WallFmt;
tplAddLine(" WallFmt", &pTmp);
tplAddLine(ourConf, " WallFmt", &pTmp);
pTmp = template_ForwardFormat;
tplAddLine("RSYSLOG_ForwardFormat", &pTmp);
tplAddLine(ourConf, "RSYSLOG_ForwardFormat", &pTmp);
pTmp = template_TraditionalForwardFormat;
tplAddLine("RSYSLOG_TraditionalForwardFormat", &pTmp);
tplAddLine(ourConf, "RSYSLOG_TraditionalForwardFormat", &pTmp);
pTmp = template_StdUsrMsgFmt;
tplAddLine(" StdUsrMsgFmt", &pTmp);
tplAddLine(ourConf, " StdUsrMsgFmt", &pTmp);
pTmp = template_StdDBFmt;
tplAddLine(" StdDBFmt", &pTmp);
tplAddLine(ourConf, " StdDBFmt", &pTmp);
pTmp = template_StdPgSQLFmt;
tplLastStaticInit(tplAddLine(" StdPgSQLFmt", &pTmp));
tplAddLine(ourConf, " StdPgSQLFmt", &pTmp);
pTmp = template_spoofadr;
tplLastStaticInit(tplAddLine("RSYSLOG_omudpspoofDfltSourceTpl", &pTmp));
tplLastStaticInit(ourConf, tplAddLine(ourConf, "RSYSLOG_omudpspoofDfltSourceTpl", &pTmp));
CHKiRet(init());
@ -2261,6 +2268,8 @@ InitGlobalClasses(void)
CHKiRet(objUse(prop, CORE_COMPONENT));
pErrObj = "parser";
CHKiRet(objUse(parser, CORE_COMPONENT));
pErrObj = "rsconf";
CHKiRet(objUse(rsconf, CORE_COMPONENT));
/* intialize some dummy classes that are not part of the runtime */
pErrObj = "action";
@ -2306,6 +2315,7 @@ GlobalClassExit(void)
objRelease(expr, CORE_COMPONENT);
vmClassExit(); /* this is hack, currently core_modules do not get this automatically called */
parserClassExit(); /* this is hack, currently core_modules do not get this automatically called */
rsconfClassExit(); /* this is hack, currently core_modules do not get this automatically called */
objRelease(datetime, CORE_COMPONENT);
/* TODO: implement the rest of the deinit */