From 809fc7dad073be21384f0ca5ca70d92cacfa37d8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 8 May 2012 11:03:35 +0000 Subject: [PATCH] get html header from file --- NEWS | 9 ++++++--- src/html.c | 51 ++++++++++++++++++++++----------------------------- www/Makefile.am | 1 + www/Makefile.in | 1 + www/header.tpl | 17 +++++++++++++++++ 5 files changed, 47 insertions(+), 32 deletions(-) create mode 100644 www/header.tpl diff --git a/NEWS b/NEWS index f2dd688..978910b 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,12 @@ * v0.0.7 -* More crash-resistant on network failure (patch from Lekensteyn). -* Retry HTTP request on LP Oops (patch from Lekensteyn). +* More crash-resistant on network failure (patch from Peter + Lekensteyn). +* Retry HTTP request on LP Oops (patch from Peter Lekensteyn). * Added intl support. * Increased HTTP requests performance: group result for - getPublishedBinaries by 300 instead of 75 + getPublishedBinaries by 300 instead of 75 (patch from Peter + Lekensteyn). +* HTML template pages are now in [prefix]/share/psensor/www * v0.0.6 ** added support of ie < 9. diff --git a/src/html.c b/src/html.c index b2e9e34..965a565 100644 --- a/src/html.c +++ b/src/html.c @@ -39,6 +39,7 @@ static char *footer; static char *ppa_body; static char *pkg_body; +static char *header; #define HTML_VERSION_TEMPLATE \ "\n\ @@ -81,34 +82,6 @@ src=\"js/excanvas.js\">\n\ \n\ \n" -#define HTML_HEADER \ -"\n\ - \n\ - %s\n\ - \n\ - \n\ - \n\ -\n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n" - static char *path_new(const char *dir, const char *file, const char *suffixe) { char *path; @@ -127,6 +100,21 @@ static char *path_new(const char *dir, const char *file, const char *suffixe) return path; } +static const char *get_header() +{ + const char *path; + + if (!header) { + path = DEFAULT_WWW_DIR"/header.tpl"; + header = file_get_content(path); + + if (!header) + log_err("Failed to read header template: %s", path); + } + + return header; +} + static const char *get_footer() { const char *path; @@ -430,6 +418,11 @@ create_html(const char *path, { FILE *f; const char *footer; + const char *header; + + header = get_header(); + if (!header) + return ; f = fopen(path, "w"); @@ -438,7 +431,7 @@ create_html(const char *path, return ; } - fprintf(f, HTML_HEADER, title, script); + fprintf(f, header, title, script); fputs(body_template, f); footer = get_footer(); diff --git a/www/Makefile.am b/www/Makefile.am index 786daba..7489d23 100644 --- a/www/Makefile.am +++ b/www/Makefile.am @@ -1,6 +1,7 @@ defaultwwwdir = $(pkgdatadir)/www defaultwww_DATA = \ footer.tpl\ + header.tpl\ js/excanvas.js\ js/jquery.min.js\ js/ppastats.js\ diff --git a/www/Makefile.in b/www/Makefile.in index f70e3f8..5c98628 100644 --- a/www/Makefile.in +++ b/www/Makefile.in @@ -206,6 +206,7 @@ top_srcdir = @top_srcdir@ defaultwwwdir = $(pkgdatadir)/www defaultwww_DATA = \ footer.tpl\ + header.tpl\ js/excanvas.js\ js/jquery.min.js\ js/ppastats.js\ diff --git a/www/header.tpl b/www/header.tpl new file mode 100644 index 0000000..c9f3552 --- /dev/null +++ b/www/header.tpl @@ -0,0 +1,17 @@ + + + %s + + + + + + + + + + + + -- 2.7.4