summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-18 16:20:06 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-18 16:20:06 +0200
commitdf9012f755a305ef48037f10fcc9413406894e66 (patch)
tree1aed124ca0396ace409a5550bf39c8432ec5f15c
parentf18c0ffb9a6de737d2b86b3df164ead22ac5ef58 (diff)
downloadrsyslog-df9012f755a305ef48037f10fcc9413406894e66.tar.gz
rsyslog-df9012f755a305ef48037f10fcc9413406894e66.tar.xz
rsyslog-df9012f755a305ef48037f10fcc9413406894e66.zip
slight optimization of template generation
-rw-r--r--runtime/msg.c10
-rw-r--r--runtime/msg.h2
-rw-r--r--runtime/rule.c4
-rw-r--r--template.c6
4 files changed, 15 insertions, 7 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index 39f2370c..67aaf250 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -1848,7 +1848,8 @@ static uchar *getNOW(eNOWType eNow)
* rgerhards 2005-09-15
*/
char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
- cstr_t *pCSPropName, unsigned short *pbMustBeFreed)
+ cstr_t *pCSPropName, size_t *pPropLen,
+ unsigned short *pbMustBeFreed)
{
uchar *pName;
char *pRes; /* result pointer */
@@ -2546,6 +2547,10 @@ char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
*pbMustBeFreed = 1;
}
+ if(bufLen == -1)
+ bufLen = strlen(pRes);
+ *pPropLen = bufLen;
+
/*dbgprintf("MsgGetProp(\"%s\"): \"%s\"\n", pName, pRes); only for verbose debug logging */
return(pRes);
}
@@ -2561,6 +2566,7 @@ msgGetMsgVar(msg_t *pThis, cstr_t *pstrPropName, var_t **ppVar)
{
DEFiRet;
var_t *pVar;
+ size_t propLen;
uchar *pszProp = NULL;
cstr_t *pstrProp;
unsigned short bMustBeFreed = 0;
@@ -2574,7 +2580,7 @@ msgGetMsgVar(msg_t *pThis, cstr_t *pstrPropName, var_t **ppVar)
CHKiRet(var.ConstructFinalize(pVar));
/* always call MsgGetProp() without a template specifier */
- pszProp = (uchar*) MsgGetProp(pThis, NULL, pstrPropName, &bMustBeFreed);
+ pszProp = (uchar*) MsgGetProp(pThis, NULL, pstrPropName, &propLen, &bMustBeFreed);
/* now create a string object out of it and hand that over to the var */
CHKiRet(rsCStrConstructFromszStr(&pstrProp, pszProp));
diff --git a/runtime/msg.h b/runtime/msg.h
index 13c2c4ea..48c1090e 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -161,7 +161,7 @@ void MsgSetRawMsgWOSize(msg_t *pMsg, char* pszRawMsg);
void MsgSetRawMsg(msg_t *pMsg, char* pszRawMsg, size_t lenMsg);
void moveHOSTNAMEtoTAG(msg_t *pM);
char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
- cstr_t *pCSPropName, unsigned short *pbMustBeFreed);
+ cstr_t *pCSPropName, size_t *pPropLen, unsigned short *pbMustBeFreed);
char *textpri(char *pRes, size_t pResLen, int pri);
rsRetVal msgGetMsgVar(msg_t *pThis, cstr_t *pstrPropName, var_t **ppVar);
rsRetVal MsgEnableThreadSafety(void);
diff --git a/runtime/rule.c b/runtime/rule.c
index f17c524e..12494543 100644
--- a/runtime/rule.c
+++ b/runtime/rule.c
@@ -106,6 +106,7 @@ shouldProcessThisMessage(rule_t *pRule, msg_t *pMsg, int *bProcessMsg)
unsigned short pbMustBeFreed;
char *pszPropVal;
int bRet = 0;
+ size_t propLen;
vm_t *pVM = NULL;
var_t *pResult = NULL;
@@ -177,7 +178,8 @@ shouldProcessThisMessage(rule_t *pRule, msg_t *pMsg, int *bProcessMsg)
bRet = (pResult->val.num) ? 1 : 0;
} else {
assert(pRule->f_filter_type == FILTER_PROP); /* assert() just in case... */
- pszPropVal = MsgGetProp(pMsg, NULL, pRule->f_filterData.prop.pCSPropName, &pbMustBeFreed);
+ pszPropVal = MsgGetProp(pMsg, NULL, pRule->f_filterData.prop.pCSPropName, &propLen, &pbMustBeFreed);
+ // TODO: optimize, we now have the length of the property!
/* Now do the compares (short list currently ;)) */
switch(pRule->f_filterData.prop.operation ) {
diff --git a/template.c b/template.c
index 6e34bcd8..aacd4dbd 100644
--- a/template.c
+++ b/template.c
@@ -103,8 +103,7 @@ rsRetVal tplToString(struct template *pTpl, msg_t *pMsg, uchar** ppSz)
FINALIZE;
}
} else if(pTpe->eEntryType == FIELD) {
- pVal = (uchar*) MsgGetProp(pMsg, pTpe, NULL, &bMustBeFreed);
- iLenVal = strlen((char*) pVal);
+ pVal = (uchar*) MsgGetProp(pMsg, pTpe, NULL, &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,
@@ -158,6 +157,7 @@ rsRetVal tplToArray(struct template *pTpl, msg_t *pMsg, uchar*** ppArr)
struct templateEntry *pTpe;
uchar **pArr;
int iArr;
+ size_t propLen;
unsigned short bMustBeFreed;
uchar *pVal;
@@ -178,7 +178,7 @@ 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, NULL, &bMustBeFreed);
+ pVal = (uchar*) MsgGetProp(pMsg, pTpe, NULL, &propLen, &bMustBeFreed);
if(bMustBeFreed) { /* if it must be freed, it is our own private copy... */
pArr[iArr] = pVal; /* ... so we can use it! */
} else {