Browse Source

* stats() impl for filter/preg

master
Alex 'AdUser' Z 8 years ago
parent
commit
a5d1b0b5e5
  1. 20
      src/filters/preg.c

20
src/filters/preg.c

@ -19,6 +19,7 @@
typedef struct f2b_regex_t {
struct f2b_regex_t *next;
char pattern[PATTERN_MAX];
int matches;
regex_t regex;
} f2b_regex_t;
@ -28,6 +29,7 @@ struct _config {
char error[256];
bool icase;
f2b_regex_t *regexps;
f2b_regex_t *statp;
};
cfg_t *
@ -86,6 +88,7 @@ append(cfg_t *cfg, const char *pattern) {
if (regcomp(&regex->regex, buf, flags) == 0) {
regex->next = cfg->regexps;
cfg->regexps = regex;
snprintf(regex->pattern, sizeof(regex->pattern), "%s", pattern);
return true;
}
@ -101,6 +104,23 @@ ready(cfg_t *cfg) {
return false;
}
bool
stats(cfg_t *cfg, int *matches, char **pattern, bool reset) {
assert(cfg != NULL);
if (reset)
cfg->statp = cfg->regexps;
if (cfg->statp) {
*matches = cfg->statp->matches;
*pattern = cfg->statp->pattern;
cfg->statp = cfg->statp->next;
return true;
}
return false;
}
const char *
error(cfg_t *cfg) {
assert(cfg != NULL);

Loading…
Cancel
Save