diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | cgit.c | 83 | ||||
-rw-r--r-- | cgit.h | 7 | ||||
-rw-r--r-- | shared.c | 74 |
4 files changed, 86 insertions, 82 deletions
diff --git a/Makefile b/Makefile index 4e532d0..c029637 100644 --- a/Makefile +++ b/Makefile | |||
@@ -5,8 +5,8 @@ INSTALL_CSS = /var/www/htdocs/cgit.css | |||
5 | CACHE_ROOT = /var/cache/cgit | 5 | CACHE_ROOT = /var/cache/cgit |
6 | 6 | ||
7 | EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto | 7 | EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto |
8 | OBJECTS = cache.o parsing.o html.o ui-shared.o ui-repolist.o ui-summary.o \ | 8 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
9 | ui-log.o ui-view.c | 9 | ui-summary.o ui-log.o ui-view.c |
10 | 10 | ||
11 | CFLAGS += -Wall | 11 | CFLAGS += -Wall |
12 | 12 | ||
diff --git a/cgit.c b/cgit.c index 52d9bd3..d1abaa0 100644 --- a/cgit.c +++ b/cgit.c | |||
@@ -10,80 +10,6 @@ | |||
10 | 10 | ||
11 | const char cgit_version[] = CGIT_VERSION; | 11 | const char cgit_version[] = CGIT_VERSION; |
12 | 12 | ||
13 | int htmlfd = 0; | ||
14 | |||
15 | char *cgit_root = "/usr/src/git"; | ||
16 | char *cgit_root_title = "Git repository browser"; | ||
17 | char *cgit_css = "/cgit.css"; | ||
18 | char *cgit_logo = "/git-logo.png"; | ||
19 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | ||
20 | char *cgit_virtual_root = NULL; | ||
21 | |||
22 | char *cgit_cache_root = "/var/cache/cgit"; | ||
23 | |||
24 | int cgit_max_lock_attempts = 5; | ||
25 | int cgit_cache_root_ttl = 5; | ||
26 | int cgit_cache_repo_ttl = 5; | ||
27 | int cgit_cache_dynamic_ttl = 5; | ||
28 | int cgit_cache_static_ttl = -1; | ||
29 | int cgit_cache_max_create_time = 5; | ||
30 | |||
31 | char *cgit_repo_name = NULL; | ||
32 | char *cgit_repo_desc = NULL; | ||
33 | char *cgit_repo_owner = NULL; | ||
34 | |||
35 | int cgit_query_has_symref = 0; | ||
36 | int cgit_query_has_sha1 = 0; | ||
37 | |||
38 | char *cgit_querystring = NULL; | ||
39 | char *cgit_query_repo = NULL; | ||
40 | char *cgit_query_page = NULL; | ||
41 | char *cgit_query_head = NULL; | ||
42 | char *cgit_query_sha1 = NULL; | ||
43 | |||
44 | struct cacheitem cacheitem; | ||
45 | |||
46 | void 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 | |||
62 | void 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 | |||
72 | void 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 | |||
87 | static void cgit_print_repo_page(struct cacheitem *item) | 13 | static 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 | ||
123 | static void cgit_refresh_cache(struct cacheitem *item) | 49 | static 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 | ||
163 | int main(int argc, const char **argv) | 89 | int 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 | } |
diff --git a/cgit.h b/cgit.h index 9c7f0b4..c1dcc97 100644 --- a/cgit.h +++ b/cgit.h | |||
@@ -47,6 +47,10 @@ extern char *cgit_query_sha1; | |||
47 | 47 | ||
48 | extern int htmlfd; | 48 | extern int htmlfd; |
49 | 49 | ||
50 | extern void cgit_global_config_cb(const char *name, const char *value); | ||
51 | extern void cgit_repo_config_cb(const char *name, const char *value); | ||
52 | extern void cgit_querystring_cb(const char *name, const char *value); | ||
53 | |||
50 | extern char *fmt(const char *format,...); | 54 | extern char *fmt(const char *format,...); |
51 | 55 | ||
52 | extern void html(const char *txt); | 56 | extern void html(const char *txt); |
@@ -79,7 +83,4 @@ extern void cgit_print_summary(); | |||
79 | extern void cgit_print_log(const char *tip, int ofs, int cnt); | 83 | extern void cgit_print_log(const char *tip, int ofs, int cnt); |
80 | extern void cgit_print_view(char *hex); | 84 | extern void cgit_print_view(char *hex); |
81 | 85 | ||
82 | extern void cgit_repo_config_cb(const char *name, const char *value); | ||
83 | |||
84 | |||
85 | #endif /* CGIT_H */ | 86 | #endif /* CGIT_H */ |
diff --git a/shared.c b/shared.c new file mode 100644 index 0000000..c58a2ff --- /dev/null +++ b/shared.c | |||
@@ -0,0 +1,74 @@ | |||
1 | #include "cgit.h" | ||
2 | |||
3 | char *cgit_root = "/usr/src/git"; | ||
4 | char *cgit_root_title = "Git repository browser"; | ||
5 | char *cgit_css = "/cgit.css"; | ||
6 | char *cgit_logo = "/git-logo.png"; | ||
7 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | ||
8 | char *cgit_virtual_root = NULL; | ||
9 | |||
10 | char *cgit_cache_root = "/var/cache/cgit"; | ||
11 | |||
12 | int cgit_max_lock_attempts = 5; | ||
13 | int cgit_cache_root_ttl = 5; | ||
14 | int cgit_cache_repo_ttl = 5; | ||
15 | int cgit_cache_dynamic_ttl = 5; | ||
16 | int cgit_cache_static_ttl = -1; | ||
17 | int cgit_cache_max_create_time = 5; | ||
18 | |||
19 | char *cgit_repo_name = NULL; | ||
20 | char *cgit_repo_desc = NULL; | ||
21 | char *cgit_repo_owner = NULL; | ||
22 | |||
23 | int cgit_query_has_symref = 0; | ||
24 | int cgit_query_has_sha1 = 0; | ||
25 | |||
26 | char *cgit_querystring = NULL; | ||
27 | char *cgit_query_repo = NULL; | ||
28 | char *cgit_query_page = NULL; | ||
29 | char *cgit_query_head = NULL; | ||
30 | char *cgit_query_sha1 = NULL; | ||
31 | |||
32 | int htmlfd = 0; | ||
33 | |||
34 | void cgit_global_config_cb(const char *name, const char *value) | ||
35 | { | ||
36 | if (!strcmp(name, "root")) | ||
37 | cgit_root = xstrdup(value); | ||
38 | else if (!strcmp(name, "root-title")) | ||
39 | cgit_root_title = xstrdup(value); | ||
40 | else if (!strcmp(name, "css")) | ||
41 | cgit_css = xstrdup(value); | ||
42 | else if (!strcmp(name, "logo")) | ||
43 | cgit_logo = xstrdup(value); | ||
44 | else if (!strcmp(name, "logo-link")) | ||
45 | cgit_logo_link = xstrdup(value); | ||
46 | else if (!strcmp(name, "virtual-root")) | ||
47 | cgit_virtual_root = xstrdup(value); | ||
48 | } | ||
49 | |||
50 | void cgit_repo_config_cb(const char *name, const char *value) | ||
51 | { | ||
52 | if (!strcmp(name, "name")) | ||
53 | cgit_repo_name = xstrdup(value); | ||
54 | else if (!strcmp(name, "desc")) | ||
55 | cgit_repo_desc = xstrdup(value); | ||
56 | else if (!strcmp(name, "owner")) | ||
57 | cgit_repo_owner = xstrdup(value); | ||
58 | } | ||
59 | |||
60 | void cgit_querystring_cb(const char *name, const char *value) | ||
61 | { | ||
62 | if (!strcmp(name,"r")) | ||
63 | cgit_query_repo = xstrdup(value); | ||
64 | else if (!strcmp(name, "p")) | ||
65 | cgit_query_page = xstrdup(value); | ||
66 | else if (!strcmp(name, "h")) { | ||
67 | cgit_query_head = xstrdup(value); | ||
68 | cgit_query_has_symref = 1; | ||
69 | } else if (!strcmp(name, "id")) { | ||
70 | cgit_query_sha1 = xstrdup(value); | ||
71 | cgit_query_has_sha1 = 1; | ||
72 | } | ||
73 | } | ||
74 | |||