diff options
Diffstat (limited to 'cgit.c')
-rw-r--r-- | cgit.c | 50 |
1 files changed, 39 insertions, 11 deletions
@@ -26,18 +26,33 @@ void add_mimetype(const char *name, const char *value) | |||
26 | item->util = xstrdup(value); | 26 | item->util = xstrdup(value); |
27 | } | 27 | } |
28 | 28 | ||
29 | struct cgit_filter *new_filter(const char *cmd, int extra_args) | 29 | struct cgit_filter *new_filter(const char *cmd, filter_type filtertype) |
30 | { | 30 | { |
31 | struct cgit_filter *f; | 31 | struct cgit_filter *f; |
32 | int args_size = 0; | ||
33 | int extra_args; | ||
32 | 34 | ||
33 | if (!cmd || !cmd[0]) | 35 | if (!cmd || !cmd[0]) |
34 | return NULL; | 36 | return NULL; |
35 | 37 | ||
38 | switch (filtertype) { | ||
39 | case SOURCE: | ||
40 | extra_args = 1; | ||
41 | break; | ||
42 | |||
43 | case ABOUT: | ||
44 | case COMMIT: | ||
45 | default: | ||
46 | extra_args = 0; | ||
47 | break; | ||
48 | } | ||
49 | |||
36 | f = xmalloc(sizeof(struct cgit_filter)); | 50 | f = xmalloc(sizeof(struct cgit_filter)); |
37 | f->cmd = xstrdup(cmd); | 51 | f->cmd = xstrdup(cmd); |
38 | f->argv = xmalloc((2 + extra_args) * sizeof(char *)); | 52 | args_size = (2 + extra_args) * sizeof(char *); |
53 | f->argv = xmalloc(args_size); | ||
54 | memset(f->argv, 0, args_size); | ||
39 | f->argv[0] = f->cmd; | 55 | f->argv[0] = f->cmd; |
40 | f->argv[1] = NULL; | ||
41 | return f; | 56 | return f; |
42 | } | 57 | } |
43 | 58 | ||
@@ -81,11 +96,11 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value) | |||
81 | repo->logo_link = xstrdup(value); | 96 | repo->logo_link = xstrdup(value); |
82 | else if (ctx.cfg.enable_filter_overrides) { | 97 | else if (ctx.cfg.enable_filter_overrides) { |
83 | if (!strcmp(name, "about-filter")) | 98 | if (!strcmp(name, "about-filter")) |
84 | repo->about_filter = new_filter(value, 0); | 99 | repo->about_filter = new_filter(value, ABOUT); |
85 | else if (!strcmp(name, "commit-filter")) | 100 | else if (!strcmp(name, "commit-filter")) |
86 | repo->commit_filter = new_filter(value, 0); | 101 | repo->commit_filter = new_filter(value, COMMIT); |
87 | else if (!strcmp(name, "source-filter")) | 102 | else if (!strcmp(name, "source-filter")) |
88 | repo->source_filter = new_filter(value, 1); | 103 | repo->source_filter = new_filter(value, SOURCE); |
89 | } | 104 | } |
90 | } | 105 | } |
91 | 106 | ||
@@ -145,6 +160,8 @@ void config_cb(const char *name, const char *value) | |||
145 | ctx.cfg.enable_filter_overrides = atoi(value); | 160 | ctx.cfg.enable_filter_overrides = atoi(value); |
146 | else if (!strcmp(name, "enable-gitweb-owner")) | 161 | else if (!strcmp(name, "enable-gitweb-owner")) |
147 | ctx.cfg.enable_gitweb_owner = atoi(value); | 162 | ctx.cfg.enable_gitweb_owner = atoi(value); |
163 | else if (!strcmp(name, "enable-http-clone")) | ||
164 | ctx.cfg.enable_http_clone = atoi(value); | ||
148 | else if (!strcmp(name, "enable-index-links")) | 165 | else if (!strcmp(name, "enable-index-links")) |
149 | ctx.cfg.enable_index_links = atoi(value); | 166 | ctx.cfg.enable_index_links = atoi(value); |
150 | else if (!strcmp(name, "enable-commit-graph")) | 167 | else if (!strcmp(name, "enable-commit-graph")) |
@@ -176,9 +193,9 @@ void config_cb(const char *name, const char *value) | |||
176 | else if (!strcmp(name, "cache-dynamic-ttl")) | 193 | else if (!strcmp(name, "cache-dynamic-ttl")) |
177 | ctx.cfg.cache_dynamic_ttl = atoi(value); | 194 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
178 | else if (!strcmp(name, "about-filter")) | 195 | else if (!strcmp(name, "about-filter")) |
179 | ctx.cfg.about_filter = new_filter(value, 0); | 196 | ctx.cfg.about_filter = new_filter(value, ABOUT); |
180 | else if (!strcmp(name, "commit-filter")) | 197 | else if (!strcmp(name, "commit-filter")) |
181 | ctx.cfg.commit_filter = new_filter(value, 0); | 198 | ctx.cfg.commit_filter = new_filter(value, COMMIT); |
182 | else if (!strcmp(name, "embedded")) | 199 | else if (!strcmp(name, "embedded")) |
183 | ctx.cfg.embedded = atoi(value); | 200 | ctx.cfg.embedded = atoi(value); |
184 | else if (!strcmp(name, "max-atom-items")) | 201 | else if (!strcmp(name, "max-atom-items")) |
@@ -208,7 +225,7 @@ void config_cb(const char *name, const char *value) | |||
208 | else if (!strcmp(name, "section-from-path")) | 225 | else if (!strcmp(name, "section-from-path")) |
209 | ctx.cfg.section_from_path = atoi(value); | 226 | ctx.cfg.section_from_path = atoi(value); |
210 | else if (!strcmp(name, "source-filter")) | 227 | else if (!strcmp(name, "source-filter")) |
211 | ctx.cfg.source_filter = new_filter(value, 1); | 228 | ctx.cfg.source_filter = new_filter(value, SOURCE); |
212 | else if (!strcmp(name, "summary-log")) | 229 | else if (!strcmp(name, "summary-log")) |
213 | ctx.cfg.summary_log = atoi(value); | 230 | ctx.cfg.summary_log = atoi(value); |
214 | else if (!strcmp(name, "summary-branches")) | 231 | else if (!strcmp(name, "summary-branches")) |
@@ -310,6 +327,7 @@ static void prepare_context(struct cgit_context *ctx) | |||
310 | ctx->cfg.logo = "/cgit.png"; | 327 | ctx->cfg.logo = "/cgit.png"; |
311 | ctx->cfg.local_time = 0; | 328 | ctx->cfg.local_time = 0; |
312 | ctx->cfg.enable_gitweb_owner = 1; | 329 | ctx->cfg.enable_gitweb_owner = 1; |
330 | ctx->cfg.enable_http_clone = 1; | ||
313 | ctx->cfg.enable_tree_linenumbers = 1; | 331 | ctx->cfg.enable_tree_linenumbers = 1; |
314 | ctx->cfg.max_repo_count = 50; | 332 | ctx->cfg.max_repo_count = 50; |
315 | ctx->cfg.max_commit_count = 50; | 333 | ctx->cfg.max_commit_count = 50; |
@@ -437,7 +455,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
437 | tmp = xstrdup(ctx->qry.head); | 455 | tmp = xstrdup(ctx->qry.head); |
438 | ctx->qry.head = ctx->repo->defbranch; | 456 | ctx->qry.head = ctx->repo->defbranch; |
439 | ctx->page.status = 404; | 457 | ctx->page.status = 404; |
440 | ctx->page.statusmsg = "not found"; | 458 | ctx->page.statusmsg = "Not found"; |
441 | cgit_print_http_headers(ctx); | 459 | cgit_print_http_headers(ctx); |
442 | cgit_print_docstart(ctx); | 460 | cgit_print_docstart(ctx); |
443 | cgit_print_pageheader(ctx); | 461 | cgit_print_pageheader(ctx); |
@@ -456,6 +474,8 @@ static void process_request(void *cbdata) | |||
456 | cmd = cgit_get_cmd(ctx); | 474 | cmd = cgit_get_cmd(ctx); |
457 | if (!cmd) { | 475 | if (!cmd) { |
458 | ctx->page.title = "cgit error"; | 476 | ctx->page.title = "cgit error"; |
477 | ctx->page.status = 404; | ||
478 | ctx->page.statusmsg = "Not found"; | ||
459 | cgit_print_http_headers(ctx); | 479 | cgit_print_http_headers(ctx); |
460 | cgit_print_docstart(ctx); | 480 | cgit_print_docstart(ctx); |
461 | cgit_print_pageheader(ctx); | 481 | cgit_print_pageheader(ctx); |
@@ -464,6 +484,11 @@ static void process_request(void *cbdata) | |||
464 | return; | 484 | return; |
465 | } | 485 | } |
466 | 486 | ||
487 | if (!ctx->cfg.enable_http_clone && cmd->is_clone) { | ||
488 | html_status(404, "Not found", 0); | ||
489 | return; | ||
490 | } | ||
491 | |||
467 | /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual" | 492 | /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual" |
468 | * in-project path limit to be made available at ctx->qry.vpath. | 493 | * in-project path limit to be made available at ctx->qry.vpath. |
469 | * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL). | 494 | * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL). |
@@ -755,8 +780,11 @@ int main(int argc, const char **argv) | |||
755 | * that virtual-root equals SCRIPT_NAME, minus any possibly | 780 | * that virtual-root equals SCRIPT_NAME, minus any possibly |
756 | * trailing slashes. | 781 | * trailing slashes. |
757 | */ | 782 | */ |
758 | if (!ctx.cfg.virtual_root) | 783 | if (!ctx.cfg.virtual_root && ctx.cfg.script_name) { |
759 | ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); | 784 | ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); |
785 | if (!ctx.cfg.virtual_root) | ||
786 | ctx.cfg.virtual_root = ""; | ||
787 | } | ||
760 | 788 | ||
761 | /* If no url parameter is specified on the querystring, lets | 789 | /* If no url parameter is specified on the querystring, lets |
762 | * use PATH_INFO as url. This allows cgit to work with virtual | 790 | * use PATH_INFO as url. This allows cgit to work with virtual |