summaryrefslogtreecommitdiffstats
path: root/template.c
diff options
context:
space:
mode:
Diffstat (limited to 'template.c')
-rw-r--r--template.c73
1 files changed, 46 insertions, 27 deletions
diff --git a/template.c b/template.c
index 54ca95af..12d27ff3 100644
--- a/template.c
+++ b/template.c
@@ -37,6 +37,7 @@
#include "obj.h"
#include "errmsg.h"
#include "strgen.h"
+#include "rsconf.h"
#include "unicode-helper.h"
/* static data */
@@ -49,16 +50,15 @@ 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 */
-
+#warning check this merge
+#if 1
enum {
NO_ESCAPE = 0,
SQL_ESCAPE,
STDSQL_ESCAPE,
JSON_ESCAPE,
};
+#endif
/* helper to tplToString and strgen's, extends buffer */
#define ALLOC_INC 128
@@ -121,7 +121,8 @@ rsRetVal tplToString(struct template *pTpl, msg_t *pMsg, uchar **ppBuf, size_t *
iLenVal = pTpe->data.constant.iLenConstant;
bMustBeFreed = 0;
} else if(pTpe->eEntryType == FIELD) {
- pVal = (uchar*) MsgGetProp(pMsg, pTpe, pTpe->data.field.propid, &iLenVal, &bMustBeFreed);
+ pVal = (uchar*) MsgGetProp(pMsg, pTpe, pTpe->data.field.propid,
+ pTpe->data.field.propName, &iLenVal, &bMustBeFreed);
/* we now need to check if we should use SQL option. In this case,
* we must go over the generated string and escape '\'' characters.
* rgerhards, 2005-09-22: the option values below look somewhat misplaced,
@@ -202,7 +203,8 @@ rsRetVal tplToArray(struct template *pTpl, msg_t *pMsg, uchar*** ppArr)
if(pTpe->eEntryType == CONSTANT) {
CHKmalloc(pArr[iArr] = (uchar*)strdup((char*) pTpe->data.constant.pConstant));
} else if(pTpe->eEntryType == FIELD) {
- pVal = (uchar*) MsgGetProp(pMsg, pTpe, pTpe->data.field.propid, &propLen, &bMustBeFreed);
+ pVal = (uchar*) MsgGetProp(pMsg, pTpe, pTpe->data.field.propid,
+ pTpe->data.field.propName, &propLen, &bMustBeFreed);
if(bMustBeFreed) { /* if it must be freed, it is our own private copy... */
pArr[iArr] = pVal; /* ... so we can use it! */
} else {
@@ -372,7 +374,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)
@@ -381,12 +384,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);
@@ -605,7 +608,14 @@ static int do_Parameter(unsigned char **pp, struct template *pTpl)
cstrDestruct(&pStrB);
return 1;
}
- cstrDestruct(&pStrB); /* no longer needed, now use ID */
+ if(pTpe->data.field.propid == PROP_CEE) {
+ /* in CEE case, we need to preserve the actual property name */
+ if((pTpe->data.field.propName = es_newStrFromCStr((char*)cstrGetSzStrNoNULL(pStrB)+2, cstrLen(pStrB)-2)) == NULL) {
+ cstrDestruct(&pStrB);
+ return 1;
+ }
+ }
+ cstrDestruct(&pStrB);
/* Check frompos, if it has an R, then topos should be a regex */
if(*p == ':') {
@@ -918,7 +928,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;
@@ -930,7 +940,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);
@@ -1059,13 +1069,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)
@@ -1083,13 +1093,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;
@@ -1114,6 +1124,8 @@ void tplDeleteAll(void)
regexp.regfree(&(pTpeDel->data.field.re));
}
}
+ if(pTpeDel->data.field.propName != NULL)
+ es_deleteStr(pTpeDel->data.field.propName);
#endif
break;
}
@@ -1133,19 +1145,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;
@@ -1170,6 +1182,8 @@ void tplDeleteNew(void)
regexp.regfree(&(pTpeDel->data.field.re));
}
}
+ if(pTpeDel->data.field.propName != NULL)
+ es_deleteStr(pTpeDel->data.field.propName);
#endif
break;
}
@@ -1186,20 +1200,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->optFormatEscape == SQL_ESCAPE)
@@ -1222,6 +1236,11 @@ void tplPrintList(void)
break;
case FIELD:
dbgprintf("(FIELD), value: '%d' ", pTpe->data.field.propid);
+ if(pTpe->data.field.propid == PROP_CEE) {
+ char *cstr = es_str2cstr(pTpe->data.field.propName, NULL);
+ dbgprintf("[EE-Property: '%s'] ", cstr);
+ free(cstr);
+ }
switch(pTpe->data.field.eDateFormat) {
case tplFmtDefault:
break;