Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdocml: fix section name bugs in man-cgi #48800

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions srcpkgs/mdocml/files/void.css

This file was deleted.

60 changes: 60 additions & 0 deletions srcpkgs/mdocml/patches/cgi-head.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
allows for injecting html into <head> for man-cgi

https://inbox.vuxu.org/mandoc-tech/[email protected]/T/#u

--- a/cgi.c
+++ b/cgi.c
@@ -408,11 +408,14 @@
printf("(%.*s)", secsz, sec);
fputs(" - ", stdout);
}
- printf("%s</title>\n"
- "</head>\n"
- "<body>\n",
+ printf("%s</title>\n",
CUSTOMIZE_TITLE);

+ resp_copy(MAN_DIR "/head.html");
+
+ printf("</head>\n"
+ "<body>\n");
+
resp_copy(MAN_DIR "/header.html");
}

--- a/man.cgi.3 15 Mar 2017 13:18:53 -0000 1.4
+++ b/man.cgi.3 7 Nov 2022 17:32:35 -0000
@@ -240,8 +240,10 @@
.It Ft void Fn resp_begin_html "int code" "const char *msg" "const char *file"
This generator calls
.Fn resp_begin_http
-to print the HTTP headers, then prints the HTML header up to the
-opening tag of the <body> element, then copies the file
+to print the HTTP headers, then prints the HTML header, then copies the file
+.Pa head.html
+to the output, if it exists and is readable, then prints up to the opening tag
+of the <body> element, then copies the file
.Pa header.html
to the output, if it exists and is readable.
If
--- a/man.cgi.8 6 Jul 2022 15:47:28 -0000 1.24
+++ b/man.cgi.8 7 Nov 2022 17:32:35 -0000
@@ -199,6 +199,7 @@
for this purpose.
The files
.Pa manpath.conf ,
+.Pa head.html ,
.Pa header.html ,
and
.Pa footer.html
@@ -380,6 +381,10 @@
.Sx Restricted character set ,
.Nm
reports an internal server error and exits without doing anything.
+.It Pa /man/head.html
+An optional file containing static HTML code to be inserted right before
+closing the <HEAD> element.
+For example, it can contain additional <META> tags or <LINK>s to other resources.
.It Pa /man/header.html
An optional file containing static HTML code to be wrapped in
a <HEADER> element and inserted right after opening the <BODY> element.
100 changes: 100 additions & 0 deletions srcpkgs/mdocml/patches/cgi-trim.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
fixes issues with the cgi script caused by our hacked-in gzip support.

* the page <title> showed foo.N(gz) instead of foo(N)
* links in apropos results linked to .../foo.N.gz instead of .../foo.N,
confusing man-cgi
* redirects for single-result apropos searches redirected to .../foo.N.gz too

--- a/cgi.c
+++ b/cgi.c
@@ -99,6 +99,7 @@
static int validate_filename(const char *);
static int validate_manpath(const struct req *, const char *);
static int validate_urifrag(const char *);
+static char * filename_trim_gz(const char *);

static const char *scriptname = SCRIPT_NAME;

@@ -139,6 +140,18 @@
};
static const int arch_MAX = sizeof(arch_names) / sizeof(char *);

+static char *
+filename_trim_gz(const char *s) {
+ char *r, *cp;
+ if (s == NULL || (r = malloc(strlen(s) + 1)) == NULL)
+ return NULL;
+ strcpy(r, s);
+ cp = strrchr(r, '.');
+ if (cp != NULL && strcasecmp(cp, ".gz") == 0)
+ *cp = '\0';
+ return r;
+}
+
/*
* Print a character, escaping HTML along the way.
* This will pass non-ASCII straight to output: be warned!
@@ -641,7 +641,7 @@
static void
pg_searchres(const struct req *req, struct manpage *r, size_t sz)
{
- char *arch, *archend;
+ char *arch, *archend, *fn;
const char *sec;
size_t i, iuse;
int archprio, archpriouse;
@@ -654,9 +667,11 @@
printf("%s/", scriptname);
if (strcmp(req->q.manpath, req->p[0]))
printf("%s/", req->q.manpath);
+ fn = filename_trim_gz(r[0].file);
printf("%s\r\n"
"Content-Type: text/html; charset=utf-8\r\n\r\n",
- r[0].file);
+ fn);
+ free(fn);
return;
}

@@ -699,7 +714,9 @@
priouse = prio;
iuse = i;
}
- resp_begin_html(200, NULL, r[iuse].file);
+ fn = filename_trim_gz(r[iuse].file);
+ resp_begin_html(200, NULL, fn);
+ free(fn);
} else
resp_begin_html(200, NULL, NULL);

@@ -716,7 +733,9 @@
printf("%s/", scriptname);
if (strcmp(req->q.manpath, req->p[0]))
printf("%s/", req->q.manpath);
- printf("%s\">", r[i].file);
+ fn = filename_trim_gz(r[i].file);
+ printf("%s\">", fn);
+ free(fn);
html_print(r[i].names);
printf("</a></td>\n"
" <td><span class=\"Nd\">");
@@ -951,7 +951,7 @@
static void
pg_show(struct req *req, const char *fullpath)
{
- char *manpath;
+ char *manpath, *fn;
const char *file;

if ((file = strchr(fullpath, '/')) == NULL) {
@@ -970,7 +989,9 @@
return;
}

- resp_begin_html(200, NULL, file);
+ fn = filename_trim_gz(file);
+ resp_begin_html(200, NULL, fn);
+ free(fn);
resp_searchform(req, FOCUS_NONE);
resp_show(req, file);
resp_end_html();
3 changes: 1 addition & 2 deletions srcpkgs/mdocml/template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Template file for 'mdocml'
pkgname=mdocml
version=1.14.6
revision=7
revision=8
build_style=configure
make_build_args="all man.cgi"
make_check_target="regress"
Expand Down Expand Up @@ -29,7 +29,6 @@ alternatives="
CFLAGS="-fcommon"

post_patch() {
cat ${FILESDIR}/void.css >>mandoc.css
cp ${FILESDIR}/cgi.h .
}
pre_configure() {
Expand Down