|
diff --git a/cgit.c b/cgit.c index 9305d0a..37154e3 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -143,17 +143,17 @@ void config_cb(const char *name, const char *value) |
143 | ctx.cfg.enable_remote_branches = atoi(value); |
143 | ctx.cfg.enable_remote_branches = atoi(value); |
144 | else if (!strcmp(name, "enable-tree-linenumbers")) |
144 | else if (!strcmp(name, "enable-tree-linenumbers")) |
145 | ctx.cfg.enable_tree_linenumbers = atoi(value); |
145 | ctx.cfg.enable_tree_linenumbers = atoi(value); |
146 | else if (!strcmp(name, "max-stats")) |
146 | else if (!strcmp(name, "max-stats")) |
147 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
147 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
148 | else if (!strcmp(name, "cache-size")) |
148 | else if (!strcmp(name, "cache-size")) |
149 | ctx.cfg.cache_size = atoi(value); |
149 | ctx.cfg.cache_size = atoi(value); |
150 | else if (!strcmp(name, "cache-root")) |
150 | else if (!strcmp(name, "cache-root")) |
151 | ctx.cfg.cache_root = xstrdup(value); |
151 | ctx.cfg.cache_root = xstrdup(expand_macros(value)); |
152 | else if (!strcmp(name, "cache-root-ttl")) |
152 | else if (!strcmp(name, "cache-root-ttl")) |
153 | ctx.cfg.cache_root_ttl = atoi(value); |
153 | ctx.cfg.cache_root_ttl = atoi(value); |
154 | else if (!strcmp(name, "cache-repo-ttl")) |
154 | else if (!strcmp(name, "cache-repo-ttl")) |
155 | ctx.cfg.cache_repo_ttl = atoi(value); |
155 | ctx.cfg.cache_repo_ttl = atoi(value); |
156 | else if (!strcmp(name, "cache-scanrc-ttl")) |
156 | else if (!strcmp(name, "cache-scanrc-ttl")) |
157 | ctx.cfg.cache_scanrc_ttl = atoi(value); |
157 | ctx.cfg.cache_scanrc_ttl = atoi(value); |
158 | else if (!strcmp(name, "cache-static-ttl")) |
158 | else if (!strcmp(name, "cache-static-ttl")) |
159 | ctx.cfg.cache_static_ttl = atoi(value); |
159 | ctx.cfg.cache_static_ttl = atoi(value); |
@@ -172,19 +172,19 @@ void config_cb(const char *name, const char *value) |
172 | else if (!strcmp(name, "max-blob-size")) |
172 | else if (!strcmp(name, "max-blob-size")) |
173 | ctx.cfg.max_blob_size = atoi(value); |
173 | ctx.cfg.max_blob_size = atoi(value); |
174 | else if (!strcmp(name, "max-repo-count")) |
174 | else if (!strcmp(name, "max-repo-count")) |
175 | ctx.cfg.max_repo_count = atoi(value); |
175 | ctx.cfg.max_repo_count = atoi(value); |
176 | else if (!strcmp(name, "max-commit-count")) |
176 | else if (!strcmp(name, "max-commit-count")) |
177 | ctx.cfg.max_commit_count = atoi(value); |
177 | ctx.cfg.max_commit_count = atoi(value); |
178 | else if (!strcmp(name, "scan-path")) |
178 | else if (!strcmp(name, "scan-path")) |
179 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) |
179 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) |
180 | process_cached_repolist(value); |
180 | process_cached_repolist(expand_macros(value)); |
181 | else |
181 | else |
182 | scan_tree(value, repo_config); |
182 | scan_tree(expand_macros(value), repo_config); |
183 | else if (!strcmp(name, "source-filter")) |
183 | else if (!strcmp(name, "source-filter")) |
184 | ctx.cfg.source_filter = new_filter(value, 1); |
184 | ctx.cfg.source_filter = new_filter(value, 1); |
185 | else if (!strcmp(name, "summary-log")) |
185 | else if (!strcmp(name, "summary-log")) |
186 | ctx.cfg.summary_log = atoi(value); |
186 | ctx.cfg.summary_log = atoi(value); |
187 | else if (!strcmp(name, "summary-branches")) |
187 | else if (!strcmp(name, "summary-branches")) |
188 | ctx.cfg.summary_branches = atoi(value); |
188 | ctx.cfg.summary_branches = atoi(value); |
189 | else if (!strcmp(name, "summary-tags")) |
189 | else if (!strcmp(name, "summary-tags")) |
190 | ctx.cfg.summary_tags = atoi(value); |
190 | ctx.cfg.summary_tags = atoi(value); |
@@ -198,17 +198,17 @@ void config_cb(const char *name, const char *value) |
198 | ctx.cfg.robots = xstrdup(value); |
198 | ctx.cfg.robots = xstrdup(value); |
199 | else if (!strcmp(name, "clone-prefix")) |
199 | else if (!strcmp(name, "clone-prefix")) |
200 | ctx.cfg.clone_prefix = xstrdup(value); |
200 | ctx.cfg.clone_prefix = xstrdup(value); |
201 | else if (!strcmp(name, "local-time")) |
201 | else if (!strcmp(name, "local-time")) |
202 | ctx.cfg.local_time = atoi(value); |
202 | ctx.cfg.local_time = atoi(value); |
203 | else if (!prefixcmp(name, "mimetype.")) |
203 | else if (!prefixcmp(name, "mimetype.")) |
204 | add_mimetype(name + 9, value); |
204 | add_mimetype(name + 9, value); |
205 | else if (!strcmp(name, "include")) |
205 | else if (!strcmp(name, "include")) |
206 | parse_configfile(value, config_cb); |
206 | parse_configfile(expand_macros(value), config_cb); |
207 | } |
207 | } |
208 | |
208 | |
209 | static void querystring_cb(const char *name, const char *value) |
209 | static void querystring_cb(const char *name, const char *value) |
210 | { |
210 | { |
211 | if (!value) |
211 | if (!value) |
212 | value = ""; |
212 | value = ""; |
213 | |
213 | |
214 | if (!strcmp(name,"r")) { |
214 | if (!strcmp(name,"r")) { |
@@ -683,17 +683,17 @@ int main(int argc, const char **argv) |
683 | int err, ttl; |
683 | int err, ttl; |
684 | |
684 | |
685 | prepare_context(&ctx); |
685 | prepare_context(&ctx); |
686 | cgit_repolist.length = 0; |
686 | cgit_repolist.length = 0; |
687 | cgit_repolist.count = 0; |
687 | cgit_repolist.count = 0; |
688 | cgit_repolist.repos = NULL; |
688 | cgit_repolist.repos = NULL; |
689 | |
689 | |
690 | cgit_parse_args(argc, argv); |
690 | cgit_parse_args(argc, argv); |
691 | parse_configfile(ctx.env.cgit_config, config_cb); |
691 | parse_configfile(expand_macros(ctx.env.cgit_config), config_cb); |
692 | ctx.repo = NULL; |
692 | ctx.repo = NULL; |
693 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
693 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
694 | |
694 | |
695 | /* If virtual-root isn't specified in cgitrc, lets pretend |
695 | /* If virtual-root isn't specified in cgitrc, lets pretend |
696 | * that virtual-root equals SCRIPT_NAME. |
696 | * that virtual-root equals SCRIPT_NAME. |
697 | */ |
697 | */ |
698 | if (!ctx.cfg.virtual_root) |
698 | if (!ctx.cfg.virtual_root) |
699 | ctx.cfg.virtual_root = ctx.cfg.script_name; |
699 | ctx.cfg.virtual_root = ctx.cfg.script_name; |
|
|
diff --git a/cgit.h b/cgit.h index cd4af72..568e0c0 100644 --- a/ cgit.h+++ b/ cgit.h |
|
@@ -291,9 +291,11 @@ extern const char *cgit_repobasename(const char *reponame); |
291 | |
291 | |
292 | extern int cgit_parse_snapshots_mask(const char *str); |
292 | extern int cgit_parse_snapshots_mask(const char *str); |
293 | |
293 | |
294 | extern int cgit_open_filter(struct cgit_filter *filter); |
294 | extern int cgit_open_filter(struct cgit_filter *filter); |
295 | extern int cgit_close_filter(struct cgit_filter *filter); |
295 | extern int cgit_close_filter(struct cgit_filter *filter); |
296 | |
296 | |
297 | extern int readfile(const char *path, char **buf, size_t *size); |
297 | extern int readfile(const char *path, char **buf, size_t *size); |
298 | |
298 | |
| |
299 | extern char *expand_macros(const char *txt); |
| |
300 | |
299 | #endif /* CGIT_H */ |
301 | #endif /* CGIT_H */ |
|
|
diff --git a/shared.c b/shared.c index 5f46793..76d26dd 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -418,8 +418,79 @@ int readfile(const char *path, char **buf, size_t *size) |
418 | } |
418 | } |
419 | *buf = xmalloc(st.st_size + 1); |
419 | *buf = xmalloc(st.st_size + 1); |
420 | *size = read_in_full(fd, *buf, st.st_size); |
420 | *size = read_in_full(fd, *buf, st.st_size); |
421 | e = errno; |
421 | e = errno; |
422 | (*buf)[*size] = '\0'; |
422 | (*buf)[*size] = '\0'; |
423 | close(fd); |
423 | close(fd); |
424 | return (*size == st.st_size ? 0 : e); |
424 | return (*size == st.st_size ? 0 : e); |
425 | } |
425 | } |
| |
426 | |
| |
427 | int is_token_char(char c) |
| |
428 | { |
| |
429 | return isalnum(c) || c == '_'; |
| |
430 | } |
| |
431 | |
| |
432 | /* Replace name with getenv(name), return pointer to zero-terminating char |
| |
433 | */ |
| |
434 | char *expand_macro(char *name, int maxlength) |
| |
435 | { |
| |
436 | char *value; |
| |
437 | int len; |
| |
438 | |
| |
439 | len = 0; |
| |
440 | value = getenv(name); |
| |
441 | if (value) { |
| |
442 | len = strlen(value); |
| |
443 | if (len > maxlength) |
| |
444 | len = maxlength; |
| |
445 | strncpy(name, value, len); |
| |
446 | } |
| |
447 | return name + len; |
| |
448 | } |
| |
449 | |
| |
450 | #define EXPBUFSIZE (1024 * 8) |
| |
451 | |
| |
452 | /* Replace all tokens prefixed by '$' in the specified text with the |
| |
453 | * value of the named environment variable. |
| |
454 | * NB: the return value is a static buffer, i.e. it must be strdup'd |
| |
455 | * by the caller. |
| |
456 | */ |
| |
457 | char *expand_macros(const char *txt) |
| |
458 | { |
| |
459 | static char result[EXPBUFSIZE]; |
| |
460 | char *p, *start; |
| |
461 | int len; |
| |
462 | |
| |
463 | p = result; |
| |
464 | start = NULL; |
| |
465 | while (p < result + EXPBUFSIZE - 1 && txt && *txt) { |
| |
466 | *p = *txt; |
| |
467 | if (start) { |
| |
468 | if (!is_token_char(*txt)) { |
| |
469 | if (p - start > 0) { |
| |
470 | *p = '\0'; |
| |
471 | len = result + EXPBUFSIZE - start - 1; |
| |
472 | p = expand_macro(start, len) - 1; |
| |
473 | } |
| |
474 | start = NULL; |
| |
475 | txt--; |
| |
476 | } |
| |
477 | p++; |
| |
478 | txt++; |
| |
479 | continue; |
| |
480 | } |
| |
481 | if (*txt == '$') { |
| |
482 | start = p; |
| |
483 | txt++; |
| |
484 | continue; |
| |
485 | } |
| |
486 | p++; |
| |
487 | txt++; |
| |
488 | } |
| |
489 | *p = '\0'; |
| |
490 | if (start && p - start > 0) { |
| |
491 | len = result + EXPBUFSIZE - start - 1; |
| |
492 | p = expand_macro(start, len); |
| |
493 | *p = '\0'; |
| |
494 | } |
| |
495 | return result; |
| |
496 | } |
|