Browse Source

+ f2b_filter_stats()

master
Alex 'AdUser' Z 8 years ago
parent
commit
ce86ddd4c0
  1. 18
      src/filter.c
  2. 1
      src/filter.h

18
src/filter.c

@ -171,3 +171,21 @@ f2b_filter_error(f2b_filter_t *filter) {
assert(filter != NULL);
return filter->error(filter->cfg);
}
void
f2b_filter_stats(f2b_filter_t *filter, char *res, size_t ressize) {
assert(filter != NULL);
assert(res != NULL);
bool reset = true;
char *pattern;
int matches;
char buf[256];
const char *fmt =
"- pattern: %s\n"
" matches: %d\n";
while (filter->stats(filter->cfg, &matches, &pattern, reset)) {
snprintf(buf, sizeof(buf), fmt, pattern, matches);
strlcat(res, buf, ressize);
reset = false;
}
}

1
src/filter.h

@ -29,5 +29,6 @@ void f2b_filter_destroy(f2b_filter_t *b);
bool f2b_filter_append(f2b_filter_t *b, const char *pattern);
bool f2b_filter_match(f2b_filter_t *b, const char *line, char *buf, size_t buf_size);
const char * f2b_filter_error(f2b_filter_t *b);
void f2b_filter_stats (f2b_filter_t *b, char *res, size_t ressize);
#endif /* F2B_FILTER_H_ */

Loading…
Cancel
Save