author | Lars Hjemli <hjemli@gmail.com> | 2008-03-23 23:51:19 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-03-23 23:51:19 (UTC) |
commit | f3c1a187fe2bc33f8423cd535d5045899699995b (patch) (unidiff) | |
tree | b5c553da7b108900535fcfcd24b78bdd0ac62387 /shared.c | |
parent | b1f9b9c1459cb9a30ebf80721aff6ef788d1f891 (diff) | |
download | cgit-f3c1a187fe2bc33f8423cd535d5045899699995b.zip cgit-f3c1a187fe2bc33f8423cd535d5045899699995b.tar.gz cgit-f3c1a187fe2bc33f8423cd535d5045899699995b.tar.bz2 |
Add struct cgit_page to cgit_context
This struct is used when generating http headers, and as such is another
small step towards the goal of the whole cleanup series; to invoke each
page/view function with a function pointer.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | shared.c | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -1,85 +1,88 @@ | |||
1 | /* shared.c: global vars + some callback functions | 1 | /* shared.c: global vars + some callback functions |
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 | 10 | ||
11 | struct cgit_repolist cgit_repolist; | 11 | struct cgit_repolist cgit_repolist; |
12 | struct cgit_context ctx; | 12 | struct cgit_context ctx; |
13 | int cgit_cmd; | 13 | int cgit_cmd; |
14 | 14 | ||
15 | const char *cgit_version = CGIT_VERSION; | 15 | const char *cgit_version = CGIT_VERSION; |
16 | 16 | ||
17 | void cgit_prepare_context(struct cgit_context *ctx) | 17 | void cgit_prepare_context(struct cgit_context *ctx) |
18 | { | 18 | { |
19 | memset(ctx, 0, sizeof(ctx)); | 19 | memset(ctx, 0, sizeof(ctx)); |
20 | ctx->cfg.agefile = "info/web/last-modified"; | 20 | ctx->cfg.agefile = "info/web/last-modified"; |
21 | ctx->cfg.cache_dynamic_ttl = 5; | 21 | ctx->cfg.cache_dynamic_ttl = 5; |
22 | ctx->cfg.cache_max_create_time = 5; | 22 | ctx->cfg.cache_max_create_time = 5; |
23 | ctx->cfg.cache_repo_ttl = 5; | 23 | ctx->cfg.cache_repo_ttl = 5; |
24 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | 24 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
25 | ctx->cfg.cache_root_ttl = 5; | 25 | ctx->cfg.cache_root_ttl = 5; |
26 | ctx->cfg.cache_static_ttl = -1; | 26 | ctx->cfg.cache_static_ttl = -1; |
27 | ctx->cfg.css = "/cgit.css"; | 27 | ctx->cfg.css = "/cgit.css"; |
28 | ctx->cfg.logo = "/git-logo.png"; | 28 | ctx->cfg.logo = "/git-logo.png"; |
29 | ctx->cfg.max_commit_count = 50; | 29 | ctx->cfg.max_commit_count = 50; |
30 | ctx->cfg.max_lock_attempts = 5; | 30 | ctx->cfg.max_lock_attempts = 5; |
31 | ctx->cfg.max_msg_len = 60; | 31 | ctx->cfg.max_msg_len = 60; |
32 | ctx->cfg.max_repodesc_len = 60; | 32 | ctx->cfg.max_repodesc_len = 60; |
33 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | 33 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
34 | ctx->cfg.renamelimit = -1; | 34 | ctx->cfg.renamelimit = -1; |
35 | ctx->cfg.robots = "index, nofollow"; | 35 | ctx->cfg.robots = "index, nofollow"; |
36 | ctx->cfg.root_title = "Git repository browser"; | 36 | ctx->cfg.root_title = "Git repository browser"; |
37 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | 37 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
38 | ctx->page.mimetype = "text/html"; | ||
39 | ctx->page.charset = PAGE_ENCODING; | ||
40 | ctx->page.filename = NULL; | ||
38 | } | 41 | } |
39 | 42 | ||
40 | int cgit_get_cmd_index(const char *cmd) | 43 | int cgit_get_cmd_index(const char *cmd) |
41 | { | 44 | { |
42 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", | 45 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
43 | "snapshot", "tag", "refs", "patch", NULL}; | 46 | "snapshot", "tag", "refs", "patch", NULL}; |
44 | int i; | 47 | int i; |
45 | 48 | ||
46 | for(i = 0; cmds[i]; i++) | 49 | for(i = 0; cmds[i]; i++) |
47 | if (!strcmp(cmd, cmds[i])) | 50 | if (!strcmp(cmd, cmds[i])) |
48 | return i + 1; | 51 | return i + 1; |
49 | return 0; | 52 | return 0; |
50 | } | 53 | } |
51 | 54 | ||
52 | int chk_zero(int result, char *msg) | 55 | int chk_zero(int result, char *msg) |
53 | { | 56 | { |
54 | if (result != 0) | 57 | if (result != 0) |
55 | die("%s: %s", msg, strerror(errno)); | 58 | die("%s: %s", msg, strerror(errno)); |
56 | return result; | 59 | return result; |
57 | } | 60 | } |
58 | 61 | ||
59 | int chk_positive(int result, char *msg) | 62 | int chk_positive(int result, char *msg) |
60 | { | 63 | { |
61 | if (result <= 0) | 64 | if (result <= 0) |
62 | die("%s: %s", msg, strerror(errno)); | 65 | die("%s: %s", msg, strerror(errno)); |
63 | return result; | 66 | return result; |
64 | } | 67 | } |
65 | 68 | ||
66 | int chk_non_negative(int result, char *msg) | 69 | int chk_non_negative(int result, char *msg) |
67 | { | 70 | { |
68 | if (result < 0) | 71 | if (result < 0) |
69 | die("%s: %s",msg, strerror(errno)); | 72 | die("%s: %s",msg, strerror(errno)); |
70 | return result; | 73 | return result; |
71 | } | 74 | } |
72 | 75 | ||
73 | struct cgit_repo *add_repo(const char *url) | 76 | struct cgit_repo *add_repo(const char *url) |
74 | { | 77 | { |
75 | struct cgit_repo *ret; | 78 | struct cgit_repo *ret; |
76 | 79 | ||
77 | if (++cgit_repolist.count > cgit_repolist.length) { | 80 | if (++cgit_repolist.count > cgit_repolist.length) { |
78 | if (cgit_repolist.length == 0) | 81 | if (cgit_repolist.length == 0) |
79 | cgit_repolist.length = 8; | 82 | cgit_repolist.length = 8; |
80 | else | 83 | else |
81 | cgit_repolist.length *= 2; | 84 | cgit_repolist.length *= 2; |
82 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 85 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
83 | cgit_repolist.length * | 86 | cgit_repolist.length * |
84 | sizeof(struct cgit_repo)); | 87 | sizeof(struct cgit_repo)); |
85 | } | 88 | } |