summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2006-12-11 15:11:40 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2006-12-11 15:11:40 (UTC)
commit51ada4fda2b47710351e6e4da8a95807d6d9f729 (patch) (unidiff)
tree48b543fd16b666db7024038506ffc4eadb0ca966
parent318d106300102c19d114a4ea89265b0a4060d9cb (diff)
downloadcgit-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>
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
@@ -8,122 +8,96 @@
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11const char cgit_version[] = CGIT_VERSION; 11const char cgit_version[] = CGIT_VERSION;
12 12
13const char cgit_doctype[] = 13const 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
17const char cgit_error[] = 17const char cgit_error[] =
18"<div class='error'>%s</div>"; 18"<div class='error'>%s</div>";
19 19
20const char cgit_lib_error[] = 20const char cgit_lib_error[] =
21"<div class='error'>%s: %s</div>"; 21"<div class='error'>%s: %s</div>";
22 22
23int htmlfd = 0; 23int htmlfd = 0;
24 24
25char *cgit_root = "/usr/src/git"; 25char *cgit_root = "/usr/src/git";
26char *cgit_root_title = "Git repository browser"; 26char *cgit_root_title = "Git repository browser";
27char *cgit_css = "/cgit.css"; 27char *cgit_css = "/cgit.css";
28char *cgit_logo = "/git-logo.png"; 28char *cgit_logo = "/git-logo.png";
29char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; 29char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
30char *cgit_virtual_root = NULL; 30char *cgit_virtual_root = NULL;
31 31
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);
106} 80}
107 81
108void cgit_querystring_cb(const char *name, const char *value) 82void 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
123char *cgit_repourl(const char *reponame) 97char *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 }
diff --git a/cgit.h b/cgit.h
index 7e4bfef..6c0aa3b 100644
--- a/cgit.h
+++ b/cgit.h
@@ -11,56 +11,57 @@ typedef void (*configfn)(const char *name, const char *value);
11struct cacheitem { 11struct 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
18extern char *cgit_root; 18extern char *cgit_root;
19extern char *cgit_root_title; 19extern char *cgit_root_title;
20extern char *cgit_css; 20extern char *cgit_css;
21extern char *cgit_logo; 21extern char *cgit_logo;
22extern char *cgit_logo_link; 22extern char *cgit_logo_link;
23extern char *cgit_virtual_root; 23extern char *cgit_virtual_root;
24extern char *cgit_cache_root; 24extern char *cgit_cache_root;
25 25
26extern int cgit_max_lock_attempts; 26extern int cgit_max_lock_attempts;
27extern int cgit_cache_root_ttl; 27extern int cgit_cache_root_ttl;
28extern int cgit_cache_repo_ttl; 28extern int cgit_cache_repo_ttl;
29extern int cgit_cache_dynamic_ttl; 29extern int cgit_cache_dynamic_ttl;
30extern int cgit_cache_static_ttl; 30extern int cgit_cache_static_ttl;
31extern int cgit_cache_max_create_time; 31extern int cgit_cache_max_create_time;
32 32
33extern char *cgit_repo_name; 33extern char *cgit_repo_name;
34extern char *cgit_repo_desc; 34extern 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
@@ -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
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}