aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cgi.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-11-05 20:55:41 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-11-05 20:55:41 +0000
commit3e3c69e597d7b127284c4d3fc3acbffb42f51999 (patch)
tree5f7b0c8190a8748956e1ceaac0e3a766cc7727bd /cgi.c
parent19b3dcea79a7058bdd6e153461a7e967e68db921 (diff)
downloadmandoc-3e3c69e597d7b127284c4d3fc3acbffb42f51999.tar.gz
mandoc-3e3c69e597d7b127284c4d3fc3acbffb42f51999.tar.zst
mandoc-3e3c69e597d7b127284c4d3fc3acbffb42f51999.zip
Use include files "header.html" and "footer.html" rather than a
compiled-in string. This is not a security risk, we read the file manpath.conf from the same directory, anyway. No error handling is needed; even if the files are absent, that's not an error. This is more flexible without causing complication of the code or the user interface. It helps the upcoming revamp of the online manual pages on man.NetBSD.org. Based on an idea by Jean-Yves Migeon <jeanyves dot migeon at free dot fr>, but implemented in a much simpler way.
Diffstat (limited to 'cgi.c')
-rw-r--r--cgi.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/cgi.c b/cgi.c
index bd9634e5..679cae25 100644
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-/* $Id: cgi.c,v 1.113 2015/11/05 17:47:51 schwarze Exp $ */
+/* $Id: cgi.c,v 1.114 2015/11/05 20:55:41 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@usta.de>
@@ -77,6 +77,7 @@ static void pg_searchres(const struct req *,
static void pg_show(struct req *, const char *);
static void resp_begin_html(int, const char *);
static void resp_begin_http(int, const char *);
+static void resp_copy(const char *);
static void resp_end_html(void);
static void resp_searchform(const struct req *);
static void resp_show(const struct req *, const char *);
@@ -368,6 +369,20 @@ resp_begin_http(int code, const char *msg)
}
static void
+resp_copy(const char *filename)
+{
+ char buf[4096];
+ ssize_t sz;
+ int fd;
+
+ if ((fd = open(filename, O_RDONLY)) != -1) {
+ fflush(stdout);
+ while ((sz = read(fd, buf, sizeof(buf))) > 0)
+ write(STDOUT_FILENO, buf, sz);
+ }
+}
+
+static void
resp_begin_html(int code, const char *msg)
{
@@ -384,12 +399,16 @@ resp_begin_html(int code, const char *msg)
"<BODY>\n"
"<!-- Begin page content. //-->\n",
CSS_DIR, CUSTOMIZE_TITLE);
+
+ resp_copy(MAN_DIR "/header.html");
}
static void
resp_end_html(void)
{
+ resp_copy(MAN_DIR "/footer.html");
+
puts("</BODY>\n"
"</HTML>");
}
@@ -399,7 +418,6 @@ resp_searchform(const struct req *req)
{
int i;
- puts(CUSTOMIZE_BEGIN);
puts("<!-- Begin search form. //-->");
printf("<DIV ID=\"mancgi\">\n"
"<FORM ACTION=\"%s\" METHOD=\"get\">\n"