summary refs log tree commit diff
path: root/events.c
diff options
context:
space:
mode:
Diffstat (limited to 'events.c')
-rw-r--r--events.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/events.c b/events.c
index 32e94c2..5e332a3 100644
--- a/events.c
+++ b/events.c
@@ -70,11 +70,8 @@ const char *EventsBeforeQuery = SQL(
 );
 
 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;
+	struct Scope scope = htmlScope(req);
+	if (!scope.network || !scope.context) return httpFail(req, KHTTP_400);
 
 	if (!req->fieldmap[After] && !req->fieldmap[Before]) {
 		struct tm *tm = gmtime(&(time_t) { time(NULL) });
@@ -85,8 +82,8 @@ enum kcgi_err pageEvents(struct kreq *req) {
 
 		char *url = khttp_urlpart(
 			NULL, NULL, Pages[Events],
-			Keys[Network].name, network,
-			Keys[Context].name, context,
+			Keys[Network].name, scope.network,
+			Keys[Context].name, scope.context,
 			Keys[Before].name, time,
 			NULL
 		);
@@ -106,16 +103,16 @@ enum kcgi_err pageEvents(struct kreq *req) {
 	error = error
 		|| khttp_body(req)
 		|| khtml_open(&html, req, KHTML_PRETTY)
-		|| htmlHead(&html, context)
-		|| htmlNav(&html, network, context)
+		|| htmlHead(&html, scope.context)
+		|| htmlNav(&html, scope)
 		|| khtml_elem(&html, KELEM_TABLE);
 	if (error) return error;
 
 	sqlite3_stmt *events = stmt.eventsAfter;
 	if (req->fieldmap[Before]) events = stmt.eventsBefore;
 
-	dbBindText(events, ":network", network);
-	dbBindText(events, ":context", context);
+	dbBindText(events, ":network", scope.network);
+	dbBindText(events, ":context", scope.context);
 	if (pagePublic) dbBindInt(events, ":query", false);
 	dbBindText(events, ":time", time);
 	dbBindInt(events, ":limit", pageLimit);
@@ -132,7 +129,7 @@ enum kcgi_err pageEvents(struct kreq *req) {
 			.target = (const char *)sqlite3_column_text(events, 6),
 			.message = (const char *)sqlite3_column_text(events, 7),
 		};
-		error = htmlEvent(&html, event);
+		error = htmlEvent(&html, scope, event);
 		if (error) break;
 	}
 	if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db));