MAN.CGI(3) | Library Functions Manual | MAN.CGI(3) |
man.cgi
—
internals of the CGI program to search and display manual
pages
The source code of man.cgi(8) is organized in four levels:
The top level of
man.cgi(8) consists of the
main
()
program and a few parser routines.
main
(void)MAN_DIR
, the data directory
containing all the manual trees;parse_manpath_conf
();PATH_INFO
is empty,
calls
parse_query_string
();
otherwise, calls
parse_path_info
();parse_manpath_conf
(struct req
*req)parse_path_info
(struct req
*req, const char *path)PATH_INFO
, clears
req->isquery, and fills
req->q.parse_query_string
(struct req
*req, const char *qs)QUERY_STRING
, sets
req->isquery, and fills
req->q. This function is the only user of the
utility functions
http_decode
()
and
set_query_attr
().The purpose of each page generator is to print a complete HTML
page, starting with the HTTP headers and continuing to the page footer.
Before starting HTML output with
resp_begin_html
(),
some page generators do some preparatory work, for example to decide which
page to show. Each page generator ends with a call to
resp_end_html
().
pg_show
(struct
req *req, const char *fullpath)PATH_INFO
contains the complete path to a manual page including manpath, section
directory, optional architecture subdirectory, manual name and section
number suffix. It validates the manpath, changes into it, validate the
filename, and then calls resp_begin_html
(),
resp_searchform
(),
resp_show
(),
and resp_end_html
() in that order.pg_search
(const
struct req *req)PATH_INFO
contains a search query in short format or when
PATH_INFO
is empty and a
QUERY_STRING
is provided. If possible, requests
using QUERY_STRING
are redirected to URIs using
PATH_INFO
by calling
pg_redirect
().
Otherwise, it changes into the manpath and calls
mansearch(3). Depending on
the result, it calls either
pg_noresult
()
or
pg_searchres
().pg_redirect
(const struct req
*req, const char *name)pg_noresult
(const struct req
*req, const char *msg)resp_begin_html
(),
resp_searchform
(), prints the
msg passed to it, and calls
resp_end_html
().pg_searchres
(const struct req
*req, struct manpage *r, size_t
sz)QUERY_STRING
was used and there is exactly one
result, it writes an HTTP redirect to that result. Otherwise, it writes an
HTML result page beginning with resp_begin_html
()
and resp_searchform
(). If there is more than one
result, it writes a list of links to all the results. If it was a
man(1) rather than an
apropos(1) query or if there
is only one single result, it calls resp_show
().
Finally, it calls resp_end_html
().pg_index
(const
struct req *req)PATH_INFO
and
QUERY_STRING
are both empty. It calls
resp_begin_html
() and
resp_searchform
(), writes links to help pages, and
calls resp_end_html
().pg_error_badrequest
(const
char *msg)main
() or
pg_show
() detect an invalid URI. It calls
resp_begin_html
(), prints the
msg provided, and calls
resp_end_html
().pg_error_internal
(void)resp_begin_html
(), prints "Internal Server
Error", and calls resp_end_html
(). Before
calling pg_error_internal
(), call
warn(3) or
warnx(3) to log
the reason of the error to the
httpd(8) server
log file.The purpose of result generators is to print a chunk of HTML code.
When they print untrusted strings or characters,
html_print
()
and
html_putchar
()
are used. The highest level result generators are:
resp_begin_html
(int code,
const char *msg, const char
*file)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
header.html to the output, if it exists and is
readable. If file is not
NULL
, it is used for the <title>
element.resp_searchform
(const struct req
*req, enum focus focus)FOCUS_QUERY
, it sets the document's autofocus to
the query input box.resp_show
(const struct req
*req, const char *file)resp_catman
()
or
resp_format
(),
depending on whether file starts with
cat or man,
respectively.resp_catman
(const struct req
*req, const char *file)resp_format
(const struct req
*req, const char *file)resp_end_html
(void)These functions take a string and return 1 if it is valid, or 0 otherwise.
validate_urifrag
(const
char *frag)validate_manpath
(const
struct req *req, const char* manpath)validate_filename
(const
char *file)mandoc(3), mansearch(3), mchars_alloc(3), mandoc.db(5), man.cgi(8)
March 15, 2017 | OpenBSD 6.7 |