summary refs log tree commit diff
path: root/server.h
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-17 13:23:21 -0400
committerJune McEnroe <june@causal.agency>2020-07-17 13:23:21 -0400
commit0a054aeb9ce8430a62be05283300ec34e9c2b0af (patch)
tree344ec24121d800a28df101defd9d01140dda4db1 /server.h
parentAdd margin to inputs (diff)
downloadscooper-0a054aeb9ce8430a62be05283300ec34e9c2b0af.tar.gz
scooper-0a054aeb9ce8430a62be05283300ec34e9c2b0af.zip
Add export option
Adding the export query parameter to any page downloads a .html with the
default stylesheet embedded, and all navigation, forms and internal
links removed, for being able to share some part of a private instance
of litterbox.
Diffstat (limited to '')
-rw-r--r--server.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/server.h b/server.h
index 20d1803..4607d76 100644
--- a/server.h
+++ b/server.h
@@ -42,6 +42,8 @@
 	X(Search, "search") \
 	X(Stylesheet, "stylesheet")
 
+extern const char *CSS;
+
 enum {
 #define X(page, path) page,
 	ENUM_PAGES
@@ -57,7 +59,8 @@ extern const char *Pages[PagesLen];
 	X(Before, "before", kvalid_stringne) \
 	X(Tidy, "tidy", kvalid_int) \
 	X(Query, "query", kvalid_stringne) \
-	X(Offset, "offset", kvalid_int)
+	X(Offset, "offset", kvalid_int) \
+	X(Export, "export", NULL)
 
 enum Key {
 #define X(key, name, valid) key,
@@ -166,19 +169,29 @@ struct Event {
 };
 
 extern const char *htmlStylesheet;
-enum kcgi_err htmlHead(struct khtmlreq *html, const char *title);
+enum kcgi_err htmlHead(
+	struct khtmlreq *html, struct kreq *req, const char *title
+);
 enum kcgi_err htmlHidden(struct khtmlreq *html, struct kreq *req, enum Key key);
 enum kcgi_err htmlNav(struct khtmlreq *html, struct kreq *req);
 enum kcgi_err htmlIRC(struct khtmlreq *html, const char *str);
 enum kcgi_err htmlEvent(
 	struct khtmlreq *html, struct kreq *req, struct Event *event
 );
-enum kcgi_err htmlFooter(struct khtmlreq *html);
+enum kcgi_err htmlFooter(struct khtmlreq *html, struct kreq *req);
 
 static inline enum kcgi_err
 httpHead(struct kreq *req, enum khttp http, enum kmime mime) {
-	return khttp_head(req, kresps[KRESP_STATUS], "%s", khttps[http])
+	enum kcgi_err error = 0
+		|| khttp_head(req, kresps[KRESP_STATUS], "%s", khttps[http])
 		|| khttp_head(req, kresps[KRESP_CONTENT_TYPE], "%s", kmimetypes[mime]);
+	if (req->fieldmap[Export]) {
+		error = error || khttp_head(
+			req, kresps[KRESP_CONTENT_DISPOSITION],
+			"attachment; filename=\"%s.%s\"", req->pagename, ksuffixes[mime]
+		);
+	}
+	return error;
 }
 
 static inline enum kcgi_err