diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2007-07-16 06:26:39 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2007-07-16 06:26:39 +0000 |
commit | 6d9e5d4e27a221ac0308d6df006e20966fe22959 (patch) | |
tree | 449827c651b0af0f87a30c33d9f54b4563f778c1 | |
parent | 594ef8b85342fcb2aab5ac1d39623a07d643c921 (diff) | |
download | rsyslog-6d9e5d4e27a221ac0308d6df006e20966fe22959.tar.gz rsyslog-6d9e5d4e27a221ac0308d6df006e20966fe22959.tar.xz rsyslog-6d9e5d4e27a221ac0308d6df006e20966fe22959.zip |
integrated patch by Michel Samia to provide regex support for the filter
engine - many thanks!
-rw-r--r-- | ChangeLog | 2 | ||||
-rwxr-xr-x | stringbuf.c | 18 | ||||
-rwxr-xr-x | stringbuf.h | 1 | ||||
-rw-r--r-- | syslogd-types.h | 3 | ||||
-rw-r--r-- | syslogd.c | 10 |
5 files changed, 33 insertions, 1 deletions
@@ -1,6 +1,8 @@ --------------------------------------------------------------------------- Version 1.16.0 (RGer), 2007-07-1? - added $RepeatedLineReduction config parameter +- added regular expression support to the filter engine + thanks to Michel Samia for providing the patch! --------------------------------------------------------------------------- Version 1.16.0 (RGer/Peter Vrabec), 2007-07-13 - The Friday, 13th Release ;) - build system switched to autotools diff --git a/stringbuf.c b/stringbuf.c index 48c63b40..140f74aa 100755 --- a/stringbuf.c +++ b/stringbuf.c @@ -14,10 +14,13 @@ #include <assert.h> #include <string.h> #include <ctype.h> +#include <sys/types.h> +#include <regex.h> #include "rsyslog.h" #include "stringbuf.h" #include "srUtils.h" + /* ################################################################# * * private members * * ################################################################# */ @@ -535,6 +538,21 @@ int rsCStrStartsWithSzStr(rsCStrObj *pCS1, unsigned char *psz, int iLenSz) return -1; /* pCS1 is less then psz */ } +/* check if a CStr object matches a regex. + * msamia@redhat.com 2007-07-12 + * @return returns 0 if matched + * bug: doesn't work for CStr containing \0 + * rgerhards, 2007-07-16: bug is no real bug, because rsyslogd ensures there + * never is a \0 *inside* a property string. + */ +int rsCStrSzStrMatchRegex(rsCStrObj *pCS1, unsigned char *psz, int iLenSz) +{ + regex_t preq; + regcomp(&preq, rsCStrGetSzStr(pCS1), 0); + int iRet = regexec(&preq, psz, 0, NULL, 0); + regfree(&preq); + return iRet; +} /* compare a rsCStr object with a classical sz string. This function * is almost identical to rsCStrZsStrCmp(), but it also takes an offset diff --git a/stringbuf.h b/stringbuf.h index de66051c..65dfe63f 100755 --- a/stringbuf.h +++ b/stringbuf.h @@ -121,6 +121,7 @@ int rsCStrLocateSzStr(rsCStrObj *pCStr, unsigned char *sz); int rsCStrLocateInSzStr(rsCStrObj *pThis, unsigned char *sz);
int rsCStrStartsWithSzStr(rsCStrObj *pCS1, unsigned char *psz, int iLenSz);
int rsCStrSzStrStartsWithCStr(rsCStrObj *pCS1, unsigned char *psz, int iLenSz);
+int rsCStrSzStrMatchRegex(rsCStrObj *pCS1, unsigned char *psz, int iLenSz);
/* now come inline-like functions */
#ifdef NDEBUG
diff --git a/syslogd-types.h b/syslogd-types.h index 2ae0964a..852b19ea 100644 --- a/syslogd-types.h +++ b/syslogd-types.h @@ -203,7 +203,8 @@ struct filed { FIOP_NOP = 0, /* do not use - No Operation */ FIOP_CONTAINS = 1, /* contains string? */ FIOP_ISEQUAL = 2, /* is (exactly) equal? */ - FIOP_STARTSWITH = 3 /* starts with a string? */ + FIOP_STARTSWITH = 3, /* starts with a string? */ + FIOP_REGEX = 4 /* matches a regular expression? */ } operation; rsCStrObj *pCSCompValue; /* value to "compare" against */ char isNegated; /* actually a boolean ;) */ @@ -690,6 +690,9 @@ static char* getFIOPName(unsigned iFIOP) case FIOP_STARTSWITH: pRet = "startswith"; break; + case FIOP_REGEX: + pRet = "regex"; + break; default: pRet = "NOP"; break; @@ -4623,6 +4626,11 @@ int shouldProcessThisMessage(selector_t *f, msg_t *pMsg) (uchar*) pszPropVal, strlen(pszPropVal)) == 0) iRet = 1; /* process message! */ break; + case FIOP_REGEX: + if(rsCStrSzStrMatchRegex(f->f_filterData.prop.pCSCompValue, + (unsigned char*) pszPropVal, strlen(pszPropVal)) == 0) + iRet = 1; + break; default: /* here, it handles NOP (for performance reasons) */ assert(f->f_filterData.prop.operation == FIOP_NOP); @@ -8112,6 +8120,8 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f) f->f_filterData.prop.operation = FIOP_ISEQUAL; } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (uchar*) "startswith", 10)) { f->f_filterData.prop.operation = FIOP_STARTSWITH; + } else if(!rsCStrOffsetSzStrCmp(pCSCompOp, iOffset, (unsigned char*) "regex", 5)) { + f->f_filterData.prop.operation = FIOP_REGEX; } else { logerrorSz("error: invalid compare operation '%s' - ignoring selector", (char*) rsCStrGetSzStr(pCSCompOp)); |