diff options
author | Christian Hesse <mail@eworm.de> | 2021-05-28 13:40:18 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2021-06-07 09:59:03 +0200 |
commit | 4a4d07193cba5e07ba4c4d94d241cc438b8b2b7c (patch) | |
tree | fdb481b68d792d9e409d8c365664f92b1e91d1d1 | |
parent | d43852fc9ff49b558a376ffc58f938fa62f028cc (diff) | |
download | pacredir-4a4d07193cba5e07ba4c4d94d241cc438b8b2b7c.tar.gz pacredir-4a4d07193cba5e07ba4c4d94d241cc438b8b2b7c.tar.zst |
get the db timestamp from http request
-rw-r--r-- | config.def.h | 3 | ||||
-rw-r--r-- | pacredir.c | 25 | ||||
-rw-r--r-- | pacredir.h | 1 |
3 files changed, 11 insertions, 18 deletions
diff --git a/config.def.h b/config.def.h index 94c5161..76e86d9 100644 --- a/config.def.h +++ b/config.def.h @@ -45,9 +45,6 @@ /* these characters are used as delimiter in config file */ #define DELIMITER " ,;" -/* this is where pacman stores its local copy of db files */ -#define SYNCPATH "/var/lib/pacman/sync" - /* This defines the initial time in seconds after which a host is queried * again after a bad request. Time is doubled after every subsequent * request. */ @@ -371,14 +371,15 @@ static mhd_result ahc_echo(void * cls, const char * basename, * host = NULL; struct timeval tv; - struct stat fst; - char * filename; + struct tm tm; + const char * if_modified_since = NULL; + time_t last_modified = 0; uint8_t dbfile = 0; int i, error, req_count = -1; pthread_t * tid = NULL; struct request ** requests = NULL; struct request * request = NULL; - long http_code = 0, last_modified = 0; + long http_code = 0; double time_total = INFINITY; char ctime[26]; @@ -429,17 +430,13 @@ static mhd_result ahc_echo(void * cls, goto response; } - /* get timestamp of local file */ - filename = malloc(strlen(SYNCPATH) + strlen(basename) + 2); - sprintf(filename, SYNCPATH "/%s", basename); - - if (stat(filename, &fst) != 0) { - if (verbose > 0) - write_log(stdout, "You do not have a local copy of %s\n", basename); - } else - last_modified = fst.st_mtime; - - free(filename); + /* get timestamp from request */ + if ((if_modified_since = MHD_lookup_connection_value(connection, + MHD_HEADER_KIND, MHD_HTTP_HEADER_IF_MODIFIED_SINCE))) { + if (strptime(if_modified_since, "%a, %d %b %Y %H:%M:%S %Z", &tm) != NULL) { + last_modified = timegm(&tm); + } + } } /* try to find a server with most recent file */ @@ -32,7 +32,6 @@ #include <stdlib.h> #include <string.h> #include <sys/socket.h> -#include <sys/stat.h> #include <time.h> /* systemd headers */ |