2
* \brief The counted string object
4
* This is the byte-counted string class for rsyslog. It is a replacement
5
* for classical \0 terminated string functions. We introduce it in
6
* the hope it will make the program more secure, obtain some performance
7
* and, most importantly, lay they foundation for syslog-protocol, which
8
* requires strings to be able to handle embedded \0 characters.
10
* \author Rainer Gerhards <rgerhards@adiscon.com>
12
* Initial version begun.
14
* All functions in this "class" start with rsCStr (rsyslog Counted String).
16
* Rainer Gerhards and Adiscon GmbH. All Rights Reserved.
17
* This code is placed under the GPL.
19
#ifndef _STRINGBUF_H_INCLUDED__
20
#define _STRINGBUF_H_INCLUDED__ 1
23
* The dynamic string buffer object.
28
rsObjID OID; /**< object ID */
30
uchar *pBuf; /**< pointer to the string buffer, may be NULL if string is empty */
31
uchar *pszBuf; /**< pointer to the sz version of the string (after it has been created )*/
32
size_t iBufSize; /**< current maximum size of the string buffer */
33
size_t iStrLen; /**< length of the string in characters. */
34
size_t iAllocIncrement; /**< the amount of bytes the string should be expanded if it needs to */
36
typedef struct rsCStrObject rsCStrObj;
40
* Construct a rsCStr object.
42
rsCStrObj *rsCStrConstruct(void);
43
rsRetVal rsCStrConstructFromszStr(rsCStrObj **ppThis, uchar *sz);
44
rsRetVal rsCStrConstructFromCStr(rsCStrObj **ppThis, rsCStrObj *pFrom);
47
* Destruct the string buffer object.
49
void rsCStrDestruct(rsCStrObj *pThis);
52
* Append a character to an existing string. If necessary, the
53
* method expands the string buffer.
55
* \param c Character to append to string.
57
rsRetVal rsCStrAppendChar(rsCStrObj *pThis, uchar c);
60
* Finish the string buffer dynamic allocation.
62
rsRetVal rsCStrFinish(rsCStrObj *pThis);
65
* Truncate "n" number of characters from the end of the
66
* string. The buffer remains unchanged, just the
67
* string length is manipulated. This is for performance
70
rsRetVal rsCStrTruncate(rsCStrObj *pThis, size_t nTrunc);
72
rsRetVal rsCStrTrimTrailingWhiteSpace(rsCStrObj *pThis);
75
* Append a string to the buffer. For performance reasons,
76
* use rsCStrAppenStrWithLen() if you know the length.
78
* \param psz pointer to string to be appended. Must not be NULL.
80
rsRetVal rsCStrAppendStr(rsCStrObj *pThis, uchar* psz);
83
* Append a string to the buffer.
85
* \param psz pointer to string to be appended. Must not be NULL.
86
* \param iStrLen the length of the string pointed to by psz
88
rsRetVal rsCStrAppendStrWithLen(rsCStrObj *pThis, uchar* psz, size_t iStrLen);
91
* Set a new allocation incremet. This will influence
92
* the allocation the next time the string will be expanded.
93
* It can be set and changed at any time. If done immediately
94
* after custructing the StrB object, this will also be
95
* the inital allocation.
97
* \param iNewIncrement The new increment size
99
* \note It is possible to use a very low increment, e.g. 1 byte.
100
* This can generate a considerable overhead. We highly
101
* advise not to use an increment below 32 bytes, except
102
* if you are very well aware why you are doing it ;)
104
void rsCStrSetAllocIncrement(rsCStrObj *pThis, int iNewIncrement);
107
* Append an integer to the string. No special formatting is
110
rsRetVal rsCStrAppendInt(rsCStrObj *pThis, int i);
113
uchar* rsCStrGetSzStr(rsCStrObj *pThis);
114
uchar* rsCStrGetSzStrNoNULL(rsCStrObj *pThis);
115
rsRetVal rsCStrSetSzStr(rsCStrObj *pThis, uchar *pszNew);
116
rsRetVal rsCStrConvSzStrAndDestruct(rsCStrObj *pThis, uchar **ppSz, int bRetNULL);
117
int rsCStrCStrCmp(rsCStrObj *pCS1, rsCStrObj *pCS2);
118
int rsCStrSzStrCmp(rsCStrObj *pCS1, uchar *psz, size_t iLenSz);
119
int rsCStrOffsetSzStrCmp(rsCStrObj *pCS1, size_t iOffset, uchar *psz, size_t iLenSz);
120
int rsCStrLocateSzStr(rsCStrObj *pCStr, uchar *sz);
121
int rsCStrLocateInSzStr(rsCStrObj *pThis, uchar *sz);
122
int rsCStrStartsWithSzStr(rsCStrObj *pCS1, uchar *psz, size_t iLenSz);
123
int rsCStrSzStrStartsWithCStr(rsCStrObj *pCS1, uchar *psz, size_t iLenSz);
124
int rsCStrSzStrMatchRegex(rsCStrObj *pCS1, uchar *psz);
126
/* now come inline-like functions */
128
# define rsCStrLen(x) ((int)((x)->iStrLen))
130
int rsCStrLen(rsCStrObj *pThis);
133
#define rsCStrGetBufBeg(x) ((x)->pBuf)
135
#endif /* single include */