|
diff --git a/shared.c b/shared.c index 76e10d0..539d533 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -1,101 +1,104 @@ |
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 | } |
86 | |
89 | |
87 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
90 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
88 | ret->url = trim_end(url, '/'); |
91 | ret->url = trim_end(url, '/'); |
89 | ret->name = ret->url; |
92 | ret->name = ret->url; |
90 | ret->path = NULL; |
93 | ret->path = NULL; |
91 | ret->desc = "[no description]"; |
94 | ret->desc = "[no description]"; |
92 | ret->owner = NULL; |
95 | ret->owner = NULL; |
93 | ret->group = ctx.cfg.repo_group; |
96 | ret->group = ctx.cfg.repo_group; |
94 | ret->defbranch = "master"; |
97 | ret->defbranch = "master"; |
95 | ret->snapshots = ctx.cfg.snapshots; |
98 | ret->snapshots = ctx.cfg.snapshots; |
96 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
99 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
97 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
100 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
98 | ret->module_link = ctx.cfg.module_link; |
101 | ret->module_link = ctx.cfg.module_link; |
99 | ret->readme = NULL; |
102 | ret->readme = NULL; |
100 | return ret; |
103 | return ret; |
101 | } |
104 | } |
|