diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-04-26 16:03:30 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-04-26 16:03:30 +0200 |
commit | 45dc0db51e78d3d6ef296f0cfd7a7a775e91415c (patch) | |
tree | 29532050057e47e532f9d376aaae33b8aed57940 /runtime | |
parent | 9ec02e670a5fec3d42d567ec593f618dfc9cacb8 (diff) | |
parent | 5624012710ea75acfd892903f05a6df69a51be39 (diff) | |
download | rsyslog-45dc0db51e78d3d6ef296f0cfd7a7a775e91415c.tar.gz rsyslog-45dc0db51e78d3d6ef296f0cfd7a7a775e91415c.tar.xz rsyslog-45dc0db51e78d3d6ef296f0cfd7a7a775e91415c.zip |
Merge branch 'master-fieldext'
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/msg.c | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/runtime/msg.c b/runtime/msg.c index 9c7a2203..4ad2b89e 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -2799,7 +2799,7 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, */ iCurrFld = 1; pFld = pRes; - while(*pFld && iCurrFld < pTpe->data.field.iToPos) { + while(*pFld && iCurrFld < pTpe->data.field.iFieldNr) { /* skip fields until the requested field or end of string is found */ while(*pFld && (uchar) *pFld != pTpe->data.field.field_delim) ++pFld; /* skip to field terminator */ @@ -2813,9 +2813,9 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, ++iCurrFld; } } - dbgprintf("field requested %d, field found %d\n", pTpe->data.field.iToPos, (int) iCurrFld); + dbgprintf("field requested %d, field found %d\n", pTpe->data.field.iFieldNr, (int) iCurrFld); - if(iCurrFld == pTpe->data.field.iToPos) { + if(iCurrFld == pTpe->data.field.iFieldNr) { /* field found, now extract it */ /* first of all, we need to find the end */ pFldEnd = pFld; @@ -2850,58 +2850,6 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, *pPropLen = sizeof("**FIELD NOT FOUND**") - 1; return UCHAR_CONSTANT("**FIELD NOT FOUND**"); } - } else if(pTpe->data.field.iFromPos != 0 || pTpe->data.field.iToPos != 0) { - /* we need to obtain a private copy */ - int iFrom, iTo; - uchar *pSb; - iFrom = pTpe->data.field.iFromPos; - iTo = pTpe->data.field.iToPos; - /* need to zero-base to and from (they are 1-based!) */ - if(iFrom > 0) - --iFrom; - if(iTo > 0) - --iTo; - if(bufLen == -1) - bufLen = ustrlen(pRes); - if(iFrom == 0 && iTo >= bufLen) { - /* in this case, the requested string is a superset of what we already have, - * so there is no need to do any processing. This is a frequent case for size-limited - * fields like TAG in the default forwarding template (so it is a useful optimization - * to check for this condition ;)). -- rgerhards, 2009-07-09 - */ - ; /*DO NOTHING*/ - } else { - iLen = iTo - iFrom + 1; /* the +1 is for an actual char, NOT \0! */ - pBufStart = pBuf = MALLOC((iLen + 1) * sizeof(char)); - if(pBuf == NULL) { - if(*pbMustBeFreed == 1) - free(pRes); - RET_OUT_OF_MEMORY; - } - pSb = pRes; - if(iFrom) { - /* skip to the start of the substring (can't do pointer arithmetic - * because the whole string might be smaller!!) - */ - while(*pSb && iFrom) { - --iFrom; - ++pSb; - } - } - /* OK, we are at the begin - now let's copy... */ - bufLen = iLen; - while(*pSb && iLen) { - *pBuf++ = *pSb; - ++pSb; - --iLen; - } - *pBuf = '\0'; - bufLen -= iLen; /* subtract remaining length if the string was smaller! */ - if(*pbMustBeFreed == 1) - free(pRes); - pRes = pBufStart; - *pbMustBeFreed = 1; - } #ifdef FEATURE_REGEXP } else { /* Check for regular expressions */ @@ -3027,6 +2975,60 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe, #endif /* #ifdef FEATURE_REGEXP */ } + if(pTpe->data.field.iFromPos != 0 || pTpe->data.field.iToPos != 0) { + /* we need to obtain a private copy */ + int iFrom, iTo; + uchar *pSb; + iFrom = pTpe->data.field.iFromPos; + iTo = pTpe->data.field.iToPos; + /* need to zero-base to and from (they are 1-based!) */ + if(iFrom > 0) + --iFrom; + if(iTo > 0) + --iTo; + if(bufLen == -1) + bufLen = ustrlen(pRes); + if(iFrom == 0 && iTo >= bufLen) { + /* in this case, the requested string is a superset of what we already have, + * so there is no need to do any processing. This is a frequent case for size-limited + * fields like TAG in the default forwarding template (so it is a useful optimization + * to check for this condition ;)). -- rgerhards, 2009-07-09 + */ + ; /*DO NOTHING*/ + } else { + iLen = iTo - iFrom + 1; /* the +1 is for an actual char, NOT \0! */ + pBufStart = pBuf = MALLOC((iLen + 1) * sizeof(char)); + if(pBuf == NULL) { + if(*pbMustBeFreed == 1) + free(pRes); + RET_OUT_OF_MEMORY; + } + pSb = pRes; + if(iFrom) { + /* skip to the start of the substring (can't do pointer arithmetic + * because the whole string might be smaller!!) + */ + while(*pSb && iFrom) { + --iFrom; + ++pSb; + } + } + /* OK, we are at the begin - now let's copy... */ + bufLen = iLen; + while(*pSb && iLen) { + *pBuf++ = *pSb; + ++pSb; + --iLen; + } + *pBuf = '\0'; + bufLen -= iLen; /* subtract remaining length if the string was smaller! */ + if(*pbMustBeFreed == 1) + free(pRes); + pRes = pBufStart; + *pbMustBeFreed = 1; + } + } + /* now check if we need to do our "SP if first char is non-space" hack logic */ if(*pRes && pTpe->data.field.options.bSPIffNo1stSP) { /* here, we always destruct the buffer and return a new one */ |