|
diff --git a/cgit.c b/cgit.c index 916feb4..f4dd6ef 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -723,68 +723,69 @@ static int calc_ttl() |
723 | if (!ctx.repo) |
723 | if (!ctx.repo) |
724 | return ctx.cfg.cache_root_ttl; |
724 | return ctx.cfg.cache_root_ttl; |
725 | |
725 | |
726 | if (!ctx.qry.page) |
726 | if (!ctx.qry.page) |
727 | return ctx.cfg.cache_repo_ttl; |
727 | return ctx.cfg.cache_repo_ttl; |
728 | |
728 | |
729 | if (ctx.qry.has_symref) |
729 | if (ctx.qry.has_symref) |
730 | return ctx.cfg.cache_dynamic_ttl; |
730 | return ctx.cfg.cache_dynamic_ttl; |
731 | |
731 | |
732 | if (ctx.qry.has_sha1) |
732 | if (ctx.qry.has_sha1) |
733 | return ctx.cfg.cache_static_ttl; |
733 | return ctx.cfg.cache_static_ttl; |
734 | |
734 | |
735 | return ctx.cfg.cache_repo_ttl; |
735 | return ctx.cfg.cache_repo_ttl; |
736 | } |
736 | } |
737 | |
737 | |
738 | int main(int argc, const char **argv) |
738 | int main(int argc, const char **argv) |
739 | { |
739 | { |
740 | const char *path; |
740 | const char *path; |
741 | char *qry; |
741 | char *qry; |
742 | int err, ttl; |
742 | int err, ttl; |
743 | |
743 | |
744 | prepare_context(&ctx); |
744 | prepare_context(&ctx); |
745 | cgit_repolist.length = 0; |
745 | cgit_repolist.length = 0; |
746 | cgit_repolist.count = 0; |
746 | cgit_repolist.count = 0; |
747 | cgit_repolist.repos = NULL; |
747 | cgit_repolist.repos = NULL; |
748 | |
748 | |
749 | cgit_parse_args(argc, argv); |
749 | cgit_parse_args(argc, argv); |
750 | parse_configfile(expand_macros(ctx.env.cgit_config), config_cb); |
750 | parse_configfile(expand_macros(ctx.env.cgit_config), config_cb); |
751 | ctx.repo = NULL; |
751 | ctx.repo = NULL; |
752 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
752 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
753 | |
753 | |
754 | /* If virtual-root isn't specified in cgitrc, lets pretend |
754 | /* If virtual-root isn't specified in cgitrc, lets pretend |
755 | * that virtual-root equals SCRIPT_NAME. |
755 | * that virtual-root equals SCRIPT_NAME, minus any possibly |
| |
756 | * trailing slashes. |
756 | */ |
757 | */ |
757 | if (!ctx.cfg.virtual_root) |
758 | if (!ctx.cfg.virtual_root) |
758 | ctx.cfg.virtual_root = ctx.cfg.script_name; |
759 | ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); |
759 | |
760 | |
760 | /* If no url parameter is specified on the querystring, lets |
761 | /* If no url parameter is specified on the querystring, lets |
761 | * use PATH_INFO as url. This allows cgit to work with virtual |
762 | * use PATH_INFO as url. This allows cgit to work with virtual |
762 | * urls without the need for rewriterules in the webserver (as |
763 | * urls without the need for rewriterules in the webserver (as |
763 | * long as PATH_INFO is included in the cache lookup key). |
764 | * long as PATH_INFO is included in the cache lookup key). |
764 | */ |
765 | */ |
765 | path = ctx.env.path_info; |
766 | path = ctx.env.path_info; |
766 | if (!ctx.qry.url && path) { |
767 | if (!ctx.qry.url && path) { |
767 | if (path[0] == '/') |
768 | if (path[0] == '/') |
768 | path++; |
769 | path++; |
769 | ctx.qry.url = xstrdup(path); |
770 | ctx.qry.url = xstrdup(path); |
770 | if (ctx.qry.raw) { |
771 | if (ctx.qry.raw) { |
771 | qry = ctx.qry.raw; |
772 | qry = ctx.qry.raw; |
772 | ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); |
773 | ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); |
773 | free(qry); |
774 | free(qry); |
774 | } else |
775 | } else |
775 | ctx.qry.raw = xstrdup(ctx.qry.url); |
776 | ctx.qry.raw = xstrdup(ctx.qry.url); |
776 | cgit_parse_url(ctx.qry.url); |
777 | cgit_parse_url(ctx.qry.url); |
777 | } |
778 | } |
778 | |
779 | |
779 | ttl = calc_ttl(); |
780 | ttl = calc_ttl(); |
780 | ctx.page.expires += ttl*60; |
781 | ctx.page.expires += ttl*60; |
781 | if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")) |
782 | if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")) |
782 | ctx.cfg.nocache = 1; |
783 | ctx.cfg.nocache = 1; |
783 | if (ctx.cfg.nocache) |
784 | if (ctx.cfg.nocache) |
784 | ctx.cfg.cache_size = 0; |
785 | ctx.cfg.cache_size = 0; |
785 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, |
786 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, |
786 | ctx.qry.raw, ttl, process_request, &ctx); |
787 | ctx.qry.raw, ttl, process_request, &ctx); |
787 | if (err) |
788 | if (err) |
788 | cgit_print_error(fmt("Error processing page: %s (%d)", |
789 | cgit_print_error(fmt("Error processing page: %s (%d)", |
789 | strerror(err), err)); |
790 | strerror(err), err)); |
790 | return err; |
791 | return err; |
|