summaryrefslogtreecommitdiffabout
path: root/shared.c
Unidiff
Diffstat (limited to 'shared.c') (more/less context) (show whitespace changes)
-rw-r--r--shared.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/shared.c b/shared.c
index 4ddba61..65af11a 100644
--- a/shared.c
+++ b/shared.c
@@ -1,28 +1,30 @@
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
11struct repolist cgit_repolist; 11struct repolist cgit_repolist;
12struct repoinfo *cgit_repo; 12struct repoinfo *cgit_repo;
13int cgit_cmd;
13 14
14char *cgit_root_title = "Git repository browser"; 15char *cgit_root_title = "Git repository browser";
15char *cgit_css = "/cgit.css"; 16char *cgit_css = "/cgit.css";
16char *cgit_logo = "/git-logo.png"; 17char *cgit_logo = "/git-logo.png";
18char *cgit_index_header = NULL;
17char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; 19char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
18char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; 20char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
19char *cgit_virtual_root = NULL; 21char *cgit_virtual_root = NULL;
20char *cgit_script_name = CGIT_SCRIPT_NAME; 22char *cgit_script_name = CGIT_SCRIPT_NAME;
21char *cgit_cache_root = "/var/cache/cgit"; 23char *cgit_cache_root = "/var/cache/cgit";
22char *cgit_repo_group = NULL; 24char *cgit_repo_group = NULL;
23 25
24int cgit_nocache = 0; 26int cgit_nocache = 0;
25int cgit_snapshots = 0; 27int cgit_snapshots = 0;
26int cgit_enable_log_filecount = 0; 28int cgit_enable_log_filecount = 0;
27int cgit_enable_log_linecount = 0; 29int cgit_enable_log_linecount = 0;
28int cgit_max_lock_attempts = 5; 30int cgit_max_lock_attempts = 5;
@@ -43,24 +45,36 @@ char *cgit_querystring = NULL;
43char *cgit_query_repo = NULL; 45char *cgit_query_repo = NULL;
44char *cgit_query_page = NULL; 46char *cgit_query_page = NULL;
45char *cgit_query_head = NULL; 47char *cgit_query_head = NULL;
46char *cgit_query_search = NULL; 48char *cgit_query_search = NULL;
47char *cgit_query_sha1 = NULL; 49char *cgit_query_sha1 = NULL;
48char *cgit_query_sha2 = NULL; 50char *cgit_query_sha2 = NULL;
49char *cgit_query_path = NULL; 51char *cgit_query_path = NULL;
50char *cgit_query_name = NULL; 52char *cgit_query_name = NULL;
51int cgit_query_ofs = 0; 53int cgit_query_ofs = 0;
52 54
53int htmlfd = 0; 55int htmlfd = 0;
54 56
57
58int cgit_get_cmd_index(const char *cmd)
59{
60 static char *cmds[] = {"log", "commit", "diff", "tree", "view", "blob", "snapshot", NULL};
61 int i;
62
63 for(i = 0; cmds[i]; i++)
64 if (!strcmp(cmd, cmds[i]))
65 return i + 1;
66 return 0;
67}
68
55int chk_zero(int result, char *msg) 69int chk_zero(int result, char *msg)
56{ 70{
57 if (result != 0) 71 if (result != 0)
58 die("%s: %s", msg, strerror(errno)); 72 die("%s: %s", msg, strerror(errno));
59 return result; 73 return result;
60} 74}
61 75
62int chk_positive(int result, char *msg) 76int chk_positive(int result, char *msg)
63{ 77{
64 if (result <= 0) 78 if (result <= 0)
65 die("%s: %s", msg, strerror(errno)); 79 die("%s: %s", msg, strerror(errno));
66 return result; 80 return result;
@@ -86,32 +100,47 @@ struct repoinfo *add_repo(const char *url)
86 ret->path = NULL; 100 ret->path = NULL;
87 ret->desc = NULL; 101 ret->desc = NULL;
88 ret->owner = NULL; 102 ret->owner = NULL;
89 ret->group = cgit_repo_group; 103 ret->group = cgit_repo_group;
90 ret->defbranch = "master"; 104 ret->defbranch = "master";
91 ret->snapshots = cgit_snapshots; 105 ret->snapshots = cgit_snapshots;
92 ret->enable_log_filecount = cgit_enable_log_filecount; 106 ret->enable_log_filecount = cgit_enable_log_filecount;
93 ret->enable_log_linecount = cgit_enable_log_linecount; 107 ret->enable_log_linecount = cgit_enable_log_linecount;
94 ret->module_link = cgit_module_link; 108 ret->module_link = cgit_module_link;
95 return ret; 109 return ret;
96} 110}
97 111
112struct repoinfo *cgit_get_repoinfo(const char *url)
113{
114 int i;
115 struct repoinfo *repo;
116
117 for (i=0; i<cgit_repolist.count; i++) {
118 repo = &cgit_repolist.repos[i];
119 if (!strcmp(repo->url, url))
120 return repo;
121 }
122 return NULL;
123}
124
98void cgit_global_config_cb(const char *name, const char *value) 125void cgit_global_config_cb(const char *name, const char *value)
99{ 126{
100 if (!strcmp(name, "root-title")) 127 if (!strcmp(name, "root-title"))
101 cgit_root_title = xstrdup(value); 128 cgit_root_title = xstrdup(value);
102 else if (!strcmp(name, "css")) 129 else if (!strcmp(name, "css"))
103 cgit_css = xstrdup(value); 130 cgit_css = xstrdup(value);
104 else if (!strcmp(name, "logo")) 131 else if (!strcmp(name, "logo"))
105 cgit_logo = xstrdup(value); 132 cgit_logo = xstrdup(value);
133 else if (!strcmp(name, "index-header"))
134 cgit_index_header = xstrdup(value);
106 else if (!strcmp(name, "logo-link")) 135 else if (!strcmp(name, "logo-link"))
107 cgit_logo_link = xstrdup(value); 136 cgit_logo_link = xstrdup(value);
108 else if (!strcmp(name, "module-link")) 137 else if (!strcmp(name, "module-link"))
109 cgit_module_link = xstrdup(value); 138 cgit_module_link = xstrdup(value);
110 else if (!strcmp(name, "virtual-root")) 139 else if (!strcmp(name, "virtual-root"))
111 cgit_virtual_root = xstrdup(value); 140 cgit_virtual_root = xstrdup(value);
112 else if (!strcmp(name, "nocache")) 141 else if (!strcmp(name, "nocache"))
113 cgit_nocache = atoi(value); 142 cgit_nocache = atoi(value);
114 else if (!strcmp(name, "snapshots")) 143 else if (!strcmp(name, "snapshots"))
115 cgit_snapshots = atoi(value); 144 cgit_snapshots = atoi(value);
116 else if (!strcmp(name, "enable-log-filecount")) 145 else if (!strcmp(name, "enable-log-filecount"))
117 cgit_enable_log_filecount = atoi(value); 146 cgit_enable_log_filecount = atoi(value);
@@ -154,26 +183,30 @@ void cgit_global_config_cb(const char *name, const char *value)
154 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) 183 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount"))
155 cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); 184 cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value);
156 else if (cgit_repo && !strcmp(name, "repo.module-link")) 185 else if (cgit_repo && !strcmp(name, "repo.module-link"))
157 cgit_repo->module_link= xstrdup(value); 186 cgit_repo->module_link= xstrdup(value);
158 else if (!strcmp(name, "include")) 187 else if (!strcmp(name, "include"))
159 cgit_read_config(value, cgit_global_config_cb); 188 cgit_read_config(value, cgit_global_config_cb);
160} 189}
161 190
162void cgit_querystring_cb(const char *name, const char *value) 191void cgit_querystring_cb(const char *name, const char *value)
163{ 192{
164 if (!strcmp(name,"r")) { 193 if (!strcmp(name,"r")) {
165 cgit_query_repo = xstrdup(value); 194 cgit_query_repo = xstrdup(value);
195 cgit_repo = cgit_get_repoinfo(value);
166 } else if (!strcmp(name, "p")) { 196 } else if (!strcmp(name, "p")) {
167 cgit_query_page = xstrdup(value); 197 cgit_query_page = xstrdup(value);
198 cgit_cmd = cgit_get_cmd_index(value);
199 } else if (!strcmp(name, "url")) {
200 cgit_parse_url(value);
168 } else if (!strcmp(name, "q")) { 201 } else if (!strcmp(name, "q")) {
169 cgit_query_search = xstrdup(value); 202 cgit_query_search = xstrdup(value);
170 } else if (!strcmp(name, "h")) { 203 } else if (!strcmp(name, "h")) {
171 cgit_query_head = xstrdup(value); 204 cgit_query_head = xstrdup(value);
172 cgit_query_has_symref = 1; 205 cgit_query_has_symref = 1;
173 } else if (!strcmp(name, "id")) { 206 } else if (!strcmp(name, "id")) {
174 cgit_query_sha1 = xstrdup(value); 207 cgit_query_sha1 = xstrdup(value);
175 cgit_query_has_sha1 = 1; 208 cgit_query_has_sha1 = 1;
176 } else if (!strcmp(name, "id2")) { 209 } else if (!strcmp(name, "id2")) {
177 cgit_query_sha2 = xstrdup(value); 210 cgit_query_sha2 = xstrdup(value);
178 cgit_query_has_sha1 = 1; 211 cgit_query_has_sha1 = 1;
179 } else if (!strcmp(name, "ofs")) { 212 } else if (!strcmp(name, "ofs")) {