diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-06-13 17:51:22 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-06-13 17:51:22 +0200 |
commit | ba00396eee5b8f8717639da396b010631ad5baa7 (patch) | |
tree | 2e5cda12795a2d238de360d6674aa852b0295157 /grammar/rainerscript.c | |
parent | c8324b3460a85d57ca1bcfa481168d566069a0d1 (diff) | |
download | rsyslog-ba00396eee5b8f8717639da396b010631ad5baa7.tar.gz rsyslog-ba00396eee5b8f8717639da396b010631ad5baa7.tar.xz rsyslog-ba00396eee5b8f8717639da396b010631ad5baa7.zip |
re_match() function now also executes
things now basically work. however, there is at least a (small)
memory leak and the code needs to be further reviewed
Diffstat (limited to 'grammar/rainerscript.c')
-rw-r--r-- | grammar/rainerscript.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index dfaff869..2f7057c5 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -754,8 +754,7 @@ var2Number(struct var *r, int *bSuccess) return n; } -/* ensure that retval is a string; if string is no number, - * emit error message and set number to 0. +/* ensure that retval is a string */ static inline es_str_t * var2String(struct var *r, int *bMustFree) @@ -779,6 +778,7 @@ doFuncCall(struct cnffunc *func, struct var *ret, void* usrptr) int bMustFree; es_str_t *estr; char *str; + int retval; struct var r[CNFFUNC_MAX_ARGS]; dbgprintf("rainerscript: executing function id %d\n", func->fID); @@ -844,9 +844,21 @@ doFuncCall(struct cnffunc *func, struct var *ret, void* usrptr) ret->datatype = 'N'; break; case CNFFUNC_RE_MATCH: - dbgprintf("TODO: implement re_match()\n"); - ret->d.n = 1; + cnfexprEval(func->expr[0], &r[0], usrptr); + estr = var2String(&r[0], &bMustFree); + str = es_str2cstr(estr, NULL); + retval = regexp.regexec(func->funcdata, str, 0, NULL, 0); + if(retval == 0) + ret->d.n = 1; + else { + ret->d.n = 0; + if(retval != REG_NOMATCH) { + DBGPRINTF("re_match: regexec returned error %d\n", retval); + } + } ret->datatype = 'N'; + if(bMustFree) es_deleteStr(estr); + free(str); break; default: if(Debug) { |