author | Lars Hjemli <hjemli@gmail.com> | 2008-03-24 00:09:39 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-03-24 00:43:48 (UTC) |
commit | e0e4478e7b4812f822d60a13a33525f8e529e1e8 (patch) (unidiff) | |
tree | 577c3927deb9b122f940b69ca7db66afe2422814 /cgit.c | |
parent | b608e88adb6f77328288afb6dd0eddf674fc9b5b (diff) | |
download | cgit-e0e4478e7b4812f822d60a13a33525f8e529e1e8.zip cgit-e0e4478e7b4812f822d60a13a33525f8e529e1e8.tar.gz cgit-e0e4478e7b4812f822d60a13a33525f8e529e1e8.tar.bz2 |
Add command dispatcher
This simplifies the code in cgit.c and makes it easier to extend cgit with
new pages/commands.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 130 |
1 files changed, 50 insertions, 80 deletions
@@ -1,332 +1,302 @@ | |||
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 "cmd.h" | 10 | #include "cmd.h" |
11 | 11 | ||
12 | static int cgit_prepare_cache(struct cacheitem *item) | 12 | static int cgit_prepare_cache(struct cacheitem *item) |
13 | { | 13 | { |
14 | if (!ctx.repo && ctx.qry.repo) { | 14 | if (!ctx.repo && ctx.qry.repo) { |
15 | ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, | 15 | ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, |
16 | "Bad request"); | 16 | "Bad request"); |
17 | cgit_print_http_headers(&ctx); | 17 | cgit_print_http_headers(&ctx); |
18 | cgit_print_docstart(&ctx); | 18 | cgit_print_docstart(&ctx); |
19 | cgit_print_pageheader(&ctx); | 19 | cgit_print_pageheader(&ctx); |
20 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); | 20 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); |
21 | cgit_print_docend(); | 21 | cgit_print_docend(); |
22 | return 0; | 22 | return 0; |
23 | } | 23 | } |
24 | 24 | ||
25 | if (!ctx.repo) { | 25 | if (!ctx.repo) { |
26 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); | 26 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); |
27 | item->ttl = ctx.cfg.cache_root_ttl; | 27 | item->ttl = ctx.cfg.cache_root_ttl; |
28 | return 1; | 28 | return 1; |
29 | } | 29 | } |
30 | 30 | ||
31 | if (!cgit_cmd) { | 31 | if (!cgit_cmd) { |
32 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, | 32 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, |
33 | cache_safe_filename(ctx.repo->url), | 33 | cache_safe_filename(ctx.repo->url), |
34 | cache_safe_filename(ctx.qry.raw))); | 34 | cache_safe_filename(ctx.qry.raw))); |
35 | item->ttl = ctx.cfg.cache_repo_ttl; | 35 | item->ttl = ctx.cfg.cache_repo_ttl; |
36 | } else { | 36 | } else { |
37 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, | 37 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, |
38 | cache_safe_filename(ctx.repo->url), | 38 | cache_safe_filename(ctx.repo->url), |
39 | ctx.qry.page, | 39 | ctx.qry.page, |
40 | cache_safe_filename(ctx.qry.raw))); | 40 | cache_safe_filename(ctx.qry.raw))); |
41 | if (ctx.qry.has_symref) | 41 | if (ctx.qry.has_symref) |
42 | item->ttl = ctx.cfg.cache_dynamic_ttl; | 42 | item->ttl = ctx.cfg.cache_dynamic_ttl; |
43 | else if (ctx.qry.has_sha1) | 43 | else if (ctx.qry.has_sha1) |
44 | item->ttl = ctx.cfg.cache_static_ttl; | 44 | item->ttl = ctx.cfg.cache_static_ttl; |
45 | else | 45 | else |
46 | item->ttl = ctx.cfg.cache_repo_ttl; | 46 | item->ttl = ctx.cfg.cache_repo_ttl; |
47 | } | 47 | } |
48 | return 1; | 48 | return 1; |
49 | } | 49 | } |
50 | 50 | ||
51 | struct refmatch { | 51 | struct refmatch { |
52 | char *req_ref; | 52 | char *req_ref; |
53 | char *first_ref; | 53 | char *first_ref; |
54 | int match; | 54 | int match; |
55 | }; | 55 | }; |
56 | 56 | ||
57 | int find_current_ref(const char *refname, const unsigned char *sha1, | 57 | int find_current_ref(const char *refname, const unsigned char *sha1, |
58 | int flags, void *cb_data) | 58 | int flags, void *cb_data) |
59 | { | 59 | { |
60 | struct refmatch *info; | 60 | struct refmatch *info; |
61 | 61 | ||
62 | info = (struct refmatch *)cb_data; | 62 | info = (struct refmatch *)cb_data; |
63 | if (!strcmp(refname, info->req_ref)) | 63 | if (!strcmp(refname, info->req_ref)) |
64 | info->match = 1; | 64 | info->match = 1; |
65 | if (!info->first_ref) | 65 | if (!info->first_ref) |
66 | info->first_ref = xstrdup(refname); | 66 | info->first_ref = xstrdup(refname); |
67 | return info->match; | 67 | return info->match; |
68 | } | 68 | } |
69 | 69 | ||
70 | char *find_default_branch(struct cgit_repo *repo) | 70 | char *find_default_branch(struct cgit_repo *repo) |
71 | { | 71 | { |
72 | struct refmatch info; | 72 | struct refmatch info; |
73 | 73 | ||
74 | info.req_ref = repo->defbranch; | 74 | info.req_ref = repo->defbranch; |
75 | info.first_ref = NULL; | 75 | info.first_ref = NULL; |
76 | info.match = 0; | 76 | info.match = 0; |
77 | for_each_branch_ref(find_current_ref, &info); | 77 | for_each_branch_ref(find_current_ref, &info); |
78 | if (info.match) | 78 | if (info.match) |
79 | return info.req_ref; | 79 | return info.req_ref; |
80 | else | 80 | else |
81 | return info.first_ref; | 81 | return info.first_ref; |
82 | } | 82 | } |
83 | 83 | ||
84 | static void cgit_print_repo_page() | 84 | static int prepare_repo_cmd(struct cgit_context *ctx) |
85 | { | 85 | { |
86 | char *tmp; | 86 | char *tmp; |
87 | int show_search; | ||
88 | unsigned char sha1[20]; | 87 | unsigned char sha1[20]; |
89 | int nongit = 0; | 88 | int nongit = 0; |
90 | 89 | ||
91 | setenv("GIT_DIR", ctx.repo->path, 1); | 90 | setenv("GIT_DIR", ctx->repo->path, 1); |
92 | setup_git_directory_gently(&nongit); | 91 | setup_git_directory_gently(&nongit); |
93 | if (nongit) { | 92 | if (nongit) { |
94 | ctx.page.title = fmt("%s - %s", ctx.cfg.root_title, | 93 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, |
95 | "config error"); | 94 | "config error"); |
96 | tmp = fmt("Not a git repository: '%s'", ctx.repo->path); | 95 | tmp = fmt("Not a git repository: '%s'", ctx->repo->path); |
97 | ctx.repo = NULL; | 96 | ctx->repo = NULL; |
98 | cgit_print_http_headers(&ctx); | 97 | cgit_print_http_headers(ctx); |
99 | cgit_print_docstart(&ctx); | 98 | cgit_print_docstart(ctx); |
100 | cgit_print_pageheader(&ctx); | 99 | cgit_print_pageheader(ctx); |
101 | cgit_print_error(tmp); | 100 | cgit_print_error(tmp); |
102 | cgit_print_docend(); | 101 | cgit_print_docend(); |
103 | return; | 102 | return 1; |
104 | } | 103 | } |
104 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); | ||
105 | 105 | ||
106 | ctx.page.title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); | 106 | if (!ctx->qry.head) { |
107 | show_search = 0; | 107 | ctx->qry.head = xstrdup(find_default_branch(ctx->repo)); |
108 | 108 | ctx->repo->defbranch = ctx->qry.head; | |
109 | if (!ctx.qry.head) { | ||
110 | ctx.qry.head = xstrdup(find_default_branch(ctx.repo)); | ||
111 | ctx.repo->defbranch = ctx.qry.head; | ||
112 | } | 109 | } |
113 | 110 | ||
114 | if (!ctx.qry.head) { | 111 | if (!ctx->qry.head) { |
115 | cgit_print_http_headers(&ctx); | 112 | cgit_print_http_headers(ctx); |
116 | cgit_print_docstart(&ctx); | 113 | cgit_print_docstart(ctx); |
117 | cgit_print_pageheader(&ctx); | 114 | cgit_print_pageheader(ctx); |
118 | cgit_print_error("Repository seems to be empty"); | 115 | cgit_print_error("Repository seems to be empty"); |
119 | cgit_print_docend(); | 116 | cgit_print_docend(); |
120 | return; | 117 | return 1; |
121 | } | 118 | } |
122 | 119 | ||
123 | if (get_sha1(ctx.qry.head, sha1)) { | 120 | if (get_sha1(ctx->qry.head, sha1)) { |
124 | tmp = xstrdup(ctx.qry.head); | 121 | tmp = xstrdup(ctx->qry.head); |
125 | ctx.qry.head = ctx.repo->defbranch; | 122 | ctx->qry.head = ctx->repo->defbranch; |
126 | cgit_print_http_headers(&ctx); | 123 | cgit_print_http_headers(ctx); |
127 | cgit_print_docstart(&ctx); | 124 | cgit_print_docstart(ctx); |
128 | cgit_print_pageheader(&ctx); | 125 | cgit_print_pageheader(ctx); |
129 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | 126 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
130 | cgit_print_docend(); | 127 | cgit_print_docend(); |
131 | return; | 128 | return 1; |
132 | } | 129 | } |
130 | return 0; | ||
131 | } | ||
133 | 132 | ||
134 | if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) { | 133 | static void process_request(struct cgit_context *ctx) |
135 | cgit_print_snapshot(ctx.qry.head, ctx.qry.sha1, | 134 | { |
136 | cgit_repobasename(ctx.repo->url), | 135 | struct cgit_cmd *cmd; |
137 | ctx.qry.path, | 136 | |
138 | ctx.repo->snapshots ); | 137 | cmd = cgit_get_cmd(ctx); |
138 | if (!cmd) { | ||
139 | ctx->page.title = "cgit error"; | ||
140 | ctx->repo = NULL; | ||
141 | cgit_print_http_headers(ctx); | ||
142 | cgit_print_docstart(ctx); | ||
143 | cgit_print_pageheader(ctx); | ||
144 | cgit_print_error("Invalid request"); | ||
145 | cgit_print_docend(); | ||
139 | return; | 146 | return; |
140 | } | 147 | } |
141 | 148 | ||
142 | if (cgit_cmd == CMD_PATCH) { | 149 | if (cmd->want_repo && prepare_repo_cmd(ctx)) |
143 | cgit_print_patch(ctx.qry.sha1); | ||
144 | return; | 150 | return; |
145 | } | ||
146 | 151 | ||
147 | if (cgit_cmd == CMD_BLOB) { | 152 | if (cmd->want_layout) { |
148 | cgit_print_blob(ctx.qry.sha1, ctx.qry.path); | 153 | cgit_print_http_headers(ctx); |
149 | return; | 154 | cgit_print_docstart(ctx); |
155 | cgit_print_pageheader(ctx); | ||
150 | } | 156 | } |
151 | 157 | ||
152 | show_search = (cgit_cmd == CMD_LOG); | 158 | cmd->fn(ctx); |
153 | cgit_print_http_headers(&ctx); | ||
154 | cgit_print_docstart(&ctx); | ||
155 | if (!cgit_cmd) { | ||
156 | cgit_print_pageheader(&ctx); | ||
157 | cgit_print_summary(); | ||
158 | cgit_print_docend(); | ||
159 | return; | ||
160 | } | ||
161 | 159 | ||
162 | cgit_print_pageheader(&ctx); | 160 | if (cmd->want_layout) |
163 | 161 | cgit_print_docend(); | |
164 | switch(cgit_cmd) { | ||
165 | case CMD_LOG: | ||
166 | cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, | ||
167 | ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, | ||
168 | ctx.qry.path, 1); | ||
169 | break; | ||
170 | case CMD_TREE: | ||
171 | cgit_print_tree(ctx.qry.sha1, ctx.qry.path); | ||
172 | break; | ||
173 | case CMD_COMMIT: | ||
174 | cgit_print_commit(ctx.qry.sha1); | ||
175 | break; | ||
176 | case CMD_REFS: | ||
177 | cgit_print_refs(); | ||
178 | break; | ||
179 | case CMD_TAG: | ||
180 | cgit_print_tag(ctx.qry.sha1); | ||
181 | break; | ||
182 | case CMD_DIFF: | ||
183 | cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); | ||
184 | break; | ||
185 | default: | ||
186 | cgit_print_error("Invalid request"); | ||
187 | } | ||
188 | cgit_print_docend(); | ||
189 | } | 162 | } |
190 | 163 | ||
191 | static long ttl_seconds(long ttl) | 164 | static long ttl_seconds(long ttl) |
192 | { | 165 | { |
193 | if (ttl<0) | 166 | if (ttl<0) |
194 | return 60 * 60 * 24 * 365; | 167 | return 60 * 60 * 24 * 365; |
195 | else | 168 | else |
196 | return ttl * 60; | 169 | return ttl * 60; |
197 | } | 170 | } |
198 | 171 | ||
199 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 172 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
200 | { | 173 | { |
201 | int stdout2; | 174 | int stdout2; |
202 | 175 | ||
203 | if (use_cache) { | 176 | if (use_cache) { |
204 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 177 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
205 | "Preserving STDOUT"); | 178 | "Preserving STDOUT"); |
206 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 179 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
207 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 180 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
208 | } | 181 | } |
209 | 182 | ||
210 | ctx.page.modified = time(NULL); | 183 | ctx.page.modified = time(NULL); |
211 | ctx.page.expires = ctx.page.modified + ttl_seconds(item->ttl); | 184 | ctx.page.expires = ctx.page.modified + ttl_seconds(item->ttl); |
212 | if (ctx.repo) | 185 | process_request(&ctx); |
213 | cgit_print_repo_page(); | ||
214 | else | ||
215 | cgit_print_repolist(); | ||
216 | 186 | ||
217 | if (use_cache) { | 187 | if (use_cache) { |
218 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 188 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
219 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 189 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
220 | "Restoring original STDOUT"); | 190 | "Restoring original STDOUT"); |
221 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 191 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
222 | } | 192 | } |
223 | } | 193 | } |
224 | 194 | ||
225 | static void cgit_check_cache(struct cacheitem *item) | 195 | static void cgit_check_cache(struct cacheitem *item) |
226 | { | 196 | { |
227 | int i = 0; | 197 | int i = 0; |
228 | 198 | ||
229 | top: | 199 | top: |
230 | if (++i > ctx.cfg.max_lock_attempts) { | 200 | if (++i > ctx.cfg.max_lock_attempts) { |
231 | die("cgit_refresh_cache: unable to lock %s: %s", | 201 | die("cgit_refresh_cache: unable to lock %s: %s", |
232 | item->name, strerror(errno)); | 202 | item->name, strerror(errno)); |
233 | } | 203 | } |
234 | if (!cache_exist(item)) { | 204 | if (!cache_exist(item)) { |
235 | if (!cache_lock(item)) { | 205 | if (!cache_lock(item)) { |
236 | sleep(1); | 206 | sleep(1); |
237 | goto top; | 207 | goto top; |
238 | } | 208 | } |
239 | if (!cache_exist(item)) { | 209 | if (!cache_exist(item)) { |
240 | cgit_fill_cache(item, 1); | 210 | cgit_fill_cache(item, 1); |
241 | cache_unlock(item); | 211 | cache_unlock(item); |
242 | } else { | 212 | } else { |
243 | cache_cancel_lock(item); | 213 | cache_cancel_lock(item); |
244 | } | 214 | } |
245 | } else if (cache_expired(item) && cache_lock(item)) { | 215 | } else if (cache_expired(item) && cache_lock(item)) { |
246 | if (cache_expired(item)) { | 216 | if (cache_expired(item)) { |
247 | cgit_fill_cache(item, 1); | 217 | cgit_fill_cache(item, 1); |
248 | cache_unlock(item); | 218 | cache_unlock(item); |
249 | } else { | 219 | } else { |
250 | cache_cancel_lock(item); | 220 | cache_cancel_lock(item); |
251 | } | 221 | } |
252 | } | 222 | } |
253 | } | 223 | } |
254 | 224 | ||
255 | static void cgit_print_cache(struct cacheitem *item) | 225 | static void cgit_print_cache(struct cacheitem *item) |
256 | { | 226 | { |
257 | static char buf[4096]; | 227 | static char buf[4096]; |
258 | ssize_t i; | 228 | ssize_t i; |
259 | 229 | ||
260 | int fd = open(item->name, O_RDONLY); | 230 | int fd = open(item->name, O_RDONLY); |
261 | if (fd<0) | 231 | if (fd<0) |
262 | die("Unable to open cached file %s", item->name); | 232 | die("Unable to open cached file %s", item->name); |
263 | 233 | ||
264 | while((i=read(fd, buf, sizeof(buf))) > 0) | 234 | while((i=read(fd, buf, sizeof(buf))) > 0) |
265 | write(STDOUT_FILENO, buf, i); | 235 | write(STDOUT_FILENO, buf, i); |
266 | 236 | ||
267 | close(fd); | 237 | close(fd); |
268 | } | 238 | } |
269 | 239 | ||
270 | static void cgit_parse_args(int argc, const char **argv) | 240 | static void cgit_parse_args(int argc, const char **argv) |
271 | { | 241 | { |
272 | int i; | 242 | int i; |
273 | 243 | ||
274 | for (i = 1; i < argc; i++) { | 244 | for (i = 1; i < argc; i++) { |
275 | if (!strncmp(argv[i], "--cache=", 8)) { | 245 | if (!strncmp(argv[i], "--cache=", 8)) { |
276 | ctx.cfg.cache_root = xstrdup(argv[i]+8); | 246 | ctx.cfg.cache_root = xstrdup(argv[i]+8); |
277 | } | 247 | } |
278 | if (!strcmp(argv[i], "--nocache")) { | 248 | if (!strcmp(argv[i], "--nocache")) { |
279 | ctx.cfg.nocache = 1; | 249 | ctx.cfg.nocache = 1; |
280 | } | 250 | } |
281 | if (!strncmp(argv[i], "--query=", 8)) { | 251 | if (!strncmp(argv[i], "--query=", 8)) { |
282 | ctx.qry.raw = xstrdup(argv[i]+8); | 252 | ctx.qry.raw = xstrdup(argv[i]+8); |
283 | } | 253 | } |
284 | if (!strncmp(argv[i], "--repo=", 7)) { | 254 | if (!strncmp(argv[i], "--repo=", 7)) { |
285 | ctx.qry.repo = xstrdup(argv[i]+7); | 255 | ctx.qry.repo = xstrdup(argv[i]+7); |
286 | } | 256 | } |
287 | if (!strncmp(argv[i], "--page=", 7)) { | 257 | if (!strncmp(argv[i], "--page=", 7)) { |
288 | ctx.qry.page = xstrdup(argv[i]+7); | 258 | ctx.qry.page = xstrdup(argv[i]+7); |
289 | } | 259 | } |
290 | if (!strncmp(argv[i], "--head=", 7)) { | 260 | if (!strncmp(argv[i], "--head=", 7)) { |
291 | ctx.qry.head = xstrdup(argv[i]+7); | 261 | ctx.qry.head = xstrdup(argv[i]+7); |
292 | ctx.qry.has_symref = 1; | 262 | ctx.qry.has_symref = 1; |
293 | } | 263 | } |
294 | if (!strncmp(argv[i], "--sha1=", 7)) { | 264 | if (!strncmp(argv[i], "--sha1=", 7)) { |
295 | ctx.qry.sha1 = xstrdup(argv[i]+7); | 265 | ctx.qry.sha1 = xstrdup(argv[i]+7); |
296 | ctx.qry.has_sha1 = 1; | 266 | ctx.qry.has_sha1 = 1; |
297 | } | 267 | } |
298 | if (!strncmp(argv[i], "--ofs=", 6)) { | 268 | if (!strncmp(argv[i], "--ofs=", 6)) { |
299 | ctx.qry.ofs = atoi(argv[i]+6); | 269 | ctx.qry.ofs = atoi(argv[i]+6); |
300 | } | 270 | } |
301 | } | 271 | } |
302 | } | 272 | } |
303 | 273 | ||
304 | int main(int argc, const char **argv) | 274 | int main(int argc, const char **argv) |
305 | { | 275 | { |
306 | struct cacheitem item; | 276 | struct cacheitem item; |
307 | const char *cgit_config_env = getenv("CGIT_CONFIG"); | 277 | const char *cgit_config_env = getenv("CGIT_CONFIG"); |
308 | 278 | ||
309 | cgit_prepare_context(&ctx); | 279 | cgit_prepare_context(&ctx); |
310 | item.st.st_mtime = time(NULL); | 280 | item.st.st_mtime = time(NULL); |
311 | cgit_repolist.length = 0; | 281 | cgit_repolist.length = 0; |
312 | cgit_repolist.count = 0; | 282 | cgit_repolist.count = 0; |
313 | cgit_repolist.repos = NULL; | 283 | cgit_repolist.repos = NULL; |
314 | 284 | ||
315 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, | 285 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
316 | cgit_global_config_cb); | 286 | cgit_global_config_cb); |
317 | if (getenv("SCRIPT_NAME")) | 287 | if (getenv("SCRIPT_NAME")) |
318 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); | 288 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
319 | if (getenv("QUERY_STRING")) | 289 | if (getenv("QUERY_STRING")) |
320 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); | 290 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
321 | cgit_parse_args(argc, argv); | 291 | cgit_parse_args(argc, argv); |
322 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); | 292 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); |
323 | if (!cgit_prepare_cache(&item)) | 293 | if (!cgit_prepare_cache(&item)) |
324 | return 0; | 294 | return 0; |
325 | if (ctx.cfg.nocache) { | 295 | if (ctx.cfg.nocache) { |
326 | cgit_fill_cache(&item, 0); | 296 | cgit_fill_cache(&item, 0); |
327 | } else { | 297 | } else { |
328 | cgit_check_cache(&item); | 298 | cgit_check_cache(&item); |
329 | cgit_print_cache(&item); | 299 | cgit_print_cache(&item); |
330 | } | 300 | } |
331 | return 0; | 301 | return 0; |
332 | } | 302 | } |