summaryrefslogtreecommitdiffstats
path: root/syslogd.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2006-11-17 10:52:08 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2006-11-17 10:52:08 +0000
commit1fd5ede03ae0a1cbb939bd6dc11d097c8bcd0da3 (patch)
treefef170735dd8b3edc27d4f56c542b71ffd0d3242 /syslogd.c
parentb52aed73f2661b7b698dedfda3f75e90f18d15a2 (diff)
downloadrsyslog-1fd5ede03ae0a1cbb939bd6dc11d097c8bcd0da3.tar.gz
rsyslog-1fd5ede03ae0a1cbb939bd6dc11d097c8bcd0da3.tar.xz
rsyslog-1fd5ede03ae0a1cbb939bd6dc11d097c8bcd0da3.zip
begin support for escape-cc property replacer option
Diffstat (limited to 'syslogd.c')
-rw-r--r--syslogd.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/syslogd.c b/syslogd.c
index 7edcb92e..fd2bcb8e 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -3166,7 +3166,6 @@ static char *MsgGetProp(struct msg *pMsg, struct templateEntry *pTpe,
}
}
dprintf("field requested %d, field found %d\n", pTpe->data.field.iToPos, iCurrFld);
-
if(iCurrFld == pTpe->data.field.iToPos) {
/* field found, now extract it */
@@ -3318,10 +3317,58 @@ static char *MsgGetProp(struct msg *pMsg, struct templateEntry *pTpe,
*pbMustBeFreed = 1;
}
+ /* now do control character dropping/escaping/replacement
+ * RGerhards, 2006-11-17
+ */
+ if(pTpe->data.field.options.bEscapeCC) {
+ /* we must first count how many control charactes are
+ * present, because we need this to compute the new string
+ * buffer length. While doing so, we also compute the string
+ * length.
+ */
+ int iNumCC = 0;
+ int iLen = 0;
+ char *pBuf;
+
+ for(pBuf = pRes ; *pBuf ; ++pBuf) {
+ ++iLen;
+ if(iscntrl(*pBuf))
+ ++iNumCC;
+ }
+
+ if(iNumCC > 0) { /* if 0, there is nothing to escape, so we are done */
+ /* OK, let's do the escaping... */
+ char *pBufStart;
+ char szCCEsc[8]; /* buffer for escape sequence */
+
+ iLen += iNumCC * 4;
+ pBufStart = pBuf = malloc((iLen + 1) * sizeof(char));
+ if(pBuf == NULL) {
+ if(*pbMustBeFreed == 1)
+ free(pRes);
+ *pbMustBeFreed = 0;
+ return "**OUT OF MEMORY**";
+ }
+ while(*pRes) {
+ if(iscntrl(*pRes)) {
+ /* TODO: fill escape coding */
+ } else {
+ *pBuf++ = *pRes;
+ }
+ ++pRes;
+ }
+ *pBuf = '\0';
+ if(*pbMustBeFreed == 1)
+ free(pRes);
+ pRes = pBufStart;
+ *pbMustBeFreed = 1;
+ }
+ }
+
/* Now drop last LF if present (pls note that this must not be done
* if bEscapeCC was set! - once that is implemented ;)).
*/
- if(pTpe->data.field.options.bDropLastLF) {
+ if(pTpe->data.field.options.bDropLastLF && !pTpe->data.field.options.bEscapeCC) {
int iLen = strlen(pRes);
char *pBuf;
if(*(pRes + iLen - 1) == '\n') {