|
diff --git a/cgit.c b/cgit.c index 1f46e0d..763242a 100644 --- a/ cgit.c+++ b/ cgit.c |
|
@@ -5,16 +5,17 @@ |
5 | * Licensed under GNU General Public License v2 |
5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) |
6 | * (see COPYING for full license text) |
7 | */ |
7 | */ |
8 | |
8 | |
9 | #include "cgit.h" |
9 | #include "cgit.h" |
10 | #include "cache.h" |
10 | #include "cache.h" |
11 | #include "cmd.h" |
11 | #include "cmd.h" |
12 | #include "configfile.h" |
12 | #include "configfile.h" |
| |
13 | #include "html.h" |
13 | #include "ui-shared.h" |
14 | #include "ui-shared.h" |
14 | |
15 | |
15 | const char *cgit_version = CGIT_VERSION; |
16 | const char *cgit_version = CGIT_VERSION; |
16 | |
17 | |
17 | void config_cb(const char *name, const char *value) |
18 | void config_cb(const char *name, const char *value) |
18 | { |
19 | { |
19 | if (!strcmp(name, "root-title")) |
20 | if (!strcmp(name, "root-title")) |
20 | ctx.cfg.root_title = xstrdup(value); |
21 | ctx.cfg.root_title = xstrdup(value); |
@@ -439,17 +440,17 @@ int main(int argc, const char **argv) |
439 | |
440 | |
440 | parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
441 | parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
441 | config_cb); |
442 | config_cb); |
442 | if (getenv("SCRIPT_NAME")) |
443 | if (getenv("SCRIPT_NAME")) |
443 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
444 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
444 | if (getenv("QUERY_STRING")) |
445 | if (getenv("QUERY_STRING")) |
445 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
446 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
446 | cgit_parse_args(argc, argv); |
447 | cgit_parse_args(argc, argv); |
447 | cgit_parse_query(ctx.qry.raw, querystring_cb); |
448 | http_parse_querystring(ctx.qry.raw, querystring_cb); |
448 | if (!cgit_prepare_cache(&item)) |
449 | if (!cgit_prepare_cache(&item)) |
449 | return 0; |
450 | return 0; |
450 | if (ctx.cfg.nocache) { |
451 | if (ctx.cfg.nocache) { |
451 | cgit_fill_cache(&item, 0); |
452 | cgit_fill_cache(&item, 0); |
452 | } else { |
453 | } else { |
453 | cgit_check_cache(&item); |
454 | cgit_check_cache(&item); |
454 | cgit_print_cache(&item); |
455 | cgit_print_cache(&item); |
455 | } |
456 | } |
|
|
diff --git a/cgit.h b/cgit.h index 91d18f8..ee8c716 100644 --- a/ cgit.h+++ b/ cgit.h |
|
@@ -186,17 +186,16 @@ extern const struct cgit_snapshot_format cgit_snapshot_formats[]; |
186 | extern struct cgit_repo *cgit_add_repo(const char *url); |
186 | extern struct cgit_repo *cgit_add_repo(const char *url); |
187 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); |
187 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); |
188 | extern void cgit_repo_config_cb(const char *name, const char *value); |
188 | extern void cgit_repo_config_cb(const char *name, const char *value); |
189 | |
189 | |
190 | extern int chk_zero(int result, char *msg); |
190 | extern int chk_zero(int result, char *msg); |
191 | extern int chk_positive(int result, char *msg); |
191 | extern int chk_positive(int result, char *msg); |
192 | extern int chk_non_negative(int result, char *msg); |
192 | extern int chk_non_negative(int result, char *msg); |
193 | |
193 | |
194 | extern int hextoint(char c); |
| |
195 | extern char *trim_end(const char *str, char c); |
194 | extern char *trim_end(const char *str, char c); |
196 | extern char *strlpart(char *txt, int maxlen); |
195 | extern char *strlpart(char *txt, int maxlen); |
197 | extern char *strrpart(char *txt, int maxlen); |
196 | extern char *strrpart(char *txt, int maxlen); |
198 | |
197 | |
199 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
198 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
200 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
199 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
201 | int flags, void *cb_data); |
200 | int flags, void *cb_data); |
202 | |
201 | |
@@ -209,17 +208,16 @@ extern int cgit_diff_files(const unsigned char *old_sha1, |
209 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
208 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
210 | const unsigned char *new_sha1, |
209 | const unsigned char *new_sha1, |
211 | filepair_fn fn, const char *prefix); |
210 | filepair_fn fn, const char *prefix); |
212 | |
211 | |
213 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
212 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
214 | |
213 | |
215 | extern char *fmt(const char *format,...); |
214 | extern char *fmt(const char *format,...); |
216 | |
215 | |
217 | extern int cgit_parse_query(char *txt, configfn fn); |
| |
218 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
216 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
219 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
217 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
220 | extern void cgit_parse_url(const char *url); |
218 | extern void cgit_parse_url(const char *url); |
221 | |
219 | |
222 | extern const char *cgit_repobasename(const char *reponame); |
220 | extern const char *cgit_repobasename(const char *reponame); |
223 | |
221 | |
224 | extern int cgit_parse_snapshots_mask(const char *str); |
222 | extern int cgit_parse_snapshots_mask(const char *str); |
225 | |
223 | |
|
|
diff --git a/html.c b/html.c index 0962e71..98ffaf9 100644 --- a/ html.c+++ b/ html.c |
|
@@ -180,8 +180,72 @@ int html_include(const char *filename) |
180 | |
180 | |
181 | if (!(f = fopen(filename, "r"))) |
181 | if (!(f = fopen(filename, "r"))) |
182 | return -1; |
182 | return -1; |
183 | while((len = fread(buf, 1, 4096, f)) > 0) |
183 | while((len = fread(buf, 1, 4096, f)) > 0) |
184 | write(htmlfd, buf, len); |
184 | write(htmlfd, buf, len); |
185 | fclose(f); |
185 | fclose(f); |
186 | return 0; |
186 | return 0; |
187 | } |
187 | } |
| |
188 | |
| |
189 | int hextoint(char c) |
| |
190 | { |
| |
191 | if (c >= 'a' && c <= 'f') |
| |
192 | return 10 + c - 'a'; |
| |
193 | else if (c >= 'A' && c <= 'F') |
| |
194 | return 10 + c - 'A'; |
| |
195 | else if (c >= '0' && c <= '9') |
| |
196 | return c - '0'; |
| |
197 | else |
| |
198 | return -1; |
| |
199 | } |
| |
200 | |
| |
201 | char *convert_query_hexchar(char *txt) |
| |
202 | { |
| |
203 | int d1, d2; |
| |
204 | if (strlen(txt) < 3) { |
| |
205 | *txt = '\0'; |
| |
206 | return txt-1; |
| |
207 | } |
| |
208 | d1 = hextoint(*(txt+1)); |
| |
209 | d2 = hextoint(*(txt+2)); |
| |
210 | if (d1<0 || d2<0) { |
| |
211 | strcpy(txt, txt+3); |
| |
212 | return txt-1; |
| |
213 | } else { |
| |
214 | *txt = d1 * 16 + d2; |
| |
215 | strcpy(txt+1, txt+3); |
| |
216 | return txt; |
| |
217 | } |
| |
218 | } |
| |
219 | |
| |
220 | int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)) |
| |
221 | { |
| |
222 | char *t, *value = NULL, c; |
| |
223 | |
| |
224 | if (!txt) |
| |
225 | return 0; |
| |
226 | |
| |
227 | t = txt = strdup(txt); |
| |
228 | if (t == NULL) { |
| |
229 | printf("Out of memory\n"); |
| |
230 | exit(1); |
| |
231 | } |
| |
232 | while((c=*t) != '\0') { |
| |
233 | if (c=='=') { |
| |
234 | *t = '\0'; |
| |
235 | value = t+1; |
| |
236 | } else if (c=='+') { |
| |
237 | *t = ' '; |
| |
238 | } else if (c=='%') { |
| |
239 | t = convert_query_hexchar(t); |
| |
240 | } else if (c=='&') { |
| |
241 | *t = '\0'; |
| |
242 | (*fn)(txt, value); |
| |
243 | txt = t+1; |
| |
244 | value = NULL; |
| |
245 | } |
| |
246 | t++; |
| |
247 | } |
| |
248 | if (t!=txt) |
| |
249 | (*fn)(txt, value); |
| |
250 | return 0; |
| |
251 | } |
|
|
diff --git a/html.h b/html.h index 63f4551..e6fdc54 100644 --- a/ html.h+++ b/ html.h |
|
@@ -10,9 +10,11 @@ extern void html_ntxt(int len, char *txt); |
10 | extern void html_attr(char *txt); |
10 | extern void html_attr(char *txt); |
11 | extern void html_hidden(char *name, char *value); |
11 | extern void html_hidden(char *name, char *value); |
12 | extern void html_option(char *value, char *text, char *selected_value); |
12 | extern void html_option(char *value, char *text, char *selected_value); |
13 | extern void html_link_open(char *url, char *title, char *class); |
13 | extern void html_link_open(char *url, char *title, char *class); |
14 | extern void html_link_close(void); |
14 | extern void html_link_close(void); |
15 | extern void html_fileperm(unsigned short mode); |
15 | extern void html_fileperm(unsigned short mode); |
16 | extern int html_include(const char *filename); |
16 | extern int html_include(const char *filename); |
17 | |
17 | |
| |
18 | extern int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)); |
| |
19 | |
18 | #endif /* HTML_H */ |
20 | #endif /* HTML_H */ |
|
|
diff --git a/parsing.c b/parsing.c index 9a4a7a3..66e8b3d 100644 --- a/ parsing.c+++ b/ parsing.c |
|
@@ -3,65 +3,16 @@ |
3 | * Copyright (C) 2006 Lars Hjemli |
3 | * Copyright (C) 2006 Lars Hjemli |
4 | * |
4 | * |
5 | * Licensed under GNU General Public License v2 |
5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) |
6 | * (see COPYING for full license text) |
7 | */ |
7 | */ |
8 | |
8 | |
9 | #include "cgit.h" |
9 | #include "cgit.h" |
10 | |
10 | |
11 | char *convert_query_hexchar(char *txt) |
| |
12 | { |
| |
13 | int d1, d2; |
| |
14 | if (strlen(txt) < 3) { |
| |
15 | *txt = '\0'; |
| |
16 | return txt-1; |
| |
17 | } |
| |
18 | d1 = hextoint(*(txt+1)); |
| |
19 | d2 = hextoint(*(txt+2)); |
| |
20 | if (d1<0 || d2<0) { |
| |
21 | strcpy(txt, txt+3); |
| |
22 | return txt-1; |
| |
23 | } else { |
| |
24 | *txt = d1 * 16 + d2; |
| |
25 | strcpy(txt+1, txt+3); |
| |
26 | return txt; |
| |
27 | } |
| |
28 | } |
| |
29 | |
| |
30 | int cgit_parse_query(char *txt, configfn fn) |
| |
31 | { |
| |
32 | char *t, *value = NULL, c; |
| |
33 | |
| |
34 | if (!txt) |
| |
35 | return 0; |
| |
36 | |
| |
37 | t = txt = xstrdup(txt); |
| |
38 | |
| |
39 | while((c=*t) != '\0') { |
| |
40 | if (c=='=') { |
| |
41 | *t = '\0'; |
| |
42 | value = t+1; |
| |
43 | } else if (c=='+') { |
| |
44 | *t = ' '; |
| |
45 | } else if (c=='%') { |
| |
46 | t = convert_query_hexchar(t); |
| |
47 | } else if (c=='&') { |
| |
48 | *t = '\0'; |
| |
49 | (*fn)(txt, value); |
| |
50 | txt = t+1; |
| |
51 | value = NULL; |
| |
52 | } |
| |
53 | t++; |
| |
54 | } |
| |
55 | if (t!=txt) |
| |
56 | (*fn)(txt, value); |
| |
57 | return 0; |
| |
58 | } |
| |
59 | |
| |
60 | /* |
11 | /* |
61 | * url syntax: [repo ['/' cmd [ '/' path]]] |
12 | * url syntax: [repo ['/' cmd [ '/' path]]] |
62 | * repo: any valid repo url, may contain '/' |
13 | * repo: any valid repo url, may contain '/' |
63 | * cmd: log | commit | diff | tree | view | blob | snapshot |
14 | * cmd: log | commit | diff | tree | view | blob | snapshot |
64 | * path: any valid path, may contain '/' |
15 | * path: any valid path, may contain '/' |
65 | * |
16 | * |
66 | */ |
17 | */ |
67 | void cgit_parse_url(const char *url) |
18 | void cgit_parse_url(const char *url) |
|
|
diff --git a/shared.c b/shared.c index 48002ac..f5875e4 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -84,28 +84,16 @@ void *cgit_free_commitinfo(struct commitinfo *info) |
84 | free(info->committer_email); |
84 | free(info->committer_email); |
85 | free(info->subject); |
85 | free(info->subject); |
86 | free(info->msg); |
86 | free(info->msg); |
87 | free(info->msg_encoding); |
87 | free(info->msg_encoding); |
88 | free(info); |
88 | free(info); |
89 | return NULL; |
89 | return NULL; |
90 | } |
90 | } |
91 | |
91 | |
92 | int hextoint(char c) |
| |
93 | { |
| |
94 | if (c >= 'a' && c <= 'f') |
| |
95 | return 10 + c - 'a'; |
| |
96 | else if (c >= 'A' && c <= 'F') |
| |
97 | return 10 + c - 'A'; |
| |
98 | else if (c >= '0' && c <= '9') |
| |
99 | return c - '0'; |
| |
100 | else |
| |
101 | return -1; |
| |
102 | } |
| |
103 | |
| |
104 | char *trim_end(const char *str, char c) |
92 | char *trim_end(const char *str, char c) |
105 | { |
93 | { |
106 | int len; |
94 | int len; |
107 | char *s, *t; |
95 | char *s, *t; |
108 | |
96 | |
109 | if (str == NULL) |
97 | if (str == NULL) |
110 | return NULL; |
98 | return NULL; |
111 | t = (char *)str; |
99 | t = (char *)str; |
|