|
diff --git a/cgit.c b/cgit.c index 6e5215e..f35f605 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -109,96 +109,100 @@ void config_cb(const char *name, const char *value) |
109 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) |
109 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) |
110 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
110 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
111 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) |
111 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) |
112 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
112 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
113 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) |
113 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) |
114 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
114 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
115 | else if (ctx.repo && !strcmp(name, "repo.module-link")) |
115 | else if (ctx.repo && !strcmp(name, "repo.module-link")) |
116 | ctx.repo->module_link= xstrdup(value); |
116 | ctx.repo->module_link= xstrdup(value); |
117 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { |
117 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { |
118 | if (*value == '/') |
118 | if (*value == '/') |
119 | ctx.repo->readme = xstrdup(value); |
119 | ctx.repo->readme = xstrdup(value); |
120 | else |
120 | else |
121 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); |
121 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); |
122 | } else if (!strcmp(name, "include")) |
122 | } else if (!strcmp(name, "include")) |
123 | parse_configfile(value, config_cb); |
123 | parse_configfile(value, config_cb); |
124 | } |
124 | } |
125 | |
125 | |
126 | static void querystring_cb(const char *name, const char *value) |
126 | static void querystring_cb(const char *name, const char *value) |
127 | { |
127 | { |
128 | if (!strcmp(name,"r")) { |
128 | if (!strcmp(name,"r")) { |
129 | ctx.qry.repo = xstrdup(value); |
129 | ctx.qry.repo = xstrdup(value); |
130 | ctx.repo = cgit_get_repoinfo(value); |
130 | ctx.repo = cgit_get_repoinfo(value); |
131 | } else if (!strcmp(name, "p")) { |
131 | } else if (!strcmp(name, "p")) { |
132 | ctx.qry.page = xstrdup(value); |
132 | ctx.qry.page = xstrdup(value); |
133 | } else if (!strcmp(name, "url")) { |
133 | } else if (!strcmp(name, "url")) { |
134 | ctx.qry.url = xstrdup(value); |
134 | ctx.qry.url = xstrdup(value); |
135 | cgit_parse_url(value); |
135 | cgit_parse_url(value); |
136 | } else if (!strcmp(name, "qt")) { |
136 | } else if (!strcmp(name, "qt")) { |
137 | ctx.qry.grep = xstrdup(value); |
137 | ctx.qry.grep = xstrdup(value); |
138 | } else if (!strcmp(name, "q")) { |
138 | } else if (!strcmp(name, "q")) { |
139 | ctx.qry.search = xstrdup(value); |
139 | ctx.qry.search = xstrdup(value); |
140 | } else if (!strcmp(name, "h")) { |
140 | } else if (!strcmp(name, "h")) { |
141 | ctx.qry.head = xstrdup(value); |
141 | ctx.qry.head = xstrdup(value); |
142 | ctx.qry.has_symref = 1; |
142 | ctx.qry.has_symref = 1; |
143 | } else if (!strcmp(name, "id")) { |
143 | } else if (!strcmp(name, "id")) { |
144 | ctx.qry.sha1 = xstrdup(value); |
144 | ctx.qry.sha1 = xstrdup(value); |
145 | ctx.qry.has_sha1 = 1; |
145 | ctx.qry.has_sha1 = 1; |
146 | } else if (!strcmp(name, "id2")) { |
146 | } else if (!strcmp(name, "id2")) { |
147 | ctx.qry.sha2 = xstrdup(value); |
147 | ctx.qry.sha2 = xstrdup(value); |
148 | ctx.qry.has_sha1 = 1; |
148 | ctx.qry.has_sha1 = 1; |
149 | } else if (!strcmp(name, "ofs")) { |
149 | } else if (!strcmp(name, "ofs")) { |
150 | ctx.qry.ofs = atoi(value); |
150 | ctx.qry.ofs = atoi(value); |
151 | } else if (!strcmp(name, "path")) { |
151 | } else if (!strcmp(name, "path")) { |
152 | ctx.qry.path = trim_end(value, '/'); |
152 | ctx.qry.path = trim_end(value, '/'); |
153 | } else if (!strcmp(name, "name")) { |
153 | } else if (!strcmp(name, "name")) { |
154 | ctx.qry.name = xstrdup(value); |
154 | ctx.qry.name = xstrdup(value); |
155 | } else if (!strcmp(name, "mimetype")) { |
155 | } else if (!strcmp(name, "mimetype")) { |
156 | ctx.qry.mimetype = xstrdup(value); |
156 | ctx.qry.mimetype = xstrdup(value); |
| |
157 | } else if (!strcmp(name, "s")){ |
| |
158 | ctx.qry.sort = xstrdup(value); |
| |
159 | } else if (!strcmp(name, "showmsg")) { |
| |
160 | ctx.qry.showmsg = atoi(value); |
157 | } |
161 | } |
158 | } |
162 | } |
159 | |
163 | |
160 | static void prepare_context(struct cgit_context *ctx) |
164 | static void prepare_context(struct cgit_context *ctx) |
161 | { |
165 | { |
162 | memset(ctx, 0, sizeof(ctx)); |
166 | memset(ctx, 0, sizeof(ctx)); |
163 | ctx->cfg.agefile = "info/web/last-modified"; |
167 | ctx->cfg.agefile = "info/web/last-modified"; |
164 | ctx->cfg.nocache = 0; |
168 | ctx->cfg.nocache = 0; |
165 | ctx->cfg.cache_size = 0; |
169 | ctx->cfg.cache_size = 0; |
166 | ctx->cfg.cache_dynamic_ttl = 5; |
170 | ctx->cfg.cache_dynamic_ttl = 5; |
167 | ctx->cfg.cache_max_create_time = 5; |
171 | ctx->cfg.cache_max_create_time = 5; |
168 | ctx->cfg.cache_repo_ttl = 5; |
172 | ctx->cfg.cache_repo_ttl = 5; |
169 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
173 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
170 | ctx->cfg.cache_root_ttl = 5; |
174 | ctx->cfg.cache_root_ttl = 5; |
171 | ctx->cfg.cache_static_ttl = -1; |
175 | ctx->cfg.cache_static_ttl = -1; |
172 | ctx->cfg.css = "/cgit.css"; |
176 | ctx->cfg.css = "/cgit.css"; |
173 | ctx->cfg.logo = "/git-logo.png"; |
177 | ctx->cfg.logo = "/git-logo.png"; |
174 | ctx->cfg.local_time = 0; |
178 | ctx->cfg.local_time = 0; |
175 | ctx->cfg.max_repo_count = 50; |
179 | ctx->cfg.max_repo_count = 50; |
176 | ctx->cfg.max_commit_count = 50; |
180 | ctx->cfg.max_commit_count = 50; |
177 | ctx->cfg.max_lock_attempts = 5; |
181 | ctx->cfg.max_lock_attempts = 5; |
178 | ctx->cfg.max_msg_len = 80; |
182 | ctx->cfg.max_msg_len = 80; |
179 | ctx->cfg.max_repodesc_len = 80; |
183 | ctx->cfg.max_repodesc_len = 80; |
180 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
184 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
181 | ctx->cfg.renamelimit = -1; |
185 | ctx->cfg.renamelimit = -1; |
182 | ctx->cfg.robots = "index, nofollow"; |
186 | ctx->cfg.robots = "index, nofollow"; |
183 | ctx->cfg.root_title = "Git repository browser"; |
187 | ctx->cfg.root_title = "Git repository browser"; |
184 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
188 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
185 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
189 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
186 | ctx->cfg.summary_branches = 10; |
190 | ctx->cfg.summary_branches = 10; |
187 | ctx->cfg.summary_log = 10; |
191 | ctx->cfg.summary_log = 10; |
188 | ctx->cfg.summary_tags = 10; |
192 | ctx->cfg.summary_tags = 10; |
189 | ctx->page.mimetype = "text/html"; |
193 | ctx->page.mimetype = "text/html"; |
190 | ctx->page.charset = PAGE_ENCODING; |
194 | ctx->page.charset = PAGE_ENCODING; |
191 | ctx->page.filename = NULL; |
195 | ctx->page.filename = NULL; |
192 | ctx->page.size = 0; |
196 | ctx->page.size = 0; |
193 | ctx->page.modified = time(NULL); |
197 | ctx->page.modified = time(NULL); |
194 | ctx->page.expires = ctx->page.modified; |
198 | ctx->page.expires = ctx->page.modified; |
195 | } |
199 | } |
196 | |
200 | |
197 | struct refmatch { |
201 | struct refmatch { |
198 | char *req_ref; |
202 | char *req_ref; |
199 | char *first_ref; |
203 | char *first_ref; |
200 | int match; |
204 | int match; |
201 | }; |
205 | }; |
202 | |
206 | |
203 | int find_current_ref(const char *refname, const unsigned char *sha1, |
207 | int find_current_ref(const char *refname, const unsigned char *sha1, |
204 | int flags, void *cb_data) |
208 | int flags, void *cb_data) |
@@ -389,83 +393,84 @@ static void cgit_parse_args(int argc, const char **argv) |
389 | } |
393 | } |
390 | if (scan) { |
394 | if (scan) { |
391 | qsort(cgit_repolist.repos, cgit_repolist.count, |
395 | qsort(cgit_repolist.repos, cgit_repolist.count, |
392 | sizeof(struct cgit_repo), cmp_repos); |
396 | sizeof(struct cgit_repo), cmp_repos); |
393 | print_repolist(&cgit_repolist); |
397 | print_repolist(&cgit_repolist); |
394 | exit(0); |
398 | exit(0); |
395 | } |
399 | } |
396 | } |
400 | } |
397 | |
401 | |
398 | static int calc_ttl() |
402 | static int calc_ttl() |
399 | { |
403 | { |
400 | if (!ctx.repo) |
404 | if (!ctx.repo) |
401 | return ctx.cfg.cache_root_ttl; |
405 | return ctx.cfg.cache_root_ttl; |
402 | |
406 | |
403 | if (!ctx.qry.page) |
407 | if (!ctx.qry.page) |
404 | return ctx.cfg.cache_repo_ttl; |
408 | return ctx.cfg.cache_repo_ttl; |
405 | |
409 | |
406 | if (ctx.qry.has_symref) |
410 | if (ctx.qry.has_symref) |
407 | return ctx.cfg.cache_dynamic_ttl; |
411 | return ctx.cfg.cache_dynamic_ttl; |
408 | |
412 | |
409 | if (ctx.qry.has_sha1) |
413 | if (ctx.qry.has_sha1) |
410 | return ctx.cfg.cache_static_ttl; |
414 | return ctx.cfg.cache_static_ttl; |
411 | |
415 | |
412 | return ctx.cfg.cache_repo_ttl; |
416 | return ctx.cfg.cache_repo_ttl; |
413 | } |
417 | } |
414 | |
418 | |
415 | int main(int argc, const char **argv) |
419 | int main(int argc, const char **argv) |
416 | { |
420 | { |
417 | const char *cgit_config_env = getenv("CGIT_CONFIG"); |
421 | const char *cgit_config_env = getenv("CGIT_CONFIG"); |
418 | const char *path; |
422 | const char *path; |
419 | char *qry; |
423 | char *qry; |
420 | int err, ttl; |
424 | int err, ttl; |
421 | |
425 | |
422 | prepare_context(&ctx); |
426 | prepare_context(&ctx); |
423 | cgit_repolist.length = 0; |
427 | cgit_repolist.length = 0; |
424 | cgit_repolist.count = 0; |
428 | cgit_repolist.count = 0; |
425 | cgit_repolist.repos = NULL; |
429 | cgit_repolist.repos = NULL; |
426 | |
430 | |
427 | if (getenv("SCRIPT_NAME")) |
431 | if (getenv("SCRIPT_NAME")) |
428 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
432 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
429 | if (getenv("QUERY_STRING")) |
433 | if (getenv("QUERY_STRING")) |
430 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
434 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
431 | cgit_parse_args(argc, argv); |
435 | cgit_parse_args(argc, argv); |
432 | parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
436 | parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
433 | config_cb); |
437 | config_cb); |
434 | ctx.repo = NULL; |
438 | ctx.repo = NULL; |
435 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
439 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
436 | |
440 | |
437 | /* If virtual-root isn't specified in cgitrc and no url |
441 | /* If virtual-root isn't specified in cgitrc, lets pretend |
438 | * parameter is specified on the querystring, lets pretend |
442 | * that virtual-root equals SCRIPT_NAME. |
439 | * that virtualroot equals SCRIPT_NAME and use PATH_INFO as |
| |
440 | * url. This allows cgit to work with virtual urls without |
| |
441 | * the need for rewriterules in the webserver (as long as |
| |
442 | * PATH_INFO is included in the cache lookup key). |
| |
443 | */ |
443 | */ |
444 | if (!ctx.cfg.virtual_root && !ctx.qry.url) { |
444 | if (!ctx.cfg.virtual_root) |
445 | ctx.cfg.virtual_root = ctx.cfg.script_name; |
445 | ctx.cfg.virtual_root = ctx.cfg.script_name; |
446 | path = getenv("PATH_INFO"); |
446 | |
447 | if (path) { |
447 | /* If no url parameter is specified on the querystring, lets |
448 | if (path[0] == '/') |
448 | * use PATH_INFO as url. This allows cgit to work with virtual |
449 | path++; |
449 | * urls without the need for rewriterules in the webserver (as |
450 | ctx.qry.url = xstrdup(path); |
450 | * long as PATH_INFO is included in the cache lookup key). |
451 | if (ctx.qry.raw) { |
451 | */ |
452 | qry = ctx.qry.raw; |
452 | path = getenv("PATH_INFO"); |
453 | ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); |
453 | if (!ctx.qry.url && path) { |
454 | free(qry); |
454 | if (path[0] == '/') |
455 | } else |
455 | path++; |
456 | ctx.qry.raw = ctx.qry.url; |
456 | ctx.qry.url = xstrdup(path); |
457 | cgit_parse_url(ctx.qry.url); |
457 | if (ctx.qry.raw) { |
458 | } |
458 | qry = ctx.qry.raw; |
| |
459 | ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); |
| |
460 | free(qry); |
| |
461 | } else |
| |
462 | ctx.qry.raw = ctx.qry.url; |
| |
463 | cgit_parse_url(ctx.qry.url); |
459 | } |
464 | } |
460 | |
465 | |
461 | ttl = calc_ttl(); |
466 | ttl = calc_ttl(); |
462 | ctx.page.expires += ttl*60; |
467 | ctx.page.expires += ttl*60; |
463 | if (ctx.cfg.nocache) |
468 | if (ctx.cfg.nocache) |
464 | ctx.cfg.cache_size = 0; |
469 | ctx.cfg.cache_size = 0; |
465 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, |
470 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, |
466 | ctx.qry.raw, ttl, process_request, &ctx); |
471 | ctx.qry.raw, ttl, process_request, &ctx); |
467 | if (err) |
472 | if (err) |
468 | cgit_print_error(fmt("Error processing page: %s (%d)", |
473 | cgit_print_error(fmt("Error processing page: %s (%d)", |
469 | strerror(err), err)); |
474 | strerror(err), err)); |
470 | return err; |
475 | return err; |
471 | } |
476 | } |
|