summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-17 15:22:13 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-17 15:22:13 +0200
commitd2d54013aebb756169182ed8716b142d27134a70 (patch)
tree9fe7f3d7a84a685ac81faa21712aee97c6ea3d60
parent34b60b389e463e260f880ca3efc591b4db2cd18a (diff)
downloadrsyslog-d2d54013aebb756169182ed8716b142d27134a70.tar.gz
rsyslog-d2d54013aebb756169182ed8716b142d27134a70.tar.xz
rsyslog-d2d54013aebb756169182ed8716b142d27134a70.zip
going forward in moving string-handling functions to new interface...
-rw-r--r--parse.c18
-rw-r--r--runtime/ctok.c17
-rw-r--r--runtime/msg.c20
-rw-r--r--runtime/nsd_gtls.c34
-rw-r--r--runtime/obj.c16
-rw-r--r--runtime/prop.c4
-rw-r--r--runtime/stream.c6
-rw-r--r--runtime/stringbuf.c74
-rw-r--r--runtime/stringbuf.h22
-rw-r--r--runtime/vm.c12
-rw-r--r--runtime/vmop.c2
-rw-r--r--tests/nettester.c4
-rw-r--r--tools/syslogd.c2
13 files changed, 126 insertions, 105 deletions
diff --git a/parse.c b/parse.c
index 87c67676..5288c8b4 100644
--- a/parse.c
+++ b/parse.c
@@ -256,7 +256,7 @@ rsRetVal parsDelimCStr(rsParsObj *pThis, cstr_t **ppCStr, char cDelim, int bTrim
pC = rsCStrGetBufBeg(pThis->pCStr) + pThis->iCurrPos;
while(pThis->iCurrPos < rsCStrLen(pThis->pCStr) && *pC != cDelim) {
- CHKiRet(rsCStrAppendChar(pCStr, bConvLower ? tolower(*pC) : *pC));
+ CHKiRet(cstrAppendChar(pCStr, bConvLower ? tolower(*pC) : *pC));
++pThis->iCurrPos;
++pC;
}
@@ -271,7 +271,7 @@ rsRetVal parsDelimCStr(rsParsObj *pThis, cstr_t **ppCStr, char cDelim, int bTrim
CHKiRet(cstrFinalize(pCStr));
if(bTrimTrailing) {
- CHKiRet(rsCStrTrimTrailingWhiteSpace(pCStr));
+ CHKiRet(cstrTrimTrailingWhiteSpace(pCStr));
}
/* done! */
@@ -313,23 +313,23 @@ rsRetVal parsQuotedCStr(rsParsObj *pThis, cstr_t **ppCStr)
pC = rsCStrGetBufBeg(pThis->pCStr) + pThis->iCurrPos;
/* OK, we most probably can obtain a value... */
- CHKiRet(rsCStrConstruct(&pCStr));
+ CHKiRet(cstrConstruct(&pCStr));
- while(pThis->iCurrPos < rsCStrLen(pThis->pCStr)) {
+ while(pThis->iCurrPos < cstrLen(pThis->pCStr)) {
if(*pC == '"') {
break; /* we are done! */
} else if(*pC == '\\') {
++pThis->iCurrPos;
++pC;
- if(pThis->iCurrPos < rsCStrLen(pThis->pCStr)) {
+ if(pThis->iCurrPos < cstrLen(pThis->pCStr)) {
/* in this case, we copy the escaped character
* to the output buffer (but do not rely on this,
* we might later introduce other things, like \007!
*/
- CHKiRet(rsCStrAppendChar(pCStr, *pC));
+ CHKiRet(cstrAppendChar(pCStr, *pC));
}
} else { /* regular character */
- CHKiRet(rsCStrAppendChar(pCStr, *pC));
+ CHKiRet(cstrAppendChar(pCStr, *pC));
}
++pThis->iCurrPos;
++pC;
@@ -339,7 +339,7 @@ rsRetVal parsQuotedCStr(rsParsObj *pThis, cstr_t **ppCStr)
++pThis->iCurrPos; /* 'eat' trailing quote */
} else {
/* error - improperly quoted string! */
- rsCStrDestruct(&pCStr);
+ cstrDestruct(&pCStr);
ABORT_FINALIZE(RS_RET_MISSING_TRAIL_QUOTE);
}
@@ -352,7 +352,7 @@ rsRetVal parsQuotedCStr(rsParsObj *pThis, cstr_t **ppCStr)
finalize_it:
if(iRet != RS_RET_OK) {
if(pCStr != NULL)
- rsCStrDestruct(&pCStr);
+ cstrDestruct(&pCStr);
}
RETiRet;
diff --git a/runtime/ctok.c b/runtime/ctok.c
index 263e656c..6f5f0273 100644
--- a/runtime/ctok.c
+++ b/runtime/ctok.c
@@ -258,13 +258,13 @@ ctokGetVar(ctok_t *pThis, ctok_token_t *pToken)
pToken->tok = ctok_MSGVAR;
}
- CHKiRet(rsCStrConstruct(&pstrVal));
+ CHKiRet(cstrConstruct(&pstrVal));
/* this loop is quite simple, a variable name is terminated when a non-supported
* character is detected. Note that we currently permit a numerical digit as the
* first char, which is not permitted by ABNF. -- rgerhards, 2009-03-10
*/
while(isalpha(c) || isdigit(c) || (c == '_') || (c == '-')) {
- CHKiRet(rsCStrAppendChar(pstrVal, tolower(c)));
+ CHKiRet(cstrAppendChar(pstrVal, tolower(c)));
CHKiRet(ctokGetCharFromStream(pThis, &c));
}
CHKiRet(ctokUngetCharFromStream(pThis, c)); /* put not processed char back */
@@ -277,7 +277,7 @@ ctokGetVar(ctok_t *pThis, ctok_token_t *pToken)
finalize_it:
if(iRet != RS_RET_OK) {
if(pstrVal != NULL) {
- rsCStrDestruct(&pstrVal);
+ cstrDestruct(&pstrVal);
}
}
@@ -301,20 +301,20 @@ ctokGetSimpStr(ctok_t *pThis, ctok_token_t *pToken)
pToken->tok = ctok_SIMPSTR;
- CHKiRet(rsCStrConstruct(&pstrVal));
+ CHKiRet(cstrConstruct(&pstrVal));
CHKiRet(ctokGetCharFromStream(pThis, &c));
/* while we are in escape mode (had a backslash), no sequence
* terminates the loop. If outside, it is terminated by a single quote.
*/
while(bInEsc || c != '\'') {
if(bInEsc) {
- CHKiRet(rsCStrAppendChar(pstrVal, c));
+ CHKiRet(cstrAppendChar(pstrVal, c));
bInEsc = 0;
} else {
if(c == '\\') {
bInEsc = 1;
} else {
- CHKiRet(rsCStrAppendChar(pstrVal, c));
+ CHKiRet(cstrAppendChar(pstrVal, c));
}
}
CHKiRet(ctokGetCharFromStream(pThis, &c));
@@ -327,7 +327,7 @@ ctokGetSimpStr(ctok_t *pThis, ctok_token_t *pToken)
finalize_it:
if(iRet != RS_RET_OK) {
if(pstrVal != NULL) {
- rsCStrDestruct(&pstrVal);
+ cstrDestruct(&pstrVal);
}
}
@@ -519,8 +519,9 @@ ctokGetToken(ctok_t *pThis, ctok_token_t **ppToken)
CHKiRet(ctokUngetCharFromStream(pThis, c));
pToken->tok = ctok_FUNCTION;
/* fill function name */
- CHKiRet(rsCStrConstruct(&pstrVal));
+ CHKiRet(cstrConstruct(&pstrVal));
CHKiRet(rsCStrSetSzStr(pstrVal, szWord));
+ CHKiRet(cstrFinalize(pstrVal));
CHKiRet(var.SetString(pToken->pVar, pstrVal));
} else { /* give up... */
dbgprintf("parser has an invalid word (token) '%s'\n", szWord);
diff --git a/runtime/msg.c b/runtime/msg.c
index 8e9d2b71..d9ff2e73 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -730,10 +730,10 @@ static rsRetVal aquirePROCIDFromTAG(msg_t *pM)
++i; /* skip '[' */
/* now obtain the PROCID string... */
- CHKiRet(rsCStrConstruct(&pM->pCSPROCID));
+ CHKiRet(cstrConstruct(&pM->pCSPROCID));
rsCStrSetAllocIncrement(pM->pCSPROCID, 16);
while((i < pM->iLenTAG) && (pM->pszTAG[i] != ']')) {
- CHKiRet(rsCStrAppendChar(pM->pCSPROCID, pM->pszTAG[i]));
+ CHKiRet(cstrAppendChar(pM->pCSPROCID, pM->pszTAG[i]));
++i;
}
@@ -743,7 +743,7 @@ static rsRetVal aquirePROCIDFromTAG(msg_t *pM)
* the buffer and simply return. Note that this is NOT an error
* case!
*/
- rsCStrDestruct(&pM->pCSPROCID);
+ cstrDestruct(&pM->pCSPROCID);
FINALIZE;
}
@@ -781,14 +781,14 @@ static rsRetVal aquireProgramName(msg_t *pM)
/* ok, we do not yet have it. So let's parse the TAG
* to obtain it.
*/
- CHKiRet(rsCStrConstruct(&pM->pCSProgName));
+ CHKiRet(cstrConstruct(&pM->pCSProgName));
rsCStrSetAllocIncrement(pM->pCSProgName, 33);
for( i = 0
; (i < pM->iLenTAG) && isprint((int) pM->pszTAG[i])
&& (pM->pszTAG[i] != '\0') && (pM->pszTAG[i] != ':')
&& (pM->pszTAG[i] != '[') && (pM->pszTAG[i] != '/')
; ++i) {
- CHKiRet(rsCStrAppendChar(pM->pCSProgName, pM->pszTAG[i]));
+ CHKiRet(cstrAppendChar(pM->pCSProgName, pM->pszTAG[i]));
}
CHKiRet(cstrFinalize(pM->pCSProgName));
}
@@ -811,8 +811,7 @@ finalize_it:
void moveHOSTNAMEtoTAG(msg_t *pM)
{
assert(pM != NULL);
- if(pM->pszTAG != NULL)
- free(pM->pszTAG);
+ free(pM->pszTAG);
pM->pszTAG = pM->pszHOSTNAME;
pM->iLenTAG = pM->iLenHOSTNAME;
pM->pszHOSTNAME = NULL;
@@ -1188,11 +1187,11 @@ rsRetVal MsgSetPROCID(msg_t *pMsg, char* pszPROCID)
ISOBJ_TYPE_assert(pMsg, msg);
if(pMsg->pCSPROCID == NULL) {
/* we need to obtain the object first */
- CHKiRet(rsCStrConstruct(&pMsg->pCSPROCID));
- rsCStrSetAllocIncrement(pMsg->pCSPROCID, 128);
+ CHKiRet(cstrConstruct(&pMsg->pCSPROCID));
}
/* if we reach this point, we have the object */
iRet = rsCStrSetSzStr(pMsg->pCSPROCID, (uchar*) pszPROCID);
+ CHKiRet(cstrFinalize(pMsg->pCSPROCID));
finalize_it:
RETiRet;
@@ -1221,7 +1220,8 @@ char *getPROCID(msg_t *pM)
MsgLock(pM);
if(pM->pCSPROCID == NULL)
aquirePROCIDFromTAG(pM);
- pszRet = (pM->pCSPROCID == NULL) ? "-" : (char*) rsCStrGetSzStrNoNULL(pM->pCSPROCID);
+ pszRet = (pM->pCSPROCID == NULL) ? "-" : (char*) cstrGetSzStrNoNULL(pM->pCSPROCID);
+ //pszRet = (pM->pCSPROCID == NULL) ? "-" : (char*) rsCStrGetSzStrNoNULL(pM->pCSPROCID);
MsgUnlock(pM);
return pszRet;
}
diff --git a/runtime/nsd_gtls.c b/runtime/nsd_gtls.c
index 19dc8678..79ceffb3 100644
--- a/runtime/nsd_gtls.c
+++ b/runtime/nsd_gtls.c
@@ -710,16 +710,16 @@ gtlsGetCN(nsd_gtls_t *pThis, gnutls_x509_crt *pCert, cstr_t **ppstrCN)
}
/* we found a common name, now extract it */
- CHKiRet(rsCStrConstruct(&pstrCN));
+ CHKiRet(cstrConstruct(&pstrCN));
while(szDN[i] != '\0' && szDN[i] != ',') {
if(szDN[i] == '\\') {
/* hex escapes are not implemented */
++i; /* escape char processed */
if(szDN[i] == '\0')
ABORT_FINALIZE(RS_RET_CERT_INVALID_DN);
- CHKiRet(rsCStrAppendChar(pstrCN, szDN[i]));
+ CHKiRet(cstrAppendChar(pstrCN, szDN[i]));
} else {
- CHKiRet(rsCStrAppendChar(pstrCN, szDN[i]));
+ CHKiRet(cstrAppendChar(pstrCN, szDN[i]));
}
++i; /* char processed */
}
@@ -734,7 +734,7 @@ gtlsGetCN(nsd_gtls_t *pThis, gnutls_x509_crt *pCert, cstr_t **ppstrCN)
finalize_it:
if(iRet != RS_RET_OK) {
if(pstrCN != NULL)
- rsCStrDestruct(&pstrCN);
+ cstrDestruct(&pstrCN);
}
RETiRet;
@@ -761,7 +761,7 @@ gtlsChkPeerFingerprint(nsd_gtls_t *pThis, gnutls_x509_crt *pCert)
size = sizeof(fingerprint);
CHKgnutls(gnutls_x509_crt_get_fingerprint(*pCert, GNUTLS_DIG_SHA1, fingerprint, &size));
CHKiRet(GenFingerprintStr(fingerprint, size, &pstrFingerprint));
- dbgprintf("peer's certificate SHA1 fingerprint: %s\n", rsCStrGetSzStr(pstrFingerprint));
+ dbgprintf("peer's certificate SHA1 fingerprint: %s\n", cstrGetSzStr(pstrFingerprint));
/* now search through the permitted peers to see if we can find a permitted one */
bFoundPositiveMatch = 0;
@@ -779,7 +779,7 @@ gtlsChkPeerFingerprint(nsd_gtls_t *pThis, gnutls_x509_crt *pCert)
if(pThis->bReportAuthErr == 1) {
errno = 0;
errmsg.LogError(0, RS_RET_INVALID_FINGERPRINT, "error: peer fingerprint '%s' unknown - we are "
- "not permitted to talk to it", rsCStrGetSzStr(pstrFingerprint));
+ "not permitted to talk to it", cstrGetSzStr(pstrFingerprint));
pThis->bReportAuthErr = 0;
}
ABORT_FINALIZE(RS_RET_INVALID_FINGERPRINT);
@@ -787,7 +787,7 @@ gtlsChkPeerFingerprint(nsd_gtls_t *pThis, gnutls_x509_crt *pCert)
finalize_it:
if(pstrFingerprint != NULL)
- rsCStrDestruct(&pstrFingerprint);
+ cstrDestruct(&pstrFingerprint);
RETiRet;
}
@@ -874,10 +874,10 @@ gtlsChkPeerName(nsd_gtls_t *pThis, gnutls_x509_crt *pCert)
/* if we did not succeed so far, we try the CN part of the DN... */
CHKiRet(gtlsGetCN(pThis, pCert, &pstrCN));
if(pstrCN != NULL) { /* NULL if there was no CN present */
- dbgprintf("gtls now checking auth for CN '%s'\n", rsCStrGetSzStr(pstrCN));
- snprintf((char*)lnBuf, sizeof(lnBuf), "CN: %s; ", rsCStrGetSzStr(pstrCN));
+ dbgprintf("gtls now checking auth for CN '%s'\n", cstrGetSzStr(pstrCN));
+ snprintf((char*)lnBuf, sizeof(lnBuf), "CN: %s; ", cstrGetSzStr(pstrCN));
CHKiRet(rsCStrAppendStr(pStr, lnBuf));
- CHKiRet(gtlsChkOnePeerName(pThis, rsCStrGetSzStr(pstrCN), &bFoundPositiveMatch));
+ CHKiRet(gtlsChkOnePeerName(pThis, cstrGetSzStr(pstrCN), &bFoundPositiveMatch));
}
}
@@ -888,7 +888,7 @@ gtlsChkPeerName(nsd_gtls_t *pThis, gnutls_x509_crt *pCert)
errno = 0;
errmsg.LogError(0, RS_RET_INVALID_FINGERPRINT, "error: peer name not authorized - "
"not permitted to talk to it. Names: %s",
- rsCStrGetSzStr(pStr));
+ cstrGetSzStr(pStr));
pThis->bReportAuthErr = 0;
}
ABORT_FINALIZE(RS_RET_INVALID_FINGERPRINT);
@@ -1010,8 +1010,8 @@ gtlsChkPeerCertValidity(nsd_gtls_t *pThis)
errmsg.LogError(0, NO_ERRCODE, "not permitted to talk to peer, certificate invalid: %s",
pszErrCause);
gtlsGetCertInfo(pThis, &pStr);
- errmsg.LogError(0, NO_ERRCODE, "invalid cert info: %s", rsCStrGetSzStr(pStr));
- rsCStrDestruct(&pStr);
+ errmsg.LogError(0, NO_ERRCODE, "invalid cert info: %s", cstrGetSzStr(pStr));
+ cstrDestruct(&pStr);
ABORT_FINALIZE(RS_RET_CERT_INVALID);
}
@@ -1032,8 +1032,8 @@ gtlsChkPeerCertValidity(nsd_gtls_t *pThis)
else if(ttCert > ttNow) {
errmsg.LogError(0, RS_RET_CERT_NOT_YET_ACTIVE, "not permitted to talk to peer: certificate %d not yet active", i);
gtlsGetCertInfo(pThis, &pStr);
- errmsg.LogError(0, RS_RET_CERT_NOT_YET_ACTIVE, "invalid cert info: %s", rsCStrGetSzStr(pStr));
- rsCStrDestruct(&pStr);
+ errmsg.LogError(0, RS_RET_CERT_NOT_YET_ACTIVE, "invalid cert info: %s", cstrGetSzStr(pStr));
+ cstrDestruct(&pStr);
ABORT_FINALIZE(RS_RET_CERT_NOT_YET_ACTIVE);
}
@@ -1043,8 +1043,8 @@ gtlsChkPeerCertValidity(nsd_gtls_t *pThis)
else if(ttCert < ttNow) {
errmsg.LogError(0, RS_RET_CERT_EXPIRED, "not permitted to talk to peer: certificate %d expired", i);
gtlsGetCertInfo(pThis, &pStr);
- errmsg.LogError(0, RS_RET_CERT_EXPIRED, "invalid cert info: %s", rsCStrGetSzStr(pStr));
- rsCStrDestruct(&pStr);
+ errmsg.LogError(0, RS_RET_CERT_EXPIRED, "invalid cert info: %s", cstrGetSzStr(pStr));
+ cstrDestruct(&pStr);
ABORT_FINALIZE(RS_RET_CERT_EXPIRED);
}
gnutls_x509_crt_deinit(cert);
diff --git a/runtime/obj.c b/runtime/obj.c
index f2cb447e..6ca05cc4 100644
--- a/runtime/obj.c
+++ b/runtime/obj.c
@@ -440,11 +440,11 @@ objDeserializeEmbedStr(cstr_t **ppStr, strm_t *pStrm)
assert(ppStr != NULL);
- CHKiRet(rsCStrConstruct(&pStr));
+ CHKiRet(cstrConstruct(&pStr));
NEXTC;
while(c != ':') {
- CHKiRet(rsCStrAppendChar(pStr, c));
+ CHKiRet(cstrAppendChar(pStr, c));
NEXTC;
}
CHKiRet(cstrFinalize(pStr));
@@ -453,7 +453,7 @@ objDeserializeEmbedStr(cstr_t **ppStr, strm_t *pStrm)
finalize_it:
if(iRet != RS_RET_OK && pStr != NULL)
- rsCStrDestruct(&pStr);
+ cstrDestruct(&pStr);
RETiRet;
}
@@ -508,11 +508,11 @@ static rsRetVal objDeserializeStr(cstr_t **ppCStr, int iLen, strm_t *pStrm)
assert(ppCStr != NULL);
assert(iLen >= 0);
- CHKiRet(rsCStrConstruct(&pCStr));
+ CHKiRet(cstrConstruct(&pCStr));
NEXTC;
for(i = 0 ; i < iLen ; ++i) {
- CHKiRet(rsCStrAppendChar(pCStr, c));
+ CHKiRet(cstrAppendChar(pCStr, c));
NEXTC;
}
CHKiRet(cstrFinalize(pCStr));
@@ -524,7 +524,7 @@ static rsRetVal objDeserializeStr(cstr_t **ppCStr, int iLen, strm_t *pStrm)
finalize_it:
if(iRet != RS_RET_OK && pCStr != NULL)
- rsCStrDestruct(&pCStr);
+ cstrDestruct(&pCStr);
RETiRet;
}
@@ -622,11 +622,11 @@ static rsRetVal objDeserializeProperty(var_t *pProp, strm_t *pStrm)
}
/* get the property name first */
- CHKiRet(rsCStrConstruct(&pProp->pcsName));
+ CHKiRet(cstrConstruct(&pProp->pcsName));
NEXTC;
while(c != ':') {
- CHKiRet(rsCStrAppendChar(pProp->pcsName, c));
+ CHKiRet(cstrAppendChar(pProp->pcsName, c));
NEXTC;
}
CHKiRet(cstrFinalize(pProp->pcsName));
diff --git a/runtime/prop.c b/runtime/prop.c
index 4130d4b7..02be315f 100644
--- a/runtime/prop.c
+++ b/runtime/prop.c
@@ -55,12 +55,10 @@ ENDobjConstruct(prop)
* rgerhards, 2008-01-09
*/
static rsRetVal
-propConstructFinalize(prop_t *pThis)
+propConstructFinalize(prop_t __attribute__((unused)) *pThis)
{
DEFiRet;
ISOBJ_TYPE_assert(pThis, prop);
-
-finalize_it:
RETiRet;
}
diff --git a/runtime/stream.c b/runtime/stream.c
index 8cbe0297..f9859617 100644
--- a/runtime/stream.c
+++ b/runtime/stream.c
@@ -531,19 +531,19 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr)
ASSERT(pThis != NULL);
ASSERT(ppCStr != NULL);
- CHKiRet(rsCStrConstruct(ppCStr));
+ CHKiRet(cstrConstruct(ppCStr));
/* now read the line */
CHKiRet(strmReadChar(pThis, &c));
while(c != '\n') {
- CHKiRet(rsCStrAppendChar(*ppCStr, c));
+ CHKiRet(cstrAppendChar(*ppCStr, c));
CHKiRet(strmReadChar(pThis, &c));
}
CHKiRet(cstrFinalize(*ppCStr));
finalize_it:
if(iRet != RS_RET_OK && *ppCStr != NULL)
- rsCStrDestruct(ppCStr);
+ cstrDestruct(ppCStr);
RETiRet;
}
diff --git a/runtime/stringbuf.c b/runtime/stringbuf.c
index a2d9c599..e7fa8c41 100644
--- a/runtime/stringbuf.c
+++ b/runtime/stringbuf.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
/* This is the byte-counted string class for rsyslog. It is a replacement
* for classical \0 terminated string functions. We introduce it in
* the hope it will make the program more secure, obtain some performance
@@ -157,7 +158,7 @@ static rsRetVal
rsCStrExtendBuf(cstr_t *pThis, size_t iMinNeeded)
{
uchar *pNewBuf;
- size_t iNewSize;
+ unsigned short iNewSize;
DEFiRet;
/* first compute the new size needed */
@@ -224,7 +225,7 @@ rsRetVal rsCStrAppendStr(cstr_t *pThis, uchar* psz)
/* append the contents of one cstr_t object to another
* rgerhards, 2008-02-25
*/
-rsRetVal rsCStrAppendCStr(cstr_t *pThis, cstr_t *pstrAppend)
+rsRetVal cstrAppendCStr(cstr_t *pThis, cstr_t *pstrAppend)
{
return rsCStrAppendStrWithLen(pThis, pstrAppend->pBuf, pstrAppend->iStrLen);
}
@@ -245,32 +246,7 @@ finalize_it:
}
-rsRetVal rsCStrAppendChar(cstr_t *pThis, uchar c)
-{
- DEFiRet;
-
- rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
-
- if(pThis->iStrLen >= pThis->iBufSize) {
- CHKiRet(rsCStrExtendBuf(pThis, 1)); /* need more memory! */
- }
-
- /* ok, when we reach this, we have sufficient memory */
- *(pThis->pBuf + pThis->iStrLen++) = c;
-
- /* check if we need to invalidate an sz representation! */
- if(pThis->pszBuf != NULL) {
- free(pThis->pszBuf);
- pThis->pszBuf = NULL;
- }
-
-finalize_it:
- RETiRet;
-}
-
-
-/* NEW VARIANT
- * Append a character to the current string object. This may only be done until
+/* Append a character to the current string object. This may only be done until
* cstrFinalize() is called.
* rgerhards, 2009-06-16
*/
@@ -392,7 +368,24 @@ uchar* rsCStrGetSzStr(cstr_t *pThis)
}
-/* NEW VERSION for interface without separate psz buffer! */
+/* Converts the CStr object to a classical sz string and returns that.
+ * Same restrictions as in cstrGetSzStr() applies (see there!). This
+ * function here guarantees that a valid string is returned, even if
+ * the CStr object currently holds a NULL pointer string buffer. If so,
+ * "" is returned.
+ * rgerhards 2005-10-19
+ * WARNING: The returned pointer MUST NOT be freed, as it may be
+ * obtained from that constant memory pool (in case of NULL!)
+ */
+uchar* cstrGetSzStrNoNULL(cstr_t *pThis)
+{
+ rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
+ if(pThis->pBuf == NULL)
+ return (uchar*) "";
+ else
+ return cstrGetSzStr(pThis);
+}
+
/* Returns the cstr data as a classical C sz string. We use that the
* Finalizer did properly terminate our string (but we may stil be NULL).
* So it is vital that the finalizer is called BEFORe this function here!
@@ -497,7 +490,7 @@ void rsCStrSetAllocIncrement(cstr_t *pThis, int iNewIncrement)
* This is due to performance reasons.
*/
#ifndef NDEBUG
-int rsCStrLen(cstr_t *pThis)
+int cstrLen(cstr_t *pThis)
{
rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
return(pThis->iStrLen);
@@ -548,6 +541,27 @@ rsRetVal rsCStrTrimTrailingWhiteSpace(cstr_t *pThis)
return RS_RET_OK;
}
+/* Trim trailing whitespace from a given string
+ */
+rsRetVal cstrTrimTrailingWhiteSpace(cstr_t *pThis)
+{
+ register int i;
+ register uchar *pC;
+ rsCHECKVALIDOBJECT(pThis, OIDrsCStr);
+
+ i = pThis->iStrLen;
+ pC = pThis->pBuf + i - 1;
+ while(i > 0 && isspace((int)*pC)) {
+ --pC;
+ --i;
+ }
+ /* i now is the new string length! */
+ pThis->iStrLen = i;
+ pThis->pBuf[pThis->iStrLen] = '0'; /* we always have this space */
+
+ return RS_RET_OK;
+}
+
/* compare two string objects - works like strcmp(), but operates
* on CStr objects. Please note that this version here is
* faster in the majority of cases, simply because it can
diff --git a/runtime/stringbuf.h b/runtime/stringbuf.h
index d28aee26..b4fc3f3c 100644
--- a/runtime/stringbuf.h
+++ b/runtime/stringbuf.h
@@ -1,5 +1,5 @@
-/*! \file stringbuf.h
- * \brief The counted string object
+/* stringbuf.h
+ * The counted string object
*
* This is the byte-counted string class for rsyslog. It is a replacement
* for classical \0 terminated string functions. We introduce it in
@@ -11,8 +11,7 @@
* \date 2005-09-07
* Initial version begun.
*
- * All functions in this "class" start with rsCStr (rsyslog Counted String).
- * Copyright 2005
+ * Copyright 2005-2009
* Rainer Gerhards and Adiscon GmbH. All Rights Reserved.
*
* This file is part of the rsyslog runtime library.
@@ -48,7 +47,7 @@ typedef struct cstr_s
uchar *pszBuf; /**< pointer to the sz version of the string (after it has been created )*/
size_t iBufSize; /**< current maximum size of the string buffer */
size_t iStrLen; /**< length of the string in characters. */
- size_t iAllocIncrement; /**< the amount of bytes the string should be expanded if it needs to */
+ unsigned short iAllocIncrement; /**< the amount of bytes the string should be expanded if it needs to */
bool bIsFinalized; /**< is this object finished and ready for use? (a debug aid, may be removed later TODO 2009-06-16) */
} cstr_t;
@@ -73,7 +72,6 @@ void rsCStrDestruct(cstr_t **ppThis);
*
* \param c Character to append to string.
*/
-rsRetVal rsCStrAppendChar(cstr_t *pThis, uchar c);
rsRetVal cstrAppendChar(cstr_t *pThis, uchar c);
/**
@@ -85,6 +83,7 @@ rsRetVal cstrAppendChar(cstr_t *pThis, uchar c);
rsRetVal rsCStrTruncate(cstr_t *pThis, size_t nTrunc);
rsRetVal rsCStrTrimTrailingWhiteSpace(cstr_t *pThis);
+rsRetVal cstrTrimTrailingWhiteSpace(cstr_t *pThis);
/**
* Append a string to the buffer. For performance reasons,
@@ -143,19 +142,24 @@ rsRetVal rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz, int iType, void *cache)
void rsCStrRegexDestruct(void *rc);
rsRetVal rsCStrConvertToNumber(cstr_t *pStr, number_t *pNumber);
rsRetVal rsCStrConvertToBool(cstr_t *pStr, number_t *pBool);
-rsRetVal rsCStrAppendCStr(cstr_t *pThis, cstr_t *pstrAppend);
+
+/* in migration */
+#define rsCStrAppendCStr(pThis, pstrAppend) cstrAppendCStr(pThis, pstrAppend)
/* new calling interface */
rsRetVal cstrFinalize(cstr_t *pThis);
rsRetVal cstrConvSzStrAndDestruct(cstr_t *pThis, uchar **ppSz, int bRetNULL);
uchar* cstrGetSzStr(cstr_t *pThis);
+uchar* cstrGetSzStrNoNULL(cstr_t *pThis);
+rsRetVal cstrAppendCStr(cstr_t *pThis, cstr_t *pstrAppend);
/* now come inline-like functions */
#ifdef NDEBUG
-# define rsCStrLen(x) ((int)((x)->iStrLen))
+# define cstrLen(x) ((int)((x)->iStrLen))
#else
- int rsCStrLen(cstr_t *pThis);
+ int cstrLen(cstr_t *pThis);
#endif
+#define rsCStrLen(s) cstrLen((s))
#define rsCStrGetBufBeg(x) ((x)->pBuf)
diff --git a/runtime/vm.c b/runtime/vm.c
index 8cbf9e12..d7cd52d5 100644
--- a/runtime/vm.c
+++ b/runtime/vm.c
@@ -82,6 +82,7 @@ rsfrAddFunction(uchar *szName, prsf_t rsf)
/* unique name, so add to head of list */
CHKmalloc(pEntry = calloc(1, sizeof(rsf_entry_t)));
CHKiRet(rsCStrConstructFromszStr(&pEntry->pName, szName));
+ CHKiRet(cstrFinalize(pEntry->pName));
pEntry->rsf = rsf;
pEntry->pNext = funcRegRoot;
funcRegRoot = pEntry;
@@ -167,7 +168,7 @@ rsfrRemoveAll(void)
while(pEntry != NULL) {
pEntryDel = pEntry;
pEntry = pEntry->pNext;
- rsCStrDestruct(&pEntryDel->pName);
+ cstrDestruct(&pEntryDel->pName);
free(pEntryDel);
}
funcRegRoot = NULL;
@@ -405,6 +406,7 @@ CODESTARTop(STRADD)
vmstk.PopString(pThis->pStk, &operand1);
CHKiRet(rsCStrAppendCStr(operand1->val.pStr, operand2->val.pStr));
+ CHKiRet(cstrFinalize(operand1->val.pStr));
/* we have a result, so let's push it */
vmstk.Push(pThis->pStk, operand1);
@@ -554,12 +556,12 @@ rsf_tolower(vmstk_t *pStk, int numOperands)
ABORT_FINALIZE(RS_RET_INVLD_NBR_ARGUMENTS);
/* pop args and do operaton */
- CHKiRet(rsCStrConstruct(&pcstr));
+ CHKiRet(cstrConstruct(&pcstr));
vmstk.PopString(pStk, &operand1);
- pSrc = rsCStrGetSzStr(operand1->val.pStr);
- iStrlen = strlen((char*)pSrc);
+ pSrc = cstrGetSzStr(operand1->val.pStr);
+ iStrlen = strlen((char*)pSrc); // TODO: use count from string!
while(iStrlen--) {
- CHKiRet(rsCStrAppendChar(pcstr, tolower(*pSrc++)));
+ CHKiRet(cstrAppendChar(pcstr, tolower(*pSrc++)));
}
/* Store result and cleanup */
diff --git a/runtime/vmop.c b/runtime/vmop.c
index acacfc9e..ea627220 100644
--- a/runtime/vmop.c
+++ b/runtime/vmop.c
@@ -125,7 +125,7 @@ Obj2Str(vmop_t *pThis, cstr_t *pstrPrg)
if(pThis->operand.pVar != NULL)
CHKiRet(var.Obj2Str(pThis->operand.pVar, pstrPrg));
}
- CHKiRet(rsCStrAppendChar(pstrPrg, '\n'));
+ CHKiRet(cstrAppendChar(pstrPrg, '\n'));
finalize_it:
RETiRet;
diff --git a/tests/nettester.c b/tests/nettester.c
index 566f553b..b7b3f892 100644
--- a/tests/nettester.c
+++ b/tests/nettester.c
@@ -321,7 +321,9 @@ doTests(int fd, char *files)
if(ret == 0) {
if(verbose) printf("successfully completed\n");
} else {
- if(verbose) printf("failed!\n");
+ if(!verbose)
+ printf("test '%s' ", testFile);
+ printf("failed!\n");
++iFailed;
}
}
diff --git a/tools/syslogd.c b/tools/syslogd.c
index 9f70ff26..cfecfd83 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -1051,7 +1051,7 @@ static int parseRFCStructuredData(uchar **pp2parse, uchar *pResult)
return 0;
}
-/* parse a RFC-formatted syslog message. This function returns
+/* parse a RFC5424-formatted syslog message. This function returns
* 0 if processing of the message shall continue and 1 if something
* went wrong and this messe should be ignored. This function has been
* implemented in the effort to support syslog-protocol. Please note that