summaryrefslogtreecommitdiffabout
path: root/cgit.c
Unidiff
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/cgit.c b/cgit.c
index 19adadd..ae20257 100644
--- a/cgit.c
+++ b/cgit.c
@@ -185,48 +185,49 @@ static void prepare_context(struct cgit_context *ctx)
185 ctx->cfg.css = "/cgit.css"; 185 ctx->cfg.css = "/cgit.css";
186 ctx->cfg.logo = "/git-logo.png"; 186 ctx->cfg.logo = "/git-logo.png";
187 ctx->cfg.local_time = 0; 187 ctx->cfg.local_time = 0;
188 ctx->cfg.max_repo_count = 50; 188 ctx->cfg.max_repo_count = 50;
189 ctx->cfg.max_commit_count = 50; 189 ctx->cfg.max_commit_count = 50;
190 ctx->cfg.max_lock_attempts = 5; 190 ctx->cfg.max_lock_attempts = 5;
191 ctx->cfg.max_msg_len = 80; 191 ctx->cfg.max_msg_len = 80;
192 ctx->cfg.max_repodesc_len = 80; 192 ctx->cfg.max_repodesc_len = 80;
193 ctx->cfg.max_stats = 0; 193 ctx->cfg.max_stats = 0;
194 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; 194 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
195 ctx->cfg.renamelimit = -1; 195 ctx->cfg.renamelimit = -1;
196 ctx->cfg.robots = "index, nofollow"; 196 ctx->cfg.robots = "index, nofollow";
197 ctx->cfg.root_title = "Git repository browser"; 197 ctx->cfg.root_title = "Git repository browser";
198 ctx->cfg.root_desc = "a fast webinterface for the git dscm"; 198 ctx->cfg.root_desc = "a fast webinterface for the git dscm";
199 ctx->cfg.script_name = CGIT_SCRIPT_NAME; 199 ctx->cfg.script_name = CGIT_SCRIPT_NAME;
200 ctx->cfg.summary_branches = 10; 200 ctx->cfg.summary_branches = 10;
201 ctx->cfg.summary_log = 10; 201 ctx->cfg.summary_log = 10;
202 ctx->cfg.summary_tags = 10; 202 ctx->cfg.summary_tags = 10;
203 ctx->page.mimetype = "text/html"; 203 ctx->page.mimetype = "text/html";
204 ctx->page.charset = PAGE_ENCODING; 204 ctx->page.charset = PAGE_ENCODING;
205 ctx->page.filename = NULL; 205 ctx->page.filename = NULL;
206 ctx->page.size = 0; 206 ctx->page.size = 0;
207 ctx->page.modified = time(NULL); 207 ctx->page.modified = time(NULL);
208 ctx->page.expires = ctx->page.modified; 208 ctx->page.expires = ctx->page.modified;
209 ctx->page.etag = NULL;
209} 210}
210 211
211struct refmatch { 212struct refmatch {
212 char *req_ref; 213 char *req_ref;
213 char *first_ref; 214 char *first_ref;
214 int match; 215 int match;
215}; 216};
216 217
217int find_current_ref(const char *refname, const unsigned char *sha1, 218int find_current_ref(const char *refname, const unsigned char *sha1,
218 int flags, void *cb_data) 219 int flags, void *cb_data)
219{ 220{
220 struct refmatch *info; 221 struct refmatch *info;
221 222
222 info = (struct refmatch *)cb_data; 223 info = (struct refmatch *)cb_data;
223 if (!strcmp(refname, info->req_ref)) 224 if (!strcmp(refname, info->req_ref))
224 info->match = 1; 225 info->match = 1;
225 if (!info->first_ref) 226 if (!info->first_ref)
226 info->first_ref = xstrdup(refname); 227 info->first_ref = xstrdup(refname);
227 return info->match; 228 return info->match;
228} 229}
229 230
230char *find_default_branch(struct cgit_repo *repo) 231char *find_default_branch(struct cgit_repo *repo)
231{ 232{
232 struct refmatch info; 233 struct refmatch info;
@@ -410,79 +411,82 @@ static void cgit_parse_args(int argc, const char **argv)
410 exit(0); 411 exit(0);
411 } 412 }
412} 413}
413 414
414static int calc_ttl() 415static int calc_ttl()
415{ 416{
416 if (!ctx.repo) 417 if (!ctx.repo)
417 return ctx.cfg.cache_root_ttl; 418 return ctx.cfg.cache_root_ttl;
418 419
419 if (!ctx.qry.page) 420 if (!ctx.qry.page)
420 return ctx.cfg.cache_repo_ttl; 421 return ctx.cfg.cache_repo_ttl;
421 422
422 if (ctx.qry.has_symref) 423 if (ctx.qry.has_symref)
423 return ctx.cfg.cache_dynamic_ttl; 424 return ctx.cfg.cache_dynamic_ttl;
424 425
425 if (ctx.qry.has_sha1) 426 if (ctx.qry.has_sha1)
426 return ctx.cfg.cache_static_ttl; 427 return ctx.cfg.cache_static_ttl;
427 428
428 return ctx.cfg.cache_repo_ttl; 429 return ctx.cfg.cache_repo_ttl;
429} 430}
430 431
431int main(int argc, const char **argv) 432int main(int argc, const char **argv)
432{ 433{
433 const char *cgit_config_env = getenv("CGIT_CONFIG"); 434 const char *cgit_config_env = getenv("CGIT_CONFIG");
435 const char *method = getenv("REQUEST_METHOD");
434 const char *path; 436 const char *path;
435 char *qry; 437 char *qry;
436 int err, ttl; 438 int err, ttl;
437 439
438 prepare_context(&ctx); 440 prepare_context(&ctx);
439 cgit_repolist.length = 0; 441 cgit_repolist.length = 0;
440 cgit_repolist.count = 0; 442 cgit_repolist.count = 0;
441 cgit_repolist.repos = NULL; 443 cgit_repolist.repos = NULL;
442 444
443 if (getenv("SCRIPT_NAME")) 445 if (getenv("SCRIPT_NAME"))
444 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); 446 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME"));
445 if (getenv("QUERY_STRING")) 447 if (getenv("QUERY_STRING"))
446 ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); 448 ctx.qry.raw = xstrdup(getenv("QUERY_STRING"));
447 cgit_parse_args(argc, argv); 449 cgit_parse_args(argc, argv);
448 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, 450 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
449 config_cb); 451 config_cb);
450 ctx.repo = NULL; 452 ctx.repo = NULL;
451 http_parse_querystring(ctx.qry.raw, querystring_cb); 453 http_parse_querystring(ctx.qry.raw, querystring_cb);
452 454
453 /* If virtual-root isn't specified in cgitrc, lets pretend 455 /* If virtual-root isn't specified in cgitrc, lets pretend
454 * that virtual-root equals SCRIPT_NAME. 456 * that virtual-root equals SCRIPT_NAME.
455 */ 457 */
456 if (!ctx.cfg.virtual_root) 458 if (!ctx.cfg.virtual_root)
457 ctx.cfg.virtual_root = ctx.cfg.script_name; 459 ctx.cfg.virtual_root = ctx.cfg.script_name;
458 460
459 /* If no url parameter is specified on the querystring, lets 461 /* If no url parameter is specified on the querystring, lets
460 * use PATH_INFO as url. This allows cgit to work with virtual 462 * use PATH_INFO as url. This allows cgit to work with virtual
461 * urls without the need for rewriterules in the webserver (as 463 * urls without the need for rewriterules in the webserver (as
462 * long as PATH_INFO is included in the cache lookup key). 464 * long as PATH_INFO is included in the cache lookup key).
463 */ 465 */
464 path = getenv("PATH_INFO"); 466 path = getenv("PATH_INFO");
465 if (!ctx.qry.url && path) { 467 if (!ctx.qry.url && path) {
466 if (path[0] == '/') 468 if (path[0] == '/')
467 path++; 469 path++;
468 ctx.qry.url = xstrdup(path); 470 ctx.qry.url = xstrdup(path);
469 if (ctx.qry.raw) { 471 if (ctx.qry.raw) {
470 qry = ctx.qry.raw; 472 qry = ctx.qry.raw;
471 ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); 473 ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry));
472 free(qry); 474 free(qry);
473 } else 475 } else
474 ctx.qry.raw = ctx.qry.url; 476 ctx.qry.raw = ctx.qry.url;
475 cgit_parse_url(ctx.qry.url); 477 cgit_parse_url(ctx.qry.url);
476 } 478 }
477 479
478 ttl = calc_ttl(); 480 ttl = calc_ttl();
479 ctx.page.expires += ttl*60; 481 ctx.page.expires += ttl*60;
482 if (method && !strcmp(method, "HEAD"))
483 ctx.cfg.nocache = 1;
480 if (ctx.cfg.nocache) 484 if (ctx.cfg.nocache)
481 ctx.cfg.cache_size = 0; 485 ctx.cfg.cache_size = 0;
482 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, 486 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
483 ctx.qry.raw, ttl, process_request, &ctx); 487 ctx.qry.raw, ttl, process_request, &ctx);
484 if (err) 488 if (err)
485 cgit_print_error(fmt("Error processing page: %s (%d)", 489 cgit_print_error(fmt("Error processing page: %s (%d)",
486 strerror(err), err)); 490 strerror(err), err));
487 return err; 491 return err;
488} 492}