summaryrefslogtreecommitdiffabout
path: root/shared.c
Unidiff
Diffstat (limited to 'shared.c') (more/less context) (show whitespace changes)
-rw-r--r--shared.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/shared.c b/shared.c
index 76e10d0..539d533 100644
--- a/shared.c
+++ b/shared.c
@@ -1,133 +1,136 @@
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 cgit_repolist cgit_repolist; 11struct cgit_repolist cgit_repolist;
12struct cgit_context ctx; 12struct cgit_context ctx;
13int cgit_cmd; 13int cgit_cmd;
14 14
15const char *cgit_version = CGIT_VERSION; 15const char *cgit_version = CGIT_VERSION;
16 16
17void cgit_prepare_context(struct cgit_context *ctx) 17void 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
40int cgit_get_cmd_index(const char *cmd) 43int 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
52int chk_zero(int result, char *msg) 55int 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
59int chk_positive(int result, char *msg) 62int 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
66int chk_non_negative(int result, char *msg) 69int 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
73struct cgit_repo *add_repo(const char *url) 76struct 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}
102 105
103struct cgit_repo *cgit_get_repoinfo(const char *url) 106struct cgit_repo *cgit_get_repoinfo(const char *url)
104{ 107{
105 int i; 108 int i;
106 struct cgit_repo *repo; 109 struct cgit_repo *repo;
107 110
108 for (i=0; i<cgit_repolist.count; i++) { 111 for (i=0; i<cgit_repolist.count; i++) {
109 repo = &cgit_repolist.repos[i]; 112 repo = &cgit_repolist.repos[i];
110 if (!strcmp(repo->url, url)) 113 if (!strcmp(repo->url, url))
111 return repo; 114 return repo;
112 } 115 }
113 return NULL; 116 return NULL;
114} 117}
115 118
116void cgit_global_config_cb(const char *name, const char *value) 119void cgit_global_config_cb(const char *name, const char *value)
117{ 120{
118 if (!strcmp(name, "root-title")) 121 if (!strcmp(name, "root-title"))
119 ctx.cfg.root_title = xstrdup(value); 122 ctx.cfg.root_title = xstrdup(value);
120 else if (!strcmp(name, "css")) 123 else if (!strcmp(name, "css"))
121 ctx.cfg.css = xstrdup(value); 124 ctx.cfg.css = xstrdup(value);
122 else if (!strcmp(name, "logo")) 125 else if (!strcmp(name, "logo"))
123 ctx.cfg.logo = xstrdup(value); 126 ctx.cfg.logo = xstrdup(value);
124 else if (!strcmp(name, "index-header")) 127 else if (!strcmp(name, "index-header"))
125 ctx.cfg.index_header = xstrdup(value); 128 ctx.cfg.index_header = xstrdup(value);
126 else if (!strcmp(name, "index-info")) 129 else if (!strcmp(name, "index-info"))
127 ctx.cfg.index_info = xstrdup(value); 130 ctx.cfg.index_info = xstrdup(value);
128 else if (!strcmp(name, "logo-link")) 131 else if (!strcmp(name, "logo-link"))
129 ctx.cfg.logo_link = xstrdup(value); 132 ctx.cfg.logo_link = xstrdup(value);
130 else if (!strcmp(name, "module-link")) 133 else if (!strcmp(name, "module-link"))
131 ctx.cfg.module_link = xstrdup(value); 134 ctx.cfg.module_link = xstrdup(value);
132 else if (!strcmp(name, "virtual-root")) { 135 else if (!strcmp(name, "virtual-root")) {
133 ctx.cfg.virtual_root = trim_end(value, '/'); 136 ctx.cfg.virtual_root = trim_end(value, '/');