summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--runtime/stream.c22
2 files changed, 29 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 0264f895..cbfbec5c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
---------------------------------------------------------------------------
Version 7.5.3 [devel] 2013-07-??
+- imfile: support for escaping LF characters added
+ embedded LF in syslog messages cause a lot of trouble. imfile now has
+ the capability to escape them to "#012" (just like the regular control
+ character escape option). This requires new-style input statements to be
+ used. If legacy configuration statements are used, LF escaping is always
+ turned off to preserve compatibility.
+ NOTE: if input() statements were already used, there is a CHANGE OF
+ BEHAVIOUR: starting with this version, escaping is enabled by
+ default. So if you do not want it, you need to add
+ escapeLF="off"
+ to the input statement. Given the trouble LFs cause and the fact
+ that the majority of installations still use legacy config, we
+ considered this behaviour change acceptable and useful.
- bugfix: queue file size was not correctly processed
this could lead to using one queue file per message for sizes >2GiB
Thanks to Tomas Heinrich for the patch.
diff --git a/runtime/stream.c b/runtime/stream.c
index 5ffbf10a..b35d6a11 100644
--- a/runtime/stream.c
+++ b/runtime/stream.c
@@ -745,6 +745,7 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF)
} else if(mode == 2) {
/* indented follow-up lines */
finished=0;
+ bPrevWasNL = 0;
while(finished == 0){
if ((*ppCStr)->iStrLen == 0){
if(c != '\n') {
@@ -755,22 +756,31 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF)
finished=1; /* this is a blank line, a \n with nothing since the last complete record */
}
} else {
- if ((*ppCStr)->pBuf[(*ppCStr)->iStrLen -1 ] != '\n'){
- /* not the first character after a newline, add it to the buffer */
- CHKiRet(cstrAppendChar(*ppCStr, c));
- CHKiRet(strmReadChar(pThis, &c));
- } else {
+ if(bPrevWasNL) {
if ((c == ' ') || (c == '\t')){
CHKiRet(cstrAppendChar(*ppCStr, c));
CHKiRet(strmReadChar(pThis, &c));
+ bPrevWasNL = 0;
} else {
/* clean things up by putting the character we just read back into
* the input buffer and removing the LF character that is currently at the
* end of the output string */
CHKiRet(strmUnreadChar(pThis, c));
- rsCStrTruncate(*ppCStr,1);
+ rsCStrTruncate(*ppCStr, (bEscapeLF) ? 4 : 1);
finished=1;
}
+ } else { /* not the first character after a newline, add it to the buffer */
+ if(c == '\n') {
+ bPrevWasNL = 1;
+ if(bEscapeLF) {
+ CHKiRet(rsCStrAppendStrWithLen(*ppCStr, (uchar*)"#012", sizeof("#012")-1));
+ } else {
+ CHKiRet(cstrAppendChar(*ppCStr, c));
+ }
+ } else {
+ CHKiRet(cstrAppendChar(*ppCStr, c));
+ }
+ CHKiRet(strmReadChar(pThis, &c));
}
}
}