diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2005-09-09 12:52:23 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2005-09-09 12:52:23 +0000 |
commit | 9a39532d953ac2a486635316ffd1970c993753de (patch) | |
tree | 63e02509d3d211d6be13e94c6ea34e51473b7a09 | |
parent | 602fb17d3307d3dbe619ec559688c5b0c2ebc47c (diff) | |
download | rsyslog-9a39532d953ac2a486635316ffd1970c993753de.tar.gz rsyslog-9a39532d953ac2a486635316ffd1970c993753de.tar.xz rsyslog-9a39532d953ac2a486635316ffd1970c993753de.zip |
initial implementation of the counted string class completed (but so far
only a very feature-less class). code compiles again.
-rw-r--r-- | outchannel.c | 22 | ||||
-rwxr-xr-x | stringbuf.c | 20 | ||||
-rwxr-xr-x | stringbuf.h | 2 | ||||
-rw-r--r-- | syslogd.c | 15 | ||||
-rw-r--r-- | template.c | 42 |
5 files changed, 67 insertions, 34 deletions
diff --git a/outchannel.c b/outchannel.c index cade0492..d6351b68 100644 --- a/outchannel.c +++ b/outchannel.c @@ -79,7 +79,7 @@ static void skip_Comma(char **pp) static int get_Field(char **pp, char **pField) { register char *p; - sbStrBObj *pStrB; + rsCStrObj *pStrB; assert(pp != NULL); assert(*pp != NULL); @@ -88,17 +88,18 @@ static int get_Field(char **pp, char **pField) skip_Comma(pp); p = *pp; - if((pStrB = sbStrBConstruct()) == NULL) + if((pStrB = rsCStrConstruct()) == NULL) return 1; - sbStrBSetAllocIncrement(pStrB, 32); + rsCStrSetAllocIncrement(pStrB, 32); /* copy the field */ while(*p && *p != ' ' && *p != ',') { - sbStrBAppendChar(pStrB, *p++); + rsCStrAppendChar(pStrB, *p++); } *pp = p; - *pField = sbStrBFinish(pStrB); + rsCStrFinish(pStrB); + *pField = rsCStrConvSzStrAndDestruct(pStrB); return 0; } @@ -142,7 +143,7 @@ static int get_off_t(char **pp, off_t *pOff_t) static int get_restOfLine(char **pp, char **pBuf) { register char *p; - sbStrBObj *pStrB; + rsCStrObj *pStrB; assert(pp != NULL); assert(*pp != NULL); @@ -151,17 +152,18 @@ static int get_restOfLine(char **pp, char **pBuf) skip_Comma(pp); p = *pp; - if((pStrB = sbStrBConstruct()) == NULL) + if((pStrB = rsCStrConstruct()) == NULL) return 1; - sbStrBSetAllocIncrement(pStrB, 32); + rsCStrSetAllocIncrement(pStrB, 32); /* copy the field */ while(*p) { - sbStrBAppendChar(pStrB, *p++); + rsCStrAppendChar(pStrB, *p++); } *pp = p; - *pBuf = sbStrBFinish(pStrB); + rsCStrFinish(pStrB); + *pBuf = rsCStrConvSzStrAndDestruct(pStrB); return 0; } diff --git a/stringbuf.c b/stringbuf.c index 11a1f5e4..0c5493d0 100755 --- a/stringbuf.c +++ b/stringbuf.c @@ -136,6 +136,7 @@ srRetVal rsCStrAppendChar(rsCStrObj *pThis, char c) char* rsCStrConvSzStrAndDestruct(rsCStrObj *pThis) { char* pRetBuf; + int i; sbSTRBCHECKVALIDOBJECT(pThis); @@ -153,6 +154,16 @@ char* rsCStrConvSzStrAndDestruct(rsCStrObj *pThis) *(pThis->pszBuf + pThis->iStrLen) = '\0'; } } + /* we now need to do a sanity check. The string mgiht contain a + * \0 byte. There is no way how a sz string can handle this. For + * the time being, we simply replace it with space - something that + * could definitely be improved (TODO). + * 2005-09-09 rgerhards + */ + for(i = 0 ; i < pThis->iStrLen ; ++i) { + if(*(pThis->pszBuf + i) == '\0') + *(pThis->pszBuf + i) = ' '; + } /* We got it, now free the object ourselfs. Please note * that we can NOT use the rsCStrDestruct function as it would @@ -202,6 +213,15 @@ void rsCStrSetAllocIncrement(rsCStrObj *pThis, int iNewIncrement) pThis->iAllocIncrement = iNewIncrement; } +/* return the length of the current string + * 2005-09-09 rgerhards + */ +int rsCStrLen(rsCStrObj *pThis) +{ + sbSTRBCHECKVALIDOBJECT(pThis); + return(pThis->iStrLen); +} + /* * Local variables: * c-indent-level: 8 diff --git a/stringbuf.h b/stringbuf.h index c53ff2d5..e0138bdc 100755 --- a/stringbuf.h +++ b/stringbuf.h @@ -102,4 +102,6 @@ void rsCStrSetAllocIncrement(rsCStrObj *pThis, int iNewIncrement); srRetVal rsCStrAppendInt(rsCStrObj *pThis, int i);
+char* rsCStrConvSzStrAndDestruct(rsCStrObj *pThis);
+int rsCStrLen(rsCStrObj *pThis);
#endif
@@ -3265,7 +3265,8 @@ void logmsg(pri, pMsg, flags) ++p2parse; rsCStrAppendChar(pStrB, ':'); } - MsgAssignTAG(pMsg, rsCStrFinish(pStrB)); + rsCStrFinish(pStrB); + MsgAssignTAG(pMsg, rsCStrConvSzStrAndDestruct(pStrB)); } else { /* we have no TAG, so we ... */ /*DO NOTHING*/; @@ -3435,7 +3436,8 @@ void doSQLEscape(char **pp, size_t *pLen, unsigned short *pbMustBeFreed) if(*p == '\'') { if(rsCStrAppendChar(pStrB, '\'') != SR_RET_OK) { doSQLEmergencyEscape(*pp); - if((pszGenerated = rsCStrFinish(pStrB)) + rsCStrFinish(pStrB); + if((pszGenerated = rsCStrConvSzStrAndDestruct(pStrB)) != NULL) free(pszGenerated); return; @@ -3444,14 +3446,16 @@ void doSQLEscape(char **pp, size_t *pLen, unsigned short *pbMustBeFreed) } if(rsCStrAppendChar(pStrB, *p) != SR_RET_OK) { doSQLEmergencyEscape(*pp); - if((pszGenerated = rsCStrFinish(pStrB)) + rsCStrFinish(pStrB); + if((pszGenerated = rsCStrConvSzStrAndDestruct(pStrB)) != NULL) free(pszGenerated); return; } ++p; } - if((pszGenerated = rsCStrFinish(pStrB)) == NULL) { + rsCStrFinish(pStrB); + if((pszGenerated = rsCStrConvSzStrAndDestruct(pStrB)) == NULL) { doSQLEmergencyEscape(*pp); return; } @@ -3507,7 +3511,8 @@ char *iovAsString(struct filed *f) ++v; } - f->f_psziov = rsCStrFinish(pStrB); + rsCStrFinish(pStrB); + f->f_psziov = rsCStrConvSzStrAndDestruct(pStrB); return f->f_psziov; } @@ -84,7 +84,7 @@ struct template* tplConstruct(void) static int do_Constant(char **pp, struct template *pTpl) { register char *p; - sbStrBObj *pStrB; + rsCStrObj *pStrB; struct templateEntry *pTpe; int i; @@ -94,9 +94,9 @@ static int do_Constant(char **pp, struct template *pTpl) p = *pp; - if((pStrB = sbStrBConstruct()) == NULL) + if((pStrB = rsCStrConstruct()) == NULL) return 1; - sbStrBSetAllocIncrement(pStrB, 32); + rsCStrSetAllocIncrement(pStrB, 32); /* process the message and expand escapes * (additional escapes can be added here if needed) */ @@ -105,22 +105,22 @@ static int do_Constant(char **pp, struct template *pTpl) switch(*++p) { case '\0': /* the best we can do - it's invalid anyhow... */ - sbStrBAppendChar(pStrB, *p); + rsCStrAppendChar(pStrB, *p); break; case 'n': - sbStrBAppendChar(pStrB, '\n'); + rsCStrAppendChar(pStrB, '\n'); ++p; break; case 'r': - sbStrBAppendChar(pStrB, '\r'); + rsCStrAppendChar(pStrB, '\r'); ++p; break; case '\\': - sbStrBAppendChar(pStrB, '\\'); + rsCStrAppendChar(pStrB, '\\'); ++p; break; case '%': - sbStrBAppendChar(pStrB, '%'); + rsCStrAppendChar(pStrB, '%'); ++p; break; case '0': /* numerical escape sequence */ @@ -137,15 +137,15 @@ static int do_Constant(char **pp, struct template *pTpl) while(*p && isdigit(*p)) { i = i * 10 + *p++ - '0'; } - sbStrBAppendChar(pStrB, i); + rsCStrAppendChar(pStrB, i); break; default: - sbStrBAppendChar(pStrB, *p++); + rsCStrAppendChar(pStrB, *p++); break; } } else - sbStrBAppendChar(pStrB, *p++); + rsCStrAppendChar(pStrB, *p++); } if((pTpe = tpeConstruct(pTpl)) == NULL) { @@ -157,11 +157,14 @@ static int do_Constant(char **pp, struct template *pTpl) return 1; } pTpe->eEntryType = CONSTANT; - pTpe->data.constant.pConstant = sbStrBFinish(pStrB); - /* we need to call strlen() below because of the escape sequneces. - * due to them p -*pp is NOT the right size! + rsCStrFinish(pStrB); + /* We obtain the length from the counted string object + * (before we delete it). Later we might take additional + * benefit from the counted string object. + * 2005-09-09 rgerhards */ - pTpe->data.constant.iLenConstant = strlen(pTpe->data.constant.pConstant); + pTpe->data.constant.iLenConstant = rsCStrLen(pStrB); + pTpe->data.constant.pConstant = rsCStrConvSzStrAndDestruct(pStrB); *pp = p; @@ -231,7 +234,7 @@ static void doOptions(char **pp, struct templateEntry *pTpe) static int do_Parameter(char **pp, struct template *pTpl) { char *p; - sbStrBObj *pStrB; + rsCStrObj *pStrB; struct templateEntry *pTpe; int iNum; /* to compute numbers */ @@ -241,7 +244,7 @@ static int do_Parameter(char **pp, struct template *pTpl) p = *pp; - if((pStrB = sbStrBConstruct()) == NULL) + if((pStrB = rsCStrConstruct()) == NULL) return 1; if((pTpe = tpeConstruct(pTpl)) == NULL) { @@ -252,11 +255,12 @@ static int do_Parameter(char **pp, struct template *pTpl) pTpe->eEntryType = FIELD; while(*p && *p != '%' && *p != ':') { - sbStrBAppendChar(pStrB, *p++); + rsCStrAppendChar(pStrB, *p++); } /* got the name*/ - pTpe->data.field.pPropRepl = sbStrBFinish(pStrB); + rsCStrFinish(pStrB); + pTpe->data.field.pPropRepl = rsCStrConvSzStrAndDestruct(pStrB); /* check frompos */ if(*p == ':') { |