===================================================================
RCS file: /cvs/mandoc/cgi.c,v
retrieving revision 1.55
retrieving revision 1.58
diff -u -p -r1.55 -r1.58
--- mandoc/cgi.c 2014/07/09 09:27:01 1.55
+++ mandoc/cgi.c 2014/07/09 14:18:59 1.58
@@ -1,4 +1,4 @@
-/* $Id: cgi.c,v 1.55 2014/07/09 09:27:01 schwarze Exp $ */
+/* $Id: cgi.c,v 1.58 2014/07/09 14:18:59 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons
* Copyright (c) 2014 Ingo Schwarze
@@ -20,6 +20,7 @@
#endif
#include
+#include
#include
#include
#include
@@ -27,13 +28,6 @@
#include
#include
-#if defined(__sun)
-/* for stat() */
-#include
-#include
-#include
-#endif
-
#include "mandoc.h"
#include "mandoc_aux.h"
#include "main.h"
@@ -51,7 +45,7 @@ enum page {
* A query as passed to the search function.
*/
struct query {
- const char *manroot; /* manual root directory */
+ const char *manpath; /* desired manual directory */
const char *arch; /* architecture */
const char *sec; /* manual section */
const char *expr; /* unparsed expression string */
@@ -59,10 +53,10 @@ struct query {
};
struct req {
- struct query q;
- char **p; /* array of available manroots */
- size_t psz;
- enum page page;
+ struct query q;
+ char **p; /* array of available manpaths */
+ size_t psz; /* number of available manpaths */
+ enum page page;
};
static void catman(const struct req *, const char *);
@@ -92,10 +86,10 @@ static void resp_search(const struct req *,
struct manpage *, size_t);
static void resp_searchform(const struct req *);
-static const char *progname; /* cgi script name */
-static const char *cache; /* cache directory */
-static const char *css; /* css directory */
-static const char *host; /* hostname */
+static const char *scriptname; /* CGI script name */
+static const char *mandir; /* contains all manpath directories */
+static const char *cssdir; /* css directory */
+static const char *httphost; /* hostname used in the URIs */
static const char * const pages[PAGE__MAX] = {
"index", /* PAGE_INDEX */
@@ -129,13 +123,14 @@ html_putchar(char c)
break;
}
}
+
static void
http_printquery(const struct req *req)
{
- if (NULL != req->q.manroot) {
+ if (NULL != req->q.manpath) {
printf("&manpath=");
- http_print(req->q.manroot);
+ http_print(req->q.manpath);
}
if (NULL != req->q.sec) {
printf("&sec=");
@@ -151,14 +146,13 @@ http_printquery(const struct req *req)
}
}
-
static void
html_printquery(const struct req *req)
{
- if (NULL != req->q.manroot) {
+ if (NULL != req->q.manpath) {
printf("&manpath=");
- html_print(req->q.manroot);
+ html_print(req->q.manpath);
}
if (NULL != req->q.sec) {
printf("&sec=");
@@ -210,7 +204,7 @@ http_parse(struct req *req, char *p)
int legacy;
memset(&req->q, 0, sizeof(struct query));
- req->q.manroot = req->p[0];
+ req->q.manpath = req->p[0];
legacy = -1;
while ('\0' != *p) {
@@ -244,7 +238,7 @@ http_parse(struct req *req, char *p)
else if (0 == strcmp(key, "arch"))
req->q.arch = val;
else if (0 == strcmp(key, "manpath"))
- req->q.manroot = val;
+ req->q.manpath = val;
else if (0 == strcmp(key, "apropos"))
legacy = 0 == strcmp(val, "0");
}
@@ -349,7 +343,8 @@ resp_begin_html(int code, const char *msg)
"System Manpage Reference\n"
"\n"
"\n"
- "\n", css, css);
+ "\n",
+ cssdir, cssdir);
}
static void
@@ -373,7 +368,7 @@ resp_searchform(const struct req *req)
" for manuals satisfying \n"
"q.expr ? req->q.expr : "");
printf("\">, section "
"");
for (i = 0; i < (int)req->psz; i++) {
printf("
", progname);
+ "", scriptname);
resp_end_html();
}
@@ -443,8 +438,8 @@ resp_error404(const char *page)
printf(",\n"
"could not be found.\n"
"Try searching from the\n"
- "main page.\n"
- "", progname);
+ "main page.\n"
+ "", scriptname);
resp_end_html();
}
@@ -452,7 +447,7 @@ static void
resp_bad(void)
{
resp_begin_html(500, "Internal Server Error");
- puts("Generic badness happened.
");
+ puts("Internal Server Error
");
resp_end_html();
}
@@ -477,7 +472,7 @@ resp_search(const struct req *req, struct manpage *r,
*/
puts("Status: 303 See Other");
printf("Location: http://%s%s/show/%s/%s?",
- host, progname, req->q.manroot, r[0].file);
+ httphost, scriptname, req->q.manpath, r[0].file);
http_printquery(req);
puts("\n"
"Content-Type: text/html; charset=utf-8\n");
@@ -506,7 +501,7 @@ resp_search(const struct req *req, struct manpage *r,
printf("\n"
"\n"
"q.manroot, r[i].file);
+ scriptname, req->q.manpath, r[i].file);
html_printquery(req);
printf("\">");
html_print(r[i].names);
@@ -683,7 +678,8 @@ format(const struct req *req, const char *file)
return;
}
- mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_FATAL, NULL, NULL);
+ mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_FATAL, NULL,
+ req->q.manpath);
rc = mparse_readfd(mp, fd, file);
close(fd);
@@ -694,7 +690,7 @@ format(const struct req *req, const char *file)
snprintf(opts, sizeof(opts),
"fragment,man=%s/search?sec=%%S&expr=Nm~^%%N$",
- progname);
+ scriptname);
mparse_result(mp, &mdoc, &man, NULL);
if (NULL == man && NULL == mdoc) {
@@ -732,7 +728,7 @@ pg_show(const struct req *req, char *path)
*sub++ = '\0';
/*
- * Begin by chdir()ing into the manroot.
+ * Begin by chdir()ing into the manpath.
* This way we can pick up the database files, which are
* relative to the manpath root.
*/
@@ -766,8 +762,8 @@ pg_search(const struct req *req, char *path)
* relative to the manpath root.
*/
- if (-1 == (chdir(req->q.manroot))) {
- perror(req->q.manroot);
+ if (-1 == (chdir(req->q.manpath))) {
+ perror(req->q.manpath);
resp_search(req, NULL, 0);
return;
}
@@ -829,30 +825,31 @@ main(void)
{
int i;
struct req req;
- char *p, *path, *subpath;
+ char *querystring, *path, *subpath;
/* Scan our run-time environment. */
- if (NULL == (cache = getenv("CACHE_DIR")))
- cache = "/cache/man.cgi";
+ if (NULL == (mandir = getenv("MAN_DIR")))
+ mandir = "/man";
- if (NULL == (progname = getenv("SCRIPT_NAME")))
- progname = "";
+ if (NULL == (scriptname = getenv("SCRIPT_NAME")))
+ scriptname = "";
- if (NULL == (css = getenv("CSS_DIR")))
- css = "";
+ if (NULL == (cssdir = getenv("CSS_DIR")))
+ cssdir = "";
- if (NULL == (host = getenv("HTTP_HOST")))
- host = "localhost";
+ if (NULL == (httphost = getenv("HTTP_HOST")))
+ httphost = "localhost";
/*
- * First we change directory into the cache directory so that
+ * First we change directory into the mandir so that
* subsequent scanning for manpath directories is rooted
* relative to the same position.
*/
- if (-1 == chdir(cache)) {
- perror(cache);
+ if (-1 == chdir(mandir)) {
+ fprintf(stderr, "MAN_DIR: %s: %s\n",
+ mandir, strerror(errno));
resp_bad();
return(EXIT_FAILURE);
}
@@ -862,8 +859,8 @@ main(void)
/* Next parse out the query string. */
- if (NULL != (p = getenv("QUERY_STRING")))
- http_parse(&req, p);
+ if (NULL != (querystring = getenv("QUERY_STRING")))
+ http_parse(&req, querystring);
/*
* Now juggle paths to extract information.
|