From cd2b24dfc45c4b115ace6d17ab0237511fef3d66 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 19 Feb 2008 10:30:42 +0000 Subject: - added doc on how expressions will work - cleaned up the stringbuf Construct interface - did some cleanup on stringbuf calls - we now have much better interfaces and macros --- ChangeLog | 3 + Makefile.am | 1 + cfsysline.c | 3 +- doc/Makefile.am | 1 + doc/expression.html | 24 ++++++++ doc/history.html | 4 +- doc/imfile.html | 9 +-- doc/professional_support.html | 125 +++--------------------------------------- expr.c | 68 +++++++++++------------ msg.c | 68 +++++++++++------------ obj-types.h | 5 +- obj.c | 6 +- outchannel.c | 4 +- parse.c | 27 ++++----- stream.c | 3 +- stringbuf.c | 31 +++++++---- stringbuf.h | 2 +- syslogd.c | 4 +- template.c | 11 ++-- 19 files changed, 157 insertions(+), 242 deletions(-) create mode 100644 doc/expression.html diff --git a/ChangeLog b/ChangeLog index 535bf4e3..1badc202 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ --------------------------------------------------------------------------- Version 3.12.0 (rgerhards), 2008-02-?? +- bugfix: debug.html was missing from release tarball - thanks to Michael + Biebl for bringing this to my attention +- some internal cleanup on the stringbuf object calling interface --------------------------------------------------------------------------- Version 3.11.3 (rgerhards), 2008-02-18 - fixed a bug in imklog which lead to duplicate message content in diff --git a/Makefile.am b/Makefile.am index bde71b8b..2b319401 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,6 +42,7 @@ rsyslogd_SOURCES = \ msg.c \ msg.h \ expr.c \ + expr.h \ omshell.c \ omshell.h \ omusrmsg.c \ diff --git a/cfsysline.c b/cfsysline.c index 7249188e..378bfe1d 100644 --- a/cfsysline.c +++ b/cfsysline.c @@ -453,8 +453,7 @@ getWord(uchar **pp, rsCStrObj **ppStrB) ASSERT(*pp != NULL); ASSERT(*ppStrB != NULL); - if((*ppStrB = rsCStrConstruct()) == NULL) - ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); + CHKiRet(rsCStrConstruct(ppStrB)); /* parse out the word */ p = *pp; diff --git a/doc/Makefile.am b/doc/Makefile.am index e081f88f..49a689c6 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -3,6 +3,7 @@ html_files = \ debug.html \ features.html \ generic_design.html \ + expression.html \ history.html \ how2help.html \ install.html \ diff --git a/doc/expression.html b/doc/expression.html new file mode 100644 index 00000000..51d99900 --- /dev/null +++ b/doc/expression.html @@ -0,0 +1,24 @@ + + +Expressions + + + +

Expressions

+

Rsyslog supports expressions at a growing number of places. So +far, they are supported for filtering messages.

+

+

Formal Definition

+ +

Below is the formal definition of expression format (in ABNF, RFC 2234):
+

expr     := e_and *("or" e_and)
e_and := e_cmp *("and" e_cmp)
e_cmp := val cmp_op val
val := ["+" / "-"] term *(("+" / "-") term)
term := factor *(("*" / "/" / "%") factor)
factor := ["not"] terminal
terminal := var / constant / function / "(" expr ")"
function := name "(" *("," expr) ")"
var := "$" varname
varname := msgvar / sysvar
msgvar := name
sysvar := "$" name
name := alpha *(alnum)
constant := string / number
string := simpstr / tplstr ; tplstr will be implemented in next phase
simpstr := "'" *char "'" ; use your imagination for char ;)
tplstr := '"' template '"' ; not initially implemented
number := 1*digit
cmp_op := "==" / "!=" / "<" / ">" / "<=" / ">="
digit := %x30-39
alpha := "a" ... "z" # all letters
alnum :* alpha / digit / "_"
+

[rsyslog.conf overview] +[manual index] [rsyslog site]

+

This documentation is part of the +rsyslog +project.
+Copyright © 2008 by Rainer +Gerhards and +Adiscon. +Released under the GNU GPL version 3 or higher.

