-rw-r--r-- | cgit.c | 4 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | ui-plain.c | 1 | ||||
-rw-r--r-- | ui-shared.c | 6 |
4 files changed, 12 insertions, 0 deletions
@@ -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 | ||
211 | struct refmatch { | 212 | struct 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 | ||
217 | int find_current_ref(const char *refname, const unsigned char *sha1, | 218 | int 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 | ||
230 | char *find_default_branch(struct cgit_repo *repo) | 231 | char *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 | ||
414 | static int calc_ttl() | 415 | static 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 | ||
431 | int main(int argc, const char **argv) | 432 | int 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 | } |
@@ -159,48 +159,49 @@ struct cgit_config { | |||
159 | int enable_log_filecount; | 159 | int enable_log_filecount; |
160 | int enable_log_linecount; | 160 | int enable_log_linecount; |
161 | int local_time; | 161 | int local_time; |
162 | int max_repo_count; | 162 | int max_repo_count; |
163 | int max_commit_count; | 163 | int max_commit_count; |
164 | int max_lock_attempts; | 164 | int max_lock_attempts; |
165 | int max_msg_len; | 165 | int max_msg_len; |
166 | int max_repodesc_len; | 166 | int max_repodesc_len; |
167 | int max_stats; | 167 | int max_stats; |
168 | int nocache; | 168 | int nocache; |
169 | int renamelimit; | 169 | int renamelimit; |
170 | int snapshots; | 170 | int snapshots; |
171 | int summary_branches; | 171 | int summary_branches; |
172 | int summary_log; | 172 | int summary_log; |
173 | int summary_tags; | 173 | int summary_tags; |
174 | }; | 174 | }; |
175 | 175 | ||
176 | struct cgit_page { | 176 | struct cgit_page { |
177 | time_t modified; | 177 | time_t modified; |
178 | time_t expires; | 178 | time_t expires; |
179 | size_t size; | 179 | size_t size; |
180 | char *mimetype; | 180 | char *mimetype; |
181 | char *charset; | 181 | char *charset; |
182 | char *filename; | 182 | char *filename; |
183 | char *etag; | ||
183 | char *title; | 184 | char *title; |
184 | int status; | 185 | int status; |
185 | char *statusmsg; | 186 | char *statusmsg; |
186 | }; | 187 | }; |
187 | 188 | ||
188 | struct cgit_context { | 189 | struct cgit_context { |
189 | struct cgit_query qry; | 190 | struct cgit_query qry; |
190 | struct cgit_config cfg; | 191 | struct cgit_config cfg; |
191 | struct cgit_repo *repo; | 192 | struct cgit_repo *repo; |
192 | struct cgit_page page; | 193 | struct cgit_page page; |
193 | }; | 194 | }; |
194 | 195 | ||
195 | struct cgit_snapshot_format { | 196 | struct cgit_snapshot_format { |
196 | const char *suffix; | 197 | const char *suffix; |
197 | const char *mimetype; | 198 | const char *mimetype; |
198 | write_archive_fn_t write_func; | 199 | write_archive_fn_t write_func; |
199 | int bit; | 200 | int bit; |
200 | }; | 201 | }; |
201 | 202 | ||
202 | extern const char *cgit_version; | 203 | extern const char *cgit_version; |
203 | 204 | ||
204 | extern struct cgit_repolist cgit_repolist; | 205 | extern struct cgit_repolist cgit_repolist; |
205 | extern struct cgit_context ctx; | 206 | extern struct cgit_context ctx; |
206 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; | 207 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; |
@@ -16,48 +16,49 @@ int match; | |||
16 | 16 | ||
17 | static void print_object(const unsigned char *sha1, const char *path) | 17 | static void print_object(const unsigned char *sha1, const char *path) |
18 | { | 18 | { |
19 | enum object_type type; | 19 | enum object_type type; |
20 | char *buf; | 20 | char *buf; |
21 | unsigned long size; | 21 | unsigned long size; |
22 | 22 | ||
23 | type = sha1_object_info(sha1, &size); | 23 | type = sha1_object_info(sha1, &size); |
24 | if (type == OBJ_BAD) { | 24 | if (type == OBJ_BAD) { |
25 | html_status(404, "Not found", 0); | 25 | html_status(404, "Not found", 0); |
26 | return; | 26 | return; |
27 | } | 27 | } |
28 | 28 | ||
29 | buf = read_sha1_file(sha1, &type, &size); | 29 | buf = read_sha1_file(sha1, &type, &size); |
30 | if (!buf) { | 30 | if (!buf) { |
31 | html_status(404, "Not found", 0); | 31 | html_status(404, "Not found", 0); |
32 | return; | 32 | return; |
33 | } | 33 | } |
34 | if (buffer_is_binary(buf, size)) | 34 | if (buffer_is_binary(buf, size)) |
35 | ctx.page.mimetype = "application/octet-stream"; | 35 | ctx.page.mimetype = "application/octet-stream"; |
36 | else | 36 | else |
37 | ctx.page.mimetype = "text/plain"; | 37 | ctx.page.mimetype = "text/plain"; |
38 | ctx.page.filename = fmt("%s", path); | 38 | ctx.page.filename = fmt("%s", path); |
39 | ctx.page.size = size; | 39 | ctx.page.size = size; |
40 | ctx.page.etag = sha1_to_hex(sha1); | ||
40 | cgit_print_http_headers(&ctx); | 41 | cgit_print_http_headers(&ctx); |
41 | html_raw(buf, size); | 42 | html_raw(buf, size); |
42 | match = 1; | 43 | match = 1; |
43 | } | 44 | } |
44 | 45 | ||
45 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 46 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
46 | const char *pathname, unsigned mode, int stage, | 47 | const char *pathname, unsigned mode, int stage, |
47 | void *cbdata) | 48 | void *cbdata) |
48 | { | 49 | { |
49 | if (S_ISDIR(mode)) | 50 | if (S_ISDIR(mode)) |
50 | return READ_TREE_RECURSIVE; | 51 | return READ_TREE_RECURSIVE; |
51 | 52 | ||
52 | if (S_ISREG(mode)) | 53 | if (S_ISREG(mode)) |
53 | print_object(sha1, pathname); | 54 | print_object(sha1, pathname); |
54 | 55 | ||
55 | return 0; | 56 | return 0; |
56 | } | 57 | } |
57 | 58 | ||
58 | void cgit_print_plain(struct cgit_context *ctx) | 59 | void cgit_print_plain(struct cgit_context *ctx) |
59 | { | 60 | { |
60 | const char *rev = ctx->qry.sha1; | 61 | const char *rev = ctx->qry.sha1; |
61 | unsigned char sha1[20]; | 62 | unsigned char sha1[20]; |
62 | struct commit *commit; | 63 | struct commit *commit; |
63 | const char *paths[] = {ctx->qry.path, NULL}; | 64 | const char *paths[] = {ctx->qry.path, NULL}; |
diff --git a/ui-shared.c b/ui-shared.c index 29036d0..10be3c0 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -446,63 +446,69 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) | |||
446 | secs * 1.0 / TM_HOUR); | 446 | secs * 1.0 / TM_HOUR); |
447 | return; | 447 | return; |
448 | } | 448 | } |
449 | if (secs < TM_WEEK * 2) { | 449 | if (secs < TM_WEEK * 2) { |
450 | htmlf("<span class='age-days'>%.0f days</span>", | 450 | htmlf("<span class='age-days'>%.0f days</span>", |
451 | secs * 1.0 / TM_DAY); | 451 | secs * 1.0 / TM_DAY); |
452 | return; | 452 | return; |
453 | } | 453 | } |
454 | if (secs < TM_MONTH * 2) { | 454 | if (secs < TM_MONTH * 2) { |
455 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 455 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
456 | secs * 1.0 / TM_WEEK); | 456 | secs * 1.0 / TM_WEEK); |
457 | return; | 457 | return; |
458 | } | 458 | } |
459 | if (secs < TM_YEAR * 2) { | 459 | if (secs < TM_YEAR * 2) { |
460 | htmlf("<span class='age-months'>%.0f months</span>", | 460 | htmlf("<span class='age-months'>%.0f months</span>", |
461 | secs * 1.0 / TM_MONTH); | 461 | secs * 1.0 / TM_MONTH); |
462 | return; | 462 | return; |
463 | } | 463 | } |
464 | htmlf("<span class='age-years'>%.0f years</span>", | 464 | htmlf("<span class='age-years'>%.0f years</span>", |
465 | secs * 1.0 / TM_YEAR); | 465 | secs * 1.0 / TM_YEAR); |
466 | } | 466 | } |
467 | 467 | ||
468 | void cgit_print_http_headers(struct cgit_context *ctx) | 468 | void cgit_print_http_headers(struct cgit_context *ctx) |
469 | { | 469 | { |
470 | const char *method = getenv("REQUEST_METHOD"); | ||
471 | |||
470 | if (ctx->page.status) | 472 | if (ctx->page.status) |
471 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); | 473 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); |
472 | if (ctx->page.mimetype && ctx->page.charset) | 474 | if (ctx->page.mimetype && ctx->page.charset) |
473 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 475 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
474 | ctx->page.charset); | 476 | ctx->page.charset); |
475 | else if (ctx->page.mimetype) | 477 | else if (ctx->page.mimetype) |
476 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 478 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
477 | if (ctx->page.size) | 479 | if (ctx->page.size) |
478 | htmlf("Content-Length: %ld\n", ctx->page.size); | 480 | htmlf("Content-Length: %ld\n", ctx->page.size); |
479 | if (ctx->page.filename) | 481 | if (ctx->page.filename) |
480 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 482 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
481 | ctx->page.filename); | 483 | ctx->page.filename); |
482 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 484 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
483 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 485 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
486 | if (ctx->page.etag) | ||
487 | htmlf("ETag: \"%s\"\n", ctx->page.etag); | ||
484 | html("\n"); | 488 | html("\n"); |
489 | if (method && !strcmp(method, "HEAD")) | ||
490 | exit(0); | ||
485 | } | 491 | } |
486 | 492 | ||
487 | void cgit_print_docstart(struct cgit_context *ctx) | 493 | void cgit_print_docstart(struct cgit_context *ctx) |
488 | { | 494 | { |
489 | char *host = cgit_hosturl(); | 495 | char *host = cgit_hosturl(); |
490 | html(cgit_doctype); | 496 | html(cgit_doctype); |
491 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 497 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
492 | html("<head>\n"); | 498 | html("<head>\n"); |
493 | html("<title>"); | 499 | html("<title>"); |
494 | html_txt(ctx->page.title); | 500 | html_txt(ctx->page.title); |
495 | html("</title>\n"); | 501 | html("</title>\n"); |
496 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 502 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
497 | if (ctx->cfg.robots && *ctx->cfg.robots) | 503 | if (ctx->cfg.robots && *ctx->cfg.robots) |
498 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 504 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
499 | html("<link rel='stylesheet' type='text/css' href='"); | 505 | html("<link rel='stylesheet' type='text/css' href='"); |
500 | html_attr(ctx->cfg.css); | 506 | html_attr(ctx->cfg.css); |
501 | html("'/>\n"); | 507 | html("'/>\n"); |
502 | if (ctx->cfg.favicon) { | 508 | if (ctx->cfg.favicon) { |
503 | html("<link rel='shortcut icon' href='"); | 509 | html("<link rel='shortcut icon' href='"); |
504 | html_attr(ctx->cfg.favicon); | 510 | html_attr(ctx->cfg.favicon); |
505 | html("'/>\n"); | 511 | html("'/>\n"); |
506 | } | 512 | } |
507 | if (host && ctx->repo) { | 513 | if (host && ctx->repo) { |
508 | html("<link rel='alternate' title='Atom feed' href='"); | 514 | html("<link rel='alternate' title='Atom feed' href='"); |