diff options
author | Lars Hjemli <hjemli@gmail.com> | 2008-03-25 01:26:08 (JST) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-03-25 01:26:08 (JST) |
commit | 163037e79c6cde1073d555dbeae2a095298e6101 (patch) | |
tree | 37f36b95772eff04683a7f7efc1c5c369b7bf905 /cgit.c | |
parent | a4d1ca1dc6ff8171694d9e2280b6075a1beced0c (diff) | |
download | cgit-163037e79c6cde1073d555dbeae2a095298e6101.zip cgit-163037e79c6cde1073d555dbeae2a095298e6101.tar.gz |
Move non-generic functions from shared.c to cgit.c
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'cgit.c')
-rw-r--r-- | cgit.c | 156 |
1 files changed, 153 insertions, 3 deletions
@@ -10,6 +10,156 @@ | |||
10 | #include "cmd.h" | 10 | #include "cmd.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | void config_cb(const char *name, const char *value) | ||
14 | { | ||
15 | if (!strcmp(name, "root-title")) | ||
16 | ctx.cfg.root_title = xstrdup(value); | ||
17 | else if (!strcmp(name, "css")) | ||
18 | ctx.cfg.css = xstrdup(value); | ||
19 | else if (!strcmp(name, "logo")) | ||
20 | ctx.cfg.logo = xstrdup(value); | ||
21 | else if (!strcmp(name, "index-header")) | ||
22 | ctx.cfg.index_header = xstrdup(value); | ||
23 | else if (!strcmp(name, "index-info")) | ||
24 | ctx.cfg.index_info = xstrdup(value); | ||
25 | else if (!strcmp(name, "logo-link")) | ||
26 | ctx.cfg.logo_link = xstrdup(value); | ||
27 | else if (!strcmp(name, "module-link")) | ||
28 | ctx.cfg.module_link = xstrdup(value); | ||
29 | else if (!strcmp(name, "virtual-root")) { | ||
30 | ctx.cfg.virtual_root = trim_end(value, '/'); | ||
31 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) | ||
32 | ctx.cfg.virtual_root = ""; | ||
33 | } else if (!strcmp(name, "nocache")) | ||
34 | ctx.cfg.nocache = atoi(value); | ||
35 | else if (!strcmp(name, "snapshots")) | ||
36 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); | ||
37 | else if (!strcmp(name, "enable-index-links")) | ||
38 | ctx.cfg.enable_index_links = atoi(value); | ||
39 | else if (!strcmp(name, "enable-log-filecount")) | ||
40 | ctx.cfg.enable_log_filecount = atoi(value); | ||
41 | else if (!strcmp(name, "enable-log-linecount")) | ||
42 | ctx.cfg.enable_log_linecount = atoi(value); | ||
43 | else if (!strcmp(name, "cache-root")) | ||
44 | ctx.cfg.cache_root = xstrdup(value); | ||
45 | else if (!strcmp(name, "cache-root-ttl")) | ||
46 | ctx.cfg.cache_root_ttl = atoi(value); | ||
47 | else if (!strcmp(name, "cache-repo-ttl")) | ||
48 | ctx.cfg.cache_repo_ttl = atoi(value); | ||
49 | else if (!strcmp(name, "cache-static-ttl")) | ||
50 | ctx.cfg.cache_static_ttl = atoi(value); | ||
51 | else if (!strcmp(name, "cache-dynamic-ttl")) | ||
52 | ctx.cfg.cache_dynamic_ttl = atoi(value); | ||
53 | else if (!strcmp(name, "max-message-length")) | ||
54 | ctx.cfg.max_msg_len = atoi(value); | ||
55 | else if (!strcmp(name, "max-repodesc-length")) | ||
56 | ctx.cfg.max_repodesc_len = atoi(value); | ||
57 | else if (!strcmp(name, "max-commit-count")) | ||
58 | ctx.cfg.max_commit_count = atoi(value); | ||
59 | else if (!strcmp(name, "summary-log")) | ||
60 | ctx.cfg.summary_log = atoi(value); | ||
61 | else if (!strcmp(name, "summary-branches")) | ||
62 | ctx.cfg.summary_branches = atoi(value); | ||
63 | else if (!strcmp(name, "summary-tags")) | ||
64 | ctx.cfg.summary_tags = atoi(value); | ||
65 | else if (!strcmp(name, "agefile")) | ||
66 | ctx.cfg.agefile = xstrdup(value); | ||
67 | else if (!strcmp(name, "renamelimit")) | ||
68 | ctx.cfg.renamelimit = atoi(value); | ||
69 | else if (!strcmp(name, "robots")) | ||
70 | ctx.cfg.robots = xstrdup(value); | ||
71 | else if (!strcmp(name, "clone-prefix")) | ||
72 | ctx.cfg.clone_prefix = xstrdup(value); | ||
73 | else if (!strcmp(name, "repo.group")) | ||
74 | ctx.cfg.repo_group = xstrdup(value); | ||
75 | else if (!strcmp(name, "repo.url")) | ||
76 | ctx.repo = cgit_add_repo(value); | ||
77 | else if (!strcmp(name, "repo.name")) | ||
78 | ctx.repo->name = xstrdup(value); | ||
79 | else if (ctx.repo && !strcmp(name, "repo.path")) | ||
80 | ctx.repo->path = trim_end(value, '/'); | ||
81 | else if (ctx.repo && !strcmp(name, "repo.clone-url")) | ||
82 | ctx.repo->clone_url = xstrdup(value); | ||
83 | else if (ctx.repo && !strcmp(name, "repo.desc")) | ||
84 | ctx.repo->desc = xstrdup(value); | ||
85 | else if (ctx.repo && !strcmp(name, "repo.owner")) | ||
86 | ctx.repo->owner = xstrdup(value); | ||
87 | else if (ctx.repo && !strcmp(name, "repo.defbranch")) | ||
88 | ctx.repo->defbranch = xstrdup(value); | ||
89 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) | ||
90 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ | ||
91 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) | ||
92 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | ||
93 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) | ||
94 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | ||
95 | else if (ctx.repo && !strcmp(name, "repo.module-link")) | ||
96 | ctx.repo->module_link= xstrdup(value); | ||
97 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { | ||
98 | if (*value == '/') | ||
99 | ctx.repo->readme = xstrdup(value); | ||
100 | else | ||
101 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); | ||
102 | } else if (!strcmp(name, "include")) | ||
103 | cgit_read_config(value, config_cb); | ||
104 | } | ||
105 | |||
106 | static void querystring_cb(const char *name, const char *value) | ||
107 | { | ||
108 | if (!strcmp(name,"r")) { | ||
109 | ctx.qry.repo = xstrdup(value); | ||
110 | ctx.repo = cgit_get_repoinfo(value); | ||
111 | } else if (!strcmp(name, "p")) { | ||
112 | ctx.qry.page = xstrdup(value); | ||
113 | } else if (!strcmp(name, "url")) { | ||
114 | cgit_parse_url(value); | ||
115 | } else if (!strcmp(name, "qt")) { | ||
116 | ctx.qry.grep = xstrdup(value); | ||
117 | } else if (!strcmp(name, "q")) { | ||
118 | ctx.qry.search = xstrdup(value); | ||
119 | } else if (!strcmp(name, "h")) { | ||
120 | ctx.qry.head = xstrdup(value); | ||
121 | ctx.qry.has_symref = 1; | ||
122 | } else if (!strcmp(name, "id")) { | ||
123 | ctx.qry.sha1 = xstrdup(value); | ||
124 | ctx.qry.has_sha1 = 1; | ||
125 | } else if (!strcmp(name, "id2")) { | ||
126 | ctx.qry.sha2 = xstrdup(value); | ||
127 | ctx.qry.has_sha1 = 1; | ||
128 | } else if (!strcmp(name, "ofs")) { | ||
129 | ctx.qry.ofs = atoi(value); | ||
130 | } else if (!strcmp(name, "path")) { | ||
131 | ctx.qry.path = trim_end(value, '/'); | ||
132 | } else if (!strcmp(name, "name")) { | ||
133 | ctx.qry.name = xstrdup(value); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | static void prepare_context(struct cgit_context *ctx) | ||
138 | { | ||
139 | memset(ctx, 0, sizeof(ctx)); | ||
140 | ctx->cfg.agefile = "info/web/last-modified"; | ||
141 | ctx->cfg.cache_dynamic_ttl = 5; | ||
142 | ctx->cfg.cache_max_create_time = 5; | ||
143 | ctx->cfg.cache_repo_ttl = 5; | ||
144 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | ||
145 | ctx->cfg.cache_root_ttl = 5; | ||
146 | ctx->cfg.cache_static_ttl = -1; | ||
147 | ctx->cfg.css = "/cgit.css"; | ||
148 | ctx->cfg.logo = "/git-logo.png"; | ||
149 | ctx->cfg.max_commit_count = 50; | ||
150 | ctx->cfg.max_lock_attempts = 5; | ||
151 | ctx->cfg.max_msg_len = 60; | ||
152 | ctx->cfg.max_repodesc_len = 60; | ||
153 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | ||
154 | ctx->cfg.renamelimit = -1; | ||
155 | ctx->cfg.robots = "index, nofollow"; | ||
156 | ctx->cfg.root_title = "Git repository browser"; | ||
157 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | ||
158 | ctx->page.mimetype = "text/html"; | ||
159 | ctx->page.charset = PAGE_ENCODING; | ||
160 | ctx->page.filename = NULL; | ||
161 | } | ||
162 | |||
13 | static int cgit_prepare_cache(struct cacheitem *item) | 163 | static int cgit_prepare_cache(struct cacheitem *item) |
14 | { | 164 | { |
15 | if (!ctx.repo && ctx.qry.repo) { | 165 | if (!ctx.repo && ctx.qry.repo) { |
@@ -277,20 +427,20 @@ int main(int argc, const char **argv) | |||
277 | struct cacheitem item; | 427 | struct cacheitem item; |
278 | const char *cgit_config_env = getenv("CGIT_CONFIG"); | 428 | const char *cgit_config_env = getenv("CGIT_CONFIG"); |
279 | 429 | ||
280 | cgit_prepare_context(&ctx); | 430 | prepare_context(&ctx); |
281 | item.st.st_mtime = time(NULL); | 431 | item.st.st_mtime = time(NULL); |
282 | cgit_repolist.length = 0; | 432 | cgit_repolist.length = 0; |
283 | cgit_repolist.count = 0; | 433 | cgit_repolist.count = 0; |
284 | cgit_repolist.repos = NULL; | 434 | cgit_repolist.repos = NULL; |
285 | 435 | ||
286 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, | 436 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
287 | cgit_global_config_cb); | 437 | config_cb); |
288 | if (getenv("SCRIPT_NAME")) | 438 | if (getenv("SCRIPT_NAME")) |
289 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); | 439 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
290 | if (getenv("QUERY_STRING")) | 440 | if (getenv("QUERY_STRING")) |
291 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); | 441 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
292 | cgit_parse_args(argc, argv); | 442 | cgit_parse_args(argc, argv); |
293 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); | 443 | cgit_parse_query(ctx.qry.raw, querystring_cb); |
294 | if (!cgit_prepare_cache(&item)) | 444 | if (!cgit_prepare_cache(&item)) |
295 | return 0; | 445 | return 0; |
296 | if (ctx.cfg.nocache) { | 446 | if (ctx.cfg.nocache) { |