summaryrefslogtreecommitdiffabout
path: root/cgit.c
Unidiff
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/cgit.c b/cgit.c
index f4dd6ef..e302a7c 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,232 +1,234 @@
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 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com>
5 * 5 *
6 * Licensed under GNU General Public License v2 6 * Licensed under GNU General Public License v2
7 * (see COPYING for full license text) 7 * (see COPYING for full license text)
8 */ 8 */
9 9
10#include "cgit.h" 10#include "cgit.h"
11#include "cache.h" 11#include "cache.h"
12#include "cmd.h" 12#include "cmd.h"
13#include "configfile.h" 13#include "configfile.h"
14#include "html.h" 14#include "html.h"
15#include "ui-shared.h" 15#include "ui-shared.h"
16#include "ui-stats.h" 16#include "ui-stats.h"
17#include "scan-tree.h" 17#include "scan-tree.h"
18 18
19const char *cgit_version = CGIT_VERSION; 19const char *cgit_version = CGIT_VERSION;
20 20
21void add_mimetype(const char *name, const char *value) 21void add_mimetype(const char *name, const char *value)
22{ 22{
23 struct string_list_item *item; 23 struct string_list_item *item;
24 24
25 item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name)); 25 item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name));
26 item->util = xstrdup(value); 26 item->util = xstrdup(value);
27} 27}
28 28
29struct cgit_filter *new_filter(const char *cmd, int extra_args) 29struct cgit_filter *new_filter(const char *cmd, int extra_args)
30{ 30{
31 struct cgit_filter *f; 31 struct cgit_filter *f;
32 int args_size = 0;
32 33
33 if (!cmd || !cmd[0]) 34 if (!cmd || !cmd[0])
34 return NULL; 35 return NULL;
35 36
36 f = xmalloc(sizeof(struct cgit_filter)); 37 f = xmalloc(sizeof(struct cgit_filter));
37 f->cmd = xstrdup(cmd); 38 f->cmd = xstrdup(cmd);
38 f->argv = xmalloc((2 + extra_args) * sizeof(char *)); 39 args_size = (2 + extra_args) * sizeof(char *);
40 f->argv = xmalloc(args_size);
41 memset(f->argv, 0, args_size);
39 f->argv[0] = f->cmd; 42 f->argv[0] = f->cmd;
40 f->argv[1] = NULL;
41 return f; 43 return f;
42} 44}
43 45
44static void process_cached_repolist(const char *path); 46static void process_cached_repolist(const char *path);
45 47
46void repo_config(struct cgit_repo *repo, const char *name, const char *value) 48void repo_config(struct cgit_repo *repo, const char *name, const char *value)
47{ 49{
48 if (!strcmp(name, "name")) 50 if (!strcmp(name, "name"))
49 repo->name = xstrdup(value); 51 repo->name = xstrdup(value);
50 else if (!strcmp(name, "clone-url")) 52 else if (!strcmp(name, "clone-url"))
51 repo->clone_url = xstrdup(value); 53 repo->clone_url = xstrdup(value);
52 else if (!strcmp(name, "desc")) 54 else if (!strcmp(name, "desc"))
53 repo->desc = xstrdup(value); 55 repo->desc = xstrdup(value);
54 else if (!strcmp(name, "owner")) 56 else if (!strcmp(name, "owner"))
55 repo->owner = xstrdup(value); 57 repo->owner = xstrdup(value);
56 else if (!strcmp(name, "defbranch")) 58 else if (!strcmp(name, "defbranch"))
57 repo->defbranch = xstrdup(value); 59 repo->defbranch = xstrdup(value);
58 else if (!strcmp(name, "snapshots")) 60 else if (!strcmp(name, "snapshots"))
59 repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); 61 repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
60 else if (!strcmp(name, "enable-commit-graph")) 62 else if (!strcmp(name, "enable-commit-graph"))
61 repo->enable_commit_graph = ctx.cfg.enable_commit_graph * atoi(value); 63 repo->enable_commit_graph = ctx.cfg.enable_commit_graph * atoi(value);
62 else if (!strcmp(name, "enable-log-filecount")) 64 else if (!strcmp(name, "enable-log-filecount"))
63 repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); 65 repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
64 else if (!strcmp(name, "enable-log-linecount")) 66 else if (!strcmp(name, "enable-log-linecount"))
65 repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); 67 repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
66 else if (!strcmp(name, "enable-remote-branches")) 68 else if (!strcmp(name, "enable-remote-branches"))
67 repo->enable_remote_branches = atoi(value); 69 repo->enable_remote_branches = atoi(value);
68 else if (!strcmp(name, "enable-subject-links")) 70 else if (!strcmp(name, "enable-subject-links"))
69 repo->enable_subject_links = atoi(value); 71 repo->enable_subject_links = atoi(value);
70 else if (!strcmp(name, "max-stats")) 72 else if (!strcmp(name, "max-stats"))
71 repo->max_stats = cgit_find_stats_period(value, NULL); 73 repo->max_stats = cgit_find_stats_period(value, NULL);
72 else if (!strcmp(name, "module-link")) 74 else if (!strcmp(name, "module-link"))
73 repo->module_link= xstrdup(value); 75 repo->module_link= xstrdup(value);
74 else if (!strcmp(name, "section")) 76 else if (!strcmp(name, "section"))
75 repo->section = xstrdup(value); 77 repo->section = xstrdup(value);
76 else if (!strcmp(name, "readme") && value != NULL) 78 else if (!strcmp(name, "readme") && value != NULL)
77 repo->readme = xstrdup(value); 79 repo->readme = xstrdup(value);
78 else if (!strcmp(name, "logo") && value != NULL) 80 else if (!strcmp(name, "logo") && value != NULL)
79 repo->logo = xstrdup(value); 81 repo->logo = xstrdup(value);
80 else if (!strcmp(name, "logo-link") && value != NULL) 82 else if (!strcmp(name, "logo-link") && value != NULL)
81 repo->logo_link = xstrdup(value); 83 repo->logo_link = xstrdup(value);
82 else if (ctx.cfg.enable_filter_overrides) { 84 else if (ctx.cfg.enable_filter_overrides) {
83 if (!strcmp(name, "about-filter")) 85 if (!strcmp(name, "about-filter"))
84 repo->about_filter = new_filter(value, 0); 86 repo->about_filter = new_filter(value, 0);
85 else if (!strcmp(name, "commit-filter")) 87 else if (!strcmp(name, "commit-filter"))
86 repo->commit_filter = new_filter(value, 0); 88 repo->commit_filter = new_filter(value, 0);
87 else if (!strcmp(name, "source-filter")) 89 else if (!strcmp(name, "source-filter"))
88 repo->source_filter = new_filter(value, 1); 90 repo->source_filter = new_filter(value, 1);
89 } 91 }
90} 92}
91 93
92void config_cb(const char *name, const char *value) 94void config_cb(const char *name, const char *value)
93{ 95{
94 if (!strcmp(name, "section") || !strcmp(name, "repo.group")) 96 if (!strcmp(name, "section") || !strcmp(name, "repo.group"))
95 ctx.cfg.section = xstrdup(value); 97 ctx.cfg.section = xstrdup(value);
96 else if (!strcmp(name, "repo.url")) 98 else if (!strcmp(name, "repo.url"))
97 ctx.repo = cgit_add_repo(value); 99 ctx.repo = cgit_add_repo(value);
98 else if (ctx.repo && !strcmp(name, "repo.path")) 100 else if (ctx.repo && !strcmp(name, "repo.path"))
99 ctx.repo->path = trim_end(value, '/'); 101 ctx.repo->path = trim_end(value, '/');
100 else if (ctx.repo && !prefixcmp(name, "repo.")) 102 else if (ctx.repo && !prefixcmp(name, "repo."))
101 repo_config(ctx.repo, name + 5, value); 103 repo_config(ctx.repo, name + 5, value);
102 else if (!strcmp(name, "readme")) 104 else if (!strcmp(name, "readme"))
103 ctx.cfg.readme = xstrdup(value); 105 ctx.cfg.readme = xstrdup(value);
104 else if (!strcmp(name, "root-title")) 106 else if (!strcmp(name, "root-title"))
105 ctx.cfg.root_title = xstrdup(value); 107 ctx.cfg.root_title = xstrdup(value);
106 else if (!strcmp(name, "root-desc")) 108 else if (!strcmp(name, "root-desc"))
107 ctx.cfg.root_desc = xstrdup(value); 109 ctx.cfg.root_desc = xstrdup(value);
108 else if (!strcmp(name, "root-readme")) 110 else if (!strcmp(name, "root-readme"))
109 ctx.cfg.root_readme = xstrdup(value); 111 ctx.cfg.root_readme = xstrdup(value);
110 else if (!strcmp(name, "css")) 112 else if (!strcmp(name, "css"))
111 ctx.cfg.css = xstrdup(value); 113 ctx.cfg.css = xstrdup(value);
112 else if (!strcmp(name, "favicon")) 114 else if (!strcmp(name, "favicon"))
113 ctx.cfg.favicon = xstrdup(value); 115 ctx.cfg.favicon = xstrdup(value);
114 else if (!strcmp(name, "footer")) 116 else if (!strcmp(name, "footer"))
115 ctx.cfg.footer = xstrdup(value); 117 ctx.cfg.footer = xstrdup(value);
116 else if (!strcmp(name, "head-include")) 118 else if (!strcmp(name, "head-include"))
117 ctx.cfg.head_include = xstrdup(value); 119 ctx.cfg.head_include = xstrdup(value);
118 else if (!strcmp(name, "header")) 120 else if (!strcmp(name, "header"))
119 ctx.cfg.header = xstrdup(value); 121 ctx.cfg.header = xstrdup(value);
120 else if (!strcmp(name, "logo")) 122 else if (!strcmp(name, "logo"))
121 ctx.cfg.logo = xstrdup(value); 123 ctx.cfg.logo = xstrdup(value);
122 else if (!strcmp(name, "index-header")) 124 else if (!strcmp(name, "index-header"))
123 ctx.cfg.index_header = xstrdup(value); 125 ctx.cfg.index_header = xstrdup(value);
124 else if (!strcmp(name, "index-info")) 126 else if (!strcmp(name, "index-info"))
125 ctx.cfg.index_info = xstrdup(value); 127 ctx.cfg.index_info = xstrdup(value);
126 else if (!strcmp(name, "logo-link")) 128 else if (!strcmp(name, "logo-link"))
127 ctx.cfg.logo_link = xstrdup(value); 129 ctx.cfg.logo_link = xstrdup(value);
128 else if (!strcmp(name, "module-link")) 130 else if (!strcmp(name, "module-link"))
129 ctx.cfg.module_link = xstrdup(value); 131 ctx.cfg.module_link = xstrdup(value);
130 else if (!strcmp(name, "strict-export")) 132 else if (!strcmp(name, "strict-export"))
131 ctx.cfg.strict_export = xstrdup(value); 133 ctx.cfg.strict_export = xstrdup(value);
132 else if (!strcmp(name, "virtual-root")) { 134 else if (!strcmp(name, "virtual-root")) {
133 ctx.cfg.virtual_root = trim_end(value, '/'); 135 ctx.cfg.virtual_root = trim_end(value, '/');
134 if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) 136 if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
135 ctx.cfg.virtual_root = ""; 137 ctx.cfg.virtual_root = "";
136 } else if (!strcmp(name, "nocache")) 138 } else if (!strcmp(name, "nocache"))
137 ctx.cfg.nocache = atoi(value); 139 ctx.cfg.nocache = atoi(value);
138 else if (!strcmp(name, "noplainemail")) 140 else if (!strcmp(name, "noplainemail"))
139 ctx.cfg.noplainemail = atoi(value); 141 ctx.cfg.noplainemail = atoi(value);
140 else if (!strcmp(name, "noheader")) 142 else if (!strcmp(name, "noheader"))
141 ctx.cfg.noheader = atoi(value); 143 ctx.cfg.noheader = atoi(value);
142 else if (!strcmp(name, "snapshots")) 144 else if (!strcmp(name, "snapshots"))
143 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); 145 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
144 else if (!strcmp(name, "enable-filter-overrides")) 146 else if (!strcmp(name, "enable-filter-overrides"))
145 ctx.cfg.enable_filter_overrides = atoi(value); 147 ctx.cfg.enable_filter_overrides = atoi(value);
146 else if (!strcmp(name, "enable-gitweb-owner")) 148 else if (!strcmp(name, "enable-gitweb-owner"))
147 ctx.cfg.enable_gitweb_owner = atoi(value); 149 ctx.cfg.enable_gitweb_owner = atoi(value);
148 else if (!strcmp(name, "enable-index-links")) 150 else if (!strcmp(name, "enable-index-links"))
149 ctx.cfg.enable_index_links = atoi(value); 151 ctx.cfg.enable_index_links = atoi(value);
150 else if (!strcmp(name, "enable-commit-graph")) 152 else if (!strcmp(name, "enable-commit-graph"))
151 ctx.cfg.enable_commit_graph = atoi(value); 153 ctx.cfg.enable_commit_graph = atoi(value);
152 else if (!strcmp(name, "enable-log-filecount")) 154 else if (!strcmp(name, "enable-log-filecount"))
153 ctx.cfg.enable_log_filecount = atoi(value); 155 ctx.cfg.enable_log_filecount = atoi(value);
154 else if (!strcmp(name, "enable-log-linecount")) 156 else if (!strcmp(name, "enable-log-linecount"))
155 ctx.cfg.enable_log_linecount = atoi(value); 157 ctx.cfg.enable_log_linecount = atoi(value);
156 else if (!strcmp(name, "enable-remote-branches")) 158 else if (!strcmp(name, "enable-remote-branches"))
157 ctx.cfg.enable_remote_branches = atoi(value); 159 ctx.cfg.enable_remote_branches = atoi(value);
158 else if (!strcmp(name, "enable-subject-links")) 160 else if (!strcmp(name, "enable-subject-links"))
159 ctx.cfg.enable_subject_links = atoi(value); 161 ctx.cfg.enable_subject_links = atoi(value);
160 else if (!strcmp(name, "enable-tree-linenumbers")) 162 else if (!strcmp(name, "enable-tree-linenumbers"))
161 ctx.cfg.enable_tree_linenumbers = atoi(value); 163 ctx.cfg.enable_tree_linenumbers = atoi(value);
162 else if (!strcmp(name, "max-stats")) 164 else if (!strcmp(name, "max-stats"))
163 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); 165 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
164 else if (!strcmp(name, "cache-size")) 166 else if (!strcmp(name, "cache-size"))
165 ctx.cfg.cache_size = atoi(value); 167 ctx.cfg.cache_size = atoi(value);
166 else if (!strcmp(name, "cache-root")) 168 else if (!strcmp(name, "cache-root"))
167 ctx.cfg.cache_root = xstrdup(expand_macros(value)); 169 ctx.cfg.cache_root = xstrdup(expand_macros(value));
168 else if (!strcmp(name, "cache-root-ttl")) 170 else if (!strcmp(name, "cache-root-ttl"))
169 ctx.cfg.cache_root_ttl = atoi(value); 171 ctx.cfg.cache_root_ttl = atoi(value);
170 else if (!strcmp(name, "cache-repo-ttl")) 172 else if (!strcmp(name, "cache-repo-ttl"))
171 ctx.cfg.cache_repo_ttl = atoi(value); 173 ctx.cfg.cache_repo_ttl = atoi(value);
172 else if (!strcmp(name, "cache-scanrc-ttl")) 174 else if (!strcmp(name, "cache-scanrc-ttl"))
173 ctx.cfg.cache_scanrc_ttl = atoi(value); 175 ctx.cfg.cache_scanrc_ttl = atoi(value);
174 else if (!strcmp(name, "cache-static-ttl")) 176 else if (!strcmp(name, "cache-static-ttl"))
175 ctx.cfg.cache_static_ttl = atoi(value); 177 ctx.cfg.cache_static_ttl = atoi(value);
176 else if (!strcmp(name, "cache-dynamic-ttl")) 178 else if (!strcmp(name, "cache-dynamic-ttl"))
177 ctx.cfg.cache_dynamic_ttl = atoi(value); 179 ctx.cfg.cache_dynamic_ttl = atoi(value);
178 else if (!strcmp(name, "about-filter")) 180 else if (!strcmp(name, "about-filter"))
179 ctx.cfg.about_filter = new_filter(value, 0); 181 ctx.cfg.about_filter = new_filter(value, 0);
180 else if (!strcmp(name, "commit-filter")) 182 else if (!strcmp(name, "commit-filter"))
181 ctx.cfg.commit_filter = new_filter(value, 0); 183 ctx.cfg.commit_filter = new_filter(value, 0);
182 else if (!strcmp(name, "embedded")) 184 else if (!strcmp(name, "embedded"))
183 ctx.cfg.embedded = atoi(value); 185 ctx.cfg.embedded = atoi(value);
184 else if (!strcmp(name, "max-atom-items")) 186 else if (!strcmp(name, "max-atom-items"))
185 ctx.cfg.max_atom_items = atoi(value); 187 ctx.cfg.max_atom_items = atoi(value);
186 else if (!strcmp(name, "max-message-length")) 188 else if (!strcmp(name, "max-message-length"))
187 ctx.cfg.max_msg_len = atoi(value); 189 ctx.cfg.max_msg_len = atoi(value);
188 else if (!strcmp(name, "max-repodesc-length")) 190 else if (!strcmp(name, "max-repodesc-length"))
189 ctx.cfg.max_repodesc_len = atoi(value); 191 ctx.cfg.max_repodesc_len = atoi(value);
190 else if (!strcmp(name, "max-blob-size")) 192 else if (!strcmp(name, "max-blob-size"))
191 ctx.cfg.max_blob_size = atoi(value); 193 ctx.cfg.max_blob_size = atoi(value);
192 else if (!strcmp(name, "max-repo-count")) 194 else if (!strcmp(name, "max-repo-count"))
193 ctx.cfg.max_repo_count = atoi(value); 195 ctx.cfg.max_repo_count = atoi(value);
194 else if (!strcmp(name, "max-commit-count")) 196 else if (!strcmp(name, "max-commit-count"))
195 ctx.cfg.max_commit_count = atoi(value); 197 ctx.cfg.max_commit_count = atoi(value);
196 else if (!strcmp(name, "project-list")) 198 else if (!strcmp(name, "project-list"))
197 ctx.cfg.project_list = xstrdup(expand_macros(value)); 199 ctx.cfg.project_list = xstrdup(expand_macros(value));
198 else if (!strcmp(name, "scan-path")) 200 else if (!strcmp(name, "scan-path"))
199 if (!ctx.cfg.nocache && ctx.cfg.cache_size) 201 if (!ctx.cfg.nocache && ctx.cfg.cache_size)
200 process_cached_repolist(expand_macros(value)); 202 process_cached_repolist(expand_macros(value));
201 else if (ctx.cfg.project_list) 203 else if (ctx.cfg.project_list)
202 scan_projects(expand_macros(value), 204 scan_projects(expand_macros(value),
203 ctx.cfg.project_list, repo_config); 205 ctx.cfg.project_list, repo_config);
204 else 206 else
205 scan_tree(expand_macros(value), repo_config); 207 scan_tree(expand_macros(value), repo_config);
206 else if (!strcmp(name, "scan-hidden-path")) 208 else if (!strcmp(name, "scan-hidden-path"))
207 ctx.cfg.scan_hidden_path = atoi(value); 209 ctx.cfg.scan_hidden_path = atoi(value);
208 else if (!strcmp(name, "section-from-path")) 210 else if (!strcmp(name, "section-from-path"))
209 ctx.cfg.section_from_path = atoi(value); 211 ctx.cfg.section_from_path = atoi(value);
210 else if (!strcmp(name, "source-filter")) 212 else if (!strcmp(name, "source-filter"))
211 ctx.cfg.source_filter = new_filter(value, 1); 213 ctx.cfg.source_filter = new_filter(value, 1);
212 else if (!strcmp(name, "summary-log")) 214 else if (!strcmp(name, "summary-log"))
213 ctx.cfg.summary_log = atoi(value); 215 ctx.cfg.summary_log = atoi(value);
214 else if (!strcmp(name, "summary-branches")) 216 else if (!strcmp(name, "summary-branches"))
215 ctx.cfg.summary_branches = atoi(value); 217 ctx.cfg.summary_branches = atoi(value);
216 else if (!strcmp(name, "summary-tags")) 218 else if (!strcmp(name, "summary-tags"))
217 ctx.cfg.summary_tags = atoi(value); 219 ctx.cfg.summary_tags = atoi(value);
218 else if (!strcmp(name, "side-by-side-diffs")) 220 else if (!strcmp(name, "side-by-side-diffs"))
219 ctx.cfg.ssdiff = atoi(value); 221 ctx.cfg.ssdiff = atoi(value);
220 else if (!strcmp(name, "agefile")) 222 else if (!strcmp(name, "agefile"))
221 ctx.cfg.agefile = xstrdup(value); 223 ctx.cfg.agefile = xstrdup(value);
222 else if (!strcmp(name, "renamelimit")) 224 else if (!strcmp(name, "renamelimit"))
223 ctx.cfg.renamelimit = atoi(value); 225 ctx.cfg.renamelimit = atoi(value);
224 else if (!strcmp(name, "remove-suffix")) 226 else if (!strcmp(name, "remove-suffix"))
225 ctx.cfg.remove_suffix = atoi(value); 227 ctx.cfg.remove_suffix = atoi(value);
226 else if (!strcmp(name, "robots")) 228 else if (!strcmp(name, "robots"))
227 ctx.cfg.robots = xstrdup(value); 229 ctx.cfg.robots = xstrdup(value);
228 else if (!strcmp(name, "clone-prefix")) 230 else if (!strcmp(name, "clone-prefix"))
229 ctx.cfg.clone_prefix = xstrdup(value); 231 ctx.cfg.clone_prefix = xstrdup(value);
230 else if (!strcmp(name, "local-time")) 232 else if (!strcmp(name, "local-time"))
231 ctx.cfg.local_time = atoi(value); 233 ctx.cfg.local_time = atoi(value);
232 else if (!prefixcmp(name, "mimetype.")) 234 else if (!prefixcmp(name, "mimetype."))