summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-04-02 16:16:57 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-04-02 16:16:57 +0200
commita86e42028afeba1daca262b590bfd49d9c393b90 (patch)
treec9276d5a21fbe13b2c819137d705f696ea15ea1d
parenteb807027af9e126a212b0630c5873dddae48963b (diff)
downloadrsyslog-a86e42028afeba1daca262b590bfd49d9c393b90.tar.gz
rsyslog-a86e42028afeba1daca262b590bfd49d9c393b90.tar.xz
rsyslog-a86e42028afeba1daca262b590bfd49d9c393b90.zip
improved performance of regexp-based filters
Thanks to Arnaud Cornet for providing the idea and initial patch.
-rw-r--r--runtime/stringbuf.c30
-rw-r--r--runtime/stringbuf.h2
-rw-r--r--tools/syslogd.c8
-rw-r--r--tools/syslogd.h1
4 files changed, 39 insertions, 2 deletions
diff --git a/runtime/stringbuf.c b/runtime/stringbuf.c
index a5dc625a..c0a19ae4 100644
--- a/runtime/stringbuf.c
+++ b/runtime/stringbuf.c
@@ -724,6 +724,36 @@ finalize_it:
RETiRet;
}
+/* same as above, only not braindead */
+int rsCStrSzStrMatchRegexCache(cstr_t *pCS1, uchar *psz, void **rc)
+{
+ int ret;
+
+ BEGINfunc
+
+ if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) {
+ regex_t **cache = rc;
+ if (*cache == NULL) {
+ *cache = calloc(sizeof(regex_t), 1);
+ regexp.regcomp(*cache, (char*) rsCStrGetSzStr(pCS1), 0);
+ }
+ ret = regexp.regexec(*cache, (char*) psz, 0, NULL, 0);
+ } else {
+ ret = 1; /* simulate "not found" */
+ }
+
+ ENDfunc
+ return ret;
+}
+
+/* free a cached compiled regex */
+void rsRegexDestruct(void **rc) {
+ regex_t **cache = rc;
+ regexp.regfree(*cache);
+ free(*cache);
+ *cache = NULL;
+}
+
/* 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/runtime/stringbuf.h b/runtime/stringbuf.h
index f3e08439..4b0fb065 100644
--- a/runtime/stringbuf.h
+++ b/runtime/stringbuf.h
@@ -137,6 +137,8 @@ int rsCStrStartsWithSzStr(cstr_t *pCS1, uchar *psz, size_t iLenSz);
int rsCStrCaseInsensitveStartsWithSzStr(cstr_t *pCS1, uchar *psz, size_t iLenSz);
int rsCStrSzStrStartsWithCStr(cstr_t *pCS1, uchar *psz, size_t iLenSz);
rsRetVal rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz, int iType);
+int rsCStrSzStrMatchRegexCache(cstr_t *pCS1, uchar *psz, void **cache);
+void rsRegexDestruct(void **rc);
rsRetVal rsCStrConvertToNumber(cstr_t *pStr, number_t *pNumber);
rsRetVal rsCStrConvertToBool(cstr_t *pStr, number_t *pBool);
rsRetVal rsCStrAppendCStr(cstr_t *pThis, cstr_t *pstrAppend);
diff --git a/tools/syslogd.c b/tools/syslogd.c
index 16f255ea..c7f36b45 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -432,6 +432,8 @@ selectorDestruct(void *pVal)
} else if(pThis->f_filter_type == FILTER_EXPR) {
if(pThis->f_filterData.f_expr != NULL)
expr.Destruct(&pThis->f_filterData.f_expr);
+ if(pThis->regex_cache != NULL)
+ rsRegexDestruct(&pThis->regex_cache);
}
llDestroy(&pThis->llActList);
@@ -1075,8 +1077,10 @@ static rsRetVal shouldProcessThisMessage(selector_t *f, msg_t *pMsg, int *bProce
bRet = 1; /* process message! */
break;
case FIOP_REGEX:
- if(rsCStrSzStrMatchRegex(f->f_filterData.prop.pCSCompValue,
- (unsigned char*) pszPropVal, 0) == RS_RET_OK)
+ //TODO REGEX: this needs to be merged with new functionality below
+ //rgerhards, 2009-04-02
+ if(rsCStrSzStrMatchRegexCache(f->f_filterData.prop.pCSCompValue,
+ (unsigned char*) pszPropVal, &f->regex_cache) == 0)
bRet = 1;
break;
case FIOP_EREREGEX:
diff --git a/tools/syslogd.h b/tools/syslogd.h
index f1b11a91..ecaaec34 100644
--- a/tools/syslogd.h
+++ b/tools/syslogd.h
@@ -80,6 +80,7 @@ struct filed {
} f_filterData;
linkedList_t llActList; /* list of configured actions */
+regex_t *regex_cache;
};