summaryrefslogtreecommitdiffabout
path: root/cgit.c
Unidiff
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/cgit.c b/cgit.c
index aa1107a..dbec196 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,189 +1,212 @@
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 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10#include "cache.h" 10#include "cache.h"
11#include "cmd.h" 11#include "cmd.h"
12#include "configfile.h" 12#include "configfile.h"
13#include "html.h" 13#include "html.h"
14#include "ui-shared.h" 14#include "ui-shared.h"
15#include "ui-stats.h" 15#include "ui-stats.h"
16#include "scan-tree.h" 16#include "scan-tree.h"
17 17
18const char *cgit_version = CGIT_VERSION; 18const char *cgit_version = CGIT_VERSION;
19 19
20void add_mimetype(const char *name, const char *value) 20void add_mimetype(const char *name, const char *value)
21{ 21{
22 struct string_list_item *item; 22 struct string_list_item *item;
23 23
24 item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); 24 item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes);
25 item->util = xstrdup(value); 25 item->util = xstrdup(value);
26} 26}
27 27
28struct cgit_filter *new_filter(const char *cmd, int extra_args)
29{
30 struct cgit_filter *f;
31
32 if (!cmd || !cmd[0])
33 return NULL;
34
35 f = xmalloc(sizeof(struct cgit_filter));
36 f->cmd = xstrdup(cmd);
37 f->argv = xmalloc((2 + extra_args) * sizeof(char *));
38 f->argv[0] = f->cmd;
39 f->argv[1] = NULL;
40 return f;
41}
42
28void config_cb(const char *name, const char *value) 43void config_cb(const char *name, const char *value)
29{ 44{
30 if (!strcmp(name, "root-title")) 45 if (!strcmp(name, "root-title"))
31 ctx.cfg.root_title = xstrdup(value); 46 ctx.cfg.root_title = xstrdup(value);
32 else if (!strcmp(name, "root-desc")) 47 else if (!strcmp(name, "root-desc"))
33 ctx.cfg.root_desc = xstrdup(value); 48 ctx.cfg.root_desc = xstrdup(value);
34 else if (!strcmp(name, "root-readme")) 49 else if (!strcmp(name, "root-readme"))
35 ctx.cfg.root_readme = xstrdup(value); 50 ctx.cfg.root_readme = xstrdup(value);
36 else if (!strcmp(name, "css")) 51 else if (!strcmp(name, "css"))
37 ctx.cfg.css = xstrdup(value); 52 ctx.cfg.css = xstrdup(value);
38 else if (!strcmp(name, "favicon")) 53 else if (!strcmp(name, "favicon"))
39 ctx.cfg.favicon = xstrdup(value); 54 ctx.cfg.favicon = xstrdup(value);
40 else if (!strcmp(name, "footer")) 55 else if (!strcmp(name, "footer"))
41 ctx.cfg.footer = xstrdup(value); 56 ctx.cfg.footer = xstrdup(value);
42 else if (!strcmp(name, "head-include")) 57 else if (!strcmp(name, "head-include"))
43 ctx.cfg.head_include = xstrdup(value); 58 ctx.cfg.head_include = xstrdup(value);
44 else if (!strcmp(name, "header")) 59 else if (!strcmp(name, "header"))
45 ctx.cfg.header = xstrdup(value); 60 ctx.cfg.header = xstrdup(value);
46 else if (!strcmp(name, "logo")) 61 else if (!strcmp(name, "logo"))
47 ctx.cfg.logo = xstrdup(value); 62 ctx.cfg.logo = xstrdup(value);
48 else if (!strcmp(name, "index-header")) 63 else if (!strcmp(name, "index-header"))
49 ctx.cfg.index_header = xstrdup(value); 64 ctx.cfg.index_header = xstrdup(value);
50 else if (!strcmp(name, "index-info")) 65 else if (!strcmp(name, "index-info"))
51 ctx.cfg.index_info = xstrdup(value); 66 ctx.cfg.index_info = xstrdup(value);
52 else if (!strcmp(name, "logo-link")) 67 else if (!strcmp(name, "logo-link"))
53 ctx.cfg.logo_link = xstrdup(value); 68 ctx.cfg.logo_link = xstrdup(value);
54 else if (!strcmp(name, "module-link")) 69 else if (!strcmp(name, "module-link"))
55 ctx.cfg.module_link = xstrdup(value); 70 ctx.cfg.module_link = xstrdup(value);
56 else if (!strcmp(name, "virtual-root")) { 71 else if (!strcmp(name, "virtual-root")) {
57 ctx.cfg.virtual_root = trim_end(value, '/'); 72 ctx.cfg.virtual_root = trim_end(value, '/');
58 if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) 73 if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
59 ctx.cfg.virtual_root = ""; 74 ctx.cfg.virtual_root = "";
60 } else if (!strcmp(name, "nocache")) 75 } else if (!strcmp(name, "nocache"))
61 ctx.cfg.nocache = atoi(value); 76 ctx.cfg.nocache = atoi(value);
62 else if (!strcmp(name, "noplainemail")) 77 else if (!strcmp(name, "noplainemail"))
63 ctx.cfg.noplainemail = atoi(value); 78 ctx.cfg.noplainemail = atoi(value);
64 else if (!strcmp(name, "noheader")) 79 else if (!strcmp(name, "noheader"))
65 ctx.cfg.noheader = atoi(value); 80 ctx.cfg.noheader = atoi(value);
66 else if (!strcmp(name, "snapshots")) 81 else if (!strcmp(name, "snapshots"))
67 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); 82 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
68 else if (!strcmp(name, "enable-index-links")) 83 else if (!strcmp(name, "enable-index-links"))
69 ctx.cfg.enable_index_links = atoi(value); 84 ctx.cfg.enable_index_links = atoi(value);
70 else if (!strcmp(name, "enable-log-filecount")) 85 else if (!strcmp(name, "enable-log-filecount"))
71 ctx.cfg.enable_log_filecount = atoi(value); 86 ctx.cfg.enable_log_filecount = atoi(value);
72 else if (!strcmp(name, "enable-log-linecount")) 87 else if (!strcmp(name, "enable-log-linecount"))
73 ctx.cfg.enable_log_linecount = atoi(value); 88 ctx.cfg.enable_log_linecount = atoi(value);
74 else if (!strcmp(name, "max-stats")) 89 else if (!strcmp(name, "max-stats"))
75 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); 90 ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
76 else if (!strcmp(name, "cache-size")) 91 else if (!strcmp(name, "cache-size"))
77 ctx.cfg.cache_size = atoi(value); 92 ctx.cfg.cache_size = atoi(value);
78 else if (!strcmp(name, "cache-root")) 93 else if (!strcmp(name, "cache-root"))
79 ctx.cfg.cache_root = xstrdup(value); 94 ctx.cfg.cache_root = xstrdup(value);
80 else if (!strcmp(name, "cache-root-ttl")) 95 else if (!strcmp(name, "cache-root-ttl"))
81 ctx.cfg.cache_root_ttl = atoi(value); 96 ctx.cfg.cache_root_ttl = atoi(value);
82 else if (!strcmp(name, "cache-repo-ttl")) 97 else if (!strcmp(name, "cache-repo-ttl"))
83 ctx.cfg.cache_repo_ttl = atoi(value); 98 ctx.cfg.cache_repo_ttl = atoi(value);
84 else if (!strcmp(name, "cache-static-ttl")) 99 else if (!strcmp(name, "cache-static-ttl"))
85 ctx.cfg.cache_static_ttl = atoi(value); 100 ctx.cfg.cache_static_ttl = atoi(value);
86 else if (!strcmp(name, "cache-dynamic-ttl")) 101 else if (!strcmp(name, "cache-dynamic-ttl"))
87 ctx.cfg.cache_dynamic_ttl = atoi(value); 102 ctx.cfg.cache_dynamic_ttl = atoi(value);
103 else if (!strcmp(name, "commit-filter"))
104 ctx.cfg.commit_filter = new_filter(value, 0);
88 else if (!strcmp(name, "embedded")) 105 else if (!strcmp(name, "embedded"))
89 ctx.cfg.embedded = atoi(value); 106 ctx.cfg.embedded = atoi(value);
90 else if (!strcmp(name, "max-message-length")) 107 else if (!strcmp(name, "max-message-length"))
91 ctx.cfg.max_msg_len = atoi(value); 108 ctx.cfg.max_msg_len = atoi(value);
92 else if (!strcmp(name, "max-repodesc-length")) 109 else if (!strcmp(name, "max-repodesc-length"))
93 ctx.cfg.max_repodesc_len = atoi(value); 110 ctx.cfg.max_repodesc_len = atoi(value);
94 else if (!strcmp(name, "max-repo-count")) 111 else if (!strcmp(name, "max-repo-count"))
95 ctx.cfg.max_repo_count = atoi(value); 112 ctx.cfg.max_repo_count = atoi(value);
96 else if (!strcmp(name, "max-commit-count")) 113 else if (!strcmp(name, "max-commit-count"))
97 ctx.cfg.max_commit_count = atoi(value); 114 ctx.cfg.max_commit_count = atoi(value);
115 else if (!strcmp(name, "source-filter"))
116 ctx.cfg.source_filter = new_filter(value, 1);
98 else if (!strcmp(name, "summary-log")) 117 else if (!strcmp(name, "summary-log"))
99 ctx.cfg.summary_log = atoi(value); 118 ctx.cfg.summary_log = atoi(value);
100 else if (!strcmp(name, "summary-branches")) 119 else if (!strcmp(name, "summary-branches"))
101 ctx.cfg.summary_branches = atoi(value); 120 ctx.cfg.summary_branches = atoi(value);
102 else if (!strcmp(name, "summary-tags")) 121 else if (!strcmp(name, "summary-tags"))
103 ctx.cfg.summary_tags = atoi(value); 122 ctx.cfg.summary_tags = atoi(value);
104 else if (!strcmp(name, "agefile")) 123 else if (!strcmp(name, "agefile"))
105 ctx.cfg.agefile = xstrdup(value); 124 ctx.cfg.agefile = xstrdup(value);
106 else if (!strcmp(name, "renamelimit")) 125 else if (!strcmp(name, "renamelimit"))
107 ctx.cfg.renamelimit = atoi(value); 126 ctx.cfg.renamelimit = atoi(value);
108 else if (!strcmp(name, "robots")) 127 else if (!strcmp(name, "robots"))
109 ctx.cfg.robots = xstrdup(value); 128 ctx.cfg.robots = xstrdup(value);
110 else if (!strcmp(name, "clone-prefix")) 129 else if (!strcmp(name, "clone-prefix"))
111 ctx.cfg.clone_prefix = xstrdup(value); 130 ctx.cfg.clone_prefix = xstrdup(value);
112 else if (!strcmp(name, "local-time")) 131 else if (!strcmp(name, "local-time"))
113 ctx.cfg.local_time = atoi(value); 132 ctx.cfg.local_time = atoi(value);
114 else if (!prefixcmp(name, "mimetype.")) 133 else if (!prefixcmp(name, "mimetype."))
115 add_mimetype(name + 9, value); 134 add_mimetype(name + 9, value);
116 else if (!strcmp(name, "repo.group")) 135 else if (!strcmp(name, "repo.group"))
117 ctx.cfg.repo_group = xstrdup(value); 136 ctx.cfg.repo_group = xstrdup(value);
118 else if (!strcmp(name, "repo.url")) 137 else if (!strcmp(name, "repo.url"))
119 ctx.repo = cgit_add_repo(value); 138 ctx.repo = cgit_add_repo(value);
120 else if (!strcmp(name, "repo.name")) 139 else if (!strcmp(name, "repo.name"))
121 ctx.repo->name = xstrdup(value); 140 ctx.repo->name = xstrdup(value);
122 else if (ctx.repo && !strcmp(name, "repo.path")) 141 else if (ctx.repo && !strcmp(name, "repo.path"))
123 ctx.repo->path = trim_end(value, '/'); 142 ctx.repo->path = trim_end(value, '/');
124 else if (ctx.repo && !strcmp(name, "repo.clone-url")) 143 else if (ctx.repo && !strcmp(name, "repo.clone-url"))
125 ctx.repo->clone_url = xstrdup(value); 144 ctx.repo->clone_url = xstrdup(value);
126 else if (ctx.repo && !strcmp(name, "repo.desc")) 145 else if (ctx.repo && !strcmp(name, "repo.desc"))
127 ctx.repo->desc = xstrdup(value); 146 ctx.repo->desc = xstrdup(value);
128 else if (ctx.repo && !strcmp(name, "repo.owner")) 147 else if (ctx.repo && !strcmp(name, "repo.owner"))
129 ctx.repo->owner = xstrdup(value); 148 ctx.repo->owner = xstrdup(value);
130 else if (ctx.repo && !strcmp(name, "repo.defbranch")) 149 else if (ctx.repo && !strcmp(name, "repo.defbranch"))
131 ctx.repo->defbranch = xstrdup(value); 150 ctx.repo->defbranch = xstrdup(value);
132 else if (ctx.repo && !strcmp(name, "repo.snapshots")) 151 else if (ctx.repo && !strcmp(name, "repo.snapshots"))
133 ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ 152 ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
134 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) 153 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount"))
135 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); 154 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
136 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) 155 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount"))
137 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); 156 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
138 else if (ctx.repo && !strcmp(name, "repo.max-stats")) 157 else if (ctx.repo && !strcmp(name, "repo.max-stats"))
139 ctx.repo->max_stats = cgit_find_stats_period(value, NULL); 158 ctx.repo->max_stats = cgit_find_stats_period(value, NULL);
140 else if (ctx.repo && !strcmp(name, "repo.module-link")) 159 else if (ctx.repo && !strcmp(name, "repo.module-link"))
141 ctx.repo->module_link= xstrdup(value); 160 ctx.repo->module_link= xstrdup(value);
161 else if (ctx.repo && !strcmp(name, "repo.commit-filter"))
162 ctx.repo->commit_filter = new_filter(value, 0);
163 else if (ctx.repo && !strcmp(name, "repo.source-filter"))
164 ctx.repo->source_filter = new_filter(value, 1);
142 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { 165 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) {
143 if (*value == '/') 166 if (*value == '/')
144 ctx.repo->readme = xstrdup(value); 167 ctx.repo->readme = xstrdup(value);
145 else 168 else
146 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); 169 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value));
147 } else if (!strcmp(name, "include")) 170 } else if (!strcmp(name, "include"))
148 parse_configfile(value, config_cb); 171 parse_configfile(value, config_cb);
149} 172}
150 173
151static void querystring_cb(const char *name, const char *value) 174static void querystring_cb(const char *name, const char *value)
152{ 175{
153 if (!strcmp(name,"r")) { 176 if (!strcmp(name,"r")) {
154 ctx.qry.repo = xstrdup(value); 177 ctx.qry.repo = xstrdup(value);
155 ctx.repo = cgit_get_repoinfo(value); 178 ctx.repo = cgit_get_repoinfo(value);
156 } else if (!strcmp(name, "p")) { 179 } else if (!strcmp(name, "p")) {
157 ctx.qry.page = xstrdup(value); 180 ctx.qry.page = xstrdup(value);
158 } else if (!strcmp(name, "url")) { 181 } else if (!strcmp(name, "url")) {
159 ctx.qry.url = xstrdup(value); 182 ctx.qry.url = xstrdup(value);
160 cgit_parse_url(value); 183 cgit_parse_url(value);
161 } else if (!strcmp(name, "qt")) { 184 } else if (!strcmp(name, "qt")) {
162 ctx.qry.grep = xstrdup(value); 185 ctx.qry.grep = xstrdup(value);
163 } else if (!strcmp(name, "q")) { 186 } else if (!strcmp(name, "q")) {
164 ctx.qry.search = xstrdup(value); 187 ctx.qry.search = xstrdup(value);
165 } else if (!strcmp(name, "h")) { 188 } else if (!strcmp(name, "h")) {
166 ctx.qry.head = xstrdup(value); 189 ctx.qry.head = xstrdup(value);
167 ctx.qry.has_symref = 1; 190 ctx.qry.has_symref = 1;
168 } else if (!strcmp(name, "id")) { 191 } else if (!strcmp(name, "id")) {
169 ctx.qry.sha1 = xstrdup(value); 192 ctx.qry.sha1 = xstrdup(value);
170 ctx.qry.has_sha1 = 1; 193 ctx.qry.has_sha1 = 1;
171 } else if (!strcmp(name, "id2")) { 194 } else if (!strcmp(name, "id2")) {
172 ctx.qry.sha2 = xstrdup(value); 195 ctx.qry.sha2 = xstrdup(value);
173 ctx.qry.has_sha1 = 1; 196 ctx.qry.has_sha1 = 1;
174 } else if (!strcmp(name, "ofs")) { 197 } else if (!strcmp(name, "ofs")) {
175 ctx.qry.ofs = atoi(value); 198 ctx.qry.ofs = atoi(value);
176 } else if (!strcmp(name, "path")) { 199 } else if (!strcmp(name, "path")) {
177 ctx.qry.path = trim_end(value, '/'); 200 ctx.qry.path = trim_end(value, '/');
178 } else if (!strcmp(name, "name")) { 201 } else if (!strcmp(name, "name")) {
179 ctx.qry.name = xstrdup(value); 202 ctx.qry.name = xstrdup(value);
180 } else if (!strcmp(name, "mimetype")) { 203 } else if (!strcmp(name, "mimetype")) {
181 ctx.qry.mimetype = xstrdup(value); 204 ctx.qry.mimetype = xstrdup(value);
182 } else if (!strcmp(name, "s")){ 205 } else if (!strcmp(name, "s")){
183 ctx.qry.sort = xstrdup(value); 206 ctx.qry.sort = xstrdup(value);
184 } else if (!strcmp(name, "showmsg")) { 207 } else if (!strcmp(name, "showmsg")) {
185 ctx.qry.showmsg = atoi(value); 208 ctx.qry.showmsg = atoi(value);
186 } else if (!strcmp(name, "period")) { 209 } else if (!strcmp(name, "period")) {
187 ctx.qry.period = xstrdup(value); 210 ctx.qry.period = xstrdup(value);
188 } 211 }
189} 212}