|
diff --git a/shared.c b/shared.c index 06693b0..077934f 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -57,169 +57,176 @@ char *cgit_query_path = NULL; |
57 | char *cgit_query_name = NULL; |
57 | char *cgit_query_name = NULL; |
58 | int cgit_query_ofs = 0; |
58 | int cgit_query_ofs = 0; |
59 | |
59 | |
60 | int htmlfd = 0; |
60 | int htmlfd = 0; |
61 | |
61 | |
62 | |
62 | |
63 | int cgit_get_cmd_index(const char *cmd) |
63 | int cgit_get_cmd_index(const char *cmd) |
64 | { |
64 | { |
65 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
65 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
66 | "snapshot", "tag", NULL}; |
66 | "snapshot", "tag", NULL}; |
67 | int i; |
67 | int i; |
68 | |
68 | |
69 | for(i = 0; cmds[i]; i++) |
69 | for(i = 0; cmds[i]; i++) |
70 | if (!strcmp(cmd, cmds[i])) |
70 | if (!strcmp(cmd, cmds[i])) |
71 | return i + 1; |
71 | return i + 1; |
72 | return 0; |
72 | return 0; |
73 | } |
73 | } |
74 | |
74 | |
75 | int chk_zero(int result, char *msg) |
75 | int chk_zero(int result, char *msg) |
76 | { |
76 | { |
77 | if (result != 0) |
77 | if (result != 0) |
78 | die("%s: %s", msg, strerror(errno)); |
78 | die("%s: %s", msg, strerror(errno)); |
79 | return result; |
79 | return result; |
80 | } |
80 | } |
81 | |
81 | |
82 | int chk_positive(int result, char *msg) |
82 | int chk_positive(int result, char *msg) |
83 | { |
83 | { |
84 | if (result <= 0) |
84 | if (result <= 0) |
85 | die("%s: %s", msg, strerror(errno)); |
85 | die("%s: %s", msg, strerror(errno)); |
86 | return result; |
86 | return result; |
87 | } |
87 | } |
88 | |
88 | |
| |
89 | int chk_non_negative(int result, char *msg) |
| |
90 | { |
| |
91 | if (result < 0) |
| |
92 | die("%s: %s",msg, strerror(errno)); |
| |
93 | return result; |
| |
94 | } |
| |
95 | |
89 | struct repoinfo *add_repo(const char *url) |
96 | struct repoinfo *add_repo(const char *url) |
90 | { |
97 | { |
91 | struct repoinfo *ret; |
98 | struct repoinfo *ret; |
92 | |
99 | |
93 | if (++cgit_repolist.count > cgit_repolist.length) { |
100 | if (++cgit_repolist.count > cgit_repolist.length) { |
94 | if (cgit_repolist.length == 0) |
101 | if (cgit_repolist.length == 0) |
95 | cgit_repolist.length = 8; |
102 | cgit_repolist.length = 8; |
96 | else |
103 | else |
97 | cgit_repolist.length *= 2; |
104 | cgit_repolist.length *= 2; |
98 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
105 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
99 | cgit_repolist.length * |
106 | cgit_repolist.length * |
100 | sizeof(struct repoinfo)); |
107 | sizeof(struct repoinfo)); |
101 | } |
108 | } |
102 | |
109 | |
103 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
110 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
104 | ret->url = xstrdup(url); |
111 | ret->url = xstrdup(url); |
105 | ret->name = ret->url; |
112 | ret->name = ret->url; |
106 | ret->path = NULL; |
113 | ret->path = NULL; |
107 | ret->desc = NULL; |
114 | ret->desc = NULL; |
108 | ret->owner = NULL; |
115 | ret->owner = NULL; |
109 | ret->group = cgit_repo_group; |
116 | ret->group = cgit_repo_group; |
110 | ret->defbranch = "master"; |
117 | ret->defbranch = "master"; |
111 | ret->snapshots = cgit_snapshots; |
118 | ret->snapshots = cgit_snapshots; |
112 | ret->enable_log_filecount = cgit_enable_log_filecount; |
119 | ret->enable_log_filecount = cgit_enable_log_filecount; |
113 | ret->enable_log_linecount = cgit_enable_log_linecount; |
120 | ret->enable_log_linecount = cgit_enable_log_linecount; |
114 | ret->module_link = cgit_module_link; |
121 | ret->module_link = cgit_module_link; |
115 | ret->readme = NULL; |
122 | ret->readme = NULL; |
116 | return ret; |
123 | return ret; |
117 | } |
124 | } |
118 | |
125 | |
119 | struct repoinfo *cgit_get_repoinfo(const char *url) |
126 | struct repoinfo *cgit_get_repoinfo(const char *url) |
120 | { |
127 | { |
121 | int i; |
128 | int i; |
122 | struct repoinfo *repo; |
129 | struct repoinfo *repo; |
123 | |
130 | |
124 | for (i=0; i<cgit_repolist.count; i++) { |
131 | for (i=0; i<cgit_repolist.count; i++) { |
125 | repo = &cgit_repolist.repos[i]; |
132 | repo = &cgit_repolist.repos[i]; |
126 | if (!strcmp(repo->url, url)) |
133 | if (!strcmp(repo->url, url)) |
127 | return repo; |
134 | return repo; |
128 | } |
135 | } |
129 | return NULL; |
136 | return NULL; |
130 | } |
137 | } |
131 | |
138 | |
132 | void cgit_global_config_cb(const char *name, const char *value) |
139 | void cgit_global_config_cb(const char *name, const char *value) |
133 | { |
140 | { |
134 | if (!strcmp(name, "root-title")) |
141 | if (!strcmp(name, "root-title")) |
135 | cgit_root_title = xstrdup(value); |
142 | cgit_root_title = xstrdup(value); |
136 | else if (!strcmp(name, "css")) |
143 | else if (!strcmp(name, "css")) |
137 | cgit_css = xstrdup(value); |
144 | cgit_css = xstrdup(value); |
138 | else if (!strcmp(name, "logo")) |
145 | else if (!strcmp(name, "logo")) |
139 | cgit_logo = xstrdup(value); |
146 | cgit_logo = xstrdup(value); |
140 | else if (!strcmp(name, "index-header")) |
147 | else if (!strcmp(name, "index-header")) |
141 | cgit_index_header = xstrdup(value); |
148 | cgit_index_header = xstrdup(value); |
142 | else if (!strcmp(name, "logo-link")) |
149 | else if (!strcmp(name, "logo-link")) |
143 | cgit_logo_link = xstrdup(value); |
150 | cgit_logo_link = xstrdup(value); |
144 | else if (!strcmp(name, "module-link")) |
151 | else if (!strcmp(name, "module-link")) |
145 | cgit_module_link = xstrdup(value); |
152 | cgit_module_link = xstrdup(value); |
146 | else if (!strcmp(name, "virtual-root")) |
153 | else if (!strcmp(name, "virtual-root")) |
147 | cgit_virtual_root = xstrdup(value); |
154 | cgit_virtual_root = xstrdup(value); |
148 | else if (!strcmp(name, "nocache")) |
155 | else if (!strcmp(name, "nocache")) |
149 | cgit_nocache = atoi(value); |
156 | cgit_nocache = atoi(value); |
150 | else if (!strcmp(name, "snapshots")) |
157 | else if (!strcmp(name, "snapshots")) |
151 | cgit_snapshots = atoi(value); |
158 | cgit_snapshots = cgit_parse_snapshots_mask(value); |
152 | else if (!strcmp(name, "enable-index-links")) |
159 | else if (!strcmp(name, "enable-index-links")) |
153 | cgit_enable_index_links = atoi(value); |
160 | cgit_enable_index_links = atoi(value); |
154 | else if (!strcmp(name, "enable-log-filecount")) |
161 | else if (!strcmp(name, "enable-log-filecount")) |
155 | cgit_enable_log_filecount = atoi(value); |
162 | cgit_enable_log_filecount = atoi(value); |
156 | else if (!strcmp(name, "enable-log-linecount")) |
163 | else if (!strcmp(name, "enable-log-linecount")) |
157 | cgit_enable_log_linecount = atoi(value); |
164 | cgit_enable_log_linecount = atoi(value); |
158 | else if (!strcmp(name, "cache-root")) |
165 | else if (!strcmp(name, "cache-root")) |
159 | cgit_cache_root = xstrdup(value); |
166 | cgit_cache_root = xstrdup(value); |
160 | else if (!strcmp(name, "cache-root-ttl")) |
167 | else if (!strcmp(name, "cache-root-ttl")) |
161 | cgit_cache_root_ttl = atoi(value); |
168 | cgit_cache_root_ttl = atoi(value); |
162 | else if (!strcmp(name, "cache-repo-ttl")) |
169 | else if (!strcmp(name, "cache-repo-ttl")) |
163 | cgit_cache_repo_ttl = atoi(value); |
170 | cgit_cache_repo_ttl = atoi(value); |
164 | else if (!strcmp(name, "cache-static-ttl")) |
171 | else if (!strcmp(name, "cache-static-ttl")) |
165 | cgit_cache_static_ttl = atoi(value); |
172 | cgit_cache_static_ttl = atoi(value); |
166 | else if (!strcmp(name, "cache-dynamic-ttl")) |
173 | else if (!strcmp(name, "cache-dynamic-ttl")) |
167 | cgit_cache_dynamic_ttl = atoi(value); |
174 | cgit_cache_dynamic_ttl = atoi(value); |
168 | else if (!strcmp(name, "max-message-length")) |
175 | else if (!strcmp(name, "max-message-length")) |
169 | cgit_max_msg_len = atoi(value); |
176 | cgit_max_msg_len = atoi(value); |
170 | else if (!strcmp(name, "max-repodesc-length")) |
177 | else if (!strcmp(name, "max-repodesc-length")) |
171 | cgit_max_repodesc_len = atoi(value); |
178 | cgit_max_repodesc_len = atoi(value); |
172 | else if (!strcmp(name, "max-commit-count")) |
179 | else if (!strcmp(name, "max-commit-count")) |
173 | cgit_max_commit_count = atoi(value); |
180 | cgit_max_commit_count = atoi(value); |
174 | else if (!strcmp(name, "summary-log")) |
181 | else if (!strcmp(name, "summary-log")) |
175 | cgit_summary_log = atoi(value); |
182 | cgit_summary_log = atoi(value); |
176 | else if (!strcmp(name, "agefile")) |
183 | else if (!strcmp(name, "agefile")) |
177 | cgit_agefile = xstrdup(value); |
184 | cgit_agefile = xstrdup(value); |
178 | else if (!strcmp(name, "repo.group")) |
185 | else if (!strcmp(name, "repo.group")) |
179 | cgit_repo_group = xstrdup(value); |
186 | cgit_repo_group = xstrdup(value); |
180 | else if (!strcmp(name, "repo.url")) |
187 | else if (!strcmp(name, "repo.url")) |
181 | cgit_repo = add_repo(value); |
188 | cgit_repo = add_repo(value); |
182 | else if (!strcmp(name, "repo.name")) |
189 | else if (!strcmp(name, "repo.name")) |
183 | cgit_repo->name = xstrdup(value); |
190 | cgit_repo->name = xstrdup(value); |
184 | else if (cgit_repo && !strcmp(name, "repo.path")) |
191 | else if (cgit_repo && !strcmp(name, "repo.path")) |
185 | cgit_repo->path = xstrdup(value); |
192 | cgit_repo->path = xstrdup(value); |
186 | else if (cgit_repo && !strcmp(name, "repo.desc")) |
193 | else if (cgit_repo && !strcmp(name, "repo.desc")) |
187 | cgit_repo->desc = xstrdup(value); |
194 | cgit_repo->desc = xstrdup(value); |
188 | else if (cgit_repo && !strcmp(name, "repo.owner")) |
195 | else if (cgit_repo && !strcmp(name, "repo.owner")) |
189 | cgit_repo->owner = xstrdup(value); |
196 | cgit_repo->owner = xstrdup(value); |
190 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) |
197 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) |
191 | cgit_repo->defbranch = xstrdup(value); |
198 | cgit_repo->defbranch = xstrdup(value); |
192 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) |
199 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) |
193 | cgit_repo->snapshots = cgit_snapshots * atoi(value); |
200 | cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
194 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) |
201 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) |
195 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); |
202 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); |
196 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) |
203 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) |
197 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); |
204 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); |
198 | else if (cgit_repo && !strcmp(name, "repo.module-link")) |
205 | else if (cgit_repo && !strcmp(name, "repo.module-link")) |
199 | cgit_repo->module_link= xstrdup(value); |
206 | cgit_repo->module_link= xstrdup(value); |
200 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { |
207 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { |
201 | if (*value == '/') |
208 | if (*value == '/') |
202 | cgit_repo->readme = xstrdup(value); |
209 | cgit_repo->readme = xstrdup(value); |
203 | else |
210 | else |
204 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); |
211 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); |
205 | } else if (!strcmp(name, "include")) |
212 | } else if (!strcmp(name, "include")) |
206 | cgit_read_config(value, cgit_global_config_cb); |
213 | cgit_read_config(value, cgit_global_config_cb); |
207 | } |
214 | } |
208 | |
215 | |
209 | void cgit_querystring_cb(const char *name, const char *value) |
216 | void cgit_querystring_cb(const char *name, const char *value) |
210 | { |
217 | { |
211 | if (!strcmp(name,"r")) { |
218 | if (!strcmp(name,"r")) { |
212 | cgit_query_repo = xstrdup(value); |
219 | cgit_query_repo = xstrdup(value); |
213 | cgit_repo = cgit_get_repoinfo(value); |
220 | cgit_repo = cgit_get_repoinfo(value); |
214 | } else if (!strcmp(name, "p")) { |
221 | } else if (!strcmp(name, "p")) { |
215 | cgit_query_page = xstrdup(value); |
222 | cgit_query_page = xstrdup(value); |
216 | cgit_cmd = cgit_get_cmd_index(value); |
223 | cgit_cmd = cgit_get_cmd_index(value); |
217 | } else if (!strcmp(name, "url")) { |
224 | } else if (!strcmp(name, "url")) { |
218 | cgit_parse_url(value); |
225 | cgit_parse_url(value); |
219 | } else if (!strcmp(name, "q")) { |
226 | } else if (!strcmp(name, "q")) { |
220 | cgit_query_search = xstrdup(value); |
227 | cgit_query_search = xstrdup(value); |
221 | } else if (!strcmp(name, "h")) { |
228 | } else if (!strcmp(name, "h")) { |
222 | cgit_query_head = xstrdup(value); |
229 | cgit_query_head = xstrdup(value); |
223 | cgit_query_has_symref = 1; |
230 | cgit_query_has_symref = 1; |
224 | } else if (!strcmp(name, "id")) { |
231 | } else if (!strcmp(name, "id")) { |
225 | cgit_query_sha1 = xstrdup(value); |
232 | cgit_query_sha1 = xstrdup(value); |
|