diff options
| author | 2008-02-16 21:07:13 (JST) | |
|---|---|---|
| committer | 2008-02-16 21:10:50 (JST) | |
| commit | b228d4ff82a65fdcd4a7364759fe36a0bdda5978 (patch) | |
| tree | 33b8cc2ff48113f8d7ad3ba88c7ea19a7cac570a | |
| parent | d14d77fe95c3b6224b40df9b101dded0deea913c (diff) | |
| download | cgit-b228d4ff82a65fdcd4a7364759fe36a0bdda5978.zip cgit-b228d4ff82a65fdcd4a7364759fe36a0bdda5978.tar.gz | |
Add all config variables into struct cgit_context
This removes another big set of global variables, and introduces the
cgit_prepare_context() function which populates a context-variable with
compile-time default values.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
| -rw-r--r-- | cache.c | 10 | ||||
| -rw-r--r-- | cgit.c | 33 | ||||
| -rw-r--r-- | cgit.h | 72 | ||||
| -rw-r--r-- | shared.c | 138 | ||||
| -rw-r--r-- | ui-repolist.c | 18 | ||||
| -rw-r--r-- | ui-shared.c | 60 | ||||
| -rw-r--r-- | ui-summary.c | 10 |
7 files changed, 166 insertions, 175 deletions
| @@ -44,21 +44,21 @@ int cache_create_dirs() | |||
| 44 | { | 44 | { |
| 45 | char *path; | 45 | char *path; |
| 46 | 46 | ||
| 47 | path = fmt("%s", cgit_cache_root); | 47 | path = fmt("%s", ctx.cfg.cache_root); |
| 48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
| 49 | return 0; | 49 | return 0; |
| 50 | 50 | ||
| 51 | if (!cgit_repo) | 51 | if (!cgit_repo) |
| 52 | return 0; | 52 | return 0; |
| 53 | 53 | ||
| 54 | path = fmt("%s/%s", cgit_cache_root, | 54 | path = fmt("%s/%s", ctx.cfg.cache_root, |
| 55 | cache_safe_filename(cgit_repo->url)); | 55 | cache_safe_filename(cgit_repo->url)); |
| 56 | 56 | ||
| 57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
| 58 | return 0; | 58 | return 0; |
| 59 | 59 | ||
| 60 | if (ctx.qry.page) { | 60 | if (ctx.qry.page) { |
| 61 | path = fmt("%s/%s/%s", cgit_cache_root, | 61 | path = fmt("%s/%s/%s", ctx.cfg.cache_root, |
| 62 | cache_safe_filename(cgit_repo->url), | 62 | cache_safe_filename(cgit_repo->url), |
| 63 | ctx.qry.page); | 63 | ctx.qry.page); |
| 64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
| @@ -74,7 +74,7 @@ int cache_refill_overdue(const char *lockfile) | |||
| 74 | if (stat(lockfile, &st)) | 74 | if (stat(lockfile, &st)) |
| 75 | return 0; | 75 | return 0; |
| 76 | else | 76 | else |
| 77 | return (time(NULL) - st.st_mtime > cgit_cache_max_create_time); | 77 | return (time(NULL) - st.st_mtime > ctx.cfg.cache_max_create_time); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | int cache_lock(struct cacheitem *item) | 80 | int cache_lock(struct cacheitem *item) |
| @@ -83,7 +83,7 @@ int cache_lock(struct cacheitem *item) | |||
| 83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); | 83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); |
| 84 | 84 | ||
| 85 | top: | 85 | top: |
| 86 | if (++i > cgit_max_lock_attempts) | 86 | if (++i > ctx.cfg.max_lock_attempts) |
| 87 | die("cache_lock: unable to lock %s: %s", | 87 | die("cache_lock: unable to lock %s: %s", |
| 88 | item->name, strerror(errno)); | 88 | item->name, strerror(errno)); |
| 89 | 89 | ||
| @@ -11,7 +11,7 @@ | |||
| 11 | static int cgit_prepare_cache(struct cacheitem *item) | 11 | static int cgit_prepare_cache(struct cacheitem *item) |
| 12 | { | 12 | { |
| 13 | if (!cgit_repo && ctx.qry.repo) { | 13 | if (!cgit_repo && ctx.qry.repo) { |
| 14 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 14 | char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); |
| 15 | cgit_print_docstart(title, item); | 15 | cgit_print_docstart(title, item); |
| 16 | cgit_print_pageheader(title, 0); | 16 | cgit_print_pageheader(title, 0); |
| 17 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); | 17 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); |
| @@ -20,27 +20,27 @@ static int cgit_prepare_cache(struct cacheitem *item) | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | if (!cgit_repo) { | 22 | if (!cgit_repo) { |
| 23 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | 23 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); |
| 24 | item->ttl = cgit_cache_root_ttl; | 24 | item->ttl = ctx.cfg.cache_root_ttl; |
| 25 | return 1; | 25 | return 1; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | if (!cgit_cmd) { | 28 | if (!cgit_cmd) { |
| 29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", cgit_cache_root, | 29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, |
| 30 | cache_safe_filename(cgit_repo->url), | 30 | cache_safe_filename(cgit_repo->url), |
| 31 | cache_safe_filename(ctx.qry.raw))); | 31 | cache_safe_filename(ctx.qry.raw))); |
| 32 | item->ttl = cgit_cache_repo_ttl; | 32 | item->ttl = ctx.cfg.cache_repo_ttl; |
| 33 | } else { | 33 | } else { |
| 34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, |
| 35 | cache_safe_filename(cgit_repo->url), | 35 | cache_safe_filename(cgit_repo->url), |
| 36 | ctx.qry.page, | 36 | ctx.qry.page, |
| 37 | cache_safe_filename(ctx.qry.raw))); | 37 | cache_safe_filename(ctx.qry.raw))); |
| 38 | if (ctx.qry.has_symref) | 38 | if (ctx.qry.has_symref) |
| 39 | item->ttl = cgit_cache_dynamic_ttl; | 39 | item->ttl = ctx.cfg.cache_dynamic_ttl; |
| 40 | else if (ctx.qry.has_sha1) | 40 | else if (ctx.qry.has_sha1) |
| 41 | item->ttl = cgit_cache_static_ttl; | 41 | item->ttl = ctx.cfg.cache_static_ttl; |
| 42 | else | 42 | else |
| 43 | item->ttl = cgit_cache_repo_ttl; | 43 | item->ttl = ctx.cfg.cache_repo_ttl; |
| 44 | } | 44 | } |
| 45 | return 1; | 45 | return 1; |
| 46 | } | 46 | } |
| @@ -85,7 +85,7 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
| 85 | unsigned char sha1[20]; | 85 | unsigned char sha1[20]; |
| 86 | 86 | ||
| 87 | if (chdir(cgit_repo->path)) { | 87 | if (chdir(cgit_repo->path)) { |
| 88 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 88 | title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); |
| 89 | cgit_print_docstart(title, item); | 89 | cgit_print_docstart(title, item); |
| 90 | cgit_print_pageheader(title, 0); | 90 | cgit_print_pageheader(title, 0); |
| 91 | cgit_print_error(fmt("Unable to scan repository: %s", | 91 | cgit_print_error(fmt("Unable to scan repository: %s", |
| @@ -153,7 +153,7 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
| 153 | switch(cgit_cmd) { | 153 | switch(cgit_cmd) { |
| 154 | case CMD_LOG: | 154 | case CMD_LOG: |
| 155 | cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, | 155 | cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, |
| 156 | cgit_max_commit_count, ctx.qry.grep, ctx.qry.search, | 156 | ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, |
| 157 | ctx.qry.path, 1); | 157 | ctx.qry.path, 1); |
| 158 | break; | 158 | break; |
| 159 | case CMD_TREE: | 159 | case CMD_TREE: |
| @@ -212,7 +212,7 @@ static void cgit_check_cache(struct cacheitem *item) | |||
| 212 | int i = 0; | 212 | int i = 0; |
| 213 | 213 | ||
| 214 | top: | 214 | top: |
| 215 | if (++i > cgit_max_lock_attempts) { | 215 | if (++i > ctx.cfg.max_lock_attempts) { |
| 216 | die("cgit_refresh_cache: unable to lock %s: %s", | 216 | die("cgit_refresh_cache: unable to lock %s: %s", |
| 217 | item->name, strerror(errno)); | 217 | item->name, strerror(errno)); |
| 218 | } | 218 | } |
| @@ -258,10 +258,10 @@ static void cgit_parse_args(int argc, const char **argv) | |||
| 258 | 258 | ||
| 259 | for (i = 1; i < argc; i++) { | 259 | for (i = 1; i < argc; i++) { |
| 260 | if (!strncmp(argv[i], "--cache=", 8)) { | 260 | if (!strncmp(argv[i], "--cache=", 8)) { |
| 261 | cgit_cache_root = xstrdup(argv[i]+8); | 261 | ctx.cfg.cache_root = xstrdup(argv[i]+8); |
| 262 | } | 262 | } |
| 263 | if (!strcmp(argv[i], "--nocache")) { | 263 | if (!strcmp(argv[i], "--nocache")) { |
| 264 | cgit_nocache = 1; | 264 | ctx.cfg.nocache = 1; |
| 265 | } | 265 | } |
| 266 | if (!strncmp(argv[i], "--query=", 8)) { | 266 | if (!strncmp(argv[i], "--query=", 8)) { |
| 267 | ctx.qry.raw = xstrdup(argv[i]+8); | 267 | ctx.qry.raw = xstrdup(argv[i]+8); |
| @@ -291,6 +291,7 @@ int main(int argc, const char **argv) | |||
| 291 | struct cacheitem item; | 291 | struct cacheitem item; |
| 292 | const char *cgit_config_env = getenv("CGIT_CONFIG"); | 292 | const char *cgit_config_env = getenv("CGIT_CONFIG"); |
| 293 | 293 | ||
| 294 | cgit_prepare_context(&ctx); | ||
| 294 | htmlfd = STDOUT_FILENO; | 295 | htmlfd = STDOUT_FILENO; |
| 295 | item.st.st_mtime = time(NULL); | 296 | item.st.st_mtime = time(NULL); |
| 296 | cgit_repolist.length = 0; | 297 | cgit_repolist.length = 0; |
| @@ -301,14 +302,14 @@ int main(int argc, const char **argv) | |||
| 301 | cgit_global_config_cb); | 302 | cgit_global_config_cb); |
| 302 | cgit_repo = NULL; | 303 | cgit_repo = NULL; |
| 303 | if (getenv("SCRIPT_NAME")) | 304 | if (getenv("SCRIPT_NAME")) |
| 304 | cgit_script_name = xstrdup(getenv("SCRIPT_NAME")); | 305 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
| 305 | if (getenv("QUERY_STRING")) | 306 | if (getenv("QUERY_STRING")) |
| 306 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); | 307 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
| 307 | cgit_parse_args(argc, argv); | 308 | cgit_parse_args(argc, argv); |
| 308 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); | 309 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); |
| 309 | if (!cgit_prepare_cache(&item)) | 310 | if (!cgit_prepare_cache(&item)) |
| 310 | return 0; | 311 | return 0; |
| 311 | if (cgit_nocache) { | 312 | if (ctx.cfg.nocache) { |
| 312 | cgit_fill_cache(&item, 0); | 313 | cgit_fill_cache(&item, 0); |
| 313 | } else { | 314 | } else { |
| 314 | cgit_check_cache(&item); | 315 | cgit_check_cache(&item); |
| @@ -139,8 +139,44 @@ struct cgit_query { | |||
| 139 | int ofs; | 139 | int ofs; |
| 140 | }; | 140 | }; |
| 141 | 141 | ||
| 142 | struct cgit_config { | ||
| 143 | char *agefile; | ||
| 144 | char *cache_root; | ||
| 145 | char *clone_prefix; | ||
| 146 | char *css; | ||
| 147 | char *index_header; | ||
| 148 | char *index_info; | ||
| 149 | char *logo; | ||
| 150 | char *logo_link; | ||
| 151 | char *module_link; | ||
| 152 | char *repo_group; | ||
| 153 | char *robots; | ||
| 154 | char *root_title; | ||
| 155 | char *script_name; | ||
| 156 | char *virtual_root; | ||
| 157 | int cache_dynamic_ttl; | ||
| 158 | int cache_max_create_time; | ||
| 159 | int cache_repo_ttl; | ||
| 160 | int cache_root_ttl; | ||
| 161 | int cache_static_ttl; | ||
| 162 | int enable_index_links; | ||
| 163 | int enable_log_filecount; | ||
