Blame


1 3c1cf9d0 2021-01-11 op /*
2 3c1cf9d0 2021-01-11 op * Copyright (c) 2020 Omar Polo <op@omarpolo.com>
3 3c1cf9d0 2021-01-11 op *
4 3c1cf9d0 2021-01-11 op * Permission to use, copy, modify, and distribute this software for any
5 3c1cf9d0 2021-01-11 op * purpose with or without fee is hereby granted, provided that the above
6 3c1cf9d0 2021-01-11 op * copyright notice and this permission notice appear in all copies.
7 3c1cf9d0 2021-01-11 op *
8 3c1cf9d0 2021-01-11 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 3c1cf9d0 2021-01-11 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 3c1cf9d0 2021-01-11 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 3c1cf9d0 2021-01-11 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 3c1cf9d0 2021-01-11 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 3c1cf9d0 2021-01-11 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 3c1cf9d0 2021-01-11 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 3c1cf9d0 2021-01-11 op */
16 3c1cf9d0 2021-01-11 op
17 3c1cf9d0 2021-01-11 op #include <ctype.h>
18 3c1cf9d0 2021-01-11 op #include <string.h>
19 3c1cf9d0 2021-01-11 op
20 3c1cf9d0 2021-01-11 op #include "gmid.h"
21 3c1cf9d0 2021-01-11 op
22 3c1cf9d0 2021-01-11 op static inline int
23 3c1cf9d0 2021-01-11 op unreserved(int p)
24 3c1cf9d0 2021-01-11 op {
25 3c1cf9d0 2021-01-11 op return isalnum(p)
26 3c1cf9d0 2021-01-11 op || p == '-'
27 3c1cf9d0 2021-01-11 op || p == '.'
28 3c1cf9d0 2021-01-11 op || p == '_'
29 3c1cf9d0 2021-01-11 op || p == '~';
30 3c1cf9d0 2021-01-11 op }
31 3c1cf9d0 2021-01-11 op
32 3c1cf9d0 2021-01-11 op static inline int
33 3c1cf9d0 2021-01-11 op sub_delimiters(int p)
34 3c1cf9d0 2021-01-11 op {
35 3c1cf9d0 2021-01-11 op return p == '!'
36 3c1cf9d0 2021-01-11 op || p == '$'
37 3c1cf9d0 2021-01-11 op || p == '&'
38 3c1cf9d0 2021-01-11 op || p == '\''
39 3c1cf9d0 2021-01-11 op || p == '('
40 3c1cf9d0 2021-01-11 op || p == ')'
41 3c1cf9d0 2021-01-11 op || p == '*'
42 3c1cf9d0 2021-01-11 op || p == '+'
43 3c1cf9d0 2021-01-11 op || p == ','
44 3c1cf9d0 2021-01-11 op || p == ';'
45 3c1cf9d0 2021-01-11 op || p == '=';
46 3c1cf9d0 2021-01-11 op }
47 3c1cf9d0 2021-01-11 op
48 3c1cf9d0 2021-01-11 op static int
49 3c1cf9d0 2021-01-11 op parse_pct_encoded(struct parser *p)
50 3c1cf9d0 2021-01-11 op {
51 9a672b37 2021-01-28 op if (p->iri[0] != '%')
52 3c1cf9d0 2021-01-11 op return 0;
53 3c1cf9d0 2021-01-11 op
54 9a672b37 2021-01-28 op if (!isxdigit(p->iri[1]) || !isxdigit(p->iri[2])) {
55 3c1cf9d0 2021-01-11 op p->err = "illegal percent-encoding";
56 3c1cf9d0 2021-01-11 op return 0;
57 3c1cf9d0 2021-01-11 op }
58 3c1cf9d0 2021-01-11 op
59 3c1cf9d0 2021-01-11 op sscanf(p->iri+1, "%2hhx", p->iri);
60 3c1cf9d0 2021-01-11 op memmove(p->iri+1, p->iri+3, strlen(p->iri+3)+1);
61 3c1cf9d0 2021-01-11 op if (*p->iri == '\0') {
62 3c1cf9d0 2021-01-11 op p->err = "illegal percent-encoding";
63 3c1cf9d0 2021-01-11 op return 0;
64 3c1cf9d0 2021-01-11 op }
65 3c1cf9d0 2021-01-11 op
66 3c1cf9d0 2021-01-11 op return 1;
67 3c1cf9d0 2021-01-11 op }
68 3c1cf9d0 2021-01-11 op
69 3c1cf9d0 2021-01-11 op /* ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) "://" */
70 3c1cf9d0 2021-01-11 op static int
71 3c1cf9d0 2021-01-11 op parse_scheme(struct parser *p)
72 3c1cf9d0 2021-01-11 op {
73 3c1cf9d0 2021-01-11 op p->parsed->schema = p->iri;
74 3c1cf9d0 2021-01-11 op
75 3c1cf9d0 2021-01-11 op if (!isalpha(*p->iri)) {
76 3c1cf9d0 2021-01-11 op p->err = "illegal character in scheme";
77 3c1cf9d0 2021-01-11 op return 0;
78 3c1cf9d0 2021-01-11 op }
79 3c1cf9d0 2021-01-11 op
80 de428fff 2021-01-13 op do {
81 de428fff 2021-01-13 op /* normalize the scheme (i.e. lowercase it)
82 de428fff 2021-01-13 op *
83 de428fff 2021-01-13 op * XXX: since we cannot have good things, tolower
84 881dc835 2021-01-16 op * behaviour depends on the LC_CTYPE locale. The good
85 881dc835 2021-01-16 op * news is that we're sure p->iri points to something
86 881dc835 2021-01-16 op * that's in the ASCII range, so tolower can't
87 881dc835 2021-01-16 op * mis-behave on some systems due to the locale. */
88 de428fff 2021-01-13 op *p->iri = tolower(*p->iri);
89 de428fff 2021-01-13 op p->iri++;
90 de428fff 2021-01-13 op } while (isalnum(*p->iri)
91 3c1cf9d0 2021-01-11 op || *p->iri == '+'
92 3c1cf9d0 2021-01-11 op || *p->iri == '-'
93 de428fff 2021-01-13 op || *p->iri == '.');
94 3c1cf9d0 2021-01-11 op
95 3c1cf9d0 2021-01-11 op if (*p->iri != ':') {
96 3c1cf9d0 2021-01-11 op p->err = "illegal character in scheme";
97 3c1cf9d0 2021-01-11 op return 0;
98 3c1cf9d0 2021-01-11 op }
99 3c1cf9d0 2021-01-11 op
100 3c1cf9d0 2021-01-11 op *p->iri = '\0';
101 f7b816dc 2021-01-15 op if (p->iri[1] != '/' || p->iri[2] != '/') {
102 3c1cf9d0 2021-01-11 op p->err = "invalid marker after scheme";
103 3c1cf9d0 2021-01-11 op return 0;
104 3c1cf9d0 2021-01-11 op }
105 3c1cf9d0 2021-01-11 op
106 f7b816dc 2021-01-15 op p->iri += 3;
107 3c1cf9d0 2021-01-11 op return 1;
108 3c1cf9d0 2021-01-11 op }
109 3c1cf9d0 2021-01-11 op
110 3c1cf9d0 2021-01-11 op /* *DIGIT */
111 3c1cf9d0 2021-01-11 op static int
112 3c1cf9d0 2021-01-11 op parse_port(struct parser *p)
113 3c1cf9d0 2021-01-11 op {
114 3c1cf9d0 2021-01-11 op uint32_t i = 0;
115 3c1cf9d0 2021-01-11 op
116 3c1cf9d0 2021-01-11 op p->parsed->port = p->iri;
117 3c1cf9d0 2021-01-11 op
118 3c1cf9d0 2021-01-11 op for (; isdigit(*p->iri); p->iri++) {
119 3c1cf9d0 2021-01-11 op i = i * 10 + *p->iri - '0';
120 3c1cf9d0 2021-01-11 op if (i > UINT16_MAX) {
121 3c1cf9d0 2021-01-11 op p->err = "port number too large";
122 3c1cf9d0 2021-01-11 op return 0;
123 3c1cf9d0 2021-01-11 op }
124 3c1cf9d0 2021-01-11 op }
125 3c1cf9d0 2021-01-11 op
126 3c1cf9d0 2021-01-11 op if (*p->iri != '/' && *p->iri != '\0') {
127 3c1cf9d0 2021-01-11 op p->err = "illegal character in port number";
128 3c1cf9d0 2021-01-11 op return 0;
129 3c1cf9d0 2021-01-11 op }
130 3c1cf9d0 2021-01-11 op
131 3c1cf9d0 2021-01-11 op p->parsed->port_no = i;
132 3c1cf9d0 2021-01-11 op
133 3c1cf9d0 2021-01-11 op if (*p->iri != '\0') {
134 3c1cf9d0 2021-01-11 op *p->iri = '\0';
135 3c1cf9d0 2021-01-11 op p->iri++;
136 3c1cf9d0 2021-01-11 op }
137 3c1cf9d0 2021-01-11 op
138 3c1cf9d0 2021-01-11 op return 1;
139 3c1cf9d0 2021-01-11 op }
140 3c1cf9d0 2021-01-11 op
141 3c1cf9d0 2021-01-11 op /* TODO: add support for ip-literal and ipv4addr ? */
142 3c1cf9d0 2021-01-11 op /* *( unreserved / sub-delims / pct-encoded ) */
143 3c1cf9d0 2021-01-11 op static int
144 3c1cf9d0 2021-01-11 op parse_authority(struct parser *p)
145 3c1cf9d0 2021-01-11 op {
146 3c1cf9d0 2021-01-11 op p->parsed->host = p->iri;
147 3c1cf9d0 2021-01-11 op
148 3c1cf9d0 2021-01-11 op while (unreserved(*p->iri)
149 3c1cf9d0 2021-01-11 op || sub_delimiters(*p->iri)
150 117ac52c 2021-01-29 op || parse_pct_encoded(p)
151 117ac52c 2021-01-29 op || valid_multibyte_utf8(p)) {
152 e4d82bec 2021-01-15 op /* normalize the host name. */
153 e4d82bec 2021-01-15 op if (*p->iri < 0x7F)
154 e4d82bec 2021-01-15 op *p->iri = tolower(*p->iri);
155 3c1cf9d0 2021-01-11 op p->iri++;
156 e4d82bec 2021-01-15 op }
157 3c1cf9d0 2021-01-11 op
158 3c1cf9d0 2021-01-11 op if (p->err != NULL)
159 3c1cf9d0 2021-01-11 op return 0;
160 3c1cf9d0 2021-01-11 op
161 3c1cf9d0 2021-01-11 op if (*p->iri == ':') {
162 3c1cf9d0 2021-01-11 op *p->iri = '\0';
163 3c1cf9d0 2021-01-11 op p->iri++;
164 3c1cf9d0 2021-01-11 op return parse_port(p);
165 b777bf4b 2021-01-15 op } else
166 b777bf4b 2021-01-15 op p->parsed->port_no = 1965;
167 3c1cf9d0 2021-01-11 op
168 3c1cf9d0 2021-01-11 op if (*p->iri == '/') {
169 3c1cf9d0 2021-01-11 op *p->iri = '\0';
170 3c1cf9d0 2021-01-11 op p->iri++;
171 3c1cf9d0 2021-01-11 op return 1;
172 3c1cf9d0 2021-01-11 op }
173 3c1cf9d0 2021-01-11 op
174 3c1cf9d0 2021-01-11 op if (*p->iri == '\0')
175 3c1cf9d0 2021-01-11 op return 1;
176 3c1cf9d0 2021-01-11 op
177 3c1cf9d0 2021-01-11 op p->err = "illegal character in authority section";
178 3c1cf9d0 2021-01-11 op return 0;
179 3c1cf9d0 2021-01-11 op }
180 3c1cf9d0 2021-01-11 op
181 3c1cf9d0 2021-01-11 op /* Routine for path_clean. Elide the pointed .. with the preceding
182 3c1cf9d0 2021-01-11 op * element. Return 0 if it's not possible. incr is the length of
183 3c1cf9d0 2021-01-11 op * the increment, 3 for ../ and 2 for .. */
184 3c1cf9d0 2021-01-11 op static int
185 3c1cf9d0 2021-01-11 op path_elide_dotdot(char *path, char *i, int incr)
186 3c1cf9d0 2021-01-11 op {
187 3c1cf9d0 2021-01-11 op char *j;
188 3c1cf9d0 2021-01-11 op
189 3c1cf9d0 2021-01-11 op if (i == path)
190 3c1cf9d0 2021-01-11 op return 0;
191 3c1cf9d0 2021-01-11 op for (j = i-2; j != path && *j != '/'; j--)
192 3c1cf9d0 2021-01-11 op /* noop */ ;
193 3c1cf9d0 2021-01-11 op if (*j == '/')
194 3c1cf9d0 2021-01-11 op j++;
195 3c1cf9d0 2021-01-11 op i += incr;
196 3c1cf9d0 2021-01-11 op memmove(j, i, strlen(i)+1);
197 3c1cf9d0 2021-01-11 op return 1;
198 3c1cf9d0 2021-01-11 op }
199 3c1cf9d0 2021-01-11 op
200 3c1cf9d0 2021-01-11 op /*
201 3c1cf9d0 2021-01-11 op * Use an algorithm similar to the one implemented in go' path.Clean:
202 3c1cf9d0 2021-01-11 op *
203 3c1cf9d0 2021-01-11 op * 1. Replace multiple slashes with a single slash
204 3c1cf9d0 2021-01-11 op * 2. Eliminate each . path name element
205 3c1cf9d0 2021-01-11 op * 3. Eliminate each inner .. along with the non-.. element that precedes it
206 3c1cf9d0 2021-01-11 op * 4. Eliminate trailing .. if possible or error (go would only discard)
207 3c1cf9d0 2021-01-11 op *
208 3c1cf9d0 2021-01-11 op * Unlike path.Clean, this function return the empty string if the
209 3c1cf9d0 2021-01-11 op * original path is equivalent to "/".
210 3c1cf9d0 2021-01-11 op */
211 3c1cf9d0 2021-01-11 op static int
212 3c1cf9d0 2021-01-11 op path_clean(char *path)
213 3c1cf9d0 2021-01-11 op {
214 3c1cf9d0 2021-01-11 op char *i;
215 3c1cf9d0 2021-01-11 op
216 3c1cf9d0 2021-01-11 op /* 1. replace multiple slashes with a single one */
217 3c1cf9d0 2021-01-11 op for (i = path; *i; ++i) {
218 3c1cf9d0 2021-01-11 op if (*i == '/' && *(i+1) == '/') {
219 3c1cf9d0 2021-01-11 op memmove(i, i+1, strlen(i)); /* move also the \0 */
220 3c1cf9d0 2021-01-11 op i--;
221 3c1cf9d0 2021-01-11 op }
222 3c1cf9d0 2021-01-11 op }
223 3c1cf9d0 2021-01-11 op
224 3c1cf9d0 2021-01-11 op /* 2. eliminate each . path name element */
225 3c1cf9d0 2021-01-11 op for (i = path; *i; ++i) {
226 6a9ae707 2021-01-11 op if ((i == path || *i == '/') &&
227 6a9ae707 2021-01-11 op *i != '.' && i[1] == '.' && i[2] == '/') {
228 3c1cf9d0 2021-01-11 op /* move also the \0 */
229 3c1cf9d0 2021-01-11 op memmove(i, i+2, strlen(i)-1);
230 3c1cf9d0 2021-01-11 op i--;
231 3c1cf9d0 2021-01-11 op }
232 3c1cf9d0 2021-01-11 op }
233 3c1cf9d0 2021-01-11 op if (!strcmp(path, ".") || !strcmp(path, "/.")) {
234 3c1cf9d0 2021-01-11 op *path = '\0';
235 3c1cf9d0 2021-01-11 op return 1;
236 3c1cf9d0 2021-01-11 op }
237 3c1cf9d0 2021-01-11 op
238 3c1cf9d0 2021-01-11 op /* 3. eliminate each inner .. along with the preceding non-.. */
239 3c1cf9d0 2021-01-11 op for (i = strstr(path, "../"); i != NULL; i = strstr(path, ".."))
240 3c1cf9d0 2021-01-11 op if (!path_elide_dotdot(path, i, 3))
241 3c1cf9d0 2021-01-11 op return 0;
242 3c1cf9d0 2021-01-11 op
243 3c1cf9d0 2021-01-11 op /* 4. eliminate trailing ..*/
244 3c1cf9d0 2021-01-11 op if ((i = strstr(path, "..")) != NULL)
245 3c1cf9d0 2021-01-11 op if (!path_elide_dotdot(path, i, 2))
246 3c1cf9d0 2021-01-11 op return 0;
247 3c1cf9d0 2021-01-11 op
248 3c1cf9d0 2021-01-11 op return 1;
249 3c1cf9d0 2021-01-11 op }
250 3c1cf9d0 2021-01-11 op
251 3c1cf9d0 2021-01-11 op static int
252 3c1cf9d0 2021-01-11 op parse_query(struct parser *p)
253 3c1cf9d0 2021-01-11 op {
254 3c1cf9d0 2021-01-11 op p->parsed->query = p->iri;
255 3c1cf9d0 2021-01-11 op if (*p->iri == '\0')
256 3c1cf9d0 2021-01-11 op return 1;
257 3c1cf9d0 2021-01-11 op
258 3c1cf9d0 2021-01-11 op while (unreserved(*p->iri)
259 3c1cf9d0 2021-01-11 op || sub_delimiters(*p->iri)
260 3c1cf9d0 2021-01-11 op || *p->iri == '/'
261 3c1cf9d0 2021-01-11 op || *p->iri == '?'
262 3c1cf9d0 2021-01-11 op || parse_pct_encoded(p)
263 3c1cf9d0 2021-01-11 op || valid_multibyte_utf8(p))
264 3c1cf9d0 2021-01-11 op p->iri++;
265 3c1cf9d0 2021-01-11 op
266 3c1cf9d0 2021-01-11 op if (p->err != NULL)
267 3c1cf9d0 2021-01-11 op return 0;
268 3c1cf9d0 2021-01-11 op
269 3c1cf9d0 2021-01-11 op if (*p->iri != '\0' && *p->iri != '#') {
270 3c1cf9d0 2021-01-11 op p->err = "illegal character in query";
271 3c1cf9d0 2021-01-11 op return 0;
272 3c1cf9d0 2021-01-11 op }
273 3c1cf9d0 2021-01-11 op
274 3c1cf9d0 2021-01-11 op if (*p->iri != '\0') {
275 3c1cf9d0 2021-01-11 op *p->iri = '\0';
276 3c1cf9d0 2021-01-11 op p->iri++;
277 3c1cf9d0 2021-01-11 op }
278 3c1cf9d0 2021-01-11 op
279 3c1cf9d0 2021-01-11 op return 1;
280 3c1cf9d0 2021-01-11 op }
281 3c1cf9d0 2021-01-11 op
282 3c1cf9d0 2021-01-11 op /* don't even bother */
283 3c1cf9d0 2021-01-11 op static int
284 3c1cf9d0 2021-01-11 op parse_fragment(struct parser *p)
285 3c1cf9d0 2021-01-11 op {
286 3c1cf9d0 2021-01-11 op p->parsed->fragment = p->iri;
287 3c1cf9d0 2021-01-11 op return 1;
288 3c1cf9d0 2021-01-11 op }
289 3c1cf9d0 2021-01-11 op
290 3c1cf9d0 2021-01-11 op /* XXX: is it too broad? */
291 3c1cf9d0 2021-01-11 op /* *(pchar / "/") */
292 3c1cf9d0 2021-01-11 op static int
293 3c1cf9d0 2021-01-11 op parse_path(struct parser *p)
294 3c1cf9d0 2021-01-11 op {
295 3c1cf9d0 2021-01-11 op char c;
296 42bbdc79 2021-01-21 op
297 42bbdc79 2021-01-21 op /* trim initial slashes */
298 42bbdc79 2021-01-21 op while (*p->iri == '/')
299 42bbdc79 2021-01-21 op p->iri++;
300 3c1cf9d0 2021-01-11 op
301 3c1cf9d0 2021-01-11 op p->parsed->path = p->iri;
302 3c1cf9d0 2021-01-11 op if (*p->iri == '\0') {
303 3c1cf9d0 2021-01-11 op p->parsed->query = p->parsed->fragment = p->iri;
304 3c1cf9d0 2021-01-11 op return 1;
305 3c1cf9d0 2021-01-11 op }
306 3c1cf9d0 2021-01-11 op
307 3c1cf9d0 2021-01-11 op while (unreserved(*p->iri)
308 3c1cf9d0 2021-01-11 op || sub_delimiters(*p->iri)
309 3c1cf9d0 2021-01-11 op || *p->iri == '/'
310 3c1cf9d0 2021-01-11 op || parse_pct_encoded(p)
311 3c1cf9d0 2021-01-11 op || valid_multibyte_utf8(p))
312 3c1cf9d0 2021-01-11 op p->iri++;
313 3c1cf9d0 2021-01-11 op
314 3c1cf9d0 2021-01-11 op if (p->err != NULL)
315 3c1cf9d0 2021-01-11 op return 0;
316 3c1cf9d0 2021-01-11 op
317 3c1cf9d0 2021-01-11 op if (*p->iri != '\0' && *p->iri != '?' && *p->iri != '#') {
318 3c1cf9d0 2021-01-11 op p->err = "illegal character in path";
319 3c1cf9d0 2021-01-11 op return 0;
320 3c1cf9d0 2021-01-11 op }
321 3c1cf9d0 2021-01-11 op
322 3c1cf9d0 2021-01-11 op if (*p->iri != '\0') {
323 3c1cf9d0 2021-01-11 op c = *p->iri;
324 3c1cf9d0 2021-01-11 op *p->iri = '\0';
325 3c1cf9d0 2021-01-11 op p->iri++;
326 3c1cf9d0 2021-01-11 op
327 3c1cf9d0 2021-01-11 op if (c == '#') {
328 3c1cf9d0 2021-01-11 op if (!parse_fragment(p))
329 3c1cf9d0 2021-01-11 op return 0;
330 3c1cf9d0 2021-01-11 op } else
331 3c1cf9d0 2021-01-11 op if (!parse_query(p) || !parse_fragment(p))
332 3c1cf9d0 2021-01-11 op return 0;
333 3c1cf9d0 2021-01-11 op }
334 3c1cf9d0 2021-01-11 op
335 3c1cf9d0 2021-01-11 op if (!path_clean(p->parsed->path)) {
336 3c1cf9d0 2021-01-11 op p->err = "illegal path";
337 3c1cf9d0 2021-01-11 op return 0;
338 3c1cf9d0 2021-01-11 op }
339 3c1cf9d0 2021-01-11 op
340 3c1cf9d0 2021-01-11 op return 1;
341 3c1cf9d0 2021-01-11 op }
342 3c1cf9d0 2021-01-11 op
343 3c1cf9d0 2021-01-11 op int
344 3c1cf9d0 2021-01-11 op parse_iri(char *iri, struct iri *ret, const char **err_ret)
345 3c1cf9d0 2021-01-11 op {
346 3c1cf9d0 2021-01-11 op char *end;
347 3c1cf9d0 2021-01-11 op struct parser p = {iri, ret, NULL};
348 3c1cf9d0 2021-01-11 op
349 3c1cf9d0 2021-01-11 op bzero(ret, sizeof(*ret));
350 3c1cf9d0 2021-01-11 op
351 3c1cf9d0 2021-01-11 op /* initialize optional stuff to the empty string */
352 3c1cf9d0 2021-01-11 op end = iri + strlen(iri);
353 57d0d0ad 2021-01-31 op p.parsed->host = end;
354 3c1cf9d0 2021-01-11 op p.parsed->port = end;
355 3c1cf9d0 2021-01-11 op p.parsed->path = end;
356 3c1cf9d0 2021-01-11 op p.parsed->query = end;
357 3c1cf9d0 2021-01-11 op p.parsed->fragment = end;
358 3c1cf9d0 2021-01-11 op
359 3c1cf9d0 2021-01-11 op if (!parse_scheme(&p) || !parse_authority(&p) || !parse_path(&p)) {
360 3c1cf9d0 2021-01-11 op *err_ret = p.err;
361 3c1cf9d0 2021-01-11 op return 0;
362 3c1cf9d0 2021-01-11 op }
363 3c1cf9d0 2021-01-11 op
364 3c1cf9d0 2021-01-11 op *err_ret = NULL;
365 3c1cf9d0 2021-01-11 op return 1;
366 3c1cf9d0 2021-01-11 op }
367 3c1cf9d0 2021-01-11 op
368 3c1cf9d0 2021-01-11 op int
369 c4f682f8 2021-01-27 op trim_req_iri(char *iri, const char **err)
370 3c1cf9d0 2021-01-11 op {
371 3c1cf9d0 2021-01-11 op char *i;
372 3c1cf9d0 2021-01-11 op
373 c4f682f8 2021-01-27 op if ((i = strstr(iri, "\r\n")) == NULL) {
374 c4f682f8 2021-01-27 op *err = "missing CRLF";
375 3c1cf9d0 2021-01-11 op return 0;
376 c4f682f8 2021-01-27 op }
377 3c1cf9d0 2021-01-11 op *i = '\0';
378 3c1cf9d0 2021-01-11 op return 1;
379 3c1cf9d0 2021-01-11 op }