summaryrefslogtreecommitdiffstats
path: root/stringbuf.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2005-10-19 11:33:57 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2005-10-19 11:33:57 +0000
commit8dc836cf04eaf061fb4ee31bcc771e2297f7630b (patch)
tree03cf513f99abc17fc9de7351c9323ca2ab0bf357 /stringbuf.c
parent33232dc70bcd6223c8d47536e913edbb4be0a9f7 (diff)
downloadrsyslog-8dc836cf04eaf061fb4ee31bcc771e2297f7630b.tar.gz
rsyslog-8dc836cf04eaf061fb4ee31bcc771e2297f7630b.tar.xz
rsyslog-8dc836cf04eaf061fb4ee31bcc771e2297f7630b.zip
fixing a bug with the "startswith" comparison mode; more work on BSD-style
host blocks
Diffstat (limited to 'stringbuf.c')
-rwxr-xr-xstringbuf.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/stringbuf.c b/stringbuf.c
index fb9a9f46..ea008e77 100755
--- a/stringbuf.c
+++ b/stringbuf.c
@@ -440,13 +440,47 @@ int rsCStrCStrCmp(rsCStrObj *pCS1, rsCStrObj *pCS2)
}
-/* check if a CStr object starts with a sz-type string. This function
+/* check if a sz-type string start with a CStr object. This function
* is initially written to support the "startswith" property-filter
* comparison operation. Maybe it also has other needs.
+ * rgerhards 2005-10-19
+ */
+int rsCStrSzStrStartsWithCStr(rsCStrObj *pCS1, char *psz, int iLenSz)
+{
+ register int i;
+ int iMax;
+
+ rsCHECKVALIDOBJECT(pCS1, OIDrsCStr);
+ assert(psz != NULL);
+ assert(iLenSz == strlen(psz)); /* just make sure during debugging! */
+ if(iLenSz >= pCS1->iStrLen) {
+ /* we need to checkusing pCS1->iStrLen charactes at maximum, thus
+ * we move it to iMax.
+ */
+ iMax = pCS1->iStrLen;
+ if(iMax == 0)
+ return 0; /* yes, it starts with a zero-sized string ;) */
+ else { /* we now have something to compare, so let's do it... */
+ for(i = 0 ; i < iMax ; ++i) {
+ if(psz[i] != pCS1->pBuf[i])
+ return psz[i] - pCS1->pBuf[i];
+ }
+ /* if we arrive here, the string actually starts with pCS1 */
+ return 0;
+ }
+ }
+ else
+ return -1; /* pCS1 is less then psz */
+}
+
+
+/* check if a CStr object starts with a sz-type string.
* rgerhards 2005-09-26
*/
int rsCStrStartsWithSzStr(rsCStrObj *pCS1, char *psz, int iLenSz)
{
+ register int i;
+
rsCHECKVALIDOBJECT(pCS1, OIDrsCStr);
assert(psz != NULL);
assert(iLenSz == strlen(psz)); /* just make sure during debugging! */
@@ -457,7 +491,6 @@ int rsCStrStartsWithSzStr(rsCStrObj *pCS1, char *psz, int iLenSz)
if(iLenSz == 0)
return 0; /* yes, it starts with a zero-sized string ;) */
else { /* we now have something to compare, so let's do it... */
- register int i;
for(i = 0 ; i < iLenSz ; ++i) {
if(pCS1->pBuf[i] != psz[i])
return pCS1->pBuf[i] - psz[i];
@@ -540,7 +573,6 @@ int rsCStrSzStrCmp(rsCStrObj *pCS1, char *psz, int iLenSz)
{
rsCHECKVALIDOBJECT(pCS1, OIDrsCStr);
assert(psz != NULL);
-printf("strlen('%s'): %d, given %d\n", psz, strlen(psz), iLenSz);
assert(iLenSz == strlen(psz)); /* just make sure during debugging! */
if(pCS1->iStrLen == iLenSz)
/* we are using iLenSz below, because the lengths