| 1 |
/* The prop object. |
| 2 |
* |
| 3 |
* This implements props within rsyslog. |
| 4 |
* |
| 5 |
* Copyright 2009-2026 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 |
| 30 |
; /* Data to implement generic object - MUST be the first data element! */ |
| 31 |
int iRefCount; /* reference counter */ |
| 32 |
union { |
| 33 |
uchar *psz; /* stored string */ |
| 34 |
uchar sz[CONF_PROP_BUFSIZE]; |
| 35 |
} szVal; |
| 36 |
int len; /* we use int intentionally, otherwise we may get some troubles... */ |
| 37 |
DEF_ATOMIC_HELPER_MUT(mutRefCount); |
| 38 |
}; |
| 39 |
|
| 40 |
/* interfaces */ |
| 41 |
BEGINinterface(prop) /* name must also be changed in ENDinterface macro! */ |
| 42 |
INTERFACEObjDebugPrint(prop); |
| 43 |
rsRetVal (*Construct)(prop_t **ppThis); |
| 44 |
rsRetVal (*ConstructFinalize)(prop_t *pThis); |
| 45 |
rsRetVal (*Destruct)(prop_t **ppThis); |
| 46 |
rsRetVal (*SetString)(prop_t *pThis, const uchar *psz, const int len); |
| 47 |
rsRetVal (*GetString)(prop_t *pThis, uchar **ppsz, int *plen); |
| 48 |
int (*GetStringLen)(prop_t *pThis); |
| 49 |
rsRetVal (*AddRef)(prop_t *pThis); |
| 50 |
rsRetVal (*CreateStringProp)(prop_t **ppThis, const uchar *psz, const int len); |
| 51 |
rsRetVal (*CreateOrReuseStringProp)(prop_t **ppThis, const uchar *psz, const int len); |
| 52 |
ENDinterface(prop) |
| 53 |
#define propCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */ |
| 54 |
|
| 55 |
|
| 56 |
/* get classic c-style string */ |
| 57 |
/* Note: I know that "static inline" is not the right thing from a C99 |
| 58 |
* PoV, but some environments treat, even in C99 mode, compile |
| 59 |
* non-static inline into the source even if not defined as "extern". This |
| 60 |
* obviously results in linker errors. Using "static inline" as below together |
| 61 |
* with "__attribute__((unused))" works in all cases. Note also that we |
| 62 |
* cannot work around this as we would otherwise need to evaluate |
| 63 |
* pThis more than once. |
| 64 |
*/ |
| 65 |
static inline uchar *__attribute__((unused)) ATTR_NONNULL(1) propGetSzStr(prop_t *pThis) { |
| 66 |
return (pThis->len < CONF_PROP_BUFSIZE) ? pThis->szVal.sz : pThis->szVal.psz; |
| 67 |
} |
| 68 |
|
| 69 |
static inline const char *__attribute__((unused)) propGetSzStrOrDefault(prop_t *pThis, const char *dflt) { |
| 70 |
return (pThis != NULL) ? (const char *)propGetSzStr(pThis) : dflt; |
| 71 |
} |
| 72 |
|
| 73 |
static inline const char *__attribute__((unused)) szStrOrDefault(const uchar *psz, const char *dflt) { |
| 74 |
return (psz != NULL) ? (const char *)psz : dflt; |
| 75 |
} |
| 76 |
|
| 77 |
/* prototypes */ |
| 78 |
PROTOTYPEObjFull(prop); |
| 79 |
PROTOTYPEObjDebugPrint(prop); |
| 80 |
|
| 81 |
#endif /* #ifndef INCLUDED_PROP_H */ |