summaryrefslogtreecommitdiffabout
path: root/cgit.c
authorLars Hjemli <hjemli@gmail.com>2010-03-21 23:09:43 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-03-21 23:09:43 (UTC)
commitba56a37e863d0f90e3e953047486905cfb959925 (patch) (unidiff)
tree965e2c917f472264de35125eec35c361984eba4f /cgit.c
parentff3a3b4e2b7463bb8cb370bdda393e8b3526fcb9 (diff)
downloadcgit-ba56a37e863d0f90e3e953047486905cfb959925.zip
cgit-ba56a37e863d0f90e3e953047486905cfb959925.tar.gz
cgit-ba56a37e863d0f90e3e953047486905cfb959925.tar.bz2
Add support for environment variable expansion
This patch teaches cgit to expand environment variables in certain cgitrc option values (cache_root, scan-path, include) plus when finding the location of cgitrc itself. One use case for this feature is virtual hosting - e.g. by setting $CGIT_CONFIG='/etc/cgitrc/$HTTP_HOST' in httpd.conf, all virtual hosts automatically gets their own cgitrc. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/cgit.c b/cgit.c
index 9305d0a..37154e3 100644
--- a/cgit.c
+++ b/cgit.c
@@ -127,104 +127,104 @@ void config_cb(const char *name, const char *value)
127 ctx.cfg.nocache = atoi(value); 127 ctx.cfg.nocache = atoi(value);
128 else if (!strcmp(name, "noplainemail")) 128 else if (!strcmp(name, "noplainemail"))
129 ctx.cfg.noplainemail = atoi(value); 129 ctx.cfg.noplainemail = atoi(value);
130 else if (!strcmp(name, "noheader")) 130 else if (!strcmp(name, "noheader"))
131 ctx.cfg.noheader = atoi(value); 131 ctx.cfg.noheader = atoi(value);
132 else if (!strcmp(name, "snapshots")) 132 else if (!strcmp(name, "snapshots"))
133 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); 133 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
134 else if (!strcmp(name, "enable-filter-overrides")) 134 else if (!strcmp(name, "enable-filter-overrides"))
135 ctx.cfg.enable_filter_overrides = atoi(value); 135 ctx.cfg.enable_filter_overrides = atoi(value);
136 else if (!strcmp(name, "enable-index-links")) 136 else if (!strcmp(name, "enable-index-links"))
137 ctx.cfg.enable_index_links = atoi(value); 137 ctx.cfg.enable_index_links = atoi(value);
138 else if (!strcmp(name, "enable-log-filecount")) 138 else if (!strcmp(name, "enable-log-filecount"))
139 ctx.cfg.enable_log_filecount = atoi(value); 139 ctx.cfg.enable_log_filecount = atoi(value);
140 else if (!strcmp(name, "enable-log-linecount")) 140 else if (!strcmp(name, "enable-log-linecount"))
141 ctx.cfg.enable_log_linecount = atoi(value); 141 ctx.cfg.enable_log_linecount = atoi(value);
142 else if (!strcmp(name, "enable-remote-branches")) 142 else if (!strcmp(name, "enable-remote-branches"))
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);
160 else if (!strcmp(name, "cache-dynamic-ttl")) 160 else if (!strcmp(name, "cache-dynamic-ttl"))
161 ctx.cfg.cache_dynamic_ttl = atoi(value); 161 ctx.cfg.cache_dynamic_ttl = atoi(value);
162 else if (!strcmp(name, "about-filter")) 162 else if (!strcmp(name, "about-filter"))
163 ctx.cfg.about_filter = new_filter(value, 0); 163 ctx.cfg.about_filter = new_filter(value, 0);
164 else if (!strcmp(name, "commit-filter")) 164 else if (!strcmp(name, "commit-filter"))
165 ctx.cfg.commit_filter = new_filter(value, 0); 165 ctx.cfg.commit_filter = new_filter(value, 0);
166 else if (!strcmp(name, "embedded")) 166 else if (!strcmp(name, "embedded"))
167 ctx.cfg.embedded = atoi(value); 167 ctx.cfg.embedded = atoi(value);
168 else if (!strcmp(name, "max-message-length")) 168 else if (!strcmp(name, "max-message-length"))
169 ctx.cfg.max_msg_len = atoi(value); 169 ctx.cfg.max_msg_len = atoi(value);
170 else if (!strcmp(name, "max-repodesc-length")) 170 else if (!strcmp(name, "max-repodesc-length"))
171 ctx.cfg.max_repodesc_len = atoi(value); 171 ctx.cfg.max_repodesc_len = atoi(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);
191 else if (!strcmp(name, "side-by-side-diffs")) 191 else if (!strcmp(name, "side-by-side-diffs"))
192 ctx.cfg.ssdiff = atoi(value); 192 ctx.cfg.ssdiff = atoi(value);
193 else if (!strcmp(name, "agefile")) 193 else if (!strcmp(name, "agefile"))
194 ctx.cfg.agefile = xstrdup(value); 194 ctx.cfg.agefile = xstrdup(value);
195 else if (!strcmp(name, "renamelimit")) 195 else if (!strcmp(name, "renamelimit"))
196 ctx.cfg.renamelimit = atoi(value); 196 ctx.cfg.renamelimit = atoi(value);
197 else if (!strcmp(name, "robots")) 197 else if (!strcmp(name, "robots"))
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
209static void querystring_cb(const char *name, const char *value) 209static 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")) {
215 ctx.qry.repo = xstrdup(value); 215 ctx.qry.repo = xstrdup(value);
216 ctx.repo = cgit_get_repoinfo(value); 216 ctx.repo = cgit_get_repoinfo(value);
217 } else if (!strcmp(name, "p")) { 217 } else if (!strcmp(name, "p")) {
218 ctx.qry.page = xstrdup(value); 218 ctx.qry.page = xstrdup(value);
219 } else if (!strcmp(name, "url")) { 219 } else if (!strcmp(name, "url")) {
220 if (*value == '/') 220 if (*value == '/')
221 value++; 221 value++;
222 ctx.qry.url = xstrdup(value); 222 ctx.qry.url = xstrdup(value);
223 cgit_parse_url(value); 223 cgit_parse_url(value);
224 } else if (!strcmp(name, "qt")) { 224 } else if (!strcmp(name, "qt")) {
225 ctx.qry.grep = xstrdup(value); 225 ctx.qry.grep = xstrdup(value);
226 } else if (!strcmp(name, "q")) { 226 } else if (!strcmp(name, "q")) {
227 ctx.qry.search = xstrdup(value); 227 ctx.qry.search = xstrdup(value);
228 } else if (!strcmp(name, "h")) { 228 } else if (!strcmp(name, "h")) {
229 ctx.qry.head = xstrdup(value); 229 ctx.qry.head = xstrdup(value);
230 ctx.qry.has_symref = 1; 230 ctx.qry.has_symref = 1;
@@ -667,49 +667,49 @@ static int calc_ttl()
667 if (!ctx.qry.page) 667 if (!ctx.qry.page)
668 return ctx.cfg.cache_repo_ttl; 668 return ctx.cfg.cache_repo_ttl;
669 669
670 if (ctx.qry.has_symref) 670 if (ctx.qry.has_symref)
671 return ctx.cfg.cache_dynamic_ttl; 671 return ctx.cfg.cache_dynamic_ttl;
672 672
673 if (ctx.qry.has_sha1) 673 if (ctx.qry.has_sha1)
674 return ctx.cfg.cache_static_ttl; 674 return ctx.cfg.cache_static_ttl;
675 675
676 return ctx.cfg.cache_repo_ttl; 676 return ctx.cfg.cache_repo_ttl;
677} 677}
678 678
679int main(int argc, const char **argv) 679int main(int argc, const char **argv)
680{ 680{
681 const char *path; 681 const char *path;
682 char *qry; 682 char *qry;
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;
700 700
701 /* If no url parameter is specified on the querystring, lets 701 /* If no url parameter is specified on the querystring, lets
702 * use PATH_INFO as url. This allows cgit to work with virtual 702 * use PATH_INFO as url. This allows cgit to work with virtual
703 * urls without the need for rewriterules in the webserver (as 703 * urls without the need for rewriterules in the webserver (as
704 * long as PATH_INFO is included in the cache lookup key). 704 * long as PATH_INFO is included in the cache lookup key).
705 */ 705 */
706 path = ctx.env.path_info; 706 path = ctx.env.path_info;
707 if (!ctx.qry.url && path) { 707 if (!ctx.qry.url && path) {
708 if (path[0] == '/') 708 if (path[0] == '/')
709 path++; 709 path++;
710 ctx.qry.url = xstrdup(path); 710 ctx.qry.url = xstrdup(path);
711 if (ctx.qry.raw) { 711 if (ctx.qry.raw) {
712 qry = ctx.qry.raw; 712 qry = ctx.qry.raw;
713 ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); 713 ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry));
714 free(qry); 714 free(qry);
715 } else 715 } else