101 lines
2.5 KiB
Diff
101 lines
2.5 KiB
Diff
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();
|