Switch all the HTML-based reporting modes (the internal httpd, the CGI
[sgt/agedu] / html.h
CommitLineData
70322ae3 1/*
2 * html.h: HTML output format for agedu.
3 */
4
f2e52893 5struct html_config {
6 /*
c47f39de 7 * Configure the format of the URI pathname fragment corresponding
8 * to a given tree entry.
9 *
10 * 'uriformat' is expected to have the following format:
11 * - it consists of one or more _options_, each indicating a
12 * particular way to format a URI, separated by '%|'
13 * - each option contains _at most one_ formatting directive;
14 * without any, it is assumed to only be able to encode the
15 * root tree entry
16 * - the formatting directive may be followed before and/or
17 * afterwards with literal text; percent signs in that literal
18 * text are specified as %% (which doesn't count as a
19 * formatting directive for the 'at most one' rule)
20 * - formatting directives are as follows:
21 * + '%n' outputs the numeric index (in decimal) of the tree
22 * entry
23 * + '%p' outputs the pathname of the tree entry, not counting
24 * any common prefix of the whole tree or a subdirectory
25 * separator following that (so that the root directory of
26 * the tree will always be rendered as the empty string).
27 * The subdirectory separator is translated into '/'; any
28 * remotely worrying character is escaped as = followed by
29 * two hex digits (including, in particular, = itself). The
30 * only characters not escaped are the ASCII alphabets and
31 * numbers, the subdirectory separator as mentioned above,
32 * and the four punctuation characters -.@_ .
33 * - '%/p' outputs the pathname of the tree entry, but this time
34 * the subdirectory separator is also considered to be a
35 * worrying character and is escaped.
36 * - '%-p' and '%-/p' are like '%p' and '%/p' respectively,
37 * except that they use the full pathname stored in the tree
38 * without stripping a common prefix.
39 *
40 * These formats are used both for generating and parsing URI
41 * fragments. When generating, the first valid option is used
42 * (which is always the very first one if we're generating the
43 * root URI, or else it's the first option with any formatting
44 * directive); when parsing, the first option that matches will be
45 * accepted. (Thus, you can have '.../subdir' and '.../subdir/'
46 * both accepted, but make the latter canonical; clients of this
47 * mechanism will typically regenerate a URI string after parsing
48 * an index out of it, and return an HTTP redirect if it isn't in
49 * canonical form.)
50 *
51 * All hyperlinks should be correctly generated as relative (i.e.
52 * with the right number of ../ and ./ considering both the
53 * pathname for the page currently being generated, and the one
54 * for the link target).
55 *
56 * If 'uriformat' is NULL, the HTML is generated without hyperlinks.
f2e52893 57 */
c47f39de 58 const char *uriformat;
f2e52893 59
60 /*
c47f39de 61 * Configure the filenames output by html_dump(). These can be
62 * configured separately from the URI formats, so that the root
63 * file can be called index.html on disk but have a notional URI
64 * of just / or similar.
65 *
66 * Formatting directives are the same as the uriformat above.
00c5e40c 67 */
c47f39de 68 const char *fileformat;
00c5e40c 69
70 /*
f2e52893 71 * Time stamps to assign to the extreme ends of the colour
72 * scale. If "autoage" is true, they are ignored and the time
73 * stamps are derived from the limits of the age data stored
74 * in the index.
75 */
76 int autoage;
77 time_t oldest, newest;
16139d21 78
79 /*
80 * Specify whether to show individual files as well as
81 * directories in the report.
82 */
83 int showfiles;
f2e52893 84};
85
70322ae3 86/*
c47f39de 87 * Parse a URI pathname segment against the URI formats specified in
88 * 'cfg', and return a numeric index in '*index'. Return value is true
89 * on success, or false if the pathname makes no sense, or the index
90 * is out of range, or the index does not correspond to a directory in
91 * the trie.
92 */
93int html_parse_path(const void *t, const char *path,
94 const struct html_config *cfg, unsigned long *index);
95
96/*
97 * Generate a URI pathname segment from an index.
98 */
99char *html_format_path(const void *t, const struct html_config *cfg,
100 unsigned long index);
101
102/*
70322ae3 103 * Generate an HTML document containing the results of a query
104 * against the pathname at a given index. Returns a dynamically
105 * allocated piece of memory containing the entire HTML document,
106 * as an ordinary C zero-terminated string.
00c5e40c 107 *
108 * 'downlink' is TRUE if hyperlinks should be generated for
109 * subdirectories. (This can also be disabled by setting cfg->format
110 * to NULL, but that also disables the upward hyperlinks to parent
111 * directories. Setting cfg->format to non-NULL but downlink to NULL
112 * will generate uplinks but no downlinks.)
70322ae3 113 */
f2e52893 114char *html_query(const void *t, unsigned long index,
00c5e40c 115 const struct html_config *cfg, int downlink);
116
117/*
118 * Recursively output a dump of lots of HTML files which crosslink
119 * to each other. cfg->format and cfg->rootpath will be used to
120 * generate the filenames for both the hyperlinks and the output
121 * file names; the file names will have "pathprefix" prepended to
122 * them before being opened.
123 *
124 * "index" and "endindex" point to the region of index file that
125 * should be generated by the dump, which must be a subdirectory.
126 *
127 * "maxdepth" limits the depth of recursion. Setting it to zero
128 * outputs only one page, 1 outputs the current directory and its
129 * immediate children but no further, and so on. Making it negative
130 * gives unlimited depth.
131 *
132 * Return value is 0 on success, or 1 if an error occurs during
133 * output.
134 */
135int html_dump(const void *t, unsigned long index, unsigned long endindex,
136 int maxdepth, const struct html_config *cfg,
137 const char *pathprefix);