summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Makefile.am1
-rw-r--r--cfsysline.c3
-rw-r--r--doc/Makefile.am1
-rw-r--r--doc/expression.html24
-rw-r--r--doc/history.html4
-rw-r--r--doc/imfile.html9
-rw-r--r--doc/professional_support.html125
-rw-r--r--expr.c68
-rw-r--r--msg.c68
-rw-r--r--obj-types.h5
-rw-r--r--obj.c6
-rw-r--r--outchannel.c4
-rw-r--r--parse.c27
-rw-r--r--stream.c3
-rwxr-xr-xstringbuf.c31
-rwxr-xr-xstringbuf.h2
-rw-r--r--syslogd.c4
-rw-r--r--template.c11
19 files changed, 157 insertions, 242 deletions
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 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head>
+<meta http-equiv="Content-Language" content="en"><title>Expressions</title>
+
+</head>
+<body>
+<h1>Expressions</h1>
+<p>Rsyslog supports expressions at a growing number of places. So
+far, they are supported for filtering messages.</p>
+<p></p>
+<h2>Formal Definition</h2>
+
+<p>Below is the formal definition of expression format (in ABNF, RFC 2234):<br>
+</p><pre>expr := e_and *("or" e_and)<br>e_and := e_cmp *("and" e_cmp)<br>e_cmp := val cmp_op val<br>val := ["+" / "-"] term *(("+" / "-") term)<br>term := factor *(("*" / "/" / "%") factor)<br>factor := ["not"] terminal<br>terminal := var / constant / function / "(" expr ")"<br>function := name "(" *("," expr) ")"<br>var := "$" varname<br>varname := msgvar / sysvar<br>msgvar := name<br>sysvar := "$" name<br>name := alpha *(alnum)<br>constant := string / number<br>string := simpstr / tplstr ; tplstr will be implemented in next phase<br>simpstr := "'" *char "'" ; use your imagination for char ;)<br>tplstr := '"' template '"' ; not initially implemented<br>number := 1*digit<br>cmp_op := "==" / "!=" / "&lt;" / "&gt;" / "&lt;=" / "&gt;=" <br>digit := %x30-39<br>alpha := "a" ... "z" # all letters<br>alnum :* alpha / digit / "_"<br></pre>
+<p>[<a href="rsyslog_conf.html">rsyslog.conf overview</a>]
+[<a href="manual.html">manual index</a>] [<a href="http://www.rsyslog.com/">rsyslog site</a>]</p>
+<p><font size="2">This documentation is part of the
+<a href="http://www.rsyslog.com/">rsyslog</a>
+project.<br>
+Copyright © 2008 by <a href="http://www.gerhards.net/rainer">Rainer
+Gerhards</a> and
+<a href="http://www.adiscon.com/">Adiscon</a>.
+Released under the GNU GPL version 3 or higher.</font></p>
+</body></html> \ 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.</p>
@@ -118,4 +118,4 @@ Don't be shy to post to either the blog or the
<ul>
<li><a href="http://www.rsyslog.com/Topic4.phtml">the rsyslog change log</a></li>
</ul>
-</body></html> \ No newline at end of file
+</body></html>
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 @@
<meta http-equiv="Content-Language" content="en"><title>Text File Input Monitor</title>
</head>
-
<body>
<h1>Text File Input Module</h1>
<p><b>Module Name:&nbsp;&nbsp;&nbsp; imfile</b></p>
@@ -58,12 +57,14 @@ specified multiple times.</li>
facility</span><br>
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. <span style="font-weight: bold;">Default</span> &nbsp;is "local0".<span style="font-weight: bold;"></span></li>
+"local0"). Textual form is suggested. <span style="font-weight: bold;">Default</span> &nbsp;is
+"local0".<span style="font-weight: bold;"></span></li>
<li><span style="font-weight: bold;">$InputFileSeverity</span><br>
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. <span style="font-weight: bold;">Default</span> is "notice".</li>
+"info"). Textual form is suggested. <span style="font-weight: bold;">Default</span>
+is "notice".</li>
<li><span style="font-weight: bold;">$InputRunFileMonitor</span><br>
This <span style="font-weight: bold;">activates</span>
the current monitor. It has no parameters. If you forget this
@@ -122,7 +123,7 @@ $InputFilePollingInterval 10
<p><font size="2">This documentation is part of the
<a href="http://www.rsyslog.com/">rsyslog</a>
project.<br>
-Copyright © 2008 by <a href="http://www.gerhards.net/rainer">Rainer
+Copyright © 2008 by <a href="http://www.gerhards.net/rainer">Rainer
Gerhards</a> and
<a href="http://www.adiscon.com/">Adiscon</a>.
Released under the GNU GPL version 3 or higher.</font></p>
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 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
-<meta http-equiv="Content-Language" content="en"><title>Text File Input Monitor</title>
+<meta http-equiv="Content-Language" content="en"><title>Professional Support for Rsyslog</title>
</head>
-
<body>
-<h1>Text File Input Module</h1>
-<p><b>Module Name:&nbsp;&nbsp;&nbsp; imfile</b></p>
-<p><b>Author: </b>Rainer Gerhards
-&lt;rgerhards@adiscon.com&gt;</p>
-<p><b>Description</b>:</p>
-<p>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&nbsp;delimited by LF.</p>
-<p>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.</p>
-<p>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.</p>
-<p>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).</p>
-<p>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.</p>
-<p>Multiple files may be monitored by specifying
-$InputRunFileMonitor multiple times.
-</p>
-<p><b>Configuration Directives</b>:</p>
-<ul>
-<li><strong>$InputFileName&nbsp;/path/to/file</strong><br>
-The file being monitored. So far, this must be an absolute name (no
-macros or templates)</li>
-<li><span style="font-weight: bold;">$InputFileTag
-tag:</span><br>
-The tag to be used for messages that originate from this file. If you
-would like to see the colon after the tag, you need to specify it here
-(as shown above).</li>
-<li><span style="font-weight: bold;">$InputFileStateFile
-&lt;name-of-state-file&gt;</span><br>
-Rsyslog must keep track of which parts of the to be monitored file it
-already processed. This is done in the state file. This file always is
-created in the rsyslog working directory (configurable via
-$WorkDirectory). Be careful to use unique names for different files
-being monitored. If there are duplicates, all sorts of "interesting"
-things may happen. Rsyslog currently does not check if a name is
-specified multiple times.</li>
-<li><span style="font-weight: bold;">$InputFileFacility
-facility</span><br>
-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. <span style="font-weight: bold;">Default</span> &nbsp;is "local0".<span style="font-weight: bold;"></span></li>
-<li><span style="font-weight: bold;">$InputFileSeverity</span><br>
-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. <span style="font-weight: bold;">Default</span> is "notice".</li>
-<li><span style="font-weight: bold;">$InputRunFileMonitor</span><br>
-This <span style="font-weight: bold;">activates</span>
-the current monitor. It has no parameters. If you forget this
-directive, no file monitoring will take place.</li>
-<li><span style="font-weight: bold;">$InputFilePollInterval
-seconds</span><br>
-This is a global setting. It specifies how often files are to be polled
-for new data. The time specified is in seconds. The <span style="font-weight: bold;">default value</span> is 10
-seconds. Please note that future
-releases of imfile may support per-file polling intervals, but
-currently this is not the case. If multiple $InputFilePollInterval
-statements are present in rsyslog.conf, only the last one is used.<br>
-A short poll interval provides more rapid message forwarding, but
-requires more system ressources. While it is possible, we stongly
-recommend not to set the polling interval to 0 seconds. That will make
-rsyslogd become a CPU hog, taking up considerable ressources. It is
-supported, however, for the few very unusual situations where this
-level may be needed. Even if you need quick response, 1 seconds should
-be well enough. Please note that imfile keeps reading files as long as
-there is any data in them. So a "polling sleep" will only happen when
-nothing is left to be processed.</li>
-</ul>
-<b>Caveats/Known Bugs:</b>
-<p>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
-</p>
-<p><b>Sample:</b></p>
-<p>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.<br>
-</p>
-<textarea rows="15" cols="60">$ModLoad imfile.so #
-needs to be done just once
-# File 1
-$InputFileName /path/to/file1
-$InputFileTag tag1:
-$InputFileStateFile stat-file1
-$InputFileSeverity error
-$InputFileFacility local7
-$InputRunFileMonitor
-# File 2
-$InputFileName /path/to/file2
-$InputFileTag tag2:
-$InputFileStateFile stat-file2
-$InputRunFileMonitor
-# ... and so on ...
-#
-# check for new lines every 10 seconds
-$InputFilePollingInterval 10
-</textarea>
-<p>[<a href="rsyslog_conf.html">rsyslog.conf overview</a>]
-[<a href="manual.html">manual index</a>] [<a href="http://www.rsyslog.com/">rsyslog site</a>]</p>
+<h1>Professional Support for Rsyslog</h1>
+<p>Professional Support is offered by <a href="http://www.adiscon.com">Adiscon</a>, the company
+that sponsored rsyslog development. For details, please either contact <a href="mailto:info%40adiscon.com">Adiscon Sales</a> or
+view <a href="http://sourceforge.net/services/project_services.php?project_id=123448">our
+offerings on the sourceforge market place</a>.</p>
+<p>[<a href="manual.html">manual index</a>] [<a href="http://www.rsyslog.com/">rsyslog site</a>]</p>
<p><font size="2">This documentation is part of the
<a href="http://www.rsyslog.com/">rsyslog</a>
project.<br>
-Copyright © 2008 by <a href="http://www.gerhards.net/rainer">Rainer
+Copyright&nbsp;© 2008 by <a href="http://www.gerhards.net/rainer">Rainer
Gerhards</a> and
<a href="http://www.adiscon.com/">Adiscon</a>.
Released under the GNU GPL version 3 or higher.</font></p>
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 <stdlib.h>
#include <assert.h>
#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) {