diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2013-09-10 11:34:31 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2013-09-10 11:34:31 +0200 |
commit | ea9c81ce3c512d1835e323ef7e817014e109b25a (patch) | |
tree | d6eeb83951cc3d60f0c654ffbb19a84a64d3aaa7 /runtime/stream.c | |
parent | dc02a38d512029e5ba0d2a1bbff7d919f9c86d7e (diff) | |
download | rsyslog-ea9c81ce3c512d1835e323ef7e817014e109b25a.tar.gz rsyslog-ea9c81ce3c512d1835e323ef7e817014e109b25a.tar.bz2 rsyslog-ea9c81ce3c512d1835e323ef7e817014e109b25a.zip |
imfile: support LF escaping in read mode 1
Diffstat (limited to 'runtime/stream.c')
-rw-r--r-- | runtime/stream.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/runtime/stream.c b/runtime/stream.c index 444a33ff..5ffbf10a 100644 --- a/runtime/stream.c +++ b/runtime/stream.c @@ -680,7 +680,7 @@ static rsRetVal strmUnreadChar(strm_t *pThis, uchar c) * destruction of the returned CStr object! -- dlang 2010-12-13 */ static rsRetVal -strmReadLine(strm_t *pThis, cstr_t **ppCStr, int mode) +strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF) { /* mode = 0 single line mode (equivalent to ReadLine) * mode = 1 LFLF mode (paragraph, blank line between entries) @@ -690,6 +690,7 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, int mode) uchar c; uchar finished; rsRetVal readCharRet; + sbool bPrevWasNL; DEFiRet; ASSERT(pThis != NULL); @@ -715,18 +716,25 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, int mode) CHKiRet(cstrFinalize(*ppCStr)); } else if(mode == 1) { finished=0; + bPrevWasNL = 0; while(finished == 0){ if(c != '\n') { CHKiRet(cstrAppendChar(*ppCStr, c)); CHKiRet(strmReadChar(pThis, &c)); + bPrevWasNL = 0; } else { if ((((*ppCStr)->iStrLen) > 0) ){ - if ((*ppCStr)->pBuf[(*ppCStr)->iStrLen -1 ] == '\n'){ - rsCStrTruncate(*ppCStr,1); /* remove the prior newline */ + if(bPrevWasNL) { + rsCStrTruncate(*ppCStr, (bEscapeLF) ? 4 : 1); /* remove the prior newline */ finished=1; } else { - CHKiRet(cstrAppendChar(*ppCStr, c)); + if(bEscapeLF) { + CHKiRet(rsCStrAppendStrWithLen(*ppCStr, (uchar*)"#012", sizeof("#012")-1)); + } else { + CHKiRet(cstrAppendChar(*ppCStr, c)); + } CHKiRet(strmReadChar(pThis, &c)); + bPrevWasNL = 1; } } else { finished=1; /* this is a blank line, a \n with nothing since the last complete record */ |