diff options
Diffstat (limited to 'stringbuf.c')
-rwxr-xr-x | stringbuf.c | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/stringbuf.c b/stringbuf.c index b95892ad..d5b77d99 100755 --- a/stringbuf.c +++ b/stringbuf.c @@ -33,17 +33,20 @@ #include <string.h> #include <ctype.h> #include <sys/types.h> -#include <regex.h> #include "rsyslog.h" #include "stringbuf.h" #include "srUtils.h" +#include "regexp.h" +#include "obj.h" /* ################################################################# * * private members * * ################################################################# */ - +/* static data */ +DEFobjCurrIf(obj) +DEFobjCurrIf(regexp) /* ################################################################# * * public members * @@ -696,18 +699,29 @@ int rsCStrCaseInsensitveStartsWithSzStr(cstr_t *pCS1, uchar *psz, size_t iLenSz) * 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. + * Note that the function returns -1 if regexp functionality is not available. + * TODO: change calling interface! -- rgerhards, 2008-03-07 */ int rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz) { - regex_t preq; - BEGINfunc - regcomp(&preq, (char*) rsCStrGetSzStr(pCS1), 0); - int ret = regexec(&preq, (char*) psz, 0, NULL, 0); - regfree(&preq); - ENDfunc - return ret; + regex_t preq; + int ret; + + BEGINfunc + + if(objUse(regexp, "regexp") == RS_RET_OK) { + regexp.regcomp(&preq, (char*) rsCStrGetSzStr(pCS1), 0); + ret = regexp.regexec(&preq, (char*) psz, 0, NULL, 0); + regexp.regfree(&preq); + } else { + ret = 1; /* simulate "not found" */ + } + + ENDfunc + return ret; } + /* compare a rsCStr object with a classical sz string. This function * is almost identical to rsCStrZsStrCmp(), but it also takes an offset * to the CStr object from where the comparison is to start. @@ -1032,6 +1046,18 @@ int rsCStrLocateSzStr(cstr_t *pThis, uchar *sz) #endif /* end comment out */ +/* our init function. TODO: remove once converted to a class + */ +rsRetVal strInit() +{ + DEFiRet; + CHKiRet(objGetObjInterface(&obj)); + +finalize_it: + RETiRet; +} + + /* * Local variables: * c-indent-level: 8 |