summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--scooper.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/scooper.c b/scooper.c
index 130ea15..291abb0 100644
--- a/scooper.c
+++ b/scooper.c
@@ -58,10 +58,10 @@ static const char *Pages[PagesLen] = {
 };
 
 #define ENUM_KEYS \
-	X(Network, "network", kvalid_string) \
-	X(Context, "context", kvalid_string) \
-	X(After, "after", kvalid_string) \
-	X(Query, "query", kvalid_string)
+	X(Network, "network", kvalid_stringne) \
+	X(Context, "context", kvalid_stringne) \
+	X(After, "after", kvalid_stringne) \
+	X(Query, "query", kvalid_stringne)
 
 enum {
 #define X(key, name, valid) key,
@@ -76,7 +76,25 @@ static const struct kvalid Keys[KeysLen] = {
 #undef X
 };
 
-static void request(struct kreq *req) {
+static enum kcgi_err fail(struct kreq *req, enum khttp status) {
+	return khttp_head(req, kresps[KRESP_STATUS], "%s", khttps[status])
+		|| khttp_head(
+			req, kresps[KRESP_CONTENT_TYPE], "%s", kmimetypes[KMIME_TEXT_PLAIN]
+		)
+		|| khttp_body(req)
+		|| khttp_puts(req, khttps[status])
+		|| khttp_putc(req, '\n');
+}
+
+static enum kcgi_err request(struct kreq *req) {
+	if (req->method != KMETHOD_HEAD && req->method != KMETHOD_GET) {
+		return fail(req, KHTTP_405);
+	}
+	if (req->mime != KMIME_TEXT_HTML || req->page == PagesLen) {
+		return fail(req, KHTTP_404);
+	}
+
+	return KCGI_OK;
 }
 
 int main(int argc, char *argv[]) {
@@ -126,16 +144,18 @@ int main(int argc, char *argv[]) {
 			KCGI_OK == (error = khttp_fcgi_parse(fcgi, &req));
 			khttp_free(&req)
 		) {
-			request(&req);
+			error = request(&req);
+			if (error && error != KCGI_HUP) break;
 		}
-		errx(EX_DATAERR, "khttp_fcgi_parse: %s", kcgi_strerror(error));
+		errx(EX_PROTOCOL, "khttp_fcgi_parse: %s", kcgi_strerror(error));
 	} else {
 		struct kreq req;
 		enum kcgi_err error = khttp_parse(
 			&req, Keys, KeysLen, Pages, PagesLen, Networks
 		);
-		if (error) errx(EX_DATAERR, "khttp_parse: %s", kcgi_strerror(error));
-		request(&req);
+		if (error) errx(EX_PROTOCOL, "khttp_parse: %s", kcgi_strerror(error));
+		error = request(&req);
+		if (error) errx(EX_PROTOCOL, "%s", kcgi_strerror(error));
 		khttp_free(&req);
 	}
 }
McEnroe 2020-11-19Add "Come On Petunia"June McEnroe 2020-11-13Add x4 to LESSJune McEnroe 2020-11-04Remove modified sensitivity settingsJune McEnroe 2020-10-29Remove editJune McEnroe 2020-10-27Switch gr alias back to git rebaseJune McEnroe 2020-10-27Allow cd host: to cd to same path over sshJune McEnroe 2020-10-27Use SendEnv for cd host:pathJune McEnroe 2020-10-27Allow cd host:path over sshJune McEnroe 2020-10-07Use mandoc -T utf8 for text.June McEnroe 2020-09-20Add The Awakened KingdomJune McEnroe 2020-09-12Move /opt/local back, cheat port select to use system manJune McEnroe 2020-09-12Move /opt/local behind /usr againJune McEnroe 2020-09-12Enable toc in cgit renderings of man pagesJune McEnroe 2020-09-11Install mandoc on macOSJune McEnroe 2020-09-11Rewrite install script yet againJune McEnroe 2020-09-11Remove NetBSD from install scriptJune McEnroe 2020-09-11Use MacPorts rather than pkgsrcJune McEnroe 2020-09-11Add debian VM name to sshJune McEnroe 2020-09-11Add influencer tweetJune McEnroe 2020-09-10Add The Kingdom of GodsJune McEnroe 2020-09-07Add SunglassesJune McEnroe 2020-09-06Add Between the BreathsJune McEnroe 2020-09-04Open /dev/tty in nudgeJune McEnroe 2020-09-04Add nudgeJune McEnroe 2020-09-03Build fbclock with -lzJune McEnroe 2020-08-29Add tweets from retweetsJune McEnroe