Remove headers callback and tidy up html module a bit.
authorEmil Mikulic <emikulic@gmail.com>
Sun, 15 May 2011 10:01:38 +0000 (20:01 +1000)
committerEmil Mikulic <emikulic@gmail.com>
Sat, 28 May 2011 10:10:53 +0000 (20:10 +1000)
graph_db.c
hosts_db.c
html.c
html.h

index 44685e9..edba22d 100644 (file)
@@ -302,12 +302,6 @@ graph_export(const int fd)
    return 1;
 }
 
-static void cb_headers(struct str *buf)
-{
-   str_appendf(buf, "<script src=\"%s%s\" type=\"text/javascript\">"
-      "</script>\n", base_url, "graph.js");
-}
-
 /* ---------------------------------------------------------------------------
  * Web interface: front page!
  */
@@ -319,7 +313,7 @@ html_front_page(void)
    char start_when[100];
 
    buf = str_make();
-   html_open(buf, "Graphs", interface, cb_headers);
+   html_open(buf, "Graphs", interface, /*want_graph_js=*/1);
 
    str_append(buf, "<p>\n");
    str_append(buf, "<b>Running for</b> <span id=\"rf\">");
index 954daba..d3c65df 100644 (file)
@@ -974,7 +974,7 @@ html_hosts_main(const char *qs)
 #define NEXT "next page &gt;&gt;&gt;"
 #define FULL "full table"
 
-   html_open(buf, "Hosts", interface, NULL);
+   html_open(buf, "Hosts", interface, /*want_graph_js=*/0);
    format_table(buf, hosts_db, start, sort, full);
 
    /* <prev | full | stats | next> */
@@ -1031,7 +1031,7 @@ html_hosts_detail(const char *ip)
 
    /* Overview. */
    buf = str_make();
-   html_open(buf, ip, interface, NULL);
+   html_open(buf, ip, interface, /*want_graph_js=*/0);
    if (strcmp(ip, canonical) != 0)
       str_appendf(buf, "(canonically <b>%s</b>)\n", canonical);
    str_appendf(buf,
diff --git a/html.c b/html.c
index 18d434f..ebc5eca 100644 (file)
--- a/html.c
+++ b/html.c
 #include "http.h" /* for base_url */
 
 void html_open(struct str *buf, const char *title, const char *interface,
-    void (*header_callback)(struct str *buf))
+    const int want_graph_js)
 {
-    str_append(buf,
+    str_appendf(buf,
         "<!DOCTYPE html>\n"
         "<html>\n"
-        "<head>\n");
-    str_appendf(buf, "<title>%s (darkstat3 : %s)</title>\n"
-        "<meta name=\"generator\" content=\"%s\" />\n", title, interface,
-        PACKAGE_STRING);
-    str_append(buf, "<meta name=\"robots\" content=\"noindex, noarchive\" />\n");
-    str_appendf(buf, "<link rel=\"stylesheet\" href=\"%s%s\" type=\"text/css\"/>\n",
-        base_url, "style.css");
-    if (header_callback != NULL)
-        header_callback(buf);
-            
-    str_append(buf, "</head>\n"
+        "<head>\n"
+         "<title>%s (darkstat3 %s)</title>\n"
+         "<meta name=\"generator\" content=\"%s\">\n"
+         "<meta name=\"robots\" content=\"noindex, noarchive\">\n"
+         "<link rel=\"stylesheet\" href=\"%sstyle.css\" type=\"text/css\">\n"
+        , title, interface, PACKAGE_STRING, base_url);
+
+    if (want_graph_js)
+        str_appendf(buf,
+            "<script src=\"%sgraph.js\" type=\"text/javascript\"></script>\n"
+            , base_url);
+
+    str_appendf(buf,
+        "</head>\n"
         "<body>\n"
         "<div class=\"menu\">\n"
-        "<ul class=\"menu\">\n");
-    str_appendf(buf, "<li class=\"label\">%s</li>\n"
-        "<li><a href=\"%s\">graphs</a></li>\n"
-        "<li><a href=\"%shosts/\">hosts</a></li>\n"
-        "<li><a href=\"http://dmr.ath.cx/net/darkstat/\">homepage</a></li>\n",
-        PACKAGE_STRING, base_url, base_url);
-    str_append(buf, "</ul>\n"
+        "<ul class=\"menu\">" /* no whitespace (newlines) in list */
+         "<li class=\"label\">%s</li>"
+         "<li><a href=\"%s\">graphs</a></li>"
+         "<li><a href=\"%shosts/\">hosts</a></li>"
+         "<li><a href=\"http://dmr.ath.cx/net/darkstat/\">homepage</a></li>"
+        "</ul>\n"
         "</div>\n"
-        "<div class=\"content\">\n");
-    str_appendf(buf, "<h2 class=\"pageheader\">%s</h2>\n", title);
+        "<div class=\"content\">\n"
+         "<h2 class=\"pageheader\">%s</h2>\n"
+        , PACKAGE_STRING, base_url, base_url, title);
 }
 
 void html_close(struct str *buf)
@@ -49,9 +52,7 @@ void html_close(struct str *buf)
     str_append(buf, 
         "</div>\n"
         "</body>\n"
-        "</html>\n"
-    );
+        "</html>\n");
 }
 
-
 /* vim:set ts=4 sw=4 tw=78 expandtab: */
diff --git a/html.h b/html.h
index 296e022..2dcc874 100644 (file)
--- a/html.h
+++ b/html.h
@@ -10,7 +10,7 @@
 #include "config.h" /* for PACKAGE_STRING */
 
 void html_open(struct str *buf, const char *title, const char *interface,
-    void (*header_callback)(struct str *buf));
+    const int want_graph_js);
 void html_close(struct str *buf);
 
 #endif