summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-02-21 14:31:56 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-02-21 14:31:56 +0000
commit45136c665690534d934d0c0c188dbb18a0131b96 (patch)
tree50e774280a622de5dfc8b98707f0be6324aeb974
parent04622f7d2210cbb8036502afadf5bcdcb0394d28 (diff)
downloadrsyslog-45136c665690534d934d0c0c188dbb18a0131b96.tar.gz
rsyslog-45136c665690534d934d0c0c188dbb18a0131b96.tar.xz
rsyslog-45136c665690534d934d0c0c188dbb18a0131b96.zip
some more interface changes
-rw-r--r--conf.c19
-rw-r--r--ctok.c45
-rw-r--r--ctok.h23
-rw-r--r--ctok_token.c34
-rw-r--r--ctok_token.h19
-rw-r--r--expr.c111
-rw-r--r--expr.h8
-rw-r--r--obj-types.h18
-rw-r--r--var.c21
-rw-r--r--var.h17
-rw-r--r--vmop.h8
-rw-r--r--vmprg.h9
12 files changed, 222 insertions, 110 deletions
diff --git a/conf.c b/conf.c
index 89bc1c33..7140a98c 100644
--- a/conf.c
+++ b/conf.c
@@ -56,6 +56,7 @@
/* static data */
DEFobjCurrIf(expr)
+DEFobjCurrIf(ctok)
uchar *pModDir = NULL; /* read-only after startup */
/* The following global variables are used for building
@@ -733,7 +734,7 @@ dbgPrintAllDebugInfo();
static rsRetVal cflineProcessIfFilter(uchar **pline, register selector_t *f)
{
DEFiRet;
- ctok_t *ctok;
+ ctok_t *tok;
ctok_token_t *pToken;
ASSERT(pline != NULL);
@@ -750,28 +751,28 @@ dbgprintf("calling expression parser, pp %p ('%s')\n", *pline, *pline);
(*pline) += 3;
/* we first need a tokenizer... */
- CHKiRet(ctokConstruct(&ctok));
- CHKiRet(ctokSetpp(ctok, *pline));
- CHKiRet(ctokConstructFinalize(ctok));
+ CHKiRet(ctok.Construct(&tok));
+ CHKiRet(ctok.Setpp(tok, *pline));
+ CHKiRet(ctok.ConstructFinalize(tok));
/* now construct our expression */
CHKiRet(expr.Construct(&f->f_filterData.f_expr));
CHKiRet(expr.ConstructFinalize(f->f_filterData.f_expr));
/* ready to go... */
- CHKiRet(expr.Parse(f->f_filterData.f_expr, ctok));
+ CHKiRet(expr.Parse(f->f_filterData.f_expr, tok));
/* we now need to parse off the "then" - and note an error if it is
* missing...
*/
- CHKiRet(ctokGetToken(ctok, &pToken));
+ CHKiRet(ctok.GetToken(tok, &pToken));
if(pToken->tok != ctok_THEN) {
ABORT_FINALIZE(RS_RET_SYNTAX_ERROR);
}
/* we are done, so we now need to restore things */
- CHKiRet(ctokGetpp(ctok, pline));
- CHKiRet(ctokDestruct(&ctok));
+ CHKiRet(ctok.Getpp(tok, pline));
+ CHKiRet(ctok.Destruct(&tok));
dbgprintf("expression parser successfully ended, pp %p ('%s')\n", *pline, *pline);
@@ -1155,6 +1156,8 @@ rsRetVal confClassInit(void)
DEFiRet;
/* request objects we use */
CHKiRet(objUse(expr));
+ CHKiRet(objUse(ctok));
+
finalize_it:
RETiRet;
}
diff --git a/ctok.c b/ctok.c
index b0c24b9b..71b10098 100644
--- a/ctok.c
+++ b/ctok.c
@@ -40,6 +40,7 @@
/* static data */
DEFobjStaticHelpers
+DEFobjCurrIf(ctok_token)
/* Standard-Constructor
@@ -328,7 +329,7 @@ finalize_it:
* a programming error.
* rgerhards, 2008-02-20
*/
-rsRetVal
+static rsRetVal
ctokUngetToken(ctok_t *pThis, ctok_token_t *pToken)
{
DEFiRet;
@@ -373,7 +374,7 @@ finalize_it:
* back to ctokUngetToken().
* rgerhards, 2008-02-19
*/
-rsRetVal
+static rsRetVal
ctokGetToken(ctok_t *pThis, ctok_token_t **ppToken)
{
DEFiRet;
@@ -395,8 +396,8 @@ ctokGetToken(ctok_t *pThis, ctok_token_t **ppToken)
}
/* setup the stage - create our token */
- CHKiRet(ctok_tokenConstruct(&pToken));
- CHKiRet(ctok_tokenConstructFinalize(pToken));
+ CHKiRet(ctok_token.Construct(&pToken));
+ CHKiRet(ctok_token.ConstructFinalize(pToken));
/* find the next token. We may loop when we have inline comments */
do {
@@ -513,7 +514,7 @@ RUNLOG_VAR("%d", pToken->tok);
finalize_it:
if(iRet != RS_RET_OK) {
if(pToken != NULL)
- ctok_tokenDestruct(&pToken);
+ ctok_token.Destruct(&pToken);
}
RETiRet;
@@ -528,7 +529,7 @@ DEFpropSetMeth(ctok, pp, uchar*)
* partial parsing, so the rest must know where to start from...
* rgerhards, 2008-02-19
*/
-rsRetVal
+static rsRetVal
ctokGetpp(ctok_t *pThis, uchar **pp)
{
DEFiRet;
@@ -537,7 +538,39 @@ ctokGetpp(ctok_t *pThis, uchar **pp)
RETiRet;
}
+
+/* queryInterface function
+ * rgerhards, 2008-02-21
+ */
+BEGINobjQueryInterface(ctok)
+CODESTARTobjQueryInterface(ctok)
+ if(pIf->ifVersion != ctokCURR_IF_VERSION) { /* check for current version, increment on each change */
+ ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
+ }
+
+ /* ok, we have the right interface, so let's fill it
+ * Please note that we may also do some backwards-compatibility
+ * work here (if we can support an older interface version - that,
+ * of course, also affects the "if" above).
+ */
+ pIf->oID = OBJctok;
+
+ pIf->Construct = ctokConstruct;
+ pIf->ConstructFinalize = ctokConstructFinalize;
+ pIf->Destruct = ctokDestruct;
+ pIf->Getpp = ctokGetpp;
+ pIf->GetToken = ctokGetToken;
+ pIf->UngetToken = ctokUngetToken;
+ pIf->Setpp = ctokSetpp;
+finalize_it:
+ENDobjQueryInterface(ctok)
+
+
+
BEGINObjClassInit(ctok, 1) /* class, version */
+ /* request objects we use */
+ CHKiRet(objUse(ctok_token));
+
OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, ctokConstructFinalize);
ENDObjClassInit(ctok)
diff --git a/ctok.h b/ctok.h
index 26dae5f1..aa1af4e0 100644
--- a/ctok.h
+++ b/ctok.h
@@ -35,14 +35,21 @@ typedef struct ctok_s {
} ctok_t;
+/* interfaces */
+BEGINinterface(ctok) /* name must also be changed in ENDinterface macro! */
+ INTERFACEObjDebugPrint(ctok);
+ INTERFACEpropSetMeth(ctok, pp, uchar*);
+ rsRetVal (*Construct)(ctok_t **ppThis);
+ rsRetVal (*ConstructFinalize)(ctok_t __attribute__((unused)) *pThis);
+ rsRetVal (*Destruct)(ctok_t **ppThis);
+ rsRetVal (*Getpp)(ctok_t *pThis, uchar **pp);
+ rsRetVal (*GetToken)(ctok_t *pThis, ctok_token_t **ppToken);
+ rsRetVal (*UngetToken)(ctok_t *pThis, ctok_token_t *pToken);
+ENDinterface(ctok)
+#define ctokCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
+
+
/* prototypes */
-rsRetVal ctokConstruct(ctok_t **ppThis);
-rsRetVal ctokConstructFinalize(ctok_t __attribute__((unused)) *pThis);
-rsRetVal ctokDestruct(ctok_t **ppThis);
-rsRetVal ctokGetpp(ctok_t *pThis, uchar **pp);
-rsRetVal ctokGetToken(ctok_t *pThis, ctok_token_t **ppToken);
-rsRetVal ctokUngetToken(ctok_t *pThis, ctok_token_t *pToken);
-PROTOTYPEObjClassInit(ctok);
-PROTOTYPEpropSetMeth(ctok, pp, uchar*);
+PROTOTYPEObj(ctok);
#endif /* #ifndef INCLUDED_CTOK_H */
diff --git a/ctok_token.c b/ctok_token.c
index 11667323..a7acabd2 100644
--- a/ctok_token.c
+++ b/ctok_token.c
@@ -66,7 +66,7 @@ ENDobjDestruct(ctok_token)
* caller is responsible for destructing it.
* rgerhards, 2008-02-20
*/
-rsRetVal
+static rsRetVal
ctok_tokenUnlinkCStr(ctok_token_t *pThis, cstr_t **ppCStr)
{
DEFiRet;
@@ -80,6 +80,38 @@ ctok_tokenUnlinkCStr(ctok_token_t *pThis, cstr_t **ppCStr)
RETiRet;
}
+
+/* tell the caller if the supplied token is a compare operation */
+static int ctok_tokenIsCmpOp(ctok_token_t *pThis)
+{
+ return(pThis->tok >= ctok_CMP_EQ && pThis->tok <= ctok_CMP_GTEQ);
+}
+
+/* queryInterface function
+ * rgerhards, 2008-02-21
+ */
+BEGINobjQueryInterface(ctok_token)
+CODESTARTobjQueryInterface(ctok_token)
+ if(pIf->ifVersion != ctok_tokenCURR_IF_VERSION) { /* check for current version, increment on each change */
+ ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
+ }
+
+ /* ok, we have the right interface, so let's fill it
+ * Please note that we may also do some backwards-compatibility
+ * work here (if we can support an older interface version - that,
+ * of course, also affects the "if" above).
+ */
+ pIf->oID = OBJctok_token;
+
+ pIf->Construct = ctok_tokenConstruct;
+ pIf->ConstructFinalize = ctok_tokenConstructFinalize;
+ pIf->Destruct = ctok_tokenDestruct;
+ pIf->UnlinkCStr = ctok_tokenUnlinkCStr;
+ pIf->IsCmpOp = ctok_tokenIsCmpOp;
+finalize_it:
+ENDobjQueryInterface(ctok_token)
+
+
BEGINObjClassInit(ctok_token, 1) /* class, version */
OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, ctok_tokenConstructFinalize);
ENDObjClassInit(ctok_token)
diff --git a/ctok_token.h b/ctok_token.h
index a93cfe49..4ea88d1a 100644
--- a/ctok_token.h
+++ b/ctok_token.h
@@ -65,15 +65,20 @@ typedef struct {
int64 intVal;
} ctok_token_t;
-/* defines to handle compare operation tokens in a single if... */
-#define ctok_tokenIsCmpOp(x) ((x)->tok >= ctok_CMP_EQ && (x)->tok <= ctok_CMP_GTEQ)
+
+/* interfaces */
+BEGINinterface(ctok_token) /* name must also be changed in ENDinterface macro! */
+ INTERFACEObjDebugPrint(ctok_token);
+ rsRetVal (*Construct)(ctok_token_t **ppThis);
+ rsRetVal (*ConstructFinalize)(ctok_token_t __attribute__((unused)) *pThis);
+ rsRetVal (*Destruct)(ctok_token_t **ppThis);
+ rsRetVal (*UnlinkCStr)(ctok_token_t *pThis, cstr_t **ppCStr);
+ int (*IsCmpOp)(ctok_token_t *pThis);
+ENDinterface(ctok_token)
+#define ctok_tokenCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
/* prototypes */
-rsRetVal ctok_tokenConstruct(ctok_token_t **ppThis);
-rsRetVal ctok_tokenConstructFinalize(ctok_token_t __attribute__((unused)) *pThis);
-rsRetVal ctok_tokenDestruct(ctok_token_t **ppThis);
-rsRetVal ctok_tokenUnlinkCStr(ctok_token_t *pThis, cstr_t **ppCStr);
-PROTOTYPEObjClassInit(ctok_token);
+PROTOTYPEObj(ctok_token);
#endif /* #ifndef INCLUDED_CTOK_TOKEN_H */
diff --git a/expr.c b/expr.c
index 785d4216..23284b10 100644
--- a/expr.c
+++ b/expr.c
@@ -38,6 +38,8 @@
DEFobjStaticHelpers
DEFobjCurrIf(vmprg)
DEFobjCurrIf(var)
+DEFobjCurrIf(ctok_token)
+DEFobjCurrIf(ctok)
/* ------------------------------ parser functions ------------------------------ */
@@ -53,11 +55,11 @@ DEFobjCurrIf(var)
*/
/* forward definiton - thanks to recursive ABNF, we can not avoid at least one ;) */
-static rsRetVal expr(expr_t *pThis, ctok_t *ctok);
+static rsRetVal expr(expr_t *pThis, ctok_t *tok);
static rsRetVal
-terminal(expr_t *pThis, ctok_t *ctok)
+terminal(expr_t *pThis, ctok_t *tok)
{
DEFiRet;
ctok_token_t *pToken;
@@ -65,19 +67,18 @@ terminal(expr_t *pThis, ctok_t *ctok)
cstr_t *pCStr;
ISOBJ_TYPE_assert(pThis, expr);
- ISOBJ_TYPE_assert(ctok, ctok);
+ ISOBJ_TYPE_assert(tok, ctok);
- CHKiRet(ctokGetToken(ctok, &pToken));
+ CHKiRet(ctok.GetToken(tok, &pToken));
switch(pToken->tok) {
case ctok_SIMPSTR:
CHKiRet(var.Construct(&pVar));
CHKiRet(var.ConstructFinalize(pVar));
- CHKiRet(ctok_tokenUnlinkCStr(pToken, &pCStr));
+ CHKiRet(ctok_token.UnlinkCStr(pToken, &pCStr));
CHKiRet(var.SetString(pVar, pCStr));
dbgoprint((obj_t*) pThis, "simpstr\n");
CHKiRet(vmprg.AddVarOperation(pThis->pVmprg, opcode_PUSHCONSTANT, pVar)); /* add to program */
- // push val
break;
case ctok_NUMBER:
dbgoprint((obj_t*) pThis, "number\n");
@@ -101,12 +102,12 @@ terminal(expr_t *pThis, ctok_t *ctok)
break;
case ctok_LPAREN:
dbgoprint((obj_t*) pThis, "expr\n");
- CHKiRet(ctok_tokenDestruct(&pToken)); /* "eat" processed token */
- CHKiRet(expr(pThis, ctok));
- CHKiRet(ctokGetToken(ctok, &pToken)); /* get next one */
+ CHKiRet(ctok_token.Destruct(&pToken)); /* "eat" processed token */
+ CHKiRet(expr(pThis, tok));
+ CHKiRet(ctok.GetToken(tok, &pToken)); /* get next one */
if(pToken->tok != ctok_RPAREN)
ABORT_FINALIZE(RS_RET_SYNTAX_ERROR);
- CHKiRet(ctok_tokenDestruct(&pToken)); /* "eat" processed token */
+ CHKiRet(ctok_token.Destruct(&pToken)); /* "eat" processed token */
dbgoprint((obj_t*) pThis, "end expr, rparen eaten\n");
break;
default:
@@ -120,24 +121,24 @@ finalize_it:
}
static rsRetVal
-factor(expr_t *pThis, ctok_t *ctok)
+factor(expr_t *pThis, ctok_t *tok)
{
DEFiRet;
ctok_token_t *pToken;
ISOBJ_TYPE_assert(pThis, expr);
- ISOBJ_TYPE_assert(ctok, ctok);
+ ISOBJ_TYPE_assert(tok, ctok);
- CHKiRet(ctokGetToken(ctok, &pToken));
+ CHKiRet(ctok.GetToken(tok, &pToken));
if(pToken->tok == ctok_NOT) {
dbgprintf("not\n");
- CHKiRet(ctok_tokenDestruct(&pToken)); /* no longer needed */
- CHKiRet(ctokGetToken(ctok, &pToken)); /* get next one */
+ CHKiRet(ctok_token.Destruct(&pToken)); /* no longer needed */
+ CHKiRet(ctok.GetToken(tok, &pToken)); /* get next one */
} else {
/* we could not process the token, so push it back */
- CHKiRet(ctokUngetToken(ctok, pToken));
+ CHKiRet(ctok.UngetToken(tok, pToken));
}
- CHKiRet(terminal(pThis, ctok));
+ CHKiRet(terminal(pThis, tok));
// vm: not
finalize_it:
@@ -146,14 +147,14 @@ finalize_it:
static rsRetVal
-term(expr_t *pThis, ctok_t *ctok)
+term(expr_t *pThis, ctok_t *tok)
{
DEFiRet;
ISOBJ_TYPE_assert(pThis, expr);
- ISOBJ_TYPE_assert(ctok, ctok);
+ ISOBJ_TYPE_assert(tok, ctok);
- CHKiRet(factor(pThis, ctok));
+ CHKiRet(factor(pThis, tok));
// vm: +/-
finalize_it:
@@ -161,27 +162,27 @@ finalize_it:
}
static rsRetVal
-val(expr_t *pThis, ctok_t *ctok)
+val(expr_t *pThis, ctok_t *tok)
{
DEFiRet;
ctok_token_t *pToken;
ISOBJ_TYPE_assert(pThis, expr);
- ISOBJ_TYPE_assert(ctok, ctok);
+ ISOBJ_TYPE_assert(tok, ctok);
- CHKiRet(ctokGetToken(ctok, &pToken));
+ CHKiRet(ctok.GetToken(tok, &pToken));
if(pToken->tok == ctok_PLUS || pToken->tok == ctok_MINUS) {
/* TODO: this must be a loop! */
dbgprintf("plus/minus\n");
- CHKiRet(ctok_tokenDestruct(&pToken)); /* no longer needed */
+ CHKiRet(ctok_token.Destruct(&pToken)); /* no longer needed */
// vm: +/-???
- CHKiRet(ctokGetToken(ctok, &pToken)); /* get next one */
+ CHKiRet(ctok.GetToken(tok, &pToken)); /* get next one */
} else {
/* we could not process the token, so push it back */
- CHKiRet(ctokUngetToken(ctok, pToken));
+ CHKiRet(ctok.UngetToken(tok, pToken));
}
- CHKiRet(term(pThis, ctok));
+ CHKiRet(term(pThis, tok));
finalize_it:
RETiRet;
@@ -189,26 +190,26 @@ finalize_it:
static rsRetVal
-e_cmp(expr_t *pThis, ctok_t *ctok)
+e_cmp(expr_t *pThis, ctok_t *tok)
{
DEFiRet;
ctok_token_t *pToken;
ISOBJ_TYPE_assert(pThis, expr);
- ISOBJ_TYPE_assert(ctok, ctok);
+ ISOBJ_TYPE_assert(tok, ctok);
- CHKiRet(val(pThis, ctok));
+ CHKiRet(val(pThis, tok));
/* 0*1(cmp_op val) part */
- CHKiRet(ctokGetToken(ctok, &pToken));
- if(ctok_tokenIsCmpOp(pToken)) {
+ CHKiRet(ctok.GetToken(tok, &pToken));
+ if(ctok_token.IsCmpOp(pToken)) {
dbgoprint((obj_t*) pThis, "cmp\n");
- CHKiRet(val(pThis, ctok));
+ CHKiRet(val(pThis, tok));
CHKiRet(vmprg.AddVarOperation(pThis->pVmprg, (opcode_t) pToken->tok, NULL)); /* add to program */
- CHKiRet(ctok_tokenDestruct(&pToken)); /* no longer needed */
+ CHKiRet(ctok_token.Destruct(&pToken)); /* no longer needed */
} else {
/* we could not process the token, so push it back */
- CHKiRet(ctokUngetToken(ctok, pToken));
+ CHKiRet(ctok.UngetToken(tok, pToken));
}
@@ -218,31 +219,31 @@ finalize_it:
static rsRetVal
-e_and(expr_t *pThis, ctok_t *ctok)
+e_and(expr_t *pThis, ctok_t *tok)
{
DEFiRet;
ctok_token_t *pToken;
ISOBJ_TYPE_assert(pThis, expr);
- ISOBJ_TYPE_assert(ctok, ctok);
+ ISOBJ_TYPE_assert(tok, ctok);
- CHKiRet(e_cmp(pThis, ctok));
+ CHKiRet(e_cmp(pThis, tok));
/* *("and" e_cmp) part */
- CHKiRet(ctokGetToken(ctok, &pToken));
+ CHKiRet(ctok.GetToken(tok, &pToken));
while(pToken->tok == ctok_AND) {
dbgoprint((obj_t*) pThis, "and\n");
/* fill structure */
- CHKiRet(ctok_tokenDestruct(&pToken)); /* no longer needed */
- CHKiRet(e_cmp(pThis, ctok));
+ CHKiRet(ctok_token.Destruct(&pToken)); /* no longer needed */
+ CHKiRet(e_cmp(pThis, tok));
CHKiRet(vmprg.AddVarOperation(pThis->pVmprg, opcode_AND, NULL)); /* add to program */
- CHKiRet(ctokGetToken(ctok, &pToken));
+ CHKiRet(ctok.GetToken(tok, &pToken));
}
/* unget the token that made us exit the loop - it's obviously not one
* we can process.
*/
- CHKiRet(ctokUngetToken(ctok, pToken));
+ CHKiRet(ctok.UngetToken(tok, pToken));
finalize_it:
RETiRet;
@@ -250,31 +251,31 @@ finalize_it:
static rsRetVal
-expr(expr_t *pThis, ctok_t *ctok)
+expr(expr_t *pThis, ctok_t *tok)
{
DEFiRet;
ctok_token_t *pToken;
ISOBJ_TYPE_assert(pThis, expr);
- ISOBJ_TYPE_assert(ctok, ctok);
+ ISOBJ_TYPE_assert(tok, ctok);
- CHKiRet(e_and(pThis, ctok));
+ CHKiRet(e_and(pThis, tok));
/* *("or" e_and) part */
- CHKiRet(ctokGetToken(ctok, &pToken));
+ CHKiRet(ctok.GetToken(tok, &pToken));
while(pToken->tok == ctok_OR) {
/* fill structure */
dbgoprint((obj_t*) pThis, "found OR\n");
- CHKiRet(ctok_tokenDestruct(&pToken)); /* no longer needed */
- CHKiRet(e_and(pThis, ctok));
+ CHKiRet(ctok_token.Destruct(&pToken)); /* no longer needed */
+ CHKiRet(e_and(pThis, tok));
CHKiRet(vmprg.AddVarOperation(pThis->pVmprg, opcode_OR, NULL)); /* add to program */
- CHKiRet(ctokGetToken(ctok, &pToken));
+ CHKiRet(ctok.GetToken(tok, &pToken));
}
/* unget the token that made us exit the loop - it's obviously not one
* we can process.
*/
- CHKiRet(ctokUngetToken(ctok, pToken));
+ CHKiRet(ctok.UngetToken(tok, pToken));
finalize_it:
RETiRet;
@@ -356,19 +357,19 @@ exprGetStr(expr_t *pThis, cstr_t **ppStr)
* rgerhards, 2008-02-19
*/
rsRetVal
-exprParse(expr_t *pThis, ctok_t *ctok)
+exprParse(expr_t *pThis, ctok_t *tok)
{
DEFiRet;
ISOBJ_TYPE_assert(pThis, expr);
- ISOBJ_TYPE_assert(ctok, ctok);
+ ISOBJ_TYPE_assert(tok, ctok);
/* first, we need to make sure we have a program where we can add to what we parse... */
CHKiRet(vmprg.Construct(&pThis->pVmprg));
CHKiRet(vmprg.ConstructFinalize(pThis->pVmprg));
/* happy parsing... */
- CHKiRet(expr(pThis, ctok));
+ CHKiRet(expr(pThis, tok));
dbgoprint((obj_t*) pThis, "successfully parsed/created expression\n");
vmprg.DebugPrint(pThis->pVmprg);
@@ -409,6 +410,8 @@ BEGINObjClassInit(expr, 1) /* class, version */
/* request objects we use */
CHKiRet(objUse(vmprg));
CHKiRet(objUse(var));
+ CHKiRet(objUse(ctok_token));
+ CHKiRet(objUse(ctok));
OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, exprConstructFinalize);
ENDObjClassInit(expr)
diff --git a/expr.h b/expr.h
index 78005a5a..34816952 100644
--- a/expr.h
+++ b/expr.h
@@ -40,18 +40,16 @@ typedef struct expr_s {
/* interfaces */
-typedef struct expr_if_s {
- ifBEGIN; /* This MUST always be the first interface member */
+BEGINinterface(expr) /* name must also be changed in ENDinterface macro! */
INTERFACEObjDebugPrint(expr);
rsRetVal (*Construct)(expr_t **ppThis);
rsRetVal (*ConstructFinalize)(expr_t __attribute__((unused)) *pThis);
rsRetVal (*Destruct)(expr_t **ppThis);
rsRetVal (*Parse)(expr_t *pThis, ctok_t *ctok);
-} expr_if_t;
+ENDinterface(expr)
#define exprCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
/* prototypes */
-PROTOTYPEObjClassInit(expr);
-PROTOTYPEObjQueryInterface(expr);
+PROTOTYPEObj(expr);
#endif /* #ifndef INCLUDED_EXPR_H */
diff --git a/obj-types.h b/obj-types.h
index 3046e96f..ee82c49f 100644
--- a/obj-types.h
+++ b/obj-types.h
@@ -138,6 +138,8 @@ typedef struct obj { /* the dummy struct that each derived class can be casted t
}
#define PROTOTYPEpropSetMeth(obj, prop, dataType)\
rsRetVal obj##Set##prop(obj##_t *pThis, dataType pVal)
+#define INTERFACEpropSetMeth(obj, prop, dataType)\
+ rsRetVal (*Set##prop)(obj##_t *pThis, dataType)
/* class initializer */
#define PROTOTYPEObjClassInit(objName) rsRetVal objName##ClassInit(void)
#define BEGINObjClassInit(objName, objVers) \
@@ -288,6 +290,7 @@ finalize_it: \
#define ENDobjQueryInterface(obj) \
RETiRet; \
}
+
/* the base data type for interfaces
* This MUST be in sync with the ifBEGIN macro
*/
@@ -297,6 +300,15 @@ typedef struct interface_s {
} interface_t;
+/* the following macros should be used to define interfaces inside the
+ * header files.
+ */
+#define BEGINinterface(obj) \
+ typedef struct obj##_if_s {\
+ ifBEGIN; /* This MUST always be the first interface member */
+#define ENDinterface(obj) \
+ } obj##_if_t;
+
/* the following macro is used to get access to an object (not an instance,
* just the class itself!). It must be called before any of the object's
* methods can be accessed.
@@ -316,6 +328,12 @@ typedef struct interface_s {
#define DEFobjCurrIf(obj) \
static obj##_if_t obj = { .ifVersion = obj##CURR_IF_VERSION };
+/* define the prototypes for a class - when we use interfaces, we just have few
+ * functions that actually need to be non-static.
+ */
+#define PROTOTYPEObj(obj) \
+ PROTOTYPEObjClassInit(obj); \
+ PROTOTYPEObjQueryInterface(obj) \
/* ------------------------------ end object loader system ------------------------------ */
diff --git a/var.c b/var.c
index 308bd684..c4cf0b9b 100644
--- a/var.c
+++ b/var.c
@@ -102,8 +102,7 @@ varUnsetValues(var_t *pThis)
}
-/* set a string value
- */
+/* set a string value */
static rsRetVal
varSetString(var_t *pThis, cstr_t *pCStr)
{
@@ -120,6 +119,23 @@ finalize_it:
}
+/* set an int64 value */
+static rsRetVal
+varSetInt64(var_t *pThis, int64 iVal)
+{
+ DEFiRet;
+
+ ISOBJ_TYPE_assert(pThis, var);
+
+ CHKiRet(varUnsetValues(pThis));
+ pThis->varType = VARTYPE_INT64;
+ pThis->val.vInt64 = iVal;
+
+finalize_it:
+ RETiRet;
+}
+
+
/* queryInterface function
* rgerhards, 2008-02-21
*/
@@ -140,6 +156,7 @@ CODESTARTobjQueryInterface(var)
pIf->ConstructFinalize = varConstructFinalize;
pIf->Destruct = varDestruct;
pIf->DebugPrint = varDebugPrint;
+ pIf->SetInt64 = varSetInt64;
pIf->SetString = varSetString;
finalize_it:
ENDobjQueryInterface(var)
diff --git a/var.h b/var.h
index f400b109..24efca7b 100644
--- a/var.h
+++ b/var.h
@@ -31,8 +31,9 @@ typedef enum {
VARTYPE_SHORT = 2,
VARTYPE_INT = 3,
VARTYPE_LONG = 4,
- VARTYPE_CSTR = 5,
- VARTYPE_SYSLOGTIME = 6
+ VARTYPE_INT64 = 5,
+ VARTYPE_CSTR = 6,
+ VARTYPE_SYSLOGTIME = 7
} varType_t;
/* the var object */
@@ -44,6 +45,7 @@ typedef struct var_s {
short vShort;
int vInt;
long vLong;
+ int64 vInt64;
cstr_t *vpCStr; /* used for both rsCStr and psz */
syslogTime_t vSyslogTime;
@@ -52,19 +54,18 @@ typedef struct var_s {
/* interfaces */
-typedef struct var_if_s {
- ifBEGIN; /* This MUST always be the first interface member */
+BEGINinterface(var) /* name must also be changed in ENDinterface macro! */
INTERFACEObjDebugPrint(var);
rsRetVal (*Construct)(var_t **ppThis);
rsRetVal (*ConstructFinalize)(var_t __attribute__((unused)) *pThis);
rsRetVal (*Destruct)(var_t **ppThis);
+ rsRetVal (*SetInt64)(var_t *pThis, int64 iVal);
rsRetVal (*SetString)(var_t *pThis, cstr_t *pCStr);
-} var_if_t;
-#define varCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
+ENDinterface(var)
+#define varCURR_IF_VERSION 1 /* increment whenever you change the interface above! */
/* prototypes */
-PROTOTYPEObjClassInit(var);
-PROTOTYPEObjQueryInterface(var);
+PROTOTYPEObj(var);
#endif /* #ifndef INCLUDED_VAR_H */
diff --git a/vmop.h b/vmop.h
index 6964f7fd..dea54dbd 100644
--- a/vmop.h
+++ b/vmop.h
@@ -67,8 +67,7 @@ typedef struct vmop_s {
/* interfaces */
-typedef struct vmop_if_s {
- ifBEGIN; /* This MUST always be the first interface member */
+BEGINinterface(vmop) /* name must also be changed in ENDinterface macro! */
INTERFACEObjDebugPrint(vmop);
rsRetVal (*Construct)(vmop_t **ppThis);
rsRetVal (*ConstructFinalize)(vmop_t __attribute__((unused)) *pThis);
@@ -76,11 +75,10 @@ typedef struct vmop_if_s {
rsRetVal (*SetOpcode)(vmop_t *pThis, opcode_t opcode);
rsRetVal (*SetVar)(vmop_t *pThis, var_t *pVar);
rsRetVal (*Opcode2Str)(vmop_t *pThis, uchar **ppName);
-} vmop_if_t;
+ENDinterface(vmop)
#define vmopCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
/* the remaining prototypes */
-PROTOTYPEObjClassInit(vmop);
-PROTOTYPEObjQueryInterface(vmop);
+PROTOTYPEObj(vmop);
#endif /* #ifndef INCLUDED_VMOP_H */
diff --git a/vmprg.h b/vmprg.h
index f69abca1..71e77e19 100644
--- a/vmprg.h
+++ b/vmprg.h
@@ -48,21 +48,18 @@ typedef struct vmprg_s {
/* interfaces */
-typedef struct vmprg_if_s {
- ifBEGIN; /* This MUST always be the first interface member */
+BEGINinterface(vmprg) /* name must also be changed in ENDinterface macro! */
INTERFACEObjDebugPrint(vmprg);
rsRetVal (*Construct)(vmprg_t **ppThis);
rsRetVal (*ConstructFinalize)(vmprg_t __attribute__((unused)) *pThis);
rsRetVal (*Destruct)(vmprg_t **ppThis);
rsRetVal (*AddOperation)(vmprg_t *pThis, vmop_t *pOp);
rsRetVal (*AddVarOperation)(vmprg_t *pThis, opcode_t opcode, var_t *pVar);
-} vmprg_if_t;
-
+ENDinterface(vmprg)
#define vmprgCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
/* prototypes */
-PROTOTYPEObjClassInit(vmprg);
-PROTOTYPEObjQueryInterface(vmprg);
+PROTOTYPEObj(vmprg);
#endif /* #ifndef INCLUDED_VMPRG_H */