From eb5b69d278b1430750a5e1d74bd2804cbc4b14e8 Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Fri, 4 Apr 2014 16:31:24 +0200 Subject: all: unified framework for reporting errors/warnings/info messages to stderr/syslog --- src/squark-filter.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/squark-filter.c') diff --git a/src/squark-filter.c b/src/squark-filter.c index 1955a59..19c3583 100644 --- a/src/squark-filter.c +++ b/src/squark-filter.c @@ -23,12 +23,7 @@ #include "addr.h" #include "filterdb.h" #include "authdb.h" - -#if 0 -#define dbg_printf(x...) fprintf(stderr, x) -#else -#define dbg_printf(x...) -#endif +#include "reporting.h" #define FILTER_OVERRIDE_TIMEOUT (15*60) @@ -244,7 +239,7 @@ static int url_classify(struct url_info *url, struct sqdb *db) if (blob_is_null(got)) break; - dbg_printf("Trying '%.*s'\n", key.len, key.ptr); + report_debug("Trying '%.*s'\n", key.len, key.ptr); previ = i; i = cmph_search_packed(cmph, key.ptr, key.len); @@ -282,7 +277,7 @@ static int url_classify(struct url_info *url, struct sqdb *db) blob_push_urldecode(&keybuf, url->path); keylimits = blob_pushed(BLOB_BUF(buffer), keybuf); - dbg_printf("Checking path components on '%.*s'\n", keylimits.len, keylimits.ptr); + report_debug("Checking path components on '%.*s'\n", keylimits.len, keylimits.ptr); while (indx[i].has_paths) { /* add one more path component */ @@ -290,7 +285,7 @@ static int url_classify(struct url_info *url, struct sqdb *db) if (blob_is_null(got)) break; - dbg_printf("Trying with path '%.*s'\n", key.len, key.ptr); + report_debug("Trying with path '%.*s'\n", key.len, key.ptr); previ = i; i = cmph_search_packed(cmph, key.ptr, key.len); @@ -459,21 +454,34 @@ int main(int argc, char **argv) { int rc = 1, opt; - while ((opt = getopt(argc, argv, "V")) != -1) { + reporting_init("squark-filter"); + + while ((opt = getopt(argc, argv, "Vsqv::")) != -1) { switch (opt) { case 'V': fprintf(stderr, "squark-filter %s\n", squark_version); return 0; + case 's': + reporting_use_syslog(1); + break; + case 'q': + reporting_verbosity(REPORT_ALERT); + break; + case 'v': + if (optarg == 0) + reporting_verbosity(REPORT_INFO); + else if (*optarg == 'v') + reporting_verbosity(REPORT_DEBUG); + break; } } if (sqdb_open(&db, squark_dbname) < 0) { - fprintf(stderr, "%s: failed to open squarkdb\n", - squark_dbname); + report_error("%s: failed to open squarkdb\n", squark_dbname); goto err_sqdb; } if (authdb_open(&adb, &adbc, &db) < 0) { - fprintf(stderr, "Failed to initialize authdb\n"); + report_error("Failed to initialize authdb\n"); goto err_adb; } -- cgit v1.2.3