diff options
author | June McEnroe <june@causal.agency> | 2020-07-09 20:39:38 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-09 20:39:38 -0400 |
commit | ec20355dfdcf27f43a7341d225edddd605a3ba7c (patch) | |
tree | 5ee822c7d27a800bb8e717af120f8ee7d42c1344 /events.c | |
parent | Implement very basic events listing (diff) | |
download | scooper-ec20355dfdcf27f43a7341d225edddd605a3ba7c.tar.gz scooper-ec20355dfdcf27f43a7341d225edddd605a3ba7c.zip |
Add before param in redirect
Diffstat (limited to '')
-rw-r--r-- | events.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/events.c b/events.c index 04fdbf8..f40e5ae 100644 --- a/events.c +++ b/events.c @@ -18,6 +18,7 @@ #include <stdio.h> #include <stdlib.h> #include <sysexits.h> +#include <time.h> #include "server.h" @@ -72,19 +73,35 @@ enum kcgi_err pageEvents(struct kreq *req) { if (!req->fieldmap[Network] || !req->fieldmap[Context]) { return httpFail(req, KHTTP_400); } + const char *network = req->fieldmap[Network]->parsed.s; + const char *context = req->fieldmap[Context]->parsed.s; + if (!req->fieldmap[After] && !req->fieldmap[Before]) { - return httpFail(req, KHTTP_400); - } + struct tm *tm = gmtime(&(time_t) { time(NULL) }); + if (!tm) err(EX_OSERR, "gmtime"); - enum kcgi_err error = httpHead(req, KHTTP_200, KMIME_TEXT_HTML); - if (req->method == KMETHOD_HEAD) return error; + char time[sizeof("0000-00-00T00:00:00")]; + strftime(time, sizeof(time), "%FT%T", tm); + + char *url = khttp_urlpart( + NULL, NULL, Pages[Events], + Keys[Network].name, network, + Keys[Context].name, context, + Keys[Before].name, time, + NULL + ); + enum kcgi_err error = httpRedirect(req, url); + free(url); + return error; + } - const char *network = req->fieldmap[Network]->parsed.s; - const char *context = req->fieldmap[Context]->parsed.s; const char *time = req->fieldmap[Before] ? req->fieldmap[Before]->parsed.s : req->fieldmap[After]->parsed.s; + enum kcgi_err error = httpHead(req, KHTTP_200, KMIME_TEXT_HTML); + if (req->method == KMETHOD_HEAD) return error; + struct khtmlreq html; error = error || khttp_body(req) |