diff options
author | Lukas Fleischer <cgit@cryptocrack.de> | 2014-01-16 05:53:15 (JST) |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2014-01-17 08:44:54 (JST) |
commit | f60ffa143cca61e9729ac71033e1a556cf422871 (patch) | |
tree | ff9122fef2779ddea8e37806cc66dc67b63df99f | |
parent | a431326e8fab8153905fbde036dd3c9fb4cc8eaa (diff) | |
download | cgit-f60ffa143cca61e9729ac71033e1a556cf422871.zip cgit-f60ffa143cca61e9729ac71033e1a556cf422871.tar.gz |
Switch to exclusively using global ctx
Drop the context parameter from the following functions (and all static
helpers used by them) and use the global context instead:
* cgit_print_http_headers()
* cgit_print_docstart()
* cgit_print_pageheader()
Remove context parameter from all commands
Drop the context parameter from the following functions (and all static
helpers used by them) and use the global context instead:
* cgit_get_cmd()
* All cgit command functions.
* cgit_clone_info()
* cgit_clone_objects()
* cgit_clone_head()
* cgit_print_plain()
* cgit_show_stats()
In initialization routines, use the global context variable instead of
passing a pointer around locally.
Remove callback data parameter for cache slots
This is no longer needed since the context is always read from the
global context variable.
Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rw-r--r-- | cache.c | 14 | ||||
-rw-r--r-- | cache.h | 5 | ||||
-rw-r--r-- | cgit.c | 322 | ||||
-rw-r--r-- | cmd.c | 102 | ||||
-rw-r--r-- | cmd.h | 4 | ||||
-rw-r--r-- | ui-atom.c | 2 | ||||
-rw-r--r-- | ui-blob.c | 2 | ||||
-rw-r--r-- | ui-clone.c | 48 | ||||
-rw-r--r-- | ui-clone.h | 6 | ||||
-rw-r--r-- | ui-diff.c | 2 | ||||
-rw-r--r-- | ui-patch.c | 2 | ||||
-rw-r--r-- | ui-plain.c | 14 | ||||
-rw-r--r-- | ui-plain.h | 2 | ||||
-rw-r--r-- | ui-repolist.c | 6 | ||||
-rw-r--r-- | ui-shared.c | 303 | ||||
-rw-r--r-- | ui-shared.h | 6 | ||||
-rw-r--r-- | ui-snapshot.c | 8 | ||||
-rw-r--r-- | ui-stats.c | 29 | ||||
-rw-r--r-- | ui-stats.h | 2 |
19 files changed, 437 insertions, 442 deletions
@@ -24,7 +24,6 @@ struct cache_slot { | |||
24 | int keylen; | 24 | int keylen; |
25 | int ttl; | 25 | int ttl; |
26 | cache_fill_fn fn; | 26 | cache_fill_fn fn; |
27 | void *cbdata; | ||
28 | int cache_fd; | 27 | int cache_fd; |
29 | int lock_fd; | 28 | int lock_fd; |
30 | const char *cache_name; | 29 | const char *cache_name; |
@@ -187,7 +186,7 @@ static int fill_slot(struct cache_slot *slot) | |||
187 | return errno; | 186 | return errno; |
188 | 187 | ||
189 | /* Generate cache content */ | 188 | /* Generate cache content */ |
190 | slot->fn(slot->cbdata); | 189 | slot->fn(); |
191 | 190 | ||
192 | /* Restore stdout */ | 191 | /* Restore stdout */ |
193 | if (dup2(tmp, STDOUT_FILENO) == -1) | 192 | if (dup2(tmp, STDOUT_FILENO) == -1) |
@@ -277,7 +276,7 @@ static int process_slot(struct cache_slot *slot) | |||
277 | if ((err = lock_slot(slot)) != 0) { | 276 | if ((err = lock_slot(slot)) != 0) { |
278 | cache_log("[cgit] Unable to lock slot %s: %s (%d)\n", | 277 | cache_log("[cgit] Unable to lock slot %s: %s (%d)\n", |
279 | slot->lock_name, strerror(err), err); | 278 | slot->lock_name, strerror(err), err); |
280 | slot->fn(slot->cbdata); | 279 | slot->fn(); |
281 | return 0; | 280 | return 0; |
282 | } | 281 | } |
283 | 282 | ||
@@ -286,7 +285,7 @@ static int process_slot(struct cache_slot *slot) | |||
286 | slot->lock_name, strerror(err), err); | 285 | slot->lock_name, strerror(err), err); |
287 | unlock_slot(slot, 0); | 286 | unlock_slot(slot, 0); |
288 | close_lock(slot); | 287 | close_lock(slot); |
289 | slot->fn(slot->cbdata); | 288 | slot->fn(); |
290 | return 0; | 289 | return 0; |
291 | } | 290 | } |
292 | // We've got a valid cache slot in the lock file, which | 291 | // We've got a valid cache slot in the lock file, which |
@@ -310,7 +309,7 @@ static int process_slot(struct cache_slot *slot) | |||
310 | 309 | ||
311 | /* Print cached content to stdout, generate the content if necessary. */ | 310 | /* Print cached content to stdout, generate the content if necessary. */ |
312 | int cache_process(int size, const char *path, const char *key, int ttl, | 311 | int cache_process(int size, const char *path, const char *key, int ttl, |
313 | cache_fill_fn fn, void *cbdata) | 312 | cache_fill_fn fn) |
314 | { | 313 | { |
315 | unsigned long hash; | 314 | unsigned long hash; |
316 | int i; | 315 | int i; |
@@ -321,14 +320,14 @@ int cache_process(int size, const char *path, const char *key, int ttl, | |||
321 | 320 | ||
322 | /* If the cache is disabled, just generate the content */ | 321 | /* If the cache is disabled, just generate the content */ |
323 | if (size <= 0) { | 322 | if (size <= 0) { |
324 | fn(cbdata); | 323 | fn(); |
325 | return 0; | 324 | return 0; |
326 | } | 325 | } |
327 | 326 | ||
328 | /* Verify input, calculate filenames */ | 327 | /* Verify input, calculate filenames */ |
329 | if (!path) { | 328 | if (!path) { |
330 | cache_log("[cgit] Cache path not specified, caching is disabled\n"); | 329 | cache_log("[cgit] Cache path not specified, caching is disabled\n"); |
331 | fn(cbdata); | 330 | fn(); |
332 | return 0; | 331 | return 0; |
333 | } | 332 | } |
334 | if (!key) | 333 | if (!key) |
@@ -343,7 +342,6 @@ int cache_process(int size, const char *path, const char *key, int ttl, | |||
343 | strbuf_addbuf(&lockname, &filename); | 342 | strbuf_addbuf(&lockname, &filename); |
344 | strbuf_addstr(&lockname, ".lock"); | 343 | strbuf_addstr(&lockname, ".lock"); |
345 | slot.fn = fn; | 344 | slot.fn = fn; |
346 | slot.cbdata = cbdata; | ||
347 | slot.ttl = ttl; | 345 | slot.ttl = ttl; |
348 | slot.cache_name = filename.buf; | 346 | slot.cache_name = filename.buf; |
349 | slot.lock_name = lockname.buf; | 347 | slot.lock_name = lockname.buf; |
@@ -6,7 +6,7 @@ | |||
6 | #ifndef CGIT_CACHE_H | 6 | #ifndef CGIT_CACHE_H |
7 | #define CGIT_CACHE_H | 7 | #define CGIT_CACHE_H |
8 | 8 | ||
9 | typedef void (*cache_fill_fn)(void *cbdata); | 9 | typedef void (*cache_fill_fn)(void); |
10 | 10 | ||
11 | 11 | ||
12 | /* Print cached content to stdout, generate the content if necessary. | 12 | /* Print cached content to stdout, generate the content if necessary. |
@@ -17,13 +17,12 @@ typedef void (*cache_fill_fn)(void *cbdata); | |||
17 | * key the key used to lookup cache files | 17 | * key the key used to lookup cache files |
18 | * ttl max cache time in seconds for this key | 18 | * ttl max cache time in seconds for this key |
19 | * fn content generator function for this key | 19 | * fn content generator function for this key |
20 | * cbdata user-supplied data to the content generator function | ||
21 | * | 20 | * |
22 | * Return value | 21 | * Return value |
23 | * 0 indicates success, everyting else is an error | 22 | * 0 indicates success, everyting else is an error |
24 | */ | 23 | */ |
25 | extern int cache_process(int size, const char *path, const char *key, int ttl, | 24 | extern int cache_process(int size, const char *path, const char *key, int ttl, |
26 | cache_fill_fn fn, void *cbdata); | 25 | cache_fill_fn fn); |
27 | 26 | ||
28 | 27 | ||
29 | /* List info about all cache entries on stdout */ | 28 | /* List info about all cache entries on stdout */ |
@@ -322,82 +322,82 @@ static void querystring_cb(const char *name, const char *value) | |||
322 | } | 322 | } |
323 | } | 323 | } |
324 | 324 | ||
325 | static void prepare_context(struct cgit_context *ctx) | 325 | static void prepare_context(void) |
326 | { | 326 | { |
327 | memset(ctx, 0, sizeof(*ctx)); | 327 | memset(&ctx, 0, sizeof(ctx)); |
328 | ctx->cfg.agefile = "info/web/last-modified"; | 328 | ctx.cfg.agefile = "info/web/last-modified"; |
329 | ctx->cfg.nocache = 0; | 329 | ctx.cfg.nocache = 0; |
330 | ctx->cfg.cache_size = 0; | 330 | ctx.cfg.cache_size = 0; |
331 | ctx->cfg.cache_max_create_time = 5; | 331 | ctx.cfg.cache_max_create_time = 5; |
332 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | 332 | ctx.cfg.cache_root = CGIT_CACHE_ROOT; |
333 | ctx->cfg.cache_about_ttl = 15; | 333 | ctx.cfg.cache_about_ttl = 15; |
334 | ctx->cfg.cache_repo_ttl = 5; | 334 | ctx.cfg.cache_repo_ttl = 5; |
335 | ctx->cfg.cache_root_ttl = 5; | 335 | ctx.cfg.cache_root_ttl = 5; |
336 | ctx->cfg.cache_scanrc_ttl = 15; | 336 | ctx.cfg.cache_scanrc_ttl = 15; |
337 | ctx->cfg.cache_dynamic_ttl = 5; | 337 | ctx.cfg.cache_dynamic_ttl = 5; |
338 | ctx->cfg.cache_static_ttl = -1; | 338 | ctx.cfg.cache_static_ttl = -1; |
339 | ctx->cfg.case_sensitive_sort = 1; | 339 | ctx.cfg.case_sensitive_sort = 1; |
340 | ctx->cfg.branch_sort = 0; | 340 | ctx.cfg.branch_sort = 0; |
341 | ctx->cfg.commit_sort = 0; | 341 | ctx.cfg.commit_sort = 0; |
342 | ctx->cfg.css = "/cgit.css"; | 342 | ctx.cfg.css = "/cgit.css"; |
343 | ctx->cfg.logo = "/cgit.png"; | 343 | ctx.cfg.logo = "/cgit.png"; |
344 | ctx->cfg.favicon = "/favicon.ico"; | 344 | ctx.cfg.favicon = "/favicon.ico"; |
345 | ctx->cfg.local_time = 0; | 345 | ctx.cfg.local_time = 0; |
346 | ctx->cfg.enable_http_clone = 1; | 346 | ctx.cfg.enable_http_clone = 1; |
347 | ctx->cfg.enable_index_owner = 1; | 347 | ctx.cfg.enable_index_owner = 1; |
348 | ctx->cfg.enable_tree_linenumbers = 1; | 348 | ctx.cfg.enable_tree_linenumbers = 1; |
349 | ctx->cfg.enable_git_config = 0; | 349 | ctx.cfg.enable_git_config = 0; |
350 | ctx->cfg.max_repo_count = 50; | 350 | ctx.cfg.max_repo_count = 50; |
351 | ctx->cfg.max_commit_count = 50; | 351 | ctx.cfg.max_commit_count = 50; |
352 | ctx->cfg.max_lock_attempts = 5; | 352 | ctx.cfg.max_lock_attempts = 5; |
353 | ctx->cfg.max_msg_len = 80; | 353 | ctx.cfg.max_msg_len = 80; |
354 | ctx->cfg.max_repodesc_len = 80; | 354 | ctx.cfg.max_repodesc_len = 80; |
355 | ctx->cfg.max_blob_size = 0; | 355 | ctx.cfg.max_blob_size = 0; |
356 | ctx->cfg.max_stats = 0; | 356 | ctx.cfg.max_stats = 0; |
357 | ctx->cfg.project_list = NULL; | 357 | ctx.cfg.project_list = NULL; |
358 | ctx->cfg.renamelimit = -1; | 358 | ctx.cfg.renamelimit = -1; |
359 | ctx->cfg.remove_suffix = 0; | 359 | ctx.cfg.remove_suffix = 0; |
360 | ctx->cfg.robots = "index, nofollow"; | 360 | ctx.cfg.robots = "index, nofollow"; |
361 | ctx->cfg.root_title = "Git repository browser"; | 361 | ctx.cfg.root_title = "Git repository browser"; |
362 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; | 362 | ctx.cfg.root_desc = "a fast webinterface for the git dscm"; |
363 | ctx->cfg.scan_hidden_path = 0; | 363 | ctx.cfg.scan_hidden_path = 0; |
364 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | 364 | ctx.cfg.script_name = CGIT_SCRIPT_NAME; |
365 | ctx->cfg.section = ""; | 365 | ctx.cfg.section = ""; |
366 | ctx->cfg.repository_sort = "name"; | 366 | ctx.cfg.repository_sort = "name"; |
367 | ctx->cfg.section_sort = 1; | 367 | ctx.cfg.section_sort = 1; |
368 | ctx->cfg.summary_branches = 10; | 368 | ctx.cfg.summary_branches = 10; |
369 | ctx->cfg.summary_log = 10; | 369 | ctx.cfg.summary_log = 10; |
370 | ctx->cfg.summary_tags = 10; | 370 | ctx.cfg.summary_tags = 10; |
371 | ctx->cfg.max_atom_items = 10; | 371 | ctx.cfg.max_atom_items = 10; |
372 | ctx->cfg.ssdiff = 0; | 372 | ctx.cfg.ssdiff = 0; |
373 | ctx->env.cgit_config = getenv("CGIT_CONFIG"); | 373 | ctx.env.cgit_config = getenv("CGIT_CONFIG"); |
374 | ctx->env.http_host = getenv("HTTP_HOST"); | 374 | ctx.env.http_host = getenv("HTTP_HOST"); |
375 | ctx->env.https = getenv("HTTPS"); | 375 | ctx.env.https = getenv("HTTPS"); |
376 | ctx->env.no_http = getenv("NO_HTTP"); | 376 | ctx.env.no_http = getenv("NO_HTTP"); |
377 | ctx->env.path_info = getenv("PATH_INFO"); | 377 | ctx.env.path_info = getenv("PATH_INFO"); |
378 | ctx->env.query_string = getenv("QUERY_STRING"); | 378 | ctx.env.query_string = getenv("QUERY_STRING"); |
379 | ctx->env.request_method = getenv("REQUEST_METHOD"); | 379 | ctx.env.request_method = getenv("REQUEST_METHOD"); |
380 | ctx->env.script_name = getenv("SCRIPT_NAME"); | 380 | ctx.env.script_name = getenv("SCRIPT_NAME"); |
381 | ctx->env.server_name = getenv("SERVER_NAME"); | 381 | ctx.env.server_name = getenv("SERVER_NAME"); |
382 | ctx->env.server_port = getenv("SERVER_PORT"); | 382 | ctx.env.server_port = getenv("SERVER_PORT"); |
383 | ctx->env.http_cookie = getenv("HTTP_COOKIE"); | 383 | ctx.env.http_cookie = getenv("HTTP_COOKIE"); |
384 | ctx->env.http_referer = getenv("HTTP_REFERER"); | 384 | ctx.env.http_referer = getenv("HTTP_REFERER"); |
385 | ctx->env.content_length = getenv("CONTENT_LENGTH") ? strtoul(getenv("CONTENT_LENGTH"), NULL, 10) : 0; | 385 | ctx.env.content_length = getenv("CONTENT_LENGTH") ? strtoul(getenv("CONTENT_LENGTH"), NULL, 10) : 0; |
386 | ctx->env.authenticated = 0; | 386 | ctx.env.authenticated = 0; |
387 | ctx->page.mimetype = "text/html"; | 387 | ctx.page.mimetype = "text/html"; |
388 | ctx->page.charset = PAGE_ENCODING; | 388 | ctx.page.charset = PAGE_ENCODING; |
389 | ctx->page.filename = NULL; | 389 | ctx.page.filename = NULL; |
390 | ctx->page.size = 0; | 390 | ctx.page.size = 0; |
391 | ctx->page.modified = time(NULL); | 391 | ctx.page.modified = time(NULL); |
392 | ctx->page.expires = ctx->page.modified; | 392 | ctx.page.expires = ctx.page.modified; |
393 | ctx->page.etag = NULL; | 393 | ctx.page.etag = NULL; |
394 | memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list)); | 394 | memset(&ctx.cfg.mimetypes, 0, sizeof(struct string_list)); |
395 | if (ctx->env.script_name) | 395 | if (ctx.env.script_name) |
396 | ctx->cfg.script_name = xstrdup(ctx->env.script_name); | 396 | ctx.cfg.script_name = xstrdup(ctx.env.script_name); |
397 | if (ctx->env.query_string) | 397 | if (ctx.env.query_string) |
398 | ctx->qry.raw = xstrdup(ctx->env.query_string); | 398 | ctx.qry.raw = xstrdup(ctx.env.query_string); |
399 | if (!ctx->env.cgit_config) | 399 | if (!ctx.env.cgit_config) |
400 | ctx->env.cgit_config = CGIT_CONFIG; | 400 | ctx.env.cgit_config = CGIT_CONFIG; |
401 | } | 401 | } |
402 | 402 | ||
403 | struct refmatch { | 403 | struct refmatch { |
@@ -527,14 +527,14 @@ static void choose_readme(struct cgit_repo *repo) | |||
527 | string_list_append(&repo->readme, filename)->util = ref; | 527 | string_list_append(&repo->readme, filename)->util = ref; |
528 | } | 528 | } |
529 | 529 | ||
530 | static int prepare_repo_cmd(struct cgit_context *ctx) | 530 | static int prepare_repo_cmd(void) |
531 | { | 531 | { |
532 | unsigned char sha1[20]; | 532 | unsigned char sha1[20]; |
533 | int nongit = 0; | 533 | int nongit = 0; |
534 | int rc; | 534 | int rc; |
535 | 535 | ||
536 | /* The path to the git repository. */ | 536 | /* The path to the git repository. */ |
537 | setenv("GIT_DIR", ctx->repo->path, 1); | 537 | setenv("GIT_DIR", ctx.repo->path, 1); |
538 | 538 | ||
539 | /* Do not look in /etc/ for gitconfig and gitattributes. */ | 539 | /* Do not look in /etc/ for gitconfig and gitattributes. */ |
540 | setenv("GIT_CONFIG_NOSYSTEM", "1", 1); | 540 | setenv("GIT_CONFIG_NOSYSTEM", "1", 1); |
@@ -549,69 +549,69 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
549 | init_display_notes(NULL); | 549 | init_display_notes(NULL); |
550 | 550 | ||
551 | if (nongit) { | 551 | if (nongit) { |
552 | const char *name = ctx->repo->name; | 552 | const char *name = ctx.repo->name; |
553 | rc = errno; | 553 | rc = errno; |
554 | ctx->page.title = fmtalloc("%s - %s", ctx->cfg.root_title, | 554 | ctx.page.title = fmtalloc("%s - %s", ctx.cfg.root_title, |
555 | "config error"); | 555 | "config error"); |
556 | ctx->repo = NULL; | 556 | ctx.repo = NULL; |
557 | cgit_print_http_headers(ctx); | 557 | cgit_print_http_headers(); |
558 | cgit_print_docstart(ctx); | 558 | cgit_print_docstart(); |
559 | cgit_print_pageheader(ctx); | 559 | cgit_print_pageheader(); |
560 | cgit_print_error("Failed to open %s: %s", name, | 560 | cgit_print_error("Failed to open %s: %s", name, |
561 | rc ? strerror(rc) : "Not a valid git repository"); | 561 | rc ? strerror(rc) : "Not a valid git repository"); |
562 | cgit_print_docend(); | 562 | cgit_print_docend(); |
563 | return 1; | 563 | return 1; |
564 | } | 564 | } |
565 | ctx->page.title = fmtalloc("%s - %s", ctx->repo->name, ctx->repo->desc); | 565 | ctx.page.title = fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc); |
566 | 566 | ||
567 | if (!ctx->repo->defbranch) | 567 | if (!ctx.repo->defbranch) |
568 | ctx->repo->defbranch = guess_defbranch(); | 568 | ctx.repo->defbranch = guess_defbranch(); |
569 | 569 | ||
570 | if (!ctx->qry.head) { | 570 | if (!ctx.qry.head) { |
571 | ctx->qry.nohead = 1; | 571 | ctx.qry.nohead = 1; |
572 | ctx->qry.head = find_default_branch(ctx->repo); | 572 | ctx.qry.head = find_default_branch(ctx.repo); |
573 | } | 573 | } |
574 | 574 | ||
575 | if (!ctx->qry.head) { | 575 | if (!ctx.qry.head) { |
576 | cgit_print_http_headers(ctx); | 576 | cgit_print_http_headers(); |
577 | cgit_print_docstart(ctx); | 577 | cgit_print_docstart(); |
578 | cgit_print_pageheader(ctx); | 578 | cgit_print_pageheader(); |
579 | cgit_print_error("Repository seems to be empty"); | 579 | cgit_print_error("Repository seems to be empty"); |
580 | cgit_print_docend(); | 580 | cgit_print_docend(); |
581 | return 1; | 581 | return 1; |
582 | } | 582 | } |
583 | 583 | ||
584 | if (get_sha1(ctx->qry.head, sha1)) { | 584 | if (get_sha1(ctx.qry.head, sha1)) { |
585 | char *tmp = xstrdup(ctx->qry.head); | 585 | char *tmp = xstrdup(ctx.qry.head); |
586 | ctx->qry.head = ctx->repo->defbranch; | 586 | ctx.qry.head = ctx.repo->defbranch; |
587 | ctx->page.status = 404; | 587 | ctx.page.status = 404; |
588 | ctx->page.statusmsg = "Not found"; | 588 | ctx.page.statusmsg = "Not found"; |
589 | cgit_print_http_headers(ctx); | 589 | cgit_print_http_headers(); |
590 | cgit_print_docstart(ctx); | 590 | cgit_print_docstart(); |
591 | cgit_print_pageheader(ctx); | 591 | cgit_print_pageheader(); |
592 | cgit_print_error("Invalid branch: %s", tmp); | 592 | cgit_print_error("Invalid branch: %s", tmp); |
593 | cgit_print_docend(); | 593 | cgit_print_docend(); |
594 | return 1; | 594 | return 1; |
595 | } | 595 | } |
596 | sort_string_list(&ctx->repo->submodules); | 596 | sort_string_list(&ctx.repo->submodules); |
597 | cgit_prepare_repo_env(ctx->repo); | 597 | cgit_prepare_repo_env(ctx.repo); |
598 | choose_readme(ctx->repo); | 598 | choose_readme(ctx.repo); |
599 | return 0; | 599 | return 0; |
600 | } | 600 | } |
601 | 601 | ||
602 | static inline void open_auth_filter(struct cgit_context *ctx, const char *function) | 602 | static inline void open_auth_filter(const char *function) |
603 | { | 603 | { |
604 | cgit_open_filter(ctx->cfg.auth_filter, function, | 604 | cgit_open_filter(ctx.cfg.auth_filter, function, |
605 | ctx->env.http_cookie ? ctx->env.http_cookie : "", | 605 | ctx.env.http_cookie ? ctx.env.http_cookie : "", |
606 | ctx->env.request_method ? ctx->env.request_method : "", | 606 | ctx.env.request_method ? ctx.env.request_method : "", |
607 | ctx->env.query_string ? ctx->env.query_string : "", | 607 | ctx.env.query_string ? ctx.env.query_string : "", |
608 | ctx->env.http_referer ? ctx->env.http_referer : "", | 608 | ctx.env.http_referer ? ctx.env.http_referer : "", |
609 | ctx->env.path_info ? ctx->env.path_info : "", | 609 | ctx.env.path_info ? ctx.env.path_info : "", |
610 | ctx->env.http_host ? ctx->env.http_host : "", | 610 | ctx.env.http_host ? ctx.env.http_host : "", |
611 | ctx->env.https ? ctx->env.https : "", | 611 | ctx.env.https ? ctx.env.https : "", |
612 | ctx->qry.repo ? ctx->qry.repo : "", | 612 | ctx.qry.repo ? ctx.qry.repo : "", |
613 | ctx->qry.page ? ctx->qry.page : "", | 613 | ctx.qry.page ? ctx.qry.page : "", |
614 | ctx->qry.url ? ctx->qry.url : "", | 614 | ctx.qry.url ? ctx.qry.url : "", |
615 | cgit_loginurl()); | 615 | cgit_loginurl()); |
616 | } | 616 | } |
617 | 617 | ||
@@ -622,107 +622,106 @@ static inline void open_auth_filter(struct cgit_context *ctx, const char *functi | |||
622 | * will complain on the mailing list, and we'll increase it as needed. */ | 622 | * will complain on the mailing list, and we'll increase it as needed. */ |
623 | #define MAX_AUTHENTICATION_POST_BYTES 4096 | 623 | #define MAX_AUTHENTICATION_POST_BYTES 4096 |
624 | /* The filter is expected to spit out "Status: " and all headers. */ | 624 | /* The filter is expected to spit out "Status: " and all headers. */ |
625 | static inline void authenticate_post(struct cgit_context *ctx) | 625 | static inline void authenticate_post(void) |
626 | { | 626 | { |
627 | char buffer[MAX_AUTHENTICATION_POST_BYTES]; | 627 | char buffer[MAX_AUTHENTICATION_POST_BYTES]; |
628 | int len; | 628 | int len; |
629 | 629 | ||
630 | open_auth_filter(ctx, "authenticate-post"); | 630 | open_auth_filter("authenticate-post"); |
631 | len = ctx->env.content_length; | 631 | len = ctx.env.content_length; |
632 | if (len > MAX_AUTHENTICATION_POST_BYTES) | 632 | if (len > MAX_AUTHENTICATION_POST_BYTES) |
633 | len = MAX_AUTHENTICATION_POST_BYTES; | 633 | len = MAX_AUTHENTICATION_POST_BYTES; |
634 | if (read(STDIN_FILENO, buffer, len) < 0) | 634 | if (read(STDIN_FILENO, buffer, len) < 0) |
635 | die_errno("Could not read POST from stdin"); | 635 | die_errno("Could not read POST from stdin"); |
636 | if (write(STDOUT_FILENO, buffer, len) < 0) | 636 | if (write(STDOUT_FILENO, buffer, len) < 0) |
637 | die_errno("Could not write POST to stdout"); | 637 | die_errno("Could not write POST to stdout"); |
638 | cgit_close_filter(ctx->cfg.auth_filter); | 638 | cgit_close_filter(ctx.cfg.auth_filter); |
639 | exit(0); | 639 | exit(0); |
640 | } | 640 | } |
641 | 641 | ||
642 | static inline void authenticate_cookie(struct cgit_context *ctx) | 642 | static inline void authenticate_cookie(void) |
643 | { | 643 | { |
644 | /* If we don't have an auth_filter, consider all cookies valid, and thus return early. */ | 644 | /* If we don't have an auth_filter, consider all cookies valid, and thus return early. */ |
645 | if (!ctx->cfg.auth_filter) { | 645 | if (!ctx.cfg.auth_filter) { |
646 | ctx->env.authenticated = 1; | 646 | ctx.env.authenticated = 1; |
647 | return; | 647 | return; |
648 | } | 648 | } |
649 | 649 | ||
650 | /* If we're having something POST'd to /login, we're authenticating POST, | 650 | /* If we're having something POST'd to /login, we're authenticating POST, |
651 | * instead of the cookie, so call authenticate_post and bail out early. | 651 | * instead of the cookie, so call authenticate_post and bail out early. |
652 | * This pattern here should match /?p=login with POST. */ | 652 | * This pattern here should match /?p=login with POST. */ |
653 | if (ctx->env.request_method && ctx->qry.page && !ctx->repo && \ | 653 | if (ctx.env.request_method && ctx.qry.page && !ctx.repo && \ |
654 | !strcmp(ctx->env.request_method, "POST") && !strcmp(ctx->qry.page, "login")) { | 654 | !strcmp(ctx.env.request_method, "POST") && !strcmp(ctx.qry.page, "login")) { |
655 | authenticate_post(ctx); | 655 | authenticate_post(); |
656 | return; | 656 | return; |
657 | } | 657 | } |
658 | 658 | ||
659 | /* If we've made it this far, we're authenticating the cookie for real, so do that. */ | 659 | /* If we've made it this far, we're authenticating the cookie for real, so do that. */ |
660 | open_auth_filter(ctx, "authenticate-cookie"); | 660 | open_auth_filter("authenticate-cookie"); |
661 | ctx->env.authenticated = cgit_close_filter(ctx->cfg.auth_filter); | 661 | ctx.env.authenticated = cgit_close_filter(ctx.cfg.auth_filter); |
662 | } | 662 | } |
663 | 663 | ||
664 | static void process_request(void *cbdata) | 664 | static void process_request(void) |
665 | { | 665 | { |
666 | struct cgit_context *ctx = cbdata; | ||
667 | struct cgit_cmd *cmd; | 666 | struct cgit_cmd *cmd; |
668 | 667 | ||
669 | /* If we're not yet authenticated, no matter what page we're on, | 668 | /* If we're not yet authenticated, no matter what page we're on, |
670 | * display the authentication body from the auth_filter. This should | 669 | * display the authentication body from the auth_filter. This should |
671 | * never be cached. */ | 670 | * never be cached. */ |
672 | if (!ctx->env.authenticated) { | 671 | if (!ctx.env.authenticated) { |
673 | ctx->page.title = "Authentication Required"; | 672 | ctx.page.title = "Authentication Required"; |
674 | cgit_print_http_headers(ctx); | 673 | cgit_print_http_headers(); |
675 | cgit_print_docstart(ctx); | 674 | cgit_print_docstart(); |
676 | cgit_print_pageheader(ctx); | 675 | cgit_print_pageheader(); |
677 | open_auth_filter(ctx, "body"); | 676 | open_auth_filter("body"); |
678 | cgit_close_filter(ctx->cfg.auth_filter); | 677 | cgit_close_filter(ctx.cfg.auth_filter); |
679 | cgit_print_docend(); | 678 | cgit_print_docend(); |
680 | return; | 679 | return; |
681 | } | 680 | } |
682 | 681 | ||
683 | cmd = cgit_get_cmd(ctx); | 682 | cmd = cgit_get_cmd(); |
684 | if (!cmd) { | 683 | if (!cmd) { |
685 | ctx->page.title = "cgit error"; | 684 | ctx.page.title = "cgit error"; |
686 | ctx->page.status = 404; | 685 | ctx.page.status = 404; |
687 | ctx->page.statusmsg = "Not found"; | 686 | ctx.page.statusmsg = "Not found"; |
688 | cgit_print_http_headers(ctx); | 687 | cgit_print_http_headers(); |
689 | cgit_print_docstart(ctx); | 688 | cgit_print_docstart(); |
690 | cgit_print_pageheader(ctx); | 689 | cgit_print_pageheader(); |
691 | cgit_print_error("Invalid request"); | 690 | cgit_print_error("Invalid request"); |
692 | cgit_print_docend(); | 691 | cgit_print_docend(); |
693 | return; | 692 | return; |
694 | } | 693 | } |
695 | 694 | ||
696 | if (!ctx->cfg.enable_http_clone && cmd->is_clone) { | 695 | if (!ctx.cfg.enable_http_clone && cmd->is_clone) { |
697 | html_status(404, "Not found", 0); | 696 | html_status(404, "Not found", 0); |
698 | return; | 697 | return; |
699 | } | 698 | } |
700 | 699 | ||
701 | /* If cmd->want_vpath is set, assume ctx->qry.path contains a "virtual" | 700 | /* If cmd->want_vpath is set, assume ctx.qry.path contains a "virtual" |
702 | * in-project path limit to be made available at ctx->qry.vpath. | 701 | * in-project path limit to be made available at ctx.qry.vpath. |
703 | * Otherwise, no path limit is in effect (ctx->qry.vpath = NULL). | 702 | * Otherwise, no path limit is in effect (ctx.qry.vpath = NULL). |
704 | */ | 703 | */ |
705 | ctx->qry.vpath = cmd->want_vpath ? ctx->qry.path : NULL; | 704 | ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL; |
706 | 705 | ||
707 | if (cmd->want_repo && !ctx->repo) { | 706 | if (cmd->want_repo && !ctx.repo) { |
708 | cgit_print_http_headers(ctx); | 707 | cgit_print_http_headers(); |
709 | cgit_print_docstart(ctx); | 708 | cgit_print_docstart(); |
710 | cgit_print_pageheader(ctx); | 709 | cgit_print_pageheader(); |
711 | cgit_print_error("No repository selected"); | 710 | cgit_print_error("No repository selected"); |
712 | cgit_print_docend(); | 711 | cgit_print_docend(); |
713 | return; | 712 | return; |
714 | } | 713 | } |
715 | 714 | ||
716 | if (ctx->repo && prepare_repo_cmd(ctx)) | 715 | if (ctx.repo && prepare_repo_cmd()) |
717 | return; | 716 | return; |
718 | 717 | ||
719 | if (cmd->want_layout) { | 718 | if (cmd->want_layout) { |
720 | cgit_print_http_headers(ctx); | 719 | cgit_print_http_headers(); |
721 | cgit_print_docstart(ctx); | 720 | cgit_print_docstart(); |
722 | cgit_print_pageheader(ctx); | 721 | cgit_print_pageheader(); |
723 | } | 722 | } |
724 | 723 | ||
725 | cmd->fn(ctx); | 724 | cmd->fn(); |
726 | 725 | ||
727 | if (cmd->want_layout) | 726 | if (cmd->want_layout) |
728 | cgit_print_docend(); | 727 | cgit_print_docend(); |
@@ -995,7 +994,7 @@ int main(int argc, const char **argv) | |||
995 | cgit_init_filters(); | 994 | cgit_init_filters(); |
996 | atexit(cgit_cleanup_filters); | 995 | atexit(cgit_cleanup_filters); |
997 | 996 | ||
998 | prepare_context(&ctx); | 997 | prepare_context(); |
999 | cgit_repolist.length = 0; | 998 | cgit_repolist.length = 0; |
1000 | cgit_repolist.count = 0; | 999 | cgit_repolist.count = 0; |
1001 | cgit_repolist.repos = NULL; | 1000 | cgit_repolist.repos = NULL; |
@@ -1034,7 +1033,7 @@ int main(int argc, const char **argv) | |||
1034 | /* Before we go any further, we set ctx.env.authenticated by checking to see | 1033 | /* Before we go any further, we set ctx.env.authenticated by checking to see |
1035 | * if the supplied cookie is valid. All cookies are valid if there is no | 1034 | * if the supplied cookie is valid. All cookies are valid if there is no |
1036 | * auth_filter. If there is an auth_filter, the filter decides. */ | 1035 | * auth_filter. If there is an auth_filter, the filter decides. */ |
1037 | authenticate_cookie(&ctx); | 1036 | authenticate_cookie(); |
1038 | 1037 | ||
1039 | ttl = calc_ttl(); | 1038 | ttl = calc_ttl(); |
1040 | if (ttl < 0) | 1039 | if (ttl < 0) |
@@ -1046,7 +1045,8 @@ int main(int argc, const char **argv) | |||
1046 | if (ctx.cfg.nocache) | 1045 | if (ctx.cfg.nocache) |
1047 | ctx.cfg.cache_size = 0; | 1046 | ctx.cfg.cache_size = 0; |
1048 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, | 1047 | err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, |
1049 | ctx.qry.raw, ttl, process_request, &ctx); | 1048 | ctx.qry.raw, ttl, process_request); |
1049 | cgit_cleanup_filters(); | ||
1050 | if (err) | 1050 | if (err) |
1051 | cgit_print_error("Error processing page: %s (%d)", | 1051 | cgit_print_error("Error processing page: %s (%d)", |
1052 | strerror(err), err); | 1052 | strerror(err), err); |
@@ -26,120 +26,120 @@ | |||
26 | #include "ui-tag.h" | 26 | #include "ui-tag.h" |
27 | #include "ui-tree.h" | 27 | #include "ui-tree.h" |
28 | 28 | ||
29 | static void HEAD_fn(struct cgit_context *ctx) | 29 | static void HEAD_fn(void) |
30 | { | 30 | { |
31 | cgit_clone_head(ctx); | 31 | cgit_clone_head(); |
32 | } | 32 | } |
33 | 33 | ||
34 | static void atom_fn(struct cgit_context *ctx) | 34 | static void atom_fn(void) |
35 | { | 35 | { |
36 | cgit_print_atom(ctx->qry.head, ctx->qry.path, ctx->cfg.max_atom_items); | 36 | cgit_print_atom(ctx.qry.head, ctx.qry.path, ctx.cfg.max_atom_items); |
37 | } | 37 | } |
38 | 38 | ||
39 | static void about_fn(struct cgit_context *ctx) | 39 | static void about_fn(void) |
40 | { | 40 | { |
41 | if (ctx->repo) | 41 | if (ctx.repo) |
42 | cgit_print_repo_readme(ctx->qry.path); | 42 | cgit_print_repo_readme(ctx.qry.path); |
43 | else | 43 | else |
44 | cgit_print_site_readme(); | 44 | cgit_print_site_readme(); |
45 | } | 45 | } |
46 | 46 | ||
47 | static void blob_fn(struct cgit_context *ctx) | 47 | static void blob_fn(void) |
48 | { | 48 | { |
49 | cgit_print_blob(ctx->qry.sha1, ctx->qry.path, ctx->qry.head, 0); | 49 | cgit_print_blob(ctx.qry.sha1, ctx.qry.path, ctx.qry.head, 0); |
50 | } | 50 | } |
51 | 51 | ||
52 | static void commit_fn(struct cgit_context *ctx) | 52 | static void commit_fn(void) |
53 | { | 53 | { |
54 | cgit_print_commit(ctx->qry.sha1, ctx->qry.path); | 54 | cgit_print_commit(ctx.qry.sha1, ctx.qry.path); |
55 | } | 55 | } |
56 | 56 | ||
57 | static void diff_fn(struct cgit_context *ctx) | 57 | static void diff_fn(void) |
58 | { | 58 | { |
59 | cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path, 1, 0); | 59 | cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1, 0); |
60 | } | 60 | } |
61 | 61 | ||
62 | static void rawdiff_fn(struct cgit_context *ctx) | 62 | static void rawdiff_fn(void) |
63 | { | 63 | { |
64 | cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path, 1, 1); | 64 | cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1, 1); |
65 | } | 65 | } |
66 | 66 | ||
67 | static void info_fn(struct cgit_context *ctx) | 67 | static void info_fn(void) |
68 | { | 68 | { |
69 | cgit_clone_info(ctx); | 69 | cgit_clone_info(); |
70 | } | 70 | } |
71 | 71 | ||
72 | static void log_fn(struct cgit_context *ctx) | 72 | static void log_fn(void) |
73 | { | 73 | { |
74 | cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count, | 74 | cgit_print_log(ctx.qry.sha1, ctx.qry.ofs, ctx.cfg.max_commit_count, |
75 | ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1, | 75 | ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1, |
76 | ctx->repo->enable_commit_graph, | 76 | ctx.repo->enable_commit_graph, |
77 | ctx->repo->commit_sort); | 77 | ctx.repo->commit_sort); |
78 | } | 78 | } |
79 | 79 | ||
80 | static void ls_cache_fn(struct cgit_context *ctx) | 80 | static void ls_cache_fn(void) |
81 | { | 81 | { |
82 | ctx->page.mimetype = "text/plain"; | 82 | ctx.page.mimetype = "text/plain"; |
83 | ctx->page.filename = "ls-cache.txt"; | 83 | ctx.page.filename = "ls-cache.txt"; |
84 | cgit_print_http_headers(ctx); | 84 | cgit_print_http_headers(); |
85 | cache_ls(ctx->cfg.cache_root); | 85 | cache_ls(ctx.cfg.cache_root); |
86 | } | 86 | } |
87 | 87 | ||
88 | static void objects_fn(struct cgit_context *ctx) | 88 | static void objects_fn(void) |
89 | { | 89 | { |
90 | cgit_clone_objects(ctx); | 90 | cgit_clone_objects(); |
91 | } | 91 | } |
92 | 92 | ||
93 | static void repolist_fn(struct cgit_context *ctx) | 93 | static void repolist_fn(void) |
94 | { | 94 | { |
95 | cgit_print_repolist(); | 95 | cgit_print_repolist(); |
96 | } | 96 | } |
97 | 97 | ||
98 | static void patch_fn(struct cgit_context *ctx) | 98 | static void patch_fn(void) |
99 | { | 99 | { |
100 | cgit_print_patch(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); | 100 | cgit_print_patch(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); |
101 | } | 101 | } |
102 | 102 | ||
103 | static void plain_fn(struct cgit_context *ctx) | 103 | static void plain_fn(void) |
104 | { | 104 | { |
105 | cgit_print_plain(ctx); | 105 | cgit_print_plain(); |
106 | } | 106 | } |
107 | 107 | ||
108 | static void refs_fn(struct cgit_context *ctx) | 108 | static void refs_fn(void) |
109 | { | 109 | { |
110 | cgit_print_refs(); | 110 | cgit_print_refs(); |
111 | } | 111 | } |
112 | 112 | ||
113 | static void snapshot_fn(struct cgit_context *ctx) | 113 | static void snapshot_fn(void) |
114 | { | 114 | { |
115 | cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, ctx->qry.path, | 115 | cgit_print_snapshot(ctx.qry.head, ctx.qry.sha1, ctx.qry.path, |
116 | ctx->repo->snapshots, ctx->qry.nohead); | 116 | ctx.repo->snapshots, ctx.qry.nohead); |
117 | } | 117 | } |
118 | 118 | ||
119 | static void stats_fn(struct cgit_context *ctx) | 119 | static void stats_fn(void) |
120 | { | 120 | { |
121 | cgit_show_stats(ctx); | 121 | cgit_show_stats(); |
122 | } | 122 | } |
123 | 123 | ||
124 | static void summary_fn(struct cgit_context *ctx) | 124 | static void summary_fn(void) |
125 | { | 125 | { |
126 | cgit_print_summary(); | 126 | cgit_print_summary(); |
127 | } | 127 | } |
128 | 128 | ||
129 | static void tag_fn(struct cgit_context *ctx) | 129 | static void tag_fn(void) |
130 | { | 130 | { |
131 | cgit_print_tag(ctx->qry.sha1); | 131 | cgit_print_tag(ctx.qry.sha1); |
132 | } | 132 | } |
133 | 133 | ||
134 | static void tree_fn(struct cgit_context *ctx) | 134 | static void tree_fn(void) |
135 | { | 135 | { |
136 | cgit_print_tree(ctx->qry.sha1, ctx->qry.path); | 136 | cgit_print_tree(ctx.qry.sha1, ctx.qry.path); |
137 | } | 137 | } |
138 | 138 | ||
139 | #define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \ | 139 | #define def_cmd(name, want_repo, want_layout, want_vpath, is_clone) \ |
140 | {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone} | 140 | {#name, name##_fn, want_repo, want_layout, want_vpath, is_clone} |
141 | 141 | ||
142 | struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) | 142 | struct cgit_cmd *cgit_get_cmd(void) |
143 | { | 143 | { |
144 | static struct cgit_cmd cmds[] = { | 144 | static struct cgit_cmd cmds[] = { |
145 | def_cmd(HEAD, 1, 0, 0, 1), | 145 | def_cmd(HEAD, 1, 0, 0, 1), |
@@ -165,15 +165,15 @@ struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) | |||
165 | }; | 165 | }; |
166 | int i; | 166 | int i; |
167 | 167 | ||
168 | if (ctx->qry.page == NULL) { | 168 | if (ctx.qry.page == NULL) { |
169 | if (ctx->repo) | 169 | if (ctx.repo) |
170 | ctx->qry.page = "summary"; | 170 | ctx.qry.page = "summary"; |
171 | else | 171 | else |
172 | ctx->qry.page = "repolist"; | 172 | ctx.qry.page = "repolist"; |
173 | } | 173 | } |
174 | 174 | ||
175 | for (i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) | 175 | for (i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) |
176 | if (!strcmp(ctx->qry.page, cmds[i].name)) | 176 | if (!strcmp(ctx.qry.page, cmds[i].name)) |
177 | return &cmds[i]; | 177 | return &cmds[i]; |
178 | return NULL; | 178 | return NULL; |
179 | } | 179 | } |
@@ -1,7 +1,7 @@ | |||
1 | #ifndef CMD_H | 1 | #ifndef CMD_H |
2 | #define CMD_H | 2 | #define CMD_H |
3 | 3 | ||
4 | typedef void (*cgit_cmd_fn)(struct cgit_context *ctx); | 4 | typedef void (*cgit_cmd_fn)(void); |
5 | 5 | ||
6 | struct cgit_cmd { | 6 | struct cgit_cmd { |
7 | const char *name; | 7 | const char *name; |
@@ -12,6 +12,6 @@ struct cgit_cmd { | |||
12 | is_clone:1; | 12 | is_clone:1; |
13 | }; | 13 | }; |
14 | 14 | ||
15 | extern struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx); | 15 | extern struct cgit_cmd *cgit_get_cmd(void); |
16 | 16 | ||
17 | #endif /* CMD_H */ | 17 | #endif /* CMD_H */ |
@@ -108,7 +108,7 @@ void cgit_print_atom(char *tip, char *path, int max_count) | |||
108 | host = cgit_hosturl(); | 108 | host = cgit_hosturl(); |
109 | ctx.page.mimetype = "text/xml"; | 109 | ctx.page.mimetype = "text/xml"; |
110 | ctx.page.charset = "utf-8"; | 110 | ctx.page.charset = "utf-8"; |
111 | cgit_print_http_headers(&ctx); | 111 | cgit_print_http_headers(); |
112 | html("<feed xmlns='http://www.w3.org/2005/Atom'>\n"); | 112 | html("<feed xmlns='http://www.w3.org/2005/Atom'>\n"); |
113 | html("<title>"); | 113 | html("<title>"); |
114 | html_txt(ctx.repo->name); | 114 | html_txt(ctx.repo->name); |
@@ -164,6 +164,6 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl | |||
164 | ctx.page.mimetype = "text/plain"; | 164 | ctx.page.mimetype = "text/plain"; |
165 | } | 165 | } |
166 | ctx.page.filename = path; | 166 | ctx.page.filename = path; |
167 | cgit_print_http_headers(&ctx); | 167 | cgit_print_http_headers(); |
168 | html_raw(buf, size); | 168 | html_raw(buf, size); |
169 | } | 169 | } |
@@ -29,22 +29,22 @@ static int print_ref_info(const char *refname, const unsigned char *sha1, | |||
29 | return 0; | 29 | return 0; |
30 | } | 30 | } |
31 | 31 | ||
32 | static void print_pack_info(struct cgit_context *ctx) | 32 | static void print_pack_info(void) |
33 | { | 33 | { |
34 | struct packed_git *pack; | 34 | struct packed_git *pack; |
35 | int ofs; | 35 | int ofs; |
36 | 36 | ||
37 | ctx->page.mimetype = "text/plain"; | 37 | ctx.page.mimetype = "text/plain"; |
38 | ctx->page.filename = "objects/info/packs"; | 38 | ctx.page.filename = "objects/info/packs"; |
39 | cgit_print_http_headers(ctx); | 39 | cgit_print_http_headers(); |
40 | ofs = strlen(ctx->repo->path) + strlen("/objects/pack/"); | 40 | ofs = strlen(ctx.repo->path) + strlen("/objects/pack/"); |
41 | prepare_packed_git(); | 41 | prepare_packed_git(); |
42 | for (pack = packed_git; pack; pack = pack->next) | 42 | for (pack = packed_git; pack; pack = pack->next) |
43 | if (pack->pack_local) | 43 | if (pack->pack_local) |
44 | htmlf("P %s\n", pack->pack_name + ofs); | 44 | htmlf("P %s\n", pack->pack_name + ofs); |
45 | } | 45 | } |
46 | 46 | ||
47 | static void send_file(struct cgit_context *ctx, char *path) | 47 | static void send_file(char *path) |
48 | { | 48 | { |
49 | struct stat st; | 49 | struct stat st; |
50 | 50 | ||
@@ -61,41 +61,41 @@ static void send_file(struct cgit_context *ctx, char *path) | |||
61 | } | 61 | } |
62 | return; | 62 | return; |
63 | } | 63 | } |
64 | ctx->page.mimetype = "application/octet-stream"; | 64 | ctx.page.mimetype = "application/octet-stream"; |
65 | ctx->page.filename = path; | 65 | ctx.page.filename = path; |
66 | if (prefixcmp(ctx->repo->path, path)) | 66 | if (prefixcmp(ctx.repo->path, path)) |
67 | ctx->page.filename += strlen(ctx->repo->path) + 1; | 67 | ctx.page.filename += strlen(ctx.repo->path) + 1; |
68 | cgit_print_http_headers(ctx); | 68 | cgit_print_http_headers(); |
69 | html_include(path); | 69 | html_include(path); |
70 | } | 70 | } |
71 | 71 | ||
72 | void cgit_clone_info(struct cgit_context *ctx) | 72 | void cgit_clone_info(void) |
73 | { | 73 | { |
74 | if (!ctx->qry.path || strcmp(ctx->qry.path, "refs")) | 74 | if (!ctx.qry.path || strcmp(ctx.qry.path, "refs")) |
75 | return; | 75 | return; |
76 | 76 | ||
77 | ctx->page.mimetype = "text/plain"; | 77 | ctx.page.mimetype = "text/plain"; |
78 | ctx->page.filename = "info/refs"; | 78 | ctx.page.filename = "info/refs"; |
79 | cgit_print_http_headers(ctx); | 79 | cgit_print_http_headers(); |
80 | for_each_ref(print_ref_info, ctx); | 80 | for_each_ref(print_ref_info, NULL); |
81 | } | 81 | } |
82 | 82 | ||
83 | void cgit_clone_objects(struct cgit_context *ctx) | 83 | void cgit_clone_objects(void) |
84 | { | 84 | { |
85 | if (!ctx->qry.path) { | 85 | if (!ctx.qry.path) { |
86 | html_status(400, "Bad request", 0); | 86 | html_status(400, "Bad request", 0); |
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | 89 | ||
90 | if (!strcmp(ctx->qry.path, "info/packs")) { | 90 | if (!strcmp(ctx.qry.path, "info/packs")) { |
91 | print_pack_info(ctx); | 91 | print_pack_info(); |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | 94 | ||
95 | send_file(ctx, git_path("objects/%s", ctx->qry.path)); | 95 | send_file(git_path("objects/%s", ctx.qry.path)); |
96 | } | 96 | } |
97 | 97 | ||
98 | void cgit_clone_head(struct cgit_context *ctx) | 98 | void cgit_clone_head(void) |
99 | { | 99 | { |
100 | send_file(ctx, git_path("%s", "HEAD")); | 100 | send_file(git_path("%s", "HEAD")); |
101 | } | 101 | } |
@@ -1,8 +1,8 @@ | |||
1 | #ifndef UI_CLONE_H | 1 | #ifndef UI_CLONE_H |
2 | #define UI_CLONE_H | 2 | #define UI_CLONE_H |
3 | 3 | ||
4 | void cgit_clone_info(struct cgit_context *ctx); | 4 | void cgit_clone_info(void); |
5 | void cgit_clone_objects(struct cgit_context *ctx); | 5 | void cgit_clone_objects(void); |
6 | void cgit_clone_head(struct cgit_context *ctx); | 6 | void cgit_clone_head(void); |
7 | 7 | ||
8 | #endif /* UI_CLONE_H */ | 8 | #endif /* UI_CLONE_H */ |
@@ -407,7 +407,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, | |||
407 | diff_setup_done(&diffopt); | 407 | diff_setup_done(&diffopt); |
408 | 408 | ||
409 | ctx.page.mimetype = "text/plain"; | 409 | ctx.page.mimetype = "text/plain"; |
410 | cgit_print_http_headers(&ctx); | 410 | cgit_print_http_headers(); |
411 | if (old_tree_sha1) { | 411 | if (old_tree_sha1) { |
412 | diff_tree_sha1(old_tree_sha1, new_tree_sha1, "", | 412 | diff_tree_sha1(old_tree_sha1, new_tree_sha1, "", |
413 | &diffopt); | 413 | &diffopt); |
@@ -59,7 +59,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, | |||
59 | patchname = fmt("%s.patch", rev_range); | 59 | patchname = fmt("%s.patch", rev_range); |
60 | ctx.page.mimetype = "text/plain"; | 60 | ctx.page.mimetype = "text/plain"; |
61 | ctx.page.filename = patchname; | 61 | ctx.page.filename = patchname; |
62 | cgit_print_http_headers(&ctx); | 62 | cgit_print_http_headers(); |
63 | 63 | ||
64 | if (ctx.cfg.noplainemail) { | 64 | if (ctx.cfg.noplainemail) { |
65 | rev_argv[2] = "--format=format:From %H Mon Sep 17 00:00:00 " | 65 | rev_argv[2] = "--format=format:From %H Mon Sep 17 00:00:00 " |
@@ -103,7 +103,7 @@ static int print_object(const unsigned char *sha1, const char *path) | |||
103 | ctx.page.filename = path; | 103 | ctx.page.filename = path; |
104 | ctx.page.size = size; | 104 | ctx.page.size = size; |
105 | ctx.page.etag = sha1_to_hex(sha1); | 105 | ctx.page.etag = sha1_to_hex(sha1); |
106 | cgit_print_http_headers(&ctx); | 106 | cgit_print_http_headers(); |
107 | html_raw(buf, size); | 107 | html_raw(buf, size); |
108 | /* If we allocated this, then casting away const is safe. */ | 108 | /* If we allocated this, then casting away const is safe. */ |
109 | if (freemime) | 109 | if (freemime) |
@@ -128,7 +128,7 @@ static void print_dir(const unsigned char *sha1, const char *base, | |||
128 | fullpath = buildpath(base, baselen, path); | 128 | fullpath = buildpath(base, baselen, path); |
129 | slash = (fullpath[0] == '/' ? "" : "/"); | 129 | slash = (fullpath[0] == '/' ? "" : "/"); |
130 | ctx.page.etag = sha1_to_hex(sha1); | 130 | ctx.page.etag = sha1_to_hex(sha1); |
131 | cgit_print_http_headers(&ctx); | 131 | cgit_print_http_headers(); |
132 | htmlf("<html><head><title>%s", slash); | 132 | htmlf("<html><head><title>%s", slash); |
133 | html_txt(fullpath); | 133 | html_txt(fullpath); |
134 | htmlf("</title></head>\n<body>\n<h2>%s", slash); | 134 | htmlf("</title></head>\n<body>\n<h2> |