From: Andy Spencer Date: Mon, 24 Dec 2012 20:52:52 +0000 (+0000) Subject: Add status codes X-Git-Url: http://pileus.org/git/?p=site;a=commitdiff_plain;h=9d8c8e797c0d5d82dffa63686806c513d5699d1b Add status codes --- diff --git a/src/html.h b/src/html.h index b3a5d72..a170dff 100644 --- a/src/html.h +++ b/src/html.h @@ -23,6 +23,7 @@ struct page_t { char *title; // title tag char *keys; // meta keywords tag, or NULL char *desc; // meta description tag, or NULL + char *error; // http status char *text; // unfiltered text char *html; // generated html }; @@ -44,5 +45,5 @@ void print_link(char *path, char *name, int cur); void print_menu(menu_t *menu, int first, int last); /* Global functions */ -void print_header(void); +void print_header(page_t *page); void print_page(page_t *page, menu_t *menu); diff --git a/src/main.c b/src/main.c index 8cfc49c..71f8b40 100644 --- a/src/main.c +++ b/src/main.c @@ -247,13 +247,15 @@ static void do_regular(page_t *page, const char *file) else page->html = markdown_to_string(page->text, 0, 0); } else { - page->html = g_strdup("Page not found"); + page->error = g_strdup("403 Forbidden"); + page->html = g_strdup("Page not accessable\n"); } } static void do_notfound(page_t *page, const char *path) { - page->html = "Page not found"; + page->error = g_strdup("404 Not Found"); + page->html = g_strdup("Page not found\n"); } static char *clean(const char *src) @@ -277,9 +279,7 @@ static char *clean(const char *src) /* Main */ int main(int argc, char **argv) { - char *path = clean(getenv("PATH_INFO") ?: "/aweather/"); - - print_header(); + char *path = clean(getenv("PATH_INFO") ?: "/"); page_t *page = get_page(path); menu_t *menu = get_menu(path); @@ -303,6 +303,7 @@ int main(int argc, char **argv) g_free(index); g_free(file); + print_header(page); print_page(page, menu); return 0; diff --git a/theme/html.ct b/theme/html.ct index a882093..8493cd6 100644 --- a/theme/html.ct +++ b/theme/html.ct @@ -1,7 +1,7 @@ -<% #include "string.h" %> <% #include "html.h" %> -<% void print_header(void) { %> +<% void print_header(page_t *page) { %> +<% if (page->error) %><%% "Status: %s\n", page->error %> Content-Type: text/html;charset=UTF-8 <% } %> @@ -16,7 +16,7 @@ Content-Type: text/html;charset=UTF-8 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - <% if (page->title) printf("%s - ", page->title); %>pileus.org + <% if (page->title) %><%% "%s - ", page->title %>pileus.org " rel="stylesheet" type="text/css" /> @@ -30,7 +30,7 @@ Content-Type: text/html;charset=UTF-8
">pileus.org - <% if (page->title) printf("%s", page->title); %> + <% if (page->title) %><%= page->title %>

<% print_menu(menu, 0, 0); %> @@ -46,7 +46,12 @@ Content-Type: text/html;charset=UTF-8 <% print_menu(menu, 1, -1); %>

- <%= page->html %> + <% if (page->error) { %> +

<%= page->error %>

+

<%= page->html %>

+ <% } else { %> + <%= page->html %> + <% } %>