|
diff --git a/cgit.c b/cgit.c index ad62d10..96900bb 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -1,27 +1,28 @@ |
1 | /* cgit.c: cgi for the git scm |
1 | /* cgit.c: cgi for the git scm |
2 | * |
2 | * |
3 | * Copyright (C) 2006 Lars Hjemli |
3 | * Copyright (C) 2006 Lars Hjemli |
| |
4 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> |
4 | * |
5 | * |
5 | * Licensed under GNU General Public License v2 |
6 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) |
7 | * (see COPYING for full license text) |
7 | */ |
8 | */ |
8 | |
9 | |
9 | #include "cgit.h" |
10 | #include "cgit.h" |
10 | #include "cache.h" |
11 | #include "cache.h" |
11 | #include "cmd.h" |
12 | #include "cmd.h" |
12 | #include "configfile.h" |
13 | #include "configfile.h" |
13 | #include "html.h" |
14 | #include "html.h" |
14 | #include "ui-shared.h" |
15 | #include "ui-shared.h" |
15 | #include "ui-stats.h" |
16 | #include "ui-stats.h" |
16 | #include "scan-tree.h" |
17 | #include "scan-tree.h" |
17 | |
18 | |
18 | const char *cgit_version = CGIT_VERSION; |
19 | const char *cgit_version = CGIT_VERSION; |
19 | |
20 | |
20 | void add_mimetype(const char *name, const char *value) |
21 | void add_mimetype(const char *name, const char *value) |
21 | { |
22 | { |
22 | struct string_list_item *item; |
23 | struct string_list_item *item; |
23 | |
24 | |
24 | item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name)); |
25 | item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name)); |
25 | item->util = xstrdup(value); |
26 | item->util = xstrdup(value); |
26 | } |
27 | } |
27 | |
28 | |
@@ -39,267 +40,307 @@ struct cgit_filter *new_filter(const char *cmd, int extra_args) |
39 | f->argv[1] = NULL; |
40 | f->argv[1] = NULL; |
40 | return f; |
41 | return f; |
41 | } |
42 | } |
42 | |
43 | |
43 | static void process_cached_repolist(const char *path); |
44 | static void process_cached_repolist(const char *path); |
44 | |
45 | |
45 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) |
46 | void repo_config(struct cgit_repo *repo, const char *name, const char *value) |
46 | { |
47 | { |
47 | if (!strcmp(name, "name")) |
48 | if (!strcmp(name, "name")) |
48 | repo->name = xstrdup(value); |
49 | repo->name = xstrdup(value); |
49 | else if (!strcmp(name, "clone-url")) |
50 | else if (!strcmp(name, "clone-url")) |
50 | repo->clone_url = xstrdup(value); |
51 | repo->clone_url = xstrdup(value); |
51 | else if (!strcmp(name, "desc")) |
52 | else if (!strcmp(name, "desc")) |
52 | repo->desc = xstrdup(value); |
53 | repo->desc = xstrdup(value); |
53 | else if (!strcmp(name, "owner")) |
54 | else if (!strcmp(name, "owner")) |
54 | repo->owner = xstrdup(value); |
55 | repo->owner = xstrdup(value); |
55 | else if (!strcmp(name, "defbranch")) |
56 | else if (!strcmp(name, "defbranch")) |
56 | repo->defbranch = xstrdup(value); |
57 | repo->defbranch = xstrdup(value); |
57 | else if (!strcmp(name, "snapshots")) |
58 | else if (!strcmp(name, "snapshots")) |
58 | repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); |
59 | repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); |
59 | else if (!strcmp(name, "enable-log-filecount")) |
60 | else if (!strcmp(name, "enable-log-filecount")) |
60 | repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
61 | repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
61 | else if (!strcmp(name, "enable-log-linecount")) |
62 | else if (!strcmp(name, "enable-log-linecount")) |
62 | repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
63 | repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
| |
64 | else if (!strcmp(name, "enable-remote-branches")) |
| |
65 | repo->enable_remote_branches = atoi(value); |
| |
66 | else if (!strcmp(name, "enable-subject-links")) |
| |
67 | repo->enable_subject_links = atoi(value); |
63 | else if (!strcmp(name, "max-stats")) |
68 | else if (!strcmp(name, "max-stats")) |
64 | repo->max_stats = cgit_find_stats_period(value, NULL); |
69 | repo->max_stats = cgit_find_stats_period(value, NULL); |
65 | else if (!strcmp(name, "module-link")) |
70 | else if (!strcmp(name, "module-link")) |
66 | repo->module_link= xstrdup(value); |
71 | repo->module_link= xstrdup(value); |
67 | else if (!strcmp(name, "section")) |
72 | else if (!strcmp(name, "section")) |
68 | repo->section = xstrdup(value); |
73 | repo->section = xstrdup(value); |
69 | else if (!strcmp(name, "readme") && value != NULL) { |
74 | else if (!strcmp(name, "readme") && value != NULL) { |
70 | if (*value == '/') |
75 | repo->readme = xstrdup(value); |
71 | repo->readme = xstrdup(value); |
| |
72 | else |
| |
73 | repo->readme = xstrdup(fmt("%s/%s", repo->path, value)); |
| |
74 | } else if (ctx.cfg.enable_filter_overrides) { |
76 | } else if (ctx.cfg.enable_filter_overrides) { |
75 | if (!strcmp(name, "about-filter")) |
77 | if (!strcmp(name, "about-filter")) |
76 | repo->about_filter = new_filter(value, 0); |
78 | repo->about_filter = new_filter(value, 0); |
77 | else if (!strcmp(name, "commit-filter")) |
79 | else if (!strcmp(name, "commit-filter")) |
78 | repo->commit_filter = new_filter(value, 0); |
80 | repo->commit_filter = new_filter(value, 0); |
79 | else if (!strcmp(name, "source-filter")) |
81 | else if (!strcmp(name, "source-filter")) |
80 | repo->source_filter = new_filter(value, 1); |
82 | repo->source_filter = new_filter(value, 1); |
81 | } |
83 | } |
82 | } |
84 | } |
83 | |
85 | |
84 | void config_cb(const char *name, const char *value) |
86 | void config_cb(const char *name, const char *value) |
85 | { |
87 | { |
86 | if (!strcmp(name, "section") || !strcmp(name, "repo.group")) |
88 | if (!strcmp(name, "section") || !strcmp(name, "repo.group")) |
87 | ctx.cfg.section = xstrdup(value); |
89 | ctx.cfg.section = xstrdup(value); |
88 | else if (!strcmp(name, "repo.url")) |
90 | else if (!strcmp(name, "repo.url")) |
89 | ctx.repo = cgit_add_repo(value); |
91 | ctx.repo = cgit_add_repo(value); |
90 | else if (ctx.repo && !strcmp(name, "repo.path")) |
92 | else if (ctx.repo && !strcmp(name, "repo.path")) |
91 | ctx.repo->path = trim_end(value, '/'); |
93 | ctx.repo->path = trim_end(value, '/'); |
92 | else if (ctx.repo && !prefixcmp(name, "repo.")) |
94 | else if (ctx.repo && !prefixcmp(name, "repo.")) |
93 | repo_config(ctx.repo, name + 5, value); |
95 | repo_config(ctx.repo, name + 5, value); |
| |
96 | else if (!strcmp(name, "readme")) |
| |
97 | ctx.cfg.readme = xstrdup(value); |
94 | else if (!strcmp(name, "root-title")) |
98 | else if (!strcmp(name, "root-title")) |
95 | ctx.cfg.root_title = xstrdup(value); |
99 | ctx.cfg.root_title = xstrdup(value); |
96 | else if (!strcmp(name, "root-desc")) |
100 | else if (!strcmp(name, "root-desc")) |
97 | ctx.cfg.root_desc = xstrdup(value); |
101 | ctx.cfg.root_desc = xstrdup(value); |
98 | else if (!strcmp(name, "root-readme")) |
102 | else if (!strcmp(name, "root-readme")) |
99 | ctx.cfg.root_readme = xstrdup(value); |
103 | ctx.cfg.root_readme = xstrdup(value); |
100 | else if (!strcmp(name, "css")) |
104 | else if (!strcmp(name, "css")) |
101 | ctx.cfg.css = xstrdup(value); |
105 | ctx.cfg.css = xstrdup(value); |
102 | else if (!strcmp(name, "favicon")) |
106 | else if (!strcmp(name, "favicon")) |
103 | ctx.cfg.favicon = xstrdup(value); |
107 | ctx.cfg.favicon = xstrdup(value); |
104 | else if (!strcmp(name, "footer")) |
108 | else if (!strcmp(name, "footer")) |
105 | ctx.cfg.footer = xstrdup(value); |
109 | ctx.cfg.footer = xstrdup(value); |
106 | else if (!strcmp(name, "head-include")) |
110 | else if (!strcmp(name, "head-include")) |
107 | ctx.cfg.head_include = xstrdup(value); |
111 | ctx.cfg.head_include = xstrdup(value); |
108 | else if (!strcmp(name, "header")) |
112 | else if (!strcmp(name, "header")) |
109 | ctx.cfg.header = xstrdup(value); |
113 | ctx.cfg.header = xstrdup(value); |
110 | else if (!strcmp(name, "logo")) |
114 | else if (!strcmp(name, "logo")) |
111 | ctx.cfg.logo = xstrdup(value); |
115 | ctx.cfg.logo = xstrdup(value); |
112 | else if (!strcmp(name, "index-header")) |
116 | else if (!strcmp(name, "index-header")) |
113 | ctx.cfg.index_header = xstrdup(value); |
117 | ctx.cfg.index_header = xstrdup(value); |
114 | else if (!strcmp(name, "index-info")) |
118 | else if (!strcmp(name, "index-info")) |
115 | ctx.cfg.index_info = xstrdup(value); |
119 | ctx.cfg.index_info = xstrdup(value); |
116 | else if (!strcmp(name, "logo-link")) |
120 | else if (!strcmp(name, "logo-link")) |
117 | ctx.cfg.logo_link = xstrdup(value); |
121 | ctx.cfg.logo_link = xstrdup(value); |
118 | else if (!strcmp(name, "module-link")) |
122 | else if (!strcmp(name, "module-link")) |
119 | ctx.cfg.module_link = xstrdup(value); |
123 | ctx.cfg.module_link = xstrdup(value); |
120 | else if (!strcmp(name, "virtual-root")) { |
124 | else if (!strcmp(name, "virtual-root")) { |
121 | ctx.cfg.virtual_root = trim_end(value, '/'); |
125 | ctx.cfg.virtual_root = trim_end(value, '/'); |
122 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) |
126 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) |
123 | ctx.cfg.virtual_root = ""; |
127 | ctx.cfg.virtual_root = ""; |
124 | } else if (!strcmp(name, "nocache")) |
128 | } else if (!strcmp(name, "nocache")) |
125 | ctx.cfg.nocache = atoi(value); |
129 | ctx.cfg.nocache = atoi(value); |
126 | else if (!strcmp(name, "noplainemail")) |
130 | else if (!strcmp(name, "noplainemail")) |
127 | ctx.cfg.noplainemail = atoi(value); |
131 | ctx.cfg.noplainemail = atoi(value); |
128 | else if (!strcmp(name, "noheader")) |
132 | else if (!strcmp(name, "noheader")) |
129 | ctx.cfg.noheader = atoi(value); |
133 | ctx.cfg.noheader = atoi(value); |
130 | else if (!strcmp(name, "snapshots")) |
134 | else if (!strcmp(name, "snapshots")) |
131 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); |
135 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); |
132 | else if (!strcmp(name, "enable-filter-overrides")) |
136 | else if (!strcmp(name, "enable-filter-overrides")) |
133 | ctx.cfg.enable_filter_overrides = atoi(value); |
137 | ctx.cfg.enable_filter_overrides = atoi(value); |
| |
138 | else if (!strcmp(name, "enable-gitweb-owner")) |
| |
139 | ctx.cfg.enable_gitweb_owner = atoi(value); |
134 | else if (!strcmp(name, "enable-index-links")) |
140 | else if (!strcmp(name, "enable-index-links")) |
135 | ctx.cfg.enable_index_links = atoi(value); |
141 | ctx.cfg.enable_index_links = atoi(value); |
136 | else if (!strcmp(name, "enable-log-filecount")) |
142 | else if (!strcmp(name, "enable-log-filecount")) |
137 | ctx.cfg.enable_log_filecount = atoi(value); |
143 | ctx.cfg.enable_log_filecount = atoi(value); |
138 | else if (!strcmp(name, "enable-log-linecount")) |
144 | else if (!strcmp(name, "enable-log-linecount")) |
139 | ctx.cfg.enable_log_linecount = atoi(value); |
145 | ctx.cfg.enable_log_linecount = atoi(value); |
| |
146 | else if (!strcmp(name, "enable-remote-branches")) |
| |
147 | ctx.cfg.enable_remote_branches = atoi(value); |
| |
148 | else if (!strcmp(name, "enable-subject-links")) |
| |
149 | ctx.cfg.enable_subject_links = atoi(value); |
140 | else if (!strcmp(name, "enable-tree-linenumbers")) |
150 | else if (!strcmp(name, "enable-tree-linenumbers")) |
141 | ctx.cfg.enable_tree_linenumbers = atoi(value); |
151 | ctx.cfg.enable_tree_linenumbers = atoi(value); |
142 | else if (!strcmp(name, "max-stats")) |
152 | else if (!strcmp(name, "max-stats")) |
143 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
153 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
144 | else if (!strcmp(name, "cache-size")) |
154 | else if (!strcmp(name, "cache-size")) |
145 | ctx.cfg.cache_size = atoi(value); |
155 | ctx.cfg.cache_size = atoi(value); |
146 | else if (!strcmp(name, "cache-root")) |
156 | else if (!strcmp(name, "cache-root")) |
147 | ctx.cfg.cache_root = xstrdup(value); |
157 | ctx.cfg.cache_root = xstrdup(expand_macros(value)); |
148 | else if (!strcmp(name, "cache-root-ttl")) |
158 | else if (!strcmp(name, "cache-root-ttl")) |
149 | ctx.cfg.cache_root_ttl = atoi(value); |
159 | ctx.cfg.cache_root_ttl = atoi(value); |
150 | else if (!strcmp(name, "cache-repo-ttl")) |
160 | else if (!strcmp(name, "cache-repo-ttl")) |
151 | ctx.cfg.cache_repo_ttl = atoi(value); |
161 | ctx.cfg.cache_repo_ttl = atoi(value); |
152 | else if (!strcmp(name, "cache-scanrc-ttl")) |
162 | else if (!strcmp(name, "cache-scanrc-ttl")) |
153 | ctx.cfg.cache_scanrc_ttl = atoi(value); |
163 | ctx.cfg.cache_scanrc_ttl = atoi(value); |
154 | else if (!strcmp(name, "cache-static-ttl")) |
164 | else if (!strcmp(name, "cache-static-ttl")) |
155 | ctx.cfg.cache_static_ttl = atoi(value); |
165 | ctx.cfg.cache_static_ttl = atoi(value); |
156 | else if (!strcmp(name, "cache-dynamic-ttl")) |
166 | else if (!strcmp(name, "cache-dynamic-ttl")) |
157 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
167 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
158 | else if (!strcmp(name, "about-filter")) |
168 | else if (!strcmp(name, "about-filter")) |
159 | ctx.cfg.about_filter = new_filter(value, 0); |
169 | ctx.cfg.about_filter = new_filter(value, 0); |
160 | else if (!strcmp(name, "commit-filter")) |
170 | else if (!strcmp(name, "commit-filter")) |
161 | ctx.cfg.commit_filter = new_filter(value, 0); |
171 | ctx.cfg.commit_filter = new_filter(value, 0); |
162 | else if (!strcmp(name, "embedded")) |
172 | else if (!strcmp(name, "embedded")) |
163 | ctx.cfg.embedded = atoi(value); |
173 | ctx.cfg.embedded = atoi(value); |
| |
174 | else if (!strcmp(name, "max-atom-items")) |
| |
175 | ctx.cfg.max_atom_items = atoi(value); |
164 | else if (!strcmp(name, "max-message-length")) |
176 | else if (!strcmp(name, "max-message-length")) |
165 | ctx.cfg.max_msg_len = atoi(value); |
177 | ctx.cfg.max_msg_len = atoi(value); |
166 | else if (!strcmp(name, "max-repodesc-length")) |
178 | else if (!strcmp(name, "max-repodesc-length")) |
167 | ctx.cfg.max_repodesc_len = atoi(value); |
179 | ctx.cfg.max_repodesc_len = atoi(value); |
| |
180 | else if (!strcmp(name, "max-blob-size")) |
| |
181 | ctx.cfg.max_blob_size = atoi(value); |
168 | else if (!strcmp(name, "max-repo-count")) |
182 | else if (!strcmp(name, "max-repo-count")) |
169 | ctx.cfg.max_repo_count = atoi(value); |
183 | ctx.cfg.max_repo_count = atoi(value); |
170 | else if (!strcmp(name, "max-commit-count")) |
184 | else if (!strcmp(name, "max-commit-count")) |
171 | ctx.cfg.max_commit_count = atoi(value); |
185 | ctx.cfg.max_commit_count = atoi(value); |
| |
186 | else if (!strcmp(name, "project-list")) |
| |
187 | ctx.cfg.project_list = xstrdup(expand_macros(value)); |
172 | else if (!strcmp(name, "scan-path")) |
188 | else if (!strcmp(name, "scan-path")) |
173 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) |
189 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) |
174 | process_cached_repolist(value); |
190 | process_cached_repolist(expand_macros(value)); |
| |
191 | else if (ctx.cfg.project_list) |
| |
192 | scan_projects(expand_macros(value), |
| |
193 | ctx.cfg.project_list, repo_config); |
175 | else |
194 | else |
176 | scan_tree(value, repo_config); |
195 | scan_tree(expand_macros(value), repo_config); |
| |
196 | else if (!strcmp(name, "section-from-path")) |
| |
197 | ctx.cfg.section_from_path = atoi(value); |
177 | else if (!strcmp(name, "source-filter")) |
198 | else if (!strcmp(name, "source-filter")) |
178 | ctx.cfg.source_filter = new_filter(value, 1); |
199 | ctx.cfg.source_filter = new_filter(value, 1); |
179 | else if (!strcmp(name, "summary-log")) |
200 | else if (!strcmp(name, "summary-log")) |
180 | ctx.cfg.summary_log = atoi(value); |
201 | ctx.cfg.summary_log = atoi(value); |
181 | else if (!strcmp(name, "summary-branches")) |
202 | else if (!strcmp(name, "summary-branches")) |
182 | ctx.cfg.summary_branches = atoi(value); |
203 | ctx.cfg.summary_branches = atoi(value); |
183 | else if (!strcmp(name, "summary-tags")) |
204 | else if (!strcmp(name, "summary-tags")) |
184 | ctx.cfg.summary_tags = atoi(value); |
205 | ctx.cfg.summary_tags = atoi(value); |
| |
206 | else if (!strcmp(name, "side-by-side-diffs")) |
| |
207 | ctx.cfg.ssdiff = atoi(value); |
185 | else if (!strcmp(name, "agefile")) |
208 | else if (!strcmp(name, "agefile")) |
186 | ctx.cfg.agefile = xstrdup(value); |
209 | ctx.cfg.agefile = xstrdup(value); |
187 | else if (!strcmp(name, "renamelimit")) |
210 | else if (!strcmp(name, "renamelimit")) |
188 | ctx.cfg.renamelimit = atoi(value); |
211 | ctx.cfg.renamelimit = atoi(value); |
| |
212 | else if (!strcmp(name, "remove-suffix")) |
| |
213 | ctx.cfg.remove_suffix = atoi(value); |
189 | else if (!strcmp(name, "robots")) |
214 | else if (!strcmp(name, "robots")) |
190 | ctx.cfg.robots = xstrdup(value); |
215 | ctx.cfg.robots = xstrdup(value); |
191 | else if (!strcmp(name, "clone-prefix")) |
216 | else if (!strcmp(name, "clone-prefix")) |
192 | ctx.cfg.clone_prefix = xstrdup(value); |
217 | ctx.cfg.clone_prefix = xstrdup(value); |
193 | else if (!strcmp(name, "local-time")) |
218 | else if (!strcmp(name, "local-time")) |
194 | ctx.cfg.local_time = atoi(value); |
219 | ctx.cfg.local_time = atoi(value); |
195 | else if (!prefixcmp(name, "mimetype.")) |
220 | else if (!prefixcmp(name, "mimetype.")) |
196 | add_mimetype(name + 9, value); |
221 | add_mimetype(name + 9, value); |
197 | else if (!strcmp(name, "include")) |
222 | else if (!strcmp(name, "include")) |
198 | parse_configfile(value, config_cb); |
223 | parse_configfile(expand_macros(value), config_cb); |
199 | } |
224 | } |
200 | |
225 | |
201 | static void querystring_cb(const char *name, const char *value) |
226 | static void querystring_cb(const char *name, const char *value) |
202 | { |
227 | { |
203 | if (!value) |
228 | if (!value) |
204 | value = ""; |
229 | value = ""; |
205 | |
230 | |
206 | if (!strcmp(name,"r")) { |
231 | if (!strcmp(name,"r")) { |
207 | ctx.qry.repo = xstrdup(value); |
232 | ctx.qry.repo = xstrdup(value); |
208 | ctx.repo = cgit_get_repoinfo(value); |
233 | ctx.repo = cgit_get_repoinfo(value); |
209 | } else if (!strcmp(name, "p")) { |
234 | } else if (!strcmp(name, "p")) { |
210 | ctx.qry.page = xstrdup(value); |
235 | ctx.qry.page = xstrdup(value); |
211 | } else if (!strcmp(name, "url")) { |
236 | } else if (!strcmp(name, "url")) { |
| |
237 | if (*value == '/') |
| |
238 | value++; |
212 | ctx.qry.url = xstrdup(value); |
239 | ctx.qry.url = xstrdup(value); |
213 | cgit_parse_url(value); |
240 | cgit_parse_url(value); |
214 | } else if (!strcmp(name, "qt")) { |
241 | } else if (!strcmp(name, "qt")) { |
215 | ctx.qry.grep = xstrdup(value); |
242 | ctx.qry.grep = xstrdup(value); |
216 | } else if (!strcmp(name, "q")) { |
243 | } else if (!strcmp(name, "q")) { |
217 | ctx.qry.search = xstrdup(value); |
244 | ctx.qry.search = xstrdup(value); |
218 | } else if (!strcmp(name, "h")) { |
245 | } else if (!strcmp(name, "h")) { |
219 | ctx.qry.head = xstrdup(value); |
246 | ctx.qry.head = xstrdup(value); |
220 | ctx.qry.has_symref = 1; |
247 | ctx.qry.has_symref = 1; |
221 | } else if (!strcmp(name, "id")) { |
248 | } else if (!strcmp(name, "id")) { |
222 | ctx.qry.sha1 = xstrdup(value); |
249 | ctx.qry.sha1 = xstrdup(value); |
223 | ctx.qry.has_sha1 = 1; |
250 | ctx.qry.has_sha1 = 1; |
224 | } else if (!strcmp(name, "id2")) { |
251 | } else if (!strcmp(name, "id2")) { |
225 | ctx.qry.sha2 = xstrdup(value); |
252 | ctx.qry.sha2 = xstrdup(value); |
226 | ctx.qry.has_sha1 = 1; |
253 | ctx.qry.has_sha1 = 1; |
227 | } else if (!strcmp(name, "ofs")) { |
254 | } else if (!strcmp(name, "ofs")) { |
228 | ctx.qry.ofs = atoi(value); |
255 | ctx.qry.ofs = atoi(value); |
229 | } else if (!strcmp(name, "path")) { |
256 | } else if (!strcmp(name, "path")) { |
230 | ctx.qry.path = trim_end(value, '/'); |
257 | ctx.qry.path = trim_end(value, '/'); |
231 | } else if (!strcmp(name, "name")) { |
258 | } else if (!strcmp(name, "name")) { |
232 | ctx.qry.name = xstrdup(value); |
259 | ctx.qry.name = xstrdup(value); |
233 | } else if (!strcmp(name, "mimetype")) { |
260 | } else if (!strcmp(name, "mimetype")) { |
234 | ctx.qry.mimetype = xstrdup(value); |
261 | ctx.qry.mimetype = xstrdup(value); |
235 | } else if (!strcmp(name, "s")){ |
262 | } else if (!strcmp(name, "s")){ |
236 | ctx.qry.sort = xstrdup(value); |
263 | ctx.qry.sort = xstrdup(value); |
237 | } else if (!strcmp(name, "showmsg")) { |
264 | } else if (!strcmp(name, "showmsg")) { |
238 | ctx.qry.showmsg = atoi(value); |
265 | ctx.qry.showmsg = atoi(value); |
239 | } else if (!strcmp(name, "period")) { |
266 | } else if (!strcmp(name, "period")) { |
240 | ctx.qry.period = xstrdup(value); |
267 | ctx.qry.period = xstrdup(value); |
| |
268 | } else if (!strcmp(name, "ss")) { |
| |
269 | ctx.qry.ssdiff = atoi(value); |
| |
270 | } else if (!strcmp(name, "all")) { |
| |
271 | ctx.qry.show_all = atoi(value); |
| |
272 | } else if (!strcmp(name, "context")) { |
| |
273 | ctx.qry.context = atoi(value); |
| |
274 | } else if (!strcmp(name, "ignorews")) { |
| |
275 | ctx.qry.ignorews = atoi(value); |
241 | } |
276 | } |
242 | } |
277 | } |
243 | |
278 | |
244 | char *xstrdupn(const char *str) |
279 | char *xstrdupn(const char *str) |
245 | { |
280 | { |
246 | return (str ? xstrdup(str) : NULL); |
281 | return (str ? xstrdup(str) : NULL); |
247 | } |
282 | } |
248 | |
283 | |
249 | static void prepare_context(struct cgit_context *ctx) |
284 | static void prepare_context(struct cgit_context *ctx) |
250 | { |
285 | { |
251 | memset(ctx, 0, sizeof(*ctx)); |
286 | memset(ctx, 0, sizeof(*ctx)); |
252 | ctx->cfg.agefile = "info/web/last-modified"; |
287 | ctx->cfg.agefile = "info/web/last-modified"; |
253 | ctx->cfg.nocache = 0; |
288 | ctx->cfg.nocache = 0; |
254 | ctx->cfg.cache_size = 0; |
289 | ctx->cfg.cache_size = 0; |
255 | ctx->cfg.cache_dynamic_ttl = 5; |
290 | ctx->cfg.cache_dynamic_ttl = 5; |
256 | ctx->cfg.cache_max_create_time = 5; |
291 | ctx->cfg.cache_max_create_time = 5; |
257 | ctx->cfg.cache_repo_ttl = 5; |
292 | ctx->cfg.cache_repo_ttl = 5; |
258 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
293 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
259 | ctx->cfg.cache_root_ttl = 5; |
294 | ctx->cfg.cache_root_ttl = 5; |
260 | ctx->cfg.cache_scanrc_ttl = 15; |
295 | ctx->cfg.cache_scanrc_ttl = 15; |
261 | ctx->cfg.cache_static_ttl = -1; |
296 | ctx->cfg.cache_static_ttl = -1; |
262 | ctx->cfg.css = "/cgit.css"; |
297 | ctx->cfg.css = "/cgit.css"; |
263 | ctx->cfg.logo = "/cgit.png"; |
298 | ctx->cfg.logo = "/cgit.png"; |
264 | ctx->cfg.local_time = 0; |
299 | ctx->cfg.local_time = 0; |
| |
300 | ctx->cfg.enable_gitweb_owner = 1; |
265 | ctx->cfg.enable_tree_linenumbers = 1; |
301 | ctx->cfg.enable_tree_linenumbers = 1; |
266 | ctx->cfg.max_repo_count = 50; |
302 | ctx->cfg.max_repo_count = 50; |
267 | ctx->cfg.max_commit_count = 50; |
303 | ctx->cfg.max_commit_count = 50; |
268 | ctx->cfg.max_lock_attempts = 5; |
304 | ctx->cfg.max_lock_attempts = 5; |
269 | ctx->cfg.max_msg_len = 80; |
305 | ctx->cfg.max_msg_len = 80; |
270 | ctx->cfg.max_repodesc_len = 80; |
306 | ctx->cfg.max_repodesc_len = 80; |
| |
307 | ctx->cfg.max_blob_size = 0; |
271 | ctx->cfg.max_stats = 0; |
308 | ctx->cfg.max_stats = 0; |
272 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
309 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
| |
310 | ctx->cfg.project_list = NULL; |
273 | ctx->cfg.renamelimit = -1; |
311 | ctx->cfg.renamelimit = -1; |
| |
312 | ctx->cfg.remove_suffix = 0; |
274 | ctx->cfg.robots = "index, nofollow"; |
313 | ctx->cfg.robots = "index, nofollow"; |
275 | ctx->cfg.root_title = "Git repository browser"; |
314 | ctx->cfg.root_title = "Git repository browser"; |
276 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
315 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
277 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
316 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
278 | ctx->cfg.section = ""; |
317 | ctx->cfg.section = ""; |
279 | ctx->cfg.summary_branches = 10; |
318 | ctx->cfg.summary_branches = 10; |
280 | ctx->cfg.summary_log = 10; |
319 | ctx->cfg.summary_log = 10; |
281 | ctx->cfg.summary_tags = 10; |
320 | ctx->cfg.summary_tags = 10; |
| |
321 | ctx->cfg.max_atom_items = 10; |
| |
322 | ctx->cfg.ssdiff = 0; |
282 | ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); |
323 | ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); |
283 | ctx->env.http_host = xstrdupn(getenv("HTTP_HOST")); |
324 | ctx->env.http_host = xstrdupn(getenv("HTTP_HOST")); |
284 | ctx->env.https = xstrdupn(getenv("HTTPS")); |
325 | ctx->env.https = xstrdupn(getenv("HTTPS")); |
285 | ctx->env.no_http = xstrdupn(getenv("NO_HTTP")); |
326 | ctx->env.no_http = xstrdupn(getenv("NO_HTTP")); |
286 | ctx->env.path_info = xstrdupn(getenv("PATH_INFO")); |
327 | ctx->env.path_info = xstrdupn(getenv("PATH_INFO")); |
287 | ctx->env.query_string = xstrdupn(getenv("QUERY_STRING")); |
328 | ctx->env.query_string = xstrdupn(getenv("QUERY_STRING")); |
288 | ctx->env.request_method = xstrdupn(getenv("REQUEST_METHOD")); |
329 | ctx->env.request_method = xstrdupn(getenv("REQUEST_METHOD")); |
289 | ctx->env.script_name = xstrdupn(getenv("SCRIPT_NAME")); |
330 | ctx->env.script_name = xstrdupn(getenv("SCRIPT_NAME")); |
290 | ctx->env.server_name = xstrdupn(getenv("SERVER_NAME")); |
331 | ctx->env.server_name = xstrdupn(getenv("SERVER_NAME")); |
291 | ctx->env.server_port = xstrdupn(getenv("SERVER_PORT")); |
332 | ctx->env.server_port = xstrdupn(getenv("SERVER_PORT")); |
292 | ctx->page.mimetype = "text/html"; |
333 | ctx->page.mimetype = "text/html"; |
293 | ctx->page.charset = PAGE_ENCODING; |
334 | ctx->page.charset = PAGE_ENCODING; |
294 | ctx->page.filename = NULL; |
335 | ctx->page.filename = NULL; |
295 | ctx->page.size = 0; |
336 | ctx->page.size = 0; |
296 | ctx->page.modified = time(NULL); |
337 | ctx->page.modified = time(NULL); |
297 | ctx->page.expires = ctx->page.modified; |
338 | ctx->page.expires = ctx->page.modified; |
298 | ctx->page.etag = NULL; |
339 | ctx->page.etag = NULL; |
299 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); |
340 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); |
300 | if (ctx->env.script_name) |
341 | if (ctx->env.script_name) |
301 | ctx->cfg.script_name = ctx->env.script_name; |
342 | ctx->cfg.script_name = ctx->env.script_name; |
302 | if (ctx->env.query_string) |
343 | if (ctx->env.query_string) |
303 | ctx->qry.raw = ctx->env.query_string; |
344 | ctx->qry.raw = ctx->env.query_string; |
304 | if (!ctx->env.cgit_config) |
345 | if (!ctx->env.cgit_config) |
305 | ctx->env.cgit_config = CGIT_CONFIG; |
346 | ctx->env.cgit_config = CGIT_CONFIG; |
@@ -389,48 +430,54 @@ static int prepare_repo_cmd(struct cgit_context *ctx) |
389 | cgit_print_pageheader(ctx); |
430 | cgit_print_pageheader(ctx); |
390 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
431 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
391 | cgit_print_docend(); |
432 | cgit_print_docend(); |
392 | return 1; |
433 | return 1; |
393 | } |
434 | } |
394 | return 0; |
435 | return 0; |
395 | } |
436 | } |
396 | |
437 | |
397 | static void process_request(void *cbdata) |
438 | static void process_request(void *cbdata) |
398 | { |
439 | { |
399 | struct cgit_context *ctx = cbdata; |
440 | struct cgit_context *ctx = cbdata; |
400 | struct cgit_cmd *cmd; |
441 | struct cgit_cmd *cmd; |
401 | |
442 | |
402 | cmd = cgit_get_cmd(ctx); |
443 | cmd = cgit_get_cmd(ctx); |
403 | if (!cmd) { |
444 | if (!cmd) { |
404 | ctx->page.title = "cgit error"; |
445 | ctx->page.title = "cgit error"; |
405 | cgit_print_http_headers(ctx); |
446 | cgit_print_http_headers(ctx); |
406 | cgit_print_docstart(ctx); |
447 | cgit_print_docstart(ctx); |
407 | cgit_print_pageheader(ctx); |
448 | cgit_print_pageheader(ctx); |
408 | cgit_print_error("Invalid request"); |
449 | cgit_print_error("Invalid request"); |
409 | cgit_print_docend(); |
450 | cgit_print_docend(); |
410 | return; |
451 | return; |
411 | } |
452 | } |
412 | |
453 | |
| |
454 | /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual" |
| |
455 | * in-project path limit to be made available at ctx->qry.vpath. |
| |
456 | * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL). |
| |
457 | */ |
| |
458 | ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL; |
| |
459 | |
413 | if (cmd->want_repo && !ctx->repo) { |
460 | if (cmd->want_repo && !ctx->repo) { |
414 | cgit_print_http_headers(ctx); |
461 | cgit_print_http_headers(ctx); |
415 | cgit_print_docstart(ctx); |
462 | cgit_print_docstart(ctx); |
416 | cgit_print_pageheader(ctx); |
463 | cgit_print_pageheader(ctx); |
417 | cgit_print_error(fmt("No repository selected")); |
464 | cgit_print_error(fmt("No repository selected")); |
418 | cgit_print_docend(); |
465 | cgit_print_docend(); |
419 | return; |
466 | return; |
420 | } |
467 | } |
421 | |
468 | |
422 | if (ctx->repo && prepare_repo_cmd(ctx)) |
469 | if (ctx->repo && prepare_repo_cmd(ctx)) |
423 | return; |
470 | return; |
424 | |
471 | |
425 | if (cmd->want_layout) { |
472 | if (cmd->want_layout) { |
426 | cgit_print_http_headers(ctx); |
473 | cgit_print_http_headers(ctx); |
427 | cgit_print_docstart(ctx); |
474 | cgit_print_docstart(ctx); |
428 | cgit_print_pageheader(ctx); |
475 | cgit_print_pageheader(ctx); |
429 | } |
476 | } |
430 | |
477 | |
431 | cmd->fn(ctx); |
478 | cmd->fn(ctx); |
432 | |
479 | |
433 | if (cmd->want_layout) |
480 | if (cmd->want_layout) |
434 | cgit_print_docend(); |
481 | cgit_print_docend(); |
435 | } |
482 | } |
436 | |
483 | |
@@ -520,73 +567,84 @@ void print_repolist(FILE *f, struct cgit_repolist *list, int start) |
520 | print_repo(f, &list->repos[i]); |
567 | print_repo(f, &list->repos[i]); |
521 | } |
568 | } |
522 | |
569 | |
523 | /* Scan 'path' for git repositories, save the resulting repolist in 'cached_rc' |
570 | /* Scan 'path' for git repositories, save the resulting repolist in 'cached_rc' |
524 | * and return 0 on success. |
571 | * and return 0 on success. |
525 | */ |
572 | */ |
526 | static int generate_cached_repolist(const char *path, const char *cached_rc) |
573 | static int generate_cached_repolist(const char *path, const char *cached_rc) |
527 | { |
574 | { |
528 | char *locked_rc; |
575 | char *locked_rc; |
529 | int idx; |
576 | int idx; |
530 | FILE *f; |
577 | FILE *f; |
531 | |
578 | |
532 | locked_rc = xstrdup(fmt("%s.lock", cached_rc)); |
579 | locked_rc = xstrdup(fmt("%s.lock", cached_rc)); |
533 | f = fopen(locked_rc, "wx"); |
580 | f = fopen(locked_rc, "wx"); |
534 | if (!f) { |
581 | if (!f) { |
535 | /* Inform about the error unless the lockfile already existed, |
582 | /* Inform about the error unless the lockfile already existed, |
536 | * since that only means we've got concurrent requests. |
583 | * since that only means we've got concurrent requests. |
537 | */ |
584 | */ |
538 | if (errno != EEXIST) |
585 | if (errno != EEXIST) |
539 | fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n", |
586 | fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n", |
540 | locked_rc, strerror(errno), errno); |
587 | locked_rc, strerror(errno), errno); |
541 | return errno; |
588 | return errno; |
542 | } |
589 | } |
543 | idx = cgit_repolist.count; |
590 | idx = cgit_repolist.count; |
544 | scan_tree(path, repo_config); |
591 | if (ctx.cfg.project_list) |
| |
592 | scan_projects(path, ctx.cfg.project_list, repo_config); |
| |
593 | else |
| |
594 | scan_tree(path, repo_config); |
545 | print_repolist(f, &cgit_repolist, idx); |
595 | print_repolist(f, &cgit_repolist, idx); |
546 | if (rename(locked_rc, cached_rc)) |
596 | if (rename(locked_rc, cached_rc)) |
547 | fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n", |
597 | fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n", |
548 | locked_rc, cached_rc, strerror(errno), errno); |
598 | locked_rc, cached_rc, strerror(errno), errno); |
549 | fclose(f); |
599 | fclose(f); |
550 | return 0; |
600 | return 0; |
551 | } |
601 | } |
552 | |
602 | |
553 | static void process_cached_repolist(const char *path) |
603 | static void process_cached_repolist(const char *path) |
554 | { |
604 | { |
555 | struct stat st; |
605 | struct stat st; |
556 | char *cached_rc; |
606 | char *cached_rc; |
557 | time_t age; |
607 | time_t age; |
| |
608 | unsigned long hash; |
558 | |
609 | |
559 | cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root, |
610 | hash = hash_str(path); |
560 | hash_str(path))); |
611 | if (ctx.cfg.project_list) |
| |
612 | hash += hash_str(ctx.cfg.project_list); |
| |
613 | cached_rc = xstrdup(fmt("%s/rc-%8lx", ctx.cfg.cache_root, hash)); |
561 | |
614 | |
562 | if (stat(cached_rc, &st)) { |
615 | if (stat(cached_rc, &st)) { |
563 | /* Nothing is cached, we need to scan without forking. And |
616 | /* Nothing is cached, we need to scan without forking. And |
564 | * if we fail to generate a cached repolist, we need to |
617 | * if we fail to generate a cached repolist, we need to |
565 | * invoke scan_tree manually. |
618 | * invoke scan_tree manually. |
566 | */ |
619 | */ |
567 | if (generate_cached_repolist(path, cached_rc)) |
620 | if (generate_cached_repolist(path, cached_rc)) { |
568 | scan_tree(path, repo_config); |
621 | if (ctx.cfg.project_list) |
| |
622 | scan_projects(path, ctx.cfg.project_list, |
| |
623 | repo_config); |
| |
624 | else |
| |
625 | scan_tree(path, repo_config); |
| |
626 | } |
569 | return; |
627 | return; |
570 | } |
628 | } |
571 | |
629 | |
572 | parse_configfile(cached_rc, config_cb); |
630 | parse_configfile(cached_rc, config_cb); |
573 | |
631 | |
574 | /* If the cached configfile hasn't expired, lets exit now */ |
632 | /* If the cached configfile hasn't expired, lets exit now */ |
575 | age = time(NULL) - st.st_mtime; |
633 | age = time(NULL) - st.st_mtime; |
576 | if (age <= (ctx.cfg.cache_scanrc_ttl * 60)) |
634 | if (age <= (ctx.cfg.cache_scanrc_ttl * 60)) |
577 | return; |
635 | return; |
578 | |
636 | |
579 | /* The cached repolist has been parsed, but it was old. So lets |
637 | /* The cached repolist has been parsed, but it was old. So lets |
580 | * rescan the specified path and generate a new cached repolist |
638 | * rescan the specified path and generate a new cached repolist |
581 | * in a child-process to avoid latency for the current request. |
639 | * in a child-process to avoid latency for the current request. |
582 | */ |
640 | */ |
583 | if (fork()) |
641 | if (fork()) |
584 | return; |
642 | return; |
585 | |
643 | |
586 | exit(generate_cached_repolist(path, cached_rc)); |
644 | exit(generate_cached_repolist(path, cached_rc)); |
587 | } |
645 | } |
588 | |
646 | |
589 | static void cgit_parse_args(int argc, const char **argv) |
647 | static void cgit_parse_args(int argc, const char **argv) |
590 | { |
648 | { |
591 | int i; |
649 | int i; |
592 | int scan = 0; |
650 | int scan = 0; |
@@ -653,49 +711,49 @@ static int calc_ttl() |
653 | if (!ctx.qry.page) |
711 | if (!ctx.qry.page) |
654 | return ctx.cfg.cache_repo_ttl; |
712 | return ctx.cfg.cache_repo_ttl; |
655 | |
713 | |
656 | if (ctx.qry.has_symref) |
714 | if (ctx.qry.has_symref) |
657 | return ctx.cfg.cache_dynamic_ttl; |
715 | return ctx.cfg.cache_dynamic_ttl; |
658 | |
716 | |
659 | if (ctx.qry.has_sha1) |
717 | if (ctx.qry.has_sha1) |
660 | return ctx.cfg.cache_static_ttl; |
718 | return ctx.cfg.cache_static_ttl; |
661 | |
719 | |
662 | return ctx.cfg.cache_repo_ttl; |
720 | return ctx.cfg.cache_repo_ttl; |
663 | } |
721 | } |
664 | |
722 | |
665 | int main(int argc, const char **argv) |
723 | int main(int argc, const char **argv) |
666 | { |
724 | { |
667 | const char *path; |
725 | const char *path; |
668 | char *qry; |
726 | char *qry; |
669 | int err, ttl; |
727 | int err, ttl; |
670 | |
728 | |
671 | prepare_context(&ctx); |
729 | prepare_context(&ctx); |
672 | cgit_repolist.length = 0; |
730 | cgit_repolist.length = 0; |
673 | cgit_repolist.count = 0; |
731 | cgit_repolist.count = 0; |
674 | cgit_repolist.repos = NULL; |
732 | cgit_repolist.repos = NULL; |
675 | |
733 | |
676 | cgit_parse_args(argc, argv); |
734 | cgit_parse_args(argc, argv); |
677 | parse_configfile(ctx.env.cgit_config, config_cb); |
735 | parse_configfile(expand_macros(ctx.env.cgit_config), config_cb); |
678 | ctx.repo = NULL; |
736 | ctx.repo = NULL; |
679 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
737 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
680 | |
738 | |
681 | /* If virtual-root isn't specified in cgitrc, lets pretend |
739 | /* If virtual-root isn't specified in cgitrc, lets pretend |
682 | * that virtual-root equals SCRIPT_NAME. |
740 | * that virtual-root equals SCRIPT_NAME. |
683 | */ |
741 | */ |
684 | if (!ctx.cfg.virtual_root) |
742 | if (!ctx.cfg.virtual_root) |
685 | ctx.cfg.virtual_root = ctx.cfg.script_name; |
743 | ctx.cfg.virtual_root = ctx.cfg.script_name; |
686 | |
744 | |
687 | /* If no url parameter is specified on the querystring, lets |
745 | /* If no url parameter is specified on the querystring, lets |
688 | * use PATH_INFO as url. This allows cgit to work with virtual |
746 | * use PATH_INFO as url. This allows cgit to work with virtual |
689 | * urls without the need for rewriterules in the webserver (as |
747 | * urls without the need for rewriterules in the webserver (as |
690 | * long as PATH_INFO is included in the cache lookup key). |
748 | * long as PATH_INFO is included in the cache lookup key). |
691 | */ |
749 | */ |
692 | path = ctx.env.path_info; |
750 | path = ctx.env.path_info; |
693 | if (!ctx.qry.url && path) { |
751 | if (!ctx.qry.url && path) { |
694 | if (path[0] == '/') |
752 | if (path[0] == '/') |
695 | path++; |
753 | path++; |
696 | ctx.qry.url = xstrdup(path); |
754 | ctx.qry.url = xstrdup(path); |
697 | if (ctx.qry.raw) { |
755 | if (ctx.qry.raw) { |
698 | qry = ctx.qry.raw; |
756 | qry = ctx.qry.raw; |
699 | ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); |
757 | ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); |
700 | free(qry); |
758 | free(qry); |
701 | } else |
759 | } else |
|