701
702
* rgerhards, 2007-07-16: bug is no real bug, because rsyslogd ensures there
702
703
* never is a \0 *inside* a property string.
703
704
* Note that the function returns -1 if regexp functionality is not available.
704
* TODO: change calling interface! -- rgerhards, 2008-03-07
705
* rgerhards: 2009-03-04: ERE support added, via parameter iType: 0 - BRE, 1 - ERE
706
* Arnaud Cornet/rgerhards: 2009-04-02: performance improvement by caching compiled regex
707
* If a caller does not need the cached version, it must still provide memory for it
708
* and must call rsCStrRegexDestruct() afterwards.
706
int rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz)
710
rsRetVal rsCStrSzStrMatchRegex(cstr_t *pCS1, uchar *psz, int iType, void *rc)
712
regex_t **cache = (regex_t**) rc;
716
assert(pCS1 != NULL);
718
assert(cache != NULL);
713
720
if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) {
714
regexp.regcomp(&preq, (char*) rsCStrGetSzStr(pCS1), 0);
715
ret = regexp.regexec(&preq, (char*) psz, 0, NULL, 0);
716
regexp.regfree(&preq);
721
if (*cache == NULL) {
722
*cache = calloc(sizeof(regex_t), 1);
723
regexp.regcomp(*cache, (char*) rsCStrGetSzStr(pCS1), (iType == 1 ? REG_EXTENDED : 0) | REG_NOSUB);
725
ret = regexp.regexec(*cache, (char*) psz, 0, NULL, 0);
727
ABORT_FINALIZE(RS_RET_NOT_FOUND);
718
ret = 1; /* simulate "not found" */
729
ABORT_FINALIZE(RS_RET_NOT_FOUND);
737
/* free a cached compiled regex
738
* Caller must provide a pointer to a buffer that was created by
739
* rsCStrSzStrMatchRegexCache()
741
void rsCStrRegexDestruct(void *rc)
743
regex_t **cache = rc;
745
assert(cache != NULL);
746
assert(*cache != NULL);
748
if(objUse(regexp, LM_REGEXP_FILENAME) == RS_RET_OK) {
749
regexp.regfree(*cache);