1 /* The prop object.
2 *
3 * This implements props within rsyslog.
4 *
5 * Copyright 2009-2012 Adiscon GmbH.
6 *
7 * This file is part of the rsyslog runtime library.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 * -or-
15 * see COPYING.ASL20 in the source distribution
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23 #ifndef INCLUDED_PROP_H
24 #define INCLUDED_PROP_H
25 #include "atomic.h"
26
27 /* the prop object */
28 struct prop_s {
29 BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
30 int iRefCount; /* reference counter */
31 union {
32 uchar *psz; /* stored string */
33 uchar sz[CONF_PROP_BUFSIZE];
34 } szVal;
35 int len; /* we use int intentionally, otherwise we may get some troubles... */
36 DEF_ATOMIC_HELPER_MUT(mutRefCount)
37 };
38
39 /* interfaces */
40 BEGINinterface(prop) /* name must also be changed in ENDinterface macro! */
41 INTERFACEObjDebugPrint(prop);
42 rsRetVal (*Construct)(prop_t **ppThis);
43 rsRetVal (*ConstructFinalize)(prop_t *pThis);
44 rsRetVal (*Destruct)(prop_t **ppThis);
45 rsRetVal (*SetString)(prop_t *pThis, const uchar* psz, const int len);
46 rsRetVal (*GetString)(prop_t *pThis, uchar** ppsz, int *plen);
47 int (*GetStringLen)(prop_t *pThis);
48 rsRetVal (*AddRef)(prop_t *pThis);
49 rsRetVal (*CreateStringProp)(prop_t **ppThis, const uchar* psz, const int len);
50 rsRetVal (*CreateOrReuseStringProp)(prop_t **ppThis, const uchar *psz, const int len);
ENDinterface(prop)51 ENDinterface(prop)
52 #define propCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
53
54
55 /* get classic c-style string */
56 /* Note: I know that "static inline" is not the right thing from a C99
57 * PoV, but some environments treat, even in C99 mode, compile
58 * non-static inline into the source even if not defined as "extern". This
59 * obviously results in linker errors. Using "static inline" as below together
60 * with "__attribute__((unused))" works in all cases. Note also that we
61 * cannot work around this as we would otherwise need to evaluate
62 * pThis more than once.
63 */
64 static inline uchar * __attribute__((unused)) ATTR_NONNULL(1)
65 propGetSzStr(prop_t *pThis)
66 {
67 return(pThis->len < CONF_PROP_BUFSIZE) ? pThis->szVal.sz : pThis->szVal.psz;
68 }
69
70 /* prototypes */
71 PROTOTYPEObj(prop);
72
73 #endif /* #ifndef INCLUDED_PROP_H */
74