+ \ No newline at end of file diff --git a/doc/history.html b/doc/history.html index 4e0b374a..ba6b6fc6 100644 --- a/doc/history.html +++ b/doc/history.html @@ -31,7 +31,7 @@ rather better control over the output format. So there we were, with a rsyslogd that covers a lot of enhancements, but not a single one of these that made its name ;) Since version 0.9.2, receiving syslog messages via plain tcp is finally supported, a bit later sending via -TCP, too. Starting with 1.11.0, RFC 3195 is finally support at the +TCP, too. Starting with 1.11.0, RFC 3195 is finally supported at the receiving side (a.k.a. "listener"). Support for sending via RFC 3195 is still due. Anyhow, rsyslog has come much closer to what it name promises.

@@ -118,4 +118,4 @@ Don't be shy to post to either the blog or the - \ No newline at end of file + diff --git a/doc/imfile.html b/doc/imfile.html index 3cc8308d..c35fd022 100644 --- a/doc/imfile.html +++ b/doc/imfile.html @@ -3,7 +3,6 @@ Text File Input Monitor -

Text File Input Module

Module Name:    imfile

@@ -58,12 +57,14 @@ specified multiple times. facility
The syslog facility to be assigned to lines read. Can be specified in textual form (e.g. "local0", "local1", ...) or as numbers (e.g. 128 for -"local0"). Textual form is suggested. Default  is "local0". +"local0"). Textual form is suggested. Default  is +"local0".
  • $InputFileSeverity
    The syslog severity to be assigned to lines read. Can be specified in textual form (e.g. "info", "warning", ...) or as numbers (e.g. 4 for -"info"). Textual form is suggested. Default is "notice".
  • +"info"). Textual form is suggested. Default +is "notice".
  • $InputRunFileMonitor
    This activates the current monitor. It has no parameters. If you forget this @@ -122,7 +123,7 @@ $InputFilePollingInterval 10

    This documentation is part of the rsyslog project.
    -Copyright © 2008 by Rainer +Copyright © 2008 by Rainer Gerhards and Adiscon. Released under the GNU GPL version 3 or higher.

    diff --git a/doc/professional_support.html b/doc/professional_support.html index 3cc8308d..83556b66 100644 --- a/doc/professional_support.html +++ b/doc/professional_support.html @@ -1,128 +1,19 @@ -Text File Input Monitor +Professional Support for Rsyslog - -

    Text File Input Module

    -

    Module Name:    imfile

    -

    Author: Rainer Gerhards -<rgerhards@adiscon.com>

    -

    Description:

    -

    Provides the ability to convert any standard text file into -a syslog message. A standard -text file is a file consisting of printable characters with lines -being delimited by LF.

    -

    The file is read line-by-line and any line read is passed to -rsyslog's rule engine. The rule engine applies filter conditons and -selects which actions needs to be carried out.

    -

    As new lines are written they are taken from the file and -processed. Please note that this happens based on a polling interval -and not immediately. The file monitor support file rotation. To fully -work, rsyslogd must run while the file is rotated. Then, any remaining -lines from the old file are read and processed and when done with that, -the new file is being processed from the beginning. If rsyslogd is -stopped during rotation, the new file is read, but any not-yet-reported -lines from the previous file can no longer be obtained.

    -

    When rsyslogd is stopped while monitoring a text file, it -records the last processed location and continues to work from there -upon restart. So no data is lost during a restart (except, as noted -above, if the file is rotated just in this very moment).

    -

    Currently, the file must have a fixed name and location -(directory). It is planned to add support for dynamically generating -file names in the future.

    -

    Multiple files may be monitored by specifying -$InputRunFileMonitor multiple times. -

    -

    Configuration Directives:

    - -Caveats/Known Bugs: -

    So far, only 100 files can be monitored. If more are needed, -the source needs to be patched. See define MAX_INPUT_FILES in imfile.c -

    -

    Sample:

    -

    The following sample monitors two files. If you need just one, -remove the second one. If you need more, add them according to the -sample ;). This code must be placed in /etc/rsyslog.conf (or wherever -your distro puts rsyslog's config files). Note that only commands -actually needed need to be specified. The second file uses less -commands and uses defaults instead.
    -

    - -

    [rsyslog.conf overview] -[manual index] [rsyslog site]

    +

    Professional Support for Rsyslog

    +

    Professional Support is offered by Adiscon, the company +that sponsored rsyslog development. For details, please either contact Adiscon Sales or +view our +offerings on the sourceforge market place.

    +

    [manual index] [rsyslog site]

    This documentation is part of the rsyslog project.
    -Copyright © 2008 by Rainer +Copyright © 2008 by Rainer Gerhards and Adiscon. Released under the GNU GPL version 3 or higher.

    diff --git a/expr.c b/expr.c index 448909d4..eb673a29 100644 --- a/expr.c +++ b/expr.c @@ -36,46 +36,43 @@ */ #include "config.h" - +#include #include #include "rsyslog.h" #include "template.h" -#include "stringbuf.h" +#include "expr.h" -/* This is the syntax of an expression. I keep it as inline documentation - * as this enhances the chance that it is updates should there be a change. - * - * expr = (simple-string / template-string / function / property) [* expr ] - * simple-string = "'" chars "'" - * template-string = '"' template-as--1.19.11-and-below '"' - * ; string as used in previous $template directive - * function = function-name "(" expr ")" - * property = [list of property names] - */ -/* a single expression node */ -typedef struct exprNode_s { -} exprNode_t; +/* static data */ +DEFobjStaticHelpers -/* the expression object */ -typedef struct expr_s { - exprNode_t enodeRoot; /* the root node where evaluation starts */ - /* a variant (or such) to hold the ultimate return value */ - /* for the time being, we just use a string. That still provides us the - * hooks for doing better later. - */ - rsCStrObj *cstrConst; -} expr_t; +/* Standard-Constructor + */ +BEGINobjConstruct(expr) /* be sure to specify the object type also in END macro! */ +ENDobjConstruct(expr) -/* the following three need to be implemented, I just provide some dummies for - * now -- rgerhards, 2008-02-13 +/* ConstructionFinalizer + * rgerhards, 2008-01-09 */ -static rsRetVal exprConstruct() { return RS_RET_OK; } -static rsRetVal exprFinalize() { return RS_RET_OK; } -static rsRetVal exprDestruct() { return RS_RET_OK; } -//exprDestruct MUST free the cstrConst! +rsRetVal exprConstructFinalize(strm_t *pThis) +{ + DEFiRet; + + ISOBJ_TYPE_assert(pThis, expr); + +finalize_it: + RETiRet; +} + + +/* destructor for the strm object */ +BEGINobjDestruct(expr) /* be sure to specify the object type also in END and CODESTART macros! */ +CODESTARTobjDestruct(expr) + /* ... then free resources */ +ENDobjDestruct(expr) + /* evaluate an expression and store the result. pMsg is optional, but if * it is not given, no message-based variables can be accessed. The expression @@ -87,7 +84,7 @@ exprEval(expr_t *pThis, msg_t *pMsg) { DEFiRet; - //ISOBJ_TYPE_assert(pThis, expr); + ISOBJ_TYPE_assert(pThis, expr); RETiRet; } @@ -108,7 +105,7 @@ exprGetStr(expr_t *pThis, rsCStrObj **ppStr) { DEFiRet; - //ISOBJ_TYPE_assert(pThis, expr); + ISOBJ_TYPE_assert(pThis, expr); ASSERT(ppStr != NULL); RETiRet; @@ -133,10 +130,7 @@ exprParseStr(expr_t **ppThis, uchar *p) CHKiRet(exprConstruct(&pThis)); - // TODO: use this method, but requires changing stringbuf.c: CHKiRet(rsCStrConstruct(&pThis->cstrConst)); - if((pThis->cstrConst = rsCStrConstruct()) == NULL) { - ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); - } + CHKiRet(rsCStrConstruct(&pThis->cstrConst)); /* so far, we are a dummy - we just pull the first string and * ignore the rest... @@ -155,7 +149,7 @@ exprParseStr(expr_t **ppThis, uchar *p) /* we are done with it... */ CHKiRet(rsCStrFinish(pThis->cstrConst)); - CHKiRet(exprFinalize(&pThis)); + CHKiRet(exprConstructFinalize(&pThis)); /* we are successfully done, so store the result */ *ppThis = pThis; diff --git a/msg.c b/msg.c index a5fc2bc7..72cb6a3b 100644 --- a/msg.c +++ b/msg.c @@ -467,13 +467,10 @@ static rsRetVal aquirePROCIDFromTAG(msg_t *pM) ++i; /* skip '[' */ /* now obtain the PROCID string... */ - if((pM->pCSPROCID = rsCStrConstruct()) == NULL) - return RS_RET_OBJ_CREATION_FAILED; /* best we can do... */ + CHKiRet(rsCStrConstruct(&pM->pCSPROCID)); rsCStrSetAllocIncrement(pM->pCSPROCID, 16); while((i < pM->iLenTAG) && (pM->pszTAG[i] != ']')) { - if((iRet = rsCStrAppendChar(pM->pCSPROCID, pM->pszTAG[i])) != RS_RET_OK) { - RETiRet; - } + CHKiRet(rsCStrAppendChar(pM->pCSPROCID, pM->pszTAG[i])); ++i; } @@ -485,14 +482,13 @@ static rsRetVal aquirePROCIDFromTAG(msg_t *pM) */ rsCStrDestruct(pM->pCSPROCID); pM->pCSPROCID = NULL; - return RS_RET_OK; + FINALIZE; } /* OK, finaally we could obtain a PROCID. So let's use it ;) */ - if((iRet = rsCStrFinish(pM->pCSPROCID)) != RS_RET_OK) { - RETiRet; - } + CHKiRet(rsCStrFinish(pM->pCSPROCID)); +finalize_it: RETiRet; } @@ -515,30 +511,26 @@ static rsRetVal aquirePROCIDFromTAG(msg_t *pM) */ static rsRetVal aquireProgramName(msg_t *pM) { - register int i; DEFiRet; + register int i; assert(pM != NULL); if(pM->pCSProgName == NULL) { /* ok, we do not yet have it. So let's parse the TAG * to obtain it. */ - if((pM->pCSProgName = rsCStrConstruct()) == NULL) - return RS_RET_OBJ_CREATION_FAILED; /* best we can do... */ + CHKiRet(rsCStrConstruct(&pM->pCSProgName)); rsCStrSetAllocIncrement(pM->pCSProgName, 33); for( i = 0 ; (i < pM->iLenTAG) && isprint((int) pM->pszTAG[i]) && (pM->pszTAG[i] != '\0') && (pM->pszTAG[i] != ':') && (pM->pszTAG[i] != '[') && (pM->pszTAG[i] != '/') ; ++i) { - if((iRet = rsCStrAppendChar(pM->pCSProgName, pM->pszTAG[i])) != RS_RET_OK) { - RETiRet; - } - } - if((iRet = rsCStrFinish(pM->pCSProgName)) != RS_RET_OK) { - RETiRet; + CHKiRet(rsCStrAppendChar(pM->pCSProgName, pM->pszTAG[i])); } + CHKiRet(rsCStrFinish(pM->pCSProgName)); } +finalize_it: RETiRet; } @@ -911,14 +903,13 @@ rsRetVal MsgSetAPPNAME(msg_t *pMsg, char* pszAPPNAME) assert(pMsg != NULL); if(pMsg->pCSAPPNAME == NULL) { /* we need to obtain the object first */ - if((pMsg->pCSAPPNAME = rsCStrConstruct()) == NULL) { - return RS_RET_OBJ_CREATION_FAILED; /* best we can do... */ - } + CHKiRet(rsCStrConstruct(&pMsg->pCSAPPNAME)); rsCStrSetAllocIncrement(pMsg->pCSAPPNAME, 128); } /* if we reach this point, we have the object */ iRet = rsCStrSetSzStr(pMsg->pCSAPPNAME, (uchar*) pszAPPNAME); +finalize_it: RETiRet; } @@ -941,15 +932,18 @@ char *getAPPNAME(msg_t *pM) */ rsRetVal MsgSetPROCID(msg_t *pMsg, char* pszPROCID) { - assert(pMsg != NULL); + DEFiRet; + ISOBJ_TYPE_assert(pMsg, msg); if(pMsg->pCSPROCID == NULL) { /* we need to obtain the object first */ - if((pMsg->pCSPROCID = rsCStrConstruct()) == NULL) - return RS_RET_OBJ_CREATION_FAILED; /* best we can do... */ + CHKiRet(rsCStrConstruct(&pMsg->pCSPROCID)); rsCStrSetAllocIncrement(pMsg->pCSPROCID, 128); } /* if we reach this point, we have the object */ - return rsCStrSetSzStr(pMsg->pCSPROCID, (uchar*) pszPROCID); + iRet = rsCStrSetSzStr(pMsg->pCSPROCID, (uchar*) pszPROCID); + +finalize_it: + RETiRet; } /* rgerhards, 2005-11-24 @@ -971,7 +965,7 @@ char *getPROCID(msg_t *pM) { char* pszRet; - assert(pM != NULL); + ISOBJ_TYPE_assert(pM, msg); MsgLock(pM); if(pM->pCSPROCID == NULL) aquirePROCIDFromTAG(pM); @@ -985,15 +979,18 @@ char *getPROCID(msg_t *pM) */ rsRetVal MsgSetMSGID(msg_t *pMsg, char* pszMSGID) { - assert(pMsg != NULL); + DEFiRet; + ISOBJ_TYPE_assert(pMsg, msg); if(pMsg->pCSMSGID == NULL) { /* we need to obtain the object first */ - if((pMsg->pCSMSGID = rsCStrConstruct()) == NULL) - return RS_RET_OBJ_CREATION_FAILED; /* best we can do... */ + CHKiRet(rsCStrConstruct(&pMsg->pCSMSGID)); rsCStrSetAllocIncrement(pMsg->pCSMSGID, 128); } /* if we reach this point, we have the object */ - return rsCStrSetSzStr(pMsg->pCSMSGID, (uchar*) pszMSGID); + iRet = rsCStrSetSzStr(pMsg->pCSMSGID, (uchar*) pszMSGID); + +finalize_it: + RETiRet; } /* rgerhards, 2005-11-24 @@ -1148,15 +1145,18 @@ char *getRcvFrom(msg_t *pM) */ rsRetVal MsgSetStructuredData(msg_t *pMsg, char* pszStrucData) { - assert(pMsg != NULL); + DEFiRet; + ISOBJ_TYPE_assert(pMsg, msg); if(pMsg->pCSStrucData == NULL) { /* we need to obtain the object first */ - if((pMsg->pCSStrucData = rsCStrConstruct()) == NULL) - return RS_RET_OBJ_CREATION_FAILED; /* best we can do... */ + CHKiRet(rsCStrConstruct(&pMsg->pCSStrucData)); rsCStrSetAllocIncrement(pMsg->pCSStrucData, 128); } /* if we reach this point, we have the object */ - return rsCStrSetSzStr(pMsg->pCSStrucData, (uchar*) pszStrucData); + iRet = rsCStrSetSzStr(pMsg->pCSStrucData, (uchar*) pszStrucData); + +finalize_it: + RETiRet; } /* get the length of the "STRUCTURED-DATA" sz string diff --git a/obj-types.h b/obj-types.h index 66dc4143..68f565dd 100644 --- a/obj-types.h +++ b/obj-types.h @@ -61,9 +61,10 @@ typedef enum { /* IDs of known object "types/classes" */ OBJstrm = 2, OBJwtp = 3, OBJwti = 4, - OBJqueue = 5 /* remeber to UPDATE OBJ_NUM_IDS (below) if you add one! */ + OBJqueue = 5, + OBJexpr = 6 /* remeber to UPDATE OBJ_NUM_IDS (below) if you add one! */ } objID_t; -#define OBJ_NUM_IDS 6 +#define OBJ_NUM_IDS 7 typedef enum { /* IDs of base methods supported by all objects - used for jump table, so * they must start at zero and be incremented. -- rgerahrds, 2008-01-04 diff --git a/obj.c b/obj.c index 1ae3b109..32818672 100644 --- a/obj.c +++ b/obj.c @@ -366,8 +366,7 @@ static rsRetVal objDeserializeStr(rsCStrObj **ppCStr, int iLen, strm_t *pStrm) assert(ppCStr != NULL); assert(iLen > 0); - if((pCStr = rsCStrConstruct()) == NULL) - ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); + CHKiRet(rsCStrConstruct(&pCStr)); NEXTC; for(i = 0 ; i < iLen ; ++i) { @@ -485,8 +484,7 @@ static rsRetVal objDeserializeProperty(property_t *pProp, strm_t *pStrm) } /* get the property name first */ - if((pProp->pcsName = rsCStrConstruct()) == NULL) - ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); + CHKiRet(rsCStrConstruct(&pProp->pcsName)); NEXTC; while(c != ':') { diff --git a/outchannel.c b/outchannel.c index fc2fd659..debe3b43 100644 --- a/outchannel.c +++ b/outchannel.c @@ -105,7 +105,7 @@ static int get_Field(uchar **pp, uchar **pField) skip_Comma((char**)pp); p = *pp; - if((pStrB = rsCStrConstruct()) == NULL) + if(rsCStrConstruct(&pStrB) != RS_RET_OK) return 1; rsCStrSetAllocIncrement(pStrB, 32); @@ -170,7 +170,7 @@ static inline int get_restOfLine(uchar **pp, uchar **pBuf) skip_Comma((char**)pp); p = *pp; - if((pStrB = rsCStrConstruct()) == NULL) + if(rsCStrConstruct(&pStrB) != RS_RET_OK) return 1; rsCStrSetAllocIncrement(pStrB, 32); diff --git a/parse.c b/parse.c index 3132b570..b7edba98 100644 --- a/parse.c +++ b/parse.c @@ -89,31 +89,31 @@ rsRetVal rsParsConstruct(rsParsObj **ppThis) */ rsRetVal rsParsConstructFromSz(rsParsObj **ppThis, unsigned char *psz) { + DEFiRet; rsParsObj *pThis; rsCStrObj *pCS; - rsRetVal iRet; assert(ppThis != NULL); assert(psz != NULL); /* create string for parser */ - if((iRet = rsCStrConstructFromszStr(&pCS, psz)) != RS_RET_OK) - return(iRet); + CHKiRet(rsCStrConstructFromszStr(&pCS, psz)); /* create parser */ if((iRet = rsParsConstruct(&pThis)) != RS_RET_OK) { rsCStrDestruct (pCS); - return(iRet); + FINALIZE; } /* assign string to parser */ if((iRet = rsParsAssignString(pThis, pCS)) != RS_RET_OK) { rsParsDestruct(pThis); - return(iRet); + FINALIZE; } - *ppThis = pThis; - return RS_RET_OK; + +finalize_it: + RETiRet; } /** @@ -241,14 +241,13 @@ rsRetVal parsSkipWhitespace(rsParsObj *pThis) */ rsRetVal parsDelimCStr(rsParsObj *pThis, rsCStrObj **ppCStr, char cDelim, int bTrimLeading, int bTrimTrailing) { + DEFiRet; register unsigned char *pC; rsCStrObj *pCStr; - DEFiRet; rsCHECKVALIDOBJECT(pThis, OIDrsPars); - if((pCStr = rsCStrConstruct()) == NULL) - ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); + CHKiRet(rsCStrConstruct(&pCStr)); if(bTrimLeading) parsSkipWhitespace(pThis); @@ -259,7 +258,7 @@ rsRetVal parsDelimCStr(rsParsObj *pThis, rsCStrObj **ppCStr, char cDelim, int bT && *pC != cDelim) { if((iRet = rsCStrAppendChar(pCStr, *pC)) != RS_RET_OK) { rsCStrDestruct (pCStr); - return(iRet); + FINALIZE; } ++pThis->iCurrPos; ++pC; @@ -319,8 +318,7 @@ rsRetVal parsQuotedCStr(rsParsObj *pThis, rsCStrObj **ppCStr) pC = rsCStrGetBufBeg(pThis->pCStr) + pThis->iCurrPos; /* OK, we most probably can obtain a value... */ - if((pCStr = rsCStrConstruct()) == NULL) - ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); + CHKiRet(rsCStrConstruct(&pCStr)); while(pThis->iCurrPos < rsCStrLen(pThis->pCStr)) { if(*pC == '"') { @@ -390,8 +388,7 @@ rsRetVal parsAddrWithBits(rsParsObj *pThis, struct NetAddr **pIP, int *pBits) assert(pIP != NULL); assert(pBits != NULL); - if((pCStr = rsCStrConstruct()) == NULL) - ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); + CHKiRet(rsCStrConstruct(&pCStr)); parsSkipWhitespace(pThis); pC = rsCStrGetBufBeg(pThis->pCStr) + pThis->iCurrPos; diff --git a/stream.c b/stream.c index 5cff2bc3..5adc0b7e 100644 --- a/stream.c +++ b/stream.c @@ -357,8 +357,7 @@ strmReadLine(strm_t *pThis, rsCStrObj **ppCStr) ASSERT(pThis != NULL); ASSERT(ppCStr != NULL); - if((pCStr = rsCStrConstruct()) == NULL) - ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); + CHKiRet(rsCStrConstruct(&pCStr)); /* now read the line */ CHKiRet(strmReadChar(pThis, &c)); diff --git a/stringbuf.c b/stringbuf.c index 7f3575cf..237355c0 100755 --- a/stringbuf.c +++ b/stringbuf.c @@ -50,12 +50,15 @@ * ################################################################# */ -rsCStrObj *rsCStrConstruct(void) +rsRetVal rsCStrConstruct(rsCStrObj **ppThis) { + DEFiRet; rsCStrObj *pThis; + ASSERT(ppThis != NULL); + if((pThis = (rsCStrObj*) calloc(1, sizeof(rsCStrObj))) == NULL) - return NULL; + ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); rsSETOBJTYPE(pThis, OIDrsCStr); pThis->pBuf = NULL; @@ -63,33 +66,38 @@ rsCStrObj *rsCStrConstruct(void) pThis->iBufSize = 0; pThis->iStrLen = 0; pThis->iAllocIncrement = RS_STRINGBUF_ALLOC_INCREMENT; + *ppThis = pThis; - return pThis; +finalize_it: + RETiRet; } + /* construct from sz string * rgerhards 2005-09-15 */ rsRetVal rsCStrConstructFromszStr(rsCStrObj **ppThis, uchar *sz) { + DEFiRet; rsCStrObj *pThis; assert(ppThis != NULL); - if((pThis = rsCStrConstruct()) == NULL) - return RS_RET_OUT_OF_MEMORY; + CHKiRet(rsCStrConstruct(&pThis)); pThis->iBufSize = pThis->iStrLen = strlen((char*)(char *) sz); if((pThis->pBuf = (uchar*) malloc(sizeof(uchar) * pThis->iStrLen)) == NULL) { RSFREEOBJ(pThis); - return RS_RET_OUT_OF_MEMORY; + ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); } /* we do NOT need to copy the \0! */ memcpy(pThis->pBuf, sz, pThis->iStrLen); *ppThis = pThis; - return RS_RET_OK; + +finalize_it: + RETiRet; } /* construct from CStr object. only the counted string is @@ -98,25 +106,26 @@ rsRetVal rsCStrConstructFromszStr(rsCStrObj **ppThis, uchar *sz) */ rsRetVal rsCStrConstructFromCStr(rsCStrObj **ppThis, rsCStrObj *pFrom) { + DEFiRet; rsCStrObj *pThis; assert(ppThis != NULL); rsCHECKVALIDOBJECT(pFrom, OIDrsCStr); - if((pThis = rsCStrConstruct()) == NULL) - return RS_RET_OUT_OF_MEMORY; + CHKiRet(rsCStrConstruct(&pThis)); pThis->iBufSize = pThis->iStrLen = pFrom->iStrLen; if((pThis->pBuf = (uchar*) malloc(sizeof(uchar) * pThis->iStrLen)) == NULL) { RSFREEOBJ(pThis); - return RS_RET_OUT_OF_MEMORY; + ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); } /* copy properties */ memcpy(pThis->pBuf, pFrom->pBuf, pThis->iStrLen); *ppThis = pThis; - return RS_RET_OK; +finalize_it: + RETiRet; } diff --git a/stringbuf.h b/stringbuf.h index 4649758a..123f59d7 100755 --- a/stringbuf.h +++ b/stringbuf.h @@ -55,7 +55,7 @@ typedef struct rsCStrObject rsCStrObj; /** * Construct a rsCStr object. */ -rsCStrObj *rsCStrConstruct(void); +rsRetVal rsCStrConstruct(rsCStrObj **ppThis); rsRetVal rsCStrConstructFromszStr(rsCStrObj **ppThis, uchar *sz); rsRetVal rsCStrConstructFromCStr(rsCStrObj **ppThis, rsCStrObj *pFrom); diff --git a/syslogd.c b/syslogd.c index 6923e89b..ec19dc03 100644 --- a/syslogd.c +++ b/syslogd.c @@ -2032,7 +2032,7 @@ static int parseLegacySyslogMsg(msg_t *pMsg, int flags) * the records: the code is currently clean, but we could optimize it! */ if(!bTAGCharDetected) { uchar *pszTAG; - if((pStrB = rsCStrConstruct()) == NULL) + if(rsCStrConstruct(&pStrB) != RS_RET_OK) return 1; rsCStrSetAllocIncrement(pStrB, 33); pWork = pBuf; @@ -3323,7 +3323,7 @@ rsRetVal cflineParseTemplateName(uchar** pp, omodStringRequest_t *pOMSR, int iEn tplName = (uchar*) strdup((char*)dfltTplName); } else { /* template specified, pick it up */ - if((pStrB = rsCStrConstruct()) == NULL) { + if(rsCStrConstruct(&pStrB) != RS_RET_OK) { glblHadMemShortage = 1; iRet = RS_RET_OUT_OF_MEMORY; goto finalize_it; diff --git a/template.c b/template.c index 12096c91..9a5a2651 100644 --- a/template.c +++ b/template.c @@ -78,10 +78,7 @@ rsRetVal tplToString(struct template *pTpl, msg_t *pMsg, uchar** ppSz) * free the obtained value (if requested). We continue this * loop until we got hold of all values. */ - if((pCStr = rsCStrConstruct()) == NULL) { - dbgprintf("memory shortage, tplToString failed\n"); - ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); - } + CHKiRet(rsCStrConstruct(&pCStr)); pTpe = pTpl->pEntryRoot; while(pTpe != NULL) { @@ -209,7 +206,7 @@ void doSQLEscape(uchar **pp, size_t *pLen, unsigned short *pbMustBeFreed, int es p = *pp; iLen = *pLen; - if((pStrB = rsCStrConstruct()) == NULL) { + if(rsCStrConstruct(&pStrB) != RS_RET_OK) { /* oops - no mem ... Do emergency... */ doSQLEmergencyEscape(p, escapeMode); return; @@ -323,7 +320,7 @@ static int do_Constant(unsigned char **pp, struct template *pTpl) p = *pp; - if((pStrB = rsCStrConstruct()) == NULL) + if(rsCStrConstruct(&pStrB) != RS_RET_OK) return 1; rsCStrSetAllocIncrement(pStrB, 32); /* process the message and expand escapes @@ -493,7 +490,7 @@ static int do_Parameter(unsigned char **pp, struct template *pTpl) p = (unsigned char*) *pp; - if((pStrB = rsCStrConstruct()) == NULL) + if(rsCStrConstruct(&pStrB) != RS_RET_OK) return 1; if((pTpe = tpeConstruct(pTpl)) == NULL) { -- cgit v1.2.3