summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--conf.c53
-rw-r--r--conf.h19
-rw-r--r--obj-types.h27
-rw-r--r--obj.c20
-rw-r--r--syslogd.c31
6 files changed, 115 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 97352167..934ec9da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@ Version 3.12.1 (rgerhards), 2008-0?-??
an environment variable
- bugfix: removed debugging code that I forgot to remove before releasing
3.12.0 (does not cause harm and happened only during startup)
+- internal code improvements (more code converted into classes)
---------------------------------------------------------------------------
Version 3.12.0 (rgerhards), 2008-02-28
- added full expression support for filters; filters can now contain
diff --git a/conf.c b/conf.c
index 115224f6..d793b10a 100644
--- a/conf.c
+++ b/conf.c
@@ -54,8 +54,14 @@
#include "stringbuf.h"
#include "srUtils.h"
+
+/* forward definitions */
+static rsRetVal cfline(uchar *line, selector_t **pfCurr);
+static rsRetVal processConfFile(uchar *pConfFile);
+
+
/* static data */
-DEFobjCurrIf(obj)
+DEFobjStaticHelpers
DEFobjCurrIf(expr)
DEFobjCurrIf(ctok)
@@ -401,7 +407,7 @@ finalize_it:
/* process a configuration file
* started with code from init() by rgerhards on 2007-07-31
*/
-rsRetVal
+static rsRetVal
processConfFile(uchar *pConfFile)
{
DEFiRet;
@@ -1141,7 +1147,7 @@ finalize_it:
* I re-did this functon because it was desperately time to do so
* rgerhards, 2007-08-01
*/
-rsRetVal
+static rsRetVal
cfline(uchar *line, selector_t **pfCurr)
{
DEFiRet;
@@ -1172,20 +1178,41 @@ cfline(uchar *line, selector_t **pfCurr)
}
-/* dummy */
-//static rsRetVal confQueryInterface(void) { return RS_RET_NOT_IMPLEMENTED; }
+/* queryInterface function
+ * rgerhards, 2008-02-29
+ */
+BEGINobjQueryInterface(conf)
+CODESTARTobjQueryInterface(conf)
+ if(pIf->ifVersion != confCURR_IF_VERSION) { /* check for current version, increment on each change */
+ ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
+ }
-/* "mimic" a real object - we are currently not one... */
-rsRetVal confClassInit(void)
-{
- DEFiRet;
+ /* 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->doNameLine = doNameLine;
+ pIf->cfsysline = cfsysline;
+ pIf->doModLoad = doModLoad;
+ pIf->doIncludeLine = doIncludeLine;
+ pIf->cfline = cfline;
+ pIf->processConfFile = processConfFile;
+
+finalize_it:
+ENDobjQueryInterface(conf)
+
+
+
+/* Initialize our class. Must be called as the very first method
+ * before anything else is called inside this class.
+ * rgerhards, 2008-02-29
+ */
+BEGINAbstractObjClassInit(conf, 1, OBJ_IS_CORE_MODULE) /* class, version - CHANGE class also in END MACRO! */
/* request objects we use */
- CHKiRet(objGetObjInterface(&obj)); /* this provides the root pointer for all other queries */
CHKiRet(objUse(expr, CORE_COMPONENT));
CHKiRet(objUse(ctok, CORE_COMPONENT));
+ENDObjClassInit(conf)
-finalize_it:
- RETiRet;
-}
/* vi:set ai:
*/
diff --git a/conf.h b/conf.h
index 6a49ff71..584e29dc 100644
--- a/conf.h
+++ b/conf.h
@@ -29,7 +29,21 @@
*/
enum eDirective { DIR_TEMPLATE = 0, DIR_OUTCHANNEL = 1, DIR_ALLOWEDSENDER = 2};
-/* propotypes */
+/* interfaces */
+BEGINinterface(conf) /* name must also be changed in ENDinterface macro! */
+ rsRetVal (*doNameLine)(uchar **pp, void* pVal);
+ rsRetVal (*cfsysline)(uchar *p);
+ rsRetVal (*doModLoad)(uchar **pp, __attribute__((unused)) void* pVal);
+ rsRetVal (*doIncludeLine)(uchar **pp, __attribute__((unused)) void* pVal);
+ rsRetVal (*cfline)(uchar *line, selector_t **pfCurr);
+ rsRetVal (*processConfFile)(uchar *pConfFile);
+ //rsRetVal (*confClassInit)(void); /* TODO: make this a real object! */
+ENDinterface(conf)
+#define confCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
+
+
+/* prototypes */
+#if 0
rsRetVal doNameLine(uchar **pp, void* pVal);
rsRetVal cfsysline(uchar *p);
rsRetVal doModLoad(uchar **pp, __attribute__((unused)) void* pVal);
@@ -37,6 +51,9 @@ rsRetVal doIncludeLine(uchar **pp, __attribute__((unused)) void* pVal);
rsRetVal cfline(uchar *line, selector_t **pfCurr);
rsRetVal processConfFile(uchar *pConfFile);
rsRetVal confClassInit(void); /* TODO: make this a real object! */
+#endif
+PROTOTYPEObj(conf);
+
/* TODO: remove them below (means move the config init code) -- rgerhards, 2008-02-19 */
extern uchar *pModDir; /* read-only after startup */
diff --git a/obj-types.h b/obj-types.h
index ad8c555c..31fdd03d 100644
--- a/obj-types.h
+++ b/obj-types.h
@@ -166,7 +166,8 @@ rsRetVal objName##ClassInit(void) \
CHKiRet(objGetObjInterface(&obj)); /* this provides the root pointer for all other queries */ \
} \
CHKiRet(obj.InfoConstruct(&pObjInfoOBJ, (uchar*) #objName, objVers, \
- (rsRetVal (*)(void*))objName##Construct, (rsRetVal (*)(void*))objName##Destruct,\
+ (rsRetVal (*)(void*))objName##Construct,\
+ (rsRetVal (*)(void*))objName##Destruct,\
(rsRetVal (*)(interface_t*))objName##QueryInterface));
#define ENDObjClassInit(objName) \
@@ -175,6 +176,26 @@ finalize_it: \
RETiRet; \
}
+/* ... and now the same for abstract classes.
+ * TODO: consolidate the two -- rgerhards, 2008-02-29
+ */
+#define BEGINAbstractObjClassInit(objName, objVers, objType) \
+rsRetVal objName##ClassInit(void) \
+{ \
+ DEFiRet; \
+ if(objType == OBJ_IS_CORE_MODULE) { \
+ CHKiRet(objGetObjInterface(&obj)); /* this provides the root pointer for all other queries */ \
+ } \
+ CHKiRet(obj.InfoConstruct(&pObjInfoOBJ, (uchar*) #objName, objVers, \
+ NULL,\
+ NULL,\
+ (rsRetVal (*)(interface_t*))objName##QueryInterface));
+
+#define ENDObjClassInit(objName) \
+ iRet = obj.RegisterObj((uchar*)#objName, pObjInfoOBJ); \
+finalize_it: \
+ RETiRet; \
+}
/* this defines both the constructor and initializer
* rgerhards, 2008-01-10
@@ -345,8 +366,8 @@ finalize_it: \
* functions that actually need to be non-static.
*/
#define PROTOTYPEObj(obj) \
- PROTOTYPEObjClassInit(obj); \
- //PROTOTYPEObjQueryInterface(obj)
+ PROTOTYPEObjClassInit(obj);
+
/* ------------------------------ end object loader system ------------------------------ */
diff --git a/obj.c b/obj.c
index 0680c32b..d454211b 100644
--- a/obj.c
+++ b/obj.c
@@ -133,7 +133,6 @@ InfoConstruct(objInfo_t **ppThis, uchar *pszID, int iObjVers,
objInfo_t *pThis;
assert(ppThis != NULL);
- assert(pDestruct != NULL);
if((pThis = calloc(1, sizeof(objInfo_t))) == NULL)
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
@@ -143,7 +142,6 @@ InfoConstruct(objInfo_t **ppThis, uchar *pszID, int iObjVers,
pThis->pszName = (uchar*)strdup((char*)pszID); /* it's OK if we have NULL ptr, GetName() will deal with that! */
pThis->iObjVers = iObjVers;
pThis->QueryIF = pQueryIF;
- //xxxpThis->objID = objID;
pThis->objMethods[0] = pConstruct;
pThis->objMethods[1] = pDestruct;
@@ -994,6 +992,7 @@ finalize_it:
} else {
dbgprintf("caller requested object '%s', not found (iRet %d)\n", rsCStrGetSzStr(pstrOID), iRet);
}
+dbgPrintAllDebugInfo();
RETiRet;
}
@@ -1034,6 +1033,10 @@ RegisterObj(uchar *pszObjName, objInfo_t *pInfo)
dbgprintf("object '%s' successfully registered with index %d, qIF %p\n", pszObjName, i, pInfo->QueryIF);
finalize_it:
+ if(iRet != RS_RET_OK) {
+ logerrorVar("registering object '%s' failed with error code %d", pszObjName, iRet);
+ }
+
RETiRet;
}
@@ -1120,7 +1123,14 @@ objGetObjInterface(obj_if_t *pIf)
}
-/* initialize our own class */
+/* initialize our own class
+ * Please note that this also initializes those classes that we rely on.
+ * Though this is a bit dirty, we need to do it - otherwise we can't get
+ * around that bootstrap problem. We need to face the fact the the obj
+ * class is a little different from the rest of the system, as it provides
+ * the core class loader functionality.
+ * rgerhards, 2008-02-29
+ */
rsRetVal
objClassInit(void)
{
@@ -1136,7 +1146,9 @@ objClassInit(void)
/* request objects we use */
CHKiRet(objGetObjInterface(&obj)); /* get ourselves ;) */
-CHKiRet(varClassInit());
+
+ /* init classes we use (limit to as few as possible!) */
+ CHKiRet(varClassInit());
CHKiRet(objUse(var, CORE_COMPONENT));
finalize_it:
diff --git a/syslogd.c b/syslogd.c
index cf2b85e7..7f24dac5 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -179,6 +179,7 @@
/* definitions for objects we access */
DEFobjCurrIf(obj)
+DEFobjCurrIf(conf)
DEFobjCurrIf(expr)
DEFobjCurrIf(vm)
@@ -2374,7 +2375,7 @@ void legacyOptsHook(void)
while(pThis != NULL) {
if(pThis->line != NULL)
- cfsysline(pThis->line);
+ conf.cfsysline(pThis->line);
pThis = pThis->next;
}
}
@@ -2834,10 +2835,10 @@ init(void)
* think about the whole situation when we implement loadable plugins.
* rgerhards, 2007-07-31
*/
- cfsysline((uchar*)"ResetConfigVariables");
+ conf.cfsysline((uchar*)"ResetConfigVariables");
/* open the configuration file */
- if((iRet = processConfFile(ConfFile)) != RS_RET_OK) {
+ if((iRet = conf.processConfFile(ConfFile)) != RS_RET_OK) {
/* rgerhards: this code is executed to set defaults when the
* config file could not be opened. We might think about
* abandoning the run in this case - but this, too, is not
@@ -2847,11 +2848,11 @@ init(void)
selector_t *f = NULL;
char szTTYNameBuf[_POSIX_TTY_NAME_MAX+1]; /* +1 for NULL character */
dbgprintf("primary config file could not be opened - using emergency definitions.\n");
- cfline((uchar*)"*.ERR\t" _PATH_CONSOLE, &f);
- cfline((uchar*)"*.PANIC\t*", &f);
+ conf.cfline((uchar*)"*.ERR\t" _PATH_CONSOLE, &f);
+ conf.cfline((uchar*)"*.PANIC\t*", &f);
if(ttyname_r(0, szTTYNameBuf, sizeof(szTTYNameBuf)) == 0) {
snprintf(cbuf,sizeof(cbuf), "*.*\t%s", szTTYNameBuf);
- cfline((uchar*)cbuf, &f);
+ conf.cfline((uchar*)cbuf, &f);
}
selectorAddList(f);
}
@@ -3439,11 +3440,11 @@ static rsRetVal loadBuildInModules(void)
CHKiRet(regCfSysLineHdlr((uchar *)"escapecontrolcharactersonreceive", 0, eCmdHdlrBinary, NULL, &bEscapeCCOnRcv, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"dropmsgswithmaliciousdnsptrrecords", 0, eCmdHdlrBinary, NULL, &bDropMalPTRMsgs, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"droptrailinglfonreception", 0, eCmdHdlrBinary, NULL, &bDropTrailingLF, NULL));
- CHKiRet(regCfSysLineHdlr((uchar *)"template", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_TEMPLATE, NULL));
- CHKiRet(regCfSysLineHdlr((uchar *)"outchannel", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_OUTCHANNEL, NULL));
- CHKiRet(regCfSysLineHdlr((uchar *)"allowedsender", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_ALLOWEDSENDER, NULL));
- CHKiRet(regCfSysLineHdlr((uchar *)"modload", 0, eCmdHdlrCustomHandler, doModLoad, NULL, NULL));
- CHKiRet(regCfSysLineHdlr((uchar *)"includeconfig", 0, eCmdHdlrCustomHandler, doIncludeLine, NULL, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"template", 0, eCmdHdlrCustomHandler, conf.doNameLine, (void*)DIR_TEMPLATE, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"outchannel", 0, eCmdHdlrCustomHandler, conf.doNameLine, (void*)DIR_OUTCHANNEL, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"allowedsender", 0, eCmdHdlrCustomHandler, conf.doNameLine, (void*)DIR_ALLOWEDSENDER, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"modload", 0, eCmdHdlrCustomHandler, conf.doModLoad, NULL, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"includeconfig", 0, eCmdHdlrCustomHandler, conf.doIncludeLine, NULL, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"umask", 0, eCmdHdlrFileCreateMode, setUmask, NULL, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"debugprinttemplatelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintTemplateList, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"debugprintmodulelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintModuleList, NULL));
@@ -3584,7 +3585,6 @@ static rsRetVal InitGlobalClasses(void)
CHKiRet(wtpClassInit());
CHKiRet(queueClassInit());
CHKiRet(vmstkClassInit());
- //TODO: currently done in objClassInit CHKiRet(varClassInit());
CHKiRet(sysvarClassInit());
CHKiRet(vmClassInit());
CHKiRet(vmopClassInit());
@@ -3592,15 +3592,16 @@ static rsRetVal InitGlobalClasses(void)
CHKiRet(ctok_tokenClassInit());
CHKiRet(ctokClassInit());
CHKiRet(exprClassInit());
+ CHKiRet(confClassInit());
/* dummy "classes" */
- CHKiRet(confClassInit());
CHKiRet(actionClassInit());
/* request objects we use */
CHKiRet(objGetObjInterface(&obj)); /* this provides the root pointer for all other queries */
- CHKiRet(obj.UseObj((uchar*)"expr", NULL, (void*) &expr));
- CHKiRet(obj.UseObj((uchar*)"vm", NULL, (void*) &vm));
+ CHKiRet(objUse(conf, CORE_COMPONENT));
+ CHKiRet(objUse(expr, CORE_COMPONENT));
+ CHKiRet(objUse(vm, CORE_COMPONENT));
finalize_it:
RETiRet;