~ubuntu-branches/ubuntu/karmic/rsyslog/karmic

« back to all changes in this revision

Viewing changes to runtime/vmop.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-04-08 00:59:14 UTC
  • mfrom: (1.1.9 upstream) (3.2.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090408005914-gfyay7o45szt05zl
Tags: 3.20.5-1
* New upstream release.
* debian/rsyslog.logcheck.ignore.server
  - Install a logcheck ignore file for rsyslog (using dh_installlogcheck).
    Thanks to Kim Holviala for the patch. Closes: #522164

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vmop.c - abstracts an operation (instructed) supported by the
 
2
 * rsyslog virtual machine
 
3
 *
 
4
 * Module begun 2008-02-20 by Rainer Gerhards
 
5
 *
 
6
 * Copyright 2007, 2008 Rainer Gerhards and Adiscon GmbH.
 
7
 *
 
8
 * This file is part of the rsyslog runtime library.
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
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/>.
 
22
 *
 
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.
 
25
 */
 
26
 
 
27
#include "config.h"
 
28
#include <stdlib.h>
 
29
#include <assert.h>
 
30
 
 
31
#include "rsyslog.h"
 
32
#include "obj.h"
 
33
#include "vmop.h"
 
34
 
 
35
/* static data */
 
36
DEFobjStaticHelpers
 
37
DEFobjCurrIf(var)
 
38
 
 
39
 
 
40
/* forward definitions */
 
41
static rsRetVal vmopOpcode2Str(vmop_t *pThis, uchar **ppName);
 
42
 
 
43
/* Standard-Constructor
 
44
 */
 
45
BEGINobjConstruct(vmop) /* be sure to specify the object type also in END macro! */
 
46
ENDobjConstruct(vmop)
 
47
 
 
48
 
 
49
/* ConstructionFinalizer
 
50
 * rgerhards, 2008-01-09
 
51
 */
 
52
rsRetVal vmopConstructFinalize(vmop_t __attribute__((unused)) *pThis)
 
53
{
 
54
        DEFiRet;
 
55
        ISOBJ_TYPE_assert(pThis, vmop);
 
56
        RETiRet;
 
57
}
 
58
 
 
59
 
 
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);
 
68
        }
 
69
ENDobjDestruct(vmop)
 
70
 
 
71
 
 
72
/* DebugPrint support for the vmop object */
 
73
BEGINobjDebugPrint(vmop) /* be sure to specify the object type also in END and CODESTART macros! */
 
74
        uchar *pOpcodeName;
 
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,
 
78
                  pThis->pNext);
 
79
        if(pThis->operand.pVar != NULL)
 
80
                var.DebugPrint(pThis->operand.pVar);
 
81
ENDobjDebugPrint(vmop)
 
82
 
 
83
 
 
84
/* set operand (variant case)
 
85
 * rgerhards, 2008-02-20
 
86
 */
 
87
static rsRetVal
 
88
vmopSetVar(vmop_t *pThis, var_t *pVar)
 
89
{
 
90
        DEFiRet;
 
91
        ISOBJ_TYPE_assert(pThis, vmop);
 
92
        ISOBJ_TYPE_assert(pVar, var);
 
93
        pThis->operand.pVar = pVar;
 
94
        RETiRet;
 
95
}
 
96
 
 
97
 
 
98
/* set operation
 
99
 * rgerhards, 2008-02-20
 
100
 */
 
101
static rsRetVal
 
102
vmopSetOpcode(vmop_t *pThis, opcode_t opcode)
 
103
{
 
104
        DEFiRet;
 
105
        ISOBJ_TYPE_assert(pThis, vmop);
 
106
        pThis->opcode = opcode;
 
107
        RETiRet;
 
108
}
 
109
 
 
110
 
 
111
/* a way to turn an opcode into a readable string
 
112
 */
 
113
static rsRetVal
 
114
vmopOpcode2Str(vmop_t *pThis, uchar **ppName)
 
