From edbadb4ad430651654435e5d605a20ff9da172f8 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sun, 30 Jun 2019 22:45:15 +0200 Subject: allow to ignore database files --- pacredir.c | 12 +++++++++++- pacredir.conf | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pacredir.c b/pacredir.c index df6614e..051ff67 100644 --- a/pacredir.c +++ b/pacredir.c @@ -22,7 +22,7 @@ struct hosts * hosts = NULL; struct ignore_interfaces * ignore_interfaces = NULL; int max_threads = 0; static AvahiSimplePoll *simple_poll = NULL; -uint8_t verbose = 0; +uint8_t verbose = 0, ignore_db_files = 0; unsigned int count_redirect = 0, count_not_found = 0; /*** write_log ***/ @@ -409,6 +409,13 @@ static int ahc_echo(void * cls, /* process db file request (*.db and *.files) */ if ((strlen(basename) > 3 && strcmp(basename + strlen(basename) - 3, ".db") == 0) || (strlen(basename) > 6 && strcmp(basename + strlen(basename) - 6, ".files") == 0)) { + + /* return 404 if database file are disabled */ + if (ignore_db_files > 0) { + http_code = MHD_HTTP_NOT_FOUND; + goto response; + } + dbfile = 1; /* get timestamp of local file */ filename = malloc(strlen(SYNCPATH) + strlen(basename) + 2); @@ -683,6 +690,9 @@ int main(int argc, char ** argv) { if (verbose > 0 && max_threads > 0) write_log(stdout, "Limiting number of threads to a maximum of %d\n", max_threads); + /* whether to ignore db files */ + ignore_db_files = iniparser_getboolean(ini, "general:ignore db files", ignore_db_files); + /* store interfaces to ignore */ if ((inistring = iniparser_getstring(ini, "general:ignore interfaces", NULL)) != NULL) { values = strdup(inistring); diff --git a/pacredir.conf b/pacredir.conf index 9045af7..3d79d1e 100644 --- a/pacredir.conf +++ b/pacredir.conf @@ -10,6 +10,10 @@ max threads = 0 #max threads = 32 +# Set this to true if you want to ignore database files, to always download +# them from mirrors. +ignore db files = false + # Some people like to run avahi on network interfaces with low bandwidth or # high cost, for example to use 'Bonjour' (Link-Local Messaging) on it. # Add these interfaces here to ignore them by pacredir. Just give multiple -- cgit v1.2.3-70-g09d2 From d4ca52db773f2e799e84150428bf705bd78d1624 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 1 Jul 2019 14:04:23 +0200 Subject: use proper log message when ignoring database files --- pacredir.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pacredir.c b/pacredir.c index 051ff67..210c7d3 100644 --- a/pacredir.c +++ b/pacredir.c @@ -410,13 +410,14 @@ static int ahc_echo(void * cls, if ((strlen(basename) > 3 && strcmp(basename + strlen(basename) - 3, ".db") == 0) || (strlen(basename) > 6 && strcmp(basename + strlen(basename) - 6, ".files") == 0)) { + dbfile = 1; + /* return 404 if database file are disabled */ if (ignore_db_files > 0) { http_code = MHD_HTTP_NOT_FOUND; goto response; } - dbfile = 1; /* get timestamp of local file */ filename = malloc(strlen(SYNCPATH) + strlen(basename) + 2); sprintf(filename, SYNCPATH "/%s", basename); @@ -553,10 +554,12 @@ response: ret = MHD_queue_response(connection, MHD_HTTP_TEMPORARY_REDIRECT, response); free(url); } else { - if (req_count < 0) + if (dbfile > 0 && ignore_db_files > 0) + write_log(stdout, "Ignoring request for db file %s.\n", basename); + else if (req_count < 0) write_log(stdout, "Currently no servers are available to check for %s.\n", basename); - else if (dbfile == 1) + else if (dbfile > 0) write_log(stdout, "No more recent version of %s found on %d servers.\n", basename, req_count + 1); else -- cgit v1.2.3-70-g09d2