|
diff --git a/shared.c b/shared.c index f20fb5c..f7f43b2 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -1,142 +1,144 @@ |
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 repolist cgit_repolist; |
11 | struct repolist cgit_repolist; |
12 | struct repoinfo *cgit_repo; |
12 | struct repoinfo *cgit_repo; |
13 | int cgit_cmd; |
13 | int cgit_cmd; |
14 | |
14 | |
| |
15 | const char *cgit_version = CGIT_VERSION; |
| |
16 | |
15 | char *cgit_root_title = "Git repository browser"; |
17 | char *cgit_root_title = "Git repository browser"; |
16 | char *cgit_css = "/cgit.css"; |
18 | char *cgit_css = "/cgit.css"; |
17 | char *cgit_logo = "/git-logo.png"; |
19 | char *cgit_logo = "/git-logo.png"; |
18 | char *cgit_index_header = NULL; |
20 | char *cgit_index_header = NULL; |
19 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
21 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
20 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; |
22 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; |
21 | char *cgit_agefile = "info/web/last-modified"; |
23 | char *cgit_agefile = "info/web/last-modified"; |
22 | char *cgit_virtual_root = NULL; |
24 | char *cgit_virtual_root = NULL; |
23 | char *cgit_script_name = CGIT_SCRIPT_NAME; |
25 | char *cgit_script_name = CGIT_SCRIPT_NAME; |
24 | char *cgit_cache_root = "/var/cache/cgit"; |
26 | char *cgit_cache_root = "/var/cache/cgit"; |
25 | char *cgit_repo_group = NULL; |
27 | char *cgit_repo_group = NULL; |
26 | |
28 | |
27 | int cgit_nocache = 0; |
29 | int cgit_nocache = 0; |
28 | int cgit_snapshots = 0; |
30 | int cgit_snapshots = 0; |
29 | int cgit_enable_log_filecount = 0; |
31 | int cgit_enable_log_filecount = 0; |
30 | int cgit_enable_log_linecount = 0; |
32 | int cgit_enable_log_linecount = 0; |
31 | int cgit_max_lock_attempts = 5; |
33 | int cgit_max_lock_attempts = 5; |
32 | int cgit_cache_root_ttl = 5; |
34 | int cgit_cache_root_ttl = 5; |
33 | int cgit_cache_repo_ttl = 5; |
35 | int cgit_cache_repo_ttl = 5; |
34 | int cgit_cache_dynamic_ttl = 5; |
36 | int cgit_cache_dynamic_ttl = 5; |
35 | int cgit_cache_static_ttl = -1; |
37 | int cgit_cache_static_ttl = -1; |
36 | int cgit_cache_max_create_time = 5; |
38 | int cgit_cache_max_create_time = 5; |
37 | int cgit_summary_log = 0; |
39 | int cgit_summary_log = 0; |
38 | |
40 | |
39 | int cgit_max_msg_len = 60; |
41 | int cgit_max_msg_len = 60; |
40 | int cgit_max_repodesc_len = 60; |
42 | int cgit_max_repodesc_len = 60; |
41 | int cgit_max_commit_count = 50; |
43 | int cgit_max_commit_count = 50; |
42 | |
44 | |
43 | int cgit_query_has_symref = 0; |
45 | int cgit_query_has_symref = 0; |
44 | int cgit_query_has_sha1 = 0; |
46 | int cgit_query_has_sha1 = 0; |
45 | |
47 | |
46 | char *cgit_querystring = NULL; |
48 | char *cgit_querystring = NULL; |
47 | char *cgit_query_repo = NULL; |
49 | char *cgit_query_repo = NULL; |
48 | char *cgit_query_page = NULL; |
50 | char *cgit_query_page = NULL; |
49 | char *cgit_query_head = NULL; |
51 | char *cgit_query_head = NULL; |
50 | char *cgit_query_search = NULL; |
52 | char *cgit_query_search = NULL; |
51 | char *cgit_query_sha1 = NULL; |
53 | char *cgit_query_sha1 = NULL; |
52 | char *cgit_query_sha2 = NULL; |
54 | char *cgit_query_sha2 = NULL; |
53 | char *cgit_query_path = NULL; |
55 | char *cgit_query_path = NULL; |
54 | char *cgit_query_name = NULL; |
56 | char *cgit_query_name = NULL; |
55 | int cgit_query_ofs = 0; |
57 | int cgit_query_ofs = 0; |
56 | |
58 | |
57 | int htmlfd = 0; |
59 | int htmlfd = 0; |
58 | |
60 | |
59 | |
61 | |
60 | int cgit_get_cmd_index(const char *cmd) |
62 | int cgit_get_cmd_index(const char *cmd) |
61 | { |
63 | { |
62 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
64 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
63 | "snapshot", NULL}; |
65 | "snapshot", NULL}; |
64 | int i; |
66 | int i; |
65 | |
67 | |
66 | for(i = 0; cmds[i]; i++) |
68 | for(i = 0; cmds[i]; i++) |
67 | if (!strcmp(cmd, cmds[i])) |
69 | if (!strcmp(cmd, cmds[i])) |
68 | return i + 1; |
70 | return i + 1; |
69 | return 0; |
71 | return 0; |
70 | } |
72 | } |
71 | |
73 | |
72 | int chk_zero(int result, char *msg) |
74 | int chk_zero(int result, char *msg) |
73 | { |
75 | { |
74 | if (result != 0) |
76 | if (result != 0) |
75 | die("%s: %s", msg, strerror(errno)); |
77 | die("%s: %s", msg, strerror(errno)); |
76 | return result; |
78 | return result; |
77 | } |
79 | } |
78 | |
80 | |
79 | int chk_positive(int result, char *msg) |
81 | int chk_positive(int result, char *msg) |
80 | { |
82 | { |
81 | if (result <= 0) |
83 | if (result <= 0) |
82 | die("%s: %s", msg, strerror(errno)); |
84 | die("%s: %s", msg, strerror(errno)); |
83 | return result; |
85 | return result; |
84 | } |
86 | } |
85 | |
87 | |
86 | struct repoinfo *add_repo(const char *url) |
88 | struct repoinfo *add_repo(const char *url) |
87 | { |
89 | { |
88 | struct repoinfo *ret; |
90 | struct repoinfo *ret; |
89 | |
91 | |
90 | if (++cgit_repolist.count > cgit_repolist.length) { |
92 | if (++cgit_repolist.count > cgit_repolist.length) { |
91 | if (cgit_repolist.length == 0) |
93 | if (cgit_repolist.length == 0) |
92 | cgit_repolist.length = 8; |
94 | cgit_repolist.length = 8; |
93 | else |
95 | else |
94 | cgit_repolist.length *= 2; |
96 | cgit_repolist.length *= 2; |
95 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
97 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
96 | cgit_repolist.length * |
98 | cgit_repolist.length * |
97 | sizeof(struct repoinfo)); |
99 | sizeof(struct repoinfo)); |
98 | } |
100 | } |
99 | |
101 | |
100 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
102 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
101 | ret->url = xstrdup(url); |
103 | ret->url = xstrdup(url); |
102 | ret->name = ret->url; |
104 | ret->name = ret->url; |
103 | ret->path = NULL; |
105 | ret->path = NULL; |
104 | ret->desc = NULL; |
106 | ret->desc = NULL; |
105 | ret->owner = NULL; |
107 | ret->owner = NULL; |
106 | ret->group = cgit_repo_group; |
108 | ret->group = cgit_repo_group; |
107 | ret->defbranch = "master"; |
109 | ret->defbranch = "master"; |
108 | ret->snapshots = cgit_snapshots; |
110 | ret->snapshots = cgit_snapshots; |
109 | ret->enable_log_filecount = cgit_enable_log_filecount; |
111 | ret->enable_log_filecount = cgit_enable_log_filecount; |
110 | ret->enable_log_linecount = cgit_enable_log_linecount; |
112 | ret->enable_log_linecount = cgit_enable_log_linecount; |
111 | ret->module_link = cgit_module_link; |
113 | ret->module_link = cgit_module_link; |
112 | ret->readme = NULL; |
114 | ret->readme = NULL; |
113 | return ret; |
115 | return ret; |
114 | } |
116 | } |
115 | |
117 | |
116 | struct repoinfo *cgit_get_repoinfo(const char *url) |
118 | struct repoinfo *cgit_get_repoinfo(const char *url) |
117 | { |
119 | { |
118 | int i; |
120 | int i; |
119 | struct repoinfo *repo; |
121 | struct repoinfo *repo; |
120 | |
122 | |
121 | for (i=0; i<cgit_repolist.count; i++) { |
123 | for (i=0; i<cgit_repolist.count; i++) { |
122 | repo = &cgit_repolist.repos[i]; |
124 | repo = &cgit_repolist.repos[i]; |
123 | if (!strcmp(repo->url, url)) |
125 | if (!strcmp(repo->url, url)) |
124 | return repo; |
126 | return repo; |
125 | } |
127 | } |
126 | return NULL; |
128 | return NULL; |
127 | } |
129 | } |
128 | |
130 | |
129 | void cgit_global_config_cb(const char *name, const char *value) |
131 | void cgit_global_config_cb(const char *name, const char *value) |
130 | { |
132 | { |
131 | if (!strcmp(name, "root-title")) |
133 | if (!strcmp(name, "root-title")) |
132 | cgit_root_title = xstrdup(value); |
134 | cgit_root_title = xstrdup(value); |
133 | else if (!strcmp(name, "css")) |
135 | else if (!strcmp(name, "css")) |
134 | cgit_css = xstrdup(value); |
136 | cgit_css = xstrdup(value); |
135 | else if (!strcmp(name, "logo")) |
137 | else if (!strcmp(name, "logo")) |
136 | cgit_logo = xstrdup(value); |
138 | cgit_logo = xstrdup(value); |
137 | else if (!strcmp(name, "index-header")) |
139 | else if (!strcmp(name, "index-header")) |
138 | cgit_index_header = xstrdup(value); |
140 | cgit_index_header = xstrdup(value); |
139 | else if (!strcmp(name, "logo-link")) |
141 | else if (!strcmp(name, "logo-link")) |
140 | cgit_logo_link = xstrdup(value); |
142 | cgit_logo_link = xstrdup(value); |
141 | else if (!strcmp(name, "module-link")) |
143 | else if (!strcmp(name, "module-link")) |
142 | cgit_module_link = xstrdup(value); |
144 | cgit_module_link = xstrdup(value); |
|