|
diff --git a/Makefile b/Makefile index c71e39c..eab7926 100644 --- a/ Makefile+++ b/ Makefile |
|
@@ -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 |
|
|
diff --git a/cgit.c b/cgit.c index dc91125..5567859 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -40,58 +40,32 @@ 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 | |
|
|
diff --git a/cgit.h b/cgit.h index 7e4bfef..6c0aa3b 100644 --- a/ cgit.h+++ b/ cgit.h |
|
@@ -43,24 +43,25 @@ 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 */ |
|
|
diff --git a/config.c b/parsing.c index 871edf2..98b3243 100644 --- a/ config.c+++ b/ parsing.c |
|
@@ -66,16 +66,41 @@ 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 | } |
|