summaryrefslogtreecommitdiffstats
path: root/expr.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-02-13 07:08:18 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-02-13 07:08:18 +0000
commit1e047df3b96edfaab2511faad58ab76c69ade42b (patch)
tree47b0f894820f2ecac3fc733fcf90e344620a6009 /expr.c
parentc7d04fade43cd7ac1514f11b95589140c441489e (diff)
downloadrsyslog-1e047df3b96edfaab2511faad58ab76c69ade42b.tar.gz
rsyslog-1e047df3b96edfaab2511faad58ab76c69ade42b.tar.xz
rsyslog-1e047df3b96edfaab2511faad58ab76c69ade42b.zip
added some code to expr.c - not yet to be used
Diffstat (limited to 'expr.c')
-rw-r--r--expr.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/expr.c b/expr.c
index 853e1727..c21f91a5 100644
--- a/expr.c
+++ b/expr.c
@@ -8,6 +8,15 @@
*
* Copyright 2007 Rainer Gerhards and Adiscon GmbH.
*
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * W A R N I N G
+ *
+ * This module is not really existing. The current code has never been
+ * tested or run. It is just some preparation for when we actually implement
+ * this fuctionality!
+ *
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ *
* This file is part of rsyslog.
*
* Rsyslog is free software: you can redistribute it and/or modify
@@ -26,6 +35,12 @@
* A copy of the GPL can be found in the file "COPYING" in this distribution.
*/
+#include "config.h"
+
+#include "rsyslog.h"
+#include "template.h"
+#include "stringbuf.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.
*
@@ -36,6 +51,121 @@
* function = function-name "(" expr ")"
* property = [list of property names]
*/
+/* a single expression node */
+typedef struct exprNode_s {
+} exprNode_t;
+
+
+/* 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;
+
+
+/* the following three need to be implemented, I just provide some dummies for
+ * now -- rgerhards, 2008-02-13
+ */
+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!
+
+/* 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
+ * must previously have been created.
+ * rgerhards, 2008-02-09
+ */
+rsRetVal
+exprEval(expr_t *pThis, msg_t *pMsg)
+{
+ DEFiRet;
+
+ ISOBJ_TYPE_assert(pThis, expr);
+
+ RETiRet;
+}
+
+
+/* returns the expression result as a string. The string is read-only and valid
+ * only as long as the expression exists and is not newly evaluated. If the caller
+ * needs to access it for an extended period of time, it must copy it. This is a
+ * performance optimization, as most expression results are expected to be used
+ * only for a brief period. In such cases, it saves us the need to copy the string.
+ * Also, it is assumed that most callers will hold their private expression. If it
+ * is not shared, the caller can count on the string to remain stable as long as it
+ * does not reevaluate the expression (via exprEval or other means) or destruct it.
+ * rgerhards, 2008-02-09
+ */
+rsRetVal
+exprGetStr(expr_t *pThis, rsCStrObj **ppStr)
+{
+ DEFiRet;
+
+ ISOBJ_TYPE_assert(pThis, expr);
+ ASSERT(ppStr != NULL);
+
+ RETiRet;
+}
+
+
+/* parse an expression from a string. The string MUST include the full expression. The
+ * expression object is only created if there is no error during parsing.
+ * The string is a standard C string. It must NOT contain anything else but the
+ * expression. Most importantly, it must not contain any comments after the
+ * expression.
+ * rgerhards, 2008-02-09 (a rainy tenerife return flight day ;))
+ */
+rsRetVal
+exprParseStr(expr_t **ppThis, uchar *p)
+{
+ DEFiRet;
+ expr_t *pThis = NULL;
+
+ ASSERT(ppThis != NULL);
+ ASSERT(p != NULL);
+
+ 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);
+ }
+
+ /* so far, we are a dummy - we just pull the first string and
+ * ignore the rest...
+ */
+ while(*p && *p != '"')
+ ++p; /* find begin of string */
+ if(*p == '"')
+ ++p; /* eat it */
+
+ /* we got it, now copy over everything up until the end of the string */
+ while(*p && *p != '"') {
+ CHKiRet(rsCStrAppendChar(pThis->cstrConst, *p));
+ ++p;
+ }
+
+ /* we are done with it... */
+ CHKiRet(rsCStrFinish(pThis->cstrConst));
+
+ CHKiRet(exprFinalize(&pThis));
+
+ /* we are successfully done, so store the result */
+ *ppThis = pThis;
+
+finalize_it:
+ if(iRet != RS_RET_OK) {
+ if(pThis != NULL)
+ exprDestruct(pThis);
+ }
+
+ RETiRet;
+}
/* vi:set ai:
*/