-rw-r--r-- | cgit.c | 50 |
1 files changed, 33 insertions, 17 deletions
@@ -8,11 +8,14 @@ #include "cgit.h" +#include "cmd.h" 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)); cgit_print_docend(); @@ -81,5 +84,5 @@ char *find_default_branch(struct cgit_repo *repo) static void cgit_print_repo_page(struct cacheitem *item) { - char *title, *tmp; + char *tmp; int show_search; unsigned char sha1[20]; @@ -89,9 +92,11 @@ static void cgit_print_repo_page(struct cacheitem *item) setup_git_directory_gently(&nongit); 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); cgit_print_docend(); @@ -99,5 +104,5 @@ 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; @@ -108,6 +113,7 @@ 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"); cgit_print_docend(); @@ -118,6 +124,7 @@ static void cgit_print_repo_page(struct cacheitem *item) tmp = xstrdup(ctx.qry.head); 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)); cgit_print_docend(); @@ -144,7 +151,8 @@ 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(); cgit_print_docend(); @@ -152,5 +160,5 @@ static void cgit_print_repo_page(struct cacheitem *item) } - cgit_print_pageheader(ctx.qry.page, show_search); + cgit_print_pageheader(&ctx); switch(cgit_cmd) { @@ -181,10 +189,16 @@ 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) { int stdout2; - item->st.st_mtime = time(NULL); - if (use_cache) { stdout2 = chk_positive(dup(STDOUT_FILENO), @@ -194,4 +208,6 @@ 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) cgit_print_repo_page(item); |