author | Lars Hjemli <hjemli@gmail.com> | 2008-04-08 19:11:36 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-04-08 19:11:36 (UTC) |
commit | e87e89633383b8b75c68c98be3e0c14212109de2 (patch) (unidiff) | |
tree | f57e131ab854b58023387aee8efc0e4ee54653b5 | |
parent | 20a33548b9a87a6eb23162ee5d137daa46d78613 (diff) | |
download | cgit-e87e89633383b8b75c68c98be3e0c14212109de2.zip cgit-e87e89633383b8b75c68c98be3e0c14212109de2.tar.gz cgit-e87e89633383b8b75c68c98be3e0c14212109de2.tar.bz2 |
Move cgit_parse_query() from parsing.c to html.c as http_parse_querystring()
This is a generic http-function.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | html.c | 64 | ||||
-rw-r--r-- | html.h | 2 | ||||
-rw-r--r-- | parsing.c | 49 | ||||
-rw-r--r-- | shared.c | 12 |
6 files changed, 68 insertions, 64 deletions
@@ -12,2 +12,3 @@ | |||
12 | #include "configfile.h" | 12 | #include "configfile.h" |
13 | #include "html.h" | ||
13 | #include "ui-shared.h" | 14 | #include "ui-shared.h" |
@@ -446,3 +447,3 @@ int main(int argc, const char **argv) | |||
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)) |
@@ -193,3 +193,2 @@ 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); |
@@ -216,3 +215,2 @@ 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); |
@@ -187 +187,65 @@ int html_include(const char *filename) | |||
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 | } | ||
@@ -17,2 +17,4 @@ 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 */ |
@@ -10,51 +10,2 @@ | |||
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 | /* |
@@ -91,14 +91,2 @@ void *cgit_free_commitinfo(struct commitinfo *info) | |||
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) |