summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-23 14:50:03 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-23 14:50:03 +0200
commitb50d13a6a97c0b6fa14807775ae0edf52ef015fb (patch)
tree86817355dc2631e21b7b4e2977ecbbf9007537cd /runtime
parent6181156b1c42825bac892d3e1284dcb2d4fcf5d3 (diff)
downloadrsyslog-b50d13a6a97c0b6fa14807775ae0edf52ef015fb.tar.gz
rsyslog-b50d13a6a97c0b6fa14807775ae0edf52ef015fb.tar.xz
rsyslog-b50d13a6a97c0b6fa14807775ae0edf52ef015fb.zip
restored repeated message reduction processing
Diffstat (limited to 'runtime')
-rw-r--r--runtime/msg.c70
-rw-r--r--runtime/msg.h5
-rw-r--r--runtime/rsyslog.h3
-rw-r--r--runtime/ruleset.c7
4 files changed, 60 insertions, 25 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index 6ad0ee4f..8c306aca 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -1733,38 +1733,76 @@ void MsgSetHOSTNAME(msg_t *pMsg, uchar* pszHOSTNAME)
}
-/* rgerhards 2004-11-09: set MSG in msg object
+/* set the offset of the MSG part into the raw msg buffer
*/
void MsgSetMSGoffs(msg_t *pMsg, short offs)
{
- assert(pMsg != NULL);
-
- pMsg->iLenMSG = ustrlen(pMsg->pszRawMsg + offs);
+ ISOBJ_TYPE_assert(pMsg, msg);
+ pMsg->iLenMSG = pMsg->iLenRawMsg - offs;
pMsg->offMSG = offs;
}
+/* replace the MSG part of a message. The update actually takes place inside
+ * rawmsg.
+ * There are two cases: either the new message will be larger than the new msg
+ * or it will be less than or equal. If it is less than or equal, we can utilize
+ * the previous message buffer. If it is larger, we can utilize the msg_t-included
+ * message buffer if it fits in there. If this is not the case, we need to alloc
+ * a new, larger, chunk and copy over the data to it. Note that this function is
+ * (hopefully) relatively seldom being called, so some performance impact is
+ * uncritical. In any case, pszMSG is copied, so if it was dynamically allocated,
+ * the caller is responsible for freeing it.
+ * rgerhards, 2009-06-23
+ */
+rsRetVal MsgReplaceMSG(msg_t *pThis, uchar* pszMSG, int lenMSG)
+{
+ int lenNew;
+ uchar *bufNew;
+ DEFiRet;
+ ISOBJ_TYPE_assert(pThis, msg);
+ assert(pszMSG != NULL);
+
+ lenNew = pThis->iLenRawMsg + lenMSG - pThis->iLenMSG;
+ if(lenMSG > pThis->iLenMSG && lenNew >= CONF_RAWMSG_BUFSIZE) {
+ /* we have lost and need to alloc a new buffer ;) */
+ CHKmalloc(bufNew = malloc(lenNew + 1));
+ memcpy(bufNew, pThis->pszRawMsg, pThis->offMSG);
+ free(pThis->pszRawMsg);
+ pThis->pszRawMsg = bufNew;
+ }
+
+ memcpy(pThis->pszRawMsg + pThis->offMSG, pszMSG, lenMSG);
+ pThis->pszRawMsg[lenNew] = '\0'; /* this also works with truncation! */
+ pThis->iLenRawMsg = lenNew;
+ pThis->iLenMSG = lenMSG;
+
+finalize_it:
+ RETiRet;
+}
+
+
/* set raw message in message object. Size of message is provided.
* rgerhards, 2009-06-16
*/
-void MsgSetRawMsg(msg_t *pMsg, char* pszRawMsg, size_t lenMsg)
+void MsgSetRawMsg(msg_t *pThis, char* pszRawMsg, size_t lenMsg)
{
- assert(pMsg != NULL);
- if(pMsg->pszRawMsg != pMsg->szRawMsg)
- free(pMsg->pszRawMsg);
+ assert(pThis != NULL);
+ if(pThis->pszRawMsg != pThis->szRawMsg)
+ free(pThis->pszRawMsg);
- pMsg->iLenRawMsg = lenMsg;
- if(pMsg->iLenRawMsg < CONF_RAWMSG_BUFSIZE) {
+ pThis->iLenRawMsg = lenMsg;
+ if(pThis->iLenRawMsg < CONF_RAWMSG_BUFSIZE) {
/* small enough: use fixed buffer (faster!) */
- pMsg->pszRawMsg = pMsg->szRawMsg;
- } else if((pMsg->pszRawMsg = (uchar*) malloc(pMsg->iLenRawMsg + 1)) == NULL) {
+ pThis->pszRawMsg = pThis->szRawMsg;
+ } else if((pThis->pszRawMsg = (uchar*) malloc(pThis->iLenRawMsg + 1)) == NULL) {
/* truncate message, better than completely loosing it... */
- pMsg->pszRawMsg = pMsg->szRawMsg;
- pMsg->iLenRawMsg = CONF_RAWMSG_BUFSIZE - 1;
+ pThis->pszRawMsg = pThis->szRawMsg;
+ pThis->iLenRawMsg = CONF_RAWMSG_BUFSIZE - 1;
}
- memcpy(pMsg->pszRawMsg, pszRawMsg, pMsg->iLenRawMsg);
- pMsg->pszRawMsg[pMsg->iLenRawMsg] = '\0'; /* this also works with truncation! */
+ memcpy(pThis->pszRawMsg, pszRawMsg, pThis->iLenRawMsg);
+ pThis->pszRawMsg[pThis->iLenRawMsg] = '\0'; /* this also works with truncation! */
}
diff --git a/runtime/msg.h b/runtime/msg.h
index 9113882a..c38cb788 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -28,10 +28,6 @@
#ifndef MSG_H_INCLUDED
#define MSG_H_INCLUDED 1
-/* some configuration constants */
-#define CONF_RAWMSG_BUFSIZE 101
-#define CONF_TAG_BUFSIZE 33 /* RFC says 32 chars (+ \0), but in practice we see longer ones... */
-
#include <pthread.h>
#include "obj.h"
#include "syslogd-types.h"
@@ -162,6 +158,7 @@ rsRetVal MsgSetAfterPRIOffs(msg_t *pMsg, short offs);
void MsgSetMSGoffs(msg_t *pMsg, short offs);
void MsgSetRawMsgWOSize(msg_t *pMsg, char* pszRawMsg);
void MsgSetRawMsg(msg_t *pMsg, char* pszRawMsg, size_t lenMsg);
+rsRetVal MsgReplaceMSG(msg_t *pThis, uchar* pszMSG, int lenMSG);
void moveHOSTNAMEtoTAG(msg_t *pM);
char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
cstr_t *pCSPropName, size_t *pPropLen, unsigned short *pbMustBeFreed);
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index ac068d5e..793df782 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -31,6 +31,9 @@
* ############################################################# */
#define RS_STRINGBUF_ALLOC_INCREMENT 128
#define CONF_TAG_MAXSIZE 512 /* a value that is deemed far too large for any valid TAG */
+#define CONF_RAWMSG_BUFSIZE 101
+#define CONF_TAG_BUFSIZE 33 /* RFC says 32 chars (+ \0), but in practice we see longer ones... */
+
/* ############################################################# *
* # End Config Settings # *
diff --git a/runtime/ruleset.c b/runtime/ruleset.c
index 93d40e24..d98b4217 100644
--- a/runtime/ruleset.c
+++ b/runtime/ruleset.c
@@ -84,7 +84,6 @@ DEFFUNC_llExecFunc(doIterateRulesetActions)
iRet = rule.IterateAllActions(pRule, pMyParam->pFunc, pMyParam->pParam);
RETiRet;
}
-#if 0
/* iterate over all actions of THIS rule set.
*/
static rsRetVal
@@ -96,7 +95,7 @@ iterateRulesetAllActions(ruleset_t *pThis, rsRetVal (*pFunc)(void*, void*), void
params.pFunc = pFunc;
params.pParam = pParam;
- CHKiRet(llExecFunc(&llRulesets, doIterateRulesetActions, &params));
+ CHKiRet(llExecFunc(&(pThis->llRules), doIterateRulesetActions, &params));
finalize_it:
RETiRet;
@@ -112,7 +111,6 @@ DEFFUNC_llExecFunc(doIterateAllActions)
iRet = iterateRulesetAllActions(pThis, pMyParam->pFunc, pMyParam->pParam);
RETiRet;
}
-#endif
/* iterate over ALL actions present in the WHOLE system.
* this is often needed, for example when HUP processing
* must be done or a shutdown is pending.
@@ -126,8 +124,7 @@ iterateAllActions(rsRetVal (*pFunc)(void*, void*), void* pParam)
params.pFunc = pFunc;
params.pParam = pParam;
- //CHKiRet(llExecFunc(&llRulesets, doIterateAllActions, &params));
- CHKiRet(llExecFunc(&llRulesets, doIterateRulesetActions, &params));
+ CHKiRet(llExecFunc(&llRulesets, doIterateAllActions, &params));
finalize_it:
RETiRet;