summaryrefslogtreecommitdiffabout
path: root/shared.c
Unidiff
Diffstat (limited to 'shared.c') (more/less context) (show whitespace changes)
-rw-r--r--shared.c13
1 files changed, 0 insertions, 13 deletions
diff --git a/shared.c b/shared.c
index 539d533..67eb67b 100644
--- a/shared.c
+++ b/shared.c
@@ -19,60 +19,48 @@ void cgit_prepare_context(struct cgit_context *ctx)
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"; 38 ctx->page.mimetype = "text/html";
39 ctx->page.charset = PAGE_ENCODING; 39 ctx->page.charset = PAGE_ENCODING;
40 ctx->page.filename = NULL; 40 ctx->page.filename = NULL;
41} 41}
42 42
43int cgit_get_cmd_index(const char *cmd)
44{
45 static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
46 "snapshot", "tag", "refs", "patch", NULL};
47 int i;
48
49 for(i = 0; cmds[i]; i++)
50 if (!strcmp(cmd, cmds[i]))
51 return i + 1;
52 return 0;
53}
54
55int chk_zero(int result, char *msg) 43int chk_zero(int result, char *msg)
56{ 44{
57 if (result != 0) 45 if (result != 0)
58 die("%s: %s", msg, strerror(errno)); 46 die("%s: %s", msg, strerror(errno));
59 return result; 47 return result;
60} 48}
61 49
62int chk_positive(int result, char *msg) 50int chk_positive(int result, char *msg)
63{ 51{
64 if (result <= 0) 52 if (result <= 0)
65 die("%s: %s", msg, strerror(errno)); 53 die("%s: %s", msg, strerror(errno));
66 return result; 54 return result;
67} 55}
68 56
69int chk_non_negative(int result, char *msg) 57int chk_non_negative(int result, char *msg)
70{ 58{
71 if (result < 0) 59 if (result < 0)
72 die("%s: %s",msg, strerror(errno)); 60 die("%s: %s",msg, strerror(errno));
73 return result; 61 return result;
74} 62}
75 63
76struct cgit_repo *add_repo(const char *url) 64struct cgit_repo *add_repo(const char *url)
77{ 65{
78 struct cgit_repo *ret; 66 struct cgit_repo *ret;
@@ -195,49 +183,48 @@ void cgit_global_config_cb(const char *name, const char *value)
195 else if (ctx.repo && !strcmp(name, "repo.snapshots")) 183 else if (ctx.repo && !strcmp(name, "repo.snapshots"))
196 ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ 184 ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
197 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) 185 else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount"))
198 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); 186 ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
199 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) 187 else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount"))
200 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); 188 ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
201 else if (ctx.repo && !strcmp(name, "repo.module-link")) 189 else if (ctx.repo && !strcmp(name, "repo.module-link"))
202 ctx.repo->module_link= xstrdup(value); 190 ctx.repo->module_link= xstrdup(value);
203 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { 191 else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) {
204 if (*value == '/') 192 if (*value == '/')
205 ctx.repo->readme = xstrdup(value); 193 ctx.repo->readme = xstrdup(value);
206 else 194 else
207 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); 195 ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value));
208 } else if (!strcmp(name, "include")) 196 } else if (!strcmp(name, "include"))
209 cgit_read_config(value, cgit_global_config_cb); 197 cgit_read_config(value, cgit_global_config_cb);
210} 198}
211 199
212void cgit_querystring_cb(const char *name, const char *value) 200void cgit_querystring_cb(const char *name, const char *value)
213{ 201{
214 if (!strcmp(name,"r")) { 202 if (!strcmp(name,"r")) {
215 ctx.qry.repo = xstrdup(value); 203 ctx.qry.repo = xstrdup(value);
216 ctx.repo = cgit_get_repoinfo(value); 204 ctx.repo = cgit_get_repoinfo(value);
217 } else if (!strcmp(name, "p")) { 205 } else if (!strcmp(name, "p")) {
218 ctx.qry.page = xstrdup(value); 206 ctx.qry.page = xstrdup(value);
219 cgit_cmd = cgit_get_cmd_index(value);
220 } else if (!strcmp(name, "url")) { 207 } else if (!strcmp(name, "url")) {
221 cgit_parse_url(value); 208 cgit_parse_url(value);
222 } else if (!strcmp(name, "qt")) { 209 } else if (!strcmp(name, "qt")) {
223 ctx.qry.grep = xstrdup(value); 210 ctx.qry.grep = xstrdup(value);
224 } else if (!strcmp(name, "q")) { 211 } else if (!strcmp(name, "q")) {
225 ctx.qry.search = xstrdup(value); 212 ctx.qry.search = xstrdup(value);
226 } else if (!strcmp(name, "h")) { 213 } else if (!strcmp(name, "h")) {
227 ctx.qry.head = xstrdup(value); 214 ctx.qry.head = xstrdup(value);
228 ctx.qry.has_symref = 1; 215 ctx.qry.has_symref = 1;
229 } else if (!strcmp(name, "id")) { 216 } else if (!strcmp(name, "id")) {
230 ctx.qry.sha1 = xstrdup(value); 217 ctx.qry.sha1 = xstrdup(value);
231 ctx.qry.has_sha1 = 1; 218 ctx.qry.has_sha1 = 1;
232 } else if (!strcmp(name, "id2")) { 219 } else if (!strcmp(name, "id2")) {
233 ctx.qry.sha2 = xstrdup(value); 220 ctx.qry.sha2 = xstrdup(value);
234 ctx.qry.has_sha1 = 1; 221 ctx.qry.has_sha1 = 1;
235 } else if (!strcmp(name, "ofs")) { 222 } else if (!strcmp(name, "ofs")) {
236 ctx.qry.ofs = atoi(value); 223 ctx.qry.ofs = atoi(value);
237 } else if (!strcmp(name, "path")) { 224 } else if (!strcmp(name, "path")) {
238 ctx.qry.path = trim_end(value, '/'); 225 ctx.qry.path = trim_end(value, '/');
239 } else if (!strcmp(name, "name")) { 226 } else if (!strcmp(name, "name")) {
240 ctx.qry.name = xstrdup(value); 227 ctx.qry.name = xstrdup(value);
241 } 228 }
242} 229}
243 230