Debian Codegraph @

runtime/var.c

raw
1 /* var.c - a typeless variable class
2 *
3 * This class is used to represent variable values, which may have any type.
4 * Among others, it will be used inside rsyslog's expression system, but
5 * also internally at any place where a typeless variable is needed.
6 *
7 * Module begun 2008-02-20 by Rainer Gerhards, with some code taken
8 * from the obj.c/.h files.
9 *
10 * Copyright 2007-2016 Rainer Gerhards and Adiscon GmbH.
11 *
12 * This file is part of the rsyslog runtime library.
13 *
14 * The rsyslog runtime library is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * The rsyslog runtime library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with the rsyslog runtime library. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * A copy of the GPL can be found in the file "COPYING" in this distribution.
28 * A copy of the LGPL can be found in the file "COPYING.LESSER" in this distribution.
29 */
30
31 #include "config.h"
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <assert.h>
35
36 #include "rsyslog.h"
37 #include "obj.h"
38 #include "srUtils.h"
39 #include "var.h"
40
41 /* static data */
42 DEFobjStaticHelpers;
43
44
45 /* Standard-Constructor
46 */
47 BEGINobjConstruct(var) /* be sure to specify the object type also in END macro! */
48 ENDobjConstruct(var)
49
50
51 /* ConstructionFinalizer
52 * rgerhards, 2008-01-09
53 */
54 static rsRetVal varConstructFinalize(var_t __attribute__((unused)) * pThis) {
55 DEFiRet;
56
57 ISOBJ_TYPE_assert(pThis, var);
58
59 RETiRet;
60 }
61
62
63 /* destructor for the var object */
64 BEGINobjDestruct(var) /* be sure to specify the object type also in END and CODESTART macros! */
65 CODESTARTobjDestruct(var);
66 if (pThis->pcsName != NULL) rsCStrDestruct(&pThis->pcsName);
67 if (pThis->varType == VARTYPE_STR) {
68 if (pThis->val.pStr != NULL) rsCStrDestruct(&pThis->val.pStr);
69 }
70 ENDobjDestruct(var)
71
72
73 /* DebugPrint support for the var object */
74 BEGINobjDebugPrint(var) /* be sure to specify the object type also in END and CODESTART macros! */
75 CODESTARTobjDebugPrint(var);
76 switch (pThis->varType) {
77 case VARTYPE_STR:
78 dbgoprint((obj_t*)pThis, "type: cstr, val '%s'\n", rsCStrGetSzStrNoNULL(pThis->val.pStr));
79 break;
80 case VARTYPE_NUMBER:
81 dbgoprint((obj_t*)pThis, "type: number, val %lld\n", pThis->val.num);
82 break;
83 case VARTYPE_SYSLOGTIME:
84 case VARTYPE_NONE:
85 default:
86 dbgoprint((obj_t*)pThis, "type %d currently not supported in debug output\n", pThis->varType);
87 break;
88 }
89 ENDobjDebugPrint(var)
90
91
92 /* queryInterface function
93 * rgerhards, 2008-02-21
94 */
95 BEGINobjQueryInterface(var)
96 CODESTARTobjQueryInterface(var);
97 if (pIf->ifVersion != varCURR_IF_VERSION) { /* check for current version, increment on each change */
98 ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
99 }
100
101 /* ok, we have the right interface, so let's fill it
102 * Please note that we may also do some backwards-compatibility
103 * work here (if we can support an older interface version - that,
104 * of course, also affects the "if" above).
105 */
106 pIf->Construct = varConstruct;
107 pIf->ConstructFinalize = varConstructFinalize;
108 pIf->Destruct = varDestruct;
109 pIf->DebugPrint = varDebugPrint;
110 finalize_it:
111 ENDobjQueryInterface(var)
112
113
114 /* Initialize the var class. Must be called as the very first method
115 * before anything else is called inside this class.
116 * rgerhards, 2008-02-19
117 */
118 BEGINObjClassInit(var, 1, OBJ_IS_CORE_MODULE) /* class, version */
119 /* request objects we use */
120
121 /* now set our own handlers */
122 OBJSetMethodHandler(objMethod_DEBUGPRINT, varDebugPrint);
123 OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, varConstructFinalize);
124 ENDObjClassInit(var)
125
126 /* vi:set ai:
127 */