Browse Source

* more informative csocket error message

master
Alex 'AdUser' Z 4 years ago
parent
commit
5e0ce72199
  1. 2
      src/csocket.c
  2. 15
      src/filter.c

2
src/csocket.c

@ -99,7 +99,7 @@ f2b_conn_process(f2b_conn_t *conn, bool in, void (*cb)(const f2b_cmd_t *cmd, f2b
cb(cmd, &conn->send); /* handle command */ cb(cmd, &conn->send); /* handle command */
f2b_cmd_destroy(cmd); f2b_cmd_destroy(cmd);
} else { } else {
f2b_buf_append(&conn->send, "can't parse input\n", 0); f2b_buf_append(&conn->send, "can't parse input, try 'help'\n", 0);
} }
free(line); free(line);
} }

15
src/filter.c

@ -16,11 +16,12 @@
#define HOST_TOKEN "<HOST>" #define HOST_TOKEN "<HOST>"
#define FILTER_LIBRARY_PARAM "load" #define FILTER_LIBRARY_PARAM "load"
static bool static size_t
f2b_filter_load_file(f2b_filter_t *filter, const char *path) { f2b_filter_load_file(f2b_filter_t *filter, const char *path) {
f2b_config_param_t *param; f2b_config_param_t *param;
FILE *f = NULL; FILE *f = NULL;
size_t linenum = 0; size_t linenum = 0;
size_t loaded = 0;
char line[REGEX_LINE_MAX] = ""; char line[REGEX_LINE_MAX] = "";
char *p, *q; char *p, *q;
@ -29,7 +30,7 @@ f2b_filter_load_file(f2b_filter_t *filter, const char *path) {
if ((f = fopen(path, "r")) == NULL) { if ((f = fopen(path, "r")) == NULL) {
f2b_log_msg(log_error, "can't open regex list '%s': %s", path, strerror(errno)); f2b_log_msg(log_error, "can't open regex list '%s': %s", path, strerror(errno));
return false; return 0;
} }
filter->flush(filter->cfg); filter->flush(filter->cfg);
@ -73,12 +74,13 @@ f2b_filter_load_file(f2b_filter_t *filter, const char *path) {
f2b_log_msg(log_warn, "can't create regex from pattern at %s:%zu: %s", path, linenum, p); f2b_log_msg(log_warn, "can't create regex from pattern at %s:%zu: %s", path, linenum, p);
continue; continue;
} }
loaded++;
break; break;
} }
} }
fclose(f); fclose(f);
return true; return loaded;
} }
f2b_filter_t * f2b_filter_t *
@ -232,11 +234,14 @@ f2b_filter_cmd_stats(char *buf, size_t bufsize, f2b_filter_t *filter) {
void void
f2b_filter_cmd_reload(char *buf, size_t bufsize, f2b_filter_t *filter) { f2b_filter_cmd_reload(char *buf, size_t bufsize, f2b_filter_t *filter) {
size_t c = 0;
assert(buf != NULL); assert(buf != NULL);
assert(filter != NULL); assert(filter != NULL);
filter->flush(filter->cfg); filter->flush(filter->cfg);
if (f2b_filter_load_file(filter, filter->init)) { if ((c = f2b_filter_load_file(filter, filter->init)) > 0) {
snprintf(buf, bufsize, "can't reload filter"); snprintf(buf, bufsize, "loaded %zu regexps\n", c);
} else {
snprintf(buf, bufsize, "can't reload filter\n");
} }
} }

Loading…
Cancel
Save