summaryrefslogtreecommitdiffstats
path: root/stringbuf.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-03-07 16:10:58 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-03-07 16:10:58 +0000
commit549c0cccd44dc36a6ba8c480fa65bcaad6cb20ec (patch)
treeed166a3d83210c30502825d644f5be40a9624b08 /stringbuf.c
parent1888852c9a59631771efb5975aa51ddb0305ceb2 (diff)
downloadrsyslog-549c0cccd44dc36a6ba8c480fa65bcaad6cb20ec.tar.gz
rsyslog-549c0cccd44dc36a6ba8c480fa65bcaad6cb20ec.tar.xz
rsyslog-549c0cccd44dc36a6ba8c480fa65bcaad6cb20ec.zip
extracted regexp functionality to its own dynamically loadable module
Diffstat (limited to 'stringbuf.c')
-rwxr-xr-xstringbuf.c44
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