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 /parsing.c | |
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-- | parsing.c | 49 |
1 files changed, 0 insertions, 49 deletions
@@ -1,123 +1,74 @@ | |||
1 | /* config.c: parsing of config files | 1 | /* config.c: parsing of config files |
2 | * | 2 | * |
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) |
68 | { | 19 | { |
69 | char *cmd, *p; | 20 | char *cmd, *p; |
70 | 21 | ||
71 | ctx.repo = NULL; | 22 | ctx.repo = NULL; |
72 | if (!url || url[0] == '\0') | 23 | if (!url || url[0] == '\0') |
73 | return; | 24 | return; |
74 | 25 | ||
75 | ctx.repo = cgit_get_repoinfo(url); | 26 | ctx.repo = cgit_get_repoinfo(url); |
76 | if (ctx.repo) { | 27 | if (ctx.repo) { |
77 | ctx.qry.repo = ctx.repo->url; | 28 | ctx.qry.repo = ctx.repo->url; |
78 | return; | 29 | return; |
79 | } | 30 | } |
80 | 31 | ||
81 | cmd = strchr(url, '/'); | 32 | cmd = strchr(url, '/'); |
82 | while (!ctx.repo && cmd) { | 33 | while (!ctx.repo && cmd) { |
83 | cmd[0] = '\0'; | 34 | cmd[0] = '\0'; |
84 | ctx.repo = cgit_get_repoinfo(url); | 35 | ctx.repo = cgit_get_repoinfo(url); |
85 | if (ctx.repo == NULL) { | 36 | if (ctx.repo == NULL) { |
86 | cmd[0] = '/'; | 37 | cmd[0] = '/'; |
87 | cmd = strchr(cmd + 1, '/'); | 38 | cmd = strchr(cmd + 1, '/'); |
88 | continue; | 39 | continue; |
89 | } | 40 | } |
90 | 41 | ||
91 | ctx.qry.repo = ctx.repo->url; | 42 | ctx.qry.repo = ctx.repo->url; |
92 | p = strchr(cmd + 1, '/'); | 43 | p = strchr(cmd + 1, '/'); |
93 | if (p) { | 44 | if (p) { |
94 | p[0] = '\0'; | 45 | p[0] = '\0'; |
95 | if (p[1]) | 46 | if (p[1]) |
96 | ctx.qry.path = trim_end(p + 1, '/'); | 47 | ctx.qry.path = trim_end(p + 1, '/'); |
97 | } | 48 | } |
98 | if (cmd[1]) | 49 | if (cmd[1]) |
99 | ctx.qry.page = xstrdup(cmd + 1); | 50 | ctx.qry.page = xstrdup(cmd + 1); |
100 | return; | 51 | return; |
101 | } | 52 | } |
102 | } | 53 | } |
103 | 54 | ||
104 | char *substr(const char *head, const char *tail) | 55 | char *substr(const char *head, const char *tail) |
105 | { | 56 | { |
106 | char *buf; | 57 | char *buf; |
107 | 58 | ||
108 | buf = xmalloc(tail - head + 1); | 59 | buf = xmalloc(tail - head + 1); |
109 | strncpy(buf, head, tail - head); | 60 | strncpy(buf, head, tail - head); |
110 | buf[tail - head] = '\0'; | 61 | buf[tail - head] = '\0'; |
111 | return buf; | 62 | return buf; |
112 | } | 63 | } |
113 | 64 | ||
114 | struct commitinfo *cgit_parse_commit(struct commit *commit) | 65 | struct commitinfo *cgit_parse_commit(struct commit *commit) |
115 | { | 66 | { |
116 | struct commitinfo *ret; | 67 | struct commitinfo *ret; |
117 | char *p = commit->buffer, *t = commit->buffer; | 68 | char *p = commit->buffer, *t = commit->buffer; |
118 | 69 | ||
119 | ret = xmalloc(sizeof(*ret)); | 70 | ret = xmalloc(sizeof(*ret)); |
120 | ret->commit = commit; | 71 | ret->commit = commit; |
121 | ret->author = NULL; | 72 | ret->author = NULL; |
122 | ret->author_email = NULL; | 73 | ret->author_email = NULL; |
123 | ret->committer = NULL; | 74 | ret->committer = NULL; |