author | Lars Hjemli <hjemli@gmail.com> | 2006-12-11 15:11:40 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2006-12-11 15:11:40 (UTC) |
commit | 51ada4fda2b47710351e6e4da8a95807d6d9f729 (patch) (unidiff) | |
tree | 48b543fd16b666db7024038506ffc4eadb0ca966 | |
parent | 318d106300102c19d114a4ea89265b0a4060d9cb (diff) | |
download | cgit-51ada4fda2b47710351e6e4da8a95807d6d9f729.zip cgit-51ada4fda2b47710351e6e4da8a95807d6d9f729.tar.gz cgit-51ada4fda2b47710351e6e4da8a95807d6d9f729.tar.bz2 |
Rename config.c to parsing.c + move cgit_parse_query from cgit.c to parsing.c
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | cgit.c | 26 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | parsing.c (renamed from config.c) | 25 |
4 files changed, 29 insertions, 28 deletions
@@ -1,26 +1,27 @@ | |||
1 | CGIT_VERSION = 0.1-pre | 1 | CGIT_VERSION = 0.1-pre |
2 | 2 | ||
3 | INSTALL_BIN = /var/www/htdocs/cgit.cgi | 3 | INSTALL_BIN = /var/www/htdocs/cgit.cgi |
4 | INSTALL_CSS = /var/www/htdocs/cgit.css | 4 | 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 = config.o html.o cache.o | 8 | OBJECTS = parsing.o html.o cache.o |
9 | 9 | ||
10 | CFLAGS += -Wall | 10 | CFLAGS += -Wall |
11 | 11 | ||
12 | all: cgit | 12 | all: cgit |
13 | 13 | ||
14 | install: all | 14 | install: all |
15 | install cgit $(INSTALL_BIN) | 15 | install cgit $(INSTALL_BIN) |
16 | install cgit.css $(INSTALL_CSS) | 16 | install cgit.css $(INSTALL_CSS) |
17 | rm -rf $(CACHE_ROOT)/* | 17 | rm -rf $(CACHE_ROOT)/* |
18 | 18 | ||
19 | cgit: cgit.c cgit.h git.h $(OBJECTS) | 19 | cgit: cgit.c cgit.h git.h $(OBJECTS) |
20 | $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit $(OBJECTS) $(EXTLIBS) | 20 | $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit \ |
21 | $(OBJECTS) $(EXTLIBS) | ||
21 | 22 | ||
22 | $(OBJECTS): cgit.h git.h | 23 | $(OBJECTS): cgit.h git.h |
23 | 24 | ||
24 | .PHONY: clean | 25 | .PHONY: clean |
25 | clean: | 26 | clean: |
26 | rm -f cgit *.o | 27 | rm -f cgit *.o |
@@ -8,122 +8,96 @@ | |||
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | const char cgit_version[] = CGIT_VERSION; | 11 | const char cgit_version[] = CGIT_VERSION; |
12 | 12 | ||
13 | const char cgit_doctype[] = | 13 | const char cgit_doctype[] = |
14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
16 | 16 | ||
17 | const char cgit_error[] = | 17 | const char cgit_error[] = |
18 | "<div class='error'>%s</div>"; | 18 | "<div class='error'>%s</div>"; |
19 | 19 | ||
20 | const char cgit_lib_error[] = | 20 | const char cgit_lib_error[] = |
21 | "<div class='error'>%s: %s</div>"; | 21 | "<div class='error'>%s: %s</div>"; |
22 | 22 | ||
23 | int htmlfd = 0; | 23 | int htmlfd = 0; |
24 | 24 | ||
25 | char *cgit_root = "/usr/src/git"; | 25 | char *cgit_root = "/usr/src/git"; |
26 | char *cgit_root_title = "Git repository browser"; | 26 | char *cgit_root_title = "Git repository browser"; |
27 | char *cgit_css = "/cgit.css"; | 27 | char *cgit_css = "/cgit.css"; |
28 | char *cgit_logo = "/git-logo.png"; | 28 | char *cgit_logo = "/git-logo.png"; |
29 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | 29 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
30 | char *cgit_virtual_root = NULL; | 30 | char *cgit_virtual_root = NULL; |
31 | 31 | ||
32 | char *cgit_cache_root = "/var/cache/cgit"; | 32 | char *cgit_cache_root = "/var/cache/cgit"; |
33 | 33 | ||
34 | int cgit_max_lock_attempts = 5; | 34 | int cgit_max_lock_attempts = 5; |
35 | int cgit_cache_root_ttl = 5; | 35 | int cgit_cache_root_ttl = 5; |
36 | int cgit_cache_repo_ttl = 5; | 36 | int cgit_cache_repo_ttl = 5; |
37 | int cgit_cache_dynamic_ttl = 5; | 37 | int cgit_cache_dynamic_ttl = 5; |
38 | int cgit_cache_static_ttl = -1; | 38 | int cgit_cache_static_ttl = -1; |
39 | int cgit_cache_max_create_time = 5; | 39 | int cgit_cache_max_create_time = 5; |
40 | 40 | ||
41 | char *cgit_repo_name = NULL; | 41 | char *cgit_repo_name = NULL; |
42 | char *cgit_repo_desc = NULL; | 42 | char *cgit_repo_desc = NULL; |
43 | char *cgit_repo_owner = NULL; | 43 | char *cgit_repo_owner = NULL; |
44 | 44 | ||
45 | int cgit_query_has_symref = 0; | 45 | int cgit_query_has_symref = 0; |
46 | int cgit_query_has_sha1 = 0; | 46 | int cgit_query_has_sha1 = 0; |
47 | 47 | ||
48 | char *cgit_querystring = NULL; | 48 | char *cgit_querystring = NULL; |
49 | char *cgit_query_repo = NULL; | 49 | char *cgit_query_repo = NULL; |
50 | char *cgit_query_page = NULL; | 50 | char *cgit_query_page = NULL; |
51 | char *cgit_query_head = NULL; | 51 | char *cgit_query_head = NULL; |
52 | char *cgit_query_sha1 = NULL; | 52 | char *cgit_query_sha1 = NULL; |
53 | 53 | ||
54 | struct cacheitem cacheitem; | 54 | struct cacheitem cacheitem; |
55 | 55 | ||
56 | int cgit_parse_query(char *txt, configfn fn) | ||
57 | { | ||
58 | char *t, *value = NULL, c; | ||
59 | |||
60 | if (!txt) | ||
61 | return 0; | ||
62 | |||
63 | t = txt = xstrdup(txt); | ||
64 | |||
65 | while((c=*t) != '\0') { | ||
66 | if (c=='=') { | ||
67 | *t = '\0'; | ||
68 | value = t+1; | ||
69 | } else if (c=='&') { | ||
70 | *t = '\0'; | ||
71 | (*fn)(txt, value); | ||
72 | txt = t+1; | ||
73 | value = NULL; | ||
74 | } | ||
75 | t++; | ||
76 | } | ||
77 | if (t!=txt) | ||
78 | (*fn)(txt, value); | ||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | void cgit_global_config_cb(const char *name, const char *value) | 56 | void cgit_global_config_cb(const char *name, const char *value) |
83 | { | 57 | { |
84 | if (!strcmp(name, "root")) | 58 | if (!strcmp(name, "root")) |
85 | cgit_root = xstrdup(value); | 59 | cgit_root = xstrdup(value); |
86 | else if (!strcmp(name, "root-title")) | 60 | else if (!strcmp(name, "root-title")) |
87 | cgit_root_title = xstrdup(value); | 61 | cgit_root_title = xstrdup(value); |
88 | else if (!strcmp(name, "css")) | 62 | else if (!strcmp(name, "css")) |
89 | cgit_css = xstrdup(value); | 63 | cgit_css = xstrdup(value); |
90 | else if (!strcmp(name, "logo")) | 64 | else if (!strcmp(name, "logo")) |
91 | cgit_logo = xstrdup(value); | 65 | cgit_logo = xstrdup(value); |
92 | else if (!strcmp(name, "logo-link")) | 66 | else if (!strcmp(name, "logo-link")) |
93 | cgit_logo_link = xstrdup(value); | 67 | cgit_logo_link = xstrdup(value); |
94 | else if (!strcmp(name, "virtual-root")) | 68 | else if (!strcmp(name, "virtual-root")) |
95 | cgit_virtual_root = xstrdup(value); | 69 | cgit_virtual_root = xstrdup(value); |
96 | } | 70 | } |
97 | 71 | ||
98 | void cgit_repo_config_cb(const char *name, const char *value) | 72 | void cgit_repo_config_cb(const char *name, const char *value) |
99 | { | 73 | { |
100 | if (!strcmp(name, "name")) | 74 | if (!strcmp(name, "name")) |
101 | cgit_repo_name = xstrdup(value); | 75 | cgit_repo_name = xstrdup(value); |
102 | else if (!strcmp(name, "desc")) | 76 | else if (!strcmp(name, "desc")) |
103 | cgit_repo_desc = xstrdup(value); | 77 | cgit_repo_desc = xstrdup(value); |
104 | else if (!strcmp(name, "owner")) | 78 | else if (!strcmp(name, "owner")) |
105 | cgit_repo_owner = xstrdup(value); | 79 | cgit_repo_owner = xstrdup(value); |
106 | } | 80 | } |
107 | 81 | ||
108 | void cgit_querystring_cb(const char *name, const char *value) | 82 | void cgit_querystring_cb(const char *name, const char *value) |
109 | { | 83 | { |
110 | if (!strcmp(name,"r")) | 84 | if (!strcmp(name,"r")) |
111 | cgit_query_repo = xstrdup(value); | 85 | cgit_query_repo = xstrdup(value); |
112 | else if (!strcmp(name, "p")) | 86 | else if (!strcmp(name, "p")) |
113 | cgit_query_page = xstrdup(value); | 87 | cgit_query_page = xstrdup(value); |
114 | else if (!strcmp(name, "h")) { | 88 | else if (!strcmp(name, "h")) { |
115 | cgit_query_head = xstrdup(value); | 89 | cgit_query_head = xstrdup(value); |
116 | cgit_query_has_symref = 1; | 90 | cgit_query_has_symref = 1; |
117 | } else if (!strcmp(name, "id")) { | 91 | } else if (!strcmp(name, "id")) { |
118 | cgit_query_sha1 = xstrdup(value); | 92 | cgit_query_sha1 = xstrdup(value); |
119 | cgit_query_has_sha1 = 1; | 93 | cgit_query_has_sha1 = 1; |
120 | } | 94 | } |
121 | } | 95 | } |
122 | 96 | ||
123 | char *cgit_repourl(const char *reponame) | 97 | char *cgit_repourl(const char *reponame) |
124 | { | 98 | { |
125 | if (cgit_virtual_root) { | 99 | if (cgit_virtual_root) { |
126 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 100 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
127 | } else { | 101 | } else { |
128 | return fmt("?r=%s", reponame); | 102 | return fmt("?r=%s", reponame); |
129 | } | 103 | } |
@@ -11,56 +11,57 @@ typedef void (*configfn)(const char *name, const char *value); | |||
11 | struct cacheitem { | 11 | struct cacheitem { |
12 | char *name; | 12 | char *name; |
13 | struct stat st; | 13 | struct stat st; |
14 | int ttl; | 14 | int ttl; |
15 | int fd; | 15 | int fd; |
16 | }; | 16 | }; |
17 | 17 | ||
18 | extern char *cgit_root; | 18 | extern char *cgit_root; |
19 | extern char *cgit_root_title; | 19 | extern char *cgit_root_title; |
20 | extern char *cgit_css; | 20 | extern char *cgit_css; |
21 | extern char *cgit_logo; | 21 | extern char *cgit_logo; |
22 | extern char *cgit_logo_link; | 22 | extern char *cgit_logo_link; |
23 | extern char *cgit_virtual_root; | 23 | extern char *cgit_virtual_root; |
24 | extern char *cgit_cache_root; | 24 | extern char *cgit_cache_root; |
25 | 25 | ||
26 | extern int cgit_max_lock_attempts; | 26 | extern int cgit_max_lock_attempts; |
27 | extern int cgit_cache_root_ttl; | 27 | extern int cgit_cache_root_ttl; |
28 | extern int cgit_cache_repo_ttl; | 28 | extern int cgit_cache_repo_ttl; |
29 | extern int cgit_cache_dynamic_ttl; | 29 | extern int cgit_cache_dynamic_ttl; |
30 | extern int cgit_cache_static_ttl; | 30 | extern int cgit_cache_static_ttl; |
31 | extern int cgit_cache_max_create_time; | 31 | extern int cgit_cache_max_create_time; |
32 | 32 | ||
33 | extern char *cgit_repo_name; | 33 | extern char *cgit_repo_name; |
34 | extern char *cgit_repo_desc; | 34 | extern char *cgit_repo_desc; |
35 | extern char *cgit_repo_owner; | 35 | extern char *cgit_repo_owner; |
36 | 36 | ||
37 | extern int cgit_query_has_symref; | 37 | extern int cgit_query_has_symref; |
38 | extern int cgit_query_has_sha1; | 38 | extern int cgit_query_has_sha1; |
39 | 39 | ||
40 | extern char *cgit_querystring; | 40 | extern char *cgit_querystring; |
41 | extern char *cgit_query_repo; | 41 | extern char *cgit_query_repo; |
42 | extern char *cgit_query_page; | 42 | extern char *cgit_query_page; |
43 | extern char *cgit_query_head; | 43 | extern char *cgit_query_head; |
44 | extern char *cgit_query_sha1; | 44 | extern char *cgit_query_sha1; |
45 | 45 | ||
46 | extern int htmlfd; | 46 | extern int htmlfd; |
47 | 47 | ||
48 | extern char *fmt(const char *format,...); | 48 | extern char *fmt(const char *format,...); |
49 | 49 | ||
50 | extern void html(const char *txt); | 50 | extern void html(const char *txt); |
51 | extern void htmlf(const char *format,...); | 51 | extern void htmlf(const char *format,...); |
52 | extern void html_txt(char *txt); | 52 | extern void html_txt(char *txt); |
53 | extern void html_attr(char *txt); | 53 | extern void html_attr(char *txt); |
54 | extern void html_link_open(char *url, char *title, char *class); | 54 | extern void html_link_open(char *url, char *title, char *class); |
55 | extern void html_link_close(void); | 55 | extern void html_link_close(void); |
56 | 56 | ||
57 | 57 | ||
58 | extern int cgit_read_config(const char *filename, configfn fn); | 58 | extern int cgit_read_config(const char *filename, configfn fn); |
59 | extern int cgit_parse_query(char *txt, configfn fn); | ||
59 | 60 | ||
60 | extern void cache_prepare(struct cacheitem *item); | 61 | extern void cache_prepare(struct cacheitem *item); |
61 | extern int cache_lock(struct cacheitem *item); | 62 | extern int cache_lock(struct cacheitem *item); |
62 | extern int cache_unlock(struct cacheitem *item); | 63 | extern int cache_unlock(struct cacheitem *item); |
63 | extern int cache_exist(struct cacheitem *item); | 64 | extern int cache_exist(struct cacheitem *item); |
64 | extern int cache_expired(struct cacheitem *item); | 65 | extern int cache_expired(struct cacheitem *item); |
65 | 66 | ||
66 | #endif /* CGIT_H */ | 67 | #endif /* CGIT_H */ |
@@ -34,48 +34,73 @@ int read_config_line(FILE *f, char *line, const char **value, int bufsize) | |||
34 | int i = 0, isname = 0; | 34 | int i = 0, isname = 0; |
35 | 35 | ||
36 | *value = NULL; | 36 | *value = NULL; |
37 | while(i<bufsize-1) { | 37 | while(i<bufsize-1) { |
38 | int c = next_char(f); | 38 | int c = next_char(f); |
39 | if (!isname && (c=='#' || c==';')) { | 39 | if (!isname && (c=='#' || c==';')) { |
40 | skip_line(f); | 40 | skip_line(f); |
41 | continue; | 41 | continue; |
42 | } | 42 | } |
43 | if (!isname && isspace(c)) | 43 | if (!isname && isspace(c)) |
44 | continue; | 44 | continue; |
45 | 45 | ||
46 | if (c=='=' && !*value) { | 46 | if (c=='=' && !*value) { |
47 | line[i] = 0; | 47 | line[i] = 0; |
48 | *value = &line[i+1]; | 48 | *value = &line[i+1]; |
49 | } else if (c=='\n' && !isname) { | 49 | } else if (c=='\n' && !isname) { |
50 | i = 0; | 50 | i = 0; |
51 | continue; | 51 | continue; |
52 | } else if (c=='\n' || c==EOF) { | 52 | } else if (c=='\n' || c==EOF) { |
53 | line[i] = 0; | 53 | line[i] = 0; |
54 | break; | 54 | break; |
55 | } else { | 55 | } else { |
56 | line[i]=c; | 56 | line[i]=c; |
57 | } | 57 | } |
58 | isname = 1; | 58 | isname = 1; |
59 | i++; | 59 | i++; |
60 | } | 60 | } |
61 | line[i+1] = 0; | 61 | line[i+1] = 0; |
62 | return i; | 62 | return i; |
63 | } | 63 | } |
64 | 64 | ||
65 | int cgit_read_config(const char *filename, configfn fn) | 65 | int cgit_read_config(const char *filename, configfn fn) |
66 | { | 66 | { |
67 | int ret = 0, len; | 67 | int ret = 0, len; |
68 | char line[256]; | 68 | char line[256]; |
69 | const char *value; | 69 | const char *value; |
70 | FILE *f = fopen(filename, "r"); | 70 | FILE *f = fopen(filename, "r"); |
71 | 71 | ||
72 | if (!f) | 72 | if (!f) |
73 | return -1; | 73 | return -1; |
74 | 74 | ||
75 | while((len = read_config_line(f, line, &value, sizeof(line))) > 0) | 75 | while((len = read_config_line(f, line, &value, sizeof(line))) > 0) |
76 | (*fn)(line, value); | 76 | (*fn)(line, value); |
77 | 77 | ||
78 | fclose(f); | 78 | fclose(f); |
79 | return ret; | 79 | return ret; |
80 | } | 80 | } |
81 | 81 | ||
82 | int cgit_parse_query(char *txt, configfn fn) | ||
83 | { | ||
84 | char *t, *value = NULL, c; | ||
85 | |||
86 | if (!txt) | ||
87 | return 0; | ||
88 | |||
89 | t = txt = xstrdup(txt); | ||
90 | |||
91 | while((c=*t) != '\0') { | ||
92 | if (c=='=') { | ||
93 | *t = '\0'; | ||
94 | value = t+1; | ||
95 | } else if (c=='&') { | ||
96 | *t = '\0'; | ||
97 | (*fn)(txt, value); | ||
98 | txt = t+1; | ||
99 | value = NULL; | ||
100 | } | ||
101 | t++; | ||
102 | } | ||
103 | if (t!=txt) | ||
104 | (*fn)(txt, value); | ||
105 | return 0; | ||
106 | } | ||