115
{
 
116
        DEFiRet;
 
117
        ISOBJ_TYPE_assert(pThis, vmop);
 
118
 
 
119
        switch(pThis->opcode) {
 
120
                case opcode_OR:
 
121
                        *ppName = (uchar*) "or";
 
122
                        break;
 
123
                case opcode_AND:
 
124
                        *ppName = (uchar*) "and";
 
125
                        break;
 
126
                case opcode_PLUS:
 
127
                        *ppName = (uchar*) "+";
 
128
                        break;
 
129
                case opcode_MINUS:
 
130
                        *ppName = (uchar*) "-";
 
131
                        break;
 
132
                case opcode_TIMES:
 
133
                        *ppName = (uchar*) "*";
 
134
                        break;
 
135
                case opcode_DIV:
 
136
                        *ppName = (uchar*) "/";
 
137
                        break;
 
138
                case opcode_MOD:
 
139
                        *ppName = (uchar*) "%";
 
140
                        break;
 
141
                case opcode_NOT:
 
142
                        *ppName = (uchar*) "not";
 
143
                        break;
 
144
                case opcode_CMP_EQ:
 
145
                        *ppName = (uchar*) "==";
 
146
                        break;
 
147
                case opcode_CMP_NEQ:
 
148
                        *ppName = (uchar*) "!=";
 
149
                        break;
 
150
                case opcode_CMP_LT:
 
151
                        *ppName = (uchar*) "<";
 
152
                        break;
 
153
                case opcode_CMP_GT:
 
154
                        *ppName = (uchar*) ">";
 
155
                        break;
 
156
                case opcode_CMP_LTEQ:
 
157
                        *ppName = (uchar*) "<=";
 
158
                        break;
 
159
                case opcode_CMP_CONTAINS:
 
160
                        *ppName = (uchar*) "contains";
 
161
                        break;
 
162
                case opcode_CMP_STARTSWITH:
 
163
                        *ppName = (uchar*) "startswith";
 
164
                        break;
 
165
                case opcode_CMP_GTEQ:
 
166
                        *ppName = (uchar*) ">=";
 
167
                        break;
 
168
                case opcode_PUSHSYSVAR:
 
169
                        *ppName = (uchar*) "PUSHSYSVAR";
 
170
                        break;
 
171
                case opcode_PUSHMSGVAR:
 
172
                        *ppName = (uchar*) "PUSHMSGVAR";
 
173
                        break;
 
174
                case opcode_PUSHCONSTANT:
 
175
                        *ppName = (uchar*) "PUSHCONSTANT";
 
176
                        break;
 
177
                case opcode_POP:
 
178
                        *ppName = (uchar*) "POP";
 
179
                        break;
 
180
                case opcode_UNARY_MINUS:
 
181
                        *ppName = (uchar*) "UNARY_MINUS";
 
182
                        break;
 
183
                case opcode_STRADD:
 
184
                        *ppName = (uchar*) "STRADD";
 
185
                        break;
 
186
                default:
 
187
                        *ppName = (uchar*) "INVALID opcode";
 
188
                        break;
 
189
        }
 
190
 
 
191
        RETiRet;
 
192
}
 
193
 
 
194
 
 
195
/* queryInterface function
 
196
 * rgerhards, 2008-02-21
 
197
 */
 
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);
 
202
        }
 
203
 
 
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).
 
208
         */
 
209
        //xxxpIf->oID = OBJvmop;
 
210
 
 
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;
 
218
finalize_it:
 
219
ENDobjQueryInterface(vmop)
 
220
 
 
221
 
 
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
 
225
 */
 
226
BEGINObjClassInit(vmop, 1, OBJ_IS_CORE_MODULE) /* class, version */
 
227
        /* request objects we use */
 
228
        CHKiRet(objUse(var, CORE_COMPONENT));
 
229
 
 
230
        OBJSetMethodHandler(objMethod_DEBUGPRINT, vmopDebugPrint);
 
231
        OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, vmopConstructFinalize);
 
232
ENDObjClassInit(vmop)
 
233
 
 
234
/* vi:set ai:
 
235
 */