version 1.8, 2011/11/27 11:46:44 |
version 1.9, 2011/12/04 22:52:50 |
|
|
}; |
}; |
|
|
static int atou(const char *, unsigned *); |
static int atou(const char *, unsigned *); |
|
static void catman(const char *); |
static void format(const char *); |
static void format(const char *); |
static void html_print(const char *); |
static void html_print(const char *); |
static int kval_decode(char *); |
static int kval_decode(char *); |
Line 81 static void resp_bad(void); |
|
Line 82 static void resp_bad(void); |
|
static void resp_baddb(void); |
static void resp_baddb(void); |
static void resp_badexpr(const struct req *); |
static void resp_badexpr(const struct req *); |
static void resp_badmanual(void); |
static void resp_badmanual(void); |
|
static void resp_badpage(void); |
static void resp_begin_html(int, const char *); |
static void resp_begin_html(int, const char *); |
static void resp_begin_http(int, const char *); |
static void resp_begin_http(int, const char *); |
static void resp_end_html(void); |
static void resp_end_html(void); |
Line 320 resp_searchform(const struct req *req) |
|
Line 322 resp_searchform(const struct req *req) |
|
puts("<!-- Begin search form. //-->"); |
puts("<!-- Begin search form. //-->"); |
printf("<FORM ACTION=\""); |
printf("<FORM ACTION=\""); |
html_print(progname); |
html_print(progname); |
printf("/search\" METHOD=\"get\">\n"); |
printf("/search.html\" METHOD=\"get\">\n"); |
puts(" <FIELDSET>" "\n" |
puts(" <FIELDSET>" "\n" |
" <INPUT TYPE=\"submit\" VALUE=\"Search:\">"); |
" <INPUT TYPE=\"submit\" VALUE=\"Search:\">"); |
printf(" Terms: <INPUT TYPE=\"text\" " |
printf(" Terms: <INPUT TYPE=\"text\" " |
Line 348 resp_index(const struct req *req) |
|
Line 350 resp_index(const struct req *req) |
|
} |
} |
|
|
static void |
static void |
|
resp_badpage(void) |
|
{ |
|
|
|
resp_begin_html(404, "Not Found"); |
|
puts("<P>Page not found.</P>"); |
|
resp_end_html(); |
|
} |
|
|
|
static void |
resp_badmanual(void) |
resp_badmanual(void) |
{ |
{ |
|
|
Line 435 pg_index(const struct manpaths *ps, const struct req * |
|
Line 446 pg_index(const struct manpaths *ps, const struct req * |
|
} |
} |
|
|
static void |
static void |
|
catman(const char *file) |
|
{ |
|
int fd; |
|
char buf[BUFSIZ]; |
|
ssize_t ssz; |
|
|
|
if (-1 == (fd = open(file, O_RDONLY, 0))) { |
|
resp_baddb(); |
|
return; |
|
} |
|
|
|
resp_begin_http(200, NULL); |
|
|
|
while ((ssz = read(fd, buf, BUFSIZ)) > 0) |
|
write(STDOUT_FILENO, buf, (size_t)ssz); |
|
|
|
if (ssz < 0) |
|
perror(file); |
|
|
|
close(fd); |
|
} |
|
|
|
static void |
format(const char *file) |
format(const char *file) |
{ |
{ |
struct mparse *mp; |
struct mparse *mp; |
Line 479 pg_show(const struct manpaths *ps, const struct req *r |
|
Line 513 pg_show(const struct manpaths *ps, const struct req *r |
|
{ |
{ |
char *sub; |
char *sub; |
char file[MAXPATHLEN]; |
char file[MAXPATHLEN]; |
|
const char *fn, *cp; |
int rc; |
int rc; |
unsigned int vol, rec; |
unsigned int vol, rec; |
DB *db; |
DB *idx; |
DBT key, val; |
DBT key, val; |
|
|
if (NULL == path) { |
if (NULL == path) { |
Line 506 pg_show(const struct manpaths *ps, const struct req *r |
|
Line 541 pg_show(const struct manpaths *ps, const struct req *r |
|
|
|
/* Open the index recno(3) database. */ |
/* Open the index recno(3) database. */ |
|
|
db = dbopen(file, O_RDONLY, 0, DB_RECNO, NULL); |
idx = dbopen(file, O_RDONLY, 0, DB_RECNO, NULL); |
if (NULL == db) { |
if (NULL == idx) { |
resp_baddb(); |
resp_baddb(); |
return; |
return; |
} |
} |
Line 515 pg_show(const struct manpaths *ps, const struct req *r |
|
Line 550 pg_show(const struct manpaths *ps, const struct req *r |
|
key.data = &rec; |
key.data = &rec; |
key.size = 4; |
key.size = 4; |
|
|
if (0 != (rc = (*db->get)(db, &key, &val, 0))) { |
if (0 != (rc = (*idx->get)(idx, &key, &val, 0))) { |
rc < 0 ? resp_baddb() : resp_badmanual(); |
rc < 0 ? resp_baddb() : resp_badmanual(); |
(*db->close)(db); |
goto out; |
return; |
|
} |
} |
|
|
/* Extra filename: the first nil-terminated entry. */ |
cp = (char *)val.data; |
|
|
strlcpy(file, ps->paths[vol], MAXPATHLEN); |
if (NULL == (fn = memchr(cp, '\0', val.size))) |
strlcat(file, "/", MAXPATHLEN); |
resp_baddb(); |
strlcat(file, (char *)val.data, MAXPATHLEN); |
else if (++fn - cp >= (int)val.size) |
|
resp_baddb(); |
(*db->close)(db); |
else if (NULL == memchr(fn, '\0', val.size - (fn - cp))) |
|
resp_baddb(); |
format(file); |
else { |
|
strlcpy(file, ps->paths[vol], MAXPATHLEN); |
|
strlcat(file, "/", MAXPATHLEN); |
|
strlcat(file, fn, MAXPATHLEN); |
|
if (0 == strcmp(cp, "cat")) |
|
catman(file); |
|
else |
|
format(file); |
|
} |
|
out: |
|
(*idx->close)(idx); |
} |
} |
|
|
static void |
static void |
|
|
/* Initialise MANPATH. */ |
/* Initialise MANPATH. */ |
|
|
memset(&paths, 0, sizeof(struct manpaths)); |
memset(&paths, 0, sizeof(struct manpaths)); |
manpath_manconf("etc/man.conf", &paths); |
manpath_manconf("etc/catman.conf", &paths); |
|
|
/* Route pages. */ |
/* Route pages. */ |
|
|
|
|
pg_show(&paths, &req, subpath); |
pg_show(&paths, &req, subpath); |
break; |
break; |
default: |
default: |
|
resp_badpage(); |
break; |
break; |
} |
} |
|
|