Fix warnings.
[darkstat] / html.c
1 /* darkstat 3
2 *
3 * html.c: HTML header/footer templating for web interface.
4 * copyright (c) 2006 Ben Stewart.
5 * copyright (c) 2010 Malte S. Stretz.
6 *
7 * You may use, modify and redistribute this file under the terms of the
8 * GNU General Public License version 2. (see COPYING.GPL)
9 */
10
11 #include "darkstat.h"
12 #include "config.h"
13 #include "str.h"
14 #include "html.h"
15 #include "opt.h"
16
17 #include <assert.h>
18
19 static const char *relpaths[] = {
20 ".",
21 "..",
22 "../.."
23 };
24
25 void html_open(struct str *buf, const char *title,
26 const unsigned int path_depth, const int want_graph_js)
27 {
28 const char *root;
29 assert(path_depth < (sizeof(relpaths)/sizeof(*relpaths)));
30 root = relpaths[path_depth];
31
32 str_appendf(buf,
33 "<!DOCTYPE html>\n"
34 "<html>\n"
35 "<head>\n"
36 "<title>%s (darkstat3 %s)</title>\n"
37 "<meta name=\"generator\" content=\"" PACKAGE_STRING "\">\n"
38 "<meta name=\"robots\" content=\"noindex, noarchive\">\n"
39 "<link rel=\"stylesheet\" href=\"%s/style.css\" type=\"text/css\">\n"
40 , title, opt_interface, root);
41
42 if (want_graph_js)
43 str_appendf(buf,
44 "<script src=\"%s/graph.js\" type=\"text/javascript\"></script>\n"
45 , root);
46
47 str_appendf(buf,
48 "</head>\n"
49 "<body>\n"
50 "<div class=\"menu\">\n"
51 "<ul class=\"menu\">" /* no whitespace (newlines) in list */
52 "<li class=\"label\">" PACKAGE_STRING "</li>"
53 "<li><a href=\"%s/\">graphs</a></li>"
54 "<li><a href=\"%s/hosts/\">hosts</a></li>"
55 "<li><a href=\"" PACKAGE_URL "\">homepage</a></li>"
56 "</ul>\n"
57 "</div>\n"
58 "<div class=\"content\">\n"
59 "<h2 class=\"pageheader\">%s</h2>\n"
60 , root, root, title);
61 }
62
63 void html_close(struct str *buf)
64 {
65 str_append(buf,
66 "</div>\n"
67 "</body>\n"
68 "</html>\n");
69 }
70
71 /* vim:set ts=4 sw=4 tw=78 expandtab: */