1
/* ctok_token - implements the token_t class.
3
* Module begun 2008-02-20 by Rainer Gerhards
5
* Copyright 2008 Rainer Gerhards and Adiscon GmbH.
7
* This file is part of the rsyslog runtime library.
9
* The rsyslog runtime library is free software: you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation, either version 3 of the License, or
12
* (at your option) any later version.
14
* The rsyslog runtime library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public License
20
* along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>.
22
* A copy of the GPL can be found in the file "COPYING" in this distribution.
23
* A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
34
#include "ctok_token.h"
41
/* Standard-Constructor
43
BEGINobjConstruct(ctok_token) /* be sure to specify the object type also in END macro! */
44
/* TODO: we may optimize the code below and alloc var only if actually
45
* needed (but we need it quite often)
47
CHKiRet(var.Construct(&pThis->pVar));
48
CHKiRet(var.ConstructFinalize(pThis->pVar));
50
ENDobjConstruct(ctok_token)
53
/* ConstructionFinalizer
54
* rgerhards, 2008-01-09
56
rsRetVal ctok_tokenConstructFinalize(ctok_token_t __attribute__((unused)) *pThis)
63
/* destructor for the ctok object */
64
BEGINobjDestruct(ctok_token) /* be sure to specify the object type also in END and CODESTART macros! */
65
CODESTARTobjDestruct(ctok_token)
66
if(pThis->pVar != NULL) {
67
var.Destruct(&pThis->pVar);
69
ENDobjDestruct(ctok_token)
72
/* get the cstr_t from the token, but do not destruct it. This is meant to
73
* be used by a caller who passes on the string to some other function. The
74
* caller is responsible for destructing it.
75
* rgerhards, 2008-02-20
78
ctok_tokenUnlinkVar(ctok_token_t *pThis, var_t **ppVar)
82
ISOBJ_TYPE_assert(pThis, ctok_token);
83
ASSERT(ppVar != NULL);
92
/* tell the caller if the supplied token is a compare operation */
93
static int ctok_tokenIsCmpOp(ctok_token_t *pThis)
95
return(pThis->tok >= ctok_CMP_EQ && pThis->tok <= ctok_CMP_GTEQ);
98
/* queryInterface function
99
* rgerhards, 2008-02-21
101
BEGINobjQueryInterface(ctok_token)
102
CODESTARTobjQueryInterface(ctok_token)
103
if(pIf->ifVersion != ctok_tokenCURR_IF_VERSION) { /* check for current version, increment on each change */
104
ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
107
/* ok, we have the right interface, so let's fill it
108
* Please note that we may also do some backwards-compatibility
109
* work here (if we can support an older interface version - that,
110
* of course, also affects the "if" above).
112
//xxxpIf->oID = OBJctok_token;
114
pIf->Construct = ctok_tokenConstruct;
115
pIf->ConstructFinalize = ctok_tokenConstructFinalize;
116
pIf->Destruct = ctok_tokenDestruct;
117
pIf->UnlinkVar = ctok_tokenUnlinkVar;
118
pIf->IsCmpOp = ctok_tokenIsCmpOp;
120
ENDobjQueryInterface(ctok_token)
123
BEGINObjClassInit(ctok_token, 1, OBJ_IS_CORE_MODULE) /* class, version */
124
/* request objects we use */
125
CHKiRet(objUse(var, CORE_COMPONENT));
127
OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, ctok_tokenConstructFinalize);
128
ENDObjClassInit(ctok_token)