Browse Source

+ src/filter-test.c

master
Alex 'AdUser' Z 9 years ago
parent
commit
b4c03ea506
  1. 3
      src/CMakeLists.txt
  2. 43
      src/filter-test.c

3
src/CMakeLists.txt

@ -9,6 +9,9 @@ set(SOURCES "backend-test.c" "log.c" "backend.c" "config.c")
add_executable("backend-test" ${SOURCES})
target_link_libraries("backend-test" "dl")
set(SOURCES "filter-test.c" "log.c" "regexps_posix.c")
add_executable("filter-test" ${SOURCES})
install(TARGETS f2b
RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")

43
src/filter-test.c

@ -0,0 +1,43 @@
#include "common.h"
#include "log.h"
#include "ipaddr.h"
#include "regexps.h"
void usage() {
fprintf(stderr, "Usage: filter-test <regexps-file.txt> <logfile.txt>\n");
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]) {
FILE *f = NULL;
char matchbuf[IPADDR_MAX] = "";
char logline[LOGLINE_MAX] = "";
f2b_regex_t *list = NULL;
size_t read = 0, matched = 0;
if (argc < 3)
usage();
if ((list = f2b_regexlist_from_file(argv[1])) == NULL) {
f2b_log_msg(log_error, "can't load regexps list from file '%s'", argv[1]);
return EXIT_FAILURE;
}
if ((f = fopen(argv[2], "r")) == NULL) {
f2b_log_msg(log_error, "can't open logfile '%s'", argv[2]);
return EXIT_FAILURE;
}
while (fgets(logline, sizeof(logline), f) != NULL) {
read++;
if (f2b_regexlist_match(list, logline, matchbuf, sizeof(matchbuf))) {
matched++;
f2b_log_msg(log_info, "match found: %s", matchbuf);
continue;
}
f2b_log_msg(log_info, "unmatched line: %s", logline);
}
f2b_log_msg(log_info, "lines read: %d, matched: %d", read, matched);
return EXIT_SUCCESS;
}
Loading…
Cancel
Save