summary refs log tree commit diff
path: root/events.c
diff options
context:
space:
mode:
Diffstat (limited to 'events.c')
-rw-r--r--events.c29
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)