~arges/ubuntu/quantal/rsyslog/fix-lp1059592

« back to all changes in this revision

Viewing changes to ctok_token.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-02-15 21:56:23 UTC
  • mto: (3.2.4 squeeze) (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090215215623-xsycf628eo3kguc0
Tags: upstream-3.20.4
ImportĀ upstreamĀ versionĀ 3.20.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ctok_token - implements the token_t class.
2
 
 *
3
 
 * Module begun 2008-02-20 by Rainer Gerhards
4
 
 *
5
 
 * Copyright 2008 Rainer Gerhards and Adiscon GmbH.
6
 
 *
7
 
 * This file is part of the rsyslog runtime library.
8
 
 *
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.
13
 
 *
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.
18
 
 *
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/>.
21
 
 *
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.
24
 
 */
25
 
 
26
 
#include "config.h"
27
 
#include <stdlib.h>
28
 
#include <ctype.h>
29
 
#include <strings.h>
30
 
#include <assert.h>
31
 
 
32
 
#include "rsyslog.h"
33
 
#include "template.h"
34
 
#include "ctok_token.h"
35
 
 
36
 
/* static data */
37
 
DEFobjStaticHelpers
38
 
DEFobjCurrIf(var)
39
 
 
40
 
 
41
 
/* Standard-Constructor
42
 
 */
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)
46
 
         */
47
 
        CHKiRet(var.Construct(&pThis->pVar));
48
 
        CHKiRet(var.ConstructFinalize(pThis->pVar));
49
 
finalize_it:
50
 
ENDobjConstruct(ctok_token)
51
 
 
52
 
 
53
 
/* ConstructionFinalizer
54
 
 * rgerhards, 2008-01-09
55
 
 */
56
 
rsRetVal ctok_tokenConstructFinalize(ctok_token_t __attribute__((unused)) *pThis)
57
 
{
58
 
        DEFiRet;
59
 
        RETiRet;
60
 
}
61
 
 
62
 
 
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);
68
 
        }
69
 
ENDobjDestruct(ctok_token)
70
 
 
71
 
 
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
76
 
 */
77
 
static rsRetVal
78
 
ctok_tokenUnlinkVar(ctok_token_t *pThis, var_t **ppVar)
79
 
{
80
 
        DEFiRet;
81
 
 
82
 
        ISOBJ_TYPE_assert(pThis, ctok_token);
83
 
        ASSERT(ppVar != NULL);
84
 
 
85
 
        *ppVar = pThis->pVar;
86
 
        pThis->pVar = NULL;
87
 
 
88
 
        RETiRet;
89
 
}
90
 
 
91
 
 
92
 
/* tell the caller if the supplied token is a compare operation */
93
 
static int ctok_tokenIsCmpOp(ctok_token_t *pThis)
94
 
{
95
 
        return(pThis->tok >= ctok_CMP_EQ && pThis->tok <= ctok_CMP_GTEQ);
96
 
}
97
 
 
98
 
/* queryInterface function
99
 
 * rgerhards, 2008-02-21
100
 
 */
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);
105
 
        }
106
 
 
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).
111
 
         */
112
 
        //xxxpIf->oID = OBJctok_token;
113
 
 
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;
119
 
finalize_it:
120
 
ENDobjQueryInterface(ctok_token)
121
 
 
122
 
 
123
 
BEGINObjClassInit(ctok_token, 1, OBJ_IS_CORE_MODULE) /* class, version */
124
 
        /* request objects we use */
125
 
        CHKiRet(objUse(var, CORE_COMPONENT));
126
 
 
127
 
        OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, ctok_tokenConstructFinalize);
128
 
ENDObjClassInit(ctok_token)
129
 
 
130
 
/* vi:set ai:
131
 
 */