1
/* vmop.c - abstracts an operation (instructed) supported by the
2
* rsyslog virtual machine
4
* Module begun 2008-02-20 by Rainer Gerhards
6
* Copyright 2007, 2008 Rainer Gerhards and Adiscon GmbH.
8
* This file is part of the rsyslog runtime library.
10
* The rsyslog runtime library is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU Lesser General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
15
* The rsyslog runtime library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>.
23
* A copy of the GPL can be found in the file "COPYING" in this distribution.
24
* A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
40
/* forward definitions */
41
static rsRetVal vmopOpcode2Str(vmop_t *pThis, uchar **ppName);
43
/* Standard-Constructor
45
BEGINobjConstruct(vmop) /* be sure to specify the object type also in END macro! */
49
/* ConstructionFinalizer
50
* rgerhards, 2008-01-09
52
rsRetVal vmopConstructFinalize(vmop_t __attribute__((unused)) *pThis)
55
ISOBJ_TYPE_assert(pThis, vmop);
60
/* destructor for the vmop object */
61
BEGINobjDestruct(vmop) /* be sure to specify the object type also in END and CODESTART macros! */
62
CODESTARTobjDestruct(vmop)
63
if( pThis->opcode == opcode_PUSHSYSVAR
64
|| pThis->opcode == opcode_PUSHMSGVAR
65
|| pThis->opcode == opcode_PUSHCONSTANT) {
66
if(pThis->operand.pVar != NULL)
67
var.Destruct(&pThis->operand.pVar);
72
/* DebugPrint support for the vmop object */
73
BEGINobjDebugPrint(vmop) /* be sure to specify the object type also in END and CODESTART macros! */
75
CODESTARTobjDebugPrint(vmop)
76
vmopOpcode2Str(pThis, &pOpcodeName);
77
dbgoprint((obj_t*) pThis, "opcode: %d\t(%s), next %p, var in next line\n", (int) pThis->opcode, pOpcodeName,
79
if(pThis->operand.pVar != NULL)
80
var.DebugPrint(pThis->operand.pVar);
81
ENDobjDebugPrint(vmop)
84
/* set operand (variant case)
85
* rgerhards, 2008-02-20
88
vmopSetVar(vmop_t *pThis, var_t *pVar)
91
ISOBJ_TYPE_assert(pThis, vmop);
92
ISOBJ_TYPE_assert(pVar, var);
93
pThis->operand.pVar = pVar;
99
* rgerhards, 2008-02-20
102
vmopSetOpcode(vmop_t *pThis, opcode_t opcode)
105
ISOBJ_TYPE_assert(pThis, vmop);
106
pThis->opcode = opcode;
111
/* a way to turn an opcode into a readable string
114
vmopOpcode2Str(vmop_t *pThis, uchar **ppName)
117
ISOBJ_TYPE_assert(pThis, vmop);
119
switch(pThis->opcode) {
121
*ppName = (uchar*) "or";
124
*ppName = (uchar*) "and";
127
*ppName = (uchar*) "+";
130
*ppName = (uchar*) "-";
133
*ppName = (uchar*) "*";
136
*ppName = (uchar*) "/";
139
*ppName = (uchar*) "%";
142
*ppName = (uchar*) "not";
145
*ppName = (uchar*) "==";
148
*ppName = (uchar*) "!=";
151
*ppName = (uchar*) "<";
154
*ppName = (uchar*) ">";
156
case opcode_CMP_LTEQ:
157
*ppName = (uchar*) "<=";
159
case opcode_CMP_CONTAINS:
160
*ppName = (uchar*) "contains";
162
case opcode_CMP_STARTSWITH:
163
*ppName = (uchar*) "startswith";
165
case opcode_CMP_GTEQ:
166
*ppName = (uchar*) ">=";
168
case opcode_PUSHSYSVAR:
169
*ppName = (uchar*) "PUSHSYSVAR";
171
case opcode_PUSHMSGVAR:
172
*ppName = (uchar*) "PUSHMSGVAR";
174
case opcode_PUSHCONSTANT:
175
*ppName = (uchar*) "PUSHCONSTANT";
178
*ppName = (uchar*) "POP";
180
case opcode_UNARY_MINUS:
181
*ppName = (uchar*) "UNARY_MINUS";
184
*ppName = (uchar*) "STRADD";
187
*ppName = (uchar*) "INVALID opcode";
195
/* queryInterface function
196
* rgerhards, 2008-02-21
198
BEGINobjQueryInterface(vmop)
199
CODESTARTobjQueryInterface(vmop)
200
if(pIf->ifVersion != vmopCURR_IF_VERSION) { /* check for current version, increment on each change */
201
ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
204
/* ok, we have the right interface, so let's fill it
205
* Please note that we may also do some backwards-compatibility
206
* work here (if we can support an older interface version - that,
207
* of course, also affects the "if" above).
209
//xxxpIf->oID = OBJvmop;
211
pIf->Construct = vmopConstruct;
212
pIf->ConstructFinalize = vmopConstructFinalize;
213
pIf->Destruct = vmopDestruct;
214
pIf->DebugPrint = vmopDebugPrint;
215
pIf->SetOpcode = vmopSetOpcode;
216
pIf->SetVar = vmopSetVar;
217
pIf->Opcode2Str = vmopOpcode2Str;
219
ENDobjQueryInterface(vmop)
222
/* Initialize the vmop class. Must be called as the very first method
223
* before anything else is called inside this class.
224
* rgerhards, 2008-02-19
226
BEGINObjClassInit(vmop, 1, OBJ_IS_CORE_MODULE) /* class, version */
227
/* request objects we use */
228
CHKiRet(objUse(var, CORE_COMPONENT));
230
OBJSetMethodHandler(objMethod_DEBUGPRINT, vmopDebugPrint);
231
OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, vmopConstructFinalize);
232
ENDObjClassInit(vmop)