summaryrefslogtreecommitdiffabout
path: root/cgit.c
Unidiff
Diffstat (limited to 'cgit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/cgit.c b/cgit.c
index 2036ceb..ac882c3 100644
--- a/cgit.c
+++ b/cgit.c
@@ -287,100 +287,100 @@ static void process_request(void *cbdata)
287 return; 287 return;
288 } 288 }
289 289
290 if (ctx->repo && prepare_repo_cmd(ctx)) 290 if (ctx->repo && prepare_repo_cmd(ctx))
291 return; 291 return;
292 292
293 if (cmd->want_layout) { 293 if (cmd->want_layout) {
294 cgit_print_http_headers(ctx); 294 cgit_print_http_headers(ctx);
295 cgit_print_docstart(ctx); 295 cgit_print_docstart(ctx);
296 cgit_print_pageheader(ctx); 296 cgit_print_pageheader(ctx);
297 } 297 }
298 298
299 cmd->fn(ctx); 299 cmd->fn(ctx);
300 300
301 if (cmd->want_layout) 301 if (cmd->want_layout)
302 cgit_print_docend(); 302 cgit_print_docend();
303} 303}
304 304
305static void cgit_parse_args(int argc, const char **argv) 305static void cgit_parse_args(int argc, const char **argv)
306{ 306{
307 int i; 307 int i;
308 308
309 for (i = 1; i < argc; i++) { 309 for (i = 1; i < argc; i++) {
310 if (!strncmp(argv[i], "--cache=", 8)) { 310 if (!strncmp(argv[i], "--cache=", 8)) {
311 ctx.cfg.cache_root = xstrdup(argv[i]+8); 311 ctx.cfg.cache_root = xstrdup(argv[i]+8);
312 } 312 }
313 if (!strcmp(argv[i], "--nocache")) { 313 if (!strcmp(argv[i], "--nocache")) {
314 ctx.cfg.nocache = 1; 314 ctx.cfg.nocache = 1;
315 } 315 }
316 if (!strncmp(argv[i], "--query=", 8)) { 316 if (!strncmp(argv[i], "--query=", 8)) {
317 ctx.qry.raw = xstrdup(argv[i]+8); 317 ctx.qry.raw = xstrdup(argv[i]+8);
318 } 318 }
319 if (!strncmp(argv[i], "--repo=", 7)) { 319 if (!strncmp(argv[i], "--repo=", 7)) {
320 ctx.qry.repo = xstrdup(argv[i]+7); 320 ctx.qry.repo = xstrdup(argv[i]+7);
321 } 321 }
322 if (!strncmp(argv[i], "--page=", 7)) { 322 if (!strncmp(argv[i], "--page=", 7)) {
323 ctx.qry.page = xstrdup(argv[i]+7); 323 ctx.qry.page = xstrdup(argv[i]+7);
324 } 324 }
325 if (!strncmp(argv[i], "--head=", 7)) { 325 if (!strncmp(argv[i], "--head=", 7)) {
326 ctx.qry.head = xstrdup(argv[i]+7); 326 ctx.qry.head = xstrdup(argv[i]+7);
327 ctx.qry.has_symref = 1; 327 ctx.qry.has_symref = 1;
328 } 328 }
329 if (!strncmp(argv[i], "--sha1=", 7)) { 329 if (!strncmp(argv[i], "--sha1=", 7)) {
330 ctx.qry.sha1 = xstrdup(argv[i]+7); 330 ctx.qry.sha1 = xstrdup(argv[i]+7);
331 ctx.qry.has_sha1 = 1; 331 ctx.qry.has_sha1 = 1;
332 } 332 }
333 if (!strncmp(argv[i], "--ofs=", 6)) { 333 if (!strncmp(argv[i], "--ofs=", 6)) {
334 ctx.qry.ofs = atoi(argv[i]+6); 334 ctx.qry.ofs = atoi(argv[i]+6);
335 } 335 }
336 } 336 }
337} 337}
338 338
339static int calc_ttl() 339static int calc_ttl()
340{ 340{
341 if (!ctx.repo) 341 if (!ctx.repo)
342 return ctx.cfg.cache_root_ttl; 342 return ctx.cfg.cache_root_ttl;
343 343
344 if (!ctx.qry.page) 344 if (!ctx.qry.page)
345 return ctx.cfg.cache_repo_ttl; 345 return ctx.cfg.cache_repo_ttl;
346 346
347 if (ctx.qry.has_symref) 347 if (ctx.qry.has_symref)
348 return ctx.cfg.cache_dynamic_ttl; 348 return ctx.cfg.cache_dynamic_ttl;
349 349
350 if (ctx.qry.has_sha1) 350 if (ctx.qry.has_sha1)
351 return ctx.cfg.cache_static_ttl; 351 return ctx.cfg.cache_static_ttl;
352 352
353 return ctx.cfg.cache_repo_ttl; 353 return ctx.cfg.cache_repo_ttl;
354} 354}
355 355
356int main(int argc, const char **argv) 356int main(int argc, const char **argv)
357{ 357{
358 const char *cgit_config_env = getenv("CGIT_CONFIG"); 358 const char *cgit_config_env = getenv("CGIT_CONFIG");
359 int err, ttl; 359 int err, ttl;
360 360
361 prepare_context(&ctx); 361 prepare_context(&ctx);
362 cgit_repolist.length = 0; 362 cgit_repolist.length = 0;
363 cgit_repolist.count = 0; 363 cgit_repolist.count = 0;
364 cgit_repolist.repos = NULL; 364 cgit_repolist.repos = NULL;
365 365
366 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, 366 parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
367 config_cb); 367 config_cb);
368 ctx.repo = NULL; 368 ctx.repo = NULL;
369 if (getenv("SCRIPT_NAME")) 369 if (getenv("SCRIPT_NAME"))
370 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); 370 ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME"));
371 if (getenv("QUERY_STRING")) 371 if (getenv("QUERY_STRING"))
372 ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); 372 ctx.qry.raw = xstrdup(getenv("QUERY_STRING"));
373 cgit_parse_args(argc, argv); 373 cgit_parse_args(argc, argv);
374 http_parse_querystring(ctx.qry.raw, querystring_cb); 374 http_parse_querystring(ctx.qry.raw, querystring_cb);
375 375
376 ttl = calc_ttl(); 376 ttl = calc_ttl();
377 ctx.page.expires += ttl*60; 377 ctx.page.expires += ttl*60;
378 if (ctx.cfg.nocache) 378 if (ctx.cfg.nocache)
379 ctx.cfg.cache_size = 0; 379 ctx.cfg.cache_size = 0;
380 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, 380 err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
381 ctx.qry.raw, ttl, process_request, &ctx); 381 ctx.qry.raw, ttl, process_request, &ctx);
382 if (err) 382 if (err)
383 cache_log("[cgit] error %d - %s\n", 383 cgit_print_error(fmt("Error processing page: %s (%d)",
384 err, strerror(err)); 384 strerror(err), err));
385 return err; 385 return err;
386} 386}