|
diff --git a/cgit.c b/cgit.c index 57e11cd..608cab6 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -154,16 +154,20 @@ static void querystring_cb(const char *name, const char *value) |
154 | } else if (!strcmp(name, "ofs")) { |
154 | } else if (!strcmp(name, "ofs")) { |
155 | ctx.qry.ofs = atoi(value); |
155 | ctx.qry.ofs = atoi(value); |
156 | } else if (!strcmp(name, "path")) { |
156 | } else if (!strcmp(name, "path")) { |
157 | ctx.qry.path = trim_end(value, '/'); |
157 | ctx.qry.path = trim_end(value, '/'); |
158 | } else if (!strcmp(name, "name")) { |
158 | } else if (!strcmp(name, "name")) { |
159 | ctx.qry.name = xstrdup(value); |
159 | ctx.qry.name = xstrdup(value); |
160 | } else if (!strcmp(name, "mimetype")) { |
160 | } else if (!strcmp(name, "mimetype")) { |
161 | ctx.qry.mimetype = xstrdup(value); |
161 | ctx.qry.mimetype = xstrdup(value); |
| |
162 | } else if (!strcmp(name, "s")){ |
| |
163 | ctx.qry.sort = xstrdup(value); |
| |
164 | } else if (!strcmp(name, "showmsg")) { |
| |
165 | ctx.qry.showmsg = atoi(value); |
162 | } else if (!strcmp(name, "period")) { |
166 | } else if (!strcmp(name, "period")) { |
163 | ctx.qry.period = xstrdup(value); |
167 | ctx.qry.period = xstrdup(value); |
164 | } |
168 | } |
165 | } |
169 | } |
166 | |
170 | |
167 | static void prepare_context(struct cgit_context *ctx) |
171 | static void prepare_context(struct cgit_context *ctx) |
168 | { |
172 | { |
169 | memset(ctx, 0, sizeof(ctx)); |
173 | memset(ctx, 0, sizeof(ctx)); |
@@ -292,17 +296,16 @@ static int prepare_repo_cmd(struct cgit_context *ctx) |
292 | static void process_request(void *cbdata) |
296 | static void process_request(void *cbdata) |
293 | { |
297 | { |
294 | struct cgit_context *ctx = cbdata; |
298 | struct cgit_context *ctx = cbdata; |
295 | struct cgit_cmd *cmd; |
299 | struct cgit_cmd *cmd; |
296 | |
300 | |
297 | cmd = cgit_get_cmd(ctx); |
301 | cmd = cgit_get_cmd(ctx); |
298 | if (!cmd) { |
302 | if (!cmd) { |
299 | ctx->page.title = "cgit error"; |
303 | ctx->page.title = "cgit error"; |
300 | ctx->repo = NULL; |
| |
301 | cgit_print_http_headers(ctx); |
304 | cgit_print_http_headers(ctx); |
302 | cgit_print_docstart(ctx); |
305 | cgit_print_docstart(ctx); |
303 | cgit_print_pageheader(ctx); |
306 | cgit_print_pageheader(ctx); |
304 | cgit_print_error("Invalid request"); |
307 | cgit_print_error("Invalid request"); |
305 | cgit_print_docend(); |
308 | cgit_print_docend(); |
306 | return; |
309 | return; |
307 | } |
310 | } |
308 | |
311 | |
@@ -438,38 +441,39 @@ int main(int argc, const char **argv) |
438 | if (getenv("QUERY_STRING")) |
441 | if (getenv("QUERY_STRING")) |
439 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
442 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
440 | cgit_parse_args(argc, argv); |
443 | cgit_parse_args(argc, argv); |
441 | parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
444 | parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
442 | config_cb); |
445 | config_cb); |
443 | ctx.repo = NULL; |
446 | ctx.repo = NULL; |
444 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
447 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
445 | |
448 | |
446 | /* If virtual-root isn't specified in cgitrc and no url |
449 | /* If virtual-root isn't specified in cgitrc, lets pretend |
447 | * parameter is specified on the querystring, lets pretend |
450 | * that virtual-root equals SCRIPT_NAME. |
448 | * that virtualroot equals SCRIPT_NAME and use PATH_INFO as |
| |
449 | * url. This allows cgit to work with virtual urls without |
| |
450 | * the need for rewriterules in the webserver (as long as |
| |
451 | * PATH_INFO is included in the cache lookup key). |
| |
452 | */ |
451 | */ |
453 | if (!ctx.cfg.virtual_root && !ctx.qry.url) { |
452 | if (!ctx.cfg.virtual_root) |
454 | ctx.cfg.virtual_root = ctx.cfg.script_name; |
453 | ctx.cfg.virtual_root = ctx.cfg.script_name; |
455 | path = getenv("PATH_INFO"); |
454 | |
456 | if (path) { |
455 | /* If no url parameter is specified on the querystring, lets |
457 | if (path[0] == '/') |
456 | * use PATH_INFO as url. This allows cgit to work with virtual |
458 | path++; |
457 | * urls without the need for rewriterules in the webserver (as |
459 | ctx.qry.url = xstrdup(path); |
458 | * long as PATH_INFO is included in the cache lookup key). |
460 | if (ctx.qry.raw) { |
459 | */ |
461 | qry = ctx.qry.raw; |
460 | path = getenv("PATH_INFO"); |
462 | ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); |
461 | if (!ctx.qry.url && path) { |
463 | free(qry); |
462 | if (path[0] == '/') |
464 | } else |
463 | path++; |
465 | ctx.qry.raw = ctx.qry.url; |
464 | ctx.qry.url = xstrdup(path); |
466 | cgit_parse_url(ctx.qry.url); |
465 | if (ctx.qry.raw) { |
467 | } |
466 | qry = ctx.qry.raw; |
| |
467 | ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); |
| |
468 | free(qry); |
| |
469 | } else |
| |
470 | ctx.qry.raw = ctx.qry.url; |
| |
471 | cgit_parse_url(ctx.qry.url); |
468 | } |
472 | } |
469 | |
473 | |
470 | ttl = calc_ttl(); |
474 | ttl = calc_ttl(); |
471 | ctx.page.expires += ttl*60; |
475 | ctx.page.expires += ttl*60; |
472 | if (ctx.cfg.nocache) |
476 | if (ctx.cfg.nocache) |
473 | ctx.cfg.cache_size = 0; |
477 | ctx.cfg.cache_size = 0; |
474 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, |
478 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, |
475 | ctx.qry.raw, ttl, process_request, &ctx); |
479 | ctx.qry.raw, ttl, process_request, &ctx); |
|