From ba69aa639557cc57c6a07324567644eef2559e3b Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 8 Dec 2004 09:31:30 +0000 Subject: property option drop-last-lf added; some doc in test.conf --- syslogd.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'syslogd.c') diff --git a/syslogd.c b/syslogd.c index 8d611aba..067351f6 100644 --- a/syslogd.c +++ b/syslogd.c @@ -959,7 +959,7 @@ int Initialized = 0; /* set when we have initialized ourselves extern int errno; /* hardcoded standard templates (used for defaults) */ -static char template_TraditionalFormat[] = "\"%timegenerated% %HOSTNAME% %syslogtag%%msg%\n\""; +static char template_TraditionalFormat[] = "\"%timegenerated% %HOSTNAME% %syslogtag%%msg:::drop-last-lf%\n\""; static char template_WallFmt[] = "\"\r\n\7Message from syslogd@%HOSTNAME% at %timegenerated% ...\r\n %syslogtag%%msg%\n\r\""; static char template_StdFwdFmt[] = "\"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag%%msg%\""; static char template_StdUsrMsgFmt[] = "\" %syslogtag%%msg%\n\r\""; @@ -1924,14 +1924,12 @@ char *MsgGetProp(struct msg *pMsg, struct templateEntry *pTpe, unsigned short *p */ // ++iFrom; /* nbr of chars to skip! */ while(*pRes && iFrom) { - printf("%c", *pRes); --iFrom; ++pRes; } } /* OK, we are at the begin - now let's copy... */ while(*pRes && iLen) { - printf("%c", *pRes); *pBuf++ = *pRes; ++pRes; --iLen; @@ -1943,8 +1941,8 @@ char *MsgGetProp(struct msg *pMsg, struct templateEntry *pTpe, unsigned short *p *pbMustBeFreed = 1; } - /* case conversations (should go last, because so we are able to - * work on the smalles possible buffer). + /* case conversations (should go after substring, because so we are able to + * work on the smallest possible buffer). */ if(pTpe->data.field.eCaseConv != tplCaseConvNo) { /* we need to obtain a private copy */ @@ -1971,6 +1969,32 @@ char *MsgGetProp(struct msg *pMsg, struct templateEntry *pTpe, unsigned short *p *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) { + int iLen = strlen(pRes); + char *pBuf; + if(*(pRes + iLen - 1) == '\n') { + /* we have a LF! */ + /* check if we need to obtain a private copy */ + if(pbMustBeFreed == 0) { + /* ok, original copy, need a private one */ + pBuf = malloc((iLen + 1) * sizeof(char)); + if(pBuf == NULL) { + if(*pbMustBeFreed == 1) + free(pRes); + *pbMustBeFreed = 0; + return "**OUT OF MEMORY**"; + } + memcpy(pBuf, pRes, iLen - 1); + pRes = pBuf; + *pbMustBeFreed = 1; + } + *(pRes + iLen - 1) = '\0'; /* drop LF ;) */ + } + } + /*dprintf("MsgGetProp(\"%s\"): \"%s\"\n", pName, pRes); only for verbose debug logging */ return(pRes); } @@ -3654,7 +3678,7 @@ const char *cvthname(f) } hp = gethostbyaddr((char *) &f->sin_addr, sizeof(struct in_addr), \ f->sin_family); - if (hp == 0) { + if (hp == NULL) { dprintf("Host name for your address (%s) unknown.\n", inet_ntoa(f->sin_addr)); return (inet_ntoa(f->sin_addr)); -- cgit