summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile5
-rw-r--r--cgit.c26
-rw-r--r--cgit.h1
-rw-r--r--parsing.c (renamed from config.c)25
4 files changed, 29 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index c71e39c..eab7926 100644
--- a/Makefile
+++ b/Makefile
@@ -1,26 +1,27 @@
1CGIT_VERSION = 0.1-pre 1CGIT_VERSION = 0.1-pre
2 2
3INSTALL_BIN = /var/www/htdocs/cgit.cgi 3INSTALL_BIN = /var/www/htdocs/cgit.cgi
4INSTALL_CSS = /var/www/htdocs/cgit.css 4INSTALL_CSS = /var/www/htdocs/cgit.css
5CACHE_ROOT = /var/cache/cgit 5CACHE_ROOT = /var/cache/cgit
6 6
7EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto 7EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto
8OBJECTS = config.o html.o cache.o 8OBJECTS = parsing.o html.o cache.o
9 9
10CFLAGS += -Wall 10CFLAGS += -Wall
11 11
12all: cgit 12all: cgit
13 13
14install: all 14install: 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
19cgit: cgit.c cgit.h git.h $(OBJECTS) 19cgit: 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
25clean: 26clean:
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
@@ -32,74 +32,48 @@ char *cgit_virtual_root = NULL;
32char *cgit_cache_root = "/var/cache/cgit"; 32char *cgit_cache_root = "/var/cache/cgit";
33 33
34int cgit_max_lock_attempts = 5; 34int cgit_max_lock_attempts = 5;
35int cgit_cache_root_ttl = 5; 35int cgit_cache_root_ttl = 5;
36int cgit_cache_repo_ttl = 5; 36int cgit_cache_repo_ttl = 5;
37int cgit_cache_dynamic_ttl = 5; 37int cgit_cache_dynamic_ttl = 5;
38int cgit_cache_static_ttl = -1; 38int cgit_cache_static_ttl = -1;
39int cgit_cache_max_create_time = 5; 39int cgit_cache_max_create_time = 5;
40 40
41char *cgit_repo_name = NULL; 41char *cgit_repo_name = NULL;
42char *cgit_repo_desc = NULL; 42char *cgit_repo_desc = NULL;
43char *cgit_repo_owner = NULL; 43char *cgit_repo_owner = NULL;
44 44
45int cgit_query_has_symref = 0; 45int cgit_query_has_symref = 0;
46int cgit_query_has_sha1 = 0; 46int cgit_query_has_sha1 = 0;
47 47
48char *cgit_querystring = NULL; 48char *cgit_querystring = NULL;
49char *cgit_query_repo = NULL; 49char *cgit_query_repo = NULL;
50char *cgit_query_page = NULL; 50char *cgit_query_page = NULL;
51char *cgit_query_head = NULL; 51char *cgit_query_head = NULL;
52char *cgit_query_sha1 = NULL; 52char *cgit_query_sha1 = NULL;
53 53
54struct cacheitem cacheitem; 54struct cacheitem cacheitem;
55 55
56int 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
82void cgit_global_config_cb(const char *name, const char *value) 56void 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
98void cgit_repo_config_cb(const char *name, const char *value) 72void 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);
diff --git a/cgit.h b/cgit.h
index 7e4bfef..6c0aa3b 100644
--- a/cgit.h
+++ b/cgit.h
@@ -35,32 +35,33 @@ extern char *cgit_repo_desc;
35extern char *cgit_repo_owner; 35extern char *cgit_repo_owner;
36 36
37extern int cgit_query_has_symref; 37extern int cgit_query_has_symref;
38extern int cgit_query_has_sha1; 38extern int cgit_query_has_sha1;
39 39
40extern char *cgit_querystring; 40extern char *cgit_querystring;
41extern char *cgit_query_repo; 41extern char *cgit_query_repo;
42extern char *cgit_query_page; 42extern char *cgit_query_page;
43extern char *cgit_query_head; 43extern char *cgit_query_head;
44extern char *cgit_query_sha1; 44extern char *cgit_query_sha1;
45 45
46extern int htmlfd; 46extern int htmlfd;
47 47
48extern char *fmt(const char *format,...); 48extern char *fmt(const char *format,...);
49 49
50extern void html(const char *txt); 50extern void html(const char *txt);
51extern void htmlf(const char *format,...); 51extern void htmlf(const char *format,...);
52extern void html_txt(char *txt); 52extern void html_txt(char *txt);
53extern void html_attr(char *txt); 53extern void html_attr(char *txt);
54extern void html_link_open(char *url, char *title, char *class); 54extern void html_link_open(char *url, char *title, char *class);
55extern void html_link_close(void); 55extern void html_link_close(void);
56 56
57 57
58extern int cgit_read_config(const char *filename, configfn fn); 58extern int cgit_read_config(const char *filename, configfn fn);
59extern int cgit_parse_query(char *txt, configfn fn);
59 60
60extern void cache_prepare(struct cacheitem *item); 61extern void cache_prepare(struct cacheitem *item);
61extern int cache_lock(struct cacheitem *item); 62extern int cache_lock(struct cacheitem *item);
62extern int cache_unlock(struct cacheitem *item); 63extern int cache_unlock(struct cacheitem *item);
63extern int cache_exist(struct cacheitem *item); 64extern int cache_exist(struct cacheitem *item);
64extern int cache_expired(struct cacheitem *item); 65extern 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
@@ -58,24 +58,49 @@ int read_config_line(FILE *f, char *line, const char **value, int bufsize)
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
65int cgit_read_config(const char *filename, configfn fn) 65int 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
82int 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}