From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 39f26251 for ; Thu, 5 Nov 2015 15:56:11 -0500 (EST) Date: Thu, 5 Nov 2015 15:56:11 -0500 (EST) Message-Id: <16055428756692677477.enqueue@fantadrom.bsd.lv> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Use include files "header.html" and "footer.html" rather than a X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- 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 , but implemented in a much simpler way. Modified Files: -------------- mdocml: cgi.c cgi.h.example man.cgi.8 Revision Data ------------- Index: cgi.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/cgi.c,v retrieving revision 1.113 retrieving revision 1.114 diff -Lcgi.c -Lcgi.c -u -p -r1.113 -r1.114 --- cgi.c +++ cgi.c @@ -77,6 +77,7 @@ static void pg_searchres(const struct 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 *ms } 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 *ms "\n" "\n", CSS_DIR, CUSTOMIZE_TITLE); + + resp_copy(MAN_DIR "/header.html"); } static void resp_end_html(void) { + resp_copy(MAN_DIR "/footer.html"); + puts("\n" ""); } @@ -399,7 +418,6 @@ resp_searchform(const struct req *req) { int i; - puts(CUSTOMIZE_BEGIN); puts(""); printf("
\n" "
\n" Index: cgi.h.example =================================================================== RCS file: /home/cvs/mdocml/mdocml/cgi.h.example,v retrieving revision 1.3 retrieving revision 1.4 diff -Lcgi.h.example -Lcgi.h.example -u -p -r1.3 -r1.4 --- cgi.h.example +++ cgi.h.example @@ -4,6 +4,4 @@ #define MAN_DIR "/var/www/man" #define CSS_DIR "" #define CUSTOMIZE_TITLE "Manual pages with mandoc" -#define CUSTOMIZE_BEGIN "

\nManual pages with " \ - "mandoc\n

" #define COMPAT_OLDURI Yes Index: man.cgi.8 =================================================================== RCS file: /home/cvs/mdocml/mdocml/man.cgi.8,v retrieving revision 1.12 retrieving revision 1.13 diff -Lman.cgi.8 -Lman.cgi.8 -u -p -r1.12 -r1.13 --- man.cgi.8 +++ man.cgi.8 @@ -190,14 +190,8 @@ and to be specified without a trailing s When not specified, the CSS files are assumed to be in the document root. This is used in generated HTML code. -.It Ev CUSTOMIZE_BEGIN -A HTML string to be inserted right after opening the -.Aq BODY -element. .It Ev CUSTOMIZE_TITLE -An ASCII string to be used for the HTML -.Aq TITLE -element. +An ASCII string to be used for the HTML element. .It Ev HTTP_HOST The FQDN of the (possibly virtual) host the HTTP server is running on. This is used for @@ -374,6 +368,12 @@ or any character not contained in the .Sx Restricted character set , .Nm reports an internal server error and exits without doing anything. +.It Pa /man/header.html +An optional file containing static HTML code to be inserted right +after opening the <BODY> element. +.It Pa /man/footer.html +An optional file containing static HTML code to be inserted right +before closing the <BODY> element. .It Pa /man/OpenBSD-current/man1/mandoc.1 An example .Xr mdoc 7 -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv