summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--runtime/lookup.c52
-rw-r--r--runtime/lookup.h10
-rw-r--r--runtime/rsconf.c1
-rw-r--r--runtime/rsconf.h2
-rw-r--r--runtime/rsyslog.c3
-rw-r--r--runtime/typedefs.h1
6 files changed, 60 insertions, 9 deletions
diff --git a/runtime/lookup.c b/runtime/lookup.c
index 7cb27b07..f1931838 100644
--- a/runtime/lookup.c
+++ b/runtime/lookup.c
@@ -30,6 +30,7 @@
#include "msg.h"
#include "rsconf.h"
#include "dirty.h"
+#include "unicode-helper.h"
/* definitions for objects we access */
DEFobjStaticHelpers
@@ -48,16 +49,32 @@ static struct cnfparamblk modpblk =
modpdescr
};
+
+/* create a new lookup table object AND include it in our list of
+ * lookup tables.
+ */
rsRetVal
-lookupNew(lookup_t **ppThis, char *modname, char *dynname)
+lookupNew(lookup_t **ppThis)
{
- lookup_t *pThis;
+ lookup_t *pThis = NULL;
DEFiRet;
- CHKmalloc(pThis = calloc(1, sizeof(lookup_t)));
+ CHKmalloc(pThis = malloc(sizeof(lookup_t)));
+ pThis->name = NULL;
+
+ if(loadConf->lu_tabs.root == NULL) {
+ loadConf->lu_tabs.root = pThis;
+ pThis->next = NULL;
+ } else {
+ pThis->next = loadConf->lu_tabs.last;
+ }
+ loadConf->lu_tabs.last = pThis;
*ppThis = pThis;
finalize_it:
+ if(iRet != RS_RET_OK) {
+ free(pThis);
+ }
RETiRet;
}
void
@@ -66,12 +83,20 @@ lookupDestruct(lookup_t *lookup)
free(lookup);
}
+void
+lookupInitCnf(lookup_tables_t *lu_tabs)
+{
+ lu_tabs->root = NULL;
+ lu_tabs->last = NULL;
+}
+
+
rsRetVal
lookupProcessCnf(struct cnfobj *o)
{
struct cnfparamvals *pvals;
- uchar *cnfModName = NULL;
- int typeIdx;
+ lookup_t *lu;
+ short i;
DEFiRet;
pvals = nvlstGetParams(o->nvlst, &modpblk, NULL);
@@ -81,10 +106,23 @@ lookupProcessCnf(struct cnfobj *o)
DBGPRINTF("lookupProcessCnf params:\n");
cnfparamsPrint(&modpblk, pvals);
- // TODO: add code
+ CHKiRet(lookupNew(&lu));
+
+ for(i = 0 ; i < modpblk.nParams ; ++i) {
+ if(!pvals[i].bUsed)
+ continue;
+ if(!strcmp(modpblk.descr[i].name, "file")) {
+ CHKmalloc(lu->filename = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL));
+ } else if(!strcmp(modpblk.descr[i].name, "name")) {
+ CHKmalloc(lu->name = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL));
+ } else {
+ dbgprintf("lookup_table: program error, non-handled "
+ "param '%s'\n", modpblk.descr[i].name);
+ }
+ }
+ DBGPRINTF("lookup table '%s' loaded from file '%s'\n", lu->name, lu->filename);
finalize_it:
- free(cnfModName);
cnfparamvalsDestruct(pvals, &modpblk);
RETiRet;
}
diff --git a/runtime/lookup.h b/runtime/lookup.h
index d7f38118..8dd7c23e 100644
--- a/runtime/lookup.h
+++ b/runtime/lookup.h
@@ -21,11 +21,19 @@
#ifndef INCLUDED_LOOKUP_H
#define INCLUDED_LOOKUP_H
+struct lookup_tables_s {
+ lookup_t *root; /* the root of the template list */
+ lookup_t *last; /* points to the last element of the template list */
+};
+
struct lookup_s {
+ uchar *name;
+ uchar *filename;
+ lookup_t *next;
};
/* prototypes */
-rsRetVal lookupNew(lookup_t **ppThis, char *modname, char *dynname);
+void lookupInitCnf(lookup_tables_t *lu_tabs);
rsRetVal lookupProcessCnf(struct cnfobj *o);
void lookupDestruct(lookup_t *pThis);
void lookupClassExit(void);
diff --git a/runtime/rsconf.c b/runtime/rsconf.c
index e0b7d5eb..d4f8c8af 100644
--- a/runtime/rsconf.c
+++ b/runtime/rsconf.c
@@ -124,6 +124,7 @@ BEGINobjConstruct(rsconf) /* be sure to specify the object type also in END macr
pThis->templates.last = NULL;
pThis->templates.lastStatic = NULL;
pThis->actions.nbrActions = 0;
+ lookupInitCnf(&pThis->lu_tabs);
CHKiRet(llInit(&pThis->rulesets.llRulesets, rulesetDestructForLinkedList,
rulesetKeyDestruct, strcasecmp));
/* queue params */
diff --git a/runtime/rsconf.h b/runtime/rsconf.h
index 484fec8c..894c0d12 100644
--- a/runtime/rsconf.h
+++ b/runtime/rsconf.h
@@ -25,6 +25,7 @@
#include "linkedlist.h"
#include "queue.h"
+#include "lookup.h"
/* --- configuration objects (the plan is to have ALL upper layers in this file) --- */
@@ -143,6 +144,7 @@ struct rsconf_s {
globals_t globals;
defaults_t defaults;
templates_t templates;
+ lookup_tables_t lu_tabs;
outchannels_t och;
actions_t actions;
rulesets_t rulesets;
diff --git a/runtime/rsyslog.c b/runtime/rsyslog.c
index f9c52bb9..53c7855a 100644
--- a/runtime/rsyslog.c
+++ b/runtime/rsyslog.c
@@ -74,6 +74,7 @@
#include "prop.h"
#include "ruleset.h"
#include "parser.h"
+#include "lookup.h"
#include "strgen.h"
#include "statsobj.h"
#include "atomic.h"
@@ -187,7 +188,7 @@ rsrtInit(char **ppErrObj, obj_if_t *pObjIF)
if(ppErrObj != NULL) *ppErrObj = "rsconf";
CHKiRet(rsconfClassInit(NULL));
if(ppErrObj != NULL) *ppErrObj = "lookup";
- CHKiRet(lookupClassInit(NULL));
+ CHKiRet(lookupClassInit());
/* dummy "classes" */
if(ppErrObj != NULL) *ppErrObj = "str";
diff --git a/runtime/typedefs.h b/runtime/typedefs.h
index 616b60c9..c962d0a8 100644
--- a/runtime/typedefs.h
+++ b/runtime/typedefs.h
@@ -100,6 +100,7 @@ typedef struct outchannels_s outchannels_t;
typedef struct modConfData_s modConfData_t;
typedef struct instanceConf_s instanceConf_t;
typedef struct ratelimit_s ratelimit_t;
+typedef struct lookup_tables_s lookup_tables_t;
typedef struct lookup_s lookup_t;
typedef struct action_s action_t;
typedef int rs_size_t; /* we do never need more than 2Gig strings, signed permits to