aboutsummaryrefslogtreecommitdiffstats
path: root/cgit.c
diff options
context:
space:
mode:
authorGravatar Lars Hjemli <hjemli@gmail.com>2006-12-12 01:25:41 (JST)
committerGravatar Lars Hjemli <hjemli@gmail.com>2006-12-12 01:25:51 (JST)
commit44923f8953c66dc9b852316b655ab3b5aec9478e (patch)
treee129ec8db3f8ffcf7f82f94052f430e576a9714c /cgit.c
parentdf63119302910587e280d91dce67f6537a671f74 (diff)
downloadcgit-44923f8953c66dc9b852316b655ab3b5aec9478e.zip
cgit-44923f8953c66dc9b852316b655ab3b5aec9478e.tar.gz
Move global variables + callback functions into shared.c
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'cgit.c')
-rw-r--r--cgit.c83
1 files changed, 6 insertions, 77 deletions
diff --git a/cgit.c b/cgit.c
index 52d9bd3..d1abaa0 100644
--- a/cgit.c
+++ b/cgit.c
@@ -10,80 +10,6 @@
10 10
11const char cgit_version[] = CGIT_VERSION; 11const char cgit_version[] = CGIT_VERSION;
12 12
13int htmlfd = 0;
14
15char *cgit_root = "/usr/src/git";
16char *cgit_root_title = "Git repository browser";
17char *cgit_css = "/cgit.css";
18char *cgit_logo = "/git-logo.png";
19char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
20char *cgit_virtual_root = NULL;
21
22char *cgit_cache_root = "/var/cache/cgit";
23
24int cgit_max_lock_attempts = 5;
25int cgit_cache_root_ttl = 5;
26int cgit_cache_repo_ttl = 5;
27int cgit_cache_dynamic_ttl = 5;
28int cgit_cache_static_ttl = -1;
29int cgit_cache_max_create_time = 5;
30
31char *cgit_repo_name = NULL;
32char *cgit_repo_desc = NULL;
33char *cgit_repo_owner = NULL;
34
35int cgit_query_has_symref = 0;
36int cgit_query_has_sha1 = 0;
37
38char *cgit_querystring = NULL;
39char *cgit_query_repo = NULL;
40char *cgit_query_page = NULL;
41char *cgit_query_head = NULL;
42char *cgit_query_sha1 = NULL;
43
44struct cacheitem cacheitem;
45
46void cgit_global_config_cb(const char *name, const char *value)
47{
48 if (!strcmp(name, "root"))
49 cgit_root = xstrdup(value);
50 else if (!strcmp(name, "root-title"))
51 cgit_root_title = xstrdup(value);
52 else if (!strcmp(name, "css"))
53 cgit_css = xstrdup(value);
54 else if (!strcmp(name, "logo"))
55 cgit_logo = xstrdup(value);
56 else if (!strcmp(name, "logo-link"))
57 cgit_logo_link = xstrdup(value);
58 else if (!strcmp(name, "virtual-root"))
59 cgit_virtual_root = xstrdup(value);
60}
61
62void cgit_repo_config_cb(const char *name, const char *value)
63{
64 if (!strcmp(name, "name"))
65 cgit_repo_name = xstrdup(value);
66 else if (!strcmp(name, "desc"))
67 cgit_repo_desc = xstrdup(value);
68 else if (!strcmp(name, "owner"))
69 cgit_repo_owner = xstrdup(value);
70}
71
72void cgit_querystring_cb(const char *name, const char *value)
73{
74 if (!strcmp(name,"r"))
75 cgit_query_repo = xstrdup(value);
76 else if (!strcmp(name, "p"))
77 cgit_query_page = xstrdup(value);
78 else if (!strcmp(name, "h")) {
79 cgit_query_head = xstrdup(value);
80 cgit_query_has_symref = 1;
81 } else if (!strcmp(name, "id")) {
82 cgit_query_sha1 = xstrdup(value);
83 cgit_query_has_sha1 = 1;
84 }
85}
86
87static void cgit_print_repo_page(struct cacheitem *item) 13static void cgit_print_repo_page(struct cacheitem *item)
88{ 14{
89 if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) || 15 if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) ||
@@ -120,7 +46,7 @@ static void cgit_fill_cache(struct cacheitem *item)
120 cgit_print_repolist(item); 46 cgit_print_repolist(item);
121} 47}
122 48
123static void cgit_refresh_cache(struct cacheitem *item) 49static void cgit_check_cache(struct cacheitem *item)
124{ 50{
125 int i = 0; 51 int i = 0;
126 52
@@ -162,10 +88,13 @@ static void cgit_print_cache(struct cacheitem *item)
162 88
163int main(int argc, const char **argv) 89int main(int argc, const char **argv)
164{ 90{
91 struct cacheitem item;
92
165 cgit_read_config("/etc/cgitrc", cgit_global_config_cb); 93 cgit_read_config("/etc/cgitrc", cgit_global_config_cb);
166 cgit_querystring = xstrdup(getenv("QUERY_STRING")); 94 cgit_querystring = xstrdup(getenv("QUERY_STRING"));
167 cgit_parse_query(cgit_querystring, cgit_querystring_cb); 95 cgit_parse_query(cgit_querystring, cgit_querystring_cb);
168 cgit_refresh_cache(&cacheitem); 96
169 cgit_print_cache(&cacheitem); 97 cgit_check_cache(&item);
98 cgit_print_cache(&item);
170 return 0; 99 return 0;
171} 100}