aboutsummaryrefslogtreecommitdiffstats
path: root/cgit.c
diff options
context:
space:
mode:
Diffstat (limited to 'cgit.c')
-rw-r--r--cgit.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/cgit.c b/cgit.c
index 435ce5a..1d50129 100644
--- a/cgit.c
+++ b/cgit.c
@@ -26,14 +26,27 @@ void add_mimetype(const char *name, const char *value)
26 item->util = xstrdup(value); 26 item->util = xstrdup(value);
27} 27}
28 28
29struct cgit_filter *new_filter(const char *cmd, int extra_args) 29struct 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; 32 int args_size = 0;
33 int extra_args;
33 34
34 if (!cmd || !cmd[0]) 35 if (!cmd || !cmd[0])
35 return NULL; 36 return NULL;
36 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
37 f = xmalloc(sizeof(struct cgit_filter)); 50 f = xmalloc(sizeof(struct cgit_filter));
38 f->cmd = xstrdup(cmd); 51 f->cmd = xstrdup(cmd);
39 args_size = (2 + extra_args) * sizeof(char *); 52 args_size = (2 + extra_args) * sizeof(char *);
@@ -83,11 +96,11 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
83 repo->logo_link = xstrdup(value); 96 repo->logo_link = xstrdup(value);
84 else if (ctx.cfg.enable_filter_overrides) { 97 else if (ctx.cfg.enable_filter_overrides) {
85 if (!strcmp(name, "about-filter")) 98 if (!strcmp(name, "about-filter"))
86 repo->about_filter = new_filter(value, 0); 99 repo->about_filter = new_filter(value, ABOUT);
87 else if (!strcmp(name, "commit-filter")) 100 else if (!strcmp(name, "commit-filter"))
88 repo->commit_filter = new_filter(value, 0); 101 repo->commit_filter = new_filter(value, COMMIT);
89 else if (!strcmp(name, "source-filter")) 102 else if (!strcmp(name, "source-filter"))
90 repo->source_filter = new_filter(value, 1); 103 repo->source_filter = new_filter(value, SOURCE);
91 } 104 }
92} 105}
93 106
@@ -147,6 +160,8 @@ void config_cb(const char *name, const char *value)
147 ctx.cfg.enable_filter_overrides = atoi(value); 160 ctx.cfg.enable_filter_overrides = atoi(value);
148 else if (!strcmp(name, "enable-gitweb-owner")) 161 else if (!strcmp(name, "enable-gitweb-owner"))
149 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);
150 else if (!strcmp(name, "enable-index-links")) 165 else if (!strcmp(name, "enable-index-links"))
151 ctx.cfg.enable_index_links = atoi(value); 166 ctx.cfg.enable_index_links = atoi(value);
152 else if (!strcmp(name, "enable-commit-graph")) 167 else if (!strcmp(name, "enable-commit-graph"))
@@ -178,9 +193,9 @@ void config_cb(const char *name, const char *value)
178 else if (!strcmp(name, "cache-dynamic-ttl")) 193 else if (!strcmp(name, "cache-dynamic-ttl"))
179 ctx.cfg.cache_dynamic_ttl = atoi(value); 194 ctx.cfg.cache_dynamic_ttl = atoi(value);
180 else if (!strcmp(name, "about-filter")) 195 else if (!strcmp(name, "about-filter"))
181 ctx.cfg.about_filter = new_filter(value, 0); 196 ctx.cfg.about_filter = new_filter(value, ABOUT);
182 else if (!strcmp(name, "commit-filter")) 197 else if (!strcmp(name, "commit-filter"))
183 ctx.cfg.commit_filter = new_filter(value, 0); 198 ctx.cfg.commit_filter = new_filter(value, COMMIT);
184 else if (!strcmp(name, "embedded")) 199 else if (!strcmp(name, "embedded"))
185 ctx.cfg.embedded = atoi(value); 200 ctx.cfg.embedded = atoi(value);
186 else if (!strcmp(name, "max-atom-items")) 201 else if (!strcmp(name, "max-atom-items"))
@@ -210,7 +225,7 @@ void config_cb(const char *name, const char *value)
210 else if (!strcmp(name, "section-from-path")) 225 else if (!strcmp(name, "section-from-path"))
211 ctx.cfg.section_from_path = atoi(value); 226 ctx.cfg.section_from_path = atoi(value);
212 else if (!strcmp(name, "source-filter")) 227 else if (!strcmp(name, "source-filter"))
213 ctx.cfg.source_filter = new_filter(value, 1); 228 ctx.cfg.source_filter = new_filter(value, SOURCE);
214 else if (!strcmp(name, "summary-log")) 229 else if (!strcmp(name, "summary-log"))
215 ctx.cfg.summary_log = atoi(value); 230 ctx.cfg.summary_log = atoi(value);
216 else if (!strcmp(name, "summary-branches")) 231 else if (!strcmp(name, "summary-branches"))
@@ -229,6 +244,8 @@ void config_cb(const char *name, const char *value)
229 ctx.cfg.robots = xstrdup(value); 244 ctx.cfg.robots = xstrdup(value);
230 else if (!strcmp(name, "clone-prefix")) 245 else if (!strcmp(name, "clone-prefix"))
231 ctx.cfg.clone_prefix = xstrdup(value); 246 ctx.cfg.clone_prefix = xstrdup(value);
247 else if (!strcmp(name, "clone-url"))
248 ctx.cfg.clone_url = xstrdup(value);
232 else if (!strcmp(name, "local-time")) 249 else if (!strcmp(name, "local-time"))
233 ctx.cfg.local_time = atoi(value); 250 ctx.cfg.local_time = atoi(value);
234 else if (!prefixcmp(name, "mimetype.")) 251 else if (!prefixcmp(name, "mimetype."))
@@ -313,6 +330,7 @@ static void prepare_context(struct cgit_context *ctx)
313 ctx->cfg.logo = "/cgit.png"; 330 ctx->cfg.logo = "/cgit.png";
314 ctx->cfg.local_time = 0; 331 ctx->cfg.local_time = 0;
315 ctx->cfg.enable_gitweb_owner = 1; 332 ctx->cfg.enable_gitweb_owner = 1;
333 ctx->cfg.enable_http_clone = 1;
316 ctx->cfg.enable_tree_linenumbers = 1; 334 ctx->cfg.enable_tree_linenumbers = 1;
317 ctx->cfg.max_repo_count = 50; 335 ctx->cfg.max_repo_count = 50;
318 ctx->cfg.max_commit_count = 50; 336 ctx->cfg.max_commit_count = 50;
@@ -444,7 +462,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
444 tmp = xstrdup(ctx->qry.head); 462 tmp = xstrdup(ctx->qry.head);
445 ctx->qry.head = ctx->repo->defbranch; 463 ctx->qry.head = ctx->repo->defbranch;
446 ctx->page.status = 404; 464 ctx->page.status = 404;
447 ctx->page.statusmsg = "not found"; 465 ctx->page.statusmsg = "Not found";
448 cgit_print_http_headers(ctx); 466 cgit_print_http_headers(ctx);
449 cgit_print_docstart(ctx); 467 cgit_print_docstart(ctx);
450 cgit_print_pageheader(ctx); 468 cgit_print_pageheader(ctx);
@@ -452,6 +470,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
452 cgit_print_docend(); 470 cgit_print_docend();
453 return 1; 471 return 1;
454 } 472 }
473 cgit_prepare_repo_env(ctx->repo);
455 return 0; 474 return 0;
456} 475}
457 476
@@ -463,6 +482,8 @@ static void process_request(void *cbdata)
463 cmd = cgit_get_cmd(ctx); 482 cmd = cgit_get_cmd(ctx);
464 if (!cmd) { 483 if (!cmd) {
465 ctx->page.title = "cgit error"; 484 ctx->page.title = "cgit error";
485 ctx->page.status = 404;
486 ctx->page.statusmsg = "Not found";
466 cgit_print_http_headers(ctx); 487 cgit_print_http_headers(ctx);
467 cgit_print_docstart(ctx); 488 cgit_print_docstart(ctx);
468 cgit_print_pageheader(ctx); 489 cgit_print_pageheader(ctx);
@@ -471,6 +492,11 @@ static void process_request(void *cbdata)
471 return; 492 return;
472 } 493 }
473 494
495 if (!ctx->cfg.enable_http_clone && cmd->is_clone) {
496 html_status(404, "Not found", 0);
497 return;
498 }
499
474 /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual" 500 /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual"
475 * in-project path limit to be made available at ctx->qry.vpath. 501 * in-project path limit to be made available at ctx->qry.vpath.
476 * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL). 502 * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL).