-rw-r--r-- | cgit.c | 50 |
1 files changed, 33 insertions, 17 deletions
@@ -9,2 +9,3 @@ #include "cgit.h" +#include "cmd.h" @@ -13,5 +14,7 @@ static int cgit_prepare_cache(struct cacheitem *item) if (!ctx.repo && ctx.qry.repo) { - char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); - cgit_print_docstart(title, item); - cgit_print_pageheader(title, 0); + ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, + "Bad request"); + cgit_print_http_headers(&ctx); + cgit_print_docstart(&ctx); + cgit_print_pageheader(&ctx); cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); @@ -82,3 +85,3 @@ static void cgit_print_repo_page(struct cacheitem *item) { - char *title, *tmp; + char *tmp; int show_search; @@ -90,7 +93,9 @@ static void cgit_print_repo_page(struct cacheitem *item) if (nongit) { - title = fmt("%s - %s", ctx.cfg.root_title, "config error"); + ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, + "config error"); tmp = fmt("Not a git repository: '%s'", ctx.repo->path); ctx.repo = NULL; - cgit_print_docstart(title, item); - cgit_print_pageheader(title, 0); + cgit_print_http_headers(&ctx); + cgit_print_docstart(&ctx); + cgit_print_pageheader(&ctx); cgit_print_error(tmp); @@ -100,3 +105,3 @@ static void cgit_print_repo_page(struct cacheitem *item) - title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); + ctx.page.title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); show_search = 0; @@ -109,4 +114,5 @@ static void cgit_print_repo_page(struct cacheitem *item) if (!ctx.qry.head) { - cgit_print_docstart(title, item); - cgit_print_pageheader(title, 0); + cgit_print_http_headers(&ctx); + cgit_print_docstart(&ctx); + cgit_print_pageheader(&ctx); cgit_print_error("Repository seems to be empty"); @@ -119,4 +125,5 @@ static void cgit_print_repo_page(struct cacheitem *item) ctx.qry.head = ctx.repo->defbranch; - cgit_print_docstart(title, item); - cgit_print_pageheader(title, 0); + cgit_print_http_headers(&ctx); + cgit_print_docstart(&ctx); + cgit_print_pageheader(&ctx); cgit_print_error(fmt("Invalid branch: %s", tmp)); @@ -145,5 +152,6 @@ static void cgit_print_repo_page(struct cacheitem *item) show_search = (cgit_cmd == CMD_LOG); - cgit_print_docstart(title, item); + cgit_print_http_headers(&ctx); + cgit_print_docstart(&ctx); if (!cgit_cmd) { - cgit_print_pageheader("summary", show_search); + cgit_print_pageheader(&ctx); cgit_print_summary(); @@ -153,3 +161,3 @@ static void cgit_print_repo_page(struct cacheitem *item) - cgit_print_pageheader(ctx.qry.page, show_search); + cgit_print_pageheader(&ctx); @@ -182,2 +190,10 @@ static void cgit_print_repo_page(struct cacheitem *item) +static long ttl_seconds(long ttl) +{ + if (ttl<0) + return 60 * 60 * 24 * 365; + else + return ttl * 60; +} + static void cgit_fill_cache(struct cacheitem *item, int use_cache) @@ -186,4 +202,2 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache) - item->st.st_mtime = time(NULL); - if (use_cache) { @@ -195,2 +209,4 @@ static void cgit_fill_cache(struct cacheitem *item, int use_cache) + ctx.page.modified = time(NULL); + ctx.page.expires = ctx.page.modified + ttl_seconds(item->ttl); if (ctx.repo) |