Mercurial > blahgd
changeset 298:3c03652ee40c
print the page content generically
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Thu, 24 Jan 2013 23:00:01 +0000 |
parents | e1189f859b3f |
children | 9f65aedec864 |
files | feed.c index.c main.c main.h story.c tag.c |
diffstat | 6 files changed, 26 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/feed.c Thu Jan 24 22:46:38 2013 +0000 +++ b/feed.c Thu Jan 24 23:00:01 2013 +0000 @@ -9,14 +9,6 @@ #include "db.h" #include "error.h" -static int __render_page(struct req *req, char *tmpl) -{ - printf("Content-Type: application/atom+xml; charset=UTF-8\n\n"); - printf("%s\n", render_page(req, tmpl)); - - return 0; -} - static void __load_posts(struct req *req, int page) { struct var_val vv; @@ -60,7 +52,8 @@ __load_posts(req, 0); - return __render_page(req, "{feed}"); + req->body = render_page(req, "{feed}"); + return 0; } int blahg_feed(struct req *req, char *feed, int p)
--- a/index.c Thu Jan 24 22:46:38 2013 +0000 +++ b/index.c Thu Jan 24 23:00:01 2013 +0000 @@ -18,14 +18,6 @@ #include "error.h" #include "utils.h" -static int __render_page(struct req *req, char *tmpl) -{ - printf("Content-type: text/html\n\n"); - printf("%s\n", render_page(req, tmpl)); - - return 0; -} - static void __load_posts(struct req *req, int page) { sqlite3_stmt *stmt; @@ -138,7 +130,8 @@ __load_posts(req, page); - return __render_page(req, "{index}"); + req->body = render_page(req, "{index}"); + return 0; } static int validate_arch_id(int arch) @@ -179,5 +172,6 @@ __load_posts_archive(req, page, m); - return __render_page(req, "{archive}"); + req->body = render_page(req, "{archive}"); + return 0; }
--- a/main.c Thu Jan 24 22:46:38 2013 +0000 +++ b/main.c Thu Jan 24 23:00:01 2013 +0000 @@ -150,7 +150,7 @@ { req->dump_latency = true; req->start = gettime(); - req->buf = NULL; + req->body = NULL; req->fmt = "html"; INIT_LIST_HEAD(&req->headers); @@ -163,6 +163,16 @@ static void req_destroy(struct req *req) { + struct header *cur, *tmp; + + printf("Status: %u\n", req->status); + + list_for_each_entry_safe(cur, tmp, &req->headers, list) { + printf("%s: %s\n", cur->name, cur->val); + } + + printf("\n%s\n", req->body); + if (req->dump_latency) { uint64_t delta; @@ -181,6 +191,7 @@ list_for_each_entry_safe(cur, tmp, &req->headers, list) { if (!strcmp(cur->name, name)) { free(cur->val); + list_del(&cur->list); goto set; } } @@ -192,6 +203,7 @@ set: cur->val = xstrdup(val); + list_add_tail(&cur->list, &req->headers); } int main(int argc, char **argv)
--- a/main.h Thu Jan 24 22:46:38 2013 +0000 +++ b/main.h Thu Jan 24 23:00:01 2013 +0000 @@ -49,8 +49,8 @@ unsigned int status; struct qs args; - char *buf; struct list_head headers; + char *body; char *fmt; /* format (e.g., "html") */
--- a/story.c Thu Jan 24 22:46:38 2013 +0000 +++ b/story.c Thu Jan 24 23:00:01 2013 +0000 @@ -11,14 +11,6 @@ #include "error.h" #include "utils.h" -static int __render_page(struct req *req, char *tmpl) -{ - printf("Content-type: text/html\n\n"); - printf("%s\n", render_page(req, tmpl)); - - return 0; -} - static void __store_title(struct vars *vars, const char *title) { struct var_val vv; @@ -63,7 +55,9 @@ vars_scope_push(&req->vars); if (__load_post(req, p)) - return __render_page(req, "{404}"); + req->body = render_page(req, "{404}"); + else + req->body = render_page(req, "{storyview}"); - return __render_page(req, "{storyview}"); + return 0; }
--- a/tag.c Thu Jan 24 22:46:38 2013 +0000 +++ b/tag.c Thu Jan 24 23:00:01 2013 +0000 @@ -12,14 +12,6 @@ #include "sidebar.h" #include "error.h" -static int __render_page(struct req *req, char *tmpl) -{ - printf("Content-type: text/html\n\n"); - printf("%s\n", render_page(req, tmpl)); - - return 0; -} - static void __store_title(struct vars *vars, const char *title) { struct var_val vv; @@ -112,7 +104,8 @@ __load_posts_tag(req, page, tagcat, istag, nstories); - return __render_page(req, tmpl); + req->body = render_page(req, tmpl); + return 0; } int blahg_tag(struct req *req, char *tag, int page)