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